@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
|
@@ -1,12 +1,80 @@
|
|
|
1
1
|
import { uploadAll } from "../workers/upload.js";
|
|
2
|
+
import { createUploadStateTracker } from "../upload-state.js";
|
|
3
|
+
import { createMemoryUploadAttemptStore, createUploadAttemptLedger, } from "../upload-attempts.js";
|
|
2
4
|
import { requeueLostDataPoints } from "../workers/lost-data-points.js";
|
|
3
5
|
import { downloadAll, downloadScopes } from "../workers/download.js";
|
|
4
6
|
import { deleteScope, retryPendingBlobDeletions, } from "../workers/delete.js";
|
|
5
7
|
import { createDownloadRetryMemory } from "../retry-memory.js";
|
|
6
8
|
import { createTombstoneResubmitTracker } from "../tombstone-resubmits.js";
|
|
9
|
+
import { changePushBackoffMs } from "./change-push.js";
|
|
7
10
|
const MAX_ERRORS = 10;
|
|
11
|
+
const DEFAULT_POLL_INTERVAL_MS = 60_000;
|
|
12
|
+
/**
|
|
13
|
+
* The longest delay a host timer holds: it keeps the delay in a signed 32-bit
|
|
14
|
+
* integer of milliseconds, and runs a longer one after 1 ms.
|
|
15
|
+
*/
|
|
16
|
+
const MAX_TIMER_DELAY_MS = 2 ** 31 - 1;
|
|
17
|
+
/**
|
|
18
|
+
* A repeating period the host timer runs as written. The timer counts whole
|
|
19
|
+
* milliseconds and runs a delay below 1 after 1 ms, so a period that is not
|
|
20
|
+
* finite or is below 1 would turn the fallback into a busy loop or never run;
|
|
21
|
+
* it takes the default. A period beyond the timer's limit is the longest
|
|
22
|
+
* period the timer holds: the caller asked for a long wait, not a short one.
|
|
23
|
+
*/
|
|
24
|
+
function timerPeriod(requested) {
|
|
25
|
+
if (typeof requested !== "number" ||
|
|
26
|
+
Number.isNaN(requested) ||
|
|
27
|
+
requested < 1 ||
|
|
28
|
+
requested === Number.POSITIVE_INFINITY) {
|
|
29
|
+
return DEFAULT_POLL_INTERVAL_MS;
|
|
30
|
+
}
|
|
31
|
+
return Math.min(Math.floor(requested), MAX_TIMER_DELAY_MS);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The connections a stream-sync cycle's report says it left work on, that
|
|
35
|
+
* nothing in the registry announces. The cycle reports per connection and does
|
|
36
|
+
* not throw: a connection that failed, or a stream whose publish backs off or
|
|
37
|
+
* waits on a condition, is tried again only by a later cycle. A position
|
|
38
|
+
* cannot stand in for that cycle, so the pass is not settled and the timer
|
|
39
|
+
* keeps running, for these connections alone (see `owedScope`). A connection
|
|
40
|
+
* whose log this build cannot read (`status: "update_required"`) owes nothing:
|
|
41
|
+
* a later cycle of this build reads the same format and refuses again, so
|
|
42
|
+
* only an update changes it, and the status shows it until then. A report of
|
|
43
|
+
* another shape says nothing and leaves nothing owed.
|
|
44
|
+
*/
|
|
45
|
+
function connectionsOwingWork(report) {
|
|
46
|
+
const connections = report
|
|
47
|
+
?.connections;
|
|
48
|
+
if (!Array.isArray(connections))
|
|
49
|
+
return [];
|
|
50
|
+
const owed = [];
|
|
51
|
+
for (const connection of connections) {
|
|
52
|
+
const { connectionId, error, published, status } = (connection ?? {});
|
|
53
|
+
if (status === "update_required")
|
|
54
|
+
continue;
|
|
55
|
+
const id = typeof connectionId === "string" ? connectionId : null;
|
|
56
|
+
if (error !== null && error !== undefined) {
|
|
57
|
+
owed.push({ connectionId: id, why: `error: ${String(error)}` });
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (!Array.isArray(published))
|
|
61
|
+
continue;
|
|
62
|
+
const waiting = published.filter((result) => result?.outcome === "backoff" || result?.outcome === "deferred");
|
|
63
|
+
if (waiting.length > 0)
|
|
64
|
+
owed.push({
|
|
65
|
+
connectionId: id,
|
|
66
|
+
why: waiting
|
|
67
|
+
.map((result) => `${String(result?.stream)}: ${result?.outcome}`)
|
|
68
|
+
.join(", "),
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return owed;
|
|
72
|
+
}
|
|
73
|
+
function errorMessage(error) {
|
|
74
|
+
return error instanceof Error ? error.message : String(error);
|
|
75
|
+
}
|
|
8
76
|
export function createSyncManager(uploadDeps, downloadDeps, options) {
|
|
9
|
-
const pollInterval = options?.pollInterval
|
|
77
|
+
const pollInterval = timerPeriod(options?.pollInterval);
|
|
10
78
|
const uploadBatchSize = options?.uploadBatchSize ?? 50;
|
|
11
79
|
const notifyDebounceMs = options?.notifyDebounceMs ?? 500;
|
|
12
80
|
const transferMode = options?.transferMode ?? "upload-download";
|
|
@@ -19,7 +87,85 @@ export function createSyncManager(uploadDeps, downloadDeps, options) {
|
|
|
19
87
|
let blocked = null;
|
|
20
88
|
let errors = [];
|
|
21
89
|
let cycleInFlight = null;
|
|
90
|
+
// The dirty follow-up flag: a request arrived that the running cycle may not
|
|
91
|
+
// have seen. It is owed one more cycle and is dropped only by running one (or
|
|
92
|
+
// by a stop). A pass clears it on entry, so it never re-arms itself.
|
|
22
93
|
let rerunRequested = false;
|
|
94
|
+
// What the running cycle owes beyond `rerunRequested`, for a request that
|
|
95
|
+
// arrived with change deltas. The next pass takes the queued deltas in
|
|
96
|
+
// order; a request without one requires a full pass instead.
|
|
97
|
+
let queuedDeltas = [];
|
|
98
|
+
let deltaBarred = false;
|
|
99
|
+
// The position the cycle in flight will settle at if it ends clean: the
|
|
100
|
+
// position its pass started under. The held request asks from it (see
|
|
101
|
+
// `since` in `startChangePush`), so a change that lands during the pass
|
|
102
|
+
// comes back with a delta. Read only while a cycle is in flight, and set by
|
|
103
|
+
// each cycle before its pass starts.
|
|
104
|
+
let inFlightTarget;
|
|
105
|
+
// Failed cycles in a row, and the pending retry of the follow-up they owe.
|
|
106
|
+
// `retryTimer` set means cooling down: a pushed change only marks the flag.
|
|
107
|
+
let cycleFailures = 0;
|
|
108
|
+
let retryTimer = null;
|
|
109
|
+
// Pulls: one probe-and-cycle in flight; `pullRequested` is its dirty flag.
|
|
110
|
+
let pullInFlight = null;
|
|
111
|
+
let pullInFlightRun = 0;
|
|
112
|
+
let pullSeq = 0;
|
|
113
|
+
let pullRequested = false;
|
|
114
|
+
// True when a person-driven signal (focus, online) joined the pull in flight.
|
|
115
|
+
let pullSignalled = false;
|
|
116
|
+
// One value per start() and per stop(). A pull remembers the value it began
|
|
117
|
+
// under and does nothing once it differs: a probe answering after stop(), or
|
|
118
|
+
// from before a stop and start, can start no cycle and set no baseline.
|
|
119
|
+
let lifecycle = 0;
|
|
120
|
+
// Ends with the lifecycle value it belongs to: a pause or a stop aborts every
|
|
121
|
+
// request and timer the run before it still holds (the probe's read).
|
|
122
|
+
let lifecycleEnd = new AbortController();
|
|
123
|
+
const nextLifecycle = (why) => {
|
|
124
|
+
lifecycle += 1;
|
|
125
|
+
lifecycleEnd.abort(new Error(`sync manager ${why}`));
|
|
126
|
+
lifecycleEnd = new AbortController();
|
|
127
|
+
};
|
|
128
|
+
// Failed probes in a row, and the earliest time the timed probe tries again.
|
|
129
|
+
let probeFailures = 0;
|
|
130
|
+
let nextTimedProbeAt = 0;
|
|
131
|
+
// The change push (`ChangeProbe.push`): whether it can be trusted now, and
|
|
132
|
+
// how to end the subscription of this run.
|
|
133
|
+
let pushHealthy = false;
|
|
134
|
+
let stopPush = null;
|
|
135
|
+
// Positions (see `ChangePush`). `knownPosition` is the push's latest answer.
|
|
136
|
+
// `syncedPosition` is the position the last cleanly finished pass started
|
|
137
|
+
// under; it is undefined while a pass runs or when the last one did not
|
|
138
|
+
// finish clean.
|
|
139
|
+
let knownPosition;
|
|
140
|
+
let syncedPosition;
|
|
141
|
+
// What the last pass that ran to its end left owed, and the position it
|
|
142
|
+
// started under. Null while a pass runs or when the last one did not end
|
|
143
|
+
// clean. A retry limited to `connections` is sound only while the push still
|
|
144
|
+
// reports that position: see `owedScope`.
|
|
145
|
+
let lastPass = null;
|
|
146
|
+
// The owed work last reported, so the log says it when it changes, not on
|
|
147
|
+
// every pass.
|
|
148
|
+
let owedReported = "";
|
|
149
|
+
// A format this build cannot read needs an update, not repeated polling.
|
|
150
|
+
// This position suppresses that repeat but is never offered as `since`.
|
|
151
|
+
let refusedPosition;
|
|
152
|
+
// The host paused the manager (no one is looking): no request, no timer.
|
|
153
|
+
// `owedWhilePaused` remembers a local ingest that arrived meanwhile.
|
|
154
|
+
let paused = false;
|
|
155
|
+
let owedWhilePaused = false;
|
|
156
|
+
// The registry marker as of the last cycle a pull ran and finished cleanly.
|
|
157
|
+
// Only `pullIfChanged` moves it, and only to a marker read BEFORE its cycle
|
|
158
|
+
// started, so every change up to it was in the registry when that cycle read.
|
|
159
|
+
// A cycle that does not read its own marker first (a pushed change) leaves it
|
|
160
|
+
// alone: the next probe then runs one conservative follow-up.
|
|
161
|
+
let pulledMarker;
|
|
162
|
+
let errorSeq = 0;
|
|
163
|
+
// Status subscribers (`subscribeStatus`). `statusSeen` is the serialized
|
|
164
|
+
// value last delivered or taken as the baseline; null while no one listens.
|
|
165
|
+
const statusListeners = new Set();
|
|
166
|
+
let statusSeen = null;
|
|
167
|
+
let statusDelivering = false;
|
|
168
|
+
let probeIntervalId = null;
|
|
23
169
|
let needsFullReconcile = true;
|
|
24
170
|
// Once per boot, then only the scopes whose lookup failed, a few times.
|
|
25
171
|
let lostDataPointRetryScopes = null;
|
|
@@ -33,16 +179,35 @@ export function createSyncManager(uploadDeps, downloadDeps, options) {
|
|
|
33
179
|
const downloadRetryMemory = createDownloadRetryMemory();
|
|
34
180
|
// Re-submissions of deletes whose tombstone failed (bounded per boot).
|
|
35
181
|
const tombstoneResubmits = createTombstoneResubmitTracker();
|
|
182
|
+
// The pending blob deletions as the last drain left them (see SyncStatus).
|
|
183
|
+
let blobDeletions;
|
|
184
|
+
// Entries too large to upload and failing uploads that back off (per boot).
|
|
185
|
+
const uploadState = uploadDeps.uploadState ?? createUploadStateTracker();
|
|
36
186
|
const dataPointFeed = downloadDeps.dataPointFeed ?? uploadDeps.dataPointFeed;
|
|
37
187
|
const scopeDeletions = uploadDeps.scopeDeletions ?? downloadDeps.scopeDeletions;
|
|
188
|
+
const namelessAttempts = !uploadDeps.uploadAttempts && !options?.uploadAttemptStore;
|
|
38
189
|
// The upload worker queues guarded cleanup for ciphertext it had to
|
|
39
190
|
// abandon mid-race; it shares the manager's marker store.
|
|
191
|
+
const uploadAttempts = uploadDeps.uploadAttempts ??
|
|
192
|
+
createUploadAttemptLedger(options?.uploadAttemptStore ?? createMemoryUploadAttemptStore(), uploadDeps.serverOwner, {
|
|
193
|
+
onDegraded: (message) => pushError({
|
|
194
|
+
fileId: null,
|
|
195
|
+
scope: null,
|
|
196
|
+
message,
|
|
197
|
+
timestamp: new Date().toISOString(),
|
|
198
|
+
}),
|
|
199
|
+
});
|
|
40
200
|
const workerUploadDeps = {
|
|
41
201
|
...uploadDeps,
|
|
202
|
+
uploadState,
|
|
203
|
+
uploadAttempts,
|
|
42
204
|
pendingBlobDeletions: uploadDeps.pendingBlobDeletions ?? options?.pendingBlobDeletions,
|
|
43
205
|
};
|
|
44
206
|
const workerDownloadDeps = {
|
|
45
207
|
...downloadDeps,
|
|
208
|
+
// A mode-aware manager handles On through its cycle above. Its legacy
|
|
209
|
+
// worker is reached only for Off and must not invoke the database hook.
|
|
210
|
+
localSync: options?.accountStorageMode ? undefined : downloadDeps.localSync,
|
|
46
211
|
pendingBlobDeletions: downloadDeps.pendingBlobDeletions ?? options?.pendingBlobDeletions,
|
|
47
212
|
};
|
|
48
213
|
// Sync cycles and durable deletes mutate the same local index and the same
|
|
@@ -67,31 +232,262 @@ export function createSyncManager(uploadDeps, downloadDeps, options) {
|
|
|
67
232
|
// data point or tombstone; it does not guarantee local bytes exist.
|
|
68
233
|
hydratedScopes.add(scope);
|
|
69
234
|
downloadDeps.logger.info({ scope }, "Hydrated requested scope");
|
|
235
|
+
statusMayHaveChanged();
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Clear the block a pass starts with. A connection that needs an update
|
|
240
|
+
* stays reported while the local cycle that can end it runs (and if that
|
|
241
|
+
* cycle throws): only a cycle that reports without it clears it
|
|
242
|
+
* (`runLocalCycle`). Any other block ends here.
|
|
243
|
+
*/
|
|
244
|
+
function clearBlockBeforePass(mode) {
|
|
245
|
+
const localCycleFollows = mode === "switched" && options?.localSync;
|
|
246
|
+
if (blocked?.reason === "update_required" && localCycleFollows)
|
|
247
|
+
return;
|
|
248
|
+
blocked = null;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* One cycle of the local stream database. A connection whose log this
|
|
252
|
+
* build cannot read is reported by the cycle as `update_required`: it is
|
|
253
|
+
* shown as the sync status's `blocked` reason, so every host that reads the
|
|
254
|
+
* status shows it without code of its own. It ends with a cycle that does
|
|
255
|
+
* not report one.
|
|
256
|
+
*/
|
|
257
|
+
async function runLocalCycle(localSync, scope) {
|
|
258
|
+
const report = (await localSync.cycle(scope));
|
|
259
|
+
const waiting = (report?.connections ?? []).filter((c) => c.status === "update_required");
|
|
260
|
+
if (waiting.length > 0) {
|
|
261
|
+
blocked = {
|
|
262
|
+
reason: "update_required",
|
|
263
|
+
message: "A connection's log is in a format this version cannot read. Update to sync it.",
|
|
264
|
+
};
|
|
265
|
+
uploadDeps.logger.warn({ connections: waiting.map((c) => c.connectionId) }, "Sync blocked: update required");
|
|
266
|
+
}
|
|
267
|
+
else if (blocked?.reason === "update_required")
|
|
268
|
+
blocked = null;
|
|
269
|
+
statusMayHaveChanged();
|
|
270
|
+
return report;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* The first pass of a cycle that a change delta started: apply the delta
|
|
274
|
+
* instead of the cycle's registry reads (the server row, the owner listing,
|
|
275
|
+
* and each connection's control row). `settle`: the pass ended clean; `owed`: the delta
|
|
276
|
+
* is applied and deletion debt is left, as a full pass that left it would
|
|
277
|
+
* end; `full`: a full pass must run (see `DeltaApplyResult`).
|
|
278
|
+
*
|
|
279
|
+
* Why it is the same as a full pass. The last clean pass started under
|
|
280
|
+
* `heldUpTo`, so this device held the registry as of that position, and a
|
|
281
|
+
* clean pass found its server registered. The gateway numbers changes in
|
|
282
|
+
* commit order with no gap, and the delta lists every row whose latest
|
|
283
|
+
* change is above `delta.since`, read in one snapshot at `delta.seq`. When
|
|
284
|
+
* `delta.since` is `heldUpTo`, no server change is in it, and every row in
|
|
285
|
+
* it is applied, the device holds what the registry held at `delta.seq`:
|
|
286
|
+
* what a full pass that started under it would read. The manager settles
|
|
287
|
+
* the pass at `delta.seq` only when that is also the position the push
|
|
288
|
+
* reported last (`startedUnder`), as for any pass. Only the switched
|
|
289
|
+
* (stream database) pass has this path; a legacy pass reads per scope.
|
|
290
|
+
*/
|
|
291
|
+
async function deltaPass(delta, heldUpTo, startedUnder) {
|
|
292
|
+
const localSync = options?.localSync;
|
|
293
|
+
if (!localSync ||
|
|
294
|
+
delta.reset ||
|
|
295
|
+
delta.since !== heldUpTo ||
|
|
296
|
+
delta.seq !== startedUnder ||
|
|
297
|
+
blocked !== null ||
|
|
298
|
+
options?.accountStorageMode?.read() !== "switched")
|
|
299
|
+
return "full";
|
|
300
|
+
const started = Date.now();
|
|
301
|
+
let result;
|
|
302
|
+
try {
|
|
303
|
+
result = await localSync.applyDelta(delta);
|
|
304
|
+
}
|
|
305
|
+
catch (error) {
|
|
306
|
+
// Whatever failed is the full pass's to meet and report.
|
|
307
|
+
downloadDeps.logger.warn({ error: error.message }, "Change delta apply failed; running a full cycle");
|
|
308
|
+
return "full";
|
|
309
|
+
}
|
|
310
|
+
if (result.outcome !== "applied") {
|
|
311
|
+
downloadDeps.logger.debug({ reason: result.reason }, "Change delta needs a full cycle");
|
|
312
|
+
return "full";
|
|
313
|
+
}
|
|
314
|
+
lastSync = new Date().toISOString();
|
|
315
|
+
statusMayHaveChanged();
|
|
316
|
+
const debt = await drainPendingBlobDeletions("switched");
|
|
317
|
+
// One line per wake a delta served: the receive side's hops after the
|
|
318
|
+
// held request answered (its answer carried the delta, so no read sits
|
|
319
|
+
// between them). `blobMs` is the segment GETs; the rest of `applyMs` is
|
|
320
|
+
// the local apply and its commit, after which a read sees the rows.
|
|
321
|
+
downloadDeps.logger.info({
|
|
322
|
+
since: delta.since,
|
|
323
|
+
seq: delta.seq,
|
|
324
|
+
rows: delta.rows.length,
|
|
325
|
+
connections: result.connections,
|
|
326
|
+
blobGets: result.blobGets,
|
|
327
|
+
blobMs: result.blobMs,
|
|
328
|
+
applyMs: result.applyMs,
|
|
329
|
+
totalMs: Date.now() - started,
|
|
330
|
+
}, "Change delta applied");
|
|
331
|
+
return debt.owed ? "owed" : "settle";
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Say what a pass left owed, once per change: a pass that leaves the same
|
|
335
|
+
* work every minute would otherwise log it every minute, and a pass that
|
|
336
|
+
* clears it says so.
|
|
337
|
+
*/
|
|
338
|
+
function reportOwed(owed, debtOwed) {
|
|
339
|
+
const signature = JSON.stringify([
|
|
340
|
+
owed.map((entry) => [entry.connectionId, entry.why]),
|
|
341
|
+
debtOwed,
|
|
342
|
+
]);
|
|
343
|
+
if (signature === owedReported)
|
|
344
|
+
return;
|
|
345
|
+
const hadOwed = owedReported !== "";
|
|
346
|
+
owedReported = owed.length === 0 && !debtOwed ? "" : signature;
|
|
347
|
+
if (owedReported === "") {
|
|
348
|
+
if (hadOwed)
|
|
349
|
+
uploadDeps.logger.info("Sync pass owes nothing");
|
|
350
|
+
return;
|
|
70
351
|
}
|
|
352
|
+
uploadDeps.logger.info({
|
|
353
|
+
connections: owed.map((entry) => ({
|
|
354
|
+
connectionId: entry.connectionId,
|
|
355
|
+
why: entry.why,
|
|
356
|
+
})),
|
|
357
|
+
blobDeletionDebt: debtOwed,
|
|
358
|
+
}, "Sync pass left work owed");
|
|
71
359
|
}
|
|
72
|
-
async function runCycle() {
|
|
360
|
+
async function runCycle(delta, retry) {
|
|
73
361
|
// Prevent concurrent cycles
|
|
74
362
|
if (cycleInFlight) {
|
|
363
|
+
// The follow-up is owed. Its delta, if the request had one, waits for
|
|
364
|
+
// it: the request asked from the position the pass in flight settles at
|
|
365
|
+
// (`inFlightTarget`), which is what the follow-up holds when that pass
|
|
366
|
+
// ends clean. When it does not, `deltaPass` sees another position and the
|
|
367
|
+
// follow-up is a full pass, as it is for a request without a delta.
|
|
75
368
|
rerunRequested = true;
|
|
369
|
+
if (delta === undefined) {
|
|
370
|
+
deltaBarred = true;
|
|
371
|
+
queuedDeltas = [];
|
|
372
|
+
}
|
|
373
|
+
else if (!deltaBarred)
|
|
374
|
+
queuedDeltas.push(delta);
|
|
76
375
|
return cycleInFlight;
|
|
77
376
|
}
|
|
78
|
-
|
|
377
|
+
// One cycle's passes: repeats while a request arrived during a pass.
|
|
378
|
+
const passes = async () => {
|
|
379
|
+
let first = true;
|
|
79
380
|
do {
|
|
381
|
+
// Reaching another pass means the previous one succeeded: the failure
|
|
382
|
+
// streak ends at that boundary, not when the whole cycle returns, or a
|
|
383
|
+
// failure in a pass that follows a success would back off as a repeat.
|
|
384
|
+
if (!first)
|
|
385
|
+
cycleFailures = 0;
|
|
386
|
+
const passDeltas = first ? (delta ? [delta] : []) : queuedDeltas;
|
|
387
|
+
first = false;
|
|
80
388
|
rerunRequested = false;
|
|
389
|
+
queuedDeltas = [];
|
|
390
|
+
deltaBarred = false;
|
|
391
|
+
// Sample before anything is read: every change up to this position is
|
|
392
|
+
// in the registry when the pass reads. Nothing is settled until it
|
|
393
|
+
// ends clean.
|
|
394
|
+
const startedUnder = knownPosition;
|
|
395
|
+
const errorsBefore = errorSeq;
|
|
396
|
+
const heldUpTo = syncedPosition;
|
|
397
|
+
inFlightTarget = startedUnder;
|
|
398
|
+
syncedPosition = undefined;
|
|
399
|
+
lastPass = null;
|
|
400
|
+
// A retry is limited to what was owed only if nothing in the registry
|
|
401
|
+
// moved between the decision and this pass; a follow-up pass (a request
|
|
402
|
+
// arrived) reads everything.
|
|
403
|
+
const scope = retry && startedUnder === retry.position
|
|
404
|
+
? { connections: retry.connections }
|
|
405
|
+
: undefined;
|
|
406
|
+
retry = undefined;
|
|
407
|
+
refusedPosition = undefined;
|
|
408
|
+
const settle = () => {
|
|
409
|
+
// The update-required block is a diagnostic of a refusal no retry
|
|
410
|
+
// changes (`connectionsOwingWork`); any other block means no cycle ran.
|
|
411
|
+
if ((blocked !== null && blocked.reason !== "update_required") ||
|
|
412
|
+
errorSeq !== errorsBefore)
|
|
413
|
+
return;
|
|
414
|
+
if (blocked?.reason === "update_required")
|
|
415
|
+
refusedPosition = startedUnder;
|
|
416
|
+
else
|
|
417
|
+
syncedPosition = startedUnder;
|
|
418
|
+
};
|
|
419
|
+
let byDelta = passDeltas.length === 0 ? "full" : "settle";
|
|
420
|
+
let held = heldUpTo;
|
|
421
|
+
for (let i = 0; i < passDeltas.length && byDelta !== "full"; i++) {
|
|
422
|
+
const d = passDeltas[i];
|
|
423
|
+
const target = i === passDeltas.length - 1 ? startedUnder : d.seq;
|
|
424
|
+
const result = await deltaPass(d, held, target);
|
|
425
|
+
if (result === "full")
|
|
426
|
+
byDelta = "full";
|
|
427
|
+
else if (result === "owed")
|
|
428
|
+
byDelta = "owed";
|
|
429
|
+
held = d.seq;
|
|
430
|
+
}
|
|
431
|
+
if (byDelta !== "full") {
|
|
432
|
+
if (byDelta === "settle")
|
|
433
|
+
settle();
|
|
434
|
+
continue;
|
|
435
|
+
}
|
|
81
436
|
const canRun = await (options?.canSync?.() ?? { ok: true });
|
|
82
437
|
if (!canRun.ok) {
|
|
83
438
|
blocked = { reason: canRun.reason, message: canRun.message };
|
|
84
439
|
uploadDeps.logger.warn(blocked, "Sync cycle blocked");
|
|
85
440
|
continue;
|
|
86
441
|
}
|
|
87
|
-
|
|
442
|
+
// canSync can yield while Account changes. Sample only after it returns.
|
|
443
|
+
const mode = options?.accountStorageMode?.read();
|
|
444
|
+
clearBlockBeforePass(mode);
|
|
445
|
+
statusMayHaveChanged();
|
|
446
|
+
if (options?.accountStorageMode && mode !== undefined) {
|
|
447
|
+
if (mode !== "unswitched") {
|
|
448
|
+
if (mode === "switched" && options.localSync) {
|
|
449
|
+
// Nothing owed on a connection and a scope with none: no cycle.
|
|
450
|
+
const report = scope && scope.connections.length === 0
|
|
451
|
+
? { connections: [] }
|
|
452
|
+
: await runLocalCycle(options.localSync, scope);
|
|
453
|
+
lastSync = new Date().toISOString();
|
|
454
|
+
statusMayHaveChanged();
|
|
455
|
+
// Deletion debt is owed work like a backed-off publish: a blob
|
|
456
|
+
// waits on a tombstone's finality, a version-row change no
|
|
457
|
+
// position announces. Nothing is settled while any is left.
|
|
458
|
+
const debt = await drainPendingBlobDeletions("switched");
|
|
459
|
+
const owed = connectionsOwingWork(report);
|
|
460
|
+
reportOwed(owed, debt.owed);
|
|
461
|
+
if (owed.length === 0 && !debt.owed)
|
|
462
|
+
settle();
|
|
463
|
+
// Only a pass that named every owed connection can be retried
|
|
464
|
+
// for those alone; any other outcome retries in full.
|
|
465
|
+
if (startedUnder !== undefined &&
|
|
466
|
+
errorSeq === errorsBefore &&
|
|
467
|
+
owed.every((entry) => entry.connectionId !== null))
|
|
468
|
+
lastPass = {
|
|
469
|
+
position: startedUnder,
|
|
470
|
+
connections: owed.map((entry) => entry.connectionId),
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
else {
|
|
474
|
+
blocked = {
|
|
475
|
+
reason: mode === "unknown"
|
|
476
|
+
? "account_mode_unknown"
|
|
477
|
+
: "stream_sync_unavailable",
|
|
478
|
+
message: "Waiting for the account or its stream database",
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
continue;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
88
484
|
if (needsStartupHydration) {
|
|
89
485
|
try {
|
|
90
486
|
await hydrateScopesExclusive(startupHydrateScopes);
|
|
91
487
|
needsStartupHydration = false;
|
|
92
488
|
}
|
|
93
489
|
catch (err) {
|
|
94
|
-
downloadDeps.logger.warn({ error: err
|
|
490
|
+
downloadDeps.logger.warn({ error: errorMessage(err) }, "Scope hydration failed; continuing with full sync");
|
|
95
491
|
}
|
|
96
492
|
}
|
|
97
493
|
// Finish blob deletions whose tombstone landed but whose storage
|
|
@@ -114,6 +510,7 @@ export function createSyncManager(uploadDeps, downloadDeps, options) {
|
|
|
114
510
|
}
|
|
115
511
|
}
|
|
116
512
|
await runUploadCycle();
|
|
513
|
+
statusMayHaveChanged(); // uploads moved, the pending count with them
|
|
117
514
|
}
|
|
118
515
|
try {
|
|
119
516
|
// Download new remote files
|
|
@@ -129,11 +526,11 @@ export function createSyncManager(uploadDeps, downloadDeps, options) {
|
|
|
129
526
|
const syncError = {
|
|
130
527
|
fileId: null,
|
|
131
528
|
scope: null,
|
|
132
|
-
message: `Download cycle failed: ${err
|
|
529
|
+
message: `Download cycle failed: ${errorMessage(err)}`,
|
|
133
530
|
timestamp: new Date().toISOString(),
|
|
134
531
|
};
|
|
135
532
|
pushError(syncError);
|
|
136
|
-
downloadDeps.logger.error({ error: err
|
|
533
|
+
downloadDeps.logger.error({ error: errorMessage(err) }, "Download cycle failed");
|
|
137
534
|
}
|
|
138
535
|
// Update cached cursor value
|
|
139
536
|
try {
|
|
@@ -143,15 +540,60 @@ export function createSyncManager(uploadDeps, downloadDeps, options) {
|
|
|
143
540
|
// Non-critical: status will show stale value
|
|
144
541
|
}
|
|
145
542
|
lastSync = new Date().toISOString();
|
|
146
|
-
|
|
147
|
-
|
|
543
|
+
statusMayHaveChanged(); // the cursor and lastSync, at the pass boundary
|
|
544
|
+
// No `settle()`: this pass retries on the clock (a deletion waiting on
|
|
545
|
+
// chain finality, a download in backoff, an upload cap) and no
|
|
546
|
+
// registry position announces that, so the timer keeps running.
|
|
547
|
+
} while (rerunRequested && isRunning && !paused);
|
|
548
|
+
};
|
|
549
|
+
// Set before the pass starts, not by it: the next held request can be sent
|
|
550
|
+
// before the pass runs, and it must ask from where the pass will settle.
|
|
551
|
+
inFlightTarget = knownPosition;
|
|
552
|
+
// A failed cycle ends its exclusive operation at once: callers get its
|
|
553
|
+
// error and queued mutations run. A follow-up it still owes (the dirty
|
|
554
|
+
// flag) waits out a cooldown first: see `scheduleRetry`.
|
|
555
|
+
cycleInFlight = exclusive(passes);
|
|
556
|
+
statusMayHaveChanged(); // syncing: true
|
|
148
557
|
try {
|
|
149
558
|
await cycleInFlight;
|
|
559
|
+
cycleFailures = 0;
|
|
560
|
+
}
|
|
561
|
+
catch (error) {
|
|
562
|
+
cycleFailed();
|
|
563
|
+
throw error;
|
|
150
564
|
}
|
|
151
565
|
finally {
|
|
152
566
|
cycleInFlight = null;
|
|
567
|
+
statusMayHaveChanged(); // syncing: false, and whatever the cycle moved
|
|
153
568
|
}
|
|
154
569
|
}
|
|
570
|
+
/**
|
|
571
|
+
* A cycle failed. If a request arrived while it ran, one follow-up is owed:
|
|
572
|
+
* run it after a cooldown from the push's back-off schedule (1 s doubling to
|
|
573
|
+
* 30 s over consecutive failures), never at once. Pushes cannot shorten or
|
|
574
|
+
* restart the cooldown: while it runs they only mark the dirty flag, and the
|
|
575
|
+
* one timer runs the follow-up. Without a request nothing retries; the timed
|
|
576
|
+
* cycle is the fallback.
|
|
577
|
+
*/
|
|
578
|
+
function cycleFailed() {
|
|
579
|
+
const failures = cycleFailures;
|
|
580
|
+
cycleFailures += 1;
|
|
581
|
+
if (!rerunRequested || !isRunning || paused || retryTimer !== null)
|
|
582
|
+
return;
|
|
583
|
+
retryTimer = setTimeout(() => {
|
|
584
|
+
retryTimer = null;
|
|
585
|
+
if (!isRunning || paused || !rerunRequested)
|
|
586
|
+
return;
|
|
587
|
+
runCycle().catch(() => {
|
|
588
|
+
// Errors already captured in ring buffer
|
|
589
|
+
});
|
|
590
|
+
}, changePushBackoffMs(failures));
|
|
591
|
+
}
|
|
592
|
+
function clearRetryTimer() {
|
|
593
|
+
if (retryTimer !== null)
|
|
594
|
+
clearTimeout(retryTimer);
|
|
595
|
+
retryTimer = null;
|
|
596
|
+
}
|
|
155
597
|
function deleteScopeDeps() {
|
|
156
598
|
return {
|
|
157
599
|
storage: uploadDeps.storage,
|
|
@@ -182,9 +624,26 @@ export function createSyncManager(uploadDeps, downloadDeps, options) {
|
|
|
182
624
|
uploadDeps.logger.warn({ scope, error: err.message }, "Could not delete the additions ledger of a re-deleted scope");
|
|
183
625
|
});
|
|
184
626
|
}
|
|
185
|
-
|
|
627
|
+
/**
|
|
628
|
+
* Finish the storage deletes whose covering tombstone has become final.
|
|
629
|
+
* Both modes call it inside the exclusive pass.
|
|
630
|
+
*
|
|
631
|
+
* `legacy` may re-send a rolled-back tombstone through `deleteScope`, which
|
|
632
|
+
* writes to legacy storage and is sealed once the account has switched.
|
|
633
|
+
* `switched` never does: it only waits for finality and then deletes the
|
|
634
|
+
* blob, and parks a rolled-back scope as a visible failure until the user
|
|
635
|
+
* deletes it again. Either way, a manager that knows the account mode fails
|
|
636
|
+
* closed without a finality port: the worker's permissive no-port release
|
|
637
|
+
* would free a slot a rolled-back tombstone can still hand to another
|
|
638
|
+
* writer, and the mode can change while the drain awaits.
|
|
639
|
+
*
|
|
640
|
+
* Returns whether work is owed that a later pass can do: markers waiting on
|
|
641
|
+
* finality, a failed key, or a retry that threw. Parked and unavailable
|
|
642
|
+
* markers stay queued and show in the status, but are not runnable work.
|
|
643
|
+
*/
|
|
644
|
+
async function drainPendingBlobDeletions(mode) {
|
|
186
645
|
try {
|
|
187
|
-
await retryPendingBlobDeletions({
|
|
646
|
+
const result = await retryPendingBlobDeletions({
|
|
188
647
|
deleteData: options?.deleteData,
|
|
189
648
|
pendingBlobDeletions: options?.pendingBlobDeletions,
|
|
190
649
|
tombstoneFinality: options?.tombstoneFinality,
|
|
@@ -192,43 +651,67 @@ export function createSyncManager(uploadDeps, downloadDeps, options) {
|
|
|
192
651
|
serverOwner: uploadDeps.serverOwner,
|
|
193
652
|
storage: uploadDeps.storage,
|
|
194
653
|
logger: uploadDeps.logger,
|
|
654
|
+
// The account can switch at any await below, and the legacy write seal
|
|
655
|
+
// does not guard a blob delete. Only a manager that has no account
|
|
656
|
+
// mode at all is fixed to legacy, so only it may release without
|
|
657
|
+
// finality.
|
|
658
|
+
requireFinality: options?.accountStorageMode !== undefined,
|
|
195
659
|
...(options?.tombstoneFinality && options.deleteData
|
|
196
660
|
? {
|
|
197
661
|
tombstoneResubmits,
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
662
|
+
...(mode === "legacy"
|
|
663
|
+
? {
|
|
664
|
+
// Already inside the mutation queue: call the worker directly.
|
|
665
|
+
async resubmitDeletion(scope, deleteOptions) {
|
|
666
|
+
const result = await deleteScope(deleteScopeDeps(), scope, deleteOptions);
|
|
667
|
+
if (result.durable)
|
|
668
|
+
deleteAdditionsAfter(scope);
|
|
669
|
+
return result;
|
|
670
|
+
},
|
|
671
|
+
}
|
|
672
|
+
: {}),
|
|
205
673
|
onDeletionAbandoned(state) {
|
|
206
674
|
pushError({
|
|
207
675
|
fileId: null,
|
|
208
676
|
scope: state.scope,
|
|
209
|
-
message: state.reason === "
|
|
210
|
-
? `Deletion of ${state.scope} did not complete: the gateway tombstone failed and the data is live again. Delete it again to retry.`
|
|
211
|
-
: `Deletion of ${state.scope} did not complete: the gateway tombstone failed
|
|
677
|
+
message: state.reason === "attempts-exhausted"
|
|
678
|
+
? `Deletion of ${state.scope} did not complete: the gateway tombstone failed ${state.attempts + 1} times and the data is live again. Delete it again to retry.`
|
|
679
|
+
: `Deletion of ${state.scope} did not complete: the gateway tombstone failed and the data is live again. Delete it again to retry.`,
|
|
212
680
|
timestamp: new Date().toISOString(),
|
|
213
681
|
});
|
|
214
682
|
},
|
|
215
683
|
}
|
|
216
684
|
: {}),
|
|
217
685
|
});
|
|
686
|
+
blobDeletions =
|
|
687
|
+
result.remaining > 0
|
|
688
|
+
? {
|
|
689
|
+
remaining: result.remaining,
|
|
690
|
+
waiting: result.waiting,
|
|
691
|
+
unavailable: result.unavailable,
|
|
692
|
+
}
|
|
693
|
+
: undefined;
|
|
694
|
+
statusMayHaveChanged();
|
|
695
|
+
return { owed: result.waiting > 0 || result.failed.length > 0 };
|
|
218
696
|
}
|
|
219
697
|
catch (err) {
|
|
220
698
|
uploadDeps.logger.warn({ error: err.message }, "Pending blob deletion retry failed");
|
|
699
|
+
return { owed: true };
|
|
221
700
|
}
|
|
701
|
+
}
|
|
702
|
+
async function runUploadCycle() {
|
|
703
|
+
await drainPendingBlobDeletions("legacy");
|
|
222
704
|
try {
|
|
223
705
|
const uploadResults = await uploadAll(workerUploadDeps, {
|
|
224
706
|
batchSize: uploadBatchSize,
|
|
225
707
|
onError(entry, error) {
|
|
708
|
+
// One notification for the whole upload cycle, from the caller.
|
|
226
709
|
pushError({
|
|
227
710
|
fileId: entry.fileId,
|
|
228
711
|
scope: entry.scope,
|
|
229
712
|
message: `Upload failed for ${entry.path}: ${error.message}`,
|
|
230
713
|
timestamp: new Date().toISOString(),
|
|
231
|
-
});
|
|
714
|
+
}, false);
|
|
232
715
|
},
|
|
233
716
|
});
|
|
234
717
|
uploadDeps.logger.debug({ uploaded: uploadResults.length }, "Upload cycle complete");
|
|
@@ -243,30 +726,272 @@ export function createSyncManager(uploadDeps, downloadDeps, options) {
|
|
|
243
726
|
pushError(syncError);
|
|
244
727
|
uploadDeps.logger.error({ error: err.message }, "Upload cycle failed");
|
|
245
728
|
}
|
|
729
|
+
if (options?.streamSync?.write) {
|
|
730
|
+
try {
|
|
731
|
+
await options.streamSync.publisher.cycle();
|
|
732
|
+
}
|
|
733
|
+
catch (err) {
|
|
734
|
+
pushError({
|
|
735
|
+
fileId: null,
|
|
736
|
+
scope: null,
|
|
737
|
+
message: `Stream sync publish failed: ${err.message}`,
|
|
738
|
+
timestamp: new Date().toISOString(),
|
|
739
|
+
});
|
|
740
|
+
uploadDeps.logger.warn({ error: err.message }, "Stream sync publish failed");
|
|
741
|
+
}
|
|
742
|
+
}
|
|
246
743
|
}
|
|
247
|
-
|
|
248
|
-
|
|
744
|
+
/**
|
|
745
|
+
* After a failed probe the timed probe waits probe period x 2^failures, capped
|
|
746
|
+
* at the poll interval, so an offline device probes about once a minute and
|
|
747
|
+
* the timer's own cycle stays the fallback. Both numbers are the host's.
|
|
748
|
+
*/
|
|
749
|
+
function noteProbeFailure(probe) {
|
|
750
|
+
probeFailures += 1;
|
|
751
|
+
const wait = Math.min(probe.intervalMs * 2 ** probeFailures, Math.max(pollInterval, probe.intervalMs));
|
|
752
|
+
nextTimedProbeAt = Date.now() + wait;
|
|
753
|
+
}
|
|
754
|
+
async function pullIfChanged(probe, run, fromSignal, ended) {
|
|
755
|
+
let marker;
|
|
756
|
+
try {
|
|
757
|
+
marker = await probe.read(ended);
|
|
758
|
+
}
|
|
759
|
+
catch (err) {
|
|
760
|
+
if (run === lifecycle)
|
|
761
|
+
noteProbeFailure(probe);
|
|
762
|
+
uploadDeps.logger.debug({ error: err.message }, "Registry change probe failed; the timer cycle is the fallback");
|
|
249
763
|
return;
|
|
250
|
-
|
|
764
|
+
}
|
|
765
|
+
// stop() does not wait for a probe; an answer from an earlier run is void.
|
|
766
|
+
if (run !== lifecycle || !isRunning)
|
|
767
|
+
return;
|
|
768
|
+
probeFailures = 0;
|
|
769
|
+
nextTimedProbeAt = 0;
|
|
770
|
+
if (marker === undefined && !fromSignal)
|
|
771
|
+
return; // cannot tell: the timer decides
|
|
772
|
+
if (marker !== undefined && marker === pulledMarker)
|
|
773
|
+
return;
|
|
774
|
+
const errorsBefore = errorSeq;
|
|
775
|
+
// A cycle already running may have read the registry before the change:
|
|
776
|
+
// `runCycle` makes a joiner wait for a follow-up that starts after this call.
|
|
777
|
+
await runCycle();
|
|
778
|
+
if (run === lifecycle &&
|
|
779
|
+
marker !== undefined &&
|
|
780
|
+
blocked === null &&
|
|
781
|
+
errorSeq === errorsBefore) {
|
|
782
|
+
pulledMarker = marker;
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
function pull(fromSignal) {
|
|
786
|
+
if (!isRunning || paused)
|
|
787
|
+
return Promise.resolve();
|
|
788
|
+
// No probe: a pull is a cycle request, and `runCycle` coalesces those.
|
|
789
|
+
const probe = options?.changeProbe;
|
|
790
|
+
if (!probe)
|
|
791
|
+
return runCycle();
|
|
792
|
+
const run = lifecycle;
|
|
793
|
+
const ended = lifecycleEnd.signal;
|
|
794
|
+
if (pullInFlight && pullInFlightRun === run) {
|
|
795
|
+
pullRequested = true;
|
|
796
|
+
pullSignalled ||= fromSignal;
|
|
797
|
+
return pullInFlight;
|
|
798
|
+
}
|
|
799
|
+
pullSignalled = fromSignal;
|
|
800
|
+
const seq = ++pullSeq;
|
|
801
|
+
const current = (async () => {
|
|
802
|
+
try {
|
|
803
|
+
do {
|
|
804
|
+
pullRequested = false;
|
|
805
|
+
const signalled = pullSignalled;
|
|
806
|
+
pullSignalled = false;
|
|
807
|
+
await pullIfChanged(probe, run, signalled, ended);
|
|
808
|
+
// A tick that joined a read that then failed waits out the back-off;
|
|
809
|
+
// only a signal (focus, online) is read again at once.
|
|
810
|
+
} while (pullRequested &&
|
|
811
|
+
isRunning &&
|
|
812
|
+
run === lifecycle &&
|
|
813
|
+
(pullSignalled || Date.now() >= nextTimedProbeAt));
|
|
814
|
+
}
|
|
815
|
+
finally {
|
|
816
|
+
// Only the newest pull clears the slot; an older run's may end later.
|
|
817
|
+
if (pullSeq === seq)
|
|
818
|
+
pullInFlight = null;
|
|
819
|
+
}
|
|
820
|
+
})();
|
|
821
|
+
pullInFlight = current;
|
|
822
|
+
pullInFlightRun = run;
|
|
823
|
+
return current;
|
|
824
|
+
}
|
|
825
|
+
function requestPull() {
|
|
826
|
+
return pull(true);
|
|
827
|
+
}
|
|
828
|
+
function scheduleNotifiedCycle(delayMs = notifyDebounceMs) {
|
|
829
|
+
if (!isRunning)
|
|
830
|
+
return;
|
|
831
|
+
if (paused) {
|
|
832
|
+
owedWhilePaused = true;
|
|
833
|
+
return;
|
|
834
|
+
}
|
|
835
|
+
const start = () => {
|
|
251
836
|
notifyTimerId = null;
|
|
252
837
|
if (!isRunning)
|
|
253
838
|
return;
|
|
254
839
|
runCycle().catch(() => {
|
|
255
840
|
// Errors already captured in ring buffer
|
|
256
841
|
});
|
|
257
|
-
}
|
|
842
|
+
};
|
|
843
|
+
if (delayMs === 0) {
|
|
844
|
+
// The cycle starts now and takes whatever a pending timer was waiting for.
|
|
845
|
+
if (notifyTimerId !== null)
|
|
846
|
+
clearTimeout(notifyTimerId);
|
|
847
|
+
start();
|
|
848
|
+
return;
|
|
849
|
+
}
|
|
850
|
+
if (notifyTimerId !== null)
|
|
851
|
+
return;
|
|
852
|
+
notifyTimerId = setTimeout(start, delayMs);
|
|
258
853
|
}
|
|
259
|
-
|
|
854
|
+
/**
|
|
855
|
+
* Record an error for the status. `notify: false` leaves the notification to
|
|
856
|
+
* the caller, which owes one at the end of its batch: the upload worker
|
|
857
|
+
* reports one error per failed file, and a status read per file would cost
|
|
858
|
+
* a count each.
|
|
859
|
+
*/
|
|
860
|
+
function pushError(error, notify = true) {
|
|
861
|
+
errorSeq += 1;
|
|
260
862
|
errors.push(error);
|
|
261
863
|
if (errors.length > MAX_ERRORS) {
|
|
262
864
|
errors = errors.slice(-MAX_ERRORS);
|
|
263
865
|
}
|
|
866
|
+
if (notify)
|
|
867
|
+
statusMayHaveChanged();
|
|
868
|
+
}
|
|
869
|
+
/**
|
|
870
|
+
* Log a failure of delivery. Anything can be thrown (`null`, a string), and
|
|
871
|
+
* the logger can throw too; neither may leave delivery, or a caller such as
|
|
872
|
+
* `start` would stop before its first cycle.
|
|
873
|
+
*/
|
|
874
|
+
function reportQuietly(message, thrown) {
|
|
875
|
+
try {
|
|
876
|
+
uploadDeps.logger.warn({ error: thrown instanceof Error ? thrown.message : String(thrown) }, message);
|
|
877
|
+
}
|
|
878
|
+
catch {
|
|
879
|
+
// A failing logger has no one left to tell.
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
/**
|
|
883
|
+
* Called at every point where a field of `getStatus()` can change. Reads the
|
|
884
|
+
* status only when someone listens, and tells them only if it differs from
|
|
885
|
+
* what they last had. Not reentrant: a change a listener causes is picked up
|
|
886
|
+
* by the loop below after the listeners return.
|
|
887
|
+
*/
|
|
888
|
+
function statusMayHaveChanged() {
|
|
889
|
+
if (statusListeners.size === 0) {
|
|
890
|
+
statusSeen = null; // unknown from here: the next subscriber re-baselines
|
|
891
|
+
return;
|
|
892
|
+
}
|
|
893
|
+
if (statusDelivering)
|
|
894
|
+
return;
|
|
895
|
+
statusDelivering = true;
|
|
896
|
+
try {
|
|
897
|
+
for (;;) {
|
|
898
|
+
let status;
|
|
899
|
+
let seen;
|
|
900
|
+
try {
|
|
901
|
+
status = manager.getStatus();
|
|
902
|
+
seen = JSON.stringify(status);
|
|
903
|
+
}
|
|
904
|
+
catch (error) {
|
|
905
|
+
reportQuietly("sync status could not be read for subscribers", error);
|
|
906
|
+
return;
|
|
907
|
+
}
|
|
908
|
+
if (seen === statusSeen)
|
|
909
|
+
return;
|
|
910
|
+
const first = statusSeen === null;
|
|
911
|
+
statusSeen = seen;
|
|
912
|
+
if (first)
|
|
913
|
+
return; // the baseline, not a change
|
|
914
|
+
for (const listener of [...statusListeners]) {
|
|
915
|
+
try {
|
|
916
|
+
listener(status);
|
|
917
|
+
}
|
|
918
|
+
catch (error) {
|
|
919
|
+
reportQuietly("a sync status listener threw", error);
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
finally {
|
|
925
|
+
statusDelivering = false;
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
/**
|
|
929
|
+
* True when a full timer cycle would only repeat what the last
|
|
930
|
+
* clean cycle read: the push answers (healthy), nothing runs now, and its
|
|
931
|
+
* position is the one that cycle started under. Each answer of the held
|
|
932
|
+
* request carries the current position, so a change whose wake was lost
|
|
933
|
+
* shows as a position that differs, at the next answer.
|
|
934
|
+
*/
|
|
935
|
+
function pushCovers() {
|
|
936
|
+
return (options?.changeProbe?.push !== undefined &&
|
|
937
|
+
pushHealthy &&
|
|
938
|
+
cycleInFlight === null &&
|
|
939
|
+
knownPosition !== undefined &&
|
|
940
|
+
(knownPosition === syncedPosition || knownPosition === refusedPosition));
|
|
941
|
+
}
|
|
942
|
+
/**
|
|
943
|
+
* True when the push alone announces every registry change: it is healthy and
|
|
944
|
+
* its answers carry a position. The gateway wakes the held request on every
|
|
945
|
+
* write, so a marker read finds nothing the held request does not announce
|
|
946
|
+
* sooner. This holds whether or not the last pass settled: owed work (a
|
|
947
|
+
* deferred publish, a deletion waiting on finality) is retried by the timer
|
|
948
|
+
* cycle, and no marker read speeds that up. Without a position (a gateway
|
|
949
|
+
* that sends none) the push cannot vouch and the probe keeps running.
|
|
950
|
+
*/
|
|
951
|
+
function pushAnnouncesChanges() {
|
|
952
|
+
return (options?.changeProbe?.push !== undefined &&
|
|
953
|
+
pushHealthy &&
|
|
954
|
+
knownPosition !== undefined);
|
|
955
|
+
}
|
|
956
|
+
/**
|
|
957
|
+
* What the timer retries when the push does not cover a full cycle. The
|
|
958
|
+
* push announces every registry change (`pushAnnouncesChanges`), and the last
|
|
959
|
+
* pass that ran to its end read the registry at the position the push still
|
|
960
|
+
* reports, so nothing but the work that pass left owed can have changed: the
|
|
961
|
+
* retry reads those connections alone. Any other state (no push, a moved
|
|
962
|
+
* position, a pass that did not end, a block, a connection the report did not
|
|
963
|
+
* name) retries in full, as before.
|
|
964
|
+
*/
|
|
965
|
+
function owedScope() {
|
|
966
|
+
if (!pushAnnouncesChanges() ||
|
|
967
|
+
cycleInFlight !== null ||
|
|
968
|
+
blocked !== null ||
|
|
969
|
+
lastPass === null ||
|
|
970
|
+
lastPass.position !== knownPosition)
|
|
971
|
+
return undefined;
|
|
972
|
+
return lastPass;
|
|
264
973
|
}
|
|
265
974
|
function startInterval() {
|
|
266
975
|
if (intervalId !== null)
|
|
267
976
|
return;
|
|
268
977
|
intervalId = setInterval(() => {
|
|
269
|
-
|
|
978
|
+
const run = lifecycle;
|
|
979
|
+
void (async () => {
|
|
980
|
+
let pending = false;
|
|
981
|
+
try {
|
|
982
|
+
pending = await (options?.localSync?.hasPendingPublication?.() ??
|
|
983
|
+
false);
|
|
984
|
+
}
|
|
985
|
+
catch {
|
|
986
|
+
// A failed local read cannot prove the cycle is safe to skip.
|
|
987
|
+
pending = true;
|
|
988
|
+
}
|
|
989
|
+
if (run !== lifecycle || !isRunning || paused)
|
|
990
|
+
return;
|
|
991
|
+
if (!pending && pushCovers())
|
|
992
|
+
return;
|
|
993
|
+
await runCycle(undefined, pending ? undefined : owedScope());
|
|
994
|
+
})().catch(() => {
|
|
270
995
|
// Errors already captured in ring buffer
|
|
271
996
|
});
|
|
272
997
|
}, pollInterval);
|
|
@@ -277,6 +1002,110 @@ export function createSyncManager(uploadDeps, downloadDeps, options) {
|
|
|
277
1002
|
intervalId = null;
|
|
278
1003
|
}
|
|
279
1004
|
}
|
|
1005
|
+
function startProbeInterval() {
|
|
1006
|
+
const probe = options?.changeProbe;
|
|
1007
|
+
if (!probe || probeIntervalId !== null)
|
|
1008
|
+
return;
|
|
1009
|
+
probeIntervalId = setInterval(() => {
|
|
1010
|
+
if (Date.now() < nextTimedProbeAt)
|
|
1011
|
+
return; // backing off after failures
|
|
1012
|
+
// The held request announces every change: a marker read adds requests
|
|
1013
|
+
// and no news (see `pushAnnouncesChanges`).
|
|
1014
|
+
if (pushAnnouncesChanges())
|
|
1015
|
+
return;
|
|
1016
|
+
pull(false).catch(() => {
|
|
1017
|
+
// Errors already captured in ring buffer
|
|
1018
|
+
});
|
|
1019
|
+
}, probe.intervalMs);
|
|
1020
|
+
}
|
|
1021
|
+
function startChangePush() {
|
|
1022
|
+
const push = options?.changeProbe?.push;
|
|
1023
|
+
if (!push || stopPush !== null)
|
|
1024
|
+
return;
|
|
1025
|
+
const run = lifecycle;
|
|
1026
|
+
// A cycle the push asks for. It does not wait for the optional probe or
|
|
1027
|
+
// join a timed probe read in flight, so a probe that never answers cannot
|
|
1028
|
+
// hold it up; `runCycle` still runs one cycle at a time. It reads no marker
|
|
1029
|
+
// and publishes none: see `pulledMarker`.
|
|
1030
|
+
const cycleNow = (delta) => {
|
|
1031
|
+
if (retryTimer !== null) {
|
|
1032
|
+
// Cooling down after a failed cycle: the request is owed, and the
|
|
1033
|
+
// retry timer runs it. A push neither skips nor restarts the wait.
|
|
1034
|
+
rerunRequested = true;
|
|
1035
|
+
return;
|
|
1036
|
+
}
|
|
1037
|
+
runCycle(delta).catch(() => {
|
|
1038
|
+
// Errors already captured in ring buffer
|
|
1039
|
+
});
|
|
1040
|
+
};
|
|
1041
|
+
stopPush = push.subscribe({
|
|
1042
|
+
onChange(delta) {
|
|
1043
|
+
if (run !== lifecycle || !isRunning)
|
|
1044
|
+
return;
|
|
1045
|
+
// A reset can describe a restored registry whose counter went back.
|
|
1046
|
+
// It always owes a listing. Ordinary late answers cannot move either
|
|
1047
|
+
// the observed or the applied position backwards.
|
|
1048
|
+
if (delta?.reset) {
|
|
1049
|
+
// A lower counter needs a fresh baseline after the listing. It
|
|
1050
|
+
// cannot settle this answer's older position, even after restore.
|
|
1051
|
+
knownPosition =
|
|
1052
|
+
knownPosition !== undefined &&
|
|
1053
|
+
BigInt(delta.seq) < BigInt(knownPosition)
|
|
1054
|
+
? undefined
|
|
1055
|
+
: delta.seq;
|
|
1056
|
+
}
|
|
1057
|
+
else if (delta &&
|
|
1058
|
+
syncedPosition !== undefined &&
|
|
1059
|
+
BigInt(delta.seq) <= BigInt(syncedPosition))
|
|
1060
|
+
return;
|
|
1061
|
+
cycleNow(delta);
|
|
1062
|
+
},
|
|
1063
|
+
// The position this device holds the registry up to once its work in
|
|
1064
|
+
// flight ends: the target of the pass running, or of the follow-up a
|
|
1065
|
+
// request queued (it starts under the latest position the push gave).
|
|
1066
|
+
// Between cycles that is the last clean pass's. A pass that does not
|
|
1067
|
+
// end clean leaves no position (`syncedPosition` is cleared when a pass
|
|
1068
|
+
// starts), so after it the request asks from none.
|
|
1069
|
+
since: () => options?.accountStorageMode?.read() !== "switched"
|
|
1070
|
+
? undefined
|
|
1071
|
+
: cycleInFlight === null
|
|
1072
|
+
? syncedPosition
|
|
1073
|
+
: rerunRequested
|
|
1074
|
+
? knownPosition
|
|
1075
|
+
: inFlightTarget,
|
|
1076
|
+
onHealth(healthy) {
|
|
1077
|
+
if (run !== lifecycle)
|
|
1078
|
+
return;
|
|
1079
|
+
const wasHealthy = pushHealthy;
|
|
1080
|
+
pushHealthy = healthy;
|
|
1081
|
+
// While the push was silent its position could not vouch for the
|
|
1082
|
+
// registry, and a change committed in that time is not in any
|
|
1083
|
+
// position. Read once now rather than wait for the timer, which may
|
|
1084
|
+
// have skipped its last tick on the strength of that position.
|
|
1085
|
+
if (wasHealthy && !healthy && isRunning)
|
|
1086
|
+
cycleNow();
|
|
1087
|
+
},
|
|
1088
|
+
onPosition(position) {
|
|
1089
|
+
if (run !== lifecycle || !isRunning)
|
|
1090
|
+
return;
|
|
1091
|
+
if (knownPosition === undefined ||
|
|
1092
|
+
BigInt(position) >= BigInt(knownPosition))
|
|
1093
|
+
knownPosition = position;
|
|
1094
|
+
},
|
|
1095
|
+
});
|
|
1096
|
+
}
|
|
1097
|
+
function stopChangePush() {
|
|
1098
|
+
stopPush?.();
|
|
1099
|
+
stopPush = null;
|
|
1100
|
+
pushHealthy = false;
|
|
1101
|
+
knownPosition = undefined;
|
|
1102
|
+
}
|
|
1103
|
+
function clearProbeInterval() {
|
|
1104
|
+
if (probeIntervalId !== null) {
|
|
1105
|
+
clearInterval(probeIntervalId);
|
|
1106
|
+
probeIntervalId = null;
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
280
1109
|
function clearNotifyTimer() {
|
|
281
1110
|
if (notifyTimerId !== null) {
|
|
282
1111
|
clearTimeout(notifyTimerId);
|
|
@@ -291,32 +1120,116 @@ export function createSyncManager(uploadDeps, downloadDeps, options) {
|
|
|
291
1120
|
if (isRunning)
|
|
292
1121
|
return; // Idempotent
|
|
293
1122
|
isRunning = true;
|
|
1123
|
+
paused = false;
|
|
1124
|
+
owedWhilePaused = false;
|
|
1125
|
+
nextLifecycle("started");
|
|
1126
|
+
pulledMarker = undefined;
|
|
1127
|
+
cycleFailures = 0;
|
|
1128
|
+
probeFailures = 0;
|
|
1129
|
+
nextTimedProbeAt = 0;
|
|
1130
|
+
knownPosition = undefined;
|
|
1131
|
+
syncedPosition = undefined;
|
|
1132
|
+
refusedPosition = undefined;
|
|
1133
|
+
statusMayHaveChanged(); // running: true
|
|
294
1134
|
// Crash recovery: run one cycle immediately on start
|
|
295
1135
|
runCycle().catch(() => {
|
|
296
1136
|
// Errors already captured in ring buffer
|
|
297
1137
|
});
|
|
298
1138
|
startInterval();
|
|
1139
|
+
startProbeInterval();
|
|
1140
|
+
startChangePush();
|
|
299
1141
|
},
|
|
300
1142
|
async stop() {
|
|
1143
|
+
// Opens the stop's repair window before anything awaits, so a stop that
|
|
1144
|
+
// nothing awaits still holds its repair duty.
|
|
1145
|
+
const closing = uploadAttempts
|
|
1146
|
+
.close(namelessAttempts ? Infinity : undefined)
|
|
1147
|
+
.catch((err) => err);
|
|
301
1148
|
clearIntervalTimer();
|
|
1149
|
+
clearProbeInterval();
|
|
1150
|
+
stopChangePush();
|
|
302
1151
|
clearNotifyTimer();
|
|
1152
|
+
clearRetryTimer();
|
|
1153
|
+
rerunRequested = false;
|
|
1154
|
+
queuedDeltas = [];
|
|
1155
|
+
deltaBarred = false;
|
|
303
1156
|
isRunning = false;
|
|
1157
|
+
paused = false;
|
|
1158
|
+
owedWhilePaused = false;
|
|
1159
|
+
// Cancel pulls: a probe that answers later finds a new lifecycle value.
|
|
1160
|
+
nextLifecycle("stopped");
|
|
1161
|
+
statusMayHaveChanged(); // running: false
|
|
304
1162
|
// Wait for any in-flight cycle to complete
|
|
305
1163
|
if (cycleInFlight) {
|
|
306
1164
|
await cycleInFlight;
|
|
307
1165
|
}
|
|
1166
|
+
// Hand the upload markers to the next manager over this store, once no
|
|
1167
|
+
// attempt is still running (a running one keeps its entry excluded).
|
|
1168
|
+
// Without a stable store namespace a rebuilt manager gets a fresh,
|
|
1169
|
+
// unrelated lock, so only a fully drained stop keeps two managers over
|
|
1170
|
+
// the same persistence from overlapping.
|
|
1171
|
+
const err = await closing;
|
|
1172
|
+
if (err !== undefined) {
|
|
1173
|
+
// The ledger keeps the store and retries the repair itself; say so.
|
|
1174
|
+
pushError({
|
|
1175
|
+
fileId: null,
|
|
1176
|
+
scope: null,
|
|
1177
|
+
message: `Upload crash protection could not be saved on stop: ${err.message}`,
|
|
1178
|
+
timestamp: new Date().toISOString(),
|
|
1179
|
+
});
|
|
1180
|
+
uploadDeps.logger.error({ error: err.message }, "Upload attempt store could not be repaired on stop");
|
|
1181
|
+
}
|
|
308
1182
|
},
|
|
309
1183
|
async trigger() {
|
|
310
1184
|
// Clear existing timers, run immediately, restart interval
|
|
311
1185
|
clearIntervalTimer();
|
|
312
1186
|
clearNotifyTimer();
|
|
313
1187
|
await runCycle();
|
|
314
|
-
if (isRunning) {
|
|
1188
|
+
if (isRunning && !paused) {
|
|
315
1189
|
startInterval();
|
|
316
1190
|
}
|
|
317
1191
|
},
|
|
1192
|
+
pause() {
|
|
1193
|
+
if (!isRunning || paused)
|
|
1194
|
+
return;
|
|
1195
|
+
paused = true;
|
|
1196
|
+
// Stale answers (a probe, a poke) of the run before the hide are void.
|
|
1197
|
+
nextLifecycle("paused");
|
|
1198
|
+
// A debounced ingest still waiting for its timer is owed, not dropped.
|
|
1199
|
+
if (notifyTimerId !== null)
|
|
1200
|
+
owedWhilePaused = true;
|
|
1201
|
+
clearIntervalTimer();
|
|
1202
|
+
clearProbeInterval();
|
|
1203
|
+
clearNotifyTimer();
|
|
1204
|
+
clearRetryTimer();
|
|
1205
|
+
stopChangePush(); // aborts the held request and the push's own timers
|
|
1206
|
+
cycleFailures = 0;
|
|
1207
|
+
probeFailures = 0;
|
|
1208
|
+
nextTimedProbeAt = 0;
|
|
1209
|
+
},
|
|
1210
|
+
resume() {
|
|
1211
|
+
if (!isRunning || !paused)
|
|
1212
|
+
return;
|
|
1213
|
+
paused = false;
|
|
1214
|
+
startInterval();
|
|
1215
|
+
startProbeInterval();
|
|
1216
|
+
startChangePush();
|
|
1217
|
+
// A follow-up the last cycle owed, or an ingest, waited for this.
|
|
1218
|
+
const owed = owedWhilePaused || rerunRequested;
|
|
1219
|
+
owedWhilePaused = false;
|
|
1220
|
+
if (owed) {
|
|
1221
|
+
runCycle().catch(() => {
|
|
1222
|
+
// Errors already captured in ring buffer
|
|
1223
|
+
});
|
|
1224
|
+
}
|
|
1225
|
+
},
|
|
1226
|
+
requestPull,
|
|
318
1227
|
getStatus() {
|
|
319
|
-
const pendingFiles =
|
|
1228
|
+
const pendingFiles = options?.accountStorageMode &&
|
|
1229
|
+
options.accountStorageMode.read() !== "unswitched"
|
|
1230
|
+
? 0
|
|
1231
|
+
: (uploadDeps.storage.countUnsynced?.() ??
|
|
1232
|
+
uploadDeps.storage.findUnsynced().length);
|
|
320
1233
|
return {
|
|
321
1234
|
enabled: true,
|
|
322
1235
|
running: isRunning,
|
|
@@ -327,7 +1240,21 @@ export function createSyncManager(uploadDeps, downloadDeps, options) {
|
|
|
327
1240
|
pendingFiles,
|
|
328
1241
|
hydratedScopes: [...hydratedScopes],
|
|
329
1242
|
errors: [...errors],
|
|
1243
|
+
changeProbeMs: options?.changeProbe?.intervalMs ?? 0,
|
|
330
1244
|
deletions: tombstoneResubmits.snapshot(),
|
|
1245
|
+
...(blobDeletions ? { blobDeletions: { ...blobDeletions } } : {}),
|
|
1246
|
+
uploads: uploadState.snapshot(),
|
|
1247
|
+
};
|
|
1248
|
+
},
|
|
1249
|
+
subscribeStatus(listener) {
|
|
1250
|
+
statusListeners.add(listener);
|
|
1251
|
+
// The first subscriber's value is the baseline, not an event.
|
|
1252
|
+
if (statusListeners.size === 1)
|
|
1253
|
+
statusMayHaveChanged();
|
|
1254
|
+
return () => {
|
|
1255
|
+
statusListeners.delete(listener);
|
|
1256
|
+
if (statusListeners.size === 0)
|
|
1257
|
+
statusSeen = null;
|
|
331
1258
|
};
|
|
332
1259
|
},
|
|
333
1260
|
hydrateScopes(scopes) {
|
|
@@ -336,21 +1263,65 @@ export function createSyncManager(uploadDeps, downloadDeps, options) {
|
|
|
336
1263
|
if (!canRun.ok) {
|
|
337
1264
|
blocked = { reason: canRun.reason, message: canRun.message };
|
|
338
1265
|
downloadDeps.logger.warn(blocked, "Scope hydration blocked");
|
|
1266
|
+
statusMayHaveChanged();
|
|
339
1267
|
return;
|
|
340
1268
|
}
|
|
341
|
-
|
|
1269
|
+
const mode = options?.accountStorageMode?.read();
|
|
1270
|
+
clearBlockBeforePass(mode);
|
|
1271
|
+
statusMayHaveChanged();
|
|
1272
|
+
if (options?.accountStorageMode && mode !== undefined) {
|
|
1273
|
+
if (mode !== "unswitched") {
|
|
1274
|
+
if (mode === "switched" && options.localSync)
|
|
1275
|
+
await runLocalCycle(options.localSync);
|
|
1276
|
+
else {
|
|
1277
|
+
blocked = {
|
|
1278
|
+
reason: "account_mode_unknown",
|
|
1279
|
+
message: "Waiting for the account or its stream database",
|
|
1280
|
+
};
|
|
1281
|
+
statusMayHaveChanged();
|
|
1282
|
+
}
|
|
1283
|
+
return;
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
342
1286
|
await hydrateScopesExclusive(scopes);
|
|
343
1287
|
});
|
|
344
1288
|
},
|
|
345
1289
|
notifyNewData() {
|
|
346
1290
|
uploadDeps.logger.debug("New data notification received");
|
|
1291
|
+
statusMayHaveChanged(); // the new data is pending until a cycle takes it
|
|
347
1292
|
scheduleNotifiedCycle();
|
|
348
1293
|
},
|
|
349
|
-
|
|
350
|
-
|
|
1294
|
+
notifyRecordsCommitted() {
|
|
1295
|
+
uploadDeps.logger.debug("Records committed notification received");
|
|
1296
|
+
statusMayHaveChanged();
|
|
1297
|
+
scheduleNotifiedCycle(0);
|
|
1298
|
+
},
|
|
1299
|
+
async retryQuarantinedUploads(scope) {
|
|
1300
|
+
if (!(await uploadAttempts.recover()))
|
|
1301
|
+
return;
|
|
1302
|
+
try {
|
|
1303
|
+
for (const path of await uploadAttempts.release(scope))
|
|
1304
|
+
uploadState.clear(path);
|
|
1305
|
+
}
|
|
1306
|
+
finally {
|
|
1307
|
+
// The tracker's snapshot is part of the status, and a release that
|
|
1308
|
+
// fails part way has still cleared the paths before it.
|
|
1309
|
+
statusMayHaveChanged();
|
|
1310
|
+
}
|
|
1311
|
+
},
|
|
1312
|
+
async deleteScope(scope, within) {
|
|
1313
|
+
const result = await exclusive(async () => {
|
|
351
1314
|
// A delete the user asks for starts a fresh set of re-submissions.
|
|
352
1315
|
tombstoneResubmits.reset(scope);
|
|
353
|
-
|
|
1316
|
+
const outcome = within
|
|
1317
|
+
? await within((hold) => deleteScope(deleteScopeDeps(), scope, { hold }))
|
|
1318
|
+
: await deleteScope(deleteScopeDeps(), scope);
|
|
1319
|
+
// Upload state follows the rows. A failed delete removed nothing, so
|
|
1320
|
+
// its entries keep their budget and status; entries the delete did
|
|
1321
|
+
// remove are forgotten by comparing with what is still unsynced.
|
|
1322
|
+
uploadState.reconcile(uploadDeps.storage.findUnsynced());
|
|
1323
|
+
statusMayHaveChanged();
|
|
1324
|
+
return outcome;
|
|
354
1325
|
});
|
|
355
1326
|
if (result.durable && uploadDeps.additions)
|
|
356
1327
|
await uploadDeps.additions.deleteScope(scope);
|