{"_id":"@calamari-radix/sbor-ez-mode","_rev":"4-e58c926456b24125ce671778a66b20d1","name":"@calamari-radix/sbor-ez-mode","dist-tags":{"latest":"1.2.1"},"versions":{"1.0.0":{"name":"@calamari-radix/sbor-ez-mode","version":"1.0.0","keywords":[],"license":"MIT","_id":"@calamari-radix/sbor-ez-mode@1.0.0","maintainers":[{"name":"krulk","email":"krulknul@gmail.com"}],"homepage":"https://github.com/CalamariRadix/gateway-ez-mode#readme","bugs":{"url":"https://github.com/CalamariRadix/gateway-ez-mode/issues"},"dist":{"shasum":"c6c99bd00683decbc0776e5f5f40b17942725f9d","tarball":"https://registry.npmjs.org/@calamari-radix/sbor-ez-mode/-/sbor-ez-mode-1.0.0.tgz","fileCount":76,"integrity":"sha512-aEHkLziYZPnKnjf81giOQJRj8teKdL50ITtJdXUFduMpzCAEr4+1okzaBVo9VfLfx9aQkmRM5aq8EeSV8CqVuw==","signatures":[{"sig":"MEQCIBJkxuPD8v4EqYt9xuf1wT6clCSgFmRFOuclHUW3lCZiAiBuC6IQloaJY4Rsb/b3BTDsuHsrQuCVtBQROitovXCp2w==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":208303},"main":"dist/index.js","_from":"file:calamari-radix-sbor-ez-mode-1.0.0.tgz","types":"dist/index.d.ts","scripts":{"lint":"eslint --ext .ts src","test":"vitest run","build":"rm -rf dist && tsc -p tsconfig.build.json","test:watch":"vitest","check-types":"tsc --noEmit"},"_npmUser":{"name":"krulk","email":"krulknul@gmail.com"},"_resolved":"/tmp/2b7d4b36ff5370d30fa6874c2da5cd98/calamari-radix-sbor-ez-mode-1.0.0.tgz","_integrity":"sha512-aEHkLziYZPnKnjf81giOQJRj8teKdL50ITtJdXUFduMpzCAEr4+1okzaBVo9VfLfx9aQkmRM5aq8EeSV8CqVuw==","repository":{"url":"git+https://github.com/CalamariRadix/gateway-ez-mode.git","type":"github"},"_npmVersion":"10.8.2","description":"A TypeScript schema definition and parsing library for the Scrypto SBOR Programmatic JSON representation","directories":{},"_nodeVersion":"20.18.3","dependencies":{"@radixdlt/babylon-gateway-api-sdk":"^1.10.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"eslint":"^9.21.0","vitest":"^3.0.7","typescript":"5.7.3","@calamari-radix/eslint-config":"1.0.0"},"_npmOperationalInternal":{"tmp":"tmp/sbor-ez-mode_1.0.0_1742079649630_0.37552203214924784","host":"s3://npm-registry-packages-npm-production"}},"1.1.0":{"name":"@calamari-radix/sbor-ez-mode","version":"1.1.0","keywords":[],"license":"MIT","_id":"@calamari-radix/sbor-ez-mode@1.1.0","maintainers":[{"name":"krulk","email":"krulknul@gmail.com"}],"homepage":"https://github.com/CalamariRadix/gateway-ez-mode#readme","bugs":{"url":"https://github.com/CalamariRadix/gateway-ez-mode/issues"},"dist":{"shasum":"eb6d15e6e77ca8db032cf37f54e25da581797d71","tarball":"https://registry.npmjs.org/@calamari-radix/sbor-ez-mode/-/sbor-ez-mode-1.1.0.tgz","fileCount":70,"integrity":"sha512-ZoAqQrWtLbaJQVQn7+1uDlKLd2HFl07UKp4iIQa/2g+1sHMtnZz5UKFz2DqDn4MA/LxfQSro9FJR1mFunginoA==","signatures":[{"sig":"MEUCIQDvdd3ZoV59AEcV1QvKTmlFt6dBvZkYf9aT0Kc2OtIQogIgD9Q3FP2wEmErLjxHY+LKKdDRCvOPmU4R+iu3/Wj39+o=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":149423},"main":"dist/index.js","_from":"file:calamari-radix-sbor-ez-mode-1.1.0.tgz","types":"dist/index.d.ts","scripts":{"lint":"eslint --ext .ts src","test":"vitest run","build":"rm -rf dist && tsc -p tsconfig.build.json","test:watch":"vitest","check-types":"tsc --noEmit"},"_npmUser":{"name":"krulk","email":"krulknul@gmail.com"},"_resolved":"/tmp/607c3b1accbea30423f73c6e07a327c1/calamari-radix-sbor-ez-mode-1.1.0.tgz","_integrity":"sha512-ZoAqQrWtLbaJQVQn7+1uDlKLd2HFl07UKp4iIQa/2g+1sHMtnZz5UKFz2DqDn4MA/LxfQSro9FJR1mFunginoA==","repository":{"url":"git+https://github.com/CalamariRadix/gateway-ez-mode.git","type":"github"},"_npmVersion":"10.8.2","description":"A TypeScript schema definition and parsing library for the Scrypto SBOR Programmatic JSON representation","directories":{},"_nodeVersion":"20.19.0","dependencies":{"neverthrow":"^8.2.0","@radixdlt/babylon-gateway-api-sdk":"^1.10.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"eslint":"^9.21.0","vitest":"^3.0.7","typescript":"5.7.3","@calamari-radix/eslint-config":"1.0.0"},"_npmOperationalInternal":{"tmp":"tmp/sbor-ez-mode_1.1.0_1742420539018_0.20148557839316128","host":"s3://npm-registry-packages-npm-production"}},"1.2.0":{"name":"@calamari-radix/sbor-ez-mode","version":"1.2.0","keywords":[],"license":"MIT","_id":"@calamari-radix/sbor-ez-mode@1.2.0","maintainers":[{"name":"krulk","email":"krulknul@gmail.com"}],"homepage":"https://github.com/CalamariRadix/gateway-ez-mode#readme","bugs":{"url":"https://github.com/CalamariRadix/gateway-ez-mode/issues"},"dist":{"shasum":"055b86a5b486c2074af53302276769f7a56294fb","tarball":"https://registry.npmjs.org/@calamari-radix/sbor-ez-mode/-/sbor-ez-mode-1.2.0.tgz","fileCount":70,"integrity":"sha512-aMaxeJ2hB8ciU9CtW8gya4QMyR/3X1DhxhRUTO5rA9c5Thd8k7sWD9vkw1AZ4du0JxStGN1dJJazIUODWyAeqA==","signatures":[{"sig":"MEQCIDY1DUV4PlZRItzYHTddIIHEKOuxIo1oD/Y+jXGGJiVzAiBGWO8eulZ0V/5RP1aK18FwlM1SurWraVa6UgbJ0Z2Ozw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":150835},"main":"dist/index.js","_from":"file:calamari-radix-sbor-ez-mode-1.2.0.tgz","types":"dist/index.d.ts","scripts":{"lint":"eslint --ext .ts src","test":"vitest run","build":"rm -rf dist && tsc -p tsconfig.build.json","test:watch":"vitest","check-types":"tsc --noEmit"},"_npmUser":{"name":"krulk","email":"krulknul@gmail.com"},"_resolved":"/tmp/551343abec725af25d1a364b04aa575a/calamari-radix-sbor-ez-mode-1.2.0.tgz","_integrity":"sha512-aMaxeJ2hB8ciU9CtW8gya4QMyR/3X1DhxhRUTO5rA9c5Thd8k7sWD9vkw1AZ4du0JxStGN1dJJazIUODWyAeqA==","repository":{"url":"git+https://github.com/CalamariRadix/gateway-ez-mode.git","type":"github"},"_npmVersion":"10.8.2","description":"A TypeScript schema definition and parsing library for the Scrypto SBOR Programmatic JSON representation","directories":{},"_nodeVersion":"20.19.0","dependencies":{"neverthrow":"^8.2.0","@radixdlt/babylon-gateway-api-sdk":"^1.10.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"eslint":"^9.21.0","vitest":"^3.0.7","typescript":"5.7.3","@calamari-radix/eslint-config":"1.0.0"},"_npmOperationalInternal":{"tmp":"tmp/sbor-ez-mode_1.2.0_1742496449336_0.9312611732370704","host":"s3://npm-registry-packages-npm-production"}},"1.2.1":{"name":"@calamari-radix/sbor-ez-mode","version":"1.2.1","main":"dist/index.js","types":"dist/index.d.ts","keywords":[],"repository":{"url":"git+https://github.com/CalamariRadix/gateway-ez-mode.git","type":"github"},"license":"MIT","description":"A TypeScript schema definition and parsing library for the Scrypto SBOR Programmatic JSON representation","devDependencies":{"eslint":"^9.21.0","typescript":"5.7.3","vitest":"^3.0.7","@calamari-radix/eslint-config":"1.0.0"},"dependencies":{"@radixdlt/babylon-gateway-api-sdk":"^1.10.0","neverthrow":"^8.2.0"},"publishConfig":{"access":"public"},"scripts":{"build":"rm -rf dist && tsc -p tsconfig.build.json","lint":"eslint --ext .ts src","check-types":"tsc --noEmit","test":"vitest run","test:watch":"vitest"},"_id":"@calamari-radix/sbor-ez-mode@1.2.1","bugs":{"url":"https://github.com/CalamariRadix/gateway-ez-mode/issues"},"homepage":"https://github.com/CalamariRadix/gateway-ez-mode#readme","_integrity":"sha512-fQl6hYFzvYG081WYBKOR08WfQwdt8/nsjnP79+b3zldlfThc3RUEBabPpRllr9QpSGKhb2wJ60ORo2cxVS9xyg==","_resolved":"/tmp/50b8d180c46da14c6e7119f9025de7ce/calamari-radix-sbor-ez-mode-1.2.1.tgz","_from":"file:calamari-radix-sbor-ez-mode-1.2.1.tgz","_nodeVersion":"20.19.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-fQl6hYFzvYG081WYBKOR08WfQwdt8/nsjnP79+b3zldlfThc3RUEBabPpRllr9QpSGKhb2wJ60ORo2cxVS9xyg==","shasum":"b584a05911aff8e3afca13b9ff3658efd308d949","tarball":"https://registry.npmjs.org/@calamari-radix/sbor-ez-mode/-/sbor-ez-mode-1.2.1.tgz","fileCount":70,"unpackedSize":151577,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIClA69m8PjrePTXTL9x+Jm5KEsSD1Nxt4o9wMTAf8+ScAiEA9qS5/bGVk16orh95AyVCiqjGDtnLpo6SSM4gHXby56M="}]},"_npmUser":{"name":"krulk","email":"krulknul@gmail.com"},"directories":{},"maintainers":[{"name":"krulk","email":"krulknul@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/sbor-ez-mode_1.2.1_1743262713539_0.057391991627387506"},"_hasShrinkwrap":false}},"time":{"created":"2025-03-15T23:00:49.568Z","modified":"2025-03-29T15:38:33.991Z","1.0.0":"2025-03-15T23:00:49.797Z","1.1.0":"2025-03-19T21:42:19.205Z","1.2.0":"2025-03-20T18:47:29.541Z","1.2.1":"2025-03-29T15:38:33.783Z"},"bugs":{"url":"https://github.com/CalamariRadix/gateway-ez-mode/issues"},"license":"MIT","homepage":"https://github.com/CalamariRadix/gateway-ez-mode#readme","keywords":[],"repository":{"url":"git+https://github.com/CalamariRadix/gateway-ez-mode.git","type":"github"},"description":"A TypeScript schema definition and parsing library for the Scrypto SBOR Programmatic JSON representation","maintainers":[{"name":"krulk","email":"krulknul@gmail.com"}],"readme":"# sbor-ez-mode\n\nThe simple way to parse Programmatic JSON into nice JavaScript objects with an api inspired by Zod.\n\n## Installation\n\n```sh\nnpm install @calamari-radix/sbor-ez-mode\n```\n\n## Warning: The APIs in this repository may not be stable and could be changed at any time.\n\n## Usage\n\n## Parsing ProgrammaticScryptoSborValue\n\nThe Radix network uses a custom data serialization standard called Scrypto SBOR for storing on-ledger state. This data format can be represented and consumed as JSON in a special representation called Scrypto SBOR Programmatic JSON. While the Babylon Gateway SDK has good types for this programmatic JSON, it is quite difficult and time-consuming to parse the values coming from ledger into workable JS/TS values.\n\nThis package contains a library inspired by the popular validation library Zod, that makes it easy to write TypeScript schemas for your Scrypto types and parse them into nice javascript objects, arrays, maps etc in one go.\n\n### A note on error handling\n\nThis package uses [neverthrow](https://github.com/supermacro/neverthrow)'s `Result` type for error handling. This means that the result of a safeParse operation will always be a `Result` object, which can be either `Ok` or `Err`. You can check if the result is `Ok` or `Err` and then access the value or error accordingly. For more information on how to use the Result type, please refer to the neverthrow documentation.\n\n### A simple example:\n\n```ts\n// s (for sbor) is the main object you'll have to import to create schemas and parse\nimport s from '@calamari-radix/sbor-ez-mode';\n\nconst swapEventSchema = s.struct({\n    input_address: s.address(),\n    input_amount: s.decimal(),\n    output_address: s.address(),\n    output_amount: s.decimal(),\n    is_success: s.bool(),\n});\n```\n\nThis schema represents the following Rust struct:\n\n```rust\nstruct SwapEvent {\n    input_address: ResourceAddress,\n    input_amount: Decimal,\n    output_address: ResourceAddress,\n    output_amount: Decimal,\n    is_success: bool\n}\n```\n\nThe programmatic json might look like this:\nDon't be fooled! The `Kind` is `Tuple`, but this is surely a struct!\nScrypto SBOR does not have a Struct Kind natively, it is represented by Tuple.\n\n```json\n{\n    \"fields\": [\n        {\n            \"value\": \"resource_rdx1t5pyvlaas0ljxy0wytm5gvyamyv896m69njqdmm2stukr3xexc2up9\",\n            \"kind\": \"Reference\",\n            \"type_name\": \"ResourceAddress\",\n            \"field_name\": \"input_address\"\n        },\n        {\n            \"value\": \"0.003427947474666592\",\n            \"kind\": \"Decimal\",\n            \"field_name\": \"input_amount\"\n        },\n        {\n            \"value\": \"resource_rdx1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxradxrd\",\n            \"kind\": \"Reference\",\n            \"type_name\": \"ResourceAddress\",\n            \"field_name\": \"output_address\"\n        },\n        {\n            \"value\": \"522.23800528105807128\",\n            \"kind\": \"Decimal\",\n            \"field_name\": \"output_amount\"\n        },\n        {\n            \"field_name\": \"is_success\",\n            \"kind\": \"Bool\",\n            \"value\": true\n        }\n    ],\n    \"kind\": \"Tuple\",\n    \"type_name\": \"SwapEvent\"\n}\n```\n\nNow we can parse this programmatic JSON into our nice schema:\n\n```ts\n// The return type is `neverthrow`'s `Result` type, which you can nicely handle\n// in a lot of ways.\nconst result = swapEventSchema.safeParse(example);\n\nif (result.isOk()) {\n    console.log(result.value);\n}\n// {\n//     input_address: 'resource_rdx1t5py...',\n//     input_amount: '0.003427947474666592',\n//     output_address: 'resource_rdx1tknxxxx...',\n//     output_amount: '522.23800528105807128',\n//     is_success: true,\n// }\n```\n\nSo now we managed to go from this huge JSON representation to an easy to use, pretty object representation.\n\n### Parsing arrays\n\nRust type:\n\n```rust\nVec<u32>\n```\n\n```ts\nconst example: ProgrammaticScryptoSborValue = {\n    kind: 'Array',\n    field_name: 'nft_ids',\n    type_name: 'Array',\n    element_kind: 'NonFungibleLocalId',\n    elements: [\n        {\n            kind: 'NonFungibleLocalId',\n            value: '#1#',\n        },\n        {\n            kind: 'NonFungibleLocalId',\n            value: '#2#',\n        },\n        {\n            kind: 'NonFungibleLocalId',\n            value: '#3#',\n        },\n    ],\n};\nconst schema = s.array(s.nonFungibleLocalId());\nconst result = schema.safeParse(example);\n\nif (result.isOk()) {\n    console.log(result.value);\n}\n\n// ['#1#', '#2#', '#3#'];\n```\n\n### Parsing maps\n\nRust type:\n\n```rust\nHashMap<String, String>\n```\n\n```ts\nconst example: ProgrammaticScryptoSborValue = {\n    kind: 'Map',\n    field_name: 'map',\n    key_kind: 'String',\n    value_kind: 'String',\n    entries: [\n        {\n            key: {\n                kind: 'String',\n                value: 'boinoing',\n            },\n            value: {\n                kind: 'String',\n                value: 'boobies',\n            },\n        },\n        {\n            key: {\n                kind: 'String',\n                value: 'impostor',\n            },\n            value: {\n                kind: 'String',\n                value: 'amogus',\n            },\n        },\n    ],\n};\n```\n\n```ts\nconst schema = s.map({\n    key: s.string(),\n    value: s.string(),\n});\n\nconst result = schema.safeParse(example);\n\nif (result.isOk()) {\n    console.log(result.value);\n}\n\n// Map(2) { 'boinoing' => 'boobies', 'impostor' => 'amogus' }\n```\n\n### Parsing a tuple\n\nRust type:\n\n```rust\n(String, u32)\n```\n\n```ts\nconst example: ProgrammaticScryptoSborValue = {\n    kind: 'Tuple',\n    field_name: 'tuple',\n    type_name: 'tuple',\n    fields: [\n        {\n            kind: 'String',\n            value: 'hello',\n        },\n        {\n            kind: 'U32',\n            value: '5',\n        },\n    ],\n};\n\nconst schema = s.tuple([s.string(), s.number()]);\nconst result = schema.safeParse(example);\n\nif (result.isOk()) {\n    console.log(result.value);\n}\n\n// ['hello', 5];\n```\n\n## Parsing enums\n\nThe corresponding Rust type:\n\n```rust\nenum MyEnum {\n    NonFungible {\n        ids: Vec<NonFungibleLocalId>,\n        resource_address: ResourceAddress,\n    },\n    Fungible(Decimal),\n}\n```\n\nTo parse enums, you will have to provide the `enum` schema constructor with an array of variant definitions. The schema passed to `schema` _must_ be either a struct or a tuple schema, but of course it can then contain any other schema. The result will have the nice type inference you would expect, meeaning you can do type narrowing on the result to figure out which variant was parsed and act accordingly.\n\n```ts\nconst myEnumSchema = s.enum([\n    {\n        variant: 'NonFungible',\n        schema: s.struct({\n            ids: s.array(s.nonFungibleLocalId()),\n            resource_address: s.address(),\n        }),\n    },\n    { variant: 'Fungible', schema: s.tuple([s.decimal()]) },\n]);\n```\n\nIn the case of a `NonFungible` variant, the programmatic JSON might look like this:\n\n```ts\nconst example: ProgrammaticScryptoSborValue = {\n    kind: 'Enum',\n    variant_id: '0',\n    variant_name: 'NonFungible',\n    fields: [\n        {\n            kind: 'Array',\n            field_name: 'ids',\n            values: [\n                {\n                    kind: 'NonFungibleLocalId',\n                    value: '#1#',\n                },\n            ],\n        },\n        {\n            kind: 'Reference',\n            field_name: 'resource_address',\n            value: 'resource_rdx1t5pyvlaas0ljxy0wytm5gvyamyv896m69njqdmm2stukr3xexc2up9',\n        },\n    ],\n};\n```\n\nNow we can parse this programmatic JSON into our nice schema:\n\n```ts\nconst result = myEnumSchema.safeParse(example);\n\nif (result.isOk()) {\n    console.log(result.value);\n}\n\n// {\n//     variant: 'NonFungible',\n//     value: {\n//         ids: ['#1#'],\n//         resource_address: 'resource_rdx1t5pyvlaas0ljxy0wytm5gvyamyv896m69njqdmm2stukr3xexc2up9',\n//     },\n// }\n```\n\n### Using the option utility enum\n\nThe `option` utility enum is a special enum schema that can be used to represent optional values. It has two variants: `Some` and `None`.\n\nThe corresponding Rust type:\n\n```rust\nOption<u32>\n```\n\nExample of parsing a `None`:\n\n```ts\nconst example: ProgrammaticScryptoSborValue = {\n    kind: 'Enum',\n    variant_id: '0',\n    variant_name: 'None',\n    fields: [],\n};\n\nconst schema = s.option(s.string());\n\nconst result = schema.safeParse(example);\n\nif (result.isOk()) {\n    console.log(result.value);\n}\n\n// { variant: 'None' }\n```\n\nExample of parsing a `Some`:\n\n```ts\nconst example: ProgrammaticScryptoSborValue = {\n    kind: 'Enum',\n    variant_id: '1',\n    variant_name: 'Some',\n    fields: [\n        {\n            kind: 'Tuple',\n            fields: [\n                {\n                    kind: 'Bool',\n                    value: true,\n                },\n            ],\n        },\n    ],\n};\n\nconst schema = s.option(s.bool());\n\nconst result = schema.safeParse(example);\n\nif (result.isOk()) {\n    console.log(result.value);\n}\n\n// { variant: 'Some', value: true }\n```\n","readmeFilename":"README.md"}