@abloatai/transaction 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/CONVENTIONS.md +83 -0
- package/README.md +48 -0
- package/dist/ablo.d.ts +90 -0
- package/dist/ablo.d.ts.map +1 -0
- package/dist/ablo.js +34 -0
- package/dist/ablo.js.map +1 -0
- package/dist/ai-sdk/coordinatedTool.d.ts +123 -0
- package/dist/ai-sdk/coordinatedTool.d.ts.map +1 -0
- package/dist/ai-sdk/coordinatedTool.js +135 -0
- package/dist/ai-sdk/coordinatedTool.js.map +1 -0
- package/dist/ai-sdk/index.d.ts +2 -0
- package/dist/ai-sdk/index.d.ts.map +1 -0
- package/dist/ai-sdk/index.js +2 -0
- package/dist/ai-sdk/index.js.map +1 -0
- package/dist/auth/apiKey.d.ts +154 -0
- package/dist/auth/apiKey.d.ts.map +1 -0
- package/dist/auth/apiKey.js +408 -0
- package/dist/auth/apiKey.js.map +1 -0
- package/dist/auth/bootstrapScope.d.ts +16 -0
- package/dist/auth/bootstrapScope.d.ts.map +1 -0
- package/dist/auth/bootstrapScope.js +2 -0
- package/dist/auth/bootstrapScope.js.map +1 -0
- package/dist/auth/browserCredentialSafety.d.ts +7 -0
- package/dist/auth/browserCredentialSafety.d.ts.map +1 -0
- package/dist/auth/browserCredentialSafety.js +29 -0
- package/dist/auth/browserCredentialSafety.js.map +1 -0
- package/dist/auth/capability.d.ts +241 -0
- package/dist/auth/capability.d.ts.map +1 -0
- package/dist/auth/capability.js +253 -0
- package/dist/auth/capability.js.map +1 -0
- package/dist/auth/capabilityLifecycle.d.ts +47 -0
- package/dist/auth/capabilityLifecycle.d.ts.map +1 -0
- package/dist/auth/capabilityLifecycle.js +108 -0
- package/dist/auth/capabilityLifecycle.js.map +1 -0
- package/dist/auth/credentialEndpoint.d.ts +10 -0
- package/dist/auth/credentialEndpoint.d.ts.map +1 -0
- package/dist/auth/credentialEndpoint.js +58 -0
- package/dist/auth/credentialEndpoint.js.map +1 -0
- package/dist/auth/credentialEndpointProtocol.d.ts +24 -0
- package/dist/auth/credentialEndpointProtocol.d.ts.map +1 -0
- package/dist/auth/credentialEndpointProtocol.js +34 -0
- package/dist/auth/credentialEndpointProtocol.js.map +1 -0
- package/dist/auth/credentialKind.d.ts +4 -0
- package/dist/auth/credentialKind.d.ts.map +1 -0
- package/dist/auth/credentialKind.js +15 -0
- package/dist/auth/credentialKind.js.map +1 -0
- package/dist/auth/credentialPolicy.d.ts +141 -0
- package/dist/auth/credentialPolicy.d.ts.map +1 -0
- package/dist/auth/credentialPolicy.js +113 -0
- package/dist/auth/credentialPolicy.js.map +1 -0
- package/dist/auth/credentialResult.d.ts +7 -0
- package/dist/auth/credentialResult.d.ts.map +1 -0
- package/dist/auth/credentialResult.js +9 -0
- package/dist/auth/credentialResult.js.map +1 -0
- package/dist/auth/credentialSource.d.ts +31 -0
- package/dist/auth/credentialSource.d.ts.map +1 -0
- package/dist/auth/credentialSource.js +56 -0
- package/dist/auth/credentialSource.js.map +1 -0
- package/dist/auth/hostedEndpoints.d.ts +22 -0
- package/dist/auth/hostedEndpoints.d.ts.map +1 -0
- package/dist/auth/hostedEndpoints.js +22 -0
- package/dist/auth/hostedEndpoints.js.map +1 -0
- package/dist/auth/identity.d.ts +62 -0
- package/dist/auth/identity.d.ts.map +1 -0
- package/dist/auth/identity.js +224 -0
- package/dist/auth/identity.js.map +1 -0
- package/dist/auth/index.d.ts +189 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +312 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/schemas.d.ts +41 -0
- package/dist/auth/schemas.d.ts.map +1 -0
- package/dist/auth/schemas.js +69 -0
- package/dist/auth/schemas.js.map +1 -0
- package/dist/auth/sessionMint.d.ts +29 -0
- package/dist/auth/sessionMint.d.ts.map +1 -0
- package/dist/auth/sessionMint.js +92 -0
- package/dist/auth/sessionMint.js.map +1 -0
- package/dist/auth/token.d.ts +4 -0
- package/dist/auth/token.d.ts.map +1 -0
- package/dist/auth/token.js +4 -0
- package/dist/auth/token.js.map +1 -0
- package/dist/batching/index.d.ts +56 -0
- package/dist/batching/index.d.ts.map +1 -0
- package/dist/batching/index.js +148 -0
- package/dist/batching/index.js.map +1 -0
- package/dist/coordination/awaitClaimGrant.d.ts +57 -0
- package/dist/coordination/awaitClaimGrant.d.ts.map +1 -0
- package/dist/coordination/awaitClaimGrant.js +138 -0
- package/dist/coordination/awaitClaimGrant.js.map +1 -0
- package/dist/coordination/claimHeartbeatLoop.d.ts +85 -0
- package/dist/coordination/claimHeartbeatLoop.d.ts.map +1 -0
- package/dist/coordination/claimHeartbeatLoop.js +109 -0
- package/dist/coordination/claimHeartbeatLoop.js.map +1 -0
- package/dist/coordination/claimMeta.d.ts +50 -0
- package/dist/coordination/claimMeta.d.ts.map +1 -0
- package/dist/coordination/claimMeta.js +53 -0
- package/dist/coordination/claimMeta.js.map +1 -0
- package/dist/coordination/events.d.ts +75 -0
- package/dist/coordination/events.d.ts.map +1 -0
- package/dist/coordination/events.js +8 -0
- package/dist/coordination/events.js.map +1 -0
- package/dist/coordination/index.d.ts +20 -0
- package/dist/coordination/index.d.ts.map +1 -0
- package/dist/coordination/index.js +46 -0
- package/dist/coordination/index.js.map +1 -0
- package/dist/coordination/locator.d.ts +106 -0
- package/dist/coordination/locator.d.ts.map +1 -0
- package/dist/coordination/locator.js +110 -0
- package/dist/coordination/locator.js.map +1 -0
- package/dist/coordination/schema.d.ts +1332 -0
- package/dist/coordination/schema.d.ts.map +1 -0
- package/dist/coordination/schema.js +1137 -0
- package/dist/coordination/schema.js.map +1 -0
- package/dist/coordination/targetConflict.d.ts +3 -0
- package/dist/coordination/targetConflict.d.ts.map +1 -0
- package/dist/coordination/targetConflict.js +74 -0
- package/dist/coordination/targetConflict.js.map +1 -0
- package/dist/coordination/trace.d.ts +79 -0
- package/dist/coordination/trace.d.ts.map +1 -0
- package/dist/coordination/trace.js +139 -0
- package/dist/coordination/trace.js.map +1 -0
- package/dist/docs/catalog.d.ts +73 -0
- package/dist/docs/catalog.d.ts.map +1 -0
- package/dist/docs/catalog.js +231 -0
- package/dist/docs/catalog.js.map +1 -0
- package/dist/docs/index.d.ts +11 -0
- package/dist/docs/index.d.ts.map +1 -0
- package/dist/docs/index.js +11 -0
- package/dist/docs/index.js.map +1 -0
- package/dist/durableWrites.d.ts +63 -0
- package/dist/durableWrites.d.ts.map +1 -0
- package/dist/durableWrites.js +72 -0
- package/dist/durableWrites.js.map +1 -0
- package/dist/environment.d.ts +106 -0
- package/dist/environment.d.ts.map +1 -0
- package/dist/environment.js +109 -0
- package/dist/environment.js.map +1 -0
- package/dist/errorCodes.d.ts +411 -0
- package/dist/errorCodes.d.ts.map +1 -0
- package/dist/errorCodes.js +500 -0
- package/dist/errorCodes.js.map +1 -0
- package/dist/errors.d.ts +429 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +687 -0
- package/dist/errors.js.map +1 -0
- package/dist/footprint.d.ts +112 -0
- package/dist/footprint.d.ts.map +1 -0
- package/dist/footprint.js +0 -0
- package/dist/footprint.js.map +1 -0
- package/dist/headlessClient.d.ts +10 -0
- package/dist/headlessClient.d.ts.map +1 -0
- package/dist/headlessClient.js +114 -0
- package/dist/headlessClient.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/keys/index.d.ts +88 -0
- package/dist/keys/index.d.ts.map +1 -0
- package/dist/keys/index.js +208 -0
- package/dist/keys/index.js.map +1 -0
- package/dist/log/syncDeltaRow.d.ts +159 -0
- package/dist/log/syncDeltaRow.d.ts.map +1 -0
- package/dist/log/syncDeltaRow.js +96 -0
- package/dist/log/syncDeltaRow.js.map +1 -0
- package/dist/logger.d.ts +17 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +8 -0
- package/dist/logger.js.map +1 -0
- package/dist/observability.d.ts +54 -0
- package/dist/observability.d.ts.map +1 -0
- package/dist/observability.js +20 -0
- package/dist/observability.js.map +1 -0
- package/dist/policy/types.d.ts +218 -0
- package/dist/policy/types.d.ts.map +1 -0
- package/dist/policy/types.js +127 -0
- package/dist/policy/types.js.map +1 -0
- package/dist/resources/functionalUpdate.d.ts +80 -0
- package/dist/resources/functionalUpdate.d.ts.map +1 -0
- package/dist/resources/functionalUpdate.js +88 -0
- package/dist/resources/functionalUpdate.js.map +1 -0
- package/dist/resources/httpResources.d.ts +449 -0
- package/dist/resources/httpResources.d.ts.map +1 -0
- package/dist/resources/httpResources.js +8 -0
- package/dist/resources/httpResources.js.map +1 -0
- package/dist/resources/modelOperations.d.ts +380 -0
- package/dist/resources/modelOperations.d.ts.map +1 -0
- package/dist/resources/modelOperations.js +13 -0
- package/dist/resources/modelOperations.js.map +1 -0
- package/dist/resources/mutationOptions.d.ts +67 -0
- package/dist/resources/mutationOptions.d.ts.map +1 -0
- package/dist/resources/mutationOptions.js +10 -0
- package/dist/resources/mutationOptions.js.map +1 -0
- package/dist/resources/where.d.ts +102 -0
- package/dist/resources/where.d.ts.map +1 -0
- package/dist/resources/where.js +116 -0
- package/dist/resources/where.js.map +1 -0
- package/dist/resources/writeOptionsSchema.d.ts +48 -0
- package/dist/resources/writeOptionsSchema.d.ts.map +1 -0
- package/dist/resources/writeOptionsSchema.js +74 -0
- package/dist/resources/writeOptionsSchema.js.map +1 -0
- package/dist/schema/coordination.d.ts +113 -0
- package/dist/schema/coordination.d.ts.map +1 -0
- package/dist/schema/coordination.js +134 -0
- package/dist/schema/coordination.js.map +1 -0
- package/dist/schema/ddl.d.ts +98 -0
- package/dist/schema/ddl.d.ts.map +1 -0
- package/dist/schema/ddl.js +492 -0
- package/dist/schema/ddl.js.map +1 -0
- package/dist/schema/ddlLock.d.ts +36 -0
- package/dist/schema/ddlLock.d.ts.map +1 -0
- package/dist/schema/ddlLock.js +47 -0
- package/dist/schema/ddlLock.js.map +1 -0
- package/dist/schema/diff.d.ts +226 -0
- package/dist/schema/diff.d.ts.map +1 -0
- package/dist/schema/diff.js +290 -0
- package/dist/schema/diff.js.map +1 -0
- package/dist/schema/field.d.ts +121 -0
- package/dist/schema/field.d.ts.map +1 -0
- package/dist/schema/field.js +266 -0
- package/dist/schema/field.js.map +1 -0
- package/dist/schema/fieldRef.d.ts +58 -0
- package/dist/schema/fieldRef.d.ts.map +1 -0
- package/dist/schema/fieldRef.js +26 -0
- package/dist/schema/fieldRef.js.map +1 -0
- package/dist/schema/generate.d.ts +20 -0
- package/dist/schema/generate.d.ts.map +1 -0
- package/dist/schema/generate.js +87 -0
- package/dist/schema/generate.js.map +1 -0
- package/dist/schema/index.d.ts +43 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +81 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/loadStrategy.d.ts +46 -0
- package/dist/schema/loadStrategy.d.ts.map +1 -0
- package/dist/schema/loadStrategy.js +47 -0
- package/dist/schema/loadStrategy.js.map +1 -0
- package/dist/schema/model.d.ts +380 -0
- package/dist/schema/model.d.ts.map +1 -0
- package/dist/schema/model.js +124 -0
- package/dist/schema/model.js.map +1 -0
- package/dist/schema/openapi.d.ts +59 -0
- package/dist/schema/openapi.d.ts.map +1 -0
- package/dist/schema/openapi.js +508 -0
- package/dist/schema/openapi.js.map +1 -0
- package/dist/schema/queries.d.ts +202 -0
- package/dist/schema/queries.d.ts.map +1 -0
- package/dist/schema/queries.js +144 -0
- package/dist/schema/queries.js.map +1 -0
- package/dist/schema/relation.d.ts +205 -0
- package/dist/schema/relation.d.ts.map +1 -0
- package/dist/schema/relation.js +105 -0
- package/dist/schema/relation.js.map +1 -0
- package/dist/schema/residency.d.ts +30 -0
- package/dist/schema/residency.d.ts.map +1 -0
- package/dist/schema/residency.js +26 -0
- package/dist/schema/residency.js.map +1 -0
- package/dist/schema/roles.d.ts +250 -0
- package/dist/schema/roles.d.ts.map +1 -0
- package/dist/schema/roles.js +231 -0
- package/dist/schema/roles.js.map +1 -0
- package/dist/schema/schema.d.ts +352 -0
- package/dist/schema/schema.d.ts.map +1 -0
- package/dist/schema/schema.js +326 -0
- package/dist/schema/schema.js.map +1 -0
- package/dist/schema/select.d.ts +41 -0
- package/dist/schema/select.d.ts.map +1 -0
- package/dist/schema/select.js +91 -0
- package/dist/schema/select.js.map +1 -0
- package/dist/schema/serialize.d.ts +116 -0
- package/dist/schema/serialize.d.ts.map +1 -0
- package/dist/schema/serialize.js +278 -0
- package/dist/schema/serialize.js.map +1 -0
- package/dist/schema/sugar.d.ts +110 -0
- package/dist/schema/sugar.d.ts.map +1 -0
- package/dist/schema/sugar.js +84 -0
- package/dist/schema/sugar.js.map +1 -0
- package/dist/schema/tenancy.d.ts +140 -0
- package/dist/schema/tenancy.d.ts.map +1 -0
- package/dist/schema/tenancy.js +191 -0
- package/dist/schema/tenancy.js.map +1 -0
- package/dist/server/adapter.d.ts +174 -0
- package/dist/server/adapter.d.ts.map +1 -0
- package/dist/server/adapter.js +19 -0
- package/dist/server/adapter.js.map +1 -0
- package/dist/server/commit.d.ts +108 -0
- package/dist/server/commit.d.ts.map +1 -0
- package/dist/server/commit.js +2 -0
- package/dist/server/commit.js.map +1 -0
- package/dist/server/index.d.ts +15 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +3 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/readConfig.d.ts +81 -0
- package/dist/server/readConfig.d.ts.map +1 -0
- package/dist/server/readConfig.js +9 -0
- package/dist/server/readConfig.js.map +1 -0
- package/dist/server/storageMode.d.ts +24 -0
- package/dist/server/storageMode.d.ts.map +1 -0
- package/dist/server/storageMode.js +18 -0
- package/dist/server/storageMode.js.map +1 -0
- package/dist/source/adapter.d.ts +84 -0
- package/dist/source/adapter.d.ts.map +1 -0
- package/dist/source/adapter.js +25 -0
- package/dist/source/adapter.js.map +1 -0
- package/dist/source/adapters/drizzle.d.ts +49 -0
- package/dist/source/adapters/drizzle.d.ts.map +1 -0
- package/dist/source/adapters/drizzle.js +220 -0
- package/dist/source/adapters/drizzle.js.map +1 -0
- package/dist/source/adapters/kysely.d.ts +43 -0
- package/dist/source/adapters/kysely.d.ts.map +1 -0
- package/dist/source/adapters/kysely.js +206 -0
- package/dist/source/adapters/kysely.js.map +1 -0
- package/dist/source/adapters/kyselyMutationCore.d.ts +77 -0
- package/dist/source/adapters/kyselyMutationCore.d.ts.map +1 -0
- package/dist/source/adapters/kyselyMutationCore.js +126 -0
- package/dist/source/adapters/kyselyMutationCore.js.map +1 -0
- package/dist/source/adapters/memory.d.ts +14 -0
- package/dist/source/adapters/memory.d.ts.map +1 -0
- package/dist/source/adapters/memory.js +131 -0
- package/dist/source/adapters/memory.js.map +1 -0
- package/dist/source/adapters/prisma.d.ts +64 -0
- package/dist/source/adapters/prisma.d.ts.map +1 -0
- package/dist/source/adapters/prisma.js +203 -0
- package/dist/source/adapters/prisma.js.map +1 -0
- package/dist/source/conformance.d.ts +38 -0
- package/dist/source/conformance.d.ts.map +1 -0
- package/dist/source/conformance.js +216 -0
- package/dist/source/conformance.js.map +1 -0
- package/dist/source/connector.d.ts +96 -0
- package/dist/source/connector.d.ts.map +1 -0
- package/dist/source/connector.js +267 -0
- package/dist/source/connector.js.map +1 -0
- package/dist/source/connectorProtocol.d.ts +155 -0
- package/dist/source/connectorProtocol.d.ts.map +1 -0
- package/dist/source/connectorProtocol.js +164 -0
- package/dist/source/connectorProtocol.js.map +1 -0
- package/dist/source/contract.d.ts +196 -0
- package/dist/source/contract.d.ts.map +1 -0
- package/dist/source/contract.js +165 -0
- package/dist/source/contract.js.map +1 -0
- package/dist/source/drizzle.d.ts +2 -0
- package/dist/source/drizzle.d.ts.map +1 -0
- package/dist/source/drizzle.js +2 -0
- package/dist/source/drizzle.js.map +1 -0
- package/dist/source/factory.d.ts +93 -0
- package/dist/source/factory.d.ts.map +1 -0
- package/dist/source/factory.js +287 -0
- package/dist/source/factory.js.map +1 -0
- package/dist/source/idempotency.d.ts +62 -0
- package/dist/source/idempotency.d.ts.map +1 -0
- package/dist/source/idempotency.js +145 -0
- package/dist/source/idempotency.js.map +1 -0
- package/dist/source/index.d.ts +24 -0
- package/dist/source/index.d.ts.map +1 -0
- package/dist/source/index.js +29 -0
- package/dist/source/index.js.map +1 -0
- package/dist/source/kysely.d.ts +3 -0
- package/dist/source/kysely.d.ts.map +1 -0
- package/dist/source/kysely.js +3 -0
- package/dist/source/kysely.js.map +1 -0
- package/dist/source/migrations.d.ts +22 -0
- package/dist/source/migrations.d.ts.map +1 -0
- package/dist/source/migrations.js +104 -0
- package/dist/source/migrations.js.map +1 -0
- package/dist/source/next.d.ts +33 -0
- package/dist/source/next.d.ts.map +1 -0
- package/dist/source/next.js +26 -0
- package/dist/source/next.js.map +1 -0
- package/dist/source/pushQueue.d.ts +135 -0
- package/dist/source/pushQueue.d.ts.map +1 -0
- package/dist/source/pushQueue.js +257 -0
- package/dist/source/pushQueue.js.map +1 -0
- package/dist/source/signing.d.ts +93 -0
- package/dist/source/signing.d.ts.map +1 -0
- package/dist/source/signing.js +163 -0
- package/dist/source/signing.js.map +1 -0
- package/dist/source/types.d.ts +402 -0
- package/dist/source/types.d.ts.map +1 -0
- package/dist/source/types.js +60 -0
- package/dist/source/types.js.map +1 -0
- package/dist/syncLog/contract.d.ts +21 -0
- package/dist/syncLog/contract.d.ts.map +1 -0
- package/dist/syncLog/contract.js +20 -0
- package/dist/syncLog/contract.js.map +1 -0
- package/dist/syncLog/index.d.ts +2 -0
- package/dist/syncLog/index.d.ts.map +1 -0
- package/dist/syncLog/index.js +2 -0
- package/dist/syncLog/index.js.map +1 -0
- package/dist/testing/fixtures/httpResponses.d.ts +74 -0
- package/dist/testing/fixtures/httpResponses.d.ts.map +1 -0
- package/dist/testing/fixtures/httpResponses.js +102 -0
- package/dist/testing/fixtures/httpResponses.js.map +1 -0
- package/dist/transactionLayer.d.ts +110 -0
- package/dist/transactionLayer.d.ts.map +1 -0
- package/dist/transactionLayer.js +25 -0
- package/dist/transactionLayer.js.map +1 -0
- package/dist/transactions/settlement/commitEnvelope.d.ts +144 -0
- package/dist/transactions/settlement/commitEnvelope.d.ts.map +1 -0
- package/dist/transactions/settlement/commitEnvelope.js +162 -0
- package/dist/transactions/settlement/commitEnvelope.js.map +1 -0
- package/dist/transactions/settlement/httpCommitEnvelope.d.ts +54 -0
- package/dist/transactions/settlement/httpCommitEnvelope.d.ts.map +1 -0
- package/dist/transactions/settlement/httpCommitEnvelope.js +208 -0
- package/dist/transactions/settlement/httpCommitEnvelope.js.map +1 -0
- package/dist/transactions/settlement/idempotencyKey.d.ts +11 -0
- package/dist/transactions/settlement/idempotencyKey.d.ts.map +1 -0
- package/dist/transactions/settlement/idempotencyKey.js +10 -0
- package/dist/transactions/settlement/idempotencyKey.js.map +1 -0
- package/dist/transactions/settlement/pendingWrite.d.ts +113 -0
- package/dist/transactions/settlement/pendingWrite.d.ts.map +1 -0
- package/dist/transactions/settlement/pendingWrite.js +21 -0
- package/dist/transactions/settlement/pendingWrite.js.map +1 -0
- package/dist/transport/commitFrames.d.ts +91 -0
- package/dist/transport/commitFrames.d.ts.map +1 -0
- package/dist/transport/commitFrames.js +135 -0
- package/dist/transport/commitFrames.js.map +1 -0
- package/dist/transport/connectionManager.d.ts +216 -0
- package/dist/transport/connectionManager.d.ts.map +1 -0
- package/dist/transport/connectionManager.js +674 -0
- package/dist/transport/connectionManager.js.map +1 -0
- package/dist/transport/credentialLifecycle.d.ts +178 -0
- package/dist/transport/credentialLifecycle.d.ts.map +1 -0
- package/dist/transport/credentialLifecycle.js +324 -0
- package/dist/transport/credentialLifecycle.js.map +1 -0
- package/dist/transport/heartbeat.d.ts +66 -0
- package/dist/transport/heartbeat.d.ts.map +1 -0
- package/dist/transport/heartbeat.js +94 -0
- package/dist/transport/heartbeat.js.map +1 -0
- package/dist/transport/httpClient.d.ts +143 -0
- package/dist/transport/httpClient.d.ts.map +1 -0
- package/dist/transport/httpClient.js +150 -0
- package/dist/transport/httpClient.js.map +1 -0
- package/dist/transport/httpFeed.d.ts +4 -0
- package/dist/transport/httpFeed.d.ts.map +1 -0
- package/dist/transport/httpFeed.js +94 -0
- package/dist/transport/httpFeed.js.map +1 -0
- package/dist/transport/httpOptions.d.ts +34 -0
- package/dist/transport/httpOptions.d.ts.map +1 -0
- package/dist/transport/httpOptions.js +13 -0
- package/dist/transport/httpOptions.js.map +1 -0
- package/dist/transport/httpTransport.d.ts +68 -0
- package/dist/transport/httpTransport.d.ts.map +1 -0
- package/dist/transport/httpTransport.js +1433 -0
- package/dist/transport/httpTransport.js.map +1 -0
- package/dist/transport/networkProbe.d.ts +85 -0
- package/dist/transport/networkProbe.d.ts.map +1 -0
- package/dist/transport/networkProbe.js +208 -0
- package/dist/transport/networkProbe.js.map +1 -0
- package/dist/transport/wsFrameHandlers.d.ts +129 -0
- package/dist/transport/wsFrameHandlers.d.ts.map +1 -0
- package/dist/transport/wsFrameHandlers.js +429 -0
- package/dist/transport/wsFrameHandlers.js.map +1 -0
- package/dist/transport/wsTransport.d.ts +575 -0
- package/dist/transport/wsTransport.d.ts.map +1 -0
- package/dist/transport/wsTransport.js +1024 -0
- package/dist/transport/wsTransport.js.map +1 -0
- package/dist/types/assertExact.d.ts +18 -0
- package/dist/types/assertExact.d.ts.map +1 -0
- package/dist/types/assertExact.js +2 -0
- package/dist/types/assertExact.js.map +1 -0
- package/dist/types/global.d.ts +108 -0
- package/dist/types/global.d.ts.map +1 -0
- package/dist/types/global.js +41 -0
- package/dist/types/global.js.map +1 -0
- package/dist/types/index.d.ts +206 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +57 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/modelData.d.ts +11 -0
- package/dist/types/modelData.d.ts.map +1 -0
- package/dist/types/modelData.js +10 -0
- package/dist/types/modelData.js.map +1 -0
- package/dist/types/participant.d.ts +21 -0
- package/dist/types/participant.d.ts.map +1 -0
- package/dist/types/participant.js +11 -0
- package/dist/types/participant.js.map +1 -0
- package/dist/types/streams.d.ts +545 -0
- package/dist/types/streams.d.ts.map +1 -0
- package/dist/types/streams.js +12 -0
- package/dist/types/streams.js.map +1 -0
- package/dist/utils/asyncIterator.d.ts +35 -0
- package/dist/utils/asyncIterator.d.ts.map +1 -0
- package/dist/utils/asyncIterator.js +136 -0
- package/dist/utils/asyncIterator.js.map +1 -0
- package/dist/utils/duration.d.ts +51 -0
- package/dist/utils/duration.d.ts.map +1 -0
- package/dist/utils/duration.js +78 -0
- package/dist/utils/duration.js.map +1 -0
- package/dist/utils/json.d.ts +58 -0
- package/dist/utils/json.d.ts.map +1 -0
- package/dist/utils/json.js +277 -0
- package/dist/utils/json.js.map +1 -0
- package/dist/webhooks/events.d.ts +44 -0
- package/dist/webhooks/events.d.ts.map +1 -0
- package/dist/webhooks/events.js +43 -0
- package/dist/webhooks/events.js.map +1 -0
- package/dist/webhooks/index.d.ts +9 -0
- package/dist/webhooks/index.d.ts.map +1 -0
- package/dist/webhooks/index.js +9 -0
- package/dist/webhooks/index.js.map +1 -0
- package/dist/wire/accountResponses.d.ts +463 -0
- package/dist/wire/accountResponses.d.ts.map +1 -0
- package/dist/wire/accountResponses.js +294 -0
- package/dist/wire/accountResponses.js.map +1 -0
- package/dist/wire/auth.d.ts +57 -0
- package/dist/wire/auth.d.ts.map +1 -0
- package/dist/wire/auth.js +71 -0
- package/dist/wire/auth.js.map +1 -0
- package/dist/wire/bootstrapReason.d.ts +10 -0
- package/dist/wire/bootstrapReason.d.ts.map +1 -0
- package/dist/wire/bootstrapReason.js +9 -0
- package/dist/wire/bootstrapReason.js.map +1 -0
- package/dist/wire/claimEvent.d.ts +70 -0
- package/dist/wire/claimEvent.d.ts.map +1 -0
- package/dist/wire/claimEvent.js +74 -0
- package/dist/wire/claimEvent.js.map +1 -0
- package/dist/wire/claims.d.ts +475 -0
- package/dist/wire/claims.d.ts.map +1 -0
- package/dist/wire/claims.js +326 -0
- package/dist/wire/claims.js.map +1 -0
- package/dist/wire/commit.d.ts +604 -0
- package/dist/wire/commit.d.ts.map +1 -0
- package/dist/wire/commit.js +322 -0
- package/dist/wire/commit.js.map +1 -0
- package/dist/wire/delta.d.ts +251 -0
- package/dist/wire/delta.d.ts.map +1 -0
- package/dist/wire/delta.js +148 -0
- package/dist/wire/delta.js.map +1 -0
- package/dist/wire/errorEnvelope.d.ts +73 -0
- package/dist/wire/errorEnvelope.d.ts.map +1 -0
- package/dist/wire/errorEnvelope.js +124 -0
- package/dist/wire/errorEnvelope.js.map +1 -0
- package/dist/wire/feedCursor.d.ts +61 -0
- package/dist/wire/feedCursor.d.ts.map +1 -0
- package/dist/wire/feedCursor.js +83 -0
- package/dist/wire/feedCursor.js.map +1 -0
- package/dist/wire/feedEvent.d.ts +264 -0
- package/dist/wire/feedEvent.d.ts.map +1 -0
- package/dist/wire/feedEvent.js +66 -0
- package/dist/wire/feedEvent.js.map +1 -0
- package/dist/wire/frames.d.ts +195 -0
- package/dist/wire/frames.d.ts.map +1 -0
- package/dist/wire/frames.js +51 -0
- package/dist/wire/frames.js.map +1 -0
- package/dist/wire/inboundFrames.d.ts +490 -0
- package/dist/wire/inboundFrames.d.ts.map +1 -0
- package/dist/wire/inboundFrames.js +117 -0
- package/dist/wire/inboundFrames.js.map +1 -0
- package/dist/wire/index.d.ts +55 -0
- package/dist/wire/index.d.ts.map +1 -0
- package/dist/wire/index.js +84 -0
- package/dist/wire/index.js.map +1 -0
- package/dist/wire/listEnvelope.d.ts +38 -0
- package/dist/wire/listEnvelope.d.ts.map +1 -0
- package/dist/wire/listEnvelope.js +43 -0
- package/dist/wire/listEnvelope.js.map +1 -0
- package/dist/wire/modelMutations.d.ts +32 -0
- package/dist/wire/modelMutations.d.ts.map +1 -0
- package/dist/wire/modelMutations.js +53 -0
- package/dist/wire/modelMutations.js.map +1 -0
- package/dist/wire/modelResponses.d.ts +79 -0
- package/dist/wire/modelResponses.d.ts.map +1 -0
- package/dist/wire/modelResponses.js +44 -0
- package/dist/wire/modelResponses.js.map +1 -0
- package/dist/wire/modelShape.d.ts +79 -0
- package/dist/wire/modelShape.d.ts.map +1 -0
- package/dist/wire/modelShape.js +75 -0
- package/dist/wire/modelShape.js.map +1 -0
- package/dist/wire/protocol.d.ts +39 -0
- package/dist/wire/protocol.d.ts.map +1 -0
- package/dist/wire/protocol.js +39 -0
- package/dist/wire/protocol.js.map +1 -0
- package/dist/wire/protocolVersion.d.ts +74 -0
- package/dist/wire/protocolVersion.d.ts.map +1 -0
- package/dist/wire/protocolVersion.js +84 -0
- package/dist/wire/protocolVersion.js.map +1 -0
- package/package.json +187 -0
- package/src/ablo.ts +139 -0
- package/src/ai-sdk/coordinatedTool.ts +214 -0
- package/src/ai-sdk/index.ts +7 -0
- package/src/auth/apiKey.ts +540 -0
- package/src/auth/bootstrapScope.ts +15 -0
- package/src/auth/browserCredentialSafety.ts +48 -0
- package/src/auth/capability.ts +326 -0
- package/src/auth/capabilityLifecycle.ts +174 -0
- package/src/auth/credentialEndpoint.ts +79 -0
- package/src/auth/credentialEndpointProtocol.ts +51 -0
- package/src/auth/credentialKind.ts +20 -0
- package/src/auth/credentialPolicy.ts +244 -0
- package/src/auth/credentialResult.ts +23 -0
- package/src/auth/credentialSource.ts +99 -0
- package/src/auth/hostedEndpoints.ts +24 -0
- package/src/auth/identity.ts +330 -0
- package/src/auth/index.ts +592 -0
- package/src/auth/schemas.ts +94 -0
- package/src/auth/sessionMint.ts +126 -0
- package/src/auth/token.ts +4 -0
- package/src/batching/index.ts +200 -0
- package/src/coordination/awaitClaimGrant.ts +243 -0
- package/src/coordination/claimHeartbeatLoop.ts +165 -0
- package/src/coordination/claimMeta.ts +56 -0
- package/src/coordination/events.ts +86 -0
- package/src/coordination/index.ts +181 -0
- package/src/coordination/locator.ts +200 -0
- package/src/coordination/schema.ts +1346 -0
- package/src/coordination/targetConflict.ts +85 -0
- package/src/coordination/trace.ts +173 -0
- package/src/docs/catalog.ts +274 -0
- package/src/docs/index.ts +18 -0
- package/src/durableWrites.ts +134 -0
- package/src/environment.ts +132 -0
- package/src/errorCodes.ts +1591 -0
- package/src/errors.ts +918 -0
- package/src/footprint.ts +0 -0
- package/src/headlessClient.ts +161 -0
- package/src/index.ts +52 -0
- package/src/keys/index.ts +254 -0
- package/src/log/syncDeltaRow.ts +119 -0
- package/src/logger.ts +22 -0
- package/src/observability.ts +85 -0
- package/src/policy/types.ts +292 -0
- package/src/resources/functionalUpdate.ts +151 -0
- package/src/resources/httpResources.ts +520 -0
- package/src/resources/modelOperations.ts +444 -0
- package/src/resources/mutationOptions.ts +66 -0
- package/src/resources/where.ts +160 -0
- package/src/resources/writeOptionsSchema.ts +91 -0
- package/src/schema/coordination.ts +161 -0
- package/src/schema/ddl.ts +593 -0
- package/src/schema/ddlLock.ts +53 -0
- package/src/schema/diff.ts +489 -0
- package/src/schema/field.ts +321 -0
- package/src/schema/fieldRef.ts +88 -0
- package/src/schema/generate.ts +95 -0
- package/src/schema/index.ts +278 -0
- package/src/schema/loadStrategy.ts +52 -0
- package/src/schema/model.ts +476 -0
- package/src/schema/openapi.ts +658 -0
- package/src/schema/queries.ts +273 -0
- package/src/schema/relation.ts +291 -0
- package/src/schema/residency.ts +30 -0
- package/src/schema/roles.ts +325 -0
- package/src/schema/schema.ts +825 -0
- package/src/schema/select.ts +115 -0
- package/src/schema/serialize.ts +373 -0
- package/src/schema/sugar.ts +194 -0
- package/src/schema/tenancy.ts +221 -0
- package/src/server/adapter.ts +203 -0
- package/src/server/commit.ts +109 -0
- package/src/server/index.ts +26 -0
- package/src/server/readConfig.ts +82 -0
- package/src/server/storageMode.ts +20 -0
- package/src/source/adapter.ts +85 -0
- package/src/source/adapters/drizzle.ts +291 -0
- package/src/source/adapters/kysely.ts +346 -0
- package/src/source/adapters/kyselyMutationCore.ts +220 -0
- package/src/source/adapters/memory.ts +154 -0
- package/src/source/adapters/prisma.ts +282 -0
- package/src/source/conformance.ts +287 -0
- package/src/source/connector.ts +394 -0
- package/src/source/connectorProtocol.ts +189 -0
- package/src/source/contract.ts +221 -0
- package/src/source/drizzle.ts +1 -0
- package/src/source/factory.ts +444 -0
- package/src/source/idempotency.ts +189 -0
- package/src/source/index.ts +182 -0
- package/src/source/kysely.ts +2 -0
- package/src/source/migrations.ts +109 -0
- package/src/source/next.ts +38 -0
- package/src/source/pushQueue.ts +368 -0
- package/src/source/signing.ts +279 -0
- package/src/source/types.ts +502 -0
- package/src/syncLog/contract.ts +32 -0
- package/src/syncLog/index.ts +1 -0
- package/src/testing/fixtures/httpResponses.ts +155 -0
- package/src/transactionLayer.ts +122 -0
- package/src/transactions/settlement/commitEnvelope.ts +192 -0
- package/src/transactions/settlement/httpCommitEnvelope.ts +250 -0
- package/src/transactions/settlement/idempotencyKey.ts +11 -0
- package/src/transactions/settlement/pendingWrite.ts +24 -0
- package/src/transport/commitFrames.ts +225 -0
- package/src/transport/connectionManager.ts +856 -0
- package/src/transport/credentialLifecycle.ts +389 -0
- package/src/transport/heartbeat.ts +118 -0
- package/src/transport/httpClient.ts +354 -0
- package/src/transport/httpFeed.ts +111 -0
- package/src/transport/httpOptions.ts +41 -0
- package/src/transport/httpTransport.ts +1976 -0
- package/src/transport/networkProbe.ts +249 -0
- package/src/transport/wsFrameHandlers.ts +619 -0
- package/src/transport/wsTransport.ts +1491 -0
- package/src/types/assertExact.ts +17 -0
- package/src/types/global.ts +123 -0
- package/src/types/index.ts +270 -0
- package/src/types/modelData.ts +11 -0
- package/src/types/participant.ts +22 -0
- package/src/types/streams.ts +702 -0
- package/src/utils/asyncIterator.ts +141 -0
- package/src/utils/duration.ts +88 -0
- package/src/utils/json.ts +281 -0
- package/src/webhooks/events.ts +96 -0
- package/src/webhooks/index.ts +12 -0
- package/src/wire/accountResponses.ts +328 -0
- package/src/wire/auth.ts +86 -0
- package/src/wire/bootstrapReason.ts +10 -0
- package/src/wire/claimEvent.ts +85 -0
- package/src/wire/claims.ts +370 -0
- package/src/wire/commit.ts +379 -0
- package/src/wire/delta.ts +173 -0
- package/src/wire/errorEnvelope.ts +133 -0
- package/src/wire/feedCursor.ts +91 -0
- package/src/wire/feedEvent.ts +74 -0
- package/src/wire/frames.ts +77 -0
- package/src/wire/inboundFrames.ts +182 -0
- package/src/wire/index.ts +328 -0
- package/src/wire/listEnvelope.ts +51 -0
- package/src/wire/modelMutations.ts +55 -0
- package/src/wire/modelResponses.ts +48 -0
- package/src/wire/modelShape.ts +83 -0
- package/src/wire/protocol.ts +39 -0
- package/src/wire/protocolVersion.ts +97 -0
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema Definition + Type Inference
|
|
3
|
+
*
|
|
4
|
+
* defineSchema() wraps your models. Types are inferred via Zod — no custom type system.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* import { z } from 'zod';
|
|
8
|
+
* import { defineSchema, model, relation } from '@abloatai/transaction/schema';
|
|
9
|
+
*
|
|
10
|
+
* const schema = defineSchema({
|
|
11
|
+
* tasks: model({
|
|
12
|
+
* title: z.string(),
|
|
13
|
+
* status: z.enum(['todo', 'doing', 'done']).default('todo'),
|
|
14
|
+
* projectId: z.string().optional(),
|
|
15
|
+
* }, {
|
|
16
|
+
* project: relation.belongsTo('projects', 'projectId'),
|
|
17
|
+
* }),
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* type Task = InferModel<typeof schema, 'tasks'>;
|
|
21
|
+
*/
|
|
22
|
+
import { z } from 'zod';
|
|
23
|
+
import { AbloValidationError } from '../errors.js';
|
|
24
|
+
import { fieldRef } from './fieldRef.js';
|
|
25
|
+
import { scopeSchema, grantsRefSchema } from './roles.js';
|
|
26
|
+
// Sync-group roles (identity and entity) are defined in `./roles.js` and
|
|
27
|
+
// re-exported here so they can also be imported from this module. See
|
|
28
|
+
// `./roles.js` for the full vocabulary.
|
|
29
|
+
export { identityRole, entityRole, extractIdentityIds, extractEntityIds, composeIdentitySyncGroups, composeEntitySyncGroups, intersectRequestedWithAllowed, syncGroup, syncGroupSchema, syncGroupInputSchema, isSyncGroupInput, identityRoleSchema, entityRoleSchema, roleSchema, roleSourceSchema, scopeSchema, grantsRefSchema, groupsInputSchema, } from './roles.js';
|
|
30
|
+
function resolveCasing(fn) {
|
|
31
|
+
if (fn === undefined)
|
|
32
|
+
return (x) => x;
|
|
33
|
+
if (typeof fn === 'function')
|
|
34
|
+
return fn;
|
|
35
|
+
switch (fn) {
|
|
36
|
+
case 'snake_case':
|
|
37
|
+
return camelToSnake;
|
|
38
|
+
case 'camelCase':
|
|
39
|
+
return (x) => x;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** Converts a camelCase identifier to snake_case. Kept local so the package
|
|
43
|
+
* carries no database-driver dependency, and so consumers on any stack get the
|
|
44
|
+
* same result. */
|
|
45
|
+
function camelToSnake(identifier) {
|
|
46
|
+
return identifier.replace(/[A-Z]/g, (ch) => `_${ch.toLowerCase()}`);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Session settings Ablo already sets on its direct-write connection. A
|
|
50
|
+
* `sessionSettings` entry FORWARDS Ablo's trusted context into a setting the
|
|
51
|
+
* customer's own policies read — it may never reassign one of these, which would
|
|
52
|
+
* let a schema push relax the engine's own scoping, timeouts, or `row_security`.
|
|
53
|
+
* Shared with the engine's direct-write seam so authoring-time validation and
|
|
54
|
+
* the runtime guard read one list. See ADR 0011.
|
|
55
|
+
*/
|
|
56
|
+
export const RESERVED_SESSION_SETTINGS = [
|
|
57
|
+
'statement_timeout',
|
|
58
|
+
'lock_timeout',
|
|
59
|
+
'row_security',
|
|
60
|
+
'search_path',
|
|
61
|
+
'app.current_org_id',
|
|
62
|
+
'app.current_project_id',
|
|
63
|
+
'app.current_environment',
|
|
64
|
+
'app.current_sandbox_id',
|
|
65
|
+
'app.current_participant_id',
|
|
66
|
+
'app.current_participant_kind',
|
|
67
|
+
'app.current_user_id',
|
|
68
|
+
];
|
|
69
|
+
/**
|
|
70
|
+
* Base fields every synced model gets automatically.
|
|
71
|
+
*
|
|
72
|
+
* Exported (internal) so `parseSchema` can rebuild a model's validator the
|
|
73
|
+
* same way `defineSchema` does — `baseFieldsSchema.merge(modelSchema)` — when
|
|
74
|
+
* reconstructing a `Schema` from its JSON form.
|
|
75
|
+
*/
|
|
76
|
+
export const baseFieldsSchema = z.object({
|
|
77
|
+
id: z.string(),
|
|
78
|
+
createdAt: z.date(),
|
|
79
|
+
updatedAt: z.date(),
|
|
80
|
+
organizationId: z.string().optional(),
|
|
81
|
+
createdBy: z.string().optional(),
|
|
82
|
+
});
|
|
83
|
+
/**
|
|
84
|
+
* The base-column names every model carries automatically — the keys of
|
|
85
|
+
* {@link baseFieldsSchema}, kept here as the single source of truth. Code
|
|
86
|
+
* generation reads it to avoid emitting a base column twice, and
|
|
87
|
+
* {@link defineSchema} uses it to reject a model that redeclares one, since
|
|
88
|
+
* merging the user's field over the base field would produce a `string & Date`
|
|
89
|
+
* type and break the build.
|
|
90
|
+
*/
|
|
91
|
+
export const BASE_FIELDS = [
|
|
92
|
+
'id',
|
|
93
|
+
'createdAt',
|
|
94
|
+
'updatedAt',
|
|
95
|
+
'organizationId',
|
|
96
|
+
'createdBy',
|
|
97
|
+
];
|
|
98
|
+
// ── Factory ───────────────────────────────────────────────────────────────
|
|
99
|
+
/**
|
|
100
|
+
* Define a sync engine schema.
|
|
101
|
+
*
|
|
102
|
+
* ```ts
|
|
103
|
+
* const schema = defineSchema({
|
|
104
|
+
* tasks: model({ title: z.string(), status: z.string().default('todo') }),
|
|
105
|
+
* projects: model({ name: z.string() }),
|
|
106
|
+
* });
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
/**
|
|
110
|
+
* Rejects field names that will not survive the sync driver's snake_case ↔
|
|
111
|
+
* camelCase round-trip. The driver maps identifiers like this:
|
|
112
|
+
*
|
|
113
|
+
* `content_json` → `contentJson` (snake → camel)
|
|
114
|
+
* `contentJson` → `content_json` (camel → snake)
|
|
115
|
+
* `contentJSON` → `content_j_s_o_n` (does not round-trip)
|
|
116
|
+
*
|
|
117
|
+
* A name that does not round-trip through this pair of transforms will silently
|
|
118
|
+
* fail to populate on the client: the wire delivers one casing, the model reads
|
|
119
|
+
* another, and the field lands as `undefined`. Catching it here surfaces the
|
|
120
|
+
* problem when the schema is defined rather than at runtime.
|
|
121
|
+
*
|
|
122
|
+
* The rule: a standard camelCase identifier has runs of a single uppercase
|
|
123
|
+
* letter followed by lowercase letters, never two uppercase letters in a row.
|
|
124
|
+
* `contentJSON` has `JSON` in all caps, so it is rejected.
|
|
125
|
+
*/
|
|
126
|
+
function assertRoundTrippableCamelCase(modelName, fieldName) {
|
|
127
|
+
// Base fields merged in by defineSchema are already validated; skip.
|
|
128
|
+
if (fieldName === 'id')
|
|
129
|
+
return;
|
|
130
|
+
// Leading-lowercase constraint: fields must be camelCase, not PascalCase.
|
|
131
|
+
// PascalCase is reserved for typenames.
|
|
132
|
+
const first = fieldName.charAt(0);
|
|
133
|
+
if (first >= 'A' && first <= 'Z') {
|
|
134
|
+
throw new AbloValidationError(`[defineSchema] ${modelName}.${fieldName}: field names must start lowercase ` +
|
|
135
|
+
`(camelCase). Use "${first.toLowerCase()}${fieldName.slice(1)}" instead.`, { code: 'schema_field_not_camelcase' });
|
|
136
|
+
}
|
|
137
|
+
// Two-consecutive-uppercase check. The classic failure mode is
|
|
138
|
+
// `contentJSON`, `contentHTML`, `myURLParam`, etc. These don't round-trip
|
|
139
|
+
// through `postgres.camel` — the snake_case intermediate would be
|
|
140
|
+
// `content_j_s_o_n`, which is not a column that exists.
|
|
141
|
+
for (let i = 0; i < fieldName.length - 1; i++) {
|
|
142
|
+
const a = fieldName.charAt(i);
|
|
143
|
+
const b = fieldName.charAt(i + 1);
|
|
144
|
+
const aUpper = a >= 'A' && a <= 'Z';
|
|
145
|
+
const bUpper = b >= 'A' && b <= 'Z';
|
|
146
|
+
if (aUpper && bUpper) {
|
|
147
|
+
throw new AbloValidationError(`[defineSchema] ${modelName}.${fieldName}: two consecutive uppercase ` +
|
|
148
|
+
`letters ("${a}${b}") will not round-trip through the ` +
|
|
149
|
+
`snake_case ↔ camelCase transform used by the sync driver. ` +
|
|
150
|
+
`The wire delivers camelCase (lowercase after the first letter of ` +
|
|
151
|
+
`each word); a field named "${fieldName}" would never receive its ` +
|
|
152
|
+
`value and read as undefined on the client. Use standard ` +
|
|
153
|
+
`camelCase (e.g. "contentJson" instead of "contentJSON").`, { code: 'schema_field_consecutive_caps' });
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* One {@link FieldRef} per declared field, keyed by model then field.
|
|
159
|
+
*
|
|
160
|
+
* Every construction of a {@link Schema} goes through here — `defineSchema`,
|
|
161
|
+
* the `selectModels`/`omitModels` projections, and the deserializer — so a
|
|
162
|
+
* projection carries references for exactly the models it kept and a schema
|
|
163
|
+
* rebuilt from JSON carries them at all.
|
|
164
|
+
*/
|
|
165
|
+
export function buildFieldRefs(models) {
|
|
166
|
+
const refs = {};
|
|
167
|
+
for (const [model, def] of Object.entries(models)) {
|
|
168
|
+
const perField = {};
|
|
169
|
+
for (const field of Object.keys(def.shape))
|
|
170
|
+
perField[field] = fieldRef(model, field);
|
|
171
|
+
refs[model] = perField;
|
|
172
|
+
}
|
|
173
|
+
return refs;
|
|
174
|
+
}
|
|
175
|
+
export function defineSchema(models, options) {
|
|
176
|
+
// Build validators with base fields merged in, and resolve defaults for
|
|
177
|
+
// `typename` and `persist.store` so downstream code (the loader and the
|
|
178
|
+
// hydration pipeline) can rely on these fields being set without re-deriving
|
|
179
|
+
// them at every call site.
|
|
180
|
+
//
|
|
181
|
+
// Defaults:
|
|
182
|
+
// typename ← schema key (e.g. `block` → `'block'`)
|
|
183
|
+
// persist.store ← typename (only resolved when `persist` was provided)
|
|
184
|
+
//
|
|
185
|
+
// A consumer that passes `typename: 'Block'` explicitly (common when
|
|
186
|
+
// the wire shape uses PascalCase while the schema key is camelCase) keeps
|
|
187
|
+
// that value — the fallback only fires when the field is unset.
|
|
188
|
+
//
|
|
189
|
+
// The models record is rebuilt rather than mutated in place because
|
|
190
|
+
// `ModelDef`'s fields are `readonly`. The rebuild is a shallow spread per
|
|
191
|
+
// entry, so the inferred shape/relations/fields metadata references are
|
|
192
|
+
// preserved (no type inference regression at consumer call sites).
|
|
193
|
+
const validators = {};
|
|
194
|
+
const resolvedModels = {};
|
|
195
|
+
const casing = resolveCasing(options?.casing);
|
|
196
|
+
for (const [name, def] of Object.entries(models)) {
|
|
197
|
+
// Catch round-trip-hostile field names at definition time. Deferring
|
|
198
|
+
// this check to runtime means every affected field silently reads
|
|
199
|
+
// `undefined` on the client — and the author only notices when a UI
|
|
200
|
+
// that depends on the field goes blank. Throwing here makes the
|
|
201
|
+
// failure immediate and unambiguous.
|
|
202
|
+
for (const fieldName of Object.keys(def.shape)) {
|
|
203
|
+
assertRoundTrippableCamelCase(name, fieldName);
|
|
204
|
+
// Reserved base columns are merged in below via `baseFieldsSchema.merge`,
|
|
205
|
+
// and Zod `.merge` silently OVERWRITES the base field with the user's —
|
|
206
|
+
// e.g. a model declaring `createdAt: z.string()` ends up with a field
|
|
207
|
+
// typed `string & Date`, which breaks the build. Reject the collision at
|
|
208
|
+
// definition time so the author sees an unambiguous error instead.
|
|
209
|
+
if (BASE_FIELDS.includes(fieldName)) {
|
|
210
|
+
throw new AbloValidationError(`[defineSchema] ${name}.${fieldName}: field \`${fieldName}\` collides with a ` +
|
|
211
|
+
`reserved field that the SDK provides automatically ` +
|
|
212
|
+
`(${BASE_FIELDS.join(', ')}). Remove it from your model — redeclaring it ` +
|
|
213
|
+
`produces a \`string & Date\` type and breaks the build.`, { code: 'schema_reserved_field', param: `${name}.${fieldName}` });
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
validators[name] = baseFieldsSchema.merge(def.schema);
|
|
217
|
+
// Resolve every relation's `foreignKeyColumn` once, now. The builder
|
|
218
|
+
// constructs each RelationDef with `foreignKeyColumn = foreignKey`
|
|
219
|
+
// (identity) so this is a no-op when `casing` is unset — existing
|
|
220
|
+
// consumers get the same behavior they had before the option landed.
|
|
221
|
+
// When `casing: 'snake_case'` is set, every FK flips to its
|
|
222
|
+
// snake_case DB column name here and nowhere else. A field-level
|
|
223
|
+
// `.from(column)` override wins over the convention, so legacy
|
|
224
|
+
// columns stay declared in the artifact instead of rediscovered by
|
|
225
|
+
// SQL compilers. Server-side SQL compilers read the resolved value
|
|
226
|
+
// directly.
|
|
227
|
+
for (const rel of Object.values(def.relations)) {
|
|
228
|
+
const fieldColumn = def.fields[rel.foreignKey]?.column;
|
|
229
|
+
rel.foreignKeyColumn = fieldColumn ?? casing(rel.foreignKey);
|
|
230
|
+
}
|
|
231
|
+
const typename = def.typename ?? name;
|
|
232
|
+
const persist = def.persist
|
|
233
|
+
? { ...def.persist, store: def.persist.store ?? typename }
|
|
234
|
+
: undefined;
|
|
235
|
+
// Physical table defaults to the schema key — the SAME rule the
|
|
236
|
+
// provisioner/planner use (`tableName ?? key`), resolved here once so the
|
|
237
|
+
// serialized artifact always carries it. Required now that models are
|
|
238
|
+
// mutable by default: the server's `buildModelMap` rejects a mutable
|
|
239
|
+
// model with no `tableName`, which would otherwise break every commit.
|
|
240
|
+
const tableName = def.tableName ?? name;
|
|
241
|
+
resolvedModels[name] = { ...def, typename, tableName, persist };
|
|
242
|
+
}
|
|
243
|
+
validateSyncGroupSchema(resolvedModels);
|
|
244
|
+
validateSessionSettings(options?.sessionSettings ?? {});
|
|
245
|
+
return {
|
|
246
|
+
// Cast back to S: we only added values to optional fields that were
|
|
247
|
+
// already part of ModelDef, so the shape is structurally unchanged.
|
|
248
|
+
models: resolvedModels,
|
|
249
|
+
validators: validators,
|
|
250
|
+
fields: buildFieldRefs(resolvedModels),
|
|
251
|
+
identityRoles: options?.identityRoles ?? [],
|
|
252
|
+
sessionSettings: options?.sessionSettings ?? {},
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Reject session-setting mappings that couldn't do what the author intends —
|
|
257
|
+
* caught here at definition time rather than silently dropped on the write path.
|
|
258
|
+
* Each key must name a non-empty setting the customer's policies read, and must
|
|
259
|
+
* not reassign one Ablo already manages. Uniqueness needs no check: the map is
|
|
260
|
+
* keyed by the setting name, so a duplicate is unrepresentable.
|
|
261
|
+
*/
|
|
262
|
+
function validateSessionSettings(settings) {
|
|
263
|
+
for (const setting of Object.keys(settings)) {
|
|
264
|
+
const name = setting.trim();
|
|
265
|
+
if (name === '') {
|
|
266
|
+
throw new AbloValidationError(`[defineSchema] sessionSettings: a key is empty. Name the Postgres ` +
|
|
267
|
+
`setting your row-level-security policies read, e.g. ` +
|
|
268
|
+
`\`{ 'app.current_org': 'orgId' }\`.`, { code: 'schema_definition_invalid', param: 'sessionSettings' });
|
|
269
|
+
}
|
|
270
|
+
if (RESERVED_SESSION_SETTINGS.includes(name)) {
|
|
271
|
+
throw new AbloValidationError(`[defineSchema] sessionSettings: \`${name}\` is a setting Ablo already ` +
|
|
272
|
+
`manages on its write connection, so a mapping can't reassign it — ` +
|
|
273
|
+
`that would let a schema relax the engine's own scoping. Point your ` +
|
|
274
|
+
`policies at a setting your app owns (e.g. \`app.current_org\`) and ` +
|
|
275
|
+
`map Ablo's trusted identity into that instead. Reserved: ` +
|
|
276
|
+
`${RESERVED_SESSION_SETTINGS.join(', ')}.`, { code: 'schema_definition_invalid', param: `sessionSettings.${name}` });
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Validates the relation-driven sync-group declarations (`scope` and `grants`)
|
|
282
|
+
* at schema-build time, so a mistyped membership edge fails here — with a
|
|
283
|
+
* structured error (`code`, `param`, `doc_url`) pointing at the exact
|
|
284
|
+
* declaration — rather than silently mis-routing changes at runtime.
|
|
285
|
+
*/
|
|
286
|
+
function validateSyncGroupSchema(models) {
|
|
287
|
+
for (const [name, def] of Object.entries(models)) {
|
|
288
|
+
// Shape-validate the `scope` declaration via the shared Zod schema.
|
|
289
|
+
if (def.scope !== undefined && !scopeSchema.safeParse(def.scope).success) {
|
|
290
|
+
throw new AbloValidationError(`Model "${name}": scope kind "${String(def.scope)}" must be a lowercase identifier (e.g. 'workspace').`, { code: 'schema_scope_kind_invalid', param: `${name}.scope` });
|
|
291
|
+
}
|
|
292
|
+
if (!def.grants)
|
|
293
|
+
continue;
|
|
294
|
+
// Shape-validate the `grants` edge via the shared Zod schema before the
|
|
295
|
+
// cross-field (relation-exists / belongsTo) checks below.
|
|
296
|
+
if (!grantsRefSchema.safeParse(def.grants).success) {
|
|
297
|
+
throw new AbloValidationError(`Model "${name}": grants must be { subject, scope } naming two relations on this model.`, { code: 'schema_grants_shape_invalid', param: `${name}.grants` });
|
|
298
|
+
}
|
|
299
|
+
const relations = def.relations;
|
|
300
|
+
for (const role of ['subject', 'scope']) {
|
|
301
|
+
const relName = def.grants[role];
|
|
302
|
+
const rel = relations?.[relName];
|
|
303
|
+
if (!rel) {
|
|
304
|
+
throw new AbloValidationError(`Model "${name}": grants.${role} "${relName}" is not a relation on this model. ` +
|
|
305
|
+
`Declare a \`belongsTo\` relation named "${relName}" first.`, { code: 'schema_grants_relation_missing', param: `${name}.grants.${role}` });
|
|
306
|
+
}
|
|
307
|
+
if (rel.type !== 'belongsTo') {
|
|
308
|
+
throw new AbloValidationError(`Model "${name}": grants.${role} "${relName}" must be a \`belongsTo\` relation ` +
|
|
309
|
+
`(got "${rel.type}"). A membership edge points at a single subject/scope row.`, { code: 'schema_grants_relation_kind', param: `${name}.grants.${role}` });
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
// The scope edge must target a model that is actually a scope root —
|
|
313
|
+
// otherwise the resolved `<kind>:<id>` group is one nothing fans into.
|
|
314
|
+
const scopeRel = relations[def.grants.scope];
|
|
315
|
+
// Unreachable: the role loop above already threw if the scope relation
|
|
316
|
+
// is missing — this narrows the indexed access for the checks below.
|
|
317
|
+
if (!scopeRel)
|
|
318
|
+
continue;
|
|
319
|
+
const target = models[scopeRel.target];
|
|
320
|
+
if (target && !target.scope) {
|
|
321
|
+
throw new AbloValidationError(`Model "${name}": grants.scope "${def.grants.scope}" targets "${scopeRel.target}", ` +
|
|
322
|
+
`which is not a scope root. Add \`scope: true\` to the "${scopeRel.target}" model.`, { code: 'schema_grants_target_not_scope_root', param: `${scopeRel.target}.scope` });
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/schema/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAE,QAAQ,EAAiB,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE1D,yEAAyE;AACzE,sEAAsE;AACtE,wCAAwC;AACxC,OAAO,EAWL,YAAY,EACZ,UAAU,EACV,kBAAkB,EAClB,gBAAgB,EAChB,yBAAyB,EACzB,uBAAuB,EACvB,6BAA6B,EAC7B,SAAS,EACT,eAAe,EACf,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,eAAe,EACf,iBAAiB,GAElB,MAAM,YAAY,CAAC;AAqBpB,SAAS,aAAa,CAAC,EAAsB;IAC3C,IAAI,EAAE,KAAK,SAAS;QAAE,OAAO,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IACtC,IAAI,OAAO,EAAE,KAAK,UAAU;QAAE,OAAO,EAAE,CAAC;IACxC,QAAQ,EAAE,EAAE,CAAC;QACX,KAAK,YAAY;YACf,OAAO,YAAY,CAAC;QACtB,KAAK,WAAW;YACd,OAAO,CAAC,CAAC,EAAE,EAAE,CAAC,CA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AAG,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;gBAC7B,MAAM,IAAI,mBAAmB,CAC3B,UAAU,IAAI,aAAa,IAAI,KAAK,OAAO,qCAAqC;oBAC9E,SAAS,GAAG,CAAC,IAAI,6DAA6D,EAChF,EAAE,IAAI,EAAE,6BAA6B,EAAE,KAAK,EAAE,GAAG,IAAI,WAAW,IAAI,EAAE,EAAE,CACzE,CAAC;YACJ,CAAC;QACH,CAAC;QAED,qEAAqE;QACrE,uEAAuE;QACvE,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC7C,uEAAuE;QACvE,qEAAqE;QACrE,IAAI,CAAC,QAAQ;YAAE,SAAS;QACxB,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACvC,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YAC5B,MAAM,IAAI,mBAAmB,CAC3B,UAAU,IAAI,oBAAoB,GAAG,CAAC,MAAM,CAAC,KAAK,cAAc,QAAQ,CAAC,MAAM,KAAK;gBAClF,0DAA0D,QAAQ,CAAC,MAAM,UAAU,EACrF,EAAE,IAAI,EAAE,qCAAqC,EAAE,KAAK,EAAE,GAAG,QAAQ,CAAC,MAAM,QAAQ,EAAE,CACnF,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `selectModels` projects a schema down to a subset of its models.
|
|
3
|
+
*
|
|
4
|
+
* It lets one canonical schema serve several apps, each subscribing only to the
|
|
5
|
+
* models it needs. Rather than re-declare a model's fields in a second schema —
|
|
6
|
+
* which you would then have to keep identical by hand — an app selects the
|
|
7
|
+
* models it wants from the canonical schema. Field shapes, resolved foreign-key
|
|
8
|
+
* columns, computed getters, typenames, and identity roles all come from the
|
|
9
|
+
* source, so a subset cannot drift from the canonical definition.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { schema as full } from './schema';
|
|
13
|
+
* import { selectModels } from '@abloatai/transaction/schema';
|
|
14
|
+
*
|
|
15
|
+
* // Subscribe to identity and document content only.
|
|
16
|
+
* export const schema = selectModels(full, ['users', 'organizations', 'workspaces', 'folders', 'files']);
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* Relations whose target falls outside the selected set are dropped, so the
|
|
20
|
+
* subset sees only its own models. Dropping a relation that carries `parent`
|
|
21
|
+
* scope-inheritance throws instead, because silently losing it would mis-route
|
|
22
|
+
* a record's fan-out — the selected set must be closed under `parent` edges.
|
|
23
|
+
*/
|
|
24
|
+
import type { Schema, SchemaRecord } from './schema.js';
|
|
25
|
+
export declare function selectModels<S extends SchemaRecord, K extends keyof S & string>(schema: Schema<S>, keys: readonly K[]): Schema<Pick<S, K>>;
|
|
26
|
+
/**
|
|
27
|
+
* `omitModels` is `selectModels` from the other side: keep every model EXCEPT
|
|
28
|
+
* the named ones. Use it when an app is the general case and a separate app
|
|
29
|
+
* owns the omitted models — the suite shell drops a specialized store that the
|
|
30
|
+
* standalone app selects for itself:
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* export const schema = omitModels(full, ['reports', 'reportSections']);
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* Same validation as `selectModels`: relations into the omitted set are
|
|
37
|
+
* dropped, and a dropped `parent` edge throws — so a model whose scope routes
|
|
38
|
+
* through an omitted parent cannot be silently kept.
|
|
39
|
+
*/
|
|
40
|
+
export declare function omitModels<S extends SchemaRecord, K extends keyof S & string>(schema: Schema<S>, keys: readonly K[]): Schema<Omit<S, K>>;
|
|
41
|
+
//# sourceMappingURL=select.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.d.ts","sourceRoot":"","sources":["../../src/schema/select.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAOxD,wBAAgB,YAAY,CAAC,CAAC,SAAS,YAAY,EAAE,CAAC,SAAS,MAAM,CAAC,GAAG,MAAM,EAC7E,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EACjB,IAAI,EAAE,SAAS,CAAC,EAAE,GACjB,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAiDpB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,YAAY,EAAE,CAAC,SAAS,MAAM,CAAC,GAAG,MAAM,EAC3E,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EACjB,IAAI,EAAE,SAAS,CAAC,EAAE,GACjB,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAYpB"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `selectModels` projects a schema down to a subset of its models.
|
|
3
|
+
*
|
|
4
|
+
* It lets one canonical schema serve several apps, each subscribing only to the
|
|
5
|
+
* models it needs. Rather than re-declare a model's fields in a second schema —
|
|
6
|
+
* which you would then have to keep identical by hand — an app selects the
|
|
7
|
+
* models it wants from the canonical schema. Field shapes, resolved foreign-key
|
|
8
|
+
* columns, computed getters, typenames, and identity roles all come from the
|
|
9
|
+
* source, so a subset cannot drift from the canonical definition.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { schema as full } from './schema';
|
|
13
|
+
* import { selectModels } from '@abloatai/transaction/schema';
|
|
14
|
+
*
|
|
15
|
+
* // Subscribe to identity and document content only.
|
|
16
|
+
* export const schema = selectModels(full, ['users', 'organizations', 'workspaces', 'folders', 'files']);
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* Relations whose target falls outside the selected set are dropped, so the
|
|
20
|
+
* subset sees only its own models. Dropping a relation that carries `parent`
|
|
21
|
+
* scope-inheritance throws instead, because silently losing it would mis-route
|
|
22
|
+
* a record's fan-out — the selected set must be closed under `parent` edges.
|
|
23
|
+
*/
|
|
24
|
+
import { buildFieldRefs } from './schema.js';
|
|
25
|
+
import { AbloValidationError } from '../errors.js';
|
|
26
|
+
import { schemaHash } from './serialize.js';
|
|
27
|
+
export function selectModels(schema, keys) {
|
|
28
|
+
const keep = new Set(keys);
|
|
29
|
+
const models = {};
|
|
30
|
+
const validators = {};
|
|
31
|
+
for (const key of keys) {
|
|
32
|
+
const def = schema.models[key];
|
|
33
|
+
if (!def) {
|
|
34
|
+
throw new AbloValidationError(`selectModels: "${key}" is not a model in the source schema`, { code: 'invalid_schema', param: key });
|
|
35
|
+
}
|
|
36
|
+
// Prune relations whose target isn't in the selected set. A pruned
|
|
37
|
+
// `parent` edge is a routing error, not a silent drop.
|
|
38
|
+
const relations = {};
|
|
39
|
+
for (const [relName, rel] of Object.entries(def.relations)) {
|
|
40
|
+
if (keep.has(rel.target)) {
|
|
41
|
+
relations[relName] = rel;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (rel.options?.parent) {
|
|
45
|
+
throw new AbloValidationError(`selectModels: model "${key}" has a parent relation "${relName}" → "${rel.target}", ` +
|
|
46
|
+
`which is not in the selected set. Include "${rel.target}" so scope inheritance still routes.`, { code: 'invalid_schema', param: `${key}.${relName}` });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
models[key] = { ...def, relations };
|
|
50
|
+
validators[key] = schema.validators[key];
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
models: models,
|
|
54
|
+
// References for exactly the models this projection kept.
|
|
55
|
+
fields: buildFieldRefs(models),
|
|
56
|
+
validators: validators,
|
|
57
|
+
identityRoles: schema.identityRoles,
|
|
58
|
+
sessionSettings: schema.sessionSettings,
|
|
59
|
+
// Record the full source's hash so the drift check can recognize this subset
|
|
60
|
+
// as current against a server running that full schema. Prefer the source's
|
|
61
|
+
// OWN `sourceSchemaHash` when it is itself a projection, so a subset-of-a-
|
|
62
|
+
// subset still points at the original full schema rather than an intermediate
|
|
63
|
+
// one. `schemaHash` ignores this field, so re-projecting stays deterministic.
|
|
64
|
+
sourceSchemaHash: schema.sourceSchemaHash ?? schemaHash(schema),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* `omitModels` is `selectModels` from the other side: keep every model EXCEPT
|
|
69
|
+
* the named ones. Use it when an app is the general case and a separate app
|
|
70
|
+
* owns the omitted models — the suite shell drops a specialized store that the
|
|
71
|
+
* standalone app selects for itself:
|
|
72
|
+
*
|
|
73
|
+
* ```ts
|
|
74
|
+
* export const schema = omitModels(full, ['reports', 'reportSections']);
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* Same validation as `selectModels`: relations into the omitted set are
|
|
78
|
+
* dropped, and a dropped `parent` edge throws — so a model whose scope routes
|
|
79
|
+
* through an omitted parent cannot be silently kept.
|
|
80
|
+
*/
|
|
81
|
+
export function omitModels(schema, keys) {
|
|
82
|
+
const drop = new Set(keys);
|
|
83
|
+
for (const key of keys) {
|
|
84
|
+
if (!schema.models[key]) {
|
|
85
|
+
throw new AbloValidationError(`omitModels: "${key}" is not a model in the source schema`, { code: 'invalid_schema', param: key });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const kept = Object.keys(schema.models).filter((k) => !drop.has(k));
|
|
89
|
+
return selectModels(schema, kept);
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=select.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.js","sourceRoot":"","sources":["../../src/schema/select.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AA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AI,MAAM,CAAC,UAAsC,CAAC,GAAG,CAAC,CAAC;IACxE,CAAC;IAED,OAAO;QACL,MAAM,EAAE,MAA+B;QACvC,0DAA0D;QAC1D,MAAM,EAAE,cAAc,CAAC,MAAM,CAAiC;QAC9D,UAAU,EAAE,UAA8C;QAC1D,aAAa,EAAE,MAAM,CAAC,aAAa;QACnC,eAAe,EAAE,MAAM,CAAC,eAAe;QACvC,6EAA6E;QAC7E,4EAA4E;QAC5E,2EAA2E;QAC3E,8EAA8E;QAC9E,8EAA8E;QAC9E,gBAAgB,EAAE,MAAM,CAAC,gBAAgB,IAAI,UAAU,CAAC,MAAM,CAAC;KAChE,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,UAAU,CACxB,MAAiB,EACjB,IAAkB;IAElB,MAAM,IAAI,GAAG,IAAI,GAAG,CAAS,IAAyB,CAAC,CAAC;IACxD,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;YACxB,MAAM,IAAI,mBAAmB,CAC3B,gBAAgB,GAAG,uCAAuC,EAC1D,EAAE,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE,GAAG,EAAE,CACvC,CAAC;QACJ,CAAC;IACH,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACpE,OAAO,YAAY,CAAC,MAAM,EAAE,IAA4B,CAAuB,CAAC;AAClF,CAAC"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema ⇄ JSON.
|
|
3
|
+
*
|
|
4
|
+
* A `Schema` is fully serializable apart from its client-only closures — the
|
|
5
|
+
* Zod validators and computed getters. {@link serializeSchema} emits the
|
|
6
|
+
* plain-data JSON form and {@link parseSchema} reconstructs a working `Schema`
|
|
7
|
+
* from it: one `Schema` type with two representations.
|
|
8
|
+
*
|
|
9
|
+
* A hosted, multi-tenant server loads a tenant's schema with `parseSchema(json)`
|
|
10
|
+
* rather than importing it in process. The JSON is what `ablo push` sends and
|
|
11
|
+
* what the server stores per tenant and version.
|
|
12
|
+
*
|
|
13
|
+
* What round-trips:
|
|
14
|
+
* - all model routing and scoping metadata: typename, tableName, load,
|
|
15
|
+
* mutable, the `tenancy` descriptor, bootstrap hints, scope, grants,
|
|
16
|
+
* entityRoles, the `conflict` disposition map, persist, autoFill,
|
|
17
|
+
* requiredFields, and lazyObservable. The authoring shorthands (`policy`
|
|
18
|
+
* and `groups`) are normalized into these canonical fields when the model
|
|
19
|
+
* is built, so only the canonical fields cross here.
|
|
20
|
+
* - relations, including the resolved `foreignKeyColumn`
|
|
21
|
+
* - field metadata (names and type tags), from which validators are rebuilt
|
|
22
|
+
* - identity roles
|
|
23
|
+
*
|
|
24
|
+
* What does not round-trip, because the server never needs it:
|
|
25
|
+
* - computed getters, which are closures and are dropped
|
|
26
|
+
* - exact Zod refinements, which are rebuilt as permissive validators from
|
|
27
|
+
* {@link FieldMeta}; the server does no field-shape validation
|
|
28
|
+
*/
|
|
29
|
+
import type { FieldMeta } from './field.js';
|
|
30
|
+
import type { Tenancy } from './tenancy.js';
|
|
31
|
+
import type { ModelResidency } from './residency.js';
|
|
32
|
+
import type { GrantsRef, LoadStrategy, PersistOptions, AutoFillRule, ConflictAxis } from './model.js';
|
|
33
|
+
import { type RelationType } from './relation.js';
|
|
34
|
+
import { type Schema, type IdentityRole, type EntityRole, type SessionSettings } from './schema.js';
|
|
35
|
+
/** Current schema-JSON envelope version. Bump this on a breaking change to the
|
|
36
|
+
* JSON shape itself — not to a user's schema. */
|
|
37
|
+
declare const SCHEMA_JSON_VERSION: 3;
|
|
38
|
+
/** A relation in JSON form. Mirrors the serializable members of {@link RelationDef}. */
|
|
39
|
+
export interface RelationJSON {
|
|
40
|
+
readonly type: RelationType;
|
|
41
|
+
readonly target: string;
|
|
42
|
+
readonly foreignKey: string;
|
|
43
|
+
readonly foreignKeyColumn: string;
|
|
44
|
+
readonly options?: Record<string, boolean>;
|
|
45
|
+
readonly orderBy?: string;
|
|
46
|
+
}
|
|
47
|
+
/** A model in JSON form. Everything on {@link ModelDef} except closures. */
|
|
48
|
+
export interface ModelJSON {
|
|
49
|
+
readonly fields: Record<string, FieldMeta>;
|
|
50
|
+
readonly relations: Record<string, RelationJSON>;
|
|
51
|
+
readonly load: LoadStrategy;
|
|
52
|
+
readonly typename: string;
|
|
53
|
+
readonly tableName?: string;
|
|
54
|
+
readonly tenancy: Tenancy;
|
|
55
|
+
/** The database plane the model's rows live in. Optional for backward
|
|
56
|
+
* compatibility: when absent (an artifact written before this field existed)
|
|
57
|
+
* it reads as `tenant`, the default. See {@link ModelResidency}. */
|
|
58
|
+
readonly plane?: ModelResidency;
|
|
59
|
+
readonly scope?: boolean | string;
|
|
60
|
+
readonly grants?: GrantsRef;
|
|
61
|
+
readonly entityRoles?: readonly EntityRole[];
|
|
62
|
+
/** The declared write-conflict disposition per committer kind. When absent,
|
|
63
|
+
* the engine falls back to its default. */
|
|
64
|
+
readonly conflict?: ConflictAxis;
|
|
65
|
+
readonly bootstrapLimit?: number;
|
|
66
|
+
readonly bootstrapOrderBy?: string;
|
|
67
|
+
readonly mutable?: boolean;
|
|
68
|
+
readonly lazyObservable?: boolean;
|
|
69
|
+
readonly persist?: PersistOptions;
|
|
70
|
+
readonly autoFill?: readonly AutoFillRule[];
|
|
71
|
+
readonly requiredFields?: readonly string[];
|
|
72
|
+
}
|
|
73
|
+
/** The JSON form of a {@link Schema}. The `ablo push` payload. */
|
|
74
|
+
export interface SchemaJSON {
|
|
75
|
+
readonly v: typeof SCHEMA_JSON_VERSION;
|
|
76
|
+
readonly models: Record<string, ModelJSON>;
|
|
77
|
+
readonly identityRoles: readonly IdentityRole[];
|
|
78
|
+
/** Optional so schemas pushed before ADR 0011 still parse (defaults to `{}`). */
|
|
79
|
+
readonly sessionSettings?: SessionSettings;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Project a `Schema` to its JSON form. Drops the client-only closures
|
|
83
|
+
* (validators, `computed`); keeps everything the server and a faithful
|
|
84
|
+
* rebuild need. The result is plain data — `JSON.stringify`-safe.
|
|
85
|
+
*/
|
|
86
|
+
export declare function toSchemaJSON(schema: Schema): SchemaJSON;
|
|
87
|
+
/** Serialize a `Schema` to a JSON string (the `ablo push` payload). */
|
|
88
|
+
export declare function serializeSchema(schema: Schema): string;
|
|
89
|
+
/**
|
|
90
|
+
* Reconstruct a working `Schema` from its JSON form. Validators are rebuilt
|
|
91
|
+
* permissively from field metadata (the server never validates field shapes);
|
|
92
|
+
* `computed` getters are absent. Everything the server reads — routing,
|
|
93
|
+
* scoping, relations, identity roles — is restored exactly.
|
|
94
|
+
*/
|
|
95
|
+
export declare function fromSchemaJSON(json: SchemaJSON): Schema;
|
|
96
|
+
/** Parse a `Schema` from a JSON string (inverse of {@link serializeSchema}). */
|
|
97
|
+
export declare function parseSchema(json: string): Schema;
|
|
98
|
+
/**
|
|
99
|
+
* Stable content hash of a `Schema`'s JSON form. FNV-1a over a canonical
|
|
100
|
+
* (sorted-key) encoding — deterministic across runs and order-invariant, no
|
|
101
|
+
* `crypto` dependency. Used for connect-time version gating: the client sends
|
|
102
|
+
* the hash it was built against, the server compares it to the tenant's
|
|
103
|
+
* active schema hash. Not a security primitive.
|
|
104
|
+
*/
|
|
105
|
+
export declare function schemaHash(schema: Schema): string;
|
|
106
|
+
/**
|
|
107
|
+
* Content hash of ONE serialized model — the unit of the semantic drift check.
|
|
108
|
+
* Two schemas agree on a model exactly when these match, which is what lets a
|
|
109
|
+
* client compare only the models it declares instead of welding itself to the
|
|
110
|
+
* whole-schema hash (where any additive push reads as drift). Computed over the
|
|
111
|
+
* model's `SchemaJSON` entry with the same canonicalization and hash as
|
|
112
|
+
* {@link schemaHash}, on both the client and the server's `GET /api/schema`.
|
|
113
|
+
*/
|
|
114
|
+
export declare function modelHash(modelJson: unknown): string;
|
|
115
|
+
export {};
|
|
116
|
+
//# sourceMappingURL=serialize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../src/schema/serialize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAGV,SAAS,EACT,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,YAAY,EACb,MAAM,YAAY,CAAC;AACpB,OAAO,EAGL,KAAK,YAAY,EAClB,MAAM,eAAe,CAAC;AACvB,OAAO,EAEL,KAAK,MAAM,EAEX,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,eAAe,EACrB,MAAM,aAAa,CAAC;AAErB;iDACiD;AACjD,QAAA,MAAM,mBAAmB,EAAG,CAAU,CAAC;AAIvC,wFAAwF;AACxF,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC3C,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,4EAA4E;AAC5E,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAA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