New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@dao-xyz/borsh

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dao-xyz/borsh - npm Package Compare versions

Comparing version 2.1.1 to 2.1.2

20

lib/cjs/__tests__/index.test.js

@@ -432,2 +432,22 @@ "use strict";

});
test("extended enum inheritance and field value conflict is resolved", () => {
let Super = class Super {
};
Super = __decorate([
(0, index_1.variant)(1)
], Super);
let Clazz = class Clazz extends Super {
constructor() {
super();
}
};
__decorate([
(0, index_1.field)({ type: (0, index_1.option)(Super) })
], Clazz.prototype, "field", void 0);
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", () => {

@@ -434,0 +454,0 @@ class Super {

34

lib/cjs/index.js

@@ -45,3 +45,15 @@ "use strict";

// TODO: Handle missing values properly (make sure they never result in just skipped write)
if (typeof fieldType === "string") {
if (value === null || value === undefined) {
if (fieldType instanceof types_1.OptionKind) {
writer.writeU8(0);
}
else {
throw new error_1.BorshError(`Trying to serialize a null value but field ${fieldName} but field type is not of type 'option(...)' but is: ${fieldType}`);
}
}
else if (fieldType instanceof types_1.OptionKind) {
writer.writeU8(1);
serializeField(fieldName, value, fieldType.elementType, writer);
}
else if (typeof fieldType === "string") {
writer[`write${capitalizeFirstLetter(fieldType)}`](value);

@@ -64,11 +76,2 @@ }

}
else if (fieldType instanceof types_1.OptionKind) {
if (value === null || value === undefined) {
writer.writeU8(0);
}
else {
writer.writeU8(1);
serializeField(fieldName, value, fieldType.elementType, writer);
}
}
else if (typeof fieldType["serialize"] == "function") {

@@ -90,2 +93,5 @@ fieldType.serialize(value, writer);

function serializeStruct(obj, writer) {
if (obj == undefined) {
const t = 123;
}
if (typeof obj.borshSerialize === "function") {

@@ -314,2 +320,6 @@ obj.borshSerialize(writer);

let key = JSON.stringify((0, exports.getVariantIndex)(dependency));
let classPathKey = "__" + ctor.name + "/" + dependency.name;
if (dependencies.has(classPathKey) && key != undefined) {
dependencies.delete(classPathKey);
}
if (key != undefined && dependencies.has(key)) {

@@ -326,3 +336,3 @@ if (dependencies.get(key) == dependency) {

* class A {}
* class B extends A {}
* class B extends A { @field... }
*

@@ -334,3 +344,3 @@ * @variant(0)

*/
key = ctor.name + "/" + dependency.name;
key = classPathKey;
}

@@ -337,0 +347,0 @@ dependencies.set(key, dependency);

{
"name": "@dao-xyz/borsh",
"version": "2.1.1",
"version": "2.1.2",
"readme": "README.md",

@@ -60,2 +60,2 @@ "homepage": "https://github.com/dao-xyz/borsh-ts#README",

}
}
}

@@ -466,2 +466,3 @@ import BN from "bn.js";

);
deserialize(

@@ -475,2 +476,30 @@ Buffer.from(serialize(new Clazz())),

test("extended enum inheritance and field value conflict is resolved", () => {
@variant(1)
class Super {}
@variant(2)
class Clazz extends Super {
@field({ type: option(Super) })
field: 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", () => {

@@ -477,0 +506,0 @@ class Super {}

@@ -41,3 +41,15 @@ import bs58 from "bs58";

// TODO: Handle missing values properly (make sure they never result in just skipped write)
if (typeof fieldType === "string") {
if (value === null || value === undefined) {
if (fieldType instanceof OptionKind) {
writer.writeU8(0);
} else {
throw new BorshError(`Trying to serialize a null value but field ${fieldName} but field type is not of type 'option(...)' but is: ${fieldType}`)
}
}
else if (fieldType instanceof OptionKind) {
writer.writeU8(1);
serializeField(fieldName, value, fieldType.elementType, writer);
}
else if (typeof fieldType === "string") {
writer[`write${capitalizeFirstLetter(fieldType)}`](value);

@@ -62,9 +74,2 @@ } else if (

}
} else if (fieldType instanceof OptionKind) {
if (value === null || value === undefined) {
writer.writeU8(0);
} else {
writer.writeU8(1);
serializeField(fieldName, value, fieldType.elementType, writer);
}
} else if (typeof fieldType["serialize"] == "function") {

@@ -87,2 +92,5 @@ fieldType.serialize(value, writer);

) {
if (obj == undefined) {
const t = 123;
}
if (typeof obj.borshSerialize === "function") {

@@ -366,2 +374,6 @@ obj.borshSerialize(writer);

let key = JSON.stringify(getVariantIndex(dependency));
let classPathKey = "__" + ctor.name + "/" + dependency.name;
if (dependencies.has(classPathKey) && key != undefined) {
dependencies.delete(classPathKey)
}
if (key != undefined && dependencies.has(key)) {

@@ -378,3 +390,3 @@ if (dependencies.get(key) == dependency) {

* class A {}
* class B extends A {}
* class B extends A { @field... }
*

@@ -386,3 +398,3 @@ * @variant(0)

*/
key = ctor.name + "/" + dependency.name;
key = classPathKey;
}

@@ -389,0 +401,0 @@ dependencies.set(key, dependency);

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc