@fireproof/vendor 0.0.0-smoke
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +29 -0
- package/patched/@ipld/dag-json/.github/dependabot.yml +11 -0
- package/patched/@ipld/dag-json/.github/workflows/js-test-and-release.yml +28 -0
- package/patched/@ipld/dag-json/CHANGELOG.md +202 -0
- package/patched/@ipld/dag-json/LICENSE +4 -0
- package/patched/@ipld/dag-json/LICENSE-APACHE +5 -0
- package/patched/@ipld/dag-json/LICENSE-MIT +19 -0
- package/patched/@ipld/dag-json/README.md +58 -0
- package/patched/@ipld/dag-json/ipld-dag-json-10.2.3.tgz +0 -0
- package/patched/@ipld/dag-json/package.json +173 -0
- package/patched/@ipld/dag-json/src/index.js +291 -0
- package/patched/@ipld/dag-json/test/test-basics.spec.js +290 -0
- package/patched/@ipld/dag-json/test/ts-use/package.json +11 -0
- package/patched/@ipld/dag-json/test/ts-use/src/main.ts +54 -0
- package/patched/@ipld/dag-json/test/ts-use/tsconfig.json +9 -0
- package/patched/@ipld/dag-json/tsconfig.json +14 -0
- package/patched/cborg/.github/dependabot.yml +16 -0
- package/patched/cborg/.github/workflows/test-and-release.yml +52 -0
- package/patched/cborg/CHANGELOG.md +513 -0
- package/patched/cborg/LICENSE +13 -0
- package/patched/cborg/README.md +515 -0
- package/patched/cborg/bench/bench.js +117 -0
- package/patched/cborg/bench/json.js +124 -0
- package/patched/cborg/bench/package.json +8 -0
- package/patched/cborg/cborg-4.2.7.tgz +0 -0
- package/patched/cborg/cborg.js +31 -0
- package/patched/cborg/example-bytestrings.js +180 -0
- package/patched/cborg/example-json.js +6 -0
- package/patched/cborg/example.js +5 -0
- package/patched/cborg/interface.ts +56 -0
- package/patched/cborg/lib/0uint.js +227 -0
- package/patched/cborg/lib/1negint.js +111 -0
- package/patched/cborg/lib/2bytes.js +133 -0
- package/patched/cborg/lib/3string.js +90 -0
- package/patched/cborg/lib/4array.js +113 -0
- package/patched/cborg/lib/5map.js +113 -0
- package/patched/cborg/lib/6tag.js +80 -0
- package/patched/cborg/lib/7float.js +308 -0
- package/patched/cborg/lib/bin.js +189 -0
- package/patched/cborg/lib/bl.js +124 -0
- package/patched/cborg/lib/byte-utils.js +417 -0
- package/patched/cborg/lib/common.js +27 -0
- package/patched/cborg/lib/decode.js +209 -0
- package/patched/cborg/lib/diagnostic.js +156 -0
- package/patched/cborg/lib/diagnostic_test.js +117 -0
- package/patched/cborg/lib/encode.js +464 -0
- package/patched/cborg/lib/is.js +106 -0
- package/patched/cborg/lib/json/decode.js +462 -0
- package/patched/cborg/lib/json/encode.js +299 -0
- package/patched/cborg/lib/json/json.js +4 -0
- package/patched/cborg/lib/jump.js +209 -0
- package/patched/cborg/lib/length.js +61 -0
- package/patched/cborg/lib/token.js +76 -0
- package/patched/cborg/package.json +169 -0
- package/patched/cborg/pnpm-lock.yaml +6096 -0
- package/patched/cborg/taglib.js +73 -0
- package/patched/cborg/test/appendix_a.js +647 -0
- package/patched/cborg/test/common.js +18 -0
- package/patched/cborg/test/node-test-bin.js +402 -0
- package/patched/cborg/test/noop-bin-test.js +3 -0
- package/patched/cborg/test/test-0uint.js +103 -0
- package/patched/cborg/test/test-1negint.js +96 -0
- package/patched/cborg/test/test-2bytes.js +198 -0
- package/patched/cborg/test/test-3string.js +136 -0
- package/patched/cborg/test/test-4array.js +93 -0
- package/patched/cborg/test/test-5map.js +284 -0
- package/patched/cborg/test/test-6tag.js +85 -0
- package/patched/cborg/test/test-7float.js +131 -0
- package/patched/cborg/test/test-bl.js +37 -0
- package/patched/cborg/test/test-cbor-vectors.js +107 -0
- package/patched/cborg/test/test-decode-errors.js +65 -0
- package/patched/cborg/test/test-fuzz.js +42 -0
- package/patched/cborg/test/test-json.js +219 -0
- package/patched/cborg/test/test-length.js +65 -0
- package/patched/cborg/test/test-partial.js +111 -0
- package/patched/cborg/tsconfig.json +45 -0
- package/patched/cborg/types/cborg.d.ts +28 -0
- package/patched/cborg/types/cborg.d.ts.map +1 -0
- package/patched/cborg/types/example.d.ts +2 -0
- package/patched/cborg/types/example.d.ts.map +1 -0
- package/patched/cborg/types/interface.d.ts +47 -0
- package/patched/cborg/types/interface.d.ts.map +1 -0
- package/patched/cborg/types/lib/0uint.d.ts +100 -0
- package/patched/cborg/types/lib/0uint.d.ts.map +1 -0
- package/patched/cborg/types/lib/1negint.d.ts +58 -0
- package/patched/cborg/types/lib/1negint.d.ts.map +1 -0
- package/patched/cborg/types/lib/2bytes.d.ts +68 -0
- package/patched/cborg/types/lib/2bytes.d.ts.map +1 -0
- package/patched/cborg/types/lib/3string.d.ts +46 -0
- package/patched/cborg/types/lib/3string.d.ts.map +1 -0
- package/patched/cborg/types/lib/4array.d.ts +65 -0
- package/patched/cborg/types/lib/4array.d.ts.map +1 -0
- package/patched/cborg/types/lib/5map.d.ts +65 -0
- package/patched/cborg/types/lib/5map.d.ts.map +1 -0
- package/patched/cborg/types/lib/6tag.d.ts +61 -0
- package/patched/cborg/types/lib/6tag.d.ts.map +1 -0
- package/patched/cborg/types/lib/7float.d.ts +60 -0
- package/patched/cborg/types/lib/7float.d.ts.map +1 -0
- package/patched/cborg/types/lib/bin.d.ts +4 -0
- package/patched/cborg/types/lib/bin.d.ts.map +1 -0
- package/patched/cborg/types/lib/bl.d.ts +26 -0
- package/patched/cborg/types/lib/bl.d.ts.map +1 -0
- package/patched/cborg/types/lib/byte-utils.d.ts +53 -0
- package/patched/cborg/types/lib/byte-utils.d.ts.map +1 -0
- package/patched/cborg/types/lib/common.d.ts +10 -0
- package/patched/cborg/types/lib/common.d.ts.map +1 -0
- package/patched/cborg/types/lib/decode.d.ts +41 -0
- package/patched/cborg/types/lib/decode.d.ts.map +1 -0
- package/patched/cborg/types/lib/diagnostic.d.ts +12 -0
- package/patched/cborg/types/lib/diagnostic.d.ts.map +1 -0
- package/patched/cborg/types/lib/diagnostic_test.d.ts +2 -0
- package/patched/cborg/types/lib/diagnostic_test.d.ts.map +1 -0
- package/patched/cborg/types/lib/encode.d.ts +50 -0
- package/patched/cborg/types/lib/encode.d.ts.map +1 -0
- package/patched/cborg/types/lib/is.d.ts +6 -0
- package/patched/cborg/types/lib/is.d.ts.map +1 -0
- package/patched/cborg/types/lib/json/decode.d.ts +67 -0
- package/patched/cborg/types/lib/json/decode.d.ts.map +1 -0
- package/patched/cborg/types/lib/json/encode.d.ts +11 -0
- package/patched/cborg/types/lib/json/encode.d.ts.map +1 -0
- package/patched/cborg/types/lib/json/forward-cborg.d.ts +6 -0
- package/patched/cborg/types/lib/json/forward-cborg.d.ts.map +1 -0
- package/patched/cborg/types/lib/json/json.d.ts +6 -0
- package/patched/cborg/types/lib/json/json.d.ts.map +1 -0
- package/patched/cborg/types/lib/jump.d.ts +12 -0
- package/patched/cborg/types/lib/jump.d.ts.map +1 -0
- package/patched/cborg/types/lib/length.d.ts +27 -0
- package/patched/cborg/types/lib/length.d.ts.map +1 -0
- package/patched/cborg/types/lib/token.d.ts +59 -0
- package/patched/cborg/types/lib/token.d.ts.map +1 -0
- package/patched/cborg/types/taglib.d.ts +18 -0
- package/patched/cborg/types/taglib.d.ts.map +1 -0
- package/patched/cborg/types/tsconfig.tsbuildinfo +1 -0
- package/src/@ipld/car/car/LICENSE +4 -0
- package/src/@ipld/car/car/README.md +1078 -0
- package/src/@ipld/car/car/dist/index.min.js +5 -0
- package/src/@ipld/car/car/dist/src/api.d.ts +72 -0
- package/src/@ipld/car/car/dist/src/api.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/buffer-decoder.d.ts +67 -0
- package/src/@ipld/car/car/dist/src/buffer-decoder.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/buffer-reader-browser.d.ts +116 -0
- package/src/@ipld/car/car/dist/src/buffer-reader-browser.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/buffer-reader.d.ts +31 -0
- package/src/@ipld/car/car/dist/src/buffer-reader.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/buffer-writer.d.ts +86 -0
- package/src/@ipld/car/car/dist/src/buffer-writer.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/coding.d.ts +49 -0
- package/src/@ipld/car/car/dist/src/coding.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/decoder-common.d.ts +43 -0
- package/src/@ipld/car/car/dist/src/decoder-common.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/decoder.d.ts +87 -0
- package/src/@ipld/car/car/dist/src/decoder.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/encoder.d.ts +17 -0
- package/src/@ipld/car/car/dist/src/encoder.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/header-validator.d.ts +5 -0
- package/src/@ipld/car/car/dist/src/header-validator.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/index-browser.d.ts +10 -0
- package/src/@ipld/car/car/dist/src/index-browser.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/index.d.ts +11 -0
- package/src/@ipld/car/car/dist/src/index.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/indexed-reader-browser.d.ts +5 -0
- package/src/@ipld/car/car/dist/src/indexed-reader-browser.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/indexed-reader.d.ts +152 -0
- package/src/@ipld/car/car/dist/src/indexed-reader.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/indexer.d.ts +95 -0
- package/src/@ipld/car/car/dist/src/indexer.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/iterator-channel.d.ts +7 -0
- package/src/@ipld/car/car/dist/src/iterator-channel.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/iterator.d.ts +174 -0
- package/src/@ipld/car/car/dist/src/iterator.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/reader-browser.d.ts +151 -0
- package/src/@ipld/car/car/dist/src/reader-browser.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/reader.d.ts +35 -0
- package/src/@ipld/car/car/dist/src/reader.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/writer-browser.d.ts +155 -0
- package/src/@ipld/car/car/dist/src/writer-browser.d.ts.map +1 -0
- package/src/@ipld/car/car/dist/src/writer.d.ts +45 -0
- package/src/@ipld/car/car/dist/src/writer.d.ts.map +1 -0
- package/src/@ipld/car/car/node_modules/.bin/cborg +17 -0
- package/src/@ipld/car/car/package.json +235 -0
- package/src/@ipld/car/car/src/api.ts +90 -0
- package/src/@ipld/car/car/src/buffer-decoder.js +213 -0
- package/src/@ipld/car/car/src/buffer-reader-browser.js +144 -0
- package/src/@ipld/car/car/src/buffer-reader.js +51 -0
- package/src/@ipld/car/car/src/buffer-writer.js +286 -0
- package/src/@ipld/car/car/src/coding.ts +68 -0
- package/src/@ipld/car/car/src/decoder-common.js +82 -0
- package/src/@ipld/car/car/src/decoder.js +347 -0
- package/src/@ipld/car/car/src/encoder.js +76 -0
- package/src/@ipld/car/car/src/header-validator.js +214 -0
- package/src/@ipld/car/car/src/header.ipldsch +18 -0
- package/src/@ipld/car/car/src/index-browser.js +18 -0
- package/src/@ipld/car/car/src/index.js +21 -0
- package/src/@ipld/car/car/src/indexed-reader-browser.js +7 -0
- package/src/@ipld/car/car/src/indexed-reader.js +211 -0
- package/src/@ipld/car/car/src/indexer.js +130 -0
- package/src/@ipld/car/car/src/iterator-channel.js +91 -0
- package/src/@ipld/car/car/src/iterator.js +267 -0
- package/src/@ipld/car/car/src/reader-browser.js +194 -0
- package/src/@ipld/car/car/src/reader.js +56 -0
- package/src/@ipld/car/car/src/writer-browser.js +250 -0
- package/src/@ipld/car/car/src/writer.js +84 -0
- package/src/@ipld/dag-cbor/dag-cbor/LICENSE +4 -0
- package/src/@ipld/dag-cbor/dag-cbor/README.md +80 -0
- package/src/@ipld/dag-cbor/dag-cbor/dist/index.min.js +3 -0
- package/src/@ipld/dag-cbor/dag-cbor/dist/src/index.d.ts +67 -0
- package/src/@ipld/dag-cbor/dag-cbor/dist/src/index.d.ts.map +1 -0
- package/src/@ipld/dag-cbor/dag-cbor/node_modules/.bin/cborg +17 -0
- package/src/@ipld/dag-cbor/dag-cbor/package.json +171 -0
- package/src/@ipld/dag-cbor/dag-cbor/src/index.js +147 -0
- package/src/@ipld/dag-json/dag-json/LICENSE +4 -0
- package/src/@ipld/dag-json/dag-json/README.md +58 -0
- package/src/@ipld/dag-json/dag-json/dist/index.min.js +3 -0
- package/src/@ipld/dag-json/dag-json/dist/src/index.d.ts +12 -0
- package/src/@ipld/dag-json/dag-json/dist/src/index.d.ts.map +1 -0
- package/src/@ipld/dag-json/dag-json/node_modules/.bin/cborg +17 -0
- package/src/@ipld/dag-json/dag-json/package.json +173 -0
- package/src/@ipld/dag-json/dag-json/src/index.js +291 -0
- package/src/@web3-storage/pail/pail/LICENSE.md +232 -0
- package/src/@web3-storage/pail/pail/README.md +84 -0
- package/src/@web3-storage/pail/pail/cli.js +218 -0
- package/src/@web3-storage/pail/pail/dist/src/api.d.ts +59 -0
- package/src/@web3-storage/pail/pail/dist/src/api.d.ts.map +1 -0
- package/src/@web3-storage/pail/pail/dist/src/batch/api.d.ts +31 -0
- package/src/@web3-storage/pail/pail/dist/src/batch/api.d.ts.map +1 -0
- package/src/@web3-storage/pail/pail/dist/src/batch/index.d.ts +75 -0
- package/src/@web3-storage/pail/pail/dist/src/batch/index.d.ts.map +1 -0
- package/src/@web3-storage/pail/pail/dist/src/batch/shard.d.ts +3 -0
- package/src/@web3-storage/pail/pail/dist/src/batch/shard.d.ts.map +1 -0
- package/src/@web3-storage/pail/pail/dist/src/block.d.ts +35 -0
- package/src/@web3-storage/pail/pail/dist/src/block.d.ts.map +1 -0
- package/src/@web3-storage/pail/pail/dist/src/clock/api.d.ts +10 -0
- package/src/@web3-storage/pail/pail/dist/src/clock/api.d.ts.map +1 -0
- package/src/@web3-storage/pail/pail/dist/src/clock/index.d.ts +48 -0
- package/src/@web3-storage/pail/pail/dist/src/clock/index.d.ts.map +1 -0
- package/src/@web3-storage/pail/pail/dist/src/crdt/api.d.ts +26 -0
- package/src/@web3-storage/pail/pail/dist/src/crdt/api.d.ts.map +1 -0
- package/src/@web3-storage/pail/pail/dist/src/crdt/batch/api.d.ts +11 -0
- package/src/@web3-storage/pail/pail/dist/src/crdt/batch/api.d.ts.map +1 -0
- package/src/@web3-storage/pail/pail/dist/src/crdt/batch/index.d.ts +5 -0
- package/src/@web3-storage/pail/pail/dist/src/crdt/batch/index.d.ts.map +1 -0
- package/src/@web3-storage/pail/pail/dist/src/crdt/index.d.ts +9 -0
- package/src/@web3-storage/pail/pail/dist/src/crdt/index.d.ts.map +1 -0
- package/src/@web3-storage/pail/pail/dist/src/diff.d.ts +13 -0
- package/src/@web3-storage/pail/pail/dist/src/diff.d.ts.map +1 -0
- package/src/@web3-storage/pail/pail/dist/src/index.d.ts +10 -0
- package/src/@web3-storage/pail/pail/dist/src/index.d.ts.map +1 -0
- package/src/@web3-storage/pail/pail/dist/src/merge.d.ts +5 -0
- package/src/@web3-storage/pail/pail/dist/src/merge.d.ts.map +1 -0
- package/src/@web3-storage/pail/pail/dist/src/shard.d.ts +43 -0
- package/src/@web3-storage/pail/pail/dist/src/shard.d.ts.map +1 -0
- package/src/@web3-storage/pail/pail/dist/tsconfig.tsbuildinfo +1 -0
- package/src/@web3-storage/pail/pail/node_modules/.bin/pail +17 -0
- package/src/@web3-storage/pail/pail/package.json +173 -0
- package/src/@web3-storage/pail/pail/src/api.js +1 -0
- package/src/@web3-storage/pail/pail/src/api.ts +90 -0
- package/src/@web3-storage/pail/pail/src/batch/api.js +1 -0
- package/src/@web3-storage/pail/pail/src/batch/api.ts +59 -0
- package/src/@web3-storage/pail/pail/src/batch/index.js +258 -0
- package/src/@web3-storage/pail/pail/src/batch/shard.js +13 -0
- package/src/@web3-storage/pail/pail/src/block.js +75 -0
- package/src/@web3-storage/pail/pail/src/clock/api.js +1 -0
- package/src/@web3-storage/pail/pail/src/clock/api.ts +12 -0
- package/src/@web3-storage/pail/pail/src/clock/index.js +182 -0
- package/src/@web3-storage/pail/pail/src/crdt/api.js +1 -0
- package/src/@web3-storage/pail/pail/src/crdt/api.ts +33 -0
- package/src/@web3-storage/pail/pail/src/crdt/batch/api.js +1 -0
- package/src/@web3-storage/pail/pail/src/crdt/batch/api.ts +30 -0
- package/src/@web3-storage/pail/pail/src/crdt/batch/index.js +155 -0
- package/src/@web3-storage/pail/pail/src/crdt/index.js +354 -0
- package/src/@web3-storage/pail/pail/src/diff.js +151 -0
- package/src/@web3-storage/pail/pail/src/index.js +406 -0
- package/src/@web3-storage/pail/pail/src/merge.js +43 -0
- package/src/@web3-storage/pail/pail/src/shard.js +180 -0
- package/src/cborg/cborg/.github/dependabot.yml +16 -0
- package/src/cborg/cborg/.github/workflows/test-and-release.yml +52 -0
- package/src/cborg/cborg/CHANGELOG.md +513 -0
- package/src/cborg/cborg/LICENSE +13 -0
- package/src/cborg/cborg/README.md +515 -0
- package/src/cborg/cborg/bench/bench.js +117 -0
- package/src/cborg/cborg/bench/json.js +124 -0
- package/src/cborg/cborg/bench/package.json +8 -0
- package/src/cborg/cborg/cborg.js +31 -0
- package/src/cborg/cborg/example-bytestrings.js +180 -0
- package/src/cborg/cborg/example-json.js +6 -0
- package/src/cborg/cborg/example.js +5 -0
- package/src/cborg/cborg/interface.ts +56 -0
- package/src/cborg/cborg/lib/0uint.js +227 -0
- package/src/cborg/cborg/lib/1negint.js +111 -0
- package/src/cborg/cborg/lib/2bytes.js +133 -0
- package/src/cborg/cborg/lib/3string.js +90 -0
- package/src/cborg/cborg/lib/4array.js +113 -0
- package/src/cborg/cborg/lib/5map.js +113 -0
- package/src/cborg/cborg/lib/6tag.js +80 -0
- package/src/cborg/cborg/lib/7float.js +308 -0
- package/src/cborg/cborg/lib/bin.js +189 -0
- package/src/cborg/cborg/lib/bl.js +124 -0
- package/src/cborg/cborg/lib/byte-utils.js +417 -0
- package/src/cborg/cborg/lib/common.js +27 -0
- package/src/cborg/cborg/lib/decode.js +209 -0
- package/src/cborg/cborg/lib/diagnostic.js +156 -0
- package/src/cborg/cborg/lib/diagnostic_test.js +117 -0
- package/src/cborg/cborg/lib/encode.js +464 -0
- package/src/cborg/cborg/lib/is.js +106 -0
- package/src/cborg/cborg/lib/json/decode.js +462 -0
- package/src/cborg/cborg/lib/json/encode.js +299 -0
- package/src/cborg/cborg/lib/json/json.js +4 -0
- package/src/cborg/cborg/lib/jump.js +209 -0
- package/src/cborg/cborg/lib/length.js +61 -0
- package/src/cborg/cborg/lib/token.js +76 -0
- package/src/cborg/cborg/node_modules/.bin/cborg +17 -0
- package/src/cborg/cborg/package.json +168 -0
- package/src/cborg/cborg/taglib.js +73 -0
- package/src/cborg/cborg/test/appendix_a.js +647 -0
- package/src/cborg/cborg/test/common.js +18 -0
- package/src/cborg/cborg/test/node-test-bin.js +402 -0
- package/src/cborg/cborg/test/noop-bin-test.js +3 -0
- package/src/cborg/cborg/test/test-0uint.js +103 -0
- package/src/cborg/cborg/test/test-1negint.js +96 -0
- package/src/cborg/cborg/test/test-2bytes.js +198 -0
- package/src/cborg/cborg/test/test-3string.js +136 -0
- package/src/cborg/cborg/test/test-4array.js +93 -0
- package/src/cborg/cborg/test/test-5map.js +284 -0
- package/src/cborg/cborg/test/test-6tag.js +85 -0
- package/src/cborg/cborg/test/test-7float.js +131 -0
- package/src/cborg/cborg/test/test-bl.js +37 -0
- package/src/cborg/cborg/test/test-cbor-vectors.js +107 -0
- package/src/cborg/cborg/test/test-decode-errors.js +65 -0
- package/src/cborg/cborg/test/test-fuzz.js +42 -0
- package/src/cborg/cborg/test/test-json.js +219 -0
- package/src/cborg/cborg/test/test-length.js +65 -0
- package/src/cborg/cborg/test/test-partial.js +111 -0
- package/src/cborg/cborg/tsconfig.json +45 -0
- package/src/cborg/cborg/types/cborg.d.ts +28 -0
- package/src/cborg/cborg/types/cborg.d.ts.map +1 -0
- package/src/cborg/cborg/types/example.d.ts +2 -0
- package/src/cborg/cborg/types/example.d.ts.map +1 -0
- package/src/cborg/cborg/types/interface.d.ts +47 -0
- package/src/cborg/cborg/types/interface.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/0uint.d.ts +100 -0
- package/src/cborg/cborg/types/lib/0uint.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/1negint.d.ts +58 -0
- package/src/cborg/cborg/types/lib/1negint.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/2bytes.d.ts +68 -0
- package/src/cborg/cborg/types/lib/2bytes.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/3string.d.ts +46 -0
- package/src/cborg/cborg/types/lib/3string.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/4array.d.ts +65 -0
- package/src/cborg/cborg/types/lib/4array.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/5map.d.ts +65 -0
- package/src/cborg/cborg/types/lib/5map.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/6tag.d.ts +61 -0
- package/src/cborg/cborg/types/lib/6tag.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/7float.d.ts +60 -0
- package/src/cborg/cborg/types/lib/7float.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/bin.d.ts +4 -0
- package/src/cborg/cborg/types/lib/bin.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/bl.d.ts +26 -0
- package/src/cborg/cborg/types/lib/bl.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/byte-utils.d.ts +53 -0
- package/src/cborg/cborg/types/lib/byte-utils.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/common.d.ts +10 -0
- package/src/cborg/cborg/types/lib/common.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/decode.d.ts +41 -0
- package/src/cborg/cborg/types/lib/decode.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/diagnostic.d.ts +12 -0
- package/src/cborg/cborg/types/lib/diagnostic.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/diagnostic_test.d.ts +2 -0
- package/src/cborg/cborg/types/lib/diagnostic_test.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/encode.d.ts +50 -0
- package/src/cborg/cborg/types/lib/encode.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/is.d.ts +6 -0
- package/src/cborg/cborg/types/lib/is.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/json/decode.d.ts +67 -0
- package/src/cborg/cborg/types/lib/json/decode.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/json/encode.d.ts +11 -0
- package/src/cborg/cborg/types/lib/json/encode.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/json/forward-cborg.d.ts +6 -0
- package/src/cborg/cborg/types/lib/json/forward-cborg.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/json/json.d.ts +6 -0
- package/src/cborg/cborg/types/lib/json/json.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/jump.d.ts +12 -0
- package/src/cborg/cborg/types/lib/jump.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/length.d.ts +27 -0
- package/src/cborg/cborg/types/lib/length.d.ts.map +1 -0
- package/src/cborg/cborg/types/lib/token.d.ts +59 -0
- package/src/cborg/cborg/types/lib/token.d.ts.map +1 -0
- package/src/cborg/cborg/types/taglib.d.ts +18 -0
- package/src/cborg/cborg/types/taglib.d.ts.map +1 -0
- package/src/cborg/cborg/types/tsconfig.tsbuildinfo +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/LICENSE +4 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/README.md +105 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/index.min.js +3 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/errors.d.ts +57 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/errors.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/errors.js +73 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/errors.js.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/index.d.ts +355 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/index.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/index.js +197 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/index.js.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/dag-cbor.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/dag-cbor.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/dag-cbor.js +9 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/dag-cbor.js.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/dag-json.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/dag-json.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/dag-json.js +9 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/dag-json.js.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/identity.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/identity.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/identity.js +38 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/identity.js.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/index.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/index.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/index.js +30 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/index.js.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/json.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/json.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/json.js +9 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/json.js.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/raw.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/raw.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/raw.js +37 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/raw.js.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/directory.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/directory.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/directory.js +29 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/directory.js.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/file.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/file.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/file.js +153 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/file.js.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/hamt-sharded-directory.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/hamt-sharded-directory.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/hamt-sharded-directory.js +59 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/hamt-sharded-directory.js.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/raw.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/raw.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/raw.js +25 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/raw.js.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/index.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/index.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/index.js +104 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/index.js.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/extract-data-from-block.d.ts +3 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/extract-data-from-block.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/extract-data-from-block.js +20 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/extract-data-from-block.js.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/find-cid-in-shard.d.ts +6 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/find-cid-in-shard.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/find-cid-in-shard.js +116 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/find-cid-in-shard.js.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/resolve-object-path.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/resolve-object-path.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/resolve-object-path.js +57 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/resolve-object-path.js.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/validate-offset-and-length.d.ts +6 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/validate-offset-and-length.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/validate-offset-and-length.js +30 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/src/utils/validate-offset-and-length.js.map +1 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/dist/typedoc-urls.json +58 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/package.json +180 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/errors.ts +87 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/index.ts +498 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/resolvers/dag-cbor.ts +12 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/resolvers/dag-json.ts +12 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/resolvers/identity.ts +49 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/resolvers/index.ts +35 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/resolvers/json.ts +12 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/resolvers/raw.ts +49 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/directory.ts +39 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/file.ts +198 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.ts +76 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/raw.ts +37 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/index.ts +121 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/utils/extract-data-from-block.ts +24 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/utils/find-cid-in-shard.ts +149 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/utils/resolve-object-path.ts +62 -0
- package/src/ipfs-unixfs-exporter/ipfs-unixfs-exporter/src/utils/validate-offset-and-length.ts +38 -0
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
/* eslint max-depth: ["error", 7] */
|
|
2
|
+
import { Token, Type } from 'cborg'
|
|
3
|
+
import * as cborgJson from 'cborg/json'
|
|
4
|
+
import { CID } from 'multiformats'
|
|
5
|
+
import { base64 } from 'multiformats/bases/base64'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @template T
|
|
9
|
+
* @typedef {import('multiformats/codecs/interface').ByteView<T>} ByteView
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* @template T
|
|
13
|
+
* @typedef {import('multiformats/codecs/interface').ArrayBufferView<T>} ArrayBufferView
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* @template T
|
|
17
|
+
* @typedef {import('multiformats').ToString<T>} ToString
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* @typedef {import('cborg/interface').DecodeTokenizer} DecodeTokenizer
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @template T
|
|
25
|
+
* @param {ByteView<T> | ArrayBufferView<T>} buf
|
|
26
|
+
* @returns {ByteView<T>}
|
|
27
|
+
*/
|
|
28
|
+
function toByteView (buf) {
|
|
29
|
+
if (buf instanceof ArrayBuffer) {
|
|
30
|
+
return new Uint8Array(buf, 0, buf.byteLength)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return buf
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* cidEncoder will receive all Objects during encode, it needs to filter out
|
|
38
|
+
* anything that's not a CID and return `null` for that so it's encoded as
|
|
39
|
+
* normal. Encoding a CID means replacing it with a `{"/":"<CidString>}`
|
|
40
|
+
* object as per the DAG-JSON spec.
|
|
41
|
+
*
|
|
42
|
+
* @param {any} obj
|
|
43
|
+
* @returns {Token[]|null}
|
|
44
|
+
*/
|
|
45
|
+
function cidEncoder (obj) {
|
|
46
|
+
if (obj.asCID !== obj && obj['/'] !== obj.bytes) {
|
|
47
|
+
return null // any other kind of object
|
|
48
|
+
}
|
|
49
|
+
const cid = CID.asCID(obj)
|
|
50
|
+
/* c8 ignore next 4 */
|
|
51
|
+
// very unlikely case, and it'll probably throw a recursion error in cborg
|
|
52
|
+
if (!cid) {
|
|
53
|
+
return null
|
|
54
|
+
}
|
|
55
|
+
const cidString = cid.toString()
|
|
56
|
+
|
|
57
|
+
return [
|
|
58
|
+
new Token(Type.map, Infinity, 1),
|
|
59
|
+
new Token(Type.string, '/', 1), // key
|
|
60
|
+
new Token(Type.string, cidString, cidString.length), // value
|
|
61
|
+
new Token(Type.break, undefined, 1)
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* bytesEncoder will receive all Uint8Arrays (and friends) during encode, it
|
|
67
|
+
* needs to replace it with a `{"/":{"bytes":"Base64ByteString"}}` object as
|
|
68
|
+
* per the DAG-JSON spec.
|
|
69
|
+
*
|
|
70
|
+
* @param {Uint8Array} bytes
|
|
71
|
+
* @returns {Token[]|null}
|
|
72
|
+
*/
|
|
73
|
+
function bytesEncoder (bytes) {
|
|
74
|
+
const bytesString = base64.encode(bytes).slice(1) // no mbase prefix
|
|
75
|
+
return [
|
|
76
|
+
new Token(Type.map, Infinity, 1),
|
|
77
|
+
new Token(Type.string, '/', 1), // key
|
|
78
|
+
new Token(Type.map, Infinity, 1), // value
|
|
79
|
+
new Token(Type.string, 'bytes', 5), // inner key
|
|
80
|
+
new Token(Type.string, bytesString, bytesString.length), // inner value
|
|
81
|
+
new Token(Type.break, undefined, 1),
|
|
82
|
+
new Token(Type.break, undefined, 1)
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* taBytesEncoder wraps bytesEncoder() but for the more exotic typed arrays so
|
|
88
|
+
* that we access the underlying ArrayBuffer data
|
|
89
|
+
*
|
|
90
|
+
* @param {Int8Array|Uint16Array|Int16Array|Uint32Array|Int32Array|Float32Array|Float64Array|Uint8ClampedArray|BigInt64Array|BigUint64Array} obj
|
|
91
|
+
* @returns {Token[]|null}
|
|
92
|
+
*/
|
|
93
|
+
function taBytesEncoder (obj) {
|
|
94
|
+
return bytesEncoder(new Uint8Array(obj.buffer, obj.byteOffset, obj.byteLength))
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* abBytesEncoder wraps bytesEncoder() but for plain ArrayBuffers
|
|
99
|
+
*
|
|
100
|
+
* @param {ArrayBuffer} ab
|
|
101
|
+
* @returns {Token[]|null}
|
|
102
|
+
*/
|
|
103
|
+
function abBytesEncoder (ab) {
|
|
104
|
+
return bytesEncoder(new Uint8Array(ab))
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// eslint-disable-next-line jsdoc/require-returns-check
|
|
108
|
+
/**
|
|
109
|
+
* Intercept all `undefined` values from an object walk and reject the entire
|
|
110
|
+
* object if we find one.
|
|
111
|
+
*
|
|
112
|
+
* @returns {null}
|
|
113
|
+
*/
|
|
114
|
+
function undefinedEncoder () {
|
|
115
|
+
throw new Error('`undefined` is not supported by the IPLD Data Model and cannot be encoded')
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Intercept all `number` values from an object walk and reject the entire
|
|
120
|
+
* object if we find something that doesn't fit the IPLD data model (NaN &
|
|
121
|
+
* Infinity).
|
|
122
|
+
*
|
|
123
|
+
* @param {number} num
|
|
124
|
+
* @returns {null}
|
|
125
|
+
*/
|
|
126
|
+
function numberEncoder (num) {
|
|
127
|
+
if (Number.isNaN(num)) {
|
|
128
|
+
throw new Error('`NaN` is not supported by the IPLD Data Model and cannot be encoded')
|
|
129
|
+
}
|
|
130
|
+
if (num === Infinity || num === -Infinity) {
|
|
131
|
+
throw new Error('`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded')
|
|
132
|
+
}
|
|
133
|
+
return null // process with standard number encoder
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const encodeOptions = {
|
|
137
|
+
typeEncoders: {
|
|
138
|
+
Object: cidEncoder,
|
|
139
|
+
Buffer: bytesEncoder,
|
|
140
|
+
Uint8Array: bytesEncoder,
|
|
141
|
+
Int8Array: taBytesEncoder,
|
|
142
|
+
Uint16Array: taBytesEncoder,
|
|
143
|
+
Int16Array: taBytesEncoder,
|
|
144
|
+
Uint32Array: taBytesEncoder,
|
|
145
|
+
Int32Array: taBytesEncoder,
|
|
146
|
+
Float32Array: taBytesEncoder,
|
|
147
|
+
Float64Array: taBytesEncoder,
|
|
148
|
+
Uint8ClampedArray: taBytesEncoder,
|
|
149
|
+
BigInt64Array: taBytesEncoder,
|
|
150
|
+
BigUint64Array: taBytesEncoder,
|
|
151
|
+
DataView: taBytesEncoder,
|
|
152
|
+
ArrayBuffer: abBytesEncoder,
|
|
153
|
+
undefined: undefinedEncoder,
|
|
154
|
+
number: numberEncoder
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* @implements {DecodeTokenizer}
|
|
160
|
+
*/
|
|
161
|
+
class DagJsonTokenizer extends cborgJson.Tokenizer {
|
|
162
|
+
/**
|
|
163
|
+
* @param {Uint8Array} data
|
|
164
|
+
* @param {object} [options]
|
|
165
|
+
*/
|
|
166
|
+
constructor (data, options) {
|
|
167
|
+
super(data, options)
|
|
168
|
+
/** @type {Token[]} */
|
|
169
|
+
this.tokenBuffer = []
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* @returns {boolean}
|
|
174
|
+
*/
|
|
175
|
+
done () {
|
|
176
|
+
return this.tokenBuffer.length === 0 && super.done()
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* @returns {Token}
|
|
181
|
+
*/
|
|
182
|
+
_next () {
|
|
183
|
+
if (this.tokenBuffer.length > 0) {
|
|
184
|
+
// @ts-ignore https://github.com/Microsoft/TypeScript/issues/30406
|
|
185
|
+
return this.tokenBuffer.pop()
|
|
186
|
+
}
|
|
187
|
+
return super.next()
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Implements rules outlined in https://github.com/ipld/specs/pull/356
|
|
192
|
+
*
|
|
193
|
+
* @returns {Token}
|
|
194
|
+
*/
|
|
195
|
+
next () {
|
|
196
|
+
const token = this._next()
|
|
197
|
+
|
|
198
|
+
if (token.type.compare(Type.map) === 0) {
|
|
199
|
+
const keyToken = this._next()
|
|
200
|
+
if (keyToken.type.compare(Type.string) === 0 && keyToken.value === '/') {
|
|
201
|
+
const valueToken = this._next()
|
|
202
|
+
if (valueToken.type.compare(Type.string) === 0) { // *must* be a CID
|
|
203
|
+
const breakToken = this._next() // swallow the end-of-map token
|
|
204
|
+
if (breakToken.type.compare(Type.break)) {
|
|
205
|
+
throw new Error('Invalid encoded CID form')
|
|
206
|
+
}
|
|
207
|
+
this.tokenBuffer.push(valueToken) // CID.parse will pick this up after our tag token
|
|
208
|
+
return new Token(Type.tag, 42, 0)
|
|
209
|
+
}
|
|
210
|
+
if (valueToken.type.compare(Type.map) === 0) {
|
|
211
|
+
const innerKeyToken = this._next()
|
|
212
|
+
if (innerKeyToken.type.compare(Type.string) === 0 && innerKeyToken.value === 'bytes') {
|
|
213
|
+
const innerValueToken = this._next()
|
|
214
|
+
if (innerValueToken.type.compare(Type.string) === 0) { // *must* be Bytes
|
|
215
|
+
for (let i = 0; i < 2; i++) {
|
|
216
|
+
const breakToken = this._next() // swallow two end-of-map tokens
|
|
217
|
+
if (breakToken.type.compare(Type.break)) {
|
|
218
|
+
throw new Error('Invalid encoded Bytes form')
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
const bytes = base64.decode(`m${innerValueToken.value}`)
|
|
222
|
+
return new Token(Type.bytes, bytes, innerValueToken.value.length)
|
|
223
|
+
}
|
|
224
|
+
this.tokenBuffer.push(innerValueToken) // bail
|
|
225
|
+
}
|
|
226
|
+
this.tokenBuffer.push(innerKeyToken) // bail
|
|
227
|
+
}
|
|
228
|
+
this.tokenBuffer.push(valueToken) // bail
|
|
229
|
+
}
|
|
230
|
+
this.tokenBuffer.push(keyToken) // bail
|
|
231
|
+
}
|
|
232
|
+
return token
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const decodeOptions = {
|
|
237
|
+
allowIndefinite: false,
|
|
238
|
+
allowUndefined: false,
|
|
239
|
+
allowNaN: false,
|
|
240
|
+
allowInfinity: false,
|
|
241
|
+
allowBigInt: true, // this will lead to BigInt for ints outside of
|
|
242
|
+
// safe-integer range, which may surprise users
|
|
243
|
+
strict: true,
|
|
244
|
+
useMaps: false,
|
|
245
|
+
rejectDuplicateMapKeys: true,
|
|
246
|
+
/** @type {import('cborg').TagDecoder[]} */
|
|
247
|
+
tags: []
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// we're going to get TAG(42)STRING("bafy...") from the tokenizer so we only need
|
|
251
|
+
// to deal with the STRING("bafy...") at this point
|
|
252
|
+
decodeOptions.tags[42] = CID.parse
|
|
253
|
+
|
|
254
|
+
export const name = 'dag-json'
|
|
255
|
+
export const code = 0x0129
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* @template T
|
|
259
|
+
* @param {T} node
|
|
260
|
+
* @returns {ByteView<T>}
|
|
261
|
+
*/
|
|
262
|
+
export const encode = (node) => cborgJson.encode(node, encodeOptions)
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* @template T
|
|
266
|
+
* @param {ByteView<T> | ArrayBufferView<T>} data
|
|
267
|
+
* @returns {T}
|
|
268
|
+
*/
|
|
269
|
+
export const decode = (data) => {
|
|
270
|
+
const buf = toByteView(data)
|
|
271
|
+
// the tokenizer is stateful so we need a single instance of it
|
|
272
|
+
const options = Object.assign(decodeOptions, { tokenizer: new DagJsonTokenizer(buf, decodeOptions) })
|
|
273
|
+
return cborgJson.decode(buf, options)
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* @template T
|
|
278
|
+
* @param {T} node
|
|
279
|
+
* @returns {ToString<T>}
|
|
280
|
+
*/
|
|
281
|
+
export const format = (node) => utf8Decoder.decode(encode(node))
|
|
282
|
+
export { format as stringify }
|
|
283
|
+
const utf8Decoder = new TextDecoder()
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* @template T
|
|
287
|
+
* @param {ToString<T>} data
|
|
288
|
+
* @returns {T}
|
|
289
|
+
*/
|
|
290
|
+
export const parse = (data) => decode(utf8Encoder.encode(data))
|
|
291
|
+
const utf8Encoder = new TextEncoder()
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
import { garbage } from '@ipld/garbage'
|
|
3
|
+
import { assert } from 'aegir/chai'
|
|
4
|
+
import { bytes, CID } from 'multiformats'
|
|
5
|
+
import { base64 } from 'multiformats/bases/base64'
|
|
6
|
+
import { encode, decode, stringify, parse } from '../src/index.js'
|
|
7
|
+
|
|
8
|
+
const same = assert.deepStrictEqual
|
|
9
|
+
|
|
10
|
+
const recode = (/** @type {Uint8Array} */ byts) => encode(decode(byts))
|
|
11
|
+
|
|
12
|
+
const link = CID.parse('bafyreifepiu23okq5zuyvyhsoiazv2icw2van3s7ko6d3ixl5jx2yj2yhu')
|
|
13
|
+
|
|
14
|
+
describe('basic dag-json', () => {
|
|
15
|
+
it('encode decode', () => {
|
|
16
|
+
const byts = encode({ hello: 'world' })
|
|
17
|
+
same(JSON.parse(bytes.toString(recode(byts))), { hello: 'world' })
|
|
18
|
+
const o = { link, byts: bytes.fromString('asdf'), n: null, o: {} }
|
|
19
|
+
const byts2 = encode(o)
|
|
20
|
+
same(decode(byts2), o)
|
|
21
|
+
same(bytes.isBinary(decode(byts2).byts), true)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('encode decode 2', () => {
|
|
25
|
+
// mirrors a go-ipld-prime test, but with sorted keys
|
|
26
|
+
const obj = { plain: 'olde string', bytes: utf8Encode('deadbeef') }
|
|
27
|
+
const expected = '{"bytes":{"/":{"bytes":"ZGVhZGJlZWY"}},"plain":"olde string"}'
|
|
28
|
+
const byts = encode(obj)
|
|
29
|
+
same(JSON.parse(bytes.toString(recode(byts))), JSON.parse(expected))
|
|
30
|
+
same(bytes.toString(recode(byts)), expected)
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('encode decode with ArrayBuffer', () => {
|
|
34
|
+
const byts = encode({ hello: 'world' })
|
|
35
|
+
same(JSON.parse(bytes.toString(recode(byts))), { hello: 'world' })
|
|
36
|
+
const o = { link, byts: bytes.fromString('asdf'), n: null, o: {} }
|
|
37
|
+
const byts2 = encode(o)
|
|
38
|
+
same(decode(byts2), o)
|
|
39
|
+
same(bytes.isBinary(decode(byts2).byts.buffer), true)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
describe('reserved space', () => {
|
|
43
|
+
it('allow alternative types', () => {
|
|
44
|
+
// wrong types
|
|
45
|
+
for (const obj of [true, false, null, 1, -1, 1.1, { blip: 'bop' }, ['foo']]) {
|
|
46
|
+
same(decode(encode({ '/': obj })), { '/': obj })
|
|
47
|
+
same(decode(encode({ '/': { bytes: obj } })), { '/': { bytes: obj } })
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('allow specials within reserved space', () => {
|
|
52
|
+
// can we put slash-objects within slashes?
|
|
53
|
+
same(decode(encode({ '/': bytes.fromString('asdf') })), { '/': bytes.fromString('asdf') })
|
|
54
|
+
same(new TextDecoder().decode(encode({ '/': bytes.fromString('asdf') })), '{"/":{"/":{"bytes":"YXNkZg"}}}')
|
|
55
|
+
same(decode(encode({ '/': link })), { '/': link })
|
|
56
|
+
same(new TextDecoder().decode(encode({ '/': link })), '{"/":{"/":"bafyreifepiu23okq5zuyvyhsoiazv2icw2van3s7ko6d3ixl5jx2yj2yhu"}}')
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('disallow extraneous tokens', () => {
|
|
60
|
+
// encode() shouldn't allow this but it currently does
|
|
61
|
+
// https://github.com/ipld/js-dag-json/issues/91 should change this test
|
|
62
|
+
// into two parts, encode and decode
|
|
63
|
+
assert.throws(() => decode(encode({ '/': link.toString(), x: 'bip' })))
|
|
64
|
+
assert.throws(() => decode(encode({ '/': { bytes: 'mS7ldeA', x: 'bip' } })))
|
|
65
|
+
assert.throws(() => decode(encode({ '/': { bytes: 'mS7ldeA' }, x: 'bip' })))
|
|
66
|
+
assert.throws(() => decode(encode({ '/': { bytes: 'mS7ldeA', x: 'bip' }, bop: 'bip' })))
|
|
67
|
+
})
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('native types', () => {
|
|
71
|
+
const flip = (/** @type {any} */ obj) => decode(encode(obj))
|
|
72
|
+
same(flip('test'), 'test')
|
|
73
|
+
same(flip(null), null)
|
|
74
|
+
same(flip(12), 12)
|
|
75
|
+
same(flip(-1), -1)
|
|
76
|
+
same(flip(1.2), 1.2)
|
|
77
|
+
same(flip(true), true)
|
|
78
|
+
same(flip(false), false)
|
|
79
|
+
same(flip([]), [])
|
|
80
|
+
same(flip(['asdf']), ['asdf'])
|
|
81
|
+
same(decode(utf8Encode('10.0')), 10)
|
|
82
|
+
same(decode(utf8Encode('[-10.0, 1.0, 0.0, 100.0]')), [-10, 1, 0, 100])
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('stable map key sorting', () => {
|
|
86
|
+
const s1 = bytes.toString(encode({ a: 1, b: 2, bb: 2.2, c: 3, c_: 3.3 }))
|
|
87
|
+
const s2 = bytes.toString(encode({ c_: 3.3, bb: 2.2, b: 2, c: 3, a: 1 }))
|
|
88
|
+
same('{"a":1,"b":2,"bb":2.2,"c":3,"c_":3.3}', s1)
|
|
89
|
+
same('{"a":1,"b":2,"bb":2.2,"c":3,"c_":3.3}', s2)
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it('bigints', () => {
|
|
93
|
+
const verify = (/** @type {number | bigint} **/ inp) => {
|
|
94
|
+
assert.strictEqual(decode(utf8Encode(String(inp))), inp)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// plain Number objects
|
|
98
|
+
verify(0)
|
|
99
|
+
verify(1)
|
|
100
|
+
verify(-1)
|
|
101
|
+
verify(Math.pow(2, 50))
|
|
102
|
+
verify(-Math.pow(2, 50))
|
|
103
|
+
verify(Number.MAX_SAFE_INTEGER)
|
|
104
|
+
verify(-Number.MAX_SAFE_INTEGER)
|
|
105
|
+
// should round-trip as BigInts
|
|
106
|
+
verify(BigInt('9007199254740992')) // Number.MAX_SAFE_INTEGER+1
|
|
107
|
+
verify(BigInt('9007199254740993'))
|
|
108
|
+
verify(BigInt('11959030306112471731'))
|
|
109
|
+
verify(BigInt('18446744073709551615')) // max uint64
|
|
110
|
+
verify(BigInt('9223372036854775807')) // max int64
|
|
111
|
+
verify(BigInt('-9007199254740992'))
|
|
112
|
+
verify(BigInt('-9007199254740993'))
|
|
113
|
+
verify(BigInt('-9223372036854776000')) // min int64
|
|
114
|
+
verify(BigInt('-11959030306112471732'))
|
|
115
|
+
verify(BigInt('-18446744073709551616')) // min -uint64
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
it('error on circular references', () => {
|
|
119
|
+
const circularObj = {}
|
|
120
|
+
circularObj.a = circularObj
|
|
121
|
+
assert.throws(() => encode(circularObj), /object contains circular references/)
|
|
122
|
+
const circularArr = [circularObj]
|
|
123
|
+
circularObj.a = circularArr
|
|
124
|
+
assert.throws(() => encode(circularArr), /object contains circular references/)
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
it('error on encoding undefined', () => {
|
|
128
|
+
assert.throws(() => encode(undefined), /\Wundefined\W.*not supported/)
|
|
129
|
+
const objWithUndefined = { a: 'a', b: undefined }
|
|
130
|
+
assert.throws(() => encode(objWithUndefined), /\Wundefined\W.*not supported/)
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
it('error on encoding IEEE 754 specials', () => {
|
|
134
|
+
for (const special of [NaN, Infinity, -Infinity]) {
|
|
135
|
+
assert.throws(() => encode(special), new RegExp(`\\W${String(special)}\\W.*not supported`))
|
|
136
|
+
const objWithSpecial = { a: 'a', b: special }
|
|
137
|
+
assert.throws(() => encode(objWithSpecial), new RegExp(`\\W${String(special)}\\W.*not supported`))
|
|
138
|
+
const arrWithSpecial = [1, 1.1, -1, -1.1, Number.MAX_SAFE_INTEGER, special, Number.MIN_SAFE_INTEGER]
|
|
139
|
+
assert.throws(() => encode(arrWithSpecial), new RegExp(`\\W${String(special)}\\W.*not supported`))
|
|
140
|
+
}
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
it('fuzz serialize and deserialize with garbage', function () {
|
|
144
|
+
// filter out fuzz garbage for objects that are disqualified by DAG-JSON rules
|
|
145
|
+
/** @type {(obj: any) => boolean} */
|
|
146
|
+
const checkObj = (obj) => {
|
|
147
|
+
if (Array.isArray(obj)) {
|
|
148
|
+
return obj.every(checkObj)
|
|
149
|
+
}
|
|
150
|
+
if (obj && typeof obj === 'object') {
|
|
151
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
152
|
+
if (key === '/') {
|
|
153
|
+
if (typeof value === 'string') {
|
|
154
|
+
return false
|
|
155
|
+
}
|
|
156
|
+
if (value && typeof value === 'object' && value.bytes !== undefined) {
|
|
157
|
+
return false
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (!checkObj(value)) {
|
|
161
|
+
return false
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return true
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
this.timeout(5000)
|
|
169
|
+
for (let ii = 0; ii < 1000; ii++) {
|
|
170
|
+
const original = garbage(300)
|
|
171
|
+
if (!checkObj(original)) {
|
|
172
|
+
continue
|
|
173
|
+
}
|
|
174
|
+
const encoded = encode(original)
|
|
175
|
+
const decoded = decode(encoded)
|
|
176
|
+
same(decoded, original)
|
|
177
|
+
}
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
it('serialize', () => {
|
|
181
|
+
same(stringify({ hello: 'world' }), JSON.stringify({ hello: 'world' }))
|
|
182
|
+
|
|
183
|
+
const input = { link, bytes: bytes.fromString('asdf'), n: null, o: {} }
|
|
184
|
+
same(stringify(input), JSON.stringify({
|
|
185
|
+
bytes: { '/': { bytes: base64.baseEncode(input.bytes) } },
|
|
186
|
+
link: { '/': link.toString() },
|
|
187
|
+
n: null,
|
|
188
|
+
o: {}
|
|
189
|
+
}))
|
|
190
|
+
|
|
191
|
+
const output = parse(stringify(input))
|
|
192
|
+
same(input, output)
|
|
193
|
+
same(bytes.isBinary(output.bytes), true)
|
|
194
|
+
same(CID.asCID(output.link), output.link)
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
describe('typed arrays', () => {
|
|
198
|
+
// This mirrors what ships by default in dag-cbor: https://github.com/rvagg/cborg/blob/968fdac4af22c9b22fe5b40c2a6f9bb855780a4a/test/test-2bytes.js#L121
|
|
199
|
+
// It's an open question whether this should slip by without error or not,
|
|
200
|
+
// for now we silently convert them to plain bytes and they all round trip
|
|
201
|
+
// as Uint8Arrays.
|
|
202
|
+
const cases = /** @type {{obj: ArrayBufferView, expected: string}[]} */([
|
|
203
|
+
{
|
|
204
|
+
obj: Uint8Array.from([1, 2, 3]),
|
|
205
|
+
expected: '{"/":{"bytes":"AQID"}}'
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
obj: Uint8ClampedArray.from([1, 2, 3]),
|
|
209
|
+
expected: '{"/":{"bytes":"AQID"}}'
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
obj: Uint16Array.from([1, 2, 3]),
|
|
213
|
+
expected: '{"/":{"bytes":"AQACAAMA"}}'
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
obj: Uint32Array.from([1, 2, 3]),
|
|
217
|
+
expected: '{"/":{"bytes":"AQAAAAIAAAADAAAA"}}'
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
obj: Int8Array.from([1, 2, -3]),
|
|
221
|
+
expected: '{"/":{"bytes":"AQL9"}}'
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
obj: Int16Array.from([1, 2, -3]),
|
|
225
|
+
expected: '{"/":{"bytes":"AQACAP3/"}}'
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
obj: Int32Array.from([1, 2, -3]),
|
|
229
|
+
expected: '{"/":{"bytes":"AQAAAAIAAAD9////"}}'
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
obj: Float32Array.from([1, 2, -3]),
|
|
233
|
+
expected: '{"/":{"bytes":"AACAPwAAAEAAAEDA"}}'
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
obj: Float64Array.from([1, 2, -3]),
|
|
237
|
+
expected: '{"/":{"bytes":"AAAAAAAA8D8AAAAAAAAAQAAAAAAAAAjA"}}'
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
obj: BigUint64Array.from([BigInt(1), BigInt(2), BigInt(3)]),
|
|
241
|
+
expected: '{"/":{"bytes":"AQAAAAAAAAACAAAAAAAAAAMAAAAAAAAA"}}'
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
obj: BigInt64Array.from([BigInt(1), BigInt(2), BigInt(-3)]),
|
|
245
|
+
expected: '{"/":{"bytes":"AQAAAAAAAAACAAAAAAAAAP3/////////"}}'
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
obj: new DataView(Uint8Array.from([1, 2, 3]).buffer),
|
|
249
|
+
expected: '{"/":{"bytes":"AQID"}}'
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
obj: Uint8Array.from([1, 2, 3]).buffer,
|
|
253
|
+
expected: '{"/":{"bytes":"AQID"}}'
|
|
254
|
+
}
|
|
255
|
+
])
|
|
256
|
+
|
|
257
|
+
for (const testCase of cases) {
|
|
258
|
+
it(testCase.obj.constructor.name, () => {
|
|
259
|
+
same(utf8Decode(encode(testCase.obj)), testCase.expected)
|
|
260
|
+
const decoded = decode(utf8Encode(testCase.expected))
|
|
261
|
+
assert.instanceOf(decoded, Uint8Array)
|
|
262
|
+
if (testCase.obj instanceof ArrayBuffer) {
|
|
263
|
+
same(decoded, new Uint8Array(testCase.obj))
|
|
264
|
+
} else {
|
|
265
|
+
same(decoded, new Uint8Array(testCase.obj.buffer, testCase.obj.byteOffset, testCase.obj.byteLength))
|
|
266
|
+
}
|
|
267
|
+
})
|
|
268
|
+
}
|
|
269
|
+
})
|
|
270
|
+
|
|
271
|
+
it('reject duplicate map keys', () => {
|
|
272
|
+
assert.throws(() => decode(utf8Encode('{"foo":1,"foo":2,"bar":3}')), /found repeat map key "foo"/)
|
|
273
|
+
})
|
|
274
|
+
})
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* @param {string} s
|
|
278
|
+
* @returns {Uint8Array}
|
|
279
|
+
*/
|
|
280
|
+
function utf8Encode (s) {
|
|
281
|
+
return new TextEncoder().encode(s)
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* @param {Uint8Array} b
|
|
286
|
+
* @returns {string}
|
|
287
|
+
*/
|
|
288
|
+
function utf8Decode (b) {
|
|
289
|
+
return new TextDecoder().decode(b)
|
|
290
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { deepStrictEqual } from 'assert'
|
|
2
|
+
|
|
3
|
+
import { BlockEncoder, BlockDecoder, BlockCodec } from 'multiformats/codecs/interface'
|
|
4
|
+
import * as dagJson from '@ipld/dag-json'
|
|
5
|
+
|
|
6
|
+
const main = () => {
|
|
7
|
+
// make sure we have a full CodecFeature
|
|
8
|
+
useCodecFeature(dagJson)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function useCodecFeature (codec: BlockCodec<297, any>) {
|
|
12
|
+
// use only as a BlockEncoder
|
|
13
|
+
useEncoder(codec)
|
|
14
|
+
|
|
15
|
+
// use only as a BlockDecoder
|
|
16
|
+
useDecoder(codec)
|
|
17
|
+
|
|
18
|
+
// use with ArrayBuffer input type
|
|
19
|
+
useDecoderWithArrayBuffer(codec)
|
|
20
|
+
|
|
21
|
+
// use as a full BlockCodec which does both BlockEncoder & BlockDecoder
|
|
22
|
+
useBlockCodec(codec)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function useEncoder<Codec extends number> (encoder: BlockEncoder<Codec, string>) {
|
|
26
|
+
deepStrictEqual(encoder.code, 297)
|
|
27
|
+
deepStrictEqual(encoder.name, 'dag-json')
|
|
28
|
+
deepStrictEqual(Array.from(encoder.encode('blip')), [34, 98, 108, 105, 112, 34])
|
|
29
|
+
console.log('[TS] ✓ { encoder: BlockEncoder }')
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function useDecoder<Codec extends number> (decoder: BlockDecoder<Codec, Uint8Array>) {
|
|
33
|
+
deepStrictEqual(decoder.code, 297)
|
|
34
|
+
deepStrictEqual(decoder.decode(Uint8Array.from([34, 98, 108, 105, 112, 34 ])), 'blip')
|
|
35
|
+
console.log('[TS] ✓ { decoder: BlockDecoder }')
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function useDecoderWithArrayBuffer<Codec extends number> (decoder: BlockDecoder<Codec, Uint8Array>) {
|
|
39
|
+
deepStrictEqual(decoder.code, 297)
|
|
40
|
+
deepStrictEqual(decoder.decode(Uint8Array.from([34, 98, 108, 105, 112, 34 ]).buffer), 'blip')
|
|
41
|
+
console.log('[TS] ✓ { decoder: BlockDecoder }')
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function useBlockCodec<Codec extends number> (blockCodec: BlockCodec<Codec, string>) {
|
|
45
|
+
deepStrictEqual(blockCodec.code, 297)
|
|
46
|
+
deepStrictEqual(blockCodec.name, 'dag-json')
|
|
47
|
+
deepStrictEqual(Array.from(blockCodec.encode('blip')), [34, 98, 108, 105, 112, 34])
|
|
48
|
+
deepStrictEqual(blockCodec.decode(Uint8Array.from([34, 98, 108, 105, 112, 34])), 'blip')
|
|
49
|
+
console.log('[TS] ✓ {}:BlockCodec')
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
main()
|
|
53
|
+
|
|
54
|
+
export default main
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
version: 2
|
|
2
|
+
updates:
|
|
3
|
+
- package-ecosystem: 'github-actions'
|
|
4
|
+
directory: '/'
|
|
5
|
+
schedule:
|
|
6
|
+
interval: 'daily'
|
|
7
|
+
commit-message:
|
|
8
|
+
prefix: 'chore'
|
|
9
|
+
include: 'scope'
|
|
10
|
+
- package-ecosystem: 'npm'
|
|
11
|
+
directory: '/'
|
|
12
|
+
schedule:
|
|
13
|
+
interval: 'daily'
|
|
14
|
+
commit-message:
|
|
15
|
+
prefix: 'chore'
|
|
16
|
+
include: 'scope'
|