@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,299 @@
|
|
|
1
|
+
// never reference the file directly to ensure the
|
|
2
|
+
// indepency of the json module
|
|
3
|
+
import { Type } from 'cborg'
|
|
4
|
+
import { encodeCustom } from 'cborg'
|
|
5
|
+
import { encodeErrPrefix } from 'cborg'
|
|
6
|
+
import { asU8A, fromString } from 'cborg'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @typedef {import('../../interface').EncodeOptions} EncodeOptions
|
|
10
|
+
* @typedef {import('../../interface').TokenTypeEncoder} TokenTypeEncoder
|
|
11
|
+
* @typedef {import('../token').Token} Token
|
|
12
|
+
* @typedef {import('../bl').Bl} Bl
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {(buf: Bl, token: Token) => void} action
|
|
17
|
+
* @returns {TokenTypeEncoder}
|
|
18
|
+
*/
|
|
19
|
+
function wrapCompareTokens (action) {
|
|
20
|
+
const wrapped = (/** @type {Bl} */ buf, /** @type {Token} */token) => action(buf, token)
|
|
21
|
+
/**
|
|
22
|
+
* @param {Token} tok1
|
|
23
|
+
* @param {Token} tok2
|
|
24
|
+
* @returns {number}
|
|
25
|
+
*/
|
|
26
|
+
wrapped.compareTokens = function compareTokens (tok1, tok2) {
|
|
27
|
+
return tok1.value < tok2.value ? -1 : tok1.value > tok2.value ? 1 : 0
|
|
28
|
+
}
|
|
29
|
+
return wrapped
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @returns {TokenTypeEncoder[]}
|
|
34
|
+
*/
|
|
35
|
+
function makeJSONEncoders() {
|
|
36
|
+
/** @type {TokenTypeEncoder[]} */
|
|
37
|
+
const encoders = []
|
|
38
|
+
/** @type {{type:Type,elements:number}[]} */
|
|
39
|
+
const inRecursive = []
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @param {Bl} buf
|
|
43
|
+
*/
|
|
44
|
+
function prefix (buf) {
|
|
45
|
+
const recurs = inRecursive[inRecursive.length - 1]
|
|
46
|
+
if (recurs) {
|
|
47
|
+
if (recurs.type.equals(Type.array)) {
|
|
48
|
+
recurs.elements++
|
|
49
|
+
if (recurs.elements !== 1) { // >first
|
|
50
|
+
buf.push([44]) // ','
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (recurs.type.equals(Type.map)) {
|
|
54
|
+
recurs.elements++
|
|
55
|
+
if (recurs.elements !== 1) { // >first
|
|
56
|
+
if (recurs.elements % 2 === 1) { // key
|
|
57
|
+
buf.push([44]) // ','
|
|
58
|
+
} else {
|
|
59
|
+
buf.push([58]) // ':'
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
encoders[Type.uint.major] = wrapCompareTokens((buf, token) => {
|
|
67
|
+
prefix(buf)
|
|
68
|
+
const is = String(token.value)
|
|
69
|
+
const isa = []
|
|
70
|
+
for (let i = 0; i < is.length; i++) {
|
|
71
|
+
isa[i] = is.charCodeAt(i)
|
|
72
|
+
}
|
|
73
|
+
buf.push(isa)
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
encoders[Type.negint.major] = wrapCompareTokens((buf, token) => {
|
|
77
|
+
encoders[Type.uint.major](buf, token)
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
encoders[Type.bytes.major] = wrapCompareTokens((_buf, _token) => {
|
|
81
|
+
throw new Error(`${encodeErrPrefix} unsupported type: Uint8Array`)
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
encoders[Type.string.major] = wrapCompareTokens((buf, token) => {
|
|
85
|
+
prefix(buf)
|
|
86
|
+
const byts = fromString(JSON.stringify(token.value))
|
|
87
|
+
buf.push(byts.length > 32 ? asU8A(byts) : byts)
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
encoders[Type.array.major] = wrapCompareTokens((buf, _token) => {
|
|
91
|
+
prefix(buf)
|
|
92
|
+
inRecursive.push({ type: Type.array, elements: 0 })
|
|
93
|
+
buf.push([91]) // '['
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
encoders[Type.map.major] = wrapCompareTokens((buf, _token) => {
|
|
97
|
+
prefix(buf)
|
|
98
|
+
inRecursive.push({ type: Type.map, elements: 0 })
|
|
99
|
+
buf.push([123]) // '{'
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
encoders[Type.tag.major] = wrapCompareTokens((_buf, _token) => {
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
encoders[Type.float.major] = wrapCompareTokens((buf, token) => {
|
|
106
|
+
if (token.type.equals(Type.break)) {
|
|
107
|
+
const recurs = inRecursive.pop()
|
|
108
|
+
if (recurs) {
|
|
109
|
+
if (recurs.type.equals(Type.array)) {
|
|
110
|
+
buf.push([93]) // ']'
|
|
111
|
+
} else if (recurs.type.equals(Type.map)) {
|
|
112
|
+
buf.push([125]) // '}'
|
|
113
|
+
/* c8 ignore next 3 */
|
|
114
|
+
} else {
|
|
115
|
+
throw new Error('Unexpected recursive type; this should not happen!')
|
|
116
|
+
}
|
|
117
|
+
return
|
|
118
|
+
}
|
|
119
|
+
/* c8 ignore next 2 */
|
|
120
|
+
throw new Error('Unexpected break; this should not happen!')
|
|
121
|
+
}
|
|
122
|
+
if (token.value === undefined) {
|
|
123
|
+
throw new Error(`${encodeErrPrefix} unsupported type: undefined`)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
prefix(buf)
|
|
127
|
+
if (token.type.equals(Type.true)) {
|
|
128
|
+
buf.push([116, 114, 117, 101]) // 'true'
|
|
129
|
+
return
|
|
130
|
+
} else if (token.type.equals(Type.false)) {
|
|
131
|
+
buf.push([102, 97, 108, 115, 101]) // 'false'
|
|
132
|
+
return
|
|
133
|
+
} else if (token.type.equals(Type.null)) {
|
|
134
|
+
buf.push([110, 117, 108, 108]) // 'null'
|
|
135
|
+
return
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// number
|
|
139
|
+
const is = String(token.value)
|
|
140
|
+
const isa = []
|
|
141
|
+
let dp = false
|
|
142
|
+
for (let i = 0; i < is.length; i++) {
|
|
143
|
+
isa[i] = is.charCodeAt(i)
|
|
144
|
+
if (!dp && (isa[i] === 46 || isa[i] === 101 || isa[i] === 69)) { // '[.eE]'
|
|
145
|
+
dp = true
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (!dp) { // need a decimal point for floats
|
|
149
|
+
isa.push(46) // '.'
|
|
150
|
+
isa.push(48) // '0'
|
|
151
|
+
}
|
|
152
|
+
buf.push(isa)
|
|
153
|
+
})
|
|
154
|
+
return encoders
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// The below code is mostly taken and modified from https://github.com/feross/buffer
|
|
158
|
+
// Licensed MIT. Copyright (c) Feross Aboukhadijeh
|
|
159
|
+
// function encodeUtf8 (string, byts) {
|
|
160
|
+
// let codePoint
|
|
161
|
+
// const length = string.length
|
|
162
|
+
// let leadSurrogate = null
|
|
163
|
+
|
|
164
|
+
// for (let i = 0; i < length; ++i) {
|
|
165
|
+
// codePoint = string.charCodeAt(i)
|
|
166
|
+
|
|
167
|
+
// // is surrogate component
|
|
168
|
+
// if (codePoint > 0xd7ff && codePoint < 0xe000) {
|
|
169
|
+
// // last char was a lead
|
|
170
|
+
// if (!leadSurrogate) {
|
|
171
|
+
// // no lead yet
|
|
172
|
+
// /* c8 ignore next 9 */
|
|
173
|
+
// if (codePoint > 0xdbff) {
|
|
174
|
+
// // unexpected trail
|
|
175
|
+
// byts.push(0xef, 0xbf, 0xbd)
|
|
176
|
+
// continue
|
|
177
|
+
// } else if (i + 1 === length) {
|
|
178
|
+
// // unpaired lead
|
|
179
|
+
// byts.push(0xef, 0xbf, 0xbd)
|
|
180
|
+
// continue
|
|
181
|
+
// }
|
|
182
|
+
|
|
183
|
+
// // valid lead
|
|
184
|
+
// leadSurrogate = codePoint
|
|
185
|
+
|
|
186
|
+
// continue
|
|
187
|
+
// }
|
|
188
|
+
|
|
189
|
+
// // 2 leads in a row
|
|
190
|
+
// /* c8 ignore next 5 */
|
|
191
|
+
// if (codePoint < 0xdc00) {
|
|
192
|
+
// byts.push(0xef, 0xbf, 0xbd)
|
|
193
|
+
// leadSurrogate = codePoint
|
|
194
|
+
// continue
|
|
195
|
+
// }
|
|
196
|
+
|
|
197
|
+
// // valid surrogate pair
|
|
198
|
+
// codePoint = (leadSurrogate - 0xd800 << 10 | codePoint - 0xdc00) + 0x10000
|
|
199
|
+
// /* c8 ignore next 4 */
|
|
200
|
+
// } else if (leadSurrogate) {
|
|
201
|
+
// // valid bmp char, but last char was a lead
|
|
202
|
+
// byts.push(0xef, 0xbf, 0xbd)
|
|
203
|
+
// }
|
|
204
|
+
|
|
205
|
+
// leadSurrogate = null
|
|
206
|
+
|
|
207
|
+
// // encode utf8
|
|
208
|
+
// if (codePoint < 0x80) {
|
|
209
|
+
// // special JSON escapes
|
|
210
|
+
// switch (codePoint) {
|
|
211
|
+
// case 8: // '\b'
|
|
212
|
+
// byts.push(92, 98) // '\\b'
|
|
213
|
+
// continue
|
|
214
|
+
// case 9: // '\t'
|
|
215
|
+
// byts.push(92, 116) // '\\t'
|
|
216
|
+
// continue
|
|
217
|
+
// case 10: // '\n'
|
|
218
|
+
// byts.push(92, 110) // '\\n'
|
|
219
|
+
// continue
|
|
220
|
+
// case 12: // '\f'
|
|
221
|
+
// byts.push(92, 102) // '\\f'
|
|
222
|
+
// continue
|
|
223
|
+
// case 13: // '\r'
|
|
224
|
+
// byts.push(92, 114) // '\\r'
|
|
225
|
+
// continue
|
|
226
|
+
// case 34: // '"'
|
|
227
|
+
// byts.push(92, 34) // '\\"'
|
|
228
|
+
// continue
|
|
229
|
+
// case 92: // '\\'
|
|
230
|
+
// byts.push(92, 92) // '\\\\'
|
|
231
|
+
// continue
|
|
232
|
+
// }
|
|
233
|
+
|
|
234
|
+
// byts.push(codePoint)
|
|
235
|
+
// } else if (codePoint < 0x800) {
|
|
236
|
+
// /* c8 ignore next 1 */
|
|
237
|
+
// byts.push(
|
|
238
|
+
// codePoint >> 0x6 | 0xc0,
|
|
239
|
+
// codePoint & 0x3f | 0x80
|
|
240
|
+
// )
|
|
241
|
+
// } else if (codePoint < 0x10000) {
|
|
242
|
+
// /* c8 ignore next 1 */
|
|
243
|
+
// byts.push(
|
|
244
|
+
// codePoint >> 0xc | 0xe0,
|
|
245
|
+
// codePoint >> 0x6 & 0x3f | 0x80,
|
|
246
|
+
// codePoint & 0x3f | 0x80
|
|
247
|
+
// )
|
|
248
|
+
// /* c8 ignore next 9 */
|
|
249
|
+
// } else if (codePoint < 0x110000) {
|
|
250
|
+
// byts.push(
|
|
251
|
+
// codePoint >> 0x12 | 0xf0,
|
|
252
|
+
// codePoint >> 0xc & 0x3f | 0x80,
|
|
253
|
+
// codePoint >> 0x6 & 0x3f | 0x80,
|
|
254
|
+
// codePoint & 0x3f | 0x80
|
|
255
|
+
// )
|
|
256
|
+
// } else {
|
|
257
|
+
// /* c8 ignore next 2 */
|
|
258
|
+
// throw new Error('Invalid code point')
|
|
259
|
+
// }
|
|
260
|
+
// }
|
|
261
|
+
// }
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* @param {(Token|Token[])[]} e1
|
|
265
|
+
* @param {(Token|Token[])[]} e2
|
|
266
|
+
* @returns {number}
|
|
267
|
+
*/
|
|
268
|
+
function mapSorter (e1, e2) {
|
|
269
|
+
if (Array.isArray(e1[0]) || Array.isArray(e2[0])) {
|
|
270
|
+
throw new Error(`${encodeErrPrefix} complex map keys are not supported`)
|
|
271
|
+
}
|
|
272
|
+
const keyToken1 = e1[0]
|
|
273
|
+
const keyToken2 = e2[0]
|
|
274
|
+
if (!keyToken1.type.equals(Type.string) || !keyToken2.type.equals(Type.string)) {
|
|
275
|
+
throw new Error(`${encodeErrPrefix} non-string map keys are not supported`)
|
|
276
|
+
}
|
|
277
|
+
if (keyToken1 < keyToken2) {
|
|
278
|
+
return -1
|
|
279
|
+
}
|
|
280
|
+
if (keyToken1 > keyToken2) {
|
|
281
|
+
return 1
|
|
282
|
+
}
|
|
283
|
+
/* c8 ignore next 1 */
|
|
284
|
+
throw new Error(`${encodeErrPrefix} unexpected duplicate map keys, this is not supported`)
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const defaultEncodeOptions = { addBreakTokens: true, mapSorter }
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* @param {any} data
|
|
291
|
+
* @param {EncodeOptions} [options]
|
|
292
|
+
* @returns {Uint8Array}
|
|
293
|
+
*/
|
|
294
|
+
function encode (data, options) {
|
|
295
|
+
options = Object.assign({}, defaultEncodeOptions, options)
|
|
296
|
+
return encodeCustom(data, makeJSONEncoders(), options)
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export { encode }
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { Token, Type } from './token.js'
|
|
2
|
+
import * as uint from './0uint.js'
|
|
3
|
+
import * as negint from './1negint.js'
|
|
4
|
+
import * as bytes from './2bytes.js'
|
|
5
|
+
import * as string from './3string.js'
|
|
6
|
+
import * as array from './4array.js'
|
|
7
|
+
import * as map from './5map.js'
|
|
8
|
+
import * as tag from './6tag.js'
|
|
9
|
+
import * as float from './7float.js'
|
|
10
|
+
import { decodeErrPrefix } from './common.js'
|
|
11
|
+
import { fromArray } from './byte-utils.js'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @typedef {import('../interface').DecodeOptions} DecodeOptions
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {Uint8Array} data
|
|
19
|
+
* @param {number} pos
|
|
20
|
+
* @param {number} minor
|
|
21
|
+
*/
|
|
22
|
+
function invalidMinor (data, pos, minor) {
|
|
23
|
+
throw new Error(`${decodeErrPrefix} encountered invalid minor (${minor}) for major ${data[pos] >>> 5}`)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param {string} msg
|
|
28
|
+
* @returns {()=>any}
|
|
29
|
+
*/
|
|
30
|
+
function errorer (msg) {
|
|
31
|
+
return () => { throw new Error(`${decodeErrPrefix} ${msg}`) }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** @type {((data:Uint8Array, pos:number, minor:number, options?:DecodeOptions) => any)[]} */
|
|
35
|
+
export const jump = []
|
|
36
|
+
|
|
37
|
+
// unsigned integer, 0x00..0x17 (0..23)
|
|
38
|
+
for (let i = 0; i <= 0x17; i++) {
|
|
39
|
+
jump[i] = invalidMinor // uint.decodeUintCompact, handled by quick[]
|
|
40
|
+
}
|
|
41
|
+
jump[0x18] = uint.decodeUint8 // unsigned integer, one-byte uint8_t follows
|
|
42
|
+
jump[0x19] = uint.decodeUint16 // unsigned integer, two-byte uint16_t follows
|
|
43
|
+
jump[0x1a] = uint.decodeUint32 // unsigned integer, four-byte uint32_t follows
|
|
44
|
+
jump[0x1b] = uint.decodeUint64 // unsigned integer, eight-byte uint64_t follows
|
|
45
|
+
jump[0x1c] = invalidMinor
|
|
46
|
+
jump[0x1d] = invalidMinor
|
|
47
|
+
jump[0x1e] = invalidMinor
|
|
48
|
+
jump[0x1f] = invalidMinor
|
|
49
|
+
// negative integer, -1-0x00..-1-0x17 (-1..-24)
|
|
50
|
+
for (let i = 0x20; i <= 0x37; i++) {
|
|
51
|
+
jump[i] = invalidMinor // negintDecode, handled by quick[]
|
|
52
|
+
}
|
|
53
|
+
jump[0x38] = negint.decodeNegint8 // negative integer, -1-n one-byte uint8_t for n follows
|
|
54
|
+
jump[0x39] = negint.decodeNegint16 // negative integer, -1-n two-byte uint16_t for n follows
|
|
55
|
+
jump[0x3a] = negint.decodeNegint32 // negative integer, -1-n four-byte uint32_t for follows
|
|
56
|
+
jump[0x3b] = negint.decodeNegint64 // negative integer, -1-n eight-byte uint64_t for follows
|
|
57
|
+
jump[0x3c] = invalidMinor
|
|
58
|
+
jump[0x3d] = invalidMinor
|
|
59
|
+
jump[0x3e] = invalidMinor
|
|
60
|
+
jump[0x3f] = invalidMinor
|
|
61
|
+
// byte string, 0x00..0x17 bytes follow
|
|
62
|
+
for (let i = 0x40; i <= 0x57; i++) {
|
|
63
|
+
jump[i] = bytes.decodeBytesCompact
|
|
64
|
+
}
|
|
65
|
+
jump[0x58] = bytes.decodeBytes8 // byte string, one-byte uint8_t for n, and then n bytes follow
|
|
66
|
+
jump[0x59] = bytes.decodeBytes16 // byte string, two-byte uint16_t for n, and then n bytes follow
|
|
67
|
+
jump[0x5a] = bytes.decodeBytes32 // byte string, four-byte uint32_t for n, and then n bytes follow
|
|
68
|
+
jump[0x5b] = bytes.decodeBytes64 // byte string, eight-byte uint64_t for n, and then n bytes follow
|
|
69
|
+
jump[0x5c] = invalidMinor
|
|
70
|
+
jump[0x5d] = invalidMinor
|
|
71
|
+
jump[0x5e] = invalidMinor
|
|
72
|
+
jump[0x5f] = errorer('indefinite length bytes/strings are not supported') // byte string, byte strings follow, terminated by "break"
|
|
73
|
+
// UTF-8 string 0x00..0x17 bytes follow
|
|
74
|
+
for (let i = 0x60; i <= 0x77; i++) {
|
|
75
|
+
jump[i] = string.decodeStringCompact
|
|
76
|
+
}
|
|
77
|
+
jump[0x78] = string.decodeString8 // UTF-8 string, one-byte uint8_t for n, and then n bytes follow
|
|
78
|
+
jump[0x79] = string.decodeString16 // UTF-8 string, two-byte uint16_t for n, and then n bytes follow
|
|
79
|
+
jump[0x7a] = string.decodeString32 // UTF-8 string, four-byte uint32_t for n, and then n bytes follow
|
|
80
|
+
jump[0x7b] = string.decodeString64 // UTF-8 string, eight-byte uint64_t for n, and then n bytes follow
|
|
81
|
+
jump[0x7c] = invalidMinor
|
|
82
|
+
jump[0x7d] = invalidMinor
|
|
83
|
+
jump[0x7e] = invalidMinor
|
|
84
|
+
jump[0x7f] = errorer('indefinite length bytes/strings are not supported') // UTF-8 strings follow, terminated by "break"
|
|
85
|
+
// array, 0x00..0x17 data items follow
|
|
86
|
+
for (let i = 0x80; i <= 0x97; i++) {
|
|
87
|
+
jump[i] = array.decodeArrayCompact
|
|
88
|
+
}
|
|
89
|
+
jump[0x98] = array.decodeArray8 // array, one-byte uint8_t for n, and then n data items follow
|
|
90
|
+
jump[0x99] = array.decodeArray16 // array, two-byte uint16_t for n, and then n data items follow
|
|
91
|
+
jump[0x9a] = array.decodeArray32 // array, four-byte uint32_t for n, and then n data items follow
|
|
92
|
+
jump[0x9b] = array.decodeArray64 // array, eight-byte uint64_t for n, and then n data items follow
|
|
93
|
+
jump[0x9c] = invalidMinor
|
|
94
|
+
jump[0x9d] = invalidMinor
|
|
95
|
+
jump[0x9e] = invalidMinor
|
|
96
|
+
jump[0x9f] = array.decodeArrayIndefinite // array, data items follow, terminated by "break"
|
|
97
|
+
// map, 0x00..0x17 pairs of data items follow
|
|
98
|
+
for (let i = 0xa0; i <= 0xb7; i++) {
|
|
99
|
+
jump[i] = map.decodeMapCompact
|
|
100
|
+
}
|
|
101
|
+
jump[0xb8] = map.decodeMap8 // map, one-byte uint8_t for n, and then n pairs of data items follow
|
|
102
|
+
jump[0xb9] = map.decodeMap16 // map, two-byte uint16_t for n, and then n pairs of data items follow
|
|
103
|
+
jump[0xba] = map.decodeMap32 // map, four-byte uint32_t for n, and then n pairs of data items follow
|
|
104
|
+
jump[0xbb] = map.decodeMap64 // map, eight-byte uint64_t for n, and then n pairs of data items follow
|
|
105
|
+
jump[0xbc] = invalidMinor
|
|
106
|
+
jump[0xbd] = invalidMinor
|
|
107
|
+
jump[0xbe] = invalidMinor
|
|
108
|
+
jump[0xbf] = map.decodeMapIndefinite // map, pairs of data items follow, terminated by "break"
|
|
109
|
+
// tags
|
|
110
|
+
for (let i = 0xc0; i <= 0xd7; i++) {
|
|
111
|
+
jump[i] = tag.decodeTagCompact
|
|
112
|
+
}
|
|
113
|
+
jump[0xd8] = tag.decodeTag8
|
|
114
|
+
jump[0xd9] = tag.decodeTag16
|
|
115
|
+
jump[0xda] = tag.decodeTag32
|
|
116
|
+
jump[0xdb] = tag.decodeTag64
|
|
117
|
+
jump[0xdc] = invalidMinor
|
|
118
|
+
jump[0xdd] = invalidMinor
|
|
119
|
+
jump[0xde] = invalidMinor
|
|
120
|
+
jump[0xdf] = invalidMinor
|
|
121
|
+
// 0xe0..0xf3 simple values, unsupported
|
|
122
|
+
for (let i = 0xe0; i <= 0xf3; i++) {
|
|
123
|
+
jump[i] = errorer('simple values are not supported')
|
|
124
|
+
}
|
|
125
|
+
jump[0xf4] = invalidMinor // false, handled by quick[]
|
|
126
|
+
jump[0xf5] = invalidMinor // true, handled by quick[]
|
|
127
|
+
jump[0xf6] = invalidMinor // null, handled by quick[]
|
|
128
|
+
jump[0xf7] = float.decodeUndefined // undefined
|
|
129
|
+
jump[0xf8] = errorer('simple values are not supported') // simple value, one byte follows, unsupported
|
|
130
|
+
jump[0xf9] = float.decodeFloat16 // half-precision float (two-byte IEEE 754)
|
|
131
|
+
jump[0xfa] = float.decodeFloat32 // single-precision float (four-byte IEEE 754)
|
|
132
|
+
jump[0xfb] = float.decodeFloat64 // double-precision float (eight-byte IEEE 754)
|
|
133
|
+
jump[0xfc] = invalidMinor
|
|
134
|
+
jump[0xfd] = invalidMinor
|
|
135
|
+
jump[0xfe] = invalidMinor
|
|
136
|
+
jump[0xff] = float.decodeBreak // "break" stop code
|
|
137
|
+
|
|
138
|
+
/** @type {Token[]} */
|
|
139
|
+
export const quick = []
|
|
140
|
+
// ints <24
|
|
141
|
+
for (let i = 0; i < 24; i++) {
|
|
142
|
+
quick[i] = new Token(Type.uint, i, 1)
|
|
143
|
+
}
|
|
144
|
+
// negints >= -24
|
|
145
|
+
for (let i = -1; i >= -24; i--) {
|
|
146
|
+
quick[31 - i] = new Token(Type.negint, i, 1)
|
|
147
|
+
}
|
|
148
|
+
// empty bytes
|
|
149
|
+
quick[0x40] = new Token(Type.bytes, new Uint8Array(0), 1)
|
|
150
|
+
// empty string
|
|
151
|
+
quick[0x60] = new Token(Type.string, '', 1)
|
|
152
|
+
// empty list
|
|
153
|
+
quick[0x80] = new Token(Type.array, 0, 1)
|
|
154
|
+
// empty map
|
|
155
|
+
quick[0xa0] = new Token(Type.map, 0, 1)
|
|
156
|
+
// false
|
|
157
|
+
quick[0xf4] = new Token(Type.false, false, 1)
|
|
158
|
+
// true
|
|
159
|
+
quick[0xf5] = new Token(Type.true, true, 1)
|
|
160
|
+
// null
|
|
161
|
+
quick[0xf6] = new Token(Type.null, null, 1)
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* @param {Token} token
|
|
165
|
+
* @returns {Uint8Array|undefined}
|
|
166
|
+
*/
|
|
167
|
+
export function quickEncodeToken (token) {
|
|
168
|
+
switch (token.type) {
|
|
169
|
+
case Type.false:
|
|
170
|
+
return fromArray([0xf4])
|
|
171
|
+
case Type.true:
|
|
172
|
+
return fromArray([0xf5])
|
|
173
|
+
case Type.null:
|
|
174
|
+
return fromArray([0xf6])
|
|
175
|
+
case Type.bytes:
|
|
176
|
+
if (!token.value.length) {
|
|
177
|
+
return fromArray([0x40])
|
|
178
|
+
}
|
|
179
|
+
return
|
|
180
|
+
case Type.string:
|
|
181
|
+
if (token.value === '') {
|
|
182
|
+
return fromArray([0x60])
|
|
183
|
+
}
|
|
184
|
+
return
|
|
185
|
+
case Type.array:
|
|
186
|
+
if (token.value === 0) {
|
|
187
|
+
return fromArray([0x80])
|
|
188
|
+
}
|
|
189
|
+
/* c8 ignore next 2 */
|
|
190
|
+
// shouldn't be possible if this were called when there was only one token
|
|
191
|
+
return
|
|
192
|
+
case Type.map:
|
|
193
|
+
if (token.value === 0) {
|
|
194
|
+
return fromArray([0xa0])
|
|
195
|
+
}
|
|
196
|
+
/* c8 ignore next 2 */
|
|
197
|
+
// shouldn't be possible if this were called when there was only one token
|
|
198
|
+
return
|
|
199
|
+
case Type.uint:
|
|
200
|
+
if (token.value < 24) {
|
|
201
|
+
return fromArray([Number(token.value)])
|
|
202
|
+
}
|
|
203
|
+
return
|
|
204
|
+
case Type.negint:
|
|
205
|
+
if (token.value >= -24) {
|
|
206
|
+
return fromArray([31 - Number(token.value)])
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { makeCborEncoders, objectToTokens } from './encode.js'
|
|
2
|
+
import { quickEncodeToken } from './jump.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {import('../interface').EncodeOptions} EncodeOptions
|
|
6
|
+
* @typedef {import('../interface').TokenTypeEncoder} TokenTypeEncoder
|
|
7
|
+
* @typedef {import('../interface').TokenOrNestedTokens} TokenOrNestedTokens
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const cborEncoders = makeCborEncoders()
|
|
11
|
+
|
|
12
|
+
/** @type {EncodeOptions} */
|
|
13
|
+
const defaultEncodeOptions = {
|
|
14
|
+
float64: false,
|
|
15
|
+
quickEncodeToken
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Calculate the byte length of the given data when encoded as CBOR with the
|
|
20
|
+
* options provided.
|
|
21
|
+
* This calculation will be accurate if the same options are used as when
|
|
22
|
+
* performing a normal encode. Some encode options can change the encoding
|
|
23
|
+
* output length.
|
|
24
|
+
*
|
|
25
|
+
* @param {any} data
|
|
26
|
+
* @param {EncodeOptions} [options]
|
|
27
|
+
* @returns {number}
|
|
28
|
+
*/
|
|
29
|
+
export function encodedLength (data, options) {
|
|
30
|
+
options = Object.assign({}, defaultEncodeOptions, options)
|
|
31
|
+
options.mapSorter = undefined // won't change the length
|
|
32
|
+
const tokens = objectToTokens(data, options)
|
|
33
|
+
return tokensToLength(tokens, cborEncoders, options)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Calculate the byte length of the data as represented by the given tokens when
|
|
38
|
+
* encoded as CBOR with the options provided.
|
|
39
|
+
* This function is for advanced users and would not normally be called
|
|
40
|
+
* directly. See `encodedLength()` for appropriate use.
|
|
41
|
+
*
|
|
42
|
+
* @param {TokenOrNestedTokens} tokens
|
|
43
|
+
* @param {TokenTypeEncoder[]} [encoders]
|
|
44
|
+
* @param {EncodeOptions} [options]
|
|
45
|
+
*/
|
|
46
|
+
export function tokensToLength (tokens, encoders = cborEncoders, options = defaultEncodeOptions) {
|
|
47
|
+
if (Array.isArray(tokens)) {
|
|
48
|
+
let len = 0
|
|
49
|
+
for (const token of tokens) {
|
|
50
|
+
len += tokensToLength(token, encoders, options)
|
|
51
|
+
}
|
|
52
|
+
return len
|
|
53
|
+
} else {
|
|
54
|
+
const encoder = encoders[tokens.type.major]
|
|
55
|
+
/* c8 ignore next 3 */
|
|
56
|
+
if (encoder.encodedSize === undefined || typeof encoder.encodedSize !== 'function') {
|
|
57
|
+
throw new Error(`Encoder for ${tokens.type.name} does not have an encodedSize()`)
|
|
58
|
+
}
|
|
59
|
+
return encoder.encodedSize(tokens, options)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
class Type {
|
|
2
|
+
/**
|
|
3
|
+
* @param {number} major
|
|
4
|
+
* @param {string} name
|
|
5
|
+
* @param {boolean} terminal
|
|
6
|
+
*/
|
|
7
|
+
constructor (major, name, terminal) {
|
|
8
|
+
this.major = major
|
|
9
|
+
this.majorEncoded = major << 5
|
|
10
|
+
this.name = name
|
|
11
|
+
this.terminal = terminal
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/* c8 ignore next 3 */
|
|
15
|
+
toString () {
|
|
16
|
+
return `Type[${this.major}].${this.name}`
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param {Type} typ
|
|
21
|
+
* @returns {boolean}
|
|
22
|
+
*/
|
|
23
|
+
equals (typ) {
|
|
24
|
+
return this.major === typ.major && this.name === typ.name
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @param {Type} typ
|
|
29
|
+
* @returns {number}
|
|
30
|
+
*/
|
|
31
|
+
compare (typ) {
|
|
32
|
+
/* c8 ignore next 1 */
|
|
33
|
+
return this.major < typ.major ? -1 : this.major > typ.major ? 1 : 0
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// convert to static fields when better supported
|
|
38
|
+
Type.uint = new Type(0, 'uint', true)
|
|
39
|
+
Type.negint = new Type(1, 'negint', true)
|
|
40
|
+
Type.bytes = new Type(2, 'bytes', true)
|
|
41
|
+
Type.string = new Type(3, 'string', true)
|
|
42
|
+
Type.array = new Type(4, 'array', false)
|
|
43
|
+
Type.map = new Type(5, 'map', false)
|
|
44
|
+
Type.tag = new Type(6, 'tag', false) // terminal?
|
|
45
|
+
Type.float = new Type(7, 'float', true)
|
|
46
|
+
Type.false = new Type(7, 'false', true)
|
|
47
|
+
Type.true = new Type(7, 'true', true)
|
|
48
|
+
Type.null = new Type(7, 'null', true)
|
|
49
|
+
Type.undefined = new Type(7, 'undefined', true)
|
|
50
|
+
Type.break = new Type(7, 'break', true)
|
|
51
|
+
|
|
52
|
+
// Type.indefiniteLength = new Type(0, 'indefiniteLength', true)
|
|
53
|
+
|
|
54
|
+
class Token {
|
|
55
|
+
/**
|
|
56
|
+
* @param {Type} type
|
|
57
|
+
* @param {any} [value]
|
|
58
|
+
* @param {number} [encodedLength]
|
|
59
|
+
*/
|
|
60
|
+
constructor (type, value, encodedLength) {
|
|
61
|
+
this.type = type
|
|
62
|
+
this.value = value
|
|
63
|
+
this.encodedLength = encodedLength
|
|
64
|
+
/** @type {Uint8Array|undefined} */
|
|
65
|
+
this.encodedBytes = undefined
|
|
66
|
+
/** @type {Uint8Array|undefined} */
|
|
67
|
+
this.byteValue = undefined
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/* c8 ignore next 3 */
|
|
71
|
+
toString () {
|
|
72
|
+
return `Token[${this.type}].${this.value}`
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export { Type, Token }
|