@opendatalabs/personal-server-ts-core 1.37.0 → 1.38.1
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/contracts/host-contract.json +115 -0
- package/contracts/raw-end.json +2360 -0
- package/contracts/replace-conformance.json +729 -0
- package/contracts/routes.json +349 -0
- package/contracts/run-finish-plan.json +3238 -0
- package/contracts/run-saved.json +1308 -0
- package/contracts/scope-delete-receipt.json +616 -0
- package/dist/api/account-storage-mode.d.ts +77 -0
- package/dist/api/account-storage-mode.d.ts.map +1 -0
- package/dist/api/account-storage-mode.js +72 -0
- package/dist/api/account-storage-mode.js.map +1 -0
- package/dist/api/index.d.ts +139 -3
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +973 -191
- package/dist/api/index.js.map +1 -1
- package/dist/api/legacy-write-gate.d.ts +51 -0
- package/dist/api/legacy-write-gate.d.ts.map +1 -0
- package/dist/api/legacy-write-gate.js +88 -0
- package/dist/api/legacy-write-gate.js.map +1 -0
- package/dist/api/owner-connector-delete.d.ts +103 -0
- package/dist/api/owner-connector-delete.d.ts.map +1 -0
- package/dist/api/owner-connector-delete.js +158 -0
- package/dist/api/owner-connector-delete.js.map +1 -0
- package/dist/api/pdpp-record-query.d.ts +25 -0
- package/dist/api/pdpp-record-query.d.ts.map +1 -0
- package/dist/api/pdpp-record-query.js +72 -0
- package/dist/api/pdpp-record-query.js.map +1 -0
- package/dist/api/pdpp-records-list.d.ts +133 -0
- package/dist/api/pdpp-records-list.d.ts.map +1 -0
- package/dist/api/pdpp-records-list.js +380 -0
- package/dist/api/pdpp-records-list.js.map +1 -0
- package/dist/api/scope-delete-verdict.d.ts +107 -0
- package/dist/api/scope-delete-verdict.d.ts.map +1 -0
- package/dist/api/scope-delete-verdict.js +92 -0
- package/dist/api/scope-delete-verdict.js.map +1 -0
- package/dist/api/switched-delete-refusal.d.ts +16 -0
- package/dist/api/switched-delete-refusal.d.ts.map +1 -0
- package/dist/api/switched-delete-refusal.js +30 -0
- package/dist/api/switched-delete-refusal.js.map +1 -0
- package/dist/client.d.ts +29 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +34 -2
- package/dist/client.js.map +1 -1
- package/dist/contracts/access-logs.d.ts +1 -0
- package/dist/contracts/access-logs.d.ts.map +1 -1
- package/dist/contracts/access-logs.js +7 -1
- package/dist/contracts/access-logs.js.map +1 -1
- package/dist/contracts/data.d.ts +12 -0
- package/dist/contracts/data.d.ts.map +1 -1
- package/dist/contracts/data.js +30 -1
- package/dist/contracts/data.js.map +1 -1
- package/dist/contracts/grants.d.ts.map +1 -1
- package/dist/contracts/grants.js +9 -0
- package/dist/contracts/grants.js.map +1 -1
- package/dist/contracts/index.d.ts +1 -1
- package/dist/contracts/index.d.ts.map +1 -1
- package/dist/contracts/index.js +1 -1
- package/dist/contracts/index.js.map +1 -1
- package/dist/contracts/sync.d.ts +9 -1
- package/dist/contracts/sync.d.ts.map +1 -1
- package/dist/contracts/sync.js +6 -2
- package/dist/contracts/sync.js.map +1 -1
- package/dist/derivatives/compute.d.ts.map +1 -1
- package/dist/derivatives/compute.js +19 -0
- package/dist/derivatives/compute.js.map +1 -1
- package/dist/encoding/base64url.d.ts +6 -0
- package/dist/encoding/base64url.d.ts.map +1 -0
- package/dist/encoding/base64url.js +29 -0
- package/dist/encoding/base64url.js.map +1 -0
- package/dist/errors/pdpp-catalog.d.ts +1 -1
- package/dist/errors/pdpp-catalog.d.ts.map +1 -1
- package/dist/errors/pdpp-catalog.js +6 -0
- package/dist/errors/pdpp-catalog.js.map +1 -1
- package/dist/keys/index.d.ts +1 -0
- package/dist/keys/index.d.ts.map +1 -1
- package/dist/keys/index.js +1 -0
- package/dist/keys/index.js.map +1 -1
- package/dist/keys/owner-master-key.d.ts +37 -0
- package/dist/keys/owner-master-key.d.ts.map +1 -0
- package/dist/keys/owner-master-key.js +45 -0
- package/dist/keys/owner-master-key.js.map +1 -0
- package/dist/legacy-projection/bindings.d.ts.map +1 -1
- package/dist/legacy-projection/bindings.js +10 -4
- package/dist/legacy-projection/bindings.js.map +1 -1
- package/dist/legacy-projection/erase-connector.d.ts +18 -0
- package/dist/legacy-projection/erase-connector.d.ts.map +1 -0
- package/dist/legacy-projection/erase-connector.js +29 -0
- package/dist/legacy-projection/erase-connector.js.map +1 -0
- package/dist/legacy-projection/index.d.ts +17 -0
- package/dist/legacy-projection/index.d.ts.map +1 -1
- package/dist/legacy-projection/index.js +41 -0
- package/dist/legacy-projection/index.js.map +1 -1
- package/dist/legacy-projection/types.d.ts +12 -2
- package/dist/legacy-projection/types.d.ts.map +1 -1
- package/dist/lineage/gateway.d.ts +3 -1
- package/dist/lineage/gateway.d.ts.map +1 -1
- package/dist/lineage/gateway.js +2 -1
- package/dist/lineage/gateway.js.map +1 -1
- package/dist/localdb/admit.d.ts +138 -0
- package/dist/localdb/admit.d.ts.map +1 -0
- package/dist/localdb/admit.js +344 -0
- package/dist/localdb/admit.js.map +1 -0
- package/dist/localdb/apply-meter.d.ts +14 -0
- package/dist/localdb/apply-meter.d.ts.map +1 -0
- package/dist/localdb/apply-meter.js +31 -0
- package/dist/localdb/apply-meter.js.map +1 -0
- package/dist/localdb/apply-progress.d.ts +10 -0
- package/dist/localdb/apply-progress.d.ts.map +1 -0
- package/dist/localdb/apply-progress.js +39 -0
- package/dist/localdb/apply-progress.js.map +1 -0
- package/dist/localdb/apply.d.ts +17 -0
- package/dist/localdb/apply.d.ts.map +1 -0
- package/dist/localdb/apply.js +291 -0
- package/dist/localdb/apply.js.map +1 -0
- package/dist/localdb/batch-commit.d.ts +70 -0
- package/dist/localdb/batch-commit.d.ts.map +1 -0
- package/dist/localdb/batch-commit.js +91 -0
- package/dist/localdb/batch-commit.js.map +1 -0
- package/dist/localdb/batch-contract.d.ts +19 -0
- package/dist/localdb/batch-contract.d.ts.map +1 -0
- package/dist/localdb/batch-contract.js +24 -0
- package/dist/localdb/batch-contract.js.map +1 -0
- package/dist/localdb/blobs.d.ts +71 -0
- package/dist/localdb/blobs.d.ts.map +1 -0
- package/dist/localdb/blobs.js +306 -0
- package/dist/localdb/blobs.js.map +1 -0
- package/dist/localdb/bootstrap-copy.d.ts +6 -0
- package/dist/localdb/bootstrap-copy.d.ts.map +1 -0
- package/dist/localdb/bootstrap-copy.js +79 -0
- package/dist/localdb/bootstrap-copy.js.map +1 -0
- package/dist/localdb/bootstrap-keys.d.ts +33 -0
- package/dist/localdb/bootstrap-keys.d.ts.map +1 -0
- package/dist/localdb/bootstrap-keys.js +89 -0
- package/dist/localdb/bootstrap-keys.js.map +1 -0
- package/dist/localdb/bootstrap-swap.d.ts +17 -0
- package/dist/localdb/bootstrap-swap.d.ts.map +1 -0
- package/dist/localdb/bootstrap-swap.js +78 -0
- package/dist/localdb/bootstrap-swap.js.map +1 -0
- package/dist/localdb/bootstrap.d.ts +55 -0
- package/dist/localdb/bootstrap.d.ts.map +1 -0
- package/dist/localdb/bootstrap.js +195 -0
- package/dist/localdb/bootstrap.js.map +1 -0
- package/dist/localdb/complete-read.d.ts +77 -0
- package/dist/localdb/complete-read.d.ts.map +1 -0
- package/dist/localdb/complete-read.js +136 -0
- package/dist/localdb/complete-read.js.map +1 -0
- package/dist/localdb/connection-link.d.ts +12 -0
- package/dist/localdb/connection-link.d.ts.map +1 -0
- package/dist/localdb/connection-link.js +79 -0
- package/dist/localdb/connection-link.js.map +1 -0
- package/dist/localdb/cursor.d.ts +61 -0
- package/dist/localdb/cursor.d.ts.map +1 -0
- package/dist/localdb/cursor.js +178 -0
- package/dist/localdb/cursor.js.map +1 -0
- package/dist/localdb/cycle.d.ts +69 -0
- package/dist/localdb/cycle.d.ts.map +1 -0
- package/dist/localdb/cycle.js +189 -0
- package/dist/localdb/cycle.js.map +1 -0
- package/dist/localdb/delete-batch.d.ts +29 -0
- package/dist/localdb/delete-batch.d.ts.map +1 -0
- package/dist/localdb/delete-batch.js +84 -0
- package/dist/localdb/delete-batch.js.map +1 -0
- package/dist/localdb/delete-lifetime.d.ts +24 -0
- package/dist/localdb/delete-lifetime.d.ts.map +1 -0
- package/dist/localdb/delete-lifetime.js +83 -0
- package/dist/localdb/delete-lifetime.js.map +1 -0
- package/dist/localdb/delete.d.ts +88 -0
- package/dist/localdb/delete.d.ts.map +1 -0
- package/dist/localdb/delete.js +521 -0
- package/dist/localdb/delete.js.map +1 -0
- package/dist/localdb/delta-apply.d.ts +4 -0
- package/dist/localdb/delta-apply.d.ts.map +1 -0
- package/dist/localdb/delta-apply.js +253 -0
- package/dist/localdb/delta-apply.js.map +1 -0
- package/dist/localdb/deps.d.ts +87 -0
- package/dist/localdb/deps.d.ts.map +1 -0
- package/dist/localdb/deps.js +10 -0
- package/dist/localdb/deps.js.map +1 -0
- package/dist/localdb/driver.d.ts +51 -0
- package/dist/localdb/driver.d.ts.map +1 -0
- package/dist/localdb/driver.js +3 -0
- package/dist/localdb/driver.js.map +1 -0
- package/dist/localdb/fence.d.ts +31 -0
- package/dist/localdb/fence.d.ts.map +1 -0
- package/dist/localdb/fence.js +69 -0
- package/dist/localdb/fence.js.map +1 -0
- package/dist/localdb/history.d.ts +76 -0
- package/dist/localdb/history.d.ts.map +1 -0
- package/dist/localdb/history.js +256 -0
- package/dist/localdb/history.js.map +1 -0
- package/dist/localdb/import-fingerprint.d.ts +8 -0
- package/dist/localdb/import-fingerprint.d.ts.map +1 -0
- package/dist/localdb/import-fingerprint.js +35 -0
- package/dist/localdb/import-fingerprint.js.map +1 -0
- package/dist/localdb/import-ledger.d.ts +27 -0
- package/dist/localdb/import-ledger.d.ts.map +1 -0
- package/dist/localdb/import-ledger.js +197 -0
- package/dist/localdb/import-ledger.js.map +1 -0
- package/dist/localdb/import-readback.d.ts +8 -0
- package/dist/localdb/import-readback.d.ts.map +1 -0
- package/dist/localdb/import-readback.js +69 -0
- package/dist/localdb/import-readback.js.map +1 -0
- package/dist/localdb/import-snapshot.d.ts +21 -0
- package/dist/localdb/import-snapshot.d.ts.map +1 -0
- package/dist/localdb/import-snapshot.js +94 -0
- package/dist/localdb/import-snapshot.js.map +1 -0
- package/dist/localdb/index.d.ts +42 -0
- package/dist/localdb/index.d.ts.map +1 -0
- package/dist/localdb/index.js +40 -0
- package/dist/localdb/index.js.map +1 -0
- package/dist/localdb/legacy-import-types.d.ts +112 -0
- package/dist/localdb/legacy-import-types.d.ts.map +1 -0
- package/dist/localdb/legacy-import-types.js +2 -0
- package/dist/localdb/legacy-import-types.js.map +1 -0
- package/dist/localdb/legacy-import.d.ts +67 -0
- package/dist/localdb/legacy-import.d.ts.map +1 -0
- package/dist/localdb/legacy-import.js +320 -0
- package/dist/localdb/legacy-import.js.map +1 -0
- package/dist/localdb/legacy-retire.d.ts +26 -0
- package/dist/localdb/legacy-retire.d.ts.map +1 -0
- package/dist/localdb/legacy-retire.js +93 -0
- package/dist/localdb/legacy-retire.js.map +1 -0
- package/dist/localdb/lifetime.d.ts +29 -0
- package/dist/localdb/lifetime.d.ts.map +1 -0
- package/dist/localdb/lifetime.js +64 -0
- package/dist/localdb/lifetime.js.map +1 -0
- package/dist/localdb/listing.d.ts +70 -0
- package/dist/localdb/listing.d.ts.map +1 -0
- package/dist/localdb/listing.js +345 -0
- package/dist/localdb/listing.js.map +1 -0
- package/dist/localdb/log-apply.d.ts +46 -0
- package/dist/localdb/log-apply.d.ts.map +1 -0
- package/dist/localdb/log-apply.js +827 -0
- package/dist/localdb/log-apply.js.map +1 -0
- package/dist/localdb/log-batch.d.ts +204 -0
- package/dist/localdb/log-batch.d.ts.map +1 -0
- package/dist/localdb/log-batch.js +418 -0
- package/dist/localdb/log-batch.js.map +1 -0
- package/dist/localdb/log-bodies.d.ts +27 -0
- package/dist/localdb/log-bodies.d.ts.map +1 -0
- package/dist/localdb/log-bodies.js +142 -0
- package/dist/localdb/log-bodies.js.map +1 -0
- package/dist/localdb/log-bootstrap-stage.d.ts +5 -0
- package/dist/localdb/log-bootstrap-stage.d.ts.map +1 -0
- package/dist/localdb/log-bootstrap-stage.js +60 -0
- package/dist/localdb/log-bootstrap-stage.js.map +1 -0
- package/dist/localdb/log-bootstrap.d.ts +23 -0
- package/dist/localdb/log-bootstrap.d.ts.map +1 -0
- package/dist/localdb/log-bootstrap.js +399 -0
- package/dist/localdb/log-bootstrap.js.map +1 -0
- package/dist/localdb/log-compact.d.ts +28 -0
- package/dist/localdb/log-compact.d.ts.map +1 -0
- package/dist/localdb/log-compact.js +83 -0
- package/dist/localdb/log-compact.js.map +1 -0
- package/dist/localdb/log-keyed.d.ts +118 -0
- package/dist/localdb/log-keyed.d.ts.map +1 -0
- package/dist/localdb/log-keyed.js +640 -0
- package/dist/localdb/log-keyed.js.map +1 -0
- package/dist/localdb/log-progressive.d.ts +18 -0
- package/dist/localdb/log-progressive.d.ts.map +1 -0
- package/dist/localdb/log-progressive.js +58 -0
- package/dist/localdb/log-progressive.js.map +1 -0
- package/dist/localdb/log-publish-phases.d.ts +31 -0
- package/dist/localdb/log-publish-phases.d.ts.map +1 -0
- package/dist/localdb/log-publish-phases.js +40 -0
- package/dist/localdb/log-publish-phases.js.map +1 -0
- package/dist/localdb/log-publish.d.ts +16 -0
- package/dist/localdb/log-publish.d.ts.map +1 -0
- package/dist/localdb/log-publish.js +1745 -0
- package/dist/localdb/log-publish.js.map +1 -0
- package/dist/localdb/log-rebase.d.ts +12 -0
- package/dist/localdb/log-rebase.d.ts.map +1 -0
- package/dist/localdb/log-rebase.js +74 -0
- package/dist/localdb/log-rebase.js.map +1 -0
- package/dist/localdb/log-recommit.d.ts +15 -0
- package/dist/localdb/log-recommit.d.ts.map +1 -0
- package/dist/localdb/log-recommit.js +88 -0
- package/dist/localdb/log-recommit.js.map +1 -0
- package/dist/localdb/log-seed.d.ts +25 -0
- package/dist/localdb/log-seed.d.ts.map +1 -0
- package/dist/localdb/log-seed.js +129 -0
- package/dist/localdb/log-seed.js.map +1 -0
- package/dist/localdb/log-state.d.ts +34 -0
- package/dist/localdb/log-state.d.ts.map +1 -0
- package/dist/localdb/log-state.js +79 -0
- package/dist/localdb/log-state.js.map +1 -0
- package/dist/localdb/merge.d.ts +122 -0
- package/dist/localdb/merge.d.ts.map +1 -0
- package/dist/localdb/merge.js +339 -0
- package/dist/localdb/merge.js.map +1 -0
- package/dist/localdb/migrate.d.ts +10 -0
- package/dist/localdb/migrate.d.ts.map +1 -0
- package/dist/localdb/migrate.js +27 -0
- package/dist/localdb/migrate.js.map +1 -0
- package/dist/localdb/name.d.ts +10 -0
- package/dist/localdb/name.d.ts.map +1 -0
- package/dist/localdb/name.js +15 -0
- package/dist/localdb/name.js.map +1 -0
- package/dist/localdb/open.d.ts +33 -0
- package/dist/localdb/open.d.ts.map +1 -0
- package/dist/localdb/open.js +46 -0
- package/dist/localdb/open.js.map +1 -0
- package/dist/localdb/part-layout.d.ts +6 -0
- package/dist/localdb/part-layout.d.ts.map +1 -0
- package/dist/localdb/part-layout.js +6 -0
- package/dist/localdb/part-layout.js.map +1 -0
- package/dist/localdb/part-readahead.d.ts +87 -0
- package/dist/localdb/part-readahead.d.ts.map +1 -0
- package/dist/localdb/part-readahead.js +130 -0
- package/dist/localdb/part-readahead.js.map +1 -0
- package/dist/localdb/partial-load.d.ts +42 -0
- package/dist/localdb/partial-load.d.ts.map +1 -0
- package/dist/localdb/partial-load.js +120 -0
- package/dist/localdb/partial-load.js.map +1 -0
- package/dist/localdb/partial-read.d.ts +64 -0
- package/dist/localdb/partial-read.d.ts.map +1 -0
- package/dist/localdb/partial-read.js +110 -0
- package/dist/localdb/partial-read.js.map +1 -0
- package/dist/localdb/plan-inputs.d.ts +31 -0
- package/dist/localdb/plan-inputs.d.ts.map +1 -0
- package/dist/localdb/plan-inputs.js +26 -0
- package/dist/localdb/plan-inputs.js.map +1 -0
- package/dist/localdb/publication-work.d.ts +20 -0
- package/dist/localdb/publication-work.d.ts.map +1 -0
- package/dist/localdb/publication-work.js +60 -0
- package/dist/localdb/publication-work.js.map +1 -0
- package/dist/localdb/publish-meter.d.ts +32 -0
- package/dist/localdb/publish-meter.d.ts.map +1 -0
- package/dist/localdb/publish-meter.js +36 -0
- package/dist/localdb/publish-meter.js.map +1 -0
- package/dist/localdb/publish.d.ts +153 -0
- package/dist/localdb/publish.d.ts.map +1 -0
- package/dist/localdb/publish.js +329 -0
- package/dist/localdb/publish.js.map +1 -0
- package/dist/localdb/purge.d.ts +40 -0
- package/dist/localdb/purge.d.ts.map +1 -0
- package/dist/localdb/purge.js +159 -0
- package/dist/localdb/purge.js.map +1 -0
- package/dist/localdb/query.d.ts +77 -0
- package/dist/localdb/query.d.ts.map +1 -0
- package/dist/localdb/query.js +330 -0
- package/dist/localdb/query.js.map +1 -0
- package/dist/localdb/queue.d.ts +10 -0
- package/dist/localdb/queue.d.ts.map +1 -0
- package/dist/localdb/queue.js +31 -0
- package/dist/localdb/queue.js.map +1 -0
- package/dist/localdb/raw-end-evidence.d.ts +16 -0
- package/dist/localdb/raw-end-evidence.d.ts.map +1 -0
- package/dist/localdb/raw-end-evidence.js +27 -0
- package/dist/localdb/raw-end-evidence.js.map +1 -0
- package/dist/localdb/read-selection.d.ts +182 -0
- package/dist/localdb/read-selection.d.ts.map +1 -0
- package/dist/localdb/read-selection.js +290 -0
- package/dist/localdb/read-selection.js.map +1 -0
- package/dist/localdb/registered-read.d.ts +15 -0
- package/dist/localdb/registered-read.d.ts.map +1 -0
- package/dist/localdb/registered-read.js +62 -0
- package/dist/localdb/registered-read.js.map +1 -0
- package/dist/localdb/replace.d.ts +33 -0
- package/dist/localdb/replace.d.ts.map +1 -0
- package/dist/localdb/replace.js +22 -0
- package/dist/localdb/replace.js.map +1 -0
- package/dist/localdb/requirements.d.ts +35 -0
- package/dist/localdb/requirements.d.ts.map +1 -0
- package/dist/localdb/requirements.js +66 -0
- package/dist/localdb/requirements.js.map +1 -0
- package/dist/localdb/resolve.d.ts +69 -0
- package/dist/localdb/resolve.d.ts.map +1 -0
- package/dist/localdb/resolve.js +436 -0
- package/dist/localdb/resolve.js.map +1 -0
- package/dist/localdb/run-end.d.ts +35 -0
- package/dist/localdb/run-end.d.ts.map +1 -0
- package/dist/localdb/run-end.js +520 -0
- package/dist/localdb/run-end.js.map +1 -0
- package/dist/localdb/run-intake.d.ts +17 -0
- package/dist/localdb/run-intake.d.ts.map +1 -0
- package/dist/localdb/run-intake.js +662 -0
- package/dist/localdb/run-intake.js.map +1 -0
- package/dist/localdb/run-receipts.d.ts +19 -0
- package/dist/localdb/run-receipts.d.ts.map +1 -0
- package/dist/localdb/run-receipts.js +151 -0
- package/dist/localdb/run-receipts.js.map +1 -0
- package/dist/localdb/schema.d.ts +7 -0
- package/dist/localdb/schema.d.ts.map +1 -0
- package/dist/localdb/schema.js +686 -0
- package/dist/localdb/schema.js.map +1 -0
- package/dist/localdb/seed.d.ts +39 -0
- package/dist/localdb/seed.d.ts.map +1 -0
- package/dist/localdb/seed.js +188 -0
- package/dist/localdb/seed.js.map +1 -0
- package/dist/localdb/slot.d.ts +9 -0
- package/dist/localdb/slot.d.ts.map +1 -0
- package/dist/localdb/slot.js +15 -0
- package/dist/localdb/slot.js.map +1 -0
- package/dist/localdb/stream-digest.d.ts +35 -0
- package/dist/localdb/stream-digest.d.ts.map +1 -0
- package/dist/localdb/stream-digest.js +50 -0
- package/dist/localdb/stream-digest.js.map +1 -0
- package/dist/localdb/sync.d.ts +75 -0
- package/dist/localdb/sync.d.ts.map +1 -0
- package/dist/localdb/sync.js +339 -0
- package/dist/localdb/sync.js.map +1 -0
- package/dist/localdb/system-stream-descriptor.d.ts +22 -0
- package/dist/localdb/system-stream-descriptor.d.ts.map +1 -0
- package/dist/localdb/system-stream-descriptor.js +24 -0
- package/dist/localdb/system-stream-descriptor.js.map +1 -0
- package/dist/localdb/system-stream-page.d.ts +15 -0
- package/dist/localdb/system-stream-page.d.ts.map +1 -0
- package/dist/localdb/system-stream-page.js +98 -0
- package/dist/localdb/system-stream-page.js.map +1 -0
- package/dist/localdb/system-streams.d.ts +35 -0
- package/dist/localdb/system-streams.d.ts.map +1 -0
- package/dist/localdb/system-streams.js +350 -0
- package/dist/localdb/system-streams.js.map +1 -0
- package/dist/localdb/transfer-memory.d.ts +17 -0
- package/dist/localdb/transfer-memory.d.ts.map +1 -0
- package/dist/localdb/transfer-memory.js +17 -0
- package/dist/localdb/transfer-memory.js.map +1 -0
- package/dist/localdb/unwrite.d.ts +28 -0
- package/dist/localdb/unwrite.d.ts.map +1 -0
- package/dist/localdb/unwrite.js +62 -0
- package/dist/localdb/unwrite.js.map +1 -0
- package/dist/localdb/update-required.d.ts +10 -0
- package/dist/localdb/update-required.d.ts.map +1 -0
- package/dist/localdb/update-required.js +27 -0
- package/dist/localdb/update-required.js.map +1 -0
- package/dist/localdb/view-changes.d.ts +58 -0
- package/dist/localdb/view-changes.d.ts.map +1 -0
- package/dist/localdb/view-changes.js +174 -0
- package/dist/localdb/view-changes.js.map +1 -0
- package/dist/logging/access-log.d.ts +2 -2
- package/dist/logging/access-log.d.ts.map +1 -1
- package/dist/logging/access-reader.d.ts +4 -1
- package/dist/logging/access-reader.d.ts.map +1 -1
- package/dist/logging/activity-stream.d.ts +37 -0
- package/dist/logging/activity-stream.d.ts.map +1 -0
- package/dist/logging/activity-stream.js +86 -0
- package/dist/logging/activity-stream.js.map +1 -0
- package/dist/mcp/approval-url.d.ts +32 -0
- package/dist/mcp/approval-url.d.ts.map +1 -1
- package/dist/mcp/approval-url.js +76 -0
- package/dist/mcp/approval-url.js.map +1 -1
- package/dist/mcp/connection-api.d.ts +54 -27
- package/dist/mcp/connection-api.d.ts.map +1 -1
- package/dist/mcp/connection-api.js +267 -77
- package/dist/mcp/connection-api.js.map +1 -1
- package/dist/mcp/grant-registration.d.ts +15 -0
- package/dist/mcp/grant-registration.d.ts.map +1 -0
- package/dist/mcp/grant-registration.js +44 -0
- package/dist/mcp/grant-registration.js.map +1 -0
- package/dist/mcp/index.d.ts +1 -0
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +1 -0
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/read-client.d.ts +32 -10
- package/dist/mcp/read-client.d.ts.map +1 -1
- package/dist/mcp/read-client.js +299 -15
- package/dist/mcp/read-client.js.map +1 -1
- package/dist/mcp/resources.d.ts +3 -1
- package/dist/mcp/resources.d.ts.map +1 -1
- package/dist/mcp/resources.js +11 -2
- package/dist/mcp/resources.js.map +1 -1
- package/dist/mcp/server.d.ts +17 -0
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +54 -7
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/session.d.ts +2 -0
- package/dist/mcp/session.d.ts.map +1 -1
- package/dist/mcp/session.js +41 -8
- package/dist/mcp/session.js.map +1 -1
- package/dist/mcp/store.d.ts +14 -1
- package/dist/mcp/store.d.ts.map +1 -1
- package/dist/mcp/store.js +31 -2
- package/dist/mcp/store.js.map +1 -1
- package/dist/mcp/tools.d.ts +62 -0
- package/dist/mcp/tools.d.ts.map +1 -1
- package/dist/mcp/tools.js +186 -64
- package/dist/mcp/tools.js.map +1 -1
- package/dist/mcp/types.d.ts +3 -1
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/oura/index.d.ts +1 -1
- package/dist/oura/index.d.ts.map +1 -1
- package/dist/oura/index.js +15 -0
- package/dist/oura/index.js.map +1 -1
- package/dist/payment/x402.d.ts +6 -3
- package/dist/payment/x402.d.ts.map +1 -1
- package/dist/payment/x402.js +35 -0
- package/dist/payment/x402.js.map +1 -1
- package/dist/pdpp/pkce.d.ts +1 -22
- package/dist/pdpp/pkce.d.ts.map +1 -1
- package/dist/pdpp/pkce.js +3 -2
- package/dist/pdpp/pkce.js.map +1 -1
- package/dist/policy/reserved-scopes.d.ts +3 -0
- package/dist/policy/reserved-scopes.d.ts.map +1 -1
- package/dist/policy/reserved-scopes.js +12 -1
- package/dist/policy/reserved-scopes.js.map +1 -1
- package/dist/ports/index.d.ts +61 -9
- package/dist/ports/index.d.ts.map +1 -1
- package/dist/ports/index.js.map +1 -1
- package/dist/publication/publish.d.ts +31 -1
- package/dist/publication/publish.d.ts.map +1 -1
- package/dist/publication/publish.js +30 -14
- package/dist/publication/publish.js.map +1 -1
- package/dist/replication/copies.d.ts +1 -1
- package/dist/replication/dpv2.d.ts.map +1 -1
- package/dist/replication/dpv2.js +33 -0
- package/dist/replication/dpv2.js.map +1 -1
- package/dist/schemas/server-config.d.ts +16 -0
- package/dist/schemas/server-config.d.ts.map +1 -1
- package/dist/schemas/server-config.js +49 -0
- package/dist/schemas/server-config.js.map +1 -1
- package/dist/storage/adapters/interface.d.ts +12 -2
- package/dist/storage/adapters/interface.d.ts.map +1 -1
- package/dist/storage/adapters/interface.js.map +1 -1
- package/dist/storage/adapters/rate-limit-policy.d.ts +71 -0
- package/dist/storage/adapters/rate-limit-policy.d.ts.map +1 -0
- package/dist/storage/adapters/rate-limit-policy.js +107 -0
- package/dist/storage/adapters/rate-limit-policy.js.map +1 -0
- package/dist/storage/adapters/sdk.d.ts +7 -0
- package/dist/storage/adapters/sdk.d.ts.map +1 -1
- package/dist/storage/adapters/sdk.js +12 -6
- package/dist/storage/adapters/sdk.js.map +1 -1
- package/dist/storage/adapters/throttle.d.ts +30 -0
- package/dist/storage/adapters/throttle.d.ts.map +1 -0
- package/dist/storage/adapters/throttle.js +94 -0
- package/dist/storage/adapters/throttle.js.map +1 -0
- package/dist/storage/adapters/vana-audience.d.ts +4 -1
- package/dist/storage/adapters/vana-audience.d.ts.map +1 -1
- package/dist/storage/adapters/vana-audience.js +23 -11
- package/dist/storage/adapters/vana-audience.js.map +1 -1
- package/dist/storage/adapters/vana.d.ts +5 -0
- package/dist/storage/adapters/vana.d.ts.map +1 -1
- package/dist/storage/adapters/vana.js +82 -18
- package/dist/storage/adapters/vana.js.map +1 -1
- package/dist/storage/blocks/cursor.d.ts.map +1 -1
- package/dist/storage/blocks/cursor.js +3 -13
- package/dist/storage/blocks/cursor.js.map +1 -1
- package/dist/storage/canonical-legacy-projection.d.ts +13 -1
- package/dist/storage/canonical-legacy-projection.d.ts.map +1 -1
- package/dist/storage/canonical-legacy-projection.js +92 -24
- package/dist/storage/canonical-legacy-projection.js.map +1 -1
- package/dist/storage/hierarchy/paths.d.ts.map +1 -1
- package/dist/storage/hierarchy/paths.js +9 -2
- package/dist/storage/hierarchy/paths.js.map +1 -1
- package/dist/storage/index/manager.d.ts +19 -5
- package/dist/storage/index/manager.d.ts.map +1 -1
- package/dist/storage/legacy-scope-view.d.ts +4 -6
- package/dist/storage/legacy-scope-view.d.ts.map +1 -1
- package/dist/storage/legacy-scope-view.js +50 -57
- package/dist/storage/legacy-scope-view.js.map +1 -1
- package/dist/storage/legacy-write-seal.d.ts +73 -0
- package/dist/storage/legacy-write-seal.d.ts.map +1 -0
- package/dist/storage/legacy-write-seal.js +74 -0
- package/dist/storage/legacy-write-seal.js.map +1 -0
- package/dist/storage/pdpp-records/cursor.d.ts.map +1 -1
- package/dist/storage/pdpp-records/cursor.js +3 -29
- package/dist/storage/pdpp-records/cursor.js.map +1 -1
- package/dist/storage/pdpp-records/declaration-witness.d.ts.map +1 -1
- package/dist/storage/pdpp-records/declaration-witness.js +4 -3
- package/dist/storage/pdpp-records/declaration-witness.js.map +1 -1
- package/dist/storage/pdpp-records/types.d.ts +2 -0
- package/dist/storage/pdpp-records/types.d.ts.map +1 -1
- package/dist/storage/pdpp-records/types.js.map +1 -1
- package/dist/stream-sync/artifacts.d.ts +38 -0
- package/dist/stream-sync/artifacts.d.ts.map +1 -0
- package/dist/stream-sync/artifacts.js +179 -0
- package/dist/stream-sync/artifacts.js.map +1 -0
- package/dist/stream-sync/blobs.d.ts +18 -0
- package/dist/stream-sync/blobs.d.ts.map +1 -0
- package/dist/stream-sync/blobs.js +83 -0
- package/dist/stream-sync/blobs.js.map +1 -0
- package/dist/stream-sync/crypto-port.d.ts +30 -0
- package/dist/stream-sync/crypto-port.d.ts.map +1 -0
- package/dist/stream-sync/crypto-port.js +29 -0
- package/dist/stream-sync/crypto-port.js.map +1 -0
- package/dist/stream-sync/crypto.d.ts +27 -0
- package/dist/stream-sync/crypto.d.ts.map +1 -0
- package/dist/stream-sync/crypto.js +67 -0
- package/dist/stream-sync/crypto.js.map +1 -0
- package/dist/stream-sync/delete-metadata.d.ts +23 -0
- package/dist/stream-sync/delete-metadata.d.ts.map +1 -0
- package/dist/stream-sync/delete-metadata.js +40 -0
- package/dist/stream-sync/delete-metadata.js.map +1 -0
- package/dist/stream-sync/design-flags.d.ts +31 -0
- package/dist/stream-sync/design-flags.d.ts.map +1 -0
- package/dist/stream-sync/design-flags.js +44 -0
- package/dist/stream-sync/design-flags.js.map +1 -0
- package/dist/stream-sync/host-contract.d.ts +50 -0
- package/dist/stream-sync/host-contract.d.ts.map +1 -0
- package/dist/stream-sync/host-contract.js +80 -0
- package/dist/stream-sync/host-contract.js.map +1 -0
- package/dist/stream-sync/index.d.ts +19 -0
- package/dist/stream-sync/index.d.ts.map +1 -0
- package/dist/stream-sync/index.js +19 -0
- package/dist/stream-sync/index.js.map +1 -0
- package/dist/stream-sync/intake.d.ts +319 -0
- package/dist/stream-sync/intake.d.ts.map +1 -0
- package/dist/stream-sync/intake.js +62 -0
- package/dist/stream-sync/intake.js.map +1 -0
- package/dist/stream-sync/memory-registry.d.ts +85 -0
- package/dist/stream-sync/memory-registry.d.ts.map +1 -0
- package/dist/stream-sync/memory-registry.js +293 -0
- package/dist/stream-sync/memory-registry.js.map +1 -0
- package/dist/stream-sync/normalize-raw-end.d.ts +25 -0
- package/dist/stream-sync/normalize-raw-end.d.ts.map +1 -0
- package/dist/stream-sync/normalize-raw-end.js +177 -0
- package/dist/stream-sync/normalize-raw-end.js.map +1 -0
- package/dist/stream-sync/ports.d.ts +486 -0
- package/dist/stream-sync/ports.d.ts.map +1 -0
- package/dist/stream-sync/ports.js +91 -0
- package/dist/stream-sync/ports.js.map +1 -0
- package/dist/stream-sync/publish-plan.d.ts +129 -0
- package/dist/stream-sync/publish-plan.d.ts.map +1 -0
- package/dist/stream-sync/publish-plan.js +134 -0
- package/dist/stream-sync/publish-plan.js.map +1 -0
- package/dist/stream-sync/raw-end.d.ts +59 -0
- package/dist/stream-sync/raw-end.d.ts.map +1 -0
- package/dist/stream-sync/raw-end.js +113 -0
- package/dist/stream-sync/raw-end.js.map +1 -0
- package/dist/stream-sync/registry.d.ts +31 -0
- package/dist/stream-sync/registry.d.ts.map +1 -0
- package/dist/stream-sync/registry.js +645 -0
- package/dist/stream-sync/registry.js.map +1 -0
- package/dist/stream-sync/run-finish-plan.d.ts +61 -0
- package/dist/stream-sync/run-finish-plan.d.ts.map +1 -0
- package/dist/stream-sync/run-finish-plan.js +373 -0
- package/dist/stream-sync/run-finish-plan.js.map +1 -0
- package/dist/stream-sync/run-saved.d.ts +51 -0
- package/dist/stream-sync/run-saved.d.ts.map +1 -0
- package/dist/stream-sync/run-saved.js +83 -0
- package/dist/stream-sync/run-saved.js.map +1 -0
- package/dist/stream-sync/scope-routing.d.ts +17 -0
- package/dist/stream-sync/scope-routing.d.ts.map +1 -0
- package/dist/stream-sync/scope-routing.js +24 -0
- package/dist/stream-sync/scope-routing.js.map +1 -0
- package/dist/stream-sync/seed-staging.d.ts +85 -0
- package/dist/stream-sync/seed-staging.d.ts.map +1 -0
- package/dist/stream-sync/seed-staging.js +325 -0
- package/dist/stream-sync/seed-staging.js.map +1 -0
- package/dist/stream-sync/semver.d.ts +3 -0
- package/dist/stream-sync/semver.d.ts.map +1 -0
- package/dist/stream-sync/semver.js +49 -0
- package/dist/stream-sync/semver.js.map +1 -0
- package/dist/stream-sync/send-gate.d.ts +149 -0
- package/dist/stream-sync/send-gate.d.ts.map +1 -0
- package/dist/stream-sync/send-gate.js +382 -0
- package/dist/stream-sync/send-gate.js.map +1 -0
- package/dist/stream-sync/storage-retry.d.ts +216 -0
- package/dist/stream-sync/storage-retry.d.ts.map +1 -0
- package/dist/stream-sync/storage-retry.js +315 -0
- package/dist/stream-sync/storage-retry.js.map +1 -0
- package/dist/stream-sync/stream-aead.d.ts +33 -0
- package/dist/stream-sync/stream-aead.d.ts.map +1 -0
- package/dist/stream-sync/stream-aead.js +183 -0
- package/dist/stream-sync/stream-aead.js.map +1 -0
- package/dist/stream-sync/timer.d.ts +3 -0
- package/dist/stream-sync/timer.d.ts.map +1 -0
- package/dist/stream-sync/timer.js +3 -0
- package/dist/stream-sync/timer.js.map +1 -0
- package/dist/stream-sync-read/index.d.ts +4 -0
- package/dist/stream-sync-read/index.d.ts.map +1 -0
- package/dist/stream-sync-read/index.js +3 -0
- package/dist/stream-sync-read/index.js.map +1 -0
- package/dist/stream-sync-read/routing.d.ts +27 -0
- package/dist/stream-sync-read/routing.d.ts.map +1 -0
- package/dist/stream-sync-read/routing.js +49 -0
- package/dist/stream-sync-read/routing.js.map +1 -0
- package/dist/stream-sync-read/service.d.ts +281 -0
- package/dist/stream-sync-read/service.d.ts.map +1 -0
- package/dist/stream-sync-read/service.js +18 -0
- package/dist/stream-sync-read/service.js.map +1 -0
- package/dist/sync/account-mode/authority.d.ts +121 -0
- package/dist/sync/account-mode/authority.d.ts.map +1 -0
- package/dist/sync/account-mode/authority.js +446 -0
- package/dist/sync/account-mode/authority.js.map +1 -0
- package/dist/sync/account-mode/evidence-wire.d.ts +42 -0
- package/dist/sync/account-mode/evidence-wire.d.ts.map +1 -0
- package/dist/sync/account-mode/evidence-wire.js +76 -0
- package/dist/sync/account-mode/evidence-wire.js.map +1 -0
- package/dist/sync/account-mode/import-waker.d.ts +36 -0
- package/dist/sync/account-mode/import-waker.d.ts.map +1 -0
- package/dist/sync/account-mode/import-waker.js +55 -0
- package/dist/sync/account-mode/import-waker.js.map +1 -0
- package/dist/sync/account-mode/index.d.ts +10 -0
- package/dist/sync/account-mode/index.d.ts.map +1 -0
- package/dist/sync/account-mode/index.js +10 -0
- package/dist/sync/account-mode/index.js.map +1 -0
- package/dist/sync/account-mode/port.d.ts +11 -0
- package/dist/sync/account-mode/port.d.ts.map +1 -0
- package/dist/sync/account-mode/port.js +21 -0
- package/dist/sync/account-mode/port.js.map +1 -0
- package/dist/sync/account-mode/record.d.ts +54 -0
- package/dist/sync/account-mode/record.d.ts.map +1 -0
- package/dist/sync/account-mode/record.js +62 -0
- package/dist/sync/account-mode/record.js.map +1 -0
- package/dist/sync/account-mode/rw-lock.d.ts +14 -0
- package/dist/sync/account-mode/rw-lock.d.ts.map +1 -0
- package/dist/sync/account-mode/rw-lock.js +59 -0
- package/dist/sync/account-mode/rw-lock.js.map +1 -0
- package/dist/sync/cancellable-gateway.d.ts +25 -0
- package/dist/sync/cancellable-gateway.d.ts.map +1 -0
- package/dist/sync/cancellable-gateway.js +64 -0
- package/dist/sync/cancellable-gateway.js.map +1 -0
- package/dist/sync/engine/change-probe.d.ts +49 -0
- package/dist/sync/engine/change-probe.d.ts.map +1 -0
- package/dist/sync/engine/change-probe.js +84 -0
- package/dist/sync/engine/change-probe.js.map +1 -0
- package/dist/sync/engine/change-push.d.ts +56 -0
- package/dist/sync/engine/change-push.d.ts.map +1 -0
- package/dist/sync/engine/change-push.js +176 -0
- package/dist/sync/engine/change-push.js.map +1 -0
- package/dist/sync/engine/sync-manager.d.ts +208 -1
- package/dist/sync/engine/sync-manager.d.ts.map +1 -1
- package/dist/sync/engine/sync-manager.js +1005 -34
- package/dist/sync/engine/sync-manager.js.map +1 -1
- package/dist/sync/index.d.ts +6 -2
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/index.js +5 -1
- package/dist/sync/index.js.map +1 -1
- package/dist/sync/pdpp-import.d.ts +12 -2
- package/dist/sync/pdpp-import.d.ts.map +1 -1
- package/dist/sync/pdpp-import.js +32 -7
- package/dist/sync/pdpp-import.js.map +1 -1
- package/dist/sync/tombstone-resubmits.d.ts +7 -4
- package/dist/sync/tombstone-resubmits.d.ts.map +1 -1
- package/dist/sync/tombstone-resubmits.js.map +1 -1
- package/dist/sync/types.d.ts +29 -0
- package/dist/sync/types.d.ts.map +1 -1
- package/dist/sync/upload-attempts.d.ts +244 -0
- package/dist/sync/upload-attempts.d.ts.map +1 -0
- package/dist/sync/upload-attempts.js +548 -0
- package/dist/sync/upload-attempts.js.map +1 -0
- package/dist/sync/upload-state.d.ts +163 -0
- package/dist/sync/upload-state.d.ts.map +1 -0
- package/dist/sync/upload-state.js +239 -0
- package/dist/sync/upload-state.js.map +1 -0
- package/dist/sync/workers/delete.d.ts +33 -1
- package/dist/sync/workers/delete.d.ts.map +1 -1
- package/dist/sync/workers/delete.js +83 -11
- package/dist/sync/workers/delete.js.map +1 -1
- package/dist/sync/workers/download.d.ts +3 -0
- package/dist/sync/workers/download.d.ts.map +1 -1
- package/dist/sync/workers/download.js +67 -12
- package/dist/sync/workers/download.js.map +1 -1
- package/dist/sync/workers/upload.d.ts +70 -2
- package/dist/sync/workers/upload.d.ts.map +1 -1
- package/dist/sync/workers/upload.js +354 -23
- package/dist/sync/workers/upload.js.map +1 -1
- package/dist/test-support/memory-oracle.calibration.d.ts +16 -0
- package/dist/test-support/memory-oracle.calibration.d.ts.map +1 -0
- package/dist/test-support/memory-oracle.calibration.js +43 -0
- package/dist/test-support/memory-oracle.calibration.js.map +1 -0
- package/dist/test-support/memory-oracle.d.ts +82 -0
- package/dist/test-support/memory-oracle.d.ts.map +1 -0
- package/dist/test-support/memory-oracle.js +104 -0
- package/dist/test-support/memory-oracle.js.map +1 -0
- package/dist/test-utils/account-mode.d.ts +36 -0
- package/dist/test-utils/account-mode.d.ts.map +1 -0
- package/dist/test-utils/account-mode.js +78 -0
- package/dist/test-utils/account-mode.js.map +1 -0
- package/dist/test-utils/index.d.ts +3 -0
- package/dist/test-utils/index.d.ts.map +1 -1
- package/dist/test-utils/index.js +3 -0
- package/dist/test-utils/index.js.map +1 -1
- package/dist/test-utils/legacy-write-seal.d.ts +16 -0
- package/dist/test-utils/legacy-write-seal.d.ts.map +1 -0
- package/dist/test-utils/legacy-write-seal.js +20 -0
- package/dist/test-utils/legacy-write-seal.js.map +1 -0
- package/dist/test-utils/live-grants.d.ts +24 -0
- package/dist/test-utils/live-grants.d.ts.map +1 -0
- package/dist/test-utils/live-grants.js +6 -0
- package/dist/test-utils/live-grants.js.map +1 -0
- package/dist/test-utils/memory-storage.d.ts +17 -1
- package/dist/test-utils/memory-storage.d.ts.map +1 -1
- package/dist/test-utils/memory-storage.js +94 -46
- package/dist/test-utils/memory-storage.js.map +1 -1
- package/dist/test-utils/run-end.d.ts +27 -0
- package/dist/test-utils/run-end.d.ts.map +1 -0
- package/dist/test-utils/run-end.js +44 -0
- package/dist/test-utils/run-end.js.map +1 -0
- package/dist/test-utils/wallet.d.ts +0 -4
- package/dist/test-utils/wallet.d.ts.map +1 -1
- package/dist/test-utils/wallet.js +3 -12
- package/dist/test-utils/wallet.js.map +1 -1
- package/dist/write/attribution.d.ts.map +1 -1
- package/dist/write/attribution.js +2 -4
- package/dist/write/attribution.js.map +1 -1
- package/dist-test/localdb/conformance.d.ts +13 -0
- package/dist-test/localdb/conformance.d.ts.map +1 -0
- package/dist-test/localdb/conformance.js +372 -0
- package/dist-test/localdb/conformance.js.map +1 -0
- package/dist-test/tsconfig.tsbuildinfo +1 -0
- package/package.json +60 -5
|
@@ -0,0 +1,640 @@
|
|
|
1
|
+
// The keyed first load: a device with no rows loads a log it has never read key
|
|
2
|
+
// by key, not segment by segment.
|
|
3
|
+
//
|
|
4
|
+
// Why. The keys of a log are in publish order and `records` is in key order, so
|
|
5
|
+
// a segment's rows land across the whole table and its secondary indexes, and a
|
|
6
|
+
// commit rewrites about as many pages as the table has leaves (the log's keys
|
|
7
|
+
// are hashes; see `pk_hash`). A host whose every page write costs a call (the
|
|
8
|
+
// Web's OPFS) pays for each. Committing segments together (`applyInGroups`)
|
|
9
|
+
// divides the commits, but each one still rewrites most of the table: the cost
|
|
10
|
+
// is the number of commits times the table, and the memory budget sets the
|
|
11
|
+
// number of commits. Loading in key order writes each page once.
|
|
12
|
+
//
|
|
13
|
+
// How. Two phases; the cursor (`log_state`) and the streams' heads move only in
|
|
14
|
+
// the last commit, so no reader sees a state between them.
|
|
15
|
+
//
|
|
16
|
+
// 1. Stage. The segments are fetched, checked and hashed as `applyInGroups`
|
|
17
|
+
// does it (read-ahead against the memory budget), and each operation is
|
|
18
|
+
// appended to the stage table of its key range ("bucket": a range of the
|
|
19
|
+
// first digits of the key's hash). Appending to P tables is sequential
|
|
20
|
+
// writing; nothing touches `records`.
|
|
21
|
+
// 2. Apply. One bucket at a time, in one transaction: the keys that have one
|
|
22
|
+
// operation, an upsert (nearly all of a first import), merge in one batch
|
|
23
|
+
// that the merge reads in key order; the keys that have several or a
|
|
24
|
+
// deletion go through the same statements a segment-by-segment load uses,
|
|
25
|
+
// one position at a time, so what the merge does for them is not
|
|
26
|
+
// re-derived here. The bucket's stage table is dropped in the same
|
|
27
|
+
// transaction.
|
|
28
|
+
//
|
|
29
|
+
// Why it is the same fold: an operation changes only its own key's row and
|
|
30
|
+
// tombstone, so keys are independent and a key's operations apply in position
|
|
31
|
+
// order in both. What differs is the order in which two keys are written, so
|
|
32
|
+
// `record_changes` holds the same changes per key in another order across keys.
|
|
33
|
+
// The model: `KeyedLoad` and `KeyedPublish` in docs/formal/log-protocol.
|
|
34
|
+
//
|
|
35
|
+
// How many buckets is not a number here: the rows of a bucket are in the stage
|
|
36
|
+
// table and in `temp.incoming` while it applies, so a bucket is half the
|
|
37
|
+
// memory budget, and the buckets are the log's bytes over that (`keyedBuckets`).
|
|
38
|
+
// A log that fits in the budget has one commit's worth of rows and gains
|
|
39
|
+
// nothing from this: it takes the pass of `applyInGroups`.
|
|
40
|
+
//
|
|
41
|
+
// What a stopped load leaves. Each bucket's commit makes its rows and
|
|
42
|
+
// tombstones durable in `records` and `log_tombstones`, but the streams have no
|
|
43
|
+
// version row, so no reader serves them, and the cursor is where it was. Those
|
|
44
|
+
// rows are bound to the position the load meant to publish: bucket 0's commit
|
|
45
|
+
// also writes `log_keyed_pending` (that position, the base and the segment
|
|
46
|
+
// refs), and the commit that publishes deletes it. A retry may publish only a
|
|
47
|
+
// target that `pendingAdmits` accepts (same base, no shorter, same data hashes
|
|
48
|
+
// at the pending refs): a retry that can fetch fewer segments than the stopped
|
|
49
|
+
// load wrote would otherwise publish rows from beyond its cursor. A refused
|
|
50
|
+
// retry writes nothing and raises. While the marker exists and the log can
|
|
51
|
+
// still finish it, `applyLog` takes this path whatever the flags say. A log
|
|
52
|
+
// that cannot (a snapshot, a compaction, a different log) has no key-ordered
|
|
53
|
+
// load that could finish what was written, and the rows left cannot be told
|
|
54
|
+
// apart from rows of the live log: `applyLog` rebaselines (below). The marker holds back every other way to move the
|
|
55
|
+
// position, not only the load plan: the lifetime branches of `applyLog` (a log
|
|
56
|
+
// read as ended, a log of an earlier lifetime) write a cursor without applying
|
|
57
|
+
// anything, and a device that holds a cursor above 0 beside the marker is not
|
|
58
|
+
// one this load made, so each of them raises with the marker kept. The model:
|
|
59
|
+
// `KeyedBucket`, `KeyedPage`, `PendingAdmits`, `NoPending`.
|
|
60
|
+
//
|
|
61
|
+
// The way out. A log that compacted, or was rewritten, after a stopped load has
|
|
62
|
+
// nothing a key-ordered load can finish, and the rows the stopped load left are
|
|
63
|
+
// not told apart from rows of the live log (no per-key record says which
|
|
64
|
+
// position wrote a row). `keyedLoadBlocked` names that case (a snapshot, no
|
|
65
|
+
// segment past the marker, the flag off, another base, another segment at a
|
|
66
|
+
// position the marker names) and `rebaselineKeyedLoad` ends it: in one batch it
|
|
67
|
+
// drops the rows the load wrote, the log's tombstones and the marker, and the
|
|
68
|
+
// first load restarts from the log as it is now. A device that holds nothing
|
|
69
|
+
// of the log's streams (no cursor, no stream version) loses nothing the log
|
|
70
|
+
// does not hold; what is kept is the rows of a local write the device has not
|
|
71
|
+
// published (below). A log that only reads short (a segment that cannot be
|
|
72
|
+
// fetched now, a registry that lags) is not this case: the marker stands and
|
|
73
|
+
// the retry is refused until the log is whole, as `pendingAdmits` says. The
|
|
74
|
+
// model: `Rebaseline`, `Unfinishable`, and `EventuallyConverged` in
|
|
75
|
+
// docs/formal/log-protocol.
|
|
76
|
+
//
|
|
77
|
+
// A segment that cannot be fetched ends staging there: if no bucket has
|
|
78
|
+
// committed yet, the segments before it load, the cursor stands at the last of
|
|
79
|
+
// them, and the error is raised, as it is when they apply one by one.
|
|
80
|
+
//
|
|
81
|
+
// What a bucket holds. Its simple keys (one upsert) merge from the stage table
|
|
82
|
+
// in SQL, so they hold nothing in memory. Its complex keys (several operations,
|
|
83
|
+
// deletes, omissions) are read into memory to build statements. `STAGE_ROW_BYTES`
|
|
84
|
+
// counts every row by what it holds (key, hash and body in UTF-8 bytes, NULL
|
|
85
|
+
// bodies and tombstone rows included), and a bucket whose complex rows exceed
|
|
86
|
+
// the room is applied a page at a time (`complexPages`: a hash range, or a
|
|
87
|
+
// position slice of one key), each page in its own commit. This is weighted
|
|
88
|
+
// in-flight accounting against the governor's budget, not a hard memory bound:
|
|
89
|
+
// the SQLite driver and the statements a page builds are not counted, and a
|
|
90
|
+
// page is held at twice its row bytes to cover them.
|
|
91
|
+
import { sha256 } from "@noble/hashes/sha2";
|
|
92
|
+
import { followMeta, toHex, } from "@opendatalabs/personal-server-ts-stream-sync";
|
|
93
|
+
import { withOrigin } from "./merge.js";
|
|
94
|
+
import { applyInGroups, rowsPerStatement, commitStaged, mergeStaged, operationStatements, prepareOperations, streamHeadStatements, streamStateStatement, } from "./log-batch.js";
|
|
95
|
+
import { clearKeyedPending, LogDivergedError, readKeyedPending, writeKeyedPending, writeLogState, } from "./log-state.js";
|
|
96
|
+
import { holdMemory } from "./transfer-memory.js";
|
|
97
|
+
/**
|
|
98
|
+
* Hex digits of a key's hash that place it in a bucket. The count of buckets
|
|
99
|
+
* is the log's bytes over half the memory budget (`keyedBuckets`) and is capped
|
|
100
|
+
* by the key space, 16^PLACING_DIGITS, which is also the most stage tables a
|
|
101
|
+
* load can create. With 4 digits the cap is 65,536 tables, reached only by a
|
|
102
|
+
* log of `32,768 x budget` bytes, so the cap never decides the plan for a log
|
|
103
|
+
* a device can hold; a fifth digit would only raise a table-count ceiling that
|
|
104
|
+
* no log reaches, while 3 (4,096) would cap a log of `2,048 x budget`. A key's
|
|
105
|
+
* hash is uniform, so a range holds its share of the bytes within the variance
|
|
106
|
+
* of that many keys, not by construction.
|
|
107
|
+
*/
|
|
108
|
+
const PLACING_DIGITS = 4;
|
|
109
|
+
const KEY_SPACE = 16 ** PLACING_DIGITS;
|
|
110
|
+
/**
|
|
111
|
+
* How many key ranges a log of `totalBytes` splits into so that one range
|
|
112
|
+
* (twice: its stage rows and the rows being merged) fits in the memory budget.
|
|
113
|
+
*/
|
|
114
|
+
export function keyedBuckets(segmentBytes, budgetBytes) {
|
|
115
|
+
const total = segmentBytes.reduce((sum, bytes) => sum + bytes, 0);
|
|
116
|
+
// A budget under two segments (the read-ahead holds a segment as plain and
|
|
117
|
+
// as encrypted bytes) still admits one alone, so a range holds one at least.
|
|
118
|
+
const room = Math.max(budgetBytes, 2 * Math.max(0, ...segmentBytes));
|
|
119
|
+
return Math.min(KEY_SPACE, Math.max(1, Math.ceil((2 * total) / room)));
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Whether this pass loads key by key, and into how many ranges. It does when
|
|
123
|
+
* the device holds nothing of the log's streams (no stream version, so no
|
|
124
|
+
* reader serves a row, and no position) and the log is more than the memory
|
|
125
|
+
* budget can apply in one commit. Not with a snapshot: its parts are
|
|
126
|
+
* key-ordered already and load as they are.
|
|
127
|
+
*
|
|
128
|
+
* A host that shows a stream while it loads (`progressiveFirstLoad`) loads
|
|
129
|
+
* key by key too. Segment by segment, each commit rewrites most of the table
|
|
130
|
+
* (see the top of this file): on the Web's OPFS a 198,001-row log took 378 s
|
|
131
|
+
* that way and 26 s key by key, and the rows the progressive load would show
|
|
132
|
+
* meanwhile reach no listing, which serves a stream only once its head is
|
|
133
|
+
* complete. The key-ordered load shows the streams when its last range
|
|
134
|
+
* commits.
|
|
135
|
+
*/
|
|
136
|
+
export async function planKeyedLoad(deps, connectionId, local, snapshotPresent, tail, pending = null) {
|
|
137
|
+
const buckets = keyedBuckets(tail.map((ref) => ref.bytes), deps.blobs.governor.limitBytes);
|
|
138
|
+
if (pending !== null) {
|
|
139
|
+
// An unfinished key-ordered load left rows in `records` that only a
|
|
140
|
+
// key-ordered load that covers them may publish over. The rest of the
|
|
141
|
+
// gate (a flag, the size of the log) decided how the first attempt began;
|
|
142
|
+
// it does not decide how to end it. `applyLog` rebaselines a connection
|
|
143
|
+
// whose log cannot finish it (`keyedLoadBlocked`) before it gets here, so
|
|
144
|
+
// this refusal holds the line for any other caller.
|
|
145
|
+
if (snapshotPresent || tail.length === 0 || deps.keyedFirstLoad === false)
|
|
146
|
+
throw unfinishedKeyedLoad(pending, snapshotPresent
|
|
147
|
+
? "the log has a snapshot now"
|
|
148
|
+
: tail.length === 0
|
|
149
|
+
? "the log holds no segment past it"
|
|
150
|
+
: "the key-ordered first load is off");
|
|
151
|
+
return buckets;
|
|
152
|
+
}
|
|
153
|
+
if (deps.keyedFirstLoad === false ||
|
|
154
|
+
snapshotPresent ||
|
|
155
|
+
local.position !== 0 ||
|
|
156
|
+
tail.length < 2)
|
|
157
|
+
return null;
|
|
158
|
+
if (buckets < 2)
|
|
159
|
+
return null;
|
|
160
|
+
const [held] = await deps.db.query("SELECT COUNT(*) AS n FROM (SELECT 1 FROM stream_versions WHERE connection_id = ? LIMIT 1)", [connectionId]);
|
|
161
|
+
return held?.n === 0 ? buckets : null;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* The refusal of every path that cannot finish an unfinished key-ordered load
|
|
165
|
+
* of this connection and may not drop it. Its rows are in `records` and
|
|
166
|
+
* `log_tombstones` and belong to no published position; the way out is a
|
|
167
|
+
* key-ordered load of the same log, or `rebaselineKeyedLoad` when the log can
|
|
168
|
+
* no longer be one.
|
|
169
|
+
*/
|
|
170
|
+
export function unfinishedKeyedLoad(pending, why) {
|
|
171
|
+
return new LogDivergedError(`apply: an earlier key-ordered load of this connection wrote rows up to position ${pending.position} and did not finish; only a key-ordered load of the same log can finish it, or a rebaseline (${why})`);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Whether the rows an unfinished key-ordered load left (`pending`) lie inside
|
|
175
|
+
* the prefix that a load ending at `target` publishes: the same log (the same
|
|
176
|
+
* segment at every position they name) and no shorter. A load that holds less
|
|
177
|
+
* (a segment it cannot fetch now) must leave the cursor where it is, because
|
|
178
|
+
* the rows beyond it would become visible, or hide a row of the prefix, under
|
|
179
|
+
* a cursor that does not cover them.
|
|
180
|
+
*/
|
|
181
|
+
export function pendingAdmits(pending, target) {
|
|
182
|
+
if (pending === null)
|
|
183
|
+
return true;
|
|
184
|
+
if (pending.base !== target.base || pending.position > target.position)
|
|
185
|
+
return false;
|
|
186
|
+
const hashes = new Map(target.refs.map((ref) => [ref.position, ref.dataHash.toLowerCase()]));
|
|
187
|
+
return pending.refs.every((ref) => hashes.get(ref.position) === ref.dataHash.toLowerCase());
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Why no key-ordered load of this log can finish the one that stopped (the
|
|
191
|
+
* marker `pending`), or `null` when one still can. `target` is the state the
|
|
192
|
+
* load would publish: the last segment of the plan, or `null` when the plan
|
|
193
|
+
* holds none.
|
|
194
|
+
*
|
|
195
|
+
* Blocked: the load is off, the plan starts from a snapshot, the plan holds no
|
|
196
|
+
* segment, the log's base is not the one the rows were written under, or the
|
|
197
|
+
* log names another segment at a position the marker names. A log that holds
|
|
198
|
+
* the marker's prefix and is only shorter (a lagging registry) is not blocked:
|
|
199
|
+
* the load that cannot fetch the whole prefix is refused by `pendingAdmits`
|
|
200
|
+
* with the marker kept, and ends when the log is whole.
|
|
201
|
+
*/
|
|
202
|
+
export function keyedLoadBlocked(deps, pending, plan) {
|
|
203
|
+
if (deps.keyedFirstLoad === false)
|
|
204
|
+
return "the key-ordered first load is off";
|
|
205
|
+
if (plan.snapshotPresent)
|
|
206
|
+
return "the log has a snapshot now";
|
|
207
|
+
const { target } = plan;
|
|
208
|
+
if (target === null)
|
|
209
|
+
return "the log holds no segment past the marker";
|
|
210
|
+
if (pending.base !== target.base)
|
|
211
|
+
return "the log's base moved";
|
|
212
|
+
const named = new Map(target.refs.map((ref) => [ref.position, ref.dataHash.toLowerCase()]));
|
|
213
|
+
for (const ref of pending.refs) {
|
|
214
|
+
const hash = named.get(ref.position);
|
|
215
|
+
if (hash === undefined
|
|
216
|
+
? target.position >= ref.position
|
|
217
|
+
: hash !== ref.dataHash.toLowerCase())
|
|
218
|
+
return "the log names another segment than the rows were written from";
|
|
219
|
+
}
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* End an unfinished key-ordered load that no load can finish (`keyedLoadBlocked`):
|
|
224
|
+
* in ONE batch (a failing statement rolls all back, so the marker never
|
|
225
|
+
* outlives the decision to drop its rows), delete the rows the load wrote, the
|
|
226
|
+
* log's tombstones and the marker, as `purgeConnection` does for the rows of a
|
|
227
|
+
* lifetime. The cursor is at 0 by the marker's invariant (the commit that
|
|
228
|
+
* writes it also clears the marker), so its row is deleted as well.
|
|
229
|
+
*
|
|
230
|
+
* What stays is every row that is the newest local write of its key the
|
|
231
|
+
* device has not published (a `record_changes` upsert of origin `local`,
|
|
232
|
+
* `import` or `refresh` past the stream's `publish_watermark`, at the row's own
|
|
233
|
+
* stamp: the test `mergeIncoming` uses to keep a key an omission names). Those
|
|
234
|
+
* writes exist nowhere else. The retry loads the log's rows under them, and
|
|
235
|
+
* the merge is order-insensitive per key, so the result is the one a device
|
|
236
|
+
* that held the write before the log would have. Streams' rows (`stream_state`,
|
|
237
|
+
* with the watermarks), `record_tombstones` and `record_changes` are not touched.
|
|
238
|
+
*/
|
|
239
|
+
export async function rebaselineKeyedLoad(deps, connectionId, why) {
|
|
240
|
+
const { changes } = await deps.db.batch(withOrigin("purge", [
|
|
241
|
+
{
|
|
242
|
+
sql: `DELETE FROM records
|
|
243
|
+
WHERE connection_id = ?
|
|
244
|
+
AND NOT EXISTS (
|
|
245
|
+
SELECT 1 FROM record_changes ch
|
|
246
|
+
WHERE ch.connection_id = records.connection_id
|
|
247
|
+
AND ch.stream = records.stream
|
|
248
|
+
AND ch.pk_hash = records.pk_hash
|
|
249
|
+
AND ch.origin IN ('local','import','refresh')
|
|
250
|
+
AND ch.op = 'upsert'
|
|
251
|
+
AND ch.stamp_o = records.stamp_o
|
|
252
|
+
AND ch.stamp_r = records.stamp_r
|
|
253
|
+
AND ch.seq > COALESCE(
|
|
254
|
+
(SELECT s.publish_watermark FROM stream_state s
|
|
255
|
+
WHERE s.connection_id = ch.connection_id AND s.stream = ch.stream), 0))`,
|
|
256
|
+
params: [connectionId],
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
sql: "DELETE FROM log_tombstones WHERE connection_id = ?",
|
|
260
|
+
params: [connectionId],
|
|
261
|
+
},
|
|
262
|
+
clearKeyedPending(connectionId),
|
|
263
|
+
{
|
|
264
|
+
sql: "DELETE FROM log_state WHERE connection_id = ?",
|
|
265
|
+
params: [connectionId],
|
|
266
|
+
},
|
|
267
|
+
]));
|
|
268
|
+
deps.logger.info({ connectionId, why, rowsDropped: changes[1] }, "rebaseline unfinished key-ordered load");
|
|
269
|
+
}
|
|
270
|
+
/** The stage tables of one connection: its id hashed, so any id is a name. */
|
|
271
|
+
const tagOf = (connectionId) => toHex(sha256(new TextEncoder().encode(connectionId)));
|
|
272
|
+
const stageTable = (tag, bucket) => `log_stage_${tag}_${bucket}`;
|
|
273
|
+
const bucketOf = (pkHash, buckets) => Math.floor((Number.parseInt(pkHash.slice(0, PLACING_DIGITS), 16) * buckets) /
|
|
274
|
+
KEY_SPACE);
|
|
275
|
+
const STAGE_COLUMNS = "position, kind, stream, pk_hash, record_key, stamp_o, stamp_r, body, body_sha256, first_o, stamp_n";
|
|
276
|
+
/**
|
|
277
|
+
* The keys of a stage table that are not one upsert: written more than once, or
|
|
278
|
+
* deleted or omitted. Those apply through the statements of a segment, one
|
|
279
|
+
* position at a time.
|
|
280
|
+
*/
|
|
281
|
+
const complexKeys = (table) => `SELECT stream, pk_hash FROM ${table} GROUP BY stream, pk_hash
|
|
282
|
+
HAVING COUNT(*) > 1 OR MAX(kind <> 'u')`;
|
|
283
|
+
async function dropStages(deps, tag) {
|
|
284
|
+
const stale = await deps.db.query("SELECT name FROM sqlite_master WHERE type = 'table' AND name LIKE ? ESCAPE '\\'", [`log\\_stage\\_${tag}\\_%`]);
|
|
285
|
+
if (stale.length > 0)
|
|
286
|
+
await deps.db.batch(stale.map(({ name }) => ({
|
|
287
|
+
sql: `DROP TABLE IF EXISTS ${name}`,
|
|
288
|
+
params: [],
|
|
289
|
+
})));
|
|
290
|
+
}
|
|
291
|
+
/** Variables a stage row binds. */
|
|
292
|
+
const STAGE_FIELDS = STAGE_COLUMNS.split(",").length;
|
|
293
|
+
/**
|
|
294
|
+
* The rows a batch's operations add to the stage tables, each in its key's
|
|
295
|
+
* bucket. A bucket's rows go in multi-row inserts, in the order they came: a
|
|
296
|
+
* statement costs the host a call, a row is a few variables.
|
|
297
|
+
*/
|
|
298
|
+
function stageStatements(tag, buckets, position, operations) {
|
|
299
|
+
const rowsOf = new Map();
|
|
300
|
+
const add = (kind, stream, pkHash, recordKey, stampO, stampR, upsert) => {
|
|
301
|
+
const bucket = bucketOf(pkHash, buckets);
|
|
302
|
+
const row = [
|
|
303
|
+
position,
|
|
304
|
+
kind,
|
|
305
|
+
stream,
|
|
306
|
+
pkHash,
|
|
307
|
+
recordKey,
|
|
308
|
+
stampO,
|
|
309
|
+
stampR,
|
|
310
|
+
upsert?.body ?? null,
|
|
311
|
+
upsert?.bodySha256 ?? null,
|
|
312
|
+
upsert?.firstO ?? null,
|
|
313
|
+
upsert?.ordinal ?? 0,
|
|
314
|
+
];
|
|
315
|
+
const rows = rowsOf.get(bucket);
|
|
316
|
+
if (rows)
|
|
317
|
+
rows.push(row);
|
|
318
|
+
else
|
|
319
|
+
rowsOf.set(bucket, [row]);
|
|
320
|
+
};
|
|
321
|
+
for (const operation of operations) {
|
|
322
|
+
if (operation.kind === "upsert")
|
|
323
|
+
add("u", operation.stream, operation.pkHash, operation.recordKey, operation.stampO, operation.stampR, operation);
|
|
324
|
+
else if (operation.kind === "complete")
|
|
325
|
+
for (const omission of operation.omitted)
|
|
326
|
+
add("o", operation.stream, omission.pkHash, omission.recordKey, operation.stampO, operation.stampR);
|
|
327
|
+
else
|
|
328
|
+
add(operation.kind === "delete" ? "d" : "o", operation.stream, operation.pkHash, operation.recordKey, operation.stampO, operation.stampR);
|
|
329
|
+
}
|
|
330
|
+
const perStatement = rowsPerStatement(STAGE_FIELDS);
|
|
331
|
+
const statements = [];
|
|
332
|
+
for (const [bucket, rows] of rowsOf)
|
|
333
|
+
for (let i = 0; i < rows.length; i += perStatement) {
|
|
334
|
+
const group = rows.slice(i, i + perStatement);
|
|
335
|
+
statements.push({
|
|
336
|
+
sql: `INSERT INTO ${stageTable(tag, bucket)} (${STAGE_COLUMNS}) VALUES ${group
|
|
337
|
+
.map(() => `(${"?, ".repeat(STAGE_FIELDS - 1)}?)`)
|
|
338
|
+
.join(", ")}`,
|
|
339
|
+
params: group.flat(),
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
return statements;
|
|
343
|
+
}
|
|
344
|
+
/** A stage row as the operation it stands for. */
|
|
345
|
+
function operationOf(row) {
|
|
346
|
+
if (row.kind === "u")
|
|
347
|
+
return {
|
|
348
|
+
kind: "upsert",
|
|
349
|
+
stream: row.stream,
|
|
350
|
+
pkHash: row.pk_hash,
|
|
351
|
+
recordKey: row.record_key,
|
|
352
|
+
stampO: row.stamp_o,
|
|
353
|
+
stampR: row.stamp_r,
|
|
354
|
+
body: row.body,
|
|
355
|
+
bodySha256: row.body_sha256,
|
|
356
|
+
firstO: row.first_o,
|
|
357
|
+
ordinal: row.stamp_n,
|
|
358
|
+
};
|
|
359
|
+
return {
|
|
360
|
+
kind: row.kind === "d" ? "delete" : "omitted",
|
|
361
|
+
stream: row.stream,
|
|
362
|
+
pkHash: row.pk_hash,
|
|
363
|
+
recordKey: row.record_key,
|
|
364
|
+
stampO: row.stamp_o,
|
|
365
|
+
stampR: row.stamp_r,
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Load `sources` (the segments after the device's position, in order) key by
|
|
370
|
+
* key into `buckets` key ranges, and move the cursor to the last one loaded.
|
|
371
|
+
* Throws the error that ended the staging, after loading what came before it.
|
|
372
|
+
*/
|
|
373
|
+
export async function loadKeyed(deps, connectionId, sources, buckets) {
|
|
374
|
+
const tag = tagOf(connectionId);
|
|
375
|
+
await dropStages(deps, tag);
|
|
376
|
+
try {
|
|
377
|
+
await deps.db.batch([
|
|
378
|
+
{
|
|
379
|
+
sql: `CREATE TEMP TABLE IF NOT EXISTS log_complex (stream TEXT NOT NULL, pk_hash TEXT NOT NULL,
|
|
380
|
+
PRIMARY KEY (stream, pk_hash)) WITHOUT ROWID`,
|
|
381
|
+
params: [],
|
|
382
|
+
},
|
|
383
|
+
...Array.from({ length: buckets }, (_, bucket) => ({
|
|
384
|
+
sql: `CREATE TABLE ${stageTable(tag, bucket)} (position INTEGER NOT NULL, kind TEXT NOT NULL,
|
|
385
|
+
stream TEXT NOT NULL, pk_hash TEXT NOT NULL, record_key TEXT NOT NULL,
|
|
386
|
+
stamp_o INTEGER NOT NULL, stamp_r TEXT NOT NULL, body TEXT, body_sha256 TEXT, first_o INTEGER,
|
|
387
|
+
stamp_n INTEGER NOT NULL DEFAULT 0)`,
|
|
388
|
+
params: [],
|
|
389
|
+
})),
|
|
390
|
+
]);
|
|
391
|
+
// Phase 1: stage.
|
|
392
|
+
const infos = [];
|
|
393
|
+
const items = sources.map((source, position) => ({
|
|
394
|
+
bytes: source.bytes,
|
|
395
|
+
stage: async () => {
|
|
396
|
+
const { batch, identity } = await source.load();
|
|
397
|
+
const operations = await prepareOperations(batch.streams, batch.operations);
|
|
398
|
+
// Only what the heads need: the operations are not kept.
|
|
399
|
+
infos[position] = {
|
|
400
|
+
streams: batch.streams,
|
|
401
|
+
generation: batch.generation,
|
|
402
|
+
observedAt: batch.observedAt,
|
|
403
|
+
identity,
|
|
404
|
+
};
|
|
405
|
+
return {
|
|
406
|
+
op: deps.newOp(),
|
|
407
|
+
statements: stageStatements(tag, buckets, position, operations),
|
|
408
|
+
};
|
|
409
|
+
},
|
|
410
|
+
}));
|
|
411
|
+
let staged = 0;
|
|
412
|
+
let stopped;
|
|
413
|
+
try {
|
|
414
|
+
await applyInGroups(deps, items, {
|
|
415
|
+
firstAlone: false,
|
|
416
|
+
onCommit: (_first, last) => {
|
|
417
|
+
staged = last + 1;
|
|
418
|
+
},
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
catch (error) {
|
|
422
|
+
stopped = { error };
|
|
423
|
+
}
|
|
424
|
+
if (staged === 0)
|
|
425
|
+
throw stopped?.error;
|
|
426
|
+
// Phase 2: apply, one bucket per transaction.
|
|
427
|
+
const heads = new Map();
|
|
428
|
+
const primaryKeys = new Map();
|
|
429
|
+
for (const info of infos.slice(0, staged))
|
|
430
|
+
for (const meta of info.streams) {
|
|
431
|
+
if (!primaryKeys.has(meta.stream))
|
|
432
|
+
primaryKeys.set(meta.stream, meta);
|
|
433
|
+
heads.set(meta.stream, {
|
|
434
|
+
...info,
|
|
435
|
+
meta: followMeta(heads.get(meta.stream)?.meta, meta),
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
const last = sources[staged - 1].state;
|
|
439
|
+
// What an unfinished load of this connection wrote must lie inside the
|
|
440
|
+
// prefix this one publishes; if it does not, write nothing.
|
|
441
|
+
if (!pendingAdmits(await readKeyedPending(deps, connectionId), last)) {
|
|
442
|
+
if (stopped)
|
|
443
|
+
throw stopped.error;
|
|
444
|
+
throw new LogDivergedError("apply: the log is not the one an earlier key-ordered load of this connection wrote rows from");
|
|
445
|
+
}
|
|
446
|
+
for (let bucket = 0; bucket < buckets; bucket++)
|
|
447
|
+
await applyBucket(deps, connectionId, tag, bucket, {
|
|
448
|
+
// The first range creates the streams' rows and names the position
|
|
449
|
+
// the rows it and the later ranges write belong to.
|
|
450
|
+
first: bucket === 0
|
|
451
|
+
? { primaryKeys: [...primaryKeys.values()], target: last }
|
|
452
|
+
: undefined,
|
|
453
|
+
last: bucket === buckets - 1
|
|
454
|
+
? { heads: [...heads.values()], state: last }
|
|
455
|
+
: undefined,
|
|
456
|
+
});
|
|
457
|
+
if (stopped)
|
|
458
|
+
throw stopped.error;
|
|
459
|
+
}
|
|
460
|
+
finally {
|
|
461
|
+
await dropStages(deps, tag).catch(() => undefined);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* What a stage row holds in memory, in bytes: every text field as UTF-8 (a
|
|
466
|
+
* body or a key of non-ASCII text is more bytes than characters) and each
|
|
467
|
+
* number as 8. A deletion or an omission has no body and still holds its keys.
|
|
468
|
+
*/
|
|
469
|
+
const STAGE_ROW_BYTES = `(
|
|
470
|
+
LENGTH(CAST(kind AS BLOB)) + LENGTH(CAST(stream AS BLOB)) + LENGTH(CAST(pk_hash AS BLOB))
|
|
471
|
+
+ LENGTH(CAST(record_key AS BLOB)) + LENGTH(CAST(stamp_r AS BLOB))
|
|
472
|
+
+ COALESCE(LENGTH(CAST(body AS BLOB)), 0) + COALESCE(LENGTH(CAST(body_sha256 AS BLOB)), 0)
|
|
473
|
+
+ 4 * 8)`;
|
|
474
|
+
const PAGE_FILTER = "pk_hash >= ? AND pk_hash < ? AND position BETWEEN ? AND ?";
|
|
475
|
+
const pageParams = (page) => [
|
|
476
|
+
page.from,
|
|
477
|
+
page.to,
|
|
478
|
+
page.firstPosition,
|
|
479
|
+
page.lastPosition,
|
|
480
|
+
];
|
|
481
|
+
async function weighPage(deps, table, page) {
|
|
482
|
+
const [weight] = await deps.db.query(`SELECT COUNT(*) AS n, COALESCE(SUM(${STAGE_ROW_BYTES}), 0) AS bytes
|
|
483
|
+
FROM ${table} WHERE ${PAGE_FILTER}
|
|
484
|
+
AND (stream, pk_hash) IN (${complexKeys(table)})`, pageParams(page));
|
|
485
|
+
return weight;
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* The slices the complex rows of a bucket are applied in, each holding at most
|
|
489
|
+
* `room` bytes (as `weighPage` counts them, twice: the rows and the statements
|
|
490
|
+
* made from them). One slice for a bucket that fits, which is nearly always: the
|
|
491
|
+
* bucket count already divides the log's bytes by the budget. A bucket whose
|
|
492
|
+
* keys cluster (their hashes share a prefix) splits by the next hex digit of
|
|
493
|
+
* the hash until each piece fits. A single key whose operations are over the
|
|
494
|
+
* room splits by position: its operations apply in position order, and a slice
|
|
495
|
+
* is a run of them.
|
|
496
|
+
*/
|
|
497
|
+
export async function complexPages(deps, table, room) {
|
|
498
|
+
const all = {
|
|
499
|
+
from: "",
|
|
500
|
+
to: "g",
|
|
501
|
+
firstPosition: 0,
|
|
502
|
+
lastPosition: Number.MAX_SAFE_INTEGER,
|
|
503
|
+
bytes: 0,
|
|
504
|
+
};
|
|
505
|
+
const split = async (prefix) => {
|
|
506
|
+
const page = { ...all, from: prefix, to: `${prefix}g` };
|
|
507
|
+
const weight = await weighPage(deps, table, page);
|
|
508
|
+
if (weight.n === 0)
|
|
509
|
+
return [];
|
|
510
|
+
if (2 * weight.bytes <= room)
|
|
511
|
+
return [{ ...page, bytes: weight.bytes }];
|
|
512
|
+
if (prefix.length < 64) {
|
|
513
|
+
const pieces = [];
|
|
514
|
+
for (const digit of "0123456789abcdef")
|
|
515
|
+
pieces.push(...(await split(prefix + digit)));
|
|
516
|
+
return pieces;
|
|
517
|
+
}
|
|
518
|
+
// One key: slice its positions.
|
|
519
|
+
const byPosition = await deps.db.query(`SELECT position, SUM(${STAGE_ROW_BYTES}) AS bytes FROM ${table}
|
|
520
|
+
WHERE pk_hash = ? AND (stream, pk_hash) IN (${complexKeys(table)})
|
|
521
|
+
GROUP BY position ORDER BY position`, [prefix]);
|
|
522
|
+
const slices = [];
|
|
523
|
+
let start = byPosition[0].position;
|
|
524
|
+
let held = 0;
|
|
525
|
+
for (const { position, bytes } of byPosition) {
|
|
526
|
+
if (held > 0 && 2 * (held + bytes) > room) {
|
|
527
|
+
slices.push({
|
|
528
|
+
...page,
|
|
529
|
+
firstPosition: start,
|
|
530
|
+
lastPosition: position - 1,
|
|
531
|
+
bytes: held,
|
|
532
|
+
});
|
|
533
|
+
start = position;
|
|
534
|
+
held = 0;
|
|
535
|
+
}
|
|
536
|
+
held += bytes;
|
|
537
|
+
}
|
|
538
|
+
slices.push({
|
|
539
|
+
...page,
|
|
540
|
+
firstPosition: start,
|
|
541
|
+
lastPosition: Number.MAX_SAFE_INTEGER,
|
|
542
|
+
bytes: held,
|
|
543
|
+
});
|
|
544
|
+
return slices;
|
|
545
|
+
};
|
|
546
|
+
return split("");
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* One key range. A bucket whose complex rows fit the memory budget commits in
|
|
550
|
+
* one transaction. The single-upsert keys merge in one batch from the stage
|
|
551
|
+
* table; the others (see `complexKeys`) apply as the segments they came from,
|
|
552
|
+
* in position order, restricted to these keys. A bucket whose complex rows do
|
|
553
|
+
* not fit commits the single-upsert keys first, then the complex rows a page
|
|
554
|
+
* at a time (`complexPages`), then the clean-up: the rows are held in memory
|
|
555
|
+
* for a page, not for the bucket.
|
|
556
|
+
*/
|
|
557
|
+
async function applyBucket(deps, connectionId, tag, bucket, edges) {
|
|
558
|
+
const table = stageTable(tag, bucket);
|
|
559
|
+
const pages = await complexPages(deps, table, deps.blobs.governor.limitBytes);
|
|
560
|
+
const simpleOp = deps.newOp();
|
|
561
|
+
const simple = [
|
|
562
|
+
...(edges.first
|
|
563
|
+
? [
|
|
564
|
+
// In the commit of the first rows the load writes, or before it: the
|
|
565
|
+
// position those rows lie within. A load that is one commit has no
|
|
566
|
+
// rows to fence.
|
|
567
|
+
...(edges.last && pages.length <= 1
|
|
568
|
+
? []
|
|
569
|
+
: [writeKeyedPending(connectionId, edges.first.target)]),
|
|
570
|
+
...edges.first.primaryKeys.map((meta) => streamStateStatement(connectionId, meta)),
|
|
571
|
+
]
|
|
572
|
+
: []),
|
|
573
|
+
{ sql: `INSERT INTO temp.log_complex ${complexKeys(table)}`, params: [] },
|
|
574
|
+
{
|
|
575
|
+
sql: `INSERT INTO temp.incoming (op, stream, pk_hash, record_key, stamp_o, stamp_r, body, body_sha256, first_o, stamp_n)
|
|
576
|
+
SELECT ?, stream, pk_hash, record_key, stamp_o, stamp_r, body, body_sha256, first_o, stamp_n
|
|
577
|
+
FROM ${table} s
|
|
578
|
+
WHERE s.kind = 'u' AND NOT EXISTS (
|
|
579
|
+
SELECT 1 FROM temp.log_complex c WHERE c.stream = s.stream AND c.pk_hash = s.pk_hash)`,
|
|
580
|
+
params: [simpleOp],
|
|
581
|
+
},
|
|
582
|
+
...mergeStaged(connectionId, simpleOp),
|
|
583
|
+
{ sql: "DELETE FROM temp.log_complex", params: [] },
|
|
584
|
+
];
|
|
585
|
+
const closing = [{ sql: `DROP TABLE ${table}`, params: [] }];
|
|
586
|
+
if (edges.last) {
|
|
587
|
+
for (const head of edges.last.heads)
|
|
588
|
+
closing.push(...streamHeadStatements(connectionId, [head.meta], head, head.identity));
|
|
589
|
+
closing.push(writeLogState(connectionId, edges.last.state), clearKeyedPending(connectionId));
|
|
590
|
+
}
|
|
591
|
+
// The complex rows of a page, as the batches that apply them: one per
|
|
592
|
+
// position, in position order (the rows came out in the order they were staged).
|
|
593
|
+
const batchesOf = async (page) => {
|
|
594
|
+
const rows = await deps.db.query(`SELECT ${STAGE_COLUMNS} FROM ${table}
|
|
595
|
+
WHERE ${PAGE_FILTER} AND (stream, pk_hash) IN (${complexKeys(table)}) ORDER BY rowid`, pageParams(page));
|
|
596
|
+
const byPosition = new Map();
|
|
597
|
+
for (const row of rows) {
|
|
598
|
+
const operations = byPosition.get(row.position);
|
|
599
|
+
if (operations)
|
|
600
|
+
operations.push(operationOf(row));
|
|
601
|
+
else
|
|
602
|
+
byPosition.set(row.position, [operationOf(row)]);
|
|
603
|
+
}
|
|
604
|
+
return [...byPosition.values()].map((operations) => {
|
|
605
|
+
const op = deps.newOp();
|
|
606
|
+
return {
|
|
607
|
+
op,
|
|
608
|
+
statements: operationStatements(connectionId, op, operations),
|
|
609
|
+
};
|
|
610
|
+
});
|
|
611
|
+
};
|
|
612
|
+
// The rows of a page and the statements made from them: twice its bytes.
|
|
613
|
+
const hold = (page) => holdMemory(deps.blobs, 2 * page.bytes, 0);
|
|
614
|
+
if (pages.length <= 1) {
|
|
615
|
+
const release = pages[0] ? await hold(pages[0]) : undefined;
|
|
616
|
+
try {
|
|
617
|
+
await commitStaged(deps, [
|
|
618
|
+
{ op: simpleOp, statements: simple },
|
|
619
|
+
...(pages[0] ? await batchesOf(pages[0]) : []),
|
|
620
|
+
{ op: deps.newOp(), statements: closing },
|
|
621
|
+
]);
|
|
622
|
+
}
|
|
623
|
+
finally {
|
|
624
|
+
release?.();
|
|
625
|
+
}
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
628
|
+
await commitStaged(deps, [{ op: simpleOp, statements: simple }]);
|
|
629
|
+
for (const page of pages) {
|
|
630
|
+
const release = await hold(page);
|
|
631
|
+
try {
|
|
632
|
+
await commitStaged(deps, await batchesOf(page));
|
|
633
|
+
}
|
|
634
|
+
finally {
|
|
635
|
+
release();
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
await commitStaged(deps, [{ op: deps.newOp(), statements: closing }]);
|
|
639
|
+
}
|
|
640
|
+
//# sourceMappingURL=log-keyed.js.map
|