@abloatai/ablo 0.34.1 → 0.35.0
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/AGENTS.md +2 -1
- package/CHANGELOG.md +674 -5
- package/README.md +39 -22
- package/dist/BaseSyncedStore.d.ts +152 -44
- package/dist/BaseSyncedStore.js +300 -184
- package/dist/Database.d.ts +9 -24
- package/dist/Database.js +37 -22
- package/dist/InstanceCache.d.ts +25 -4
- package/dist/InstanceCache.js +48 -15
- package/dist/LazyReferenceCollection.d.ts +3 -3
- package/dist/LazyReferenceCollection.js +4 -4
- package/dist/Model.d.ts +6 -6
- package/dist/Model.js +10 -10
- package/dist/ModelRegistry.d.ts +4 -4
- package/dist/ModelRegistry.js +3 -3
- package/dist/{SyncEngineContext.d.ts → RuntimeContext.d.ts} +20 -13
- package/dist/{SyncEngineContext.js → RuntimeContext.js} +11 -12
- package/dist/SyncClient.d.ts +42 -32
- package/dist/SyncClient.js +166 -110
- package/dist/ai-sdk/coordinatedTool.d.ts +2 -2
- package/dist/ai-sdk/coordinatedTool.js +1 -1
- package/dist/ai-sdk/coordinationContext.d.ts +2 -2
- package/dist/ai-sdk/coordinationContext.js +1 -1
- package/dist/ai-sdk/wrap.d.ts +3 -3
- package/dist/ai-sdk/wrap.js +2 -2
- package/dist/auth/index.d.ts +1 -156
- package/dist/auth/index.js +8 -301
- package/dist/cli.cjs +3344 -1073
- package/dist/client/Ablo.d.ts +42 -287
- package/dist/client/Ablo.js +118 -963
- package/dist/client/abloClient.d.ts +309 -0
- package/dist/client/abloClient.js +13 -0
- package/dist/client/clientPrelude.d.ts +52 -0
- package/dist/client/clientPrelude.js +60 -0
- package/dist/client/consoleLogger.d.ts +2 -2
- package/dist/client/coreClient.d.ts +60 -0
- package/dist/client/coreClient.js +118 -0
- package/dist/client/createInternalComponents.d.ts +4 -4
- package/dist/client/createInternalComponents.js +9 -8
- package/dist/client/createModelProxy.d.ts +78 -373
- package/dist/client/createModelProxy.js +114 -86
- package/dist/client/humans.d.ts +48 -0
- package/dist/client/humans.js +52 -0
- package/dist/client/modelRegistration.d.ts +1 -1
- package/dist/client/modelRegistration.js +9 -9
- package/dist/client/options.d.ts +73 -17
- package/dist/client/reactiveEngine.d.ts +48 -0
- package/dist/client/reactiveEngine.js +910 -0
- package/dist/client/resourceTypes.d.ts +9 -250
- package/dist/client/resourceTypes.js +8 -5
- package/dist/client/schemaConfig.d.ts +4 -4
- package/dist/client/schemaConfig.js +6 -2
- package/dist/client/validateAbloOptions.d.ts +3 -2
- package/dist/client/validateAbloOptions.js +1 -1
- package/dist/client/wsMutationExecutor.d.ts +3 -3
- package/dist/client/wsMutationExecutor.js +3 -3
- package/dist/context.d.ts +9 -9
- package/dist/context.js +10 -9
- package/dist/coordination/ClaimLog.d.ts +26 -0
- package/dist/coordination/ClaimLog.js +32 -0
- package/dist/coordination/index.d.ts +1 -15
- package/dist/coordination/index.js +8 -31
- package/dist/core/DatabaseManager.js +1 -1
- package/dist/core/QueryView.d.ts +1 -1
- package/dist/core/QueryView.js +1 -1
- package/dist/core/StoreManager.d.ts +4 -23
- package/dist/core/StoreManager.js +5 -55
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js +2 -2
- package/dist/core/storeContract.d.ts +2 -2
- package/dist/docs/catalog.d.ts +72 -0
- package/dist/docs/catalog.js +227 -0
- package/dist/docs/index.d.ts +10 -0
- package/dist/docs/index.js +10 -0
- package/dist/environment.d.ts +1 -40
- package/dist/environment.js +8 -37
- package/dist/index.d.ts +40 -34
- package/dist/index.js +26 -20
- package/dist/interfaces/index.d.ts +44 -134
- package/dist/keys/index.d.ts +1 -77
- package/dist/keys/index.js +8 -190
- package/dist/mutators/{RecordingTransaction.d.ts → RecordingMutation.d.ts} +4 -4
- package/dist/mutators/{RecordingTransaction.js → RecordingMutation.js} +2 -2
- package/dist/mutators/Transaction.d.ts +1 -1
- package/dist/mutators/Transaction.js +1 -1
- package/dist/mutators/UndoManager.d.ts +6 -6
- package/dist/mutators/UndoManager.js +5 -5
- package/dist/mutators/defineMutators.d.ts +3 -3
- package/dist/mutators/defineMutators.js +1 -1
- package/dist/mutators/inverseOp.js +2 -2
- package/dist/mutators/mutateActions.d.ts +3 -3
- package/dist/mutators/mutateActions.js +1 -1
- package/dist/mutators/readerActions.d.ts +1 -1
- package/dist/mutators/undoApply.d.ts +1 -1
- package/dist/mutators/undoApply.js +1 -1
- package/dist/policy/index.d.ts +2 -2
- package/dist/policy/index.js +1 -1
- package/dist/query/client.d.ts +2 -2
- package/dist/query/client.js +4 -4
- package/dist/query/types.d.ts +6 -41
- package/dist/query/types.js +2 -2
- package/dist/react/AbloProvider.d.ts +6 -8
- package/dist/react/AbloProvider.js +5 -7
- package/dist/react/context.d.ts +1 -1
- package/dist/react/context.js +1 -1
- package/dist/react/index.d.ts +5 -5
- package/dist/react/index.js +3 -3
- package/dist/react/internalContext.d.ts +1 -1
- package/dist/react/useAblo.d.ts +3 -3
- package/dist/react/useAblo.js +1 -1
- package/dist/react/useCurrentUserId.js +1 -1
- package/dist/react/useErrorListener.js +1 -1
- package/dist/react/useMutationFailureListener.d.ts +2 -2
- package/dist/react/useMutationFailureListener.js +1 -1
- package/dist/react/useMutators.d.ts +3 -3
- package/dist/react/useMutators.js +3 -3
- package/dist/react/useUndoScope.d.ts +5 -5
- package/dist/react/useUndoScope.js +1 -1
- package/dist/schema/coordination.d.ts +69 -10
- package/dist/schema/coordination.js +86 -9
- package/dist/schema/ddl.js +2 -2
- package/dist/schema/diff.d.ts +1 -1
- package/dist/schema/generate.js +1 -1
- package/dist/schema/index.d.ts +10 -10
- package/dist/schema/index.js +18 -18
- package/dist/schema/queries.d.ts +27 -27
- package/dist/schema/queries.js +23 -23
- package/dist/schema/select.d.ts +3 -3
- package/dist/schema/select.js +3 -3
- package/dist/schema/serialize.d.ts +15 -6
- package/dist/schema/serialize.js +17 -3
- package/dist/schema/sugar.d.ts +6 -7
- package/dist/schema/sugar.js +9 -12
- package/dist/schema/syncDeltaRow.d.ts +4 -152
- package/dist/schema/syncDeltaRow.js +4 -105
- package/dist/server/adapter.d.ts +18 -1
- package/dist/server/commit.d.ts +10 -16
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/readConfig.d.ts +1 -1
- package/dist/source/adapters/drizzle.d.ts +1 -1
- package/dist/source/adapters/drizzle.js +2 -2
- package/dist/source/adapters/kysely.d.ts +1 -1
- package/dist/source/adapters/kysely.js +1 -1
- package/dist/source/adapters/kyselyMutationCore.d.ts +1 -1
- package/dist/source/adapters/kyselyMutationCore.js +2 -2
- package/dist/source/adapters/memory.js +1 -1
- package/dist/source/adapters/prisma.d.ts +8 -3
- package/dist/source/adapters/prisma.js +1 -1
- package/dist/source/connector.js +1 -1
- package/dist/source/connectorProtocol.d.ts +2 -8
- package/dist/source/connectorProtocol.js +3 -2
- package/dist/source/contract.d.ts +29 -17
- package/dist/source/contract.js +27 -22
- package/dist/source/factory.d.ts +1 -1
- package/dist/source/footprint.d.ts +111 -0
- package/dist/source/footprint.js +0 -0
- package/dist/source/idempotency.js +2 -2
- package/dist/source/index.d.ts +1 -0
- package/dist/source/index.js +3 -0
- package/dist/source/next.d.ts +1 -1
- package/dist/source/signing.d.ts +9 -2
- package/dist/source/signing.js +4 -1
- package/dist/source/types.d.ts +6 -4
- package/dist/source/types.js +1 -1
- package/dist/stores/ObjectStore.d.ts +1 -1
- package/dist/stores/SyncActionStore.d.ts +1 -1
- package/dist/stores/SyncActionStore.js +2 -10
- package/dist/stores/syncAction.d.ts +26 -0
- package/dist/stores/syncAction.js +16 -0
- package/dist/surface.d.ts +3 -3
- package/dist/surface.js +6 -4
- package/dist/sync/BootstrapFetcher.d.ts +123 -6
- package/dist/sync/BootstrapFetcher.js +492 -66
- package/dist/sync/ConnectionManager.d.ts +6 -198
- package/dist/sync/ConnectionManager.js +6 -677
- package/dist/sync/OnDemandLoader.d.ts +2 -2
- package/dist/sync/OnDemandLoader.js +60 -21
- package/dist/sync/SubscriptionManager.d.ts +13 -2
- package/dist/sync/SubscriptionManager.js +23 -5
- package/dist/sync/SyncWebSocket.d.ts +27 -510
- package/dist/sync/SyncWebSocket.js +76 -954
- package/dist/sync/awaitClaimGrant.d.ts +4 -44
- package/dist/sync/awaitClaimGrant.js +4 -109
- package/dist/sync/commitFrames.d.ts +6 -40
- package/dist/sync/commitFrames.js +6 -97
- package/dist/sync/contextPorts.d.ts +18 -0
- package/dist/sync/contextPorts.js +31 -0
- package/dist/sync/createClaimStream.d.ts +5 -49
- package/dist/sync/createClaimStream.js +5 -469
- package/dist/sync/createPresenceStream.d.ts +26 -4
- package/dist/sync/createPresenceStream.js +28 -20
- package/dist/sync/createSnapshot.d.ts +2 -2
- package/dist/sync/createSnapshot.js +1 -1
- package/dist/sync/credentialLifecycle.d.ts +5 -173
- package/dist/sync/credentialLifecycle.js +5 -320
- package/dist/sync/deltaPipeline.d.ts +1 -1
- package/dist/sync/participants.d.ts +5 -4
- package/dist/sync/participants.js +29 -22
- package/dist/sync/schemaDrift.d.ts +55 -0
- package/dist/sync/schemaDrift.js +53 -0
- package/dist/sync/schemas.d.ts +21 -32
- package/dist/sync/schemas.js +26 -17
- package/dist/sync/syncPlan.d.ts +3 -3
- package/dist/sync/wsFrameHandlers.d.ts +6 -114
- package/dist/sync/wsFrameHandlers.js +6 -392
- package/dist/testing/fixtures/bootstrap.d.ts +1 -1
- package/dist/testing/fixtures/deltas.d.ts +1 -1
- package/dist/testing/fixtures/httpResponses.d.ts +70 -0
- package/dist/testing/fixtures/httpResponses.js +90 -0
- package/dist/testing/fixtures/models.js +1 -1
- package/dist/testing/helpers/wait.js +1 -1
- package/dist/testing/mocks/MockMutationExecutor.d.ts +2 -2
- package/dist/testing/mocks/MockMutationExecutor.js +8 -14
- package/dist/testing/mocks/MockSyncContext.d.ts +11 -11
- package/dist/testing/mocks/MockSyncContext.js +10 -9
- package/dist/testing/mocks/MockSyncStore.js +1 -1
- package/dist/testing/mocks/MockWebSocket.d.ts +2 -2
- package/dist/transaction/ablo.d.ts +88 -0
- package/dist/transaction/ablo.js +33 -0
- package/dist/{client/auth.d.ts → transaction/auth/apiKey.d.ts} +43 -8
- package/dist/{client/auth.js → transaction/auth/apiKey.js} +19 -0
- package/dist/transaction/auth/bootstrapScope.d.ts +15 -0
- package/dist/transaction/auth/bootstrapScope.js +1 -0
- package/dist/transaction/auth/capability.d.ts +177 -0
- package/dist/transaction/auth/capability.js +199 -0
- package/dist/{auth → transaction/auth}/credentialSource.d.ts +8 -1
- package/dist/{client → transaction/auth}/identity.d.ts +8 -7
- package/dist/{client → transaction/auth}/identity.js +1 -1
- package/dist/transaction/auth/index.d.ts +162 -0
- package/dist/transaction/auth/index.js +304 -0
- package/dist/{auth → transaction/auth}/schemas.d.ts +1 -1
- package/dist/{auth → transaction/auth}/schemas.js +13 -13
- package/dist/{client → transaction/auth}/sessionMint.d.ts +8 -8
- package/dist/{client → transaction/auth}/sessionMint.js +4 -7
- package/dist/transaction/coordination/awaitClaimGrant.d.ts +49 -0
- package/dist/transaction/coordination/awaitClaimGrant.js +112 -0
- package/dist/transaction/coordination/claimMeta.d.ts +49 -0
- package/dist/transaction/coordination/claimMeta.js +52 -0
- package/dist/transaction/coordination/createClaimStream.d.ts +64 -0
- package/dist/transaction/coordination/createClaimStream.js +475 -0
- package/dist/transaction/coordination/events.d.ts +74 -0
- package/dist/transaction/coordination/events.js +7 -0
- package/dist/transaction/coordination/index.d.ts +19 -0
- package/dist/transaction/coordination/index.js +44 -0
- package/dist/transaction/coordination/locator.d.ts +83 -0
- package/dist/transaction/coordination/locator.js +82 -0
- package/dist/transaction/coordination/schema.d.ts +1473 -0
- package/dist/{coordination → transaction/coordination}/schema.js +490 -55
- package/dist/transaction/coordination/targetConflict.d.ts +2 -0
- package/dist/transaction/coordination/targetConflict.js +103 -0
- package/dist/{coordination → transaction/coordination}/trace.d.ts +7 -18
- package/dist/{coordination → transaction/coordination}/trace.js +18 -25
- package/dist/transaction/durableWrites.d.ts +62 -0
- package/dist/{client → transaction}/durableWrites.js +28 -3
- package/dist/transaction/environment.d.ts +105 -0
- package/dist/transaction/environment.js +108 -0
- package/dist/{errorCodes.d.ts → transaction/errorCodes.d.ts} +11 -11
- package/dist/{errorCodes.js → transaction/errorCodes.js} +35 -12
- package/dist/{errors.d.ts → transaction/errors.d.ts} +37 -13
- package/dist/{errors.js → transaction/errors.js} +85 -16
- package/dist/transaction/index.d.ts +20 -0
- package/dist/transaction/index.js +20 -0
- package/dist/transaction/keys/index.d.ts +87 -0
- package/dist/transaction/keys/index.js +207 -0
- package/dist/transaction/log/syncDeltaRow.d.ts +158 -0
- package/dist/transaction/log/syncDeltaRow.js +95 -0
- package/dist/{sync/syncPosition.d.ts → transaction/logPosition.d.ts} +22 -8
- package/dist/{sync/syncPosition.js → transaction/logPosition.js} +15 -6
- package/dist/transaction/logger.d.ts +16 -0
- package/dist/transaction/logger.js +7 -0
- package/dist/transaction/observability.d.ts +53 -0
- package/dist/transaction/observability.js +19 -0
- package/dist/transaction/plugin.d.ts +192 -0
- package/dist/transaction/plugin.js +87 -0
- package/dist/{policy → transaction/policy}/types.d.ts +3 -3
- package/dist/{policy → transaction/policy}/types.js +2 -0
- package/dist/transaction/resources/httpResources.d.ts +266 -0
- package/dist/transaction/resources/httpResources.js +7 -0
- package/dist/transaction/resources/modelOperations.d.ts +319 -0
- package/dist/transaction/resources/modelOperations.js +12 -0
- package/dist/transaction/resources/mutationOptions.d.ts +66 -0
- package/dist/transaction/resources/mutationOptions.js +9 -0
- package/dist/transaction/resources/where.d.ts +85 -0
- package/dist/transaction/resources/where.js +70 -0
- package/dist/{client → transaction/resources}/writeOptionsSchema.d.ts +2 -6
- package/dist/{client → transaction/resources}/writeOptionsSchema.js +9 -5
- package/dist/{schema → transaction/schema}/field.d.ts +5 -5
- package/dist/{schema → transaction/schema}/field.js +5 -5
- package/dist/transaction/schema/loadStrategy.d.ts +45 -0
- package/dist/transaction/schema/loadStrategy.js +46 -0
- package/dist/{schema → transaction/schema}/model.d.ts +50 -35
- package/dist/{schema → transaction/schema}/model.js +30 -20
- package/dist/transaction/schema/openapi.d.ts +57 -0
- package/dist/transaction/schema/openapi.js +340 -0
- package/dist/{schema → transaction/schema}/relation.d.ts +14 -14
- package/dist/{schema → transaction/schema}/relation.js +7 -7
- package/dist/{schema → transaction/schema}/residency.d.ts +0 -9
- package/dist/{schema → transaction/schema}/residency.js +0 -5
- package/dist/{schema → transaction/schema}/roles.d.ts +5 -5
- package/dist/{schema → transaction/schema}/roles.js +5 -5
- package/dist/{schema → transaction/schema}/schema.d.ts +12 -10
- package/dist/{schema → transaction/schema}/schema.js +4 -3
- package/dist/{schema → transaction/schema}/tenancy.d.ts +1 -1
- package/dist/{schema → transaction/schema}/tenancy.js +7 -4
- package/dist/transaction/transactionLayer.d.ts +82 -0
- package/dist/transaction/transactionLayer.js +24 -0
- package/dist/{transactions → transaction/transactions/settlement}/commitEnvelope.d.ts +4 -5
- package/dist/{transactions → transaction/transactions/settlement}/commitEnvelope.js +9 -13
- package/dist/{transactions → transaction/transactions/settlement}/httpCommitEnvelope.d.ts +9 -2
- package/dist/{transactions → transaction/transactions/settlement}/httpCommitEnvelope.js +5 -9
- package/dist/{transactions/durableWriteStore.d.ts → transaction/transactions/settlement/pendingWrite.d.ts} +10 -36
- package/dist/transaction/transactions/settlement/pendingWrite.js +20 -0
- package/dist/transaction/transport/commitFrames.d.ts +90 -0
- package/dist/transaction/transport/commitFrames.js +134 -0
- package/dist/transaction/transport/connectionManager.d.ts +215 -0
- package/dist/transaction/transport/connectionManager.js +673 -0
- package/dist/transaction/transport/credentialLifecycle.d.ts +177 -0
- package/dist/transaction/transport/credentialLifecycle.js +324 -0
- package/dist/{sync → transaction/transport}/heartbeat.d.ts +3 -1
- package/dist/{sync → transaction/transport}/heartbeat.js +6 -4
- package/dist/{client → transaction/transport}/httpClient.d.ts +59 -16
- package/dist/{client → transaction/transport}/httpClient.js +5 -5
- package/dist/transaction/transport/httpOptions.d.ts +33 -0
- package/dist/transaction/transport/httpOptions.js +12 -0
- package/dist/{client → transaction/transport}/httpTransport.js +171 -85
- package/dist/{sync/NetworkProbe.d.ts → transaction/transport/networkProbe.d.ts} +7 -4
- package/dist/{sync/NetworkProbe.js → transaction/transport/networkProbe.js} +14 -13
- package/dist/transaction/transport/wsFrameHandlers.d.ts +128 -0
- package/dist/transaction/transport/wsFrameHandlers.js +429 -0
- package/dist/transaction/transport/wsTransport.d.ts +576 -0
- package/dist/transaction/transport/wsTransport.js +1017 -0
- package/dist/transaction/types/assertExact.d.ts +17 -0
- package/dist/transaction/types/assertExact.js +1 -0
- package/dist/{types → transaction/types}/global.d.ts +17 -2
- package/dist/{types → transaction/types}/global.js +2 -1
- package/dist/{types → transaction/types}/index.d.ts +14 -46
- package/dist/{types → transaction/types}/index.js +7 -16
- package/dist/{types → transaction/types}/streams.d.ts +63 -45
- package/dist/{utils → transaction/utils}/json.d.ts +18 -0
- package/dist/transaction/utils/json.js +276 -0
- package/dist/transaction/wire/accountResponses.d.ts +351 -0
- package/dist/transaction/wire/accountResponses.js +255 -0
- package/dist/transaction/wire/auth.d.ts +49 -0
- package/dist/transaction/wire/auth.js +57 -0
- package/dist/transaction/wire/claimEvent.d.ts +76 -0
- package/dist/transaction/wire/claimEvent.js +73 -0
- package/dist/transaction/wire/claims.d.ts +463 -0
- package/dist/transaction/wire/claims.js +229 -0
- package/dist/{wire → transaction/wire}/commit.d.ts +125 -193
- package/dist/{wire → transaction/wire}/commit.js +68 -47
- package/dist/{wire → transaction/wire}/delta.d.ts +66 -17
- package/dist/{wire → transaction/wire}/delta.js +37 -13
- package/dist/transaction/wire/errorEnvelope.d.ts +72 -0
- package/dist/{wire → transaction/wire}/errorEnvelope.js +36 -5
- package/dist/transaction/wire/feedCursor.d.ts +60 -0
- package/dist/transaction/wire/feedCursor.js +82 -0
- package/dist/transaction/wire/feedEvent.d.ts +177 -0
- package/dist/transaction/wire/feedEvent.js +39 -0
- package/dist/transaction/wire/frames.d.ts +194 -0
- package/dist/transaction/wire/frames.js +50 -0
- package/dist/transaction/wire/inboundFrames.d.ts +552 -0
- package/dist/transaction/wire/inboundFrames.js +116 -0
- package/dist/transaction/wire/index.d.ts +50 -0
- package/dist/transaction/wire/index.js +74 -0
- package/dist/{wire → transaction/wire}/listEnvelope.d.ts +13 -14
- package/dist/transaction/wire/listEnvelope.js +42 -0
- package/dist/transaction/wire/modelResponses.d.ts +85 -0
- package/dist/transaction/wire/modelResponses.js +43 -0
- package/dist/transactions/{TransactionQueue.d.ts → mutations/MutationQueue.d.ts} +79 -38
- package/dist/transactions/{TransactionQueue.js → mutations/MutationQueue.js} +110 -59
- package/dist/transactions/{TransactionStore.d.ts → mutations/MutationStore.d.ts} +8 -8
- package/dist/transactions/{TransactionStore.js → mutations/MutationStore.js} +2 -2
- package/dist/transactions/{coalesceRules.d.ts → mutations/coalesceRules.d.ts} +10 -10
- package/dist/transactions/{coalesceRules.js → mutations/coalesceRules.js} +1 -1
- package/dist/transactions/mutations/commitLatency.d.ts +52 -0
- package/dist/transactions/mutations/commitLatency.js +130 -0
- package/dist/transactions/{commitOutboxStore.d.ts → mutations/commitOutboxStore.d.ts} +1 -5
- package/dist/transactions/{commitOutboxStore.js → mutations/commitOutboxStore.js} +1 -1
- package/dist/transactions/{commitPayload.d.ts → mutations/commitPayload.d.ts} +16 -15
- package/dist/transactions/{commitPayload.js → mutations/commitPayload.js} +12 -12
- package/dist/transactions/{deltaConfirmation.d.ts → mutations/deltaConfirmation.d.ts} +11 -11
- package/dist/transactions/{deltaConfirmation.js → mutations/deltaConfirmation.js} +7 -7
- package/dist/transactions/mutations/durableWriteStore.d.ts +14 -0
- package/dist/transactions/mutations/durableWriteStore.js +12 -0
- package/dist/transactions/{optimisticApply.d.ts → mutations/optimisticApply.d.ts} +7 -7
- package/dist/transactions/{replayValidation.d.ts → mutations/replayValidation.d.ts} +3 -3
- package/dist/transactions/{replayValidation.js → mutations/replayValidation.js} +4 -3
- package/dist/utils/mobxSetup.d.ts +1 -1
- package/dist/utils/mobxSetup.js +5 -2
- package/dist/webhooks/events.d.ts +2 -2
- package/dist/wire/index.d.ts +1 -34
- package/dist/wire/index.js +8 -49
- package/docs/agent-messaging.md +3 -3
- package/docs/agents.md +19 -12
- package/docs/api-keys.md +8 -4
- package/docs/api.md +22 -18
- package/docs/audit.md +2 -0
- package/docs/cli.md +31 -3
- package/docs/client-behavior.md +8 -6
- package/docs/concurrency-convention.md +30 -24
- package/docs/coordination.md +48 -38
- package/docs/data-sources.md +3 -1
- package/docs/debugging.md +5 -3
- package/docs/deployment.md +267 -0
- package/docs/examples/agent-human.md +49 -42
- package/docs/examples/ai-sdk-tool.md +69 -44
- package/docs/examples/existing-python-backend.md +8 -6
- package/docs/examples/nextjs.md +129 -47
- package/docs/examples/scoped-agent.md +45 -44
- package/docs/examples/server-agent.md +46 -26
- package/docs/groups.md +32 -29
- package/docs/guarantees.md +4 -2
- package/docs/how-it-works.md +9 -7
- package/docs/idempotency.md +126 -0
- package/docs/identity.md +58 -54
- package/docs/index.md +172 -86
- package/docs/integration-guide.md +17 -16
- package/docs/interaction-model.md +6 -4
- package/docs/mcp.md +41 -16
- package/docs/migration.md +63 -5
- package/docs/operating-on-your-database.md +3 -1
- package/docs/projects.md +2 -0
- package/docs/quickstart.md +22 -5
- package/docs/react.md +12 -10
- package/docs/schema-contract.md +5 -3
- package/docs/session-settings.md +108 -0
- package/docs/sessions.md +3 -1
- package/docs/webhooks.md +3 -1
- package/llms.txt +47 -17
- package/package.json +10 -8
- package/dist/agent/Agent.d.ts +0 -366
- package/dist/agent/Agent.js +0 -514
- package/dist/agent/index.d.ts +0 -115
- package/dist/agent/index.js +0 -128
- package/dist/agent/session.d.ts +0 -93
- package/dist/agent/session.js +0 -149
- package/dist/agent/types.d.ts +0 -68
- package/dist/agent/types.js +0 -9
- package/dist/client/durableWrites.d.ts +0 -21
- package/dist/coordination/schema.d.ts +0 -722
- package/dist/schema/openapi.d.ts +0 -29
- package/dist/schema/openapi.js +0 -124
- package/dist/transactions/durableWriteStore.js +0 -30
- package/dist/utils/json.js +0 -88
- package/dist/wire/errorEnvelope.d.ts +0 -55
- package/dist/wire/frames.d.ts +0 -197
- package/dist/wire/frames.js +0 -49
- package/dist/wire/listEnvelope.js +0 -18
- /package/dist/{client → transaction/auth}/credentialEndpoint.d.ts +0 -0
- /package/dist/{client → transaction/auth}/credentialEndpoint.js +0 -0
- /package/dist/{auth → transaction/auth}/credentialPolicy.d.ts +0 -0
- /package/dist/{auth → transaction/auth}/credentialPolicy.js +0 -0
- /package/dist/{auth → transaction/auth}/credentialSource.js +0 -0
- /package/dist/{client → transaction/auth}/hostedEndpoints.d.ts +0 -0
- /package/dist/{client → transaction/auth}/hostedEndpoints.js +0 -0
- /package/dist/{client → transaction/coordination}/claimHeartbeatLoop.d.ts +0 -0
- /package/dist/{client → transaction/coordination}/claimHeartbeatLoop.js +0 -0
- /package/dist/{client → transaction}/persistence.d.ts +0 -0
- /package/dist/{client → transaction}/persistence.js +0 -0
- /package/dist/{client → transaction/resources}/functionalUpdate.d.ts +0 -0
- /package/dist/{client → transaction/resources}/functionalUpdate.js +0 -0
- /package/dist/{transactions → transaction/transactions/settlement}/idempotencyKey.d.ts +0 -0
- /package/dist/{transactions → transaction/transactions/settlement}/idempotencyKey.js +0 -0
- /package/dist/{client → transaction/transport}/httpTransport.d.ts +0 -0
- /package/dist/{types → transaction/types}/modelData.d.ts +0 -0
- /package/dist/{types → transaction/types}/modelData.js +0 -0
- /package/dist/{types → transaction/types}/participant.d.ts +0 -0
- /package/dist/{types → transaction/types}/participant.js +0 -0
- /package/dist/{types → transaction/types}/streams.js +0 -0
- /package/dist/{utils → transaction/utils}/asyncIterator.d.ts +0 -0
- /package/dist/{utils → transaction/utils}/asyncIterator.js +0 -0
- /package/dist/{utils → transaction/utils}/duration.d.ts +0 -0
- /package/dist/{utils → transaction/utils}/duration.js +0 -0
- /package/dist/{wire → transaction/wire}/bootstrapReason.d.ts +0 -0
- /package/dist/{wire → transaction/wire}/bootstrapReason.js +0 -0
- /package/dist/{wire → transaction/wire}/protocol.d.ts +0 -0
- /package/dist/{wire → transaction/wire}/protocol.js +0 -0
- /package/dist/{wire → transaction/wire}/protocolVersion.d.ts +0 -0
- /package/dist/{wire → transaction/wire}/protocolVersion.js +0 -0
- /package/dist/transactions/{UnconfirmedWrites.d.ts → mutations/UnconfirmedWrites.d.ts} +0 -0
- /package/dist/transactions/{UnconfirmedWrites.js → mutations/UnconfirmedWrites.js} +0 -0
- /package/dist/transactions/{optimisticApply.js → mutations/optimisticApply.js} +0 -0
|
@@ -63,6 +63,7 @@ export const RESERVED_SESSION_SETTINGS = [
|
|
|
63
63
|
'app.current_sandbox_id',
|
|
64
64
|
'app.current_participant_id',
|
|
65
65
|
'app.current_participant_kind',
|
|
66
|
+
'app.current_user_id',
|
|
66
67
|
];
|
|
67
68
|
/**
|
|
68
69
|
* Base fields every synced model gets automatically.
|
|
@@ -159,10 +160,10 @@ export function defineSchema(models, options) {
|
|
|
159
160
|
// them at every call site.
|
|
160
161
|
//
|
|
161
162
|
// Defaults:
|
|
162
|
-
// typename ← schema key (e.g. `
|
|
163
|
+
// typename ← schema key (e.g. `block` → `'block'`)
|
|
163
164
|
// persist.store ← typename (only resolved when `persist` was provided)
|
|
164
165
|
//
|
|
165
|
-
// A consumer that passes `typename: '
|
|
166
|
+
// A consumer that passes `typename: 'Block'` explicitly (common when
|
|
166
167
|
// the wire shape uses PascalCase while the schema key is camelCase) keeps
|
|
167
168
|
// that value — the fallback only fires when the field is unset.
|
|
168
169
|
//
|
|
@@ -266,7 +267,7 @@ function validateSyncGroupSchema(models) {
|
|
|
266
267
|
for (const [name, def] of Object.entries(models)) {
|
|
267
268
|
// Shape-validate the `scope` declaration via the shared Zod schema.
|
|
268
269
|
if (def.scope !== undefined && !scopeSchema.safeParse(def.scope).success) {
|
|
269
|
-
throw new AbloValidationError(`Model "${name}": scope kind "${String(def.scope)}" must be a lowercase identifier (e.g. '
|
|
270
|
+
throw new AbloValidationError(`Model "${name}": scope kind "${String(def.scope)}" must be a lowercase identifier (e.g. 'workspace').`, { code: 'schema_scope_kind_invalid', param: `${name}.scope` });
|
|
270
271
|
}
|
|
271
272
|
if (!def.grants)
|
|
272
273
|
continue;
|
|
@@ -26,7 +26,7 @@ import { z } from 'zod';
|
|
|
26
26
|
export declare const DEFAULT_ORG_COLUMN = "organization_id";
|
|
27
27
|
/**
|
|
28
28
|
* Scopes a table's rows through a parent table, for rows that carry no tenancy
|
|
29
|
-
* column of their own (for example,
|
|
29
|
+
* column of their own (for example, blocks scoped through their section, report,
|
|
30
30
|
* and organization). This is the canonical `parent` payload; authors write the
|
|
31
31
|
* friendlier {@link PolicyInput} `{ by: 'parent', fk, parent }` form, which
|
|
32
32
|
* {@link resolvePolicy} normalizes into this.
|
|
@@ -26,7 +26,7 @@ import { z } from 'zod';
|
|
|
26
26
|
export const DEFAULT_ORG_COLUMN = 'organization_id';
|
|
27
27
|
/**
|
|
28
28
|
* Scopes a table's rows through a parent table, for rows that carry no tenancy
|
|
29
|
-
* column of their own (for example,
|
|
29
|
+
* column of their own (for example, blocks scoped through their section, report,
|
|
30
30
|
* and organization). This is the canonical `parent` payload; authors write the
|
|
31
31
|
* friendlier {@link PolicyInput} `{ by: 'parent', fk, parent }` form, which
|
|
32
32
|
* {@link resolvePolicy} normalizes into this.
|
|
@@ -90,9 +90,9 @@ export const policyInputSchema = z
|
|
|
90
90
|
by: z.enum(['column', 'parent', 'none', 'source']),
|
|
91
91
|
/** `by: 'column'` — override the physical tenancy column name. Default {@link DEFAULT_ORG_COLUMN}. */
|
|
92
92
|
column: z.string().min(1).optional(),
|
|
93
|
-
/** `by: 'parent'` — column on this table that points at the parent (for example, `'
|
|
93
|
+
/** `by: 'parent'` — column on this table that points at the parent (for example, `'sectionId'`). */
|
|
94
94
|
fk: z.string().min(1).optional(),
|
|
95
|
-
/** `by: 'parent'` — parent table name (e.g. `'
|
|
95
|
+
/** `by: 'parent'` — parent table name (e.g. `'sections'`). */
|
|
96
96
|
parent: z.string().min(1).optional(),
|
|
97
97
|
/** `by: 'parent'` — column on the parent that `fk` references. Default `'id'`. */
|
|
98
98
|
parentKey: z.string().min(1).optional(),
|
|
@@ -138,7 +138,10 @@ export const policyInputSchema = z
|
|
|
138
138
|
});
|
|
139
139
|
}
|
|
140
140
|
});
|
|
141
|
-
const _policyInputAssignable =
|
|
141
|
+
const _policyInputAssignable = [
|
|
142
|
+
true,
|
|
143
|
+
true,
|
|
144
|
+
];
|
|
142
145
|
void _policyInputAssignable;
|
|
143
146
|
/**
|
|
144
147
|
* Normalizes the authoring {@link PolicyInput} into the canonical {@link Tenancy}.
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The transaction layer's seam — the surface the sync engine (and any other
|
|
3
|
+
* caller) sits on. ADR 0013's thesis as an interface: the layer defines,
|
|
4
|
+
* orders, settles, and authorizes changes; it holds no materialised state.
|
|
5
|
+
*
|
|
6
|
+
* `observe()` is the whole seam in one method. The sync engine is `observe()`
|
|
7
|
+
* piped into a materializer — deltas → local store → IndexedDB → reactive
|
|
8
|
+
* re-render — plus local optimistic mutations reconciled against `commit()` /
|
|
9
|
+
* `settled()`. Everything reactive is downstream of that method; the
|
|
10
|
+
* transaction layer never calls up into it.
|
|
11
|
+
*
|
|
12
|
+
* `participant` stays the WHO (user | agent | system), never the name of this.
|
|
13
|
+
* The taught verbs map onto the seam directly: `create`/`update`/`delete` are
|
|
14
|
+
* operations inside a `commit()` payload; `claim` is `claim()`; `track` rides
|
|
15
|
+
* the commit payload's `track` field (a durable premise is a zero-operation
|
|
16
|
+
* commit). Presence (`join`) is deliberately absent: it is live observation
|
|
17
|
+
* over a socket, and it joins the seam when its core carrier type exists —
|
|
18
|
+
* see docs/plans/transaction-core-language.md, Tier 3.
|
|
19
|
+
*
|
|
20
|
+
* This is the contract, not a runtime: nothing in this package implements it
|
|
21
|
+
* yet. The first explicit implementation (a headless client, a test harness)
|
|
22
|
+
* gains a compile-time conformance pin against this interface.
|
|
23
|
+
*/
|
|
24
|
+
import type { CommitMessage } from './wire/frames.js';
|
|
25
|
+
import type { CommitReceiptWire } from './wire/commit.js';
|
|
26
|
+
import type { Delta, HeldClaim, ClaimTarget, ClaimLeaseOptions } from './types/streams.js';
|
|
27
|
+
import type { ModelData } from './types/modelData.js';
|
|
28
|
+
import type { ModelScope } from './types/index.js';
|
|
29
|
+
/**
|
|
30
|
+
* A commit's durable acceptance — `{ status: 'queued' }` with the correlation
|
|
31
|
+
* the settlement feed later confirms. The wire layer names this
|
|
32
|
+
* {@link CommitReceiptWire}; the seam names it plainly.
|
|
33
|
+
*/
|
|
34
|
+
export type CommitReceipt = CommitReceiptWire;
|
|
35
|
+
/**
|
|
36
|
+
* The seam's read grammar for {@link TransactionLayer.list} — filter, order,
|
|
37
|
+
* and page through settled rows. Mirrors the taught list options
|
|
38
|
+
* (`where` / `orderBy` / `limit` / `offset` / `state`) without binding the
|
|
39
|
+
* seam to the client's local-read machinery.
|
|
40
|
+
*/
|
|
41
|
+
export interface ListQuery {
|
|
42
|
+
/** Equality filter on field values. */
|
|
43
|
+
where?: ModelData;
|
|
44
|
+
/** Sort order, field → direction. */
|
|
45
|
+
orderBy?: Record<string, 'asc' | 'desc'>;
|
|
46
|
+
limit?: number;
|
|
47
|
+
offset?: number;
|
|
48
|
+
/** Lifecycle filter; defaults to `'live'`. */
|
|
49
|
+
state?: `${ModelScope}`;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The transaction layer. Reads return settled state, point-in-time — never a
|
|
53
|
+
* reactive subscription. A write is an intent submitted through `commit()`;
|
|
54
|
+
* durable acceptance is the receipt (`queued`), and `settled()` resolves when
|
|
55
|
+
* the sync log has appended it (`confirmed`).
|
|
56
|
+
*/
|
|
57
|
+
export interface TransactionLayer {
|
|
58
|
+
/** Authentication: mint or renew the short-lived credential (`ek_`). */
|
|
59
|
+
ready(): Promise<void>;
|
|
60
|
+
/** Read one settled row by id, or `null` when absent. */
|
|
61
|
+
get(model: string, id: string): Promise<ModelData | null>;
|
|
62
|
+
/** Read settled rows matching a {@link ListQuery}. */
|
|
63
|
+
list(model: string, query?: ListQuery): Promise<ModelData[]>;
|
|
64
|
+
/**
|
|
65
|
+
* Submit a batch of operations — with its idempotent `clientTxId`, its
|
|
66
|
+
* `reads` premise, and any durable `track` registrations — and receive
|
|
67
|
+
* durable acceptance.
|
|
68
|
+
*/
|
|
69
|
+
commit(payload: CommitMessage['payload']): Promise<CommitReceipt>;
|
|
70
|
+
/** Resolve when the receipt's operations have appended to the sync log. */
|
|
71
|
+
settled(receipt: CommitReceipt): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Take a FIFO lease with a fence token on a target; release through the
|
|
74
|
+
* handle (`await using` disposes it).
|
|
75
|
+
*/
|
|
76
|
+
claim(target: ClaimTarget, options?: ClaimLeaseOptions): Promise<HeldClaim>;
|
|
77
|
+
/**
|
|
78
|
+
* The authoritative change feed, scoped to one or more sync groups —
|
|
79
|
+
* omitted, everything the credential can see.
|
|
80
|
+
*/
|
|
81
|
+
observe(scope?: string | readonly string[]): AsyncIterable<Delta>;
|
|
82
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The transaction layer's seam — the surface the sync engine (and any other
|
|
3
|
+
* caller) sits on. ADR 0013's thesis as an interface: the layer defines,
|
|
4
|
+
* orders, settles, and authorizes changes; it holds no materialised state.
|
|
5
|
+
*
|
|
6
|
+
* `observe()` is the whole seam in one method. The sync engine is `observe()`
|
|
7
|
+
* piped into a materializer — deltas → local store → IndexedDB → reactive
|
|
8
|
+
* re-render — plus local optimistic mutations reconciled against `commit()` /
|
|
9
|
+
* `settled()`. Everything reactive is downstream of that method; the
|
|
10
|
+
* transaction layer never calls up into it.
|
|
11
|
+
*
|
|
12
|
+
* `participant` stays the WHO (user | agent | system), never the name of this.
|
|
13
|
+
* The taught verbs map onto the seam directly: `create`/`update`/`delete` are
|
|
14
|
+
* operations inside a `commit()` payload; `claim` is `claim()`; `track` rides
|
|
15
|
+
* the commit payload's `track` field (a durable premise is a zero-operation
|
|
16
|
+
* commit). Presence (`join`) is deliberately absent: it is live observation
|
|
17
|
+
* over a socket, and it joins the seam when its core carrier type exists —
|
|
18
|
+
* see docs/plans/transaction-core-language.md, Tier 3.
|
|
19
|
+
*
|
|
20
|
+
* This is the contract, not a runtime: nothing in this package implements it
|
|
21
|
+
* yet. The first explicit implementation (a headless client, a test harness)
|
|
22
|
+
* gains a compile-time conformance pin against this interface.
|
|
23
|
+
*/
|
|
24
|
+
export {};
|
|
@@ -91,12 +91,11 @@ export declare const durableCommitEnvelopeSchema: z.ZodObject<{
|
|
|
91
91
|
}, z.core.$strip>>;
|
|
92
92
|
sourceMutationIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
93
93
|
commitOptions: z.ZodDefault<z.ZodObject<{
|
|
94
|
-
causedByTaskId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
95
94
|
reads: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
96
95
|
model: z.ZodString;
|
|
97
96
|
id: z.ZodString;
|
|
98
97
|
readAt: z.ZodNumber;
|
|
99
|
-
fields: z.ZodOptional<z.ZodArray<z.ZodString
|
|
98
|
+
fields: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
100
99
|
onStale: z.ZodOptional<z.ZodEnum<{
|
|
101
100
|
reject: "reject";
|
|
102
101
|
overwrite: "overwrite";
|
|
@@ -137,8 +136,8 @@ export declare function commitEnvelopeRecordId(idempotencyKey: string): string;
|
|
|
137
136
|
/** Constructs validated member metadata when an in-memory batch is formed. */
|
|
138
137
|
export declare function createCommitEnvelopeMember(value: z.input<typeof commitEnvelopeMemberSchema>): CommitEnvelopeMember;
|
|
139
138
|
/**
|
|
140
|
-
* Freezes the exact JSON request that will be persisted and sent. The
|
|
141
|
-
*
|
|
142
|
-
*
|
|
139
|
+
* Freezes the exact JSON request that will be persisted and sent. The shared
|
|
140
|
+
* snapshot contract makes framework proxies plain and rejects values that
|
|
141
|
+
* would be lost or corrupted by JSON serialization.
|
|
143
142
|
*/
|
|
144
143
|
export declare function createDurableCommitEnvelope(value: Omit<z.input<typeof durableCommitEnvelopeSchema>, 'id' | 'type' | 'storageVersion' | 'timestamp'>): DurableCommitEnvelope;
|
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
* operations, and the source mutations it supersedes.
|
|
8
8
|
*/
|
|
9
9
|
import { z } from 'zod';
|
|
10
|
-
import { readDependencySchema, trackDependencySchema } from '
|
|
11
|
-
import {
|
|
12
|
-
import { correlationIdSchema } from '
|
|
10
|
+
import { readDependencySchema, trackDependencySchema } from '../../coordination/schema.js';
|
|
11
|
+
import { wireCommitOperationSchema } from '../../wire/frames.js';
|
|
12
|
+
import { correlationIdSchema } from '../../wire/commit.js';
|
|
13
13
|
import { idempotencyKeySchema } from './idempotencyKey.js';
|
|
14
|
+
import { snapshotJsonValue } from '../../utils/json.js';
|
|
14
15
|
export const COMMIT_ENVELOPE_VERSION = 1;
|
|
15
16
|
export const COMMIT_ENVELOPE_RECORD_PREFIX = 'commit-envelope:';
|
|
16
17
|
/** One transaction's position in a commit; this is not the envelope itself. */
|
|
@@ -24,7 +25,7 @@ export const commitEnvelopeMemberSchema = z
|
|
|
24
25
|
})
|
|
25
26
|
.refine(({ operationIndex, operationCount }) => operationIndex < operationCount, { message: 'operationIndex must be smaller than operationCount' });
|
|
26
27
|
/** One operation stored exactly as the current commit transport sends it. */
|
|
27
|
-
export const durableCommitOperationSchema =
|
|
28
|
+
export const durableCommitOperationSchema = wireCommitOperationSchema
|
|
28
29
|
.pick({
|
|
29
30
|
type: true,
|
|
30
31
|
model: true,
|
|
@@ -48,7 +49,6 @@ export const durableCommitOperationSchema = commitOperationSchema
|
|
|
48
49
|
.optional(),
|
|
49
50
|
});
|
|
50
51
|
const durableCommitOptionsSchema = z.strictObject({
|
|
51
|
-
causedByTaskId: z.string().min(1).nullable().optional(),
|
|
52
52
|
reads: z.array(readDependencySchema).nullable().optional(),
|
|
53
53
|
track: z.array(trackDependencySchema).nullable().optional(),
|
|
54
54
|
});
|
|
@@ -145,9 +145,9 @@ export function createCommitEnvelopeMember(value) {
|
|
|
145
145
|
return commitEnvelopeMemberSchema.parse(value);
|
|
146
146
|
}
|
|
147
147
|
/**
|
|
148
|
-
* Freezes the exact JSON request that will be persisted and sent. The
|
|
149
|
-
*
|
|
150
|
-
*
|
|
148
|
+
* Freezes the exact JSON request that will be persisted and sent. The shared
|
|
149
|
+
* snapshot contract makes framework proxies plain and rejects values that
|
|
150
|
+
* would be lost or corrupted by JSON serialization.
|
|
151
151
|
*/
|
|
152
152
|
export function createDurableCommitEnvelope(value) {
|
|
153
153
|
const candidate = {
|
|
@@ -157,9 +157,5 @@ export function createDurableCommitEnvelope(value) {
|
|
|
157
157
|
storageVersion: COMMIT_ENVELOPE_VERSION,
|
|
158
158
|
timestamp: value.sealedAt,
|
|
159
159
|
};
|
|
160
|
-
|
|
161
|
-
if (serialized === undefined) {
|
|
162
|
-
throw new TypeError('Commit envelope is not JSON serializable');
|
|
163
|
-
}
|
|
164
|
-
return durableCommitEnvelopeSchema.parse(JSON.parse(serialized));
|
|
160
|
+
return durableCommitEnvelopeSchema.parse(snapshotJsonValue(candidate, '$.commitEnvelope'));
|
|
165
161
|
}
|
|
@@ -4,7 +4,7 @@ export declare const HTTP_COMMIT_ENVELOPE_VERSION: 1;
|
|
|
4
4
|
export declare const HTTP_COMMIT_ENVELOPE_PREFIX = "http-commit-envelope:";
|
|
5
5
|
/** Stay one hour inside the server's 24-hour idempotency retention window. */
|
|
6
6
|
export declare const HTTP_COMMIT_REPLAY_WINDOW_MS: number;
|
|
7
|
-
/**
|
|
7
|
+
/** Snapshot the JSON contract once, then make object-key order canonical. */
|
|
8
8
|
export declare function canonicalHttpCommitBody(value: unknown): string;
|
|
9
9
|
export declare const durableHttpCommitEnvelopeSchema: z.ZodObject<{
|
|
10
10
|
id: z.ZodString;
|
|
@@ -30,11 +30,18 @@ export declare const durableHttpCommitEnvelopeSchema: z.ZodObject<{
|
|
|
30
30
|
timestamp: z.ZodNumber;
|
|
31
31
|
}, z.core.$strict>;
|
|
32
32
|
export type DurableHttpCommitEnvelope = z.infer<typeof durableHttpCommitEnvelopeSchema>;
|
|
33
|
+
/**
|
|
34
|
+
* The HTTP verbs a durable commit envelope can carry, projected out of the
|
|
35
|
+
* persisted schema above. Callers that build, seal, or dispatch an envelope
|
|
36
|
+
* take this rather than restating the verbs: the envelope is a stored contract,
|
|
37
|
+
* so a verb the schema does not accept must not be constructible.
|
|
38
|
+
*/
|
|
39
|
+
export type DurableHttpCommitMethod = DurableHttpCommitEnvelope['request']['method'];
|
|
33
40
|
export declare function httpCommitEnvelopeRecordId(idempotencyKey: string, scopeNamespace?: string): string;
|
|
34
41
|
export declare function createDurableHttpCommitEnvelope(input: {
|
|
35
42
|
idempotencyKey: string;
|
|
36
43
|
request: {
|
|
37
|
-
method:
|
|
44
|
+
method: DurableHttpCommitMethod;
|
|
38
45
|
path: string;
|
|
39
46
|
body: unknown;
|
|
40
47
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/** Crash-durable exact HTTP request used by the stateless agent client. */
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { v5 as uuidv5 } from 'uuid';
|
|
4
|
-
import { stableStringify } from '
|
|
5
|
-
import { correlationIdSchema } from '
|
|
6
|
-
import { PROTOCOL_VERSION } from '
|
|
4
|
+
import { snapshotJsonValue, stableStringify } from '../../utils/json.js';
|
|
5
|
+
import { correlationIdSchema } from '../../wire/commit.js';
|
|
6
|
+
import { PROTOCOL_VERSION } from '../../wire/protocolVersion.js';
|
|
7
7
|
import { idempotencyKeySchema } from './idempotencyKey.js';
|
|
8
8
|
export const HTTP_COMMIT_ENVELOPE_VERSION = 1;
|
|
9
9
|
export const HTTP_COMMIT_ENVELOPE_PREFIX = 'http-commit-envelope:';
|
|
@@ -33,13 +33,9 @@ function hasSafeModelPathSegments(path) {
|
|
|
33
33
|
return false;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
/**
|
|
36
|
+
/** Snapshot the JSON contract once, then make object-key order canonical. */
|
|
37
37
|
export function canonicalHttpCommitBody(value) {
|
|
38
|
-
|
|
39
|
-
if (serialized === undefined) {
|
|
40
|
-
throw new TypeError('HTTP commit body is not JSON serializable');
|
|
41
|
-
}
|
|
42
|
-
return stableStringify(JSON.parse(serialized));
|
|
38
|
+
return stableStringify(snapshotJsonValue(value, '$.body'));
|
|
43
39
|
}
|
|
44
40
|
export const durableHttpCommitEnvelopeSchema = z
|
|
45
41
|
.strictObject({
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* restart or an ambiguous network response.
|
|
2
|
+
* The persisted shape of a write awaiting a definitive outcome.
|
|
4
3
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Owns one authoritative union over the two durable commit envelopes — the
|
|
5
|
+
* WebSocket envelope and its HTTP counterpart — so an injected store and the
|
|
6
|
+
* engine that reads back from it agree on exactly one set of records. The
|
|
7
|
+
* envelope schemas in this directory remain authoritative for their own fields;
|
|
8
|
+
* this module only unions them.
|
|
9
|
+
*
|
|
10
|
+
* The port that persists these records is a behavior contract, not a persisted
|
|
11
|
+
* shape, so it lives outside this directory in `src/durableWrites.ts`.
|
|
7
12
|
*/
|
|
8
13
|
import { z } from 'zod';
|
|
9
14
|
/** Every write shape that Ablo may ask an injected store to persist. */
|
|
@@ -42,12 +47,11 @@ export declare const pendingWriteSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
42
47
|
}, z.core.$strip>>;
|
|
43
48
|
sourceMutationIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
44
49
|
commitOptions: z.ZodDefault<z.ZodObject<{
|
|
45
|
-
causedByTaskId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
46
50
|
reads: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
47
51
|
model: z.ZodString;
|
|
48
52
|
id: z.ZodString;
|
|
49
53
|
readAt: z.ZodNumber;
|
|
50
|
-
fields: z.ZodOptional<z.ZodArray<z.ZodString
|
|
54
|
+
fields: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
51
55
|
onStale: z.ZodOptional<z.ZodEnum<{
|
|
52
56
|
reject: "reject";
|
|
53
57
|
overwrite: "overwrite";
|
|
@@ -106,33 +110,3 @@ export declare const pendingWriteSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
106
110
|
timestamp: z.ZodNumber;
|
|
107
111
|
}, z.core.$strict>]>;
|
|
108
112
|
export type PendingWrite = z.infer<typeof pendingWriteSchema>;
|
|
109
|
-
/**
|
|
110
|
-
* Persistence port used by `Ablo({ durableWrites })`.
|
|
111
|
-
*
|
|
112
|
-
* `seal` is the durability boundary: it must atomically persist the exact write
|
|
113
|
-
* and consume the staged records that write supersedes. Resolving this promise
|
|
114
|
-
* authorizes Ablo to dispatch the request, so adapters must never report success
|
|
115
|
-
* before the data is durable.
|
|
116
|
-
*/
|
|
117
|
-
export interface DurableWriteStore {
|
|
118
|
-
/**
|
|
119
|
-
* Atomically reserve a pending write and consume the staged records it owns.
|
|
120
|
-
* The same id + same request is idempotent; the same id + a different request
|
|
121
|
-
* must be rejected. For a source-accepted envelope, a re-seal may add the
|
|
122
|
-
* monotonic `acceptedAt`/`correlationId` evidence and the store must preserve
|
|
123
|
-
* that upgrade atomically rather than ignoring it.
|
|
124
|
-
*/
|
|
125
|
-
seal(write: PendingWrite, consumedRecordIds: readonly string[]): Promise<void>;
|
|
126
|
-
/** Load all unacknowledged writes. Stored data is treated as untrusted. */
|
|
127
|
-
list(): Promise<readonly unknown[]>;
|
|
128
|
-
/** Remove one write only after its outcome is definitive. */
|
|
129
|
-
remove(writeId: string): Promise<void>;
|
|
130
|
-
}
|
|
131
|
-
/** Runtime validation for injected adapters, including JavaScript consumers. */
|
|
132
|
-
export declare const durableWriteStoreSchema: z.ZodCustom<DurableWriteStore, DurableWriteStore>;
|
|
133
|
-
/** Options for crash-durable `create`, `update`, and `delete` calls. */
|
|
134
|
-
export declare const durableWritesConfigSchema: z.ZodObject<{
|
|
135
|
-
store: z.ZodCustom<DurableWriteStore, DurableWriteStore>;
|
|
136
|
-
namespace: z.ZodOptional<z.ZodString>;
|
|
137
|
-
}, z.core.$strict>;
|
|
138
|
-
export type DurableWritesConfig = z.infer<typeof durableWritesConfigSchema>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The persisted shape of a write awaiting a definitive outcome.
|
|
3
|
+
*
|
|
4
|
+
* Owns one authoritative union over the two durable commit envelopes — the
|
|
5
|
+
* WebSocket envelope and its HTTP counterpart — so an injected store and the
|
|
6
|
+
* engine that reads back from it agree on exactly one set of records. The
|
|
7
|
+
* envelope schemas in this directory remain authoritative for their own fields;
|
|
8
|
+
* this module only unions them.
|
|
9
|
+
*
|
|
10
|
+
* The port that persists these records is a behavior contract, not a persisted
|
|
11
|
+
* shape, so it lives outside this directory in `src/durableWrites.ts`.
|
|
12
|
+
*/
|
|
13
|
+
import { z } from 'zod';
|
|
14
|
+
import { durableCommitEnvelopeSchema } from './commitEnvelope.js';
|
|
15
|
+
import { durableHttpCommitEnvelopeSchema } from './httpCommitEnvelope.js';
|
|
16
|
+
/** Every write shape that Ablo may ask an injected store to persist. */
|
|
17
|
+
export const pendingWriteSchema = z.union([
|
|
18
|
+
durableCommitEnvelopeSchema,
|
|
19
|
+
durableHttpCommitEnvelopeSchema,
|
|
20
|
+
]);
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds the outgoing frames the sync WebSocket sends on the commit path, and
|
|
3
|
+
* provides the single place claim events are traced. These are stateless
|
|
4
|
+
* helpers that hold no socket state, so both the transport and its frame
|
|
5
|
+
* dispatch can share them.
|
|
6
|
+
*/
|
|
7
|
+
import type { CommitMessage } from '../wire/index.js';
|
|
8
|
+
import type { CommitAck as CanonicalCommitAck } from '../wire/commit.js';
|
|
9
|
+
import type { OnStaleMode, StaleNotification, ReadDependency, TrackDependency } from '../coordination/schema.js';
|
|
10
|
+
import type { ClaimAcquired, ClaimGranted, ClaimQueued, ClaimLost, ClaimRejection, ClaimExpired } from '../coordination/schema.js';
|
|
11
|
+
import type { Logger } from '../logger.js';
|
|
12
|
+
import type { SocketObservability } from '../observability.js';
|
|
13
|
+
/**
|
|
14
|
+
* The value a commit acknowledgement resolves to. `notifications` is present
|
|
15
|
+
* only when a guarded write (`onStale: 'notify'`) met a concurrent change; it
|
|
16
|
+
* carries the advisory signal that lets the writer self-heal, and the same
|
|
17
|
+
* signal also arrives on the `conflict:notified` event.
|
|
18
|
+
*/
|
|
19
|
+
export type CommitAck = CanonicalCommitAck;
|
|
20
|
+
/**
|
|
21
|
+
* The slice of a queued client mutation the commit frame reads — a structural
|
|
22
|
+
* port, so the reactive engine's fatter `MutationOperation` satisfies it
|
|
23
|
+
* without this module importing the consumer package.
|
|
24
|
+
*/
|
|
25
|
+
export interface CommitFrameOperation {
|
|
26
|
+
readonly type: string;
|
|
27
|
+
readonly model: string;
|
|
28
|
+
readonly id: string;
|
|
29
|
+
readonly input?: Record<string, unknown>;
|
|
30
|
+
readonly transactionId?: string;
|
|
31
|
+
readonly readAt?: number | null;
|
|
32
|
+
readonly onStale?: OnStaleMode | null;
|
|
33
|
+
readonly fenceToken?: number | null;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Converts the client's list of {@link CommitFrameOperation} values into the wire
|
|
37
|
+
* {@link CommitMessage} the server accepts. This is the one place the loosely
|
|
38
|
+
* typed operation — its `type` is a string, and it carries client-only
|
|
39
|
+
* `options` the server never reads — becomes the strict wire contract. Mapping
|
|
40
|
+
* each field by hand means a change to {@link WireCommitOperation} fails to compile
|
|
41
|
+
* here; the single `as` cast narrows the validated `type` to the wire union and
|
|
42
|
+
* is the only place that loosening happens.
|
|
43
|
+
*/
|
|
44
|
+
export declare function buildCommitFrame(operations: readonly CommitFrameOperation[], clientTxId: string, reads?: readonly ReadDependency[] | null, track?: readonly TrackDependency[] | null): CommitMessage;
|
|
45
|
+
/**
|
|
46
|
+
* Defensively validate the optional `notifications` array off a commit ack.
|
|
47
|
+
* Untrusted wire data — a malformed entry is dropped rather than throwing,
|
|
48
|
+
* so a bad notification never sinks an otherwise-successful commit.
|
|
49
|
+
*/
|
|
50
|
+
export declare function parseNotifications(raw: unknown): StaleNotification[] | undefined;
|
|
51
|
+
/** The reporting ports a claim trace writes through — supplied by the caller
|
|
52
|
+
* (the frame dispatch passes its session's own ports). */
|
|
53
|
+
export interface ClaimTracePorts {
|
|
54
|
+
readonly logger: Logger;
|
|
55
|
+
readonly observability: SocketObservability;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Which frame reports each phase of a claim's life.
|
|
59
|
+
*
|
|
60
|
+
* The correspondence is real and was previously implicit: six dispatch handlers
|
|
61
|
+
* each passed their own payload alongside a phase they picked by hand, and
|
|
62
|
+
* nothing checked that the two matched. Stating it once means a caller cannot
|
|
63
|
+
* label a rejection as an acquisition.
|
|
64
|
+
*
|
|
65
|
+
* Every value is the `z.infer` of the schema the dispatcher parsed with, so no
|
|
66
|
+
* field is restated here — this maps existing types, it does not describe them.
|
|
67
|
+
*/
|
|
68
|
+
interface ClaimFrameByPhase {
|
|
69
|
+
acquired: ClaimAcquired;
|
|
70
|
+
granted: ClaimGranted;
|
|
71
|
+
queued: ClaimQueued;
|
|
72
|
+
lost: ClaimLost;
|
|
73
|
+
rejected: ClaimRejection;
|
|
74
|
+
expired: ClaimExpired;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The single place claim events are traced. Every `claim_*` frame passes
|
|
78
|
+
* through here, so a developer debugging a collision gets one consistent record
|
|
79
|
+
* — a console line and a structured capture — without each frame case
|
|
80
|
+
* re-deriving the row and holder shape.
|
|
81
|
+
*
|
|
82
|
+
* The payload arrives already validated against its frame's schema, so this
|
|
83
|
+
* reads it as the shape it is rather than re-narrowing an untyped record. That
|
|
84
|
+
* distinction is not cosmetic: while this took `Record<string, unknown>` it
|
|
85
|
+
* read `actor`, `participantKind`, and `description` off frames that carry none
|
|
86
|
+
* of them, and every one of those reads silently produced `undefined` because a
|
|
87
|
+
* string key never has to exist.
|
|
88
|
+
*/
|
|
89
|
+
export declare function recordClaim<P extends keyof ClaimFrameByPhase>(ports: ClaimTracePorts, phase: P, payload: ClaimFrameByPhase[P]): void;
|
|
90
|
+
export {};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds the outgoing frames the sync WebSocket sends on the commit path, and
|
|
3
|
+
* provides the single place claim events are traced. These are stateless
|
|
4
|
+
* helpers that hold no socket state, so both the transport and its frame
|
|
5
|
+
* dispatch can share them.
|
|
6
|
+
*/
|
|
7
|
+
import { claimEventReasonSchema, staleNotificationSchema, } from '../coordination/schema.js';
|
|
8
|
+
import { formatClaim } from '../coordination/trace.js';
|
|
9
|
+
import { modelTarget } from '../coordination/locator.js';
|
|
10
|
+
/**
|
|
11
|
+
* Converts the client's list of {@link CommitFrameOperation} values into the wire
|
|
12
|
+
* {@link CommitMessage} the server accepts. This is the one place the loosely
|
|
13
|
+
* typed operation — its `type` is a string, and it carries client-only
|
|
14
|
+
* `options` the server never reads — becomes the strict wire contract. Mapping
|
|
15
|
+
* each field by hand means a change to {@link WireCommitOperation} fails to compile
|
|
16
|
+
* here; the single `as` cast narrows the validated `type` to the wire union and
|
|
17
|
+
* is the only place that loosening happens.
|
|
18
|
+
*/
|
|
19
|
+
export function buildCommitFrame(operations, clientTxId, reads, track) {
|
|
20
|
+
const payload = {
|
|
21
|
+
operations: operations.map((op) => ({
|
|
22
|
+
type: op.type,
|
|
23
|
+
model: op.model,
|
|
24
|
+
id: op.id,
|
|
25
|
+
input: op.input,
|
|
26
|
+
transactionId: op.transactionId,
|
|
27
|
+
readAt: op.readAt,
|
|
28
|
+
onStale: op.onStale,
|
|
29
|
+
fenceToken: op.fenceToken,
|
|
30
|
+
})),
|
|
31
|
+
clientTxId,
|
|
32
|
+
};
|
|
33
|
+
// The batch premise: the rows or groups the writer read before committing.
|
|
34
|
+
if (reads && reads.length > 0)
|
|
35
|
+
payload.reads = [...reads];
|
|
36
|
+
// Durable premises the writer is registering: the rows or groups it
|
|
37
|
+
// wants to keep hearing about after this commit, delivered on a future receipt.
|
|
38
|
+
if (track && track.length > 0)
|
|
39
|
+
payload.track = [...track];
|
|
40
|
+
return { type: 'commit', payload };
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Defensively validate the optional `notifications` array off a commit ack.
|
|
44
|
+
* Untrusted wire data — a malformed entry is dropped rather than throwing,
|
|
45
|
+
* so a bad notification never sinks an otherwise-successful commit.
|
|
46
|
+
*/
|
|
47
|
+
export function parseNotifications(raw) {
|
|
48
|
+
if (!Array.isArray(raw) || raw.length === 0)
|
|
49
|
+
return undefined;
|
|
50
|
+
const out = [];
|
|
51
|
+
for (const entry of raw) {
|
|
52
|
+
const parsed = staleNotificationSchema.safeParse(entry);
|
|
53
|
+
if (parsed.success)
|
|
54
|
+
out.push(parsed.data);
|
|
55
|
+
}
|
|
56
|
+
return out.length > 0 ? out : undefined;
|
|
57
|
+
}
|
|
58
|
+
// The phases this map covers and the phases a ClaimEvent can report are the
|
|
59
|
+
// same set. Adding one to either without the other stops compiling here.
|
|
60
|
+
const _phaseCoverage = true;
|
|
61
|
+
void _phaseCoverage;
|
|
62
|
+
/**
|
|
63
|
+
* The single place claim events are traced. Every `claim_*` frame passes
|
|
64
|
+
* through here, so a developer debugging a collision gets one consistent record
|
|
65
|
+
* — a console line and a structured capture — without each frame case
|
|
66
|
+
* re-deriving the row and holder shape.
|
|
67
|
+
*
|
|
68
|
+
* The payload arrives already validated against its frame's schema, so this
|
|
69
|
+
* reads it as the shape it is rather than re-narrowing an untyped record. That
|
|
70
|
+
* distinction is not cosmetic: while this took `Record<string, unknown>` it
|
|
71
|
+
* read `actor`, `participantKind`, and `description` off frames that carry none
|
|
72
|
+
* of them, and every one of those reads silently produced `undefined` because a
|
|
73
|
+
* string key never has to exist.
|
|
74
|
+
*/
|
|
75
|
+
export function recordClaim(ports, phase, payload) {
|
|
76
|
+
// Widened so the members can be told apart with `in`. The parameter above
|
|
77
|
+
// stays correlated to `phase`, which is what the widening cannot undo.
|
|
78
|
+
const frame = payload;
|
|
79
|
+
const target = 'target' in frame ? frame.target : undefined;
|
|
80
|
+
// The holder rides on the rejection and queued frames, with a summary of
|
|
81
|
+
// their claim beside it. Collecting it is the whole of "name the
|
|
82
|
+
// counterparty" — the wire has carried it all along and this projection used
|
|
83
|
+
// to flatten it into one string alongside the cause.
|
|
84
|
+
const counterparty = {
|
|
85
|
+
...('heldBy' in frame && frame.heldBy !== undefined
|
|
86
|
+
? { actor: frame.heldBy }
|
|
87
|
+
: {}),
|
|
88
|
+
...('heldByKind' in frame && frame.heldByKind !== undefined
|
|
89
|
+
? { participantKind: frame.heldByKind }
|
|
90
|
+
: {}),
|
|
91
|
+
...('heldByClaimId' in frame && frame.heldByClaimId !== undefined
|
|
92
|
+
? { claimId: frame.heldByClaimId }
|
|
93
|
+
: {}),
|
|
94
|
+
...('heldByExpiresAt' in frame && frame.heldByExpiresAt !== undefined
|
|
95
|
+
? { expiresAt: frame.heldByExpiresAt }
|
|
96
|
+
: {}),
|
|
97
|
+
...('heldByClaim' in frame && frame.heldByClaim?.description !== undefined
|
|
98
|
+
? { description: frame.heldByClaim.description }
|
|
99
|
+
: {}),
|
|
100
|
+
};
|
|
101
|
+
// `reason` is a plain string on the wire, which is frozen, so an older server
|
|
102
|
+
// may send a word the closed set does not list. One that parses becomes the
|
|
103
|
+
// typed reason; one that does not is absent rather than passed off as prose.
|
|
104
|
+
const parsedReason = 'reason' in frame ? claimEventReasonSchema.safeParse(frame.reason) : undefined;
|
|
105
|
+
const event = {
|
|
106
|
+
phase,
|
|
107
|
+
claimId: frame.claimId,
|
|
108
|
+
...(target ? modelTarget(target) : {}),
|
|
109
|
+
...(target?.field !== undefined ? { field: target.field } : {}),
|
|
110
|
+
// No claim frame names an actor of its own; the only participant one
|
|
111
|
+
// carries is the holder that blocked it.
|
|
112
|
+
...('heldBy' in frame && frame.heldBy !== undefined
|
|
113
|
+
? { actor: frame.heldBy }
|
|
114
|
+
: {}),
|
|
115
|
+
...('position' in frame ? { position: frame.position } : {}),
|
|
116
|
+
...(parsedReason?.success ? { reason: parsedReason.data } : {}),
|
|
117
|
+
...('policyReason' in frame && frame.policyReason !== undefined
|
|
118
|
+
? { policyReason: frame.policyReason }
|
|
119
|
+
: {}),
|
|
120
|
+
...(Object.keys(counterparty).length > 0 ? { heldBy: counterparty } : {}),
|
|
121
|
+
};
|
|
122
|
+
const message = formatClaim(event);
|
|
123
|
+
// A rejection or lost lease is the collision a developer is actively
|
|
124
|
+
// debugging → warn (shows at the default log level). The routine events
|
|
125
|
+
// (acquired/queued/granted/expired) are debug-only so they never drown the
|
|
126
|
+
// console until you opt in with `new Ablo({ debug: true })`.
|
|
127
|
+
const isCollision = phase === 'rejected' || phase === 'lost';
|
|
128
|
+
if (isCollision)
|
|
129
|
+
ports.logger.warn(message);
|
|
130
|
+
else
|
|
131
|
+
ports.logger.debug(message);
|
|
132
|
+
ports.observability.breadcrumb(message, 'sync.coordination', isCollision ? 'warning' : 'info');
|
|
133
|
+
ports.observability.captureClaim(event);
|
|
134
|
+
}
|