@yielded/auth-persistence 0.1.0-beta.23 → 0.1.0-beta.25

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.
Files changed (182) hide show
  1. package/README.md +11 -0
  2. package/dist/Adapter.d.mts +12 -6
  3. package/dist/Adapter.mjs +8 -3
  4. package/dist/OAuthPersistence.d.mts +87 -0
  5. package/dist/OAuthPersistence.mjs +125 -0
  6. package/dist/OAuthPersistence.mjs.map +1 -0
  7. package/dist/_virtual/_rolldown/runtime.mjs +13 -0
  8. package/dist/index.d.mts +3 -1
  9. package/dist/index.mjs +3 -1
  10. package/dist/internal/configuration.d.mts +1 -1
  11. package/dist/internal/configuration.mjs.map +1 -1
  12. package/dist/internal/email-kernel.d.mts +1 -1
  13. package/dist/internal/email-kernel.mjs +1 -1
  14. package/dist/internal/email-kernel.mjs.map +1 -1
  15. package/dist/internal/models/oauth-connected-model.d.mts +294 -0
  16. package/dist/internal/models/oauth-connected-model.mjs +22 -0
  17. package/dist/internal/models/oauth-connected-model.mjs.map +1 -0
  18. package/dist/internal/models/oauth-model.d.mts +467 -0
  19. package/dist/internal/models/oauth-model.mjs +49 -0
  20. package/dist/internal/models/oauth-model.mjs.map +1 -0
  21. package/dist/internal/models/password-model.d.mts +6 -48
  22. package/dist/internal/models/password-model.mjs +0 -1
  23. package/dist/internal/models/password-model.mjs.map +1 -1
  24. package/dist/internal/native-sql-table.d.mts +4 -0
  25. package/dist/internal/native-sql-table.mjs +7 -0
  26. package/dist/internal/native-sql-table.mjs.map +1 -1
  27. package/dist/internal/oauth/accounts.d.mts +8 -0
  28. package/dist/internal/oauth/accounts.mjs +379 -0
  29. package/dist/internal/oauth/accounts.mjs.map +1 -0
  30. package/dist/internal/oauth/connected-access.d.mts +9 -0
  31. package/dist/internal/oauth/connected-access.mjs +229 -0
  32. package/dist/internal/oauth/connected-access.mjs.map +1 -0
  33. package/dist/internal/oauth/connected-collection.d.mts +7 -0
  34. package/dist/internal/oauth/connected-collection.mjs +214 -0
  35. package/dist/internal/oauth/connected-collection.mjs.map +1 -0
  36. package/dist/internal/oauth/connected-custody.d.mts +6 -0
  37. package/dist/internal/oauth/connected-custody.mjs +165 -0
  38. package/dist/internal/oauth/connected-custody.mjs.map +1 -0
  39. package/dist/internal/oauth/connected-flow.d.mts +7 -0
  40. package/dist/internal/oauth/connected-flow.mjs +324 -0
  41. package/dist/internal/oauth/connected-flow.mjs.map +1 -0
  42. package/dist/internal/oauth/connected-input.mjs +122 -0
  43. package/dist/internal/oauth/connected-input.mjs.map +1 -0
  44. package/dist/internal/oauth/connected-keys.d.mts +2 -0
  45. package/dist/internal/oauth/connected-keys.mjs +22 -0
  46. package/dist/internal/oauth/connected-keys.mjs.map +1 -0
  47. package/dist/internal/oauth/connected-maintenance.d.mts +9 -0
  48. package/dist/internal/oauth/connected-maintenance.mjs +226 -0
  49. package/dist/internal/oauth/connected-maintenance.mjs.map +1 -0
  50. package/dist/internal/oauth/connected-management.d.mts +9 -0
  51. package/dist/internal/oauth/connected-management.mjs +243 -0
  52. package/dist/internal/oauth/connected-management.mjs.map +1 -0
  53. package/dist/internal/oauth/connected-reference.mjs +63 -0
  54. package/dist/internal/oauth/connected-reference.mjs.map +1 -0
  55. package/dist/internal/oauth/connected-settlement.d.mts +8 -0
  56. package/dist/internal/oauth/connected-settlement.mjs +141 -0
  57. package/dist/internal/oauth/connected-settlement.mjs.map +1 -0
  58. package/dist/internal/oauth/connected-sign-in.d.mts +10 -0
  59. package/dist/internal/oauth/connected-sign-in.mjs +281 -0
  60. package/dist/internal/oauth/connected-sign-in.mjs.map +1 -0
  61. package/dist/internal/oauth/connected-state.d.mts +14 -0
  62. package/dist/internal/oauth/connected-state.mjs +469 -0
  63. package/dist/internal/oauth/connected-state.mjs.map +1 -0
  64. package/dist/internal/oauth/connected-target.d.mts +21 -0
  65. package/dist/internal/oauth/connected-target.mjs +117 -0
  66. package/dist/internal/oauth/connected-target.mjs.map +1 -0
  67. package/dist/internal/oauth/flow.d.mts +5 -0
  68. package/dist/internal/oauth/flow.mjs +279 -0
  69. package/dist/internal/oauth/flow.mjs.map +1 -0
  70. package/dist/internal/oauth/input.mjs +127 -0
  71. package/dist/internal/oauth/input.mjs.map +1 -0
  72. package/dist/internal/oauth/owner.d.mts +10 -0
  73. package/dist/internal/oauth/owner.mjs +10 -0
  74. package/dist/internal/oauth/owner.mjs.map +1 -0
  75. package/dist/internal/oauth/query-compiler.d.mts +7 -0
  76. package/dist/internal/oauth/query-compiler.mjs +9 -0
  77. package/dist/internal/oauth/query-compiler.mjs.map +1 -0
  78. package/dist/internal/oauth/registration.d.mts +7 -0
  79. package/dist/internal/oauth/registration.mjs +393 -0
  80. package/dist/internal/oauth/registration.mjs.map +1 -0
  81. package/dist/internal/oauth/state.mjs +107 -0
  82. package/dist/internal/oauth/state.mjs.map +1 -0
  83. package/dist/internal/oauth/target.d.mts +31 -0
  84. package/dist/internal/oauth/target.mjs +273 -0
  85. package/dist/internal/oauth/target.mjs.map +1 -0
  86. package/dist/internal/oauth-kernel.d.mts +1423 -0
  87. package/dist/internal/oauth-kernel.mjs +187 -0
  88. package/dist/internal/oauth-kernel.mjs.map +1 -0
  89. package/dist/internal/oauth-proxy.d.mts +31 -0
  90. package/dist/internal/oauth-proxy.mjs +129 -0
  91. package/dist/internal/oauth-proxy.mjs.map +1 -0
  92. package/dist/internal/passkey/write-state.mjs +9 -1
  93. package/dist/internal/passkey/write-state.mjs.map +1 -1
  94. package/dist/internal/passkey-kernel.d.mts +9 -9
  95. package/dist/internal/{password-attempts.d.mts → password-credentials.d.mts} +3 -4
  96. package/dist/internal/password-credentials.mjs +121 -0
  97. package/dist/internal/password-credentials.mjs.map +1 -0
  98. package/dist/internal/password-kernel.d.mts +8 -24
  99. package/dist/internal/password-kernel.mjs +5 -43
  100. package/dist/internal/password-kernel.mjs.map +1 -1
  101. package/dist/internal/persistence.d.mts +1 -1
  102. package/dist/internal/persistence.mjs +2 -2
  103. package/dist/internal/persistence.mjs.map +1 -1
  104. package/dist/internal/query-operations.d.mts +2 -0
  105. package/dist/internal/session-kernel.d.mts +2 -2
  106. package/dist/internal/session-kernel.mjs +74 -18
  107. package/dist/internal/session-kernel.mjs.map +1 -1
  108. package/dist/internal/sql-oauth-connected-model.d.mts +29 -0
  109. package/dist/internal/sql-oauth-connected-model.mjs +7 -0
  110. package/dist/internal/sql-oauth-connected-model.mjs.map +1 -0
  111. package/dist/internal/sql-oauth-model.d.mts +60 -0
  112. package/dist/internal/sql-oauth-model.mjs +10 -0
  113. package/dist/internal/sql-oauth-model.mjs.map +1 -0
  114. package/dist/internal/sql-query.d.mts +12 -0
  115. package/dist/internal/sql-query.mjs +15 -18
  116. package/dist/internal/sql-query.mjs.map +1 -1
  117. package/dist/internal/sql-storage-validation.mjs +54 -0
  118. package/dist/internal/sql-storage-validation.mjs.map +1 -0
  119. package/dist/internal/storage-mapping.mjs +1 -37
  120. package/dist/internal/storage-mapping.mjs.map +1 -1
  121. package/dist/internal/storage-plans.d.mts +7 -0
  122. package/dist/internal/storage-plans.mjs +189 -0
  123. package/dist/internal/storage-plans.mjs.map +1 -0
  124. package/dist/internal/storage-tables.d.mts +0 -56
  125. package/dist/internal/storage-tables.mjs +0 -17
  126. package/dist/internal/storage-tables.mjs.map +1 -1
  127. package/dist/internal/storage-validation.d.mts +6 -1
  128. package/dist/internal/storage-validation.mjs +42 -1
  129. package/dist/internal/storage-validation.mjs.map +1 -1
  130. package/dist/internal/transaction-kernel.mjs +3 -2
  131. package/dist/internal/transaction-kernel.mjs.map +1 -1
  132. package/package.json +1 -1
  133. package/src/Adapter.ts +89 -5
  134. package/src/OAuthPersistence.ts +427 -0
  135. package/src/index.ts +3 -0
  136. package/src/internal/configuration.ts +1 -3
  137. package/src/internal/email-kernel.ts +2 -1
  138. package/src/internal/models/oauth-connected-model.ts +396 -0
  139. package/src/internal/models/oauth-model.ts +708 -0
  140. package/src/internal/models/password-model.ts +2 -57
  141. package/src/internal/native-sql-table.ts +14 -0
  142. package/src/internal/oauth/accounts.ts +839 -0
  143. package/src/internal/oauth/connected-access.ts +388 -0
  144. package/src/internal/oauth/connected-collection.ts +345 -0
  145. package/src/internal/oauth/connected-custody.ts +308 -0
  146. package/src/internal/oauth/connected-flow.ts +562 -0
  147. package/src/internal/oauth/connected-input.ts +147 -0
  148. package/src/internal/oauth/connected-keys.ts +31 -0
  149. package/src/internal/oauth/connected-maintenance.ts +379 -0
  150. package/src/internal/oauth/connected-management.ts +391 -0
  151. package/src/internal/oauth/connected-reference.ts +135 -0
  152. package/src/internal/oauth/connected-settlement.ts +278 -0
  153. package/src/internal/oauth/connected-sign-in.ts +472 -0
  154. package/src/internal/oauth/connected-state.ts +924 -0
  155. package/src/internal/oauth/connected-target.ts +307 -0
  156. package/src/internal/oauth/flow.ts +505 -0
  157. package/src/internal/oauth/input.ts +201 -0
  158. package/src/internal/oauth/owner.ts +22 -0
  159. package/src/internal/oauth/query-compiler.ts +15 -0
  160. package/src/internal/oauth/registration.ts +676 -0
  161. package/src/internal/oauth/state.ts +218 -0
  162. package/src/internal/oauth/target.ts +803 -0
  163. package/src/internal/oauth-kernel.ts +294 -0
  164. package/src/internal/oauth-proxy.ts +176 -0
  165. package/src/internal/passkey/write-state.ts +18 -4
  166. package/src/internal/password-credentials.ts +245 -0
  167. package/src/internal/password-kernel.ts +7 -99
  168. package/src/internal/persistence.ts +1 -1
  169. package/src/internal/query-operations.ts +2 -0
  170. package/src/internal/session-kernel.ts +143 -55
  171. package/src/internal/sql-oauth-connected-model.ts +145 -0
  172. package/src/internal/sql-oauth-model.ts +263 -0
  173. package/src/internal/sql-query.ts +16 -13
  174. package/src/internal/sql-storage-validation.ts +64 -0
  175. package/src/internal/storage-mapping.ts +0 -37
  176. package/src/internal/storage-plans.ts +218 -0
  177. package/src/internal/storage-tables.ts +0 -20
  178. package/src/internal/storage-validation.ts +58 -0
  179. package/src/internal/transaction-kernel.ts +6 -2
  180. package/dist/internal/password-attempts.mjs +0 -197
  181. package/dist/internal/password-attempts.mjs.map +0 -1
  182. package/src/internal/password-attempts.ts +0 -466
@@ -1 +1 @@
1
- {"version":3,"file":"storage-mapping.mjs","names":["ProofRecord"],"sources":["../../src/internal/storage-mapping.ts"],"sourcesContent":["import { EmailCredentialSnapshot } from \"@yielded/auth/Email\";\nimport { LoginIdentifier } from \"@yielded/auth/Identity\";\nimport {\n PasswordAttemptId,\n PasswordCredentialSnapshot,\n EncodedPasswordHash,\n type PasswordReplacement,\n} from \"@yielded/auth/Password\";\nimport {\n ProofBinding,\n ProofContinuationId,\n ProofDeliveryId,\n ProofId,\n ProofPurpose,\n ProofRequestId,\n ProofRequestReceipt,\n ProofVersion,\n} from \"@yielded/auth/Proofs\";\nimport { TokenDigest } from \"@yielded/auth/Schema\";\nimport {\n SecurityRevision,\n SessionId,\n SessionMetadata,\n SessionAuthenticationProvenance,\n SessionCredentialVersion,\n type StatefulSessionRecord,\n} from \"@yielded/auth/Sessions\";\nimport { Crypto, DateTime, Effect, Redacted, Schema } from \"effect\";\n\nimport type { MappingInput } from \"./configuration\";\nimport { randomId } from \"./crypto\";\nimport { PersistenceMappingError } from \"./mapping-error\";\nimport { requiredEmailAddressConstraints, type AnyEmailAddressMapping } from \"./models/email-model\";\nimport {\n requiredPasswordConstraints,\n type AnyPasswordPersistenceMapping,\n} from \"./models/password-model\";\nimport { requiredProofConstraints, type AnyProofPersistenceMapping } from \"./models/proof-model\";\nimport type { StatefulSessionMapping } from \"./models/session-model\";\nimport type { TableModel, SqlFragment } from \"./query-operations\";\nimport { storageTables, type StorageRole } from \"./storage-tables\";\n\nconst failure = (cause: unknown) => PersistenceMappingError.make({ operation: \"decode\", cause });\n\nconst decode = <S extends Schema.Codec<unknown, unknown>>(schema: S, value: unknown) =>\n Schema.decodeUnknownEffect(schema)(value).pipe(Effect.mapError(failure));\n\nconst string = (value: unknown) => Schema.decodeUnknownSync(Schema.String)(value);\nconst tuple = Schema.encodeSync(Schema.fromJsonString(Schema.Array(Schema.String)));\nconst bindingJson = Schema.fromJsonString(ProofBinding);\nconst receiptJson = Schema.fromJsonString(ProofRequestReceipt);\n\nconst ProofRecord = Schema.Struct({\n moduleId: Schema.String,\n purpose: ProofPurpose,\n proofId: ProofId,\n requestId: ProofRequestId,\n fingerprint: TokenDigest,\n deliveryId: ProofDeliveryId,\n binding: ProofBinding,\n verifier: Schema.Struct({ keyId: Schema.String, digest: TokenDigest }),\n issuedAtMillis: Schema.Int,\n expiresAtMillis: Schema.Int,\n version: ProofVersion,\n});\n\nconst ProofContinuation = Schema.Struct({\n moduleId: Schema.String,\n purpose: ProofPurpose,\n continuationId: ProofContinuationId,\n digest: TokenDigest,\n proofId: ProofId,\n seriesKey: Schema.String,\n binding: ProofBinding,\n expiresAtMillis: Schema.Int,\n version: ProofVersion,\n});\n\n/** Derive shared row mappings from a managed or custom storage layout.\n * Acquire Effect Crypto once; the returned allocators retain that implementation.\n * Each factory requires its role tables to exist. Adapter authors supply typed\n * table handles and dialect-specific clocks/commit predicates, and may refine\n * authority policy for explicit services. This does not alter composed defaults.\n */\nexport const makeMappings = Effect.fnUntraced(function* (input: MappingInput) {\n const crypto = yield* Crypto.Crypto;\n\n const allocate = randomId.pipe(\n Effect.provideService(Crypto.Crypto, crypto),\n Effect.mapError(failure),\n );\n\n const table = (role: StorageRole) => {\n const found = input.tables[role];\n\n if (found === undefined) throw failure(`Missing ${role} mapping`);\n\n return found;\n };\n\n const mapped = (role: StorageRole) => ({\n table: table(role),\n ...Object.fromEntries(Object.keys(storageTables[role].columns).map((key) => [key, key])),\n });\n\n const { subjects: s, encodeInstant: instant, decodeInstant: readInstant } = input;\n const subjectId = { toNative: s.toNative, toSubject: s.toSubject, equals: Object.is };\n\n const subject = {\n table: s.table,\n id: s.id,\n status: s.status,\n securityRevision: s.securityRevision,\n isActiveStatus: (value: unknown) => Object.is(value, s.activeValue),\n d1ActiveStatusValue: s.activeValue,\n decodeRequirement: s.requirements,\n decodeActionRequirement: s.actionRequirements,\n nextSecurityRevision: () => allocate.pipe(Effect.map(SecurityRevision.make)),\n };\n\n const authorityCredential = () => ({\n ...mapped(\"credentials\"),\n subjectId: \"subjectId\",\n credentialId: \"credentialId\",\n revision: \"revision\",\n status: \"active\",\n isActiveStatus: (value: unknown) => value === true,\n encodeInsert: (row: object) => ({ ...row, active: true }),\n encodeRevision: (revision: SecurityRevision) => ({ revision }),\n });\n\n const authority = () => ({ subjectId, subject, credential: authorityCredential() });\n\n const proofs = (): AnyProofPersistenceMapping<SqlFragment> => ({\n constraints: requiredProofConstraints,\n encodeInstant: instant,\n decodeInstant: readInstant,\n allocateVersion: allocate.pipe(Effect.map(ProofVersion.make)),\n isRequestConflict: () => false,\n isSeriesConflict: () => false,\n isCommandConflict: () => false,\n scopeKeys: ({ binding }) => ({\n series: tuple([\n binding.identifier.namespace,\n binding.identifier.value,\n binding._tag === \"Identifier\" ? \"anonymous\" : binding.revision.subjectId,\n ]),\n identifier: tuple([binding.identifier.namespace, binding.identifier.value]),\n subject: binding._tag === \"Identifier\" ? \"anonymous\" : binding.revision.subjectId,\n }),\n authority: {\n ...authority(),\n identifier: {\n table: table(\"identifiers\"),\n namespace: \"namespace\",\n value: \"value\",\n isCurrent: (request, rows) =>\n request.binding._tag === \"Identifier\"\n ? rows.length === 0\n : request.binding._tag === \"IdentifierChange\"\n ? rows.length === 0 ||\n (rows.length === 1 &&\n rows.every(\n (row) =>\n Object.is(row.subjectId, request.nativeSubjectId) &&\n row.active === true &&\n row.verifiedAt === null,\n ))\n : rows.length === 1 &&\n rows.every(\n (row) => Object.is(row.subjectId, request.nativeSubjectId) && row.active === true,\n ),\n },\n },\n request: {\n ...mapped(\"proofRequests\"),\n moduleId: \"moduleId\",\n requestId: \"requestId\",\n fingerprint: \"fingerprint\",\n proofId: \"proofId\",\n purpose: \"purpose\",\n keyId: \"keyId\",\n createdAt: \"createdAt\",\n retentionUntil: \"retentionUntil\",\n encodeInsert: ({ record, retentionUntilMillis }) => ({\n moduleId: record.moduleId,\n requestId: record.requestId,\n fingerprint: record.fingerprint,\n proofId: record.proofId,\n purpose: record.purpose,\n keyId: record.verifier.keyId,\n createdAt: instant(record.issuedAtMillis),\n retentionUntil: instant(retentionUntilMillis),\n receipt: Schema.encodeSync(receiptJson)({\n requestId: record.requestId,\n reference: {\n proofId: record.proofId,\n purpose: record.purpose,\n keyId: record.verifier.keyId,\n },\n }),\n }),\n decodeReceipt: (row) => decode(receiptJson, row.receipt),\n },\n series: {\n ...mapped(\"proofSeries\"),\n moduleId: \"moduleId\",\n purpose: \"purpose\",\n scopeKey: \"scopeKey\",\n activeProofId: \"activeProofId\",\n lastIssueAt: \"lastIssueAt\",\n version: \"version\",\n encodeInsert: (row) => ({ ...row, activeProofId: null, lastIssueAt: null }),\n },\n generation: {\n ...mapped(\"proofGenerations\"),\n moduleId: \"moduleId\",\n purpose: \"purpose\",\n proofId: \"proofId\",\n requestId: \"requestId\",\n seriesKey: \"seriesKey\",\n deliveryId: \"deliveryId\",\n binding: \"binding\",\n verifierKeyId: \"verifierKeyId\",\n verifierDigest: \"verifierDigest\",\n issuedAt: \"issuedAt\",\n expiresAt: \"expiresAt\",\n version: \"version\",\n state: \"state\",\n sendCount: \"sendCount\",\n deliveryState: \"deliveryState\",\n claimVersion: \"claimVersion\",\n claimDeadline: \"claimDeadline\",\n retryAt: \"retryAt\",\n deliveryRetryMillis: \"deliveryRetryMillis\",\n retentionUntil: \"retentionUntil\",\n encodeInsert: ({\n record,\n seriesKey,\n retentionUntilMillis,\n state,\n deliveryState,\n policy,\n }) => ({\n moduleId: record.moduleId,\n purpose: record.purpose,\n proofId: record.proofId,\n requestId: record.requestId,\n seriesKey,\n deliveryId: record.deliveryId,\n binding: Schema.encodeSync(bindingJson)(record.binding),\n verifierKeyId: record.verifier.keyId,\n verifierDigest: record.verifier.digest,\n issuedAt: instant(record.issuedAtMillis),\n expiresAt: instant(record.expiresAtMillis),\n version: record.version,\n state,\n sendCount: 0,\n deliveryState,\n claimVersion: null,\n claimDeadline: null,\n retryAt: null,\n deliveryRetryMillis: policy.deliveryRetryMillis,\n retentionUntil: instant(retentionUntilMillis),\n fingerprint: record.fingerprint,\n }),\n decodeBinding: (row) => decode(bindingJson, row.binding),\n decodeRecord: (row) =>\n Effect.gen(function* () {\n return yield* decode(ProofRecord, {\n moduleId: row.moduleId,\n purpose: row.purpose,\n proofId: row.proofId,\n requestId: row.requestId,\n fingerprint: row.fingerprint,\n deliveryId: row.deliveryId,\n binding: yield* decode(bindingJson, row.binding),\n verifier: { keyId: row.verifierKeyId, digest: row.verifierDigest },\n issuedAtMillis: yield* readInstant(row.issuedAt),\n expiresAtMillis: yield* readInstant(row.expiresAt),\n version: row.version,\n });\n }),\n },\n continuation: {\n ...mapped(\"proofContinuations\"),\n moduleId: \"moduleId\",\n purpose: \"purpose\",\n continuationId: \"continuationId\",\n digest: \"digest\",\n proofId: \"proofId\",\n seriesKey: \"seriesKey\",\n binding: \"binding\",\n expiresAt: \"expiresAt\",\n consumed: \"consumed\",\n version: \"version\",\n retentionUntil: \"retentionUntil\",\n encodeInsert: (record) => ({\n ...record,\n binding: Schema.encodeSync(bindingJson)(record.binding),\n expiresAt: instant(record.expiresAtMillis),\n consumed: false,\n retentionUntil: instant(record.retentionUntilMillis),\n }),\n decode: (row) =>\n Effect.gen(function* () {\n return yield* decode(ProofContinuation, {\n ...row,\n binding: yield* decode(bindingJson, row.binding),\n expiresAtMillis: yield* readInstant(row.expiresAt),\n });\n }),\n },\n rateScope: {\n ...mapped(\"proofScopes\"),\n moduleId: \"moduleId\",\n purpose: \"purpose\",\n action: \"action\",\n scopeKind: \"scopeKind\",\n scopeKey: \"scopeKey\",\n encodeInsert: (row) => ({ ...row }),\n },\n abuseEvent: {\n ...mapped(\"proofAbuse\"),\n moduleId: \"moduleId\",\n purpose: \"purpose\",\n action: \"action\",\n scopeKind: \"scopeKind\",\n scopeKey: \"scopeKey\",\n commandId: \"commandId\",\n occurredAt: \"occurredAt\",\n retentionUntil: \"retentionUntil\",\n encodeInsert: (row) => ({\n ...row,\n occurredAt: instant(row.occurredAtMillis),\n retentionUntil: instant(row.retentionUntilMillis),\n }),\n },\n failureEvent: {\n ...mapped(\"proofFailures\"),\n moduleId: \"moduleId\",\n purpose: \"purpose\",\n seriesKey: \"seriesKey\",\n commandId: \"commandId\",\n occurredAt: \"occurredAt\",\n retentionUntil: \"retentionUntil\",\n encodeInsert: (row) => ({\n ...row,\n occurredAt: instant(row.occurredAtMillis),\n retentionUntil: instant(row.retentionUntilMillis),\n }),\n },\n command: {\n ...mapped(\"proofCommands\"),\n moduleId: \"moduleId\",\n commandId: \"commandId\",\n kind: \"kind\",\n decision: \"decision\",\n retentionUntil: \"retentionUntil\",\n encodeInsert: (row) => ({ ...row, retentionUntil: instant(row.retentionUntilMillis) }),\n },\n });\n\n const passwords = (): AnyPasswordPersistenceMapping<SqlFragment> => {\n const verifier = (replacement: PasswordReplacement) => ({\n verifier: Redacted.value(replacement.verifier),\n normalization: replacement.normalization,\n });\n\n return {\n subjectId,\n subject,\n authorityCredential: authorityCredential(),\n constraints: requiredPasswordConstraints,\n isCommandConflict: () => false,\n encodeInstant: instant,\n decodeInstant: readInstant,\n allocateAttemptId: allocate.pipe(Effect.map(PasswordAttemptId.make)),\n allocateCredentialId: allocate,\n allocateRevision: allocate.pipe(Effect.map(SecurityRevision.make)),\n commandRetentionMillis: 86_400_000,\n sessionInvalidation: \"same-authority-immediate\",\n identifier: {\n table: table(\"identifiers\"),\n namespace: \"namespace\",\n value: \"value\",\n subjectId: \"subjectId\",\n verifiedAt: \"verifiedAt\",\n bindingRevision: \"revision\",\n isCurrent: (row) => row.active === true,\n encodeInitialInsert: (identifier, subjectId, revision) => ({\n ...identifier,\n subjectId,\n revision,\n verifiedAt: null,\n active: true,\n }),\n },\n credential: {\n ...mapped(\"passwords\"),\n moduleId: \"moduleId\",\n subjectId: \"subjectId\",\n credentialId: \"credentialId\",\n credentialRevision: \"credentialRevision\",\n verifierVersion: \"verifierVersion\",\n verifier: \"verifier\",\n normalization: \"normalization\",\n encodeInsert: ({ replacement, ...row }) => ({ ...row, ...verifier(replacement) }),\n encodeVerifier: (hash, verifierVersion) => ({\n verifier: Redacted.value(hash),\n verifierVersion,\n }),\n encodeReplacement: ({ replacement, ...row }) => ({ ...row, ...verifier(replacement) }),\n decode: ({ moduleId, subject: row, identifier, credential }) =>\n Effect.gen(function* () {\n const id = yield* s.toSubject(row[s.id]);\n const hash = yield* decode(EncodedPasswordHash, credential.verifier);\n\n return yield* decode(PasswordCredentialSnapshot, {\n moduleId,\n revision: {\n subjectId: id,\n securityRevision: row[s.securityRevision],\n credentials: [\n {\n credentialId: credential.credentialId,\n revision: credential.credentialRevision,\n },\n ],\n },\n credentialId: credential.credentialId,\n credentialRevision: credential.credentialRevision,\n verifierVersion: credential.verifierVersion,\n verifier: hash,\n normalization: credential.normalization,\n identifier: yield* decode(LoginIdentifier, {\n namespace: identifier.namespace,\n value: identifier.value,\n }),\n identifierBindingRevision: identifier.revision,\n ...(identifier.verifiedAt === null\n ? {}\n : { identifierVerifiedAtMillis: yield* readInstant(identifier.verifiedAt) }),\n });\n }),\n },\n attempt: {\n ...mapped(\"passwordAttempts\"),\n moduleId: \"moduleId\",\n action: \"action\",\n attemptId: \"attemptId\",\n identifierNamespace: \"identifierNamespace\",\n identifierValue: \"identifierValue\",\n subjectId: \"subjectId\",\n credentialId: \"credentialId\",\n securityRevision: \"securityRevision\",\n credentialRevision: \"credentialRevision\",\n verifierVersion: \"verifierVersion\",\n identifierBindingRevision: \"identifierBindingRevision\",\n admittedAt: \"admittedAt\",\n deadline: \"deadline\",\n retentionUntil: \"retentionUntil\",\n state: \"state\",\n encodeInsert: (row, { nativeSubjectId, state }) => ({\n moduleId: row.moduleId,\n action: row.action,\n attemptId: row.attemptId,\n identifierNamespace: row.identifier.namespace,\n identifierValue: row.identifier.value,\n subjectId: nativeSubjectId ?? null,\n credentialId: row.credentialId ?? null,\n securityRevision: row.securityRevision ?? null,\n credentialRevision: row.credentialRevision ?? null,\n verifierVersion: row.verifierVersion ?? null,\n identifierBindingRevision: row.identifierBindingRevision ?? null,\n admittedAt: instant(row.admittedAtMillis),\n deadline: instant(row.deadlineMillis),\n retentionUntil: instant(row.retentionUntilMillis),\n state,\n }),\n },\n command: {\n ...mapped(\"passwordCommands\"),\n moduleId: \"moduleId\",\n commandId: \"commandId\",\n action: \"action\",\n bindingDigest: \"bindingDigest\",\n decision: \"decision\",\n retentionUntil: \"retentionUntil\",\n encodeInsert: (row) => ({ ...row, retentionUntil: instant(row.retentionUntilMillis) }),\n },\n };\n };\n\n const emails = (): AnyEmailAddressMapping<SqlFragment> => ({\n subjectId,\n subject,\n constraints: requiredEmailAddressConstraints,\n addressCardinality: \"single\",\n changeDisposition: \"retire-source\",\n encodeInstant: instant,\n decodeInstant: readInstant,\n allocateCredentialId: allocate,\n allocateRevision: allocate.pipe(Effect.map(SecurityRevision.make)),\n commandRetentionMillis: 86_400_000,\n sessionInvalidation: \"same-authority-immediate\",\n isCommandConflict: () => false,\n isIdentifierConflict: () => false,\n isCredentialConflict: () => false,\n authorityCredential: {\n ...authorityCredential(),\n encodeActivation: (revision) => ({ revision, active: true }),\n encodeRetirement: (revision) => ({ revision, active: false }),\n },\n identifier: {\n table: table(\"identifiers\"),\n namespace: \"namespace\",\n value: \"value\",\n subjectId: \"subjectId\",\n verifiedAt: \"verifiedAt\",\n bindingRevision: \"revision\",\n isCurrent: (row) => row.active === true && row.verifiedAt !== null,\n isMutableTarget: (row) => row.active === true && row.verifiedAt === null,\n encodeVerifiedInsert: ({ identifier, subjectId, verifiedAtMillis, bindingRevision }) => ({\n ...identifier,\n subjectId,\n verifiedAt: instant(verifiedAtMillis),\n revision: bindingRevision,\n active: true,\n }),\n encodeVerification: ({ verifiedAtMillis, bindingRevision }) => ({\n verifiedAt: instant(verifiedAtMillis),\n revision: bindingRevision,\n active: true,\n }),\n encodeRetirement: ({ bindingRevision }) => ({ revision: bindingRevision, active: false }),\n },\n credential: {\n table: table(\"emailCredentials\"),\n moduleId: \"moduleId\",\n subjectId: \"subjectId\",\n credentialId: \"credentialId\",\n identifierNamespace: \"identifierNamespace\",\n identifierValue: \"identifierValue\",\n credentialRevision: \"credentialRevision\",\n status: \"active\",\n isActiveStatus: (value) => value === true,\n encodeVerifiedInsert: ({ identifier, ...row }) => ({\n ...row,\n identifierNamespace: identifier.namespace,\n identifierValue: identifier.value,\n active: true,\n }),\n encodeActivation: ({ identifier, credentialRevision }) => ({\n identifierNamespace: identifier.namespace,\n identifierValue: identifier.value,\n credentialRevision,\n active: true,\n }),\n encodeRetirement: ({ credentialRevision }) => ({ credentialRevision, active: false }),\n decode: ({ moduleId, subject: row, identifier, credential }) =>\n Effect.gen(function* () {\n return yield* decode(EmailCredentialSnapshot, {\n moduleId,\n identifier: { namespace: identifier.namespace, value: identifier.value },\n identifierRevision: identifier.revision,\n verifiedAtMillis: yield* readInstant(identifier.verifiedAt),\n credentialId: credential.credentialId,\n credentialRevision: credential.credentialRevision,\n revision: {\n subjectId: yield* s.toSubject(row[s.id]),\n securityRevision: row[s.securityRevision],\n credentials: [\n { credentialId: credential.credentialId, revision: credential.credentialRevision },\n ],\n },\n });\n }),\n },\n command: {\n table: table(\"emailCommands\"),\n moduleId: \"moduleId\",\n commandId: \"commandId\",\n action: \"action\",\n bindingDigest: \"bindingDigest\",\n retentionUntil: \"retentionUntil\",\n encodeInsert: ({ retentionUntilMillis, ...row }) => ({\n ...row,\n retentionUntil: instant(retentionUntilMillis),\n }),\n },\n });\n\n const sessions = <C extends Schema.Codec<unknown, unknown, never, never>>(\n claims: C,\n ): StatefulSessionMapping<\n C[\"Type\"],\n TableModel,\n TableModel,\n TableModel,\n TableModel,\n TableModel,\n unknown,\n string\n > => {\n const record = Schema.fromJsonString(\n Schema.Struct({\n ...SessionMetadata.fields,\n claims: Schema.Unknown,\n digest: TokenDigest,\n version: SecurityRevision,\n provenance: SessionAuthenticationProvenance,\n credentialVersion: SessionCredentialVersion,\n }),\n );\n\n const encodeRow = (value: StatefulSessionRecord<C[\"Type\"]>) => ({\n digest: value.digest,\n version: value.version,\n securityRevision: value.securityRevision,\n issuedAt: instant(DateTime.toEpochMillis(value.issuedAt)),\n expiresAt: instant(DateTime.toEpochMillis(value.expiresAt)),\n absoluteExpiresAt: instant(DateTime.toEpochMillis(value.absoluteExpiresAt)),\n record: Schema.encodeSync(record)({\n ...value,\n claims: Schema.encodeSync(claims)(value.claims),\n }),\n });\n\n return {\n ...authority(),\n isConstraintConflict: () => false,\n constraints: { sessionDigest: \"unique(session.digest)\", flowId: \"unique(flow.flowId)\" },\n sessionId: {\n toNative: (id) => Effect.succeed(id),\n toSession: (id) => decode(SessionId, id),\n equals: Object.is,\n },\n flow: {\n table: table(\"sessionFlows\"),\n flowId: \"flowId\",\n subjectId: \"subjectId\",\n state: \"state\",\n pendingDigest: \"pendingDigest\",\n dedupUntil: \"dedupUntil\",\n pendingStateValue: \"pending\",\n establishedStateValue: \"established\",\n encodeInstant: (date) => instant(DateTime.toEpochMillis(date)),\n decodeInstant: (value) => readInstant(value).pipe(Effect.map(DateTime.makeUnsafe)),\n encodePendingInsert: (row) => ({\n flowId: row.evidence.flowId,\n subjectId: row.subjectId,\n state: \"pending\",\n pendingDigest: row.pendingDigest,\n dedupUntil: instant(DateTime.toEpochMillis(row.dedupUntil)),\n }),\n encodeEstablishedInsert: (row) => ({\n flowId: row.evidence.flowId,\n subjectId: row.subjectId,\n state: \"established\",\n pendingDigest: null,\n dedupUntil: instant(DateTime.toEpochMillis(row.dedupUntil)),\n }),\n },\n session: {\n table: table(\"sessions\"),\n sessionId: \"sessionId\",\n subjectId: \"subjectId\",\n digest: \"digest\",\n version: \"version\",\n securityRevision: \"securityRevision\",\n issuedAt: \"issuedAt\",\n expiresAt: \"expiresAt\",\n absoluteExpiresAt: \"absoluteExpiresAt\",\n encodeInstant: (date) => instant(DateTime.toEpochMillis(date)),\n allocateId: allocate,\n allocateVersion: allocate.pipe(Effect.map(SecurityRevision.make)),\n encodeInsert: (value, ids) => ({ ...encodeRow(value), ...ids }),\n encodeRotation: encodeRow,\n decode: (row) =>\n Effect.gen(function* () {\n const saved = yield* decode(record, row.record);\n const decodedClaims = yield* decode(claims, saved.claims);\n\n return { ...saved, claims: decodedClaims };\n }),\n },\n };\n };\n\n return { table, authority, proofs, passwords, emails, sessions, string };\n});\n"],"mappings":";;;;;;;;;;;;;;AA0CA,MAAM,WAAW,UAAmB,wBAAwB,KAAK;CAAE,WAAW;CAAU;AAAM,CAAC;AAE/F,MAAM,UAAoD,QAAW,UACnE,OAAO,oBAAoB,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,OAAO,SAAS,OAAO,CAAC;AAEzE,MAAM,UAAU,UAAmB,OAAO,kBAAkB,OAAO,MAAM,CAAC,CAAC,KAAK;AAChF,MAAM,QAAQ,OAAO,WAAW,OAAO,eAAe,OAAO,MAAM,OAAO,MAAM,CAAC,CAAC;AAClF,MAAM,cAAc,OAAO,eAAe,YAAY;AACtD,MAAM,cAAc,OAAO,eAAe,mBAAmB;AAE7D,MAAMA,gBAAc,OAAO,OAAO;CAChC,UAAU,OAAO;CACjB,SAAS;CACT,SAAS;CACT,WAAW;CACX,aAAa;CACb,YAAY;CACZ,SAAS;CACT,UAAU,OAAO,OAAO;EAAE,OAAO,OAAO;EAAQ,QAAQ;CAAY,CAAC;CACrE,gBAAgB,OAAO;CACvB,iBAAiB,OAAO;CACxB,SAAS;AACX,CAAC;AAED,MAAM,oBAAoB,OAAO,OAAO;CACtC,UAAU,OAAO;CACjB,SAAS;CACT,gBAAgB;CAChB,QAAQ;CACR,SAAS;CACT,WAAW,OAAO;CAClB,SAAS;CACT,iBAAiB,OAAO;CACxB,SAAS;AACX,CAAC;;;;;;;AAQD,MAAa,eAAe,OAAO,WAAW,WAAW,OAAqB;CAC5E,MAAM,SAAS,OAAO,OAAO;CAE7B,MAAM,WAAW,SAAS,KACxB,OAAO,eAAe,OAAO,QAAQ,MAAM,GAC3C,OAAO,SAA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KAAc;IAC3C,CAAC;GACL;EACF;CACF;CAEA,OAAO;EAAE;EAAO;EAAW;EAAQ;EAAW;EAAQ;EAAU;CAAO;AACzE,CAAC"}
1
+ {"version":3,"file":"storage-mapping.mjs","names":["ProofRecord"],"sources":["../../src/internal/storage-mapping.ts"],"sourcesContent":["import { EmailCredentialSnapshot } from \"@yielded/auth/Email\";\nimport { LoginIdentifier } from \"@yielded/auth/Identity\";\nimport {\n PasswordCredentialSnapshot,\n EncodedPasswordHash,\n type PasswordReplacement,\n} from \"@yielded/auth/Password\";\nimport {\n ProofBinding,\n ProofContinuationId,\n ProofDeliveryId,\n ProofId,\n ProofPurpose,\n ProofRequestId,\n ProofRequestReceipt,\n ProofVersion,\n} from \"@yielded/auth/Proofs\";\nimport { TokenDigest } from \"@yielded/auth/Schema\";\nimport {\n SecurityRevision,\n SessionId,\n SessionMetadata,\n SessionAuthenticationProvenance,\n SessionCredentialVersion,\n type StatefulSessionRecord,\n} from \"@yielded/auth/Sessions\";\nimport { Crypto, DateTime, Effect, Redacted, Schema } from \"effect\";\n\nimport type { MappingInput } from \"./configuration\";\nimport { randomId } from \"./crypto\";\nimport { PersistenceMappingError } from \"./mapping-error\";\nimport { requiredEmailAddressConstraints, type AnyEmailAddressMapping } from \"./models/email-model\";\nimport {\n requiredPasswordConstraints,\n type AnyPasswordPersistenceMapping,\n} from \"./models/password-model\";\nimport { requiredProofConstraints, type AnyProofPersistenceMapping } from \"./models/proof-model\";\nimport type { StatefulSessionMapping } from \"./models/session-model\";\nimport type { TableModel, SqlFragment } from \"./query-operations\";\nimport { storageTables, type StorageRole } from \"./storage-tables\";\n\nconst failure = (cause: unknown) => PersistenceMappingError.make({ operation: \"decode\", cause });\n\nconst decode = <S extends Schema.Codec<unknown, unknown>>(schema: S, value: unknown) =>\n Schema.decodeUnknownEffect(schema)(value).pipe(Effect.mapError(failure));\n\nconst string = (value: unknown) => Schema.decodeUnknownSync(Schema.String)(value);\nconst tuple = Schema.encodeSync(Schema.fromJsonString(Schema.Array(Schema.String)));\nconst bindingJson = Schema.fromJsonString(ProofBinding);\nconst receiptJson = Schema.fromJsonString(ProofRequestReceipt);\n\nconst ProofRecord = Schema.Struct({\n moduleId: Schema.String,\n purpose: ProofPurpose,\n proofId: ProofId,\n requestId: ProofRequestId,\n fingerprint: TokenDigest,\n deliveryId: ProofDeliveryId,\n binding: ProofBinding,\n verifier: Schema.Struct({ keyId: Schema.String, digest: TokenDigest }),\n issuedAtMillis: Schema.Int,\n expiresAtMillis: Schema.Int,\n version: ProofVersion,\n});\n\nconst ProofContinuation = Schema.Struct({\n moduleId: Schema.String,\n purpose: ProofPurpose,\n continuationId: ProofContinuationId,\n digest: TokenDigest,\n proofId: ProofId,\n seriesKey: Schema.String,\n binding: ProofBinding,\n expiresAtMillis: Schema.Int,\n version: ProofVersion,\n});\n\n/** Derive shared row mappings from a managed or custom storage layout.\n * Acquire Effect Crypto once; the returned allocators retain that implementation.\n * Each factory requires its role tables to exist. Adapter authors supply typed\n * table handles and dialect-specific clocks/commit predicates, and may refine\n * authority policy for explicit services. This does not alter composed defaults.\n */\nexport const makeMappings = Effect.fnUntraced(function* (input: MappingInput) {\n const crypto = yield* Crypto.Crypto;\n\n const allocate = randomId.pipe(\n Effect.provideService(Crypto.Crypto, crypto),\n Effect.mapError(failure),\n );\n\n const table = (role: StorageRole) => {\n const found = input.tables[role];\n\n if (found === undefined) throw failure(`Missing ${role} mapping`);\n\n return found;\n };\n\n const mapped = (role: StorageRole) => ({\n table: table(role),\n ...Object.fromEntries(Object.keys(storageTables[role].columns).map((key) => [key, key])),\n });\n\n const { subjects: s, encodeInstant: instant, decodeInstant: readInstant } = input;\n const subjectId = { toNative: s.toNative, toSubject: s.toSubject, equals: Object.is };\n\n const subject = {\n table: s.table,\n id: s.id,\n status: s.status,\n securityRevision: s.securityRevision,\n isActiveStatus: (value: unknown) => Object.is(value, s.activeValue),\n d1ActiveStatusValue: s.activeValue,\n decodeRequirement: s.requirements,\n decodeActionRequirement: s.actionRequirements,\n nextSecurityRevision: () => allocate.pipe(Effect.map(SecurityRevision.make)),\n };\n\n const authorityCredential = () => ({\n ...mapped(\"credentials\"),\n subjectId: \"subjectId\",\n credentialId: \"credentialId\",\n revision: \"revision\",\n status: \"active\",\n isActiveStatus: (value: unknown) => value === true,\n encodeInsert: (row: object) => ({ ...row, active: true }),\n encodeRevision: (revision: SecurityRevision) => ({ revision }),\n });\n\n const authority = () => ({ subjectId, subject, credential: authorityCredential() });\n\n const proofs = (): AnyProofPersistenceMapping<SqlFragment> => ({\n constraints: requiredProofConstraints,\n encodeInstant: instant,\n decodeInstant: readInstant,\n allocateVersion: allocate.pipe(Effect.map(ProofVersion.make)),\n isRequestConflict: () => false,\n isSeriesConflict: () => false,\n isCommandConflict: () => false,\n scopeKeys: ({ binding }) => ({\n series: tuple([\n binding.identifier.namespace,\n binding.identifier.value,\n binding._tag === \"Identifier\" ? \"anonymous\" : binding.revision.subjectId,\n ]),\n identifier: tuple([binding.identifier.namespace, binding.identifier.value]),\n subject: binding._tag === \"Identifier\" ? \"anonymous\" : binding.revision.subjectId,\n }),\n authority: {\n ...authority(),\n identifier: {\n table: table(\"identifiers\"),\n namespace: \"namespace\",\n value: \"value\",\n isCurrent: (request, rows) =>\n request.binding._tag === \"Identifier\"\n ? rows.length === 0\n : request.binding._tag === \"IdentifierChange\"\n ? rows.length === 0 ||\n (rows.length === 1 &&\n rows.every(\n (row) =>\n Object.is(row.subjectId, request.nativeSubjectId) &&\n row.active === true &&\n row.verifiedAt === null,\n ))\n : rows.length === 1 &&\n rows.every(\n (row) => Object.is(row.subjectId, request.nativeSubjectId) && row.active === true,\n ),\n },\n },\n request: {\n ...mapped(\"proofRequests\"),\n moduleId: \"moduleId\",\n requestId: \"requestId\",\n fingerprint: \"fingerprint\",\n proofId: \"proofId\",\n purpose: \"purpose\",\n keyId: \"keyId\",\n createdAt: \"createdAt\",\n retentionUntil: \"retentionUntil\",\n encodeInsert: ({ record, retentionUntilMillis }) => ({\n moduleId: record.moduleId,\n requestId: record.requestId,\n fingerprint: record.fingerprint,\n proofId: record.proofId,\n purpose: record.purpose,\n keyId: record.verifier.keyId,\n createdAt: instant(record.issuedAtMillis),\n retentionUntil: instant(retentionUntilMillis),\n receipt: Schema.encodeSync(receiptJson)({\n requestId: record.requestId,\n reference: {\n proofId: record.proofId,\n purpose: record.purpose,\n keyId: record.verifier.keyId,\n },\n }),\n }),\n decodeReceipt: (row) => decode(receiptJson, row.receipt),\n },\n series: {\n ...mapped(\"proofSeries\"),\n moduleId: \"moduleId\",\n purpose: \"purpose\",\n scopeKey: \"scopeKey\",\n activeProofId: \"activeProofId\",\n lastIssueAt: \"lastIssueAt\",\n version: \"version\",\n encodeInsert: (row) => ({ ...row, activeProofId: null, lastIssueAt: null }),\n },\n generation: {\n ...mapped(\"proofGenerations\"),\n moduleId: \"moduleId\",\n purpose: \"purpose\",\n proofId: \"proofId\",\n requestId: \"requestId\",\n seriesKey: \"seriesKey\",\n deliveryId: \"deliveryId\",\n binding: \"binding\",\n verifierKeyId: \"verifierKeyId\",\n verifierDigest: \"verifierDigest\",\n issuedAt: \"issuedAt\",\n expiresAt: \"expiresAt\",\n version: \"version\",\n state: \"state\",\n sendCount: \"sendCount\",\n deliveryState: \"deliveryState\",\n claimVersion: \"claimVersion\",\n claimDeadline: \"claimDeadline\",\n retryAt: \"retryAt\",\n deliveryRetryMillis: \"deliveryRetryMillis\",\n retentionUntil: \"retentionUntil\",\n encodeInsert: ({\n record,\n seriesKey,\n retentionUntilMillis,\n state,\n deliveryState,\n policy,\n }) => ({\n moduleId: record.moduleId,\n purpose: record.purpose,\n proofId: record.proofId,\n requestId: record.requestId,\n seriesKey,\n deliveryId: record.deliveryId,\n binding: Schema.encodeSync(bindingJson)(record.binding),\n verifierKeyId: record.verifier.keyId,\n verifierDigest: record.verifier.digest,\n issuedAt: instant(record.issuedAtMillis),\n expiresAt: instant(record.expiresAtMillis),\n version: record.version,\n state,\n sendCount: 0,\n deliveryState,\n claimVersion: null,\n claimDeadline: null,\n retryAt: null,\n deliveryRetryMillis: policy.deliveryRetryMillis,\n retentionUntil: instant(retentionUntilMillis),\n fingerprint: record.fingerprint,\n }),\n decodeBinding: (row) => decode(bindingJson, row.binding),\n decodeRecord: (row) =>\n Effect.gen(function* () {\n return yield* decode(ProofRecord, {\n moduleId: row.moduleId,\n purpose: row.purpose,\n proofId: row.proofId,\n requestId: row.requestId,\n fingerprint: row.fingerprint,\n deliveryId: row.deliveryId,\n binding: yield* decode(bindingJson, row.binding),\n verifier: { keyId: row.verifierKeyId, digest: row.verifierDigest },\n issuedAtMillis: yield* readInstant(row.issuedAt),\n expiresAtMillis: yield* readInstant(row.expiresAt),\n version: row.version,\n });\n }),\n },\n continuation: {\n ...mapped(\"proofContinuations\"),\n moduleId: \"moduleId\",\n purpose: \"purpose\",\n continuationId: \"continuationId\",\n digest: \"digest\",\n proofId: \"proofId\",\n seriesKey: \"seriesKey\",\n binding: \"binding\",\n expiresAt: \"expiresAt\",\n consumed: \"consumed\",\n version: \"version\",\n retentionUntil: \"retentionUntil\",\n encodeInsert: (record) => ({\n ...record,\n binding: Schema.encodeSync(bindingJson)(record.binding),\n expiresAt: instant(record.expiresAtMillis),\n consumed: false,\n retentionUntil: instant(record.retentionUntilMillis),\n }),\n decode: (row) =>\n Effect.gen(function* () {\n return yield* decode(ProofContinuation, {\n ...row,\n binding: yield* decode(bindingJson, row.binding),\n expiresAtMillis: yield* readInstant(row.expiresAt),\n });\n }),\n },\n rateScope: {\n ...mapped(\"proofScopes\"),\n moduleId: \"moduleId\",\n purpose: \"purpose\",\n action: \"action\",\n scopeKind: \"scopeKind\",\n scopeKey: \"scopeKey\",\n encodeInsert: (row) => ({ ...row }),\n },\n abuseEvent: {\n ...mapped(\"proofAbuse\"),\n moduleId: \"moduleId\",\n purpose: \"purpose\",\n action: \"action\",\n scopeKind: \"scopeKind\",\n scopeKey: \"scopeKey\",\n commandId: \"commandId\",\n occurredAt: \"occurredAt\",\n retentionUntil: \"retentionUntil\",\n encodeInsert: (row) => ({\n ...row,\n occurredAt: instant(row.occurredAtMillis),\n retentionUntil: instant(row.retentionUntilMillis),\n }),\n },\n failureEvent: {\n ...mapped(\"proofFailures\"),\n moduleId: \"moduleId\",\n purpose: \"purpose\",\n seriesKey: \"seriesKey\",\n commandId: \"commandId\",\n occurredAt: \"occurredAt\",\n retentionUntil: \"retentionUntil\",\n encodeInsert: (row) => ({\n ...row,\n occurredAt: instant(row.occurredAtMillis),\n retentionUntil: instant(row.retentionUntilMillis),\n }),\n },\n command: {\n ...mapped(\"proofCommands\"),\n moduleId: \"moduleId\",\n commandId: \"commandId\",\n kind: \"kind\",\n decision: \"decision\",\n retentionUntil: \"retentionUntil\",\n encodeInsert: (row) => ({ ...row, retentionUntil: instant(row.retentionUntilMillis) }),\n },\n });\n\n const passwords = (): AnyPasswordPersistenceMapping<SqlFragment> => {\n const verifier = (replacement: PasswordReplacement) => ({\n verifier: Redacted.value(replacement.verifier),\n normalization: replacement.normalization,\n });\n\n return {\n subjectId,\n subject,\n authorityCredential: authorityCredential(),\n constraints: requiredPasswordConstraints,\n isCommandConflict: () => false,\n encodeInstant: instant,\n decodeInstant: readInstant,\n allocateCredentialId: allocate,\n allocateRevision: allocate.pipe(Effect.map(SecurityRevision.make)),\n commandRetentionMillis: 86_400_000,\n sessionInvalidation: \"same-authority-immediate\",\n identifier: {\n table: table(\"identifiers\"),\n namespace: \"namespace\",\n value: \"value\",\n subjectId: \"subjectId\",\n verifiedAt: \"verifiedAt\",\n bindingRevision: \"revision\",\n isCurrent: (row) => row.active === true,\n encodeInitialInsert: (identifier, subjectId, revision) => ({\n ...identifier,\n subjectId,\n revision,\n verifiedAt: null,\n active: true,\n }),\n },\n credential: {\n ...mapped(\"passwords\"),\n moduleId: \"moduleId\",\n subjectId: \"subjectId\",\n credentialId: \"credentialId\",\n credentialRevision: \"credentialRevision\",\n verifierVersion: \"verifierVersion\",\n verifier: \"verifier\",\n normalization: \"normalization\",\n encodeInsert: ({ replacement, ...row }) => ({ ...row, ...verifier(replacement) }),\n encodeVerifier: (hash, verifierVersion) => ({\n verifier: Redacted.value(hash),\n verifierVersion,\n }),\n encodeReplacement: ({ replacement, ...row }) => ({ ...row, ...verifier(replacement) }),\n decode: ({ moduleId, subject: row, identifier, credential }) =>\n Effect.gen(function* () {\n const id = yield* s.toSubject(row[s.id]);\n const hash = yield* decode(EncodedPasswordHash, credential.verifier);\n\n return yield* decode(PasswordCredentialSnapshot, {\n moduleId,\n revision: {\n subjectId: id,\n securityRevision: row[s.securityRevision],\n credentials: [\n {\n credentialId: credential.credentialId,\n revision: credential.credentialRevision,\n },\n ],\n },\n credentialId: credential.credentialId,\n credentialRevision: credential.credentialRevision,\n verifierVersion: credential.verifierVersion,\n verifier: hash,\n normalization: credential.normalization,\n identifier: yield* decode(LoginIdentifier, {\n namespace: identifier.namespace,\n value: identifier.value,\n }),\n identifierBindingRevision: identifier.revision,\n ...(identifier.verifiedAt === null\n ? {}\n : { identifierVerifiedAtMillis: yield* readInstant(identifier.verifiedAt) }),\n });\n }),\n },\n command: {\n ...mapped(\"passwordCommands\"),\n moduleId: \"moduleId\",\n commandId: \"commandId\",\n action: \"action\",\n bindingDigest: \"bindingDigest\",\n decision: \"decision\",\n retentionUntil: \"retentionUntil\",\n encodeInsert: (row) => ({ ...row, retentionUntil: instant(row.retentionUntilMillis) }),\n },\n };\n };\n\n const emails = (): AnyEmailAddressMapping<SqlFragment> => ({\n subjectId,\n subject,\n constraints: requiredEmailAddressConstraints,\n addressCardinality: \"single\",\n changeDisposition: \"retire-source\",\n encodeInstant: instant,\n decodeInstant: readInstant,\n allocateCredentialId: allocate,\n allocateRevision: allocate.pipe(Effect.map(SecurityRevision.make)),\n commandRetentionMillis: 86_400_000,\n sessionInvalidation: \"same-authority-immediate\",\n isCommandConflict: () => false,\n isIdentifierConflict: () => false,\n isCredentialConflict: () => false,\n authorityCredential: {\n ...authorityCredential(),\n encodeActivation: (revision) => ({ revision, active: true }),\n encodeRetirement: (revision) => ({ revision, active: false }),\n },\n identifier: {\n table: table(\"identifiers\"),\n namespace: \"namespace\",\n value: \"value\",\n subjectId: \"subjectId\",\n verifiedAt: \"verifiedAt\",\n bindingRevision: \"revision\",\n isCurrent: (row) => row.active === true && row.verifiedAt !== null,\n isMutableTarget: (row) => row.active === true && row.verifiedAt === null,\n encodeVerifiedInsert: ({ identifier, subjectId, verifiedAtMillis, bindingRevision }) => ({\n ...identifier,\n subjectId,\n verifiedAt: instant(verifiedAtMillis),\n revision: bindingRevision,\n active: true,\n }),\n encodeVerification: ({ verifiedAtMillis, bindingRevision }) => ({\n verifiedAt: instant(verifiedAtMillis),\n revision: bindingRevision,\n active: true,\n }),\n encodeRetirement: ({ bindingRevision }) => ({ revision: bindingRevision, active: false }),\n },\n credential: {\n table: table(\"emailCredentials\"),\n moduleId: \"moduleId\",\n subjectId: \"subjectId\",\n credentialId: \"credentialId\",\n identifierNamespace: \"identifierNamespace\",\n identifierValue: \"identifierValue\",\n credentialRevision: \"credentialRevision\",\n status: \"active\",\n isActiveStatus: (value) => value === true,\n encodeVerifiedInsert: ({ identifier, ...row }) => ({\n ...row,\n identifierNamespace: identifier.namespace,\n identifierValue: identifier.value,\n active: true,\n }),\n encodeActivation: ({ identifier, credentialRevision }) => ({\n identifierNamespace: identifier.namespace,\n identifierValue: identifier.value,\n credentialRevision,\n active: true,\n }),\n encodeRetirement: ({ credentialRevision }) => ({ credentialRevision, active: false }),\n decode: ({ moduleId, subject: row, identifier, credential }) =>\n Effect.gen(function* () {\n return yield* decode(EmailCredentialSnapshot, {\n moduleId,\n identifier: { namespace: identifier.namespace, value: identifier.value },\n identifierRevision: identifier.revision,\n verifiedAtMillis: yield* readInstant(identifier.verifiedAt),\n credentialId: credential.credentialId,\n credentialRevision: credential.credentialRevision,\n revision: {\n subjectId: yield* s.toSubject(row[s.id]),\n securityRevision: row[s.securityRevision],\n credentials: [\n { credentialId: credential.credentialId, revision: credential.credentialRevision },\n ],\n },\n });\n }),\n },\n command: {\n table: table(\"emailCommands\"),\n moduleId: \"moduleId\",\n commandId: \"commandId\",\n action: \"action\",\n bindingDigest: \"bindingDigest\",\n retentionUntil: \"retentionUntil\",\n encodeInsert: ({ retentionUntilMillis, ...row }) => ({\n ...row,\n retentionUntil: instant(retentionUntilMillis),\n }),\n },\n });\n\n const sessions = <C extends Schema.Codec<unknown, unknown, never, never>>(\n claims: C,\n ): StatefulSessionMapping<\n C[\"Type\"],\n TableModel,\n TableModel,\n TableModel,\n TableModel,\n TableModel,\n unknown,\n string\n > => {\n const record = Schema.fromJsonString(\n Schema.Struct({\n ...SessionMetadata.fields,\n claims: Schema.Unknown,\n digest: TokenDigest,\n version: SecurityRevision,\n provenance: SessionAuthenticationProvenance,\n credentialVersion: SessionCredentialVersion,\n }),\n );\n\n const encodeRow = (value: StatefulSessionRecord<C[\"Type\"]>) => ({\n digest: value.digest,\n version: value.version,\n securityRevision: value.securityRevision,\n issuedAt: instant(DateTime.toEpochMillis(value.issuedAt)),\n expiresAt: instant(DateTime.toEpochMillis(value.expiresAt)),\n absoluteExpiresAt: instant(DateTime.toEpochMillis(value.absoluteExpiresAt)),\n record: Schema.encodeSync(record)({\n ...value,\n claims: Schema.encodeSync(claims)(value.claims),\n }),\n });\n\n return {\n ...authority(),\n isConstraintConflict: () => false,\n constraints: { sessionDigest: \"unique(session.digest)\", flowId: \"unique(flow.flowId)\" },\n sessionId: {\n toNative: (id) => Effect.succeed(id),\n toSession: (id) => decode(SessionId, id),\n equals: Object.is,\n },\n flow: {\n table: table(\"sessionFlows\"),\n flowId: \"flowId\",\n subjectId: \"subjectId\",\n state: \"state\",\n pendingDigest: \"pendingDigest\",\n dedupUntil: \"dedupUntil\",\n pendingStateValue: \"pending\",\n establishedStateValue: \"established\",\n encodeInstant: (date) => instant(DateTime.toEpochMillis(date)),\n decodeInstant: (value) => readInstant(value).pipe(Effect.map(DateTime.makeUnsafe)),\n encodePendingInsert: (row) => ({\n flowId: row.evidence.flowId,\n subjectId: row.subjectId,\n state: \"pending\",\n pendingDigest: row.pendingDigest,\n dedupUntil: instant(DateTime.toEpochMillis(row.dedupUntil)),\n }),\n encodeEstablishedInsert: (row) => ({\n flowId: row.evidence.flowId,\n subjectId: row.subjectId,\n state: \"established\",\n pendingDigest: null,\n dedupUntil: instant(DateTime.toEpochMillis(row.dedupUntil)),\n }),\n },\n session: {\n table: table(\"sessions\"),\n sessionId: \"sessionId\",\n subjectId: \"subjectId\",\n digest: \"digest\",\n version: \"version\",\n securityRevision: \"securityRevision\",\n issuedAt: \"issuedAt\",\n expiresAt: \"expiresAt\",\n absoluteExpiresAt: \"absoluteExpiresAt\",\n encodeInstant: (date) => instant(DateTime.toEpochMillis(date)),\n allocateId: allocate,\n allocateVersion: allocate.pipe(Effect.map(SecurityRevision.make)),\n encodeInsert: (value, ids) => ({ ...encodeRow(value), ...ids }),\n encodeRotation: encodeRow,\n decode: (row) =>\n Effect.gen(function* () {\n const saved = yield* decode(record, row.record);\n const decodedClaims = yield* decode(claims, saved.claims);\n\n return { ...saved, claims: decodedClaims };\n }),\n },\n };\n };\n\n return { table, authority, proofs, passwords, emails, sessions, string };\n});\n"],"mappings":";;;;;;;;;;;;;;AAyCA,MAAM,WAAW,UAAmB,wBAAwB,KAAK;CAAE,WAAW;CAAU;AAAM,CAAC;AAE/F,MAAM,UAAoD,QAAW,UACnE,OAAO,oBAAoB,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,OAAO,SAAS,OAAO,CAAC;AAEzE,MAAM,UAAU,UAAmB,OAAO,kBAAkB,OAAO,MAAM,CAAC,CAAC,KAAK;AAChF,MAAM,QAAQ,OAAO,WAAW,OAAO,eAAe,OAAO,MAAM,OAAO,MAAM,CAAC,CAAC;AAClF,MAAM,cAAc,OAAO,eAAe,YAAY;AACtD,MAAM,cAAc,OAAO,eAAe,mBAAmB;AAE7D,MAAMA,gBAAc,OAAO,OAAO;CAChC,UAAU,OAAO;CACjB,SAAS;CACT,S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Ac;IAC3B,QAAQ;IACR,WAAW;IACX,OAAO;IACP,eAAe;IACf,YAAY;IACZ,mBAAmB;IACnB,uBAAuB;IACvB,gBAAgB,SAAS,QAAQ,SAAS,cAAc,IAAI,CAAC;IAC7D,gBAAgB,UAAU,YAAY,KAAK,CAAC,CAAC,KAAK,OAAO,IAAI,SAAS,UAAU,CAAC;IACjF,sBAAsB,SAAS;KAC7B,QAAQ,IAAI,SAAS;KACrB,WAAW,IAAI;KACf,OAAO;KACP,eAAe,IAAI;KACnB,YAAY,QAAQ,SAAS,cAAc,IAAI,UAAU,CAAC;IAC5D;IACA,0BAA0B,SAAS;KACjC,QAAQ,IAAI,SAAS;KACrB,WAAW,IAAI;KACf,OAAO;KACP,eAAe;KACf,YAAY,QAAQ,SAAS,cAAc,IAAI,UAAU,CAAC;IAC5D;GACF;GACA,SAAS;IACP,OAAO,MAAM,UAAU;IACvB,WAAW;IACX,WAAW;IACX,QAAQ;IACR,SAAS;IACT,kBAAkB;IAClB,UAAU;IACV,WAAW;IACX,mBAAmB;IACnB,gBAAgB,SAAS,QAAQ,SAAS,cAAc,IAAI,CAAC;IAC7D,YAAY;IACZ,iBAAiB,SAAS,KAAK,OAAO,IAAI,iBAAiB,IAAI,CAAC;IAChE,eAAe,OAAO,SAAS;KAAE,GAAG,UAAU,KAAK;KAAG,GAAG;IAAI;IAC7D,gBAAgB;IAChB,SAAS,QACP,OAAO,IAAI,aAAa;KACtB,MAAM,QAAQ,OAAO,OAAO,QAAQ,IAAI,MAAM;KAC9C,MAAM,gBAAgB,OAAO,OAAO,QAAQ,MAAM,MAAM;KAExD,OAAO;MAAE,GAAG;MAAO,QAAQ;KAAc;IAC3C,CAAC;GACL;EACF;CACF;CAEA,OAAO;EAAE;EAAO;EAAW;EAAQ;EAAW;EAAQ;EAAU;CAAO;AACzE,CAAC"}
@@ -0,0 +1,7 @@
1
+ //#region src/internal/storage-plans.d.ts
2
+ export declare const storageKeyPlans: (input: unknown, columnsFor: (table: object) => Readonly<Record<string, unknown>>) => {
3
+ readonly table: object;
4
+ readonly keys: ReadonlyArray<string>;
5
+ }[];
6
+ //#endregion
7
+ //# sourceMappingURL=storage-plans.d.mts.map
@@ -0,0 +1,189 @@
1
+ import { Predicate, Schema } from "effect";
2
+ //#region src/internal/storage-plans.ts
3
+ const uniquePlans = {
4
+ "unique(abuseEvent.moduleId,abuseEvent.action,abuseEvent.scopeKind,abuseEvent.scopeKey,abuseEvent.commandId)": ["abuseEvent", [
5
+ "moduleId",
6
+ "action",
7
+ "scopeKind",
8
+ "scopeKey",
9
+ "commandId"
10
+ ]],
11
+ "unique(admission.moduleId)": ["admission", ["moduleId"]],
12
+ "unique(attempt.moduleId,attempt.attemptId)": ["attempt", ["moduleId", "attemptId"]],
13
+ "unique(authority.subjectId,authority.credentialId)": ["authority", ["subjectId", "credentialId"]],
14
+ "unique(authorityCredential.subjectId,authorityCredential.credentialId)": ["authorityCredential", ["subjectId", "credentialId"]],
15
+ "unique(command.moduleId,command.commandId)": ["command", ["moduleId", "commandId"]],
16
+ "unique(connectedAdmission.admissionId)": ["admission", ["admissionId"]],
17
+ "unique(connectedClient.clientKey)": ["client", ["clientKey"]],
18
+ "unique(connectedCohort.cohortKey)": ["cohort", ["cohortKey"]],
19
+ "unique(connectedCommand.moduleId,connectedCommand.commandId)": ["command", ["moduleId", "commandId"]],
20
+ "unique(connectedFlow.moduleId,connectedFlow.commandId)": ["flow", ["moduleId", "commandId"]],
21
+ "unique(connectedFlow.moduleId,connectedFlow.flowId)": ["flow", ["moduleId", "flowId"]],
22
+ "unique(connectedFlow.stateDigest)": ["flow", ["stateDigest"]],
23
+ "unique(connectedGrant.moduleId,connectedGrant.grantId)": ["grant", ["moduleId", "grantId"]],
24
+ "unique(connectedGrant.moduleId,connectedGrant.subjectId,connectedGrant.profileKey,connectedGrant.activeIdentityKey)": ["grant", [
25
+ "moduleId",
26
+ "subjectId",
27
+ "profileKey",
28
+ "activeIdentityKey"
29
+ ]],
30
+ "unique(connectedRevocation.jobId)": ["job", ["jobId"]],
31
+ "unique(continuation.moduleId,continuation.continuationId)": ["continuation", ["moduleId", "continuationId"]],
32
+ "unique(continuation.moduleId,continuation.digest)": ["continuation", ["moduleId", "digest"]],
33
+ "unique(credential.credentialId)": ["credential", ["credentialId"]],
34
+ "unique(credential.identityKey)": ["credential", ["identityKey"]],
35
+ "unique(credential.moduleId,credential.credentialId)": ["credential", ["moduleId", "credentialId"]],
36
+ "unique(credential.moduleId,credential.subjectId)": ["credential", ["moduleId", "subjectId"]],
37
+ "unique(emailCommand.moduleId,emailCommand.commandId)": ["command", ["moduleId", "commandId"]],
38
+ "unique(emailCredential.moduleId,emailCredential.credentialId)": ["credential", ["moduleId", "credentialId"]],
39
+ "unique(emailCredential.moduleId,emailCredential.identifierNamespace,emailCredential.identifierValue)": ["credential", [
40
+ "moduleId",
41
+ "identifierNamespace",
42
+ "identifierValue"
43
+ ]],
44
+ "unique(emailRegistration.moduleId,emailRegistration.commandId)": ["registration", ["moduleId", "commandId"]],
45
+ "unique(emailRegistration.pendingReference)": ["registration", ["pendingReference"]],
46
+ "unique(failureEvent.moduleId,failureEvent.seriesKey,failureEvent.commandId)": ["failureEvent", [
47
+ "moduleId",
48
+ "seriesKey",
49
+ "commandId"
50
+ ]],
51
+ "unique(flow.flowId)": ["flow", ["flowId"]],
52
+ "unique(flow.moduleId,flow.commandId)": ["flow", ["moduleId", "commandId"]],
53
+ "unique(flow.moduleId,flow.flowId)": ["flow", ["moduleId", "flowId"]],
54
+ "unique(flow.stateDigest)": ["flow", ["stateDigest"]],
55
+ "unique(generation.moduleId,generation.deliveryId)": ["generation", ["moduleId", "deliveryId"]],
56
+ "unique(generation.moduleId,generation.proofId)": ["generation", ["moduleId", "proofId"]],
57
+ "unique(identifier.namespace,identifier.value)": ["identifier", ["namespace", "value"]],
58
+ "unique(intent.digest)": ["intent", ["digest"]],
59
+ "unique(intent.flowId)": ["intent", ["flowId"]],
60
+ "unique(intent.moduleId,intent.commandId)": ["intent", ["moduleId", "commandId"]],
61
+ "unique(intent.moduleId,intent.flowId)": ["intent", ["moduleId", "flowId"]],
62
+ "unique(intent.moduleId,intent.intentId)": ["intent", ["moduleId", "intentId"]],
63
+ "unique(intent.moduleId,intent.reference)": ["intent", ["moduleId", "reference"]],
64
+ "unique(ownership.identityKey)": ["ownership", ["identityKey"]],
65
+ "unique(pending.digest)": ["pending", ["digest"]],
66
+ "unique(pending.flowId)": ["pending", ["flowId"]],
67
+ "unique(rateScope.moduleId,rateScope.purpose,rateScope.action,rateScope.scopeKind,rateScope.scopeKey)": ["rateScope", [
68
+ "moduleId",
69
+ "purpose",
70
+ "action",
71
+ "scopeKind",
72
+ "scopeKey"
73
+ ]],
74
+ "unique(registration.moduleId,registration.requestId)": ["registration", ["moduleId", "requestId"]],
75
+ "unique(registration.recoveryReference)": ["registration", ["recoveryReference"]],
76
+ "unique(registrationCommand.moduleId,registrationCommand.commandId)": ["command", ["moduleId", "commandId"]],
77
+ "unique(request.moduleId,request.requestId)": ["request", ["moduleId", "requestId"]],
78
+ "unique(series.moduleId,series.purpose,series.scopeKey)": ["series", [
79
+ "moduleId",
80
+ "purpose",
81
+ "scopeKey"
82
+ ]],
83
+ "unique(session.digest)": ["session", ["digest"]],
84
+ "unique(tombstone.subjectId,tombstone.sessionId)": ["tombstone", ["subjectId", "sessionId"]],
85
+ "unique(tuple.identityKey)": ["ownership.tuple", ["identityKey"]],
86
+ "unique(unlinkCommand.moduleId,unlinkCommand.commandId)": ["command", ["moduleId", "commandId"]]
87
+ };
88
+ const arrayRoles = {
89
+ credentialId: "credential",
90
+ factor: "authority",
91
+ credentialOwnership: "credentialOwnership",
92
+ handleOwnership: "handleOwnership",
93
+ boundSubjectHandle: "handleOwnership",
94
+ flow: "flow",
95
+ command: "flow",
96
+ admission: "admission",
97
+ charge: "charge",
98
+ intentFlow: "intent",
99
+ intentCommand: "intent",
100
+ handle: "handle"
101
+ };
102
+ const nestedMappings = [
103
+ "read",
104
+ "signIn",
105
+ "password",
106
+ "proof",
107
+ "proofs",
108
+ "revocation",
109
+ "pending",
110
+ "session",
111
+ "source"
112
+ ];
113
+ const constraintGroups = [
114
+ "constraints",
115
+ "tupleConstraints",
116
+ "registrationConstraints",
117
+ "managementConstraints"
118
+ ];
119
+ const MappingRecord = Schema.Record(Schema.String, Schema.Unknown);
120
+ const record = Schema.decodeUnknownSync(MappingRecord);
121
+ const storageKeyPlans = (input, columnsFor) => {
122
+ const mapping = record(input);
123
+ const result = [];
124
+ for (const group of constraintGroups) {
125
+ if (mapping[group] === void 0) continue;
126
+ for (const [name, declaration] of Object.entries(record(mapping[group]))) {
127
+ if (declaration === "notNull(provisioningRequest.subjectId)") continue;
128
+ let role;
129
+ let keys;
130
+ if (typeof declaration === "string") {
131
+ const plan = uniquePlans[declaration];
132
+ if (plan !== void 0) [role, keys] = plan;
133
+ else if (declaration === "unique(id)") {
134
+ role = "subject";
135
+ keys = ["id"];
136
+ } else if (declaration === "unique(scope)") {
137
+ role = name;
138
+ keys = ["scope"];
139
+ } else if (declaration === "unique(credentialId)") {
140
+ role = "credential";
141
+ keys = ["id"];
142
+ } else if (declaration === "unique(namespace,value)") {
143
+ role = "identifier";
144
+ keys = ["namespace", "value"];
145
+ } else if (declaration === "unique(provider,issuer,subject)") {
146
+ role = "externalIdentity";
147
+ keys = [
148
+ "provider",
149
+ "issuer",
150
+ "subject"
151
+ ];
152
+ } else if (declaration === "unique(requestId)") {
153
+ role = "provisioningRequest";
154
+ keys = ["requestId"];
155
+ } else throw new Error("Unknown storage constraint");
156
+ } else if (Array.isArray(declaration) && declaration.every(Predicate.isString)) {
157
+ const mappedRole = group === "managementConstraints" && name === "command" ? "command" : arrayRoles[name];
158
+ if (mappedRole === void 0) throw new Error("Unknown storage constraint");
159
+ role = mappedRole;
160
+ keys = declaration;
161
+ } else throw new Error("Invalid storage constraint");
162
+ let target = mapping;
163
+ for (const segment of role.split(".")) target = record(target)[segment];
164
+ if (target === void 0 && Schema.is(MappingRecord)(mapping.pending)) target = mapping.pending[role];
165
+ let mapped = record(target);
166
+ if (role === "pending" && mapped.table === void 0) mapped = record(mapped.pending);
167
+ if (role === "ownership" && mapped.table === void 0) mapped = record(mapped.external ?? mapped.tuple);
168
+ if (!Predicate.isObject(mapped.table)) throw new Error("Missing storage table");
169
+ const columns = columnsFor(mapped.table);
170
+ result.push({
171
+ table: mapped.table,
172
+ keys: keys.map((key) => {
173
+ const value = mapped[key];
174
+ if (typeof value !== "string" || columns[value] === void 0) throw new Error("Missing mapped key");
175
+ return value;
176
+ })
177
+ });
178
+ }
179
+ }
180
+ for (const nested of nestedMappings) {
181
+ const value = mapping[nested];
182
+ if (Schema.is(MappingRecord)(value) && value.table === void 0) result.push(...storageKeyPlans(value, columnsFor));
183
+ }
184
+ return result;
185
+ };
186
+ //#endregion
187
+ export { storageKeyPlans };
188
+
189
+ //# sourceMappingURL=storage-plans.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage-plans.mjs","names":[],"sources":["../../src/internal/storage-plans.ts"],"sourcesContent":["import { Predicate, Schema } from \"effect\";\n\n// These are mapping contracts, not a parser for arbitrary constraint declarations.\n// Role aliases are explicit because their documentation names differ from mapping fields.\nconst uniquePlans: Readonly<Record<string, readonly [string, ReadonlyArray<string>]>> = {\n \"unique(abuseEvent.moduleId,abuseEvent.action,abuseEvent.scopeKind,abuseEvent.scopeKey,abuseEvent.commandId)\":\n [\"abuseEvent\", [\"moduleId\", \"action\", \"scopeKind\", \"scopeKey\", \"commandId\"]],\n \"unique(admission.moduleId)\": [\"admission\", [\"moduleId\"]],\n \"unique(attempt.moduleId,attempt.attemptId)\": [\"attempt\", [\"moduleId\", \"attemptId\"]],\n \"unique(authority.subjectId,authority.credentialId)\": [\n \"authority\",\n [\"subjectId\", \"credentialId\"],\n ],\n \"unique(authorityCredential.subjectId,authorityCredential.credentialId)\": [\n \"authorityCredential\",\n [\"subjectId\", \"credentialId\"],\n ],\n \"unique(command.moduleId,command.commandId)\": [\"command\", [\"moduleId\", \"commandId\"]],\n \"unique(connectedAdmission.admissionId)\": [\"admission\", [\"admissionId\"]],\n \"unique(connectedClient.clientKey)\": [\"client\", [\"clientKey\"]],\n \"unique(connectedCohort.cohortKey)\": [\"cohort\", [\"cohortKey\"]],\n \"unique(connectedCommand.moduleId,connectedCommand.commandId)\": [\n \"command\",\n [\"moduleId\", \"commandId\"],\n ],\n \"unique(connectedFlow.moduleId,connectedFlow.commandId)\": [\"flow\", [\"moduleId\", \"commandId\"]],\n \"unique(connectedFlow.moduleId,connectedFlow.flowId)\": [\"flow\", [\"moduleId\", \"flowId\"]],\n \"unique(connectedFlow.stateDigest)\": [\"flow\", [\"stateDigest\"]],\n \"unique(connectedGrant.moduleId,connectedGrant.grantId)\": [\"grant\", [\"moduleId\", \"grantId\"]],\n \"unique(connectedGrant.moduleId,connectedGrant.subjectId,connectedGrant.profileKey,connectedGrant.activeIdentityKey)\":\n [\"grant\", [\"moduleId\", \"subjectId\", \"profileKey\", \"activeIdentityKey\"]],\n \"unique(connectedRevocation.jobId)\": [\"job\", [\"jobId\"]],\n \"unique(continuation.moduleId,continuation.continuationId)\": [\n \"continuation\",\n [\"moduleId\", \"continuationId\"],\n ],\n \"unique(continuation.moduleId,continuation.digest)\": [\"continuation\", [\"moduleId\", \"digest\"]],\n \"unique(credential.credentialId)\": [\"credential\", [\"credentialId\"]],\n \"unique(credential.identityKey)\": [\"credential\", [\"identityKey\"]],\n \"unique(credential.moduleId,credential.credentialId)\": [\n \"credential\",\n [\"moduleId\", \"credentialId\"],\n ],\n \"unique(credential.moduleId,credential.subjectId)\": [\"credential\", [\"moduleId\", \"subjectId\"]],\n \"unique(emailCommand.moduleId,emailCommand.commandId)\": [\"command\", [\"moduleId\", \"commandId\"]],\n \"unique(emailCredential.moduleId,emailCredential.credentialId)\": [\n \"credential\",\n [\"moduleId\", \"credentialId\"],\n ],\n \"unique(emailCredential.moduleId,emailCredential.identifierNamespace,emailCredential.identifierValue)\":\n [\"credential\", [\"moduleId\", \"identifierNamespace\", \"identifierValue\"]],\n \"unique(emailRegistration.moduleId,emailRegistration.commandId)\": [\n \"registration\",\n [\"moduleId\", \"commandId\"],\n ],\n \"unique(emailRegistration.pendingReference)\": [\"registration\", [\"pendingReference\"]],\n \"unique(failureEvent.moduleId,failureEvent.seriesKey,failureEvent.commandId)\": [\n \"failureEvent\",\n [\"moduleId\", \"seriesKey\", \"commandId\"],\n ],\n \"unique(flow.flowId)\": [\"flow\", [\"flowId\"]],\n \"unique(flow.moduleId,flow.commandId)\": [\"flow\", [\"moduleId\", \"commandId\"]],\n \"unique(flow.moduleId,flow.flowId)\": [\"flow\", [\"moduleId\", \"flowId\"]],\n \"unique(flow.stateDigest)\": [\"flow\", [\"stateDigest\"]],\n \"unique(generation.moduleId,generation.deliveryId)\": [\"generation\", [\"moduleId\", \"deliveryId\"]],\n \"unique(generation.moduleId,generation.proofId)\": [\"generation\", [\"moduleId\", \"proofId\"]],\n \"unique(identifier.namespace,identifier.value)\": [\"identifier\", [\"namespace\", \"value\"]],\n \"unique(intent.digest)\": [\"intent\", [\"digest\"]],\n \"unique(intent.flowId)\": [\"intent\", [\"flowId\"]],\n \"unique(intent.moduleId,intent.commandId)\": [\"intent\", [\"moduleId\", \"commandId\"]],\n \"unique(intent.moduleId,intent.flowId)\": [\"intent\", [\"moduleId\", \"flowId\"]],\n \"unique(intent.moduleId,intent.intentId)\": [\"intent\", [\"moduleId\", \"intentId\"]],\n \"unique(intent.moduleId,intent.reference)\": [\"intent\", [\"moduleId\", \"reference\"]],\n \"unique(ownership.identityKey)\": [\"ownership\", [\"identityKey\"]],\n \"unique(pending.digest)\": [\"pending\", [\"digest\"]],\n \"unique(pending.flowId)\": [\"pending\", [\"flowId\"]],\n \"unique(rateScope.moduleId,rateScope.purpose,rateScope.action,rateScope.scopeKind,rateScope.scopeKey)\":\n [\"rateScope\", [\"moduleId\", \"purpose\", \"action\", \"scopeKind\", \"scopeKey\"]],\n \"unique(registration.moduleId,registration.requestId)\": [\n \"registration\",\n [\"moduleId\", \"requestId\"],\n ],\n \"unique(registration.recoveryReference)\": [\"registration\", [\"recoveryReference\"]],\n \"unique(registrationCommand.moduleId,registrationCommand.commandId)\": [\n \"command\",\n [\"moduleId\", \"commandId\"],\n ],\n \"unique(request.moduleId,request.requestId)\": [\"request\", [\"moduleId\", \"requestId\"]],\n \"unique(series.moduleId,series.purpose,series.scopeKey)\": [\n \"series\",\n [\"moduleId\", \"purpose\", \"scopeKey\"],\n ],\n \"unique(session.digest)\": [\"session\", [\"digest\"]],\n \"unique(tombstone.subjectId,tombstone.sessionId)\": [\"tombstone\", [\"subjectId\", \"sessionId\"]],\n \"unique(tuple.identityKey)\": [\"ownership.tuple\", [\"identityKey\"]],\n \"unique(unlinkCommand.moduleId,unlinkCommand.commandId)\": [\"command\", [\"moduleId\", \"commandId\"]],\n};\n\nconst arrayRoles: Readonly<Record<string, string>> = {\n credentialId: \"credential\",\n factor: \"authority\",\n credentialOwnership: \"credentialOwnership\",\n handleOwnership: \"handleOwnership\",\n boundSubjectHandle: \"handleOwnership\",\n flow: \"flow\",\n command: \"flow\",\n admission: \"admission\",\n charge: \"charge\",\n intentFlow: \"intent\",\n intentCommand: \"intent\",\n handle: \"handle\",\n};\n\nconst nestedMappings = [\n \"read\",\n \"signIn\",\n \"password\",\n \"proof\",\n \"proofs\",\n \"revocation\",\n \"pending\",\n \"session\",\n \"source\",\n];\n\nconst constraintGroups = [\n \"constraints\",\n \"tupleConstraints\",\n \"registrationConstraints\",\n \"managementConstraints\",\n];\n\nconst MappingRecord = Schema.Record(Schema.String, Schema.Unknown);\nconst record = Schema.decodeUnknownSync(MappingRecord);\n\nexport const storageKeyPlans = (\n input: unknown,\n columnsFor: (table: object) => Readonly<Record<string, unknown>>,\n) => {\n const mapping = record(input);\n const result: Array<{ readonly table: object; readonly keys: ReadonlyArray<string> }> = [];\n\n for (const group of constraintGroups) {\n if (mapping[group] === undefined) continue;\n for (const [name, declaration] of Object.entries(record(mapping[group]))) {\n if (declaration === \"notNull(provisioningRequest.subjectId)\") continue;\n let role: string;\n let keys: ReadonlyArray<string>;\n\n if (typeof declaration === \"string\") {\n const plan = uniquePlans[declaration];\n\n if (plan !== undefined) [role, keys] = plan;\n else if (declaration === \"unique(id)\") {\n role = \"subject\";\n keys = [\"id\"];\n } else if (declaration === \"unique(scope)\") {\n role = name;\n keys = [\"scope\"];\n } else if (declaration === \"unique(credentialId)\") {\n role = \"credential\";\n keys = [\"id\"];\n } else if (declaration === \"unique(namespace,value)\") {\n role = \"identifier\";\n keys = [\"namespace\", \"value\"];\n } else if (declaration === \"unique(provider,issuer,subject)\") {\n role = \"externalIdentity\";\n keys = [\"provider\", \"issuer\", \"subject\"];\n } else if (declaration === \"unique(requestId)\") {\n role = \"provisioningRequest\";\n keys = [\"requestId\"];\n } else throw new Error(\"Unknown storage constraint\");\n } else if (Array.isArray(declaration) && declaration.every(Predicate.isString)) {\n const mappedRole =\n group === \"managementConstraints\" && name === \"command\" ? \"command\" : arrayRoles[name];\n\n if (mappedRole === undefined) throw new Error(\"Unknown storage constraint\");\n role = mappedRole;\n keys = declaration;\n } else throw new Error(\"Invalid storage constraint\");\n\n let target: unknown = mapping;\n\n for (const segment of role.split(\".\")) target = record(target)[segment];\n // Session authority places its pending tables in one nested mapping.\n if (target === undefined && Schema.is(MappingRecord)(mapping.pending))\n target = mapping.pending[role];\n let mapped = record(target);\n\n if (role === \"pending\" && mapped.table === undefined) mapped = record(mapped.pending);\n // OAuth ownership can be integrated into its tuple authority or separate.\n if (role === \"ownership\" && mapped.table === undefined)\n mapped = record(mapped.external ?? mapped.tuple);\n if (!Predicate.isObject(mapped.table)) throw new Error(\"Missing storage table\");\n const columns = columnsFor(mapped.table);\n\n result.push({\n table: mapped.table,\n keys: keys.map((key) => {\n const value = mapped[key];\n\n if (typeof value !== \"string\" || columns[value] === undefined)\n throw new Error(\"Missing mapped key\");\n\n return value;\n }),\n });\n }\n }\n for (const nested of nestedMappings) {\n const value = mapping[nested];\n\n if (Schema.is(MappingRecord)(value) && value.table === undefined)\n result.push(...storageKeyPlans(value, columnsFor));\n }\n\n return result;\n};\n"],"mappings":";;AAIA,MAAM,cAAkF;CACtF,+GACE,CAAC,cAAc;EAAC;EAAY;EAAU;EAAa;EAAY;CAAW,CAAC;CAC7E,8BAA8B,CAAC,aAAa,CAAC,UAAU,CAAC;CACxD,8CAA8C,CAAC,WAAW,CAAC,YAAY,WAAW,CAAC;CACnF,sDAAsD,CACpD,aACA,CAAC,aAAa,cAAc,CAC9B;CACA,0EAA0E,CACxE,uBACA,CAAC,aAAa,cAAc,CAC9B;CACA,8CAA8C,CAAC,WAAW,CAAC,YAAY,WAAW,CAAC;CACnF,0CAA0C,CAAC,aAAa,CAAC,aAAa,CAAC;CACvE,qCAAqC,CAAC,UAAU,CAAC,WAAW,CAAC;CAC7D,qCAAqC,CAAC,UAAU,CAAC,WAAW,CAAC;CAC7D,gEAAgE,CAC9D,WACA,CAAC,YAAY,WAAW,CAC1B;CACA,0DAA0D,CAAC,QAAQ,CAAC,YAAY,WAAW,CAAC;CAC5F,uDAAuD,CAAC,QAAQ,CAAC,YAAY,QAAQ,CAAC;CACtF,qCAAqC,CAAC,QAAQ,CAAC,aAAa,CAAC;CAC7D,0DAA0D,CAAC,SAAS,CAAC,YAAY,SAAS,CAAC;CAC3F,uHACE,CAAC,SAAS;EAAC;EAAY;EAAa;EAAc;CAAmB,CAAC;CACxE,qCAAqC,CAAC,OAAO,CAAC,OAAO,CAAC;CACtD,6DAA6D,CAC3D,gBACA,CAAC,YAAY,gBAAgB,CAC/B;CACA,qDAAqD,CAAC,gBAAgB,CAAC,YAAY,QAAQ,CAAC;CAC5F,mCAAmC,CAAC,cAAc,CAAC,cAAc,CAAC;CAClE,kCAAkC,CAAC,cAAc,CAAC,aAAa,CAAC;CAChE,uDAAuD,CACrD,cACA,CAAC,YAAY,cAAc,CAC7B;CACA,oDAAoD,CAAC,cAAc,CAAC,YAAY,WAAW,CAAC;CAC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;KACtB,MAAM,QAAQ,OAAO;KAErB,IAAI,OAAO,UAAU,YAAY,QAAQ,WAAW,KAAA,GAClD,MAAM,IAAI,MAAM,oBAAoB;KAEtC,OAAO;IACT,CAAC;GACH,CAAC;EACH;CACF;CACA,KAAK,MAAM,UAAU,gBAAgB;EACnC,MAAM,QAAQ,QAAQ;EAEtB,IAAI,OAAO,GAAG,aAAa,CAAC,CAAC,KAAK,KAAK,MAAM,UAAU,KAAA,GACrD,OAAO,KAAK,GAAG,gBAAgB,OAAO,UAAU,CAAC;CACrD;CAEA,OAAO;AACT"}
@@ -99,62 +99,6 @@ export declare const storageTables: {
99
99
  };
100
100
  unique: readonly (readonly ("credentialId" | "credentialRevision" | "moduleId" | "normalization" | "subjectId" | "verifier" | "verifierVersion")[])[];
101
101
  };
102
- readonly passwordAttempts: {
103
- columns: {
104
- moduleId: {
105
- type: "text";
106
- };
107
- action: {
108
- type: "text";
109
- };
110
- attemptId: {
111
- type: "text";
112
- };
113
- identifierNamespace: {
114
- type: "text";
115
- };
116
- identifierValue: {
117
- type: "text";
118
- };
119
- subjectId: {
120
- type: "text";
121
- nullable: boolean;
122
- };
123
- credentialId: {
124
- type: "text";
125
- nullable: boolean;
126
- };
127
- securityRevision: {
128
- type: "text";
129
- nullable: boolean;
130
- };
131
- credentialRevision: {
132
- type: "text";
133
- nullable: boolean;
134
- };
135
- verifierVersion: {
136
- type: "text";
137
- nullable: boolean;
138
- };
139
- identifierBindingRevision: {
140
- type: "text";
141
- nullable: boolean;
142
- };
143
- admittedAt: {
144
- type: "integer";
145
- };
146
- deadline: {
147
- type: "integer";
148
- };
149
- retentionUntil: {
150
- type: "integer";
151
- };
152
- state: {
153
- type: "text";
154
- };
155
- };
156
- unique: readonly (readonly ("action" | "admittedAt" | "attemptId" | "credentialId" | "credentialRevision" | "deadline" | "identifierBindingRevision" | "identifierNamespace" | "identifierValue" | "moduleId" | "retentionUntil" | "securityRevision" | "state" | "subjectId" | "verifierVersion")[])[];
157
- };
158
102
  readonly passwordCommands: {
159
103
  columns: {
160
104
  moduleId: {
@@ -60,23 +60,6 @@ const storageTables = {
60
60
  verifier: text,
61
61
  normalization: text
62
62
  }, [["moduleId", "subjectId"], ["moduleId", "credentialId"]]),
63
- passwordAttempts: spec({
64
- moduleId: text,
65
- action: text,
66
- attemptId: text,
67
- identifierNamespace: text,
68
- identifierValue: text,
69
- subjectId: optionalText,
70
- credentialId: optionalText,
71
- securityRevision: optionalText,
72
- credentialRevision: optionalText,
73
- verifierVersion: optionalText,
74
- identifierBindingRevision: optionalText,
75
- admittedAt: integer,
76
- deadline: integer,
77
- retentionUntil: integer,
78
- state: text
79
- }, [["moduleId", "attemptId"]]),
80
63
  passwordCommands: spec({
81
64
  moduleId: text,
82
65
  commandId: text,
@@ -1 +1 @@
1
- {"version":3,"file":"storage-tables.mjs","names":[],"sources":["../../src/internal/storage-tables.ts"],"sourcesContent":["import { Schema } from \"effect\";\n\nexport const StorageColumn = Schema.Struct({\n name: Schema.NonEmptyString,\n type: Schema.Literals([\"text\", \"integer\", \"boolean\"]),\n nullable: Schema.optionalKey(Schema.Boolean),\n});\n\nexport const StorageTable = Schema.Struct({\n name: Schema.NonEmptyString,\n schema: Schema.optionalKey(Schema.NonEmptyString),\n columns: Schema.Record(Schema.String, StorageColumn),\n unique: Schema.Array(Schema.Array(Schema.String)),\n});\n\nexport type StorageTable = typeof StorageTable.Type;\n\nconst text = { type: \"text\" as const };\nconst integer = { type: \"integer\" as const };\nconst boolean = { type: \"boolean\" as const };\nconst optionalText = { ...text, nullable: true };\nconst optionalInteger = { ...integer, nullable: true };\n\nconst spec = <C extends Readonly<Record<string, Omit<typeof StorageColumn.Type, \"name\">>>>(\n columns: C,\n unique: ReadonlyArray<ReadonlyArray<Extract<keyof C, string>>>,\n) => ({ columns, unique });\n\n/** Logical roles are independent of table names and migration ownership. */\nexport const storageTables = {\n subjects: spec({ id: text, active: boolean, securityRevision: text }, [[\"id\"]]),\n identifiers: spec(\n {\n namespace: text,\n value: text,\n subjectId: text,\n revision: text,\n verifiedAt: optionalInteger,\n active: boolean,\n },\n [[\"namespace\", \"value\"]],\n ),\n credentials: spec({ credentialId: text, subjectId: text, revision: text, active: boolean }, [\n [\"credentialId\"],\n ]),\n passwords: spec(\n {\n moduleId: text,\n subjectId: text,\n credentialId: text,\n credentialRevision: text,\n verifierVersion: text,\n verifier: text,\n normalization: text,\n },\n [\n [\"moduleId\", \"subjectId\"],\n [\"moduleId\", \"credentialId\"],\n ],\n ),\n passwordAttempts: spec(\n {\n moduleId: text,\n action: text,\n attemptId: text,\n identifierNamespace: text,\n identifierValue: text,\n subjectId: optionalText,\n credentialId: optionalText,\n securityRevision: optionalText,\n credentialRevision: optionalText,\n verifierVersion: optionalText,\n identifierBindingRevision: optionalText,\n admittedAt: integer,\n deadline: integer,\n retentionUntil: integer,\n state: text,\n },\n [[\"moduleId\", \"attemptId\"]],\n ),\n passwordCommands: spec(\n {\n moduleId: text,\n commandId: text,\n action: text,\n bindingDigest: text,\n decision: text,\n retentionUntil: integer,\n },\n [[\"moduleId\", \"commandId\"]],\n ),\n passwordRegistrations: spec({ moduleId: text, requestId: text }, [[\"moduleId\", \"requestId\"]]),\n emailCredentials: spec(\n {\n moduleId: text,\n subjectId: text,\n credentialId: text,\n identifierNamespace: text,\n identifierValue: text,\n credentialRevision: text,\n active: boolean,\n },\n [\n [\"moduleId\", \"credentialId\"],\n [\"moduleId\", \"identifierNamespace\", \"identifierValue\"],\n ],\n ),\n emailCommands: spec(\n { moduleId: text, commandId: text, action: text, bindingDigest: text, retentionUntil: integer },\n [[\"moduleId\", \"commandId\"]],\n ),\n phoneState: spec({ scope: text, state: text, version: text }, [[\"scope\"]]),\n passkeyCredentials: spec(\n {\n credentialId: text,\n subjectId: text,\n rpId: text,\n protocolCredentialId: text,\n credentialKey: text,\n handleKey: text,\n userHandle: text,\n publicKey: text,\n algorithm: integer,\n profile: text,\n credentialRevision: text,\n active: boolean,\n primarySignIn: boolean,\n enrollmentUserVerified: boolean,\n backupEligible: boolean,\n backupState: boolean,\n counter: integer,\n maximumCounter: integer,\n name: text,\n createdAt: integer,\n lastUsedAt: optionalInteger,\n },\n [[\"credentialId\"], [\"credentialKey\"]],\n ),\n passkeyOwnership: spec(\n {\n credentialKey: text,\n rpId: text,\n protocolCredentialId: text,\n subjectId: optionalText,\n credentialId: optionalText,\n state: text,\n version: text,\n reservationId: optionalText,\n },\n [[\"credentialKey\"]],\n ),\n passkeyHandles: spec(\n {\n handleKey: text,\n rpId: text,\n userHandle: text,\n subjectId: optionalText,\n state: text,\n version: text,\n reservationId: optionalText,\n },\n [[\"handleKey\"], [\"rpId\", \"subjectId\"]],\n ),\n passkeyModules: spec(\n {\n moduleId: text,\n active: boolean,\n policyRevision: text,\n policy: text,\n },\n [[\"moduleId\"]],\n ),\n passkeyFlows: spec(\n {\n moduleId: text,\n flowId: text,\n commandId: text,\n purpose: text,\n state: text,\n version: text,\n generation: integer,\n snapshot: text,\n policySnapshot: text,\n requestBindingVerifier: text,\n requestBindingExpiresAt: integer,\n issuedAt: integer,\n expiresAt: integer,\n retentionUntil: integer,\n claimId: optionalText,\n claimedAt: optionalInteger,\n claimExpiresAt: optionalInteger,\n credentialSnapshot: optionalText,\n subjectScope: optionalText,\n targetScope: optionalText,\n },\n [\n [\"moduleId\", \"flowId\"],\n [\"moduleId\", \"commandId\"],\n ],\n ),\n passkeyAdmissions: spec(\n {\n authorityScope: text,\n moduleId: text,\n version: text,\n ownerMarker: text,\n admittedAt: optionalInteger,\n },\n [[\"authorityScope\", \"moduleId\"]],\n ),\n passkeyCharges: spec(\n {\n moduleId: text,\n flowId: text,\n purpose: text,\n kind: text,\n scope: text,\n originalWindowMillis: integer,\n admittedAt: optionalInteger,\n retainUntil: optionalInteger,\n version: text,\n ownerMarker: text,\n },\n [[\"moduleId\", \"flowId\", \"kind\"]],\n ),\n passkeyCommands: spec(\n {\n moduleId: text,\n commandId: text,\n subjectId: text,\n credentialId: text,\n intent: text,\n decision: text,\n retentionUntil: integer,\n version: text,\n },\n [[\"moduleId\", \"commandId\"]],\n ),\n proofRequests: spec(\n {\n moduleId: text,\n requestId: text,\n fingerprint: text,\n proofId: text,\n purpose: text,\n keyId: text,\n createdAt: integer,\n retentionUntil: integer,\n receipt: text,\n },\n [[\"moduleId\", \"requestId\"]],\n ),\n proofSeries: spec(\n {\n moduleId: text,\n purpose: text,\n scopeKey: text,\n activeProofId: optionalText,\n lastIssueAt: optionalInteger,\n version: text,\n },\n [[\"moduleId\", \"purpose\", \"scopeKey\"]],\n ),\n proofGenerations: spec(\n {\n moduleId: text,\n purpose: text,\n proofId: text,\n requestId: text,\n seriesKey: text,\n deliveryId: text,\n binding: text,\n verifierKeyId: text,\n verifierDigest: text,\n issuedAt: integer,\n expiresAt: integer,\n version: text,\n state: text,\n sendCount: integer,\n deliveryState: text,\n claimVersion: optionalText,\n claimDeadline: optionalInteger,\n retryAt: optionalInteger,\n deliveryRetryMillis: integer,\n retentionUntil: integer,\n fingerprint: text,\n },\n [\n [\"moduleId\", \"proofId\"],\n [\"moduleId\", \"deliveryId\"],\n ],\n ),\n proofContinuations: spec(\n {\n moduleId: text,\n purpose: text,\n continuationId: text,\n digest: text,\n proofId: text,\n seriesKey: text,\n binding: text,\n expiresAt: integer,\n consumed: boolean,\n version: text,\n retentionUntil: integer,\n },\n [\n [\"moduleId\", \"continuationId\"],\n [\"moduleId\", \"digest\"],\n ],\n ),\n proofScopes: spec(\n { moduleId: text, purpose: text, action: text, scopeKind: text, scopeKey: text },\n [[\"moduleId\", \"purpose\", \"action\", \"scopeKind\", \"scopeKey\"]],\n ),\n proofAbuse: spec(\n {\n moduleId: text,\n purpose: text,\n action: text,\n scopeKind: text,\n scopeKey: text,\n commandId: text,\n occurredAt: integer,\n retentionUntil: integer,\n },\n [[\"moduleId\", \"action\", \"scopeKind\", \"scopeKey\", \"commandId\"]],\n ),\n proofFailures: spec(\n {\n moduleId: text,\n purpose: text,\n seriesKey: text,\n commandId: text,\n occurredAt: integer,\n retentionUntil: integer,\n },\n [[\"moduleId\", \"seriesKey\", \"commandId\"]],\n ),\n proofCommands: spec(\n { moduleId: text, commandId: text, kind: text, decision: text, retentionUntil: integer },\n [[\"moduleId\", \"commandId\"]],\n ),\n sessions: spec(\n {\n sessionId: text,\n subjectId: text,\n digest: text,\n version: text,\n securityRevision: text,\n issuedAt: integer,\n expiresAt: integer,\n absoluteExpiresAt: integer,\n record: text,\n },\n [[\"sessionId\"], [\"digest\"]],\n ),\n sessionFlows: spec(\n {\n flowId: text,\n subjectId: text,\n state: text,\n pendingDigest: optionalText,\n dedupUntil: integer,\n },\n [[\"flowId\"]],\n ),\n} as const;\n\nexport type StorageRole = keyof typeof storageTables;\n\nexport const tableDefinition = (\n role: StorageRole,\n name: string,\n subjectType: \"text\" | \"integer\" = \"text\",\n): StorageTable => {\n const table = storageTables[role];\n\n return {\n name,\n columns: Object.fromEntries(\n Object.entries(table.columns).map(([key, column]) => [\n key,\n {\n ...column,\n name: key.replace(/[A-Z]/g, (letter) => \"_\" + letter.toLowerCase()),\n ...(key === \"subjectId\" ? { type: subjectType } : {}),\n },\n ]),\n ),\n unique: table.unique,\n };\n};\n"],"mappings":";;AAEA,MAAa,gBAAgB,OAAO,OAAO;CACzC,MAAM,OAAO;CACb,MAAM,OAAO,SAAS;EAAC;EAAQ;EAAW;CAAS,CAAC;CACpD,UAAU,OAAO,YAAY,OAAO,OAAO;AAC7C,CAAC;AAED,MAAa,eAAe,OAAO,OAAO;CACxC,MAAM,OAAO;CACb,QAAQ,OAAO,YAAY,OAAO,cAAc;CAChD,SAAS,OAAO,OAAO,OAAO,QAAQ,aAAa;CACnD,QAAQ,OAAO,MAAM,OAAO,MAAM,OAAO,MAAM,CAAC;AAClD,CAAC;AAID,MAAM,OAAO,EAAE,MAAM,OAAgB;AACrC,MAAM,UAAU,EAAE,MAAM,UAAmB;AAC3C,MAAM,UAAU,EAAE,MAAM,UAAmB;AAC3C,MAAM,eAAe;CAAE,GAAG;CAAM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M,OAAO,CAAC,CAAC,KAAK,CAAC,KAAK,YAAY,CACnD,KACA;GACE,GAAG;GACH,MAAM,IAAI,QAAQ,WAAW,WAAW,MAAM,OAAO,YAAY,CAAC;GAClE,GAAI,QAAQ,cAAc,EAAE,MAAM,YAAY,IAAI,CAAC;EACrD,CACF,CAAC,CACH;EACA,QAAQ,MAAM;CAChB;AACF"}
1
+ {"version":3,"file":"storage-tables.mjs","names":[],"sources":["../../src/internal/storage-tables.ts"],"sourcesContent":["import { Schema } from \"effect\";\n\nexport const StorageColumn = Schema.Struct({\n name: Schema.NonEmptyString,\n type: Schema.Literals([\"text\", \"integer\", \"boolean\"]),\n nullable: Schema.optionalKey(Schema.Boolean),\n});\n\nexport const StorageTable = Schema.Struct({\n name: Schema.NonEmptyString,\n schema: Schema.optionalKey(Schema.NonEmptyString),\n columns: Schema.Record(Schema.String, StorageColumn),\n unique: Schema.Array(Schema.Array(Schema.String)),\n});\n\nexport type StorageTable = typeof StorageTable.Type;\n\nconst text = { type: \"text\" as const };\nconst integer = { type: \"integer\" as const };\nconst boolean = { type: \"boolean\" as const };\nconst optionalText = { ...text, nullable: true };\nconst optionalInteger = { ...integer, nullable: true };\n\nconst spec = <C extends Readonly<Record<string, Omit<typeof StorageColumn.Type, \"name\">>>>(\n columns: C,\n unique: ReadonlyArray<ReadonlyArray<Extract<keyof C, string>>>,\n) => ({ columns, unique });\n\n/** Logical roles are independent of table names and migration ownership. */\nexport const storageTables = {\n subjects: spec({ id: text, active: boolean, securityRevision: text }, [[\"id\"]]),\n identifiers: spec(\n {\n namespace: text,\n value: text,\n subjectId: text,\n revision: text,\n verifiedAt: optionalInteger,\n active: boolean,\n },\n [[\"namespace\", \"value\"]],\n ),\n credentials: spec({ credentialId: text, subjectId: text, revision: text, active: boolean }, [\n [\"credentialId\"],\n ]),\n passwords: spec(\n {\n moduleId: text,\n subjectId: text,\n credentialId: text,\n credentialRevision: text,\n verifierVersion: text,\n verifier: text,\n normalization: text,\n },\n [\n [\"moduleId\", \"subjectId\"],\n [\"moduleId\", \"credentialId\"],\n ],\n ),\n passwordCommands: spec(\n {\n moduleId: text,\n commandId: text,\n action: text,\n bindingDigest: text,\n decision: text,\n retentionUntil: integer,\n },\n [[\"moduleId\", \"commandId\"]],\n ),\n passwordRegistrations: spec({ moduleId: text, requestId: text }, [[\"moduleId\", \"requestId\"]]),\n emailCredentials: spec(\n {\n moduleId: text,\n subjectId: text,\n credentialId: text,\n identifierNamespace: text,\n identifierValue: text,\n credentialRevision: text,\n active: boolean,\n },\n [\n [\"moduleId\", \"credentialId\"],\n [\"moduleId\", \"identifierNamespace\", \"identifierValue\"],\n ],\n ),\n emailCommands: spec(\n { moduleId: text, commandId: text, action: text, bindingDigest: text, retentionUntil: integer },\n [[\"moduleId\", \"commandId\"]],\n ),\n phoneState: spec({ scope: text, state: text, version: text }, [[\"scope\"]]),\n passkeyCredentials: spec(\n {\n credentialId: text,\n subjectId: text,\n rpId: text,\n protocolCredentialId: text,\n credentialKey: text,\n handleKey: text,\n userHandle: text,\n publicKey: text,\n algorithm: integer,\n profile: text,\n credentialRevision: text,\n active: boolean,\n primarySignIn: boolean,\n enrollmentUserVerified: boolean,\n backupEligible: boolean,\n backupState: boolean,\n counter: integer,\n maximumCounter: integer,\n name: text,\n createdAt: integer,\n lastUsedAt: optionalInteger,\n },\n [[\"credentialId\"], [\"credentialKey\"]],\n ),\n passkeyOwnership: spec(\n {\n credentialKey: text,\n rpId: text,\n protocolCredentialId: text,\n subjectId: optionalText,\n credentialId: optionalText,\n state: text,\n version: text,\n reservationId: optionalText,\n },\n [[\"credentialKey\"]],\n ),\n passkeyHandles: spec(\n {\n handleKey: text,\n rpId: text,\n userHandle: text,\n subjectId: optionalText,\n state: text,\n version: text,\n reservationId: optionalText,\n },\n [[\"handleKey\"], [\"rpId\", \"subjectId\"]],\n ),\n passkeyModules: spec(\n {\n moduleId: text,\n active: boolean,\n policyRevision: text,\n policy: text,\n },\n [[\"moduleId\"]],\n ),\n passkeyFlows: spec(\n {\n moduleId: text,\n flowId: text,\n commandId: text,\n purpose: text,\n state: text,\n version: text,\n generation: integer,\n snapshot: text,\n policySnapshot: text,\n requestBindingVerifier: text,\n requestBindingExpiresAt: integer,\n issuedAt: integer,\n expiresAt: integer,\n retentionUntil: integer,\n claimId: optionalText,\n claimedAt: optionalInteger,\n claimExpiresAt: optionalInteger,\n credentialSnapshot: optionalText,\n subjectScope: optionalText,\n targetScope: optionalText,\n },\n [\n [\"moduleId\", \"flowId\"],\n [\"moduleId\", \"commandId\"],\n ],\n ),\n passkeyAdmissions: spec(\n {\n authorityScope: text,\n moduleId: text,\n version: text,\n ownerMarker: text,\n admittedAt: optionalInteger,\n },\n [[\"authorityScope\", \"moduleId\"]],\n ),\n passkeyCharges: spec(\n {\n moduleId: text,\n flowId: text,\n purpose: text,\n kind: text,\n scope: text,\n originalWindowMillis: integer,\n admittedAt: optionalInteger,\n retainUntil: optionalInteger,\n version: text,\n ownerMarker: text,\n },\n [[\"moduleId\", \"flowId\", \"kind\"]],\n ),\n passkeyCommands: spec(\n {\n moduleId: text,\n commandId: text,\n subjectId: text,\n credentialId: text,\n intent: text,\n decision: text,\n retentionUntil: integer,\n version: text,\n },\n [[\"moduleId\", \"commandId\"]],\n ),\n proofRequests: spec(\n {\n moduleId: text,\n requestId: text,\n fingerprint: text,\n proofId: text,\n purpose: text,\n keyId: text,\n createdAt: integer,\n retentionUntil: integer,\n receipt: text,\n },\n [[\"moduleId\", \"requestId\"]],\n ),\n proofSeries: spec(\n {\n moduleId: text,\n purpose: text,\n scopeKey: text,\n activeProofId: optionalText,\n lastIssueAt: optionalInteger,\n version: text,\n },\n [[\"moduleId\", \"purpose\", \"scopeKey\"]],\n ),\n proofGenerations: spec(\n {\n moduleId: text,\n purpose: text,\n proofId: text,\n requestId: text,\n seriesKey: text,\n deliveryId: text,\n binding: text,\n verifierKeyId: text,\n verifierDigest: text,\n issuedAt: integer,\n expiresAt: integer,\n version: text,\n state: text,\n sendCount: integer,\n deliveryState: text,\n claimVersion: optionalText,\n claimDeadline: optionalInteger,\n retryAt: optionalInteger,\n deliveryRetryMillis: integer,\n retentionUntil: integer,\n fingerprint: text,\n },\n [\n [\"moduleId\", \"proofId\"],\n [\"moduleId\", \"deliveryId\"],\n ],\n ),\n proofContinuations: spec(\n {\n moduleId: text,\n purpose: text,\n continuationId: text,\n digest: text,\n proofId: text,\n seriesKey: text,\n binding: text,\n expiresAt: integer,\n consumed: boolean,\n version: text,\n retentionUntil: integer,\n },\n [\n [\"moduleId\", \"continuationId\"],\n [\"moduleId\", \"digest\"],\n ],\n ),\n proofScopes: spec(\n { moduleId: text, purpose: text, action: text, scopeKind: text, scopeKey: text },\n [[\"moduleId\", \"purpose\", \"action\", \"scopeKind\", \"scopeKey\"]],\n ),\n proofAbuse: spec(\n {\n moduleId: text,\n purpose: text,\n action: text,\n scopeKind: text,\n scopeKey: text,\n commandId: text,\n occurredAt: integer,\n retentionUntil: integer,\n },\n [[\"moduleId\", \"action\", \"scopeKind\", \"scopeKey\", \"commandId\"]],\n ),\n proofFailures: spec(\n {\n moduleId: text,\n purpose: text,\n seriesKey: text,\n commandId: text,\n occurredAt: integer,\n retentionUntil: integer,\n },\n [[\"moduleId\", \"seriesKey\", \"commandId\"]],\n ),\n proofCommands: spec(\n { moduleId: text, commandId: text, kind: text, decision: text, retentionUntil: integer },\n [[\"moduleId\", \"commandId\"]],\n ),\n sessions: spec(\n {\n sessionId: text,\n subjectId: text,\n digest: text,\n version: text,\n securityRevision: text,\n issuedAt: integer,\n expiresAt: integer,\n absoluteExpiresAt: integer,\n record: text,\n },\n [[\"sessionId\"], [\"digest\"]],\n ),\n sessionFlows: spec(\n {\n flowId: text,\n subjectId: text,\n state: text,\n pendingDigest: optionalText,\n dedupUntil: integer,\n },\n [[\"flowId\"]],\n ),\n} as const;\n\nexport type StorageRole = keyof typeof storageTables;\n\nexport const tableDefinition = (\n role: StorageRole,\n name: string,\n subjectType: \"text\" | \"integer\" = \"text\",\n): StorageTable => {\n const table = storageTables[role];\n\n return {\n name,\n columns: Object.fromEntries(\n Object.entries(table.columns).map(([key, column]) => [\n key,\n {\n ...column,\n name: key.replace(/[A-Z]/g, (letter) => \"_\" + letter.toLowerCase()),\n ...(key === \"subjectId\" ? { type: subjectType } : {}),\n },\n ]),\n ),\n unique: table.unique,\n };\n};\n"],"mappings":";;AAEA,MAAa,gBAAgB,OAAO,OAAO;CACzC,MAAM,OAAO;CACb,MAAM,OAAO,SAAS;EAAC;EAAQ;EAAW;CAAS,CAAC;CACpD,UAAU,OAAO,YAAY,OAAO,OAAO;AAC7C,CAAC;AAED,MAAa,eAAe,OAAO,OAAO;CACxC,MAAM,OAAO;CACb,QAAQ,OAAO,YAAY,OAAO,cAAc;CAChD,SAAS,OAAO,OAAO,OAAO,QAAQ,aAAa;CACnD,QAAQ,OAAO,MAAM,OAAO,MAAM,OAAO,MAAM,CAAC;AAClD,CAAC;AAID,MAAM,OAAO,EAAE,MAAM,OAAgB;AACrC,MAAM,UAAU,EAAE,MAAM,UAAmB;AAC3C,MAAM,UAAU,EAAE,MAAM,UAAmB;AAC3C,MAAM,eAAe;CAAE,GAAG;CAAM,UAAU;AAAK;AAC/C,MAAM,kBAAkB;CAAE,GAAG;CAAS,UAAU;AAAK;AAErD,MAAM,QACJ,SACA,YACI;CAAE;CAAS;AAAO;;AAGxB,MAAa,gBAAgB;CAC3B,UAAU,KAAK;EAAE,IAAI;EAAM,QAAQ;EAAS,kBAAkB;CAAK,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;CAC9E,aAAa,KACX;EACE,WAAW;EACX,OAAO;EACP,WAAW;EACX,UAAU;EACV,YAAY;EACZ,QAAQ;CACV,GACA,CAAC,CAAC,aAAa,OAAO,CAAC,CACzB;CACA,aAAa,KAAK;EAAE,cAAc;EAAM,WAAW;EAAM,UAAU;EAAM,QAAQ;CAAQ,GAAG,CAC1F,CAAC,cAAc,CACjB,CAAC;CACD,WAAW,KACT;EACE,UAAU;EACV,W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GACvF,CAAC,CAAC,YAAY,WAAW,CAAC,CAC5B;CACA,UAAU,KACR;EACE,WAAW;EACX,WAAW;EACX,QAAQ;EACR,SAAS;EACT,kBAAkB;EAClB,UAAU;EACV,WAAW;EACX,mBAAmB;EACnB,QAAQ;CACV,GACA,CAAC,CAAC,WAAW,GAAG,CAAC,QAAQ,CAAC,CAC5B;CACA,cAAc,KACZ;EACE,QAAQ;EACR,WAAW;EACX,OAAO;EACP,eAAe;EACf,YAAY;CACd,GACA,CAAC,CAAC,QAAQ,CAAC,CACb;AACF;AAIA,MAAa,mBACX,MACA,MACA,cAAkC,WACjB;CACjB,MAAM,QAAQ,cAAc;CAE5B,OAAO;EACL;EACA,SAAS,OAAO,YACd,OAAO,QAAQ,MAAM,OAAO,CAAC,CAAC,KAAK,CAAC,KAAK,YAAY,CACnD,KACA;GACE,GAAG;GACH,MAAM,IAAI,QAAQ,WAAW,WAAW,MAAM,OAAO,YAAY,CAAC;GAClE,GAAI,QAAQ,cAAc,EAAE,MAAM,YAAY,IAAI,CAAC;EACrD,CACF,CAAC,CACH;EACA,QAAQ,MAAM;CAChB;AACF"}
@@ -1,6 +1,7 @@
1
+ import "./transaction-kernel.mjs";
1
2
  import "./storage-tables.mjs";
2
3
  import { PersistenceConfigurationError } from "./configuration.mjs";
3
- import { Effect } from "effect";
4
+ import { Effect, Schema } from "effect";
4
5
  import { SqlClient } from "effect/sql/SqlClient";
5
6
  //#region src/internal/storage-validation.d.ts
6
7
  /** Physical metadata needed for catalog validation; value codecs remain adapter-owned. */
@@ -11,6 +12,10 @@ export interface PhysicalStorageTable {
11
12
  readonly name: string;
12
13
  }>>;
13
14
  }
15
+ export interface PhysicalTextColumn {
16
+ readonly table: Pick<PhysicalStorageTable, "name" | "schema">;
17
+ readonly name: string;
18
+ }
14
19
  /** Share metadata only while constructing one service graph. Captured contexts
15
20
  * cannot reuse it after acquisition succeeds, fails, or is interrupted. */
16
21
  export declare const withStorageValidation: <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;