@fireproof/core 0.20.0-dev-preview-63 → 0.20.1-dev-preview-01
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/deno/index.d.ts +7 -0
- package/deno/index.js +66 -0
- package/deno/index.js.map +1 -0
- package/deno/metafile-esm.json +1 -0
- package/deno.json +2 -2
- package/index.cjs +7268 -0
- package/index.cjs.map +1 -0
- package/index.d.cts +2742 -0
- package/index.d.ts +2742 -15
- package/index.js +7267 -14
- package/index.js.map +1 -1
- package/indexeddb/index.cjs +218 -0
- package/indexeddb/index.cjs.map +1 -0
- package/indexeddb/index.d.cts +30 -0
- package/indexeddb/index.d.ts +30 -0
- package/indexeddb/index.js +195 -0
- package/indexeddb/index.js.map +1 -0
- package/indexeddb/metafile-cjs.json +1 -0
- package/indexeddb/metafile-esm.json +1 -0
- package/metafile-cjs.json +1 -0
- package/metafile-esm.json +1 -0
- package/node/index.cjs +97 -0
- package/node/index.cjs.map +1 -0
- package/node/index.d.cts +7 -0
- package/node/index.d.ts +7 -0
- package/node/index.js +64 -0
- package/node/index.js.map +1 -0
- package/node/metafile-cjs.json +1 -0
- package/node/metafile-esm.json +1 -0
- package/package.json +17 -20
- package/react/index.cjs +298 -0
- package/react/index.cjs.map +1 -0
- package/react/{img-file.d.ts → index.d.cts} +53 -6
- package/react/index.d.ts +336 -4
- package/react/index.js +264 -3
- package/react/index.js.map +1 -1
- package/react/metafile-cjs.json +1 -0
- package/react/metafile-esm.json +1 -0
- package/tests/blockstore/loader.test.ts +1 -1
- package/tests/blockstore/store.test.ts +4 -9
- package/tests/fireproof/attachable.test.ts +3 -3
- package/tests/react/use-fireproof-db-switch.test.tsx +91 -0
- package/tests/react/use-fireproof-stability.test.tsx +145 -0
- package/tests/www/gallery.html +132 -0
- package/tests/www/iife.html +42 -0
- package/tests/www/todo-aws.html +232 -0
- package/tests/www/todo-ipfs.html +213 -0
- package/tests/www/todo-local.html +214 -0
- package/tests/www/todo-netlify.html +227 -0
- package/tests/www/todo.html +254 -0
- 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 -17
- package/blockstore/attachable-store.d.ts.map +0 -1
- package/blockstore/attachable-store.js +0 -295
- package/blockstore/attachable-store.js.map +0 -1
- package/blockstore/commit-queue.d.ts +0 -12
- package/blockstore/commit-queue.d.ts.map +0 -1
- package/blockstore/commit-queue.js +0 -52
- 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 -104
- 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 -16
- package/blockstore/index.d.ts.map +0 -1
- package/blockstore/index.js +0 -16
- 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 -4
- package/blockstore/loader-helpers.d.ts.map +0 -1
- package/blockstore/loader-helpers.js +0 -16
- package/blockstore/loader-helpers.js.map +0 -1
- package/blockstore/loader.d.ts +0 -45
- package/blockstore/loader.d.ts.map +0 -1
- package/blockstore/loader.js +0 -352
- 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 -114
- 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 -105
- 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 -82
- package/blockstore/store.d.ts.map +0 -1
- package/blockstore/store.js +0 -438
- 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 -64
- package/blockstore/transaction.d.ts.map +0 -1
- package/blockstore/transaction.js +0 -249
- package/blockstore/transaction.js.map +0 -1
- package/blockstore/types.d.ts +0 -400
- package/blockstore/types.d.ts.map +0 -1
- package/blockstore/types.js +0 -55
- 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 -26114
- package/context.d.ts +0 -7
- package/context.d.ts.map +0 -1
- package/context.js +0 -15
- package/context.js.map +0 -1
- package/crdt-clock.d.ts +0 -27
- package/crdt-clock.d.ts.map +0 -1
- package/crdt-clock.js +0 -140
- package/crdt-clock.js.map +0 -1
- package/crdt-helpers.d.ts +0 -16
- package/crdt-helpers.d.ts.map +0 -1
- package/crdt-helpers.js +0 -316
- package/crdt-helpers.js.map +0 -1
- package/crdt.d.ts +0 -34
- package/crdt.d.ts.map +0 -1
- package/crdt.js +0 -131
- package/crdt.js.map +0 -1
- package/database.d.ts +0 -34
- package/database.d.ts.map +0 -1
- package/database.js +0 -121
- package/database.js.map +0 -1
- package/index.d.ts.map +0 -1
- package/indexer-helpers.d.ts +0 -69
- package/indexer-helpers.d.ts.map +0 -1
- package/indexer-helpers.js +0 -135
- package/indexer-helpers.js.map +0 -1
- package/indexer.d.ts +0 -25
- package/indexer.d.ts.map +0 -1
- package/indexer.js +0 -231
- package/indexer.js.map +0 -1
- package/ledger.d.ts +0 -56
- package/ledger.d.ts.map +0 -1
- package/ledger.js +0 -224
- package/ledger.js.map +0 -1
- package/protocols/cloud/http-connection.d.ts +0 -25
- package/protocols/cloud/http-connection.d.ts.map +0 -1
- package/protocols/cloud/http-connection.js +0 -153
- 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 -279
- package/protocols/cloud/msg-types.d.ts.map +0 -1
- package/protocols/cloud/msg-types.js +0 -278
- package/protocols/cloud/msg-types.js.map +0 -1
- package/protocols/cloud/msger.d.ts +0 -79
- package/protocols/cloud/msger.d.ts.map +0 -1
- package/protocols/cloud/msger.js +0 -198
- package/protocols/cloud/msger.js.map +0 -1
- package/protocols/cloud/ws-connection.d.ts +0 -29
- package/protocols/cloud/ws-connection.d.ts.map +0 -1
- package/protocols/cloud/ws-connection.js +0 -163
- package/protocols/cloud/ws-connection.js.map +0 -1
- package/protocols/index.d.ts +0 -2
- package/protocols/index.d.ts.map +0 -1
- package/protocols/index.js +0 -2
- package/protocols/index.js.map +0 -1
- package/react/img-file.d.ts.map +0 -1
- package/react/img-file.js +0 -58
- package/react/img-file.js.map +0 -1
- package/react/index.d.ts.map +0 -1
- package/react/types.d.ts +0 -43
- 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 -19
- package/react/use-all-docs.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 -99
- 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 -15
- 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 -38
- package/react/use-live-query.js.map +0 -1
- package/react/utils.d.ts +0 -2
- package/react/utils.d.ts.map +0 -1
- package/react/utils.js +0 -4
- package/react/utils.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 -44
- package/runtime/gateways/cloud/gateway.d.ts.map +0 -1
- package/runtime/gateways/cloud/gateway.js +0 -496
- package/runtime/gateways/cloud/gateway.js.map +0 -1
- package/runtime/gateways/def-serde-gateway.d.ts +0 -19
- package/runtime/gateways/def-serde-gateway.d.ts.map +0 -1
- package/runtime/gateways/def-serde-gateway.js +0 -73
- 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 -51
- 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 -19
- package/runtime/gateways/file/key-bag-file.d.ts.map +0 -1
- package/runtime/gateways/file/key-bag-file.js +0 -40
- 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 -37
- 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 -15
- package/runtime/gateways/indexeddb/key-bag-indexeddb.d.ts.map +0 -1
- package/runtime/gateways/indexeddb/key-bag-indexeddb.js +0 -42
- 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 -58
- 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 -12
- package/runtime/key-bag-memory.d.ts.map +0 -1
- package/runtime/key-bag-memory.js +0 -23
- package/runtime/key-bag-memory.js.map +0 -1
- package/runtime/key-bag.d.ts +0 -85
- package/runtime/key-bag.d.ts.map +0 -1
- package/runtime/key-bag.js +0 -415
- 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 -102
- 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/types.d.ts +0 -427
- package/types.d.ts.map +0 -1
- package/types.js +0 -54
- package/types.js.map +0 -1
- package/use-fireproof/index.d.ts +0 -3
- package/use-fireproof/index.d.ts.map +0 -1
- package/use-fireproof/index.js +0 -3
- package/use-fireproof/index.js.map +0 -1
- package/utils.d.ts +0 -36
- package/utils.d.ts.map +0 -1
- package/utils.js +0 -379
- 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,105 +0,0 @@
|
|
|
1
|
-
import { Result } from "@adviser/cement";
|
|
2
|
-
import { decodeFile, encodeFile } from "../runtime/files.js";
|
|
3
|
-
import { CarStoreImpl, FileStoreImpl, MetaStoreImpl, WALStoreImpl } from "./store.js";
|
|
4
|
-
import { PARAM } from "../types.js";
|
|
5
|
-
import { getGatewayFactoryItem } from "./register-store-protocol.js";
|
|
6
|
-
import { InterceptorGateway } from "./interceptor-gateway.js";
|
|
7
|
-
export async function getInterceptableGateway(ctx, url, opt) {
|
|
8
|
-
const item = getGatewayFactoryItem(url.protocol);
|
|
9
|
-
if (item) {
|
|
10
|
-
return Result.Ok(new InterceptorGateway(ctx.loader.sthis, await item.serdegateway(ctx.loader.sthis), opt.gatewayInterceptor));
|
|
11
|
-
}
|
|
12
|
-
return Result.Err(ctx.loader.sthis.logger.Warn().Url(url).Msg("unsupported protocol").AsError());
|
|
13
|
-
}
|
|
14
|
-
async function carStoreFactory(ctx, uai) {
|
|
15
|
-
const storeUrl = uai.url.build().setParam(PARAM.STORE, "car").URI();
|
|
16
|
-
const rgateway = await getInterceptableGateway(ctx, storeUrl, uai);
|
|
17
|
-
if (rgateway.isErr()) {
|
|
18
|
-
throw ctx.loader.sthis.logger.Error().Result("err", rgateway).Url(uai.url).Msg("notfound").AsError();
|
|
19
|
-
}
|
|
20
|
-
const gateway = rgateway.Ok();
|
|
21
|
-
const store = new CarStoreImpl(ctx.loader.sthis, uai.url, {
|
|
22
|
-
gateway,
|
|
23
|
-
loader: ctx.loader,
|
|
24
|
-
});
|
|
25
|
-
return store;
|
|
26
|
-
}
|
|
27
|
-
async function fileStoreFactory(ctx, uai) {
|
|
28
|
-
const storeUrl = uai.url.build().setParam(PARAM.STORE, "file").URI();
|
|
29
|
-
const rgateway = await getInterceptableGateway(ctx, storeUrl, uai);
|
|
30
|
-
if (rgateway.isErr()) {
|
|
31
|
-
throw ctx.loader.sthis.logger.Error().Result("err", rgateway).Url(uai.url).Msg("notfound").AsError();
|
|
32
|
-
}
|
|
33
|
-
const gateway = rgateway.Ok();
|
|
34
|
-
const store = new FileStoreImpl(ctx.loader.sthis, uai.url, {
|
|
35
|
-
gateway: gateway,
|
|
36
|
-
loader: ctx.loader,
|
|
37
|
-
});
|
|
38
|
-
return store;
|
|
39
|
-
}
|
|
40
|
-
async function metaStoreFactory(ctx, uai) {
|
|
41
|
-
const storeUrl = uai.url.build().setParam(PARAM.STORE, "meta").URI();
|
|
42
|
-
const rgateway = await getInterceptableGateway(ctx, storeUrl, uai);
|
|
43
|
-
if (rgateway.isErr()) {
|
|
44
|
-
throw ctx.loader.sthis.logger.Error().Result("err", rgateway).Url(uai.url).Msg("notfound").AsError();
|
|
45
|
-
}
|
|
46
|
-
const gateway = rgateway.Ok();
|
|
47
|
-
const store = new MetaStoreImpl(ctx.loader.sthis, uai.url, {
|
|
48
|
-
gateway,
|
|
49
|
-
loader: ctx.loader,
|
|
50
|
-
});
|
|
51
|
-
return store;
|
|
52
|
-
}
|
|
53
|
-
async function WALStoreFactory(ctx, uai) {
|
|
54
|
-
const storeUrl = uai.url.build().setParam(PARAM.STORE, "wal").URI();
|
|
55
|
-
const rgateway = await getInterceptableGateway(ctx, storeUrl, uai);
|
|
56
|
-
if (rgateway.isErr()) {
|
|
57
|
-
throw ctx.loader.sthis.logger.Error().Result("err", rgateway).Url(uai.url).Msg("notfound").AsError();
|
|
58
|
-
}
|
|
59
|
-
const gateway = rgateway.Ok();
|
|
60
|
-
const store = new WALStoreImpl(ctx.loader.sthis, uai.url, {
|
|
61
|
-
gateway,
|
|
62
|
-
loader: ctx.loader,
|
|
63
|
-
});
|
|
64
|
-
return store;
|
|
65
|
-
}
|
|
66
|
-
async function ensureStart(store, damaw) {
|
|
67
|
-
const ret = await store.start(damaw);
|
|
68
|
-
if (ret.isErr()) {
|
|
69
|
-
throw store.logger.Error().Result("start", ret).Msg("start failed").AsError();
|
|
70
|
-
}
|
|
71
|
-
store.logger.Debug().Url(ret.Ok(), "prepared").Msg("produced");
|
|
72
|
-
return store;
|
|
73
|
-
}
|
|
74
|
-
export function ensureStoreEnDeFile(ende) {
|
|
75
|
-
ende = ende || {};
|
|
76
|
-
return {
|
|
77
|
-
encodeFile: ende.encodeFile || encodeFile,
|
|
78
|
-
decodeFile: ende.decodeFile || decodeFile,
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
export function toStoreRuntime(sthis, endeOpts = {}) {
|
|
82
|
-
return {
|
|
83
|
-
makeStores: async (sfi) => {
|
|
84
|
-
const ctx = {
|
|
85
|
-
loader: sfi.loader,
|
|
86
|
-
};
|
|
87
|
-
const storeSet = {};
|
|
88
|
-
storeSet.meta = await metaStoreFactory(ctx, sfi.byStore.meta);
|
|
89
|
-
storeSet.car = await carStoreFactory(ctx, sfi.byStore.car);
|
|
90
|
-
storeSet.file = await fileStoreFactory(ctx, sfi.byStore.file);
|
|
91
|
-
if (sfi.byStore.wal) {
|
|
92
|
-
storeSet.wal = await WALStoreFactory(ctx, sfi.byStore.wal);
|
|
93
|
-
}
|
|
94
|
-
await ensureStart(storeSet.meta, storeSet);
|
|
95
|
-
await ensureStart(storeSet.car, storeSet);
|
|
96
|
-
await ensureStart(storeSet.file, storeSet);
|
|
97
|
-
if (storeSet.wal) {
|
|
98
|
-
await ensureStart(storeSet.wal, storeSet);
|
|
99
|
-
}
|
|
100
|
-
return storeSet;
|
|
101
|
-
},
|
|
102
|
-
...ensureStoreEnDeFile(endeOpts),
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
//# sourceMappingURL=store-factory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"store-factory.js","sourceRoot":"","sources":["../../../../src/blockstore/store-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEtD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAYtF,OAAO,EAAE,KAAK,EAAa,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAErE,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAS9D,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,GAAoB,EACpB,GAAQ,EACR,GAAqD;IAErD,MAAM,IAAI,GAAG,qBAAqB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACjD,IAAI,IAAI,EAAE,CAAC;QACT,OAAO,MAAM,CAAC,EAAE,CAAC,IAAI,kBAAkB,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,kBAAkB,CAAC,CAAC,CAAC;IAChI,CAAC;IACD,OAAO,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC,OAAO,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AC;YAC3C,IAAI,QAAQ,CAAC,GAAG,EAAE,CAAC;gBACjB,MAAM,WAAW,CAAC,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;YAC5C,CAAC;YAED,OAAO,QAAQ,CAAC;QAClB,CAAC;QAMD,GAAG,mBAAmB,CAAC,QAAQ,CAAC;KACjC,CAAC;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"store-remote.d.ts","sourceRoot":"","sources":["../../../../src/blockstore/store-remote.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"store-remote.js","sourceRoot":"","sources":["../../../../src/blockstore/store-remote.ts"],"names":[],"mappings":""}
|
package/blockstore/store.d.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { Logger, ResolveOnce, Result, URI } from "@adviser/cement";
|
|
2
|
-
import type { AnyBlock, AnyLink, CommitOpts, DataSaveOpts, DbMeta, WALStore as WALStore, WALState, LoadHandler, CryptoAction, Loadable, CarClockHead, DbMetaEvent, MetaStore, DataAndMetaStore, CarStore, FileStore } from "./types.js";
|
|
3
|
-
import { Falsy, StoreType, SuperThis } from "../types.js";
|
|
4
|
-
import { SerdeGateway, SerdeGatewayInterceptor } from "./serde-gateway.js";
|
|
5
|
-
import { CommitQueue } from "./commit-queue.js";
|
|
6
|
-
import { InterceptorGateway } from "./interceptor-gateway.js";
|
|
7
|
-
export interface StoreOpts {
|
|
8
|
-
readonly gateway: SerdeGateway;
|
|
9
|
-
readonly gatewayInterceptor?: SerdeGatewayInterceptor;
|
|
10
|
-
readonly loader: Loadable;
|
|
11
|
-
}
|
|
12
|
-
export interface BaseStoreOpts {
|
|
13
|
-
readonly gateway: InterceptorGateway;
|
|
14
|
-
readonly loader: Loadable;
|
|
15
|
-
}
|
|
16
|
-
export declare abstract class BaseStoreImpl {
|
|
17
|
-
abstract readonly storeType: StoreType;
|
|
18
|
-
private _url;
|
|
19
|
-
readonly logger: Logger;
|
|
20
|
-
readonly sthis: SuperThis;
|
|
21
|
-
readonly gateway: InterceptorGateway;
|
|
22
|
-
get realGateway(): SerdeGateway;
|
|
23
|
-
readonly opts: StoreOpts;
|
|
24
|
-
readonly loader: Loadable;
|
|
25
|
-
constructor(sthis: SuperThis, url: URI, opts: BaseStoreOpts, logger: Logger);
|
|
26
|
-
url(): URI;
|
|
27
|
-
readonly _onStarted: ((dam: DataAndMetaStore) => void)[];
|
|
28
|
-
onStarted(fn: (dam: DataAndMetaStore) => void): void;
|
|
29
|
-
readonly _onClosed: (() => void)[];
|
|
30
|
-
onClosed(fn: () => void): void;
|
|
31
|
-
abstract close(): Promise<Result<void>>;
|
|
32
|
-
ready(): Promise<void>;
|
|
33
|
-
keyedCrypto(): Promise<CryptoAction>;
|
|
34
|
-
start(dam: DataAndMetaStore): Promise<Result<URI>>;
|
|
35
|
-
}
|
|
36
|
-
export declare function createDbMetaEvent(sthis: SuperThis, dbMeta: DbMeta, parents: CarClockHead): Promise<DbMetaEvent>;
|
|
37
|
-
export declare class MetaStoreImpl extends BaseStoreImpl implements MetaStore {
|
|
38
|
-
readonly storeType = "meta";
|
|
39
|
-
readonly subscribers: Map<string, LoadHandler[]>;
|
|
40
|
-
parents: CarClockHead;
|
|
41
|
-
constructor(sthis: SuperThis, url: URI, opts: BaseStoreOpts);
|
|
42
|
-
private updateParentsFromDbMetas;
|
|
43
|
-
load(branch?: string): Promise<DbMeta[] | Falsy>;
|
|
44
|
-
save(meta: DbMeta, branch?: string): Promise<Result<void>>;
|
|
45
|
-
close(): Promise<Result<void>>;
|
|
46
|
-
destroy(): Promise<Result<void>>;
|
|
47
|
-
}
|
|
48
|
-
declare abstract class DataStoreImpl extends BaseStoreImpl {
|
|
49
|
-
constructor(sthis: SuperThis, url: URI, opts: BaseStoreOpts, logger: Logger);
|
|
50
|
-
load(cid: AnyLink): Promise<AnyBlock>;
|
|
51
|
-
save(car: AnyBlock, opts?: DataSaveOpts): Promise<void>;
|
|
52
|
-
remove(cid: AnyLink): Promise<Result<void>>;
|
|
53
|
-
close(): Promise<Result<void>>;
|
|
54
|
-
destroy(): Promise<Result<void>>;
|
|
55
|
-
}
|
|
56
|
-
export declare class CarStoreImpl extends DataStoreImpl implements CarStore {
|
|
57
|
-
readonly storeType = "car";
|
|
58
|
-
constructor(sthis: SuperThis, url: URI, opts: BaseStoreOpts);
|
|
59
|
-
}
|
|
60
|
-
export declare class FileStoreImpl extends DataStoreImpl implements FileStore {
|
|
61
|
-
readonly storeType = "file";
|
|
62
|
-
constructor(sthis: SuperThis, url: URI, opts: BaseStoreOpts);
|
|
63
|
-
}
|
|
64
|
-
export declare class WALStoreImpl extends BaseStoreImpl implements WALStore {
|
|
65
|
-
readonly storeType = "wal";
|
|
66
|
-
readonly _ready: ResolveOnce<void, void>;
|
|
67
|
-
readonly walState: WALState;
|
|
68
|
-
readonly processing: Promise<void> | undefined;
|
|
69
|
-
readonly processQueue: CommitQueue<void>;
|
|
70
|
-
constructor(sthis: SuperThis, url: URI, opts: BaseStoreOpts);
|
|
71
|
-
ready(): Promise<void>;
|
|
72
|
-
enqueue(dbMeta: DbMeta, opts: CommitOpts): Promise<void>;
|
|
73
|
-
enqueueFile(fileCid: AnyLink, publicFile?: boolean): Promise<void>;
|
|
74
|
-
process(): Promise<void>;
|
|
75
|
-
_doProcess(): Promise<void>;
|
|
76
|
-
load(): Promise<WALState | Falsy>;
|
|
77
|
-
save(state: WALState): Promise<void>;
|
|
78
|
-
close(): Promise<Result<undefined, Error>>;
|
|
79
|
-
destroy(): Promise<Result<void, Error>>;
|
|
80
|
-
}
|
|
81
|
-
export {};
|
|
82
|
-
//# sourceMappingURL=store.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../../src/blockstore/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE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IAOrD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAetB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU;IAiBxC,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,UAAQ;IAMhD,OAAO;IAeP,UAAU;IA0HV,IAAI,IAAI,OAAO,CAAC,QAAQ,GAAG,KAAK,CAAC;IAmBjC,IAAI,CAAC,KAAK,EAAE,QAAQ;IAoBpB,KAAK;IAMX,OAAO;CAIR"}
|
package/blockstore/store.js
DELETED
|
@@ -1,438 +0,0 @@
|
|
|
1
|
-
import { exception2Result, ResolveOnce, Result } from "@adviser/cement";
|
|
2
|
-
import { PARAM } from "../types.js";
|
|
3
|
-
import { ensureLogger, inplaceFilter, isNotFoundError } from "../utils.js";
|
|
4
|
-
import { carLogIncludesGroup } from "./loader.js";
|
|
5
|
-
import { CommitQueue } from "./commit-queue.js";
|
|
6
|
-
import { keyedCryptoFactory } from "../runtime/keyed-crypto.js";
|
|
7
|
-
import { Car2FPMsg, File2FPMsg } from "./fp-envelope.js";
|
|
8
|
-
import { EventBlock } from "@fireproof/vendor/@web3-storage/pail/clock";
|
|
9
|
-
import { format } from "@ipld/dag-json";
|
|
10
|
-
import pRetry from "p-retry";
|
|
11
|
-
import pMap from "p-map";
|
|
12
|
-
function guardVersion(url) {
|
|
13
|
-
if (!url.hasParam("version")) {
|
|
14
|
-
return Result.Err(`missing version: ${url.toString()}`);
|
|
15
|
-
}
|
|
16
|
-
return Result.Ok(url);
|
|
17
|
-
}
|
|
18
|
-
export class BaseStoreImpl {
|
|
19
|
-
get realGateway() {
|
|
20
|
-
return this.gateway.innerGW;
|
|
21
|
-
}
|
|
22
|
-
constructor(sthis, url, opts, logger) {
|
|
23
|
-
this._onStarted = [];
|
|
24
|
-
this._onClosed = [];
|
|
25
|
-
this._url = url;
|
|
26
|
-
this.opts = opts;
|
|
27
|
-
this.loader = opts.loader;
|
|
28
|
-
this.sthis = sthis;
|
|
29
|
-
const name = this._url.getParam(PARAM.NAME);
|
|
30
|
-
if (!name) {
|
|
31
|
-
throw logger.Error().Url(this._url).Msg("missing name").AsError();
|
|
32
|
-
}
|
|
33
|
-
this.logger = logger
|
|
34
|
-
.With()
|
|
35
|
-
.Str("this", this.sthis.nextId().str)
|
|
36
|
-
.Ref("url", () => this._url.toString())
|
|
37
|
-
.Logger();
|
|
38
|
-
this.gateway = opts.gateway;
|
|
39
|
-
}
|
|
40
|
-
url() {
|
|
41
|
-
return this._url;
|
|
42
|
-
}
|
|
43
|
-
onStarted(fn) {
|
|
44
|
-
this._onStarted.push(fn);
|
|
45
|
-
}
|
|
46
|
-
onClosed(fn) {
|
|
47
|
-
this._onClosed.push(fn);
|
|
48
|
-
}
|
|
49
|
-
async ready() {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
async keyedCrypto() {
|
|
53
|
-
return keyedCryptoFactory(this._url, await this.loader.keyBag(), this.sthis);
|
|
54
|
-
}
|
|
55
|
-
async start(dam) {
|
|
56
|
-
this.logger.Debug().Str("storeType", this.storeType).Msg("starting-gateway-pre");
|
|
57
|
-
this._url = this._url.build().setParam(PARAM.STORE, this.storeType).URI();
|
|
58
|
-
const res = await this.gateway.start({ loader: this.loader }, this._url);
|
|
59
|
-
if (res.isErr()) {
|
|
60
|
-
this.logger.Error().Result("gw-start", res).Msg("started-gateway");
|
|
61
|
-
return res;
|
|
62
|
-
}
|
|
63
|
-
this._url = res.Ok();
|
|
64
|
-
const kb = await this.loader.keyBag();
|
|
65
|
-
const skRes = await kb.ensureKeyFromUrl(this._url, () => {
|
|
66
|
-
const key = this._url.getParam(PARAM.KEY);
|
|
67
|
-
return key;
|
|
68
|
-
});
|
|
69
|
-
if (skRes.isErr()) {
|
|
70
|
-
return skRes;
|
|
71
|
-
}
|
|
72
|
-
this._url = skRes.Ok();
|
|
73
|
-
const version = guardVersion(this._url);
|
|
74
|
-
if (version.isErr()) {
|
|
75
|
-
this.logger.Error().Result("version", version).Msg("guardVersion");
|
|
76
|
-
await this.close();
|
|
77
|
-
return version;
|
|
78
|
-
}
|
|
79
|
-
if (this.ready) {
|
|
80
|
-
const fn = this.ready.bind(this);
|
|
81
|
-
const ready = await exception2Result(fn);
|
|
82
|
-
if (ready.isErr()) {
|
|
83
|
-
await this.close();
|
|
84
|
-
return ready;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
this._onStarted.forEach((fn) => fn(dam));
|
|
88
|
-
this.logger.Debug().Msg("started");
|
|
89
|
-
return version;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
export async function createDbMetaEvent(sthis, dbMeta, parents) {
|
|
93
|
-
const event = await EventBlock.create({
|
|
94
|
-
dbMeta: sthis.txt.encode(format(dbMeta)),
|
|
95
|
-
}, parents);
|
|
96
|
-
return {
|
|
97
|
-
eventCid: event.cid,
|
|
98
|
-
dbMeta,
|
|
99
|
-
parents,
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
export class MetaStoreImpl extends BaseStoreImpl {
|
|
103
|
-
constructor(sthis, url, opts) {
|
|
104
|
-
super(sthis, url, { ...opts }, ensureLogger(sthis, "MetaStoreImpl"));
|
|
105
|
-
this.storeType = "meta";
|
|
106
|
-
this.subscribers = new Map();
|
|
107
|
-
this.parents = [];
|
|
108
|
-
if (opts.gateway.subscribe) {
|
|
109
|
-
this.onStarted(async (dam) => {
|
|
110
|
-
this.logger.Debug().Str("url", this.url().toString()).Msg("Subscribing to the gateway");
|
|
111
|
-
opts.gateway.subscribe({ loader: this.loader }, this.url(), async ({ payload: dbMetas }) => {
|
|
112
|
-
this.logger.Debug().Msg("Received message from gateway");
|
|
113
|
-
await Promise.all(dbMetas.map((dbMetaEv) => this.loader.taskManager?.handleEvent(dbMetaEv.eventCid, dbMetaEv.parents, dbMetaEv.dbMeta, this.loader.attachedStores.activate(dam))));
|
|
114
|
-
this.updateParentsFromDbMetas(dbMetas);
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
updateParentsFromDbMetas(dbMetas) {
|
|
120
|
-
const cids = dbMetas.map((m) => m.eventCid);
|
|
121
|
-
const dbMetaParents = dbMetas.flatMap((m) => m.parents);
|
|
122
|
-
const uniqueParentsMap = new Map([...this.parents, ...cids].map((p) => [p.toString(), p]));
|
|
123
|
-
const dbMetaParentsSet = new Set(dbMetaParents.map((p) => p.toString()));
|
|
124
|
-
this.parents = Array.from(uniqueParentsMap.values()).filter((p) => !dbMetaParentsSet.has(p.toString()));
|
|
125
|
-
}
|
|
126
|
-
async load(branch = "main") {
|
|
127
|
-
const url = await this.gateway.buildUrl({ loader: this.loader }, this.url(), branch);
|
|
128
|
-
if (url.isErr()) {
|
|
129
|
-
throw this.logger.Error().Result("buildUrl", url).Str("branch", branch).Msg("got error from gateway.buildUrl").AsError();
|
|
130
|
-
}
|
|
131
|
-
const rfpEnv = await this.gateway.get({ loader: this.loader }, url.Ok());
|
|
132
|
-
if (rfpEnv.isErr()) {
|
|
133
|
-
if (isNotFoundError(rfpEnv)) {
|
|
134
|
-
return undefined;
|
|
135
|
-
}
|
|
136
|
-
throw this.logger.Error().Url(url.Ok()).Err(rfpEnv).Msg("gateway get").AsError();
|
|
137
|
-
}
|
|
138
|
-
const fpMeta = rfpEnv.Ok().payload;
|
|
139
|
-
const dbMetas = fpMeta.map((m) => m.dbMeta);
|
|
140
|
-
await this.loader.handleDbMetasFromStore(dbMetas, this.loader.attachedStores.activate(url.Ok()));
|
|
141
|
-
this.updateParentsFromDbMetas(fpMeta);
|
|
142
|
-
return dbMetas;
|
|
143
|
-
}
|
|
144
|
-
async save(meta, branch) {
|
|
145
|
-
branch = branch || "main";
|
|
146
|
-
this.logger.Debug().Str("branch", branch).Any("meta", meta).Msg("saving meta");
|
|
147
|
-
const url = await this.gateway.buildUrl({ loader: this.loader }, this.url(), branch);
|
|
148
|
-
if (url.isErr()) {
|
|
149
|
-
throw this.logger.Error().Err(url.Err()).Str("branch", branch).Msg("got error from gateway.buildUrl").AsError();
|
|
150
|
-
}
|
|
151
|
-
const dbMetaEvent = await createDbMetaEvent(this.sthis, meta, this.parents);
|
|
152
|
-
const res = await this.gateway.put({ loader: this.loader }, url.Ok(), {
|
|
153
|
-
type: "meta",
|
|
154
|
-
payload: [dbMetaEvent],
|
|
155
|
-
});
|
|
156
|
-
if (res.isErr()) {
|
|
157
|
-
throw this.logger.Error().Err(res.Err()).Msg("got error from gateway.put").AsError();
|
|
158
|
-
}
|
|
159
|
-
return res;
|
|
160
|
-
}
|
|
161
|
-
async close() {
|
|
162
|
-
await this.gateway.close({ loader: this.loader }, this.url());
|
|
163
|
-
this._onClosed.forEach((fn) => fn());
|
|
164
|
-
return Result.Ok(undefined);
|
|
165
|
-
}
|
|
166
|
-
async destroy() {
|
|
167
|
-
this.logger.Debug().Msg("destroy");
|
|
168
|
-
return this.gateway.destroy({ loader: this.loader }, this.url());
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
class DataStoreImpl extends BaseStoreImpl {
|
|
172
|
-
constructor(sthis, url, opts, logger) {
|
|
173
|
-
super(sthis, url, { ...opts }, logger);
|
|
174
|
-
}
|
|
175
|
-
async load(cid) {
|
|
176
|
-
this.logger.Debug().Any("cid", cid).Msg("loading");
|
|
177
|
-
const url = await this.gateway.buildUrl({ loader: this.loader }, this.url(), cid.toString());
|
|
178
|
-
if (url.isErr()) {
|
|
179
|
-
throw this.logger.Error().Err(url.Err()).Str("cid", cid.toString()).Msg("got error from gateway.buildUrl").AsError();
|
|
180
|
-
}
|
|
181
|
-
const res = await this.gateway.get({ loader: this.loader }, url.Ok());
|
|
182
|
-
if (res.isErr()) {
|
|
183
|
-
throw res.Err();
|
|
184
|
-
}
|
|
185
|
-
const fpenv = res.Ok();
|
|
186
|
-
switch (fpenv.type) {
|
|
187
|
-
case "car":
|
|
188
|
-
case "file":
|
|
189
|
-
return { cid, bytes: fpenv.payload };
|
|
190
|
-
default:
|
|
191
|
-
throw this.logger.Error().Msg("unexpected type").AsError();
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
async save(car, opts) {
|
|
195
|
-
this.logger.Debug().Any("cid", car.cid.toString()).Msg("saving");
|
|
196
|
-
const url = await this.gateway.buildUrl({ loader: this.loader }, this.url(), car.cid.toString());
|
|
197
|
-
if (url.isErr()) {
|
|
198
|
-
throw this.logger.Error().Err(url.Err()).Ref("cid", car.cid).Msg("got error from gateway.buildUrl").AsError();
|
|
199
|
-
}
|
|
200
|
-
let fpMsg;
|
|
201
|
-
switch (url.Ok().getParam(PARAM.STORE)) {
|
|
202
|
-
case "car":
|
|
203
|
-
fpMsg = Car2FPMsg(car.bytes);
|
|
204
|
-
break;
|
|
205
|
-
case "file":
|
|
206
|
-
fpMsg = File2FPMsg(car.bytes);
|
|
207
|
-
break;
|
|
208
|
-
default:
|
|
209
|
-
throw this.logger.Error().Str("store", url.Ok().getParam(PARAM.STORE)).Msg("unexpected store").AsError();
|
|
210
|
-
}
|
|
211
|
-
if (fpMsg.isErr()) {
|
|
212
|
-
throw this.logger.Error().Err(fpMsg).Msg("got error from FPMsg2Car").AsError();
|
|
213
|
-
}
|
|
214
|
-
const res = await this.gateway.put({ loader: this.loader }, url.Ok(), fpMsg.Ok());
|
|
215
|
-
if (res.isErr()) {
|
|
216
|
-
throw this.logger.Error().Err(res.Err()).Msg("got error from gateway.put").AsError();
|
|
217
|
-
}
|
|
218
|
-
return res.Ok();
|
|
219
|
-
}
|
|
220
|
-
async remove(cid) {
|
|
221
|
-
const url = await this.gateway.buildUrl({ loader: this.loader }, this.url(), cid.toString());
|
|
222
|
-
if (url.isErr()) {
|
|
223
|
-
return url;
|
|
224
|
-
}
|
|
225
|
-
return this.gateway.delete({ loader: this.loader }, url.Ok());
|
|
226
|
-
}
|
|
227
|
-
async close() {
|
|
228
|
-
await this.gateway.close({ loader: this.loader }, this.url());
|
|
229
|
-
this._onClosed.forEach((fn) => fn());
|
|
230
|
-
return Result.Ok(undefined);
|
|
231
|
-
}
|
|
232
|
-
destroy() {
|
|
233
|
-
this.logger.Debug().Msg("destroy");
|
|
234
|
-
return this.gateway.destroy({ loader: this.loader }, this.url());
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
export class CarStoreImpl extends DataStoreImpl {
|
|
238
|
-
constructor(sthis, url, opts) {
|
|
239
|
-
super(sthis, url, { ...opts }, ensureLogger(sthis, "CarStoreImpl"));
|
|
240
|
-
this.storeType = "car";
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
export class FileStoreImpl extends DataStoreImpl {
|
|
244
|
-
constructor(sthis, url, opts) {
|
|
245
|
-
super(sthis, url, { ...opts }, ensureLogger(sthis, "FileStoreImpl"));
|
|
246
|
-
this.storeType = "file";
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
export class WALStoreImpl extends BaseStoreImpl {
|
|
250
|
-
constructor(sthis, url, opts) {
|
|
251
|
-
super(sthis, url, { ...opts }, ensureLogger(sthis, "WALStoreImpl"));
|
|
252
|
-
this.storeType = "wal";
|
|
253
|
-
this._ready = new ResolveOnce();
|
|
254
|
-
this.walState = { operations: [], noLoaderOps: [], fileOperations: [] };
|
|
255
|
-
this.processing = undefined;
|
|
256
|
-
this.processQueue = new CommitQueue();
|
|
257
|
-
}
|
|
258
|
-
async ready() {
|
|
259
|
-
return this._ready.once(async () => {
|
|
260
|
-
const walState = await this.load().catch((e) => {
|
|
261
|
-
this.logger.Error().Err(e).Msg("error loading wal");
|
|
262
|
-
return undefined;
|
|
263
|
-
});
|
|
264
|
-
this.walState.operations.splice(0, this.walState.operations.length);
|
|
265
|
-
this.walState.fileOperations.splice(0, this.walState.fileOperations.length);
|
|
266
|
-
if (walState) {
|
|
267
|
-
this.walState.operations.push(...walState.operations);
|
|
268
|
-
this.walState.fileOperations.push(...walState.fileOperations);
|
|
269
|
-
}
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
async enqueue(dbMeta, opts) {
|
|
273
|
-
await this.ready();
|
|
274
|
-
if (opts.compact) {
|
|
275
|
-
this.walState.operations.splice(0, this.walState.operations.length);
|
|
276
|
-
this.walState.noLoaderOps.splice(0, this.walState.noLoaderOps.length);
|
|
277
|
-
this.walState.noLoaderOps.push(dbMeta);
|
|
278
|
-
}
|
|
279
|
-
else if (opts.noLoader) {
|
|
280
|
-
this.walState.noLoaderOps.push(dbMeta);
|
|
281
|
-
}
|
|
282
|
-
else {
|
|
283
|
-
this.walState.operations.push(dbMeta);
|
|
284
|
-
}
|
|
285
|
-
await this.save(this.walState);
|
|
286
|
-
if (!opts.noLoader) {
|
|
287
|
-
void this.process();
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
async enqueueFile(fileCid, publicFile = false) {
|
|
291
|
-
await this.ready();
|
|
292
|
-
this.walState.fileOperations.push({ cid: fileCid, public: publicFile });
|
|
293
|
-
}
|
|
294
|
-
async process() {
|
|
295
|
-
await this.ready();
|
|
296
|
-
await this.processQueue.enqueue(async () => {
|
|
297
|
-
try {
|
|
298
|
-
await this._doProcess();
|
|
299
|
-
}
|
|
300
|
-
catch (e) {
|
|
301
|
-
this.logger.Error().Any("error", e).Msg("error processing wal");
|
|
302
|
-
}
|
|
303
|
-
if (this.walState.operations.length || this.walState.fileOperations.length || this.walState.noLoaderOps.length) {
|
|
304
|
-
setTimeout(() => void this.process(), 0);
|
|
305
|
-
}
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
async _doProcess() {
|
|
309
|
-
if (!this.loader)
|
|
310
|
-
return;
|
|
311
|
-
const operations = [...this.walState.operations];
|
|
312
|
-
const noLoaderOps = [...this.walState.noLoaderOps];
|
|
313
|
-
const fileOperations = [...this.walState.fileOperations];
|
|
314
|
-
if (operations.length + noLoaderOps.length + fileOperations.length === 0)
|
|
315
|
-
return;
|
|
316
|
-
const concurrencyLimit = 3;
|
|
317
|
-
const retryableUpload = (fn, description) => pRetry(fn, {
|
|
318
|
-
retries: 5,
|
|
319
|
-
onFailedAttempt: (error) => {
|
|
320
|
-
this.logger
|
|
321
|
-
.Warn()
|
|
322
|
-
.Any("error", error)
|
|
323
|
-
.Any("fn", fn.toString())
|
|
324
|
-
.Msg(`Attempt ${error.attemptNumber} failed for ${description}. There are ${error.retriesLeft} retries left.`);
|
|
325
|
-
},
|
|
326
|
-
});
|
|
327
|
-
try {
|
|
328
|
-
await pMap(noLoaderOps, async (dbMeta) => {
|
|
329
|
-
await retryableUpload(async () => {
|
|
330
|
-
if (!this.loader) {
|
|
331
|
-
return;
|
|
332
|
-
}
|
|
333
|
-
for (const cid of dbMeta.cars) {
|
|
334
|
-
const car = await this.loader.attachedStores.local().active.car.load(cid);
|
|
335
|
-
if (!car) {
|
|
336
|
-
if (carLogIncludesGroup(this.loader.carLog.asArray(), dbMeta.cars)) {
|
|
337
|
-
throw this.logger.Error().Ref("cid", cid).Msg("missing local car").AsError();
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
else {
|
|
341
|
-
await this.loader.attachedStores.forRemotes((x) => x.active.car.save(car));
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
inplaceFilter(this.walState.noLoaderOps, (op) => op !== dbMeta);
|
|
345
|
-
}, `noLoaderOp with dbMeta.cars=${dbMeta.cars.toString()}`);
|
|
346
|
-
}, { concurrency: concurrencyLimit });
|
|
347
|
-
await pMap(operations, async (dbMeta) => {
|
|
348
|
-
await retryableUpload(async () => {
|
|
349
|
-
if (!this.loader) {
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
for (const cid of dbMeta.cars) {
|
|
353
|
-
const car = await this.loader.attachedStores.local().active.car.load(cid);
|
|
354
|
-
if (!car) {
|
|
355
|
-
if (carLogIncludesGroup(this.loader.carLog.asArray(), dbMeta.cars)) {
|
|
356
|
-
throw this.logger.Error().Ref("cid", cid).Msg(`missing local car`).AsError();
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
else {
|
|
360
|
-
await this.loader.attachedStores.forRemotes((x) => x.active.car.save(car));
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
inplaceFilter(this.walState.operations, (op) => op !== dbMeta);
|
|
364
|
-
}, `operation with dbMeta.cars=${dbMeta.cars.toString()}`);
|
|
365
|
-
}, { concurrency: concurrencyLimit });
|
|
366
|
-
await pMap(fileOperations, async ({ cid: fileCid, public: publicFile }) => {
|
|
367
|
-
await retryableUpload(async () => {
|
|
368
|
-
if (!this.loader) {
|
|
369
|
-
return;
|
|
370
|
-
}
|
|
371
|
-
const fileBlock = await this.loader.attachedStores.local().active.file.load(fileCid);
|
|
372
|
-
if (!fileBlock) {
|
|
373
|
-
throw this.logger.Error().Ref("cid", fileCid).Msg("missing file block").AsError();
|
|
374
|
-
}
|
|
375
|
-
await this.loader.attachedStores.forRemotes((x) => x.active.file.save(fileBlock, { public: publicFile }));
|
|
376
|
-
inplaceFilter(this.walState.fileOperations, (op) => op.cid !== fileCid);
|
|
377
|
-
}, `fileOperation with cid=${fileCid.toString()}`);
|
|
378
|
-
}, { concurrency: concurrencyLimit });
|
|
379
|
-
if (operations.length) {
|
|
380
|
-
const lastOp = operations[operations.length - 1];
|
|
381
|
-
await retryableUpload(async () => {
|
|
382
|
-
if (!this.loader) {
|
|
383
|
-
return;
|
|
384
|
-
}
|
|
385
|
-
await this.loader.attachedStores.forRemotes((x) => x.active.meta.save(lastOp));
|
|
386
|
-
}, `remoteMetaStore save with dbMeta.cars=${lastOp.cars.toString()}`);
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
catch (error) {
|
|
390
|
-
this.logger.Error().Any("error", error).Msg("Processing failed");
|
|
391
|
-
return;
|
|
392
|
-
}
|
|
393
|
-
finally {
|
|
394
|
-
await this.save(this.walState);
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
async load() {
|
|
398
|
-
this.logger.Debug().Msg("loading");
|
|
399
|
-
const filepath = await this.gateway.buildUrl({ loader: this.loader }, this.url(), "main");
|
|
400
|
-
if (filepath.isErr()) {
|
|
401
|
-
throw this.logger.Error().Err(filepath.Err()).Url(this.url()).Msg("error building url").AsError();
|
|
402
|
-
}
|
|
403
|
-
const bytes = (await this.gateway.get({ loader: this.loader }, filepath.Ok()));
|
|
404
|
-
if (bytes.isErr()) {
|
|
405
|
-
if (isNotFoundError(bytes)) {
|
|
406
|
-
return undefined;
|
|
407
|
-
}
|
|
408
|
-
throw this.logger.Error().Err(bytes.Err()).Msg("error get").AsError();
|
|
409
|
-
}
|
|
410
|
-
if (bytes.Ok().type !== "wal") {
|
|
411
|
-
throw this.logger.Error().Str("type", bytes.Ok().type).Msg("unexpected type").AsError();
|
|
412
|
-
}
|
|
413
|
-
return bytes.Ok().payload;
|
|
414
|
-
}
|
|
415
|
-
async save(state) {
|
|
416
|
-
const filepath = await this.gateway.buildUrl({ loader: this.loader }, this.url(), "main");
|
|
417
|
-
if (filepath.isErr()) {
|
|
418
|
-
throw this.logger.Error().Err(filepath.Err()).Url(this.url()).Msg("error building url").AsError();
|
|
419
|
-
}
|
|
420
|
-
const res = await this.gateway.put({ loader: this.loader }, filepath.Ok(), {
|
|
421
|
-
type: "wal",
|
|
422
|
-
payload: state,
|
|
423
|
-
});
|
|
424
|
-
if (res.isErr()) {
|
|
425
|
-
throw this.logger.Error().Err(res.Err()).Str("filePath", filepath.Ok().toString()).Msg("error saving").AsError();
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
async close() {
|
|
429
|
-
await this.gateway.close({ loader: this.loader }, this.url());
|
|
430
|
-
this._onClosed.forEach((fn) => fn());
|
|
431
|
-
return Result.Ok(undefined);
|
|
432
|
-
}
|
|
433
|
-
destroy() {
|
|
434
|
-
this.logger.Debug().Msg("destroy");
|
|
435
|
-
return this.gateway.destroy({ loader: this.loader }, this.url());
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
//# sourceMappingURL=store.js.map
|