@fireproof/vendor 1.0.3 → 1.1.0-dev
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 +4 -97
- package/src/@web3-storage/pail/dist/src/batch/index.d.ts +1 -53
- 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/@ipld/car/LICENSE +0 -4
- package/src/@ipld/car/README.md +0 -1132
- package/src/@ipld/car/dist/index.min.js +0 -5
- package/src/@ipld/car/dist/src/api.d.ts +0 -72
- package/src/@ipld/car/dist/src/api.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/buffer-decoder.d.ts +0 -67
- package/src/@ipld/car/dist/src/buffer-decoder.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/buffer-reader-browser.d.ts +0 -116
- package/src/@ipld/car/dist/src/buffer-reader-browser.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/buffer-reader.d.ts +0 -31
- package/src/@ipld/car/dist/src/buffer-reader.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/buffer-writer.d.ts +0 -86
- package/src/@ipld/car/dist/src/buffer-writer.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/coding.d.ts +0 -49
- package/src/@ipld/car/dist/src/coding.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/decoder-common.d.ts +0 -43
- package/src/@ipld/car/dist/src/decoder-common.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/decoder.d.ts +0 -87
- package/src/@ipld/car/dist/src/decoder.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/encoder.d.ts +0 -17
- package/src/@ipld/car/dist/src/encoder.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/header-validator.d.ts +0 -5
- package/src/@ipld/car/dist/src/header-validator.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/index-browser.d.ts +0 -10
- package/src/@ipld/car/dist/src/index-browser.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/index.d.ts +0 -11
- package/src/@ipld/car/dist/src/index.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/indexed-reader-browser.d.ts +0 -5
- package/src/@ipld/car/dist/src/indexed-reader-browser.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/indexed-reader.d.ts +0 -152
- package/src/@ipld/car/dist/src/indexed-reader.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/indexer.d.ts +0 -95
- package/src/@ipld/car/dist/src/indexer.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/iterator-channel.d.ts +0 -7
- package/src/@ipld/car/dist/src/iterator-channel.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/iterator.d.ts +0 -174
- package/src/@ipld/car/dist/src/iterator.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/reader-browser.d.ts +0 -151
- package/src/@ipld/car/dist/src/reader-browser.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/reader.d.ts +0 -35
- package/src/@ipld/car/dist/src/reader.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/writer-browser.d.ts +0 -155
- package/src/@ipld/car/dist/src/writer-browser.d.ts.map +0 -1
- package/src/@ipld/car/dist/src/writer.d.ts +0 -45
- package/src/@ipld/car/dist/src/writer.d.ts.map +0 -1
- package/src/@ipld/car/src/api.ts +0 -90
- package/src/@ipld/car/src/buffer-decoder.js +0 -213
- package/src/@ipld/car/src/buffer-reader-browser.js +0 -144
- package/src/@ipld/car/src/buffer-reader.js +0 -51
- package/src/@ipld/car/src/buffer-writer.js +0 -286
- package/src/@ipld/car/src/coding.ts +0 -68
- package/src/@ipld/car/src/decoder-common.js +0 -82
- package/src/@ipld/car/src/decoder.js +0 -347
- package/src/@ipld/car/src/encoder.js +0 -76
- package/src/@ipld/car/src/header-validator.js +0 -214
- package/src/@ipld/car/src/header.ipldsch +0 -18
- package/src/@ipld/car/src/index-browser.js +0 -18
- package/src/@ipld/car/src/index.js +0 -21
- package/src/@ipld/car/src/indexed-reader-browser.js +0 -7
- package/src/@ipld/car/src/indexed-reader.js +0 -211
- package/src/@ipld/car/src/indexer.js +0 -130
- package/src/@ipld/car/src/iterator-channel.js +0 -91
- package/src/@ipld/car/src/iterator.js +0 -267
- package/src/@ipld/car/src/reader-browser.js +0 -194
- package/src/@ipld/car/src/reader.js +0 -73
- package/src/@ipld/car/src/writer-browser.js +0 -250
- package/src/@ipld/car/src/writer.js +0 -84
- package/src/@ipld/dag-cbor/LICENSE +0 -4
- package/src/@ipld/dag-cbor/README.md +0 -80
- package/src/@ipld/dag-cbor/dist/index.min.js +0 -3
- package/src/@ipld/dag-cbor/dist/src/index.d.ts +0 -67
- package/src/@ipld/dag-cbor/dist/src/index.d.ts.map +0 -1
- package/src/@ipld/dag-cbor/src/index.js +0 -147
- package/src/@ipld/dag-json/LICENSE +0 -4
- package/src/@ipld/dag-json/README.md +0 -58
- package/src/@ipld/dag-json/dist/index.min.js +0 -3
- package/src/@ipld/dag-json/dist/src/index.d.ts +0 -12
- package/src/@ipld/dag-json/dist/src/index.d.ts.map +0 -1
- package/src/@ipld/dag-json/src/index.js +0 -291
- package/src/cborg/.github/dependabot.yml +0 -16
- package/src/cborg/.github/workflows/test-and-release.yml +0 -52
- package/src/cborg/CHANGELOG.md +0 -513
- package/src/cborg/LICENSE +0 -13
- package/src/cborg/README.md +0 -515
- package/src/cborg/bench/bench.js +0 -117
- package/src/cborg/bench/json.js +0 -124
- package/src/cborg/bench/package.json +0 -8
- package/src/cborg/cborg/bin.js +0 -189
- package/src/cborg/cborg/common.js +0 -28
- package/src/cborg/cborg/decode.js +0 -211
- package/src/cborg/cborg/diagnostic.js +0 -158
- package/src/cborg/cborg/diagnostic_test.js +0 -117
- package/src/cborg/cborg/encode.js +0 -466
- package/src/cborg/cborg/index.js +0 -33
- package/src/cborg/cborg/is.js +0 -106
- package/src/cborg/cborg/length.js +0 -62
- package/src/cborg/example-bytestrings.js +0 -180
- package/src/cborg/example-json.js +0 -6
- package/src/cborg/example.js +0 -5
- package/src/cborg/interface.ts +0 -59
- package/src/cborg/json/decode.js +0 -462
- package/src/cborg/json/encode.js +0 -302
- package/src/cborg/json/json.js +0 -4
- package/src/cborg/taglib.js +0 -75
- package/src/cborg/test/appendix_a.js +0 -647
- package/src/cborg/test/common.js +0 -18
- package/src/cborg/test/node-test-bin.js +0 -402
- package/src/cborg/test/noop-bin-test.js +0 -3
- package/src/cborg/test/test-0uint.js +0 -103
- package/src/cborg/test/test-1negint.js +0 -96
- package/src/cborg/test/test-2bytes.js +0 -198
- package/src/cborg/test/test-3string.js +0 -136
- package/src/cborg/test/test-4array.js +0 -93
- package/src/cborg/test/test-5map.js +0 -284
- package/src/cborg/test/test-6tag.js +0 -84
- package/src/cborg/test/test-7float.js +0 -131
- package/src/cborg/test/test-bl.js +0 -37
- package/src/cborg/test/test-cbor-vectors.js +0 -107
- package/src/cborg/test/test-decode-errors.js +0 -65
- package/src/cborg/test/test-fuzz.js +0 -42
- package/src/cborg/test/test-json.js +0 -219
- package/src/cborg/test/test-length.js +0 -65
- package/src/cborg/test/test-partial.js +0 -111
- package/src/cborg/tsconfig.json +0 -48
- package/src/cborg/types/cborg/decode.d.ts +0 -43
- package/src/cborg/types/cborg/decode.d.ts.map +0 -1
- package/src/cborg/types/cborg/encode.d.ts +0 -51
- package/src/cborg/types/cborg/encode.d.ts.map +0 -1
- package/src/cborg/types/cborg/index.d.ts +0 -26
- package/src/cborg/types/cborg/index.d.ts.map +0 -1
- package/src/cborg/types/cborg/is.d.ts +0 -6
- package/src/cborg/types/cborg/is.d.ts.map +0 -1
- package/src/cborg/types/example.d.ts +0 -2
- package/src/cborg/types/example.d.ts.map +0 -1
- package/src/cborg/types/interface.d.ts +0 -49
- package/src/cborg/types/interface.d.ts.map +0 -1
- package/src/cborg/types/json/decode.d.ts +0 -67
- package/src/cborg/types/json/decode.d.ts.map +0 -1
- package/src/cborg/types/json/encode.d.ts +0 -11
- package/src/cborg/types/json/encode.d.ts.map +0 -1
- package/src/cborg/types/json/json.d.ts +0 -6
- package/src/cborg/types/json/json.d.ts.map +0 -1
- package/src/cborg/types/taglib.d.ts +0 -18
- package/src/cborg/types/taglib.d.ts.map +0 -1
- package/src/cborg/types/tsconfig.tsbuildinfo +0 -1
- package/src/cborg/types/utils/0uint.d.ts +0 -102
- package/src/cborg/types/utils/0uint.d.ts.map +0 -1
- package/src/cborg/types/utils/1negint.d.ts +0 -59
- package/src/cborg/types/utils/1negint.d.ts.map +0 -1
- package/src/cborg/types/utils/2bytes.d.ts +0 -69
- package/src/cborg/types/utils/2bytes.d.ts.map +0 -1
- package/src/cborg/types/utils/3string.d.ts +0 -46
- package/src/cborg/types/utils/3string.d.ts.map +0 -1
- package/src/cborg/types/utils/4array.d.ts +0 -66
- package/src/cborg/types/utils/4array.d.ts.map +0 -1
- package/src/cborg/types/utils/5map.d.ts +0 -66
- package/src/cborg/types/utils/5map.d.ts.map +0 -1
- package/src/cborg/types/utils/6tag.d.ts +0 -62
- package/src/cborg/types/utils/6tag.d.ts.map +0 -1
- package/src/cborg/types/utils/7float.d.ts +0 -60
- package/src/cborg/types/utils/7float.d.ts.map +0 -1
- package/src/cborg/types/utils/bl.d.ts +0 -26
- package/src/cborg/types/utils/bl.d.ts.map +0 -1
- package/src/cborg/types/utils/byte-utils.d.ts +0 -53
- package/src/cborg/types/utils/byte-utils.d.ts.map +0 -1
- package/src/cborg/types/utils/common.d.ts +0 -8
- package/src/cborg/types/utils/common.d.ts.map +0 -1
- package/src/cborg/types/utils/index.d.ts +0 -13
- package/src/cborg/types/utils/index.d.ts.map +0 -1
- package/src/cborg/types/utils/jump.d.ts +0 -16
- package/src/cborg/types/utils/jump.d.ts.map +0 -1
- package/src/cborg/types/utils/token.d.ts +0 -59
- package/src/cborg/types/utils/token.d.ts.map +0 -1
- package/src/cborg/utils/0uint.js +0 -229
- package/src/cborg/utils/1negint.js +0 -111
- package/src/cborg/utils/2bytes.js +0 -135
- package/src/cborg/utils/3string.js +0 -90
- package/src/cborg/utils/4array.js +0 -114
- package/src/cborg/utils/5map.js +0 -113
- package/src/cborg/utils/6tag.js +0 -81
- package/src/cborg/utils/7float.js +0 -310
- package/src/cborg/utils/bl.js +0 -124
- package/src/cborg/utils/byte-utils.js +0 -417
- package/src/cborg/utils/common.js +0 -11
- package/src/cborg/utils/index.js +0 -12
- package/src/cborg/utils/jump.js +0 -222
- package/src/cborg/utils/token.js +0 -76
- package/src/ipfs-unixfs-exporter/LICENSE +0 -4
- package/src/ipfs-unixfs-exporter/README.md +0 -105
- package/src/ipfs-unixfs-exporter/dist/index.min.js +0 -3
- package/src/ipfs-unixfs-exporter/dist/src/errors.d.ts +0 -57
- package/src/ipfs-unixfs-exporter/dist/src/errors.d.ts.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/errors.js +0 -73
- package/src/ipfs-unixfs-exporter/dist/src/errors.js.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/index.d.ts +0 -355
- package/src/ipfs-unixfs-exporter/dist/src/index.d.ts.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/index.js +0 -197
- package/src/ipfs-unixfs-exporter/dist/src/index.js.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-cbor.d.ts +0 -4
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-cbor.d.ts.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-cbor.js +0 -9
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-cbor.js.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-json.d.ts +0 -4
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-json.d.ts.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-json.js +0 -9
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-json.js.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/identity.d.ts +0 -4
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/identity.d.ts.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/identity.js +0 -38
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/identity.js.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/index.d.ts +0 -4
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/index.d.ts.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/index.js +0 -30
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/index.js.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/json.d.ts +0 -4
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/json.d.ts.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/json.js +0 -9
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/json.js.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/raw.d.ts +0 -4
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/raw.d.ts.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/raw.js +0 -37
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/raw.js.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/directory.d.ts +0 -4
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/directory.d.ts.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/directory.js +0 -29
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/directory.js.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/file.d.ts +0 -4
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/file.d.ts.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/file.js +0 -153
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/file.js.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/hamt-sharded-directory.d.ts +0 -4
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/hamt-sharded-directory.d.ts.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/hamt-sharded-directory.js +0 -59
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/hamt-sharded-directory.js.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/raw.d.ts +0 -4
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/raw.d.ts.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/raw.js +0 -25
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/raw.js.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/index.d.ts +0 -4
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/index.d.ts.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/index.js +0 -104
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/index.js.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/utils/extract-data-from-block.d.ts +0 -3
- package/src/ipfs-unixfs-exporter/dist/src/utils/extract-data-from-block.d.ts.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/utils/extract-data-from-block.js +0 -20
- package/src/ipfs-unixfs-exporter/dist/src/utils/extract-data-from-block.js.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/utils/find-cid-in-shard.d.ts +0 -6
- package/src/ipfs-unixfs-exporter/dist/src/utils/find-cid-in-shard.d.ts.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/utils/find-cid-in-shard.js +0 -116
- package/src/ipfs-unixfs-exporter/dist/src/utils/find-cid-in-shard.js.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/utils/resolve-object-path.d.ts +0 -4
- package/src/ipfs-unixfs-exporter/dist/src/utils/resolve-object-path.d.ts.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/utils/resolve-object-path.js +0 -57
- package/src/ipfs-unixfs-exporter/dist/src/utils/resolve-object-path.js.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/utils/validate-offset-and-length.d.ts +0 -6
- package/src/ipfs-unixfs-exporter/dist/src/utils/validate-offset-and-length.d.ts.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/src/utils/validate-offset-and-length.js +0 -30
- package/src/ipfs-unixfs-exporter/dist/src/utils/validate-offset-and-length.js.map +0 -1
- package/src/ipfs-unixfs-exporter/dist/typedoc-urls.json +0 -58
- package/src/ipfs-unixfs-exporter/src/errors.ts +0 -87
- package/src/ipfs-unixfs-exporter/src/index.ts +0 -498
- package/src/ipfs-unixfs-exporter/src/resolvers/dag-cbor.ts +0 -12
- package/src/ipfs-unixfs-exporter/src/resolvers/dag-json.ts +0 -12
- package/src/ipfs-unixfs-exporter/src/resolvers/identity.ts +0 -49
- package/src/ipfs-unixfs-exporter/src/resolvers/index.ts +0 -35
- package/src/ipfs-unixfs-exporter/src/resolvers/json.ts +0 -12
- package/src/ipfs-unixfs-exporter/src/resolvers/raw.ts +0 -49
- package/src/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/directory.ts +0 -39
- package/src/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/file.ts +0 -198
- package/src/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.ts +0 -76
- package/src/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/raw.ts +0 -37
- package/src/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/index.ts +0 -121
- package/src/ipfs-unixfs-exporter/src/utils/extract-data-from-block.ts +0 -24
- package/src/ipfs-unixfs-exporter/src/utils/find-cid-in-shard.ts +0 -149
- package/src/ipfs-unixfs-exporter/src/utils/resolve-object-path.ts +0 -62
- package/src/ipfs-unixfs-exporter/src/utils/validate-offset-and-length.ts +0 -38
package/src/cborg/json/decode.js
DELETED
|
@@ -1,462 +0,0 @@
|
|
|
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 }
|