@fireproof/vendor 1.1.0 → 1.2.0
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 +97 -4
- package/src/@ipld/car/LICENSE +4 -0
- package/src/@ipld/car/README.md +1132 -0
- package/src/@ipld/car/dist/index.min.js +5 -0
- package/src/@ipld/car/dist/src/api.d.ts +72 -0
- package/src/@ipld/car/dist/src/api.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/buffer-decoder.d.ts +67 -0
- package/src/@ipld/car/dist/src/buffer-decoder.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/buffer-reader-browser.d.ts +116 -0
- package/src/@ipld/car/dist/src/buffer-reader-browser.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/buffer-reader.d.ts +31 -0
- package/src/@ipld/car/dist/src/buffer-reader.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/buffer-writer.d.ts +86 -0
- package/src/@ipld/car/dist/src/buffer-writer.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/coding.d.ts +49 -0
- package/src/@ipld/car/dist/src/coding.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/decoder-common.d.ts +43 -0
- package/src/@ipld/car/dist/src/decoder-common.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/decoder.d.ts +87 -0
- package/src/@ipld/car/dist/src/decoder.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/encoder.d.ts +17 -0
- package/src/@ipld/car/dist/src/encoder.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/header-validator.d.ts +5 -0
- package/src/@ipld/car/dist/src/header-validator.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/index-browser.d.ts +10 -0
- package/src/@ipld/car/dist/src/index-browser.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/index.d.ts +11 -0
- package/src/@ipld/car/dist/src/index.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/indexed-reader-browser.d.ts +5 -0
- package/src/@ipld/car/dist/src/indexed-reader-browser.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/indexed-reader.d.ts +152 -0
- package/src/@ipld/car/dist/src/indexed-reader.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/indexer.d.ts +95 -0
- package/src/@ipld/car/dist/src/indexer.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/iterator-channel.d.ts +7 -0
- package/src/@ipld/car/dist/src/iterator-channel.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/iterator.d.ts +174 -0
- package/src/@ipld/car/dist/src/iterator.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/promise-fs-opts.d.ts +28 -0
- package/src/@ipld/car/dist/src/promise-fs-opts.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/reader-browser.d.ts +151 -0
- package/src/@ipld/car/dist/src/reader-browser.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/reader.d.ts +40 -0
- package/src/@ipld/car/dist/src/reader.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/writer-browser.d.ts +155 -0
- package/src/@ipld/car/dist/src/writer-browser.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/writer.d.ts +45 -0
- package/src/@ipld/car/dist/src/writer.d.ts.map +1 -0
- package/src/@ipld/car/src/api.ts +90 -0
- package/src/@ipld/car/src/buffer-decoder.js +213 -0
- package/src/@ipld/car/src/buffer-reader-browser.js +144 -0
- package/src/@ipld/car/src/buffer-reader.js +51 -0
- package/src/@ipld/car/src/buffer-writer.js +286 -0
- package/src/@ipld/car/src/coding.ts +68 -0
- package/src/@ipld/car/src/decoder-common.js +82 -0
- package/src/@ipld/car/src/decoder.js +347 -0
- package/src/@ipld/car/src/encoder.js +76 -0
- package/src/@ipld/car/src/header-validator.js +214 -0
- package/src/@ipld/car/src/header.ipldsch +18 -0
- package/src/@ipld/car/src/index-browser.js +18 -0
- package/src/@ipld/car/src/index.js +21 -0
- package/src/@ipld/car/src/indexed-reader-browser.js +7 -0
- package/src/@ipld/car/src/indexed-reader.js +211 -0
- package/src/@ipld/car/src/indexer.js +130 -0
- package/src/@ipld/car/src/iterator-channel.js +91 -0
- package/src/@ipld/car/src/iterator.js +267 -0
- package/src/@ipld/car/src/promise-fs-opts.js +46 -0
- package/src/@ipld/car/src/reader-browser.js +194 -0
- package/src/@ipld/car/src/reader.js +54 -0
- package/src/@ipld/car/src/writer-browser.js +250 -0
- package/src/@ipld/car/src/writer.js +81 -0
- package/src/@ipld/dag-cbor/LICENSE +4 -0
- package/src/@ipld/dag-cbor/README.md +80 -0
- package/src/@ipld/dag-cbor/dist/index.min.js +3 -0
- package/src/@ipld/dag-cbor/dist/src/index.d.ts +67 -0
- package/src/@ipld/dag-cbor/dist/src/index.d.ts.map +1 -0
- package/src/@ipld/dag-cbor/src/index.js +147 -0
- package/src/@ipld/dag-json/LICENSE +4 -0
- package/src/@ipld/dag-json/README.md +58 -0
- package/src/@ipld/dag-json/dist/index.min.js +3 -0
- package/src/@ipld/dag-json/dist/src/index.d.ts +12 -0
- package/src/@ipld/dag-json/dist/src/index.d.ts.map +1 -0
- package/src/@ipld/dag-json/src/index.js +291 -0
- package/src/@web3-storage/pail/dist/src/batch/index.d.ts +53 -1
- package/src/@web3-storage/pail/dist/src/batch/index.d.ts.map +1 -1
- package/src/@web3-storage/pail/dist/src/batch/shard.d.ts +1 -1
- package/src/@web3-storage/pail/dist/src/batch/shard.d.ts.map +1 -1
- package/src/@web3-storage/pail/dist/src/block.d.ts +2 -2
- package/src/@web3-storage/pail/dist/src/block.d.ts.map +1 -1
- package/src/@web3-storage/pail/dist/src/clock/index.d.ts +2 -2
- package/src/@web3-storage/pail/dist/src/clock/index.d.ts.map +1 -1
- package/src/@web3-storage/pail/dist/src/crdt/batch/index.d.ts.map +1 -1
- package/src/@web3-storage/pail/dist/src/crdt/index.d.ts +2 -2
- package/src/@web3-storage/pail/dist/src/crdt/index.d.ts.map +1 -1
- package/src/@web3-storage/pail/dist/src/diff.d.ts +3 -3
- package/src/@web3-storage/pail/dist/src/diff.d.ts.map +1 -1
- package/src/@web3-storage/pail/dist/src/index.d.ts +1 -1
- package/src/@web3-storage/pail/dist/src/index.d.ts.map +1 -1
- package/src/@web3-storage/pail/dist/src/merge.d.ts.map +1 -1
- package/src/@web3-storage/pail/dist/src/shard.d.ts +4 -4
- package/src/@web3-storage/pail/dist/src/shard.d.ts.map +1 -1
- package/src/@web3-storage/pail/dist/tsconfig.tsbuildinfo +1 -1
- package/src/@web3-storage/pail/src/api.ts +1 -1
- package/src/@web3-storage/pail/src/clock/index.js +1 -1
- package/src/@web3-storage/pail/src/shard.js +1 -1
- package/src/cborg/.github/dependabot.yml +16 -0
- package/src/cborg/.github/workflows/test-and-release.yml +52 -0
- package/src/cborg/CHANGELOG.md +513 -0
- package/src/cborg/LICENSE +13 -0
- package/src/cborg/README.md +515 -0
- package/src/cborg/bench/bench.js +117 -0
- package/src/cborg/bench/json.js +124 -0
- package/src/cborg/bench/package.json +8 -0
- package/src/cborg/cborg/bin.js +189 -0
- package/src/cborg/cborg/common.js +28 -0
- package/src/cborg/cborg/decode.js +211 -0
- package/src/cborg/cborg/diagnostic.js +158 -0
- package/src/cborg/cborg/diagnostic_test.js +117 -0
- package/src/cborg/cborg/encode.js +466 -0
- package/src/cborg/cborg/index.js +33 -0
- package/src/cborg/cborg/is.js +106 -0
- package/src/cborg/cborg/length.js +62 -0
- package/src/cborg/example-bytestrings.js +180 -0
- package/src/cborg/example-json.js +6 -0
- package/src/cborg/example.js +5 -0
- package/src/cborg/interface.ts +59 -0
- package/src/cborg/json/decode.js +462 -0
- package/src/cborg/json/encode.js +302 -0
- package/src/cborg/json/json.js +4 -0
- package/src/cborg/taglib.js +75 -0
- package/src/cborg/test/appendix_a.js +647 -0
- package/src/cborg/test/common.js +18 -0
- package/src/cborg/test/node-test-bin.js +402 -0
- package/src/cborg/test/noop-bin-test.js +3 -0
- package/src/cborg/test/test-0uint.js +103 -0
- package/src/cborg/test/test-1negint.js +96 -0
- package/src/cborg/test/test-2bytes.js +198 -0
- package/src/cborg/test/test-3string.js +136 -0
- package/src/cborg/test/test-4array.js +93 -0
- package/src/cborg/test/test-5map.js +284 -0
- package/src/cborg/test/test-6tag.js +84 -0
- package/src/cborg/test/test-7float.js +131 -0
- package/src/cborg/test/test-bl.js +37 -0
- package/src/cborg/test/test-cbor-vectors.js +107 -0
- package/src/cborg/test/test-decode-errors.js +65 -0
- package/src/cborg/test/test-fuzz.js +42 -0
- package/src/cborg/test/test-json.js +219 -0
- package/src/cborg/test/test-length.js +65 -0
- package/src/cborg/test/test-partial.js +111 -0
- package/src/cborg/tsconfig.json +48 -0
- package/src/cborg/types/cborg/decode.d.ts +43 -0
- package/src/cborg/types/cborg/decode.d.ts.map +1 -0
- package/src/cborg/types/cborg/encode.d.ts +51 -0
- package/src/cborg/types/cborg/encode.d.ts.map +1 -0
- package/src/cborg/types/cborg/index.d.ts +26 -0
- package/src/cborg/types/cborg/index.d.ts.map +1 -0
- package/src/cborg/types/cborg/is.d.ts +6 -0
- package/src/cborg/types/cborg/is.d.ts.map +1 -0
- package/src/cborg/types/example.d.ts +2 -0
- package/src/cborg/types/example.d.ts.map +1 -0
- package/src/cborg/types/interface.d.ts +49 -0
- package/src/cborg/types/interface.d.ts.map +1 -0
- package/src/cborg/types/json/decode.d.ts +67 -0
- package/src/cborg/types/json/decode.d.ts.map +1 -0
- package/src/cborg/types/json/encode.d.ts +11 -0
- package/src/cborg/types/json/encode.d.ts.map +1 -0
- package/src/cborg/types/json/json.d.ts +6 -0
- package/src/cborg/types/json/json.d.ts.map +1 -0
- package/src/cborg/types/taglib.d.ts +18 -0
- package/src/cborg/types/taglib.d.ts.map +1 -0
- package/src/cborg/types/tsconfig.tsbuildinfo +1 -0
- package/src/cborg/types/utils/0uint.d.ts +102 -0
- package/src/cborg/types/utils/0uint.d.ts.map +1 -0
- package/src/cborg/types/utils/1negint.d.ts +59 -0
- package/src/cborg/types/utils/1negint.d.ts.map +1 -0
- package/src/cborg/types/utils/2bytes.d.ts +69 -0
- package/src/cborg/types/utils/2bytes.d.ts.map +1 -0
- package/src/cborg/types/utils/3string.d.ts +46 -0
- package/src/cborg/types/utils/3string.d.ts.map +1 -0
- package/src/cborg/types/utils/4array.d.ts +66 -0
- package/src/cborg/types/utils/4array.d.ts.map +1 -0
- package/src/cborg/types/utils/5map.d.ts +66 -0
- package/src/cborg/types/utils/5map.d.ts.map +1 -0
- package/src/cborg/types/utils/6tag.d.ts +62 -0
- package/src/cborg/types/utils/6tag.d.ts.map +1 -0
- package/src/cborg/types/utils/7float.d.ts +60 -0
- package/src/cborg/types/utils/7float.d.ts.map +1 -0
- package/src/cborg/types/utils/bl.d.ts +26 -0
- package/src/cborg/types/utils/bl.d.ts.map +1 -0
- package/src/cborg/types/utils/byte-utils.d.ts +53 -0
- package/src/cborg/types/utils/byte-utils.d.ts.map +1 -0
- package/src/cborg/types/utils/common.d.ts +8 -0
- package/src/cborg/types/utils/common.d.ts.map +1 -0
- package/src/cborg/types/utils/index.d.ts +13 -0
- package/src/cborg/types/utils/index.d.ts.map +1 -0
- package/src/cborg/types/utils/jump.d.ts +16 -0
- package/src/cborg/types/utils/jump.d.ts.map +1 -0
- package/src/cborg/types/utils/token.d.ts +59 -0
- package/src/cborg/types/utils/token.d.ts.map +1 -0
- package/src/cborg/utils/0uint.js +229 -0
- package/src/cborg/utils/1negint.js +111 -0
- package/src/cborg/utils/2bytes.js +135 -0
- package/src/cborg/utils/3string.js +90 -0
- package/src/cborg/utils/4array.js +114 -0
- package/src/cborg/utils/5map.js +113 -0
- package/src/cborg/utils/6tag.js +81 -0
- package/src/cborg/utils/7float.js +310 -0
- package/src/cborg/utils/bl.js +124 -0
- package/src/cborg/utils/byte-utils.js +417 -0
- package/src/cborg/utils/common.js +11 -0
- package/src/cborg/utils/index.js +12 -0
- package/src/cborg/utils/jump.js +222 -0
- package/src/cborg/utils/token.js +76 -0
- package/src/ipfs-unixfs-exporter/LICENSE +4 -0
- package/src/ipfs-unixfs-exporter/README.md +105 -0
- package/src/ipfs-unixfs-exporter/dist/index.min.js +3 -0
- package/src/ipfs-unixfs-exporter/dist/src/errors.d.ts +57 -0
- package/src/ipfs-unixfs-exporter/dist/src/errors.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/errors.js +73 -0
- package/src/ipfs-unixfs-exporter/dist/src/errors.js.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/index.d.ts +355 -0
- package/src/ipfs-unixfs-exporter/dist/src/index.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/index.js +197 -0
- package/src/ipfs-unixfs-exporter/dist/src/index.js.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-cbor.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-cbor.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-cbor.js +9 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-cbor.js.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-json.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-json.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-json.js +9 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-json.js.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/identity.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/identity.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/identity.js +38 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/identity.js.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/index.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/index.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/index.js +30 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/index.js.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/json.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/json.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/json.js +9 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/json.js.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/raw.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/raw.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/raw.js +37 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/raw.js.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/directory.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/directory.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/directory.js +29 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/directory.js.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/file.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/file.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/file.js +153 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/file.js.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/hamt-sharded-directory.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/hamt-sharded-directory.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/hamt-sharded-directory.js +59 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/hamt-sharded-directory.js.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/raw.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/raw.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/raw.js +25 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/raw.js.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/index.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/index.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/index.js +104 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/index.js.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/utils/extract-data-from-block.d.ts +3 -0
- package/src/ipfs-unixfs-exporter/dist/src/utils/extract-data-from-block.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/utils/extract-data-from-block.js +20 -0
- package/src/ipfs-unixfs-exporter/dist/src/utils/extract-data-from-block.js.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/utils/find-cid-in-shard.d.ts +6 -0
- package/src/ipfs-unixfs-exporter/dist/src/utils/find-cid-in-shard.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/utils/find-cid-in-shard.js +116 -0
- package/src/ipfs-unixfs-exporter/dist/src/utils/find-cid-in-shard.js.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/utils/resolve-object-path.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/dist/src/utils/resolve-object-path.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/utils/resolve-object-path.js +57 -0
- package/src/ipfs-unixfs-exporter/dist/src/utils/resolve-object-path.js.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/utils/validate-offset-and-length.d.ts +6 -0
- package/src/ipfs-unixfs-exporter/dist/src/utils/validate-offset-and-length.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/utils/validate-offset-and-length.js +30 -0
- package/src/ipfs-unixfs-exporter/dist/src/utils/validate-offset-and-length.js.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/typedoc-urls.json +58 -0
- package/src/ipfs-unixfs-exporter/src/errors.ts +87 -0
- package/src/ipfs-unixfs-exporter/src/index.ts +498 -0
- package/src/ipfs-unixfs-exporter/src/resolvers/dag-cbor.ts +12 -0
- package/src/ipfs-unixfs-exporter/src/resolvers/dag-json.ts +12 -0
- package/src/ipfs-unixfs-exporter/src/resolvers/identity.ts +49 -0
- package/src/ipfs-unixfs-exporter/src/resolvers/index.ts +35 -0
- package/src/ipfs-unixfs-exporter/src/resolvers/json.ts +12 -0
- package/src/ipfs-unixfs-exporter/src/resolvers/raw.ts +49 -0
- package/src/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/directory.ts +39 -0
- package/src/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/file.ts +198 -0
- package/src/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.ts +76 -0
- package/src/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/raw.ts +37 -0
- package/src/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/index.ts +121 -0
- package/src/ipfs-unixfs-exporter/src/utils/extract-data-from-block.ts +24 -0
- package/src/ipfs-unixfs-exporter/src/utils/find-cid-in-shard.ts +149 -0
- package/src/ipfs-unixfs-exporter/src/utils/resolve-object-path.ts +62 -0
- package/src/ipfs-unixfs-exporter/src/utils/validate-offset-and-length.ts +38 -0
|
@@ -0,0 +1,462 @@
|
|
|
1
|
+
// never reference the file directly to ensure the
|
|
2
|
+
// indepency of the json module
|
|
3
|
+
import { decode as _decode, decodeFirst as _decodeFirst } from "@fireproof/vendor/cborg"
|
|
4
|
+
import { Token, Type, decodeCodePointsArray } from "@fireproof/vendor/cborg/utils"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @typedef {import('../interface').DecodeOptions} DecodeOptions
|
|
8
|
+
* @typedef {import('../interface').DecodeTokenizer} DecodeTokenizer
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @implements {DecodeTokenizer}
|
|
13
|
+
*/
|
|
14
|
+
class Tokenizer {
|
|
15
|
+
/**
|
|
16
|
+
* @param {Uint8Array} data
|
|
17
|
+
* @param {DecodeOptions} options
|
|
18
|
+
*/
|
|
19
|
+
constructor (data, options) {
|
|
20
|
+
this._pos = 0
|
|
21
|
+
this.data = data
|
|
22
|
+
this.options = options
|
|
23
|
+
/** @type {string[]} */
|
|
24
|
+
this.modeStack = ['value']
|
|
25
|
+
this.lastToken = ''
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
pos () {
|
|
29
|
+
return this._pos
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @returns {boolean}
|
|
34
|
+
*/
|
|
35
|
+
done () {
|
|
36
|
+
return this._pos >= this.data.length
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @returns {number}
|
|
41
|
+
*/
|
|
42
|
+
ch () {
|
|
43
|
+
return this.data[this._pos]
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @returns {string}
|
|
48
|
+
*/
|
|
49
|
+
currentMode () {
|
|
50
|
+
return this.modeStack[this.modeStack.length - 1]
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
skipWhitespace () {
|
|
54
|
+
let c = this.ch()
|
|
55
|
+
// @ts-ignore
|
|
56
|
+
while (c === 32 /* ' ' */ || c === 9 /* '\t' */ || c === 13 /* '\r' */ || c === 10 /* '\n' */) {
|
|
57
|
+
c = this.data[++this._pos]
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @param {number[]} str
|
|
63
|
+
*/
|
|
64
|
+
expect (str) {
|
|
65
|
+
if (this.data.length - this._pos < str.length) {
|
|
66
|
+
throw new Error(`${this.options.decodeErrPrefix} unexpected end of input at position ${this._pos}`)
|
|
67
|
+
}
|
|
68
|
+
for (let i = 0; i < str.length; i++) {
|
|
69
|
+
if (this.data[this._pos++] !== str[i]) {
|
|
70
|
+
throw new Error(`${this.options.decodeErrPrefix} unexpected token at position ${this._pos}, expected to find '${String.fromCharCode(...str)}'`)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
parseNumber () {
|
|
76
|
+
const startPos = this._pos
|
|
77
|
+
let negative = false
|
|
78
|
+
let float = false
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @param {number[]} chars
|
|
82
|
+
*/
|
|
83
|
+
const swallow = (chars) => {
|
|
84
|
+
while (!this.done()) {
|
|
85
|
+
const ch = this.ch()
|
|
86
|
+
if (chars.includes(ch)) {
|
|
87
|
+
this._pos++
|
|
88
|
+
} else {
|
|
89
|
+
break
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// lead
|
|
95
|
+
if (this.ch() === 45) { // '-'
|
|
96
|
+
negative = true
|
|
97
|
+
this._pos++
|
|
98
|
+
}
|
|
99
|
+
if (this.ch() === 48) { // '0'
|
|
100
|
+
this._pos++
|
|
101
|
+
if (this.ch() === 46) { // '.'
|
|
102
|
+
this._pos++
|
|
103
|
+
float = true
|
|
104
|
+
} else {
|
|
105
|
+
return new Token(Type.uint, 0, this._pos - startPos)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
swallow([48, 49, 50, 51, 52, 53, 54, 55, 56, 57]) // DIGIT
|
|
109
|
+
if (negative && this._pos === startPos + 1) {
|
|
110
|
+
throw new Error(`${this.options.decodeErrPrefix} unexpected token at position ${this._pos}`)
|
|
111
|
+
}
|
|
112
|
+
if (!this.done() && this.ch() === 46) { // '.'
|
|
113
|
+
if (float) {
|
|
114
|
+
throw new Error(`${this.options.decodeErrPrefix} unexpected token at position ${this._pos}`)
|
|
115
|
+
}
|
|
116
|
+
float = true
|
|
117
|
+
this._pos++
|
|
118
|
+
swallow([48, 49, 50, 51, 52, 53, 54, 55, 56, 57]) // DIGIT
|
|
119
|
+
}
|
|
120
|
+
if (!this.done() && (this.ch() === 101 || this.ch() === 69)) { // '[eE]'
|
|
121
|
+
float = true
|
|
122
|
+
this._pos++
|
|
123
|
+
if (!this.done() && (this.ch() === 43 || this.ch() === 45)) { // '+', '-'
|
|
124
|
+
this._pos++
|
|
125
|
+
}
|
|
126
|
+
swallow([48, 49, 50, 51, 52, 53, 54, 55, 56, 57]) // DIGIT
|
|
127
|
+
}
|
|
128
|
+
// @ts-ignore
|
|
129
|
+
const numStr = String.fromCharCode.apply(null, this.data.subarray(startPos, this._pos))
|
|
130
|
+
const num = parseFloat(numStr)
|
|
131
|
+
if (float) {
|
|
132
|
+
return new Token(Type.float, num, this._pos - startPos)
|
|
133
|
+
}
|
|
134
|
+
if (this.options.allowBigInt !== true || Number.isSafeInteger(num)) {
|
|
135
|
+
return new Token(num >= 0 ? Type.uint : Type.negint, num, this._pos - startPos)
|
|
136
|
+
}
|
|
137
|
+
return new Token(num >= 0 ? Type.uint : Type.negint, BigInt(numStr), this._pos - startPos)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* @returns {Token}
|
|
142
|
+
*/
|
|
143
|
+
parseString () {
|
|
144
|
+
/* c8 ignore next 4 */
|
|
145
|
+
if (this.ch() !== 34) { // '"'
|
|
146
|
+
// this would be a programming error
|
|
147
|
+
throw new Error(`${this.options.decodeErrPrefix} unexpected character at position ${this._pos}; this shouldn't happen`)
|
|
148
|
+
}
|
|
149
|
+
this._pos++
|
|
150
|
+
|
|
151
|
+
// check for simple fast-path, all printable ascii, no escapes
|
|
152
|
+
// >0x10000 elements may fail fn.apply() (http://stackoverflow.com/a/22747272/680742)
|
|
153
|
+
for (let i = this._pos, l = 0; i < this.data.length && l < 0x10000; i++, l++) {
|
|
154
|
+
const ch = this.data[i]
|
|
155
|
+
if (ch === 92 || ch < 32 || ch >= 128) { // '\', ' ', control-chars or non-trivial
|
|
156
|
+
break
|
|
157
|
+
}
|
|
158
|
+
if (ch === 34) { // '"'
|
|
159
|
+
// @ts-ignore
|
|
160
|
+
const str = String.fromCharCode.apply(null, this.data.subarray(this._pos, i))
|
|
161
|
+
this._pos = i + 1
|
|
162
|
+
return new Token(Type.string, str, l)
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const startPos = this._pos
|
|
167
|
+
const chars = []
|
|
168
|
+
|
|
169
|
+
const readu4 = () => {
|
|
170
|
+
if (this._pos + 4 >= this.data.length) {
|
|
171
|
+
throw new Error(`${this.options.decodeErrPrefix} unexpected end of unicode escape sequence at position ${this._pos}`)
|
|
172
|
+
}
|
|
173
|
+
let u4 = 0
|
|
174
|
+
for (let i = 0; i < 4; i++) {
|
|
175
|
+
let ch = this.ch()
|
|
176
|
+
if (ch >= 48 && ch <= 57) { // '0' && '9'
|
|
177
|
+
ch -= 48
|
|
178
|
+
} else if (ch >= 97 && ch <= 102) { // 'a' && 'f'
|
|
179
|
+
ch = ch - 97 + 10
|
|
180
|
+
} else if (ch >= 65 && ch <= 70) { // 'A' && 'F'
|
|
181
|
+
ch = ch - 65 + 10
|
|
182
|
+
} else {
|
|
183
|
+
throw new Error(`${this.options.decodeErrPrefix} unexpected unicode escape character at position ${this._pos}`)
|
|
184
|
+
}
|
|
185
|
+
u4 = u4 * 16 + ch
|
|
186
|
+
this._pos++
|
|
187
|
+
}
|
|
188
|
+
return u4
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// mostly taken from feross/buffer and adjusted to fit
|
|
192
|
+
const readUtf8Char = () => {
|
|
193
|
+
const firstByte = this.ch()
|
|
194
|
+
let codePoint = null
|
|
195
|
+
/* c8 ignore next 1 */
|
|
196
|
+
let bytesPerSequence = (firstByte > 0xef) ? 4 : (firstByte > 0xdf) ? 3 : (firstByte > 0xbf) ? 2 : 1
|
|
197
|
+
|
|
198
|
+
if (this._pos + bytesPerSequence > this.data.length) {
|
|
199
|
+
throw new Error(`${this.options.decodeErrPrefix} unexpected unicode sequence at position ${this._pos}`)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
let secondByte, thirdByte, fourthByte, tempCodePoint
|
|
203
|
+
|
|
204
|
+
switch (bytesPerSequence) {
|
|
205
|
+
/* c8 ignore next 6 */
|
|
206
|
+
// this case is dealt with by the caller function
|
|
207
|
+
case 1:
|
|
208
|
+
if (firstByte < 0x80) {
|
|
209
|
+
codePoint = firstByte
|
|
210
|
+
}
|
|
211
|
+
break
|
|
212
|
+
case 2:
|
|
213
|
+
secondByte = this.data[this._pos + 1]
|
|
214
|
+
if ((secondByte & 0xc0) === 0x80) {
|
|
215
|
+
tempCodePoint = (firstByte & 0x1f) << 0x6 | (secondByte & 0x3f)
|
|
216
|
+
if (tempCodePoint > 0x7f) {
|
|
217
|
+
codePoint = tempCodePoint
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
break
|
|
221
|
+
case 3:
|
|
222
|
+
secondByte = this.data[this._pos + 1]
|
|
223
|
+
thirdByte = this.data[this._pos + 2]
|
|
224
|
+
if ((secondByte & 0xc0) === 0x80 && (thirdByte & 0xc0) === 0x80) {
|
|
225
|
+
tempCodePoint = (firstByte & 0xf) << 0xc | (secondByte & 0x3f) << 0x6 | (thirdByte & 0x3f)
|
|
226
|
+
/* c8 ignore next 3 */
|
|
227
|
+
if (tempCodePoint > 0x7ff && (tempCodePoint < 0xd800 || tempCodePoint > 0xdfff)) {
|
|
228
|
+
codePoint = tempCodePoint
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
break
|
|
232
|
+
case 4:
|
|
233
|
+
secondByte = this.data[this._pos + 1]
|
|
234
|
+
thirdByte = this.data[this._pos + 2]
|
|
235
|
+
fourthByte = this.data[this._pos + 3]
|
|
236
|
+
if ((secondByte & 0xc0) === 0x80 && (thirdByte & 0xc0) === 0x80 && (fourthByte & 0xc0) === 0x80) {
|
|
237
|
+
tempCodePoint = (firstByte & 0xf) << 0x12 | (secondByte & 0x3f) << 0xc | (thirdByte & 0x3f) << 0x6 | (fourthByte & 0x3f)
|
|
238
|
+
if (tempCodePoint > 0xffff && tempCodePoint < 0x110000) {
|
|
239
|
+
codePoint = tempCodePoint
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/* c8 ignore next 5 */
|
|
245
|
+
if (codePoint === null) {
|
|
246
|
+
// we did not generate a valid codePoint so insert a
|
|
247
|
+
// replacement char (U+FFFD) and advance only 1 byte
|
|
248
|
+
codePoint = 0xfffd
|
|
249
|
+
bytesPerSequence = 1
|
|
250
|
+
} else if (codePoint > 0xffff) {
|
|
251
|
+
// encode to utf16 (surrogate pair dance)
|
|
252
|
+
codePoint -= 0x10000
|
|
253
|
+
chars.push(codePoint >>> 10 & 0x3ff | 0xd800)
|
|
254
|
+
codePoint = 0xdc00 | codePoint & 0x3ff
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
chars.push(codePoint)
|
|
258
|
+
this._pos += bytesPerSequence
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// TODO: could take the approach of a quick first scan for special chars like encoding/json/decode.go#unquoteBytes
|
|
262
|
+
// and converting all of the ascii chars from the base array in bulk
|
|
263
|
+
while (!this.done()) {
|
|
264
|
+
const ch = this.ch()
|
|
265
|
+
let ch1
|
|
266
|
+
switch (ch) {
|
|
267
|
+
case 92: // '\'
|
|
268
|
+
this._pos++
|
|
269
|
+
if (this.done()) {
|
|
270
|
+
throw new Error(`${this.options.decodeErrPrefix} unexpected string termination at position ${this._pos}`)
|
|
271
|
+
}
|
|
272
|
+
ch1 = this.ch()
|
|
273
|
+
this._pos++
|
|
274
|
+
switch (ch1) {
|
|
275
|
+
case 34: // '"'
|
|
276
|
+
case 39: // '\''
|
|
277
|
+
case 92: // '\'
|
|
278
|
+
case 47: // '/'
|
|
279
|
+
chars.push(ch1)
|
|
280
|
+
break
|
|
281
|
+
case 98: // 'b'
|
|
282
|
+
chars.push(8)
|
|
283
|
+
break
|
|
284
|
+
case 116: // 't'
|
|
285
|
+
chars.push(9)
|
|
286
|
+
break
|
|
287
|
+
case 110: // 'n'
|
|
288
|
+
chars.push(10)
|
|
289
|
+
break
|
|
290
|
+
case 102: // 'f'
|
|
291
|
+
chars.push(12)
|
|
292
|
+
break
|
|
293
|
+
case 114: // 'r'
|
|
294
|
+
chars.push(13)
|
|
295
|
+
break
|
|
296
|
+
case 117: // 'u'
|
|
297
|
+
chars.push(readu4())
|
|
298
|
+
break
|
|
299
|
+
default:
|
|
300
|
+
throw new Error(`${this.options.decodeErrPrefix} unexpected string escape character at position ${this._pos}`)
|
|
301
|
+
}
|
|
302
|
+
break
|
|
303
|
+
case 34: // '"'
|
|
304
|
+
this._pos++
|
|
305
|
+
return new Token(Type.string, decodeCodePointsArray(chars), this._pos - startPos)
|
|
306
|
+
default:
|
|
307
|
+
if (ch < 32) { // ' '
|
|
308
|
+
throw new Error(`${this.options.decodeErrPrefix} invalid control character at position ${this._pos}`)
|
|
309
|
+
} else if (ch < 0x80) {
|
|
310
|
+
chars.push(ch)
|
|
311
|
+
this._pos++
|
|
312
|
+
} else {
|
|
313
|
+
readUtf8Char()
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
throw new Error(`${this.options.decodeErrPrefix} unexpected end of string at position ${this._pos}`)
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* @returns {Token}
|
|
323
|
+
*/
|
|
324
|
+
parseValue () {
|
|
325
|
+
switch (this.ch()) {
|
|
326
|
+
case 123: // '{'
|
|
327
|
+
this.modeStack.push('obj-start')
|
|
328
|
+
this._pos++
|
|
329
|
+
return new Token(Type.map, Infinity, 1)
|
|
330
|
+
case 91: // '['
|
|
331
|
+
this.modeStack.push('array-start')
|
|
332
|
+
this._pos++
|
|
333
|
+
return new Token(Type.array, Infinity, 1)
|
|
334
|
+
case 34: { // '"'
|
|
335
|
+
return this.parseString()
|
|
336
|
+
}
|
|
337
|
+
case 110: // 'n' / null
|
|
338
|
+
this.expect([110, 117, 108, 108]) // 'null'
|
|
339
|
+
return new Token(Type.null, null, 4)
|
|
340
|
+
case 102: // 'f' / // false
|
|
341
|
+
this.expect([102, 97, 108, 115, 101]) // 'false'
|
|
342
|
+
return new Token(Type.false, false, 5)
|
|
343
|
+
case 116: // 't' / // true
|
|
344
|
+
this.expect([116, 114, 117, 101]) // 'true'
|
|
345
|
+
return new Token(Type.true, true, 4)
|
|
346
|
+
case 45: // '-'
|
|
347
|
+
case 48: // '0'
|
|
348
|
+
case 49: // '1'
|
|
349
|
+
case 50: // '2'
|
|
350
|
+
case 51: // '3'
|
|
351
|
+
case 52: // '4'
|
|
352
|
+
case 53: // '5'
|
|
353
|
+
case 54: // '6'
|
|
354
|
+
case 55: // '7'
|
|
355
|
+
case 56: // '8'
|
|
356
|
+
case 57: // '9'
|
|
357
|
+
return this.parseNumber()
|
|
358
|
+
default:
|
|
359
|
+
throw new Error(`${this.options.decodeErrPrefix} unexpected character at position ${this._pos}`)
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* @returns {Token}
|
|
365
|
+
*/
|
|
366
|
+
next () {
|
|
367
|
+
this.skipWhitespace()
|
|
368
|
+
switch (this.currentMode()) {
|
|
369
|
+
case 'value':
|
|
370
|
+
this.modeStack.pop()
|
|
371
|
+
return this.parseValue()
|
|
372
|
+
case 'array-value': {
|
|
373
|
+
this.modeStack.pop()
|
|
374
|
+
if (this.ch() === 93) { // ']'
|
|
375
|
+
this._pos++
|
|
376
|
+
this.skipWhitespace()
|
|
377
|
+
return new Token(Type.break, undefined, 1)
|
|
378
|
+
}
|
|
379
|
+
if (this.ch() !== 44) { // ','
|
|
380
|
+
throw new Error(`${this.options.decodeErrPrefix} unexpected character at position ${this._pos}, was expecting array delimiter but found '${String.fromCharCode(this.ch())}'`)
|
|
381
|
+
}
|
|
382
|
+
this._pos++
|
|
383
|
+
this.modeStack.push('array-value')
|
|
384
|
+
this.skipWhitespace()
|
|
385
|
+
return this.parseValue()
|
|
386
|
+
}
|
|
387
|
+
case 'array-start': {
|
|
388
|
+
this.modeStack.pop()
|
|
389
|
+
if (this.ch() === 93) { // ']'
|
|
390
|
+
this._pos++
|
|
391
|
+
this.skipWhitespace()
|
|
392
|
+
return new Token(Type.break, undefined, 1)
|
|
393
|
+
}
|
|
394
|
+
this.modeStack.push('array-value')
|
|
395
|
+
this.skipWhitespace()
|
|
396
|
+
return this.parseValue()
|
|
397
|
+
}
|
|
398
|
+
// @ts-ignore
|
|
399
|
+
case 'obj-key':
|
|
400
|
+
if (this.ch() === 125) { // '}'
|
|
401
|
+
this.modeStack.pop()
|
|
402
|
+
this._pos++
|
|
403
|
+
this.skipWhitespace()
|
|
404
|
+
return new Token(Type.break, undefined, 1)
|
|
405
|
+
}
|
|
406
|
+
if (this.ch() !== 44) { // ','
|
|
407
|
+
throw new Error(`${this.options.decodeErrPrefix} unexpected character at position ${this._pos}, was expecting object delimiter but found '${String.fromCharCode(this.ch())}'`)
|
|
408
|
+
}
|
|
409
|
+
this._pos++
|
|
410
|
+
this.skipWhitespace()
|
|
411
|
+
case 'obj-start': { // eslint-disable-line no-fallthrough
|
|
412
|
+
this.modeStack.pop()
|
|
413
|
+
if (this.ch() === 125) { // '}'
|
|
414
|
+
this._pos++
|
|
415
|
+
this.skipWhitespace()
|
|
416
|
+
return new Token(Type.break, undefined, 1)
|
|
417
|
+
}
|
|
418
|
+
const token = this.parseString()
|
|
419
|
+
this.skipWhitespace()
|
|
420
|
+
if (this.ch() !== 58) { // ':'
|
|
421
|
+
throw new Error(`${this.options.decodeErrPrefix} unexpected character at position ${this._pos}, was expecting key/value delimiter ':' but found '${String.fromCharCode(this.ch())}'`)
|
|
422
|
+
}
|
|
423
|
+
this._pos++
|
|
424
|
+
this.modeStack.push('obj-value')
|
|
425
|
+
return token
|
|
426
|
+
}
|
|
427
|
+
case 'obj-value': {
|
|
428
|
+
this.modeStack.pop()
|
|
429
|
+
this.modeStack.push('obj-key')
|
|
430
|
+
this.skipWhitespace()
|
|
431
|
+
return this.parseValue()
|
|
432
|
+
}
|
|
433
|
+
/* c8 ignore next 2 */
|
|
434
|
+
default:
|
|
435
|
+
throw new Error(`${this.options.decodeErrPrefix} unexpected parse state at position ${this._pos}; this shouldn't happen`)
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* @param {Uint8Array} data
|
|
442
|
+
* @param {DecodeOptions} [options]
|
|
443
|
+
* @returns {any}
|
|
444
|
+
*/
|
|
445
|
+
function decode (data, options) {
|
|
446
|
+
options = { decodeErrPrefix: 'JSON decode error:', ...options }
|
|
447
|
+
options.tokenizer = options.tokenizer || new Tokenizer(data, options)
|
|
448
|
+
return _decode(data, options)
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* @param {Uint8Array} data
|
|
453
|
+
* @param {DecodeOptions} [options]
|
|
454
|
+
* @returns {[any, Uint8Array]}
|
|
455
|
+
*/
|
|
456
|
+
function decodeFirst (data, options) {
|
|
457
|
+
options = { decodeErrPrefix: 'JSON decode error:', ...options }
|
|
458
|
+
options.tokenizer = options.tokenizer || new Tokenizer(data, options)
|
|
459
|
+
return _decodeFirst(data, options)
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
export { decode, decodeFirst, Tokenizer }
|