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

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 (481) hide show
  1. package/README.md +6 -8
  2. package/dist/Adapter.d.mts +47 -33
  3. package/dist/Adapter.mjs +36 -23
  4. package/dist/OAuthPersistence.d.mts +35 -51
  5. package/dist/OAuthPersistence.mjs +60 -68
  6. package/dist/OAuthPersistence.mjs.map +1 -1
  7. package/dist/index.d.mts +2 -2
  8. package/dist/index.mjs +2 -2
  9. package/dist/internal/browser-login.d.mts +1 -1
  10. package/dist/internal/browser-login.mjs +29 -9
  11. package/dist/internal/browser-login.mjs.map +1 -1
  12. package/dist/internal/configuration.d.mts +13 -8
  13. package/dist/internal/configuration.mjs.map +1 -1
  14. package/dist/internal/crypto.d.mts +1 -0
  15. package/dist/internal/crypto.mjs +1 -1
  16. package/dist/internal/d1-planning.mjs +8 -0
  17. package/dist/internal/d1-planning.mjs.map +1 -0
  18. package/dist/internal/email-native-state.mjs +135 -0
  19. package/dist/internal/email-native-state.mjs.map +1 -0
  20. package/dist/internal/email-native.d.mts +17 -0
  21. package/dist/internal/email-native.mjs +245 -0
  22. package/dist/internal/email-native.mjs.map +1 -0
  23. package/dist/internal/email-policy.mjs +92 -0
  24. package/dist/internal/email-policy.mjs.map +1 -0
  25. package/dist/internal/email-registration-native.d.mts +38 -0
  26. package/dist/internal/email-registration-native.mjs +171 -0
  27. package/dist/internal/email-registration-native.mjs.map +1 -0
  28. package/dist/internal/models/email-model.d.mts +40 -104
  29. package/dist/internal/models/email-model.mjs +3 -5
  30. package/dist/internal/models/email-model.mjs.map +1 -1
  31. package/dist/internal/models/oauth-connected-model.d.mts +44 -213
  32. package/dist/internal/models/oauth-connected-model.mjs +6 -14
  33. package/dist/internal/models/oauth-connected-model.mjs.map +1 -1
  34. package/dist/internal/models/oauth-model.d.mts +95 -244
  35. package/dist/internal/models/oauth-model.mjs +28 -22
  36. package/dist/internal/models/oauth-model.mjs.map +1 -1
  37. package/dist/internal/models/passkey-model.d.mts +11 -147
  38. package/dist/internal/models/passkey-model.mjs +5 -24
  39. package/dist/internal/models/passkey-model.mjs.map +1 -1
  40. package/dist/internal/models/passkey-registration-ceremony-model.d.mts +5 -39
  41. package/dist/internal/models/passkey-write-model.d.mts +17 -75
  42. package/dist/internal/models/passkey-write-model.mjs +1 -7
  43. package/dist/internal/models/passkey-write-model.mjs.map +1 -1
  44. package/dist/internal/models/password-model.d.mts +14 -81
  45. package/dist/internal/models/password-model.mjs +1 -4
  46. package/dist/internal/models/password-model.mjs.map +1 -1
  47. package/dist/internal/models/phone-model.d.mts +86 -0
  48. package/dist/internal/models/phone-model.mjs +10 -0
  49. package/dist/internal/models/phone-model.mjs.map +1 -0
  50. package/dist/internal/models/proof-model.d.mts +43 -272
  51. package/dist/internal/models/proof-model.mjs +2 -10
  52. package/dist/internal/models/proof-model.mjs.map +1 -1
  53. package/dist/internal/models/session-model.d.mts +74 -93
  54. package/dist/internal/models/session-model.mjs +3 -11
  55. package/dist/internal/models/session-model.mjs.map +1 -1
  56. package/dist/internal/models/step-up-model.d.mts +12 -50
  57. package/dist/internal/models/step-up-model.mjs +2 -4
  58. package/dist/internal/models/step-up-model.mjs.map +1 -1
  59. package/dist/internal/models/totp-model.d.mts +76 -0
  60. package/dist/internal/models/totp-model.mjs +10 -0
  61. package/dist/internal/models/totp-model.mjs.map +1 -0
  62. package/dist/internal/native-sql-table.d.mts +21 -4
  63. package/dist/internal/native-sql-table.mjs +9 -5
  64. package/dist/internal/native-sql-table.mjs.map +1 -1
  65. package/dist/internal/oauth/native-accounts.d.mts +17 -0
  66. package/dist/internal/oauth/native-accounts.mjs +290 -0
  67. package/dist/internal/oauth/native-accounts.mjs.map +1 -0
  68. package/dist/internal/oauth/native-connected-state.d.mts +11 -0
  69. package/dist/internal/oauth/native-connected-state.mjs +146 -0
  70. package/dist/internal/oauth/native-connected-state.mjs.map +1 -0
  71. package/dist/internal/oauth/native-connected.d.mts +15 -0
  72. package/dist/internal/oauth/native-connected.mjs +462 -0
  73. package/dist/internal/oauth/native-connected.mjs.map +1 -0
  74. package/dist/internal/oauth/native-flow.mjs +138 -0
  75. package/dist/internal/oauth/native-flow.mjs.map +1 -0
  76. package/dist/internal/oauth/native-layers.d.mts +24 -0
  77. package/dist/internal/oauth/native-layers.mjs +13 -0
  78. package/dist/internal/oauth/native-layers.mjs.map +1 -0
  79. package/dist/internal/oauth/native-mutation.mjs +122 -0
  80. package/dist/internal/oauth/native-mutation.mjs.map +1 -0
  81. package/dist/internal/oauth/native-registration.d.mts +24 -0
  82. package/dist/internal/oauth/native-registration.mjs +328 -0
  83. package/dist/internal/oauth/native-registration.mjs.map +1 -0
  84. package/dist/internal/oauth/native-revocations.d.mts +17 -0
  85. package/dist/internal/oauth/native-revocations.mjs +106 -0
  86. package/dist/internal/oauth/native-revocations.mjs.map +1 -0
  87. package/dist/internal/oauth/native-sign-in.d.mts +17 -0
  88. package/dist/internal/oauth/native-sign-in.mjs +50 -0
  89. package/dist/internal/oauth/native-sign-in.mjs.map +1 -0
  90. package/dist/internal/oauth/native-state.d.mts +10 -0
  91. package/dist/internal/oauth/native-state.mjs +214 -0
  92. package/dist/internal/oauth/native-state.mjs.map +1 -0
  93. package/dist/internal/oauth/state.d.mts +10 -0
  94. package/dist/internal/oauth/state.mjs +3 -27
  95. package/dist/internal/oauth/state.mjs.map +1 -1
  96. package/dist/internal/passkey-actions.mjs +55 -0
  97. package/dist/internal/passkey-actions.mjs.map +1 -0
  98. package/dist/internal/passkey-inputs.mjs +73 -0
  99. package/dist/internal/passkey-inputs.mjs.map +1 -0
  100. package/dist/internal/passkey-managed.mjs +224 -0
  101. package/dist/internal/passkey-managed.mjs.map +1 -0
  102. package/dist/internal/passkey-native-ceremony.d.mts +35 -0
  103. package/dist/internal/passkey-native-ceremony.mjs +38 -0
  104. package/dist/internal/passkey-native-ceremony.mjs.map +1 -0
  105. package/dist/internal/passkey-native-flow.mjs +91 -0
  106. package/dist/internal/passkey-native-flow.mjs.map +1 -0
  107. package/dist/internal/passkey-native-registration.d.mts +10 -0
  108. package/dist/internal/passkey-native-registration.mjs +114 -0
  109. package/dist/internal/passkey-native-registration.mjs.map +1 -0
  110. package/dist/internal/passkey-native-state.d.mts +15 -0
  111. package/dist/internal/passkey-native-state.mjs +186 -0
  112. package/dist/internal/passkey-native-state.mjs.map +1 -0
  113. package/dist/internal/passkey-native-write.d.mts +82 -0
  114. package/dist/internal/passkey-native-write.mjs +330 -0
  115. package/dist/internal/passkey-native-write.mjs.map +1 -0
  116. package/dist/internal/passkey-native.d.mts +835 -0
  117. package/dist/internal/passkey-native.mjs +175 -0
  118. package/dist/internal/passkey-native.mjs.map +1 -0
  119. package/dist/internal/passkey-policy.mjs +115 -0
  120. package/dist/internal/passkey-policy.mjs.map +1 -0
  121. package/dist/internal/password-credentials.mjs +38 -9
  122. package/dist/internal/password-credentials.mjs.map +1 -1
  123. package/dist/internal/password-native.d.mts +14 -0
  124. package/dist/internal/password-native.mjs +292 -0
  125. package/dist/internal/password-native.mjs.map +1 -0
  126. package/dist/internal/password-policy.mjs +93 -0
  127. package/dist/internal/password-policy.mjs.map +1 -0
  128. package/dist/internal/password-registration-native.d.mts +22 -0
  129. package/dist/internal/password-registration-native.mjs +142 -0
  130. package/dist/internal/password-registration-native.mjs.map +1 -0
  131. package/dist/internal/persistence.d.mts +6 -19
  132. package/dist/internal/persistence.mjs +199 -166
  133. package/dist/internal/persistence.mjs.map +1 -1
  134. package/dist/internal/phone-composed.mjs +79 -0
  135. package/dist/internal/phone-composed.mjs.map +1 -0
  136. package/dist/internal/phone-native.d.mts +15 -0
  137. package/dist/internal/phone-native.mjs +354 -0
  138. package/dist/internal/phone-native.mjs.map +1 -0
  139. package/dist/internal/proof-native.d.mts +15 -0
  140. package/dist/internal/proof-native.mjs +289 -0
  141. package/dist/internal/proof-native.mjs.map +1 -0
  142. package/dist/internal/registration.mjs +50 -60
  143. package/dist/internal/registration.mjs.map +1 -1
  144. package/dist/internal/session-native-authority.d.mts +15 -0
  145. package/dist/internal/session-native-authority.mjs +91 -0
  146. package/dist/internal/session-native-authority.mjs.map +1 -0
  147. package/dist/internal/session-native-cleanup.d.mts +14 -0
  148. package/dist/internal/session-native-cleanup.mjs +48 -0
  149. package/dist/internal/session-native-cleanup.mjs.map +1 -0
  150. package/dist/internal/session-native-login.d.mts +15 -0
  151. package/dist/internal/session-native-login.mjs +87 -0
  152. package/dist/internal/session-native-login.mjs.map +1 -0
  153. package/dist/internal/session-native-pending-read.mjs +42 -0
  154. package/dist/internal/session-native-pending-read.mjs.map +1 -0
  155. package/dist/internal/session-native-pending.mjs +134 -0
  156. package/dist/internal/session-native-pending.mjs.map +1 -0
  157. package/dist/internal/session-native-record.mjs +79 -0
  158. package/dist/internal/session-native-record.mjs.map +1 -0
  159. package/dist/internal/session-native-state.mjs +130 -0
  160. package/dist/internal/session-native-state.mjs.map +1 -0
  161. package/dist/internal/session-native-stateful.d.mts +16 -0
  162. package/dist/internal/session-native-stateful.mjs +225 -0
  163. package/dist/internal/session-native-stateful.mjs.map +1 -0
  164. package/dist/internal/session-native-step-up.d.mts +15 -0
  165. package/dist/internal/session-native-step-up.mjs +212 -0
  166. package/dist/internal/session-native-step-up.mjs.map +1 -0
  167. package/dist/internal/session-native-validity.d.mts +15 -0
  168. package/dist/internal/session-native-validity.mjs +97 -0
  169. package/dist/internal/session-native-validity.mjs.map +1 -0
  170. package/dist/internal/session-policy.mjs +29 -0
  171. package/dist/internal/session-policy.mjs.map +1 -0
  172. package/dist/internal/sql-authority.d.mts +16 -0
  173. package/dist/internal/sql-authority.mjs +32 -0
  174. package/dist/internal/sql-authority.mjs.map +1 -0
  175. package/dist/internal/sql-change.mjs +21 -0
  176. package/dist/internal/sql-change.mjs.map +1 -0
  177. package/dist/internal/sql-cleanup.mjs +35 -0
  178. package/dist/internal/sql-cleanup.mjs.map +1 -0
  179. package/dist/internal/sql-commit.d.mts +72 -0
  180. package/dist/internal/sql-commit.mjs +176 -0
  181. package/dist/internal/sql-commit.mjs.map +1 -0
  182. package/dist/internal/sql-expression.d.mts +17 -0
  183. package/dist/internal/sql-expression.mjs +49 -0
  184. package/dist/internal/sql-expression.mjs.map +1 -0
  185. package/dist/internal/sql-oauth-connected-model.d.mts +7 -23
  186. package/dist/internal/sql-oauth-model.d.mts +27 -52
  187. package/dist/internal/sql-oauth-model.mjs +3 -4
  188. package/dist/internal/sql-oauth-model.mjs.map +1 -1
  189. package/dist/internal/sql-persistence.mjs +5 -9
  190. package/dist/internal/sql-persistence.mjs.map +1 -1
  191. package/dist/internal/sql-storage-validation.mjs +1 -2
  192. package/dist/internal/sql-storage-validation.mjs.map +1 -1
  193. package/dist/internal/sql-table.d.mts +3 -16
  194. package/dist/internal/sql-table.mjs +21 -42
  195. package/dist/internal/sql-table.mjs.map +1 -1
  196. package/dist/internal/standalone.mjs +2 -3
  197. package/dist/internal/standalone.mjs.map +1 -1
  198. package/dist/internal/step-up-state.mjs +5 -8
  199. package/dist/internal/step-up-state.mjs.map +1 -1
  200. package/dist/internal/storage-clock.mjs +44 -0
  201. package/dist/internal/storage-clock.mjs.map +1 -0
  202. package/dist/internal/storage-mapping.d.mts +11 -8
  203. package/dist/internal/storage-mapping.mjs +88 -302
  204. package/dist/internal/storage-mapping.mjs.map +1 -1
  205. package/dist/internal/storage-plans.mjs +15 -73
  206. package/dist/internal/storage-plans.mjs.map +1 -1
  207. package/dist/internal/storage-tables.d.mts +37 -520
  208. package/dist/internal/storage-tables.mjs +31 -211
  209. package/dist/internal/storage-tables.mjs.map +1 -1
  210. package/dist/internal/storage-validation.d.mts +1 -6
  211. package/dist/internal/storage-validation.mjs +1 -42
  212. package/dist/internal/storage-validation.mjs.map +1 -1
  213. package/dist/internal/table-model.d.mts +21 -0
  214. package/dist/internal/totp-native.d.mts +15 -0
  215. package/dist/internal/totp-native.mjs +401 -0
  216. package/dist/internal/totp-native.mjs.map +1 -0
  217. package/package.json +1 -1
  218. package/src/Adapter.ts +143 -199
  219. package/src/OAuthPersistence.ts +128 -271
  220. package/src/index.ts +1 -1
  221. package/src/internal/browser-login.ts +54 -24
  222. package/src/internal/configuration.ts +16 -31
  223. package/src/internal/d1-planning.ts +7 -0
  224. package/src/internal/email-native-state.ts +247 -0
  225. package/src/internal/email-native.ts +514 -0
  226. package/src/internal/email-policy.ts +235 -0
  227. package/src/internal/email-registration-native.ts +386 -0
  228. package/src/internal/models/email-model.ts +76 -214
  229. package/src/internal/models/oauth-connected-model.ts +50 -288
  230. package/src/internal/models/oauth-model.ts +147 -368
  231. package/src/internal/models/passkey-model.ts +11 -208
  232. package/src/internal/models/passkey-registration-ceremony-model.ts +6 -60
  233. package/src/internal/models/passkey-write-model.ts +14 -95
  234. package/src/internal/models/password-model.ts +26 -147
  235. package/src/internal/models/phone-model.ts +110 -0
  236. package/src/internal/models/proof-model.ts +48 -404
  237. package/src/internal/models/session-model.ts +102 -200
  238. package/src/internal/models/step-up-model.ts +17 -96
  239. package/src/internal/models/totp-model.ts +82 -0
  240. package/src/internal/native-sql-table.ts +32 -11
  241. package/src/internal/oauth/native-accounts.ts +576 -0
  242. package/src/internal/oauth/native-connected-state.ts +288 -0
  243. package/src/internal/oauth/native-connected.ts +888 -0
  244. package/src/internal/oauth/native-flow.ts +253 -0
  245. package/src/internal/oauth/native-layers.ts +83 -0
  246. package/src/internal/oauth/native-mutation.ts +222 -0
  247. package/src/internal/oauth/native-registration.ts +545 -0
  248. package/src/internal/oauth/native-revocations.ts +190 -0
  249. package/src/internal/oauth/native-sign-in.ts +111 -0
  250. package/src/internal/oauth/native-state.ts +346 -0
  251. package/src/internal/oauth/state.ts +2 -70
  252. package/src/internal/passkey-actions.ts +70 -0
  253. package/src/internal/passkey-inputs.ts +56 -0
  254. package/src/internal/passkey-managed.ts +360 -0
  255. package/src/internal/passkey-native-ceremony.ts +66 -0
  256. package/src/internal/passkey-native-flow.ts +140 -0
  257. package/src/internal/passkey-native-registration.ts +221 -0
  258. package/src/internal/passkey-native-state.ts +335 -0
  259. package/src/internal/passkey-native-write.ts +611 -0
  260. package/src/internal/passkey-native.ts +372 -0
  261. package/src/internal/passkey-policy.ts +246 -0
  262. package/src/internal/password-credentials.ts +52 -10
  263. package/src/internal/password-native.ts +571 -0
  264. package/src/internal/password-policy.ts +307 -0
  265. package/src/internal/password-registration-native.ts +322 -0
  266. package/src/internal/persistence.ts +336 -290
  267. package/src/internal/phone-composed.ts +86 -0
  268. package/src/internal/phone-native.ts +659 -0
  269. package/src/internal/proof-native.ts +448 -0
  270. package/src/internal/registration.ts +96 -143
  271. package/src/internal/session-native-authority.ts +247 -0
  272. package/src/internal/session-native-cleanup.ts +65 -0
  273. package/src/internal/session-native-login.ts +205 -0
  274. package/src/internal/session-native-pending-read.ts +68 -0
  275. package/src/internal/session-native-pending.ts +223 -0
  276. package/src/internal/session-native-record.ts +141 -0
  277. package/src/internal/session-native-state.ts +259 -0
  278. package/src/internal/session-native-stateful.ts +512 -0
  279. package/src/internal/session-native-step-up.ts +450 -0
  280. package/src/internal/session-native-validity.ts +208 -0
  281. package/src/internal/session-policy.ts +59 -0
  282. package/src/internal/sql-authority.ts +56 -0
  283. package/src/internal/sql-change.ts +38 -0
  284. package/src/internal/sql-cleanup.ts +56 -0
  285. package/src/internal/sql-commit.ts +435 -0
  286. package/src/internal/sql-expression.ts +94 -0
  287. package/src/internal/sql-metadata.ts +100 -0
  288. package/src/internal/sql-oauth-connected-model.ts +6 -95
  289. package/src/internal/sql-oauth-model.ts +31 -134
  290. package/src/internal/sql-persistence.ts +2 -6
  291. package/src/internal/sql-storage-validation.ts +1 -2
  292. package/src/internal/sql-table.ts +19 -52
  293. package/src/internal/standalone.ts +2 -11
  294. package/src/internal/step-up-state.ts +4 -17
  295. package/src/internal/storage-clock.ts +58 -0
  296. package/src/internal/storage-mapping.ts +125 -340
  297. package/src/internal/storage-plans.ts +14 -80
  298. package/src/internal/storage-tables.ts +28 -212
  299. package/src/internal/storage-validation.ts +0 -58
  300. package/src/internal/table-model.ts +24 -0
  301. package/src/internal/totp-native.ts +701 -0
  302. package/dist/internal/PasswordPreparedPostconditions.d.mts +0 -22
  303. package/dist/internal/PasswordPreparedPostconditions.mjs +0 -12
  304. package/dist/internal/PasswordPreparedPostconditions.mjs.map +0 -1
  305. package/dist/internal/authority-snapshot.mjs +0 -53
  306. package/dist/internal/authority-snapshot.mjs.map +0 -1
  307. package/dist/internal/email-kernel.d.mts +0 -276
  308. package/dist/internal/email-kernel.mjs +0 -497
  309. package/dist/internal/email-kernel.mjs.map +0 -1
  310. package/dist/internal/models/passkey-registration-ceremony-model.mjs +0 -18
  311. package/dist/internal/models/passkey-registration-ceremony-model.mjs.map +0 -1
  312. package/dist/internal/oauth/accounts.d.mts +0 -8
  313. package/dist/internal/oauth/accounts.mjs +0 -379
  314. package/dist/internal/oauth/accounts.mjs.map +0 -1
  315. package/dist/internal/oauth/connected-access.d.mts +0 -9
  316. package/dist/internal/oauth/connected-access.mjs +0 -229
  317. package/dist/internal/oauth/connected-access.mjs.map +0 -1
  318. package/dist/internal/oauth/connected-collection.d.mts +0 -7
  319. package/dist/internal/oauth/connected-collection.mjs +0 -214
  320. package/dist/internal/oauth/connected-collection.mjs.map +0 -1
  321. package/dist/internal/oauth/connected-custody.d.mts +0 -6
  322. package/dist/internal/oauth/connected-custody.mjs +0 -165
  323. package/dist/internal/oauth/connected-custody.mjs.map +0 -1
  324. package/dist/internal/oauth/connected-flow.d.mts +0 -7
  325. package/dist/internal/oauth/connected-flow.mjs +0 -324
  326. package/dist/internal/oauth/connected-flow.mjs.map +0 -1
  327. package/dist/internal/oauth/connected-input.mjs +0 -122
  328. package/dist/internal/oauth/connected-input.mjs.map +0 -1
  329. package/dist/internal/oauth/connected-keys.d.mts +0 -2
  330. package/dist/internal/oauth/connected-keys.mjs +0 -22
  331. package/dist/internal/oauth/connected-keys.mjs.map +0 -1
  332. package/dist/internal/oauth/connected-maintenance.d.mts +0 -9
  333. package/dist/internal/oauth/connected-maintenance.mjs +0 -226
  334. package/dist/internal/oauth/connected-maintenance.mjs.map +0 -1
  335. package/dist/internal/oauth/connected-management.d.mts +0 -9
  336. package/dist/internal/oauth/connected-management.mjs +0 -243
  337. package/dist/internal/oauth/connected-management.mjs.map +0 -1
  338. package/dist/internal/oauth/connected-reference.mjs +0 -63
  339. package/dist/internal/oauth/connected-reference.mjs.map +0 -1
  340. package/dist/internal/oauth/connected-settlement.d.mts +0 -8
  341. package/dist/internal/oauth/connected-settlement.mjs +0 -141
  342. package/dist/internal/oauth/connected-settlement.mjs.map +0 -1
  343. package/dist/internal/oauth/connected-sign-in.d.mts +0 -10
  344. package/dist/internal/oauth/connected-sign-in.mjs +0 -281
  345. package/dist/internal/oauth/connected-sign-in.mjs.map +0 -1
  346. package/dist/internal/oauth/connected-state.d.mts +0 -14
  347. package/dist/internal/oauth/connected-state.mjs +0 -469
  348. package/dist/internal/oauth/connected-state.mjs.map +0 -1
  349. package/dist/internal/oauth/connected-target.d.mts +0 -21
  350. package/dist/internal/oauth/connected-target.mjs +0 -117
  351. package/dist/internal/oauth/connected-target.mjs.map +0 -1
  352. package/dist/internal/oauth/flow.d.mts +0 -5
  353. package/dist/internal/oauth/flow.mjs +0 -279
  354. package/dist/internal/oauth/flow.mjs.map +0 -1
  355. package/dist/internal/oauth/input.mjs +0 -127
  356. package/dist/internal/oauth/input.mjs.map +0 -1
  357. package/dist/internal/oauth/owner.d.mts +0 -10
  358. package/dist/internal/oauth/owner.mjs +0 -10
  359. package/dist/internal/oauth/owner.mjs.map +0 -1
  360. package/dist/internal/oauth/query-compiler.d.mts +0 -7
  361. package/dist/internal/oauth/query-compiler.mjs +0 -9
  362. package/dist/internal/oauth/query-compiler.mjs.map +0 -1
  363. package/dist/internal/oauth/registration.d.mts +0 -7
  364. package/dist/internal/oauth/registration.mjs +0 -393
  365. package/dist/internal/oauth/registration.mjs.map +0 -1
  366. package/dist/internal/oauth/target.d.mts +0 -31
  367. package/dist/internal/oauth/target.mjs +0 -273
  368. package/dist/internal/oauth/target.mjs.map +0 -1
  369. package/dist/internal/oauth-kernel.d.mts +0 -1423
  370. package/dist/internal/oauth-kernel.mjs +0 -187
  371. package/dist/internal/oauth-kernel.mjs.map +0 -1
  372. package/dist/internal/passkey/admission.d.mts +0 -6
  373. package/dist/internal/passkey/admission.mjs +0 -220
  374. package/dist/internal/passkey/admission.mjs.map +0 -1
  375. package/dist/internal/passkey/credentials.d.mts +0 -14
  376. package/dist/internal/passkey/credentials.mjs +0 -249
  377. package/dist/internal/passkey/credentials.mjs.map +0 -1
  378. package/dist/internal/passkey/enrollment.mjs +0 -138
  379. package/dist/internal/passkey/enrollment.mjs.map +0 -1
  380. package/dist/internal/passkey/flow.d.mts +0 -21
  381. package/dist/internal/passkey/flow.mjs +0 -452
  382. package/dist/internal/passkey/flow.mjs.map +0 -1
  383. package/dist/internal/passkey/management.mjs +0 -231
  384. package/dist/internal/passkey/management.mjs.map +0 -1
  385. package/dist/internal/passkey/registration-ceremony.d.mts +0 -9
  386. package/dist/internal/passkey/registration-ceremony.mjs +0 -129
  387. package/dist/internal/passkey/registration-ceremony.mjs.map +0 -1
  388. package/dist/internal/passkey/registration-custody.d.mts +0 -2
  389. package/dist/internal/passkey/registration-custody.mjs +0 -52
  390. package/dist/internal/passkey/registration-custody.mjs.map +0 -1
  391. package/dist/internal/passkey/registration-write.mjs +0 -211
  392. package/dist/internal/passkey/registration-write.mjs.map +0 -1
  393. package/dist/internal/passkey/state.d.mts +0 -10
  394. package/dist/internal/passkey/state.mjs +0 -234
  395. package/dist/internal/passkey/state.mjs.map +0 -1
  396. package/dist/internal/passkey/target.d.mts +0 -20
  397. package/dist/internal/passkey/target.mjs +0 -200
  398. package/dist/internal/passkey/target.mjs.map +0 -1
  399. package/dist/internal/passkey/write-state.d.mts +0 -17
  400. package/dist/internal/passkey/write-state.mjs +0 -354
  401. package/dist/internal/passkey/write-state.mjs.map +0 -1
  402. package/dist/internal/passkey/write-target.mjs +0 -192
  403. package/dist/internal/passkey/write-target.mjs.map +0 -1
  404. package/dist/internal/passkey-kernel.d.mts +0 -6045
  405. package/dist/internal/passkey-kernel.mjs +0 -49
  406. package/dist/internal/passkey-kernel.mjs.map +0 -1
  407. package/dist/internal/passkeys.d.mts +0 -7
  408. package/dist/internal/passkeys.mjs +0 -387
  409. package/dist/internal/passkeys.mjs.map +0 -1
  410. package/dist/internal/password-credentials.d.mts +0 -11
  411. package/dist/internal/password-kernel.d.mts +0 -278
  412. package/dist/internal/password-kernel.mjs +0 -508
  413. package/dist/internal/password-kernel.mjs.map +0 -1
  414. package/dist/internal/phone-kernel.d.mts +0 -162
  415. package/dist/internal/phone-kernel.mjs +0 -437
  416. package/dist/internal/phone-kernel.mjs.map +0 -1
  417. package/dist/internal/proof-kernel.d.mts +0 -94
  418. package/dist/internal/proof-kernel.mjs +0 -624
  419. package/dist/internal/proof-kernel.mjs.map +0 -1
  420. package/dist/internal/query-operations.d.mts +0 -68
  421. package/dist/internal/session-kernel.d.mts +0 -62
  422. package/dist/internal/session-kernel.mjs +0 -820
  423. package/dist/internal/session-kernel.mjs.map +0 -1
  424. package/dist/internal/sql-oauth-connected-model.mjs +0 -7
  425. package/dist/internal/sql-oauth-connected-model.mjs.map +0 -1
  426. package/dist/internal/sql-query.d.mts +0 -12
  427. package/dist/internal/sql-query.mjs +0 -206
  428. package/dist/internal/sql-query.mjs.map +0 -1
  429. package/dist/internal/step-up-state.d.mts +0 -49
  430. package/dist/internal/transaction-execution-kernel.d.mts +0 -37
  431. package/dist/internal/transaction-execution-kernel.mjs +0 -120
  432. package/dist/internal/transaction-execution-kernel.mjs.map +0 -1
  433. package/dist/internal/transaction-kernel.d.mts +0 -81
  434. package/dist/internal/transaction-kernel.mjs +0 -264
  435. package/dist/internal/transaction-kernel.mjs.map +0 -1
  436. package/src/internal/PasswordPreparedPostconditions.ts +0 -30
  437. package/src/internal/authority-snapshot.ts +0 -91
  438. package/src/internal/email-kernel.ts +0 -1556
  439. package/src/internal/oauth/accounts.ts +0 -839
  440. package/src/internal/oauth/connected-access.ts +0 -388
  441. package/src/internal/oauth/connected-collection.ts +0 -345
  442. package/src/internal/oauth/connected-custody.ts +0 -308
  443. package/src/internal/oauth/connected-flow.ts +0 -562
  444. package/src/internal/oauth/connected-input.ts +0 -147
  445. package/src/internal/oauth/connected-keys.ts +0 -31
  446. package/src/internal/oauth/connected-maintenance.ts +0 -379
  447. package/src/internal/oauth/connected-management.ts +0 -391
  448. package/src/internal/oauth/connected-reference.ts +0 -135
  449. package/src/internal/oauth/connected-settlement.ts +0 -278
  450. package/src/internal/oauth/connected-sign-in.ts +0 -472
  451. package/src/internal/oauth/connected-state.ts +0 -924
  452. package/src/internal/oauth/connected-target.ts +0 -307
  453. package/src/internal/oauth/flow.ts +0 -505
  454. package/src/internal/oauth/input.ts +0 -201
  455. package/src/internal/oauth/owner.ts +0 -22
  456. package/src/internal/oauth/query-compiler.ts +0 -15
  457. package/src/internal/oauth/registration.ts +0 -676
  458. package/src/internal/oauth/target.ts +0 -803
  459. package/src/internal/oauth-kernel.ts +0 -294
  460. package/src/internal/passkey/admission.ts +0 -368
  461. package/src/internal/passkey/credentials.ts +0 -511
  462. package/src/internal/passkey/enrollment.ts +0 -326
  463. package/src/internal/passkey/flow.ts +0 -1062
  464. package/src/internal/passkey/management.ts +0 -426
  465. package/src/internal/passkey/registration-ceremony.ts +0 -283
  466. package/src/internal/passkey/registration-custody.ts +0 -91
  467. package/src/internal/passkey/registration-write.ts +0 -426
  468. package/src/internal/passkey/state.ts +0 -351
  469. package/src/internal/passkey/target.ts +0 -598
  470. package/src/internal/passkey/write-state.ts +0 -692
  471. package/src/internal/passkey/write-target.ts +0 -450
  472. package/src/internal/passkey-kernel.ts +0 -112
  473. package/src/internal/passkeys.ts +0 -652
  474. package/src/internal/password-kernel.ts +0 -1523
  475. package/src/internal/phone-kernel.ts +0 -872
  476. package/src/internal/proof-kernel.ts +0 -1992
  477. package/src/internal/query-operations.ts +0 -91
  478. package/src/internal/session-kernel.ts +0 -2406
  479. package/src/internal/sql-query.ts +0 -304
  480. package/src/internal/transaction-execution-kernel.ts +0 -335
  481. package/src/internal/transaction-kernel.ts +0 -603
@@ -1,9 +1,10 @@
1
+ import { SqlExpression, TableModel } from "../table-model.mjs";
1
2
  import { PersistenceMappingError } from "../mapping-error.mjs";
2
- import { SqlExpression, TableModel } from "../query-operations.mjs";
3
3
  import { SubjectIdCodec } from "./common.mjs";
4
+ import { ProofClock } from "./proof-model.mjs";
4
5
  import { DateTime, Effect } from "effect";
6
+ import { AuthenticationFlowId, AuthenticationRequirement, PendingAuthenticationRecord, SecurityRevision, SessionId, StatefulSessionRecord } from "@yielded/auth/Sessions";
5
7
  import { TokenDigest } from "@yielded/auth/Schema";
6
- import { AuthenticationEvidence, AuthenticationRequirement, PendingAuthenticationRecord, PendingAuthenticationState, SecurityRevision, SessionId, StatefulSessionRecord } from "@yielded/auth/Sessions";
7
8
  //#region src/internal/models/session-model.d.ts
8
9
  type ColumnKey<T extends TableModel> = T["column"];
9
10
  export interface SessionIdCodec<NativeId> {
@@ -17,8 +18,12 @@ export interface SessionSubjectTables<Subject extends TableModel, NativeId> {
17
18
  readonly id: ColumnKey<Subject>;
18
19
  readonly status: ColumnKey<Subject>;
19
20
  readonly securityRevision: ColumnKey<Subject>;
21
+ readonly activeStatusValue: unknown;
20
22
  readonly isActiveStatus: (value: unknown) => boolean;
21
23
  readonly decodeRequirement: (row: Subject["select"]) => Effect.Effect<AuthenticationRequirement, PersistenceMappingError>;
24
+ /** Required for D1 authority writes. Declare every mutable subject input of
25
+ * decodeRequirement; [] explicitly declares a constant requirement. */
26
+ readonly requirementColumns?: ReadonlyArray<ColumnKey<Subject>>;
22
27
  readonly nextSecurityRevision?: (current: SecurityRevision) => Effect.Effect<SecurityRevision, PersistenceMappingError>;
23
28
  readonly nextSecurityRevisionSync?: (current: SecurityRevision) => SecurityRevision;
24
29
  };
@@ -30,43 +35,29 @@ export interface SessionAuthorityTables<Subject extends TableModel, Credential e
30
35
  readonly subjectId: ColumnKey<Credential>;
31
36
  readonly credentialId: ColumnKey<Credential>;
32
37
  readonly revision: ColumnKey<Credential>;
33
- /** Optional consumer status predicate; omitted means every stored credential row is active. */
38
+ /** Omitted status means every row is an active credential. */
34
39
  readonly status?: ColumnKey<Credential>;
40
+ readonly activeStatusValue?: unknown;
35
41
  readonly isActiveStatus?: (value: unknown) => boolean;
36
42
  };
37
43
  }
38
- export interface SessionFlowTables<Flow extends TableModel, NativeSubjectId> {
39
- readonly flow: {
40
- readonly table: Flow["table"];
41
- readonly flowId: ColumnKey<Flow>;
42
- readonly subjectId: ColumnKey<Flow>;
43
- readonly state: ColumnKey<Flow>;
44
- readonly pendingDigest: ColumnKey<Flow>;
45
- readonly dedupUntil: ColumnKey<Flow>;
46
- readonly pendingStateValue: unknown;
47
- readonly establishedStateValue: unknown;
48
- readonly encodeInstant: (instant: DateTime.Utc) => unknown;
49
- readonly decodeInstant: (native: unknown) => Effect.Effect<DateTime.Utc, PersistenceMappingError>;
50
- readonly encodePendingInsert: (input: {
51
- readonly evidence: AuthenticationEvidence;
52
- readonly subjectId: NativeSubjectId;
53
- readonly pendingDigest: TokenDigest;
54
- readonly dedupUntil: DateTime.Utc;
55
- }) => Flow["insert"];
56
- readonly encodeEstablishedInsert: (input: {
57
- readonly evidence: AuthenticationEvidence;
58
- readonly subjectId: NativeSubjectId;
59
- readonly dedupUntil: DateTime.Utc;
60
- }) => Flow["insert"];
44
+ export interface SessionExecution<Expression extends SqlExpression = SqlExpression> {
45
+ /** Exact session module scope for pending rows and revocation tombstones. */
46
+ readonly moduleId: string;
47
+ readonly clock: ProofClock<Expression>;
48
+ /** D1 mappings must use the authoritative primary database. */
49
+ readonly d1?: {
50
+ readonly primary: true;
61
51
  };
52
+ /** Match only the declared unique keys, never generic SQL failures. */
53
+ readonly isConstraintConflict: (cause: unknown) => boolean;
62
54
  }
63
- export interface StatefulSessionTables<Claims, Session extends TableModel, Flow extends TableModel, NativeSubjectId, NativeSessionId> extends SessionFlowTables<Flow, NativeSubjectId> {
55
+ export interface StatefulSessionTables<Claims, Session extends TableModel, NativeSubjectId, NativeSessionId> {
64
56
  readonly session: {
65
57
  readonly table: Session["table"];
66
58
  readonly sessionId: ColumnKey<Session>;
67
59
  readonly subjectId: ColumnKey<Session>;
68
60
  readonly digest: ColumnKey<Session>;
69
- readonly version: ColumnKey<Session>;
70
61
  readonly securityRevision: ColumnKey<Session>;
71
62
  readonly issuedAt: ColumnKey<Session>;
72
63
  readonly expiresAt: ColumnKey<Session>;
@@ -76,51 +67,67 @@ export interface StatefulSessionTables<Claims, Session extends TableModel, Flow
76
67
  readonly subjectId: NativeSubjectId;
77
68
  readonly sessionId: NativeSessionId;
78
69
  }) => Session["insert"];
79
- /** Persist the prepared credentialVersion and retain exact private provenance. */
70
+ /** Replace prepared metadata and retain exact private provenance. Digest binds the immutable source metadata. */
80
71
  readonly encodeRotation: (record: StatefulSessionRecord<Claims>) => Partial<Session["insert"]>;
81
72
  readonly decode: (row: Session["select"]) => Effect.Effect<StatefulSessionRecord<Claims>, PersistenceMappingError>;
82
73
  readonly allocateId?: Effect.Effect<NativeSessionId, PersistenceMappingError>;
83
74
  readonly allocateIdSync?: () => NativeSessionId;
84
- readonly allocateVersion?: Effect.Effect<SecurityRevision, PersistenceMappingError>;
85
- readonly allocateVersionSync?: () => SecurityRevision;
86
75
  };
87
76
  readonly sessionId: SessionIdCodec<NativeSessionId>;
88
77
  }
89
- export interface PendingAuthenticationTables<Claims, Pending extends TableModel, Flow extends TableModel, NativeSubjectId> extends SessionFlowTables<Flow, NativeSubjectId> {
78
+ export interface SessionPendingInsert<NativeId> {
79
+ readonly moduleId: string;
80
+ readonly kind: "Login" | "StepUp";
81
+ readonly digest: TokenDigest;
82
+ readonly version: SecurityRevision;
83
+ readonly flowId: AuthenticationFlowId;
84
+ readonly subjectId: NativeId;
85
+ readonly bindingDigest: TokenDigest;
86
+ readonly snapshot: string;
87
+ readonly expiresAt: DateTime.Utc;
88
+ readonly attemptLimit: number;
89
+ }
90
+ /** One physical table and one SQL owner for Login and StepUp. The adapter sets
91
+ * every guard column and binds kind before decoding, charging or consuming. */
92
+ export interface SessionPendingTables<Pending extends TableModel, NativeSubjectId> {
90
93
  readonly pending: {
91
94
  readonly table: Pending["table"];
95
+ readonly moduleId: ColumnKey<Pending>;
96
+ readonly kind: ColumnKey<Pending>;
92
97
  readonly digest: ColumnKey<Pending>;
93
98
  readonly version: ColumnKey<Pending>;
94
99
  readonly flowId: ColumnKey<Pending>;
95
100
  readonly subjectId: ColumnKey<Pending>;
96
101
  readonly bindingDigest: ColumnKey<Pending>;
102
+ readonly snapshot: ColumnKey<Pending>;
97
103
  readonly expiresAt: ColumnKey<Pending>;
98
104
  readonly attemptLimit: ColumnKey<Pending>;
99
105
  readonly failedAttempts: ColumnKey<Pending>;
100
106
  readonly consumed: ColumnKey<Pending>;
101
107
  readonly encodeInstant: (instant: DateTime.Utc) => unknown;
102
- readonly encodeInsert: (record: PendingAuthenticationRecord<Claims>, input: {
103
- readonly subjectId: NativeSubjectId;
104
- readonly failedAttempts: 0;
105
- readonly consumed: false;
106
- }) => Pending["insert"];
107
- readonly decode: (row: Pending["select"]) => Effect.Effect<PendingAuthenticationRecord<Claims>, PersistenceMappingError>;
108
- /** Decodes original evidence and storage guards only. The internal pending
109
- * context lookup must not execute unrelated consumer Claims transforms. */
110
- readonly decodeContext: (row: Pending["select"]) => Effect.Effect<PendingAuthenticationState, PersistenceMappingError>;
108
+ readonly encodeInsert: (input: SessionPendingInsert<NativeSubjectId>) => Pending["insert"];
111
109
  readonly allocateVersion?: Effect.Effect<SecurityRevision, PersistenceMappingError>;
112
110
  readonly allocateVersionSync?: () => SecurityRevision;
113
111
  };
114
112
  }
113
+ export interface PendingAuthenticationTables<Claims, Pending extends TableModel, NativeSubjectId> extends SessionPendingTables<Pending, NativeSubjectId> {
114
+ /** Canonical JSON of the full record; the consumer Schema owns Claims encoding. */
115
+ readonly login: {
116
+ readonly encode: (record: PendingAuthenticationRecord<Claims>) => Effect.Effect<string, PersistenceMappingError>;
117
+ readonly decode: (snapshot: unknown) => Effect.Effect<PendingAuthenticationRecord<Claims>, PersistenceMappingError>;
118
+ };
119
+ }
115
120
  export interface SignedSessionValidityTables<Tombstone extends TableModel, NativeSubjectId, NativeSessionId> {
116
121
  readonly tombstone: {
117
122
  readonly table: Tombstone["table"];
123
+ readonly moduleId: ColumnKey<Tombstone>;
118
124
  readonly subjectId: ColumnKey<Tombstone>;
119
125
  readonly sessionId: ColumnKey<Tombstone>;
120
126
  readonly absoluteExpiresAt: ColumnKey<Tombstone>;
121
127
  readonly encodeInstant: (instant: DateTime.Utc) => unknown;
122
128
  readonly decodeInstant: (native: unknown) => Effect.Effect<DateTime.Utc, PersistenceMappingError>;
123
129
  readonly encodeInsert: (input: {
130
+ readonly moduleId: string;
124
131
  readonly subjectId: NativeSubjectId;
125
132
  readonly sessionId: NativeSessionId;
126
133
  readonly absoluteExpiresAt: DateTime.Utc;
@@ -128,72 +135,46 @@ export interface SignedSessionValidityTables<Tombstone extends TableModel, Nativ
128
135
  };
129
136
  readonly sessionId: SessionIdCodec<NativeSessionId>;
130
137
  }
131
- export interface RequiredSessionConstraints {
138
+ export declare const requiredSessionConstraints: {
132
139
  readonly sessionDigest: "unique(session.digest)";
133
- readonly flowId: "unique(flow.flowId)";
134
- }
135
- export interface RequiredPendingAuthenticationConstraints {
140
+ };
141
+ export declare const requiredPendingAuthenticationConstraints: {
136
142
  readonly pendingDigest: "unique(pending.digest)";
137
- readonly pendingFlow: "unique(pending.flowId)";
138
- readonly flowId: "unique(flow.flowId)";
139
- }
140
- export interface RequiredStatefulPendingConstraints extends RequiredSessionConstraints, RequiredPendingAuthenticationConstraints {}
141
- export interface RequiredSignedValidityConstraints {
142
- readonly tombstoneOwner: "unique(tombstone.subjectId,tombstone.sessionId)";
143
- }
144
- export declare const requiredSessionConstraints: RequiredSessionConstraints;
145
- export declare const requiredPendingAuthenticationConstraints: RequiredPendingAuthenticationConstraints;
146
- export declare const requiredStatefulPendingConstraints: RequiredStatefulPendingConstraints;
147
- export declare const requiredSignedValidityConstraints: RequiredSignedValidityConstraints;
148
- export interface SessionConstraintClassifier {
149
- /**
150
- * Match only the named unique constraints declared by this mapping. Broad
151
- * SQL/constraint classifiers can relabel application or NOT NULL failures as
152
- * a domain conflict.
153
- */
154
- readonly isConstraintConflict: (cause: unknown) => boolean;
155
- }
156
- export type AuthenticationAuthorityMapping<Claims, Subject extends TableModel, Credential extends TableModel, Flow extends TableModel, Pending extends TableModel, NativeSubjectId> = SessionAuthorityTables<Subject, Credential, NativeSubjectId> & SessionConstraintClassifier & ({
157
- /** Omit for single-factor authority installations. Pending input then fails closed. */
143
+ };
144
+ export declare const requiredStatefulPendingConstraints: {
145
+ readonly sessionDigest: "unique(session.digest)";
146
+ readonly pendingDigest: "unique(pending.digest)";
147
+ };
148
+ export declare const requiredSignedValidityConstraints: {
149
+ readonly tombstoneOwner: "unique(tombstone.moduleId,tombstone.subjectId,tombstone.sessionId)";
150
+ };
151
+ export type RequiredSessionConstraints = typeof requiredSessionConstraints;
152
+ export type RequiredPendingAuthenticationConstraints = typeof requiredPendingAuthenticationConstraints;
153
+ export type RequiredStatefulPendingConstraints = typeof requiredStatefulPendingConstraints;
154
+ export type RequiredSignedValidityConstraints = typeof requiredSignedValidityConstraints;
155
+ export type AuthenticationAuthorityMapping<Claims, Subject extends TableModel, Credential extends TableModel, Pending extends TableModel, NativeSubjectId, Expression extends SqlExpression = SqlExpression> = SessionAuthorityTables<Subject, Credential, NativeSubjectId> & SessionExecution<Expression> & ({
158
156
  readonly pending?: undefined;
159
157
  } | {
160
- readonly pending: PendingAuthenticationTables<Claims, Pending, Flow, NativeSubjectId>;
158
+ readonly pending: PendingAuthenticationTables<Claims, Pending, NativeSubjectId>;
161
159
  readonly constraints: RequiredPendingAuthenticationConstraints;
162
160
  });
163
- export type StatefulSessionMapping<Claims, Subject extends TableModel, Credential extends TableModel, Session extends TableModel, Flow extends TableModel, Pending extends TableModel, NativeSubjectId, NativeSessionId> = SessionAuthorityTables<Subject, Credential, NativeSubjectId> & StatefulSessionTables<Claims, Session, Flow, NativeSubjectId, NativeSessionId> & SessionConstraintClassifier & ({
164
- /** Omit when this session module does not support pending MFA completion. */
161
+ export type StatefulSessionMapping<Claims, Subject extends TableModel, Credential extends TableModel, Session extends TableModel, Pending extends TableModel, NativeSubjectId, NativeSessionId, Expression extends SqlExpression = SqlExpression> = SessionAuthorityTables<Subject, Credential, NativeSubjectId> & StatefulSessionTables<Claims, Session, NativeSubjectId, NativeSessionId> & SessionExecution<Expression> & ({
165
162
  readonly pending?: undefined;
166
163
  readonly constraints: RequiredSessionConstraints;
167
164
  } | {
168
- readonly pending: PendingAuthenticationTables<Claims, Pending, Flow, NativeSubjectId>["pending"];
165
+ readonly pending: PendingAuthenticationTables<Claims, Pending, NativeSubjectId>;
169
166
  readonly constraints: RequiredStatefulPendingConstraints;
170
167
  });
171
- export type PendingAuthenticationMapping<Claims, Subject extends TableModel, Credential extends TableModel, Pending extends TableModel, Flow extends TableModel, NativeSubjectId> = SessionAuthorityTables<Subject, Credential, NativeSubjectId> & PendingAuthenticationTables<Claims, Pending, Flow, NativeSubjectId> & SessionConstraintClassifier & {
168
+ export type PendingAuthenticationMapping<Claims, Subject extends TableModel, Credential extends TableModel, Pending extends TableModel, NativeSubjectId, Expression extends SqlExpression = SqlExpression> = SessionAuthorityTables<Subject, Credential, NativeSubjectId> & PendingAuthenticationTables<Claims, Pending, NativeSubjectId> & SessionExecution<Expression> & {
172
169
  readonly constraints: RequiredPendingAuthenticationConstraints;
173
170
  };
174
- export type SignedSessionValidityMapping<Subject extends TableModel, Tombstone extends TableModel, NativeSubjectId, NativeSessionId> = SessionSubjectTables<Subject, NativeSubjectId> & SignedSessionValidityTables<Tombstone, NativeSubjectId, NativeSessionId> & SessionConstraintClassifier & {
171
+ export type SignedSessionValidityMapping<Subject extends TableModel, Tombstone extends TableModel, NativeSubjectId, NativeSessionId, Expression extends SqlExpression = SqlExpression> = SessionSubjectTables<Subject, NativeSubjectId> & SignedSessionValidityTables<Tombstone, NativeSubjectId, NativeSessionId> & SessionExecution<Expression> & {
175
172
  readonly constraints: RequiredSignedValidityConstraints;
176
173
  };
177
- /** D1 evaluates these expressions inside the atomic batch, after queueing delay.
178
- * `engineNow` must use the exact native representation of every mapped instant
179
- * column. `engineNowMillis` is Unix epoch milliseconds for proof freshness.
180
- * Changes to the consumer's factor policy MUST bump subject.securityRevision.
181
- * Supply the authoritative primary D1 database, never a replica-affined
182
- * `withSession` handle, because verification and security revision reads must
183
- * observe completed revocation writes across clients.
184
- */
185
- export interface D1SessionClockMapping<Expression extends SqlExpression = SqlExpression> {
186
- readonly d1: {
187
- readonly engineNow: Expression;
188
- readonly engineNowMillis: Expression;
189
- readonly activeSubjectStatusValue: unknown;
190
- /** Required when `credential.status` is mapped. */
191
- readonly activeCredentialStatusValue?: unknown;
192
- };
193
- }
194
- export type D1AuthenticationAuthorityMapping<Claims, Subject extends TableModel, Credential extends TableModel, Flow extends TableModel, Pending extends TableModel, NativeSubjectId, Expression extends SqlExpression = SqlExpression> = AuthenticationAuthorityMapping<Claims, Subject, Credential, Flow, Pending, NativeSubjectId> & D1SessionClockMapping<Expression>;
195
- export type D1PendingAuthenticationMapping<Claims, Subject extends TableModel, Credential extends TableModel, Pending extends TableModel, Flow extends TableModel, NativeSubjectId, Expression extends SqlExpression = SqlExpression> = PendingAuthenticationMapping<Claims, Subject, Credential, Pending, Flow, NativeSubjectId> & D1SessionClockMapping<Expression>;
196
- export type D1StatefulSessionMapping<Claims, Subject extends TableModel, Credential extends TableModel, Session extends TableModel, Flow extends TableModel, Pending extends TableModel, NativeSubjectId, NativeSessionId, Expression extends SqlExpression = SqlExpression> = StatefulSessionMapping<Claims, Subject, Credential, Session, Flow, Pending, NativeSubjectId, NativeSessionId> & D1SessionClockMapping<Expression>;
197
- export type D1SignedSessionValidityMapping<Subject extends TableModel, Tombstone extends TableModel, NativeSubjectId, NativeSessionId, Expression extends SqlExpression = SqlExpression> = SignedSessionValidityMapping<Subject, Tombstone, NativeSubjectId, NativeSessionId> & D1SessionClockMapping<Expression>;
174
+ /** Maintenance uses the same mapped rows and one total per-call deletion limit. */
175
+ export type SessionCleanupMapping<Pending extends TableModel, Tombstone extends TableModel, NativeSubjectId, NativeSessionId, Expression extends SqlExpression = SqlExpression> = Pick<SessionExecution<Expression>, "moduleId" | "clock" | "d1"> & {
176
+ readonly pending?: SessionPendingTables<Pending, NativeSubjectId>["pending"];
177
+ readonly tombstone?: SignedSessionValidityTables<Tombstone, NativeSubjectId, NativeSessionId>["tombstone"];
178
+ };
198
179
  //#endregion
199
180
  //# sourceMappingURL=session-model.d.mts.map
@@ -1,19 +1,11 @@
1
- import "@yielded/auth/Sessions";
2
1
  //#region src/internal/models/session-model.ts
3
- const requiredSessionConstraints = {
4
- sessionDigest: "unique(session.digest)",
5
- flowId: "unique(flow.flowId)"
6
- };
7
- const requiredPendingAuthenticationConstraints = {
8
- pendingDigest: "unique(pending.digest)",
9
- pendingFlow: "unique(pending.flowId)",
10
- flowId: "unique(flow.flowId)"
11
- };
2
+ const requiredSessionConstraints = { sessionDigest: "unique(session.digest)" };
3
+ const requiredPendingAuthenticationConstraints = { pendingDigest: "unique(pending.digest)" };
12
4
  const requiredStatefulPendingConstraints = {
13
5
  ...requiredSessionConstraints,
14
6
  ...requiredPendingAuthenticationConstraints
15
7
  };
16
- const requiredSignedValidityConstraints = { tombstoneOwner: "unique(tombstone.subjectId,tombstone.sessionId)" };
8
+ const requiredSignedValidityConstraints = { tombstoneOwner: "unique(tombstone.moduleId,tombstone.subjectId,tombstone.sessionId)" };
17
9
  //#endregion
18
10
  export { requiredPendingAuthenticationConstraints, requiredSessionConstraints, requiredSignedValidityConstraints, requiredStatefulPendingConstraints };
19
11
 
@@ -1 +1 @@
1
- {"version":3,"file":"session-model.mjs","names":[],"sources":["../../../src/internal/models/session-model.ts"],"sourcesContent":["import type { TokenDigest } from \"@yielded/auth/Schema\";\nimport {\n type AuthenticationRequirement,\n type AuthenticationEvidence,\n type SecurityRevision,\n type SessionId,\n type PendingAuthenticationRecord,\n type PendingAuthenticationState,\n type StatefulSessionRecord,\n} from \"@yielded/auth/Sessions\";\nimport type { DateTime, Effect } from \"effect\";\n\nimport type { TableModel as Table, SqlExpression } from \"../query-operations\";\nimport type { PersistenceMappingError, SubjectIdCodec } from \"./common\";\n\ntype ColumnKey<T extends Table> = T[\"column\"];\n\nexport interface SessionIdCodec<NativeId> {\n readonly toNative: (id: SessionId) => Effect.Effect<NativeId, PersistenceMappingError>;\n readonly toSession: (id: NativeId) => Effect.Effect<SessionId, PersistenceMappingError>;\n readonly equals: (left: NativeId, right: NativeId) => boolean;\n}\n\nexport interface SessionSubjectTables<Subject extends Table, NativeId> {\n readonly subject: {\n readonly table: Subject[\"table\"];\n readonly id: ColumnKey<Subject>;\n readonly status: ColumnKey<Subject>;\n readonly securityRevision: ColumnKey<Subject>;\n readonly isActiveStatus: (value: unknown) => boolean;\n readonly decodeRequirement: (\n row: Subject[\"select\"],\n ) => Effect.Effect<AuthenticationRequirement, PersistenceMappingError>;\n readonly nextSecurityRevision?: (\n current: SecurityRevision,\n ) => Effect.Effect<SecurityRevision, PersistenceMappingError>;\n readonly nextSecurityRevisionSync?: (current: SecurityRevision) => SecurityRevision;\n };\n readonly subjectId: SubjectIdCodec<NativeId>;\n}\n\nexport interface SessionAuthorityTables<\n Subject extends Table,\n Credential extends Table,\n NativeId,\n> extends SessionSubjectTables<Subject, NativeId> {\n readonly credential: {\n readonly table: Credential[\"table\"];\n readonly subjectId: ColumnKey<Credential>;\n readonly credentialId: ColumnKey<Credential>;\n readonly revision: ColumnKey<Credential>;\n /** Optional consumer status predicate; omitted means every stored credential row is active. */\n readonly status?: ColumnKey<Credential>;\n readonly isActiveStatus?: (value: unknown) => boolean;\n };\n}\n\nexport interface SessionFlowTables<Flow extends Table, NativeSubjectId> {\n readonly flow: {\n readonly table: Flow[\"table\"];\n readonly flowId: ColumnKey<Flow>;\n readonly subjectId: ColumnKey<Flow>;\n readonly state: ColumnKey<Flow>;\n readonly pendingDigest: ColumnKey<Flow>;\n readonly dedupUntil: ColumnKey<Flow>;\n readonly pendingStateValue: unknown;\n readonly establishedStateValue: unknown;\n readonly encodeInstant: (instant: DateTime.Utc) => unknown;\n readonly decodeInstant: (\n native: unknown,\n ) => Effect.Effect<DateTime.Utc, PersistenceMappingError>;\n readonly encodePendingInsert: (input: {\n readonly evidence: AuthenticationEvidence;\n readonly subjectId: NativeSubjectId;\n readonly pendingDigest: TokenDigest;\n readonly dedupUntil: DateTime.Utc;\n }) => Flow[\"insert\"];\n readonly encodeEstablishedInsert: (input: {\n readonly evidence: AuthenticationEvidence;\n readonly subjectId: NativeSubjectId;\n readonly dedupUntil: DateTime.Utc;\n }) => Flow[\"insert\"];\n };\n}\n\nexport interface StatefulSessionTables<\n Claims,\n Session extends Table,\n Flow extends Table,\n NativeSubjectId,\n NativeSessionId,\n> extends SessionFlowTables<Flow, NativeSubjectId> {\n readonly session: {\n readonly table: Session[\"table\"];\n readonly sessionId: ColumnKey<Session>;\n readonly subjectId: ColumnKey<Session>;\n readonly digest: ColumnKey<Session>;\n readonly version: ColumnKey<Session>;\n readonly securityRevision: ColumnKey<Session>;\n readonly issuedAt: ColumnKey<Session>;\n readonly expiresAt: ColumnKey<Session>;\n readonly absoluteExpiresAt: ColumnKey<Session>;\n readonly encodeInstant: (instant: DateTime.Utc) => unknown;\n readonly encodeInsert: (\n record: StatefulSessionRecord<Claims>,\n ids: {\n readonly subjectId: NativeSubjectId;\n readonly sessionId: NativeSessionId;\n },\n ) => Session[\"insert\"];\n /** Persist the prepared credentialVersion and retain exact private provenance. */\n readonly encodeRotation: (record: StatefulSessionRecord<Claims>) => Partial<Session[\"insert\"]>;\n readonly decode: (\n row: Session[\"select\"],\n ) => Effect.Effect<StatefulSessionRecord<Claims>, PersistenceMappingError>;\n readonly allocateId?: Effect.Effect<NativeSessionId, PersistenceMappingError>;\n readonly allocateIdSync?: () => NativeSessionId;\n readonly allocateVersion?: Effect.Effect<SecurityRevision, PersistenceMappingError>;\n readonly allocateVersionSync?: () => SecurityRevision;\n };\n readonly sessionId: SessionIdCodec<NativeSessionId>;\n}\n\nexport interface PendingAuthenticationTables<\n Claims,\n Pending extends Table,\n Flow extends Table,\n NativeSubjectId,\n> extends SessionFlowTables<Flow, NativeSubjectId> {\n readonly pending: {\n readonly table: Pending[\"table\"];\n readonly digest: ColumnKey<Pending>;\n readonly version: ColumnKey<Pending>;\n readonly flowId: ColumnKey<Pending>;\n readonly subjectId: ColumnKey<Pending>;\n readonly bindingDigest: ColumnKey<Pending>;\n readonly expiresAt: ColumnKey<Pending>;\n readonly attemptLimit: ColumnKey<Pending>;\n readonly failedAttempts: ColumnKey<Pending>;\n readonly consumed: ColumnKey<Pending>;\n readonly encodeInstant: (instant: DateTime.Utc) => unknown;\n readonly encodeInsert: (\n record: PendingAuthenticationRecord<Claims>,\n input: {\n readonly subjectId: NativeSubjectId;\n readonly failedAttempts: 0;\n readonly consumed: false;\n },\n ) => Pending[\"insert\"];\n readonly decode: (\n row: Pending[\"select\"],\n ) => Effect.Effect<PendingAuthenticationRecord<Claims>, PersistenceMappingError>;\n /** Decodes original evidence and storage guards only. The internal pending\n * context lookup must not execute unrelated consumer Claims transforms. */\n readonly decodeContext: (\n row: Pending[\"select\"],\n ) => Effect.Effect<PendingAuthenticationState, PersistenceMappingError>;\n readonly allocateVersion?: Effect.Effect<SecurityRevision, PersistenceMappingError>;\n readonly allocateVersionSync?: () => SecurityRevision;\n };\n}\n\nexport interface SignedSessionValidityTables<\n Tombstone extends Table,\n NativeSubjectId,\n NativeSessionId,\n> {\n readonly tombstone: {\n readonly table: Tombstone[\"table\"];\n readonly subjectId: ColumnKey<Tombstone>;\n readonly sessionId: ColumnKey<Tombstone>;\n readonly absoluteExpiresAt: ColumnKey<Tombstone>;\n readonly encodeInstant: (instant: DateTime.Utc) => unknown;\n readonly decodeInstant: (\n native: unknown,\n ) => Effect.Effect<DateTime.Utc, PersistenceMappingError>;\n readonly encodeInsert: (input: {\n readonly subjectId: NativeSubjectId;\n readonly sessionId: NativeSessionId;\n readonly absoluteExpiresAt: DateTime.Utc;\n }) => Tombstone[\"insert\"];\n };\n readonly sessionId: SessionIdCodec<NativeSessionId>;\n}\n\nexport interface RequiredSessionConstraints {\n readonly sessionDigest: \"unique(session.digest)\";\n readonly flowId: \"unique(flow.flowId)\";\n}\n\nexport interface RequiredPendingAuthenticationConstraints {\n readonly pendingDigest: \"unique(pending.digest)\";\n readonly pendingFlow: \"unique(pending.flowId)\";\n readonly flowId: \"unique(flow.flowId)\";\n}\n\nexport interface RequiredStatefulPendingConstraints\n extends RequiredSessionConstraints, RequiredPendingAuthenticationConstraints {}\n\nexport interface RequiredSignedValidityConstraints {\n readonly tombstoneOwner: \"unique(tombstone.subjectId,tombstone.sessionId)\";\n}\n\nexport const requiredSessionConstraints: RequiredSessionConstraints = {\n sessionDigest: \"unique(session.digest)\",\n flowId: \"unique(flow.flowId)\",\n};\n\nexport const requiredPendingAuthenticationConstraints: RequiredPendingAuthenticationConstraints = {\n pendingDigest: \"unique(pending.digest)\",\n pendingFlow: \"unique(pending.flowId)\",\n flowId: \"unique(flow.flowId)\",\n};\n\nexport const requiredStatefulPendingConstraints: RequiredStatefulPendingConstraints = {\n ...requiredSessionConstraints,\n ...requiredPendingAuthenticationConstraints,\n};\n\nexport const requiredSignedValidityConstraints: RequiredSignedValidityConstraints = {\n tombstoneOwner: \"unique(tombstone.subjectId,tombstone.sessionId)\",\n};\n\nexport interface SessionConstraintClassifier {\n /**\n * Match only the named unique constraints declared by this mapping. Broad\n * SQL/constraint classifiers can relabel application or NOT NULL failures as\n * a domain conflict.\n */\n readonly isConstraintConflict: (cause: unknown) => boolean;\n}\n\nexport type AuthenticationAuthorityMapping<\n Claims,\n Subject extends Table,\n Credential extends Table,\n Flow extends Table,\n Pending extends Table,\n NativeSubjectId,\n> = SessionAuthorityTables<Subject, Credential, NativeSubjectId> &\n SessionConstraintClassifier &\n (\n | {\n /** Omit for single-factor authority installations. Pending input then fails closed. */\n readonly pending?: undefined;\n }\n | {\n readonly pending: PendingAuthenticationTables<Claims, Pending, Flow, NativeSubjectId>;\n readonly constraints: RequiredPendingAuthenticationConstraints;\n }\n );\n\nexport type StatefulSessionMapping<\n Claims,\n Subject extends Table,\n Credential extends Table,\n Session extends Table,\n Flow extends Table,\n Pending extends Table,\n NativeSubjectId,\n NativeSessionId,\n> = SessionAuthorityTables<Subject, Credential, NativeSubjectId> &\n StatefulSessionTables<Claims, Session, Flow, NativeSubjectId, NativeSessionId> &\n SessionConstraintClassifier &\n (\n | {\n /** Omit when this session module does not support pending MFA completion. */\n readonly pending?: undefined;\n readonly constraints: RequiredSessionConstraints;\n }\n | {\n readonly pending: PendingAuthenticationTables<\n Claims,\n Pending,\n Flow,\n NativeSubjectId\n >[\"pending\"];\n readonly constraints: RequiredStatefulPendingConstraints;\n }\n );\n\nexport type PendingAuthenticationMapping<\n Claims,\n Subject extends Table,\n Credential extends Table,\n Pending extends Table,\n Flow extends Table,\n NativeSubjectId,\n> = SessionAuthorityTables<Subject, Credential, NativeSubjectId> &\n PendingAuthenticationTables<Claims, Pending, Flow, NativeSubjectId> &\n SessionConstraintClassifier & {\n readonly constraints: RequiredPendingAuthenticationConstraints;\n };\n\nexport type SignedSessionValidityMapping<\n Subject extends Table,\n Tombstone extends Table,\n NativeSubjectId,\n NativeSessionId,\n> = SessionSubjectTables<Subject, NativeSubjectId> &\n SignedSessionValidityTables<Tombstone, NativeSubjectId, NativeSessionId> &\n SessionConstraintClassifier & {\n readonly constraints: RequiredSignedValidityConstraints;\n };\n\n/** D1 evaluates these expressions inside the atomic batch, after queueing delay.\n * `engineNow` must use the exact native representation of every mapped instant\n * column. `engineNowMillis` is Unix epoch milliseconds for proof freshness.\n * Changes to the consumer's factor policy MUST bump subject.securityRevision.\n * Supply the authoritative primary D1 database, never a replica-affined\n * `withSession` handle, because verification and security revision reads must\n * observe completed revocation writes across clients.\n */\nexport interface D1SessionClockMapping<Expression extends SqlExpression = SqlExpression> {\n readonly d1: {\n readonly engineNow: Expression;\n readonly engineNowMillis: Expression;\n readonly activeSubjectStatusValue: unknown;\n /** Required when `credential.status` is mapped. */\n readonly activeCredentialStatusValue?: unknown;\n };\n}\n\nexport type D1AuthenticationAuthorityMapping<\n Claims,\n Subject extends Table,\n Credential extends Table,\n Flow extends Table,\n Pending extends Table,\n NativeSubjectId,\n Expression extends SqlExpression = SqlExpression,\n> = AuthenticationAuthorityMapping<Claims, Subject, Credential, Flow, Pending, NativeSubjectId> &\n D1SessionClockMapping<Expression>;\n\nexport type D1PendingAuthenticationMapping<\n Claims,\n Subject extends Table,\n Credential extends Table,\n Pending extends Table,\n Flow extends Table,\n NativeSubjectId,\n Expression extends SqlExpression = SqlExpression,\n> = PendingAuthenticationMapping<Claims, Subject, Credential, Pending, Flow, NativeSubjectId> &\n D1SessionClockMapping<Expression>;\n\nexport type D1StatefulSessionMapping<\n Claims,\n Subject extends Table,\n Credential extends Table,\n Session extends Table,\n Flow extends Table,\n Pending extends Table,\n NativeSubjectId,\n NativeSessionId,\n Expression extends SqlExpression = SqlExpression,\n> = StatefulSessionMapping<\n Claims,\n Subject,\n Credential,\n Session,\n Flow,\n Pending,\n NativeSubjectId,\n NativeSessionId\n> &\n D1SessionClockMapping<Expression>;\n\nexport type D1SignedSessionValidityMapping<\n Subject extends Table,\n Tombstone extends Table,\n NativeSubjectId,\n NativeSessionId,\n Expression extends SqlExpression = SqlExpression,\n> = SignedSessionValidityMapping<Subject, Tombstone, NativeSubjectId, NativeSessionId> &\n D1SessionClockMapping<Expression>;\n"],"mappings":";;AA2MA,MAAa,6BAAyD;CACpE,eAAe;CACf,QAAQ;AACV;AAEA,MAAa,2CAAqF;CAChG,eAAe;CACf,aAAa;CACb,QAAQ;AACV;AAEA,MAAa,qCAAyE;CACpF,GAAG;CACH,GAAG;AACL;AAEA,MAAa,oCAAuE,EAClF,gBAAgB,kDAClB"}
1
+ {"version":3,"file":"session-model.mjs","names":[],"sources":["../../../src/internal/models/session-model.ts"],"sourcesContent":["import type { TokenDigest } from \"@yielded/auth/Schema\";\nimport type {\n AuthenticationRequirement,\n SecurityRevision,\n SessionId,\n AuthenticationFlowId,\n PendingAuthenticationRecord,\n StatefulSessionRecord,\n} from \"@yielded/auth/Sessions\";\nimport type { DateTime, Effect } from \"effect\";\n\nimport type { TableModel as Table, SqlExpression } from \"../table-model\";\nimport type { PersistenceMappingError, SubjectIdCodec } from \"./common\";\nimport type { ProofClock } from \"./proof-model\";\n\ntype ColumnKey<T extends Table> = T[\"column\"];\n\nexport interface SessionIdCodec<NativeId> {\n readonly toNative: (id: SessionId) => Effect.Effect<NativeId, PersistenceMappingError>;\n readonly toSession: (id: NativeId) => Effect.Effect<SessionId, PersistenceMappingError>;\n readonly equals: (left: NativeId, right: NativeId) => boolean;\n}\n\nexport interface SessionSubjectTables<Subject extends Table, NativeId> {\n readonly subject: {\n readonly table: Subject[\"table\"];\n readonly id: ColumnKey<Subject>;\n readonly status: ColumnKey<Subject>;\n readonly securityRevision: ColumnKey<Subject>;\n readonly activeStatusValue: unknown;\n readonly isActiveStatus: (value: unknown) => boolean;\n readonly decodeRequirement: (\n row: Subject[\"select\"],\n ) => Effect.Effect<AuthenticationRequirement, PersistenceMappingError>;\n /** Required for D1 authority writes. Declare every mutable subject input of\n * decodeRequirement; [] explicitly declares a constant requirement. */\n readonly requirementColumns?: ReadonlyArray<ColumnKey<Subject>>;\n readonly nextSecurityRevision?: (\n current: SecurityRevision,\n ) => Effect.Effect<SecurityRevision, PersistenceMappingError>;\n readonly nextSecurityRevisionSync?: (current: SecurityRevision) => SecurityRevision;\n };\n readonly subjectId: SubjectIdCodec<NativeId>;\n}\n\nexport interface SessionAuthorityTables<\n Subject extends Table,\n Credential extends Table,\n NativeId,\n> extends SessionSubjectTables<Subject, NativeId> {\n readonly credential: {\n readonly table: Credential[\"table\"];\n readonly subjectId: ColumnKey<Credential>;\n readonly credentialId: ColumnKey<Credential>;\n readonly revision: ColumnKey<Credential>;\n /** Omitted status means every row is an active credential. */\n readonly status?: ColumnKey<Credential>;\n readonly activeStatusValue?: unknown;\n readonly isActiveStatus?: (value: unknown) => boolean;\n };\n}\n\nexport interface SessionExecution<Expression extends SqlExpression = SqlExpression> {\n /** Exact session module scope for pending rows and revocation tombstones. */\n readonly moduleId: string;\n readonly clock: ProofClock<Expression>;\n /** D1 mappings must use the authoritative primary database. */\n readonly d1?: { readonly primary: true };\n /** Match only the declared unique keys, never generic SQL failures. */\n readonly isConstraintConflict: (cause: unknown) => boolean;\n}\n\nexport interface StatefulSessionTables<\n Claims,\n Session extends Table,\n NativeSubjectId,\n NativeSessionId,\n> {\n readonly session: {\n readonly table: Session[\"table\"];\n readonly sessionId: ColumnKey<Session>;\n readonly subjectId: ColumnKey<Session>;\n readonly digest: ColumnKey<Session>;\n readonly securityRevision: ColumnKey<Session>;\n readonly issuedAt: ColumnKey<Session>;\n readonly expiresAt: ColumnKey<Session>;\n readonly absoluteExpiresAt: ColumnKey<Session>;\n readonly encodeInstant: (instant: DateTime.Utc) => unknown;\n readonly encodeInsert: (\n record: StatefulSessionRecord<Claims>,\n ids: { readonly subjectId: NativeSubjectId; readonly sessionId: NativeSessionId },\n ) => Session[\"insert\"];\n /** Replace prepared metadata and retain exact private provenance. Digest binds the immutable source metadata. */\n readonly encodeRotation: (record: StatefulSessionRecord<Claims>) => Partial<Session[\"insert\"]>;\n readonly decode: (\n row: Session[\"select\"],\n ) => Effect.Effect<StatefulSessionRecord<Claims>, PersistenceMappingError>;\n readonly allocateId?: Effect.Effect<NativeSessionId, PersistenceMappingError>;\n readonly allocateIdSync?: () => NativeSessionId;\n };\n readonly sessionId: SessionIdCodec<NativeSessionId>;\n}\n\nexport interface SessionPendingInsert<NativeId> {\n readonly moduleId: string;\n readonly kind: \"Login\" | \"StepUp\";\n readonly digest: TokenDigest;\n readonly version: SecurityRevision;\n readonly flowId: AuthenticationFlowId;\n readonly subjectId: NativeId;\n readonly bindingDigest: TokenDigest;\n readonly snapshot: string;\n readonly expiresAt: DateTime.Utc;\n readonly attemptLimit: number;\n}\n\n/** One physical table and one SQL owner for Login and StepUp. The adapter sets\n * every guard column and binds kind before decoding, charging or consuming. */\nexport interface SessionPendingTables<Pending extends Table, NativeSubjectId> {\n readonly pending: {\n readonly table: Pending[\"table\"];\n readonly moduleId: ColumnKey<Pending>;\n readonly kind: ColumnKey<Pending>;\n readonly digest: ColumnKey<Pending>;\n readonly version: ColumnKey<Pending>;\n readonly flowId: ColumnKey<Pending>;\n readonly subjectId: ColumnKey<Pending>;\n readonly bindingDigest: ColumnKey<Pending>;\n readonly snapshot: ColumnKey<Pending>;\n readonly expiresAt: ColumnKey<Pending>;\n readonly attemptLimit: ColumnKey<Pending>;\n readonly failedAttempts: ColumnKey<Pending>;\n readonly consumed: ColumnKey<Pending>;\n readonly encodeInstant: (instant: DateTime.Utc) => unknown;\n readonly encodeInsert: (input: SessionPendingInsert<NativeSubjectId>) => Pending[\"insert\"];\n readonly allocateVersion?: Effect.Effect<SecurityRevision, PersistenceMappingError>;\n readonly allocateVersionSync?: () => SecurityRevision;\n };\n}\n\nexport interface PendingAuthenticationTables<\n Claims,\n Pending extends Table,\n NativeSubjectId,\n> extends SessionPendingTables<Pending, NativeSubjectId> {\n /** Canonical JSON of the full record; the consumer Schema owns Claims encoding. */\n readonly login: {\n readonly encode: (\n record: PendingAuthenticationRecord<Claims>,\n ) => Effect.Effect<string, PersistenceMappingError>;\n readonly decode: (\n snapshot: unknown,\n ) => Effect.Effect<PendingAuthenticationRecord<Claims>, PersistenceMappingError>;\n };\n}\n\nexport interface SignedSessionValidityTables<\n Tombstone extends Table,\n NativeSubjectId,\n NativeSessionId,\n> {\n readonly tombstone: {\n readonly table: Tombstone[\"table\"];\n readonly moduleId: ColumnKey<Tombstone>;\n readonly subjectId: ColumnKey<Tombstone>;\n readonly sessionId: ColumnKey<Tombstone>;\n readonly absoluteExpiresAt: ColumnKey<Tombstone>;\n readonly encodeInstant: (instant: DateTime.Utc) => unknown;\n readonly decodeInstant: (\n native: unknown,\n ) => Effect.Effect<DateTime.Utc, PersistenceMappingError>;\n readonly encodeInsert: (input: {\n readonly moduleId: string;\n readonly subjectId: NativeSubjectId;\n readonly sessionId: NativeSessionId;\n readonly absoluteExpiresAt: DateTime.Utc;\n }) => Tombstone[\"insert\"];\n };\n readonly sessionId: SessionIdCodec<NativeSessionId>;\n}\n\nexport const requiredSessionConstraints = { sessionDigest: \"unique(session.digest)\" } as const;\n\nexport const requiredPendingAuthenticationConstraints = {\n pendingDigest: \"unique(pending.digest)\",\n} as const;\n\nexport const requiredStatefulPendingConstraints = {\n ...requiredSessionConstraints,\n ...requiredPendingAuthenticationConstraints,\n} as const;\n\nexport const requiredSignedValidityConstraints = {\n tombstoneOwner: \"unique(tombstone.moduleId,tombstone.subjectId,tombstone.sessionId)\",\n} as const;\n\nexport type RequiredSessionConstraints = typeof requiredSessionConstraints;\n\nexport type RequiredPendingAuthenticationConstraints =\n typeof requiredPendingAuthenticationConstraints;\n\nexport type RequiredStatefulPendingConstraints = typeof requiredStatefulPendingConstraints;\nexport type RequiredSignedValidityConstraints = typeof requiredSignedValidityConstraints;\n\nexport type AuthenticationAuthorityMapping<\n Claims,\n Subject extends Table,\n Credential extends Table,\n Pending extends Table,\n NativeSubjectId,\n Expression extends SqlExpression = SqlExpression,\n> = SessionAuthorityTables<Subject, Credential, NativeSubjectId> &\n SessionExecution<Expression> &\n (\n | { readonly pending?: undefined }\n | {\n readonly pending: PendingAuthenticationTables<Claims, Pending, NativeSubjectId>;\n readonly constraints: RequiredPendingAuthenticationConstraints;\n }\n );\n\nexport type StatefulSessionMapping<\n Claims,\n Subject extends Table,\n Credential extends Table,\n Session extends Table,\n Pending extends Table,\n NativeSubjectId,\n NativeSessionId,\n Expression extends SqlExpression = SqlExpression,\n> = SessionAuthorityTables<Subject, Credential, NativeSubjectId> &\n StatefulSessionTables<Claims, Session, NativeSubjectId, NativeSessionId> &\n SessionExecution<Expression> &\n (\n | { readonly pending?: undefined; readonly constraints: RequiredSessionConstraints }\n | {\n readonly pending: PendingAuthenticationTables<Claims, Pending, NativeSubjectId>;\n readonly constraints: RequiredStatefulPendingConstraints;\n }\n );\n\nexport type PendingAuthenticationMapping<\n Claims,\n Subject extends Table,\n Credential extends Table,\n Pending extends Table,\n NativeSubjectId,\n Expression extends SqlExpression = SqlExpression,\n> = SessionAuthorityTables<Subject, Credential, NativeSubjectId> &\n PendingAuthenticationTables<Claims, Pending, NativeSubjectId> &\n SessionExecution<Expression> & { readonly constraints: RequiredPendingAuthenticationConstraints };\n\nexport type SignedSessionValidityMapping<\n Subject extends Table,\n Tombstone extends Table,\n NativeSubjectId,\n NativeSessionId,\n Expression extends SqlExpression = SqlExpression,\n> = SessionSubjectTables<Subject, NativeSubjectId> &\n SignedSessionValidityTables<Tombstone, NativeSubjectId, NativeSessionId> &\n SessionExecution<Expression> & { readonly constraints: RequiredSignedValidityConstraints };\n\n/** Maintenance uses the same mapped rows and one total per-call deletion limit. */\nexport type SessionCleanupMapping<\n Pending extends Table,\n Tombstone extends Table,\n NativeSubjectId,\n NativeSessionId,\n Expression extends SqlExpression = SqlExpression,\n> = Pick<SessionExecution<Expression>, \"moduleId\" | \"clock\" | \"d1\"> & {\n readonly pending?: SessionPendingTables<Pending, NativeSubjectId>[\"pending\"];\n readonly tombstone?: SignedSessionValidityTables<\n Tombstone,\n NativeSubjectId,\n NativeSessionId\n >[\"tombstone\"];\n};\n"],"mappings":";AAqLA,MAAa,6BAA6B,EAAE,eAAe,yBAAyB;AAEpF,MAAa,2CAA2C,EACtD,eAAe,yBACjB;AAEA,MAAa,qCAAqC;CAChD,GAAG;CACH,GAAG;AACL;AAEA,MAAa,oCAAoC,EAC/C,gBAAgB,qEAClB"}
@@ -1,66 +1,28 @@
1
- import { PersistenceMappingError } from "../mapping-error.mjs";
2
- import { SqlExpression, TableModel } from "../query-operations.mjs";
3
- import "./common.mjs";
4
- import { D1SessionClockMapping, SessionAuthorityTables, SessionConstraintClassifier, SessionIdCodec, SignedSessionValidityTables, StatefulSessionTables } from "./session-model.mjs";
5
- import { DateTime, Effect } from "effect";
6
- import { SecurityRevision, SessionStepUpIntent } from "@yielded/auth/Sessions";
1
+ import { SqlExpression, TableModel } from "../table-model.mjs";
2
+ import { SessionAuthorityTables, SessionExecution, SessionPendingTables, SignedSessionValidityTables, StatefulSessionTables } from "./session-model.mjs";
7
3
  //#region src/internal/models/step-up-model.d.ts
8
- type ColumnKey<T extends TableModel> = T["column"];
9
- /** Distinct from login-pending storage. Snapshot is TEXT encoded by the core's
10
- * SessionStepUpIntent schema; it contains no Claims and needs no consumer decoder. */
11
- export interface SessionStepUpIntentTables<Intent extends TableModel, NativeSubjectId> {
12
- readonly intent: {
13
- readonly table: Intent["table"];
14
- readonly digest: ColumnKey<Intent>;
15
- readonly version: ColumnKey<Intent>;
16
- readonly flowId: ColumnKey<Intent>;
17
- readonly subjectId: ColumnKey<Intent>;
18
- readonly bindingDigest: ColumnKey<Intent>;
19
- readonly snapshot: ColumnKey<Intent>;
20
- readonly expiresAt: ColumnKey<Intent>;
21
- readonly attemptLimit: ColumnKey<Intent>;
22
- readonly failedAttempts: ColumnKey<Intent>;
23
- readonly consumed: ColumnKey<Intent>;
24
- readonly encodeInstant: (instant: DateTime.Utc) => unknown;
25
- /** Consumer fields/defaults; the adapter sets all mapped security columns. */
26
- readonly encodeInsert: (intent: SessionStepUpIntent, input: {
27
- readonly subjectId: NativeSubjectId;
28
- }) => Intent["insert"];
29
- readonly allocateVersion?: Effect.Effect<SecurityRevision, PersistenceMappingError>;
30
- readonly allocateVersionSync?: () => SecurityRevision;
31
- };
32
- }
33
- export interface RequiredSessionStepUpConstraints {
34
- readonly intentDigest: "unique(intent.digest)";
35
- readonly intentFlow: "unique(intent.flowId)";
36
- }
37
- export declare const requiredSessionStepUpConstraints: RequiredSessionStepUpConstraints;
38
- /** Fixed source discriminator is checked against every stored intent. A minimal
39
- * pure-signed installation does not provide dummy session or tombstone tables. */
4
+ export declare const requiredSessionStepUpConstraints: {
5
+ readonly pendingDigest: "unique(pending.digest)";
6
+ };
7
+ export type RequiredSessionStepUpConstraints = typeof requiredSessionStepUpConstraints;
8
+ /** Stateful metadata is decoded from the exact inspected digest's record. No
9
+ * duplicate credentialVersion/authenticatedAt columns or row-version CAS. */
40
10
  export type SessionStepUpSourceTables<Claims, Session extends TableModel, Tombstone extends TableModel, NativeSubjectId, NativeSessionId> = {
41
11
  readonly kind: "StatelessSigned";
42
12
  } | ({
43
13
  readonly kind: "StateAssistedSigned";
44
14
  readonly constraints: {
45
- readonly tombstoneOwner: "unique(tombstone.subjectId,tombstone.sessionId)";
15
+ readonly tombstoneOwner: "unique(tombstone.moduleId,tombstone.subjectId,tombstone.sessionId)";
46
16
  };
47
- } & SignedSessionValidityTables<Tombstone, NativeSubjectId, NativeSessionId>) | {
17
+ } & SignedSessionValidityTables<Tombstone, NativeSubjectId, NativeSessionId>) | ({
48
18
  readonly kind: "Stateful";
49
19
  readonly constraints: {
50
20
  readonly sessionDigest: "unique(session.digest)";
51
21
  };
52
- readonly sessionId: SessionIdCodec<NativeSessionId>;
53
- /** encodeRotation must replace Claims, provenance, and the queryable security
54
- * fields together; it must not retain the old proof payload. */
55
- readonly session: StatefulSessionTables<Claims, Session, TableModel, NativeSubjectId, NativeSessionId>["session"] & {
56
- readonly credentialVersion: ColumnKey<Session>;
57
- readonly authenticatedAt: ColumnKey<Session>;
58
- };
59
- };
60
- export type SessionStepUpMapping<Claims, Subject extends TableModel, Credential extends TableModel, Intent extends TableModel, Session extends TableModel, Tombstone extends TableModel, NativeSubjectId, NativeSessionId> = SessionAuthorityTables<Subject, Credential, NativeSubjectId> & SessionStepUpIntentTables<Intent, NativeSubjectId> & SessionConstraintClassifier & {
22
+ } & StatefulSessionTables<Claims, Session, NativeSubjectId, NativeSessionId>);
23
+ export type SessionStepUpMapping<Claims, Subject extends TableModel, Credential extends TableModel, Pending extends TableModel, Session extends TableModel, Tombstone extends TableModel, NativeSubjectId, NativeSessionId, Expression extends SqlExpression = SqlExpression> = SessionAuthorityTables<Subject, Credential, NativeSubjectId> & SessionPendingTables<Pending, NativeSubjectId> & SessionExecution<Expression> & {
61
24
  readonly source: SessionStepUpSourceTables<Claims, Session, Tombstone, NativeSubjectId, NativeSessionId>;
62
25
  readonly constraints: RequiredSessionStepUpConstraints;
63
26
  };
64
- export type D1SessionStepUpMapping<Claims, Subject extends TableModel, Credential extends TableModel, Intent extends TableModel, Session extends TableModel, Tombstone extends TableModel, NativeSubjectId, NativeSessionId, Expression extends SqlExpression = SqlExpression> = SessionStepUpMapping<Claims, Subject, Credential, Intent, Session, Tombstone, NativeSubjectId, NativeSessionId> & D1SessionClockMapping<Expression>;
65
27
  //#endregion
66
28
  //# sourceMappingURL=step-up-model.d.mts.map
@@ -1,8 +1,6 @@
1
+ import { requiredPendingAuthenticationConstraints } from "./session-model.mjs";
1
2
  //#region src/internal/models/step-up-model.ts
2
- const requiredSessionStepUpConstraints = {
3
- intentDigest: "unique(intent.digest)",
4
- intentFlow: "unique(intent.flowId)"
5
- };
3
+ const requiredSessionStepUpConstraints = requiredPendingAuthenticationConstraints;
6
4
  //#endregion
7
5
  export { requiredSessionStepUpConstraints };
8
6
 
@@ -1 +1 @@
1
- {"version":3,"file":"step-up-model.mjs","names":[],"sources":["../../../src/internal/models/step-up-model.ts"],"sourcesContent":["import type { SecurityRevision, SessionStepUpIntent } from \"@yielded/auth/Sessions\";\nimport type { DateTime, Effect } from \"effect\";\n\nimport type { TableModel as Table, SqlExpression } from \"../query-operations\";\nimport type { PersistenceMappingError } from \"./common\";\nimport type {\n D1SessionClockMapping,\n SessionAuthorityTables,\n SessionConstraintClassifier,\n SessionIdCodec,\n SignedSessionValidityTables,\n StatefulSessionTables,\n} from \"./session-model\";\n\ntype ColumnKey<T extends Table> = T[\"column\"];\n\n/** Distinct from login-pending storage. Snapshot is TEXT encoded by the core's\n * SessionStepUpIntent schema; it contains no Claims and needs no consumer decoder. */\nexport interface SessionStepUpIntentTables<Intent extends Table, NativeSubjectId> {\n readonly intent: {\n readonly table: Intent[\"table\"];\n readonly digest: ColumnKey<Intent>;\n readonly version: ColumnKey<Intent>;\n readonly flowId: ColumnKey<Intent>;\n readonly subjectId: ColumnKey<Intent>;\n readonly bindingDigest: ColumnKey<Intent>;\n readonly snapshot: ColumnKey<Intent>;\n readonly expiresAt: ColumnKey<Intent>;\n readonly attemptLimit: ColumnKey<Intent>;\n readonly failedAttempts: ColumnKey<Intent>;\n readonly consumed: ColumnKey<Intent>;\n readonly encodeInstant: (instant: DateTime.Utc) => unknown;\n /** Consumer fields/defaults; the adapter sets all mapped security columns. */\n readonly encodeInsert: (\n intent: SessionStepUpIntent,\n input: {\n readonly subjectId: NativeSubjectId;\n },\n ) => Intent[\"insert\"];\n readonly allocateVersion?: Effect.Effect<SecurityRevision, PersistenceMappingError>;\n readonly allocateVersionSync?: () => SecurityRevision;\n };\n}\n\nexport interface RequiredSessionStepUpConstraints {\n readonly intentDigest: \"unique(intent.digest)\";\n readonly intentFlow: \"unique(intent.flowId)\";\n}\n\nexport const requiredSessionStepUpConstraints: RequiredSessionStepUpConstraints = {\n intentDigest: \"unique(intent.digest)\",\n intentFlow: \"unique(intent.flowId)\",\n};\n\n/** Fixed source discriminator is checked against every stored intent. A minimal\n * pure-signed installation does not provide dummy session or tombstone tables. */\nexport type SessionStepUpSourceTables<\n Claims,\n Session extends Table,\n Tombstone extends Table,\n NativeSubjectId,\n NativeSessionId,\n> =\n | {\n readonly kind: \"StatelessSigned\";\n }\n | ({\n readonly kind: \"StateAssistedSigned\";\n readonly constraints: {\n readonly tombstoneOwner: \"unique(tombstone.subjectId,tombstone.sessionId)\";\n };\n } & SignedSessionValidityTables<Tombstone, NativeSubjectId, NativeSessionId>)\n | {\n readonly kind: \"Stateful\";\n readonly constraints: {\n readonly sessionDigest: \"unique(session.digest)\";\n };\n readonly sessionId: SessionIdCodec<NativeSessionId>;\n /** encodeRotation must replace Claims, provenance, and the queryable security\n * fields together; it must not retain the old proof payload. */\n readonly session: StatefulSessionTables<\n Claims,\n Session,\n Table,\n NativeSubjectId,\n NativeSessionId\n >[\"session\"] & {\n readonly credentialVersion: ColumnKey<Session>;\n readonly authenticatedAt: ColumnKey<Session>;\n };\n };\n\nexport type SessionStepUpMapping<\n Claims,\n Subject extends Table,\n Credential extends Table,\n Intent extends Table,\n Session extends Table,\n Tombstone extends Table,\n NativeSubjectId,\n NativeSessionId,\n> = SessionAuthorityTables<Subject, Credential, NativeSubjectId> &\n SessionStepUpIntentTables<Intent, NativeSubjectId> &\n SessionConstraintClassifier & {\n readonly source: SessionStepUpSourceTables<\n Claims,\n Session,\n Tombstone,\n NativeSubjectId,\n NativeSessionId\n >;\n readonly constraints: RequiredSessionStepUpConstraints;\n };\n\nexport type D1SessionStepUpMapping<\n Claims,\n Subject extends Table,\n Credential extends Table,\n Intent extends Table,\n Session extends Table,\n Tombstone extends Table,\n NativeSubjectId,\n NativeSessionId,\n Expression extends SqlExpression = SqlExpression,\n> = SessionStepUpMapping<\n Claims,\n Subject,\n Credential,\n Intent,\n Session,\n Tombstone,\n NativeSubjectId,\n NativeSessionId\n> &\n D1SessionClockMapping<Expression>;\n"],"mappings":";AAiDA,MAAa,mCAAqE;CAChF,cAAc;CACd,YAAY;AACd"}
1
+ {"version":3,"file":"step-up-model.mjs","names":[],"sources":["../../../src/internal/models/step-up-model.ts"],"sourcesContent":["import type { TableModel as Table, SqlExpression } from \"../table-model\";\nimport type {\n SessionAuthorityTables,\n SessionExecution,\n SessionPendingTables,\n SignedSessionValidityTables,\n StatefulSessionTables,\n} from \"./session-model\";\nimport { requiredPendingAuthenticationConstraints } from \"./session-model\";\n\nexport const requiredSessionStepUpConstraints = requiredPendingAuthenticationConstraints;\nexport type RequiredSessionStepUpConstraints = typeof requiredSessionStepUpConstraints;\n\n/** Stateful metadata is decoded from the exact inspected digest's record. No\n * duplicate credentialVersion/authenticatedAt columns or row-version CAS. */\nexport type SessionStepUpSourceTables<\n Claims,\n Session extends Table,\n Tombstone extends Table,\n NativeSubjectId,\n NativeSessionId,\n> =\n | { readonly kind: \"StatelessSigned\" }\n | ({\n readonly kind: \"StateAssistedSigned\";\n readonly constraints: {\n readonly tombstoneOwner: \"unique(tombstone.moduleId,tombstone.subjectId,tombstone.sessionId)\";\n };\n } & SignedSessionValidityTables<Tombstone, NativeSubjectId, NativeSessionId>)\n | ({\n readonly kind: \"Stateful\";\n readonly constraints: { readonly sessionDigest: \"unique(session.digest)\" };\n } & StatefulSessionTables<Claims, Session, NativeSubjectId, NativeSessionId>);\n\nexport type SessionStepUpMapping<\n Claims,\n Subject extends Table,\n Credential extends Table,\n Pending extends Table,\n Session extends Table,\n Tombstone extends Table,\n NativeSubjectId,\n NativeSessionId,\n Expression extends SqlExpression = SqlExpression,\n> = SessionAuthorityTables<Subject, Credential, NativeSubjectId> &\n SessionPendingTables<Pending, NativeSubjectId> &\n SessionExecution<Expression> & {\n readonly source: SessionStepUpSourceTables<\n Claims,\n Session,\n Tombstone,\n NativeSubjectId,\n NativeSessionId\n >;\n readonly constraints: RequiredSessionStepUpConstraints;\n };\n"],"mappings":";;AAUA,MAAa,mCAAmC"}
@@ -0,0 +1,76 @@
1
+ import { SqlExpression, TableModel } from "../table-model.mjs";
2
+ import { PersistenceMappingError } from "../mapping-error.mjs";
3
+ import { ProofClock } from "./proof-model.mjs";
4
+ import { PendingAuthenticationTables } from "./session-model.mjs";
5
+ import { Effect } from "effect";
6
+ import { AuthenticationRequirement } from "@yielded/auth/Sessions";
7
+ import { SubjectId } from "@yielded/auth/Schema";
8
+ import { TotpPolicy } from "@yielded/auth/Totp";
9
+ //#region src/internal/models/totp-model.d.ts
10
+ export declare const requiredTotpConstraints: {
11
+ readonly factor: "unique(scope)";
12
+ readonly credential: "unique(credentialId)";
13
+ readonly subject: "unique(id)";
14
+ };
15
+ export type TotpMappingSource<M, R = never> = M | Effect.Effect<M, PersistenceMappingError, R>;
16
+ /** One encrypted factor row and the common credential authority. Version protects
17
+ * accepted-step, failure-budget and recovery-code changes; no command receipts. */
18
+ export interface TotpMapping<S extends TableModel, F extends TableModel, C extends TableModel, N, P extends TableModel = TableModel, Expression extends SqlExpression = SqlExpression> {
19
+ readonly moduleId: string;
20
+ readonly policy: TotpPolicy;
21
+ readonly constraints: typeof requiredTotpConstraints;
22
+ readonly d1?: {
23
+ readonly primary: true;
24
+ };
25
+ readonly subjectIds: {
26
+ readonly toNative: (id: SubjectId) => N;
27
+ readonly toSubject: (id: N) => SubjectId;
28
+ };
29
+ readonly subject: {
30
+ readonly table: S["table"];
31
+ readonly id: S["column"];
32
+ readonly securityRevision: S["column"];
33
+ readonly factorEnabled: S["column"];
34
+ readonly activeCondition: Expression;
35
+ readonly encodeEnabled: (enabled: boolean) => unknown;
36
+ readonly decodeRequirement: (row: S["select"]) => AuthenticationRequirement;
37
+ /** Required for D1: declare every independently mutable input read by
38
+ * decodeRequirement. An explicit [] promises a constant requirement. */
39
+ readonly requirementColumns?: ReadonlyArray<S["column"]>;
40
+ };
41
+ readonly factor: {
42
+ readonly table: F["table"];
43
+ readonly scope: F["column"];
44
+ readonly state: F["column"];
45
+ readonly version: F["column"];
46
+ readonly encodeInsert: (value: {
47
+ readonly scope: string;
48
+ readonly state: string;
49
+ readonly version: string;
50
+ }) => F["insert"];
51
+ };
52
+ readonly credential: {
53
+ readonly table: C["table"];
54
+ readonly id: C["column"];
55
+ readonly subjectId: C["column"];
56
+ readonly revision: C["column"];
57
+ readonly status: C["column"];
58
+ readonly activeCondition: Expression;
59
+ readonly encodeStatus: (active: boolean) => unknown;
60
+ readonly encodeInsert: (value: {
61
+ readonly credentialId: string;
62
+ readonly subjectId: N;
63
+ readonly revision: string;
64
+ readonly active: boolean;
65
+ }) => C["insert"];
66
+ };
67
+ readonly engineNowMillis: Expression;
68
+ /** Reset uses the very same Login-kind row owner as pending authentication. */
69
+ readonly pending?: Omit<PendingAuthenticationTables<unknown, P, N>, "login"> & {
70
+ readonly login: Pick<PendingAuthenticationTables<unknown, P, N>["login"], "decode">;
71
+ readonly moduleId: string;
72
+ readonly clock: ProofClock<Expression>;
73
+ };
74
+ }
75
+ //#endregion
76
+ //# sourceMappingURL=totp-model.d.mts.map
@@ -0,0 +1,10 @@
1
+ //#region src/internal/models/totp-model.ts
2
+ const requiredTotpConstraints = {
3
+ factor: "unique(scope)",
4
+ credential: "unique(credentialId)",
5
+ subject: "unique(id)"
6
+ };
7
+ //#endregion
8
+ export { requiredTotpConstraints };
9
+
10
+ //# sourceMappingURL=totp-model.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"totp-model.mjs","names":[],"sources":["../../../src/internal/models/totp-model.ts"],"sourcesContent":["import type { SubjectId } from \"@yielded/auth/Schema\";\nimport type { AuthenticationRequirement } from \"@yielded/auth/Sessions\";\nimport type { TotpPolicy } from \"@yielded/auth/Totp\";\nimport type { Effect } from \"effect\";\n\nimport type { PersistenceMappingError } from \"../mapping-error\";\nimport type { TableModel, SqlExpression } from \"../table-model\";\nimport type { ProofClock } from \"./proof-model\";\nimport type { PendingAuthenticationTables } from \"./session-model\";\n\nexport const requiredTotpConstraints = {\n factor: \"unique(scope)\",\n credential: \"unique(credentialId)\",\n subject: \"unique(id)\",\n} as const;\n\nexport type TotpMappingSource<M, R = never> = M | Effect.Effect<M, PersistenceMappingError, R>;\n\n/** One encrypted factor row and the common credential authority. Version protects\n * accepted-step, failure-budget and recovery-code changes; no command receipts. */\nexport interface TotpMapping<\n S extends TableModel,\n F extends TableModel,\n C extends TableModel,\n N,\n P extends TableModel = TableModel,\n Expression extends SqlExpression = SqlExpression,\n> {\n readonly moduleId: string;\n readonly policy: TotpPolicy;\n readonly constraints: typeof requiredTotpConstraints;\n readonly d1?: { readonly primary: true };\n readonly subjectIds: {\n readonly toNative: (id: SubjectId) => N;\n readonly toSubject: (id: N) => SubjectId;\n };\n readonly subject: {\n readonly table: S[\"table\"];\n readonly id: S[\"column\"];\n readonly securityRevision: S[\"column\"];\n readonly factorEnabled: S[\"column\"];\n readonly activeCondition: Expression;\n readonly encodeEnabled: (enabled: boolean) => unknown;\n readonly decodeRequirement: (row: S[\"select\"]) => AuthenticationRequirement;\n /** Required for D1: declare every independently mutable input read by\n * decodeRequirement. An explicit [] promises a constant requirement. */\n readonly requirementColumns?: ReadonlyArray<S[\"column\"]>;\n };\n readonly factor: {\n readonly table: F[\"table\"];\n readonly scope: F[\"column\"];\n readonly state: F[\"column\"];\n readonly version: F[\"column\"];\n readonly encodeInsert: (value: {\n readonly scope: string;\n readonly state: string;\n readonly version: string;\n }) => F[\"insert\"];\n };\n readonly credential: {\n readonly table: C[\"table\"];\n readonly id: C[\"column\"];\n readonly subjectId: C[\"column\"];\n readonly revision: C[\"column\"];\n readonly status: C[\"column\"];\n readonly activeCondition: Expression;\n readonly encodeStatus: (active: boolean) => unknown;\n readonly encodeInsert: (value: {\n readonly credentialId: string;\n readonly subjectId: N;\n readonly revision: string;\n readonly active: boolean;\n }) => C[\"insert\"];\n };\n readonly engineNowMillis: Expression;\n /** Reset uses the very same Login-kind row owner as pending authentication. */\n readonly pending?: Omit<PendingAuthenticationTables<unknown, P, N>, \"login\"> & {\n readonly login: Pick<PendingAuthenticationTables<unknown, P, N>[\"login\"], \"decode\">;\n readonly moduleId: string;\n readonly clock: ProofClock<Expression>;\n };\n}\n"],"mappings":";AAUA,MAAa,0BAA0B;CACrC,QAAQ;CACR,YAAY;CACZ,SAAS;AACX"}
@@ -1,16 +1,29 @@
1
- import "./mapping-error.mjs";
2
- import { PhysicalTextColumn } from "./storage-validation.mjs";
1
+ import { PersistenceMappingError } from "./mapping-error.mjs";
3
2
  import { Effect } from "effect";
4
3
  import * as Statement$1 from "effect/sql/Statement";
5
4
  import { SqlClient } from "effect/sql/SqlClient";
6
5
  //#region src/internal/native-sql-table.d.ts
6
+ export interface PhysicalTextColumn {
7
+ readonly table: {
8
+ readonly name: string;
9
+ readonly schema?: string;
10
+ };
11
+ readonly name: string;
12
+ }
13
+ /** Capture synchronous mapping callbacks without changing SQL execution errors. */
14
+ export declare const sqlMapping: <A>(thunk: () => A) => Effect.Effect<A, PersistenceMappingError>;
7
15
  /** Physical SQL representation only. Semantic row codecs and policy remain in
8
16
  * the owning mapping. Execute assembled statements without name/result transforms. */
9
17
  export interface SqlTable {
18
+ readonly keys: ReadonlyArray<string>;
10
19
  readonly name: Statement$1.Fragment;
11
20
  /** Alias reads only; writes continue to target the original physical table. */
12
21
  readonly as: (alias: string) => SqlTable;
13
22
  readonly column: (key: string) => Statement$1.Fragment;
23
+ /** Unqualified physical name for conflict targets and assignment lists. */
24
+ readonly columnName: (key: string) => Statement$1.Fragment;
25
+ /** Result projection, including the physical driver's result codec cast. */
26
+ readonly selectedColumn: (key: string) => Statement$1.Fragment;
14
27
  /** Optional codec-free text candidate. Physical type/collation compatibility
15
28
  * must still be checked against the database before comparing columns. */
16
29
  readonly unencodedTextColumn?: (key: string) => PhysicalTextColumn | undefined;
@@ -23,12 +36,16 @@ export interface SqlTable {
23
36
  /** Complete UPDATE ... SET prefix; the owning operation supplies its predicate. */
24
37
  readonly update: (values: Readonly<Record<string, unknown>>) => Statement$1.Fragment;
25
38
  }
26
- export type NativeSqlTables = (table: object) => SqlTable;
39
+ export interface NativeSqlTables {
40
+ (table: object): SqlTable;
41
+ /** Compile a mapped predicate without executing it or acquiring resources. */
42
+ readonly expression: (value: unknown) => Statement$1.Fragment;
43
+ }
27
44
  /** Prefixes are short ASCII identifiers so ordinal aliases cannot be truncated
28
45
  * by PostgreSQL. Callers distinguish tables by prefix, never by physical names. */
29
46
  export declare const nativeSqlAlias: (prefix: string, index: number) => string;
30
47
  /** Cache physical metadata only; insert/update materialize values and hooks at
31
48
  * each call. Construction acquires no client and owns no transaction. */
32
- export declare const makeNativeSqlTables: (client: SqlClient, convert?: (client: SqlClient, table: object) => SqlTable) => NativeSqlTables;
49
+ export declare const makeNativeSqlTables: (client: SqlClient, convert?: (client: SqlClient, table: object) => SqlTable, expression?: NativeSqlTables["expression"]) => NativeSqlTables;
33
50
  //#endregion
34
51
  //# sourceMappingURL=native-sql-table.d.mts.map