@abloatai/ablo 0.25.0 → 0.27.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 +5 -3
- package/CHANGELOG.md +34 -0
- package/README.md +104 -88
- package/dist/BaseSyncedStore.d.ts +140 -266
- package/dist/BaseSyncedStore.js +338 -739
- package/dist/Database.d.ts +62 -77
- package/dist/Database.js +106 -127
- package/dist/{ObjectPool.d.ts → InstanceCache.d.ts} +10 -13
- package/dist/{ObjectPool.js → InstanceCache.js} +91 -83
- package/dist/LazyReferenceCollection.d.ts +11 -15
- package/dist/LazyReferenceCollection.js +16 -15
- package/dist/Model.d.ts +37 -52
- package/dist/Model.js +52 -69
- package/dist/ModelRegistry.d.ts +46 -25
- package/dist/ModelRegistry.js +32 -30
- package/dist/NetworkMonitor.d.ts +5 -6
- package/dist/NetworkMonitor.js +6 -7
- package/dist/SyncClient.d.ts +119 -109
- package/dist/SyncClient.js +303 -224
- package/dist/SyncEngineContext.d.ts +1 -3
- package/dist/SyncEngineContext.js +1 -2
- package/dist/adapters/alwaysOnline.d.ts +6 -8
- package/dist/adapters/alwaysOnline.js +6 -8
- package/dist/adapters/inMemoryStorage.d.ts +9 -9
- package/dist/adapters/inMemoryStorage.js +9 -9
- package/dist/agent/Agent.d.ts +39 -31
- package/dist/agent/Agent.js +35 -23
- package/dist/agent/index.d.ts +4 -4
- package/dist/agent/index.js +5 -5
- package/dist/agent/session.d.ts +47 -44
- package/dist/agent/session.js +37 -48
- package/dist/agent/types.d.ts +26 -31
- package/dist/agent/types.js +6 -7
- package/dist/ai-sdk/coordinatedTool.d.ts +108 -0
- package/dist/ai-sdk/{coordinated-tool.js → coordinatedTool.js} +44 -38
- package/dist/ai-sdk/coordinationContext.d.ts +46 -0
- package/dist/ai-sdk/{coordination-context.js → coordinationContext.js} +30 -31
- package/dist/ai-sdk/index.d.ts +25 -22
- package/dist/ai-sdk/index.js +25 -22
- package/dist/ai-sdk/wrap.d.ts +7 -8
- package/dist/ai-sdk/wrap.js +2 -2
- package/dist/auth/credentialPolicy.d.ts +74 -71
- package/dist/auth/credentialPolicy.js +51 -56
- package/dist/auth/credentialSource.d.ts +7 -18
- package/dist/auth/credentialSource.js +10 -18
- package/dist/auth/index.d.ts +59 -58
- package/dist/auth/index.js +34 -40
- package/dist/auth/schemas.d.ts +5 -4
- package/dist/auth/schemas.js +5 -4
- package/dist/batching/index.d.ts +19 -21
- package/dist/batching/index.js +14 -17
- package/dist/cli.cjs +483 -369
- package/dist/client/Ablo.d.ts +107 -836
- package/dist/client/Ablo.js +174 -833
- package/dist/client/ApiClient.d.ts +44 -20
- package/dist/client/ApiClient.js +193 -44
- package/dist/client/auth.d.ts +51 -60
- package/dist/client/auth.js +137 -110
- package/dist/client/claimHeartbeatLoop.d.ts +50 -0
- package/dist/client/claimHeartbeatLoop.js +88 -0
- package/dist/client/consoleLogger.d.ts +35 -0
- package/dist/client/consoleLogger.js +44 -0
- package/dist/client/createInternalComponents.d.ts +14 -17
- package/dist/client/createInternalComponents.js +26 -31
- package/dist/client/createModelProxy.d.ts +130 -120
- package/dist/client/createModelProxy.js +158 -124
- package/dist/client/credentialEndpoint.d.ts +61 -0
- package/dist/client/credentialEndpoint.js +86 -0
- package/dist/client/functionalUpdate.d.ts +29 -27
- package/dist/client/functionalUpdate.js +21 -21
- package/dist/client/hostedEndpoints.d.ts +21 -0
- package/dist/client/hostedEndpoints.js +21 -0
- package/dist/client/httpClient.d.ts +58 -54
- package/dist/client/httpClient.js +29 -31
- package/dist/client/identity.d.ts +15 -20
- package/dist/client/identity.js +49 -59
- package/dist/client/modelRegistration.d.ts +10 -0
- package/dist/client/modelRegistration.js +301 -0
- package/dist/client/options.d.ts +373 -0
- package/dist/client/options.js +6 -0
- package/dist/client/registerDataSource.d.ts +9 -9
- package/dist/client/registerDataSource.js +15 -16
- package/dist/client/resourceTypes.d.ts +333 -0
- package/dist/client/resourceTypes.js +7 -0
- package/dist/client/schemaConfig.d.ts +44 -0
- package/dist/client/schemaConfig.js +176 -0
- package/dist/client/sessionMint.d.ts +17 -13
- package/dist/client/sessionMint.js +26 -31
- package/dist/client/validateAbloOptions.d.ts +12 -14
- package/dist/client/validateAbloOptions.js +9 -10
- package/dist/client/writeOptionsSchema.d.ts +18 -16
- package/dist/client/writeOptionsSchema.js +23 -20
- package/dist/client/wsMutationExecutor.d.ts +28 -0
- package/dist/client/wsMutationExecutor.js +71 -0
- package/dist/context.d.ts +6 -4
- package/dist/context.js +6 -7
- package/dist/coordination/index.d.ts +13 -4
- package/dist/coordination/index.js +29 -4
- package/dist/coordination/schema.d.ts +176 -128
- package/dist/coordination/schema.js +197 -133
- package/dist/coordination/trace.d.ts +9 -11
- package/dist/coordination/trace.js +13 -15
- package/dist/core/DatabaseManager.d.ts +5 -8
- package/dist/core/DatabaseManager.js +38 -40
- package/dist/core/QueryProcessor.d.ts +7 -9
- package/dist/core/QueryProcessor.js +27 -34
- package/dist/core/QueryView.d.ts +17 -5
- package/dist/core/QueryView.js +6 -7
- package/dist/core/StoreManager.d.ts +14 -16
- package/dist/core/StoreManager.js +26 -25
- package/dist/core/ViewRegistry.d.ts +5 -5
- package/dist/core/ViewRegistry.js +4 -4
- package/dist/core/index.d.ts +18 -13
- package/dist/core/index.js +32 -26
- package/dist/core/openIDBWithTimeout.d.ts +38 -36
- package/dist/core/openIDBWithTimeout.js +57 -54
- package/dist/core/queryUtils.d.ts +45 -0
- package/dist/core/queryUtils.js +69 -0
- package/dist/core/storeContract.d.ts +145 -0
- package/dist/core/storeContract.js +12 -0
- package/dist/environment.d.ts +28 -0
- package/dist/environment.js +21 -0
- package/dist/errorCodes.d.ts +118 -101
- package/dist/errorCodes.js +277 -260
- package/dist/errors.d.ts +170 -165
- package/dist/errors.js +161 -151
- package/dist/index.d.ts +30 -27
- package/dist/index.js +90 -82
- package/dist/interfaces/index.d.ts +108 -133
- package/dist/interfaces/index.js +5 -4
- package/dist/keys/index.d.ts +27 -29
- package/dist/keys/index.js +59 -49
- package/dist/mutators/RecordingTransaction.d.ts +16 -16
- package/dist/mutators/RecordingTransaction.js +31 -37
- package/dist/mutators/Transaction.d.ts +18 -26
- package/dist/mutators/Transaction.js +14 -20
- package/dist/mutators/UndoManager.d.ts +122 -131
- package/dist/mutators/UndoManager.js +149 -155
- package/dist/mutators/defineMutators.d.ts +24 -37
- package/dist/mutators/defineMutators.js +14 -20
- package/dist/mutators/inverseOp.d.ts +12 -15
- package/dist/mutators/inverseOp.js +12 -15
- package/dist/mutators/mutateActions.d.ts +10 -9
- package/dist/mutators/mutateActions.js +1 -1
- package/dist/mutators/readerActions.d.ts +9 -8
- package/dist/mutators/readerActions.js +2 -2
- package/dist/mutators/undoApply.d.ts +31 -27
- package/dist/mutators/undoApply.js +26 -24
- package/dist/policy/index.d.ts +5 -3
- package/dist/policy/index.js +5 -3
- package/dist/policy/types.d.ts +105 -101
- package/dist/policy/types.js +67 -66
- package/dist/query/client.d.ts +32 -16
- package/dist/query/client.js +103 -72
- package/dist/query/types.d.ts +37 -60
- package/dist/query/types.js +13 -33
- package/dist/react/AbloProvider.d.ts +7 -11
- package/dist/react/AbloProvider.js +24 -17
- package/dist/react/context.d.ts +27 -146
- package/dist/react/context.js +9 -10
- package/dist/react/index.d.ts +41 -42
- package/dist/react/index.js +37 -38
- package/dist/react/internalContext.d.ts +17 -19
- package/dist/react/useAblo.d.ts +23 -22
- package/dist/react/useAblo.js +17 -15
- package/dist/react/useCurrentUserId.d.ts +8 -7
- package/dist/react/useCurrentUserId.js +8 -7
- package/dist/react/useErrorListener.d.ts +7 -7
- package/dist/react/useErrorListener.js +11 -12
- package/dist/react/useMutationFailureListener.d.ts +8 -8
- package/dist/react/useMutationFailureListener.js +9 -9
- package/dist/react/useMutators.d.ts +11 -11
- package/dist/react/useMutators.js +10 -4
- package/dist/react/useReactive.js +2 -3
- package/dist/react/useSyncStatus.d.ts +4 -6
- package/dist/react/useUndoScope.d.ts +7 -9
- package/dist/react/useUndoScope.js +3 -3
- package/dist/schema/coordination.d.ts +21 -25
- package/dist/schema/coordination.js +21 -25
- package/dist/schema/ddl.d.ts +43 -39
- package/dist/schema/ddl.js +75 -68
- package/dist/schema/ddlLock.d.ts +35 -0
- package/dist/schema/ddlLock.js +46 -0
- package/dist/schema/diff.d.ts +99 -61
- package/dist/schema/diff.js +43 -34
- package/dist/schema/field.d.ts +37 -42
- package/dist/schema/field.js +36 -49
- package/dist/schema/generate.d.ts +12 -12
- package/dist/schema/generate.js +12 -12
- package/dist/schema/index.d.ts +5 -4
- package/dist/schema/index.js +29 -21
- package/dist/schema/model.d.ts +121 -146
- package/dist/schema/model.js +24 -35
- package/dist/schema/openapi.d.ts +10 -9
- package/dist/schema/openapi.js +7 -1
- package/dist/schema/queries.d.ts +30 -32
- package/dist/schema/queries.js +24 -25
- package/dist/schema/relation.d.ts +89 -99
- package/dist/schema/relation.js +13 -13
- package/dist/schema/residency.d.ts +38 -0
- package/dist/schema/residency.js +30 -0
- package/dist/schema/roles.d.ts +45 -27
- package/dist/schema/roles.js +52 -21
- package/dist/schema/schema.d.ts +36 -45
- package/dist/schema/schema.js +42 -39
- package/dist/schema/select.d.ts +13 -13
- package/dist/schema/select.js +13 -13
- package/dist/schema/serialize.d.ts +36 -39
- package/dist/schema/serialize.js +27 -31
- package/dist/schema/sugar.d.ts +17 -32
- package/dist/schema/sugar.js +14 -29
- package/dist/schema/{sync-delta-row.d.ts → syncDeltaRow.d.ts} +27 -50
- package/dist/schema/syncDeltaRow.js +89 -0
- package/dist/schema/tenancy.d.ts +44 -46
- package/dist/schema/tenancy.js +46 -48
- package/dist/server/adapter.d.ts +58 -58
- package/dist/server/adapter.js +13 -14
- package/dist/server/commit.d.ts +60 -64
- package/dist/server/index.d.ts +9 -10
- package/dist/server/index.js +1 -1
- package/dist/server/readConfig.d.ts +70 -0
- package/dist/server/readConfig.js +8 -0
- package/dist/server/storageMode.d.ts +23 -0
- package/dist/server/storageMode.js +17 -0
- package/dist/source/adapter.d.ts +31 -26
- package/dist/source/adapter.js +10 -10
- package/dist/source/adapters/drizzle.d.ts +28 -23
- package/dist/source/adapters/drizzle.js +34 -28
- package/dist/source/adapters/kysely.d.ts +27 -25
- package/dist/source/adapters/kysely.js +28 -26
- package/dist/source/adapters/memory.d.ts +8 -7
- package/dist/source/adapters/memory.js +10 -9
- package/dist/source/adapters/prisma.d.ts +13 -12
- package/dist/source/adapters/prisma.js +27 -29
- package/dist/source/conformance.d.ts +18 -11
- package/dist/source/conformance.js +27 -19
- package/dist/source/connector.d.ts +31 -32
- package/dist/source/connector.js +30 -28
- package/dist/source/connectorProtocol.d.ts +160 -0
- package/dist/source/connectorProtocol.js +162 -0
- package/dist/source/contract.d.ts +26 -27
- package/dist/source/contract.js +28 -29
- package/dist/source/factory.d.ts +94 -0
- package/dist/source/factory.js +268 -0
- package/dist/source/index.d.ts +10 -462
- package/dist/source/index.js +17 -421
- package/dist/source/migrations.d.ts +9 -9
- package/dist/source/migrations.js +9 -9
- package/dist/source/next.d.ts +10 -11
- package/dist/source/next.js +7 -8
- package/dist/source/pushQueue.d.ts +70 -48
- package/dist/source/pushQueue.js +36 -29
- package/dist/source/signing.d.ts +88 -0
- package/dist/source/signing.js +159 -0
- package/dist/source/types.d.ts +351 -0
- package/dist/source/types.js +43 -0
- package/dist/stores/ObjectStore.d.ts +11 -12
- package/dist/stores/ObjectStore.js +34 -35
- package/dist/stores/ObjectStoreContract.d.ts +12 -15
- package/dist/stores/SyncActionStore.d.ts +8 -12
- package/dist/stores/SyncActionStore.js +77 -46
- package/dist/surface.d.ts +28 -21
- package/dist/surface.js +28 -20
- package/dist/sync/{BootstrapHelper.d.ts → BootstrapFetcher.d.ts} +37 -45
- package/dist/sync/{BootstrapHelper.js → BootstrapFetcher.js} +101 -80
- package/dist/sync/ConnectionManager.d.ts +47 -50
- package/dist/sync/ConnectionManager.js +74 -70
- package/dist/sync/NetworkProbe.d.ts +27 -31
- package/dist/sync/NetworkProbe.js +67 -72
- package/dist/sync/{HydrationCoordinator.d.ts → OnDemandLoader.d.ts} +49 -36
- package/dist/sync/{HydrationCoordinator.js → OnDemandLoader.js} +79 -54
- package/dist/sync/{AreaOfInterestManager.d.ts → SubscriptionManager.d.ts} +45 -59
- package/dist/sync/{AreaOfInterestManager.js → SubscriptionManager.js} +44 -52
- package/dist/sync/SyncWebSocket.d.ts +175 -250
- package/dist/sync/SyncWebSocket.js +431 -769
- package/dist/sync/awaitClaimGrant.d.ts +18 -18
- package/dist/sync/awaitClaimGrant.js +38 -30
- package/dist/sync/bootstrapApply.d.ts +70 -0
- package/dist/sync/bootstrapApply.js +73 -0
- package/dist/sync/commitFrames.d.ts +44 -0
- package/dist/sync/commitFrames.js +94 -0
- package/dist/sync/createClaimStream.d.ts +23 -22
- package/dist/sync/createClaimStream.js +108 -25
- package/dist/sync/createPresenceStream.d.ts +19 -18
- package/dist/sync/createPresenceStream.js +25 -26
- package/dist/sync/createSnapshot.d.ts +13 -17
- package/dist/sync/createSnapshot.js +20 -26
- package/dist/sync/credentialLifecycle.d.ts +175 -0
- package/dist/sync/credentialLifecycle.js +322 -0
- package/dist/sync/deltaPipeline.d.ts +113 -0
- package/dist/sync/deltaPipeline.js +261 -0
- package/dist/sync/groupChange.d.ts +113 -0
- package/dist/sync/groupChange.js +242 -0
- package/dist/sync/heartbeat.d.ts +63 -0
- package/dist/sync/heartbeat.js +91 -0
- package/dist/sync/participants.d.ts +27 -27
- package/dist/sync/schemas.d.ts +3 -2
- package/dist/sync/schemas.js +14 -10
- package/dist/sync/syncCursor.d.ts +40 -0
- package/dist/sync/syncCursor.js +55 -0
- package/dist/sync/syncPlan.d.ts +54 -0
- package/dist/sync/syncPlan.js +50 -0
- package/dist/sync/syncPosition.d.ts +54 -49
- package/dist/sync/syncPosition.js +57 -52
- package/dist/sync/wsFrameHandlers.d.ts +116 -0
- package/dist/sync/wsFrameHandlers.js +374 -0
- package/dist/testing/fixtures/bootstrap.d.ts +21 -17
- package/dist/testing/fixtures/bootstrap.js +12 -6
- package/dist/testing/fixtures/deltas.d.ts +31 -34
- package/dist/testing/fixtures/deltas.js +30 -33
- package/dist/testing/fixtures/models.d.ts +11 -10
- package/dist/testing/fixtures/models.js +12 -10
- package/dist/testing/helpers/{react-wrapper.d.ts → reactWrapper.d.ts} +13 -10
- package/dist/testing/helpers/{react-wrapper.js → reactWrapper.js} +15 -12
- package/dist/testing/helpers/{sync-engine-harness.d.ts → syncEngineHarness.d.ts} +17 -18
- package/dist/testing/helpers/{sync-engine-harness.js → syncEngineHarness.js} +14 -11
- package/dist/testing/helpers/wait.d.ts +13 -8
- package/dist/testing/helpers/wait.js +13 -8
- package/dist/testing/index.d.ts +4 -4
- package/dist/testing/index.js +3 -3
- package/dist/testing/mocks/MockMutationExecutor.d.ts +18 -17
- package/dist/testing/mocks/MockMutationExecutor.js +15 -14
- package/dist/testing/mocks/MockNetworkMonitor.d.ts +8 -8
- package/dist/testing/mocks/MockNetworkMonitor.js +8 -8
- package/dist/testing/mocks/MockSyncContext.d.ts +21 -34
- package/dist/testing/mocks/MockSyncContext.js +16 -45
- package/dist/testing/mocks/MockSyncStore.d.ts +14 -14
- package/dist/testing/mocks/MockSyncStore.js +11 -11
- package/dist/testing/mocks/MockWebSocket.d.ts +28 -24
- package/dist/testing/mocks/MockWebSocket.js +22 -21
- package/dist/transactions/TransactionQueue.d.ts +190 -221
- package/dist/transactions/TransactionQueue.js +424 -822
- package/dist/transactions/TransactionStore.d.ts +20 -0
- package/dist/transactions/TransactionStore.js +53 -0
- package/dist/transactions/UnconfirmedWrites.d.ts +82 -0
- package/dist/transactions/UnconfirmedWrites.js +104 -0
- package/dist/transactions/coalesceRules.d.ts +58 -0
- package/dist/transactions/coalesceRules.js +140 -0
- package/dist/transactions/commitPayload.d.ts +130 -0
- package/dist/transactions/commitPayload.js +143 -0
- package/dist/transactions/deltaConfirmation.d.ts +58 -0
- package/dist/transactions/deltaConfirmation.js +215 -0
- package/dist/transactions/optimisticApply.d.ts +49 -0
- package/dist/transactions/optimisticApply.js +65 -0
- package/dist/transactions/replayValidation.d.ts +99 -0
- package/dist/transactions/replayValidation.js +111 -0
- package/dist/types/global.d.ts +46 -41
- package/dist/types/global.js +20 -19
- package/dist/types/index.d.ts +74 -80
- package/dist/types/index.js +22 -27
- package/dist/types/modelData.d.ts +10 -0
- package/dist/types/modelData.js +9 -0
- package/dist/types/participant.d.ts +20 -0
- package/dist/types/participant.js +10 -0
- package/dist/types/streams.d.ts +216 -209
- package/dist/types/streams.js +7 -7
- package/dist/utils/asyncIterator.d.ts +25 -32
- package/dist/utils/asyncIterator.js +25 -32
- package/dist/utils/duration.d.ts +12 -15
- package/dist/utils/duration.js +12 -15
- package/dist/utils/mobxSetup.d.ts +53 -0
- package/dist/utils/{mobx-setup.js → mobxSetup.js} +44 -100
- package/dist/webhooks/events.d.ts +21 -16
- package/dist/webhooks/events.js +10 -8
- package/dist/webhooks/index.d.ts +5 -7
- package/dist/webhooks/index.js +5 -7
- package/dist/{schema/sync-delta-wire.d.ts → wire/delta.d.ts} +58 -41
- package/dist/wire/delta.js +114 -0
- package/dist/wire/errorEnvelope.d.ts +35 -27
- package/dist/wire/errorEnvelope.js +38 -32
- package/dist/wire/frames.d.ts +150 -67
- package/dist/wire/frames.js +48 -1
- package/dist/wire/index.d.ts +18 -13
- package/dist/wire/index.js +36 -13
- package/dist/wire/listEnvelope.d.ts +16 -23
- package/dist/wire/listEnvelope.js +7 -6
- package/dist/wire/protocol.d.ts +38 -0
- package/dist/wire/protocol.js +38 -0
- package/dist/wire/protocolVersion.d.ts +60 -0
- package/dist/wire/protocolVersion.js +67 -0
- package/docs/api-keys.md +4 -3
- package/docs/coordination.md +59 -0
- package/docs/examples/existing-python-backend.md +3 -3
- package/docs/identity.md +4 -4
- package/docs/integration-guide.md +1 -1
- package/docs/react.md +1 -1
- package/docs/sessions.md +5 -7
- package/package.json +24 -21
- package/dist/ai-sdk/coordinated-tool.d.ts +0 -101
- package/dist/ai-sdk/coordination-context.d.ts +0 -52
- package/dist/client/index.d.ts +0 -36
- package/dist/client/index.js +0 -33
- package/dist/config/index.d.ts +0 -10
- package/dist/config/index.js +0 -12
- package/dist/core/query-utils.d.ts +0 -34
- package/dist/core/query-utils.js +0 -59
- package/dist/interfaces/headless.d.ts +0 -95
- package/dist/interfaces/headless.js +0 -41
- package/dist/query/index.d.ts +0 -6
- package/dist/query/index.js +0 -5
- package/dist/realtime/index.d.ts +0 -10
- package/dist/realtime/index.js +0 -9
- package/dist/schema/plane.d.ts +0 -23
- package/dist/schema/plane.js +0 -19
- package/dist/schema/sync-delta-row.js +0 -103
- package/dist/schema/sync-delta-wire.js +0 -102
- package/dist/server/next.d.ts +0 -51
- package/dist/server/next.js +0 -47
- package/dist/server/read-config.d.ts +0 -67
- package/dist/server/read-config.js +0 -8
- package/dist/server/storage-mode.d.ts +0 -1
- package/dist/server/storage-mode.js +0 -18
- package/dist/source/connector-protocol.d.ts +0 -159
- package/dist/source/connector-protocol.js +0 -161
- package/dist/sync/OfflineFlush.d.ts +0 -9
- package/dist/sync/OfflineFlush.js +0 -22
- package/dist/sync/OfflineTransactionStore.d.ts +0 -37
- package/dist/sync/OfflineTransactionStore.js +0 -263
- package/dist/transactions/OptimisticEchoTracker.d.ts +0 -82
- package/dist/transactions/OptimisticEchoTracker.js +0 -104
- package/dist/transactions/index.d.ts +0 -16
- package/dist/transactions/index.js +0 -7
- package/dist/transactions/mutation-error-handler.d.ts +0 -5
- package/dist/transactions/mutation-error-handler.js +0 -39
- package/dist/utils/mobx-setup.d.ts +0 -42
package/dist/schema/queries.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Query definitions for a schema.
|
|
3
3
|
*
|
|
4
|
-
* A query
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* A query pairs a Zod input schema with the name of the model it returns.
|
|
5
|
+
* Input types flow through `z.infer` and result types through `InferModel`,
|
|
6
|
+
* the same inference path `model` and `relation` use, so there is no separate
|
|
7
|
+
* type system to learn.
|
|
8
8
|
*
|
|
9
9
|
* Usage:
|
|
10
10
|
* import { z } from 'zod';
|
|
@@ -37,23 +37,21 @@
|
|
|
37
37
|
*
|
|
38
38
|
* Design notes:
|
|
39
39
|
*
|
|
40
|
-
* - `query()` accepts any string for `returns`. The
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* `relation.belongsTo('projects', 'projectId')`
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* schema. This keeps each `QueryDef` pointed at exactly one model
|
|
56
|
-
* and lets the generic loader hydrate via a single
|
|
40
|
+
* - `query()` accepts any string for `returns`. The check that the string
|
|
41
|
+
* names a real model runs when the query passes through
|
|
42
|
+
* `defineQueries(schema, ...)`, the same way
|
|
43
|
+
* `relation.belongsTo('projects', 'projectId')` takes a plain string at
|
|
44
|
+
* the factory and defers the cross-reference check to schema assembly.
|
|
45
|
+
*
|
|
46
|
+
* - A query carries no `name` until `defineQueries()` assigns one from its
|
|
47
|
+
* record key — the same pattern `defineSchema({ tasks: model(...) })`
|
|
48
|
+
* uses, where the model's name is the record key rather than a field on
|
|
49
|
+
* the factory.
|
|
50
|
+
*
|
|
51
|
+
* - Every query returns an array of a single model type. To fetch several
|
|
52
|
+
* model types at once, run several queries in one batch rather than
|
|
53
|
+
* declaring a combined shape. Each `QueryDef` therefore points at exactly
|
|
54
|
+
* one model, and the loader hydrates results through a single
|
|
57
55
|
* `schema.models[queryDef.returns]` lookup.
|
|
58
56
|
*/
|
|
59
57
|
import { z } from 'zod';
|
|
@@ -79,11 +77,11 @@ export interface QueryDef<TInput extends z.ZodType = z.ZodType, TReturns extends
|
|
|
79
77
|
*/
|
|
80
78
|
readonly returns: TReturns;
|
|
81
79
|
/**
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
80
|
+
* The name under which the query is registered. {@link defineQueries}
|
|
81
|
+
* fills this in from the record key; you do not set it directly. It lives
|
|
82
|
+
* on the definition itself so dispatch and lookup code can read the name
|
|
83
|
+
* straight off a {@link QueryDef} without carrying the surrounding
|
|
84
|
+
* {@link Queries} object.
|
|
87
85
|
*/
|
|
88
86
|
readonly name?: string;
|
|
89
87
|
}
|
|
@@ -123,7 +121,7 @@ export declare function query<TInput extends z.ZodType, const TReturns extends s
|
|
|
123
121
|
export type QueryRecord<S extends Schema> = Record<string, QueryDef<z.ZodType, InferModelNames<S>>>;
|
|
124
122
|
/**
|
|
125
123
|
* The object returned by `defineQueries()`. Holds a reference back to
|
|
126
|
-
* the schema (so the
|
|
124
|
+
* the schema (so the loader can resolve `queryDef.returns` to
|
|
127
125
|
* a `ModelDef` at runtime via `schema.models[def.returns]`) and the
|
|
128
126
|
* resolved record of queries, each with its `name` field filled in.
|
|
129
127
|
*/
|
|
@@ -158,7 +156,7 @@ export type InferQueryInput<Q extends QueryDef> = z.infer<Q['input']>;
|
|
|
158
156
|
* // Array<SlideLayer>
|
|
159
157
|
* ```
|
|
160
158
|
*/
|
|
161
|
-
export type InferQueryResult<S extends Schema, Q extends QueryDef> = Q extends QueryDef<z.ZodType, infer R> ? R extends InferModelNames<S> ?
|
|
159
|
+
export type InferQueryResult<S extends Schema, Q extends QueryDef> = Q extends QueryDef<z.ZodType, infer R> ? R extends InferModelNames<S> ? InferModel<S, R>[] : never : never;
|
|
162
160
|
/**
|
|
163
161
|
* Define a typed query set against a schema.
|
|
164
162
|
*
|
|
@@ -178,9 +176,9 @@ export type InferQueryResult<S extends Schema, Q extends QueryDef> = Q extends Q
|
|
|
178
176
|
* exist" error deep inside the loader.
|
|
179
177
|
*
|
|
180
178
|
* Each resolved query gets its `name` populated from the record key:
|
|
181
|
-
* `queries.slideLayersByDeck.name === 'slideLayersByDeck'`.
|
|
182
|
-
*
|
|
183
|
-
*
|
|
179
|
+
* `queries.slideLayersByDeck.name === 'slideLayersByDeck'`. Dispatch and
|
|
180
|
+
* lookup code read `queryDef.name` directly rather than re-deriving it from
|
|
181
|
+
* the surrounding record.
|
|
184
182
|
*
|
|
185
183
|
* ```ts
|
|
186
184
|
* const schema = defineSchema({
|
package/dist/schema/queries.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Query definitions for a schema.
|
|
3
3
|
*
|
|
4
|
-
* A query
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* A query pairs a Zod input schema with the name of the model it returns.
|
|
5
|
+
* Input types flow through `z.infer` and result types through `InferModel`,
|
|
6
|
+
* the same inference path `model` and `relation` use, so there is no separate
|
|
7
|
+
* type system to learn.
|
|
8
8
|
*
|
|
9
9
|
* Usage:
|
|
10
10
|
* import { z } from 'zod';
|
|
@@ -37,25 +37,24 @@
|
|
|
37
37
|
*
|
|
38
38
|
* Design notes:
|
|
39
39
|
*
|
|
40
|
-
* - `query()` accepts any string for `returns`. The
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* `relation.belongsTo('projects', 'projectId')`
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* schema. This keeps each `QueryDef` pointed at exactly one model
|
|
56
|
-
* and lets the generic loader hydrate via a single
|
|
40
|
+
* - `query()` accepts any string for `returns`. The check that the string
|
|
41
|
+
* names a real model runs when the query passes through
|
|
42
|
+
* `defineQueries(schema, ...)`, the same way
|
|
43
|
+
* `relation.belongsTo('projects', 'projectId')` takes a plain string at
|
|
44
|
+
* the factory and defers the cross-reference check to schema assembly.
|
|
45
|
+
*
|
|
46
|
+
* - A query carries no `name` until `defineQueries()` assigns one from its
|
|
47
|
+
* record key — the same pattern `defineSchema({ tasks: model(...) })`
|
|
48
|
+
* uses, where the model's name is the record key rather than a field on
|
|
49
|
+
* the factory.
|
|
50
|
+
*
|
|
51
|
+
* - Every query returns an array of a single model type. To fetch several
|
|
52
|
+
* model types at once, run several queries in one batch rather than
|
|
53
|
+
* declaring a combined shape. Each `QueryDef` therefore points at exactly
|
|
54
|
+
* one model, and the loader hydrates results through a single
|
|
57
55
|
* `schema.models[queryDef.returns]` lookup.
|
|
58
56
|
*/
|
|
57
|
+
import { z } from 'zod';
|
|
59
58
|
import { AbloValidationError } from '../errors.js';
|
|
60
59
|
// ── query() factory ───────────────────────────────────────────────────────
|
|
61
60
|
/**
|
|
@@ -100,9 +99,9 @@ export function query(spec) {
|
|
|
100
99
|
* exist" error deep inside the loader.
|
|
101
100
|
*
|
|
102
101
|
* Each resolved query gets its `name` populated from the record key:
|
|
103
|
-
* `queries.slideLayersByDeck.name === 'slideLayersByDeck'`.
|
|
104
|
-
*
|
|
105
|
-
*
|
|
102
|
+
* `queries.slideLayersByDeck.name === 'slideLayersByDeck'`. Dispatch and
|
|
103
|
+
* lookup code read `queryDef.name` directly rather than re-deriving it from
|
|
104
|
+
* the surrounding record.
|
|
106
105
|
*
|
|
107
106
|
* ```ts
|
|
108
107
|
* const schema = defineSchema({
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
2
|
+
* Declarative relations between your models — the edges that turn a flat set
|
|
3
|
+
* of models into a graph. You attach relations to a model with the
|
|
4
|
+
* {@link relation} factories; the engine reads them to index foreign keys for
|
|
5
|
+
* fast child lookups, to order inserts so a parent row lands before the rows
|
|
6
|
+
* that reference it, and to generate the accessor properties that let you read
|
|
7
|
+
* `task.project` or `project.tasks` directly.
|
|
8
8
|
*
|
|
9
9
|
* Usage:
|
|
10
10
|
* import { relation } from '@abloatai/ablo/schema';
|
|
@@ -16,44 +16,38 @@
|
|
|
16
16
|
* };
|
|
17
17
|
*/
|
|
18
18
|
/**
|
|
19
|
-
* Options for `relation.belongsTo
|
|
20
|
-
* is opt-in per relation.
|
|
19
|
+
* Options for `relation.belongsTo`. Each defaults to `false`, so every
|
|
20
|
+
* behavior below is opt-in per relation.
|
|
21
21
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* where you frequently want "all layers for this slide."
|
|
22
|
+
* `index: true` registers a foreign-key index for the child model when the
|
|
23
|
+
* engine starts, turning "every child that points at this parent" from a full
|
|
24
|
+
* scan into a constant-time lookup. Reach for it on relations you query this
|
|
25
|
+
* way often, such as a slide layer's `slideId`.
|
|
27
26
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* `
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* (the child data is still applied) — enrichment is best-effort.
|
|
27
|
+
* `enrich: true` auto-populates the parent reference on an incoming change
|
|
28
|
+
* before the child data lands. A change to `Task { teamId: 't1' }` picks up the
|
|
29
|
+
* already-loaded `teams:t1` record and attaches it as `data.team`, so you can
|
|
30
|
+
* read `task.team` without a second lookup. Enrichment is best-effort: if the
|
|
31
|
+
* parent has not loaded yet it quietly does nothing, and the child data still
|
|
32
|
+
* applies.
|
|
35
33
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* predecessor, so the child gets a higher priority than the parent
|
|
43
|
-
* instead of being tied with it.
|
|
34
|
+
* `defer: true` tells the engine to ignore this edge when it works out the
|
|
35
|
+
* order in which to insert rows. Use it on the soft side of a genuine reference
|
|
36
|
+
* cycle — the side where you are willing to insert the child first with the
|
|
37
|
+
* foreign key left null and fill it in with a later update. The other side of
|
|
38
|
+
* the cycle then becomes a strict predecessor, so the child is ordered after
|
|
39
|
+
* the parent rather than tied with it.
|
|
44
40
|
*
|
|
45
|
-
* `defer` only
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* database level. Example use case:
|
|
41
|
+
* `defer` changes only that ordering, not what the engine sends on the wire; it
|
|
42
|
+
* does not rewrite an insert into an insert-then-update. Pair it with a Postgres
|
|
43
|
+
* `DEFERRABLE INITIALLY DEFERRED` constraint when you also want the database to
|
|
44
|
+
* relax the foreign-key check itself. For example:
|
|
50
45
|
*
|
|
51
46
|
* ```ts
|
|
52
47
|
* layouts: model({ deckId: z.string().nullish() }, {
|
|
53
|
-
* // The deck-owns-layout link is nullable
|
|
54
|
-
* //
|
|
55
|
-
* //
|
|
56
|
-
* // SCC priority bucket.
|
|
48
|
+
* // The deck-owns-layout link is nullable and the layout is always
|
|
49
|
+
* // created first; marking it `defer` lets the deck commit ahead of the
|
|
50
|
+
* // layout instead of sharing its insert-order slot.
|
|
57
51
|
* deck: relation.belongsTo('slideDecks', 'deckId', { defer: true }),
|
|
58
52
|
* }),
|
|
59
53
|
* ```
|
|
@@ -63,40 +57,39 @@ export interface BelongsToOptions {
|
|
|
63
57
|
readonly enrich?: boolean;
|
|
64
58
|
readonly defer?: boolean;
|
|
65
59
|
/**
|
|
66
|
-
* Marks the relation's target as this record's
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
* owning entity
|
|
71
|
-
*
|
|
60
|
+
* Marks the relation's target as this record's parent: the entity the record
|
|
61
|
+
* lives inside and inherits its access scope from. When a record is written,
|
|
62
|
+
* the engine routes it into its parent's sync group — following a chain of
|
|
63
|
+
* `parent` edges all the way up — so the change reaches everyone subscribed to
|
|
64
|
+
* the owning entity. This is the familiar rule that access flows down from a
|
|
65
|
+
* container to the things it holds, as a folder does to its files.
|
|
72
66
|
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
67
|
+
* Do not set `parent` on a reference that merely points at another record for
|
|
68
|
+
* provenance or as a template, such as `sourceSlideId` or `templateId`; doing
|
|
69
|
+
* so would leak the record into an unrelated scope. The engine also cannot
|
|
70
|
+
* infer the parent from whether a field is optional — many real parent keys
|
|
71
|
+
* are optional, like a root folder or an inbox task — so you must declare the
|
|
72
|
+
* parent edge explicitly.
|
|
77
73
|
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
74
|
+
* It reads naturally at the call site:
|
|
75
|
+
* `belongsTo('deck', 'deckId', { parent: true })` — the deck is the parent.
|
|
80
76
|
*/
|
|
81
77
|
readonly parent?: boolean;
|
|
82
78
|
/**
|
|
83
|
-
* Emit a real Postgres
|
|
84
|
-
* customer-owned
|
|
85
|
-
* `parent`
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* `relations()` vs `references()` split; Zanzibar's `parent` is permission-only
|
|
89
|
-
* and "says nothing about data ownership or lifecycle").
|
|
79
|
+
* Emit a real Postgres foreign-key constraint for this relation when the
|
|
80
|
+
* engine provisions tables in a customer-owned database. This is independent
|
|
81
|
+
* of `parent`: `parent` decides which subscribers a change reaches, while
|
|
82
|
+
* `fk` decides whether the database enforces referential integrity. A relation
|
|
83
|
+
* may set either, both, or neither.
|
|
90
84
|
*
|
|
91
|
-
* Set `fk: true`
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
* INITIALLY DEFERRED, ON DELETE NO ACTION
|
|
98
|
-
*
|
|
99
|
-
* `foreignKeyStatements` in `ddl.ts`.
|
|
85
|
+
* Set `fk: true` only when the target row lives in the same database and is
|
|
86
|
+
* written in the same commit as this row, and points at a strong, contained
|
|
87
|
+
* entity. Leave it off provenance or template pointers (`sourceSlideId`,
|
|
88
|
+
* `templateId`), cross-tenant references, or anything that may be written in a
|
|
89
|
+
* different transaction than its target — a hard constraint there would reject
|
|
90
|
+
* the write and break out-of-order sync. The constraint is emitted as
|
|
91
|
+
* `DEFERRABLE INITIALLY DEFERRED, ON DELETE NO ACTION`: a plain integrity
|
|
92
|
+
* guard, leaving any cascade or null-on-delete behavior to the application.
|
|
100
93
|
*/
|
|
101
94
|
readonly fk?: boolean;
|
|
102
95
|
}
|
|
@@ -105,20 +98,18 @@ declare const __relationTarget: unique symbol;
|
|
|
105
98
|
declare const __relationField: unique symbol;
|
|
106
99
|
export type RelationType = 'belongsTo' | 'hasMany' | 'hasOne';
|
|
107
100
|
/**
|
|
108
|
-
* A relation definition
|
|
101
|
+
* A relation definition, carrying its type information at both the type and
|
|
102
|
+
* runtime level.
|
|
109
103
|
*
|
|
110
|
-
* The
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* `InferModel` auto-adding enriched-parent properties) can read the
|
|
116
|
-
* literal value off the relation def at compile time.
|
|
104
|
+
* The `Options` generic captures a relation's options in the type system; only
|
|
105
|
+
* `belongsTo` uses it, while `hasMany` and `hasOne` leave it empty. The `const`
|
|
106
|
+
* modifier on the `belongsTo` factory preserves literal inference, so
|
|
107
|
+
* `{ enrich: true }` is remembered as `true` rather than widened to `boolean`,
|
|
108
|
+
* letting type-level features read the exact option value.
|
|
117
109
|
*
|
|
118
|
-
* `options` is always present at runtime
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
* without a null guard downstream.
|
|
110
|
+
* `options` is always present at runtime: the factory substitutes an empty
|
|
111
|
+
* object when you omit it, so reading `options.index` or `options.enrich` needs
|
|
112
|
+
* no null check.
|
|
122
113
|
*/
|
|
123
114
|
export interface RelationDef<Type extends RelationType = RelationType, Target extends string = string, Field extends string = string, Options extends BelongsToOptions = BelongsToOptions> {
|
|
124
115
|
readonly [__relationType]: Type;
|
|
@@ -128,25 +119,24 @@ export interface RelationDef<Type extends RelationType = RelationType, Target ex
|
|
|
128
119
|
readonly type: Type;
|
|
129
120
|
readonly target: Target;
|
|
130
121
|
/**
|
|
131
|
-
* The child model
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
* verbatim in raw SQL.
|
|
122
|
+
* The field on the child model that holds the parent's id, as a camelCase
|
|
123
|
+
* schema field name. The engine reads `model[foreignKey]` to resolve the
|
|
124
|
+
* relation and to build client-side index keys; it is never interpolated into
|
|
125
|
+
* raw SQL — that is what {@link foreignKeyColumn} is for.
|
|
136
126
|
*/
|
|
137
127
|
readonly foreignKey: Field;
|
|
138
128
|
/**
|
|
139
|
-
* The same foreign key expressed as a database column identifier.
|
|
140
|
-
*
|
|
141
|
-
* `
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
* identifiers embedded in raw SQL
|
|
145
|
-
*
|
|
129
|
+
* The same foreign key expressed as a database column identifier.
|
|
130
|
+
* {@link foreignKey} is translated into this when you configure a `casing`
|
|
131
|
+
* option on `defineSchema` — for example `'snake_case'` turns `messageId`
|
|
132
|
+
* into `message_id`. The server interpolates this column name into SQL
|
|
133
|
+
* directly, because a driver's automatic camelCase-to-snake_case mapping does
|
|
134
|
+
* not reach identifiers embedded in raw SQL; resolving the name once at
|
|
135
|
+
* schema-build time is what makes it available there.
|
|
146
136
|
*
|
|
147
|
-
* Defaults to {@link foreignKey} when `casing` is
|
|
148
|
-
*
|
|
149
|
-
*
|
|
137
|
+
* Defaults to {@link foreignKey} when no `casing` option is set, so consumers
|
|
138
|
+
* whose database columns already match their field names need no
|
|
139
|
+
* configuration.
|
|
150
140
|
*/
|
|
151
141
|
readonly foreignKeyColumn: string;
|
|
152
142
|
readonly options: Options;
|
|
@@ -182,12 +172,12 @@ export declare const relation: {
|
|
|
182
172
|
*/
|
|
183
173
|
readonly belongsTo: <Target extends string, Field extends string, const Opts extends BelongsToOptions = Record<string, never>>(target: Target, foreignKey: Field, options?: Opts) => RelationDef<"belongsTo", Target, Field, Opts>;
|
|
184
174
|
/**
|
|
185
|
-
* This model has many of another model
|
|
186
|
-
*
|
|
175
|
+
* This model has many of another model — for example, a project has many
|
|
176
|
+
* tasks via `Task.projectId`.
|
|
187
177
|
*
|
|
188
|
-
* At runtime
|
|
189
|
-
*
|
|
190
|
-
*
|
|
178
|
+
* At runtime the engine adds a getter to the parent model that returns every
|
|
179
|
+
* child whose foreign key matches, and registers the foreign-key index on the
|
|
180
|
+
* child model automatically.
|
|
191
181
|
*
|
|
192
182
|
* ```ts
|
|
193
183
|
* slides: relation.hasMany('slideLayers', 'slideId'),
|
|
@@ -201,8 +191,8 @@ export declare const relation: {
|
|
|
201
191
|
orderBy?: string;
|
|
202
192
|
}) => RelationDef<"hasMany", Target, Field>;
|
|
203
193
|
/**
|
|
204
|
-
* This model has one of another model
|
|
205
|
-
*
|
|
194
|
+
* This model has one of another model — for example, a user has one profile
|
|
195
|
+
* via `Profile.userId`.
|
|
206
196
|
*/
|
|
207
197
|
readonly hasOne: <Target extends string, Field extends string>(target: Target, foreignKey: Field) => RelationDef<"hasOne", Target, Field>;
|
|
208
198
|
};
|
package/dist/schema/relation.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
2
|
+
* Declarative relations between your models — the edges that turn a flat set
|
|
3
|
+
* of models into a graph. You attach relations to a model with the
|
|
4
|
+
* {@link relation} factories; the engine reads them to index foreign keys for
|
|
5
|
+
* fast child lookups, to order inserts so a parent row lands before the rows
|
|
6
|
+
* that reference it, and to generate the accessor properties that let you read
|
|
7
|
+
* `task.project` or `project.tasks` directly.
|
|
8
8
|
*
|
|
9
9
|
* Usage:
|
|
10
10
|
* import { relation } from '@abloatai/ablo/schema';
|
|
@@ -72,12 +72,12 @@ export const relation = {
|
|
|
72
72
|
return new RelationBuilder('belongsTo', target, foreignKey, options ?? {});
|
|
73
73
|
},
|
|
74
74
|
/**
|
|
75
|
-
* This model has many of another model
|
|
76
|
-
*
|
|
75
|
+
* This model has many of another model — for example, a project has many
|
|
76
|
+
* tasks via `Task.projectId`.
|
|
77
77
|
*
|
|
78
|
-
* At runtime
|
|
79
|
-
*
|
|
80
|
-
*
|
|
78
|
+
* At runtime the engine adds a getter to the parent model that returns every
|
|
79
|
+
* child whose foreign key matches, and registers the foreign-key index on the
|
|
80
|
+
* child model automatically.
|
|
81
81
|
*
|
|
82
82
|
* ```ts
|
|
83
83
|
* slides: relation.hasMany('slideLayers', 'slideId'),
|
|
@@ -95,8 +95,8 @@ export const relation = {
|
|
|
95
95
|
return builder;
|
|
96
96
|
},
|
|
97
97
|
/**
|
|
98
|
-
* This model has one of another model
|
|
99
|
-
*
|
|
98
|
+
* This model has one of another model — for example, a user has one profile
|
|
99
|
+
* via `Profile.userId`.
|
|
100
100
|
*/
|
|
101
101
|
hasOne(target, foreignKey) {
|
|
102
102
|
return new RelationBuilder('hasOne', target, foreignKey);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A model's residency: which database its rows live in. This is a sibling axis
|
|
3
|
+
* to `tenancy`, which instead describes how rows are isolated within a single
|
|
4
|
+
* database.
|
|
5
|
+
*
|
|
6
|
+
* - `tenant` — the tenant data plane. For a customer-connected database this
|
|
7
|
+
* is the customer's own database, and provisioning creates these
|
|
8
|
+
* tables there.
|
|
9
|
+
* - `control` — the coordination plane the engine owns: the change log,
|
|
10
|
+
* attribution, audit, and the like. These tables are never
|
|
11
|
+
* created in a customer's database.
|
|
12
|
+
*
|
|
13
|
+
* The name is `residency` rather than `plane` because "plane" already refers to
|
|
14
|
+
* the server's tenancy scope — organization, environment, and optionally
|
|
15
|
+
* project and sandbox. On the wire the serialized option is still keyed as
|
|
16
|
+
* `plane`, a frozen part of the wire format; only the TypeScript name differs.
|
|
17
|
+
*
|
|
18
|
+
* Declaring this boundary lets provisioning derive what a customer's database
|
|
19
|
+
* receives — the models whose residency is `tenant` — rather than hand-coding
|
|
20
|
+
* that list. Defaults to `tenant`.
|
|
21
|
+
*/
|
|
22
|
+
import { z } from 'zod';
|
|
23
|
+
export declare const residencySchema: z.ZodEnum<{
|
|
24
|
+
tenant: "tenant";
|
|
25
|
+
control: "control";
|
|
26
|
+
}>;
|
|
27
|
+
export type ModelResidency = z.infer<typeof residencySchema>;
|
|
28
|
+
/** Default residency for a model that doesn't declare one — the tenant data plane. */
|
|
29
|
+
export declare const DEFAULT_RESIDENCY: ModelResidency;
|
|
30
|
+
/** @deprecated Use `residencySchema`. */
|
|
31
|
+
export declare const planeSchema: z.ZodEnum<{
|
|
32
|
+
tenant: "tenant";
|
|
33
|
+
control: "control";
|
|
34
|
+
}>;
|
|
35
|
+
/** @deprecated Use `ModelResidency`. */
|
|
36
|
+
export type SchemaPlane = ModelResidency;
|
|
37
|
+
/** @deprecated Use `DEFAULT_RESIDENCY`. */
|
|
38
|
+
export declare const DEFAULT_PLANE: "tenant";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A model's residency: which database its rows live in. This is a sibling axis
|
|
3
|
+
* to `tenancy`, which instead describes how rows are isolated within a single
|
|
4
|
+
* database.
|
|
5
|
+
*
|
|
6
|
+
* - `tenant` — the tenant data plane. For a customer-connected database this
|
|
7
|
+
* is the customer's own database, and provisioning creates these
|
|
8
|
+
* tables there.
|
|
9
|
+
* - `control` — the coordination plane the engine owns: the change log,
|
|
10
|
+
* attribution, audit, and the like. These tables are never
|
|
11
|
+
* created in a customer's database.
|
|
12
|
+
*
|
|
13
|
+
* The name is `residency` rather than `plane` because "plane" already refers to
|
|
14
|
+
* the server's tenancy scope — organization, environment, and optionally
|
|
15
|
+
* project and sandbox. On the wire the serialized option is still keyed as
|
|
16
|
+
* `plane`, a frozen part of the wire format; only the TypeScript name differs.
|
|
17
|
+
*
|
|
18
|
+
* Declaring this boundary lets provisioning derive what a customer's database
|
|
19
|
+
* receives — the models whose residency is `tenant` — rather than hand-coding
|
|
20
|
+
* that list. Defaults to `tenant`.
|
|
21
|
+
*/
|
|
22
|
+
import { z } from 'zod';
|
|
23
|
+
export const residencySchema = z.enum(['tenant', 'control']);
|
|
24
|
+
/** Default residency for a model that doesn't declare one — the tenant data plane. */
|
|
25
|
+
export const DEFAULT_RESIDENCY = 'tenant';
|
|
26
|
+
// ── Deprecated aliases (published schema subpath) ───────────────────────────
|
|
27
|
+
/** @deprecated Use `residencySchema`. */
|
|
28
|
+
export const planeSchema = residencySchema;
|
|
29
|
+
/** @deprecated Use `DEFAULT_RESIDENCY`. */
|
|
30
|
+
export const DEFAULT_PLANE = DEFAULT_RESIDENCY;
|