@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,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kysely wrappers for Ablo's two customer-database write transports.
|
|
3
|
+
*
|
|
4
|
+
* Both wrappers compose the same exported {@link createKyselyMutationCore}:
|
|
5
|
+
*
|
|
6
|
+
* - {@link kyselyDataSource} is the endpoint adapter. Its transaction contains
|
|
7
|
+
* row DML, the permanent idempotency ledger, and correlated outbox events. A
|
|
8
|
+
* Postgres logical marker remains optional for compatibility.
|
|
9
|
+
* - {@link kyselyDirectMutation} is the engine-side direct wrapper. Its
|
|
10
|
+
* transaction contains row DML, the same ledger, and a required logical
|
|
11
|
+
* marker. It never creates, writes, or serves `ablo_outbox`.
|
|
12
|
+
*
|
|
13
|
+
* The ledger reservation happens before DML via `INSERT ... ON CONFLICT DO
|
|
14
|
+
* NOTHING`. Postgres waits on a concurrent uncommitted owner of the same key;
|
|
15
|
+
* after that owner commits, the loser reads and hash-checks its durable response.
|
|
16
|
+
* If the owner rolls back, the waiter acquires the reservation and performs the
|
|
17
|
+
* mutation. This gives same-key concurrency one database arbiter and one effect.
|
|
18
|
+
*/
|
|
19
|
+
import { AbloValidationError } from '../../errors.js';
|
|
20
|
+
import { changeSetSchema, outboxEventSchema, sourceCommitEchoMarkerSchema, } from '../contract.js';
|
|
21
|
+
import { assertSourceIdempotencyIntent, assertSourceIdempotencyRetention, sourceChangeIntentHash, SOURCE_IDEMPOTENCY_RETENTION, } from '../idempotency.js';
|
|
22
|
+
import { adapterTableMigrations, idempotencyLedgerMigrations, } from '../migrations.js';
|
|
23
|
+
import { ABLO_POSTGRES_COMMIT_ECHO_PREFIX } from '../types.js';
|
|
24
|
+
import { createKyselyMutationCore, kyselyOperationRowId, } from './kyselyMutationCore.js';
|
|
25
|
+
export { createKyselyMutationCore, kyselyOperationRowId, } from './kyselyMutationCore.js';
|
|
26
|
+
function rawQuery(queryId, sql, parameters) {
|
|
27
|
+
return {
|
|
28
|
+
query: { kind: 'RawNode', sqlFragments: [sql], parameters: [] },
|
|
29
|
+
queryId: { queryId },
|
|
30
|
+
sql,
|
|
31
|
+
parameters,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function reserveLedgerQuery(correlationId, requestHash) {
|
|
35
|
+
return rawQuery('ablo-idempotency-reserve', `INSERT INTO ablo_idempotency (client_tx_id, response, request_hash, expires_at)
|
|
36
|
+
VALUES ($1, $2::jsonb, $3, now() + $4::interval)
|
|
37
|
+
ON CONFLICT (client_tx_id) DO NOTHING
|
|
38
|
+
RETURNING client_tx_id`, [correlationId, '[]', requestHash, SOURCE_IDEMPOTENCY_RETENTION]);
|
|
39
|
+
}
|
|
40
|
+
function completeLedgerQuery(correlationId, rows) {
|
|
41
|
+
return rawQuery('ablo-idempotency-complete', `UPDATE ablo_idempotency
|
|
42
|
+
SET response = $2::jsonb
|
|
43
|
+
WHERE client_tx_id = $1`, [correlationId, JSON.stringify(rows)]);
|
|
44
|
+
}
|
|
45
|
+
function postgresLogicalMarkerQuery(payload) {
|
|
46
|
+
return rawQuery('ablo-postgres-logical-marker', 'SELECT pg_logical_emit_message(true, $1::text, $2::text)', [ABLO_POSTGRES_COMMIT_ECHO_PREFIX, payload]);
|
|
47
|
+
}
|
|
48
|
+
function parseCachedRows(response) {
|
|
49
|
+
const parsed = typeof response === 'string' ? JSON.parse(response) : response;
|
|
50
|
+
if (!Array.isArray(parsed)) {
|
|
51
|
+
throw new AbloValidationError('The source idempotency response is corrupt and cannot be replayed safely', { code: 'idempotency_conflict' });
|
|
52
|
+
}
|
|
53
|
+
return parsed;
|
|
54
|
+
}
|
|
55
|
+
function markerAction(type) {
|
|
56
|
+
if (type === 'CREATE')
|
|
57
|
+
return 'I';
|
|
58
|
+
if (type === 'DELETE')
|
|
59
|
+
return 'D';
|
|
60
|
+
return 'U';
|
|
61
|
+
}
|
|
62
|
+
function assertDirectLogicalMarker(change, markerModelFor) {
|
|
63
|
+
const payload = change.echo?.payload;
|
|
64
|
+
if (!payload) {
|
|
65
|
+
throw new AbloValidationError('A direct Kysely mutation requires a transactional Postgres logical marker', { code: 'source_adapter_misconfigured' });
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
const marker = sourceCommitEchoMarkerSchema.parse(JSON.parse(payload));
|
|
69
|
+
if (marker.correlationId !== change.correlationId) {
|
|
70
|
+
throw new Error('marker correlation does not match the ledger key');
|
|
71
|
+
}
|
|
72
|
+
if (marker.operations.length !== change.operations.length) {
|
|
73
|
+
throw new Error('marker operation count does not match the mutation');
|
|
74
|
+
}
|
|
75
|
+
for (const [index, operation] of change.operations.entries()) {
|
|
76
|
+
const markerOperation = marker.operations[index];
|
|
77
|
+
// The marker speaks the canonical schema TYPENAME (the vocabulary the
|
|
78
|
+
// WAL consumer validates deltas against), while the mutation operation
|
|
79
|
+
// carries the authoring wire key. `markerModelFor` translates the wire
|
|
80
|
+
// key through the schema so the two vocabularies compare correctly.
|
|
81
|
+
if (!markerOperation ||
|
|
82
|
+
markerOperation.model !== markerModelFor(operation.model) ||
|
|
83
|
+
markerOperation.id !== kyselyOperationRowId(operation) ||
|
|
84
|
+
markerOperation.action !== markerAction(operation.type) ||
|
|
85
|
+
markerOperation.transactionId !== operation.transactionId) {
|
|
86
|
+
throw new Error(`marker operation ${index} does not match the mutation`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
if (error instanceof AbloValidationError)
|
|
92
|
+
throw error;
|
|
93
|
+
throw new AbloValidationError(`The direct Postgres logical marker is invalid: ${error instanceof Error ? error.message : 'unknown marker error'}`, { code: 'source_adapter_misconfigured' });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
export function createKyselyMutationAdapter(db, core, mode, options = {}) {
|
|
97
|
+
const markerModelFor = options.markerModelFor ?? ((model) => model);
|
|
98
|
+
return {
|
|
99
|
+
capabilities: {
|
|
100
|
+
transactions: true,
|
|
101
|
+
propose: false,
|
|
102
|
+
schemaIntrospection: true,
|
|
103
|
+
postgresWalEcho: true,
|
|
104
|
+
outboxEvents: mode === 'endpoint',
|
|
105
|
+
},
|
|
106
|
+
migrations() {
|
|
107
|
+
return mode === 'endpoint'
|
|
108
|
+
? adapterTableMigrations()
|
|
109
|
+
: idempotencyLedgerMigrations();
|
|
110
|
+
},
|
|
111
|
+
read(request) {
|
|
112
|
+
return core.read(request);
|
|
113
|
+
},
|
|
114
|
+
async commit(change) {
|
|
115
|
+
const request = changeSetSchema.parse(change);
|
|
116
|
+
if (mode === 'direct')
|
|
117
|
+
assertDirectLogicalMarker(request, markerModelFor);
|
|
118
|
+
const requestHash = sourceChangeIntentHash(request);
|
|
119
|
+
return db.transaction().execute(async (transaction) => {
|
|
120
|
+
const reservation = await transaction.executeQuery(reserveLedgerQuery(request.correlationId, requestHash));
|
|
121
|
+
if (reservation.rows.length === 0) {
|
|
122
|
+
const cached = await transaction
|
|
123
|
+
.selectFrom('ablo_idempotency')
|
|
124
|
+
.selectAll()
|
|
125
|
+
.where('client_tx_id', '=', request.correlationId)
|
|
126
|
+
.limit(1)
|
|
127
|
+
.execute();
|
|
128
|
+
const cachedRow = cached[0];
|
|
129
|
+
if (!cachedRow) {
|
|
130
|
+
throw new AbloValidationError('The source idempotency reservation disappeared during replay', { code: 'idempotency_conflict' });
|
|
131
|
+
}
|
|
132
|
+
assertSourceIdempotencyIntent(cachedRow.request_hash, requestHash);
|
|
133
|
+
assertSourceIdempotencyRetention(cachedRow.expires_at);
|
|
134
|
+
return { rows: parseCachedRows(cachedRow.response) };
|
|
135
|
+
}
|
|
136
|
+
const rows = [];
|
|
137
|
+
for (const [index, operation] of request.operations.entries()) {
|
|
138
|
+
const row = await core.applyOperation(transaction, operation);
|
|
139
|
+
rows.push(row);
|
|
140
|
+
if (mode === 'endpoint') {
|
|
141
|
+
const entityId = String(row.id ?? kyselyOperationRowId(operation));
|
|
142
|
+
await transaction
|
|
143
|
+
.insertInto('ablo_outbox')
|
|
144
|
+
.values({
|
|
145
|
+
id: `${request.correlationId}:${index}`,
|
|
146
|
+
model: operation.model,
|
|
147
|
+
entity_id: entityId,
|
|
148
|
+
type: operation.type,
|
|
149
|
+
data: operation.type === 'DELETE' ? null : JSON.stringify(row),
|
|
150
|
+
correlation_id: request.correlationId,
|
|
151
|
+
transaction_id: operation.transactionId ?? null,
|
|
152
|
+
occurred_at: Date.now(),
|
|
153
|
+
})
|
|
154
|
+
.execute();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
await transaction.executeQuery(completeLedgerQuery(request.correlationId, rows));
|
|
158
|
+
if (request.echo?.kind === 'postgres-wal') {
|
|
159
|
+
await transaction.executeQuery(postgresLogicalMarkerQuery(request.echo.payload));
|
|
160
|
+
}
|
|
161
|
+
return { rows };
|
|
162
|
+
});
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
/** Endpoint wrapper: mutation + ledger + outbox, with an optional marker. */
|
|
167
|
+
export function kyselyDataSource(db, schema) {
|
|
168
|
+
const mutation = createKyselyMutationAdapter(db, createKyselyMutationCore(db, schema), 'endpoint');
|
|
169
|
+
return {
|
|
170
|
+
...mutation,
|
|
171
|
+
capabilities: { ...mutation.capabilities, outboxEvents: true },
|
|
172
|
+
async events(cursor, limit) {
|
|
173
|
+
const rows = await db
|
|
174
|
+
.selectFrom('ablo_outbox')
|
|
175
|
+
.selectAll()
|
|
176
|
+
.where('cursor', '>', cursor ?? '0')
|
|
177
|
+
.orderBy('cursor', 'asc')
|
|
178
|
+
.limit(limit)
|
|
179
|
+
.execute();
|
|
180
|
+
const events = rows.map((row) => outboxEventSchema.parse({
|
|
181
|
+
id: row.id,
|
|
182
|
+
model: row.model,
|
|
183
|
+
entityId: row.entity_id,
|
|
184
|
+
type: row.type,
|
|
185
|
+
data: typeof row.data === 'string' ? JSON.parse(row.data) : row.data ?? null,
|
|
186
|
+
organizationId: row.organization_id ?? null,
|
|
187
|
+
clientTxId: row.client_tx_id ?? null,
|
|
188
|
+
correlationId: row.correlation_id ?? null,
|
|
189
|
+
transactionId: row.transaction_id ?? null,
|
|
190
|
+
occurredAt: row.occurred_at != null ? Number(row.occurred_at) : null,
|
|
191
|
+
cursor: String(row.cursor),
|
|
192
|
+
}));
|
|
193
|
+
return { events, nextCursor: events.at(-1)?.cursor ?? null };
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
/** Direct wrapper: mutation + ledger + required logical marker, never outbox. */
|
|
198
|
+
export function kyselyDirectMutation(db, schema) {
|
|
199
|
+
return createKyselyMutationAdapter(db, createKyselyMutationCore(db, schema), 'direct', {
|
|
200
|
+
markerModelFor: (operationModel) => {
|
|
201
|
+
const typename = schema.models[operationModel]?.typename;
|
|
202
|
+
return typename && typename.length > 0 ? typename : operationModel;
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
//# sourceMappingURL=kysely.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kysely.js","sourceRoot":"","sources":["../../../src/source/adapters/kysely.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAStD,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,4BAA4B,GAC7B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,6BAA6B,EAC7B,gCAAgC,EAChC,sBAAsB,EACtB,4BAA4B,GAC7B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,sBAAsB,EACtB,2BAA2B,GAC5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IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI;gBACpE,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;aAC3B,CAAC,CACH,CAAC;YACF,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,IAAI,IAAI,EAAE,CAAC;QAC/D,CAAC;KACF,CAAC;AACJ,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,oBAAoB,CAClC,EAAc,EACd,MAAiB;IAEjB,OAAO,2BAA2B,CAChC,EAAE,EACF,wBAAwB,CAAC,EAAE,EAAE,MAAM,CAAC,EACpC,QAAQ,EACR;QACE,cAAc,EAAE,CAAC,cAAc,EAAE,EAAE;YACjC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE,QAAQ,CAAC;YACzD,OAAO,QAAQ,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC;QACrE,CAAC;KACF,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reusable Kysely row-mutation core.
|
|
3
|
+
*
|
|
4
|
+
* This is the single schema-field ↔ physical-column translation used by both
|
|
5
|
+
* Kysely transports. It deliberately knows nothing about outboxes, logical
|
|
6
|
+
* markers, or idempotency: wrappers compose those transaction policies around
|
|
7
|
+
* the same `applyOperation` implementation, so direct and endpoint DML cannot
|
|
8
|
+
* drift into separate hand-written mappers.
|
|
9
|
+
*/
|
|
10
|
+
import type { Schema, SchemaRecord } from '../../schema/schema.js';
|
|
11
|
+
import type { AdapterReadRequest, Row } from '../adapter.js';
|
|
12
|
+
import type { Operation } from '../contract.js';
|
|
13
|
+
/** The subset of a Kysely instance, or transaction handle, used by the core. */
|
|
14
|
+
export interface KyselyLike {
|
|
15
|
+
selectFrom(table: string): KyselySelectBuilder;
|
|
16
|
+
insertInto(table: string): KyselyInsertBuilder;
|
|
17
|
+
updateTable(table: string): KyselyUpdateBuilder;
|
|
18
|
+
deleteFrom(table: string): KyselyDeleteBuilder;
|
|
19
|
+
/** Execute a precompiled raw query on this exact transaction handle. */
|
|
20
|
+
executeQuery(query: KyselyCompiledQuery): Promise<{
|
|
21
|
+
readonly rows: readonly Row[];
|
|
22
|
+
}>;
|
|
23
|
+
transaction(): KyselyTransactionBuilder;
|
|
24
|
+
}
|
|
25
|
+
/** Structural slice of Kysely's public `CompiledQuery` shape. */
|
|
26
|
+
export interface KyselyCompiledQuery {
|
|
27
|
+
readonly query: {
|
|
28
|
+
readonly kind: 'RawNode';
|
|
29
|
+
readonly sqlFragments: readonly string[];
|
|
30
|
+
readonly parameters: readonly [];
|
|
31
|
+
};
|
|
32
|
+
readonly queryId: {
|
|
33
|
+
readonly queryId: string;
|
|
34
|
+
};
|
|
35
|
+
readonly sql: string;
|
|
36
|
+
readonly parameters: readonly unknown[];
|
|
37
|
+
}
|
|
38
|
+
export interface KyselyTransactionBuilder {
|
|
39
|
+
execute<T>(fn: (trx: KyselyLike) => Promise<T>): Promise<T>;
|
|
40
|
+
}
|
|
41
|
+
export interface KyselySelectBuilder {
|
|
42
|
+
selectAll(): KyselySelectBuilder;
|
|
43
|
+
where(column: string, operator: string, value: unknown): KyselySelectBuilder;
|
|
44
|
+
orderBy(column: string, direction: 'asc' | 'desc'): KyselySelectBuilder;
|
|
45
|
+
limit(limit: number): KyselySelectBuilder;
|
|
46
|
+
execute(): Promise<readonly Row[]>;
|
|
47
|
+
}
|
|
48
|
+
export interface KyselyReturningExecutable {
|
|
49
|
+
execute(): Promise<readonly Row[]>;
|
|
50
|
+
}
|
|
51
|
+
export interface KyselyInsertBuilder {
|
|
52
|
+
values(row: Row): KyselyInsertValuesBuilder;
|
|
53
|
+
}
|
|
54
|
+
export interface KyselyInsertValuesBuilder {
|
|
55
|
+
returningAll(): KyselyReturningExecutable;
|
|
56
|
+
execute(): Promise<unknown>;
|
|
57
|
+
}
|
|
58
|
+
export interface KyselyUpdateBuilder {
|
|
59
|
+
set(patch: Row): KyselyUpdateSetBuilder;
|
|
60
|
+
}
|
|
61
|
+
export interface KyselyUpdateSetBuilder {
|
|
62
|
+
where(column: string, operator: string, value: unknown): KyselyUpdateSetBuilder;
|
|
63
|
+
returningAll(): KyselyReturningExecutable;
|
|
64
|
+
}
|
|
65
|
+
export interface KyselyDeleteBuilder {
|
|
66
|
+
where(column: string, operator: string, value: unknown): KyselyDeleteBuilder;
|
|
67
|
+
returningAll(): KyselyReturningExecutable;
|
|
68
|
+
}
|
|
69
|
+
/** Resolve the stable row id required by every source operation. */
|
|
70
|
+
export declare function kyselyOperationRowId(operation: Operation): string;
|
|
71
|
+
/** The transport-independent Kysely field/column mutation boundary. */
|
|
72
|
+
export interface KyselyMutationCore {
|
|
73
|
+
read(request: AdapterReadRequest): Promise<readonly Row[]>;
|
|
74
|
+
applyOperation(transaction: KyselyLike, operation: Operation): Promise<Row>;
|
|
75
|
+
}
|
|
76
|
+
export declare function createKyselyMutationCore<S extends SchemaRecord>(db: KyselyLike, schema: Schema<S>): KyselyMutationCore;
|
|
77
|
+
//# sourceMappingURL=kyselyMutationCore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kyselyMutationCore.d.ts","sourceRoot":"","sources":["../../../src/source/adapters/kyselyMutationCore.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAInE,OAAO,KAAK,EAAE,kBAAkB,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,gFAAgF;AAChF,MAAM,WAAW,UAAU;IACzB,UAAU,CAAC,KAAK,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EACd,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAChB,kBAAkB,CAuFpB"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reusable Kysely row-mutation core.
|
|
3
|
+
*
|
|
4
|
+
* This is the single schema-field ↔ physical-column translation used by both
|
|
5
|
+
* Kysely transports. It deliberately knows nothing about outboxes, logical
|
|
6
|
+
* markers, or idempotency: wrappers compose those transaction policies around
|
|
7
|
+
* the same `applyOperation` implementation, so direct and endpoint DML cannot
|
|
8
|
+
* drift into separate hand-written mappers.
|
|
9
|
+
*/
|
|
10
|
+
import { AbloValidationError } from '../../errors.js';
|
|
11
|
+
import { toSchemaJSON } from '../../schema/serialize.js';
|
|
12
|
+
import { camelToSnake, snakeToCamel } from '../../schema/ddl.js';
|
|
13
|
+
import { tenancyColumn } from '../../schema/tenancy.js';
|
|
14
|
+
function buildColumnMaps(schema) {
|
|
15
|
+
const json = toSchemaJSON(schema);
|
|
16
|
+
const out = new Map();
|
|
17
|
+
for (const [key, model] of Object.entries(json.models)) {
|
|
18
|
+
const fieldToColumn = new Map();
|
|
19
|
+
const columnToField = new Map();
|
|
20
|
+
const register = (field, column) => {
|
|
21
|
+
if (column === camelToSnake(field))
|
|
22
|
+
return;
|
|
23
|
+
fieldToColumn.set(field, column);
|
|
24
|
+
columnToField.set(column, field);
|
|
25
|
+
};
|
|
26
|
+
for (const [field, meta] of Object.entries(model.fields)) {
|
|
27
|
+
if (meta.column)
|
|
28
|
+
register(field, meta.column);
|
|
29
|
+
}
|
|
30
|
+
const orgColumn = tenancyColumn(model.tenancy);
|
|
31
|
+
if (orgColumn)
|
|
32
|
+
register('organizationId', orgColumn);
|
|
33
|
+
out.set(key, {
|
|
34
|
+
table: model.tableName ?? key,
|
|
35
|
+
fieldToColumn,
|
|
36
|
+
columnToField,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
/** Resolve the stable row id required by every source operation. */
|
|
42
|
+
export function kyselyOperationRowId(operation) {
|
|
43
|
+
const id = operation.id ?? operation.input?.id;
|
|
44
|
+
if (typeof id !== 'string' || id.length === 0) {
|
|
45
|
+
throw new AbloValidationError(`operation on "${operation.model}" requires an id`, { code: 'source_operation_id_required' });
|
|
46
|
+
}
|
|
47
|
+
return id;
|
|
48
|
+
}
|
|
49
|
+
export function createKyselyMutationCore(db, schema) {
|
|
50
|
+
const maps = buildColumnMaps(schema);
|
|
51
|
+
const modelColumns = (model) => {
|
|
52
|
+
const columns = maps.get(model);
|
|
53
|
+
if (!columns) {
|
|
54
|
+
throw new AbloValidationError(`kysely mutation core: no model "${model}" in schema`, { code: 'source_adapter_misconfigured' });
|
|
55
|
+
}
|
|
56
|
+
return columns;
|
|
57
|
+
};
|
|
58
|
+
const columnFor = (columns, field) => columns.fieldToColumn.get(field) ?? camelToSnake(field);
|
|
59
|
+
const fieldFor = (columns, column) => columns.columnToField.get(column) ?? snakeToCamel(column);
|
|
60
|
+
const toColumns = (columns, row) => {
|
|
61
|
+
const out = {};
|
|
62
|
+
for (const key of Object.keys(row))
|
|
63
|
+
out[columnFor(columns, key)] = row[key];
|
|
64
|
+
return out;
|
|
65
|
+
};
|
|
66
|
+
const toFields = (columns, row) => {
|
|
67
|
+
const out = {};
|
|
68
|
+
for (const key of Object.keys(row))
|
|
69
|
+
out[fieldFor(columns, key)] = row[key];
|
|
70
|
+
return out;
|
|
71
|
+
};
|
|
72
|
+
return {
|
|
73
|
+
async read(request) {
|
|
74
|
+
const columns = modelColumns(request.model);
|
|
75
|
+
if (request.kind === 'load') {
|
|
76
|
+
const rows = await db
|
|
77
|
+
.selectFrom(columns.table)
|
|
78
|
+
.selectAll()
|
|
79
|
+
.where('id', '=', request.id)
|
|
80
|
+
.limit(1)
|
|
81
|
+
.execute();
|
|
82
|
+
return rows.map((row) => toFields(columns, row));
|
|
83
|
+
}
|
|
84
|
+
const rows = await db
|
|
85
|
+
.selectFrom(columns.table)
|
|
86
|
+
.selectAll()
|
|
87
|
+
.limit(request.query?.limit ?? 1000)
|
|
88
|
+
.execute();
|
|
89
|
+
return rows.map((row) => toFields(columns, row));
|
|
90
|
+
},
|
|
91
|
+
async applyOperation(transaction, operation) {
|
|
92
|
+
const columns = modelColumns(operation.model);
|
|
93
|
+
const id = kyselyOperationRowId(operation);
|
|
94
|
+
const input = operation.input ?? {};
|
|
95
|
+
if (operation.type === 'DELETE') {
|
|
96
|
+
const deleted = await transaction
|
|
97
|
+
.deleteFrom(columns.table)
|
|
98
|
+
.where('id', '=', id)
|
|
99
|
+
.returningAll()
|
|
100
|
+
.execute();
|
|
101
|
+
return deleted[0] ? toFields(columns, deleted[0]) : { id };
|
|
102
|
+
}
|
|
103
|
+
if (operation.type === 'CREATE') {
|
|
104
|
+
const inserted = await transaction
|
|
105
|
+
.insertInto(columns.table)
|
|
106
|
+
.values(toColumns(columns, { id, ...input }))
|
|
107
|
+
.returningAll()
|
|
108
|
+
.execute();
|
|
109
|
+
return inserted[0] ? toFields(columns, inserted[0]) : { id, ...input };
|
|
110
|
+
}
|
|
111
|
+
const patch = toColumns(columns, {
|
|
112
|
+
...input,
|
|
113
|
+
...(operation.type === 'ARCHIVE' ? { archivedAt: new Date() } : {}),
|
|
114
|
+
...(operation.type === 'UNARCHIVE' ? { archivedAt: null } : {}),
|
|
115
|
+
});
|
|
116
|
+
const updated = await transaction
|
|
117
|
+
.updateTable(columns.table)
|
|
118
|
+
.set(patch)
|
|
119
|
+
.where('id', '=', id)
|
|
120
|
+
.returningAll()
|
|
121
|
+
.execute();
|
|
122
|
+
return updated[0] ? toFields(columns, updated[0]) : { id, ...input };
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=kyselyMutationCore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kyselyMutationCore.js","sourceRoot":"","sources":["../../../src/source/adapters/kyselyMutationCore.ts"],"names":[],"mappings":"AAAA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AAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,GAAG,KAAK,EAAE,CAAC;YACzE,CAAC;YAED,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,EAAE;gBAC/B,GAAG,KAAK;gBACR,GAAG,CAAC,SAAS,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACnE,GAAG,CAAC,SAAS,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAChE,CAAC,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,WAAW;iBAC9B,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC;iBAC1B,GAAG,CAAC,KAAK,CAAC;iBACV,KAAK,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC;iBACpB,YAAY,EAAE;iBACd,OAAO,EAAE,CAAC;YACb,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,GAAG,KAAK,EAAE,CAAC;QACvE,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The in-memory reference implementation of {@link DataSourceAdapter}. It is the
|
|
3
|
+
* simplest correct adapter: a stand-in you can commit to and read from in tests
|
|
4
|
+
* without a database, and the fixture the conformance suite runs against to confirm
|
|
5
|
+
* the suite exercises real behavior. An adapter for a given object-relational
|
|
6
|
+
* mapper is complete when it passes the same suite this one passes.
|
|
7
|
+
*
|
|
8
|
+
* It models the semantics minimally but faithfully: one row store per model, an
|
|
9
|
+
* idempotency ledger keyed by scoped correlation, and an append-only outbox with a
|
|
10
|
+
* monotonic cursor.
|
|
11
|
+
*/
|
|
12
|
+
import type { DataSourceAdapter } from '../adapter.js';
|
|
13
|
+
export declare function memoryDataSource(): DataSourceAdapter;
|
|
14
|
+
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../src/source/adapters/memory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAGV,iBAAiB,EAElB,MAAM,eAAe,CAAC;AAevB,wBAAgB,gBAAgB,IAAI,iBAAiB,CAwHpD"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The in-memory reference implementation of {@link DataSourceAdapter}. It is the
|
|
3
|
+
* simplest correct adapter: a stand-in you can commit to and read from in tests
|
|
4
|
+
* without a database, and the fixture the conformance suite runs against to confirm
|
|
5
|
+
* the suite exercises real behavior. An adapter for a given object-relational
|
|
6
|
+
* mapper is complete when it passes the same suite this one passes.
|
|
7
|
+
*
|
|
8
|
+
* It models the semantics minimally but faithfully: one row store per model, an
|
|
9
|
+
* idempotency ledger keyed by scoped correlation, and an append-only outbox with a
|
|
10
|
+
* monotonic cursor.
|
|
11
|
+
*/
|
|
12
|
+
import { AbloValidationError } from '../../errors.js';
|
|
13
|
+
import { assertSourceIdempotencyIntent, sourceChangeIntentHash, } from '../idempotency.js';
|
|
14
|
+
function rowId(op) {
|
|
15
|
+
const id = op.id ?? op.input?.id;
|
|
16
|
+
if (typeof id !== 'string' || id.length === 0) {
|
|
17
|
+
throw new AbloValidationError(`operation on "${op.model}" requires an id`, { code: 'source_operation_id_required' });
|
|
18
|
+
}
|
|
19
|
+
return id;
|
|
20
|
+
}
|
|
21
|
+
export function memoryDataSource() {
|
|
22
|
+
/** model → (id → row). */
|
|
23
|
+
const store = new Map();
|
|
24
|
+
/** Permanent correlationId → intent hash + original response ledger. */
|
|
25
|
+
const idempotency = new Map();
|
|
26
|
+
/** Append-only outbox; `cursor` is the 1-based index as a string. */
|
|
27
|
+
const outbox = [];
|
|
28
|
+
const modelStore = (model) => {
|
|
29
|
+
let m = store.get(model);
|
|
30
|
+
if (!m) {
|
|
31
|
+
m = new Map();
|
|
32
|
+
store.set(model, m);
|
|
33
|
+
}
|
|
34
|
+
return m;
|
|
35
|
+
};
|
|
36
|
+
const applyOperation = (op) => {
|
|
37
|
+
const m = modelStore(op.model);
|
|
38
|
+
const id = rowId(op);
|
|
39
|
+
switch (op.type) {
|
|
40
|
+
case 'CREATE': {
|
|
41
|
+
const row = { id, ...(op.input ?? {}) };
|
|
42
|
+
m.set(id, row);
|
|
43
|
+
return row;
|
|
44
|
+
}
|
|
45
|
+
case 'UPDATE':
|
|
46
|
+
case 'ARCHIVE':
|
|
47
|
+
case 'UNARCHIVE': {
|
|
48
|
+
const prev = m.get(id) ?? { id };
|
|
49
|
+
const row = {
|
|
50
|
+
...prev,
|
|
51
|
+
...(op.input ?? {}),
|
|
52
|
+
...(op.type === 'ARCHIVE' ? { archivedAt: Date.now() } : {}),
|
|
53
|
+
...(op.type === 'UNARCHIVE' ? { archivedAt: null } : {}),
|
|
54
|
+
};
|
|
55
|
+
m.set(id, row);
|
|
56
|
+
return row;
|
|
57
|
+
}
|
|
58
|
+
case 'DELETE': {
|
|
59
|
+
const prev = m.get(id) ?? { id };
|
|
60
|
+
m.delete(id);
|
|
61
|
+
return prev;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
return {
|
|
66
|
+
capabilities: {
|
|
67
|
+
transactions: true,
|
|
68
|
+
propose: false,
|
|
69
|
+
schemaIntrospection: false,
|
|
70
|
+
postgresWalEcho: false,
|
|
71
|
+
outboxEvents: true,
|
|
72
|
+
},
|
|
73
|
+
migrations() {
|
|
74
|
+
// Nothing to create in memory. A database-backed adapter returns the SQL for its ablo_idempotency and ablo_outbox tables here.
|
|
75
|
+
return [];
|
|
76
|
+
},
|
|
77
|
+
async read(req) {
|
|
78
|
+
const m = store.get(req.model);
|
|
79
|
+
if (!m)
|
|
80
|
+
return [];
|
|
81
|
+
if (req.kind === 'load') {
|
|
82
|
+
const row = m.get(req.id);
|
|
83
|
+
return row ? [row] : [];
|
|
84
|
+
}
|
|
85
|
+
let rows = [...m.values()];
|
|
86
|
+
const limit = req.query?.limit;
|
|
87
|
+
if (typeof limit === 'number')
|
|
88
|
+
rows = rows.slice(0, limit);
|
|
89
|
+
return rows;
|
|
90
|
+
},
|
|
91
|
+
async commit(change) {
|
|
92
|
+
if (change.echo) {
|
|
93
|
+
throw new AbloValidationError('memoryDataSource cannot emit a Postgres WAL commit echo');
|
|
94
|
+
}
|
|
95
|
+
// Idempotency: a duplicate scoped correlation returns the original rows.
|
|
96
|
+
const requestHash = sourceChangeIntentHash(change);
|
|
97
|
+
const cached = idempotency.get(change.correlationId);
|
|
98
|
+
if (cached) {
|
|
99
|
+
assertSourceIdempotencyIntent(cached.requestHash, requestHash);
|
|
100
|
+
return { rows: cached.rows };
|
|
101
|
+
}
|
|
102
|
+
const rows = [];
|
|
103
|
+
for (const [index, op] of change.operations.entries()) {
|
|
104
|
+
const row = applyOperation(op);
|
|
105
|
+
rows.push(row);
|
|
106
|
+
// Transactional outbox: one event per op, monotonic cursor.
|
|
107
|
+
outbox.push({
|
|
108
|
+
id: `${change.correlationId}:${index}`,
|
|
109
|
+
model: op.model,
|
|
110
|
+
entityId: String(row.id ?? rowId(op)),
|
|
111
|
+
type: op.type,
|
|
112
|
+
data: op.type === 'DELETE' ? null : row,
|
|
113
|
+
correlationId: change.correlationId,
|
|
114
|
+
...(op.transactionId ? { transactionId: op.transactionId } : {}),
|
|
115
|
+
cursor: String(outbox.length + 1),
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
idempotency.set(change.correlationId, { requestHash, rows });
|
|
119
|
+
return { rows };
|
|
120
|
+
},
|
|
121
|
+
async events(cursor, limit) {
|
|
122
|
+
const after = cursor ? Number(cursor) : 0;
|
|
123
|
+
const page = outbox.filter((e) => Number(e.cursor) > after).slice(0, limit);
|
|
124
|
+
return {
|
|
125
|
+
events: page,
|
|
126
|
+
nextCursor: page.at(-1)?.cursor ?? null,
|
|
127
|
+
};
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=memory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../../../src/source/adapters/memory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAQtD,OAAO,EACL,6BAA6B,EAC7B,sBAAsB,GACvB,MAAM,mBAAmB,CAAC;AAE3B,SAAS,KAAK,CAAC,EAAa;IAC1B,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,IAAK,EAAE,CAAC,KAAK,EAAE,EAAyB,CAAC;IACzD,IAAI,OAAO,EAAE,KAAK,QAAQ,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC9C,MAAM,IAAI,mBAAmB,CAAC,iBAAiB,EAAE,CAAC,KAAK,kBAAkB,EAAE,EAAE,IAAI,EAAE,8BAA8B,EAAE,CAAC,CAAC;IACvH,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,MAAM,UAAU,gBAAgB;IAC9B,0BAA0B;IAC1B,MAAM,KAAK,GAAG,IAAI,GAAG,EAA4B,CAAC;IAClD,wEAAwE;IACxE,MAAM,WAAW,GAAG,IAAI,GAAG,EAGxB,CAAC;IACJ,qEAAqE;IACrE,MAAM,MAAM,GAAkB,EAAE,CAAC;IAEjC,MAAM,UAAU,GAAG,CAAC,KAAa,EAAoB,EAAE;QACrD,IAAI,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACzB,IAAI,CAAC,CAAC,EAAE,CAAC;YACP,CAAC,GAAG,IAAI,GAAG,EAAE,CAAC;YACd,KA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