@dao-xyz/borsh
Advanced tools
Comparing version 2.1.0 to 2.1.1
@@ -415,2 +415,19 @@ "use strict"; | ||
}); | ||
test("extended enum inheritance variants, deserialization target does not matter", () => { | ||
let Super = class Super { | ||
}; | ||
Super = __decorate([ | ||
(0, index_1.variant)(1) | ||
], Super); | ||
let Clazz = class Clazz extends Super { | ||
constructor() { | ||
super(); | ||
} | ||
}; | ||
Clazz = __decorate([ | ||
(0, index_1.variant)(2) | ||
], Clazz); | ||
(0, index_1.deserialize)(Buffer.from((0, index_1.serialize)(new Clazz())), Clazz, false, binary_1.BinaryReader); | ||
(0, index_1.deserialize)(Buffer.from((0, index_1.serialize)(new Clazz())), Super, false, binary_1.BinaryReader); | ||
}); | ||
test("inheritance without variant", () => { | ||
@@ -417,0 +434,0 @@ class Super { |
@@ -171,2 +171,3 @@ "use strict"; | ||
const result = {}; | ||
clazz = getSuperMostClass(clazz); | ||
// assume clazz is super class | ||
@@ -334,2 +335,8 @@ if ((0, exports.getVariantIndex)(clazz) !== undefined) { | ||
}; | ||
const getSuperMostClass = (clazz) => { | ||
while (Object.getPrototypeOf(clazz).prototype != undefined) { | ||
clazz = Object.getPrototypeOf(clazz); | ||
} | ||
return clazz; | ||
}; | ||
const hasDependencies = (ctor, schema) => { | ||
@@ -492,5 +499,3 @@ if (!ctor.prototype._borsh_dependency || ctor.prototype._borsh_dependency.size == 0) { | ||
clazzes.forEach((clazz, ix) => { | ||
while (Object.getPrototypeOf(clazz).prototype != undefined) { | ||
clazz = Object.getPrototypeOf(clazz); | ||
} | ||
clazz = getSuperMostClass(clazz); | ||
let dependencies = getDependenciesRecursively(clazz); | ||
@@ -497,0 +502,0 @@ dependencies.set('_', clazz); |
{ | ||
"name": "@dao-xyz/borsh", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"readme": "README.md", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/dao-xyz/borsh-ts#README", |
@@ -449,2 +449,27 @@ import BN from "bn.js"; | ||
test("extended enum inheritance variants, deserialization target does not matter", () => { | ||
@variant(1) | ||
class Super {} | ||
@variant(2) | ||
class Clazz extends Super { | ||
constructor() { | ||
super(); | ||
} | ||
} | ||
deserialize( | ||
Buffer.from(serialize(new Clazz())), | ||
Clazz, | ||
false, | ||
BinaryReader | ||
); | ||
deserialize( | ||
Buffer.from(serialize(new Clazz())), | ||
Super, | ||
false, | ||
BinaryReader | ||
); | ||
}); | ||
test("inheritance without variant", () => { | ||
@@ -607,3 +632,2 @@ class Super {} | ||
} | ||
let bytes = serialize( | ||
@@ -610,0 +634,0 @@ new HighCouncil([new Gorilla("Go"), new Orangutan("Ora")]) |
@@ -25,3 +25,2 @@ import bs58 from "bs58"; | ||
} | ||
export function baseDecode(value: string): Buffer { | ||
@@ -192,2 +191,4 @@ return Buffer.from(bs58.decode(value)); | ||
clazz = getSuperMostClass(clazz); | ||
// assume clazz is super class | ||
@@ -387,3 +388,8 @@ if (getVariantIndex(clazz) !== undefined) { | ||
} | ||
const getSuperMostClass = (clazz: Constructor<any>) => { | ||
while (Object.getPrototypeOf(clazz).prototype != undefined) { | ||
clazz = Object.getPrototypeOf(clazz); | ||
} | ||
return clazz; | ||
} | ||
const hasDependencies = (ctor: Function, schema: Map<any, StructKind>): boolean => { | ||
@@ -568,5 +574,3 @@ if (!ctor.prototype._borsh_dependency || ctor.prototype._borsh_dependency.size == 0) { | ||
clazzes.forEach((clazz, ix) => { | ||
while (Object.getPrototypeOf(clazz).prototype != undefined) { | ||
clazz = Object.getPrototypeOf(clazz); | ||
} | ||
clazz = getSuperMostClass(clazz); | ||
let dependencies = getDependenciesRecursively(clazz); | ||
@@ -573,0 +577,0 @@ dependencies.set('_', clazz); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
320904
5769