Skip to content

Commit

Permalink
feat: use boarsh schema type
Browse files Browse the repository at this point in the history
  • Loading branch information
fospring committed May 5, 2024
1 parent 37f2f78 commit c9d5707
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 9 deletions.
5 changes: 3 additions & 2 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@
"author": "Near Inc <hello@nearprotocol.com>",
"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",
Expand Down
16 changes: 9 additions & 7 deletions examples/src/status-deserialize-class.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand All @@ -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 = "";
Expand All @@ -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},
Expand Down
2 changes: 2 additions & 0 deletions packages/near-sdk-js/lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/near-sdk-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions packages/near-sdk-js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
32 changes: 32 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c9d5707

Please sign in to comment.