diff --git a/examples/package.json b/examples/package.json index 55897f4b3..560fd27d7 100644 --- a/examples/package.json +++ b/examples/package.json @@ -62,11 +62,12 @@ "author": "Near Inc ", "license": "Apache-2.0", "dependencies": { + "borsh": "^v1.0.0", + "borsher": "^3.5.0", "lodash-es": "^4.17.21", "near-contract-standards": "workspace:*", "near-sdk-js": "workspace:*", - "typescript": "^4.7.4", - "borsh": "^v1.0.0" + "typescript": "^4.7.4" }, "devDependencies": { "@types/lodash-es": "^4.17.6", diff --git a/examples/src/index2.js b/examples/src/index2.js new file mode 100644 index 000000000..5a8e631d6 --- /dev/null +++ b/examples/src/index2.js @@ -0,0 +1,4 @@ +// test import `BorshSchema` +import { BorshSchema, borshSerialize, borshDeserialize } from 'borsher'; +const n = 100; +const buffer = borshSerialize(BorshSchema.u8, n); diff --git a/examples/src/status-deserialize-class.js b/examples/src/status-deserialize-class.js index e2bf53f70..59a897be5 100644 --- a/examples/src/status-deserialize-class.js +++ b/examples/src/status-deserialize-class.js @@ -7,12 +7,14 @@ import { LookupMap, Vector, UnorderedSet, + // BorshSchema, } from "near-sdk-js"; +import { BorshSchema, borshSerialize, borshDeserialize } from 'borsher'; class Car { static schema = { - name: "string", - speed: "number", + name: BorshSchema.String, + speed: BorshSchema.u64, }; constructor() { this.name = ""; @@ -26,9 +28,9 @@ class Car { class Truck { static schema = { - name: "string", - speed: "number", - loads: UnorderedMap + name: BorshSchema.String, + speed: BorshSchema.u64, + loads: BorshSchema.Struct(UnorderedMap) }; constructor() { this.name = ""; @@ -47,8 +49,8 @@ class Truck { @NearBindgen({}) export class StatusDeserializeClass { static schema = { - truck: Truck, - efficient_recordes: UnorderedMap, + truck: BorshSchema.Struct(Truck), + efficient_recordes: BorshSchema.Struct(UnorderedMap), nested_efficient_recordes: {class: UnorderedMap, value: UnorderedMap}, nested_lookup_recordes: {class: UnorderedMap, value: LookupMap}, vector_nested_group: {class: Vector, value: LookupMap}, diff --git a/packages/near-sdk-js/lib/index.js b/packages/near-sdk-js/lib/index.js index f1d4ec937..ec45577e2 100644 --- a/packages/near-sdk-js/lib/index.js +++ b/packages/near-sdk-js/lib/index.js @@ -4,3 +4,5 @@ export * as near from "./api"; export * from "./near-bindgen"; export * from "./promise"; export * from "./utils"; +// import { BorshSchema } from "borsher"; +// export { BorshSchema }; diff --git a/packages/near-sdk-js/package.json b/packages/near-sdk-js/package.json index 3443c5dfa..1a8148fbb 100644 --- a/packages/near-sdk-js/package.json +++ b/packages/near-sdk-js/package.json @@ -43,6 +43,7 @@ "@types/estree": "^1.0.0", "@typescript-eslint/eslint-plugin": "^5.31.0", "@typescript-eslint/parser": "^5.31.0", + "borsher": "^3.5.0", "commander": "^9.4.1", "eslint": "^8.20.0", "json-schema": "0.4.0", diff --git a/packages/near-sdk-js/src/index.ts b/packages/near-sdk-js/src/index.ts index f1d4ec937..ec45577e2 100644 --- a/packages/near-sdk-js/src/index.ts +++ b/packages/near-sdk-js/src/index.ts @@ -4,3 +4,5 @@ export * as near from "./api"; export * from "./near-bindgen"; export * from "./promise"; export * from "./utils"; +// import { BorshSchema } from "borsher"; +// export { BorshSchema }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c4c4a4d2e..19536324d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -42,6 +42,9 @@ importers: borsh: specifier: ^v1.0.0 version: 1.0.0 + borsher: + specifier: ^3.5.0 + version: 3.5.0 lodash-es: specifier: ^4.17.21 version: 4.17.21 @@ -116,6 +119,9 @@ importers: '@typescript-eslint/parser': specifier: ^5.31.0 version: 5.62.0(eslint@8.54.0)(typescript@4.7.4) + borsher: + specifier: ^3.5.0 + version: 3.5.0 commander: specifier: ^9.4.1 version: 9.5.0 @@ -1366,6 +1372,10 @@ packages: safe-buffer: 5.2.1 dev: true + /base64-js@1.5.1: + resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==} + dev: false + /base64url@3.0.1: resolution: {integrity: sha512-ir1UPr3dkwexU7FdV8qBBbNDRUhMmIekYMFZfi+C/sLNnRESKPl23nB9b2pltqfOQNnGzsDdId90AEtG5tCx4A==} engines: {node: '>=6.0.0'} @@ -1404,6 +1414,17 @@ packages: resolution: {integrity: sha512-fSVWzzemnyfF89EPwlUNsrS5swF5CrtiN4e+h0/lLf4dz2he4L3ndM20PS9wj7ICSkXJe/TQUHdaPTq15b1mNQ==} dev: false + /borsh@2.0.0: + resolution: {integrity: sha512-kc9+BgR3zz9+cjbwM8ODoUB4fs3X3I5A/HtX7LZKxCLaMrEeDFoBpnhZY//DTS1VZBSs6S5v46RZRbZjRFspEg==} + dev: false + + /borsher@3.5.0: + resolution: {integrity: sha512-53UlE2ukArKGrw3u+MKR5CBqYR+Fr47tGAeIRmAy+W5G6FMRnoM7G8mHYFeijGyhKje5aaQTCqZu/hugQ2HiBA==} + dependencies: + borsh: 2.0.0 + buffer: 6.0.3 + dev: false + /brace-expansion@1.1.11: resolution: {integrity: sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==} dependencies: @@ -1438,6 +1459,13 @@ packages: base-x: 3.0.9 dev: true + /buffer@6.0.3: + resolution: {integrity: sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==} + dependencies: + base64-js: 1.5.1 + ieee754: 1.2.1 + dev: false + /builtin-modules@3.3.0: resolution: {integrity: sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==} engines: {node: '>=6'} @@ -2357,6 +2385,10 @@ packages: resolve-alpn: 1.2.1 dev: true + /ieee754@1.2.1: + resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==} + dev: false + /ignore-by-default@2.1.0: resolution: {integrity: sha512-yiWd4GVmJp0Q6ghmM2B/V3oZGRmjrKLXvHR3TE1nfoXsmoggllfZUQe74EN0fJdPFZu2NIvNdrMMLm3OsV7Ohw==} engines: {node: '>=10 <11 || >=12 <13 || >=14'}