@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,65 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
|
|
3
|
+
import * as chai from 'chai'
|
|
4
|
+
|
|
5
|
+
import { decode } from "@fireproof/vendor/cborg"
|
|
6
|
+
import { fromHex } from "@fireproof/vendor/cborg/utils"
|
|
7
|
+
|
|
8
|
+
const { assert } = chai
|
|
9
|
+
|
|
10
|
+
describe('decode errors', () => {
|
|
11
|
+
it('not Uint8Array', () => {
|
|
12
|
+
for (const arg of [true, false, null, undefined, 'string', { obj: 'ect' }, {}, ['array'], [], [1, 2, 3], 0, 100, 1.1, -1, Symbol.for('nope')]) {
|
|
13
|
+
assert.throws(() => decode(arg), /CBOR decode error.*must be a Uint8Array/)
|
|
14
|
+
}
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
it('no data', () => {
|
|
18
|
+
assert.throws(() => decode(new Uint8Array('')), /CBOR decode error.*content/)
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it('break only', () => {
|
|
22
|
+
assert.throws(() => decode(new Uint8Array([255])), /CBOR decode error.*break/)
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it('not enough map entries (value)', () => {
|
|
26
|
+
// last value missing
|
|
27
|
+
assert.throws(() => decode(fromHex('a2616f016174')), /map.*not enough entries.*value/)
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('not enough map entries (key)', () => {
|
|
31
|
+
// last key & value missing
|
|
32
|
+
assert.throws(() => decode(fromHex('a2616f01')), /map.*not enough entries.*key/)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('break in lengthed map', () => {
|
|
36
|
+
// 0xff (break) in the middle
|
|
37
|
+
assert.throws(() => decode(fromHex('a2616f01ff740f')), /unexpected break to lengthed map/)
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('not enough array entries', () => {
|
|
41
|
+
// last value missing
|
|
42
|
+
assert.throws(() => decode(fromHex('82616f')), /array.*not enough entries/)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('break in lengthed array', () => {
|
|
46
|
+
// last value missing
|
|
47
|
+
assert.throws(() => decode(fromHex('82ff')), /unexpected break to lengthed array/)
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
it('no such decoder', () => {
|
|
51
|
+
// last value missing
|
|
52
|
+
assert.throws(() => decode(fromHex('82ff')), /unexpected break to lengthed array/)
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it('too many terminals', () => {
|
|
56
|
+
// two '1's
|
|
57
|
+
assert.throws(() => decode(fromHex('0101')), /too many terminals/)
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it('rejectDuplicateMapKeys enabled on duplicate keys', () => {
|
|
61
|
+
assert.deepStrictEqual(decode(fromHex('a3636261720363666f6f0163666f6f02')), { foo: 2, bar: 3 })
|
|
62
|
+
assert.throws(() => decode(fromHex('a3636261720363666f6f0163666f6f02'), { rejectDuplicateMapKeys: true }), /CBOR decode error: found repeat map key "foo"/)
|
|
63
|
+
assert.throws(() => decode(fromHex('a3636261720363666f6f0163666f6f02'), { useMaps: true, rejectDuplicateMapKeys: true }), /CBOR decode error: found repeat map key "foo"/)
|
|
64
|
+
})
|
|
65
|
+
})
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
|
|
3
|
+
import { garbage } from 'ipld-garbage'
|
|
4
|
+
import { decode, encode } from "@fireproof/vendor/cborg"
|
|
5
|
+
import * as chai from 'chai'
|
|
6
|
+
|
|
7
|
+
const { assert } = chai
|
|
8
|
+
|
|
9
|
+
describe('Fuzz round-trip', () => {
|
|
10
|
+
it('random objects', function () {
|
|
11
|
+
this.timeout(5000)
|
|
12
|
+
for (let i = 0; i < 1000; i++) {
|
|
13
|
+
const obj = garbage(300, { weights: { CID: 0 } })
|
|
14
|
+
const byts = encode(obj)
|
|
15
|
+
const decoded = decode(byts)
|
|
16
|
+
assert.deepEqual(decoded, obj)
|
|
17
|
+
}
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('circular references error', () => {
|
|
21
|
+
let obj = {}
|
|
22
|
+
obj.obj = obj
|
|
23
|
+
assert.throws(() => encode(obj), /circular references/)
|
|
24
|
+
|
|
25
|
+
obj = { blip: [1, 2, { blop: {} }] }
|
|
26
|
+
obj.blip[2].blop.boop = obj
|
|
27
|
+
assert.throws(() => encode(obj), /circular references/)
|
|
28
|
+
|
|
29
|
+
obj = { blip: [1, 2, { blop: {} }] }
|
|
30
|
+
obj.blip[2].blop.boop = obj.blip
|
|
31
|
+
assert.throws(() => encode(obj), /circular references/)
|
|
32
|
+
|
|
33
|
+
// not circular but a naive check might decide it is
|
|
34
|
+
obj = { blip: {}, bloop: {} }
|
|
35
|
+
obj.bloop = obj.blip
|
|
36
|
+
assert.doesNotThrow(() => encode(obj))
|
|
37
|
+
|
|
38
|
+
const arr = []
|
|
39
|
+
arr[0] = arr
|
|
40
|
+
assert.throws(() => encode(arr), /circular references/)
|
|
41
|
+
})
|
|
42
|
+
})
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/* eslint-env mocha,es2020 */
|
|
2
|
+
|
|
3
|
+
import { assert } from 'chai'
|
|
4
|
+
import { decode, decodeFirst, encode } from "@fireproof/vendor/cborg/json"
|
|
5
|
+
|
|
6
|
+
const toBytes = (str) => new TextEncoder().encode(str)
|
|
7
|
+
|
|
8
|
+
function verifyRoundTrip (obj, sorting) {
|
|
9
|
+
const encoded = new TextDecoder().decode(encode(obj, sorting === false ? { mapSorter: null } : undefined))
|
|
10
|
+
const json = JSON.stringify(obj)
|
|
11
|
+
assert.strictEqual(encoded, json)
|
|
12
|
+
const decoded = decode(toBytes(JSON.stringify(obj)))
|
|
13
|
+
assert.deepStrictEqual(decoded, obj)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function verifyEncodedForm (testCase) {
|
|
17
|
+
// round trip the original object
|
|
18
|
+
const obj = JSON.parse(testCase)
|
|
19
|
+
const encoded = encode(obj)
|
|
20
|
+
assert.strictEqual(new TextDecoder().decode(encoded), JSON.stringify(obj))
|
|
21
|
+
const decoded = decode(encoded)
|
|
22
|
+
assert.deepStrictEqual(decoded, obj)
|
|
23
|
+
// now look at the original form
|
|
24
|
+
const decoded2 = decode(toBytes(testCase))
|
|
25
|
+
assert.deepStrictEqual(decoded2, obj)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
describe('json basics', () => {
|
|
29
|
+
it('can round-trip basic literals', () => {
|
|
30
|
+
const testCases = [
|
|
31
|
+
'null',
|
|
32
|
+
'true',
|
|
33
|
+
'false',
|
|
34
|
+
'0',
|
|
35
|
+
'9007199254740991',
|
|
36
|
+
'-9007199254740991',
|
|
37
|
+
JSON.stringify(Number.MAX_VALUE),
|
|
38
|
+
JSON.stringify(Number.MIN_VALUE)
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
for (const testCase of testCases) {
|
|
42
|
+
verifyEncodedForm(testCase)
|
|
43
|
+
}
|
|
44
|
+
assert.strictEqual(decode(toBytes('1E1')), 10)
|
|
45
|
+
assert.strictEqual(decode(toBytes('0.1e1')), 1)
|
|
46
|
+
assert.strictEqual(decode(toBytes('1e-1')), 0.1)
|
|
47
|
+
assert.strictEqual(decode(toBytes('1e+00')), 1)
|
|
48
|
+
assert.strictEqual(decode(toBytes('10.0')), 10)
|
|
49
|
+
assert.deepStrictEqual(decode(toBytes('[-10.0,1.0,0.0,100.0]')), [-10, 1, 0, 100])
|
|
50
|
+
verifyRoundTrip(true)
|
|
51
|
+
verifyRoundTrip(false)
|
|
52
|
+
verifyRoundTrip(null)
|
|
53
|
+
verifyRoundTrip(100)
|
|
54
|
+
verifyRoundTrip(-100)
|
|
55
|
+
verifyRoundTrip(1.11)
|
|
56
|
+
verifyRoundTrip(-100.11111)
|
|
57
|
+
verifyRoundTrip(1.11e10)
|
|
58
|
+
verifyRoundTrip(1.0011111e-18)
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it('handles large integers as BigInt', () => {
|
|
62
|
+
const verify = (inp, str) => {
|
|
63
|
+
if (str === undefined) {
|
|
64
|
+
str = String(inp)
|
|
65
|
+
}
|
|
66
|
+
assert.strictEqual(decode(toBytes(str), { allowBigInt: true }), inp)
|
|
67
|
+
assert.strictEqual(decode(toBytes(str)), parseFloat(str)) // no BigInt for you
|
|
68
|
+
}
|
|
69
|
+
verify(Number.MAX_SAFE_INTEGER)
|
|
70
|
+
verify(-Number.MAX_SAFE_INTEGER)
|
|
71
|
+
verify(BigInt('9007199254740992')) // Number.MAX_SAFE_INTEGER+1
|
|
72
|
+
verify(BigInt('9007199254740993'))
|
|
73
|
+
verify(BigInt('11959030306112471731'))
|
|
74
|
+
verify(BigInt('18446744073709551615')) // max uint64
|
|
75
|
+
verify(BigInt('9223372036854775807')) // max int64
|
|
76
|
+
verify(BigInt('-9007199254740992'))
|
|
77
|
+
verify(BigInt('-9007199254740993'))
|
|
78
|
+
verify(BigInt('-9223372036854776000')) // min int64
|
|
79
|
+
verify(BigInt('-11959030306112471732'))
|
|
80
|
+
verify(BigInt('-18446744073709551616')) // min -uint64
|
|
81
|
+
|
|
82
|
+
// these are "floats", distinct from "ints" which wouldn't have the `.` in them
|
|
83
|
+
verify(-9007199254740992, '-9007199254740992.0')
|
|
84
|
+
verify(-9223372036854776000, '-9223372036854776000.0')
|
|
85
|
+
verify(-18446744073709551616, '-18446744073709551616.0')
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('can round-trip string literals', () => {
|
|
89
|
+
const testCases = [
|
|
90
|
+
JSON.stringify(''),
|
|
91
|
+
JSON.stringify(' '),
|
|
92
|
+
JSON.stringify('"'),
|
|
93
|
+
JSON.stringify('\\'),
|
|
94
|
+
JSON.stringify('\b\f\n\r\t'),
|
|
95
|
+
JSON.stringify('\u0022'),
|
|
96
|
+
JSON.stringify('" %22 0x22 034 "'),
|
|
97
|
+
'"😀"'
|
|
98
|
+
]
|
|
99
|
+
|
|
100
|
+
for (const testCase of testCases) {
|
|
101
|
+
verifyEncodedForm(testCase)
|
|
102
|
+
}
|
|
103
|
+
assert.strictEqual(decode(toBytes('"/ & \\/"')), '/ & /')
|
|
104
|
+
verifyRoundTrip('this is a string')
|
|
105
|
+
verifyRoundTrip('this 𝄞 is a ☺☺ ♣ string ̐ ̀\n\r') // accents like ̀ and ̐ use two-byte utf8
|
|
106
|
+
verifyRoundTrip('')
|
|
107
|
+
verifyRoundTrip('foo\\bar\nbaz\tbop\rbing"bip\'bang')
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
it('can round-trip array literals', () => {
|
|
111
|
+
const testCases = [
|
|
112
|
+
'[]',
|
|
113
|
+
'[null]',
|
|
114
|
+
'[true, false]',
|
|
115
|
+
'[ \n 0,1, 2\n , 3,\n4] \n ',
|
|
116
|
+
'[-10.0, 1.0, 0.0, 100.0]',
|
|
117
|
+
'[["2 deep"]]'
|
|
118
|
+
]
|
|
119
|
+
for (const testCase of testCases) {
|
|
120
|
+
verifyEncodedForm(testCase)
|
|
121
|
+
}
|
|
122
|
+
verifyRoundTrip([1, 2, 3, 'string', true, 4])
|
|
123
|
+
verifyRoundTrip([1, 2, 3, 'string', true, ['and', 'a', 'nested', 'array', true], 4])
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
it('can round-trip object literals', () => {
|
|
127
|
+
const testCases = [
|
|
128
|
+
'{}',
|
|
129
|
+
'\n {\n "\\b"\n :\n""\n }\n ',
|
|
130
|
+
'{"":""}',
|
|
131
|
+
'{"1":{"2":0,"3":"deep"}}'
|
|
132
|
+
]
|
|
133
|
+
for (const testCase of testCases) {
|
|
134
|
+
verifyEncodedForm(testCase)
|
|
135
|
+
}
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
it('will sort map keys', () => {
|
|
139
|
+
const unsorted = { one: 1, two: 2, three: 3.1, str: 'string', bool: true, four: 4 }
|
|
140
|
+
verifyRoundTrip(unsorted, false)
|
|
141
|
+
assert.strictEqual(
|
|
142
|
+
new TextDecoder().decode(encode(unsorted)),
|
|
143
|
+
'{"bool":true,"four":4,"one":1,"str":"string","three":3.1,"two":2}')
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
it('can handle novel cases', () => {
|
|
147
|
+
assert.strictEqual(decode(toBytes('"this \\uD834\\uDD1E is a \\u263a\\u263a string"')), 'this 𝄞 is a ☺☺ string')
|
|
148
|
+
verifyRoundTrip({ one: 1, two: 2, three: 3.1, str: 'string', arr: ['and', 'a', 'nested', [], 'array', [true, 1], false], bool: true, obj: { nested: 'object', a: [], o: {} }, four: 4 }, false)
|
|
149
|
+
verifyRoundTrip([false, [{ '#nFzU': {}, '\\w>': -0.9441451951197325, "\t'": "'JB+2Wg\tw\"IrM*#e^L/d&4rrzUuwq(1mH6aVRredB&Bfs]S\"KqK(Tz1Q\"URBAfw", '\n@FrfM': 'M[D]q&' }, "J4>'Xdc+u2$%", 4227406737130333]], false)
|
|
150
|
+
verifyRoundTrip([0.12995619865708727, -4973404279772543, { drG2: [true], ';#K^Qf>V': null, '`2=': 'ecc<e/$+-.;U>Gr5RdZDJ\n5+:{=QHNN.tVVN~dX$FWFwu`6>"&=tW!*1*^☺)JFM1p|}&X.B|${*\\f@!w2☺+' }], false)
|
|
151
|
+
assert.strictEqual(`${decode(encode(9007199254740991))}`, '9007199254740991')
|
|
152
|
+
assert.strictEqual(`${decode(encode(9007199254740992))}`, '9007199254740992')
|
|
153
|
+
assert.strictEqual(`${decode(encode(900719925474099100n))}`, '900719925474099100')
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
it('should throw on bad types', () => {
|
|
157
|
+
assert.throws(() => encode(new Uint8Array([1, 2])), /JSON encode error: unsupported type: Uint8Array/)
|
|
158
|
+
assert.throws(() => encode({ boop: new Uint8Array([1, 2]) }), /JSON encode error: unsupported type: Uint8Array/)
|
|
159
|
+
assert.throws(() => encode(undefined), /JSON encode error: unsupported type: undefined/)
|
|
160
|
+
assert.throws(() => encode(new Map([[1, 2], [2, 3]])), /JSON encode error: non-string map keys are not supported/)
|
|
161
|
+
assert.throws(() => encode(new Map([[['foo', 'bar'], 2], [['bar', 'foo'], 3]])), /JSON encode error: complex map keys are not supported/)
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
it('should throw on bad decode failure modes', () => {
|
|
165
|
+
assert.throws(() => decode(toBytes('{"a":1 & "b":2}')), 'JSON decode error: unexpected character at position 7, was expecting object delimiter but found \'&\'')
|
|
166
|
+
assert.throws(() => decode(toBytes('{"a":1,"b"!2}')), 'JSON decode error: unexpected character at position 10, was expecting key/value delimiter \':\' but found \'!\'')
|
|
167
|
+
assert.throws(() => decode(toBytes('[1,2&3]')), 'JSON decode error: unexpected character at position 4, was expecting array delimiter but found \'&\'')
|
|
168
|
+
assert.throws(() => decode(toBytes('{"a":!}')), 'JSON decode error: unexpected character at position 5')
|
|
169
|
+
assert.throws(() => decode(toBytes('"abc')), 'JSON decode error: unexpected end of string at position 4')
|
|
170
|
+
assert.throws(() => decode(toBytes('"ab\\xc"')), 'JSON decode error: unexpected string escape character at position 5')
|
|
171
|
+
assert.throws(() => decode(toBytes('"ab\x1Ec"')), 'JSON decode error: invalid control character at position 3')
|
|
172
|
+
assert.throws(() => decode(toBytes('"ab\\')), 'JSON decode error: unexpected string termination at position 4')
|
|
173
|
+
// begining of a quoted string with 3-byte unicode sequence with the last one truncated
|
|
174
|
+
assert.throws(() => decode(toBytes('"☺').subarray(0, 3)), 'JSON decode error: unexpected unicode sequence at position 1')
|
|
175
|
+
assert.throws(() => decode(toBytes('"\\uxyza"')), 'JSON decode error: unexpected unicode escape character at position 3')
|
|
176
|
+
assert.throws(() => decode(toBytes('"\\u11"')), 'JSON decode error: unexpected end of unicode escape sequence at position 3')
|
|
177
|
+
assert.throws(() => decode(toBytes('-boop')), 'JSON decode error: unexpected token at position 1')
|
|
178
|
+
assert.throws(() => decode(toBytes('{"v":nope}')), 'JSON decode error: unexpected token at position 7, expected to find \'null\'')
|
|
179
|
+
assert.throws(() => decode(toBytes('[n]')), 'JSON decode error: unexpected end of input at position 1')
|
|
180
|
+
assert.throws(() => decode(toBytes('{"v":truu}')), 'JSON decode error: unexpected token at position 9, expected to find \'true\'')
|
|
181
|
+
assert.throws(() => decode(toBytes('[tr]')), 'JSON decode error: unexpected end of input at position 1')
|
|
182
|
+
assert.throws(() => decode(toBytes('{"v":flase}')), 'JSON decode error: unexpected token at position 7, expected to find \'false\'')
|
|
183
|
+
assert.throws(() => decode(toBytes('[fa]')), 'JSON decode error: unexpected end of input at position 1')
|
|
184
|
+
assert.throws(() => decode(toBytes('-0..1')), 'JSON decode error: unexpected token at position 3')
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
it('should throw when rejectDuplicateMapKeys enabled on duplicate keys', () => {
|
|
188
|
+
assert.deepStrictEqual(decode(toBytes('{"foo":1,"foo":2}')), { foo: 2 })
|
|
189
|
+
assert.throws(() => decode(toBytes('{"foo":1,"foo":2}'), { rejectDuplicateMapKeys: true }), /JSON decode error: found repeat map key "foo"/)
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
it('decodeFirst', () => {
|
|
193
|
+
/*
|
|
194
|
+
const encoded = new TextDecoder().decode(encode(obj, sorting === false ? { mapSorter: null } : undefined))
|
|
195
|
+
const json = JSON.stringify(obj)
|
|
196
|
+
assert.strictEqual(encoded, json)
|
|
197
|
+
const decoded = decode(toBytes(JSON.stringify(obj)))
|
|
198
|
+
assert.deepStrictEqual(decoded, obj)
|
|
199
|
+
*/
|
|
200
|
+
let buf = new TextEncoder().encode('{"foo":1,"bar":2}1"ping"2null3[1,2,3]""[[],[],{"boop":true}]')
|
|
201
|
+
const expected = [
|
|
202
|
+
{ foo: 1, bar: 2 },
|
|
203
|
+
1,
|
|
204
|
+
'ping',
|
|
205
|
+
2,
|
|
206
|
+
null,
|
|
207
|
+
3,
|
|
208
|
+
[1, 2, 3],
|
|
209
|
+
'',
|
|
210
|
+
[[], [], { boop: true }]
|
|
211
|
+
]
|
|
212
|
+
for (const exp of expected) {
|
|
213
|
+
const [obj, rest] = decodeFirst(buf)
|
|
214
|
+
assert.deepStrictEqual(exp, obj)
|
|
215
|
+
buf = rest
|
|
216
|
+
}
|
|
217
|
+
assert.strictEqual(buf.length, 0)
|
|
218
|
+
})
|
|
219
|
+
})
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
|
|
3
|
+
import * as chai from 'chai'
|
|
4
|
+
import { garbage } from 'ipld-garbage'
|
|
5
|
+
import { uintBoundaries } from "@fireproof/vendor/cborg/utils"
|
|
6
|
+
import { encode } from "@fireproof/vendor/cborg"
|
|
7
|
+
import { encodedLength } from "@fireproof/vendor/cborg/length"
|
|
8
|
+
import { dateEncoder } from './common.js'
|
|
9
|
+
|
|
10
|
+
const { assert } = chai
|
|
11
|
+
|
|
12
|
+
function verifyLength (object, options) {
|
|
13
|
+
const len = encodedLength(object, options)
|
|
14
|
+
const encoded = encode(object, options)
|
|
15
|
+
const actual = encoded.length
|
|
16
|
+
assert.strictEqual(actual, len, JSON.stringify(object))
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
describe('encodedLength', () => {
|
|
20
|
+
it('int boundaries', () => {
|
|
21
|
+
for (let ii = 0; ii < 4; ii++) {
|
|
22
|
+
verifyLength(uintBoundaries[ii])
|
|
23
|
+
verifyLength(uintBoundaries[ii] - 1)
|
|
24
|
+
verifyLength(uintBoundaries[ii] + 1)
|
|
25
|
+
verifyLength(-1 * uintBoundaries[ii])
|
|
26
|
+
verifyLength(-1 * uintBoundaries[ii] - 1)
|
|
27
|
+
verifyLength(-1 * uintBoundaries[ii] + 1)
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('tags', () => {
|
|
32
|
+
verifyLength({ date: new Date('2013-03-21T20:04:00Z') }, { typeEncoders: { Date: dateEncoder } })
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('floats', () => {
|
|
36
|
+
verifyLength(0.5)
|
|
37
|
+
verifyLength(0.5, { float64: true })
|
|
38
|
+
verifyLength(8.940696716308594e-08)
|
|
39
|
+
verifyLength(8.940696716308594e-08, { float64: true })
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('small garbage', function () {
|
|
43
|
+
this.timeout(10000)
|
|
44
|
+
for (let ii = 0; ii < 1000; ii++) {
|
|
45
|
+
const gbg = garbage(1 << 6, { weights: { CID: 0 } })
|
|
46
|
+
verifyLength(gbg)
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
it('medium garbage', function () {
|
|
51
|
+
this.timeout(10000)
|
|
52
|
+
for (let ii = 0; ii < 100; ii++) {
|
|
53
|
+
const gbg = garbage(1 << 16, { weights: { CID: 0 } })
|
|
54
|
+
verifyLength(gbg)
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('large garbage', function () {
|
|
59
|
+
this.timeout(10000)
|
|
60
|
+
for (let ii = 0; ii < 10; ii++) {
|
|
61
|
+
const gbg = garbage(1 << 20, { weights: { CID: 0 } })
|
|
62
|
+
verifyLength(gbg)
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
})
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
|
|
3
|
+
import * as chai from 'chai'
|
|
4
|
+
import { garbage } from 'ipld-garbage'
|
|
5
|
+
import { uintBoundaries } from "@fireproof/vendor/cborg/utils"
|
|
6
|
+
import { encode, decodeFirst } from "@fireproof/vendor/cborg"
|
|
7
|
+
import { dateDecoder, dateEncoder } from './common.js'
|
|
8
|
+
|
|
9
|
+
const { assert } = chai
|
|
10
|
+
|
|
11
|
+
function verifyPartial (objects, options) {
|
|
12
|
+
const encoded = []
|
|
13
|
+
const lengths = []
|
|
14
|
+
let length = 0
|
|
15
|
+
for (const object of Array.isArray(objects) ? objects : [objects]) {
|
|
16
|
+
encoded.push(encode(object, options))
|
|
17
|
+
const l = encoded[encoded.length - 1].length
|
|
18
|
+
length += l
|
|
19
|
+
lengths.push(l)
|
|
20
|
+
}
|
|
21
|
+
const buf = new Uint8Array(length)
|
|
22
|
+
let offset = 0
|
|
23
|
+
for (const enc of encoded) {
|
|
24
|
+
buf.set(enc, offset)
|
|
25
|
+
offset += enc.length
|
|
26
|
+
}
|
|
27
|
+
let partial = buf
|
|
28
|
+
for (let ii = 0; ii < encoded.length; ii++) {
|
|
29
|
+
const [decoded, remainder] = decodeFirst(partial, options)
|
|
30
|
+
assert.deepEqual(decoded, objects[ii])
|
|
31
|
+
assert.equal(remainder.length, partial.length - lengths[ii])
|
|
32
|
+
partial = remainder
|
|
33
|
+
}
|
|
34
|
+
assert.equal(partial.length, 0) // just to be sure
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
describe('decodePartial', () => {
|
|
38
|
+
describe('multiple', () => {
|
|
39
|
+
it('simple', () => {
|
|
40
|
+
verifyPartial([1, 2, 3])
|
|
41
|
+
verifyPartial([8.940696716308594e-08, 1])
|
|
42
|
+
verifyPartial([
|
|
43
|
+
[],
|
|
44
|
+
[1, 2, { obj: 1.5 }, null, new Uint8Array([1, 2, 3])],
|
|
45
|
+
{ boop: true, bop: 1 },
|
|
46
|
+
'nope',
|
|
47
|
+
{ o: 'nope' },
|
|
48
|
+
new Uint8Array([1, 2, 3]),
|
|
49
|
+
true,
|
|
50
|
+
null
|
|
51
|
+
])
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('options', () => {
|
|
55
|
+
const m = new Map()
|
|
56
|
+
m.set('a', 1)
|
|
57
|
+
m.set('b', null)
|
|
58
|
+
m.set('c', 'grok')
|
|
59
|
+
m.set('date', new Date('2013-03-21T20:04:00Z'))
|
|
60
|
+
verifyPartial(
|
|
61
|
+
[8.940696716308594e-08, 1, null, 'grok', new Date('2013-03-21T20:04:00Z'),
|
|
62
|
+
[8.940696716308594e-08, 1, null, 'grok', new Date('2013-03-21T20:04:00Z')],
|
|
63
|
+
m
|
|
64
|
+
],
|
|
65
|
+
{ typeEncoders: { Date: dateEncoder }, useMaps: true, tags: { 0: dateDecoder } })
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it('garbage', function () {
|
|
69
|
+
this.timeout(10000)
|
|
70
|
+
for (let ii = 0; ii < 10; ii++) {
|
|
71
|
+
const gbg = []
|
|
72
|
+
for (let ii = 0; ii < 100; ii++) {
|
|
73
|
+
gbg.push(garbage(1 << 6, { weights: { CID: 0 } }))
|
|
74
|
+
}
|
|
75
|
+
verifyPartial(gbg)
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it('singular', () => {
|
|
81
|
+
it('int boundaries', () => {
|
|
82
|
+
for (let ii = 0; ii < 4; ii++) {
|
|
83
|
+
verifyPartial(uintBoundaries[ii])
|
|
84
|
+
verifyPartial(uintBoundaries[ii] - 1)
|
|
85
|
+
verifyPartial(uintBoundaries[ii] + 1)
|
|
86
|
+
verifyPartial(-1 * uintBoundaries[ii])
|
|
87
|
+
verifyPartial(-1 * uintBoundaries[ii] - 1)
|
|
88
|
+
verifyPartial(-1 * uintBoundaries[ii] + 1)
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it('tags', () => {
|
|
93
|
+
verifyPartial({ date: new Date('2013-03-21T20:04:00Z') }, { typeEncoders: { Date: dateEncoder } })
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
it('floats', () => {
|
|
97
|
+
verifyPartial(0.5)
|
|
98
|
+
verifyPartial(0.5, { float64: true })
|
|
99
|
+
verifyPartial(8.940696716308594e-08)
|
|
100
|
+
verifyPartial(8.940696716308594e-08, { float64: true })
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
it('small garbage', function () {
|
|
104
|
+
this.timeout(10000)
|
|
105
|
+
for (let ii = 0; ii < 1000; ii++) {
|
|
106
|
+
const gbg = garbage(1 << 6, { weights: { CID: 0 } })
|
|
107
|
+
verifyPartial(gbg)
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
})
|
|
111
|
+
})
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"allowJs": true,
|
|
4
|
+
"checkJs": true,
|
|
5
|
+
"forceConsistentCasingInFileNames": true,
|
|
6
|
+
"noImplicitReturns": false,
|
|
7
|
+
"noImplicitAny": true,
|
|
8
|
+
"noImplicitThis": true,
|
|
9
|
+
"noFallthroughCasesInSwitch": true,
|
|
10
|
+
"noUnusedLocals": true,
|
|
11
|
+
"noUnusedParameters": true,
|
|
12
|
+
"strictFunctionTypes": false,
|
|
13
|
+
"strictNullChecks": true,
|
|
14
|
+
"strictPropertyInitialization": true,
|
|
15
|
+
"strictBindCallApply": true,
|
|
16
|
+
"strict": true,
|
|
17
|
+
"alwaysStrict": true,
|
|
18
|
+
"esModuleInterop": true,
|
|
19
|
+
"target": "ES2018",
|
|
20
|
+
"moduleResolution": "node",
|
|
21
|
+
"declaration": true,
|
|
22
|
+
"declarationMap": true,
|
|
23
|
+
"outDir": "types",
|
|
24
|
+
"skipLibCheck": true,
|
|
25
|
+
"stripInternal": true,
|
|
26
|
+
"resolveJsonModule": true,
|
|
27
|
+
"baseUrl": ".",
|
|
28
|
+
"emitDeclarationOnly": true,
|
|
29
|
+
"paths": {
|
|
30
|
+
"cborg": [
|
|
31
|
+
"cborg/index.js"
|
|
32
|
+
],
|
|
33
|
+
"cborg/utils": [
|
|
34
|
+
"./utils/index.js"
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"include": [
|
|
39
|
+
"cborg.js",
|
|
40
|
+
"example.js",
|
|
41
|
+
"taglib.js",
|
|
42
|
+
"lib/"
|
|
43
|
+
, "utils/byte-utils.js", "utils/jump.js", "utils/0uint.js", "utils/1negint.js", "utils/2bytes.js", "utils/3string.js", "utils/4array.js", "utils/5map.js", "utils/6tag.js", "utils/7float.js", "json" ],
|
|
44
|
+
"exclude": [
|
|
45
|
+
"node_modules"
|
|
46
|
+
],
|
|
47
|
+
"compileOnSave": false
|
|
48
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export type Token = import("cborg/utils").Token;
|
|
2
|
+
export type DecodeOptions = import("../interface").DecodeOptions;
|
|
3
|
+
export type DecodeTokenizer = import("../interface").DecodeTokenizer;
|
|
4
|
+
export type DecodeFunction = import("../interface").DecodeFunction;
|
|
5
|
+
/**
|
|
6
|
+
* @implements {DecodeTokenizer}
|
|
7
|
+
*/
|
|
8
|
+
export class Tokeniser implements DecodeTokenizer {
|
|
9
|
+
/**
|
|
10
|
+
* @param {Uint8Array} data
|
|
11
|
+
* @param {DecodeOptions} options
|
|
12
|
+
*/
|
|
13
|
+
constructor(data: Uint8Array, options: DecodeOptions);
|
|
14
|
+
_pos: number;
|
|
15
|
+
data: Uint8Array<ArrayBufferLike>;
|
|
16
|
+
options: import("../interface").DecodeOptions;
|
|
17
|
+
jump: import("../interface").DecodeFunction[];
|
|
18
|
+
pos(): number;
|
|
19
|
+
done(): boolean;
|
|
20
|
+
next(): import("cborg/utils").Token;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @param {DecodeTokenizer} tokeniser
|
|
24
|
+
* @param {DecodeOptions} options
|
|
25
|
+
* @returns {any|BREAK|DONE}
|
|
26
|
+
*/
|
|
27
|
+
export function tokensToObject(tokeniser: DecodeTokenizer, options: DecodeOptions): any | typeof BREAK | typeof DONE;
|
|
28
|
+
/**
|
|
29
|
+
* @param {Uint8Array} data
|
|
30
|
+
* @param {DecodeOptions} [options]
|
|
31
|
+
* @returns {any}
|
|
32
|
+
*/
|
|
33
|
+
export function decode(data: Uint8Array, options?: DecodeOptions): any;
|
|
34
|
+
/**
|
|
35
|
+
* @param {Uint8Array} data
|
|
36
|
+
* @param {DecodeOptions} [options]
|
|
37
|
+
* @returns {[any, Uint8Array]}
|
|
38
|
+
*/
|
|
39
|
+
export function decodeFirst(data: Uint8Array, options?: DecodeOptions): [any, Uint8Array];
|
|
40
|
+
declare const BREAK: unique symbol;
|
|
41
|
+
declare const DONE: unique symbol;
|
|
42
|
+
export {};
|
|
43
|
+
//# sourceMappingURL=decode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../../cborg/decode.js"],"names":[],"mappings":"oBAGa,OAAO,aAAa,EAAE,KAAK;4BAC3B,OAAO,cAAc,EAAE,aAAa;8BACpC,OAAO,cAAc,EAAE,eAAe;6BACtC,OAAO,cAAc,EAAE,cAAc;AAWlD;;GAEG;AACH,kCAFgB,eAAe;IAG7B;;;OAGG;IACH,kBAHW,UAAU,WACV,aAAa,EAOvB;IAJC,aAAa;IACb,kCAAgB;IAChB,8CAAsB;IACtB,8CAAyC;IAG3C,cAEC;IAED,gBAEC;IAED,oCAgBC;CACF;AA6ED;;;;GAIG;AACH,0CAJW,eAAe,WACf,aAAa,GACX,GAAG,6BAAW,CAoC1B;AAuBD;;;;GAIG;AACH,6BAJW,UAAU,YACV,aAAa,GACX,GAAG,CASf;AAjCD;;;;GAIG;AACH,kCAJW,UAAU,YACV,aAAa,GACX,CAAC,GAAG,EAAE,UAAU,CAAC,CAgB7B;AAtID,mCAAiC;AADjC,kCAA+B"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** @returns {TokenTypeEncoder[]} */
|
|
2
|
+
export function makeCborEncoders(): TokenTypeEncoder[];
|
|
3
|
+
export type EncodeOptions = import("../interface").EncodeOptions;
|
|
4
|
+
export type OptionalTypeEncoder = import("../interface").OptionalTypeEncoder;
|
|
5
|
+
export type Reference = import("../interface").Reference;
|
|
6
|
+
export type StrictTypeEncoder = import("../interface").StrictTypeEncoder;
|
|
7
|
+
export type TokenTypeEncoder = import("../interface").TokenTypeEncoder;
|
|
8
|
+
export type TokenOrNestedTokens = import("../interface").TokenOrNestedTokens;
|
|
9
|
+
/**
|
|
10
|
+
* @param {any} obj
|
|
11
|
+
* @param {EncodeOptions} options
|
|
12
|
+
* @param {Reference} [refStack]
|
|
13
|
+
* @returns {TokenOrNestedTokens}
|
|
14
|
+
*/
|
|
15
|
+
export function objectToTokens(obj: any, options: EncodeOptions, refStack?: Reference): TokenOrNestedTokens;
|
|
16
|
+
/**
|
|
17
|
+
* @param {any} data
|
|
18
|
+
* @param {EncodeOptions} [options]
|
|
19
|
+
* @returns {Uint8Array}
|
|
20
|
+
*/
|
|
21
|
+
export function encode(data: any, options?: EncodeOptions): Uint8Array;
|
|
22
|
+
/**
|
|
23
|
+
* @param {any} data
|
|
24
|
+
* @param {TokenTypeEncoder[]} encoders
|
|
25
|
+
* @param {EncodeOptions} options
|
|
26
|
+
* @returns {Uint8Array}
|
|
27
|
+
*/
|
|
28
|
+
export function encodeCustom(data: any, encoders: TokenTypeEncoder[], options: EncodeOptions): Uint8Array;
|
|
29
|
+
/** @implements {Reference} */
|
|
30
|
+
export class Ref implements Reference {
|
|
31
|
+
/**
|
|
32
|
+
* @param {Reference|undefined} stack
|
|
33
|
+
* @param {object|any[]} obj
|
|
34
|
+
* @param {EncodeOptions} options
|
|
35
|
+
* @returns {Reference}
|
|
36
|
+
*/
|
|
37
|
+
static createCheck(stack: Reference | undefined, obj: object | any[], { encodeErrPrefix }: EncodeOptions): Reference;
|
|
38
|
+
/**
|
|
39
|
+
* @param {object|any[]} obj
|
|
40
|
+
* @param {Reference|undefined} parent
|
|
41
|
+
*/
|
|
42
|
+
constructor(obj: object | any[], parent: Reference | undefined);
|
|
43
|
+
obj: object | any[];
|
|
44
|
+
parent: import("../interface").Reference | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* @param {object|any[]} obj
|
|
47
|
+
* @returns {boolean}
|
|
48
|
+
*/
|
|
49
|
+
includes(obj: object | any[]): boolean;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=encode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../cborg/encode.js"],"names":[],"mappings":"AAiCA,oCAAoC;AACpC,oCADc,gBAAgB,EAAE,CAY/B;4BA7BY,OAAO,cAAc,EAAE,aAAa;kCACpC,OAAO,cAAc,EAAE,mBAAmB;wBAC1C,OAAO,cAAc,EAAE,SAAS;gCAChC,OAAO,cAAc,EAAE,iBAAiB;+BACxC,OAAO,cAAc,EAAE,gBAAgB;kCACvC,OAAO,cAAc,EAAE,mBAAmB;AAmQvD;;;;;GAKG;AACH,oCALW,GAAG,WACH,aAAa,aACb,SAAS,GACP,mBAAmB,CAgB/B;AA2JD;;;;GAIG;AACH,6BAJW,GAAG,YACH,aAAa,GACX,UAAU,CAKtB;AAvCD;;;;;GAKG;AACH,mCALW,GAAG,YACH,gBAAgB,EAAE,WAClB,aAAa,GACX,UAAU,CAyBtB;AAlZD,8BAA8B;AAC9B,4BADiB,SAAS;IA0BxB;;;;;OAKG;IACH,0BALW,SAAS,GAAC,SAAS,OACnB,MAAM,GAAC,GAAG,EAAE,uBACZ,aAAa,GACX,SAAS,CAOrB;IAnCD;;;OAGG;IACH,iBAHW,MAAM,GAAC,GAAG,EAAE,UACZ,SAAS,GAAC,SAAS,EAK7B;IAFC,oBAAc;IACd,qDAAoB;IAGtB;;;OAGG;IACH,cAHW,MAAM,GAAC,GAAG,EAAE,GACV,OAAO,CAWnB;CAcF"}
|