@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
|
@@ -1,466 +0,0 @@
|
|
|
1
|
-
import { is } from './is.js'
|
|
2
|
-
import {
|
|
3
|
-
Token, Type, Bl,
|
|
4
|
-
quickEncodeToken,
|
|
5
|
-
asU8A,
|
|
6
|
-
encodeUint,
|
|
7
|
-
encodeNegint,
|
|
8
|
-
encodeBytes,
|
|
9
|
-
encodeString,
|
|
10
|
-
encodeArray,
|
|
11
|
-
encodeMap,
|
|
12
|
-
encodeTag,
|
|
13
|
-
encodeFloat
|
|
14
|
-
} from "@fireproof/vendor/cborg/utils"
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @typedef {import('../interface').EncodeOptions} EncodeOptions
|
|
18
|
-
* @typedef {import('../interface').OptionalTypeEncoder} OptionalTypeEncoder
|
|
19
|
-
* @typedef {import('../interface').Reference} Reference
|
|
20
|
-
* @typedef {import('../interface').StrictTypeEncoder} StrictTypeEncoder
|
|
21
|
-
* @typedef {import('../interface').TokenTypeEncoder} TokenTypeEncoder
|
|
22
|
-
* @typedef {import('../interface').TokenOrNestedTokens} TokenOrNestedTokens
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
/** @type {EncodeOptions} */
|
|
26
|
-
const defaultEncodeOptions = {
|
|
27
|
-
float64: false,
|
|
28
|
-
mapSorter,
|
|
29
|
-
quickEncodeToken,
|
|
30
|
-
encodeErrPrefix: 'CBOR encode error:'
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** @returns {TokenTypeEncoder[]} */
|
|
35
|
-
export function makeCborEncoders () {
|
|
36
|
-
const encoders = []
|
|
37
|
-
encoders[Type.uint.major] = encodeUint
|
|
38
|
-
encoders[Type.negint.major] = encodeNegint
|
|
39
|
-
encoders[Type.bytes.major] = encodeBytes
|
|
40
|
-
encoders[Type.string.major] = encodeString
|
|
41
|
-
encoders[Type.array.major] = encodeArray
|
|
42
|
-
encoders[Type.map.major] = encodeMap
|
|
43
|
-
encoders[Type.tag.major] = encodeTag
|
|
44
|
-
encoders[Type.float.major] = encodeFloat
|
|
45
|
-
return encoders
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const cborEncoders = makeCborEncoders()
|
|
49
|
-
|
|
50
|
-
const buf = new Bl()
|
|
51
|
-
|
|
52
|
-
/** @implements {Reference} */
|
|
53
|
-
class Ref {
|
|
54
|
-
/**
|
|
55
|
-
* @param {object|any[]} obj
|
|
56
|
-
* @param {Reference|undefined} parent
|
|
57
|
-
*/
|
|
58
|
-
constructor (obj, parent) {
|
|
59
|
-
this.obj = obj
|
|
60
|
-
this.parent = parent
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* @param {object|any[]} obj
|
|
65
|
-
* @returns {boolean}
|
|
66
|
-
*/
|
|
67
|
-
includes (obj) {
|
|
68
|
-
/** @type {Reference|undefined} */
|
|
69
|
-
let p = this
|
|
70
|
-
do {
|
|
71
|
-
if (p.obj === obj) {
|
|
72
|
-
return true
|
|
73
|
-
}
|
|
74
|
-
} while (p = p.parent) // eslint-disable-line
|
|
75
|
-
return false
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* @param {Reference|undefined} stack
|
|
80
|
-
* @param {object|any[]} obj
|
|
81
|
-
* @param {EncodeOptions} options
|
|
82
|
-
* @returns {Reference}
|
|
83
|
-
*/
|
|
84
|
-
static createCheck (stack, obj, { encodeErrPrefix }) {
|
|
85
|
-
if (stack && stack.includes(obj)) {
|
|
86
|
-
throw new Error(`${encodeErrPrefix} object contains circular references`)
|
|
87
|
-
}
|
|
88
|
-
return new Ref(obj, stack)
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const simpleTokens = {
|
|
93
|
-
null: new Token(Type.null, null),
|
|
94
|
-
undefined: new Token(Type.undefined, undefined),
|
|
95
|
-
true: new Token(Type.true, true),
|
|
96
|
-
false: new Token(Type.false, false),
|
|
97
|
-
emptyArray: new Token(Type.array, 0),
|
|
98
|
-
emptyMap: new Token(Type.map, 0)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/** @type {{[typeName: string]: StrictTypeEncoder}} */
|
|
102
|
-
const typeEncoders = {
|
|
103
|
-
/**
|
|
104
|
-
* @param {any} obj
|
|
105
|
-
* @param {string} _typ
|
|
106
|
-
* @param {EncodeOptions} _options
|
|
107
|
-
* @param {Reference} [_refStack]
|
|
108
|
-
* @returns {TokenOrNestedTokens}
|
|
109
|
-
*/
|
|
110
|
-
number (obj, _typ, _options, _refStack) {
|
|
111
|
-
if (!Number.isInteger(obj) || !Number.isSafeInteger(obj)) {
|
|
112
|
-
return new Token(Type.float, obj)
|
|
113
|
-
} else if (obj >= 0) {
|
|
114
|
-
return new Token(Type.uint, obj)
|
|
115
|
-
} else {
|
|
116
|
-
return new Token(Type.negint, obj)
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* @param {any} obj
|
|
122
|
-
* @param {string} _typ
|
|
123
|
-
* @param {EncodeOptions} _options
|
|
124
|
-
* @param {Reference} [_refStack]
|
|
125
|
-
* @returns {TokenOrNestedTokens}
|
|
126
|
-
*/
|
|
127
|
-
bigint (obj, _typ, _options, _refStack) {
|
|
128
|
-
if (obj >= BigInt(0)) {
|
|
129
|
-
return new Token(Type.uint, obj)
|
|
130
|
-
} else {
|
|
131
|
-
return new Token(Type.negint, obj)
|
|
132
|
-
}
|
|
133
|
-
},
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* @param {any} obj
|
|
137
|
-
* @param {string} _typ
|
|
138
|
-
* @param {EncodeOptions} _options
|
|
139
|
-
* @param {Reference} [_refStack]
|
|
140
|
-
* @returns {TokenOrNestedTokens}
|
|
141
|
-
*/
|
|
142
|
-
Uint8Array (obj, _typ, _options, _refStack) {
|
|
143
|
-
return new Token(Type.bytes, obj)
|
|
144
|
-
},
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* @param {any} obj
|
|
148
|
-
* @param {string} _typ
|
|
149
|
-
* @param {EncodeOptions} _options
|
|
150
|
-
* @param {Reference} [_refStack]
|
|
151
|
-
* @returns {TokenOrNestedTokens}
|
|
152
|
-
*/
|
|
153
|
-
string (obj, _typ, _options, _refStack) {
|
|
154
|
-
return new Token(Type.string, obj)
|
|
155
|
-
},
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* @param {any} obj
|
|
159
|
-
* @param {string} _typ
|
|
160
|
-
* @param {EncodeOptions} _options
|
|
161
|
-
* @param {Reference} [_refStack]
|
|
162
|
-
* @returns {TokenOrNestedTokens}
|
|
163
|
-
*/
|
|
164
|
-
boolean (obj, _typ, _options, _refStack) {
|
|
165
|
-
return obj ? simpleTokens.true : simpleTokens.false
|
|
166
|
-
},
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* @param {any} _obj
|
|
170
|
-
* @param {string} _typ
|
|
171
|
-
* @param {EncodeOptions} _options
|
|
172
|
-
* @param {Reference} [_refStack]
|
|
173
|
-
* @returns {TokenOrNestedTokens}
|
|
174
|
-
*/
|
|
175
|
-
null (_obj, _typ, _options, _refStack) {
|
|
176
|
-
return simpleTokens.null
|
|
177
|
-
},
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* @param {any} _obj
|
|
181
|
-
* @param {string} _typ
|
|
182
|
-
* @param {EncodeOptions} _options
|
|
183
|
-
* @param {Reference} [_refStack]
|
|
184
|
-
* @returns {TokenOrNestedTokens}
|
|
185
|
-
*/
|
|
186
|
-
undefined (_obj, _typ, _options, _refStack) {
|
|
187
|
-
return simpleTokens.undefined
|
|
188
|
-
},
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* @param {any} obj
|
|
192
|
-
* @param {string} _typ
|
|
193
|
-
* @param {EncodeOptions} _options
|
|
194
|
-
* @param {Reference} [_refStack]
|
|
195
|
-
* @returns {TokenOrNestedTokens}
|
|
196
|
-
*/
|
|
197
|
-
ArrayBuffer (obj, _typ, _options, _refStack) {
|
|
198
|
-
return new Token(Type.bytes, new Uint8Array(obj))
|
|
199
|
-
},
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* @param {any} obj
|
|
203
|
-
* @param {string} _typ
|
|
204
|
-
* @param {EncodeOptions} _options
|
|
205
|
-
* @param {Reference} [_refStack]
|
|
206
|
-
* @returns {TokenOrNestedTokens}
|
|
207
|
-
*/
|
|
208
|
-
DataView (obj, _typ, _options, _refStack) {
|
|
209
|
-
return new Token(Type.bytes, new Uint8Array(obj.buffer, obj.byteOffset, obj.byteLength))
|
|
210
|
-
},
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* @param {any} obj
|
|
214
|
-
* @param {string} _typ
|
|
215
|
-
* @param {EncodeOptions} options
|
|
216
|
-
* @param {Reference} [refStack]
|
|
217
|
-
* @returns {TokenOrNestedTokens}
|
|
218
|
-
*/
|
|
219
|
-
Array (obj, _typ, options, refStack) {
|
|
220
|
-
if (!obj.length) {
|
|
221
|
-
if (options.addBreakTokens === true) {
|
|
222
|
-
return [simpleTokens.emptyArray, new Token(Type.break)]
|
|
223
|
-
}
|
|
224
|
-
return simpleTokens.emptyArray
|
|
225
|
-
}
|
|
226
|
-
refStack = Ref.createCheck(refStack, obj, options)
|
|
227
|
-
const entries = []
|
|
228
|
-
let i = 0
|
|
229
|
-
for (const e of obj) {
|
|
230
|
-
entries[i++] = objectToTokens(e, options, refStack)
|
|
231
|
-
}
|
|
232
|
-
if (options.addBreakTokens) {
|
|
233
|
-
return [new Token(Type.array, obj.length), entries, new Token(Type.break)]
|
|
234
|
-
}
|
|
235
|
-
return [new Token(Type.array, obj.length), entries]
|
|
236
|
-
},
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* @param {any} obj
|
|
240
|
-
* @param {string} typ
|
|
241
|
-
* @param {EncodeOptions} options
|
|
242
|
-
* @param {Reference} [refStack]
|
|
243
|
-
* @returns {TokenOrNestedTokens}
|
|
244
|
-
*/
|
|
245
|
-
Object (obj, typ, options, refStack) {
|
|
246
|
-
// could be an Object or a Map
|
|
247
|
-
const isMap = typ !== 'Object'
|
|
248
|
-
// it's slightly quicker to use Object.keys() than Object.entries()
|
|
249
|
-
const keys = isMap ? obj.keys() : Object.keys(obj)
|
|
250
|
-
const length = isMap ? obj.size : keys.length
|
|
251
|
-
if (!length) {
|
|
252
|
-
if (options.addBreakTokens === true) {
|
|
253
|
-
return [simpleTokens.emptyMap, new Token(Type.break)]
|
|
254
|
-
}
|
|
255
|
-
return simpleTokens.emptyMap
|
|
256
|
-
}
|
|
257
|
-
refStack = Ref.createCheck(refStack, obj, options)
|
|
258
|
-
/** @type {TokenOrNestedTokens[]} */
|
|
259
|
-
const entries = []
|
|
260
|
-
let i = 0
|
|
261
|
-
for (const key of keys) {
|
|
262
|
-
entries[i++] = [
|
|
263
|
-
objectToTokens(key, options, refStack),
|
|
264
|
-
objectToTokens(isMap ? obj.get(key) : obj[key], options, refStack)
|
|
265
|
-
]
|
|
266
|
-
}
|
|
267
|
-
sortMapEntries(entries, options)
|
|
268
|
-
if (options.addBreakTokens) {
|
|
269
|
-
return [new Token(Type.map, length), entries, new Token(Type.break)]
|
|
270
|
-
}
|
|
271
|
-
return [new Token(Type.map, length), entries]
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
typeEncoders.Map = typeEncoders.Object
|
|
276
|
-
typeEncoders.Buffer = typeEncoders.Uint8Array
|
|
277
|
-
for (const typ of 'Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64'.split(' ')) {
|
|
278
|
-
typeEncoders[`${typ}Array`] = typeEncoders.DataView
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* @param {any} obj
|
|
283
|
-
* @param {EncodeOptions} options
|
|
284
|
-
* @param {Reference} [refStack]
|
|
285
|
-
* @returns {TokenOrNestedTokens}
|
|
286
|
-
*/
|
|
287
|
-
function objectToTokens (obj, options, refStack) {
|
|
288
|
-
const typ = is(obj)
|
|
289
|
-
const customTypeEncoder = (options && options.typeEncoders && /** @type {OptionalTypeEncoder} */ options.typeEncoders[typ]) || typeEncoders[typ]
|
|
290
|
-
if (typeof customTypeEncoder === 'function') {
|
|
291
|
-
const tokens = customTypeEncoder(obj, typ, options, refStack)
|
|
292
|
-
if (tokens != null) {
|
|
293
|
-
return tokens
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
const typeEncoder = typeEncoders[typ]
|
|
297
|
-
if (!typeEncoder) {
|
|
298
|
-
throw new Error(`${options.encodeErrPrefix} unsupported type: ${typ}`)
|
|
299
|
-
}
|
|
300
|
-
return typeEncoder(obj, typ, options, refStack)
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
/*
|
|
304
|
-
CBOR key sorting is a mess.
|
|
305
|
-
|
|
306
|
-
The canonicalisation recommendation from https://tools.ietf.org/html/rfc7049#section-3.9
|
|
307
|
-
includes the wording:
|
|
308
|
-
|
|
309
|
-
> The keys in every map must be sorted lowest value to highest.
|
|
310
|
-
> Sorting is performed on the bytes of the representation of the key
|
|
311
|
-
> data items without paying attention to the 3/5 bit splitting for
|
|
312
|
-
> major types.
|
|
313
|
-
> ...
|
|
314
|
-
> * If two keys have different lengths, the shorter one sorts
|
|
315
|
-
earlier;
|
|
316
|
-
> * If two keys have the same length, the one with the lower value
|
|
317
|
-
in (byte-wise) lexical order sorts earlier.
|
|
318
|
-
|
|
319
|
-
1. It is not clear what "bytes of the representation of the key" means: is it
|
|
320
|
-
the CBOR representation, or the binary representation of the object itself?
|
|
321
|
-
Consider the int and uint difference here.
|
|
322
|
-
2. It is not clear what "without paying attention to" means: do we include it
|
|
323
|
-
and compare on that? Or do we omit the special prefix byte, (mostly) treating
|
|
324
|
-
the key in its plain binary representation form.
|
|
325
|
-
|
|
326
|
-
The FIDO 2.0: Client To Authenticator Protocol spec takes the original CBOR
|
|
327
|
-
wording and clarifies it according to their understanding.
|
|
328
|
-
https://fidoalliance.org/specs/fido-v2.0-rd-20170927/fido-client-to-authenticator-protocol-v2.0-rd-20170927.html#message-encoding
|
|
329
|
-
|
|
330
|
-
> The keys in every map must be sorted lowest value to highest. Sorting is
|
|
331
|
-
> performed on the bytes of the representation of the key data items without
|
|
332
|
-
> paying attention to the 3/5 bit splitting for major types. The sorting rules
|
|
333
|
-
> are:
|
|
334
|
-
> * If the major types are different, the one with the lower value in numerical
|
|
335
|
-
> order sorts earlier.
|
|
336
|
-
> * If two keys have different lengths, the shorter one sorts earlier;
|
|
337
|
-
> * If two keys have the same length, the one with the lower value in
|
|
338
|
-
> (byte-wise) lexical order sorts earlier.
|
|
339
|
-
|
|
340
|
-
Some other implementations, such as borc, do a full encode then do a
|
|
341
|
-
length-first, byte-wise-second comparison:
|
|
342
|
-
https://github.com/dignifiedquire/borc/blob/b6bae8b0bcde7c3976b0f0f0957208095c392a36/src/encoder.js#L358
|
|
343
|
-
https://github.com/dignifiedquire/borc/blob/b6bae8b0bcde7c3976b0f0f0957208095c392a36/src/utils.js#L143-L151
|
|
344
|
-
|
|
345
|
-
This has the benefit of being able to easily handle arbitrary keys, including
|
|
346
|
-
complex types (maps and arrays).
|
|
347
|
-
|
|
348
|
-
We'll opt for the FIDO approach, since it affords some efficies since we don't
|
|
349
|
-
need a full encode of each key to determine order and can defer to the types
|
|
350
|
-
to determine how to most efficiently order their values (i.e. int and uint
|
|
351
|
-
ordering can be done on the numbers, no need for byte-wise, for example).
|
|
352
|
-
|
|
353
|
-
Recommendation: stick to single key types or you'll get into trouble, and prefer
|
|
354
|
-
string keys because it's much simpler that way.
|
|
355
|
-
*/
|
|
356
|
-
|
|
357
|
-
/*
|
|
358
|
-
(UPDATE, Dec 2020)
|
|
359
|
-
https://tools.ietf.org/html/rfc8949 is the updated CBOR spec and clarifies some
|
|
360
|
-
of the questions above with a new recommendation for sorting order being much
|
|
361
|
-
closer to what would be expected in other environments (i.e. no length-first
|
|
362
|
-
weirdness).
|
|
363
|
-
This new sorting order is not yet implemented here but could be added as an
|
|
364
|
-
option. "Determinism" (canonicity) is system dependent and it's difficult to
|
|
365
|
-
change existing systems that are built with existing expectations. So if a new
|
|
366
|
-
ordering is introduced here, the old needs to be kept as well with the user
|
|
367
|
-
having the option.
|
|
368
|
-
*/
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* @param {TokenOrNestedTokens[]} entries
|
|
372
|
-
* @param {EncodeOptions} options
|
|
373
|
-
*/
|
|
374
|
-
function sortMapEntries (entries, options) {
|
|
375
|
-
if (options.mapSorter) {
|
|
376
|
-
entries.sort(options.mapSorter)
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
/**
|
|
381
|
-
* @param {(Token|Token[])[]} e1
|
|
382
|
-
* @param {(Token|Token[])[]} e2
|
|
383
|
-
* @returns {number}
|
|
384
|
-
*/
|
|
385
|
-
function mapSorter (e1, e2) {
|
|
386
|
-
// the key position ([0]) could have a single token or an array
|
|
387
|
-
// almost always it'll be a single token but complex key might get involved
|
|
388
|
-
/* c8 ignore next 2 */
|
|
389
|
-
const keyToken1 = Array.isArray(e1[0]) ? e1[0][0] : e1[0]
|
|
390
|
-
const keyToken2 = Array.isArray(e2[0]) ? e2[0][0] : e2[0]
|
|
391
|
-
|
|
392
|
-
// different key types
|
|
393
|
-
if (keyToken1.type !== keyToken2.type) {
|
|
394
|
-
return keyToken1.type.compare(keyToken2.type)
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
const major = keyToken1.type.major
|
|
398
|
-
// TODO: handle case where cmp === 0 but there are more keyToken e. complex type)
|
|
399
|
-
const tcmp = cborEncoders[major].compareTokens(keyToken1, keyToken2)
|
|
400
|
-
/* c8 ignore next 5 */
|
|
401
|
-
if (tcmp === 0) {
|
|
402
|
-
// duplicate key or complex type where the first token matched,
|
|
403
|
-
// i.e. a map or array and we're only comparing the opening token
|
|
404
|
-
console.warn('WARNING: complex key types used, CBOR key sorting guarantees are gone')
|
|
405
|
-
}
|
|
406
|
-
return tcmp
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
/**
|
|
410
|
-
* @param {Bl} buf
|
|
411
|
-
* @param {TokenOrNestedTokens} tokens
|
|
412
|
-
* @param {TokenTypeEncoder[]} encoders
|
|
413
|
-
* @param {EncodeOptions} options
|
|
414
|
-
*/
|
|
415
|
-
function tokensToEncoded (buf, tokens, encoders, options) {
|
|
416
|
-
if (Array.isArray(tokens)) {
|
|
417
|
-
for (const token of tokens) {
|
|
418
|
-
tokensToEncoded(buf, token, encoders, options)
|
|
419
|
-
}
|
|
420
|
-
} else {
|
|
421
|
-
encoders[tokens.type.major](buf, tokens, options)
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
/**
|
|
426
|
-
* @param {any} data
|
|
427
|
-
* @param {TokenTypeEncoder[]} encoders
|
|
428
|
-
* @param {EncodeOptions} options
|
|
429
|
-
* @returns {Uint8Array}
|
|
430
|
-
*/
|
|
431
|
-
function encodeCustom (data, encoders, options) {
|
|
432
|
-
const tokens = objectToTokens(data, options)
|
|
433
|
-
if (!Array.isArray(tokens) && options.quickEncodeToken) {
|
|
434
|
-
const quickBytes = options.quickEncodeToken(tokens)
|
|
435
|
-
if (quickBytes) {
|
|
436
|
-
return quickBytes
|
|
437
|
-
}
|
|
438
|
-
const encoder = encoders[tokens.type.major]
|
|
439
|
-
if (encoder.encodedSize) {
|
|
440
|
-
const size = encoder.encodedSize(tokens, options)
|
|
441
|
-
const buf = new Bl(size)
|
|
442
|
-
encoder(buf, tokens, options)
|
|
443
|
-
/* c8 ignore next 4 */
|
|
444
|
-
// this would be a problem with encodedSize() functions
|
|
445
|
-
if (buf.chunks.length !== 1) {
|
|
446
|
-
throw new Error(`Unexpected error: pre-calculated length for ${tokens} was wrong`)
|
|
447
|
-
}
|
|
448
|
-
return asU8A(buf.chunks[0])
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
buf.reset()
|
|
452
|
-
tokensToEncoded(buf, tokens, encoders, options)
|
|
453
|
-
return buf.toBytes(true)
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
/**
|
|
457
|
-
* @param {any} data
|
|
458
|
-
* @param {EncodeOptions} [options]
|
|
459
|
-
* @returns {Uint8Array}
|
|
460
|
-
*/
|
|
461
|
-
function encode (data, options) {
|
|
462
|
-
options = Object.assign({}, defaultEncodeOptions, options)
|
|
463
|
-
return encodeCustom(data, cborEncoders, options)
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
export { objectToTokens, encode, encodeCustom, Ref }
|
package/src/cborg/cborg/index.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { encode } from './encode.js'
|
|
2
|
-
import { decode, decodeFirst, Tokeniser, tokensToObject } from './decode.js'
|
|
3
|
-
import { Token, Type } from "@fireproof/vendor/cborg/utils"
|
|
4
|
-
|
|
5
|
-
// is this needed for the json module and other independ encoders
|
|
6
|
-
export { encodeCustom } from './encode.js'
|
|
7
|
-
// export { asU8A, fromString, decodeCodePointsArray } from './utils/byte-utils.js'
|
|
8
|
-
// export { quickEncodeToken } from './utils/jump.js'
|
|
9
|
-
// export { encodeErrPrefix, decodeErrPrefix } from './lib/common.js'
|
|
10
|
-
// export { makeCborEncoders, objectToTokens } from './lib/encode.js'
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Export the types that were present in the original manual cborg.d.ts
|
|
14
|
-
* @typedef {import('../interface').TagDecoder} TagDecoder
|
|
15
|
-
* There was originally just `TypeEncoder` so don't break types by renaming or not exporting
|
|
16
|
-
* @typedef {import('../interface').OptionalTypeEncoder} TypeEncoder
|
|
17
|
-
* @typedef {import('../interface').DecodeOptions} DecodeOptions
|
|
18
|
-
* @typedef {import('../interface').EncodeOptions} EncodeOptions
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
export {
|
|
22
|
-
// this is needed to prevent the bundleing trouble which happens
|
|
23
|
-
// due to the fact that token.js is used in lib/json and so in
|
|
24
|
-
// cborg/json which ends up on bundling to have two copies of token.js
|
|
25
|
-
// which will fail stmts like token.type === Type.array
|
|
26
|
-
decode,
|
|
27
|
-
decodeFirst,
|
|
28
|
-
Tokeniser as Tokenizer,
|
|
29
|
-
tokensToObject,
|
|
30
|
-
encode,
|
|
31
|
-
Token,
|
|
32
|
-
Type
|
|
33
|
-
}
|
package/src/cborg/cborg/is.js
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
// This is an unfortunate replacement for @sindresorhus/is that we need to
|
|
2
|
-
// re-implement for performance purposes. In particular the is.observable()
|
|
3
|
-
// check is expensive, and unnecessary for our purposes. The values returned
|
|
4
|
-
// are compatible with @sindresorhus/is, however.
|
|
5
|
-
|
|
6
|
-
const typeofs = [
|
|
7
|
-
'string',
|
|
8
|
-
'number',
|
|
9
|
-
'bigint',
|
|
10
|
-
'symbol'
|
|
11
|
-
]
|
|
12
|
-
|
|
13
|
-
const objectTypeNames = [
|
|
14
|
-
'Function',
|
|
15
|
-
'Generator',
|
|
16
|
-
'AsyncGenerator',
|
|
17
|
-
'GeneratorFunction',
|
|
18
|
-
'AsyncGeneratorFunction',
|
|
19
|
-
'AsyncFunction',
|
|
20
|
-
'Observable',
|
|
21
|
-
'Array',
|
|
22
|
-
'Buffer',
|
|
23
|
-
'Object',
|
|
24
|
-
'RegExp',
|
|
25
|
-
'Date',
|
|
26
|
-
'Error',
|
|
27
|
-
'Map',
|
|
28
|
-
'Set',
|
|
29
|
-
'WeakMap',
|
|
30
|
-
'WeakSet',
|
|
31
|
-
'ArrayBuffer',
|
|
32
|
-
'SharedArrayBuffer',
|
|
33
|
-
'DataView',
|
|
34
|
-
'Promise',
|
|
35
|
-
'URL',
|
|
36
|
-
'HTMLElement',
|
|
37
|
-
'Int8Array',
|
|
38
|
-
'Uint8Array',
|
|
39
|
-
'Uint8ClampedArray',
|
|
40
|
-
'Int16Array',
|
|
41
|
-
'Uint16Array',
|
|
42
|
-
'Int32Array',
|
|
43
|
-
'Uint32Array',
|
|
44
|
-
'Float32Array',
|
|
45
|
-
'Float64Array',
|
|
46
|
-
'BigInt64Array',
|
|
47
|
-
'BigUint64Array'
|
|
48
|
-
]
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* @param {any} value
|
|
52
|
-
* @returns {string}
|
|
53
|
-
*/
|
|
54
|
-
export function is (value) {
|
|
55
|
-
if (value === null) {
|
|
56
|
-
return 'null'
|
|
57
|
-
}
|
|
58
|
-
if (value === undefined) {
|
|
59
|
-
return 'undefined'
|
|
60
|
-
}
|
|
61
|
-
if (value === true || value === false) {
|
|
62
|
-
return 'boolean'
|
|
63
|
-
}
|
|
64
|
-
const typeOf = typeof value
|
|
65
|
-
if (typeofs.includes(typeOf)) {
|
|
66
|
-
return typeOf
|
|
67
|
-
}
|
|
68
|
-
/* c8 ignore next 4 */
|
|
69
|
-
// not going to bother testing this, it's not going to be valid anyway
|
|
70
|
-
if (typeOf === 'function') {
|
|
71
|
-
return 'Function'
|
|
72
|
-
}
|
|
73
|
-
if (Array.isArray(value)) {
|
|
74
|
-
return 'Array'
|
|
75
|
-
}
|
|
76
|
-
if (isBuffer(value)) {
|
|
77
|
-
return 'Buffer'
|
|
78
|
-
}
|
|
79
|
-
const objectType = getObjectType(value)
|
|
80
|
-
if (objectType) {
|
|
81
|
-
return objectType
|
|
82
|
-
}
|
|
83
|
-
/* c8 ignore next */
|
|
84
|
-
return 'Object'
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* @param {any} value
|
|
89
|
-
* @returns {boolean}
|
|
90
|
-
*/
|
|
91
|
-
function isBuffer (value) {
|
|
92
|
-
return value && value.constructor && value.constructor.isBuffer && value.constructor.isBuffer.call(null, value)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* @param {any} value
|
|
97
|
-
* @returns {string|undefined}
|
|
98
|
-
*/
|
|
99
|
-
function getObjectType (value) {
|
|
100
|
-
const objectTypeName = Object.prototype.toString.call(value).slice(8, -1)
|
|
101
|
-
if (objectTypeNames.includes(objectTypeName)) {
|
|
102
|
-
return objectTypeName
|
|
103
|
-
}
|
|
104
|
-
/* c8 ignore next */
|
|
105
|
-
return undefined
|
|
106
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { makeCborEncoders, objectToTokens } from './encode.js'
|
|
2
|
-
import { quickEncodeToken } from "@fireproof/vendor/cborg/utils"
|
|
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
|
-
encodeErrPrefix: 'CBOR encode error: '
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Calculate the byte length of the given data when encoded as CBOR with the
|
|
21
|
-
* options provided.
|
|
22
|
-
* This calculation will be accurate if the same options are used as when
|
|
23
|
-
* performing a normal encode. Some encode options can change the encoding
|
|
24
|
-
* output length.
|
|
25
|
-
*
|
|
26
|
-
* @param {any} data
|
|
27
|
-
* @param {EncodeOptions} [options]
|
|
28
|
-
* @returns {number}
|
|
29
|
-
*/
|
|
30
|
-
export function encodedLength (data, options) {
|
|
31
|
-
options = Object.assign({}, defaultEncodeOptions, options)
|
|
32
|
-
options.mapSorter = undefined // won't change the length
|
|
33
|
-
const tokens = objectToTokens(data, options)
|
|
34
|
-
return tokensToLength(tokens, cborEncoders, options)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Calculate the byte length of the data as represented by the given tokens when
|
|
39
|
-
* encoded as CBOR with the options provided.
|
|
40
|
-
* This function is for advanced users and would not normally be called
|
|
41
|
-
* directly. See `encodedLength()` for appropriate use.
|
|
42
|
-
*
|
|
43
|
-
* @param {TokenOrNestedTokens} tokens
|
|
44
|
-
* @param {TokenTypeEncoder[]} [encoders]
|
|
45
|
-
* @param {EncodeOptions} [options]
|
|
46
|
-
*/
|
|
47
|
-
export function tokensToLength (tokens, encoders = cborEncoders, options = defaultEncodeOptions) {
|
|
48
|
-
if (Array.isArray(tokens)) {
|
|
49
|
-
let len = 0
|
|
50
|
-
for (const token of tokens) {
|
|
51
|
-
len += tokensToLength(token, encoders, options)
|
|
52
|
-
}
|
|
53
|
-
return len
|
|
54
|
-
} else {
|
|
55
|
-
const encoder = encoders[tokens.type.major]
|
|
56
|
-
/* c8 ignore next 3 */
|
|
57
|
-
if (encoder.encodedSize === undefined || typeof encoder.encodedSize !== 'function') {
|
|
58
|
-
throw new Error(`Encoder for ${tokens.type.name} does not have an encodedSize()`)
|
|
59
|
-
}
|
|
60
|
-
return encoder.encodedSize(tokens, options)
|
|
61
|
-
}
|
|
62
|
-
}
|