@abloatai/humans 0.37.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/README.md +52 -0
- package/dist/Ablo.d.ts +208 -0
- package/dist/Ablo.js +120 -0
- package/dist/client.d.ts +317 -0
- package/dist/client.js +13 -0
- package/dist/core.d.ts +35 -0
- package/dist/core.js +48 -0
- package/dist/humans.d.ts +28 -0
- package/dist/humans.js +34 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +6 -0
- package/dist/local/BaseSyncedStore.d.ts +807 -0
- package/dist/local/BaseSyncedStore.js +1516 -0
- package/dist/local/Database.d.ts +322 -0
- package/dist/local/Database.js +1589 -0
- package/dist/local/InstanceCache.d.ts +255 -0
- package/dist/local/InstanceCache.js +1263 -0
- package/dist/local/LazyReferenceCollection.d.ts +177 -0
- package/dist/local/LazyReferenceCollection.js +461 -0
- package/dist/local/Model.d.ts +475 -0
- package/dist/local/Model.js +950 -0
- package/dist/local/ModelRegistry.d.ts +225 -0
- package/dist/local/ModelRegistry.js +539 -0
- package/dist/local/NetworkMonitor.d.ts +28 -0
- package/dist/local/NetworkMonitor.js +79 -0
- package/dist/local/RuntimeContext.d.ts +52 -0
- package/dist/local/RuntimeContext.js +80 -0
- package/dist/local/SyncClient.d.ts +516 -0
- package/dist/local/SyncClient.js +1754 -0
- package/dist/local/adapters/alwaysOnline.d.ts +14 -0
- package/dist/local/adapters/alwaysOnline.js +17 -0
- package/dist/local/adapters/inMemoryStorage.d.ts +37 -0
- package/dist/local/adapters/inMemoryStorage.js +122 -0
- package/dist/local/client/clientPrelude.d.ts +52 -0
- package/dist/local/client/clientPrelude.js +60 -0
- package/dist/local/client/consoleLogger.d.ts +35 -0
- package/dist/local/client/consoleLogger.js +44 -0
- package/dist/local/client/createInternalComponents.d.ts +50 -0
- package/dist/local/client/createInternalComponents.js +98 -0
- package/dist/local/client/createModelProxy.d.ts +248 -0
- package/dist/local/client/createModelProxy.js +880 -0
- package/dist/local/client/modelRegistration.d.ts +10 -0
- package/dist/local/client/modelRegistration.js +316 -0
- package/dist/local/client/options.d.ts +440 -0
- package/dist/local/client/options.js +7 -0
- package/dist/local/client/reactiveEngine.d.ts +53 -0
- package/dist/local/client/reactiveEngine.js +705 -0
- package/dist/local/client/resourceTypes.d.ts +12 -0
- package/dist/local/client/resourceTypes.js +10 -0
- package/dist/local/client/schemaConfig.d.ts +44 -0
- package/dist/local/client/schemaConfig.js +185 -0
- package/dist/local/client/storeCluster.d.ts +46 -0
- package/dist/local/client/storeCluster.js +133 -0
- package/dist/local/client/storeLifecycle.d.ts +61 -0
- package/dist/local/client/storeLifecycle.js +236 -0
- package/dist/local/client/validateAbloOptions.d.ts +42 -0
- package/dist/local/client/validateAbloOptions.js +43 -0
- package/dist/local/client/wsMutationExecutor.d.ts +27 -0
- package/dist/local/client/wsMutationExecutor.js +72 -0
- package/dist/local/context.d.ts +42 -0
- package/dist/local/context.js +81 -0
- package/dist/local/coordination/ClaimLog.d.ts +26 -0
- package/dist/local/coordination/ClaimLog.js +32 -0
- package/dist/local/interfaces/index.d.ts +311 -0
- package/dist/local/interfaces/index.js +9 -0
- package/dist/local/localModelContract.d.ts +14 -0
- package/dist/local/localModelContract.js +1 -0
- package/dist/local/logPosition.d.ts +31 -0
- package/dist/local/logPosition.js +53 -0
- package/dist/local/mutationPersistence.d.ts +6 -0
- package/dist/local/mutationPersistence.js +1 -0
- package/dist/local/mutators/RecordingMutation.d.ts +36 -0
- package/dist/local/mutators/RecordingMutation.js +182 -0
- package/dist/local/mutators/Transaction.d.ts +40 -0
- package/dist/local/mutators/Transaction.js +58 -0
- package/dist/local/mutators/UndoManager.d.ts +258 -0
- package/dist/local/mutators/UndoManager.js +665 -0
- package/dist/local/mutators/defineMutators.d.ts +60 -0
- package/dist/local/mutators/defineMutators.js +18 -0
- package/dist/local/mutators/inverseOp.d.ts +126 -0
- package/dist/local/mutators/inverseOp.js +71 -0
- package/dist/local/mutators/mutateActions.d.ts +45 -0
- package/dist/local/mutators/mutateActions.js +105 -0
- package/dist/local/mutators/readerActions.d.ts +33 -0
- package/dist/local/mutators/readerActions.js +57 -0
- package/dist/local/mutators/undoApply.d.ts +51 -0
- package/dist/local/mutators/undoApply.js +117 -0
- package/dist/local/persistence.d.ts +7 -0
- package/dist/local/persistence.js +9 -0
- package/dist/local/query/QueryProcessor.d.ts +75 -0
- package/dist/local/query/QueryProcessor.js +255 -0
- package/dist/local/query/client.d.ts +64 -0
- package/dist/local/query/client.js +138 -0
- package/dist/local/query/types.d.ts +85 -0
- package/dist/local/query/types.js +16 -0
- package/dist/local/schema/serialize.d.ts +1 -0
- package/dist/local/schema/serialize.js +1 -0
- package/dist/local/store/queryApi.d.ts +13 -0
- package/dist/local/store/queryApi.js +35 -0
- package/dist/local/storeContract.d.ts +145 -0
- package/dist/local/storeContract.js +12 -0
- package/dist/local/stores/DatabaseManager.d.ts +112 -0
- package/dist/local/stores/DatabaseManager.js +400 -0
- package/dist/local/stores/ObjectStore.d.ts +115 -0
- package/dist/local/stores/ObjectStore.js +393 -0
- package/dist/local/stores/ObjectStoreContract.d.ts +38 -0
- package/dist/local/stores/ObjectStoreContract.js +1 -0
- package/dist/local/stores/StoreManager.d.ts +114 -0
- package/dist/local/stores/StoreManager.js +304 -0
- package/dist/local/stores/SyncActionStore.d.ts +99 -0
- package/dist/local/stores/SyncActionStore.js +506 -0
- package/dist/local/stores/openIDBWithTimeout.d.ts +65 -0
- package/dist/local/stores/openIDBWithTimeout.js +153 -0
- package/dist/local/stores/persistenceCleanup.d.ts +7 -0
- package/dist/local/stores/persistenceCleanup.js +26 -0
- package/dist/local/stores/persistenceIdentity.d.ts +27 -0
- package/dist/local/stores/persistenceIdentity.js +38 -0
- package/dist/local/stores/syncAction.d.ts +26 -0
- package/dist/local/stores/syncAction.js +16 -0
- package/dist/local/stores/v1PersistenceDeletion.d.ts +8 -0
- package/dist/local/stores/v1PersistenceDeletion.js +16 -0
- package/dist/local/sync/BootstrapFetcher.d.ts +284 -0
- package/dist/local/sync/BootstrapFetcher.js +964 -0
- package/dist/local/sync/ConnectionManager.d.ts +8 -0
- package/dist/local/sync/ConnectionManager.js +8 -0
- package/dist/local/sync/OnDemandLoader.d.ts +231 -0
- package/dist/local/sync/OnDemandLoader.js +743 -0
- package/dist/local/sync/SubscriptionManager.d.ts +159 -0
- package/dist/local/sync/SubscriptionManager.js +243 -0
- package/dist/local/sync/SyncWebSocket.d.ts +173 -0
- package/dist/local/sync/SyncWebSocket.js +438 -0
- package/dist/local/sync/bootstrapApply.d.ts +73 -0
- package/dist/local/sync/bootstrapApply.js +73 -0
- package/dist/local/sync/commitFrames.d.ts +8 -0
- package/dist/local/sync/commitFrames.js +8 -0
- package/dist/local/sync/connectionManagerLifecycle.d.ts +23 -0
- package/dist/local/sync/connectionManagerLifecycle.js +126 -0
- package/dist/local/sync/contextPorts.d.ts +18 -0
- package/dist/local/sync/contextPorts.js +31 -0
- package/dist/local/sync/createClaimStream.d.ts +64 -0
- package/dist/local/sync/createClaimStream.js +475 -0
- package/dist/local/sync/createSnapshot.d.ts +29 -0
- package/dist/local/sync/createSnapshot.js +116 -0
- package/dist/local/sync/credentialLifecycle.d.ts +7 -0
- package/dist/local/sync/credentialLifecycle.js +7 -0
- package/dist/local/sync/deltaPipeline.d.ts +116 -0
- package/dist/local/sync/deltaPipeline.js +357 -0
- package/dist/local/sync/groupChange.d.ts +116 -0
- package/dist/local/sync/groupChange.js +244 -0
- package/dist/local/sync/initialize.d.ts +27 -0
- package/dist/local/sync/initialize.js +137 -0
- package/dist/local/sync/participants.d.ts +132 -0
- package/dist/local/sync/participants.js +342 -0
- package/dist/local/sync/persistedPrefix.d.ts +12 -0
- package/dist/local/sync/persistedPrefix.js +22 -0
- package/dist/local/sync/reconnect.d.ts +23 -0
- package/dist/local/sync/reconnect.js +55 -0
- package/dist/local/sync/schemaDrift.d.ts +55 -0
- package/dist/local/sync/schemaDrift.js +53 -0
- package/dist/local/sync/schemas.d.ts +71 -0
- package/dist/local/sync/schemas.js +94 -0
- package/dist/local/sync/socketEventWiring.d.ts +31 -0
- package/dist/local/sync/socketEventWiring.js +130 -0
- package/dist/local/sync/syncCursor.d.ts +40 -0
- package/dist/local/sync/syncCursor.js +55 -0
- package/dist/local/sync/syncPlan.d.ts +54 -0
- package/dist/local/sync/syncPlan.js +50 -0
- package/dist/local/sync/terminalSessionLifecycle.d.ts +20 -0
- package/dist/local/sync/terminalSessionLifecycle.js +50 -0
- package/dist/local/sync/wsFrameHandlers.d.ts +8 -0
- package/dist/local/sync/wsFrameHandlers.js +8 -0
- package/dist/local/transactions/databaseCommitOutbox.d.ts +15 -0
- package/dist/local/transactions/databaseCommitOutbox.js +16 -0
- package/dist/local/transactions/localMutation.d.ts +10 -0
- package/dist/local/transactions/localMutation.js +37 -0
- package/dist/local/transactions/mutations/MutationQueue.d.ts +511 -0
- package/dist/local/transactions/mutations/MutationQueue.js +1498 -0
- package/dist/local/transactions/mutations/MutationStore.d.ts +20 -0
- package/dist/local/transactions/mutations/MutationStore.js +53 -0
- package/dist/local/transactions/mutations/UnconfirmedWrites.d.ts +82 -0
- package/dist/local/transactions/mutations/UnconfirmedWrites.js +104 -0
- package/dist/local/transactions/mutations/batchProcessing.d.ts +64 -0
- package/dist/local/transactions/mutations/batchProcessing.js +349 -0
- package/dist/local/transactions/mutations/coalesceRules.d.ts +58 -0
- package/dist/local/transactions/mutations/coalesceRules.js +140 -0
- package/dist/local/transactions/mutations/commitApi.d.ts +19 -0
- package/dist/local/transactions/mutations/commitApi.js +74 -0
- package/dist/local/transactions/mutations/commitLane.d.ts +70 -0
- package/dist/local/transactions/mutations/commitLane.js +140 -0
- package/dist/local/transactions/mutations/commitLatency.d.ts +52 -0
- package/dist/local/transactions/mutations/commitLatency.js +130 -0
- package/dist/local/transactions/mutations/commitPayload.d.ts +165 -0
- package/dist/local/transactions/mutations/commitPayload.js +152 -0
- package/dist/local/transactions/mutations/commitTransport.d.ts +36 -0
- package/dist/local/transactions/mutations/commitTransport.js +104 -0
- package/dist/local/transactions/mutations/deltaConfirmation.d.ts +63 -0
- package/dist/local/transactions/mutations/deltaConfirmation.js +235 -0
- package/dist/local/transactions/mutations/durableCommitRestore.d.ts +17 -0
- package/dist/local/transactions/mutations/durableCommitRestore.js +95 -0
- package/dist/local/transactions/mutations/durableWriteStore.d.ts +14 -0
- package/dist/local/transactions/mutations/durableWriteStore.js +12 -0
- package/dist/local/transactions/mutations/executionSelection.d.ts +6 -0
- package/dist/local/transactions/mutations/executionSelection.js +42 -0
- package/dist/local/transactions/mutations/failureHandling.d.ts +16 -0
- package/dist/local/transactions/mutations/failureHandling.js +130 -0
- package/dist/local/transactions/mutations/failurePolicy.d.ts +13 -0
- package/dist/local/transactions/mutations/failurePolicy.js +48 -0
- package/dist/local/transactions/mutations/localMutation.d.ts +58 -0
- package/dist/local/transactions/mutations/localMutation.js +75 -0
- package/dist/local/transactions/mutations/modelOperations.d.ts +44 -0
- package/dist/local/transactions/mutations/modelOperations.js +144 -0
- package/dist/local/transactions/mutations/mutationPersistence.d.ts +25 -0
- package/dist/local/transactions/mutations/mutationPersistence.js +188 -0
- package/dist/local/transactions/mutations/pendingDrain.d.ts +33 -0
- package/dist/local/transactions/mutations/pendingDrain.js +112 -0
- package/dist/local/transactions/mutations/processingScheduler.d.ts +14 -0
- package/dist/local/transactions/mutations/processingScheduler.js +24 -0
- package/dist/local/transactions/mutations/queueCoalescing.d.ts +13 -0
- package/dist/local/transactions/mutations/queueCoalescing.js +35 -0
- package/dist/local/transactions/mutations/replayValidation.d.ts +187 -0
- package/dist/local/transactions/mutations/replayValidation.js +164 -0
- package/dist/local/transactions/reconnectDrain.d.ts +11 -0
- package/dist/local/transactions/reconnectDrain.js +13 -0
- package/dist/local/utils/mobxSetup.d.ts +53 -0
- package/dist/local/utils/mobxSetup.js +330 -0
- package/dist/local/views/QueryView.d.ts +79 -0
- package/dist/local/views/QueryView.js +218 -0
- package/dist/local/views/ViewRegistry.d.ts +20 -0
- package/dist/local/views/ViewRegistry.js +57 -0
- package/dist/local/views/incrementalView.d.ts +45 -0
- package/dist/local/views/incrementalView.js +69 -0
- package/dist/plugin.d.ts +285 -0
- package/dist/plugin.js +106 -0
- package/dist/presenceStream.d.ts +69 -0
- package/dist/presenceStream.js +200 -0
- package/dist/react/AbloProvider.d.ts +242 -0
- package/dist/react/AbloProvider.js +456 -0
- package/dist/react/ClientSideSuspense.d.ts +36 -0
- package/dist/react/ClientSideSuspense.js +17 -0
- package/dist/react/DefaultFallback.d.ts +24 -0
- package/dist/react/DefaultFallback.js +43 -0
- package/dist/react/context.d.ts +55 -0
- package/dist/react/context.js +29 -0
- package/dist/react/createAbloReact.d.ts +50 -0
- package/dist/react/createAbloReact.js +48 -0
- package/dist/react/internalContext.d.ts +33 -0
- package/dist/react/internalContext.js +3 -0
- package/dist/react/useAblo.d.ts +96 -0
- package/dist/react/useAblo.js +120 -0
- package/dist/react/useCurrentUserId.d.ts +2 -0
- package/dist/react/useCurrentUserId.js +12 -0
- package/dist/react/useErrorListener.d.ts +2 -0
- package/dist/react/useErrorListener.js +14 -0
- package/dist/react/useMutationFailureListener.d.ts +8 -0
- package/dist/react/useMutationFailureListener.js +19 -0
- package/dist/react/useMutators.d.ts +56 -0
- package/dist/react/useMutators.js +84 -0
- package/dist/react/useSyncStatus.d.ts +19 -0
- package/dist/react/useSyncStatus.js +37 -0
- package/dist/react/useUndoScope.d.ts +34 -0
- package/dist/react/useUndoScope.js +73 -0
- package/dist/react.d.ts +18 -0
- package/dist/react.js +14 -0
- package/dist/reactRuntime.d.ts +4 -0
- package/dist/reactRuntime.js +2 -0
- package/dist/surface.d.ts +36 -0
- package/dist/surface.js +77 -0
- package/dist/useReactive.d.ts +6 -0
- package/dist/useReactive.js +43 -0
- package/package.json +119 -0
- package/src/Ablo.ts +456 -0
- package/src/client.ts +374 -0
- package/src/core.ts +104 -0
- package/src/humans.ts +61 -0
- package/src/index.ts +40 -0
- package/src/local/BaseSyncedStore.ts +1991 -0
- package/src/local/Database.ts +2052 -0
- package/src/local/InstanceCache.ts +1503 -0
- package/src/local/LazyReferenceCollection.ts +563 -0
- package/src/local/Model.ts +1124 -0
- package/src/local/ModelRegistry.ts +762 -0
- package/src/local/NetworkMonitor.ts +88 -0
- package/src/local/RuntimeContext.ts +141 -0
- package/src/local/SyncClient.ts +2131 -0
- package/src/local/adapters/alwaysOnline.ts +20 -0
- package/src/local/adapters/inMemoryStorage.ts +141 -0
- package/src/local/client/clientPrelude.ts +112 -0
- package/src/local/client/consoleLogger.ts +60 -0
- package/src/local/client/createInternalComponents.ts +163 -0
- package/src/local/client/createModelProxy.ts +1390 -0
- package/src/local/client/modelRegistration.ts +350 -0
- package/src/local/client/options.ts +526 -0
- package/src/local/client/reactiveEngine.ts +935 -0
- package/src/local/client/resourceTypes.ts +37 -0
- package/src/local/client/schemaConfig.ts +194 -0
- package/src/local/client/storeCluster.ts +172 -0
- package/src/local/client/storeLifecycle.ts +343 -0
- package/src/local/client/validateAbloOptions.ts +95 -0
- package/src/local/client/wsMutationExecutor.ts +110 -0
- package/src/local/context.ts +96 -0
- package/src/local/coordination/ClaimLog.ts +39 -0
- package/src/local/interfaces/index.ts +468 -0
- package/src/local/localModelContract.ts +15 -0
- package/src/local/logPosition.ts +84 -0
- package/src/local/mutationPersistence.ts +7 -0
- package/src/local/mutators/RecordingMutation.ts +222 -0
- package/src/local/mutators/Transaction.ts +97 -0
- package/src/local/mutators/UndoManager.ts +741 -0
- package/src/local/mutators/defineMutators.ts +76 -0
- package/src/local/mutators/inverseOp.ts +83 -0
- package/src/local/mutators/mutateActions.ts +167 -0
- package/src/local/mutators/readerActions.ts +99 -0
- package/src/local/mutators/undoApply.ts +141 -0
- package/src/local/persistence.ts +16 -0
- package/src/local/query/QueryProcessor.ts +347 -0
- package/src/local/query/client.ts +197 -0
- package/src/local/query/types.ts +102 -0
- package/src/local/schema/serialize.ts +1 -0
- package/src/local/store/queryApi.ts +56 -0
- package/src/local/storeContract.ts +146 -0
- package/src/local/stores/DatabaseManager.ts +507 -0
- package/src/local/stores/ObjectStore.ts +449 -0
- package/src/local/stores/ObjectStoreContract.ts +48 -0
- package/src/local/stores/StoreManager.ts +388 -0
- package/src/local/stores/SyncActionStore.ts +579 -0
- package/src/local/stores/openIDBWithTimeout.ts +195 -0
- package/src/local/stores/persistenceCleanup.ts +43 -0
- package/src/local/stores/persistenceIdentity.ts +83 -0
- package/src/local/stores/syncAction.ts +21 -0
- package/src/local/stores/v1PersistenceDeletion.ts +21 -0
- package/src/local/sync/BootstrapFetcher.ts +1224 -0
- package/src/local/sync/ConnectionManager.ts +15 -0
- package/src/local/sync/OnDemandLoader.ts +927 -0
- package/src/local/sync/SubscriptionManager.ts +300 -0
- package/src/local/sync/SyncWebSocket.ts +584 -0
- package/src/local/sync/bootstrapApply.ts +130 -0
- package/src/local/sync/commitFrames.ts +16 -0
- package/src/local/sync/connectionManagerLifecycle.ts +158 -0
- package/src/local/sync/contextPorts.ts +37 -0
- package/src/local/sync/createClaimStream.ts +668 -0
- package/src/local/sync/createSnapshot.ts +160 -0
- package/src/local/sync/credentialLifecycle.ts +18 -0
- package/src/local/sync/deltaPipeline.ts +473 -0
- package/src/local/sync/groupChange.ts +343 -0
- package/src/local/sync/initialize.ts +205 -0
- package/src/local/sync/participants.ts +564 -0
- package/src/local/sync/persistedPrefix.ts +27 -0
- package/src/local/sync/reconnect.ts +88 -0
- package/src/local/sync/schemaDrift.ts +86 -0
- package/src/local/sync/schemas.ts +118 -0
- package/src/local/sync/socketEventWiring.ts +196 -0
- package/src/local/sync/syncCursor.ts +62 -0
- package/src/local/sync/syncPlan.ts +89 -0
- package/src/local/sync/terminalSessionLifecycle.ts +66 -0
- package/src/local/sync/wsFrameHandlers.ts +20 -0
- package/src/local/transactions/databaseCommitOutbox.ts +33 -0
- package/src/local/transactions/localMutation.ts +58 -0
- package/src/local/transactions/mutations/MutationQueue.ts +1998 -0
- package/src/local/transactions/mutations/MutationStore.ts +65 -0
- package/src/local/transactions/mutations/UnconfirmedWrites.ts +133 -0
- package/src/local/transactions/mutations/batchProcessing.ts +469 -0
- package/src/local/transactions/mutations/coalesceRules.ts +192 -0
- package/src/local/transactions/mutations/commitApi.ts +97 -0
- package/src/local/transactions/mutations/commitLane.ts +191 -0
- package/src/local/transactions/mutations/commitLatency.ts +164 -0
- package/src/local/transactions/mutations/commitPayload.ts +281 -0
- package/src/local/transactions/mutations/commitTransport.ts +174 -0
- package/src/local/transactions/mutations/deltaConfirmation.ts +298 -0
- package/src/local/transactions/mutations/durableCommitRestore.ts +128 -0
- package/src/local/transactions/mutations/durableWriteStore.ts +21 -0
- package/src/local/transactions/mutations/executionSelection.ts +42 -0
- package/src/local/transactions/mutations/failureHandling.ts +154 -0
- package/src/local/transactions/mutations/failurePolicy.ts +61 -0
- package/src/local/transactions/mutations/localMutation.ts +135 -0
- package/src/local/transactions/mutations/modelOperations.ts +210 -0
- package/src/local/transactions/mutations/mutationPersistence.ts +231 -0
- package/src/local/transactions/mutations/pendingDrain.ts +160 -0
- package/src/local/transactions/mutations/processingScheduler.ts +35 -0
- package/src/local/transactions/mutations/queueCoalescing.ts +45 -0
- package/src/local/transactions/mutations/replayValidation.ts +192 -0
- package/src/local/transactions/reconnectDrain.ts +24 -0
- package/src/local/utils/mobxSetup.ts +388 -0
- package/src/local/views/QueryView.ts +311 -0
- package/src/local/views/ViewRegistry.ts +61 -0
- package/src/local/views/incrementalView.ts +92 -0
- package/src/plugin.ts +396 -0
- package/src/presenceStream.ts +279 -0
- package/src/react/AbloProvider.tsx +744 -0
- package/src/react/ClientSideSuspense.tsx +57 -0
- package/src/react/DefaultFallback.tsx +60 -0
- package/src/react/context.ts +89 -0
- package/src/react/createAbloReact.ts +116 -0
- package/src/react/internalContext.ts +38 -0
- package/src/react/useAblo.ts +280 -0
- package/src/react/useCurrentUserId.ts +17 -0
- package/src/react/useErrorListener.ts +22 -0
- package/src/react/useMutationFailureListener.ts +34 -0
- package/src/react/useMutators.ts +184 -0
- package/src/react/useSyncStatus.ts +42 -0
- package/src/react/useUndoScope.ts +143 -0
- package/src/react.ts +69 -0
- package/src/reactRuntime.ts +10 -0
- package/src/surface.ts +106 -0
- package/src/useReactive.ts +51 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The vocabulary a local transaction uses on the wire. This module defines the
|
|
3
|
+
* {@link QueuedMutation} record and the helpers that turn a transaction into a
|
|
4
|
+
* wire-safe commit operation: schema-field projection
|
|
5
|
+
* ({@link projectCommitPayload}), write-option projection
|
|
6
|
+
* ({@link applyWriteOptions}), foreign-key-aware priority scoring
|
|
7
|
+
* ({@link computePriorityScore}), and the structural checks used to classify
|
|
8
|
+
* transport errors. Nothing here holds queue state or timers, so the batched
|
|
9
|
+
* queue path and the HTTP commit path share the same projection.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { globalRuntime } from '../../context.js';
|
|
13
|
+
import type { RuntimeContext } from '../../RuntimeContext.js';
|
|
14
|
+
import { MutationOperationType } from '@abloatai/transaction/types';
|
|
15
|
+
import { snapshotJsonValue } from '@abloatai/transaction/utils/json';
|
|
16
|
+
import type { OnStaleMode } from '@abloatai/transaction/coordination/schema';
|
|
17
|
+
import type { MutationOptions, WriteOptions } from '../../interfaces/index.js';
|
|
18
|
+
import type { CommitEnvelopeMember } from '@abloatai/transaction/transactions/settlement/commitEnvelope';
|
|
19
|
+
|
|
20
|
+
export interface UserContext {
|
|
21
|
+
userId: string;
|
|
22
|
+
organizationId: string;
|
|
23
|
+
role?: string;
|
|
24
|
+
teamIds?: string[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Wire-format mutation payload (post-projection). */
|
|
28
|
+
export type MutationInput = Record<string, unknown>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Framework-internal keys added by `Model.toJSON()` that must never
|
|
32
|
+
* reach the wire. The server treats each top-level key as a target
|
|
33
|
+
* column, so shipping these would blow up the INSERT/UPDATE.
|
|
34
|
+
*/
|
|
35
|
+
const FRAMEWORK_KEYS = new Set(['__class', '__typename', 'clientId', 'syncStatus']);
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Projects a model's serialized data onto the fields declared in its schema and
|
|
39
|
+
* returns a wire-safe commit payload. It does two things:
|
|
40
|
+
*
|
|
41
|
+
* 1. Drops framework-internal keys (`__class`, `__typename`, `clientId`,
|
|
42
|
+
* `syncStatus`) and anything not declared on the model's schema.
|
|
43
|
+
* 2. Takes a fresh plain JSON snapshot of the projected values. JSON-typed
|
|
44
|
+
* fields stay objects rather than pre-serialized strings, while reactive
|
|
45
|
+
* proxies cannot leak into persistence or the wire payload.
|
|
46
|
+
*
|
|
47
|
+
* For updates (`dropUndefined: true`), `undefined` values are also removed so
|
|
48
|
+
* they are not written as `SET column = NULL` on the server.
|
|
49
|
+
*
|
|
50
|
+
* Field metadata comes from the model registry, populated when the schema is
|
|
51
|
+
* registered at initialization. If a model has no registered field metadata —
|
|
52
|
+
* for example a manually registered model — projection snapshots all serialized
|
|
53
|
+
* data apart from the framework keys.
|
|
54
|
+
*/
|
|
55
|
+
export function projectCommitPayload(
|
|
56
|
+
modelName: string,
|
|
57
|
+
source: Record<string, unknown>,
|
|
58
|
+
opts: { dropUndefined: boolean },
|
|
59
|
+
runtime: RuntimeContext = globalRuntime,
|
|
60
|
+
): MutationInput {
|
|
61
|
+
const metadata = runtime.getModelMetadata(modelName);
|
|
62
|
+
const fields = metadata?.fields;
|
|
63
|
+
const out: MutationInput = {};
|
|
64
|
+
|
|
65
|
+
if (!fields) {
|
|
66
|
+
// Unknown registration — strip framework keys and ship the rest.
|
|
67
|
+
for (const [k, v] of Object.entries(source)) {
|
|
68
|
+
if (FRAMEWORK_KEYS.has(k)) continue;
|
|
69
|
+
if (opts.dropUndefined && v === undefined) continue;
|
|
70
|
+
out[k] = v;
|
|
71
|
+
}
|
|
72
|
+
return snapshotJsonValue(out, '$.input') as MutationInput;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
for (const key of Object.keys(fields)) {
|
|
76
|
+
if (!(key in source)) continue;
|
|
77
|
+
const value = source[key];
|
|
78
|
+
if (opts.dropUndefined && value === undefined) continue;
|
|
79
|
+
// JSON-typed fields (stored as jsonb on the server) are sent as objects,
|
|
80
|
+
// not pre-serialized strings. Pre-stringifying here corrupts a round trip:
|
|
81
|
+
//
|
|
82
|
+
// 1. The client stringifies `position: {x, y}` to `'{"x":...}'`.
|
|
83
|
+
// 2. The server writes it to the jsonb column, parsing the string, fine.
|
|
84
|
+
// 3. The server's delta echoes the input, where `position` is still the
|
|
85
|
+
// string from step 1.
|
|
86
|
+
// 4. The client merges the delta and sets `model.position` to that string.
|
|
87
|
+
// 5. The next edit spreads the string character by character, producing a
|
|
88
|
+
// corrupted, index-keyed object.
|
|
89
|
+
// 6. That corrupt object lands in the next commit and is stored in jsonb.
|
|
90
|
+
//
|
|
91
|
+
// Sending objects avoids the mismatch: the value travels through the delta
|
|
92
|
+
// and the commit unchanged, and the Postgres driver serializes a JS object
|
|
93
|
+
// to jsonb correctly once the column is identified as jsonb.
|
|
94
|
+
out[key] = value;
|
|
95
|
+
}
|
|
96
|
+
return snapshotJsonValue(out, '$.input') as MutationInput;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface QueuedMutation {
|
|
100
|
+
id: string;
|
|
101
|
+
type: 'create' | 'update' | 'delete' | 'archive' | 'unarchive';
|
|
102
|
+
modelName: string;
|
|
103
|
+
modelId: string;
|
|
104
|
+
modelKey: string;
|
|
105
|
+
data?: MutationInput;
|
|
106
|
+
previousData?: MutationInput | null;
|
|
107
|
+
context: UserContext;
|
|
108
|
+
status: 'pending' | 'executing' | 'awaiting_delta' | 'completed' | 'failed' | 'rolled_back';
|
|
109
|
+
createdAt: number;
|
|
110
|
+
attempts: number;
|
|
111
|
+
priority: 'normal' | 'high';
|
|
112
|
+
priorityScore: number; // foreign-key-aware priority, derived, used for sorting
|
|
113
|
+
writeOptions?: WriteOptions;
|
|
114
|
+
batchId?: string;
|
|
115
|
+
/**
|
|
116
|
+
* Stable identity of the wire commit that currently owns this operation.
|
|
117
|
+
*
|
|
118
|
+
* A transport failure is ambiguous: the server may have committed the
|
|
119
|
+
* batch even though the acknowledgement never reached this client. Keeping
|
|
120
|
+
* this envelope on every member lets the queue replay the exact same ordered
|
|
121
|
+
* batch with the exact same idempotency key instead of accidentally
|
|
122
|
+
* re-batching its operations under a fresh key.
|
|
123
|
+
*/
|
|
124
|
+
commitEnvelope?: CommitEnvelopeMember;
|
|
125
|
+
/** Pending-mutation journal entries atomically consumed by this envelope. */
|
|
126
|
+
sourceMutationIds?: string[];
|
|
127
|
+
/** Completed locally without a server operation; no sync echo will arrive. */
|
|
128
|
+
localOnly?: boolean;
|
|
129
|
+
/** Sync-id threshold: the transaction confirms once a delta with an id at least this value arrives. */
|
|
130
|
+
syncIdNeededForCompletion?: number;
|
|
131
|
+
/**
|
|
132
|
+
* Opaque customer-side batch identity returned with a queued source receipt.
|
|
133
|
+
* It is retained durably and is the only identity a live WAL delta may use
|
|
134
|
+
* to settle this pending commit. Server-side replay additionally proves the
|
|
135
|
+
* complete stored operation-id set before returning `confirmed`.
|
|
136
|
+
*/
|
|
137
|
+
correlationId?: string;
|
|
138
|
+
/**
|
|
139
|
+
* A queued forward has no authoritative sync-id watermark yet. It may only
|
|
140
|
+
* confirm when a WAL delta carries its opaque server-derived correlation;
|
|
141
|
+
* unrelated deltas must never satisfy it by advancing the global watermark.
|
|
142
|
+
*/
|
|
143
|
+
requiresCorrelatedDelta?: boolean;
|
|
144
|
+
/**
|
|
145
|
+
* Resolves once the server has confirmed this transaction, whether by a delta
|
|
146
|
+
* or an HTTP acknowledgement. It rejects with the originating error if the
|
|
147
|
+
* transaction is permanently rolled back; for a source-forwarded write it
|
|
148
|
+
* also rejects with `replication_lag_timeout` when the accepted write's WAL
|
|
149
|
+
* echo misses the confirmation deadline. That timeout does not roll back or
|
|
150
|
+
* fail the transaction: it remains pending and may confirm when replication
|
|
151
|
+
* recovers. This gives a caller one place to await the answer to "did my write
|
|
152
|
+
* land?", matching the
|
|
153
|
+
* `commits.create({ wait: 'confirmed' })` and
|
|
154
|
+
* {@link MutationQueue.waitForConfirmation} vocabulary, so a failure
|
|
155
|
+
* surfaces at the call site instead of only as a silent local rollback. The
|
|
156
|
+
* permanent-rejection value is the same {@link AbloError} carried on the
|
|
157
|
+
* queue's `transaction:failed` event.
|
|
158
|
+
*/
|
|
159
|
+
confirmation?: Promise<void>;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export const normalizeModelKey = (modelName: string): string =>
|
|
163
|
+
modelName.replace('Model', '').toLowerCase();
|
|
164
|
+
export const stripModelSuffix = (modelName: string): string => modelName.replace('Model', '');
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Returns the priority score used to order create operations by foreign-key
|
|
168
|
+
* depth, so a parent row commits before its children.
|
|
169
|
+
*
|
|
170
|
+
* The score comes from a priority map on the runtime configuration, built once
|
|
171
|
+
* at initialization by walking the schema's `belongsTo` graph. No model names
|
|
172
|
+
* are hard-coded here, and an application can override specific priorities
|
|
173
|
+
* through `configOverrides.modelCreatePriority`.
|
|
174
|
+
*
|
|
175
|
+
* Non-create operations (update, delete, archive, unarchive) need no
|
|
176
|
+
* foreign-key ordering because the row already exists, so they all share the
|
|
177
|
+
* configured default non-create priority.
|
|
178
|
+
*/
|
|
179
|
+
export const computePriorityScore = (
|
|
180
|
+
type: QueuedMutation['type'],
|
|
181
|
+
modelName: string,
|
|
182
|
+
runtime: RuntimeContext = globalRuntime,
|
|
183
|
+
): number => {
|
|
184
|
+
const { modelCreatePriority, defaultCreatePriority, defaultNonCreatePriority } =
|
|
185
|
+
runtime.config;
|
|
186
|
+
if (type !== 'create') return defaultNonCreatePriority;
|
|
187
|
+
return modelCreatePriority.get(modelName) ?? defaultCreatePriority;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
export const TX_TYPE_TO_MUTATION_OP: Record<QueuedMutation['type'], MutationOperationType> = {
|
|
191
|
+
create: MutationOperationType.CREATE,
|
|
192
|
+
update: MutationOperationType.UPDATE,
|
|
193
|
+
delete: MutationOperationType.DELETE,
|
|
194
|
+
archive: MutationOperationType.ARCHIVE,
|
|
195
|
+
unarchive: MutationOperationType.UNARCHIVE,
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
export function hasStaleWriteOptions(options?: WriteOptions): boolean {
|
|
199
|
+
return (
|
|
200
|
+
options?.readAt !== undefined ||
|
|
201
|
+
options?.onStale !== undefined
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** Options whose identity/audit semantics forbid merging two caller writes. */
|
|
206
|
+
export function hasCommitCoalescingBarrier(options?: WriteOptions): boolean {
|
|
207
|
+
return (
|
|
208
|
+
hasStaleWriteOptions(options) ||
|
|
209
|
+
typeof options?.idempotencyKey === 'string' ||
|
|
210
|
+
typeof options?.label === 'string'
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export interface WriteOperationFields {
|
|
215
|
+
readAt?: number | null;
|
|
216
|
+
onStale?: OnStaleMode | null;
|
|
217
|
+
fenceToken?: number | null;
|
|
218
|
+
options?: Pick<MutationOptions, 'idempotencyKey' | 'label'>;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Copies a transaction's `writeOptions` onto the wire operation. The
|
|
223
|
+
* stale-context guards (`readAt` and `onStale`) sit at the operation's root,
|
|
224
|
+
* while `idempotencyKey` and `label` go in its `options` slot — the
|
|
225
|
+
* `mutation_log` cache key and audit tag. This is the one place caller-supplied
|
|
226
|
+
* write options cross onto the wire.
|
|
227
|
+
*/
|
|
228
|
+
export function applyWriteOptions<T extends object>(
|
|
229
|
+
op: T,
|
|
230
|
+
transaction: QueuedMutation,
|
|
231
|
+
): T & WriteOperationFields {
|
|
232
|
+
const operation = op as T & WriteOperationFields;
|
|
233
|
+
const writeOptions = transaction.writeOptions;
|
|
234
|
+
if (!writeOptions) return operation;
|
|
235
|
+
if (writeOptions.readAt !== undefined) {
|
|
236
|
+
operation.readAt = writeOptions.readAt;
|
|
237
|
+
}
|
|
238
|
+
if (writeOptions.onStale !== undefined) {
|
|
239
|
+
operation.onStale = writeOptions.onStale;
|
|
240
|
+
}
|
|
241
|
+
if (writeOptions.fenceToken !== undefined) {
|
|
242
|
+
operation.fenceToken = writeOptions.fenceToken;
|
|
243
|
+
}
|
|
244
|
+
if (writeOptions.idempotencyKey != null || writeOptions.label !== undefined) {
|
|
245
|
+
operation.options = {
|
|
246
|
+
...(writeOptions.idempotencyKey != null
|
|
247
|
+
? { idempotencyKey: writeOptions.idempotencyKey }
|
|
248
|
+
: {}),
|
|
249
|
+
...(writeOptions.label !== undefined ? { label: writeOptions.label } : {}),
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
return operation;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* The structural shape used to inspect transport-layer errors. It covers the
|
|
257
|
+
* GraphQL-style and HTTP-style error shapes the mutation executor can surface,
|
|
258
|
+
* and is kept intentionally narrow so it does not claim fields the runtime may
|
|
259
|
+
* not supply.
|
|
260
|
+
*/
|
|
261
|
+
export interface TransportError {
|
|
262
|
+
message?: string;
|
|
263
|
+
code?: string | number;
|
|
264
|
+
extensions?: Record<string, unknown>;
|
|
265
|
+
locations?: readonly unknown[];
|
|
266
|
+
path?: readonly (string | number)[];
|
|
267
|
+
response?: {
|
|
268
|
+
status?: number;
|
|
269
|
+
errors?: readonly { extensions?: { code?: string }; message?: string }[];
|
|
270
|
+
};
|
|
271
|
+
// Some executors stash a wrapped server message under `error`.
|
|
272
|
+
error?: string;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export function asTransportError(value: unknown): TransportError {
|
|
276
|
+
return (value && typeof value === 'object' ? value : {});
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export function extractStatusCode(error: unknown): number | undefined {
|
|
280
|
+
return asTransportError(error).response?.status;
|
|
281
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import type { RuntimeContext } from '../../RuntimeContext.js';
|
|
2
|
+
import type { MutationExecutor } from '../../interfaces/index.js';
|
|
3
|
+
import type { ReadDependency, TrackDependency } from '@abloatai/transaction/coordination/schema';
|
|
4
|
+
import {
|
|
5
|
+
AbloConnectionError,
|
|
6
|
+
AbloError,
|
|
7
|
+
AbloIdempotencyError,
|
|
8
|
+
} from '@abloatai/transaction/errors';
|
|
9
|
+
import {
|
|
10
|
+
mutationCommitResultSchema,
|
|
11
|
+
type MutationCommitResult,
|
|
12
|
+
} from '@abloatai/transaction/wire/commit';
|
|
13
|
+
import {
|
|
14
|
+
createDurableCommitEnvelope,
|
|
15
|
+
commitEnvelopeRecordId,
|
|
16
|
+
durableCommitEnvelopeSchema,
|
|
17
|
+
type CommitOutboxScope,
|
|
18
|
+
type DurableCommitEnvelope,
|
|
19
|
+
type DurableCommitOperation,
|
|
20
|
+
} from '@abloatai/transaction/transactions/settlement/commitEnvelope';
|
|
21
|
+
import type { DurableWriteStore } from './durableWriteStore.js';
|
|
22
|
+
|
|
23
|
+
export interface CommitTransportContext {
|
|
24
|
+
readonly runtime: RuntimeContext;
|
|
25
|
+
readonly config: {
|
|
26
|
+
enablePersistence: boolean;
|
|
27
|
+
commitDispatchTimeoutMs: number;
|
|
28
|
+
};
|
|
29
|
+
readonly commitOutbox: DurableWriteStore | null;
|
|
30
|
+
readonly commitOutboxScope: CommitOutboxScope | null;
|
|
31
|
+
readonly mutationExecutor: MutationExecutor;
|
|
32
|
+
readonly emitCommitLifecycle: (event: string, payload: object) => void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface SealDurableCommitInput {
|
|
36
|
+
idempotencyKey: string;
|
|
37
|
+
origin: 'model_batch' | 'atomic_commit';
|
|
38
|
+
operations: DurableCommitOperationInput[];
|
|
39
|
+
sourceMutationIds?: string[];
|
|
40
|
+
commitOptions?: {
|
|
41
|
+
reads?: readonly ReadDependency[] | null;
|
|
42
|
+
track?: readonly TrackDependency[] | null;
|
|
43
|
+
};
|
|
44
|
+
createdAt: number;
|
|
45
|
+
sealedAt: number;
|
|
46
|
+
sequence?: number;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type DurableCommitOperationInput = DurableCommitOperation;
|
|
50
|
+
|
|
51
|
+
export async function sealDurableCommit(
|
|
52
|
+
ctx: CommitTransportContext,
|
|
53
|
+
input: SealDurableCommitInput,
|
|
54
|
+
pendingMutationRecordId: (id: string) => string,
|
|
55
|
+
): Promise<DurableCommitEnvelope> {
|
|
56
|
+
const sourceMutationIds = [...new Set(input.sourceMutationIds ?? [])];
|
|
57
|
+
const envelope = createDurableCommitEnvelope({
|
|
58
|
+
idempotencyKey: input.idempotencyKey,
|
|
59
|
+
origin: input.origin,
|
|
60
|
+
operations: [...input.operations],
|
|
61
|
+
sourceMutationIds,
|
|
62
|
+
commitOptions: {
|
|
63
|
+
...(input.commitOptions?.reads !== undefined
|
|
64
|
+
? { reads: input.commitOptions.reads === null ? null : [...input.commitOptions.reads] }
|
|
65
|
+
: {}),
|
|
66
|
+
...(input.commitOptions?.track !== undefined
|
|
67
|
+
? { track: input.commitOptions.track === null ? null : [...input.commitOptions.track] }
|
|
68
|
+
: {}),
|
|
69
|
+
},
|
|
70
|
+
...(ctx.commitOutboxScope ? { scope: ctx.commitOutboxScope } : {}),
|
|
71
|
+
createdAt: input.createdAt,
|
|
72
|
+
sealedAt: input.sealedAt,
|
|
73
|
+
sequence: input.sequence ?? input.sealedAt * 1_000,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
if (ctx.config.enablePersistence && ctx.commitOutbox) {
|
|
77
|
+
try {
|
|
78
|
+
await ctx.commitOutbox.seal(envelope, sourceMutationIds.map(pendingMutationRecordId));
|
|
79
|
+
} catch (cause) {
|
|
80
|
+
if (cause instanceof AbloError) throw cause;
|
|
81
|
+
throw new AbloConnectionError('Could not persist the durable write before dispatch', {
|
|
82
|
+
code: 'db_not_opened',
|
|
83
|
+
cause,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
ctx.emitCommitLifecycle('commit:envelope_persisted', {
|
|
87
|
+
idempotencyKey: envelope.idempotencyKey,
|
|
88
|
+
sourceMutationIds: envelope.sourceMutationIds,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return envelope;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export async function removeDurableCommit(
|
|
95
|
+
ctx: CommitTransportContext,
|
|
96
|
+
idempotencyKey: string,
|
|
97
|
+
): Promise<void> {
|
|
98
|
+
if (!ctx.config.enablePersistence || !ctx.commitOutbox) return;
|
|
99
|
+
try {
|
|
100
|
+
await ctx.commitOutbox.remove(commitEnvelopeRecordId(idempotencyKey));
|
|
101
|
+
} catch (error) {
|
|
102
|
+
ctx.runtime.logger.debug('[MutationQueue] Durable-write cleanup deferred', {
|
|
103
|
+
idempotencyKey,
|
|
104
|
+
error: error instanceof Error ? error.message : String(error),
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export async function persistDurableCommitAcceptance(
|
|
110
|
+
ctx: CommitTransportContext,
|
|
111
|
+
envelope: DurableCommitEnvelope,
|
|
112
|
+
result: MutationCommitResult,
|
|
113
|
+
): Promise<DurableCommitEnvelope> {
|
|
114
|
+
if (result.status !== 'queued') return envelope;
|
|
115
|
+
const correlationId = result.correlationId;
|
|
116
|
+
if (!correlationId) {
|
|
117
|
+
throw new AbloConnectionError('The source accepted the commit without durable correlation evidence.', {
|
|
118
|
+
code: 'commit_no_result',
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
if (envelope.correlationId !== undefined && envelope.correlationId !== correlationId) {
|
|
122
|
+
throw new AbloIdempotencyError('The same commit replay returned a different source correlation.', {
|
|
123
|
+
code: 'idempotency_conflict',
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
if (envelope.acceptedAt !== undefined) return envelope;
|
|
127
|
+
const accepted = durableCommitEnvelopeSchema.parse({
|
|
128
|
+
...envelope,
|
|
129
|
+
acceptedAt: Math.max(Date.now(), envelope.sealedAt),
|
|
130
|
+
correlationId,
|
|
131
|
+
});
|
|
132
|
+
if (ctx.config.enablePersistence && ctx.commitOutbox) {
|
|
133
|
+
try {
|
|
134
|
+
await ctx.commitOutbox.seal(accepted, []);
|
|
135
|
+
} catch (cause) {
|
|
136
|
+
if (cause instanceof AbloError) throw cause;
|
|
137
|
+
throw new AbloConnectionError(
|
|
138
|
+
'The source accepted the commit, but that acceptance could not be persisted locally.',
|
|
139
|
+
{ code: 'db_not_opened', cause },
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return accepted;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function parseMutationCommitResult(
|
|
147
|
+
value: Awaited<ReturnType<MutationExecutor['commit']>>,
|
|
148
|
+
): MutationCommitResult {
|
|
149
|
+
const parsed = mutationCommitResultSchema.safeParse(value);
|
|
150
|
+
if (parsed.success) return parsed.data;
|
|
151
|
+
throw new AbloConnectionError(
|
|
152
|
+
'The mutation transport returned an invalid commit receipt; its outcome remains pending and is safe to retry.',
|
|
153
|
+
{ code: 'commit_no_result', cause: parsed.error },
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function dispatchCommitBounded(
|
|
158
|
+
ctx: CommitTransportContext,
|
|
159
|
+
...args: Parameters<MutationExecutor['commit']>
|
|
160
|
+
): ReturnType<MutationExecutor['commit']> {
|
|
161
|
+
const dispatched = ctx.mutationExecutor.commit(...args);
|
|
162
|
+
const timeoutMs = ctx.config.commitDispatchTimeoutMs;
|
|
163
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) return dispatched;
|
|
164
|
+
return new Promise((resolve, reject) => {
|
|
165
|
+
const timer = setTimeout(() => reject(new AbloConnectionError(
|
|
166
|
+
'The mutation transport did not acknowledge the commit in time; its outcome remains pending and is safe to retry.',
|
|
167
|
+
{ code: 'commit_no_result' },
|
|
168
|
+
)), timeoutMs);
|
|
169
|
+
dispatched.then(
|
|
170
|
+
(value) => { clearTimeout(timer); resolve(value); },
|
|
171
|
+
(error) => { clearTimeout(timer); reject(error instanceof Error ? error : new Error(String(error))); },
|
|
172
|
+
);
|
|
173
|
+
});
|
|
174
|
+
}
|