@fireproof/core 0.21.0-dev-preview-7 → 0.22.0-keybag
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/index.d.ts +2 -16
- package/index.js +2 -15
- package/index.js.map +1 -1
- package/index.ts +2 -0
- package/package.json +12 -70
- package/tsconfig.json +18 -0
- package/README.md +0 -269
- package/apply-head-queue.d.ts +0 -18
- package/apply-head-queue.d.ts.map +0 -1
- package/apply-head-queue.js +0 -47
- package/apply-head-queue.js.map +0 -1
- package/blockstore/attachable-store.d.ts +0 -19
- package/blockstore/attachable-store.d.ts.map +0 -1
- package/blockstore/attachable-store.js +0 -316
- package/blockstore/attachable-store.js.map +0 -1
- package/blockstore/commit-queue.d.ts +0 -17
- package/blockstore/commit-queue.d.ts.map +0 -1
- package/blockstore/commit-queue.js +0 -60
- package/blockstore/commit-queue.js.map +0 -1
- package/blockstore/commitor.d.ts +0 -21
- package/blockstore/commitor.d.ts.map +0 -1
- package/blockstore/commitor.js +0 -95
- package/blockstore/commitor.js.map +0 -1
- package/blockstore/connect-raw.d.ts +0 -2
- package/blockstore/connect-raw.d.ts.map +0 -1
- package/blockstore/connect-raw.js +0 -2
- package/blockstore/connect-raw.js.map +0 -1
- package/blockstore/connection-base.d.ts +0 -2
- package/blockstore/connection-base.d.ts.map +0 -1
- package/blockstore/connection-base.js +0 -2
- package/blockstore/connection-base.js.map +0 -1
- package/blockstore/encrypt-helpers.d.ts +0 -2
- package/blockstore/encrypt-helpers.d.ts.map +0 -1
- package/blockstore/encrypt-helpers.js +0 -2
- package/blockstore/encrypt-helpers.js.map +0 -1
- package/blockstore/fp-envelope.d.ts +0 -32
- package/blockstore/fp-envelope.d.ts.map +0 -1
- package/blockstore/fp-envelope.js +0 -14
- package/blockstore/fp-envelope.js.map +0 -1
- package/blockstore/gateway.d.ts +0 -20
- package/blockstore/gateway.d.ts.map +0 -1
- package/blockstore/gateway.js +0 -2
- package/blockstore/gateway.js.map +0 -1
- package/blockstore/index.d.ts +0 -17
- package/blockstore/index.d.ts.map +0 -1
- package/blockstore/index.js +0 -17
- package/blockstore/index.js.map +0 -1
- package/blockstore/interceptor-gateway.d.ts +0 -29
- package/blockstore/interceptor-gateway.d.ts.map +0 -1
- package/blockstore/interceptor-gateway.js +0 -137
- package/blockstore/interceptor-gateway.js.map +0 -1
- package/blockstore/loader-helpers.d.ts +0 -10
- package/blockstore/loader-helpers.d.ts.map +0 -1
- package/blockstore/loader-helpers.js +0 -115
- package/blockstore/loader-helpers.js.map +0 -1
- package/blockstore/loader.d.ts +0 -62
- package/blockstore/loader.d.ts.map +0 -1
- package/blockstore/loader.js +0 -523
- package/blockstore/loader.js.map +0 -1
- package/blockstore/register-store-protocol.d.ts +0 -22
- package/blockstore/register-store-protocol.d.ts.map +0 -1
- package/blockstore/register-store-protocol.js +0 -125
- package/blockstore/register-store-protocol.js.map +0 -1
- package/blockstore/serde-gateway.d.ts +0 -78
- package/blockstore/serde-gateway.d.ts.map +0 -1
- package/blockstore/serde-gateway.js +0 -2
- package/blockstore/serde-gateway.js.map +0 -1
- package/blockstore/store-factory.d.ts +0 -11
- package/blockstore/store-factory.d.ts.map +0 -1
- package/blockstore/store-factory.js +0 -104
- package/blockstore/store-factory.js.map +0 -1
- package/blockstore/store-remote.d.ts +0 -2
- package/blockstore/store-remote.d.ts.map +0 -1
- package/blockstore/store-remote.js +0 -2
- package/blockstore/store-remote.js.map +0 -1
- package/blockstore/store.d.ts +0 -86
- package/blockstore/store.d.ts.map +0 -1
- package/blockstore/store.js +0 -437
- package/blockstore/store.js.map +0 -1
- package/blockstore/task-manager.d.ts +0 -19
- package/blockstore/task-manager.d.ts.map +0 -1
- package/blockstore/task-manager.js +0 -50
- package/blockstore/task-manager.js.map +0 -1
- package/blockstore/transaction.d.ts +0 -62
- package/blockstore/transaction.d.ts.map +0 -1
- package/blockstore/transaction.js +0 -256
- package/blockstore/transaction.js.map +0 -1
- package/blockstore/types.d.ts +0 -508
- package/blockstore/types.d.ts.map +0 -1
- package/blockstore/types.js +0 -83
- package/blockstore/types.js.map +0 -1
- package/blockstore/uri-interceptor.d.ts +0 -19
- package/blockstore/uri-interceptor.d.ts.map +0 -1
- package/blockstore/uri-interceptor.js +0 -61
- package/blockstore/uri-interceptor.js.map +0 -1
- package/bundle-not-impl.d.ts +0 -2
- package/bundle-not-impl.d.ts.map +0 -1
- package/bundle-not-impl.js +0 -4
- package/bundle-not-impl.js.map +0 -1
- package/cli/main.js +0 -26645
- package/crdt-clock.d.ts +0 -26
- package/crdt-clock.d.ts.map +0 -1
- package/crdt-clock.js +0 -133
- package/crdt-clock.js.map +0 -1
- package/crdt-helpers.d.ts +0 -19
- package/crdt-helpers.d.ts.map +0 -1
- package/crdt-helpers.js +0 -332
- package/crdt-helpers.js.map +0 -1
- package/crdt.d.ts +0 -41
- package/crdt.d.ts.map +0 -1
- package/crdt.js +0 -164
- package/crdt.js.map +0 -1
- package/database.d.ts +0 -33
- package/database.d.ts.map +0 -1
- package/database.js +0 -132
- package/database.js.map +0 -1
- package/deno.json +0 -20
- package/index.d.ts.map +0 -1
- package/indexer-helpers.d.ts +0 -68
- package/indexer-helpers.d.ts.map +0 -1
- package/indexer-helpers.js +0 -157
- package/indexer-helpers.js.map +0 -1
- package/indexer.d.ts +0 -24
- package/indexer.d.ts.map +0 -1
- package/indexer.js +0 -239
- package/indexer.js.map +0 -1
- package/ledger.d.ts +0 -56
- package/ledger.d.ts.map +0 -1
- package/ledger.js +0 -237
- package/ledger.js.map +0 -1
- package/protocols/cloud/http-connection.d.ts +0 -26
- package/protocols/cloud/http-connection.d.ts.map +0 -1
- package/protocols/cloud/http-connection.js +0 -154
- package/protocols/cloud/http-connection.js.map +0 -1
- package/protocols/cloud/index.d.ts +0 -10
- package/protocols/cloud/index.d.ts.map +0 -1
- package/protocols/cloud/index.js +0 -10
- package/protocols/cloud/index.js.map +0 -1
- package/protocols/cloud/msg-raw-connection-base.d.ts +0 -16
- package/protocols/cloud/msg-raw-connection-base.d.ts.map +0 -1
- package/protocols/cloud/msg-raw-connection-base.js +0 -22
- package/protocols/cloud/msg-raw-connection-base.js.map +0 -1
- package/protocols/cloud/msg-types-data.d.ts +0 -36
- package/protocols/cloud/msg-types-data.d.ts.map +0 -1
- package/protocols/cloud/msg-types-data.js +0 -38
- package/protocols/cloud/msg-types-data.js.map +0 -1
- package/protocols/cloud/msg-types-meta.d.ts +0 -41
- package/protocols/cloud/msg-types-meta.d.ts.map +0 -1
- package/protocols/cloud/msg-types-meta.js +0 -98
- package/protocols/cloud/msg-types-meta.js.map +0 -1
- package/protocols/cloud/msg-types-wal.d.ts +0 -33
- package/protocols/cloud/msg-types-wal.d.ts.map +0 -1
- package/protocols/cloud/msg-types-wal.js +0 -38
- package/protocols/cloud/msg-types-wal.js.map +0 -1
- package/protocols/cloud/msg-types.d.ts +0 -310
- package/protocols/cloud/msg-types.d.ts.map +0 -1
- package/protocols/cloud/msg-types.js +0 -299
- package/protocols/cloud/msg-types.js.map +0 -1
- package/protocols/cloud/msger.d.ts +0 -94
- package/protocols/cloud/msger.d.ts.map +0 -1
- package/protocols/cloud/msger.js +0 -319
- package/protocols/cloud/msger.js.map +0 -1
- package/protocols/cloud/ws-connection.d.ts +0 -40
- package/protocols/cloud/ws-connection.d.ts.map +0 -1
- package/protocols/cloud/ws-connection.js +0 -205
- package/protocols/cloud/ws-connection.js.map +0 -1
- package/protocols/dashboard/index.d.ts +0 -4
- package/protocols/dashboard/index.d.ts.map +0 -1
- package/protocols/dashboard/index.js +0 -4
- package/protocols/dashboard/index.js.map +0 -1
- package/protocols/dashboard/msg-api.d.ts +0 -11
- package/protocols/dashboard/msg-api.d.ts.map +0 -1
- package/protocols/dashboard/msg-api.js +0 -55
- package/protocols/dashboard/msg-api.js.map +0 -1
- package/protocols/dashboard/msg-is.d.ts +0 -45
- package/protocols/dashboard/msg-is.d.ts.map +0 -1
- package/protocols/dashboard/msg-is.js +0 -63
- package/protocols/dashboard/msg-is.js.map +0 -1
- package/protocols/dashboard/msg-types.d.ts +0 -397
- package/protocols/dashboard/msg-types.d.ts.map +0 -1
- package/protocols/dashboard/msg-types.js +0 -4
- package/protocols/dashboard/msg-types.js.map +0 -1
- package/protocols/index.d.ts +0 -3
- package/protocols/index.d.ts.map +0 -1
- package/protocols/index.js +0 -3
- package/protocols/index.js.map +0 -1
- package/react/img-file.d.ts +0 -303
- package/react/img-file.d.ts.map +0 -1
- package/react/img-file.js +0 -92
- package/react/img-file.js.map +0 -1
- package/react/index.d.ts +0 -5
- package/react/index.d.ts.map +0 -1
- package/react/index.js +0 -5
- package/react/index.js.map +0 -1
- package/react/types.d.ts +0 -91
- package/react/types.d.ts.map +0 -1
- package/react/types.js +0 -2
- package/react/types.js.map +0 -1
- package/react/use-all-docs.d.ts +0 -4
- package/react/use-all-docs.d.ts.map +0 -1
- package/react/use-all-docs.js +0 -25
- package/react/use-all-docs.js.map +0 -1
- package/react/use-attach.d.ts +0 -11
- package/react/use-attach.d.ts.map +0 -1
- package/react/use-attach.js +0 -169
- package/react/use-attach.js.map +0 -1
- package/react/use-changes.d.ts +0 -4
- package/react/use-changes.d.ts.map +0 -1
- package/react/use-changes.js +0 -19
- package/react/use-changes.js.map +0 -1
- package/react/use-document.d.ts +0 -4
- package/react/use-document.d.ts.map +0 -1
- package/react/use-document.js +0 -109
- package/react/use-document.js.map +0 -1
- package/react/use-fireproof.d.ts +0 -6
- package/react/use-fireproof.d.ts.map +0 -1
- package/react/use-fireproof.js +0 -20
- package/react/use-fireproof.js.map +0 -1
- package/react/use-live-query.d.ts +0 -4
- package/react/use-live-query.d.ts.map +0 -1
- package/react/use-live-query.js +0 -24
- package/react/use-live-query.js.map +0 -1
- package/runtime/files.d.ts +0 -12
- package/runtime/files.d.ts.map +0 -1
- package/runtime/files.js +0 -29
- package/runtime/files.js.map +0 -1
- package/runtime/gateways/cloud/gateway.d.ts +0 -41
- package/runtime/gateways/cloud/gateway.d.ts.map +0 -1
- package/runtime/gateways/cloud/gateway.js +0 -514
- package/runtime/gateways/cloud/gateway.js.map +0 -1
- package/runtime/gateways/cloud/index.d.ts +0 -3
- package/runtime/gateways/cloud/index.d.ts.map +0 -1
- package/runtime/gateways/cloud/index.js +0 -3
- package/runtime/gateways/cloud/index.js.map +0 -1
- package/runtime/gateways/cloud/to-cloud.d.ts +0 -59
- package/runtime/gateways/cloud/to-cloud.d.ts.map +0 -1
- package/runtime/gateways/cloud/to-cloud.js +0 -175
- package/runtime/gateways/cloud/to-cloud.js.map +0 -1
- package/runtime/gateways/def-serde-gateway.d.ts +0 -18
- package/runtime/gateways/def-serde-gateway.d.ts.map +0 -1
- package/runtime/gateways/def-serde-gateway.js +0 -92
- package/runtime/gateways/def-serde-gateway.js.map +0 -1
- package/runtime/gateways/file/deno/deno-filesystem.d.ts +0 -27
- package/runtime/gateways/file/deno/deno-filesystem.d.ts.map +0 -1
- package/runtime/gateways/file/deno/deno-filesystem.js +0 -52
- package/runtime/gateways/file/deno/deno-filesystem.js.map +0 -1
- package/runtime/gateways/file/deno/get-sys-file-system.d.ts +0 -4
- package/runtime/gateways/file/deno/get-sys-file-system.d.ts.map +0 -1
- package/runtime/gateways/file/deno/get-sys-file-system.js +0 -11
- package/runtime/gateways/file/deno/get-sys-file-system.js.map +0 -1
- package/runtime/gateways/file/deno/index.d.ts +0 -2
- package/runtime/gateways/file/deno/index.d.ts.map +0 -1
- package/runtime/gateways/file/deno/index.js +0 -2
- package/runtime/gateways/file/deno/index.js.map +0 -1
- package/runtime/gateways/file/gateway-impl.d.ts +0 -18
- package/runtime/gateways/file/gateway-impl.d.ts.map +0 -1
- package/runtime/gateways/file/gateway-impl.js +0 -121
- package/runtime/gateways/file/gateway-impl.js.map +0 -1
- package/runtime/gateways/file/index.d.ts +0 -3
- package/runtime/gateways/file/index.d.ts.map +0 -1
- package/runtime/gateways/file/index.js +0 -3
- package/runtime/gateways/file/index.js.map +0 -1
- package/runtime/gateways/file/key-bag-file.d.ts +0 -20
- package/runtime/gateways/file/key-bag-file.d.ts.map +0 -1
- package/runtime/gateways/file/key-bag-file.js +0 -52
- package/runtime/gateways/file/key-bag-file.js.map +0 -1
- package/runtime/gateways/file/node/get-sys-file-system.d.ts +0 -4
- package/runtime/gateways/file/node/get-sys-file-system.d.ts.map +0 -1
- package/runtime/gateways/file/node/get-sys-file-system.js +0 -11
- package/runtime/gateways/file/node/get-sys-file-system.js.map +0 -1
- package/runtime/gateways/file/node/index.d.ts +0 -2
- package/runtime/gateways/file/node/index.d.ts.map +0 -1
- package/runtime/gateways/file/node/index.js +0 -2
- package/runtime/gateways/file/node/index.js.map +0 -1
- package/runtime/gateways/file/node/node-filesystem.d.ts +0 -32
- package/runtime/gateways/file/node/node-filesystem.d.ts.map +0 -1
- package/runtime/gateways/file/node/node-filesystem.js +0 -33
- package/runtime/gateways/file/node/node-filesystem.js.map +0 -1
- package/runtime/gateways/file/node/to-array-buffer.d.ts +0 -2
- package/runtime/gateways/file/node/to-array-buffer.d.ts.map +0 -1
- package/runtime/gateways/file/node/to-array-buffer.js +0 -12
- package/runtime/gateways/file/node/to-array-buffer.js.map +0 -1
- package/runtime/gateways/file/sys-file-system-factory.d.ts +0 -4
- package/runtime/gateways/file/sys-file-system-factory.d.ts.map +0 -1
- package/runtime/gateways/file/sys-file-system-factory.js +0 -13
- package/runtime/gateways/file/sys-file-system-factory.js.map +0 -1
- package/runtime/gateways/file/utils.d.ts +0 -5
- package/runtime/gateways/file/utils.d.ts.map +0 -1
- package/runtime/gateways/file/utils.js +0 -27
- package/runtime/gateways/file/utils.js.map +0 -1
- package/runtime/gateways/file/version.d.ts +0 -2
- package/runtime/gateways/file/version.d.ts.map +0 -1
- package/runtime/gateways/file/version.js +0 -2
- package/runtime/gateways/file/version.js.map +0 -1
- package/runtime/gateways/fp-envelope-serialize.d.ts +0 -50
- package/runtime/gateways/fp-envelope-serialize.d.ts.map +0 -1
- package/runtime/gateways/fp-envelope-serialize.js +0 -141
- package/runtime/gateways/fp-envelope-serialize.js.map +0 -1
- package/runtime/gateways/index.d.ts +0 -6
- package/runtime/gateways/index.d.ts.map +0 -1
- package/runtime/gateways/index.js +0 -6
- package/runtime/gateways/index.js.map +0 -1
- package/runtime/gateways/indexeddb/gateway-impl.d.ts +0 -22
- package/runtime/gateways/indexeddb/gateway-impl.d.ts.map +0 -1
- package/runtime/gateways/indexeddb/gateway-impl.js +0 -147
- package/runtime/gateways/indexeddb/gateway-impl.js.map +0 -1
- package/runtime/gateways/indexeddb/index.d.ts +0 -6
- package/runtime/gateways/indexeddb/index.d.ts.map +0 -1
- package/runtime/gateways/indexeddb/index.js +0 -6
- package/runtime/gateways/indexeddb/index.js.map +0 -1
- package/runtime/gateways/indexeddb/key-bag-indexeddb.d.ts +0 -16
- package/runtime/gateways/indexeddb/key-bag-indexeddb.d.ts.map +0 -1
- package/runtime/gateways/indexeddb/key-bag-indexeddb.js +0 -48
- package/runtime/gateways/indexeddb/key-bag-indexeddb.js.map +0 -1
- package/runtime/gateways/indexeddb-version.d.ts +0 -2
- package/runtime/gateways/indexeddb-version.d.ts.map +0 -1
- package/runtime/gateways/indexeddb-version.js +0 -2
- package/runtime/gateways/indexeddb-version.js.map +0 -1
- package/runtime/gateways/memory/gateway.d.ts +0 -18
- package/runtime/gateways/memory/gateway.d.ts.map +0 -1
- package/runtime/gateways/memory/gateway.js +0 -73
- package/runtime/gateways/memory/gateway.js.map +0 -1
- package/runtime/gateways/memory/version.d.ts +0 -2
- package/runtime/gateways/memory/version.d.ts.map +0 -1
- package/runtime/gateways/memory/version.js +0 -2
- package/runtime/gateways/memory/version.js.map +0 -1
- package/runtime/index.d.ts +0 -13
- package/runtime/index.d.ts.map +0 -1
- package/runtime/index.js +0 -13
- package/runtime/index.js.map +0 -1
- package/runtime/key-bag-memory.d.ts +0 -13
- package/runtime/key-bag-memory.d.ts.map +0 -1
- package/runtime/key-bag-memory.js +0 -30
- package/runtime/key-bag-memory.js.map +0 -1
- package/runtime/key-bag.d.ts +0 -88
- package/runtime/key-bag.d.ts.map +0 -1
- package/runtime/key-bag.js +0 -417
- package/runtime/key-bag.js.map +0 -1
- package/runtime/keyed-crypto.d.ts +0 -19
- package/runtime/keyed-crypto.d.ts.map +0 -1
- package/runtime/keyed-crypto.js +0 -192
- package/runtime/keyed-crypto.js.map +0 -1
- package/runtime/memory-sys-container.d.ts +0 -2
- package/runtime/memory-sys-container.d.ts.map +0 -1
- package/runtime/memory-sys-container.js +0 -2
- package/runtime/memory-sys-container.js.map +0 -1
- package/runtime/meta-key-hack.d.ts +0 -42
- package/runtime/meta-key-hack.d.ts.map +0 -1
- package/runtime/meta-key-hack.js +0 -201
- package/runtime/meta-key-hack.js.map +0 -1
- package/runtime/sts-service/index.d.ts +0 -40
- package/runtime/sts-service/index.d.ts.map +0 -1
- package/runtime/sts-service/index.js +0 -108
- package/runtime/sts-service/index.js.map +0 -1
- package/runtime/sys-container.d.ts +0 -2
- package/runtime/sys-container.d.ts.map +0 -1
- package/runtime/sys-container.js +0 -2
- package/runtime/sys-container.js.map +0 -1
- package/runtime/wait-pr-multiformats/block.d.ts +0 -47
- package/runtime/wait-pr-multiformats/block.d.ts.map +0 -1
- package/runtime/wait-pr-multiformats/block.js +0 -64
- package/runtime/wait-pr-multiformats/block.js.map +0 -1
- package/runtime/wait-pr-multiformats/codec-interface.d.ts +0 -29
- package/runtime/wait-pr-multiformats/codec-interface.d.ts.map +0 -1
- package/runtime/wait-pr-multiformats/codec-interface.js +0 -2
- package/runtime/wait-pr-multiformats/codec-interface.js.map +0 -1
- package/runtime/wait-pr-multiformats/index.d.ts +0 -3
- package/runtime/wait-pr-multiformats/index.d.ts.map +0 -1
- package/runtime/wait-pr-multiformats/index.js +0 -3
- package/runtime/wait-pr-multiformats/index.js.map +0 -1
- package/tests/blockstore/fp-envelope.test.ts-off +0 -65
- package/tests/blockstore/fragment-gateway.test.ts-off +0 -106
- package/tests/blockstore/interceptor-gateway.test.ts +0 -254
- package/tests/blockstore/keyed-crypto-indexeddb-file.test.ts +0 -128
- package/tests/blockstore/keyed-crypto.test.ts +0 -376
- package/tests/blockstore/loader.test.ts +0 -298
- package/tests/blockstore/standalone.test.ts +0 -152
- package/tests/blockstore/store.test.ts +0 -192
- package/tests/blockstore/transaction.test.ts +0 -130
- package/tests/fireproof/all-gateway.test.ts +0 -461
- package/tests/fireproof/attachable.test.ts +0 -686
- package/tests/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.car +0 -0
- package/tests/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.ts +0 -324
- package/tests/fireproof/charwise-boolean.test.ts +0 -66
- package/tests/fireproof/crdt.test.ts +0 -570
- package/tests/fireproof/database.test.ts +0 -779
- package/tests/fireproof/deleted-docs-handling.test.ts +0 -111
- package/tests/fireproof/fireproof.test.fixture.ts +0 -133
- package/tests/fireproof/fireproof.test.ts +0 -777
- package/tests/fireproof/hello.test.ts +0 -74
- package/tests/fireproof/indexer.test.ts +0 -458
- package/tests/fireproof/multiple-ledger.test.ts +0 -65
- package/tests/fireproof/query-docs.test.ts +0 -116
- package/tests/fireproof/query-limit-issue.test.ts +0 -147
- package/tests/fireproof/query-property-inconsistency.test.ts +0 -89
- package/tests/fireproof/query-result-properties.test.ts +0 -42
- package/tests/fireproof/stable-cid.test.ts +0 -69
- package/tests/fireproof/utils.test.ts +0 -135
- package/tests/gateway/file/loader-config.test.ts +0 -307
- package/tests/gateway/indexeddb/loader-config.test.ts +0 -79
- package/tests/helpers.ts +0 -172
- package/tests/protocols/cloud/msger.test.ts +0 -548
- package/tests/react/img-file.test.tsx +0 -190
- package/tests/react/use-all-docs.test.tsx +0 -172
- package/tests/react/use-document-with-nonexistent-id.test.tsx +0 -96
- package/tests/react/use-fireproof-db-switch.test.tsx +0 -91
- package/tests/react/use-fireproof-stability.test.tsx +0 -145
- package/tests/react/use-fireproof.test.tsx +0 -645
- package/tests/runtime/fp-envelope-serialize.test.ts +0 -254
- package/tests/runtime/meta-key-hack.test.ts +0 -95
- package/tests/setup.file.ts +0 -1
- package/tests/setup.indexeddb.ts +0 -0
- package/tests/setup.memory.ts +0 -2
- package/tests/vitest.file.config.ts +0 -14
- package/tests/vitest.indexeddb.config.ts +0 -37
- package/tests/vitest.memory.config.ts +0 -25
- package/types.d.ts +0 -461
- package/types.d.ts.map +0 -1
- package/types.js +0 -60
- package/types.js.map +0 -1
- package/use-fireproof/iframe-strategy.d.ts +0 -14
- package/use-fireproof/iframe-strategy.d.ts.map +0 -1
- package/use-fireproof/iframe-strategy.js +0 -79
- package/use-fireproof/iframe-strategy.js.map +0 -1
- package/use-fireproof/index.d.ts +0 -14
- package/use-fireproof/index.d.ts.map +0 -1
- package/use-fireproof/index.js +0 -36
- package/use-fireproof/index.js.map +0 -1
- package/use-fireproof/redirect-strategy.d.ts +0 -15
- package/use-fireproof/redirect-strategy.d.ts.map +0 -1
- package/use-fireproof/redirect-strategy.js +0 -153
- package/use-fireproof/redirect-strategy.js.map +0 -1
- package/utils.d.ts +0 -48
- package/utils.d.ts.map +0 -1
- package/utils.js +0 -406
- package/utils.js.map +0 -1
- package/version.d.ts +0 -2
- package/version.d.ts.map +0 -1
- package/version.js +0 -4
- package/version.js.map +0 -1
- package/write-queue.d.ts +0 -9
- package/write-queue.d.ts.map +0 -1
- package/write-queue.js +0 -70
- package/write-queue.js.map +0 -1
@@ -1,686 +0,0 @@
|
|
1
|
-
import { AppContext, BuildURI, URI, WithoutPromise } from "@adviser/cement";
|
2
|
-
import { stripper } from "@adviser/cement/utils";
|
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";
|
16
|
-
import { CarReader } from "@ipld/car/reader";
|
17
|
-
import * as dagCbor from "@ipld/dag-cbor";
|
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
|
-
}
|
80
|
-
|
81
|
-
describe("meta check", () => {
|
82
|
-
const sthis = ensureSuperThis();
|
83
|
-
it("empty Database", async () => {
|
84
|
-
const name = `remote-db-${sthis.nextId().str}`;
|
85
|
-
const db = fireproof(name, {
|
86
|
-
storeUrls: {
|
87
|
-
base: `memory://${name}`,
|
88
|
-
},
|
89
|
-
});
|
90
|
-
await db.ready();
|
91
|
-
const gws = db.ledger.crdt.blockstore.loader.attachedStores.local();
|
92
|
-
await db.close();
|
93
|
-
expect(
|
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}`)),
|
97
|
-
).toEqual([]);
|
98
|
-
});
|
99
|
-
|
100
|
-
it("one record Database", async () => {
|
101
|
-
const name = `remote-db-${sthis.nextId().str}`;
|
102
|
-
const db = fireproof(name, {
|
103
|
-
storeUrls: {
|
104
|
-
base: `memory://${name}`,
|
105
|
-
},
|
106
|
-
});
|
107
|
-
await db.put({ _id: `id-${0}`, value: `value-${0}` });
|
108
|
-
await db.close();
|
109
|
-
|
110
|
-
const db1 = fireproof(name, {
|
111
|
-
storeUrls: {
|
112
|
-
base: `memory://${name}`,
|
113
|
-
},
|
114
|
-
});
|
115
|
-
await db1.close();
|
116
|
-
});
|
117
|
-
|
118
|
-
it("multiple record Database", async () => {
|
119
|
-
const name = `remote-db-${sthis.nextId().str}`;
|
120
|
-
const base = `memory://${name}?storekey=insecure`;
|
121
|
-
const db = fireproof(name, {
|
122
|
-
storeUrls: {
|
123
|
-
base,
|
124
|
-
},
|
125
|
-
});
|
126
|
-
await db.ready();
|
127
|
-
await db.put({ _id: `id-${0}`, value: `value-${0}` });
|
128
|
-
const gws = db.ledger.crdt.blockstore.loader.attachedStores.local();
|
129
|
-
expect(db.ledger.crdt.blockstore.loader.carLog.asArray().map((i) => i.map((i) => i.toString()))).toEqual([
|
130
|
-
["baembeieldbalgnyxqp7rmj4cbrot75gweavqy3aw22km43zsfufrihfn7e"],
|
131
|
-
["baembeig2is4vdgz4gyiadfh5uutxxeiuqtacnesnytrnilpwcu7q5m5tmu"],
|
132
|
-
]);
|
133
|
-
await db.close();
|
134
|
-
expect(
|
135
|
-
Array.from(((gws.active.car.realGateway as rt.gw.DefSerdeGateway).gw as rt.gw.memory.MemoryGateway).memories.entries())
|
136
|
-
.filter(([k]) => k.startsWith(`memory://${name}`))
|
137
|
-
.map(([k]) =>
|
138
|
-
stripper(
|
139
|
-
["name", "storekey", "version"],
|
140
|
-
Array.from(URI.from(k).getParams).reduce((acc, [k, v]) => ({ ...acc, [k]: v }), {}),
|
141
|
-
),
|
142
|
-
),
|
143
|
-
).toEqual([
|
144
|
-
{
|
145
|
-
key: "baembeig2is4vdgz4gyiadfh5uutxxeiuqtacnesnytrnilpwcu7q5m5tmu",
|
146
|
-
store: "car",
|
147
|
-
suffix: ".car",
|
148
|
-
},
|
149
|
-
{
|
150
|
-
key: "main",
|
151
|
-
store: "wal",
|
152
|
-
},
|
153
|
-
{
|
154
|
-
key: "main",
|
155
|
-
store: "meta",
|
156
|
-
},
|
157
|
-
{
|
158
|
-
key: "baembeieldbalgnyxqp7rmj4cbrot75gweavqy3aw22km43zsfufrihfn7e",
|
159
|
-
store: "car",
|
160
|
-
suffix: ".car",
|
161
|
-
},
|
162
|
-
]);
|
163
|
-
|
164
|
-
const db1 = fireproof(name, {
|
165
|
-
storeUrls: {
|
166
|
-
base,
|
167
|
-
},
|
168
|
-
});
|
169
|
-
expect(db1.ledger).not.equal(db.ledger);
|
170
|
-
await db1.ready();
|
171
|
-
expect(db1.ledger.crdt.blockstore.loader.carLog.asArray().map((i) => i.map((i) => i.toString()))).toEqual([
|
172
|
-
["baembeieldbalgnyxqp7rmj4cbrot75gweavqy3aw22km43zsfufrihfn7e"],
|
173
|
-
["baembeig2is4vdgz4gyiadfh5uutxxeiuqtacnesnytrnilpwcu7q5m5tmu"],
|
174
|
-
]);
|
175
|
-
|
176
|
-
const gensis = await db1.get(PARAM.GENESIS_CID);
|
177
|
-
expect(gensis).toEqual({ _id: PARAM.GENESIS_CID });
|
178
|
-
|
179
|
-
const val = await db1.allDocs();
|
180
|
-
expect(val.rows).toEqual([
|
181
|
-
{
|
182
|
-
key: "id-0",
|
183
|
-
value: {
|
184
|
-
_id: "id-0",
|
185
|
-
value: "value-0",
|
186
|
-
},
|
187
|
-
},
|
188
|
-
]);
|
189
|
-
const car = Array.from(
|
190
|
-
((gws.active.car.realGateway as rt.gw.DefSerdeGateway).gw as rt.gw.memory.MemoryGateway).memories.entries(),
|
191
|
-
)
|
192
|
-
.filter(([k]) => k.startsWith(`memory://${name}`))
|
193
|
-
.map(([k, v]) => [URI.from(k).getParam(PARAM.KEY), v])
|
194
|
-
.find(([k]) => k === "baembeig2is4vdgz4gyiadfh5uutxxeiuqtacnesnytrnilpwcu7q5m5tmu") as [string, Uint8Array];
|
195
|
-
const rawReader = await CarReader.fromBytes(car[1]);
|
196
|
-
const blocks = [];
|
197
|
-
for await (const block of rawReader.blocks()) {
|
198
|
-
blocks.push(block);
|
199
|
-
}
|
200
|
-
expect(dagCbor.decode(blocks[1].bytes)).toEqual({
|
201
|
-
doc: {
|
202
|
-
_id: "baembeiarootfireproofgenesisblockaaaafireproofgenesisblocka",
|
203
|
-
},
|
204
|
-
});
|
205
|
-
|
206
|
-
expect(blocks.map((i) => i.cid.toString())).toEqual([
|
207
|
-
"bafyreibxibqhi6wh5klrje7ne4htffeqyyqfd6y7x2no6wnhid4nixizau",
|
208
|
-
"bafyreidnvv4mwvweup5w52ddre2sl4syhvczm6ejqsmuekajowdl2cf2q4",
|
209
|
-
"bafyreihh6nbfbhgkf5lz7hhsscjgiquw426rxzr3fprbgonekzmyvirrhe",
|
210
|
-
"bafyreiejg3twlaxr7gfvvhtxrhvwaydytdv4guidmtvaz5dskm6gp73ryi",
|
211
|
-
"bafyreiblui55o25dopc5faol3umsnuohb5carto7tot4kicnkfc37he4h4",
|
212
|
-
]);
|
213
|
-
});
|
214
|
-
});
|
215
|
-
|
216
|
-
describe("activate store", () => {
|
217
|
-
// activate(store: DataAndMetaStore | CoerceURI): ActiveStore {
|
218
|
-
// if (isCoerceURI(store)) {
|
219
|
-
// throw this.loadable.sthis.logger.Error().Msg("store must be an object").AsError();
|
220
|
-
// }
|
221
|
-
// return new ActiveStoreImpl(store as DataAndMetaStore, this);
|
222
|
-
// }
|
223
|
-
|
224
|
-
const sthis = ensureSuperThis();
|
225
|
-
let attach: bs.AttachedStores;
|
226
|
-
let firstAttached: Attached;
|
227
|
-
let secondAttached: Attached;
|
228
|
-
beforeEach(async () => {
|
229
|
-
attach = new bs.AttachedRemotesImpl(mockLoader(sthis));
|
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
|
-
);
|
243
|
-
|
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
|
-
);
|
256
|
-
});
|
257
|
-
|
258
|
-
it("activate by store", async () => {
|
259
|
-
expect(attach.activate(secondAttached.stores).active.car.url().toString()).toBe(
|
260
|
-
"memory://second?localName=first&name=second&store=car&storekey=%40first-data%40&suffix=.car&version=v0.19-memory",
|
261
|
-
);
|
262
|
-
expect(attach.activate(firstAttached.stores).local().active.car.url().toString()).toBe(
|
263
|
-
"memory://first?name=first&store=car&storekey=%40first-data%40&suffix=.car&version=v0.19-memory",
|
264
|
-
);
|
265
|
-
expect(attach.activate(firstAttached.stores).active.meta.url().toString()).toBe(
|
266
|
-
"memory://first?name=first&store=meta&storekey=%40first-meta%40&version=v0.19-memory",
|
267
|
-
);
|
268
|
-
});
|
269
|
-
|
270
|
-
it("activate by store", async () => {
|
271
|
-
expect(attach.activate("memory://second").active.car.url().toString()).toBe(
|
272
|
-
"memory://second?localName=first&name=second&store=car&storekey=%40first-data%40&suffix=.car&version=v0.19-memory",
|
273
|
-
);
|
274
|
-
expect(attach.activate("memory://second").remotes()[0].active.car.url().toString()).toEqual(
|
275
|
-
"memory://second?localName=first&name=second&store=car&storekey=%40first-data%40&suffix=.car&version=v0.19-memory",
|
276
|
-
);
|
277
|
-
expect(attach.activate("memory://first?store=meta").active.car.url().toString()).toBe(
|
278
|
-
"memory://first?name=first&store=car&storekey=%40first-data%40&suffix=.car&version=v0.19-memory",
|
279
|
-
);
|
280
|
-
});
|
281
|
-
});
|
282
|
-
|
283
|
-
describe("join function", () => {
|
284
|
-
const sthis = ensureSuperThis();
|
285
|
-
// export const connect: ConnectFunction = (
|
286
|
-
// db: Database,
|
287
|
-
// remoteDbName = "",
|
288
|
-
// url = "netlify://localhost:8888?protocol=ws"
|
289
|
-
// ) => {
|
290
|
-
// const { sthis, name: dbName } = db;
|
291
|
-
// if (!dbName) {
|
292
|
-
// throw new Error("dbName is required");
|
293
|
-
// }
|
294
|
-
// const urlObj = BuildURI.from(url);
|
295
|
-
// const existingName = urlObj.getParam("name");
|
296
|
-
// urlObj.defParam("name", remoteDbName || existingName || dbName);
|
297
|
-
// urlObj.defParam("localName", dbName);
|
298
|
-
// urlObj.defParam("storekey", `@${dbName}:data@`);
|
299
|
-
// return connectionCache.get(urlObj.toString()).once(() => {
|
300
|
-
// makeKeyBagUrlExtractable(sthis);
|
301
|
-
// const connection = connectionFactory(sthis, urlObj);
|
302
|
-
// connection.connect(db.ledger.crdt.blockstore);
|
303
|
-
// return connection;
|
304
|
-
// });
|
305
|
-
// };
|
306
|
-
|
307
|
-
let db: Database;
|
308
|
-
let joinableDBs: string[] = [];
|
309
|
-
beforeEach(async () => {
|
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
|
-
|
322
|
-
joinableDBs = await Promise.all(
|
323
|
-
new Array(1).fill(1).map(async (_, i) => {
|
324
|
-
const name = `remote-db-${i}-${set}`;
|
325
|
-
const jdb = fireproof(name, {
|
326
|
-
storeUrls: attachableStoreUrls(name, db),
|
327
|
-
});
|
328
|
-
// await db.put({ _id: `genesis`, value: `genesis` });
|
329
|
-
// await db.ready();
|
330
|
-
for (let j = 0; j < ROWS; j++) {
|
331
|
-
await jdb.put({ _id: `${i}-${j}`, value: `${i}-${j}` });
|
332
|
-
}
|
333
|
-
expect(await jdb.get(PARAM.GENESIS_CID)).toEqual({ _id: PARAM.GENESIS_CID });
|
334
|
-
await jdb.close();
|
335
|
-
return name;
|
336
|
-
}),
|
337
|
-
);
|
338
|
-
// await new Promise((resolve) => setTimeout(resolve, 1000));
|
339
|
-
|
340
|
-
expect(await db.get(PARAM.GENESIS_CID)).toEqual({ _id: PARAM.GENESIS_CID });
|
341
|
-
});
|
342
|
-
afterEach(async () => {
|
343
|
-
await db.close();
|
344
|
-
});
|
345
|
-
|
346
|
-
it("it is joinable detachable", async () => {
|
347
|
-
const my = fireproof("my", {
|
348
|
-
storeUrls: {
|
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@"),
|
353
|
-
},
|
354
|
-
});
|
355
|
-
await my.put({ _id: "genesis", value: "genesis" });
|
356
|
-
await Promise.all(
|
357
|
-
joinableDBs.map(async (name) => {
|
358
|
-
const tmp = fireproof(name, {
|
359
|
-
storeUrls: attachableStoreUrls(name, my),
|
360
|
-
});
|
361
|
-
const res = await tmp.allDocs();
|
362
|
-
expect(res.rows.length).toBe(ROWS);
|
363
|
-
await tmp.close();
|
364
|
-
const attached = await my.attach(aJoinable(name, my));
|
365
|
-
expect(attached).toBeDefined();
|
366
|
-
}),
|
367
|
-
);
|
368
|
-
expect(my.ledger.crdt.blockstore.loader.attachedStores.remotes().length).toBe(joinableDBs.length);
|
369
|
-
await my.close();
|
370
|
-
expect(my.ledger.crdt.blockstore.loader.attachedStores.remotes().length).toBe(0);
|
371
|
-
});
|
372
|
-
|
373
|
-
it("it is inbound syncing", async () => {
|
374
|
-
await Promise.all(
|
375
|
-
joinableDBs.map(async (name) => {
|
376
|
-
const attached = await db.attach(aJoinable(name, db));
|
377
|
-
expect(attached).toBeDefined();
|
378
|
-
}),
|
379
|
-
);
|
380
|
-
await sleep(100);
|
381
|
-
expect(db.ledger.crdt.blockstore.loader.attachedStores.remotes().length).toBe(joinableDBs.length);
|
382
|
-
const res = await db.allDocs();
|
383
|
-
expect(res.rows.length).toBe(ROWS + ROWS * joinableDBs.length);
|
384
|
-
});
|
385
|
-
|
386
|
-
it("it empty inbound syncing", async () => {
|
387
|
-
const name = `empty-db-${sthis.nextId().str}`;
|
388
|
-
const mydb = fireproof(name, {
|
389
|
-
storeUrls: attachableStoreUrls(name, db),
|
390
|
-
});
|
391
|
-
await Promise.all(
|
392
|
-
joinableDBs.map(async (name) => {
|
393
|
-
const attached = await mydb.attach(aJoinable(name, mydb));
|
394
|
-
expect(attached).toBeDefined();
|
395
|
-
}),
|
396
|
-
);
|
397
|
-
await sleep(100);
|
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
|
-
}
|
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);
|
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(1000);
|
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
|
-
// eslint-disable-next-line no-console
|
626
|
-
console.log(
|
627
|
-
"out",
|
628
|
-
outRows.map((row) => row.key),
|
629
|
-
);
|
630
|
-
// eslint-disable-next-line no-console
|
631
|
-
console.log(
|
632
|
-
"in",
|
633
|
-
inRows.map((row) => row.key),
|
634
|
-
);
|
635
|
-
expect(inRows).toEqual(outRows);
|
636
|
-
}, 100_000);
|
637
|
-
});
|
638
|
-
|
639
|
-
async function syncDb(name: string, base: string, tracer?: TraceFn) {
|
640
|
-
const db = fireproof(name, {
|
641
|
-
storeUrls: {
|
642
|
-
base: BuildURI.from(base).setParam(PARAM.STORE_KEY, "@fireproof:attach@"), // .setParam(PARAM.SELF_REFLECT, "yes"),
|
643
|
-
},
|
644
|
-
ctx: AppContext.merge({ base }),
|
645
|
-
tracer,
|
646
|
-
});
|
647
|
-
await db.ready();
|
648
|
-
return db;
|
649
|
-
}
|
650
|
-
|
651
|
-
async function prepareDb(name: string, base: string, tracer?: TraceFn) {
|
652
|
-
{
|
653
|
-
const db = await syncDb(name, base, tracer);
|
654
|
-
await db.ready();
|
655
|
-
const dbId = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.car.id();
|
656
|
-
const ret = { db, dbId };
|
657
|
-
await writeRow(ret, `initial`);
|
658
|
-
await db.close();
|
659
|
-
}
|
660
|
-
|
661
|
-
const db = await syncDb(name, base);
|
662
|
-
await db.ready();
|
663
|
-
const dbId = await db.ledger.crdt.blockstore.loader.attachedStores.local().active.car.id();
|
664
|
-
// const ret = { db, dbId };
|
665
|
-
return { db, dbId };
|
666
|
-
}
|
667
|
-
|
668
|
-
async function readDb(name: string, base: string) {
|
669
|
-
const db = await syncDb(name, base);
|
670
|
-
const rows = await db.allDocs();
|
671
|
-
await db.close();
|
672
|
-
return rows.rows.sort((a, b) => a.key.localeCompare(b.key));
|
673
|
-
}
|
674
|
-
|
675
|
-
async function writeRow(pdb: WithoutPromise<ReturnType<typeof prepareDb>>, style: string) {
|
676
|
-
return await Promise.all(
|
677
|
-
Array(ROWS)
|
678
|
-
.fill(0)
|
679
|
-
.map(async (_, i) => {
|
680
|
-
const key = `${pdb.dbId}-${pdb.db.name}-${style}-${i}`;
|
681
|
-
// console.log(key);
|
682
|
-
await pdb.db.put({ _id: key, value: key });
|
683
|
-
return key;
|
684
|
-
}),
|
685
|
-
);
|
686
|
-
}
|