@yielded/auth-persistence-drizzle 0.1.0-beta.23 → 0.1.0-beta.24

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 (185) hide show
  1. package/README.md +3 -0
  2. package/dist/D1.d.mts +9 -9
  3. package/dist/D1.mjs +2 -1
  4. package/dist/D1.mjs.map +1 -1
  5. package/dist/Libsql.d.mts +46 -62
  6. package/dist/Libsql.mjs +2 -1
  7. package/dist/Libsql.mjs.map +1 -1
  8. package/dist/Mysql2.d.mts +24 -25
  9. package/dist/Pglite.d.mts +26 -26
  10. package/dist/Pglite.mjs +2 -1
  11. package/dist/Pglite.mjs.map +1 -1
  12. package/dist/Postgres.d.mts +27 -27
  13. package/dist/Postgres.mjs +2 -1
  14. package/dist/Postgres.mjs.map +1 -1
  15. package/dist/SqliteBun.d.mts +47 -63
  16. package/dist/SqliteBun.mjs +2 -1
  17. package/dist/SqliteBun.mjs.map +1 -1
  18. package/dist/SqliteDo.d.mts +45 -61
  19. package/dist/SqliteDo.mjs +2 -1
  20. package/dist/SqliteDo.mjs.map +1 -1
  21. package/dist/SqliteNode.d.mts +49 -65
  22. package/dist/SqliteNode.mjs +2 -1
  23. package/dist/SqliteNode.mjs.map +1 -1
  24. package/dist/SqliteWasm.d.mts +45 -61
  25. package/dist/SqliteWasm.mjs +2 -1
  26. package/dist/SqliteWasm.mjs.map +1 -1
  27. package/dist/drizzle/crypto.mjs +1 -1
  28. package/dist/drizzle/d1-emails.d.mts +1 -1
  29. package/dist/drizzle/d1-oauth.d.mts +13 -13
  30. package/dist/drizzle/d1-passkey.d.mts +1 -1
  31. package/dist/drizzle/d1-password-prepared.d.mts +4 -4
  32. package/dist/drizzle/d1-password-prepared.mjs.map +1 -1
  33. package/dist/drizzle/d1-passwords.d.mts +17 -33
  34. package/dist/drizzle/d1-passwords.mjs +56 -198
  35. package/dist/drizzle/d1-passwords.mjs.map +1 -1
  36. package/dist/drizzle/d1-phone.d.mts +1 -1
  37. package/dist/drizzle/d1-proofs.d.mts +1 -1
  38. package/dist/drizzle/d1-sessions.d.mts +2 -2
  39. package/dist/drizzle/d1-sessions.mjs +11 -6
  40. package/dist/drizzle/d1-sessions.mjs.map +1 -1
  41. package/dist/drizzle/d1-totp.d.mts +1 -1
  42. package/dist/drizzle/mysql-password-prepared.d.mts +5 -5
  43. package/dist/drizzle/mysql-password-prepared.mjs.map +1 -1
  44. package/dist/drizzle/mysql-passwords.d.mts +16 -32
  45. package/dist/drizzle/mysql-passwords.mjs.map +1 -1
  46. package/dist/drizzle/mysql-sessions.d.mts +1 -1
  47. package/dist/drizzle/native-sql-table.mjs +26 -1
  48. package/dist/drizzle/native-sql-table.mjs.map +1 -1
  49. package/dist/drizzle/oauth-connected-model.d.mts +20 -281
  50. package/dist/drizzle/oauth-connected-model.mjs +3 -17
  51. package/dist/drizzle/oauth-connected-model.mjs.map +1 -1
  52. package/dist/drizzle/oauth-connected-reference.d.mts +1 -3
  53. package/dist/drizzle/oauth-connected-reference.mjs +4 -53
  54. package/dist/drizzle/oauth-connected-reference.mjs.map +1 -1
  55. package/dist/drizzle/oauth-connected-target.d.mts +3 -990
  56. package/dist/drizzle/oauth-connected-target.mjs +8 -92
  57. package/dist/drizzle/oauth-connected-target.mjs.map +1 -1
  58. package/dist/drizzle/oauth-kernel.mjs +11 -0
  59. package/dist/drizzle/oauth-kernel.mjs.map +1 -0
  60. package/dist/drizzle/oauth-model.d.mts +35 -438
  61. package/dist/drizzle/oauth-model.mjs +6 -44
  62. package/dist/drizzle/oauth-model.mjs.map +1 -1
  63. package/dist/drizzle/oauth-mysql.mjs +2 -2
  64. package/dist/drizzle/oauth-mysql.mjs.map +1 -1
  65. package/dist/drizzle/oauth-proxy.d.mts +10 -0
  66. package/dist/drizzle/oauth-proxy.mjs +54 -0
  67. package/dist/drizzle/oauth-proxy.mjs.map +1 -0
  68. package/dist/drizzle/oauth-target.d.mts +6 -107
  69. package/dist/drizzle/oauth-target.mjs +15 -245
  70. package/dist/drizzle/oauth-target.mjs.map +1 -1
  71. package/dist/drizzle/password-model.d.mts +5 -6
  72. package/dist/drizzle/password-prepared-model.d.mts +5 -5
  73. package/dist/drizzle/password-prepared-model.mjs.map +1 -1
  74. package/dist/drizzle/password-prepared-state.mjs +1 -1
  75. package/dist/drizzle/pg-password-prepared.d.mts +5 -5
  76. package/dist/drizzle/pg-password-prepared.mjs.map +1 -1
  77. package/dist/drizzle/pg-passwords.d.mts +16 -32
  78. package/dist/drizzle/pg-passwords.mjs.map +1 -1
  79. package/dist/drizzle/pg-sessions.d.mts +1 -1
  80. package/dist/drizzle/phone-target.d.mts +1 -1
  81. package/dist/drizzle/phone-target.mjs +1 -1
  82. package/dist/drizzle/query-operations.mjs +3 -1
  83. package/dist/drizzle/query-operations.mjs.map +1 -1
  84. package/dist/drizzle/sqlite-password-prepared.mjs.map +1 -1
  85. package/dist/drizzle/sqlite-passwords.mjs.map +1 -1
  86. package/dist/drizzle/storage-validation.mjs +10 -185
  87. package/dist/drizzle/storage-validation.mjs.map +1 -1
  88. package/dist/drizzle/totp-target.d.mts +2 -2
  89. package/dist/drizzle/totp-target.mjs +2 -2
  90. package/dist/drizzle/transaction-execution.d.mts +2 -2
  91. package/dist/drizzle/transaction-owner.d.mts +1 -2
  92. package/dist/index.d.mts +3 -2
  93. package/dist/internal/drizzle-postgres-oauth-proxy.d.mts +138 -0
  94. package/dist/internal/drizzle-postgres-oauth-proxy.mjs +29 -0
  95. package/dist/internal/drizzle-postgres-oauth-proxy.mjs.map +1 -0
  96. package/dist/internal/drizzle-sqlite-oauth-proxy.d.mts +146 -0
  97. package/dist/internal/drizzle-sqlite-oauth-proxy.mjs +29 -0
  98. package/dist/internal/drizzle-sqlite-oauth-proxy.mjs.map +1 -0
  99. package/package.json +1 -1
  100. package/src/D1.ts +2 -0
  101. package/src/Libsql.ts +2 -0
  102. package/src/Pglite.ts +2 -0
  103. package/src/Postgres.ts +2 -0
  104. package/src/SqliteBun.ts +2 -0
  105. package/src/SqliteDo.ts +2 -0
  106. package/src/SqliteNode.ts +2 -0
  107. package/src/SqliteWasm.ts +2 -0
  108. package/src/drizzle/d1-password-prepared.ts +2 -5
  109. package/src/drizzle/d1-passwords.ts +123 -458
  110. package/src/drizzle/d1-sessions.ts +21 -6
  111. package/src/drizzle/mysql-password-prepared.ts +4 -8
  112. package/src/drizzle/mysql-passwords.ts +5 -10
  113. package/src/drizzle/native-sql-table.ts +30 -0
  114. package/src/drizzle/oauth-connected-model.ts +97 -315
  115. package/src/drizzle/oauth-connected-reference.ts +13 -93
  116. package/src/drizzle/oauth-connected-target.ts +14 -271
  117. package/src/drizzle/oauth-kernel.ts +10 -0
  118. package/src/drizzle/oauth-model.ts +188 -541
  119. package/src/drizzle/oauth-mysql.ts +2 -2
  120. package/src/drizzle/oauth-proxy.ts +101 -0
  121. package/src/drizzle/oauth-target.ts +33 -737
  122. package/src/drizzle/password-model.ts +0 -13
  123. package/src/drizzle/password-prepared-model.ts +0 -6
  124. package/src/drizzle/pg-password-prepared.ts +4 -8
  125. package/src/drizzle/pg-passwords.ts +5 -10
  126. package/src/drizzle/query-operations.ts +4 -0
  127. package/src/drizzle/sqlite-password-prepared.ts +4 -8
  128. package/src/drizzle/sqlite-passwords.ts +7 -14
  129. package/src/drizzle/storage-validation.ts +13 -214
  130. package/src/index.ts +2 -4
  131. package/src/internal/drizzle-postgres-oauth-proxy.ts +37 -0
  132. package/src/internal/drizzle-sqlite-oauth-proxy.ts +44 -0
  133. package/dist/_virtual/_rolldown/runtime.mjs +0 -13
  134. package/dist/drizzle/oauth-accounts.mjs +0 -359
  135. package/dist/drizzle/oauth-accounts.mjs.map +0 -1
  136. package/dist/drizzle/oauth-connected-access.mjs +0 -212
  137. package/dist/drizzle/oauth-connected-access.mjs.map +0 -1
  138. package/dist/drizzle/oauth-connected-collection.mjs +0 -202
  139. package/dist/drizzle/oauth-connected-collection.mjs.map +0 -1
  140. package/dist/drizzle/oauth-connected-custody.mjs +0 -147
  141. package/dist/drizzle/oauth-connected-custody.mjs.map +0 -1
  142. package/dist/drizzle/oauth-connected-flow.mjs +0 -297
  143. package/dist/drizzle/oauth-connected-flow.mjs.map +0 -1
  144. package/dist/drizzle/oauth-connected-input.mjs +0 -122
  145. package/dist/drizzle/oauth-connected-input.mjs.map +0 -1
  146. package/dist/drizzle/oauth-connected-maintenance.mjs +0 -214
  147. package/dist/drizzle/oauth-connected-maintenance.mjs.map +0 -1
  148. package/dist/drizzle/oauth-connected-management.mjs +0 -229
  149. package/dist/drizzle/oauth-connected-management.mjs.map +0 -1
  150. package/dist/drizzle/oauth-connected-settlement.mjs +0 -128
  151. package/dist/drizzle/oauth-connected-settlement.mjs.map +0 -1
  152. package/dist/drizzle/oauth-connected-sign-in.mjs +0 -265
  153. package/dist/drizzle/oauth-connected-sign-in.mjs.map +0 -1
  154. package/dist/drizzle/oauth-connected-state.d.mts +0 -2062
  155. package/dist/drizzle/oauth-connected-state.mjs +0 -430
  156. package/dist/drizzle/oauth-connected-state.mjs.map +0 -1
  157. package/dist/drizzle/oauth-flow.d.mts +0 -22
  158. package/dist/drizzle/oauth-flow.mjs +0 -253
  159. package/dist/drizzle/oauth-flow.mjs.map +0 -1
  160. package/dist/drizzle/oauth-input.mjs +0 -127
  161. package/dist/drizzle/oauth-input.mjs.map +0 -1
  162. package/dist/drizzle/oauth-owner.d.mts +0 -10
  163. package/dist/drizzle/oauth-owner.mjs +0 -10
  164. package/dist/drizzle/oauth-owner.mjs.map +0 -1
  165. package/dist/drizzle/oauth-registration.d.mts +0 -5
  166. package/dist/drizzle/oauth-registration.mjs +0 -374
  167. package/dist/drizzle/oauth-registration.mjs.map +0 -1
  168. package/dist/drizzle/oauth-state.mjs +0 -107
  169. package/dist/drizzle/oauth-state.mjs.map +0 -1
  170. package/src/drizzle/oauth-accounts.ts +0 -805
  171. package/src/drizzle/oauth-connected-access.ts +0 -361
  172. package/src/drizzle/oauth-connected-collection.ts +0 -324
  173. package/src/drizzle/oauth-connected-custody.ts +0 -279
  174. package/src/drizzle/oauth-connected-flow.ts +0 -529
  175. package/src/drizzle/oauth-connected-input.ts +0 -147
  176. package/src/drizzle/oauth-connected-maintenance.ts +0 -346
  177. package/src/drizzle/oauth-connected-management.ts +0 -365
  178. package/src/drizzle/oauth-connected-settlement.ts +0 -251
  179. package/src/drizzle/oauth-connected-sign-in.ts +0 -443
  180. package/src/drizzle/oauth-connected-state.ts +0 -872
  181. package/src/drizzle/oauth-flow.ts +0 -462
  182. package/src/drizzle/oauth-input.ts +0 -201
  183. package/src/drizzle/oauth-owner.ts +0 -29
  184. package/src/drizzle/oauth-registration.ts +0 -640
  185. package/src/drizzle/oauth-state.ts +0 -218
@@ -1,196 +1,17 @@
1
- import { NativeDatabase, PersistenceMappingError, validateStorageBatch } from "@yielded/auth-persistence/Adapter";
1
+ import { NativeDatabase, PersistenceMappingError, storageKeyPlans, validateStorageBatch } from "@yielded/auth-persistence/Adapter";
2
2
  import { Table, getTableColumns, getTableName, is } from "drizzle-orm";
3
- import { Effect, Predicate, Schema } from "effect";
3
+ import { Effect } from "effect";
4
4
  import { MySqlTable, getTableConfig } from "drizzle-orm/mysql-core";
5
5
  import { PgTable, getTableConfig as getTableConfig$1 } from "drizzle-orm/pg-core";
6
6
  import { SqlClient } from "effect/sql/SqlClient";
7
7
  //#region src/drizzle/storage-validation.ts
8
- const uniquePlans = {
9
- "unique(abuseEvent.moduleId,abuseEvent.action,abuseEvent.scopeKind,abuseEvent.scopeKey,abuseEvent.commandId)": ["abuseEvent", [
10
- "moduleId",
11
- "action",
12
- "scopeKind",
13
- "scopeKey",
14
- "commandId"
15
- ]],
16
- "unique(admission.moduleId)": ["admission", ["moduleId"]],
17
- "unique(attempt.moduleId,attempt.attemptId)": ["attempt", ["moduleId", "attemptId"]],
18
- "unique(authority.subjectId,authority.credentialId)": ["authority", ["subjectId", "credentialId"]],
19
- "unique(authorityCredential.subjectId,authorityCredential.credentialId)": ["authorityCredential", ["subjectId", "credentialId"]],
20
- "unique(command.moduleId,command.commandId)": ["command", ["moduleId", "commandId"]],
21
- "unique(connectedAdmission.admissionId)": ["admission", ["admissionId"]],
22
- "unique(connectedClient.clientKey)": ["client", ["clientKey"]],
23
- "unique(connectedCohort.cohortKey)": ["cohort", ["cohortKey"]],
24
- "unique(connectedCommand.moduleId,connectedCommand.commandId)": ["command", ["moduleId", "commandId"]],
25
- "unique(connectedFlow.moduleId,connectedFlow.commandId)": ["flow", ["moduleId", "commandId"]],
26
- "unique(connectedFlow.moduleId,connectedFlow.flowId)": ["flow", ["moduleId", "flowId"]],
27
- "unique(connectedFlow.stateDigest)": ["flow", ["stateDigest"]],
28
- "unique(connectedGrant.moduleId,connectedGrant.grantId)": ["grant", ["moduleId", "grantId"]],
29
- "unique(connectedGrant.moduleId,connectedGrant.subjectId,connectedGrant.profileKey,connectedGrant.activeIdentityKey)": ["grant", [
30
- "moduleId",
31
- "subjectId",
32
- "profileKey",
33
- "activeIdentityKey"
34
- ]],
35
- "unique(connectedRevocation.jobId)": ["job", ["jobId"]],
36
- "unique(continuation.moduleId,continuation.continuationId)": ["continuation", ["moduleId", "continuationId"]],
37
- "unique(continuation.moduleId,continuation.digest)": ["continuation", ["moduleId", "digest"]],
38
- "unique(credential.credentialId)": ["credential", ["credentialId"]],
39
- "unique(credential.identityKey)": ["credential", ["identityKey"]],
40
- "unique(credential.moduleId,credential.credentialId)": ["credential", ["moduleId", "credentialId"]],
41
- "unique(credential.moduleId,credential.subjectId)": ["credential", ["moduleId", "subjectId"]],
42
- "unique(emailCommand.moduleId,emailCommand.commandId)": ["command", ["moduleId", "commandId"]],
43
- "unique(emailCredential.moduleId,emailCredential.credentialId)": ["credential", ["moduleId", "credentialId"]],
44
- "unique(emailCredential.moduleId,emailCredential.identifierNamespace,emailCredential.identifierValue)": ["credential", [
45
- "moduleId",
46
- "identifierNamespace",
47
- "identifierValue"
48
- ]],
49
- "unique(emailRegistration.moduleId,emailRegistration.commandId)": ["registration", ["moduleId", "commandId"]],
50
- "unique(emailRegistration.pendingReference)": ["registration", ["pendingReference"]],
51
- "unique(failureEvent.moduleId,failureEvent.seriesKey,failureEvent.commandId)": ["failureEvent", [
52
- "moduleId",
53
- "seriesKey",
54
- "commandId"
55
- ]],
56
- "unique(flow.flowId)": ["flow", ["flowId"]],
57
- "unique(flow.moduleId,flow.commandId)": ["flow", ["moduleId", "commandId"]],
58
- "unique(flow.moduleId,flow.flowId)": ["flow", ["moduleId", "flowId"]],
59
- "unique(flow.stateDigest)": ["flow", ["stateDigest"]],
60
- "unique(generation.moduleId,generation.deliveryId)": ["generation", ["moduleId", "deliveryId"]],
61
- "unique(generation.moduleId,generation.proofId)": ["generation", ["moduleId", "proofId"]],
62
- "unique(identifier.namespace,identifier.value)": ["identifier", ["namespace", "value"]],
63
- "unique(intent.digest)": ["intent", ["digest"]],
64
- "unique(intent.flowId)": ["intent", ["flowId"]],
65
- "unique(intent.moduleId,intent.commandId)": ["intent", ["moduleId", "commandId"]],
66
- "unique(intent.moduleId,intent.flowId)": ["intent", ["moduleId", "flowId"]],
67
- "unique(intent.moduleId,intent.intentId)": ["intent", ["moduleId", "intentId"]],
68
- "unique(intent.moduleId,intent.reference)": ["intent", ["moduleId", "reference"]],
69
- "unique(ownership.identityKey)": ["ownership", ["identityKey"]],
70
- "unique(pending.digest)": ["pending", ["digest"]],
71
- "unique(pending.flowId)": ["pending", ["flowId"]],
72
- "unique(rateScope.moduleId,rateScope.purpose,rateScope.action,rateScope.scopeKind,rateScope.scopeKey)": ["rateScope", [
73
- "moduleId",
74
- "purpose",
75
- "action",
76
- "scopeKind",
77
- "scopeKey"
78
- ]],
79
- "unique(registration.moduleId,registration.requestId)": ["registration", ["moduleId", "requestId"]],
80
- "unique(registration.recoveryReference)": ["registration", ["recoveryReference"]],
81
- "unique(registrationCommand.moduleId,registrationCommand.commandId)": ["command", ["moduleId", "commandId"]],
82
- "unique(request.moduleId,request.requestId)": ["request", ["moduleId", "requestId"]],
83
- "unique(series.moduleId,series.purpose,series.scopeKey)": ["series", [
84
- "moduleId",
85
- "purpose",
86
- "scopeKey"
87
- ]],
88
- "unique(session.digest)": ["session", ["digest"]],
89
- "unique(tombstone.subjectId,tombstone.sessionId)": ["tombstone", ["subjectId", "sessionId"]],
90
- "unique(tuple.identityKey)": ["ownership.tuple", ["identityKey"]],
91
- "unique(unlinkCommand.moduleId,unlinkCommand.commandId)": ["command", ["moduleId", "commandId"]]
92
- };
93
- const arrayRoles = {
94
- credentialId: "credential",
95
- factor: "authority",
96
- credentialOwnership: "credentialOwnership",
97
- handleOwnership: "handleOwnership",
98
- boundSubjectHandle: "handleOwnership",
99
- flow: "flow",
100
- command: "flow",
101
- admission: "admission",
102
- charge: "charge",
103
- intentFlow: "intent",
104
- intentCommand: "intent",
105
- handle: "handle"
106
- };
107
- const nestedMappings = [
108
- "read",
109
- "signIn",
110
- "password",
111
- "proof",
112
- "proofs",
113
- "revocation",
114
- "pending",
115
- "session",
116
- "source"
117
- ];
118
- const constraintGroups = [
119
- "constraints",
120
- "tupleConstraints",
121
- "registrationConstraints",
122
- "managementConstraints"
123
- ];
124
- const MappingRecord = Schema.Record(Schema.String, Schema.Unknown);
125
- const record = Schema.decodeUnknownSync(MappingRecord);
126
- const plans = (mapping) => {
127
- const result = [];
128
- for (const group of constraintGroups) {
129
- if (mapping[group] === void 0) continue;
130
- for (const [name, declaration] of Object.entries(record(mapping[group]))) {
131
- if (declaration === "notNull(provisioningRequest.subjectId)") continue;
132
- let role;
133
- let keys;
134
- if (typeof declaration === "string") {
135
- const plan = uniquePlans[declaration];
136
- if (plan !== void 0) [role, keys] = plan;
137
- else if (declaration === "unique(id)") {
138
- role = "subject";
139
- keys = ["id"];
140
- } else if (declaration === "unique(scope)") {
141
- role = name;
142
- keys = ["scope"];
143
- } else if (declaration === "unique(credentialId)") {
144
- role = "credential";
145
- keys = ["id"];
146
- } else if (declaration === "unique(namespace,value)") {
147
- role = "identifier";
148
- keys = ["namespace", "value"];
149
- } else if (declaration === "unique(provider,issuer,subject)") {
150
- role = "externalIdentity";
151
- keys = [
152
- "provider",
153
- "issuer",
154
- "subject"
155
- ];
156
- } else if (declaration === "unique(requestId)") {
157
- role = "provisioningRequest";
158
- keys = ["requestId"];
159
- } else throw new Error("Unknown storage constraint");
160
- } else if (Array.isArray(declaration) && declaration.every(Predicate.isString)) {
161
- const mappedRole = group === "managementConstraints" && name === "command" ? "command" : arrayRoles[name];
162
- if (mappedRole === void 0) throw new Error("Unknown storage constraint");
163
- role = mappedRole;
164
- keys = declaration;
165
- } else throw new Error("Invalid storage constraint");
166
- let target = mapping;
167
- for (const segment of role.split(".")) target = record(target)[segment];
168
- if (target === void 0 && Schema.is(MappingRecord)(mapping.pending)) target = mapping.pending[role];
169
- let mapped = record(target);
170
- if (role === "pending" && mapped.table === void 0) mapped = record(mapped.pending);
171
- if (role === "ownership" && mapped.table === void 0) mapped = record(mapped.external ?? mapped.tuple);
172
- if (!is(mapped.table, Table)) throw new Error("Missing storage table");
173
- const columns = getTableColumns(mapped.table);
174
- result.push({
175
- table: mapped.table,
176
- keys: keys.map((key) => {
177
- const value = mapped[key];
178
- if (typeof value !== "string" || columns[value] === void 0) throw new Error("Missing mapped key");
179
- return value;
180
- })
181
- });
182
- }
183
- }
184
- for (const nested of nestedMappings) {
185
- const value = mapping[nested];
186
- if (Schema.is(MappingRecord)(value) && value.table === void 0) result.push(...plans(value));
187
- }
188
- return result;
189
- };
190
8
  /** Validate at acquisition using the root database supplied by the adapter. */
191
9
  const validateDrizzleStorage = Effect.fnUntraced(function* (mapping) {
192
10
  const physical = yield* Effect.try({
193
- try: () => plans(record(mapping)),
11
+ try: () => storageKeyPlans(mapping, (table) => {
12
+ if (!is(table, Table)) throw new Error("Missing storage table");
13
+ return getTableColumns(table);
14
+ }),
194
15
  catch: () => PersistenceMappingError.make({
195
16
  operation: "mapping",
196
17
  cause: "Invalid storage key mapping"
@@ -199,6 +20,10 @@ const validateDrizzleStorage = Effect.fnUntraced(function* (mapping) {
199
20
  const { $client: client } = yield* NativeDatabase;
200
21
  const batches = /* @__PURE__ */ new Map();
201
22
  for (const plan of physical) {
23
+ if (!is(plan.table, Table)) return yield* PersistenceMappingError.make({
24
+ operation: "mapping",
25
+ cause: "Missing storage table"
26
+ });
202
27
  const pg = is(plan.table, PgTable);
203
28
  const mysql = is(plan.table, MySqlTable);
204
29
  const schema = pg ? getTableConfig$1(plan.table).schema : mysql ? getTableConfig(plan.table).schema : void 0;
@@ -1 +1 @@
1
- {"version":3,"file":"storage-validation.mjs","names":["getPgTableConfig","getMysqlTableConfig"],"sources":["../../src/drizzle/storage-validation.ts"],"sourcesContent":["import {\n NativeDatabase,\n PersistenceMappingError,\n validateStorageBatch,\n type StorageValidation,\n} from \"@yielded/auth-persistence/Adapter\";\nimport { getTableColumns, getTableName, is, Table } from \"drizzle-orm\";\nimport { getTableConfig as getMysqlTableConfig, MySqlTable } from \"drizzle-orm/mysql-core\";\nimport { getTableConfig as getPgTableConfig, PgTable } from \"drizzle-orm/pg-core\";\nimport { Effect, Predicate, Schema } from \"effect\";\nimport { SqlClient } from \"effect/sql/SqlClient\";\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\nconst plans = (mapping: Readonly<Record<string, unknown>>) => {\n const result: Array<{ readonly table: Table; 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 (!is(mapped.table, Table)) throw new Error(\"Missing storage table\");\n const columns = getTableColumns(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) result.push(...plans(value));\n }\n\n return result;\n};\n\n/** Validate at acquisition using the root database supplied by the adapter. */\nexport const validateDrizzleStorage = Effect.fnUntraced(\n function* (mapping: unknown) {\n const physical = yield* Effect.try({\n try: () => plans(record(mapping)),\n catch: () =>\n PersistenceMappingError.make({\n operation: \"mapping\",\n cause: \"Invalid storage key mapping\",\n }),\n });\n\n const { $client: client } = yield* NativeDatabase;\n\n const batches = new Map<\"pg\" | \"mysql\" | \"sqlite\", StorageValidation[]>();\n\n for (const plan of physical) {\n const pg = is(plan.table, PgTable);\n const mysql = is(plan.table, MySqlTable);\n\n const schema = pg\n ? getPgTableConfig(plan.table).schema\n : mysql\n ? getMysqlTableConfig(plan.table).schema\n : undefined;\n\n const columns = getTableColumns(plan.table);\n\n const dialect = pg ? \"pg\" : mysql ? \"mysql\" : \"sqlite\";\n const batch = batches.get(dialect) ?? [];\n\n batch.push({\n table: {\n name: getTableName(plan.table),\n ...(schema === undefined ? {} : { schema }),\n columns: Object.fromEntries(plan.keys.map((key) => [key, { name: columns[key]!.name }])),\n },\n required: [plan.keys],\n });\n batches.set(dialect, batch);\n }\n for (const [dialect, requirements] of batches) {\n yield* validateStorageBatch(dialect, requirements).pipe(\n Effect.provideService(SqlClient, client),\n Effect.mapError(() =>\n PersistenceMappingError.make({\n operation: \"mapping\",\n cause: \"Required SQL storage key is unavailable\",\n }),\n ),\n );\n }\n },\n Effect.catchDefect(() =>\n Effect.fail(\n PersistenceMappingError.make({\n operation: \"mapping\",\n cause: \"Cannot inspect SQL storage metadata\",\n }),\n ),\n ),\n);\n"],"mappings":";;;;;;;AAcA,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;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":"storage-validation.mjs","names":["getPgTableConfig","getMysqlTableConfig"],"sources":["../../src/drizzle/storage-validation.ts"],"sourcesContent":["import {\n NativeDatabase,\n PersistenceMappingError,\n validateStorageBatch,\n type StorageValidation,\n storageKeyPlans,\n} from \"@yielded/auth-persistence/Adapter\";\nimport { getTableColumns, getTableName, is, Table } from \"drizzle-orm\";\nimport { getTableConfig as getMysqlTableConfig, MySqlTable } from \"drizzle-orm/mysql-core\";\nimport { getTableConfig as getPgTableConfig, PgTable } from \"drizzle-orm/pg-core\";\nimport { Effect } from \"effect\";\nimport { SqlClient } from \"effect/sql/SqlClient\";\n\n/** Validate at acquisition using the root database supplied by the adapter. */\nexport const validateDrizzleStorage = Effect.fnUntraced(\n function* (mapping: unknown) {\n const physical = yield* Effect.try({\n try: () =>\n storageKeyPlans(mapping, (table) => {\n if (!is(table, Table)) throw new Error(\"Missing storage table\");\n\n return getTableColumns(table);\n }),\n catch: () =>\n PersistenceMappingError.make({\n operation: \"mapping\",\n cause: \"Invalid storage key mapping\",\n }),\n });\n\n const { $client: client } = yield* NativeDatabase;\n\n const batches = new Map<\"pg\" | \"mysql\" | \"sqlite\", StorageValidation[]>();\n\n for (const plan of physical) {\n if (!is(plan.table, Table))\n return yield* PersistenceMappingError.make({\n operation: \"mapping\",\n cause: \"Missing storage table\",\n });\n const pg = is(plan.table, PgTable);\n const mysql = is(plan.table, MySqlTable);\n\n const schema = pg\n ? getPgTableConfig(plan.table).schema\n : mysql\n ? getMysqlTableConfig(plan.table).schema\n : undefined;\n\n const columns = getTableColumns(plan.table);\n\n const dialect = pg ? \"pg\" : mysql ? \"mysql\" : \"sqlite\";\n const batch = batches.get(dialect) ?? [];\n\n batch.push({\n table: {\n name: getTableName(plan.table),\n ...(schema === undefined ? {} : { schema }),\n columns: Object.fromEntries(plan.keys.map((key) => [key, { name: columns[key]!.name }])),\n },\n required: [plan.keys],\n });\n batches.set(dialect, batch);\n }\n for (const [dialect, requirements] of batches) {\n yield* validateStorageBatch(dialect, requirements).pipe(\n Effect.provideService(SqlClient, client),\n Effect.mapError(() =>\n PersistenceMappingError.make({\n operation: \"mapping\",\n cause: \"Required SQL storage key is unavailable\",\n }),\n ),\n );\n }\n },\n Effect.catchDefect(() =>\n Effect.fail(\n PersistenceMappingError.make({\n operation: \"mapping\",\n cause: \"Cannot inspect SQL storage metadata\",\n }),\n ),\n ),\n);\n"],"mappings":";;;;;;;;AAcA,MAAa,yBAAyB,OAAO,WAC3C,WAAW,SAAkB;CAC3B,MAAM,WAAW,OAAO,OAAO,IAAI;EACjC,WACE,gBAAgB,UAAU,UAAU;GAClC,IAAI,CAAC,GAAG,OAAO,KAAK,GAAG,MAAM,IAAI,MAAM,uBAAuB;GAE9D,OAAO,gBAAgB,KAAK;EAC9B,CAAC;EACH,aACE,wBAAwB,KAAK;GAC3B,WAAW;GACX,OAAO;EACT,CAAC;CACL,CAAC;CAED,MAAM,EAAE,SAAS,WAAW,OAAO;CAEnC,MAAM,0BAAU,IAAI,IAAoD;CAExE,KAAK,MAAM,QAAQ,UAAU;EAC3B,IAAI,CAAC,GAAG,KAAK,OAAO,KAAK,GACvB,OAAO,OAAO,wBAAwB,KAAK;GACzC,WAAW;GACX,OAAO;EACT,CAAC;EACH,MAAM,KAAK,GAAG,KAAK,OAAO,OAAO;EACjC,MAAM,QAAQ,GAAG,KAAK,OAAO,UAAU;EAEvC,MAAM,SAAS,KACXA,iBAAiB,KAAK,KAAK,CAAC,CAAC,SAC7B,QACEC,eAAoB,KAAK,KAAK,CAAC,CAAC,SAChC,KAAA;EAEN,MAAM,UAAU,gBAAgB,KAAK,KAAK;EAE1C,MAAM,UAAU,KAAK,OAAO,QAAQ,UAAU;EAC9C,MAAM,QAAQ,QAAQ,IAAI,OAAO,KAAK,CAAC;EAEvC,MAAM,KAAK;GACT,OAAO;IACL,MAAM,aAAa,KAAK,KAAK;IAC7B,GAAI,WAAW,KAAA,IAAY,CAAC,IAAI,EAAE,OAAO;IACzC,SAAS,OAAO,YAAY,KAAK,KAAK,KAAK,QAAQ,CAAC,KAAK,EAAE,MAAM,QAAQ,IAAI,CAAE,KAAK,CAAC,CAAC,CAAC;GACzF;GACA,UAAU,CAAC,KAAK,IAAI;EACtB,CAAC;EACD,QAAQ,IAAI,SAAS,KAAK;CAC5B;CACA,KAAK,MAAM,CAAC,SAAS,iBAAiB,SACpC,OAAO,qBAAqB,SAAS,YAAY,CAAC,CAAC,KACjD,OAAO,eAAe,WAAW,MAAM,GACvC,OAAO,eACL,wBAAwB,KAAK;EAC3B,WAAW;EACX,OAAO;CACT,CAAC,CACH,CACF;AAEJ,GACA,OAAO,kBACL,OAAO,KACL,wBAAwB,KAAK;CAC3B,WAAW;CACX,OAAO;AACT,CAAC,CACH,CACF,CACF"}
@@ -1,8 +1,8 @@
1
1
  import { PersistenceMappingError as PersistenceMappingError$1 } from "./model.mjs";
2
- import "./transaction-owner.mjs";
3
- import { TransactionCoordinatorError } from "./transaction-execution.mjs";
4
2
  import "./totp-model.mjs";
3
+ import "./transaction-owner.mjs";
5
4
  import "./SuppliedService.mjs";
5
+ import { TransactionCoordinatorError } from "./transaction-execution.mjs";
6
6
  import { NativeDatabase } from "@yielded/auth-persistence/Adapter";
7
7
  import { Table } from "drizzle-orm";
8
8
  import { Context, Crypto, Effect } from "effect";
@@ -1,9 +1,9 @@
1
1
  import { validateDrizzleStorage } from "./storage-validation.mjs";
2
- import { randomId } from "./crypto.mjs";
3
- import { coordinateTransactionOwner, makeTransactionExecution, sqlClientTransactionStandaloneGuard } from "./transaction-execution.mjs";
4
2
  import { requiredTotpConstraints } from "./totp-model.mjs";
3
+ import { randomId } from "./crypto.mjs";
5
4
  import { CurrentTotpTransaction, captureTotp, invariant, mutateTotp, unavailable } from "./totp-state.mjs";
6
5
  import { nativeDatabase } from "./native-database.mjs";
6
+ import { coordinateTransactionOwner, makeTransactionExecution, sqlClientTransactionStandaloneGuard } from "./transaction-execution.mjs";
7
7
  import { NativeDatabase } from "@yielded/auth-persistence/Adapter";
8
8
  import { Context, Effect, Schema } from "effect";
9
9
  import { LifecycleHooks } from "@yielded/auth/Hooks";
@@ -1,2 +1,2 @@
1
- import { TransactionCoordinatorError, TransactionTargetConfiguration } from "@yielded/auth-persistence/Adapter";
2
- export type { TransactionCoordinatorError, TransactionTargetConfiguration };
1
+ import { TransactionCoordinatorError } from "@yielded/auth-persistence/Adapter";
2
+ export type { TransactionCoordinatorError };
@@ -1,2 +1 @@
1
- import { Row, TransactionOwner } from "@yielded/auth-persistence/Adapter";
2
- export type { Row, TransactionOwner };
1
+ import "@yielded/auth-persistence/Adapter";
package/dist/index.d.mts CHANGED
@@ -1,5 +1,6 @@
1
+ import { OAuthProxyColumns } from "./drizzle/oauth-proxy.mjs";
1
2
  import { AnyEmailAddressMapping, AnyEmailRegistrationMapping, AnyEmailSignInMapping, D1EmailAddressMapping, D1EmailRegistrationMapping, EmailAddressMapping, EmailAuthorityCredentialTable, EmailCommandTable, EmailCredentialReadTable, EmailCredentialTable, EmailD1Clock, EmailIdentifierReadTable, EmailIdentifierTable, EmailRegistrationAuthorityCredentialTable, EmailRegistrationCredentialTable, EmailRegistrationIdentifierTable, EmailRegistrationIntent, EmailRegistrationMapping, EmailRegistrationProvisioning, EmailRegistrationState, EmailRegistrationTable, EmailSignInMapping, EmailSubjectReadTable, EmailSubjectTable, RequiredEmailAddressConstraints, RequiredEmailRegistrationConstraints, RequiredEmailSignInConstraints, requiredEmailAddressConstraints, requiredEmailRegistrationConstraints, requiredEmailSignInConstraints } from "./drizzle/email-model.mjs";
2
- import { AnyPasswordPersistenceMapping, AnyPasswordRegistrationMapping, D1PasswordPersistenceMapping, PasswordAttemptAction, PasswordAttemptRecord, PasswordAttemptState, PasswordAttemptTable, PasswordAuthorityCredentialTable, PasswordCommandTable, PasswordConstraintClassifier, PasswordCredentialTable, PasswordD1Clock, PasswordIdentifierTable, PasswordPersistenceMapping, PasswordRegistrationConstraintClassifier, PasswordRegistrationIntent, PasswordRegistrationMapping, PasswordRegistrationProvisioning, PasswordRegistrationState, PasswordRegistrationTable, PasswordSubjectTable, RequiredPasswordConstraints, RequiredPasswordRegistrationConstraints, requiredPasswordConstraints, requiredPasswordRegistrationConstraints } from "./drizzle/password-model.mjs";
3
+ import { AnyPasswordPersistenceMapping, AnyPasswordRegistrationMapping, D1PasswordPersistenceMapping, PasswordAuthorityCredentialTable, PasswordCommandTable, PasswordConstraintClassifier, PasswordCredentialTable, PasswordD1Clock, PasswordIdentifierTable, PasswordPersistenceMapping, PasswordRegistrationConstraintClassifier, PasswordRegistrationIntent, PasswordRegistrationMapping, PasswordRegistrationProvisioning, PasswordRegistrationState, PasswordRegistrationTable, PasswordSubjectTable, RequiredPasswordConstraints, RequiredPasswordRegistrationConstraints, requiredPasswordConstraints, requiredPasswordRegistrationConstraints } from "./drizzle/password-model.mjs";
3
4
  import { CommitMode, D1ExternalIdentityMapping, D1GeneratedIdentityMapping, D1SubjectProvisioningMapping, ExternalIdentityTables, IdentityTables, InstantCodec, PersistenceMappingError, RequiredExternalIdentityConstraints, RequiredIdentityConstraints, RequiredSubjectProvisioningConstraints, SubjectIdCodec, SubjectProvisioningTables, column, identityServicesLayer, isMappedConstraintConflict, provisioningFingerprint, requiredExternalIdentityConstraints, requiredIdentityConstraints, requiredSubjectProvisioningConstraints, updateValues } from "./drizzle/model.mjs";
4
5
  import { AnyProofPersistenceMapping, D1ProofPersistenceMapping, ProofAbuseEventTable, ProofAction, ProofAuthorityInput, ProofAuthorityTables, ProofCommandDecision, ProofCommandKind, ProofCommandTable, ProofConstraintClassifier, ProofContinuationRecord, ProofContinuationTable, ProofD1Clock, ProofDeliveryState, ProofFailureEventTable, ProofGenerationState, ProofGenerationTable, ProofPersistenceMapping, ProofRateScopeTable, ProofRequestTable, ProofScopeKeys, ProofScopeKind, ProofSeriesTable, RequiredProofConstraints, requiredProofConstraints } from "./drizzle/proof-model.mjs";
5
6
  import { AnyPasswordPreparedPersistenceMapping, D1PasswordPreparedPersistenceMapping, D1PasswordPreparedProofMapping, PasswordPreparedAdmissionTable, PasswordPreparedIntentTable, PasswordPreparedPersistenceMapping, PasswordPreparedProofMapping, PasswordPreparedState, RequiredPasswordPreparedConstraints, requiredPasswordPreparedConstraints } from "./drizzle/password-prepared-model.mjs";
@@ -22,4 +23,4 @@ import { decodeTotpRecord, encodeTotpRecord } from "./drizzle/totp-state.mjs";
22
23
  import { PasskeyCommandTable, PasskeyCredentialInsert, PasskeyInvalidationInput, PasskeyInvalidationMutation, PasskeyManagementMapping, PasskeyManagementServices, PasskeyRegistrationMapping, PasskeyRegistrationServices, PasskeyRegistrationWriter, PasskeyWriteTables, passkeyInvalidationMutation, requiredPasskeyManagementConstraints, requiredPasskeyRegistrationWriteConstraints } from "./drizzle/passkey-write-model.mjs";
23
24
  import { passkeyManagementPersistenceLayer } from "./drizzle/passkey-write-target.mjs";
24
25
  import { D1PhoneMapping, PhoneMapping, PhoneMappingSource, PhonePersistenceServices, PhoneProofCompletionMapping, phonePersistenceLayer, phoneProofCompletionMapping, requiredPhoneConstraints } from "./drizzle/phone-model.mjs";
25
- export { type AnyEmailAddressMapping, type AnyEmailRegistrationMapping, type AnyEmailSignInMapping, type AnyPasswordPersistenceMapping, type AnyPasswordPreparedPersistenceMapping, type AnyPasswordRegistrationMapping, type AnyProofPersistenceMapping, type AuthenticationAuthorityMapping, type CommitMode, type D1AuthenticationAuthorityMapping, type D1EmailAddressMapping, type D1EmailRegistrationMapping, type D1ExternalIdentityMapping, type D1GeneratedIdentityMapping, type D1PasskeyMapping, type D1PasswordPersistenceMapping, type D1PasswordPreparedPersistenceMapping, type D1PasswordPreparedProofMapping, type D1PendingAuthenticationMapping, type D1PhoneMapping, type D1ProofPersistenceMapping, type D1SessionClockMapping, type D1SessionStepUpMapping, type D1SignedSessionValidityMapping, type D1StatefulSessionMapping, type D1SubjectProvisioningMapping, type D1TotpMapping, type EmailAddressMapping, type EmailAuthorityCredentialTable, type EmailCommandTable, type EmailCredentialReadTable, type EmailCredentialTable, type EmailD1Clock, type EmailIdentifierReadTable, type EmailIdentifierTable, type EmailRegistrationAuthorityCredentialTable, type EmailRegistrationCredentialTable, type EmailRegistrationIdentifierTable, type EmailRegistrationIntent, type EmailRegistrationMapping, type EmailRegistrationProvisioning, type EmailRegistrationState, type EmailRegistrationTable, type EmailSignInMapping, type EmailSubjectReadTable, type EmailSubjectTable, type ExternalIdentityTables, type IdentityTables, type InstantCodec, type OAuthAccountsMapping, type OAuthAction, type OAuthAuthorityReadTable, type OAuthAuthorityTable, type OAuthCleanupDescriptor, type OAuthCleanupTable, type OAuthClock, type OAuthConnectedAction, type OAuthConnectedAdmissionTable, type OAuthConnectedAuthorityMapping, type OAuthConnectedClientRegistrationTable, type OAuthConnectedCohortTable, type OAuthConnectedCommandTable, type OAuthConnectedFlowTable, type OAuthConnectedGrantTable, type OAuthConnectedMapping, type OAuthConnectedOrderCodec, type OAuthConnectedOwnershipRead, type OAuthConnectedPolicyGuard, type OAuthConnectedPolicyGuardTable, type OAuthConnectedPolicyInput, type OAuthConnectedRevocationJobTable, type OAuthConnectedRevocationMapping, type OAuthConnectedSqlPolicy, type OAuthConnectedSubjectTable, type OAuthCredentialReadTable, type OAuthCredentialTable, type OAuthD1Mapping, type OAuthEligibilityDescriptor, type OAuthEligibilityFact, type OAuthEligibilityTable, type OAuthFlowState, type OAuthFlowTable, type OAuthMetadataPolicy, type OAuthOwnershipMutation, type OAuthOwnershipReadTable, type OAuthOwnershipTable, type OAuthReferenceGuardDescriptor, type OAuthReferenceGuardTable, type OAuthRegistrationAuthority, type OAuthRegistrationBase, type OAuthRegistrationCommandTable, type OAuthRegistrationEligibility, type OAuthRegistrationGuardDescriptor, type OAuthRegistrationGuardTable, type OAuthRegistrationIntentMapping, type OAuthRegistrationIntentTable, type OAuthRegistrationMapping, type OAuthRegistrationState, type OAuthSignInMapping, type OAuthSubjectReadTable, type OAuthSubjectTable, type OAuthTupleAuthorityTable, type OAuthTupleState, type OAuthUnlinkCommandTable, type PasskeyAdmissionTable, type PasskeyCeremonyMapping, type PasskeyChargeInsert, type PasskeyChargeKind, type PasskeyChargeTable, type PasskeyClock, type PasskeyColumn, type PasskeyCommandTable, type PasskeyCredentialInsert, type PasskeyCredentialMapping, type PasskeyCredentialOwnershipTable, type PasskeyCredentialReadTable, type PasskeyCredentialServices, type PasskeyEnrollmentContextMapping, type PasskeyEnrollmentContextServices, type PasskeyFactorReadTable, type PasskeyFlowInsert, type PasskeyFlowState, type PasskeyFlowTable, type PasskeyHandleOwnershipTable, type PasskeyHandleReadTable, type PasskeyHandleReservationTable, type PasskeyInvalidationInput, type PasskeyInvalidationMutation, type PasskeyManagementMapping, type PasskeyManagementServices, type PasskeyMappingSource, type PasskeyModuleTable, type PasskeyPersistenceMapping, type PasskeyPersistenceServices, type PasskeyPolicyGuard, type PasskeyRegistrationCeremonyCapabilities, type PasskeyRegistrationCeremonyMapping, type PasskeyRegistrationCeremonyServices, type PasskeyRegistrationIntentReadTable, type PasskeyRegistrationMapping, type PasskeyRegistrationServices, type PasskeyRegistrationWriter, type PasskeySubjectIdCodec, type PasskeySubjectReadTable, type PasskeyWriteTables, type PasswordAttemptAction, type PasswordAttemptRecord, type PasswordAttemptState, type PasswordAttemptTable, type PasswordAuthorityCredentialTable, type PasswordCommandTable, type PasswordConstraintClassifier, type PasswordCredentialTable, type PasswordD1Clock, type PasswordIdentifierTable, type PasswordPersistenceMapping, type PasswordPreparedAdmissionTable, type PasswordPreparedIntentTable, type PasswordPreparedPersistenceMapping, type PasswordPreparedProofMapping, type PasswordPreparedState, type PasswordRegistrationConstraintClassifier, type PasswordRegistrationIntent, type PasswordRegistrationMapping, type PasswordRegistrationProvisioning, type PasswordRegistrationState, type PasswordRegistrationTable, type PasswordSubjectTable, type PendingAuthenticationMapping, type PendingAuthenticationTables, type PersistenceMappingError, type PhoneMapping, type PhoneMappingSource, type PhonePersistenceServices, type PhoneProofCompletionMapping, type ProofAbuseEventTable, type ProofAction, type ProofAuthorityInput, type ProofAuthorityTables, type ProofCommandDecision, type ProofCommandKind, type ProofCommandTable, type ProofConstraintClassifier, type ProofContinuationRecord, type ProofContinuationTable, type ProofD1Clock, type ProofDeliveryState, type ProofFailureEventTable, type ProofGenerationState, type ProofGenerationTable, type ProofPersistenceMapping, type ProofRateScopeTable, type ProofRequestTable, type ProofScopeKeys, type ProofScopeKind, type ProofSeriesTable, type RequiredEmailAddressConstraints, type RequiredEmailRegistrationConstraints, type RequiredEmailSignInConstraints, type RequiredExternalIdentityConstraints, type RequiredIdentityConstraints, type RequiredPasswordConstraints, type RequiredPasswordPreparedConstraints, type RequiredPasswordRegistrationConstraints, type RequiredPendingAuthenticationConstraints, type RequiredProofConstraints, type RequiredSessionConstraints, type RequiredSessionStepUpConstraints, type RequiredSignedValidityConstraints, type RequiredStatefulPendingConstraints, type RequiredSubjectProvisioningConstraints, type SessionAuthorityTables, type SessionConstraintClassifier, type SessionFlowTables, type SessionIdCodec, type SessionStepUpIntentTables, type SessionStepUpMapping, type SessionStepUpSourceTables, type SessionSubjectTables, type SignedSessionValidityMapping, type SignedSessionValidityTables, type StatefulSessionMapping, type StatefulSessionTables, type SubjectIdCodec, type SubjectProvisioningTables, type TotpMapping, type TotpMappingSource, type TotpPersistenceServices, authenticationAuthorityLayer, column, decodeTotpRecord, emailAddressPersistenceLayer, emailRegistrationLayer, emailSignInTargetsLayer, encodeTotpRecord, identityServicesLayer, isMappedConstraintConflict, oauthAccountsPersistenceLayer, oauthCleanupTable, oauthConnectedOwnershipReferences, oauthConnectedPersistenceLayer, oauthConnectedPolicyGuard, oauthConnectedRevocationsLayer, oauthEligibilityTable, oauthReferenceGuardTable, oauthRegistrationAuthorityLayer, oauthRegistrationGuardTable, oauthRegistrationIntentsLayer, oauthSignInPersistenceLayer, passkeyCredentialsLayer, passkeyEnrollmentContextLayer, passkeyInvalidationMutation, passkeyManagementPersistenceLayer, passkeyPersistenceLayer, passkeyPolicyGuard, passwordPersistenceLayer, passwordPreparedPersistenceLayer, passwordRegistrationLayer, pendingAuthenticationLayer, phonePersistenceLayer, phoneProofCompletionMapping, proofPersistenceLayer, provisioningFingerprint, requiredEmailAddressConstraints, requiredEmailRegistrationConstraints, requiredEmailSignInConstraints, requiredExternalIdentityConstraints, requiredIdentityConstraints, requiredOAuthAccountsConstraints, requiredOAuthConnectedConstraints, requiredOAuthConnectedRevocationConstraints, requiredOAuthRegistrationConstraints, requiredOAuthSignInConstraints, requiredOAuthTupleConstraints, requiredPasskeyCredentialConstraints, requiredPasskeyManagementConstraints, requiredPasskeyPersistenceConstraints, requiredPasskeyRegistrationCeremonyConstraints, requiredPasskeyRegistrationWriteConstraints, requiredPasswordConstraints, requiredPasswordPreparedConstraints, requiredPasswordRegistrationConstraints, requiredPendingAuthenticationConstraints, requiredPhoneConstraints, requiredProofConstraints, requiredSessionConstraints, requiredSessionStepUpConstraints, requiredSignedValidityConstraints, requiredStatefulPendingConstraints, requiredSubjectProvisioningConstraints, requiredTotpConstraints, signedSessionValidityLayer, statefulSessionLayers, totpPersistenceLayer, updateValues };
26
+ export { type AnyEmailAddressMapping, type AnyEmailRegistrationMapping, type AnyEmailSignInMapping, type AnyPasswordPersistenceMapping, type AnyPasswordPreparedPersistenceMapping, type AnyPasswordRegistrationMapping, type AnyProofPersistenceMapping, type AuthenticationAuthorityMapping, type CommitMode, type D1AuthenticationAuthorityMapping, type D1EmailAddressMapping, type D1EmailRegistrationMapping, type D1ExternalIdentityMapping, type D1GeneratedIdentityMapping, type D1PasskeyMapping, type D1PasswordPersistenceMapping, type D1PasswordPreparedPersistenceMapping, type D1PasswordPreparedProofMapping, type D1PendingAuthenticationMapping, type D1PhoneMapping, type D1ProofPersistenceMapping, type D1SessionClockMapping, type D1SessionStepUpMapping, type D1SignedSessionValidityMapping, type D1StatefulSessionMapping, type D1SubjectProvisioningMapping, type D1TotpMapping, type EmailAddressMapping, type EmailAuthorityCredentialTable, type EmailCommandTable, type EmailCredentialReadTable, type EmailCredentialTable, type EmailD1Clock, type EmailIdentifierReadTable, type EmailIdentifierTable, type EmailRegistrationAuthorityCredentialTable, type EmailRegistrationCredentialTable, type EmailRegistrationIdentifierTable, type EmailRegistrationIntent, type EmailRegistrationMapping, type EmailRegistrationProvisioning, type EmailRegistrationState, type EmailRegistrationTable, type EmailSignInMapping, type EmailSubjectReadTable, type EmailSubjectTable, type ExternalIdentityTables, type IdentityTables, type InstantCodec, type OAuthAccountsMapping, type OAuthAction, type OAuthAuthorityReadTable, type OAuthAuthorityTable, type OAuthCleanupDescriptor, type OAuthCleanupTable, type OAuthClock, type OAuthConnectedAction, type OAuthConnectedAdmissionTable, type OAuthConnectedAuthorityMapping, type OAuthConnectedClientRegistrationTable, type OAuthConnectedCohortTable, type OAuthConnectedCommandTable, type OAuthConnectedFlowTable, type OAuthConnectedGrantTable, type OAuthConnectedMapping, type OAuthConnectedOrderCodec, type OAuthConnectedOwnershipRead, type OAuthConnectedPolicyGuard, type OAuthConnectedPolicyGuardTable, type OAuthConnectedPolicyInput, type OAuthConnectedRevocationJobTable, type OAuthConnectedRevocationMapping, type OAuthConnectedSqlPolicy, type OAuthConnectedSubjectTable, type OAuthCredentialReadTable, type OAuthCredentialTable, type OAuthD1Mapping, type OAuthEligibilityDescriptor, type OAuthEligibilityFact, type OAuthEligibilityTable, type OAuthFlowState, type OAuthFlowTable, type OAuthMetadataPolicy, type OAuthOwnershipMutation, type OAuthOwnershipReadTable, type OAuthOwnershipTable, type OAuthProxyColumns, type OAuthReferenceGuardDescriptor, type OAuthReferenceGuardTable, type OAuthRegistrationAuthority, type OAuthRegistrationBase, type OAuthRegistrationCommandTable, type OAuthRegistrationEligibility, type OAuthRegistrationGuardDescriptor, type OAuthRegistrationGuardTable, type OAuthRegistrationIntentMapping, type OAuthRegistrationIntentTable, type OAuthRegistrationMapping, type OAuthRegistrationState, type OAuthSignInMapping, type OAuthSubjectReadTable, type OAuthSubjectTable, type OAuthTupleAuthorityTable, type OAuthTupleState, type OAuthUnlinkCommandTable, type PasskeyAdmissionTable, type PasskeyCeremonyMapping, type PasskeyChargeInsert, type PasskeyChargeKind, type PasskeyChargeTable, type PasskeyClock, type PasskeyColumn, type PasskeyCommandTable, type PasskeyCredentialInsert, type PasskeyCredentialMapping, type PasskeyCredentialOwnershipTable, type PasskeyCredentialReadTable, type PasskeyCredentialServices, type PasskeyEnrollmentContextMapping, type PasskeyEnrollmentContextServices, type PasskeyFactorReadTable, type PasskeyFlowInsert, type PasskeyFlowState, type PasskeyFlowTable, type PasskeyHandleOwnershipTable, type PasskeyHandleReadTable, type PasskeyHandleReservationTable, type PasskeyInvalidationInput, type PasskeyInvalidationMutation, type PasskeyManagementMapping, type PasskeyManagementServices, type PasskeyMappingSource, type PasskeyModuleTable, type PasskeyPersistenceMapping, type PasskeyPersistenceServices, type PasskeyPolicyGuard, type PasskeyRegistrationCeremonyCapabilities, type PasskeyRegistrationCeremonyMapping, type PasskeyRegistrationCeremonyServices, type PasskeyRegistrationIntentReadTable, type PasskeyRegistrationMapping, type PasskeyRegistrationServices, type PasskeyRegistrationWriter, type PasskeySubjectIdCodec, type PasskeySubjectReadTable, type PasskeyWriteTables, type PasswordAuthorityCredentialTable, type PasswordCommandTable, type PasswordConstraintClassifier, type PasswordCredentialTable, type PasswordD1Clock, type PasswordIdentifierTable, type PasswordPersistenceMapping, type PasswordPreparedAdmissionTable, type PasswordPreparedIntentTable, type PasswordPreparedPersistenceMapping, type PasswordPreparedProofMapping, type PasswordPreparedState, type PasswordRegistrationConstraintClassifier, type PasswordRegistrationIntent, type PasswordRegistrationMapping, type PasswordRegistrationProvisioning, type PasswordRegistrationState, type PasswordRegistrationTable, type PasswordSubjectTable, type PendingAuthenticationMapping, type PendingAuthenticationTables, type PersistenceMappingError, type PhoneMapping, type PhoneMappingSource, type PhonePersistenceServices, type PhoneProofCompletionMapping, type ProofAbuseEventTable, type ProofAction, type ProofAuthorityInput, type ProofAuthorityTables, type ProofCommandDecision, type ProofCommandKind, type ProofCommandTable, type ProofConstraintClassifier, type ProofContinuationRecord, type ProofContinuationTable, type ProofD1Clock, type ProofDeliveryState, type ProofFailureEventTable, type ProofGenerationState, type ProofGenerationTable, type ProofPersistenceMapping, type ProofRateScopeTable, type ProofRequestTable, type ProofScopeKeys, type ProofScopeKind, type ProofSeriesTable, type RequiredEmailAddressConstraints, type RequiredEmailRegistrationConstraints, type RequiredEmailSignInConstraints, type RequiredExternalIdentityConstraints, type RequiredIdentityConstraints, type RequiredPasswordConstraints, type RequiredPasswordPreparedConstraints, type RequiredPasswordRegistrationConstraints, type RequiredPendingAuthenticationConstraints, type RequiredProofConstraints, type RequiredSessionConstraints, type RequiredSessionStepUpConstraints, type RequiredSignedValidityConstraints, type RequiredStatefulPendingConstraints, type RequiredSubjectProvisioningConstraints, type SessionAuthorityTables, type SessionConstraintClassifier, type SessionFlowTables, type SessionIdCodec, type SessionStepUpIntentTables, type SessionStepUpMapping, type SessionStepUpSourceTables, type SessionSubjectTables, type SignedSessionValidityMapping, type SignedSessionValidityTables, type StatefulSessionMapping, type StatefulSessionTables, type SubjectIdCodec, type SubjectProvisioningTables, type TotpMapping, type TotpMappingSource, type TotpPersistenceServices, authenticationAuthorityLayer, column, decodeTotpRecord, emailAddressPersistenceLayer, emailRegistrationLayer, emailSignInTargetsLayer, encodeTotpRecord, identityServicesLayer, isMappedConstraintConflict, oauthAccountsPersistenceLayer, oauthCleanupTable, oauthConnectedOwnershipReferences, oauthConnectedPersistenceLayer, oauthConnectedPolicyGuard, oauthConnectedRevocationsLayer, oauthEligibilityTable, oauthReferenceGuardTable, oauthRegistrationAuthorityLayer, oauthRegistrationGuardTable, oauthRegistrationIntentsLayer, oauthSignInPersistenceLayer, passkeyCredentialsLayer, passkeyEnrollmentContextLayer, passkeyInvalidationMutation, passkeyManagementPersistenceLayer, passkeyPersistenceLayer, passkeyPolicyGuard, passwordPersistenceLayer, passwordPreparedPersistenceLayer, passwordRegistrationLayer, pendingAuthenticationLayer, phonePersistenceLayer, phoneProofCompletionMapping, proofPersistenceLayer, provisioningFingerprint, requiredEmailAddressConstraints, requiredEmailRegistrationConstraints, requiredEmailSignInConstraints, requiredExternalIdentityConstraints, requiredIdentityConstraints, requiredOAuthAccountsConstraints, requiredOAuthConnectedConstraints, requiredOAuthConnectedRevocationConstraints, requiredOAuthRegistrationConstraints, requiredOAuthSignInConstraints, requiredOAuthTupleConstraints, requiredPasskeyCredentialConstraints, requiredPasskeyManagementConstraints, requiredPasskeyPersistenceConstraints, requiredPasskeyRegistrationCeremonyConstraints, requiredPasskeyRegistrationWriteConstraints, requiredPasswordConstraints, requiredPasswordPreparedConstraints, requiredPasswordRegistrationConstraints, requiredPendingAuthenticationConstraints, requiredPhoneConstraints, requiredProofConstraints, requiredSessionConstraints, requiredSessionStepUpConstraints, requiredSignedValidityConstraints, requiredStatefulPendingConstraints, requiredSubjectProvisioningConstraints, requiredTotpConstraints, signedSessionValidityLayer, statefulSessionLayers, totpPersistenceLayer, updateValues };
@@ -0,0 +1,138 @@
1
+ import { OAuthProxyColumns } from "../drizzle/oauth-proxy.mjs";
2
+ import { PgTable } from "drizzle-orm/pg-core";
3
+ //#region src/internal/drizzle-postgres-oauth-proxy.d.ts
4
+ /** Export the returned table from your Drizzle Kit schema before applying the Layer. */
5
+ declare const table: (name: string) => import("drizzle-orm/pg-core").PgTableWithColumns<{
6
+ name: string;
7
+ schema: undefined;
8
+ columns: {
9
+ namespace: import("drizzle-orm/pg-core").PgBuildColumn<string, import("drizzle-orm/pg-core").SetNotNull<import("drizzle-orm/pg-core").PgTextBuilder<[string, ...string[]]>>, {
10
+ name: string;
11
+ tableName: string;
12
+ dataType: "string";
13
+ data: string;
14
+ driverParam: string;
15
+ notNull: true;
16
+ hasDefault: false;
17
+ isPrimaryKey: false;
18
+ isAutoincrement: false;
19
+ hasRuntimeDefault: false;
20
+ enumValues: undefined;
21
+ identity: undefined;
22
+ generated: undefined;
23
+ }>;
24
+ flowId: import("drizzle-orm/pg-core").PgBuildColumn<string, import("drizzle-orm/pg-core").SetNotNull<import("drizzle-orm/pg-core").PgTextBuilder<[string, ...string[]]>>, {
25
+ name: string;
26
+ tableName: string;
27
+ dataType: "string";
28
+ data: string;
29
+ driverParam: string;
30
+ notNull: true;
31
+ hasDefault: false;
32
+ isPrimaryKey: false;
33
+ isAutoincrement: false;
34
+ hasRuntimeDefault: false;
35
+ enumValues: undefined;
36
+ identity: undefined;
37
+ generated: undefined;
38
+ }>;
39
+ version: import("drizzle-orm/pg-core").PgBuildColumn<string, import("drizzle-orm/pg-core").SetNotNull<import("drizzle-orm/pg-core").PgTextBuilder<[string, ...string[]]>>, {
40
+ name: string;
41
+ tableName: string;
42
+ dataType: "string";
43
+ data: string;
44
+ driverParam: string;
45
+ notNull: true;
46
+ hasDefault: false;
47
+ isPrimaryKey: false;
48
+ isAutoincrement: false;
49
+ hasRuntimeDefault: false;
50
+ enumValues: undefined;
51
+ identity: undefined;
52
+ generated: undefined;
53
+ }>;
54
+ stage: import("drizzle-orm/pg-core").PgBuildColumn<string, import("drizzle-orm/pg-core").SetNotNull<import("drizzle-orm/pg-core").PgTextBuilder<[string, ...string[]]>>, {
55
+ name: string;
56
+ tableName: string;
57
+ dataType: "string";
58
+ data: string;
59
+ driverParam: string;
60
+ notNull: true;
61
+ hasDefault: false;
62
+ isPrimaryKey: false;
63
+ isAutoincrement: false;
64
+ hasRuntimeDefault: false;
65
+ enumValues: undefined;
66
+ identity: undefined;
67
+ generated: undefined;
68
+ }>;
69
+ context: import("drizzle-orm/pg-core").PgBuildColumn<string, import("drizzle-orm/pg-core").SetNotNull<import("drizzle-orm/pg-core").PgTextBuilder<[string, ...string[]]>>, {
70
+ name: string;
71
+ tableName: string;
72
+ dataType: "string";
73
+ data: string;
74
+ driverParam: string;
75
+ notNull: true;
76
+ hasDefault: false;
77
+ isPrimaryKey: false;
78
+ isAutoincrement: false;
79
+ hasRuntimeDefault: false;
80
+ enumValues: undefined;
81
+ identity: undefined;
82
+ generated: undefined;
83
+ }>;
84
+ expiresAtMillis: import("drizzle-orm/pg-core").PgBuildColumn<string, import("drizzle-orm/pg-core").SetNotNull<import("drizzle-orm/pg-core").PgBigInt53Builder>, {
85
+ name: string;
86
+ tableName: string;
87
+ dataType: "number int53";
88
+ data: number;
89
+ driverParam: string | number;
90
+ notNull: true;
91
+ hasDefault: false;
92
+ isPrimaryKey: false;
93
+ isAutoincrement: false;
94
+ hasRuntimeDefault: false;
95
+ enumValues: undefined;
96
+ identity: undefined;
97
+ generated: undefined;
98
+ }>;
99
+ handoffExpiresAtMillis: import("drizzle-orm/pg-core").PgBuildColumn<string, import("drizzle-orm/pg-core").PgBigInt53Builder, {
100
+ name: string;
101
+ tableName: string;
102
+ dataType: "number int53";
103
+ data: number;
104
+ driverParam: string | number;
105
+ notNull: false;
106
+ hasDefault: false;
107
+ isPrimaryKey: false;
108
+ isAutoincrement: false;
109
+ hasRuntimeDefault: false;
110
+ enumValues: undefined;
111
+ identity: undefined;
112
+ generated: undefined;
113
+ }>;
114
+ payload: import("drizzle-orm/pg-core").PgBuildColumn<string, import("drizzle-orm/pg-core").SetNotNull<import("drizzle-orm/pg-core").PgTextBuilder<[string, ...string[]]>>, {
115
+ name: string;
116
+ tableName: string;
117
+ dataType: "string";
118
+ data: string;
119
+ driverParam: string;
120
+ notNull: true;
121
+ hasDefault: false;
122
+ isPrimaryKey: false;
123
+ isAutoincrement: false;
124
+ hasRuntimeDefault: false;
125
+ enumValues: undefined;
126
+ identity: undefined;
127
+ generated: undefined;
128
+ }>;
129
+ };
130
+ dialect: 'pg';
131
+ }>;
132
+ declare const layer: <T extends PgTable>(table: T, columns?: OAuthProxyColumns<T>) => import("effect/Layer").Layer<import("@yielded/auth/OAuthProxy").Persistence, import("@yielded/auth/OAuthProxy").ConfigurationError | import("@yielded/auth/OAuthProxy").Unavailable, import("effect/sql/SqlClient").SqlClient>;
133
+ export declare const OAuthProxyPersistence: {
134
+ table: typeof table;
135
+ layer: typeof layer;
136
+ };
137
+ //#endregion
138
+ //# sourceMappingURL=drizzle-postgres-oauth-proxy.d.mts.map
@@ -0,0 +1,29 @@
1
+ import { oauthProxyLayer } from "../drizzle/oauth-proxy.mjs";
2
+ import { sql } from "drizzle-orm";
3
+ import { bigint, check, pgTable, primaryKey, text } from "drizzle-orm/pg-core";
4
+ //#region src/internal/drizzle-postgres-oauth-proxy.ts
5
+ /** Export the returned table from your Drizzle Kit schema before applying the Layer. */
6
+ const table = (name) => pgTable(name, {
7
+ namespace: text("namespace").notNull(),
8
+ flowId: text("flow_id").notNull(),
9
+ version: text("version").notNull(),
10
+ stage: text("stage").notNull(),
11
+ context: text("context").notNull(),
12
+ expiresAtMillis: bigint("expires_at_millis", { mode: "number" }).notNull(),
13
+ handoffExpiresAtMillis: bigint("handoff_expires_at_millis", { mode: "number" }),
14
+ payload: text("payload").notNull()
15
+ }, (columns) => [
16
+ primaryKey({ columns: [columns.namespace, columns.flowId] }),
17
+ check(`${name}_stage`, sql`${columns.stage} in ('Pending', 'Exchanging', 'Ready', 'Consumed')`),
18
+ check(`${name}_handoff`, sql`(${columns.stage} = 'Ready' and ${columns.handoffExpiresAtMillis} is not null)
19
+ or (${columns.stage} <> 'Ready' and ${columns.handoffExpiresAtMillis} is null)`)
20
+ ]);
21
+ const layer = (table, columns) => oauthProxyLayer("pg", table, columns);
22
+ const OAuthProxyPersistence = {
23
+ table,
24
+ layer
25
+ };
26
+ //#endregion
27
+ export { OAuthProxyPersistence };
28
+
29
+ //# sourceMappingURL=drizzle-postgres-oauth-proxy.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drizzle-postgres-oauth-proxy.mjs","names":[],"sources":["../../src/internal/drizzle-postgres-oauth-proxy.ts"],"sourcesContent":["import { sql } from \"drizzle-orm\";\nimport { bigint, check, pgTable, primaryKey, text, type PgTable } from \"drizzle-orm/pg-core\";\n\nimport { oauthProxyLayer, type OAuthProxyColumns } from \"../drizzle/oauth-proxy\";\n\n/** Export the returned table from your Drizzle Kit schema before applying the Layer. */\nconst table = (name: string) =>\n pgTable(\n name,\n {\n namespace: text(\"namespace\").notNull(),\n flowId: text(\"flow_id\").notNull(),\n version: text(\"version\").notNull(),\n stage: text(\"stage\").notNull(),\n context: text(\"context\").notNull(),\n expiresAtMillis: bigint(\"expires_at_millis\", { mode: \"number\" }).notNull(),\n handoffExpiresAtMillis: bigint(\"handoff_expires_at_millis\", { mode: \"number\" }),\n payload: text(\"payload\").notNull(),\n },\n (columns) => [\n primaryKey({ columns: [columns.namespace, columns.flowId] }),\n check(\n `${name}_stage`,\n sql`${columns.stage} in ('Pending', 'Exchanging', 'Ready', 'Consumed')`,\n ),\n check(\n `${name}_handoff`,\n sql`(${columns.stage} = 'Ready' and ${columns.handoffExpiresAtMillis} is not null)\n or (${columns.stage} <> 'Ready' and ${columns.handoffExpiresAtMillis} is null)`,\n ),\n ],\n );\n\nconst layer = <T extends PgTable>(table: T, columns?: OAuthProxyColumns<T>) =>\n oauthProxyLayer(\"pg\", table, columns);\n\nexport const OAuthProxyPersistence = { table, layer };\n"],"mappings":";;;;;AAMA,MAAM,SAAS,SACb,QACE,MACA;CACE,WAAW,KAAK,WAAW,CAAC,CAAC,QAAQ;CACrC,QAAQ,KAAK,SAAS,CAAC,CAAC,QAAQ;CAChC,SAAS,KAAK,SAAS,CAAC,CAAC,QAAQ;CACjC,OAAO,KAAK,OAAO,CAAC,CAAC,QAAQ;CAC7B,SAAS,KAAK,SAAS,CAAC,CAAC,QAAQ;CACjC,iBAAiB,OAAO,qBAAqB,EAAE,MAAM,SAAS,CAAC,CAAC,CAAC,QAAQ;CACzE,wBAAwB,OAAO,6BAA6B,EAAE,MAAM,SAAS,CAAC;CAC9E,SAAS,KAAK,SAAS,CAAC,CAAC,QAAQ;AACnC,IACC,YAAY;CACX,WAAW,EAAE,SAAS,CAAC,QAAQ,WAAW,QAAQ,MAAM,EAAE,CAAC;CAC3D,MACE,GAAG,KAAK,SACR,GAAG,GAAG,QAAQ,MAAM,mDACtB;CACA,MACE,GAAG,KAAK,WACR,GAAG,IAAI,QAAQ,MAAM,iBAAiB,QAAQ,uBAAuB;UACnE,QAAQ,MAAM,kBAAkB,QAAQ,uBAAuB,UACnE;AACF,CACF;AAEF,MAAM,SAA4B,OAAU,YAC1C,gBAAgB,MAAM,OAAO,OAAO;AAEtC,MAAa,wBAAwB;CAAE;CAAO;AAAM"}