@fireproof/core 0.20.4 → 0.20.5-dev-preview-3
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/apply-head-queue.d.ts +18 -0
- package/apply-head-queue.d.ts.map +1 -0
- package/apply-head-queue.js +47 -0
- package/apply-head-queue.js.map +1 -0
- package/blockstore/attachable-store.d.ts +19 -0
- package/blockstore/attachable-store.d.ts.map +1 -0
- package/blockstore/attachable-store.js +316 -0
- package/blockstore/attachable-store.js.map +1 -0
- package/blockstore/commit-queue.d.ts +17 -0
- package/blockstore/commit-queue.d.ts.map +1 -0
- package/blockstore/commit-queue.js +60 -0
- package/blockstore/commit-queue.js.map +1 -0
- package/blockstore/commitor.d.ts +21 -0
- package/blockstore/commitor.d.ts.map +1 -0
- package/blockstore/commitor.js +95 -0
- package/blockstore/commitor.js.map +1 -0
- package/blockstore/connect-raw.d.ts +2 -0
- package/blockstore/connect-raw.d.ts.map +1 -0
- package/blockstore/connect-raw.js +2 -0
- package/blockstore/connect-raw.js.map +1 -0
- package/blockstore/connection-base.d.ts +2 -0
- package/blockstore/connection-base.d.ts.map +1 -0
- package/blockstore/connection-base.js +2 -0
- package/blockstore/connection-base.js.map +1 -0
- package/blockstore/encrypt-helpers.d.ts +2 -0
- package/blockstore/encrypt-helpers.d.ts.map +1 -0
- package/blockstore/encrypt-helpers.js +2 -0
- package/blockstore/encrypt-helpers.js.map +1 -0
- package/blockstore/fp-envelope.d.ts +32 -0
- package/blockstore/fp-envelope.d.ts.map +1 -0
- package/blockstore/fp-envelope.js +14 -0
- package/blockstore/fp-envelope.js.map +1 -0
- package/blockstore/gateway.d.ts +20 -0
- package/blockstore/gateway.d.ts.map +1 -0
- package/blockstore/gateway.js +2 -0
- package/blockstore/gateway.js.map +1 -0
- package/blockstore/index.d.ts +16 -0
- package/blockstore/index.d.ts.map +1 -0
- package/blockstore/index.js +16 -0
- package/blockstore/index.js.map +1 -0
- package/blockstore/interceptor-gateway.d.ts +29 -0
- package/blockstore/interceptor-gateway.d.ts.map +1 -0
- package/blockstore/interceptor-gateway.js +137 -0
- package/blockstore/interceptor-gateway.js.map +1 -0
- package/blockstore/loader-helpers.d.ts +10 -0
- package/blockstore/loader-helpers.d.ts.map +1 -0
- package/blockstore/loader-helpers.js +115 -0
- package/blockstore/loader-helpers.js.map +1 -0
- package/blockstore/loader.d.ts +61 -0
- package/blockstore/loader.d.ts.map +1 -0
- package/blockstore/loader.js +494 -0
- package/blockstore/loader.js.map +1 -0
- package/blockstore/register-store-protocol.d.ts +22 -0
- package/blockstore/register-store-protocol.d.ts.map +1 -0
- package/blockstore/register-store-protocol.js +114 -0
- package/blockstore/register-store-protocol.js.map +1 -0
- package/blockstore/serde-gateway.d.ts +78 -0
- package/blockstore/serde-gateway.d.ts.map +1 -0
- package/blockstore/serde-gateway.js +2 -0
- package/blockstore/serde-gateway.js.map +1 -0
- package/blockstore/store-factory.d.ts +11 -0
- package/blockstore/store-factory.d.ts.map +1 -0
- package/blockstore/store-factory.js +104 -0
- package/blockstore/store-factory.js.map +1 -0
- package/blockstore/store-remote.d.ts +2 -0
- package/blockstore/store-remote.d.ts.map +1 -0
- package/blockstore/store-remote.js +2 -0
- package/blockstore/store-remote.js.map +1 -0
- package/blockstore/store.d.ts +86 -0
- package/blockstore/store.d.ts.map +1 -0
- package/blockstore/store.js +439 -0
- package/blockstore/store.js.map +1 -0
- package/blockstore/task-manager.d.ts +19 -0
- package/blockstore/task-manager.d.ts.map +1 -0
- package/blockstore/task-manager.js +50 -0
- package/blockstore/task-manager.js.map +1 -0
- package/blockstore/transaction.d.ts +62 -0
- package/blockstore/transaction.d.ts.map +1 -0
- package/blockstore/transaction.js +261 -0
- package/blockstore/transaction.js.map +1 -0
- package/blockstore/types.d.ts +508 -0
- package/blockstore/types.d.ts.map +1 -0
- package/blockstore/types.js +83 -0
- package/blockstore/types.js.map +1 -0
- package/blockstore/uri-interceptor.d.ts +19 -0
- package/blockstore/uri-interceptor.d.ts.map +1 -0
- package/blockstore/uri-interceptor.js +61 -0
- package/blockstore/uri-interceptor.js.map +1 -0
- package/bundle-not-impl.d.ts +2 -0
- package/bundle-not-impl.d.ts.map +1 -0
- package/bundle-not-impl.js +4 -0
- package/bundle-not-impl.js.map +1 -0
- package/cli/main.js +26616 -0
- package/crdt-clock.d.ts +27 -0
- package/crdt-clock.d.ts.map +1 -0
- package/crdt-clock.js +138 -0
- package/crdt-clock.js.map +1 -0
- package/crdt-helpers.d.ts +19 -0
- package/crdt-helpers.d.ts.map +1 -0
- package/crdt-helpers.js +332 -0
- package/crdt-helpers.js.map +1 -0
- package/crdt.d.ts +41 -0
- package/crdt.d.ts.map +1 -0
- package/crdt.js +164 -0
- package/crdt.js.map +1 -0
- package/database.d.ts +34 -0
- package/database.d.ts.map +1 -0
- package/database.js +124 -0
- package/database.js.map +1 -0
- package/deno.json +2 -2
- package/index.d.ts +15 -2741
- package/index.d.ts.map +1 -0
- package/index.js +14 -7274
- package/index.js.map +1 -1
- package/indexer-helpers.d.ts +69 -0
- package/indexer-helpers.d.ts.map +1 -0
- package/indexer-helpers.js +136 -0
- package/indexer-helpers.js.map +1 -0
- package/indexer.d.ts +24 -0
- package/indexer.d.ts.map +1 -0
- package/indexer.js +230 -0
- package/indexer.js.map +1 -0
- package/ledger.d.ts +55 -0
- package/ledger.d.ts.map +1 -0
- package/ledger.js +234 -0
- package/ledger.js.map +1 -0
- package/package.json +26 -17
- package/protocols/cloud/http-connection.d.ts +25 -0
- package/protocols/cloud/http-connection.d.ts.map +1 -0
- package/protocols/cloud/http-connection.js +153 -0
- package/protocols/cloud/http-connection.js.map +1 -0
- package/protocols/cloud/index.d.ts +10 -0
- package/protocols/cloud/index.d.ts.map +1 -0
- package/protocols/cloud/index.js +10 -0
- package/protocols/cloud/index.js.map +1 -0
- package/protocols/cloud/msg-raw-connection-base.d.ts +16 -0
- package/protocols/cloud/msg-raw-connection-base.d.ts.map +1 -0
- package/protocols/cloud/msg-raw-connection-base.js +22 -0
- package/protocols/cloud/msg-raw-connection-base.js.map +1 -0
- package/protocols/cloud/msg-types-data.d.ts +36 -0
- package/protocols/cloud/msg-types-data.d.ts.map +1 -0
- package/protocols/cloud/msg-types-data.js +38 -0
- package/protocols/cloud/msg-types-data.js.map +1 -0
- package/protocols/cloud/msg-types-meta.d.ts +41 -0
- package/protocols/cloud/msg-types-meta.d.ts.map +1 -0
- package/protocols/cloud/msg-types-meta.js +98 -0
- package/protocols/cloud/msg-types-meta.js.map +1 -0
- package/protocols/cloud/msg-types-wal.d.ts +33 -0
- package/protocols/cloud/msg-types-wal.d.ts.map +1 -0
- package/protocols/cloud/msg-types-wal.js +38 -0
- package/protocols/cloud/msg-types-wal.js.map +1 -0
- package/protocols/cloud/msg-types.d.ts +282 -0
- package/protocols/cloud/msg-types.d.ts.map +1 -0
- package/protocols/cloud/msg-types.js +278 -0
- package/protocols/cloud/msg-types.js.map +1 -0
- package/protocols/cloud/msger.d.ts +79 -0
- package/protocols/cloud/msger.d.ts.map +1 -0
- package/protocols/cloud/msger.js +198 -0
- package/protocols/cloud/msger.js.map +1 -0
- package/protocols/cloud/ws-connection.d.ts +29 -0
- package/protocols/cloud/ws-connection.d.ts.map +1 -0
- package/protocols/cloud/ws-connection.js +166 -0
- package/protocols/cloud/ws-connection.js.map +1 -0
- package/protocols/index.d.ts +2 -0
- package/protocols/index.d.ts.map +1 -0
- package/protocols/index.js +2 -0
- package/protocols/index.js.map +1 -0
- package/react/create-attach.d.ts +6 -0
- package/react/create-attach.d.ts.map +1 -0
- package/react/create-attach.js +75 -0
- package/react/create-attach.js.map +1 -0
- package/react/{index.d.cts → img-file.d.ts} +6 -53
- package/react/img-file.d.ts.map +1 -0
- package/react/img-file.js +57 -0
- package/react/img-file.js.map +1 -0
- package/react/index.d.ts +5 -336
- package/react/index.d.ts.map +1 -0
- package/react/index.js +4 -269
- package/react/index.js.map +1 -1
- package/react/types.d.ts +71 -0
- package/react/types.d.ts.map +1 -0
- package/react/types.js +2 -0
- package/react/types.js.map +1 -0
- package/react/use-all-docs.d.ts +4 -0
- package/react/use-all-docs.d.ts.map +1 -0
- package/react/use-all-docs.js +25 -0
- package/react/use-all-docs.js.map +1 -0
- package/react/use-attach.d.ts +6 -0
- package/react/use-attach.d.ts.map +1 -0
- package/react/use-attach.js +75 -0
- package/react/use-attach.js.map +1 -0
- package/react/use-changes.d.ts +4 -0
- package/react/use-changes.d.ts.map +1 -0
- package/react/use-changes.js +19 -0
- package/react/use-changes.js.map +1 -0
- package/react/use-document.d.ts +4 -0
- package/react/use-document.d.ts.map +1 -0
- package/react/use-document.js +109 -0
- package/react/use-document.js.map +1 -0
- package/react/use-fireproof.d.ts +6 -0
- package/react/use-fireproof.d.ts.map +1 -0
- package/react/use-fireproof.js +20 -0
- package/react/use-fireproof.js.map +1 -0
- package/react/use-live-query.d.ts +4 -0
- package/react/use-live-query.d.ts.map +1 -0
- package/react/use-live-query.js +27 -0
- package/react/use-live-query.js.map +1 -0
- package/runtime/files.d.ts +12 -0
- package/runtime/files.d.ts.map +1 -0
- package/runtime/files.js +29 -0
- package/runtime/files.js.map +1 -0
- package/runtime/gateways/cloud/gateway.d.ts +42 -0
- package/runtime/gateways/cloud/gateway.d.ts.map +1 -0
- package/runtime/gateways/cloud/gateway.js +528 -0
- package/runtime/gateways/cloud/gateway.js.map +1 -0
- package/runtime/gateways/cloud/index.d.ts +3 -0
- package/runtime/gateways/cloud/index.d.ts.map +1 -0
- package/runtime/gateways/cloud/index.js +3 -0
- package/runtime/gateways/cloud/index.js.map +1 -0
- package/runtime/gateways/cloud/to-cloud.d.ts +46 -0
- package/runtime/gateways/cloud/to-cloud.d.ts.map +1 -0
- package/runtime/gateways/cloud/to-cloud.js +159 -0
- package/runtime/gateways/cloud/to-cloud.js.map +1 -0
- package/runtime/gateways/def-serde-gateway.d.ts +18 -0
- package/runtime/gateways/def-serde-gateway.d.ts.map +1 -0
- package/runtime/gateways/def-serde-gateway.js +89 -0
- package/runtime/gateways/def-serde-gateway.js.map +1 -0
- package/runtime/gateways/file/deno/deno-filesystem.d.ts +27 -0
- package/runtime/gateways/file/deno/deno-filesystem.d.ts.map +1 -0
- package/runtime/gateways/file/deno/deno-filesystem.js +52 -0
- package/runtime/gateways/file/deno/deno-filesystem.js.map +1 -0
- package/runtime/gateways/file/deno/get-sys-file-system.d.ts +4 -0
- package/runtime/gateways/file/deno/get-sys-file-system.d.ts.map +1 -0
- package/runtime/gateways/file/deno/get-sys-file-system.js +11 -0
- package/runtime/gateways/file/deno/get-sys-file-system.js.map +1 -0
- package/runtime/gateways/file/deno/index.d.ts +2 -0
- package/runtime/gateways/file/deno/index.d.ts.map +1 -0
- package/runtime/gateways/file/deno/index.js +2 -0
- package/runtime/gateways/file/deno/index.js.map +1 -0
- package/runtime/gateways/file/gateway-impl.d.ts +18 -0
- package/runtime/gateways/file/gateway-impl.d.ts.map +1 -0
- package/runtime/gateways/file/gateway-impl.js +121 -0
- package/runtime/gateways/file/gateway-impl.js.map +1 -0
- package/runtime/gateways/file/index.d.ts +3 -0
- package/runtime/gateways/file/index.d.ts.map +1 -0
- package/runtime/gateways/file/index.js +3 -0
- package/runtime/gateways/file/index.js.map +1 -0
- package/runtime/gateways/file/key-bag-file.d.ts +19 -0
- package/runtime/gateways/file/key-bag-file.d.ts.map +1 -0
- package/runtime/gateways/file/key-bag-file.js +40 -0
- package/runtime/gateways/file/key-bag-file.js.map +1 -0
- package/runtime/gateways/file/node/get-sys-file-system.d.ts +4 -0
- package/runtime/gateways/file/node/get-sys-file-system.d.ts.map +1 -0
- package/runtime/gateways/file/node/get-sys-file-system.js +11 -0
- package/runtime/gateways/file/node/get-sys-file-system.js.map +1 -0
- package/runtime/gateways/file/node/index.d.ts +2 -0
- package/runtime/gateways/file/node/index.d.ts.map +1 -0
- package/runtime/gateways/file/node/index.js +2 -0
- package/runtime/gateways/file/node/index.js.map +1 -0
- package/runtime/gateways/file/node/node-filesystem.d.ts +32 -0
- package/runtime/gateways/file/node/node-filesystem.d.ts.map +1 -0
- package/runtime/gateways/file/node/node-filesystem.js +33 -0
- package/runtime/gateways/file/node/node-filesystem.js.map +1 -0
- package/runtime/gateways/file/node/to-array-buffer.d.ts +2 -0
- package/runtime/gateways/file/node/to-array-buffer.d.ts.map +1 -0
- package/runtime/gateways/file/node/to-array-buffer.js +12 -0
- package/runtime/gateways/file/node/to-array-buffer.js.map +1 -0
- package/runtime/gateways/file/sys-file-system-factory.d.ts +4 -0
- package/runtime/gateways/file/sys-file-system-factory.d.ts.map +1 -0
- package/runtime/gateways/file/sys-file-system-factory.js +13 -0
- package/runtime/gateways/file/sys-file-system-factory.js.map +1 -0
- package/runtime/gateways/file/utils.d.ts +5 -0
- package/runtime/gateways/file/utils.d.ts.map +1 -0
- package/runtime/gateways/file/utils.js +27 -0
- package/runtime/gateways/file/utils.js.map +1 -0
- package/runtime/gateways/file/version.d.ts +2 -0
- package/runtime/gateways/file/version.d.ts.map +1 -0
- package/runtime/gateways/file/version.js +2 -0
- package/runtime/gateways/file/version.js.map +1 -0
- package/runtime/gateways/fp-envelope-serialize.d.ts +50 -0
- package/runtime/gateways/fp-envelope-serialize.d.ts.map +1 -0
- package/runtime/gateways/fp-envelope-serialize.js +141 -0
- package/runtime/gateways/fp-envelope-serialize.js.map +1 -0
- package/runtime/gateways/index.d.ts +6 -0
- package/runtime/gateways/index.d.ts.map +1 -0
- package/runtime/gateways/index.js +6 -0
- package/runtime/gateways/index.js.map +1 -0
- package/runtime/gateways/indexeddb/gateway-impl.d.ts +22 -0
- package/runtime/gateways/indexeddb/gateway-impl.d.ts.map +1 -0
- package/runtime/gateways/indexeddb/gateway-impl.js +147 -0
- package/runtime/gateways/indexeddb/gateway-impl.js.map +1 -0
- package/runtime/gateways/indexeddb/index.d.ts +6 -0
- package/runtime/gateways/indexeddb/index.d.ts.map +1 -0
- package/runtime/gateways/indexeddb/index.js +6 -0
- package/runtime/gateways/indexeddb/index.js.map +1 -0
- package/runtime/gateways/indexeddb/key-bag-indexeddb.d.ts +15 -0
- package/runtime/gateways/indexeddb/key-bag-indexeddb.d.ts.map +1 -0
- package/runtime/gateways/indexeddb/key-bag-indexeddb.js +42 -0
- package/runtime/gateways/indexeddb/key-bag-indexeddb.js.map +1 -0
- package/runtime/gateways/indexeddb-version.d.ts +2 -0
- package/runtime/gateways/indexeddb-version.d.ts.map +1 -0
- package/runtime/gateways/indexeddb-version.js +2 -0
- package/runtime/gateways/indexeddb-version.js.map +1 -0
- package/runtime/gateways/memory/gateway.d.ts +18 -0
- package/runtime/gateways/memory/gateway.d.ts.map +1 -0
- package/runtime/gateways/memory/gateway.js +73 -0
- package/runtime/gateways/memory/gateway.js.map +1 -0
- package/runtime/gateways/memory/version.d.ts +2 -0
- package/runtime/gateways/memory/version.d.ts.map +1 -0
- package/runtime/gateways/memory/version.js +2 -0
- package/runtime/gateways/memory/version.js.map +1 -0
- package/runtime/index.d.ts +13 -0
- package/runtime/index.d.ts.map +1 -0
- package/runtime/index.js +13 -0
- package/runtime/index.js.map +1 -0
- package/runtime/key-bag-memory.d.ts +12 -0
- package/runtime/key-bag-memory.d.ts.map +1 -0
- package/runtime/key-bag-memory.js +23 -0
- package/runtime/key-bag-memory.js.map +1 -0
- package/runtime/key-bag.d.ts +85 -0
- package/runtime/key-bag.d.ts.map +1 -0
- package/runtime/key-bag.js +411 -0
- package/runtime/key-bag.js.map +1 -0
- package/runtime/keyed-crypto.d.ts +19 -0
- package/runtime/keyed-crypto.d.ts.map +1 -0
- package/runtime/keyed-crypto.js +192 -0
- package/runtime/keyed-crypto.js.map +1 -0
- package/runtime/memory-sys-container.d.ts +2 -0
- package/runtime/memory-sys-container.d.ts.map +1 -0
- package/runtime/memory-sys-container.js +2 -0
- package/runtime/memory-sys-container.js.map +1 -0
- package/runtime/meta-key-hack.d.ts +42 -0
- package/runtime/meta-key-hack.d.ts.map +1 -0
- package/runtime/meta-key-hack.js +201 -0
- package/runtime/meta-key-hack.js.map +1 -0
- package/runtime/sts-service/index.d.ts +40 -0
- package/runtime/sts-service/index.d.ts.map +1 -0
- package/runtime/sts-service/index.js +102 -0
- package/runtime/sts-service/index.js.map +1 -0
- package/runtime/sys-container.d.ts +2 -0
- package/runtime/sys-container.d.ts.map +1 -0
- package/runtime/sys-container.js +2 -0
- package/runtime/sys-container.js.map +1 -0
- package/runtime/wait-pr-multiformats/block.d.ts +47 -0
- package/runtime/wait-pr-multiformats/block.d.ts.map +1 -0
- package/runtime/wait-pr-multiformats/block.js +64 -0
- package/runtime/wait-pr-multiformats/block.js.map +1 -0
- package/runtime/wait-pr-multiformats/codec-interface.d.ts +29 -0
- package/runtime/wait-pr-multiformats/codec-interface.d.ts.map +1 -0
- package/runtime/wait-pr-multiformats/codec-interface.js +2 -0
- package/runtime/wait-pr-multiformats/codec-interface.js.map +1 -0
- package/runtime/wait-pr-multiformats/index.d.ts +3 -0
- package/runtime/wait-pr-multiformats/index.d.ts.map +1 -0
- package/runtime/wait-pr-multiformats/index.js +3 -0
- package/runtime/wait-pr-multiformats/index.js.map +1 -0
- package/tests/blockstore/interceptor-gateway.test.ts +10 -9
- package/tests/blockstore/keyed-crypto.test.ts +2 -2
- package/tests/blockstore/loader.test.ts +68 -51
- package/tests/blockstore/standalone.test.ts +152 -0
- package/tests/blockstore/store.test.ts +16 -9
- package/tests/blockstore/transaction.test.ts +19 -16
- package/tests/fireproof/all-gateway.test.ts +12 -27
- package/tests/fireproof/attachable.test.ts +426 -97
- package/tests/fireproof/crdt.test.ts +23 -0
- package/tests/fireproof/database.test.ts +13 -12
- package/tests/fireproof/fireproof.test.ts +2 -5
- package/tests/fireproof/indexer.test.ts +4 -0
- package/tests/helpers.ts +30 -14
- package/tests/react/img-file.test.tsx +0 -9
- package/tests/react/use-fireproof-stability.test.tsx +5 -5
- package/tests/react/use-fireproof.test.tsx +18 -13
- package/tests/runtime/meta-key-hack.test.ts +7 -6
- package/tests/setup.indexeddb.ts +0 -9
- package/types.d.ts +460 -0
- package/types.d.ts.map +1 -0
- package/types.js +60 -0
- package/types.js.map +1 -0
- package/use-fireproof/iframe-strategy.d.ts +13 -0
- package/use-fireproof/iframe-strategy.d.ts.map +1 -0
- package/use-fireproof/iframe-strategy.js +83 -0
- package/use-fireproof/iframe-strategy.js.map +1 -0
- package/use-fireproof/index.d.ts +10 -0
- package/use-fireproof/index.d.ts.map +1 -0
- package/use-fireproof/index.js +16 -0
- package/use-fireproof/index.js.map +1 -0
- package/use-fireproof/redirect-strategy.d.ts +8 -0
- package/use-fireproof/redirect-strategy.d.ts.map +1 -0
- package/use-fireproof/redirect-strategy.js +31 -0
- package/use-fireproof/redirect-strategy.js.map +1 -0
- package/utils.d.ts +45 -0
- package/utils.d.ts.map +1 -0
- package/utils.js +406 -0
- package/utils.js.map +1 -0
- package/version.d.ts +2 -0
- package/version.d.ts.map +1 -0
- package/version.js +4 -0
- package/version.js.map +1 -0
- package/write-queue.d.ts +9 -0
- package/write-queue.d.ts.map +1 -0
- package/write-queue.js +70 -0
- package/write-queue.js.map +1 -0
- package/deno/index.d.ts +0 -7
- package/deno/index.js +0 -66
- package/deno/index.js.map +0 -1
- package/deno/metafile-esm.json +0 -1
- package/index.cjs +0 -7275
- package/index.cjs.map +0 -1
- package/index.d.cts +0 -2741
- package/indexeddb/index.cjs +0 -218
- package/indexeddb/index.cjs.map +0 -1
- package/indexeddb/index.d.cts +0 -30
- package/indexeddb/index.d.ts +0 -30
- package/indexeddb/index.js +0 -195
- package/indexeddb/index.js.map +0 -1
- package/indexeddb/metafile-cjs.json +0 -1
- package/indexeddb/metafile-esm.json +0 -1
- package/metafile-cjs.json +0 -1
- package/metafile-esm.json +0 -1
- package/node/index.cjs +0 -97
- package/node/index.cjs.map +0 -1
- package/node/index.d.cts +0 -7
- package/node/index.d.ts +0 -7
- package/node/index.js +0 -64
- package/node/index.js.map +0 -1
- package/node/metafile-cjs.json +0 -1
- package/node/metafile-esm.json +0 -1
- package/react/index.cjs +0 -303
- package/react/index.cjs.map +0 -1
- package/react/metafile-cjs.json +0 -1
- package/react/metafile-esm.json +0 -1
- package/tests/www/gallery.html +0 -132
- package/tests/www/iife.html +0 -42
- package/tests/www/todo-aws.html +0 -232
- package/tests/www/todo-ipfs.html +0 -213
- package/tests/www/todo-local.html +0 -214
- package/tests/www/todo-netlify.html +0 -227
- package/tests/www/todo.html +0 -254
@@ -1,9 +1,82 @@
|
|
1
|
-
import { URI } from "@adviser/cement";
|
1
|
+
import { AppContext, BuildURI, URI, WithoutPromise } from "@adviser/cement";
|
2
2
|
import { stripper } from "@adviser/cement/utils";
|
3
|
-
import {
|
3
|
+
import {
|
4
|
+
Attachable,
|
5
|
+
Database,
|
6
|
+
ensureSuperThis,
|
7
|
+
fireproof,
|
8
|
+
GatewayUrlsParam,
|
9
|
+
PARAM,
|
10
|
+
rt,
|
11
|
+
Attached,
|
12
|
+
bs,
|
13
|
+
sleep,
|
14
|
+
TraceFn,
|
15
|
+
} from "@fireproof/core";
|
4
16
|
import { CarReader } from "@ipld/car/reader";
|
5
17
|
import * as dagCbor from "@ipld/dag-cbor";
|
6
|
-
import {
|
18
|
+
import { mockLoader } from "../helpers.js";
|
19
|
+
import { afterEach, beforeEach, expect } from "vitest";
|
20
|
+
|
21
|
+
const ROWS = 1;
|
22
|
+
|
23
|
+
class AJoinable implements Attachable {
|
24
|
+
readonly name: string;
|
25
|
+
readonly db: Database;
|
26
|
+
|
27
|
+
constructor(name: string, db: Database) {
|
28
|
+
this.name = name;
|
29
|
+
this.db = db;
|
30
|
+
}
|
31
|
+
|
32
|
+
async configHash() {
|
33
|
+
return `joinable-${this.name}`;
|
34
|
+
}
|
35
|
+
|
36
|
+
prepare(): Promise<GatewayUrlsParam> {
|
37
|
+
return Promise.resolve({
|
38
|
+
car: {
|
39
|
+
url: BuildURI.from(`memory://car/${this.name}`)
|
40
|
+
.setParam(PARAM.STORE_KEY, this.db.ledger.opts.storeUrls.data.car.getParam(PARAM.STORE_KEY, "@fireproof:attach@"))
|
41
|
+
.setParam(PARAM.SELF_REFLECT, "x"),
|
42
|
+
},
|
43
|
+
meta: {
|
44
|
+
url: BuildURI.from(`memory://meta/${this.name}`)
|
45
|
+
.setParam(PARAM.STORE_KEY, this.db.ledger.opts.storeUrls.data.meta.getParam(PARAM.STORE_KEY, "@fireproof:attach@"))
|
46
|
+
.setParam(PARAM.SELF_REFLECT, "x"),
|
47
|
+
},
|
48
|
+
file: {
|
49
|
+
url: BuildURI.from(`memory://file/${this.name}`)
|
50
|
+
.setParam(PARAM.STORE_KEY, this.db.ledger.opts.storeUrls.data.file.getParam(PARAM.STORE_KEY, "@fireproof:attach@"))
|
51
|
+
.setParam(PARAM.SELF_REFLECT, "x"),
|
52
|
+
},
|
53
|
+
});
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
function aJoinable(name: string, db: Database): Attachable {
|
58
|
+
return new AJoinable(name, db);
|
59
|
+
}
|
60
|
+
|
61
|
+
function attachableStoreUrls(name: string, db: Database) {
|
62
|
+
return {
|
63
|
+
// base: `memory://${name}`,
|
64
|
+
data: {
|
65
|
+
car: BuildURI.from(`memory://car/${name}?`)
|
66
|
+
.setParam(PARAM.STORE_KEY, db.ledger.opts.storeUrls.data.car.getParam(PARAM.STORE_KEY, ""))
|
67
|
+
.URI(),
|
68
|
+
meta: BuildURI.from(`memory://meta/${name}`)
|
69
|
+
.setParam(PARAM.STORE_KEY, db.ledger.opts.storeUrls.data.meta.getParam(PARAM.STORE_KEY, ""))
|
70
|
+
.URI(),
|
71
|
+
file: BuildURI.from(`memory://file/${name}`)
|
72
|
+
.setParam(PARAM.STORE_KEY, db.ledger.opts.storeUrls.data.file.getParam(PARAM.STORE_KEY, ""))
|
73
|
+
.URI(),
|
74
|
+
wal: BuildURI.from(`memory://wal/${name}`)
|
75
|
+
.setParam(PARAM.STORE_KEY, db.ledger.opts.storeUrls.data.wal.getParam(PARAM.STORE_KEY, ""))
|
76
|
+
.URI(),
|
77
|
+
},
|
78
|
+
};
|
79
|
+
}
|
7
80
|
|
8
81
|
describe("meta check", () => {
|
9
82
|
const sthis = ensureSuperThis();
|
@@ -18,9 +91,9 @@ describe("meta check", () => {
|
|
18
91
|
const gws = db.ledger.crdt.blockstore.loader.attachedStores.local();
|
19
92
|
await db.close();
|
20
93
|
expect(
|
21
|
-
Array.from(
|
22
|
-
(
|
23
|
-
),
|
94
|
+
Array.from(
|
95
|
+
((gws.active.car.realGateway as rt.gw.DefSerdeGateway).gw as rt.gw.memory.MemoryGateway).memories.entries(),
|
96
|
+
).filter(([k]) => k.startsWith(`memory://${name}`)),
|
24
97
|
).toEqual([]);
|
25
98
|
});
|
26
99
|
|
@@ -59,7 +132,7 @@ describe("meta check", () => {
|
|
59
132
|
]);
|
60
133
|
await db.close();
|
61
134
|
expect(
|
62
|
-
Array.from(((gws.active.car.realGateway as rt.gw.DefSerdeGateway).gw as rt.gw.memory.MemoryGateway).
|
135
|
+
Array.from(((gws.active.car.realGateway as rt.gw.DefSerdeGateway).gw as rt.gw.memory.MemoryGateway).memories.entries())
|
63
136
|
.filter(([k]) => k.startsWith(`memory://${name}`))
|
64
137
|
.map(([k]) =>
|
65
138
|
stripper(
|
@@ -114,7 +187,7 @@ describe("meta check", () => {
|
|
114
187
|
},
|
115
188
|
]);
|
116
189
|
const car = Array.from(
|
117
|
-
((gws.active.car.realGateway as rt.gw.DefSerdeGateway).gw as rt.gw.memory.MemoryGateway).
|
190
|
+
((gws.active.car.realGateway as rt.gw.DefSerdeGateway).gw as rt.gw.memory.MemoryGateway).memories.entries(),
|
118
191
|
)
|
119
192
|
.filter(([k]) => k.startsWith(`memory://${name}`))
|
120
193
|
.map(([k, v]) => [URI.from(k).getParam(PARAM.KEY), v])
|
@@ -154,29 +227,37 @@ describe("activate store", () => {
|
|
154
227
|
let secondAttached: Attached;
|
155
228
|
beforeEach(async () => {
|
156
229
|
attach = new bs.AttachedRemotesImpl(mockLoader(sthis));
|
157
|
-
firstAttached = await attach.attach(
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
230
|
+
firstAttached = await attach.attach(
|
231
|
+
{
|
232
|
+
name: "first",
|
233
|
+
configHash: async () => "first",
|
234
|
+
prepare: async () => ({
|
235
|
+
car: { url: "memory://first?store=car" },
|
236
|
+
meta: { url: "memory://first?store=meta" },
|
237
|
+
file: { url: "memory://first" },
|
238
|
+
wal: { url: "memory://first?store=wal" },
|
239
|
+
}),
|
240
|
+
},
|
241
|
+
(at) => Promise.resolve(at),
|
242
|
+
);
|
166
243
|
|
167
|
-
secondAttached = await attach.attach(
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
244
|
+
secondAttached = await attach.attach(
|
245
|
+
{
|
246
|
+
name: "second",
|
247
|
+
configHash: async () => "second",
|
248
|
+
prepare: async () => ({
|
249
|
+
car: { url: "memory://second?store=car" },
|
250
|
+
meta: { url: "memory://second?store=meta" },
|
251
|
+
file: { url: "memory://second?store=file" },
|
252
|
+
}),
|
253
|
+
},
|
254
|
+
(at) => Promise.resolve(at),
|
255
|
+
);
|
175
256
|
});
|
176
257
|
|
177
258
|
it("activate by store", async () => {
|
178
259
|
expect(attach.activate(secondAttached.stores).active.car.url().toString()).toBe(
|
179
|
-
"memory://second?name=second&store=car&storekey=%
|
260
|
+
"memory://second?localName=first&name=second&store=car&storekey=%40first-data%40&suffix=.car&version=v0.19-memory",
|
180
261
|
);
|
181
262
|
expect(attach.activate(firstAttached.stores).local().active.car.url().toString()).toBe(
|
182
263
|
"memory://first?name=first&store=car&storekey=%40first-data%40&suffix=.car&version=v0.19-memory",
|
@@ -188,10 +269,10 @@ describe("activate store", () => {
|
|
188
269
|
|
189
270
|
it("activate by store", async () => {
|
190
271
|
expect(attach.activate("memory://second").active.car.url().toString()).toBe(
|
191
|
-
"memory://second?name=second&store=car&storekey=%
|
272
|
+
"memory://second?localName=first&name=second&store=car&storekey=%40first-data%40&suffix=.car&version=v0.19-memory",
|
192
273
|
);
|
193
274
|
expect(attach.activate("memory://second").remotes()[0].active.car.url().toString()).toEqual(
|
194
|
-
"memory://second?name=second&store=car&storekey=%
|
275
|
+
"memory://second?localName=first&name=second&store=car&storekey=%40first-data%40&suffix=.car&version=v0.19-memory",
|
195
276
|
);
|
196
277
|
expect(attach.activate("memory://first?store=meta").active.car.url().toString()).toBe(
|
197
278
|
"memory://first?name=first&store=car&storekey=%40first-data%40&suffix=.car&version=v0.19-memory",
|
@@ -222,91 +303,65 @@ describe("join function", () => {
|
|
222
303
|
// return connection;
|
223
304
|
// });
|
224
305
|
// };
|
225
|
-
class AJoinable implements Attachable {
|
226
|
-
readonly name: string;
|
227
|
-
constructor(name: string) {
|
228
|
-
this.name = name;
|
229
|
-
}
|
230
|
-
prepare(): Promise<GatewayUrlsParam> {
|
231
|
-
return Promise.resolve({
|
232
|
-
car: { url: `memory://car/${this.name}` },
|
233
|
-
meta: { url: `memory://meta/${this.name}` },
|
234
|
-
file: { url: `memory://file/${this.name}` },
|
235
|
-
});
|
236
|
-
}
|
237
|
-
}
|
238
|
-
function aJoinable(name: string): Attachable {
|
239
|
-
return new AJoinable(name);
|
240
|
-
}
|
241
306
|
|
242
307
|
let db: Database;
|
243
308
|
let joinableDBs: string[] = [];
|
244
|
-
|
309
|
+
beforeEach(async () => {
|
245
310
|
const set = sthis.nextId().str;
|
311
|
+
|
312
|
+
db = fireproof(`db-${set}`, {
|
313
|
+
storeUrls: {
|
314
|
+
base: `memory://db-${set}`,
|
315
|
+
},
|
316
|
+
});
|
317
|
+
// await db.put({ _id: `genesis`, value: `genesis` });
|
318
|
+
for (let j = 0; j < ROWS; j++) {
|
319
|
+
await db.put({ _id: `db-${j}`, value: `db-${set}` });
|
320
|
+
}
|
321
|
+
|
246
322
|
joinableDBs = await Promise.all(
|
247
|
-
new Array(
|
323
|
+
new Array(1).fill(1).map(async (_, i) => {
|
248
324
|
const name = `remote-db-${i}-${set}`;
|
249
|
-
const
|
250
|
-
storeUrls:
|
251
|
-
// base: `memory://${name}`,
|
252
|
-
data: {
|
253
|
-
car: `memory://car/${name}`,
|
254
|
-
meta: `memory://meta/${name}`,
|
255
|
-
file: `memory://file/${name}`,
|
256
|
-
wal: `memory://wal/${name}`,
|
257
|
-
},
|
258
|
-
},
|
325
|
+
const jdb = fireproof(name, {
|
326
|
+
storeUrls: attachableStoreUrls(name, db),
|
259
327
|
});
|
260
328
|
// await db.put({ _id: `genesis`, value: `genesis` });
|
261
329
|
// await db.ready();
|
262
|
-
for (let j = 0; j <
|
263
|
-
await
|
330
|
+
for (let j = 0; j < ROWS; j++) {
|
331
|
+
await jdb.put({ _id: `${i}-${j}`, value: `${i}-${j}` });
|
264
332
|
}
|
265
|
-
expect(await
|
266
|
-
await
|
333
|
+
expect(await jdb.get(PARAM.GENESIS_CID)).toEqual({ _id: PARAM.GENESIS_CID });
|
334
|
+
await jdb.close();
|
267
335
|
return name;
|
268
336
|
}),
|
269
337
|
);
|
270
338
|
// await new Promise((resolve) => setTimeout(resolve, 1000));
|
271
339
|
|
272
|
-
db = fireproof(`db-${set}`, {
|
273
|
-
storeUrls: {
|
274
|
-
base: `memory://db-${set}`,
|
275
|
-
},
|
276
|
-
});
|
277
|
-
// await db.put({ _id: `genesis`, value: `genesis` });
|
278
|
-
for (let j = 0; j < 10; j++) {
|
279
|
-
await db.put({ _id: `db-${j}`, value: `db-${set}` });
|
280
|
-
}
|
281
340
|
expect(await db.get(PARAM.GENESIS_CID)).toEqual({ _id: PARAM.GENESIS_CID });
|
282
341
|
});
|
283
|
-
|
342
|
+
afterEach(async () => {
|
284
343
|
await db.close();
|
285
344
|
});
|
286
345
|
|
287
346
|
it("it is joinable detachable", async () => {
|
288
347
|
const my = fireproof("my", {
|
289
348
|
storeUrls: {
|
290
|
-
base: "memory://
|
349
|
+
base: BuildURI.from("memory://it-is-joinable-detachable").setParam(
|
350
|
+
PARAM.STORE_KEY,
|
351
|
+
db.ledger.opts.storeUrls.data.car.getParam(PARAM.STORE_KEY, ""),
|
352
|
+
), // .setParam(PARAM.STORE_KEY, "@fireproof:attach@"),
|
291
353
|
},
|
292
354
|
});
|
293
355
|
await my.put({ _id: "genesis", value: "genesis" });
|
294
356
|
await Promise.all(
|
295
357
|
joinableDBs.map(async (name) => {
|
296
358
|
const tmp = fireproof(name, {
|
297
|
-
storeUrls:
|
298
|
-
data: {
|
299
|
-
car: `memory://car/${name}`,
|
300
|
-
meta: `memory://meta/${name}`,
|
301
|
-
file: `memory://file/${name}`,
|
302
|
-
wal: `memory://wal/${name}`,
|
303
|
-
},
|
304
|
-
},
|
359
|
+
storeUrls: attachableStoreUrls(name, my),
|
305
360
|
});
|
306
361
|
const res = await tmp.allDocs();
|
307
|
-
expect(res.rows.length).toBe(
|
362
|
+
expect(res.rows.length).toBe(ROWS);
|
308
363
|
await tmp.close();
|
309
|
-
const attached = await my.attach(aJoinable(name));
|
364
|
+
const attached = await my.attach(aJoinable(name, my));
|
310
365
|
expect(attached).toBeDefined();
|
311
366
|
}),
|
312
367
|
);
|
@@ -318,38 +373,312 @@ describe("join function", () => {
|
|
318
373
|
it("it is inbound syncing", async () => {
|
319
374
|
await Promise.all(
|
320
375
|
joinableDBs.map(async (name) => {
|
321
|
-
const attached = await db.attach(aJoinable(name));
|
376
|
+
const attached = await db.attach(aJoinable(name, db));
|
322
377
|
expect(attached).toBeDefined();
|
323
378
|
}),
|
324
379
|
);
|
325
380
|
await sleep(100);
|
326
381
|
expect(db.ledger.crdt.blockstore.loader.attachedStores.remotes().length).toBe(joinableDBs.length);
|
327
382
|
const res = await db.allDocs();
|
328
|
-
expect(res.rows.length).toBe(
|
383
|
+
expect(res.rows.length).toBe(ROWS + ROWS * joinableDBs.length);
|
329
384
|
});
|
330
385
|
|
331
386
|
it("it empty inbound syncing", async () => {
|
332
387
|
const name = `empty-db-${sthis.nextId().str}`;
|
333
|
-
const
|
334
|
-
storeUrls:
|
335
|
-
// base: `memory://${name}`,
|
336
|
-
data: {
|
337
|
-
car: `memory://car/${name}`,
|
338
|
-
meta: `memory://meta/${name}`,
|
339
|
-
file: `memory://file/${name}`,
|
340
|
-
wal: `memory://wal/${name}`,
|
341
|
-
},
|
342
|
-
},
|
388
|
+
const mydb = fireproof(name, {
|
389
|
+
storeUrls: attachableStoreUrls(name, db),
|
343
390
|
});
|
344
391
|
await Promise.all(
|
345
392
|
joinableDBs.map(async (name) => {
|
346
|
-
const attached = await
|
393
|
+
const attached = await mydb.attach(aJoinable(name, mydb));
|
347
394
|
expect(attached).toBeDefined();
|
348
395
|
}),
|
349
396
|
);
|
350
397
|
await sleep(100);
|
351
|
-
expect(
|
352
|
-
const res = await
|
353
|
-
expect(res.rows.length).toBe(
|
398
|
+
expect(mydb.ledger.crdt.blockstore.loader.attachedStores.remotes().length).toBe(joinableDBs.length);
|
399
|
+
const res = await mydb.allDocs();
|
400
|
+
expect(res.rows.length).toBe(ROWS * joinableDBs.length);
|
401
|
+
});
|
402
|
+
|
403
|
+
it("prepare only once", async () => {
|
404
|
+
const db = fireproof(`db-${sthis.nextId().str}`, {
|
405
|
+
storeUrls: {
|
406
|
+
base: `memory://prepare`,
|
407
|
+
},
|
408
|
+
});
|
409
|
+
const mocked = aJoinable("test", db);
|
410
|
+
const originalPrepare = mocked.prepare;
|
411
|
+
mocked.prepare = vi.fn(() => originalPrepare.apply(mocked));
|
412
|
+
expect(mocked.prepare).not.toHaveBeenCalled();
|
413
|
+
for (let i = 0; i < 10; i++) {
|
414
|
+
await db.attach(mocked);
|
415
|
+
expect(mocked.prepare).toHaveBeenCalled();
|
416
|
+
}
|
354
417
|
});
|
418
|
+
|
419
|
+
it("offline sync", async () => {
|
420
|
+
const id = sthis.nextId().str;
|
421
|
+
// console.log("sync-offline");
|
422
|
+
|
423
|
+
// console.log("outbound-db");
|
424
|
+
// console.log("-1");
|
425
|
+
const poutbound = await prepareDb(`outbound-db-${id}`, "memory://sync-outbound");
|
426
|
+
// console.log("-2");
|
427
|
+
await poutbound.db.attach(aJoinable(`sync-${id}`, poutbound.db));
|
428
|
+
await poutbound.db.close();
|
429
|
+
// console.log("-3");
|
430
|
+
const outRows = await readDb(`outbound-db-${id}`, "memory://sync-outbound");
|
431
|
+
|
432
|
+
expect(outRows.length).toBe(ROWS);
|
433
|
+
|
434
|
+
const pinbound = await prepareDb(`inbound-db-${id}`, `memory://sync-inbound`);
|
435
|
+
await pinbound.db.close();
|
436
|
+
const inRows = await readDb(`inbound-db-${id}`, "memory://sync-inbound");
|
437
|
+
|
438
|
+
expect(inRows.length).toBe(ROWS);
|
439
|
+
|
440
|
+
const inbound = await syncDb(`inbound-db-${id}`, `memory://sync-inbound`);
|
441
|
+
await inbound.attach(aJoinable(`sync-${id}`, inbound));
|
442
|
+
await inbound.close();
|
443
|
+
|
444
|
+
// console.log("result");
|
445
|
+
const resultRows = await readDb(`inbound-db-${id}`, "memory://sync-inbound");
|
446
|
+
// console.log(re);
|
447
|
+
// console.log(inRows);
|
448
|
+
expect(resultRows.length).toBe(ROWS * 2);
|
449
|
+
expect(resultRows).toEqual(outRows.concat(inRows).sort((a, b) => a.key.localeCompare(b.key)));
|
450
|
+
|
451
|
+
const joined = { db: await syncDb(`joined-db-${id}`, "memory://sync-joined") };
|
452
|
+
await joined.db.attach(aJoinable(`sync-${id}`, joined.db));
|
453
|
+
await joined.db.close();
|
454
|
+
const joinedRows = await readDb(`joined-db-${id}`, "memory://sync-joined");
|
455
|
+
expect(resultRows).toEqual(joinedRows);
|
456
|
+
}, 100_000);
|
355
457
|
});
|
458
|
+
|
459
|
+
// interface WaitItem {
|
460
|
+
// ev: IdleEventFromBlockstore | BusyEventFromBlockstore;
|
461
|
+
// waitforIdle: Set<Future<IdleEventFromBlockstore>>;
|
462
|
+
// }
|
463
|
+
// class WaitIdle {
|
464
|
+
// readonly _waitState = new Map<string, WaitItem>();
|
465
|
+
//
|
466
|
+
// upsertItem(name: string) {
|
467
|
+
// let item = this._waitState.get(name);
|
468
|
+
// if (!item) {
|
469
|
+
// item = { ev: {} as IdleEventFromBlockstore, waitforIdle: new Set() };
|
470
|
+
// this._waitState.set(name, item);
|
471
|
+
// }
|
472
|
+
// return item;
|
473
|
+
// }
|
474
|
+
// upsertEvent(name: string, ev: IdleEventFromBlockstore | BusyEventFromBlockstore) {
|
475
|
+
// this.upsertItem(name).ev = ev;
|
476
|
+
// }
|
477
|
+
//
|
478
|
+
// readonly _traceFn = (ev: TraceEvent) => {
|
479
|
+
// console.log("trace", ev.event);
|
480
|
+
// if (EventIsIdleFromBlockstore(ev) && ev.ledger) {
|
481
|
+
// const item = this.upsertItem(ev.ledger.name);
|
482
|
+
// item.ev = ev;
|
483
|
+
// console.log("database is now idle", ev.ledger.name);
|
484
|
+
// Array.from(item.waitforIdle).forEach((waiter) => {
|
485
|
+
// waiter.resolve(ev);
|
486
|
+
// item.waitforIdle.delete(waiter);
|
487
|
+
// });
|
488
|
+
// }
|
489
|
+
// if (EventIsBusyFromBlockstore(ev) && ev.ledger) {
|
490
|
+
// this.upsertEvent(ev.ledger.name, ev);
|
491
|
+
// }
|
492
|
+
// };
|
493
|
+
//
|
494
|
+
// traceFn(): TraceFn {
|
495
|
+
// return this._traceFn;
|
496
|
+
// }
|
497
|
+
//
|
498
|
+
// async wait(dbs: Database[]) {
|
499
|
+
// const waiting = dbs.map((db) => {
|
500
|
+
// const item = this.upsertItem(db.name);
|
501
|
+
// let waiter: Promise<IdleEventFromBlockstore>;
|
502
|
+
// if (EventIsIdleFromBlockstore(item.ev)) {
|
503
|
+
// console.log("database is already idle", db.name);
|
504
|
+
// waiter = Promise.resolve(item.ev);
|
505
|
+
// } else {
|
506
|
+
// const future = new Future<IdleEventFromBlockstore>();
|
507
|
+
// item.waitforIdle.add(future);
|
508
|
+
// waiter = future.asPromise();
|
509
|
+
// }
|
510
|
+
// return waiter;
|
511
|
+
// });
|
512
|
+
// console.log(dbs.map((db) => db.name));
|
513
|
+
// await Promise.all(waiting);
|
514
|
+
// }
|
515
|
+
// }
|
516
|
+
|
517
|
+
describe("sync", () => {
|
518
|
+
const sthis = ensureSuperThis();
|
519
|
+
it("online sync", async () => {
|
520
|
+
const id = sthis.nextId().str;
|
521
|
+
// const waitIdle = new WaitIdle();
|
522
|
+
const dbs = await Promise.all(
|
523
|
+
Array(3)
|
524
|
+
.fill(0)
|
525
|
+
.map(async (_, i) => {
|
526
|
+
const tdb = await prepareDb(`online-db-${id}-${i}`, `memory://local-${id}-${i}`);
|
527
|
+
await tdb.db.attach(aJoinable(`sync-${id}`, tdb.db));
|
528
|
+
return tdb;
|
529
|
+
}),
|
530
|
+
);
|
531
|
+
|
532
|
+
// await waitIdle.wait(dbs);
|
533
|
+
await sleep(500);
|
534
|
+
await Promise.all(
|
535
|
+
dbs.map(async (tdb) => {
|
536
|
+
const rows = await tdb.db.allDocs();
|
537
|
+
// console.log(db.name, rows.rows.length);
|
538
|
+
// console.log(rows.rows.length);
|
539
|
+
expect(rows.rows.length).toBe(ROWS * dbs.length);
|
540
|
+
}),
|
541
|
+
);
|
542
|
+
|
543
|
+
const keys = (
|
544
|
+
await Promise.all(
|
545
|
+
dbs.map(async (db) => {
|
546
|
+
await sleep(100 * Math.random());
|
547
|
+
return writeRow(db, "add-online");
|
548
|
+
}),
|
549
|
+
)
|
550
|
+
).flat();
|
551
|
+
await sleep(500);
|
552
|
+
await Promise.all(
|
553
|
+
dbs.map(async (db) => {
|
554
|
+
for (const key of keys) {
|
555
|
+
const rows = await db.db.get(key);
|
556
|
+
expect(rows).toEqual({ _id: key, value: key });
|
557
|
+
}
|
558
|
+
}),
|
559
|
+
);
|
560
|
+
|
561
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
562
|
+
const toCloseDbs = [dbs.shift()!, dbs.pop()!];
|
563
|
+
await Promise.all(toCloseDbs.map((tdb) => tdb.db.close()));
|
564
|
+
|
565
|
+
await Promise.all(
|
566
|
+
dbs.map(async (db) => {
|
567
|
+
return writeRow(db, "mid-dbs");
|
568
|
+
}),
|
569
|
+
);
|
570
|
+
|
571
|
+
const reOpenedWithoutAttach = await Promise.all(
|
572
|
+
toCloseDbs.map(async (tdb) => {
|
573
|
+
// console.log("reopen", tdb.db.name, tdb.db.ledger.ctx.get("base"));
|
574
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
575
|
+
const db = await syncDb(tdb.db.name, tdb.db.ledger.ctx.get("base")!);
|
576
|
+
return { db, dbId: tdb.dbId };
|
577
|
+
}),
|
578
|
+
);
|
579
|
+
|
580
|
+
// const reOpenKeys = (
|
581
|
+
await Promise.all(
|
582
|
+
dbs.map(async (db) => {
|
583
|
+
return writeRow(db, "reOpenKeys");
|
584
|
+
}),
|
585
|
+
);
|
586
|
+
// ).flat();
|
587
|
+
|
588
|
+
await Promise.all(
|
589
|
+
reOpenedWithoutAttach.map(async (tdb) => {
|
590
|
+
await tdb.db.attach(aJoinable(`sync-${id}`, tdb.db));
|
591
|
+
}),
|
592
|
+
);
|
593
|
+
await sleep(500);
|
594
|
+
|
595
|
+
await Promise.all(
|
596
|
+
dbs.map(async (tdb) => {
|
597
|
+
const rows = await tdb.db.allDocs();
|
598
|
+
// console.log(db.name, rows.rows.length);
|
599
|
+
// console.log(rows.rows.length);
|
600
|
+
expect(rows.rows.length).toBe(8 * ROWS * dbs.length);
|
601
|
+
}),
|
602
|
+
);
|
603
|
+
|
604
|
+
await Promise.all(dbs.map((tdb) => tdb.db.close()));
|
605
|
+
await Promise.all(reOpenedWithoutAttach.map((tdb) => tdb.db.close()));
|
606
|
+
}, 100_000);
|
607
|
+
|
608
|
+
it.skip("sync outbound", async () => {
|
609
|
+
const id = sthis.nextId().str;
|
610
|
+
|
611
|
+
const outbound = await prepareDb(`outbound-db-${id}`, `memory://sync-outbound-${id}`);
|
612
|
+
await outbound.db.attach(aJoinable(`sync-${id}`, outbound.db));
|
613
|
+
await writeRow(outbound, "outbound");
|
614
|
+
|
615
|
+
const inbound = await prepareDb(`inbound-db-${id}`, `memory://sync-inbound-${id}`);
|
616
|
+
await inbound.db.attach(aJoinable(`sync-${id}`, inbound.db));
|
617
|
+
await writeRow(inbound, "both-inbound");
|
618
|
+
await writeRow(outbound, "both-outbound");
|
619
|
+
await sleep(1000);
|
620
|
+
await inbound.db.close();
|
621
|
+
await outbound.db.close();
|
622
|
+
|
623
|
+
const inRows = await readDb(`inbound-db-${id}`, `memory://sync-inbound-${id}`);
|
624
|
+
const outRows = await readDb(`outbound-db-${id}`, `memory://sync-outbound-${id}`);
|
625
|
+
console.log(
|
626
|
+
"out",
|
627
|
+
outRows.map((row) => row.key),
|
628
|
+
);
|
629
|
+
console.log(
|
630
|
+
"in",
|
631
|
+
inRows.map((row) => row.key),
|
632
|
+
);
|
633
|
+
expect(inRows).toEqual(outRows);
|
634
|
+
}, 100_000);
|
635
|
+
});
|
636
|
+
|
637
|
+
async function syncDb(name: string, base: string, tracer?: TraceFn) {
|
638
|
+
const db = fireproof(name, {
|
639
|
+
storeUrls: {
|
640
|
+
base: BuildURI.from(base).setParam(PARAM.STORE_KEY, "@fireproof:attach@"), // .setParam(PARAM.SELF_REFLECT, "yes"),
|
641
|
+
},
|
642
|
+
ctx: AppContext.merge({ base }),
|
643
|
+
tracer,
|
644
|
+
});
|
645
|
+
await db.ready();
|
646
|
+
return db;
|
647
|
+
}
|
648
|
+
|
649
|
+
async function prepareDb(name: string, base: string, tracer?: TraceFn) {
|
650
|
+
{
|
651
|
+
const db = await syncDb(name, base, tracer);
|
652
|
+
await db.ready();
|
653
|
+
const dbId = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.car.id();
|
654
|
+
const ret = { db, dbId };
|
655
|
+
await writeRow(ret, `initial`);
|
656
|
+
await db.close();
|
657
|
+
}
|
658
|
+
|
659
|
+
const db = await syncDb(name, base);
|
660
|
+
await db.ready();
|
661
|
+
const dbId = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.car.id();
|
662
|
+
// const ret = { db, dbId };
|
663
|
+
return { db, dbId };
|
664
|
+
}
|
665
|
+
|
666
|
+
async function readDb(name: string, base: string) {
|
667
|
+
const db = await syncDb(name, base);
|
668
|
+
const rows = await db.allDocs();
|
669
|
+
await db.close();
|
670
|
+
return rows.rows.sort((a, b) => a.key.localeCompare(b.key));
|
671
|
+
}
|
672
|
+
|
673
|
+
async function writeRow(pdb: WithoutPromise<ReturnType<typeof prepareDb>>, style: string) {
|
674
|
+
return await Promise.all(
|
675
|
+
Array(ROWS)
|
676
|
+
.fill(0)
|
677
|
+
.map(async (_, i) => {
|
678
|
+
const key = `${pdb.dbId}-${pdb.db.name}-${style}-${i}`;
|
679
|
+
// console.log(key);
|
680
|
+
await pdb.db.put({ _id: key, value: key });
|
681
|
+
return key;
|
682
|
+
}),
|
683
|
+
);
|
684
|
+
}
|