@opendatalabs/personal-server-ts-core 0.0.1-canary.052d47e → 0.0.1-canary.0620a9a
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/dist/additions/budget.d.ts +34 -0
- package/dist/additions/budget.d.ts.map +1 -0
- package/dist/additions/budget.js +144 -0
- package/dist/additions/budget.js.map +1 -0
- package/dist/additions/durable.d.ts +94 -0
- package/dist/additions/durable.d.ts.map +1 -0
- package/dist/additions/durable.js +823 -0
- package/dist/additions/durable.js.map +1 -0
- package/dist/additions/first-added.d.ts +204 -0
- package/dist/additions/first-added.d.ts.map +1 -0
- package/dist/additions/first-added.js +598 -0
- package/dist/additions/first-added.js.map +1 -0
- package/dist/additions/index.d.ts +9 -0
- package/dist/additions/index.d.ts.map +1 -0
- package/dist/additions/index.js +9 -0
- package/dist/additions/index.js.map +1 -0
- package/dist/additions/ledger-store.d.ts +69 -0
- package/dist/additions/ledger-store.d.ts.map +1 -0
- package/dist/additions/ledger-store.js +407 -0
- package/dist/additions/ledger-store.js.map +1 -0
- package/dist/additions/record-rules.d.ts +54 -0
- package/dist/additions/record-rules.d.ts.map +1 -0
- package/dist/additions/record-rules.js +198 -0
- package/dist/additions/record-rules.js.map +1 -0
- package/dist/additions/scope-lock.d.ts +14 -0
- package/dist/additions/scope-lock.d.ts.map +1 -0
- package/dist/additions/scope-lock.js +32 -0
- package/dist/additions/scope-lock.js.map +1 -0
- package/dist/additions/summary.d.ts +143 -0
- package/dist/additions/summary.d.ts.map +1 -0
- package/dist/additions/summary.js +279 -0
- package/dist/additions/summary.js.map +1 -0
- package/dist/additions/version-inventory.d.ts +86 -0
- package/dist/additions/version-inventory.d.ts.map +1 -0
- package/dist/additions/version-inventory.js +244 -0
- package/dist/additions/version-inventory.js.map +1 -0
- package/dist/api/index.d.ts +192 -8
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +1227 -153
- package/dist/api/index.js.map +1 -1
- package/dist/api/oura-collection-requirements.d.ts +16 -0
- package/dist/api/oura-collection-requirements.d.ts.map +1 -0
- package/dist/api/oura-collection-requirements.js +70 -0
- package/dist/api/oura-collection-requirements.js.map +1 -0
- package/dist/api/raw-envelope.d.ts +3 -0
- package/dist/api/raw-envelope.d.ts.map +1 -0
- package/dist/api/raw-envelope.js +215 -0
- package/dist/api/raw-envelope.js.map +1 -0
- package/dist/api/scope-upload-batches.d.ts +18 -0
- package/dist/api/scope-upload-batches.d.ts.map +1 -0
- package/dist/api/scope-upload-batches.js +71 -0
- package/dist/api/scope-upload-batches.js.map +1 -0
- package/dist/api/scope-uploads.d.ts +112 -0
- package/dist/api/scope-uploads.d.ts.map +1 -0
- package/dist/api/scope-uploads.js +369 -0
- package/dist/api/scope-uploads.js.map +1 -0
- package/dist/auth/index.d.ts +3 -1
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +3 -1
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/proof-id.d.ts +8 -0
- package/dist/auth/proof-id.d.ts.map +1 -0
- package/dist/auth/proof-id.js +29 -0
- package/dist/auth/proof-id.js.map +1 -0
- package/dist/auth/request.d.ts +24 -0
- package/dist/auth/request.d.ts.map +1 -1
- package/dist/auth/request.js +99 -4
- package/dist/auth/request.js.map +1 -1
- package/dist/client.d.ts +70 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +1 -0
- package/dist/client.js.map +1 -1
- package/dist/contracts/auth-device.d.ts +10 -0
- package/dist/contracts/auth-device.d.ts.map +1 -1
- package/dist/contracts/auth-device.js +2 -0
- package/dist/contracts/auth-device.js.map +1 -1
- package/dist/contracts/data.d.ts +102 -8
- package/dist/contracts/data.d.ts.map +1 -1
- package/dist/contracts/data.js +320 -47
- package/dist/contracts/data.js.map +1 -1
- package/dist/contracts/grants.d.ts.map +1 -1
- package/dist/contracts/grants.js +7 -0
- package/dist/contracts/grants.js.map +1 -1
- package/dist/contracts/index.d.ts +4 -2
- package/dist/contracts/index.d.ts.map +1 -1
- package/dist/contracts/index.js +3 -1
- package/dist/contracts/index.js.map +1 -1
- package/dist/contracts/oura-collection-requirements.d.ts +17 -0
- package/dist/contracts/oura-collection-requirements.d.ts.map +1 -0
- package/dist/contracts/oura-collection-requirements.js +49 -0
- package/dist/contracts/oura-collection-requirements.js.map +1 -0
- package/dist/contracts/sync.d.ts.map +1 -1
- package/dist/contracts/sync.js +1 -0
- package/dist/contracts/sync.js.map +1 -1
- package/dist/derivatives/answer-shape.d.ts +83 -0
- package/dist/derivatives/answer-shape.d.ts.map +1 -0
- package/dist/derivatives/answer-shape.js +320 -0
- package/dist/derivatives/answer-shape.js.map +1 -0
- package/dist/derivatives/api.d.ts +1 -1
- package/dist/derivatives/api.d.ts.map +1 -1
- package/dist/derivatives/api.js +8 -0
- package/dist/derivatives/api.js.map +1 -1
- package/dist/derivatives/compute.d.ts +9 -3
- package/dist/derivatives/compute.d.ts.map +1 -1
- package/dist/derivatives/compute.js +68 -6
- package/dist/derivatives/compute.js.map +1 -1
- package/dist/derivatives/index.d.ts +2 -1
- package/dist/derivatives/index.d.ts.map +1 -1
- package/dist/derivatives/index.js +2 -1
- package/dist/derivatives/index.js.map +1 -1
- package/dist/derivatives/prompt.d.ts +35 -0
- package/dist/derivatives/prompt.d.ts.map +1 -1
- package/dist/derivatives/prompt.js +96 -8
- package/dist/derivatives/prompt.js.map +1 -1
- package/dist/derivatives/registration.d.ts +6 -9
- package/dist/derivatives/registration.d.ts.map +1 -1
- package/dist/derivatives/registration.js +14 -6
- package/dist/derivatives/registration.js.map +1 -1
- package/dist/derivatives/scheduler.d.ts +39 -9
- package/dist/derivatives/scheduler.d.ts.map +1 -1
- package/dist/derivatives/scheduler.js +99 -8
- package/dist/derivatives/scheduler.js.map +1 -1
- package/dist/derivatives/store.d.ts.map +1 -1
- package/dist/derivatives/store.js +2 -0
- package/dist/derivatives/store.js.map +1 -1
- package/dist/derivatives/types.d.ts +13 -3
- package/dist/derivatives/types.d.ts.map +1 -1
- package/dist/derivatives/types.js +2 -0
- package/dist/derivatives/types.js.map +1 -1
- package/dist/errors/pdpp-catalog.d.ts +36 -0
- package/dist/errors/pdpp-catalog.d.ts.map +1 -0
- package/dist/errors/pdpp-catalog.js +86 -0
- package/dist/errors/pdpp-catalog.js.map +1 -0
- package/dist/grants/index.d.ts +2 -0
- package/dist/grants/index.d.ts.map +1 -1
- package/dist/grants/index.js +4 -0
- package/dist/grants/index.js.map +1 -1
- package/dist/grants/pdpp-binding-store.d.ts +89 -0
- package/dist/grants/pdpp-binding-store.d.ts.map +1 -0
- package/dist/grants/pdpp-binding-store.js +112 -0
- package/dist/grants/pdpp-binding-store.js.map +1 -0
- package/dist/grants/pdpp-binding.d.ts +169 -0
- package/dist/grants/pdpp-binding.d.ts.map +1 -0
- package/dist/grants/pdpp-binding.js +236 -0
- package/dist/grants/pdpp-binding.js.map +1 -0
- package/dist/legacy-projection/bindings.d.ts +31 -0
- package/dist/legacy-projection/bindings.d.ts.map +1 -0
- package/dist/legacy-projection/bindings.js +4512 -0
- package/dist/legacy-projection/bindings.js.map +1 -0
- package/dist/legacy-projection/claude-source-record.d.ts +22 -0
- package/dist/legacy-projection/claude-source-record.d.ts.map +1 -0
- package/dist/legacy-projection/claude-source-record.js +360 -0
- package/dist/legacy-projection/claude-source-record.js.map +1 -0
- package/dist/legacy-projection/declared-text.d.ts +41 -0
- package/dist/legacy-projection/declared-text.d.ts.map +1 -0
- package/dist/legacy-projection/declared-text.js +199 -0
- package/dist/legacy-projection/declared-text.js.map +1 -0
- package/dist/legacy-projection/github-browser-bindings.d.ts +3 -0
- package/dist/legacy-projection/github-browser-bindings.d.ts.map +1 -0
- package/dist/legacy-projection/github-browser-bindings.js +212 -0
- package/dist/legacy-projection/github-browser-bindings.js.map +1 -0
- package/dist/legacy-projection/github-legacy-fields.d.ts +6 -0
- package/dist/legacy-projection/github-legacy-fields.d.ts.map +1 -0
- package/dist/legacy-projection/github-legacy-fields.js +202 -0
- package/dist/legacy-projection/github-legacy-fields.js.map +1 -0
- package/dist/legacy-projection/index.d.ts +38 -0
- package/dist/legacy-projection/index.d.ts.map +1 -0
- package/dist/legacy-projection/index.js +231 -0
- package/dist/legacy-projection/index.js.map +1 -0
- package/dist/legacy-projection/meta-040-bindings.d.ts +3 -0
- package/dist/legacy-projection/meta-040-bindings.d.ts.map +1 -0
- package/dist/legacy-projection/meta-040-bindings.js +112 -0
- package/dist/legacy-projection/meta-040-bindings.js.map +1 -0
- package/dist/legacy-projection/oura-browser-bindings.d.ts +5 -0
- package/dist/legacy-projection/oura-browser-bindings.d.ts.map +1 -0
- package/dist/legacy-projection/oura-browser-bindings.js +141 -0
- package/dist/legacy-projection/oura-browser-bindings.js.map +1 -0
- package/dist/legacy-projection/provenance.d.ts +57 -0
- package/dist/legacy-projection/provenance.d.ts.map +1 -0
- package/dist/legacy-projection/provenance.js +2 -0
- package/dist/legacy-projection/provenance.js.map +1 -0
- package/dist/legacy-projection/strava-browser-bindings.d.ts +3 -0
- package/dist/legacy-projection/strava-browser-bindings.d.ts.map +1 -0
- package/dist/legacy-projection/strava-browser-bindings.js +32 -0
- package/dist/legacy-projection/strava-browser-bindings.js.map +1 -0
- package/dist/legacy-projection/test-debris.d.ts +2 -0
- package/dist/legacy-projection/test-debris.d.ts.map +1 -0
- package/dist/legacy-projection/test-debris.js +49 -0
- package/dist/legacy-projection/test-debris.js.map +1 -0
- package/dist/legacy-projection/types.d.ts +235 -0
- package/dist/legacy-projection/types.d.ts.map +1 -0
- package/dist/legacy-projection/types.js +2 -0
- package/dist/legacy-projection/types.js.map +1 -0
- package/dist/mcp/approval-url.d.ts +68 -0
- package/dist/mcp/approval-url.d.ts.map +1 -0
- package/dist/mcp/approval-url.js +95 -0
- package/dist/mcp/approval-url.js.map +1 -0
- package/dist/mcp/connection-api.d.ts +187 -3
- package/dist/mcp/connection-api.d.ts.map +1 -1
- package/dist/mcp/connection-api.js +600 -26
- package/dist/mcp/connection-api.js.map +1 -1
- package/dist/mcp/grantee.d.ts +1 -1
- package/dist/mcp/grantee.d.ts.map +1 -1
- package/dist/mcp/index.d.ts +4 -0
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +4 -0
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/oauth-redirect.d.ts +14 -0
- package/dist/mcp/oauth-redirect.d.ts.map +1 -0
- package/dist/mcp/oauth-redirect.js +51 -0
- package/dist/mcp/oauth-redirect.js.map +1 -0
- package/dist/mcp/read-client.d.ts +5 -1
- package/dist/mcp/read-client.d.ts.map +1 -1
- package/dist/mcp/read-client.js +18 -4
- package/dist/mcp/read-client.js.map +1 -1
- package/dist/mcp/resources.d.ts.map +1 -1
- package/dist/mcp/resources.js +3 -0
- package/dist/mcp/resources.js.map +1 -1
- package/dist/mcp/server.d.ts +30 -0
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +172 -17
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/session.d.ts +1 -1
- package/dist/mcp/session.d.ts.map +1 -1
- package/dist/mcp/session.js +17 -3
- package/dist/mcp/session.js.map +1 -1
- package/dist/mcp/store.d.ts +10 -1
- package/dist/mcp/store.d.ts.map +1 -1
- package/dist/mcp/store.js +72 -0
- package/dist/mcp/store.js.map +1 -1
- package/dist/mcp/token-expiry.d.ts +48 -0
- package/dist/mcp/token-expiry.d.ts.map +1 -0
- package/dist/mcp/token-expiry.js +69 -0
- package/dist/mcp/token-expiry.js.map +1 -0
- package/dist/mcp/tools.d.ts +92 -3
- package/dist/mcp/tools.d.ts.map +1 -1
- package/dist/mcp/tools.js +513 -28
- package/dist/mcp/tools.js.map +1 -1
- package/dist/mcp/types.d.ts +103 -4
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/mcp/types.js +13 -1
- package/dist/mcp/types.js.map +1 -1
- package/dist/mcp/write-client.d.ts +81 -0
- package/dist/mcp/write-client.d.ts.map +1 -0
- package/dist/mcp/write-client.js +140 -0
- package/dist/mcp/write-client.js.map +1 -0
- package/dist/oura/history-policy.d.ts +12 -0
- package/dist/oura/history-policy.d.ts.map +1 -0
- package/dist/oura/history-policy.js +54 -0
- package/dist/oura/history-policy.js.map +1 -0
- package/dist/oura/index.d.ts +51 -0
- package/dist/oura/index.d.ts.map +1 -0
- package/dist/oura/index.js +315 -0
- package/dist/oura/index.js.map +1 -0
- package/dist/payment/own-app.d.ts +8 -0
- package/dist/payment/own-app.d.ts.map +1 -0
- package/dist/payment/own-app.js +47 -0
- package/dist/payment/own-app.js.map +1 -0
- package/dist/pdpp/approval.d.ts +271 -0
- package/dist/pdpp/approval.d.ts.map +1 -0
- package/dist/pdpp/approval.js +486 -0
- package/dist/pdpp/approval.js.map +1 -0
- package/dist/pdpp/client-identity.d.ts +88 -0
- package/dist/pdpp/client-identity.d.ts.map +1 -0
- package/dist/pdpp/client-identity.js +196 -0
- package/dist/pdpp/client-identity.js.map +1 -0
- package/dist/pdpp/client-metadata.d.ts +95 -0
- package/dist/pdpp/client-metadata.d.ts.map +1 -0
- package/dist/pdpp/client-metadata.js +96 -0
- package/dist/pdpp/client-metadata.js.map +1 -0
- package/dist/pdpp/commitments.d.ts +75 -0
- package/dist/pdpp/commitments.d.ts.map +1 -0
- package/dist/pdpp/commitments.js +113 -0
- package/dist/pdpp/commitments.js.map +1 -0
- package/dist/pdpp/declaration-limits.d.ts +7 -0
- package/dist/pdpp/declaration-limits.d.ts.map +1 -0
- package/dist/pdpp/declaration-limits.js +7 -0
- package/dist/pdpp/declaration-limits.js.map +1 -0
- package/dist/pdpp/declaration.d.ts +119 -0
- package/dist/pdpp/declaration.d.ts.map +1 -0
- package/dist/pdpp/declaration.js +837 -0
- package/dist/pdpp/declaration.js.map +1 -0
- package/dist/pdpp/index.d.ts +38 -0
- package/dist/pdpp/index.d.ts.map +1 -0
- package/dist/pdpp/index.js +24 -0
- package/dist/pdpp/index.js.map +1 -0
- package/dist/pdpp/issuance.d.ts +126 -0
- package/dist/pdpp/issuance.d.ts.map +1 -0
- package/dist/pdpp/issuance.js +184 -0
- package/dist/pdpp/issuance.js.map +1 -0
- package/dist/pdpp/pkce.d.ts +53 -0
- package/dist/pdpp/pkce.d.ts.map +1 -0
- package/dist/pdpp/pkce.js +109 -0
- package/dist/pdpp/pkce.js.map +1 -0
- package/dist/pdpp/redirect.d.ts +60 -0
- package/dist/pdpp/redirect.d.ts.map +1 -0
- package/dist/pdpp/redirect.js +125 -0
- package/dist/pdpp/redirect.js.map +1 -0
- package/dist/pdpp/resolve.d.ts +120 -0
- package/dist/pdpp/resolve.d.ts.map +1 -0
- package/dist/pdpp/resolve.js +491 -0
- package/dist/pdpp/resolve.js.map +1 -0
- package/dist/pdpp/review.d.ts +280 -0
- package/dist/pdpp/review.d.ts.map +1 -0
- package/dist/pdpp/review.js +205 -0
- package/dist/pdpp/review.js.map +1 -0
- package/dist/pdpp/selection.d.ts +79 -0
- package/dist/pdpp/selection.d.ts.map +1 -0
- package/dist/pdpp/selection.js +493 -0
- package/dist/pdpp/selection.js.map +1 -0
- package/dist/pdpp/store.d.ts +228 -0
- package/dist/pdpp/store.d.ts.map +1 -0
- package/dist/pdpp/store.js +542 -0
- package/dist/pdpp/store.js.map +1 -0
- package/dist/pdpp/time.d.ts +39 -0
- package/dist/pdpp/time.d.ts.map +1 -0
- package/dist/pdpp/time.js +173 -0
- package/dist/pdpp/time.js.map +1 -0
- package/dist/pdpp/tokens.d.ts +181 -0
- package/dist/pdpp/tokens.d.ts.map +1 -0
- package/dist/pdpp/tokens.js +421 -0
- package/dist/pdpp/tokens.js.map +1 -0
- package/dist/pdpp/types.d.ts +457 -0
- package/dist/pdpp/types.d.ts.map +1 -0
- package/dist/pdpp/types.js +68 -0
- package/dist/pdpp/types.js.map +1 -0
- package/dist/pdpp-version.d.ts +28 -0
- package/dist/pdpp-version.d.ts.map +1 -0
- package/dist/pdpp-version.js +28 -0
- package/dist/pdpp-version.js.map +1 -0
- package/dist/policy/data-read.d.ts +52 -1
- package/dist/policy/data-read.d.ts.map +1 -1
- package/dist/policy/data-read.js +157 -3
- package/dist/policy/data-read.js.map +1 -1
- package/dist/policy/data-write.d.ts.map +1 -1
- package/dist/policy/data-write.js +18 -1
- package/dist/policy/data-write.js.map +1 -1
- package/dist/policy/index.d.ts +2 -1
- package/dist/policy/index.d.ts.map +1 -1
- package/dist/policy/index.js +2 -1
- package/dist/policy/index.js.map +1 -1
- package/dist/policy/reserved-scopes.d.ts +10 -0
- package/dist/policy/reserved-scopes.d.ts.map +1 -0
- package/dist/policy/reserved-scopes.js +16 -0
- package/dist/policy/reserved-scopes.js.map +1 -0
- package/dist/ports/index.d.ts +266 -5
- package/dist/ports/index.d.ts.map +1 -1
- package/dist/ports/index.js.map +1 -1
- package/dist/ports/pdpp-auth.d.ts +119 -0
- package/dist/ports/pdpp-auth.d.ts.map +1 -0
- package/dist/ports/pdpp-auth.js +46 -0
- package/dist/ports/pdpp-auth.js.map +1 -0
- package/dist/ports/pdpp-auth.test-utils.d.ts +9 -0
- package/dist/ports/pdpp-auth.test-utils.d.ts.map +1 -0
- package/dist/ports/pdpp-auth.test-utils.js +18 -0
- package/dist/ports/pdpp-auth.test-utils.js.map +1 -0
- package/dist/publication/publish.d.ts +109 -0
- package/dist/publication/publish.d.ts.map +1 -0
- package/dist/publication/publish.js +263 -0
- package/dist/publication/publish.js.map +1 -0
- package/dist/replication/completion.d.ts +20 -0
- package/dist/replication/completion.d.ts.map +1 -0
- package/dist/replication/completion.js +73 -0
- package/dist/replication/completion.js.map +1 -0
- package/dist/replication/coordinator-state.d.ts +29 -0
- package/dist/replication/coordinator-state.d.ts.map +1 -0
- package/dist/replication/coordinator-state.js +88 -0
- package/dist/replication/coordinator-state.js.map +1 -0
- package/dist/replication/coordinator-state.test-utils.d.ts +32 -0
- package/dist/replication/coordinator-state.test-utils.d.ts.map +1 -0
- package/dist/replication/coordinator-state.test-utils.js +113 -0
- package/dist/replication/coordinator-state.test-utils.js.map +1 -0
- package/dist/replication/coordinator.d.ts +264 -0
- package/dist/replication/coordinator.d.ts.map +1 -0
- package/dist/replication/coordinator.js +499 -0
- package/dist/replication/coordinator.js.map +1 -0
- package/dist/replication/copies.d.ts +126 -0
- package/dist/replication/copies.d.ts.map +1 -0
- package/dist/replication/copies.js +437 -0
- package/dist/replication/copies.js.map +1 -0
- package/dist/replication/copy-promotion.d.ts +132 -0
- package/dist/replication/copy-promotion.d.ts.map +1 -0
- package/dist/replication/copy-promotion.js +126 -0
- package/dist/replication/copy-promotion.js.map +1 -0
- package/dist/replication/door.d.ts +33 -0
- package/dist/replication/door.d.ts.map +1 -0
- package/dist/replication/door.js +10 -0
- package/dist/replication/door.js.map +1 -0
- package/dist/replication/dpv2.d.ts +141 -0
- package/dist/replication/dpv2.d.ts.map +1 -0
- package/dist/replication/dpv2.js +320 -0
- package/dist/replication/dpv2.js.map +1 -0
- package/dist/replication/effects.d.ts +68 -0
- package/dist/replication/effects.d.ts.map +1 -0
- package/dist/replication/effects.js +89 -0
- package/dist/replication/effects.js.map +1 -0
- package/dist/replication/engine.d.ts +378 -0
- package/dist/replication/engine.d.ts.map +1 -0
- package/dist/replication/engine.js +3197 -0
- package/dist/replication/engine.js.map +1 -0
- package/dist/replication/envelope.d.ts +481 -0
- package/dist/replication/envelope.d.ts.map +1 -0
- package/dist/replication/envelope.js +192 -0
- package/dist/replication/envelope.js.map +1 -0
- package/dist/replication/evidence.d.ts +118 -0
- package/dist/replication/evidence.d.ts.map +1 -0
- package/dist/replication/evidence.js +198 -0
- package/dist/replication/evidence.js.map +1 -0
- package/dist/replication/finality.d.ts +16 -0
- package/dist/replication/finality.d.ts.map +1 -0
- package/dist/replication/finality.js +11 -0
- package/dist/replication/finality.js.map +1 -0
- package/dist/replication/fixtures.d.ts +16 -0
- package/dist/replication/fixtures.d.ts.map +1 -0
- package/dist/replication/fixtures.js +47 -0
- package/dist/replication/fixtures.js.map +1 -0
- package/dist/replication/host-config.d.ts +52 -0
- package/dist/replication/host-config.d.ts.map +1 -0
- package/dist/replication/host-config.js +111 -0
- package/dist/replication/host-config.js.map +1 -0
- package/dist/replication/host-driver.d.ts +95 -0
- package/dist/replication/host-driver.d.ts.map +1 -0
- package/dist/replication/host-driver.js +202 -0
- package/dist/replication/host-driver.js.map +1 -0
- package/dist/replication/host-ports.d.ts +48 -0
- package/dist/replication/host-ports.d.ts.map +1 -0
- package/dist/replication/host-ports.js +69 -0
- package/dist/replication/host-ports.js.map +1 -0
- package/dist/replication/identity.d.ts +13 -0
- package/dist/replication/identity.d.ts.map +1 -0
- package/dist/replication/identity.js +22 -0
- package/dist/replication/identity.js.map +1 -0
- package/dist/replication/limits.d.ts +124 -0
- package/dist/replication/limits.d.ts.map +1 -0
- package/dist/replication/limits.js +182 -0
- package/dist/replication/limits.js.map +1 -0
- package/dist/replication/merge-plan.d.ts +92 -0
- package/dist/replication/merge-plan.d.ts.map +1 -0
- package/dist/replication/merge-plan.js +229 -0
- package/dist/replication/merge-plan.js.map +1 -0
- package/dist/replication/namespace.d.ts +4 -0
- package/dist/replication/namespace.d.ts.map +1 -0
- package/dist/replication/namespace.js +7 -0
- package/dist/replication/namespace.js.map +1 -0
- package/dist/replication/outcome.d.ts +178 -0
- package/dist/replication/outcome.d.ts.map +1 -0
- package/dist/replication/outcome.js +83 -0
- package/dist/replication/outcome.js.map +1 -0
- package/dist/replication/payload.d.ts +39 -0
- package/dist/replication/payload.d.ts.map +1 -0
- package/dist/replication/payload.js +137 -0
- package/dist/replication/payload.js.map +1 -0
- package/dist/replication/preparation.d.ts +42 -0
- package/dist/replication/preparation.d.ts.map +1 -0
- package/dist/replication/preparation.js +118 -0
- package/dist/replication/preparation.js.map +1 -0
- package/dist/replication/rebaseline.d.ts +33 -0
- package/dist/replication/rebaseline.d.ts.map +1 -0
- package/dist/replication/rebaseline.js +40 -0
- package/dist/replication/rebaseline.js.map +1 -0
- package/dist/replication/rebinding.d.ts +43 -0
- package/dist/replication/rebinding.d.ts.map +1 -0
- package/dist/replication/rebinding.js +52 -0
- package/dist/replication/rebinding.js.map +1 -0
- package/dist/replication/receive.d.ts +57 -0
- package/dist/replication/receive.d.ts.map +1 -0
- package/dist/replication/receive.js +114 -0
- package/dist/replication/receive.js.map +1 -0
- package/dist/replication/record-reducer.d.ts +16 -0
- package/dist/replication/record-reducer.d.ts.map +1 -0
- package/dist/replication/record-reducer.js +52 -0
- package/dist/replication/record-reducer.js.map +1 -0
- package/dist/replication/revision.d.ts +24 -0
- package/dist/replication/revision.d.ts.map +1 -0
- package/dist/replication/revision.js +35 -0
- package/dist/replication/revision.js.map +1 -0
- package/dist/replication/roster.d.ts +53 -0
- package/dist/replication/roster.d.ts.map +1 -0
- package/dist/replication/roster.js +115 -0
- package/dist/replication/roster.js.map +1 -0
- package/dist/replication/schedule.d.ts +73 -0
- package/dist/replication/schedule.d.ts.map +1 -0
- package/dist/replication/schedule.js +182 -0
- package/dist/replication/schedule.js.map +1 -0
- package/dist/replication/stream.d.ts +73 -0
- package/dist/replication/stream.d.ts.map +1 -0
- package/dist/replication/stream.js +542 -0
- package/dist/replication/stream.js.map +1 -0
- package/dist/replication/transport.d.ts +236 -0
- package/dist/replication/transport.d.ts.map +1 -0
- package/dist/replication/transport.js +440 -0
- package/dist/replication/transport.js.map +1 -0
- package/dist/replication/visibility-engine.d.ts +337 -0
- package/dist/replication/visibility-engine.d.ts.map +1 -0
- package/dist/replication/visibility-engine.js +602 -0
- package/dist/replication/visibility-engine.js.map +1 -0
- package/dist/replication/visibility-policy.d.ts +26 -0
- package/dist/replication/visibility-policy.d.ts.map +1 -0
- package/dist/replication/visibility-policy.js +33 -0
- package/dist/replication/visibility-policy.js.map +1 -0
- package/dist/replication/writer-identity-store.d.ts +100 -0
- package/dist/replication/writer-identity-store.d.ts.map +1 -0
- package/dist/replication/writer-identity-store.js +218 -0
- package/dist/replication/writer-identity-store.js.map +1 -0
- package/dist/replication/writer-identity.d.ts +252 -0
- package/dist/replication/writer-identity.d.ts.map +1 -0
- package/dist/replication/writer-identity.js +281 -0
- package/dist/replication/writer-identity.js.map +1 -0
- package/dist/replication/writer-identity.test-utils.d.ts +24 -0
- package/dist/replication/writer-identity.test-utils.d.ts.map +1 -0
- package/dist/replication/writer-identity.test-utils.js +86 -0
- package/dist/replication/writer-identity.test-utils.js.map +1 -0
- package/dist/schemas/server-config.d.ts +71 -0
- package/dist/schemas/server-config.d.ts.map +1 -1
- package/dist/schemas/server-config.js +151 -0
- package/dist/schemas/server-config.js.map +1 -1
- package/dist/signing/request-signer.d.ts +2 -0
- package/dist/signing/request-signer.d.ts.map +1 -1
- package/dist/signing/request-signer.js +1 -0
- package/dist/signing/request-signer.js.map +1 -1
- package/dist/storage/adapters/index.d.ts +3 -1
- package/dist/storage/adapters/index.d.ts.map +1 -1
- package/dist/storage/adapters/index.js +2 -0
- package/dist/storage/adapters/index.js.map +1 -1
- package/dist/storage/adapters/interface.d.ts +21 -1
- package/dist/storage/adapters/interface.d.ts.map +1 -1
- package/dist/storage/adapters/interface.js +13 -1
- package/dist/storage/adapters/interface.js.map +1 -1
- package/dist/storage/adapters/sdk.d.ts +2 -1
- package/dist/storage/adapters/sdk.d.ts.map +1 -1
- package/dist/storage/adapters/sdk.js +21 -3
- package/dist/storage/adapters/sdk.js.map +1 -1
- package/dist/storage/adapters/vana-audience.d.ts +24 -0
- package/dist/storage/adapters/vana-audience.d.ts.map +1 -0
- package/dist/storage/adapters/vana-audience.js +87 -0
- package/dist/storage/adapters/vana-audience.js.map +1 -0
- package/dist/storage/adapters/vana.d.ts +5 -3
- package/dist/storage/adapters/vana.d.ts.map +1 -1
- package/dist/storage/adapters/vana.js +69 -23
- package/dist/storage/adapters/vana.js.map +1 -1
- package/dist/storage/blocks/cursor.d.ts +5 -1
- package/dist/storage/blocks/cursor.d.ts.map +1 -1
- package/dist/storage/blocks/cursor.js +13 -1
- package/dist/storage/blocks/cursor.js.map +1 -1
- package/dist/storage/blocks/page.d.ts +18 -0
- package/dist/storage/blocks/page.d.ts.map +1 -0
- package/dist/storage/blocks/page.js +113 -0
- package/dist/storage/blocks/page.js.map +1 -0
- package/dist/storage/canonical-legacy-projection.d.ts +262 -0
- package/dist/storage/canonical-legacy-projection.d.ts.map +1 -0
- package/dist/storage/canonical-legacy-projection.js +759 -0
- package/dist/storage/canonical-legacy-projection.js.map +1 -0
- 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 +30 -3
- package/dist/storage/index/manager.d.ts.map +1 -1
- package/dist/storage/index/schema.d.ts +1 -1
- package/dist/storage/index/schema.js +1 -1
- package/dist/storage/index/types.d.ts +7 -1
- package/dist/storage/index/types.d.ts.map +1 -1
- package/dist/storage/legacy-projection.d.ts +88 -0
- package/dist/storage/legacy-projection.d.ts.map +1 -0
- package/dist/storage/legacy-projection.js +755 -0
- package/dist/storage/legacy-projection.js.map +1 -0
- package/dist/storage/legacy-scope-coverage-exceptions.d.ts +13 -0
- package/dist/storage/legacy-scope-coverage-exceptions.d.ts.map +1 -0
- package/dist/storage/legacy-scope-coverage-exceptions.js +14 -0
- package/dist/storage/legacy-scope-coverage-exceptions.js.map +1 -0
- package/dist/storage/legacy-scope-coverage.d.ts +53 -0
- package/dist/storage/legacy-scope-coverage.d.ts.map +1 -0
- package/dist/storage/legacy-scope-coverage.js +416 -0
- package/dist/storage/legacy-scope-coverage.js.map +1 -0
- package/dist/storage/legacy-scope-entity-keys.d.ts +17 -0
- package/dist/storage/legacy-scope-entity-keys.d.ts.map +1 -0
- package/dist/storage/legacy-scope-entity-keys.js +109 -0
- package/dist/storage/legacy-scope-entity-keys.js.map +1 -0
- package/dist/storage/legacy-scope-view.d.ts +206 -0
- package/dist/storage/legacy-scope-view.d.ts.map +1 -0
- package/dist/storage/legacy-scope-view.js +1061 -0
- package/dist/storage/legacy-scope-view.js.map +1 -0
- package/dist/storage/pdpp-records/completion.d.ts +91 -0
- package/dist/storage/pdpp-records/completion.d.ts.map +1 -0
- package/dist/storage/pdpp-records/completion.js +170 -0
- package/dist/storage/pdpp-records/completion.js.map +1 -0
- package/dist/storage/pdpp-records/cursor.d.ts +86 -0
- package/dist/storage/pdpp-records/cursor.d.ts.map +1 -0
- package/dist/storage/pdpp-records/cursor.js +56 -0
- package/dist/storage/pdpp-records/cursor.js.map +1 -0
- package/dist/storage/pdpp-records/declaration-witness.d.ts +58 -0
- package/dist/storage/pdpp-records/declaration-witness.d.ts.map +1 -0
- package/dist/storage/pdpp-records/declaration-witness.js +230 -0
- package/dist/storage/pdpp-records/declaration-witness.js.map +1 -0
- package/dist/storage/pdpp-records/enforcement.d.ts +39 -0
- package/dist/storage/pdpp-records/enforcement.d.ts.map +1 -0
- package/dist/storage/pdpp-records/enforcement.js +143 -0
- package/dist/storage/pdpp-records/enforcement.js.map +1 -0
- package/dist/storage/pdpp-records/index.d.ts +7 -0
- package/dist/storage/pdpp-records/index.d.ts.map +1 -0
- package/dist/storage/pdpp-records/index.js +6 -0
- package/dist/storage/pdpp-records/index.js.map +1 -0
- package/dist/storage/pdpp-records/ingest-plan.d.ts +39 -0
- package/dist/storage/pdpp-records/ingest-plan.d.ts.map +1 -0
- package/dist/storage/pdpp-records/ingest-plan.js +103 -0
- package/dist/storage/pdpp-records/ingest-plan.js.map +1 -0
- package/dist/storage/pdpp-records/interface.d.ts +111 -0
- package/dist/storage/pdpp-records/interface.d.ts.map +1 -0
- package/dist/storage/pdpp-records/interface.js +2 -0
- package/dist/storage/pdpp-records/interface.js.map +1 -0
- package/dist/storage/pdpp-records/list-page.d.ts +35 -0
- package/dist/storage/pdpp-records/list-page.d.ts.map +1 -0
- package/dist/storage/pdpp-records/list-page.js +106 -0
- package/dist/storage/pdpp-records/list-page.js.map +1 -0
- package/dist/storage/pdpp-records/memory-store.d.ts +9 -0
- package/dist/storage/pdpp-records/memory-store.d.ts.map +1 -0
- package/dist/storage/pdpp-records/memory-store.js +462 -0
- package/dist/storage/pdpp-records/memory-store.js.map +1 -0
- package/dist/storage/pdpp-records/portable.d.ts +12 -0
- package/dist/storage/pdpp-records/portable.d.ts.map +1 -0
- package/dist/storage/pdpp-records/portable.js +11 -0
- package/dist/storage/pdpp-records/portable.js.map +1 -0
- package/dist/storage/pdpp-records/read-port.d.ts +44 -0
- package/dist/storage/pdpp-records/read-port.d.ts.map +1 -0
- package/dist/storage/pdpp-records/read-port.js +22 -0
- package/dist/storage/pdpp-records/read-port.js.map +1 -0
- package/dist/storage/pdpp-records/record-key.d.ts +52 -0
- package/dist/storage/pdpp-records/record-key.d.ts.map +1 -0
- package/dist/storage/pdpp-records/record-key.js +97 -0
- package/dist/storage/pdpp-records/record-key.js.map +1 -0
- package/dist/storage/pdpp-records/replication-journal.d.ts +20 -0
- package/dist/storage/pdpp-records/replication-journal.d.ts.map +1 -0
- package/dist/storage/pdpp-records/replication-journal.js +2 -0
- package/dist/storage/pdpp-records/replication-journal.js.map +1 -0
- package/dist/storage/pdpp-records/schema.d.ts +41 -0
- package/dist/storage/pdpp-records/schema.d.ts.map +1 -0
- package/dist/storage/pdpp-records/schema.js +153 -0
- package/dist/storage/pdpp-records/schema.js.map +1 -0
- package/dist/storage/pdpp-records/stream-declaration.d.ts +86 -0
- package/dist/storage/pdpp-records/stream-declaration.d.ts.map +1 -0
- package/dist/storage/pdpp-records/stream-declaration.js +48 -0
- package/dist/storage/pdpp-records/stream-declaration.js.map +1 -0
- package/dist/storage/pdpp-records/sync-selection.d.ts +4 -0
- package/dist/storage/pdpp-records/sync-selection.d.ts.map +1 -0
- package/dist/storage/pdpp-records/sync-selection.js +37 -0
- package/dist/storage/pdpp-records/sync-selection.js.map +1 -0
- package/dist/storage/pdpp-records/types.d.ts +202 -0
- package/dist/storage/pdpp-records/types.d.ts.map +1 -0
- package/dist/storage/pdpp-records/types.js +38 -0
- package/dist/storage/pdpp-records/types.js.map +1 -0
- package/dist/stream-sync/artifacts.d.ts +31 -0
- package/dist/stream-sync/artifacts.d.ts.map +1 -0
- package/dist/stream-sync/artifacts.js +106 -0
- package/dist/stream-sync/artifacts.js.map +1 -0
- package/dist/stream-sync/blobs.d.ts +11 -0
- package/dist/stream-sync/blobs.d.ts.map +1 -0
- package/dist/stream-sync/blobs.js +34 -0
- package/dist/stream-sync/blobs.js.map +1 -0
- package/dist/stream-sync/crypto.d.ts +21 -0
- package/dist/stream-sync/crypto.d.ts.map +1 -0
- package/dist/stream-sync/crypto.js +45 -0
- package/dist/stream-sync/crypto.js.map +1 -0
- package/dist/stream-sync/home.d.ts +46 -0
- package/dist/stream-sync/home.d.ts.map +1 -0
- package/dist/stream-sync/home.js +37 -0
- package/dist/stream-sync/home.js.map +1 -0
- package/dist/stream-sync/index.d.ts +14 -0
- package/dist/stream-sync/index.d.ts.map +1 -0
- package/dist/stream-sync/index.js +14 -0
- package/dist/stream-sync/index.js.map +1 -0
- package/dist/stream-sync/intake.d.ts +165 -0
- package/dist/stream-sync/intake.d.ts.map +1 -0
- package/dist/stream-sync/intake.js +467 -0
- package/dist/stream-sync/intake.js.map +1 -0
- package/dist/stream-sync/io-barrier.d.ts +39 -0
- package/dist/stream-sync/io-barrier.d.ts.map +1 -0
- package/dist/stream-sync/io-barrier.js +130 -0
- package/dist/stream-sync/io-barrier.js.map +1 -0
- package/dist/stream-sync/memory-files.d.ts +6 -0
- package/dist/stream-sync/memory-files.d.ts.map +1 -0
- package/dist/stream-sync/memory-files.js +50 -0
- package/dist/stream-sync/memory-files.js.map +1 -0
- package/dist/stream-sync/ports.d.ts +134 -0
- package/dist/stream-sync/ports.d.ts.map +1 -0
- package/dist/stream-sync/ports.js +26 -0
- package/dist/stream-sync/ports.js.map +1 -0
- package/dist/stream-sync/publish-plan.d.ts +157 -0
- package/dist/stream-sync/publish-plan.d.ts.map +1 -0
- package/dist/stream-sync/publish-plan.js +212 -0
- package/dist/stream-sync/publish-plan.js.map +1 -0
- package/dist/stream-sync/registry.d.ts +19 -0
- package/dist/stream-sync/registry.d.ts.map +1 -0
- package/dist/stream-sync/registry.js +125 -0
- package/dist/stream-sync/registry.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/spool.d.ts +69 -0
- package/dist/stream-sync/spool.d.ts.map +1 -0
- package/dist/stream-sync/spool.js +197 -0
- package/dist/stream-sync/spool.js.map +1 -0
- package/dist/stream-sync/writer-overlay.d.ts +19 -0
- package/dist/stream-sync/writer-overlay.d.ts.map +1 -0
- package/dist/stream-sync/writer-overlay.js +55 -0
- package/dist/stream-sync/writer-overlay.js.map +1 -0
- package/dist/stream-sync/writer.d.ts +404 -0
- package/dist/stream-sync/writer.d.ts.map +1 -0
- package/dist/stream-sync/writer.js +1994 -0
- package/dist/stream-sync/writer.js.map +1 -0
- package/dist/stream-sync-read/fold.d.ts +69 -0
- package/dist/stream-sync-read/fold.d.ts.map +1 -0
- package/dist/stream-sync-read/fold.js +83 -0
- package/dist/stream-sync-read/fold.js.map +1 -0
- package/dist/stream-sync-read/importer.d.ts +81 -0
- package/dist/stream-sync-read/importer.d.ts.map +1 -0
- package/dist/stream-sync-read/importer.js +226 -0
- package/dist/stream-sync-read/importer.js.map +1 -0
- package/dist/stream-sync-read/index.d.ts +8 -0
- package/dist/stream-sync-read/index.d.ts.map +1 -0
- package/dist/stream-sync-read/index.js +5 -0
- package/dist/stream-sync-read/index.js.map +1 -0
- package/dist/stream-sync-read/keys.d.ts +16 -0
- package/dist/stream-sync-read/keys.d.ts.map +1 -0
- package/dist/stream-sync-read/keys.js +48 -0
- package/dist/stream-sync-read/keys.js.map +1 -0
- package/dist/stream-sync-read/lines.d.ts +37 -0
- package/dist/stream-sync-read/lines.d.ts.map +1 -0
- package/dist/stream-sync-read/lines.js +98 -0
- package/dist/stream-sync-read/lines.js.map +1 -0
- package/dist/stream-sync-read/memory-files.d.ts +6 -0
- package/dist/stream-sync-read/memory-files.d.ts.map +1 -0
- package/dist/stream-sync-read/memory-files.js +34 -0
- package/dist/stream-sync-read/memory-files.js.map +1 -0
- package/dist/stream-sync-read/mirror.d.ts +80 -0
- package/dist/stream-sync-read/mirror.d.ts.map +1 -0
- package/dist/stream-sync-read/mirror.js +189 -0
- package/dist/stream-sync-read/mirror.js.map +1 -0
- package/dist/stream-sync-read/ports.d.ts +155 -0
- package/dist/stream-sync-read/ports.d.ts.map +1 -0
- package/dist/stream-sync-read/ports.js +9 -0
- package/dist/stream-sync-read/ports.js.map +1 -0
- package/dist/stream-sync-read/projection.d.ts +47 -0
- package/dist/stream-sync-read/projection.d.ts.map +1 -0
- package/dist/stream-sync-read/projection.js +338 -0
- package/dist/stream-sync-read/projection.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-fixture.d.ts +94 -0
- package/dist/stream-sync-read/service-fixture.d.ts.map +1 -0
- package/dist/stream-sync-read/service-fixture.js +227 -0
- package/dist/stream-sync-read/service-fixture.js.map +1 -0
- package/dist/stream-sync-read/service.d.ts +260 -0
- package/dist/stream-sync-read/service.d.ts.map +1 -0
- package/dist/stream-sync-read/service.js +975 -0
- package/dist/stream-sync-read/service.js.map +1 -0
- package/dist/stream-sync-read/testing.d.ts +54 -0
- package/dist/stream-sync-read/testing.d.ts.map +1 -0
- package/dist/stream-sync-read/testing.js +80 -0
- package/dist/stream-sync-read/testing.js.map +1 -0
- package/dist/stream-sync-read/view-store.d.ts +98 -0
- package/dist/stream-sync-read/view-store.d.ts.map +1 -0
- package/dist/stream-sync-read/view-store.js +278 -0
- package/dist/stream-sync-read/view-store.js.map +1 -0
- package/dist/stream-sync-read/writer-rig.d.ts +122 -0
- package/dist/stream-sync-read/writer-rig.d.ts.map +1 -0
- package/dist/stream-sync-read/writer-rig.js +301 -0
- package/dist/stream-sync-read/writer-rig.js.map +1 -0
- package/dist/sync/data-point-feed.d.ts +3 -0
- package/dist/sync/data-point-feed.d.ts.map +1 -1
- package/dist/sync/data-point-feed.js +20 -1
- package/dist/sync/data-point-feed.js.map +1 -1
- package/dist/sync/delete-data-port.d.ts +19 -0
- package/dist/sync/delete-data-port.d.ts.map +1 -1
- package/dist/sync/delete-data-port.js +42 -9
- package/dist/sync/delete-data-port.js.map +1 -1
- package/dist/sync/engine/sync-manager.d.ts +21 -1
- package/dist/sync/engine/sync-manager.d.ts.map +1 -1
- package/dist/sync/engine/sync-manager.js +140 -11
- 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 +7 -1
- package/dist/sync/index.js.map +1 -1
- package/dist/sync/pdpp-import.d.ts +192 -0
- package/dist/sync/pdpp-import.d.ts.map +1 -0
- package/dist/sync/pdpp-import.js +441 -0
- package/dist/sync/pdpp-import.js.map +1 -0
- package/dist/sync/pending-blob-deletions.d.ts +18 -2
- package/dist/sync/pending-blob-deletions.d.ts.map +1 -1
- package/dist/sync/pending-blob-deletions.js +97 -23
- package/dist/sync/pending-blob-deletions.js.map +1 -1
- package/dist/sync/scope-deletions.d.ts +12 -0
- package/dist/sync/scope-deletions.d.ts.map +1 -1
- package/dist/sync/scope-deletions.js +99 -25
- package/dist/sync/scope-deletions.js.map +1 -1
- package/dist/sync/tombstone-finality.d.ts +36 -0
- package/dist/sync/tombstone-finality.d.ts.map +1 -0
- package/dist/sync/tombstone-finality.js +142 -0
- package/dist/sync/tombstone-finality.js.map +1 -0
- package/dist/sync/tombstone-resubmits.d.ts +61 -0
- package/dist/sync/tombstone-resubmits.d.ts.map +1 -0
- package/dist/sync/tombstone-resubmits.js +85 -0
- package/dist/sync/tombstone-resubmits.js.map +1 -0
- package/dist/sync/types.d.ts +10 -0
- package/dist/sync/types.d.ts.map +1 -1
- package/dist/sync/workers/delete.d.ts +54 -5
- package/dist/sync/workers/delete.d.ts.map +1 -1
- package/dist/sync/workers/delete.js +594 -170
- package/dist/sync/workers/delete.js.map +1 -1
- package/dist/sync/workers/download.d.ts +42 -1
- package/dist/sync/workers/download.d.ts.map +1 -1
- package/dist/sync/workers/download.js +344 -24
- package/dist/sync/workers/download.js.map +1 -1
- package/dist/sync/workers/lost-data-points.d.ts +38 -0
- package/dist/sync/workers/lost-data-points.d.ts.map +1 -0
- package/dist/sync/workers/lost-data-points.js +72 -0
- package/dist/sync/workers/lost-data-points.js.map +1 -0
- package/dist/sync/workers/upload.d.ts +27 -6
- package/dist/sync/workers/upload.d.ts.map +1 -1
- package/dist/sync/workers/upload.js +169 -274
- package/dist/sync/workers/upload.js.map +1 -1
- package/dist/test-utils/memory-storage.d.ts +1 -1
- package/dist/test-utils/memory-storage.d.ts.map +1 -1
- package/dist/test-utils/memory-storage.js +83 -17
- package/dist/test-utils/memory-storage.js.map +1 -1
- package/dist/write/attribution.d.ts.map +1 -1
- package/dist/write/attribution.js +8 -4
- package/dist/write/attribution.js.map +1 -1
- package/dist/write/route.d.ts.map +1 -1
- package/dist/write/route.js +9 -10
- package/dist/write/route.js.map +1 -1
- package/dist/write/session.d.ts.map +1 -1
- package/dist/write/session.js +13 -0
- package/dist/write/session.js.map +1 -1
- package/package.json +103 -3
|
@@ -0,0 +1,1994 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stream-sync writer: run intake, the publish driver (§2.7), the checkpoint
|
|
3
|
+
* re-check (§2.4), `needsFull`, the record limit (§2.2) and the Desktop seed
|
|
4
|
+
* with receipts (§2.9).
|
|
5
|
+
*
|
|
6
|
+
* Every rule comes from `@opendatalabs/personal-server-ts-stream-sync`
|
|
7
|
+
* (`decide`, `chooseBase`, `planBuckets`, `BucketReducer`,
|
|
8
|
+
* `checkpointDecision`, `afterCommit`, ...). This module only sequences I/O
|
|
9
|
+
* around them and keeps the outbox durable.
|
|
10
|
+
*
|
|
11
|
+
* Durable layout under the files port:
|
|
12
|
+
*
|
|
13
|
+
* state.json needsFull, checkpoints, seed targets, receipts
|
|
14
|
+
* runs/<runId>/entry.json the outbox entry and per-stream host data
|
|
15
|
+
* runs/<runId>/spool/s<i>.log intake log of stream i (durable)
|
|
16
|
+
* runs/<runId>/spool/s<i>/<shard> shards of that log (derived, never synced)
|
|
17
|
+
* runs/<runId>/seed/s<i>.log seed log of stream i (durable)
|
|
18
|
+
* runs/<runId>/seed/s<i>/<shard> shards of that log (derived, never synced)
|
|
19
|
+
* runs/<runId>/excluded.ndjson record_too_large: stream, key digest, bytes
|
|
20
|
+
* runs/<runId>/request-s<i>.json persisted signed request of stream i
|
|
21
|
+
* runs/<runId>/head-s<i>.bin persisted head ciphertext of stream i
|
|
22
|
+
* results/<runId>.json the final outcome of a finished run
|
|
23
|
+
*
|
|
24
|
+
* A run that was still collecting when the process stopped is discarded at
|
|
25
|
+
* the next start: its spool may miss records, and publishing it would be
|
|
26
|
+
* publishing a partial run under the run's checkpoint.
|
|
27
|
+
*/
|
|
28
|
+
import { IDENTITYLESS_NS, PART_LIMIT_BYTES, DEFAULT_PART_TARGET_BYTES, SEED_OBSERVED_AT, SEED_RUN_ID, afterCommit, basePartsFor, checkpointDecision, chooseBase, classifyControl, controlHashes, controlScope, createOutboxEntry, decide, decodePart, deriveKeyCheck, digestHead, encodeHead, encodeLine, encodePart, inPrefix, isNoop, isPlainObject, lineSize, parseScope, partBlobName, pkHash, pkHashBits, planBuckets, shardOf, startState, streamRunResult, streamScope, verifyHead, BucketReducer, classifyStreamRow, canonicalBytes32, } from "@opendatalabs/personal-server-ts-stream-sync";
|
|
29
|
+
import { publicationMetadataHash } from "../publication/publish.js";
|
|
30
|
+
import { NO_FLOOR, compareConnectorVersions, planStreamStep, stampBefore, } from "./publish-plan.js";
|
|
31
|
+
import { streamSyncHashes } from "./crypto.js";
|
|
32
|
+
import { AmbiguousRegistryReplyError, RegistryRefusedError, } from "./ports.js";
|
|
33
|
+
import { SpoolWriter, deriveShards, spoolLogPath, compactShard, countShard, emptyShardBytes, lineStamp, readSpool, shardPath, } from "./spool.js";
|
|
34
|
+
import { pinnedWriterSnapshot, overlayPlanKey, } from "./writer-overlay.js";
|
|
35
|
+
const encoder = new TextEncoder();
|
|
36
|
+
const decoder = new TextDecoder();
|
|
37
|
+
const RUN_ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
38
|
+
/** Conflicts handled within one publish pass before the stream waits for the next pass. */
|
|
39
|
+
const CONFLICTS_PER_PASS = 8;
|
|
40
|
+
/** m1: the furthest a producer clock may run ahead of this process. */
|
|
41
|
+
const SKEW_MS = 5 * 60 * 1000;
|
|
42
|
+
/** A run id that finished, or whose entry this process no longer drives. */
|
|
43
|
+
export class RunGoneError extends Error {
|
|
44
|
+
runId;
|
|
45
|
+
constructor(runId) {
|
|
46
|
+
super(`run ${runId} is gone`);
|
|
47
|
+
this.runId = runId;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export { compareConnectorVersions } from "./publish-plan.js";
|
|
51
|
+
/** The `streamFloors` key of a stream. */
|
|
52
|
+
function floorKey(connector, ns, stream) {
|
|
53
|
+
return JSON.stringify([connector, ns, stream]);
|
|
54
|
+
}
|
|
55
|
+
function floorOf(state, connector, ns, stream) {
|
|
56
|
+
const held = state.streamFloors?.[floorKey(connector, ns, stream)];
|
|
57
|
+
if (!held)
|
|
58
|
+
return NO_FLOOR;
|
|
59
|
+
return {
|
|
60
|
+
version: held.version,
|
|
61
|
+
committed: { observedAt: held.committed[0], runId: held.committed[1] },
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function planHeadOf(head) {
|
|
65
|
+
return {
|
|
66
|
+
generation: head.generation,
|
|
67
|
+
primaryKey: head.primaryKey,
|
|
68
|
+
profile: head.profile,
|
|
69
|
+
complete: head.complete,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function coverageKey(binding, connector, ns, stream, generation) {
|
|
73
|
+
return JSON.stringify([
|
|
74
|
+
binding.owner.toLowerCase(),
|
|
75
|
+
binding.keyCheck,
|
|
76
|
+
connector,
|
|
77
|
+
ns,
|
|
78
|
+
stream,
|
|
79
|
+
generation,
|
|
80
|
+
]);
|
|
81
|
+
}
|
|
82
|
+
function json(value) {
|
|
83
|
+
return encoder.encode(JSON.stringify(value));
|
|
84
|
+
}
|
|
85
|
+
function emptyState() {
|
|
86
|
+
return {
|
|
87
|
+
version: 1,
|
|
88
|
+
needsFull: [],
|
|
89
|
+
checkpoints: {},
|
|
90
|
+
seedTargets: {},
|
|
91
|
+
receipts: {},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
class PendingStream extends Error {
|
|
95
|
+
problem;
|
|
96
|
+
constructor(problem, detail) {
|
|
97
|
+
super(detail);
|
|
98
|
+
this.problem = problem;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
class Discard extends Error {
|
|
102
|
+
decision;
|
|
103
|
+
why;
|
|
104
|
+
constructor(decision, why) {
|
|
105
|
+
super(why);
|
|
106
|
+
this.decision = decision;
|
|
107
|
+
this.why = why;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
export class StreamSyncWriter {
|
|
111
|
+
options;
|
|
112
|
+
hashes = streamSyncHashes;
|
|
113
|
+
targetBytes;
|
|
114
|
+
reduceBudget;
|
|
115
|
+
now;
|
|
116
|
+
keyCheck = null;
|
|
117
|
+
control = null;
|
|
118
|
+
/** §2.4 `controls`: the last listing completed in this app session. */
|
|
119
|
+
controls = null;
|
|
120
|
+
active = new Map();
|
|
121
|
+
intakeQueue = Promise.resolve();
|
|
122
|
+
publishQueue = Promise.resolve();
|
|
123
|
+
stateQueue = Promise.resolve();
|
|
124
|
+
recovery = null;
|
|
125
|
+
/**
|
|
126
|
+
* Streams of a run the publish pass has selected and not yet resolved, as
|
|
127
|
+
* `runId|stream`. Memory only: it tells a snapshot that an execution order is
|
|
128
|
+
* about to be taken, before the request exists. It is never proof of a
|
|
129
|
+
* publication; `request_persisted` stays the durable form.
|
|
130
|
+
*/
|
|
131
|
+
selected = new Set();
|
|
132
|
+
lifecycleQueue = Promise.resolve();
|
|
133
|
+
/**
|
|
134
|
+
* Runs whose removal failed. They stay on disk, already covered and hidden
|
|
135
|
+
* from snapshots, and each later lifecycle step retries them. Nothing in the
|
|
136
|
+
* writer is poisoned for good: cleanup is garbage collection, so a failure
|
|
137
|
+
* to remove a run never turns off reads of other runs.
|
|
138
|
+
*/
|
|
139
|
+
removalRetry = new Set();
|
|
140
|
+
pins = new Map();
|
|
141
|
+
/**
|
|
142
|
+
* Latest durable-import coverage per (owner, keyCheck, connector, ns, stream,
|
|
143
|
+
* generation), kept even when no receipt matches it yet: the reader can
|
|
144
|
+
* acknowledge before the writer stores its receipt, and a no-op run gets a
|
|
145
|
+
* receipt for a head the reader already imported. Memory only. It belongs to
|
|
146
|
+
* this reader/store lifetime, so startup must reconcile it again.
|
|
147
|
+
*/
|
|
148
|
+
coverage = new Map();
|
|
149
|
+
constructor(options) {
|
|
150
|
+
this.options = options;
|
|
151
|
+
if (options.home.ownerAddress.toLowerCase() !==
|
|
152
|
+
options.ownerAddress.toLowerCase()) {
|
|
153
|
+
throw new Error("Stream-sync home belongs to a different owner");
|
|
154
|
+
}
|
|
155
|
+
this.targetBytes = options.partTargetBytes ?? DEFAULT_PART_TARGET_BYTES;
|
|
156
|
+
this.reduceBudget = options.reduceBudgetBytes ?? PART_LIMIT_BYTES;
|
|
157
|
+
this.now = options.now ?? (() => Date.now());
|
|
158
|
+
}
|
|
159
|
+
// ---------------------------------------------------------------- state
|
|
160
|
+
async readState() {
|
|
161
|
+
const bytes = await this.options.home.files.read("state.json");
|
|
162
|
+
if (!bytes)
|
|
163
|
+
return emptyState();
|
|
164
|
+
return JSON.parse(decoder.decode(bytes));
|
|
165
|
+
}
|
|
166
|
+
async writeState(state) {
|
|
167
|
+
await this.options.home.files.write("state.json", json(state));
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Read-modify-write of `state.json` under one short lock (V2 §3.8). The
|
|
171
|
+
* intake and publish queues both write it; `change` does no network I/O.
|
|
172
|
+
*/
|
|
173
|
+
withState(change) {
|
|
174
|
+
const run = async () => {
|
|
175
|
+
const state = await this.readState();
|
|
176
|
+
const result = await change(state);
|
|
177
|
+
await this.writeState(state);
|
|
178
|
+
return result;
|
|
179
|
+
};
|
|
180
|
+
const next = this.stateQueue.then(run, run);
|
|
181
|
+
this.stateQueue = next.catch(() => undefined);
|
|
182
|
+
return next;
|
|
183
|
+
}
|
|
184
|
+
async readEntry(runId) {
|
|
185
|
+
const bytes = await this.options.home.files.read(`runs/${runId}/entry.json`);
|
|
186
|
+
return bytes ? JSON.parse(decoder.decode(bytes)) : null;
|
|
187
|
+
}
|
|
188
|
+
lifecycle(work) {
|
|
189
|
+
const next = this.lifecycleQueue.then(work, work);
|
|
190
|
+
this.lifecycleQueue = next.catch(() => undefined);
|
|
191
|
+
return next;
|
|
192
|
+
}
|
|
193
|
+
writeEntry(host) {
|
|
194
|
+
return this.lifecycle(() => this.options.home.files.write(`runs/${host.entry.runId}/entry.json`, json(host)));
|
|
195
|
+
}
|
|
196
|
+
fault(point, runId, stream) {
|
|
197
|
+
this.options.fault?.(point, { runId, ...(stream ? { stream } : {}) });
|
|
198
|
+
}
|
|
199
|
+
async keys() {
|
|
200
|
+
if (this.keyCheck === null || this.control === null) {
|
|
201
|
+
this.keyCheck = await deriveKeyCheck((m) => this.options.keys.namespaceHmac(m));
|
|
202
|
+
this.control = await controlHashes(this.hashes.keccak256, this.keyCheck);
|
|
203
|
+
}
|
|
204
|
+
return { keyCheck: this.keyCheck, control: this.control };
|
|
205
|
+
}
|
|
206
|
+
/** Run intake work in order: begin, declare, finish, abort (V2 §3.8). */
|
|
207
|
+
intake(work) {
|
|
208
|
+
const next = this.intakeQueue.then(work, work);
|
|
209
|
+
this.intakeQueue = next.catch(() => undefined);
|
|
210
|
+
return next;
|
|
211
|
+
}
|
|
212
|
+
/** Run publish work in order. It never blocks intake. */
|
|
213
|
+
publish(work) {
|
|
214
|
+
const next = this.publishQueue.then(work, work);
|
|
215
|
+
this.publishQueue = next.catch(() => undefined);
|
|
216
|
+
return next;
|
|
217
|
+
}
|
|
218
|
+
// ------------------------------------------------------------ controls
|
|
219
|
+
/**
|
|
220
|
+
* §2.4: list every control row of the owner and keep the states as this
|
|
221
|
+
* app session's `controls`. Runs that start after this use it as `start`.
|
|
222
|
+
*/
|
|
223
|
+
refreshControls() {
|
|
224
|
+
return this.intake(async () => {
|
|
225
|
+
const { control } = await this.keys();
|
|
226
|
+
const rows = await this.options.registry.listControlRows();
|
|
227
|
+
const listed = [];
|
|
228
|
+
for (const row of rows) {
|
|
229
|
+
const parsed = parseScope(row.scope);
|
|
230
|
+
if (parsed?.kind !== "control")
|
|
231
|
+
continue;
|
|
232
|
+
listed.push({
|
|
233
|
+
connector: parsed.connector,
|
|
234
|
+
ns: parsed.ns,
|
|
235
|
+
state: classifyControl(row.read, control),
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
// A listing is a control read too: record it like every other, and
|
|
239
|
+
// keep the newest known state of each row, not the raw listing.
|
|
240
|
+
const newest = await this.withState((state) => listed.map((row) => recordControl(state, row.connector, row.ns, row.state)));
|
|
241
|
+
const next = new Map();
|
|
242
|
+
listed.forEach((row, i) => {
|
|
243
|
+
const states = next.get(row.connector) ?? {};
|
|
244
|
+
states[row.ns] = newest[i];
|
|
245
|
+
next.set(row.connector, states);
|
|
246
|
+
});
|
|
247
|
+
this.controls = next;
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
startSnapshot(connector) {
|
|
251
|
+
if (this.controls === null)
|
|
252
|
+
return null;
|
|
253
|
+
return { ...(this.controls.get(connector) ?? {}) };
|
|
254
|
+
}
|
|
255
|
+
// -------------------------------------------------------------- intake
|
|
256
|
+
/**
|
|
257
|
+
* What a run of `connector` may use: the saved checkpoint, unless a
|
|
258
|
+
* `needsFull` entry forces a full run (§2.4).
|
|
259
|
+
*/
|
|
260
|
+
async runPlan(connector) {
|
|
261
|
+
const state = await this.readState();
|
|
262
|
+
const mustBeFull = state.needsFull.some((k) => k.connector === connector);
|
|
263
|
+
return {
|
|
264
|
+
mustBeFull,
|
|
265
|
+
checkpoint: mustBeFull ? null : (state.checkpoints[connector] ?? null),
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* §2.9 seed state of `connector` on this install: whether the seed target
|
|
270
|
+
* is known (set by the first identified run of the connector) and the
|
|
271
|
+
* receipt of each stream for that target. Empty without a seed source.
|
|
272
|
+
*/
|
|
273
|
+
async seedStatus(connector) {
|
|
274
|
+
const seed = this.options.seed;
|
|
275
|
+
const state = await this.readState();
|
|
276
|
+
const target = state.seedTargets[connector];
|
|
277
|
+
const receipts = {};
|
|
278
|
+
if (seed && target !== undefined) {
|
|
279
|
+
const prefix = `${seed.installId}|${connector}|${target}|`;
|
|
280
|
+
for (const [key, receipt] of Object.entries(state.receipts)) {
|
|
281
|
+
if (key.startsWith(prefix))
|
|
282
|
+
receipts[key.slice(prefix.length)] = receipt;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return { targetKnown: target !== undefined, receipts };
|
|
286
|
+
}
|
|
287
|
+
/** The owner and key check a run is bound to (V2 §2.1, M5). */
|
|
288
|
+
async binding() {
|
|
289
|
+
const { keyCheck } = await this.keys();
|
|
290
|
+
return { owner: this.options.ownerAddress, keyCheck };
|
|
291
|
+
}
|
|
292
|
+
/** Whether `controls` was listed in this app session (§2.4). */
|
|
293
|
+
hasControls() {
|
|
294
|
+
return this.controls !== null;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* The START a run of `connector` would be issued now (V2 §2.1, R16). Full
|
|
298
|
+
* when asked, forced by `needsFull`, or without a checkpoint. `state` is
|
|
299
|
+
* the stored value unless a `needsFull` entry cleared it.
|
|
300
|
+
*/
|
|
301
|
+
async issueStart(connector, wantFull) {
|
|
302
|
+
const plan = await this.runPlan(connector);
|
|
303
|
+
const full = wantFull || plan.mustBeFull || plan.checkpoint === null;
|
|
304
|
+
const { keyCheck } = await this.keys();
|
|
305
|
+
return {
|
|
306
|
+
start: {
|
|
307
|
+
collectionMode: full ? "full_refresh" : "incremental",
|
|
308
|
+
state: plan.checkpoint?.value ?? null,
|
|
309
|
+
keyCheck,
|
|
310
|
+
},
|
|
311
|
+
checkpoint: plan.checkpoint,
|
|
312
|
+
full,
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Start a run. With `issue` the writer issues the START (returned) and
|
|
317
|
+
* records mode and checkpoint in the entry. A finished run id, or one whose
|
|
318
|
+
* entry this process does not drive (a restart), answers `RunGoneError`.
|
|
319
|
+
*/
|
|
320
|
+
beginRun(input) {
|
|
321
|
+
return this.intake(async () => {
|
|
322
|
+
if (!RUN_ID.test(input.runId))
|
|
323
|
+
throw new Error(`bad runId ${input.runId}`);
|
|
324
|
+
if (await this.options.home.files.read(`results/${input.runId}.json`)) {
|
|
325
|
+
throw new RunGoneError(input.runId);
|
|
326
|
+
}
|
|
327
|
+
if (await this.readEntry(input.runId)) {
|
|
328
|
+
if (!this.active.has(input.runId))
|
|
329
|
+
throw new RunGoneError(input.runId);
|
|
330
|
+
throw new Error(`run ${input.runId} already exists`);
|
|
331
|
+
}
|
|
332
|
+
const state = await this.readState();
|
|
333
|
+
let checkpointUsed = input.checkpointUsed ?? null;
|
|
334
|
+
let full = checkpointUsed === null;
|
|
335
|
+
let issued = null;
|
|
336
|
+
if (input.issue) {
|
|
337
|
+
const plan = await this.issueStart(input.connector, input.issue.wantFull);
|
|
338
|
+
issued = plan.start;
|
|
339
|
+
full = plan.full;
|
|
340
|
+
checkpointUsed = plan.checkpoint
|
|
341
|
+
? {
|
|
342
|
+
ns: plan.checkpoint.ns,
|
|
343
|
+
generation: plan.checkpoint.generation,
|
|
344
|
+
}
|
|
345
|
+
: null;
|
|
346
|
+
}
|
|
347
|
+
const { keyCheck } = await this.keys();
|
|
348
|
+
const now = this.now();
|
|
349
|
+
const entry = createOutboxEntry({
|
|
350
|
+
runId: input.runId,
|
|
351
|
+
connector: input.connector,
|
|
352
|
+
start: this.startSnapshot(input.connector),
|
|
353
|
+
userConnect: input.userConnect,
|
|
354
|
+
full,
|
|
355
|
+
// m1: a producer clock cannot place lines more than 5 min ahead.
|
|
356
|
+
observedAt: Math.min(input.observedAt ?? now, now + SKEW_MS),
|
|
357
|
+
spoolRef: `runs/${input.runId}/spool`,
|
|
358
|
+
checkpointCandidate: null,
|
|
359
|
+
needsFull: state.needsFull,
|
|
360
|
+
});
|
|
361
|
+
const host = {
|
|
362
|
+
version: 1,
|
|
363
|
+
phase: "collecting",
|
|
364
|
+
entry,
|
|
365
|
+
checkpointUsed: checkpointUsed
|
|
366
|
+
? { ns: checkpointUsed.ns, generation: checkpointUsed.generation }
|
|
367
|
+
: null,
|
|
368
|
+
target: null,
|
|
369
|
+
generation: verifiedGeneration(state, input.connector),
|
|
370
|
+
overlayRevision: globalThis.crypto.randomUUID(),
|
|
371
|
+
streams: {},
|
|
372
|
+
outcome: null,
|
|
373
|
+
seedStreams: [],
|
|
374
|
+
binding: {
|
|
375
|
+
owner: this.options.ownerAddress,
|
|
376
|
+
keyCheck,
|
|
377
|
+
leaseId: input.leaseId ?? null,
|
|
378
|
+
},
|
|
379
|
+
};
|
|
380
|
+
// Active before the entry exists, so a recovery pass on the publish
|
|
381
|
+
// queue never mistakes this run for one a dead process left behind.
|
|
382
|
+
this.active.set(input.runId, {
|
|
383
|
+
spool: new SpoolWriter(this.options.home.files),
|
|
384
|
+
shardBytes: new Map(),
|
|
385
|
+
recordTooLarge: new Map(),
|
|
386
|
+
records: new Map(),
|
|
387
|
+
excluded: [],
|
|
388
|
+
});
|
|
389
|
+
try {
|
|
390
|
+
await this.writeEntry(host);
|
|
391
|
+
}
|
|
392
|
+
catch (error) {
|
|
393
|
+
this.active.delete(input.runId);
|
|
394
|
+
throw error;
|
|
395
|
+
}
|
|
396
|
+
return (issued ?? {
|
|
397
|
+
collectionMode: full ? "full_refresh" : "incremental",
|
|
398
|
+
state: null,
|
|
399
|
+
keyCheck,
|
|
400
|
+
});
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
declareStream(runId, stream, shape) {
|
|
404
|
+
return this.intake(async () => {
|
|
405
|
+
const host = await this.collecting(runId);
|
|
406
|
+
if (host.streams[stream])
|
|
407
|
+
return;
|
|
408
|
+
host.streams[stream] = this.newStream(nextIndex(host), shape);
|
|
409
|
+
host.entry = {
|
|
410
|
+
...host.entry,
|
|
411
|
+
streams: { ...host.entry.streams, [stream]: { state: "planned" } },
|
|
412
|
+
};
|
|
413
|
+
await this.writeEntry(host);
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
newStream(index, shape) {
|
|
417
|
+
if (shape.primaryKey.length === 0) {
|
|
418
|
+
throw new Error("a stream needs a primary key");
|
|
419
|
+
}
|
|
420
|
+
return {
|
|
421
|
+
index,
|
|
422
|
+
primaryKey: [...shape.primaryKey],
|
|
423
|
+
profile: { key: shape.profile.key, version: shape.profile.version },
|
|
424
|
+
shardBytes: null,
|
|
425
|
+
seedShardBytes: null,
|
|
426
|
+
seedOnly: false,
|
|
427
|
+
fullStream: shape.incremental === false,
|
|
428
|
+
seedApplies: false,
|
|
429
|
+
recordTooLarge: 0,
|
|
430
|
+
problem: null,
|
|
431
|
+
detail: null,
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
async collecting(runId) {
|
|
435
|
+
const host = await this.readEntry(runId);
|
|
436
|
+
if (!host || host.phase !== "collecting" || !this.active.has(runId)) {
|
|
437
|
+
throw new Error(`run ${runId} is not collecting in this process`);
|
|
438
|
+
}
|
|
439
|
+
return host;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Add one record. A record whose canonical line is over 8 MiB is not
|
|
443
|
+
* spooled; the stream counts it as `record_too_large` and keeps its key
|
|
444
|
+
* digest and size locally (§2.2).
|
|
445
|
+
*/
|
|
446
|
+
async append(runId, stream, record, shape) {
|
|
447
|
+
const run = this.active.get(runId);
|
|
448
|
+
if (!run)
|
|
449
|
+
throw new Error(`run ${runId} is not collecting in this process`);
|
|
450
|
+
let info = this.streamCache.get(`${runId}\u0000${stream}`);
|
|
451
|
+
if (!info) {
|
|
452
|
+
if (shape)
|
|
453
|
+
await this.declareStream(runId, stream, shape);
|
|
454
|
+
const host = await this.collecting(runId);
|
|
455
|
+
const declared = host.streams[stream];
|
|
456
|
+
if (!declared)
|
|
457
|
+
throw new Error(`stream ${stream} is not declared`);
|
|
458
|
+
info = {
|
|
459
|
+
index: declared.index,
|
|
460
|
+
primaryKey: declared.primaryKey,
|
|
461
|
+
observedAt: host.entry.observedAt,
|
|
462
|
+
};
|
|
463
|
+
this.streamCache.set(`${runId}\u0000${stream}`, info);
|
|
464
|
+
}
|
|
465
|
+
if (!isPlainObject(record))
|
|
466
|
+
throw new Error("a record must be a JSON object");
|
|
467
|
+
const value = record;
|
|
468
|
+
const hash = await pkHash(this.hashes.sha256, value, info.primaryKey);
|
|
469
|
+
const text = encodeLine({ o: info.observedAt, r: runId, v: value });
|
|
470
|
+
const size = lineSize(text);
|
|
471
|
+
if (!size.fits) {
|
|
472
|
+
run.recordTooLarge.set(stream, (run.recordTooLarge.get(stream) ?? 0) + 1);
|
|
473
|
+
run.excluded.push(JSON.stringify({ stream, pkHash: hash, bytes: size.bytes }));
|
|
474
|
+
return "too_large";
|
|
475
|
+
}
|
|
476
|
+
const shard = shardOf(hash);
|
|
477
|
+
let bytes = run.shardBytes.get(stream);
|
|
478
|
+
if (!bytes) {
|
|
479
|
+
bytes = emptyShardBytes();
|
|
480
|
+
run.shardBytes.set(stream, bytes);
|
|
481
|
+
}
|
|
482
|
+
bytes[shard] += size.bytes + 1;
|
|
483
|
+
run.records.set(stream, (run.records.get(stream) ?? 0) + 1);
|
|
484
|
+
await run.spool.add(spoolLogPath(`runs/${runId}/spool/s${info.index}`), hash, text, size.bytes);
|
|
485
|
+
return "spooled";
|
|
486
|
+
}
|
|
487
|
+
/** Spool directories whose shards were derived by this process, with bytes. */
|
|
488
|
+
derived = new Map();
|
|
489
|
+
streamCache = new Map();
|
|
490
|
+
/**
|
|
491
|
+
* End intake. The run becomes publishable.
|
|
492
|
+
*
|
|
493
|
+
* `coveredStreams` limits the run to the streams its connector fully
|
|
494
|
+
* covered (§3.5): the others are dropped with their spool lines, never
|
|
495
|
+
* published empty. Omit it to publish every declared stream.
|
|
496
|
+
*
|
|
497
|
+
* Every run (R23) publishes under the identity-less name.
|
|
498
|
+
*/
|
|
499
|
+
finishRun(runId, input) {
|
|
500
|
+
return this.intake(async () => {
|
|
501
|
+
const host = await this.collecting(runId);
|
|
502
|
+
const run = this.active.get(runId);
|
|
503
|
+
// The run stays active until its `ready` write is durable, so a
|
|
504
|
+
// recovery pass on the publish queue cannot take it for an abandoned
|
|
505
|
+
// run. It is forgotten on any failure and once it is `ready`.
|
|
506
|
+
try {
|
|
507
|
+
await run.spool.flush();
|
|
508
|
+
if (input.coveredStreams)
|
|
509
|
+
this.keepCovered(host, input.coveredStreams);
|
|
510
|
+
if (run.excluded.length > 0) {
|
|
511
|
+
await this.options.home.files.appendMany([
|
|
512
|
+
{
|
|
513
|
+
path: `runs/${runId}/excluded.ndjson`,
|
|
514
|
+
bytes: encoder.encode(run.excluded.map((l) => `${l}\n`).join("")),
|
|
515
|
+
},
|
|
516
|
+
]);
|
|
517
|
+
}
|
|
518
|
+
const connector = host.entry.connector;
|
|
519
|
+
const ns = IDENTITYLESS_NS;
|
|
520
|
+
for (const [name, stream] of Object.entries(host.streams)) {
|
|
521
|
+
stream.shardBytes = run.shardBytes.get(name) ?? emptyShardBytes();
|
|
522
|
+
stream.recordTooLarge = run.recordTooLarge.get(name) ?? 0;
|
|
523
|
+
}
|
|
524
|
+
if (this.options.seed) {
|
|
525
|
+
await this.withState((state) => {
|
|
526
|
+
state.seedTargets[connector] ??= ns;
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
// Intake appends are not durable one by one. The run becomes `ready`
|
|
530
|
+
// only after one sync of its intake logs (§2.6).
|
|
531
|
+
await this.options.home.files.sync(`runs/${runId}`);
|
|
532
|
+
host.entry = {
|
|
533
|
+
...host.entry,
|
|
534
|
+
ns,
|
|
535
|
+
checkpointCandidate: input.checkpointCandidate,
|
|
536
|
+
};
|
|
537
|
+
host.generation ??= verifiedGeneration(await this.readState(), connector);
|
|
538
|
+
host.overlayRevision ??= globalThis.crypto.randomUUID();
|
|
539
|
+
host.phase = "ready";
|
|
540
|
+
host.ready = true;
|
|
541
|
+
await this.writeEntry(host);
|
|
542
|
+
}
|
|
543
|
+
finally {
|
|
544
|
+
this.forget(runId);
|
|
545
|
+
}
|
|
546
|
+
return this.statusOf(host);
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
forget(runId) {
|
|
550
|
+
this.active.delete(runId);
|
|
551
|
+
for (const key of [...this.streamCache.keys()]) {
|
|
552
|
+
if (key.startsWith(`${runId}\u0000`))
|
|
553
|
+
this.streamCache.delete(key);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
/** Drop every declared stream outside `covered` from the run (§3.5). */
|
|
557
|
+
keepCovered(host, covered) {
|
|
558
|
+
const keep = new Set(covered);
|
|
559
|
+
const streams = { ...host.entry.streams };
|
|
560
|
+
for (const name of Object.keys(host.streams)) {
|
|
561
|
+
if (keep.has(name))
|
|
562
|
+
continue;
|
|
563
|
+
delete host.streams[name];
|
|
564
|
+
delete streams[name];
|
|
565
|
+
}
|
|
566
|
+
host.entry = { ...host.entry, streams };
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* End a run that must publish nothing (V2 §3.7): `failed` or `cancelled`.
|
|
570
|
+
* Idempotent for a run this process
|
|
571
|
+
* already ended; a run it never drove answers `RunGoneError`.
|
|
572
|
+
*/
|
|
573
|
+
abortRun(runId, reason) {
|
|
574
|
+
return this.intake(async () => {
|
|
575
|
+
const run = this.active.get(runId);
|
|
576
|
+
const host = await this.readEntry(runId);
|
|
577
|
+
if (!run || !host || host.phase !== "collecting") {
|
|
578
|
+
throw new RunGoneError(runId);
|
|
579
|
+
}
|
|
580
|
+
// Buffered lines are dropped, not written to be removed again.
|
|
581
|
+
run.spool.clear();
|
|
582
|
+
try {
|
|
583
|
+
await this.finish(host, { kind: "aborted", reason });
|
|
584
|
+
}
|
|
585
|
+
finally {
|
|
586
|
+
this.forget(runId);
|
|
587
|
+
}
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* End a `retry_pending` run (V2 §3.6, R19): save its cursors, publish
|
|
592
|
+
* nothing. A cursor of a stream that emitted records in this run is
|
|
593
|
+
* dropped, because those records are not published and the next run
|
|
594
|
+
* must read them again. Same admission as a publish: a stale namespace or
|
|
595
|
+
* generation saves nothing.
|
|
596
|
+
*/
|
|
597
|
+
saveCheckpointOnly(runId, candidate) {
|
|
598
|
+
return this.intake(async () => {
|
|
599
|
+
const host = await this.collecting(runId);
|
|
600
|
+
const run = this.active.get(runId);
|
|
601
|
+
const kept = {};
|
|
602
|
+
for (const [stream, cursor] of Object.entries(candidate)) {
|
|
603
|
+
if ((run.records.get(stream) ?? 0) === 0)
|
|
604
|
+
kept[stream] = cursor;
|
|
605
|
+
}
|
|
606
|
+
run.spool.clear();
|
|
607
|
+
// Active until the run has ended, so recovery cannot end it first.
|
|
608
|
+
try {
|
|
609
|
+
this.keepCovered(host, []);
|
|
610
|
+
const ns = IDENTITYLESS_NS;
|
|
611
|
+
host.entry = {
|
|
612
|
+
...host.entry,
|
|
613
|
+
ns,
|
|
614
|
+
checkpointCandidate: Object.keys(kept).length > 0 ? kept : null,
|
|
615
|
+
};
|
|
616
|
+
try {
|
|
617
|
+
host.target = await this.admit(host, "first");
|
|
618
|
+
}
|
|
619
|
+
catch (error) {
|
|
620
|
+
if (error instanceof Discard) {
|
|
621
|
+
await this.discard(host, error);
|
|
622
|
+
return this.statusOf(host);
|
|
623
|
+
}
|
|
624
|
+
if (error instanceof PendingStream ||
|
|
625
|
+
error instanceof RegistryRefusedError) {
|
|
626
|
+
await this.finish(host, {
|
|
627
|
+
kind: "no_checkpoint",
|
|
628
|
+
generation: 0,
|
|
629
|
+
reason: "control_changed",
|
|
630
|
+
});
|
|
631
|
+
return this.statusOf(host);
|
|
632
|
+
}
|
|
633
|
+
throw error;
|
|
634
|
+
}
|
|
635
|
+
await this.checkpoint(host);
|
|
636
|
+
return this.statusOf(host);
|
|
637
|
+
}
|
|
638
|
+
finally {
|
|
639
|
+
this.forget(runId);
|
|
640
|
+
}
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
/**
|
|
644
|
+
* M4: three finished runs in a row of one connector that published
|
|
645
|
+
* nothing (failed, discarded or dropped by intake). A cancel is not a
|
|
646
|
+
* failure.
|
|
647
|
+
*/
|
|
648
|
+
async stuck(connector) {
|
|
649
|
+
const recent = (await this.readState()).recent?.[connector] ?? [];
|
|
650
|
+
return recent.length >= 3 && recent.every((v) => v === "bad");
|
|
651
|
+
}
|
|
652
|
+
/** Count a run intake dropped before the writer saw it (`will_discard`). */
|
|
653
|
+
noteDropped(connector) {
|
|
654
|
+
return this.note(connector, "bad");
|
|
655
|
+
}
|
|
656
|
+
note(connector, verdict) {
|
|
657
|
+
return this.withState((state) => {
|
|
658
|
+
const recent = (state.recent ??= {});
|
|
659
|
+
recent[connector] = [...(recent[connector] ?? []), verdict].slice(-3);
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
async compact(dir, shardBytes) {
|
|
663
|
+
for (let shard = 0; shard < shardBytes.length; shard += 1) {
|
|
664
|
+
if (shardBytes[shard] <= this.targetBytes / 4)
|
|
665
|
+
continue;
|
|
666
|
+
const after = await compactShard(this.options.home.files, shardPath(dir, shard), shard, this.reduceBudget);
|
|
667
|
+
if (after !== null)
|
|
668
|
+
shardBytes[shard] = after;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
// ------------------------------------------------------------- publish
|
|
672
|
+
/** One sync-loop step: refresh `controls`, then publish every ready run. */
|
|
673
|
+
async cycle() {
|
|
674
|
+
await this.refreshControls();
|
|
675
|
+
return this.publishPending();
|
|
676
|
+
}
|
|
677
|
+
publishPending() {
|
|
678
|
+
return this.publish(async () => {
|
|
679
|
+
await this.recover();
|
|
680
|
+
const runs = [];
|
|
681
|
+
// Selection is one critical section of the lifecycle queue, the lock
|
|
682
|
+
// ready-entry writes and snapshots also take: the run list, the entry
|
|
683
|
+
// reads, the sort and the reservation. A snapshot sees no selection or
|
|
684
|
+
// the whole reserved one, and a run that turns ready meanwhile is either
|
|
685
|
+
// in the list or written after it. The section holds only local reads
|
|
686
|
+
// (one list and one entry read per run); every network step (build,
|
|
687
|
+
// sign, upload, registry) runs after it. The reserve map is in `reserved`
|
|
688
|
+
// before the section ends, so the `finally` below always releases it.
|
|
689
|
+
const { hosts, reserved } = await this.lifecycle(async () => {
|
|
690
|
+
const hosts = [];
|
|
691
|
+
for (const runId of await this.runIds()) {
|
|
692
|
+
const host = await this.readEntry(runId);
|
|
693
|
+
if (host && host.phase === "ready")
|
|
694
|
+
hosts.push(host);
|
|
695
|
+
}
|
|
696
|
+
hosts.sort((a, b) => a.entry.observedAt - b.entry.observedAt ||
|
|
697
|
+
(a.entry.runId < b.entry.runId ? -1 : 1));
|
|
698
|
+
return {
|
|
699
|
+
hosts,
|
|
700
|
+
reserved: new Map(hosts.map((h) => [h, this.reserve(h)])),
|
|
701
|
+
};
|
|
702
|
+
});
|
|
703
|
+
try {
|
|
704
|
+
// Commit order: a stream an earlier run did not resolve in this pass
|
|
705
|
+
// holds back every later run of that stream until the next pass.
|
|
706
|
+
const held = new Set();
|
|
707
|
+
for (const host of hosts) {
|
|
708
|
+
try {
|
|
709
|
+
await this.publishEntry(host, held);
|
|
710
|
+
}
|
|
711
|
+
finally {
|
|
712
|
+
for (const key of reserved.get(host))
|
|
713
|
+
this.selected.delete(key);
|
|
714
|
+
}
|
|
715
|
+
runs.push(this.statusOf(host));
|
|
716
|
+
if (host.phase === "done" || host.entry.ns === null)
|
|
717
|
+
continue;
|
|
718
|
+
for (const [name, outbox] of Object.entries(host.entry.streams)) {
|
|
719
|
+
if (outbox.state === "committed" ||
|
|
720
|
+
outbox.state === "noop" ||
|
|
721
|
+
outbox.state === "discarded")
|
|
722
|
+
continue;
|
|
723
|
+
const problem = host.streams[name]?.problem;
|
|
724
|
+
if (problem === "connector_update_required" ||
|
|
725
|
+
problem === "out_of_order")
|
|
726
|
+
continue;
|
|
727
|
+
held.add(floorKey(host.entry.connector, host.entry.ns, name));
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
finally {
|
|
732
|
+
for (const keys of reserved.values())
|
|
733
|
+
for (const key of keys)
|
|
734
|
+
this.selected.delete(key);
|
|
735
|
+
}
|
|
736
|
+
return { runs };
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
async runIds() {
|
|
740
|
+
const ids = new Set();
|
|
741
|
+
for (const path of await this.options.home.files.list("runs")) {
|
|
742
|
+
const match = /^runs\/([^/]+)\/entry\.json$/.exec(path);
|
|
743
|
+
if (match)
|
|
744
|
+
ids.add(match[1]);
|
|
745
|
+
}
|
|
746
|
+
return [...ids].sort();
|
|
747
|
+
}
|
|
748
|
+
/** Discard runs left collecting by an earlier process. */
|
|
749
|
+
recover() {
|
|
750
|
+
this.recovery ??= (async () => {
|
|
751
|
+
for (const runId of await this.runIds()) {
|
|
752
|
+
if (this.active.has(runId))
|
|
753
|
+
continue;
|
|
754
|
+
const host = await this.readEntry(runId);
|
|
755
|
+
if (host?.phase === "collecting") {
|
|
756
|
+
await this.finish(host, {
|
|
757
|
+
kind: "failed",
|
|
758
|
+
why: "the process stopped before the run finished collecting",
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
else if (host?.phase === "done") {
|
|
762
|
+
await this.reclaim(host);
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
})().catch((error) => {
|
|
766
|
+
this.recovery = null;
|
|
767
|
+
throw error;
|
|
768
|
+
});
|
|
769
|
+
return this.recovery;
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* The only way the writer reads a control row. The read is recorded in the
|
|
773
|
+
* connector's control watermark and the watermark's state is returned
|
|
774
|
+
* (`recordControl`): a lagging read yields the newer state already known,
|
|
775
|
+
* so no decision can use a raw read. The network read is outside the state
|
|
776
|
+
* lock; the recording is one short mutation.
|
|
777
|
+
*/
|
|
778
|
+
async readControl(connector, ns) {
|
|
779
|
+
const { control } = await this.keys();
|
|
780
|
+
const current = classifyControl(await this.options.registry.read(controlScope(connector, ns)), control);
|
|
781
|
+
return this.withState((state) => recordControl(state, connector, ns, current));
|
|
782
|
+
}
|
|
783
|
+
/**
|
|
784
|
+
* §2.4 admission for one decision point: read control, `decide`, follow
|
|
785
|
+
* `reread` once and `create`/`reconnect` with an `after_write` re-read.
|
|
786
|
+
* Returns the target generation, or throws `Discard`/`PendingStream`.
|
|
787
|
+
*/
|
|
788
|
+
async admit(host, phase) {
|
|
789
|
+
const { entry } = host;
|
|
790
|
+
const ns = entry.ns;
|
|
791
|
+
const scope = controlScope(entry.connector, ns);
|
|
792
|
+
const start = startState(entry.start, ns);
|
|
793
|
+
let current = await this.readControl(entry.connector, ns);
|
|
794
|
+
let decision = decide({
|
|
795
|
+
start,
|
|
796
|
+
current,
|
|
797
|
+
userConnect: entry.userConnect,
|
|
798
|
+
full: entry.full,
|
|
799
|
+
phase,
|
|
800
|
+
});
|
|
801
|
+
if (decision.kind === "reread") {
|
|
802
|
+
current = await this.readControl(entry.connector, ns);
|
|
803
|
+
decision = decide({
|
|
804
|
+
start,
|
|
805
|
+
current,
|
|
806
|
+
userConnect: entry.userConnect,
|
|
807
|
+
full: entry.full,
|
|
808
|
+
phase: "reread",
|
|
809
|
+
});
|
|
810
|
+
}
|
|
811
|
+
if (decision.kind === "create" || decision.kind === "reconnect") {
|
|
812
|
+
await this.writeControl(scope, decision.target);
|
|
813
|
+
this.fault("after_control_write", entry.runId);
|
|
814
|
+
current = await this.readControl(entry.connector, ns);
|
|
815
|
+
decision = decide({
|
|
816
|
+
start,
|
|
817
|
+
current,
|
|
818
|
+
userConnect: entry.userConnect,
|
|
819
|
+
full: entry.full,
|
|
820
|
+
phase: "after_write",
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
switch (decision.kind) {
|
|
824
|
+
case "publish":
|
|
825
|
+
if (host.generation != null && host.generation !== decision.target) {
|
|
826
|
+
throw new PendingStream("registry_inconsistent", "admission differs from the run generation");
|
|
827
|
+
}
|
|
828
|
+
host.generation = decision.target;
|
|
829
|
+
await this.writeEntry(host);
|
|
830
|
+
return decision.target;
|
|
831
|
+
case "discard":
|
|
832
|
+
throw new Discard(decision, `control reads ${describe(current)}`);
|
|
833
|
+
case "keep_pending":
|
|
834
|
+
throw new PendingStream(decision.reason, `control reads ${describe(current)}`);
|
|
835
|
+
default:
|
|
836
|
+
throw new PendingStream("registry_inconsistent", `unexpected decision ${decision.kind}`);
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
async writeControl(scope, version) {
|
|
840
|
+
const { control } = await this.keys();
|
|
841
|
+
const request = await this.sign(scope, control.activeData, control.activeMetadata, version);
|
|
842
|
+
// A create or reconnect reply (2xx or replay) is followed by a re-read;
|
|
843
|
+
// a 409 means someone else moved the row, which the re-read shows too.
|
|
844
|
+
try {
|
|
845
|
+
await this.options.registry.post(request);
|
|
846
|
+
}
|
|
847
|
+
catch (error) {
|
|
848
|
+
if (!(error instanceof AmbiguousRegistryReplyError))
|
|
849
|
+
throw error;
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
async sign(scope, dataHash, metadataHash, version) {
|
|
853
|
+
const signature = await this.options.signer.signAddData({
|
|
854
|
+
ownerAddress: this.options.ownerAddress,
|
|
855
|
+
scope,
|
|
856
|
+
dataHash,
|
|
857
|
+
metadataHash,
|
|
858
|
+
expectedVersion: BigInt(version),
|
|
859
|
+
});
|
|
860
|
+
return {
|
|
861
|
+
ownerAddress: this.options.ownerAddress,
|
|
862
|
+
scope,
|
|
863
|
+
dataHash,
|
|
864
|
+
metadataHash,
|
|
865
|
+
expectedVersion: String(version),
|
|
866
|
+
signature,
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
/** Mark every unresolved stream of `host` as selected; returns the keys. */
|
|
870
|
+
reserve(host) {
|
|
871
|
+
const keys = [];
|
|
872
|
+
for (const [name, outbox] of Object.entries(host.entry.streams)) {
|
|
873
|
+
if (outbox.state === "committed" || outbox.state === "noop")
|
|
874
|
+
continue;
|
|
875
|
+
const key = `${host.entry.runId}|${name}`;
|
|
876
|
+
this.selected.add(key);
|
|
877
|
+
keys.push(key);
|
|
878
|
+
}
|
|
879
|
+
return keys;
|
|
880
|
+
}
|
|
881
|
+
async publishEntry(host, held = new Set()) {
|
|
882
|
+
try {
|
|
883
|
+
// M5: a run publishes only for the owner and key it began with.
|
|
884
|
+
const bound = host.binding;
|
|
885
|
+
if (bound) {
|
|
886
|
+
const now = await this.binding();
|
|
887
|
+
if (bound.owner !== now.owner || bound.keyCheck !== now.keyCheck) {
|
|
888
|
+
await this.finish(host, {
|
|
889
|
+
kind: "failed",
|
|
890
|
+
why: "owner_mismatch: the owner or key changed since the run began",
|
|
891
|
+
});
|
|
892
|
+
return;
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
const target = await this.admit(host, "first");
|
|
896
|
+
if (host.target !== null && host.target !== target) {
|
|
897
|
+
throw new PendingStream("registry_inconsistent", `admitted at ${target}, run is bound to ${host.target}`);
|
|
898
|
+
}
|
|
899
|
+
host.target = target;
|
|
900
|
+
await this.prepareSeed(host);
|
|
901
|
+
await this.writeEntry(host);
|
|
902
|
+
}
|
|
903
|
+
catch (error) {
|
|
904
|
+
if (error instanceof Discard)
|
|
905
|
+
return this.discard(host, error);
|
|
906
|
+
if (error instanceof RegistryRefusedError) {
|
|
907
|
+
error = new PendingStream("registry_refused", error.message);
|
|
908
|
+
}
|
|
909
|
+
if (error instanceof PendingStream) {
|
|
910
|
+
for (const stream of Object.values(host.streams)) {
|
|
911
|
+
stream.problem = error.problem;
|
|
912
|
+
stream.detail = error.message;
|
|
913
|
+
}
|
|
914
|
+
await this.writeEntry(host);
|
|
915
|
+
return;
|
|
916
|
+
}
|
|
917
|
+
throw error;
|
|
918
|
+
}
|
|
919
|
+
for (const name of Object.keys(host.streams).sort()) {
|
|
920
|
+
const state = host.entry.streams[name].state;
|
|
921
|
+
if (state === "committed" || state === "noop")
|
|
922
|
+
continue;
|
|
923
|
+
if (held.has(floorKey(host.entry.connector, host.entry.ns, name))) {
|
|
924
|
+
host.streams[name].problem = "earlier_run_pending";
|
|
925
|
+
host.streams[name].detail =
|
|
926
|
+
"an earlier run of this stream is not committed yet";
|
|
927
|
+
await this.writeEntry(host);
|
|
928
|
+
continue;
|
|
929
|
+
}
|
|
930
|
+
try {
|
|
931
|
+
await this.publishStream(host, name);
|
|
932
|
+
host.streams[name].problem = null;
|
|
933
|
+
host.streams[name].detail = null;
|
|
934
|
+
}
|
|
935
|
+
catch (error) {
|
|
936
|
+
if (error instanceof Discard)
|
|
937
|
+
return this.discard(host, error);
|
|
938
|
+
if (error instanceof PendingStream) {
|
|
939
|
+
host.streams[name].problem = error.problem;
|
|
940
|
+
host.streams[name].detail = error.message;
|
|
941
|
+
await this.writeEntry(host);
|
|
942
|
+
continue;
|
|
943
|
+
}
|
|
944
|
+
if (error instanceof AmbiguousRegistryReplyError) {
|
|
945
|
+
host.streams[name].problem = "ambiguous_reply";
|
|
946
|
+
host.streams[name].detail = error.message;
|
|
947
|
+
await this.writeEntry(host);
|
|
948
|
+
continue;
|
|
949
|
+
}
|
|
950
|
+
if (error instanceof RegistryRefusedError) {
|
|
951
|
+
// A refused request is never resent; the next pass signs anew.
|
|
952
|
+
this.setStream(host, name, { state: "planned" });
|
|
953
|
+
host.streams[name].problem = "registry_refused";
|
|
954
|
+
host.streams[name].detail = error.message;
|
|
955
|
+
await this.writeEntry(host);
|
|
956
|
+
continue;
|
|
957
|
+
}
|
|
958
|
+
throw error;
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
const states = Object.values(host.entry.streams).map((s) => s.state);
|
|
962
|
+
if (!states.every((s) => s === "committed" || s === "noop"))
|
|
963
|
+
return;
|
|
964
|
+
await this.checkpoint(host);
|
|
965
|
+
}
|
|
966
|
+
/** §2.9: decide the seed for this run once the target generation is known. */
|
|
967
|
+
async prepareSeed(host) {
|
|
968
|
+
const seed = this.options.seed;
|
|
969
|
+
if (!seed)
|
|
970
|
+
return;
|
|
971
|
+
const { entry } = host;
|
|
972
|
+
const state = await this.readState();
|
|
973
|
+
if (state.seedTargets[entry.connector] !== entry.ns)
|
|
974
|
+
return;
|
|
975
|
+
const seedStreams = await seed.streams(entry.connector);
|
|
976
|
+
const receiptKey = (stream) => `${seed.installId}|${entry.connector}|${entry.ns}|${stream}`;
|
|
977
|
+
if (host.target !== 1) {
|
|
978
|
+
const open = seedStreams.filter((s) => state.receipts[receiptKey(s.stream)] === undefined);
|
|
979
|
+
if (open.length > 0) {
|
|
980
|
+
await this.withState((fresh) => {
|
|
981
|
+
for (const s of open) {
|
|
982
|
+
fresh.receipts[receiptKey(s.stream)] ??= "skipped";
|
|
983
|
+
}
|
|
984
|
+
});
|
|
985
|
+
}
|
|
986
|
+
return;
|
|
987
|
+
}
|
|
988
|
+
for (const s of seedStreams) {
|
|
989
|
+
if (state.receipts[receiptKey(s.stream)] !== undefined)
|
|
990
|
+
continue;
|
|
991
|
+
let stream = host.streams[s.stream];
|
|
992
|
+
if (!stream) {
|
|
993
|
+
stream = this.newStream(nextIndex(host), s);
|
|
994
|
+
stream.shardBytes = emptyShardBytes();
|
|
995
|
+
stream.seedOnly = true;
|
|
996
|
+
host.streams[s.stream] = stream;
|
|
997
|
+
host.entry = {
|
|
998
|
+
...host.entry,
|
|
999
|
+
streams: { ...host.entry.streams, [s.stream]: { state: "planned" } },
|
|
1000
|
+
};
|
|
1001
|
+
}
|
|
1002
|
+
stream.seedApplies = true;
|
|
1003
|
+
if (!host.seedStreams.includes(s.stream))
|
|
1004
|
+
host.seedStreams.push(s.stream);
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
async spoolSeed(host, name) {
|
|
1008
|
+
const seed = this.options.seed;
|
|
1009
|
+
const stream = host.streams[name];
|
|
1010
|
+
if (stream.seedShardBytes !== null)
|
|
1011
|
+
return;
|
|
1012
|
+
const dir = `runs/${host.entry.runId}/seed/s${stream.index}`;
|
|
1013
|
+
await this.options.home.files.remove(dir);
|
|
1014
|
+
await this.options.home.files.remove(spoolLogPath(dir));
|
|
1015
|
+
this.derived.delete(dir);
|
|
1016
|
+
const writer = new SpoolWriter(this.options.home.files);
|
|
1017
|
+
const bytes = emptyShardBytes();
|
|
1018
|
+
for await (const record of seed.records(host.entry.connector, name)) {
|
|
1019
|
+
if (!isPlainObject(record))
|
|
1020
|
+
continue;
|
|
1021
|
+
const value = record;
|
|
1022
|
+
const hash = await pkHash(this.hashes.sha256, value, stream.primaryKey);
|
|
1023
|
+
const text = encodeLine({
|
|
1024
|
+
o: SEED_OBSERVED_AT,
|
|
1025
|
+
r: SEED_RUN_ID,
|
|
1026
|
+
v: value,
|
|
1027
|
+
});
|
|
1028
|
+
const size = lineSize(text);
|
|
1029
|
+
if (!size.fits) {
|
|
1030
|
+
stream.recordTooLarge += 1;
|
|
1031
|
+
continue;
|
|
1032
|
+
}
|
|
1033
|
+
const shard = shardOf(hash);
|
|
1034
|
+
bytes[shard] += size.bytes + 1;
|
|
1035
|
+
await writer.add(spoolLogPath(dir), hash, text, size.bytes);
|
|
1036
|
+
}
|
|
1037
|
+
await writer.flush();
|
|
1038
|
+
await this.options.home.files.sync(spoolLogPath(dir));
|
|
1039
|
+
stream.seedShardBytes = bytes;
|
|
1040
|
+
await this.writeEntry(host);
|
|
1041
|
+
}
|
|
1042
|
+
/**
|
|
1043
|
+
* Shard counts of a spool whose shards are ready to read. The shards are
|
|
1044
|
+
* derived from the durable intake log and compacted once per process; a
|
|
1045
|
+
* run found after a restart derives them again, because the files were
|
|
1046
|
+
* never synced and may be missing or short. `counted` is the intake count
|
|
1047
|
+
* per shard, which the log still holds.
|
|
1048
|
+
*/
|
|
1049
|
+
async readyShards(dir, counted) {
|
|
1050
|
+
const known = this.derived.get(dir);
|
|
1051
|
+
if (known)
|
|
1052
|
+
return known;
|
|
1053
|
+
await deriveShards(this.options.home.files, dir);
|
|
1054
|
+
const bytes = [...counted];
|
|
1055
|
+
await this.compact(dir, bytes);
|
|
1056
|
+
this.derived.set(dir, bytes);
|
|
1057
|
+
return bytes;
|
|
1058
|
+
}
|
|
1059
|
+
async publishStream(host, name) {
|
|
1060
|
+
for (let attempt = 0; attempt < CONFLICTS_PER_PASS; attempt += 1) {
|
|
1061
|
+
const outbox = host.entry.streams[name];
|
|
1062
|
+
if (outbox.state === "request_persisted") {
|
|
1063
|
+
if (await this.resend(host, name))
|
|
1064
|
+
return;
|
|
1065
|
+
continue;
|
|
1066
|
+
}
|
|
1067
|
+
if (await this.planAndPost(host, name))
|
|
1068
|
+
return;
|
|
1069
|
+
}
|
|
1070
|
+
throw new PendingStream("registry_inconsistent", `${CONFLICTS_PER_PASS} version conflicts in one pass; retrying next cycle`);
|
|
1071
|
+
}
|
|
1072
|
+
setStream(host, name, next) {
|
|
1073
|
+
host.entry = {
|
|
1074
|
+
...host.entry,
|
|
1075
|
+
streams: { ...host.entry.streams, [name]: next },
|
|
1076
|
+
};
|
|
1077
|
+
}
|
|
1078
|
+
/** Resend the persisted request byte for byte. True when committed. */
|
|
1079
|
+
async resend(host, name) {
|
|
1080
|
+
const runId = host.entry.runId;
|
|
1081
|
+
const outbox = host.entry.streams[name];
|
|
1082
|
+
const request = JSON.parse(decoder.decode((await this.options.home.files.read(outbox.requestRef))));
|
|
1083
|
+
const cipher = await this.options.home.files.read(outbox.headCipherRef);
|
|
1084
|
+
const head = parseHeadKey(request);
|
|
1085
|
+
if (cipher)
|
|
1086
|
+
await this.options.blobs.put(head, cipher);
|
|
1087
|
+
const result = await this.options.registry.post(request);
|
|
1088
|
+
this.fault("after_post_reply", runId, name);
|
|
1089
|
+
if (result.kind === "committed") {
|
|
1090
|
+
const stream = host.streams[name];
|
|
1091
|
+
await this.committed(host, name, outbox.generation, outbox.complete, "committed", Number(request.expectedVersion), request.dataHash, stream.planned ?? {
|
|
1092
|
+
// A request persisted before plan steps were recorded.
|
|
1093
|
+
kind: "publish",
|
|
1094
|
+
head: {
|
|
1095
|
+
generation: outbox.generation,
|
|
1096
|
+
primaryKey: stream.primaryKey,
|
|
1097
|
+
profile: stream.profile,
|
|
1098
|
+
complete: outbox.complete,
|
|
1099
|
+
},
|
|
1100
|
+
replacesBase: false,
|
|
1101
|
+
floor: stream.profile.version,
|
|
1102
|
+
});
|
|
1103
|
+
return true;
|
|
1104
|
+
}
|
|
1105
|
+
this.setStream(host, name, { state: "planned" });
|
|
1106
|
+
await this.writeEntry(host);
|
|
1107
|
+
return false;
|
|
1108
|
+
}
|
|
1109
|
+
/** §2.7 from "read control" to the POST. True when committed or no-op. */
|
|
1110
|
+
async planAndPost(host, name) {
|
|
1111
|
+
const { entry } = host;
|
|
1112
|
+
const runId = entry.runId;
|
|
1113
|
+
const ns = entry.ns;
|
|
1114
|
+
const stream = host.streams[name];
|
|
1115
|
+
const target = await this.admit(host, "first");
|
|
1116
|
+
if (target !== host.target) {
|
|
1117
|
+
throw new PendingStream("registry_inconsistent", `admitted at ${target}, run is bound to ${host.target}`);
|
|
1118
|
+
}
|
|
1119
|
+
const scope = streamScope(entry.connector, ns, name);
|
|
1120
|
+
const { keyCheck } = await this.keys();
|
|
1121
|
+
const row = await this.options.registry.read(scope);
|
|
1122
|
+
const rowKind = classifyStreamRow(row, this.control);
|
|
1123
|
+
let head = null;
|
|
1124
|
+
if (rowKind === "present" && row.found) {
|
|
1125
|
+
head = await this.loadHead(scope, row.dataHash, {
|
|
1126
|
+
connector: entry.connector,
|
|
1127
|
+
ns,
|
|
1128
|
+
stream: name,
|
|
1129
|
+
keyCheck,
|
|
1130
|
+
});
|
|
1131
|
+
}
|
|
1132
|
+
const choice = chooseBase(rowKind, head, target);
|
|
1133
|
+
if (choice.kind === "stale_generation") {
|
|
1134
|
+
// F1: the stream holds a newer generation than this run's target.
|
|
1135
|
+
try {
|
|
1136
|
+
await this.admit(host, "stale_base");
|
|
1137
|
+
}
|
|
1138
|
+
catch (error) {
|
|
1139
|
+
if (error instanceof Discard) {
|
|
1140
|
+
throw new Discard(error.decision, `stale_generation: ${error.why}`);
|
|
1141
|
+
}
|
|
1142
|
+
if (error instanceof PendingStream) {
|
|
1143
|
+
throw new PendingStream(error.problem, `stale_generation: ${error.message}`);
|
|
1144
|
+
}
|
|
1145
|
+
throw error;
|
|
1146
|
+
}
|
|
1147
|
+
throw new PendingStream("registry_inconsistent", "stale_generation: control still admits the target");
|
|
1148
|
+
}
|
|
1149
|
+
// The publish plan decides this step (publish-plan.ts); this method only
|
|
1150
|
+
// executes it: the parts, the head upload and the POST.
|
|
1151
|
+
const decision = planStreamStep({
|
|
1152
|
+
head: head && planHeadOf(head),
|
|
1153
|
+
floor: floorOf(await this.readState(), entry.connector, ns, name),
|
|
1154
|
+
}, this.planRun(host, name, await this.readState(), true));
|
|
1155
|
+
if (decision.kind === "refused") {
|
|
1156
|
+
throw new PendingStream(decision.reason, decision.reason === "out_of_order"
|
|
1157
|
+
? "a newer run already committed on this stream"
|
|
1158
|
+
: `base primary key ${JSON.stringify(head?.primaryKey ?? [])} needs a newer connector`);
|
|
1159
|
+
}
|
|
1160
|
+
if (decision.kind === "deferred") {
|
|
1161
|
+
throw new PendingStream("registry_inconsistent", `publish plan deferred the stream: ${decision.reason}`);
|
|
1162
|
+
}
|
|
1163
|
+
const base = choice.kind === "base" &&
|
|
1164
|
+
(decision.kind === "noop" || !decision.replacesBase)
|
|
1165
|
+
? choice.head
|
|
1166
|
+
: null;
|
|
1167
|
+
if (stream.seedApplies)
|
|
1168
|
+
await this.spoolSeed(host, name);
|
|
1169
|
+
const next = decision.head;
|
|
1170
|
+
const complete = next.complete;
|
|
1171
|
+
const built = await this.buildParts(host, name, scope, target, base);
|
|
1172
|
+
// A step whose parts, completeness, key and profile all equal the base's
|
|
1173
|
+
// changes nothing a reader sees: record a no-op of the same head.
|
|
1174
|
+
if (isNoop(base, built.parts, complete, {
|
|
1175
|
+
primaryKey: next.primaryKey,
|
|
1176
|
+
profile: next.profile,
|
|
1177
|
+
})) {
|
|
1178
|
+
if (!row.found)
|
|
1179
|
+
throw new Error("no-op requires a registered base");
|
|
1180
|
+
await this.committed(host, name, target, complete, "noop", row.version, row.dataHash, {
|
|
1181
|
+
kind: "noop",
|
|
1182
|
+
head: planHeadOf(base),
|
|
1183
|
+
replacesBase: false,
|
|
1184
|
+
floor: decision.floor,
|
|
1185
|
+
});
|
|
1186
|
+
return true;
|
|
1187
|
+
}
|
|
1188
|
+
const step = {
|
|
1189
|
+
kind: "publish",
|
|
1190
|
+
head: next,
|
|
1191
|
+
replacesBase: decision.kind === "publish" && decision.replacesBase,
|
|
1192
|
+
floor: decision.floor,
|
|
1193
|
+
};
|
|
1194
|
+
const clear = encodeHead({
|
|
1195
|
+
complete,
|
|
1196
|
+
connector: entry.connector,
|
|
1197
|
+
format: 1,
|
|
1198
|
+
generation: target,
|
|
1199
|
+
keyCheck,
|
|
1200
|
+
ns,
|
|
1201
|
+
observedAt: entry.observedAt,
|
|
1202
|
+
parts: built.parts,
|
|
1203
|
+
primaryKey: next.primaryKey,
|
|
1204
|
+
profile: next.profile,
|
|
1205
|
+
recordCount: built.parts.reduce((n, p) => n + p.count, 0),
|
|
1206
|
+
stream: name,
|
|
1207
|
+
});
|
|
1208
|
+
const digest = await digestHead(this.hashes.keccak256, clear);
|
|
1209
|
+
const cipher = await this.options.keys.encrypt(scope, clear);
|
|
1210
|
+
await this.options.blobs.put(`${scope}/${digest.blobName}`, cipher);
|
|
1211
|
+
this.fault("after_head_upload", runId, name);
|
|
1212
|
+
const version = row.found ? row.version + 1 : 1;
|
|
1213
|
+
const request = await this.sign(scope, digest.dataHash, publicationMetadataHash(scope, new Date(entry.observedAt).toISOString(), clear.length), version);
|
|
1214
|
+
const requestRef = `runs/${runId}/request-s${stream.index}.json`;
|
|
1215
|
+
const headCipherRef = `runs/${runId}/head-s${stream.index}.bin`;
|
|
1216
|
+
await this.options.home.files.write(headCipherRef, cipher);
|
|
1217
|
+
await this.options.home.files.write(requestRef, json(request));
|
|
1218
|
+
stream.planned = step;
|
|
1219
|
+
this.setStream(host, name, {
|
|
1220
|
+
state: "request_persisted",
|
|
1221
|
+
requestRef,
|
|
1222
|
+
headCipherRef,
|
|
1223
|
+
generation: target,
|
|
1224
|
+
complete,
|
|
1225
|
+
});
|
|
1226
|
+
await this.writeEntry(host);
|
|
1227
|
+
this.fault("after_request_persisted", runId, name);
|
|
1228
|
+
const result = await this.options.registry.post(request);
|
|
1229
|
+
this.fault("after_post_reply", runId, name);
|
|
1230
|
+
if (result.kind === "committed") {
|
|
1231
|
+
await this.committed(host, name, target, complete, "committed", version, request.dataHash, step);
|
|
1232
|
+
return true;
|
|
1233
|
+
}
|
|
1234
|
+
this.setStream(host, name, { state: "planned" });
|
|
1235
|
+
await this.writeEntry(host);
|
|
1236
|
+
return false;
|
|
1237
|
+
}
|
|
1238
|
+
/** What the publish plan reads of one run's stream. */
|
|
1239
|
+
planRun(host, name, state, executing = false) {
|
|
1240
|
+
const { entry } = host;
|
|
1241
|
+
const stream = host.streams[name];
|
|
1242
|
+
const seed = this.options.seed;
|
|
1243
|
+
const seedOpen = seed !== undefined &&
|
|
1244
|
+
entry.ns !== null &&
|
|
1245
|
+
host.target === null &&
|
|
1246
|
+
state.seedTargets[entry.connector] === entry.ns &&
|
|
1247
|
+
state.receipts[`${seed.installId}|${entry.connector}|${entry.ns}|${name}`] === undefined;
|
|
1248
|
+
const outbox = entry.streams[name];
|
|
1249
|
+
const executed = stream.executed ??
|
|
1250
|
+
((outbox?.state === "committed" || outbox?.state === "noop") &&
|
|
1251
|
+
outbox.generation !== undefined
|
|
1252
|
+
? {
|
|
1253
|
+
// An entry from before plan steps were recorded.
|
|
1254
|
+
kind: outbox.state === "noop" ? "noop" : "publish",
|
|
1255
|
+
head: {
|
|
1256
|
+
generation: outbox.generation,
|
|
1257
|
+
primaryKey: stream.primaryKey,
|
|
1258
|
+
profile: stream.profile,
|
|
1259
|
+
complete: outbox.complete ?? false,
|
|
1260
|
+
},
|
|
1261
|
+
replacesBase: false,
|
|
1262
|
+
}
|
|
1263
|
+
: undefined);
|
|
1264
|
+
return {
|
|
1265
|
+
runId: entry.runId,
|
|
1266
|
+
observedAt: entry.observedAt,
|
|
1267
|
+
generation: host.target ?? host.generation ?? null,
|
|
1268
|
+
primaryKey: stream.primaryKey,
|
|
1269
|
+
profile: stream.profile,
|
|
1270
|
+
full: entry.full || stream.fullStream,
|
|
1271
|
+
foreignCheckpoint: host.checkpointUsed !== null && host.checkpointUsed.ns !== entry.ns,
|
|
1272
|
+
empty: (stream.shardBytes ?? []).every((bytes) => bytes === 0),
|
|
1273
|
+
seed: stream.seedApplies ? "merged" : seedOpen ? "unresolved" : "none",
|
|
1274
|
+
...(executed ? { executed } : {}),
|
|
1275
|
+
// Selected by a running pass, or signed and persisted: either way the
|
|
1276
|
+
// registry's answer is not recorded yet.
|
|
1277
|
+
...(!executed &&
|
|
1278
|
+
(outbox?.state === "request_persisted" ||
|
|
1279
|
+
// The executing pass plans its own step: it is not its own barrier.
|
|
1280
|
+
(!executing && this.selected.has(`${entry.runId}|${name}`)))
|
|
1281
|
+
? { inFlight: true }
|
|
1282
|
+
: {}),
|
|
1283
|
+
};
|
|
1284
|
+
}
|
|
1285
|
+
/** Record a commit or no-op: `needsFull` and seed receipt, then the outbox. */
|
|
1286
|
+
async committed(host, name, generation, complete, kind, registryVersion, dataHash, step) {
|
|
1287
|
+
const { entry } = host;
|
|
1288
|
+
const stream = host.streams[name];
|
|
1289
|
+
await this.withState((state) => {
|
|
1290
|
+
// The version floor and the commit order only move forward.
|
|
1291
|
+
const key = floorKey(entry.connector, entry.ns, name);
|
|
1292
|
+
const prev = floorOf(state, entry.connector, entry.ns, name);
|
|
1293
|
+
const stamp = { observedAt: entry.observedAt, runId: entry.runId };
|
|
1294
|
+
const version = prev.version === null ||
|
|
1295
|
+
compareConnectorVersions(step.floor, prev.version) === "higher"
|
|
1296
|
+
? step.floor
|
|
1297
|
+
: prev.version;
|
|
1298
|
+
const committed = prev.committed && stampBefore(stamp, prev.committed)
|
|
1299
|
+
? prev.committed
|
|
1300
|
+
: stamp;
|
|
1301
|
+
(state.streamFloors ??= {})[key] = {
|
|
1302
|
+
version,
|
|
1303
|
+
committed: [committed.observedAt, committed.runId],
|
|
1304
|
+
};
|
|
1305
|
+
// §3.0: a stream declared `incremental: false` is read whole every run.
|
|
1306
|
+
const effect = afterCommit(state.needsFull, {
|
|
1307
|
+
connector: entry.connector,
|
|
1308
|
+
ns: entry.ns,
|
|
1309
|
+
stream: name,
|
|
1310
|
+
complete,
|
|
1311
|
+
runFull: entry.full || stream.fullStream,
|
|
1312
|
+
});
|
|
1313
|
+
state.needsFull = effect.needsFull;
|
|
1314
|
+
if (effect.clearCheckpoint) {
|
|
1315
|
+
invalidateCheckpoint(state, entry.connector, true);
|
|
1316
|
+
}
|
|
1317
|
+
if (stream.seedApplies && this.options.seed) {
|
|
1318
|
+
state.receipts[`${this.options.seed.installId}|${entry.connector}|${entry.ns}|${name}`] = "merged";
|
|
1319
|
+
}
|
|
1320
|
+
});
|
|
1321
|
+
stream.receipt = {
|
|
1322
|
+
registryVersion,
|
|
1323
|
+
dataHash: canonicalBytes32(dataHash),
|
|
1324
|
+
generation,
|
|
1325
|
+
};
|
|
1326
|
+
stream.executed = {
|
|
1327
|
+
kind: step.kind,
|
|
1328
|
+
head: step.head,
|
|
1329
|
+
replacesBase: step.replacesBase,
|
|
1330
|
+
};
|
|
1331
|
+
delete stream.planned;
|
|
1332
|
+
this.setStream(host, name, {
|
|
1333
|
+
state: kind,
|
|
1334
|
+
generation,
|
|
1335
|
+
complete,
|
|
1336
|
+
...(stream.recordTooLarge > 0
|
|
1337
|
+
? { recordTooLarge: stream.recordTooLarge }
|
|
1338
|
+
: {}),
|
|
1339
|
+
});
|
|
1340
|
+
await this.writeEntry(host);
|
|
1341
|
+
this.fault("after_commit_recorded", entry.runId, name);
|
|
1342
|
+
}
|
|
1343
|
+
async checkpoint(host) {
|
|
1344
|
+
const { entry } = host;
|
|
1345
|
+
const ns = entry.ns;
|
|
1346
|
+
// Snapshot before the control read: an invalidation that lands after it
|
|
1347
|
+
// makes that read stale, and the save below refuses to use it.
|
|
1348
|
+
const epoch = (await this.readState()).invalidations?.[entry.connector] ?? 0;
|
|
1349
|
+
const control = await this.readControl(entry.connector, ns);
|
|
1350
|
+
const seed = this.options.seed;
|
|
1351
|
+
const streams = Object.fromEntries(Object.entries(entry.streams).map(([k, v]) => [k, streamRunResult(v)]));
|
|
1352
|
+
const decision = await this.withState((state) => {
|
|
1353
|
+
if ((state.invalidations?.[entry.connector] ?? 0) !== epoch) {
|
|
1354
|
+
// The records are already published; the next run reads them again.
|
|
1355
|
+
return { kind: "stale" };
|
|
1356
|
+
}
|
|
1357
|
+
const seedReceiptsPending = host.seedStreams.some((s) => seed !== undefined &&
|
|
1358
|
+
state.receipts[`${seed.installId}|${entry.connector}|${ns}|${s}`] ===
|
|
1359
|
+
undefined);
|
|
1360
|
+
// Decide on the watermark as of this mutation, not on the read alone.
|
|
1361
|
+
const latest = state.observedControl?.[entry.connector]?.[ns] ?? control;
|
|
1362
|
+
const decided = checkpointDecision({
|
|
1363
|
+
target: host.target,
|
|
1364
|
+
streams,
|
|
1365
|
+
control: latest,
|
|
1366
|
+
seedReceiptsPending,
|
|
1367
|
+
});
|
|
1368
|
+
const held = state.checkpoints[entry.connector];
|
|
1369
|
+
if (decided.kind === "save" &&
|
|
1370
|
+
held?.ns === ns &&
|
|
1371
|
+
held.generation > decided.generation) {
|
|
1372
|
+
// Never replace a newer generation's checkpoint with an older one.
|
|
1373
|
+
return { kind: "stale" };
|
|
1374
|
+
}
|
|
1375
|
+
if (decided.kind === "save") {
|
|
1376
|
+
// §3.6: this run's cursors join the saved ones of the same namespace
|
|
1377
|
+
// and generation, so a stream the run did not cover keeps its own.
|
|
1378
|
+
const prev = state.checkpoints[entry.connector];
|
|
1379
|
+
const same = prev?.ns === ns && prev.generation === decided.generation;
|
|
1380
|
+
state.checkpoints[entry.connector] = {
|
|
1381
|
+
ns,
|
|
1382
|
+
generation: decided.generation,
|
|
1383
|
+
value: mergeCursors(same ? prev.value : null, entry.checkpointCandidate),
|
|
1384
|
+
};
|
|
1385
|
+
}
|
|
1386
|
+
return decided;
|
|
1387
|
+
});
|
|
1388
|
+
if (decision.kind === "stale") {
|
|
1389
|
+
await this.finish(host, {
|
|
1390
|
+
kind: "no_checkpoint",
|
|
1391
|
+
generation: host.target,
|
|
1392
|
+
reason: "control_changed",
|
|
1393
|
+
});
|
|
1394
|
+
return;
|
|
1395
|
+
}
|
|
1396
|
+
if (decision.kind === "save") {
|
|
1397
|
+
this.fault("after_checkpoint_saved", entry.runId);
|
|
1398
|
+
await this.finish(host, {
|
|
1399
|
+
kind: "checkpointed",
|
|
1400
|
+
generation: decision.generation,
|
|
1401
|
+
});
|
|
1402
|
+
return;
|
|
1403
|
+
}
|
|
1404
|
+
await this.finish(host, {
|
|
1405
|
+
kind: "no_checkpoint",
|
|
1406
|
+
generation: host.target,
|
|
1407
|
+
reason: decision.reason,
|
|
1408
|
+
});
|
|
1409
|
+
}
|
|
1410
|
+
async discard(host, error) {
|
|
1411
|
+
const { entry } = host;
|
|
1412
|
+
const { decision } = error;
|
|
1413
|
+
if (decision.clearCheckpoints) {
|
|
1414
|
+
await this.withState((state) => {
|
|
1415
|
+
invalidateCheckpoint(state, entry.connector, state.checkpoints[entry.connector]?.ns === entry.ns);
|
|
1416
|
+
});
|
|
1417
|
+
}
|
|
1418
|
+
for (const [name, stream] of Object.entries(entry.streams)) {
|
|
1419
|
+
if (stream.state !== "committed" && stream.state !== "noop") {
|
|
1420
|
+
this.setStream(host, name, { state: "discarded" });
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
await this.finish(host, {
|
|
1424
|
+
kind: "discarded",
|
|
1425
|
+
recollect: decision.recollect,
|
|
1426
|
+
clearCheckpoints: decision.clearCheckpoints,
|
|
1427
|
+
restartFull: decision.restartFull,
|
|
1428
|
+
why: error.why,
|
|
1429
|
+
});
|
|
1430
|
+
if (decision.restartFull)
|
|
1431
|
+
this.options.onRestartFull?.(entry.connector);
|
|
1432
|
+
}
|
|
1433
|
+
async finish(host, outcome) {
|
|
1434
|
+
// Older ready entries have no explicit ready marker.
|
|
1435
|
+
host.ready ??= host.phase === "ready";
|
|
1436
|
+
host.outcome = outcome;
|
|
1437
|
+
host.phase = "done";
|
|
1438
|
+
const runId = host.entry.runId;
|
|
1439
|
+
await this.writeEntry(host);
|
|
1440
|
+
await this.options.home.files.write(`results/${runId}.json`, json(this.statusOf(host)));
|
|
1441
|
+
await this.reclaim(host);
|
|
1442
|
+
if (!(outcome.kind === "aborted" && outcome.reason === "cancelled")) {
|
|
1443
|
+
const bad = outcome.kind === "failed" ||
|
|
1444
|
+
outcome.kind === "discarded" ||
|
|
1445
|
+
outcome.kind === "aborted";
|
|
1446
|
+
await this.note(host.entry.connector, bad ? "bad" : "good");
|
|
1447
|
+
}
|
|
1448
|
+
for (const dir of [...this.derived.keys()]) {
|
|
1449
|
+
if (dir.startsWith(`runs/${runId}/`))
|
|
1450
|
+
this.derived.delete(dir);
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
/**
|
|
1454
|
+
* A stream is covered only when its own receipt satisfies the latest
|
|
1455
|
+
* coverage for the same binding, connector, namespace, stream and generation.
|
|
1456
|
+
* Never treat a missing pre-upgrade receipt as proof of read coverage.
|
|
1457
|
+
*/
|
|
1458
|
+
isCovered(host, name) {
|
|
1459
|
+
const receipt = host.streams[name]?.receipt;
|
|
1460
|
+
if (!receipt ||
|
|
1461
|
+
!host.binding ||
|
|
1462
|
+
host.entry.ns === null ||
|
|
1463
|
+
host.generation == null)
|
|
1464
|
+
return false;
|
|
1465
|
+
const coverage = this.coverage.get(coverageKey(host.binding, host.entry.connector, host.entry.ns, name, host.generation));
|
|
1466
|
+
if (!coverage)
|
|
1467
|
+
return false;
|
|
1468
|
+
if (coverage.registryVersion !== receipt.registryVersion)
|
|
1469
|
+
return coverage.registryVersion > receipt.registryVersion;
|
|
1470
|
+
try {
|
|
1471
|
+
return coverage.dataHash === canonicalBytes32(receipt.dataHash);
|
|
1472
|
+
}
|
|
1473
|
+
catch {
|
|
1474
|
+
return false; // an unreadable stored hash never proves coverage
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
retainedStreams(host) {
|
|
1478
|
+
if (host.ready === false || host.outcome?.kind === "aborted")
|
|
1479
|
+
return [];
|
|
1480
|
+
// A stream only the seed fills stays until its receipt is covered: it
|
|
1481
|
+
// publishes a head later runs of the stream meet, so the reader's plan
|
|
1482
|
+
// needs its step. It holds no intake rows and exposes no seed rows.
|
|
1483
|
+
return Object.keys(host.streams).filter((name) => host.entry.streams[name]?.state !== "discarded" &&
|
|
1484
|
+
!this.isCovered(host, name));
|
|
1485
|
+
}
|
|
1486
|
+
reclaim(host) {
|
|
1487
|
+
return this.lifecycle(() => this.reclaimLocked(host));
|
|
1488
|
+
}
|
|
1489
|
+
async reclaimLocked(host) {
|
|
1490
|
+
if (host.phase !== "done" || this.inconsistentReceipt(host))
|
|
1491
|
+
return;
|
|
1492
|
+
if ((this.pins.get(host.entry.runId) ?? 0) > 0 ||
|
|
1493
|
+
this.retainedStreams(host).length > 0)
|
|
1494
|
+
return;
|
|
1495
|
+
const runId = host.entry.runId;
|
|
1496
|
+
try {
|
|
1497
|
+
await this.options.home.files.remove(`runs/${runId}`);
|
|
1498
|
+
this.removalRetry.delete(runId);
|
|
1499
|
+
}
|
|
1500
|
+
catch (error) {
|
|
1501
|
+
this.removalRetry.add(runId);
|
|
1502
|
+
this.reportCleanup(runId, error);
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
reportCleanup(runId, error) {
|
|
1506
|
+
this.options.logger?.warn({
|
|
1507
|
+
runId,
|
|
1508
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1509
|
+
}, "stream-sync run cleanup failed; it will be retried");
|
|
1510
|
+
}
|
|
1511
|
+
/** Retry removals that failed earlier. Call inside the lifecycle queue. */
|
|
1512
|
+
async retryRemovals() {
|
|
1513
|
+
for (const runId of [...this.removalRetry]) {
|
|
1514
|
+
this.removalRetry.delete(runId);
|
|
1515
|
+
try {
|
|
1516
|
+
const host = await this.readEntry(runId);
|
|
1517
|
+
if (host)
|
|
1518
|
+
await this.reclaimLocked(host);
|
|
1519
|
+
}
|
|
1520
|
+
catch (error) {
|
|
1521
|
+
this.removalRetry.add(runId);
|
|
1522
|
+
this.reportCleanup(runId, error);
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
/** Called only by the home-bound overlay adapter. Does no network I/O. */
|
|
1527
|
+
async snapshotOverlay(connector) {
|
|
1528
|
+
await this.recover();
|
|
1529
|
+
const bound = await this.binding();
|
|
1530
|
+
return this.lifecycle(async () => {
|
|
1531
|
+
await this.retryRemovals();
|
|
1532
|
+
const runs = [];
|
|
1533
|
+
const logs = new Map();
|
|
1534
|
+
const state = await this.readState();
|
|
1535
|
+
const plans = new Map();
|
|
1536
|
+
for (const runId of await this.runIds()) {
|
|
1537
|
+
const host = await this.readEntry(runId);
|
|
1538
|
+
if (!host ||
|
|
1539
|
+
host.entry.connector !== connector ||
|
|
1540
|
+
host.phase === "collecting" ||
|
|
1541
|
+
host.ready === false ||
|
|
1542
|
+
host.outcome?.kind === "aborted" ||
|
|
1543
|
+
host.entry.ns === null ||
|
|
1544
|
+
!host.binding ||
|
|
1545
|
+
host.binding.owner.toLowerCase() !== bound.owner.toLowerCase() ||
|
|
1546
|
+
host.binding.keyCheck !== bound.keyCheck)
|
|
1547
|
+
continue;
|
|
1548
|
+
const generation = host.generation ?? null;
|
|
1549
|
+
// Never expose or reclaim an inconsistent run, including a discarded receipt.
|
|
1550
|
+
if (this.inconsistentReceipt(host))
|
|
1551
|
+
continue;
|
|
1552
|
+
if (!host.overlayRevision) {
|
|
1553
|
+
host.overlayRevision = globalThis.crypto.randomUUID();
|
|
1554
|
+
await this.options.home.files.write(`runs/${runId}/entry.json`, json(host));
|
|
1555
|
+
}
|
|
1556
|
+
const streams = [];
|
|
1557
|
+
const runLogs = new Map();
|
|
1558
|
+
for (const name of this.retainedStreams(host)) {
|
|
1559
|
+
const stream = host.streams[name];
|
|
1560
|
+
if (stream.shardBytes === null)
|
|
1561
|
+
throw new Error("ready stream has no intake byte counts");
|
|
1562
|
+
const descriptor = {
|
|
1563
|
+
name,
|
|
1564
|
+
primaryKey: Object.freeze([...stream.primaryKey]),
|
|
1565
|
+
profile: Object.freeze({ ...stream.profile }),
|
|
1566
|
+
complete: (host.entry.full || stream.fullStream) &&
|
|
1567
|
+
(!host.checkpointUsed ||
|
|
1568
|
+
host.checkpointUsed.ns === host.entry.ns),
|
|
1569
|
+
state: stream.receipt
|
|
1570
|
+
? "published"
|
|
1571
|
+
: stream.problem
|
|
1572
|
+
? "failed"
|
|
1573
|
+
: "pending",
|
|
1574
|
+
...(stream.receipt
|
|
1575
|
+
? { receipt: Object.freeze({ ...stream.receipt }) }
|
|
1576
|
+
: {}),
|
|
1577
|
+
};
|
|
1578
|
+
streams.push(Object.freeze({
|
|
1579
|
+
...descriptor,
|
|
1580
|
+
contentRevision: JSON.stringify([
|
|
1581
|
+
host.overlayRevision,
|
|
1582
|
+
runId,
|
|
1583
|
+
host.entry.ns,
|
|
1584
|
+
generation,
|
|
1585
|
+
host.entry.observedAt,
|
|
1586
|
+
descriptor,
|
|
1587
|
+
]),
|
|
1588
|
+
}));
|
|
1589
|
+
const planKey = overlayPlanKey(host.entry.ns, name);
|
|
1590
|
+
const plan = plans.get(planKey) ?? {
|
|
1591
|
+
floor: floorOf(state, connector, host.entry.ns, name),
|
|
1592
|
+
runs: [],
|
|
1593
|
+
};
|
|
1594
|
+
plan.runs.push(Object.freeze(this.planRun(host, name, state)));
|
|
1595
|
+
plans.set(planKey, plan);
|
|
1596
|
+
// A seed-only stream has no intake log: its rows are never read.
|
|
1597
|
+
if (stream.seedOnly)
|
|
1598
|
+
continue;
|
|
1599
|
+
runLogs.set(name, {
|
|
1600
|
+
path: spoolLogPath(`runs/${runId}/spool/s${stream.index}`),
|
|
1601
|
+
bytes: stream.shardBytes.reduce((sum, n) => sum + n, 0),
|
|
1602
|
+
primaryKey: descriptor.primaryKey,
|
|
1603
|
+
});
|
|
1604
|
+
}
|
|
1605
|
+
if (streams.length === 0)
|
|
1606
|
+
continue;
|
|
1607
|
+
const run = Object.freeze({
|
|
1608
|
+
runId,
|
|
1609
|
+
connector,
|
|
1610
|
+
ns: host.entry.ns,
|
|
1611
|
+
generation,
|
|
1612
|
+
observedAt: host.entry.observedAt,
|
|
1613
|
+
state: streams.every((s) => s.state === "published")
|
|
1614
|
+
? "published"
|
|
1615
|
+
: streams.some((s) => s.state === "failed")
|
|
1616
|
+
? "failed"
|
|
1617
|
+
: "pending",
|
|
1618
|
+
streams: Object.freeze(streams),
|
|
1619
|
+
});
|
|
1620
|
+
runs.push(run);
|
|
1621
|
+
logs.set(run, runLogs);
|
|
1622
|
+
}
|
|
1623
|
+
for (const run of runs)
|
|
1624
|
+
this.pins.set(run.runId, (this.pins.get(run.runId) ?? 0) + 1);
|
|
1625
|
+
return pinnedWriterSnapshot(this.options.home.files, Object.freeze(runs), logs, () => {
|
|
1626
|
+
void this.lifecycle(async () => {
|
|
1627
|
+
for (const run of runs) {
|
|
1628
|
+
const count = this.pins.get(run.runId) - 1;
|
|
1629
|
+
if (count === 0)
|
|
1630
|
+
this.pins.delete(run.runId);
|
|
1631
|
+
else
|
|
1632
|
+
this.pins.set(run.runId, count);
|
|
1633
|
+
}
|
|
1634
|
+
for (const run of runs) {
|
|
1635
|
+
try {
|
|
1636
|
+
const host = await this.readEntry(run.runId);
|
|
1637
|
+
if (host?.phase === "done")
|
|
1638
|
+
await this.reclaimLocked(host);
|
|
1639
|
+
}
|
|
1640
|
+
catch (error) {
|
|
1641
|
+
// Unreadable metadata fails the read of that run, not the writer.
|
|
1642
|
+
this.removalRetry.add(run.runId);
|
|
1643
|
+
this.reportCleanup(run.runId, error);
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
await this.retryRemovals();
|
|
1647
|
+
});
|
|
1648
|
+
}, plans);
|
|
1649
|
+
});
|
|
1650
|
+
}
|
|
1651
|
+
inconsistentReceipt(host) {
|
|
1652
|
+
return Object.values(host.streams).some((stream) => stream.receipt &&
|
|
1653
|
+
(host.generation == null ||
|
|
1654
|
+
stream.receipt.generation !== host.generation));
|
|
1655
|
+
}
|
|
1656
|
+
/** The caller has committed these bytes to its durable read store. */
|
|
1657
|
+
async acknowledgeOverlay(offered) {
|
|
1658
|
+
// Reject a malformed digest before it can be stored or reclaim anything.
|
|
1659
|
+
const coverage = {
|
|
1660
|
+
...offered,
|
|
1661
|
+
dataHash: canonicalBytes32(offered.dataHash),
|
|
1662
|
+
};
|
|
1663
|
+
await this.recover();
|
|
1664
|
+
const binding = await this.binding();
|
|
1665
|
+
await this.lifecycle(async () => {
|
|
1666
|
+
await this.retryRemovals();
|
|
1667
|
+
const key = coverageKey(binding, coverage.connector, coverage.ns, coverage.stream, coverage.generation);
|
|
1668
|
+
const known = this.coverage.get(key);
|
|
1669
|
+
if (!known || coverage.registryVersion >= known.registryVersion)
|
|
1670
|
+
this.coverage.set(key, Object.freeze({ ...coverage }));
|
|
1671
|
+
for (const runId of await this.runIds()) {
|
|
1672
|
+
const host = await this.readEntry(runId);
|
|
1673
|
+
if (!host ||
|
|
1674
|
+
host.entry.connector !== coverage.connector ||
|
|
1675
|
+
host.entry.ns === null ||
|
|
1676
|
+
host.entry.ns !== coverage.ns ||
|
|
1677
|
+
host.generation == null ||
|
|
1678
|
+
host.generation !== coverage.generation ||
|
|
1679
|
+
this.inconsistentReceipt(host) ||
|
|
1680
|
+
!host.binding ||
|
|
1681
|
+
host.binding.owner.toLowerCase() !== binding.owner.toLowerCase() ||
|
|
1682
|
+
host.binding.keyCheck !== binding.keyCheck)
|
|
1683
|
+
continue;
|
|
1684
|
+
await this.reclaimLocked(host);
|
|
1685
|
+
}
|
|
1686
|
+
});
|
|
1687
|
+
}
|
|
1688
|
+
// --------------------------------------------------------------- merge
|
|
1689
|
+
async loadHead(scope, dataHash, expected) {
|
|
1690
|
+
const name = `h-${dataHash.toLowerCase().replace(/^0x/, "")}`;
|
|
1691
|
+
const cipher = await this.options.blobs.get(`${scope}/${name}`);
|
|
1692
|
+
if (!cipher)
|
|
1693
|
+
throw new PendingStream("base_unreadable", `head ${name} is missing`);
|
|
1694
|
+
let clear;
|
|
1695
|
+
try {
|
|
1696
|
+
clear = await this.options.keys.decrypt(scope, cipher);
|
|
1697
|
+
}
|
|
1698
|
+
catch {
|
|
1699
|
+
throw new PendingStream("key_mismatch", `head ${name} does not decrypt`);
|
|
1700
|
+
}
|
|
1701
|
+
const verified = await verifyHead(this.hashes.keccak256, clear, {
|
|
1702
|
+
dataHash,
|
|
1703
|
+
...expected,
|
|
1704
|
+
});
|
|
1705
|
+
switch (verified.kind) {
|
|
1706
|
+
case "ok":
|
|
1707
|
+
return verified.head;
|
|
1708
|
+
case "key_mismatch":
|
|
1709
|
+
throw new PendingStream("key_mismatch", `head ${name} has another keyCheck`);
|
|
1710
|
+
case "unsupported_format":
|
|
1711
|
+
throw new PendingStream("unsupported_format", `head ${name} format ${String(verified.format)}`);
|
|
1712
|
+
default:
|
|
1713
|
+
throw new PendingStream("base_unreadable", `head ${name}: ${verified.kind}`);
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
/**
|
|
1717
|
+
* §2.6: plan buckets with the package planner, reduce each with the
|
|
1718
|
+
* package reducer (base lines first, then seed lines, then run lines),
|
|
1719
|
+
* encode and upload the parts. Buckets under one shard are reduced in
|
|
1720
|
+
* groups that share one pass over the shard file.
|
|
1721
|
+
*/
|
|
1722
|
+
async buildParts(host, name, scope, target, base) {
|
|
1723
|
+
const stream = host.streams[name];
|
|
1724
|
+
const runDir = `runs/${host.entry.runId}/spool/s${stream.index}`;
|
|
1725
|
+
const seedDir = `runs/${host.entry.runId}/seed/s${stream.index}`;
|
|
1726
|
+
const runBytes = await this.readyShards(runDir, stream.shardBytes ?? emptyShardBytes());
|
|
1727
|
+
const seedBytes = stream.seedShardBytes
|
|
1728
|
+
? await this.readyShards(seedDir, stream.seedShardBytes)
|
|
1729
|
+
: emptyShardBytes();
|
|
1730
|
+
const shardBytes = runBytes.map((b, i) => b + seedBytes[i]);
|
|
1731
|
+
const baseParts = base?.parts ?? [];
|
|
1732
|
+
let plan = planBuckets({
|
|
1733
|
+
targetBytes: this.targetBytes,
|
|
1734
|
+
baseParts,
|
|
1735
|
+
shardBytes,
|
|
1736
|
+
});
|
|
1737
|
+
if (plan.kind === "needs_counts") {
|
|
1738
|
+
const counts = {};
|
|
1739
|
+
for (const shard of plan.shards) {
|
|
1740
|
+
counts[shard] = await countShard(this.options.home.files, [
|
|
1741
|
+
shardPath(runDir, shard),
|
|
1742
|
+
shardPath(seedDir, shard),
|
|
1743
|
+
]);
|
|
1744
|
+
}
|
|
1745
|
+
plan = planBuckets({
|
|
1746
|
+
targetBytes: this.targetBytes,
|
|
1747
|
+
baseParts,
|
|
1748
|
+
shardBytes,
|
|
1749
|
+
prefix16Bytes: counts,
|
|
1750
|
+
});
|
|
1751
|
+
if (plan.kind !== "plan")
|
|
1752
|
+
throw new Error("planner asked for counts twice");
|
|
1753
|
+
}
|
|
1754
|
+
const groups = [];
|
|
1755
|
+
let group = [];
|
|
1756
|
+
let groupShard = -1;
|
|
1757
|
+
let groupBytes = 0;
|
|
1758
|
+
for (const bucket of plan.buckets) {
|
|
1759
|
+
const deep = bucket.prefix.length > 8;
|
|
1760
|
+
const shard = deep ? parseInt(bucket.prefix.slice(0, 8), 2) : -1;
|
|
1761
|
+
if (group.length > 0 &&
|
|
1762
|
+
(!deep ||
|
|
1763
|
+
shard !== groupShard ||
|
|
1764
|
+
groupBytes + bucket.estimate > this.reduceBudget)) {
|
|
1765
|
+
groups.push(group);
|
|
1766
|
+
group = [];
|
|
1767
|
+
groupBytes = 0;
|
|
1768
|
+
}
|
|
1769
|
+
group.push(bucket.prefix);
|
|
1770
|
+
groupShard = shard;
|
|
1771
|
+
groupBytes += bucket.estimate;
|
|
1772
|
+
if (!deep) {
|
|
1773
|
+
groups.push(group);
|
|
1774
|
+
group = [];
|
|
1775
|
+
groupBytes = 0;
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
if (group.length > 0)
|
|
1779
|
+
groups.push(group);
|
|
1780
|
+
const baseByHash = new Set(baseParts.map((p) => `${p.prefix}:${p.hash}`));
|
|
1781
|
+
const parts = [];
|
|
1782
|
+
while (groups.length > 0) {
|
|
1783
|
+
const prefixes = groups.shift();
|
|
1784
|
+
const results = await this.reduceGroup(prefixes, stream.primaryKey, scope, target, baseParts, [runDir, seedDir]);
|
|
1785
|
+
for (const result of results) {
|
|
1786
|
+
if (result.kind === "split") {
|
|
1787
|
+
groups.unshift([`${result.prefix}0`, `${result.prefix}1`]);
|
|
1788
|
+
continue;
|
|
1789
|
+
}
|
|
1790
|
+
if (result.kind === "bucket_too_large") {
|
|
1791
|
+
throw new PendingStream("bucket_too_large", `bucket ${result.prefix} holds ${result.bytes} bytes of winners`);
|
|
1792
|
+
}
|
|
1793
|
+
const encoded = await encodePart(this.hashes.sha256, result);
|
|
1794
|
+
if (!encoded)
|
|
1795
|
+
continue;
|
|
1796
|
+
if (!baseByHash.has(`${encoded.entry.prefix}:${encoded.entry.hash}`)) {
|
|
1797
|
+
const cipher = await this.options.keys.encrypt(scope, encoded.data);
|
|
1798
|
+
await this.options.blobs.put(`${scope}/${partBlobName(target, encoded.entry.hash)}`, cipher);
|
|
1799
|
+
}
|
|
1800
|
+
parts.push(encoded.entry);
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
this.fault("after_parts_upload", host.entry.runId, name);
|
|
1804
|
+
parts.sort((a, b) => a.prefix < b.prefix ? -1 : a.prefix > b.prefix ? 1 : 0);
|
|
1805
|
+
return { parts };
|
|
1806
|
+
}
|
|
1807
|
+
async reduceGroup(prefixes, primaryKey, scope, target, baseParts, dirs) {
|
|
1808
|
+
const reducers = new Map(prefixes.map((p) => [p, new BucketReducer(p)]));
|
|
1809
|
+
const single = prefixes.length === 1 ? reducers.get(prefixes[0]) : null;
|
|
1810
|
+
const route = (hash) => {
|
|
1811
|
+
if (single)
|
|
1812
|
+
return inPrefix(hash, single.prefix) ? single : null;
|
|
1813
|
+
const bits = pkHashBits(hash, 16);
|
|
1814
|
+
for (const p of prefixes) {
|
|
1815
|
+
if (bits.startsWith(p))
|
|
1816
|
+
return reducers.get(p);
|
|
1817
|
+
}
|
|
1818
|
+
return null;
|
|
1819
|
+
};
|
|
1820
|
+
const parts = new Map();
|
|
1821
|
+
for (const p of prefixes) {
|
|
1822
|
+
for (const part of basePartsFor(p, baseParts))
|
|
1823
|
+
parts.set(part.hash, part);
|
|
1824
|
+
}
|
|
1825
|
+
for (const part of parts.values()) {
|
|
1826
|
+
const key = `${scope}/${partBlobName(target, part.hash)}`;
|
|
1827
|
+
const cipher = await this.options.blobs.get(key);
|
|
1828
|
+
if (!cipher)
|
|
1829
|
+
throw new PendingStream("base_unreadable", `part ${key} is missing`);
|
|
1830
|
+
const clear = await this.options.keys.decrypt(scope, cipher);
|
|
1831
|
+
const lines = await decodePart(this.hashes.sha256, clear, part, primaryKey);
|
|
1832
|
+
for (const { line, text } of lines) {
|
|
1833
|
+
const hash = await pkHash(this.hashes.sha256, line.v, primaryKey);
|
|
1834
|
+
route(hash)?.add(hash, line, text);
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
1837
|
+
const shards = new Set();
|
|
1838
|
+
for (const p of prefixes) {
|
|
1839
|
+
if (p.length >= 8)
|
|
1840
|
+
shards.add(parseInt(p.slice(0, 8), 2));
|
|
1841
|
+
else {
|
|
1842
|
+
const span = 1 << (8 - p.length);
|
|
1843
|
+
const from = p === "" ? 0 : parseInt(p, 2) * span;
|
|
1844
|
+
for (let s = from; s < from + span; s += 1)
|
|
1845
|
+
shards.add(s);
|
|
1846
|
+
}
|
|
1847
|
+
}
|
|
1848
|
+
// Seed lines before run lines: on equal stamps the later line wins.
|
|
1849
|
+
for (const dir of [...dirs].reverse()) {
|
|
1850
|
+
for (const shard of [...shards].sort((a, b) => a - b)) {
|
|
1851
|
+
for await (const line of readSpool(this.options.home.files, shardPath(dir, shard))) {
|
|
1852
|
+
route(line.pkHash)?.add(line.pkHash, lineStamp(line.text), line.text);
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
return prefixes.map((p) => reducers.get(p).finish());
|
|
1857
|
+
}
|
|
1858
|
+
// -------------------------------------------------------------- status
|
|
1859
|
+
statusOf(host) {
|
|
1860
|
+
const streams = {};
|
|
1861
|
+
for (const [name, outbox] of Object.entries(host.entry.streams)) {
|
|
1862
|
+
const info = host.streams[name];
|
|
1863
|
+
streams[name] = {
|
|
1864
|
+
state: outbox.state,
|
|
1865
|
+
...(outbox.generation !== undefined
|
|
1866
|
+
? { generation: outbox.generation }
|
|
1867
|
+
: {}),
|
|
1868
|
+
...(outbox.complete !== undefined ? { complete: outbox.complete } : {}),
|
|
1869
|
+
problem: info?.problem ?? null,
|
|
1870
|
+
detail: info?.detail ?? null,
|
|
1871
|
+
recordTooLarge: info?.recordTooLarge ?? 0,
|
|
1872
|
+
};
|
|
1873
|
+
}
|
|
1874
|
+
return {
|
|
1875
|
+
runId: host.entry.runId,
|
|
1876
|
+
connector: host.entry.connector,
|
|
1877
|
+
ns: host.entry.ns,
|
|
1878
|
+
phase: host.phase,
|
|
1879
|
+
target: host.target,
|
|
1880
|
+
outcome: host.outcome,
|
|
1881
|
+
streams,
|
|
1882
|
+
};
|
|
1883
|
+
}
|
|
1884
|
+
/** Every run still in the outbox, and the results of finished runs. */
|
|
1885
|
+
async status() {
|
|
1886
|
+
const pending = [];
|
|
1887
|
+
for (const runId of await this.runIds()) {
|
|
1888
|
+
const host = await this.readEntry(runId);
|
|
1889
|
+
if (host && host.phase !== "done")
|
|
1890
|
+
pending.push(this.statusOf(host));
|
|
1891
|
+
}
|
|
1892
|
+
const finished = [];
|
|
1893
|
+
for (const path of await this.options.home.files.list("results")) {
|
|
1894
|
+
const bytes = await this.options.home.files.read(path);
|
|
1895
|
+
if (bytes)
|
|
1896
|
+
finished.push(JSON.parse(decoder.decode(bytes)));
|
|
1897
|
+
}
|
|
1898
|
+
const state = await this.readState();
|
|
1899
|
+
return {
|
|
1900
|
+
pending,
|
|
1901
|
+
finished,
|
|
1902
|
+
needsFull: state.needsFull,
|
|
1903
|
+
checkpoints: state.checkpoints,
|
|
1904
|
+
receipts: state.receipts,
|
|
1905
|
+
};
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
function mergeCursors(prev, candidate) {
|
|
1909
|
+
if (candidate === null)
|
|
1910
|
+
return prev;
|
|
1911
|
+
if (isPlainObject(prev) && isPlainObject(candidate)) {
|
|
1912
|
+
return { ...prev, ...candidate };
|
|
1913
|
+
}
|
|
1914
|
+
return candidate;
|
|
1915
|
+
}
|
|
1916
|
+
function nextIndex(host) {
|
|
1917
|
+
return Object.values(host.streams).reduce((n, v) => Math.max(n, v.index + 1), 0);
|
|
1918
|
+
}
|
|
1919
|
+
function parseHeadKey(request) {
|
|
1920
|
+
return `${request.scope}/h-${request.dataHash.slice(2).toLowerCase()}`;
|
|
1921
|
+
}
|
|
1922
|
+
/** Control rows are ordered by registry version; an absent row ranks 0. */
|
|
1923
|
+
function controlRank(state) {
|
|
1924
|
+
switch (state.kind) {
|
|
1925
|
+
case "absent":
|
|
1926
|
+
return 0;
|
|
1927
|
+
case "active":
|
|
1928
|
+
return state.generation;
|
|
1929
|
+
case "deleted":
|
|
1930
|
+
case "foreign":
|
|
1931
|
+
return state.version;
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
/**
|
|
1935
|
+
* Apply one control read to the state and return the newest control state
|
|
1936
|
+
* known. Ordering rule: within a (connector, namespace) a read ranks by row
|
|
1937
|
+
* version and the watermark only moves forward; another namespace never
|
|
1938
|
+
* changes it. A read older than the watermark is a
|
|
1939
|
+
* late response: it changes nothing and the stored newer state is returned,
|
|
1940
|
+
* so it can neither clear a checkpoint, overwrite a newer observation nor
|
|
1941
|
+
* authorize a decision. A newer read is an invalidation: it advances the
|
|
1942
|
+
* count whether or not a checkpoint is stored.
|
|
1943
|
+
* A read that shows a stored checkpoint's generation is gone (a higher row,
|
|
1944
|
+
* or the same row no longer active) also clears that checkpoint (§2.4).
|
|
1945
|
+
*/
|
|
1946
|
+
function recordControl(state, connector, ns, current) {
|
|
1947
|
+
const marks = ((state.observedControl ??= {})[connector] ??= {});
|
|
1948
|
+
const rank = controlRank(current);
|
|
1949
|
+
const prev = marks[ns];
|
|
1950
|
+
if (prev !== undefined && rank < controlRank(prev))
|
|
1951
|
+
return prev;
|
|
1952
|
+
const moved = prev !== undefined && rank > controlRank(prev);
|
|
1953
|
+
marks[ns] = current;
|
|
1954
|
+
const checkpoint = state.checkpoints[connector];
|
|
1955
|
+
// A read ranked below the checkpoint's generation is a lagging response.
|
|
1956
|
+
const stale = checkpoint !== undefined &&
|
|
1957
|
+
checkpoint.ns === ns &&
|
|
1958
|
+
(rank > checkpoint.generation ||
|
|
1959
|
+
(rank === checkpoint.generation && current.kind !== "active"));
|
|
1960
|
+
if (stale || moved)
|
|
1961
|
+
invalidateCheckpoint(state, connector, stale);
|
|
1962
|
+
return current;
|
|
1963
|
+
}
|
|
1964
|
+
/**
|
|
1965
|
+
* The one place a checkpoint is invalidated: advance the connector's
|
|
1966
|
+
* invalidation count in the same state mutation as the clear, so a save that
|
|
1967
|
+
* read control earlier cannot restore what was cleared. The count advances
|
|
1968
|
+
* even when `clear` is false or the slot is already empty.
|
|
1969
|
+
*/
|
|
1970
|
+
function invalidateCheckpoint(state, connector, clear) {
|
|
1971
|
+
if (clear)
|
|
1972
|
+
delete state.checkpoints[connector];
|
|
1973
|
+
const epochs = (state.invalidations ??= {});
|
|
1974
|
+
epochs[connector] = (epochs[connector] ?? 0) + 1;
|
|
1975
|
+
}
|
|
1976
|
+
function describe(state) {
|
|
1977
|
+
switch (state.kind) {
|
|
1978
|
+
case "absent":
|
|
1979
|
+
return "absent";
|
|
1980
|
+
case "active":
|
|
1981
|
+
return `active(${state.generation})`;
|
|
1982
|
+
case "deleted":
|
|
1983
|
+
return `deleted(${state.version})`;
|
|
1984
|
+
case "foreign":
|
|
1985
|
+
return `foreign(${state.version})`;
|
|
1986
|
+
}
|
|
1987
|
+
}
|
|
1988
|
+
/** A persisted watermark is verified provenance; an arbitrary checkpoint is not. */
|
|
1989
|
+
function verifiedGeneration(state, connector) {
|
|
1990
|
+
const control = state.observedControl?.[connector]?.[IDENTITYLESS_NS];
|
|
1991
|
+
return control?.kind === "active" ? control.generation : null;
|
|
1992
|
+
}
|
|
1993
|
+
export { createWriterOverlaySource } from "./writer-overlay.js";
|
|
1994
|
+
//# sourceMappingURL=writer.js.map
|