@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,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An {@link OnlineStatusProvider} that always reports the client as online.
|
|
3
|
+
* Server-side runtimes — Node processes, agents, and sidecars — have no
|
|
4
|
+
* browser network stack to lose, so there is no offline state to track. A
|
|
5
|
+
* dropped database connection surfaces as a database error, not a network
|
|
6
|
+
* transition. This is the server-side counterpart to the browser's
|
|
7
|
+
* connectivity-aware provider, which watches the real online/offline signal.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { OnlineStatusProvider } from '../interfaces/index.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Returns an OnlineStatusProvider that always reports online.
|
|
14
|
+
* `onStatusChange` never fires — the network never transitions.
|
|
15
|
+
*/
|
|
16
|
+
export function alwaysOnline(): OnlineStatusProvider {
|
|
17
|
+
return {
|
|
18
|
+
isOnline: () => true,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An in-memory {@link ObjectStoreContract} implementation for runtimes
|
|
3
|
+
* without IndexedDB, such as Node processes, agents, and tests. It keeps
|
|
4
|
+
* records in a map and maintains simple secondary indexes, satisfying the
|
|
5
|
+
* same contract the IndexedDB-backed store implements — so if the two ever
|
|
6
|
+
* diverge, the mismatch becomes a typecheck error here rather than a silent
|
|
7
|
+
* failure at a call site.
|
|
8
|
+
*
|
|
9
|
+
* Nothing is persisted; the data is cleared on process restart. That is
|
|
10
|
+
* deliberate: server-side runtimes and agent workers rebuild their state from
|
|
11
|
+
* the server's delta stream rather than from a local cache.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { ObjectStoreContract } from '../stores/ObjectStoreContract.js';
|
|
15
|
+
|
|
16
|
+
export class InMemoryObjectStore implements ObjectStoreContract {
|
|
17
|
+
private data = new Map<string, Record<string, unknown>>();
|
|
18
|
+
private indexes = new Map<string, Map<string, Set<string>>>();
|
|
19
|
+
|
|
20
|
+
constructor(
|
|
21
|
+
public readonly modelName: string,
|
|
22
|
+
public readonly storeName: string,
|
|
23
|
+
indexNames: string[] = [],
|
|
24
|
+
) {
|
|
25
|
+
for (const name of indexNames) {
|
|
26
|
+
this.indexes.set(name, new Map());
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
add(record: Record<string, unknown>): Promise<void> {
|
|
31
|
+
const id = record.id as string;
|
|
32
|
+
if (!id) throw new TypeError('In-memory record must carry an id');
|
|
33
|
+
if (this.data.has(id)) {
|
|
34
|
+
const error = new Error(`Record already exists: ${id}`);
|
|
35
|
+
error.name = 'ConstraintError';
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
this.data.set(id, { ...record });
|
|
39
|
+
this.addToIndexes(id, record);
|
|
40
|
+
return Promise.resolve();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
put(record: Record<string, unknown>): Promise<void> {
|
|
44
|
+
this.putSync(record);
|
|
45
|
+
return Promise.resolve();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Synchronous fast path used by Database.processDeltaBatch in memory mode. */
|
|
49
|
+
putSync(record: Record<string, unknown>): void {
|
|
50
|
+
const id = record.id as string;
|
|
51
|
+
if (!id) return;
|
|
52
|
+
|
|
53
|
+
// Remove from old index entries if updating
|
|
54
|
+
const existing = this.data.get(id);
|
|
55
|
+
if (existing) {
|
|
56
|
+
this.removeFromIndexes(id, existing);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
this.data.set(id, { ...record });
|
|
60
|
+
this.addToIndexes(id, record);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
get(id: string): Promise<Record<string, unknown> | undefined> {
|
|
64
|
+
return Promise.resolve(this.getSync(id));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Synchronous fast path used by Database.processDeltaBatch in memory mode. */
|
|
68
|
+
getSync(id: string): Record<string, unknown> | undefined {
|
|
69
|
+
return this.data.get(id);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
getAll(): Promise<Record<string, unknown>[]> {
|
|
73
|
+
return Promise.resolve([...this.data.values()]);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
delete(id: string): Promise<void> {
|
|
77
|
+
this.deleteSync(id);
|
|
78
|
+
return Promise.resolve();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Synchronous fast path used by Database.processDeltaBatch in memory mode. */
|
|
82
|
+
deleteSync(id: string): void {
|
|
83
|
+
const existing = this.data.get(id);
|
|
84
|
+
if (existing) {
|
|
85
|
+
this.removeFromIndexes(id, existing);
|
|
86
|
+
this.data.delete(id);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
getAllFromIndex(
|
|
91
|
+
indexName: string,
|
|
92
|
+
value: IDBValidKey,
|
|
93
|
+
): Promise<Record<string, unknown>[]> {
|
|
94
|
+
const index = this.indexes.get(indexName);
|
|
95
|
+
if (!index) return Promise.resolve([]);
|
|
96
|
+
// The in-memory index stores values as strings (it doesn't support
|
|
97
|
+
// the full IDB key range — Date / BufferSource / arrays). For the
|
|
98
|
+
// overwhelmingly-common case of string FK ids, coercing through
|
|
99
|
+
// String() preserves the existing behavior while satisfying the
|
|
100
|
+
// shared `ObjectStoreContract` signature.
|
|
101
|
+
const ids = index.get(String(value));
|
|
102
|
+
if (!ids) return Promise.resolve([]);
|
|
103
|
+
return Promise.resolve(
|
|
104
|
+
[...ids]
|
|
105
|
+
.map((id) => this.data.get(id))
|
|
106
|
+
.filter((r): r is Record<string, unknown> => r != null),
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
clear(): Promise<void> {
|
|
111
|
+
this.data.clear();
|
|
112
|
+
for (const index of this.indexes.values()) {
|
|
113
|
+
index.clear();
|
|
114
|
+
}
|
|
115
|
+
return Promise.resolve();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** No-op — in-memory stores don't need closing. */
|
|
119
|
+
markAsClosing(): void {}
|
|
120
|
+
|
|
121
|
+
private addToIndexes(id: string, record: Record<string, unknown>): void {
|
|
122
|
+
for (const [indexName, indexMap] of this.indexes) {
|
|
123
|
+
const value = record[indexName];
|
|
124
|
+
if (value != null) {
|
|
125
|
+
const key = String(value);
|
|
126
|
+
if (!indexMap.has(key)) indexMap.set(key, new Set());
|
|
127
|
+
indexMap.get(key)!.add(id);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
private removeFromIndexes(id: string, record: Record<string, unknown>): void {
|
|
133
|
+
for (const [indexName, indexMap] of this.indexes) {
|
|
134
|
+
const value = record[indexName];
|
|
135
|
+
if (value != null) {
|
|
136
|
+
const key = String(value);
|
|
137
|
+
indexMap.get(key)?.delete(id);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The prelude every interactive client resolves before anything is constructed.
|
|
3
|
+
*
|
|
4
|
+
* One pass over the options bag settles the values the composition root then
|
|
5
|
+
* spends: the credential and its refresh resolver, the base URL, the logger,
|
|
6
|
+
* and this participant's identity. Nothing here opens a socket, allocates a
|
|
7
|
+
* store, or touches IndexedDB — so a misconfiguration (a secret key in the
|
|
8
|
+
* browser, the removed `databaseUrl` option, a CLI key pointing at another
|
|
9
|
+
* project) fails while the stack still points at the caller's own setup.
|
|
10
|
+
*
|
|
11
|
+
* `./Ablo.ts` calls this once and hands the result to whichever client the
|
|
12
|
+
* plugin list selected.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import type { ParticipantKind } from '@abloatai/transaction/types/participant';
|
|
16
|
+
import type { Logger } from '@abloatai/transaction/logger';
|
|
17
|
+
import type { SchemaRecord } from '@abloatai/transaction/schema/schema';
|
|
18
|
+
import {
|
|
19
|
+
createAuthCredentialSource,
|
|
20
|
+
type AuthCredentialSource,
|
|
21
|
+
} from '@abloatai/transaction/auth/credentialSource';
|
|
22
|
+
import {
|
|
23
|
+
assertBrowserSafety,
|
|
24
|
+
readProcessEnv,
|
|
25
|
+
rejectRemovedDatabaseUrlOption,
|
|
26
|
+
resolveApiKey,
|
|
27
|
+
resolveAuthToken,
|
|
28
|
+
resolveBaseURL,
|
|
29
|
+
resolveCredentialResolver,
|
|
30
|
+
warnIfCliKeyMismatch,
|
|
31
|
+
type CredentialProvider,
|
|
32
|
+
} from '@abloatai/transaction/auth/apiKey';
|
|
33
|
+
import type { AbloOptions, InternalAbloOptions } from './options.js';
|
|
34
|
+
import { createConsoleLogger, resolveLogLevel } from './consoleLogger.js';
|
|
35
|
+
|
|
36
|
+
/** What one pass over the options bag settles, for the builders downstream. */
|
|
37
|
+
export interface ClientPrelude<S extends SchemaRecord> {
|
|
38
|
+
/** The same options, widened to the fields only the SDK's own callers set. */
|
|
39
|
+
readonly internalOptions: InternalAbloOptions<S>;
|
|
40
|
+
/** The configured key — a literal key string, or a resolver to call. */
|
|
41
|
+
readonly configuredApiKey: string | CredentialProvider | null;
|
|
42
|
+
readonly configuredAuthToken: string | null;
|
|
43
|
+
/**
|
|
44
|
+
* The credential lifecycle's single resolver, or `null` when auth is static.
|
|
45
|
+
* It drives both the reactive re-mint (the connection's `credential_stale`
|
|
46
|
+
* state) and the proactive refresh timer with its wake/online/focus triggers.
|
|
47
|
+
*/
|
|
48
|
+
readonly credentialResolver: CredentialProvider | null;
|
|
49
|
+
readonly authCredentials: AuthCredentialSource;
|
|
50
|
+
readonly logger: Logger;
|
|
51
|
+
readonly url: string;
|
|
52
|
+
/**
|
|
53
|
+
* Identity routing: agents identify by agentId, users by user.id. The server
|
|
54
|
+
* stamps `isAgent` on outbound presence frames from the connection's
|
|
55
|
+
* authenticated identity prefix; the local `self` entry uses the kind we know
|
|
56
|
+
* at construction.
|
|
57
|
+
*/
|
|
58
|
+
readonly participantId: string;
|
|
59
|
+
readonly kind: ParticipantKind;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Resolve the prelude, failing fast on a misconfiguration.
|
|
64
|
+
*
|
|
65
|
+
* Three checks fire here rather than downstream: a secret key reaching the
|
|
66
|
+
* browser, the removed `databaseUrl` option, and a CLI key scoped to a
|
|
67
|
+
* different project than the one being addressed (a warning, not a throw).
|
|
68
|
+
*/
|
|
69
|
+
export function resolveClientPrelude<S extends SchemaRecord>(
|
|
70
|
+
options: AbloOptions<S>,
|
|
71
|
+
): ClientPrelude<S> {
|
|
72
|
+
const internalOptions = options as InternalAbloOptions<S>;
|
|
73
|
+
const env = readProcessEnv();
|
|
74
|
+
const authInput = { options, env };
|
|
75
|
+
const configuredApiKey = resolveApiKey(authInput);
|
|
76
|
+
const configuredAuthToken = resolveAuthToken(authInput);
|
|
77
|
+
const credentialResolver = resolveCredentialResolver(configuredApiKey);
|
|
78
|
+
const authCredentials = createAuthCredentialSource(
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated -- load-bearing on the self-hosted path; server-internal cap-mint (Phase 3) not shipped
|
|
80
|
+
internalOptions.capabilityToken ?? configuredAuthToken,
|
|
81
|
+
);
|
|
82
|
+
rejectRemovedDatabaseUrlOption(options);
|
|
83
|
+
assertBrowserSafety({
|
|
84
|
+
apiKey: configuredApiKey,
|
|
85
|
+
dangerouslyAllowBrowser: options.dangerouslyAllowBrowser,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// Custom logger wins; otherwise build the default `[Ablo]` logger at the level
|
|
89
|
+
// resolved from `debug`/`logLevel`/`ABLO_LOG_LEVEL` (default `warn`).
|
|
90
|
+
const logger =
|
|
91
|
+
internalOptions.logger ??
|
|
92
|
+
createConsoleLogger(resolveLogLevel({ debug: options.debug, logLevel: options.logLevel }));
|
|
93
|
+
void warnIfCliKeyMismatch(authInput, (m) => { logger.warn(m); });
|
|
94
|
+
|
|
95
|
+
const participantId =
|
|
96
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated -- self-hosted identity fallback; hosted path derives identity from the apiKey scope
|
|
97
|
+
(internalOptions.kind === 'agent' ? internalOptions.agentId : internalOptions.user?.id) ?? '';
|
|
98
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated -- self-hosted default; hosted path ignores it (server derives kind from the apiKey scope)
|
|
99
|
+
const kind = internalOptions.kind ?? 'user';
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
internalOptions,
|
|
103
|
+
configuredApiKey,
|
|
104
|
+
configuredAuthToken,
|
|
105
|
+
credentialResolver,
|
|
106
|
+
authCredentials,
|
|
107
|
+
logger,
|
|
108
|
+
url: resolveBaseURL(authInput),
|
|
109
|
+
participantId,
|
|
110
|
+
kind,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The default `[Ablo]` console logger and its level resolution.
|
|
3
|
+
*
|
|
4
|
+
* These helpers are exported so any entry point that needs a default logger can
|
|
5
|
+
* reuse the same level gating rather than hand-rolling a console wrapper.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { Logger } from '@abloatai/transaction/logger';
|
|
9
|
+
|
|
10
|
+
// ── Default console logger ────────────────────────────────────────────────
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Level threshold for the default console logger.
|
|
14
|
+
*
|
|
15
|
+
* The SDK emits a `debug` line per model and per property during schema
|
|
16
|
+
* registration (see `ModelRegistry`), plus assorted lifecycle chatter. That
|
|
17
|
+
* is verbose by design but carries no actionable signal for app consumers, so
|
|
18
|
+
* the default threshold is `warn` — `debug`/`info` are dropped unless a
|
|
19
|
+
* consumer opts in.
|
|
20
|
+
*
|
|
21
|
+
* Opt back in with `ABLO_LOG_LEVEL=debug` (or `info`/`warn`/`error`/`silent`).
|
|
22
|
+
* Passing a custom `logger` to `Ablo({ logger })` bypasses this entirely.
|
|
23
|
+
*/
|
|
24
|
+
export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent';
|
|
25
|
+
const LOG_LEVEL_RANK: Record<LogLevel, number> = { debug: 10, info: 20, warn: 30, error: 40, silent: 99 };
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Resolve the effective level. Precedence: explicit `logLevel` option →
|
|
29
|
+
* `debug: true` (⇒ debug) → `ABLO_LOG_LEVEL` env → default `warn`. `debug: false`
|
|
30
|
+
* / omitted just means "don't raise the level" — it falls through to env/default
|
|
31
|
+
* rather than force-silencing an ops-set env override.
|
|
32
|
+
*/
|
|
33
|
+
export function resolveLogLevel(opts?: { debug?: boolean; logLevel?: LogLevel }): LogLevel {
|
|
34
|
+
if (opts?.logLevel && opts.logLevel in LOG_LEVEL_RANK) return opts.logLevel;
|
|
35
|
+
if (opts?.debug === true) return 'debug';
|
|
36
|
+
// `globalThis.process` guard keeps this safe in browser/edge runtimes that
|
|
37
|
+
// have no `process` binding — there we fall through to the default.
|
|
38
|
+
const raw = (globalThis as { process?: { env?: Record<string, string | undefined> } }).process?.env?.ABLO_LOG_LEVEL;
|
|
39
|
+
const normalized = raw?.toLowerCase();
|
|
40
|
+
if (normalized && normalized in LOG_LEVEL_RANK) return normalized as LogLevel;
|
|
41
|
+
return 'warn';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Builds the default logger, gated at `level` and prefixed `[Ablo]` so its lines
|
|
46
|
+
* stand out in a console full of other tools' output.
|
|
47
|
+
*/
|
|
48
|
+
export function createConsoleLogger(level: LogLevel): Logger {
|
|
49
|
+
const threshold = LOG_LEVEL_RANK[level];
|
|
50
|
+
const emit = (lvl: LogLevel, fn: (...args: unknown[]) => void, args: unknown[]) => {
|
|
51
|
+
if (typeof console === 'undefined' || LOG_LEVEL_RANK[lvl] < threshold) return;
|
|
52
|
+
fn('[Ablo]', ...args);
|
|
53
|
+
};
|
|
54
|
+
return {
|
|
55
|
+
debug: (...args: unknown[]) => { emit('debug', console.debug, args); },
|
|
56
|
+
info: (...args: unknown[]) => { emit('info', console.info, args); },
|
|
57
|
+
warn: (...args: unknown[]) => { emit('warn', console.warn, args); },
|
|
58
|
+
error: (...args: unknown[]) => { emit('error', console.error, args); },
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds the internal component graph the client runs on.
|
|
3
|
+
*
|
|
4
|
+
* From the caller's options and schema this wires together the model registry,
|
|
5
|
+
* object pool, bootstrap helper, database, sync client, and hydration
|
|
6
|
+
* coordinator. Each component depends on the one before it, so construction
|
|
7
|
+
* order matters; keeping it here means the client constructor does not have to
|
|
8
|
+
* know that order.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { Database } from '../Database.js';
|
|
12
|
+
import { ModelRegistry, setActiveRegistry } from '../ModelRegistry.js';
|
|
13
|
+
import { InstanceCache } from '../InstanceCache.js';
|
|
14
|
+
import { SyncClient } from '../SyncClient.js';
|
|
15
|
+
import { OnDemandLoader } from '../sync/OnDemandLoader.js';
|
|
16
|
+
import { BootstrapFetcher } from '../sync/BootstrapFetcher.js';
|
|
17
|
+
import type { AuthCredentialSource } from '@abloatai/transaction/auth/credentialSource';
|
|
18
|
+
import type { Schema, SchemaRecord } from '@abloatai/transaction/schema/schema';
|
|
19
|
+
import { loadsAtBootstrap, type LoadStrategy } from '@abloatai/transaction/schema/loadStrategy';
|
|
20
|
+
import { resolveBootstrapBaseUrl } from '@abloatai/transaction/auth/apiKey';
|
|
21
|
+
import {
|
|
22
|
+
shouldUseInMemoryPersistence,
|
|
23
|
+
type AbloPersistence,
|
|
24
|
+
} from '../persistence.js';
|
|
25
|
+
import type {
|
|
26
|
+
DurableWriteStore,
|
|
27
|
+
DurableWritesConfig,
|
|
28
|
+
} from '@abloatai/transaction/durableWrites';
|
|
29
|
+
import type { RuntimeContext } from '../RuntimeContext.js';
|
|
30
|
+
import { globalRuntime } from '../context.js';
|
|
31
|
+
import { resolveDurableWrites } from '@abloatai/transaction/durableWrites';
|
|
32
|
+
|
|
33
|
+
export interface InternalComponentsInput<S extends SchemaRecord> {
|
|
34
|
+
readonly schema: Schema<S>;
|
|
35
|
+
/** The WebSocket URL. Used to derive the bootstrap HTTP base URL when the
|
|
36
|
+
* caller has not overridden `bootstrapBaseUrl`. */
|
|
37
|
+
readonly url: string;
|
|
38
|
+
readonly options: {
|
|
39
|
+
readonly maxPoolSize?: number;
|
|
40
|
+
readonly bootstrapBaseUrl?: string;
|
|
41
|
+
readonly syncGroups?: string[];
|
|
42
|
+
readonly persistence?: AbloPersistence;
|
|
43
|
+
readonly offline?: boolean;
|
|
44
|
+
readonly inMemory?: boolean;
|
|
45
|
+
readonly durableWrites?: DurableWritesConfig;
|
|
46
|
+
/** @deprecated Use `durableWrites`. */
|
|
47
|
+
readonly commitOutbox?: DurableWriteStore;
|
|
48
|
+
};
|
|
49
|
+
readonly auth?: AuthCredentialSource;
|
|
50
|
+
/** The owning client's runtime, threaded into every component built here.
|
|
51
|
+
* Defaults to the module-global bridge for direct construction. */
|
|
52
|
+
readonly runtime?: RuntimeContext;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface InternalComponents {
|
|
56
|
+
readonly modelRegistry: ModelRegistry;
|
|
57
|
+
readonly objectPool: InstanceCache;
|
|
58
|
+
readonly bootstrapHelper: BootstrapFetcher;
|
|
59
|
+
readonly database: Database;
|
|
60
|
+
readonly syncClient: SyncClient;
|
|
61
|
+
readonly hydration: OnDemandLoader;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function createInternalComponents<S extends SchemaRecord>(
|
|
65
|
+
input: InternalComponentsInput<S>,
|
|
66
|
+
): InternalComponents {
|
|
67
|
+
const { schema, url, options, auth } = input;
|
|
68
|
+
const runtime = input.runtime ?? globalRuntime;
|
|
69
|
+
|
|
70
|
+
// The registry is created here, but model registration happens in the caller,
|
|
71
|
+
// which owns the schema-to-class translation.
|
|
72
|
+
const modelRegistry = new ModelRegistry({
|
|
73
|
+
validateOnRegister: false,
|
|
74
|
+
allowLateReferences: true,
|
|
75
|
+
runtime,
|
|
76
|
+
});
|
|
77
|
+
setActiveRegistry(modelRegistry);
|
|
78
|
+
|
|
79
|
+
const objectPool = new InstanceCache(
|
|
80
|
+
{ maxSize: options.maxPoolSize ?? 10000, runtime },
|
|
81
|
+
modelRegistry,
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const bootstrapBaseUrl = resolveBootstrapBaseUrl({
|
|
85
|
+
url,
|
|
86
|
+
bootstrapBaseUrl: options.bootstrapBaseUrl,
|
|
87
|
+
});
|
|
88
|
+
const bootstrapHelper = new BootstrapFetcher({
|
|
89
|
+
baseUrl: bootstrapBaseUrl,
|
|
90
|
+
syncGroups: options.syncGroups,
|
|
91
|
+
instantModels: deriveInstantModels(schema),
|
|
92
|
+
getAuthToken: auth?.getAuthToken,
|
|
93
|
+
runtime,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const database = new Database(modelRegistry, bootstrapHelper, {
|
|
97
|
+
// By default there is no browser-local durable store unless the caller asks
|
|
98
|
+
// for one. Node and edge runtimes always use the in-memory store because
|
|
99
|
+
// IndexedDB is unavailable there.
|
|
100
|
+
inMemory: shouldUseInMemoryPersistence(options),
|
|
101
|
+
runtime,
|
|
102
|
+
});
|
|
103
|
+
const durableWrites = resolveDurableWrites(options);
|
|
104
|
+
const syncClient = new SyncClient(
|
|
105
|
+
objectPool,
|
|
106
|
+
database,
|
|
107
|
+
durableWrites.store,
|
|
108
|
+
durableWrites.namespace ?? url,
|
|
109
|
+
runtime,
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
// Lazy-load lane: hydrates the object pool and IndexedDB on demand for
|
|
113
|
+
// entities not in scope at bootstrap (`load: 'lazy'` models, or an entity
|
|
114
|
+
// reached by deep link before the pool warmed up). Single-flight, with
|
|
115
|
+
// write-through to IndexedDB.
|
|
116
|
+
const hydration = new OnDemandLoader({
|
|
117
|
+
objectPool,
|
|
118
|
+
database,
|
|
119
|
+
registry: modelRegistry,
|
|
120
|
+
schema,
|
|
121
|
+
baseUrl: bootstrapBaseUrl,
|
|
122
|
+
getAuthToken: auth?.getAuthToken,
|
|
123
|
+
runtime,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// Drop the lazy-lane hydration ledger on reconnect. While connected, the
|
|
127
|
+
// WebSocket delta stream keeps hydrated rows fresh so repeat reads serve
|
|
128
|
+
// pure-local with no network; after a drop, deltas may have been missed, so
|
|
129
|
+
// the next read of each query must re-confirm with the server once.
|
|
130
|
+
syncClient.on('sync:reconnecting', () => { hydration.invalidate(); });
|
|
131
|
+
|
|
132
|
+
return {
|
|
133
|
+
modelRegistry,
|
|
134
|
+
objectPool,
|
|
135
|
+
bootstrapHelper,
|
|
136
|
+
database,
|
|
137
|
+
syncClient,
|
|
138
|
+
hydration,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Derives the set of models to fetch in the initial bootstrap request from each
|
|
144
|
+
* model's load strategy. Models declared `load: 'lazy'` are left out of the
|
|
145
|
+
* bootstrap and fetched on demand instead. The default strategy is
|
|
146
|
+
* `'instant'`, which includes the model.
|
|
147
|
+
*/
|
|
148
|
+
function deriveInstantModels<S extends SchemaRecord>(
|
|
149
|
+
schema: Schema<S>,
|
|
150
|
+
): string[] {
|
|
151
|
+
const schemaModels =
|
|
152
|
+
(schema as { models?: Record<string, unknown> }).models ?? schema;
|
|
153
|
+
return Object.entries(schemaModels).flatMap(([key, def]) => {
|
|
154
|
+
if (!def || typeof def !== 'object' || !('load' in def)) {
|
|
155
|
+
return [key]; // no load → the default strategy
|
|
156
|
+
}
|
|
157
|
+
const load = (def as { load?: LoadStrategy }).load;
|
|
158
|
+
if (loadsAtBootstrap(load)) {
|
|
159
|
+
return [(def as { typename?: string }).typename ?? key];
|
|
160
|
+
}
|
|
161
|
+
return [];
|
|
162
|
+
});
|
|
163
|
+
}
|