@yielded/auth-persistence-drizzle 0.1.0-beta.25 → 0.1.0-beta.26

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 (383) hide show
  1. package/README.md +4 -2
  2. package/dist/D1.d.mts +495 -1151
  3. package/dist/D1.mjs +41 -19
  4. package/dist/D1.mjs.map +1 -1
  5. package/dist/Libsql.d.mts +385 -1996
  6. package/dist/Libsql.mjs +43 -47
  7. package/dist/Libsql.mjs.map +1 -1
  8. package/dist/Mysql2.d.mts +397 -1743
  9. package/dist/Mysql2.mjs +35 -41
  10. package/dist/Mysql2.mjs.map +1 -1
  11. package/dist/Pglite.d.mts +397 -1743
  12. package/dist/Pglite.mjs +42 -31
  13. package/dist/Pglite.mjs.map +1 -1
  14. package/dist/Postgres.d.mts +397 -1743
  15. package/dist/Postgres.mjs +42 -31
  16. package/dist/Postgres.mjs.map +1 -1
  17. package/dist/SqliteBun.d.mts +385 -1992
  18. package/dist/SqliteBun.mjs +43 -43
  19. package/dist/SqliteBun.mjs.map +1 -1
  20. package/dist/SqliteDo.d.mts +385 -1991
  21. package/dist/SqliteDo.mjs +42 -41
  22. package/dist/SqliteDo.mjs.map +1 -1
  23. package/dist/SqliteNode.d.mts +385 -1992
  24. package/dist/SqliteNode.mjs +43 -43
  25. package/dist/SqliteNode.mjs.map +1 -1
  26. package/dist/SqliteWasm.d.mts +385 -1992
  27. package/dist/SqliteWasm.mjs +43 -43
  28. package/dist/SqliteWasm.mjs.map +1 -1
  29. package/dist/drizzle/d1-identity.mjs +2 -2
  30. package/dist/drizzle/d1-identity.mjs.map +1 -1
  31. package/dist/drizzle/driver-types.d.mts +15 -0
  32. package/dist/drizzle/email-drivers.mjs +32 -0
  33. package/dist/drizzle/email-drivers.mjs.map +1 -0
  34. package/dist/drizzle/email-model.d.mts +9 -13
  35. package/dist/drizzle/email-target.d.mts +10 -11
  36. package/dist/drizzle/email-target.mjs +33 -70
  37. package/dist/drizzle/email-target.mjs.map +1 -1
  38. package/dist/drizzle/model.d.mts +1 -10
  39. package/dist/drizzle/model.mjs +1 -2
  40. package/dist/drizzle/model.mjs.map +1 -1
  41. package/dist/drizzle/mysql-identity.mjs +3 -6
  42. package/dist/drizzle/mysql-identity.mjs.map +1 -1
  43. package/dist/drizzle/native-clock.d.mts +9 -0
  44. package/dist/drizzle/native-clock.mjs +18 -0
  45. package/dist/drizzle/native-clock.mjs.map +1 -0
  46. package/dist/drizzle/native-database.d.mts +46 -0
  47. package/dist/drizzle/native-database.mjs +6 -5
  48. package/dist/drizzle/native-database.mjs.map +1 -1
  49. package/dist/drizzle/native-sql-table.mjs +13 -5
  50. package/dist/drizzle/native-sql-table.mjs.map +1 -1
  51. package/dist/drizzle/native-target.d.mts +6 -0
  52. package/dist/drizzle/native-target.mjs +44 -0
  53. package/dist/drizzle/native-target.mjs.map +1 -0
  54. package/dist/drizzle/oauth-connected-drivers.mjs +4 -56
  55. package/dist/drizzle/oauth-connected-drivers.mjs.map +1 -1
  56. package/dist/drizzle/oauth-connected-model.d.mts +5 -22
  57. package/dist/drizzle/oauth-connected-model.mjs +1 -7
  58. package/dist/drizzle/oauth-connected-reference.d.mts +5 -7
  59. package/dist/drizzle/oauth-connected-reference.mjs +11 -3
  60. package/dist/drizzle/oauth-connected-reference.mjs.map +1 -1
  61. package/dist/drizzle/oauth-drivers.mjs +1 -2
  62. package/dist/drizzle/oauth-drivers.mjs.map +1 -1
  63. package/dist/drizzle/oauth-model.d.mts +11 -37
  64. package/dist/drizzle/oauth-model.mjs +3 -4
  65. package/dist/drizzle/oauth-model.mjs.map +1 -1
  66. package/dist/drizzle/oauth-proxy.d.mts +1 -1
  67. package/dist/drizzle/oauth-proxy.mjs +1 -1
  68. package/dist/drizzle/oauth-target.d.mts +9 -6
  69. package/dist/drizzle/oauth-target.mjs +47 -15
  70. package/dist/drizzle/oauth-target.mjs.map +1 -1
  71. package/dist/drizzle/passkey/target.d.mts +14 -0
  72. package/dist/drizzle/passkey/target.mjs +52 -0
  73. package/dist/drizzle/passkey/target.mjs.map +1 -0
  74. package/dist/drizzle/passkey/write-target.d.mts +11 -0
  75. package/dist/drizzle/passkey/write-target.mjs +28 -0
  76. package/dist/drizzle/passkey/write-target.mjs.map +1 -0
  77. package/dist/drizzle/passkey-drivers.mjs +2 -4
  78. package/dist/drizzle/passkey-drivers.mjs.map +1 -1
  79. package/dist/drizzle/passkey-model.d.mts +5 -26
  80. package/dist/drizzle/passkey-model.mjs +2 -8
  81. package/dist/drizzle/passkey-registration-ceremony-model.d.mts +3 -6
  82. package/dist/drizzle/passkey-write-drivers.mjs +2 -3
  83. package/dist/drizzle/passkey-write-drivers.mjs.map +1 -1
  84. package/dist/drizzle/passkey-write-model.d.mts +7 -9
  85. package/dist/drizzle/passkey-write-model.mjs +1 -3
  86. package/dist/drizzle/passkey-write-model.mjs.map +1 -1
  87. package/dist/drizzle/password-drivers.mjs +31 -0
  88. package/dist/drizzle/password-drivers.mjs.map +1 -0
  89. package/dist/drizzle/password-model.d.mts +7 -10
  90. package/dist/drizzle/password-target.d.mts +7 -8
  91. package/dist/drizzle/password-target.mjs +23 -68
  92. package/dist/drizzle/password-target.mjs.map +1 -1
  93. package/dist/drizzle/pg-identity.mjs +3 -6
  94. package/dist/drizzle/pg-identity.mjs.map +1 -1
  95. package/dist/drizzle/phone-drivers.mjs +24 -0
  96. package/dist/drizzle/phone-drivers.mjs.map +1 -0
  97. package/dist/drizzle/phone-model.d.mts +13 -104
  98. package/dist/drizzle/phone-model.mjs +5 -33
  99. package/dist/drizzle/phone-model.mjs.map +1 -1
  100. package/dist/drizzle/phone-target.mjs +22 -171
  101. package/dist/drizzle/phone-target.mjs.map +1 -1
  102. package/dist/drizzle/proof-drivers.mjs +24 -0
  103. package/dist/drizzle/proof-drivers.mjs.map +1 -0
  104. package/dist/drizzle/proof-model.d.mts +7 -15
  105. package/dist/drizzle/proof-target.d.mts +5 -5
  106. package/dist/drizzle/proof-target.mjs +14 -28
  107. package/dist/drizzle/proof-target.mjs.map +1 -1
  108. package/dist/drizzle/session-drivers.mjs +97 -0
  109. package/dist/drizzle/session-drivers.mjs.map +1 -0
  110. package/dist/drizzle/session-model.d.mts +11 -22
  111. package/dist/drizzle/sqlite-do-database.d.mts +3 -3
  112. package/dist/drizzle/sqlite-do-database.mjs +6 -1
  113. package/dist/drizzle/sqlite-do-database.mjs.map +1 -1
  114. package/dist/drizzle/sqlite-identity.mjs +3 -5
  115. package/dist/drizzle/sqlite-identity.mjs.map +1 -1
  116. package/dist/drizzle/step-up-model.d.mts +2 -5
  117. package/dist/drizzle/storage-validation.mjs +2 -1
  118. package/dist/drizzle/storage-validation.mjs.map +1 -1
  119. package/dist/drizzle/totp-model.d.mts +7 -74
  120. package/dist/drizzle/totp-model.mjs +1 -5
  121. package/dist/drizzle/totp-model.mjs.map +1 -1
  122. package/dist/drizzle/totp-target.mjs +39 -75
  123. package/dist/drizzle/totp-target.mjs.map +1 -1
  124. package/dist/drizzle/transaction-handle.mjs +13 -0
  125. package/dist/drizzle/transaction-handle.mjs.map +1 -0
  126. package/dist/drizzle/transaction-mysql.mjs +43 -12
  127. package/dist/drizzle/transaction-mysql.mjs.map +1 -1
  128. package/dist/index.d.mts +17 -22
  129. package/dist/index.mjs +10 -16
  130. package/dist/internal/drizzle-postgres.mjs +4 -6
  131. package/dist/internal/drizzle-postgres.mjs.map +1 -1
  132. package/dist/internal/drizzle-sqlite.mjs +4 -6
  133. package/dist/internal/drizzle-sqlite.mjs.map +1 -1
  134. package/package.json +1 -1
  135. package/src/D1.ts +77 -74
  136. package/src/Libsql.ts +65 -105
  137. package/src/Mysql2.ts +52 -87
  138. package/src/Pglite.ts +74 -81
  139. package/src/Postgres.ts +74 -81
  140. package/src/SqliteBun.ts +65 -113
  141. package/src/SqliteDo.ts +58 -106
  142. package/src/SqliteNode.ts +65 -113
  143. package/src/SqliteWasm.ts +65 -113
  144. package/src/drizzle/d1-identity.ts +2 -2
  145. package/src/drizzle/driver-types.ts +26 -0
  146. package/src/drizzle/email-drivers.ts +320 -0
  147. package/src/drizzle/email-model.ts +24 -78
  148. package/src/drizzle/email-target.ts +118 -211
  149. package/src/drizzle/model.ts +0 -2
  150. package/src/drizzle/mysql-identity.ts +4 -24
  151. package/src/drizzle/native-clock.ts +21 -0
  152. package/src/drizzle/native-database.ts +59 -18
  153. package/src/drizzle/native-sql-table.ts +104 -87
  154. package/src/drizzle/native-target.ts +120 -0
  155. package/src/drizzle/oauth-connected-drivers.ts +24 -233
  156. package/src/drizzle/oauth-connected-model.ts +3 -93
  157. package/src/drizzle/oauth-connected-reference.ts +16 -25
  158. package/src/drizzle/oauth-drivers.ts +58 -99
  159. package/src/drizzle/oauth-model.ts +27 -132
  160. package/src/drizzle/oauth-target.ts +250 -33
  161. package/src/drizzle/passkey/target.ts +205 -0
  162. package/src/drizzle/passkey/write-target.ts +91 -0
  163. package/src/drizzle/passkey-drivers.ts +35 -133
  164. package/src/drizzle/passkey-model.ts +3 -81
  165. package/src/drizzle/passkey-registration-ceremony-model.ts +5 -25
  166. package/src/drizzle/passkey-write-drivers.ts +32 -102
  167. package/src/drizzle/passkey-write-model.ts +10 -44
  168. package/src/drizzle/password-drivers.ts +286 -0
  169. package/src/drizzle/password-model.ts +10 -44
  170. package/src/drizzle/password-target.ts +85 -239
  171. package/src/drizzle/pg-identity.ts +4 -19
  172. package/src/drizzle/phone-drivers.ts +142 -0
  173. package/src/drizzle/phone-model.ts +22 -162
  174. package/src/drizzle/phone-target.ts +51 -493
  175. package/src/drizzle/proof-drivers.ts +123 -0
  176. package/src/drizzle/proof-model.ts +12 -123
  177. package/src/drizzle/proof-target.ts +38 -102
  178. package/src/drizzle/session-drivers.ts +696 -0
  179. package/src/drizzle/session-model.ts +54 -118
  180. package/src/drizzle/sqlite-do-database.ts +8 -0
  181. package/src/drizzle/sqlite-identity.ts +4 -22
  182. package/src/drizzle/step-up-model.ts +13 -37
  183. package/src/drizzle/storage-validation.ts +2 -1
  184. package/src/drizzle/totp-model.ts +20 -77
  185. package/src/drizzle/totp-target.ts +121 -261
  186. package/src/drizzle/transaction-handle.ts +41 -0
  187. package/src/drizzle/transaction-mysql.ts +90 -25
  188. package/src/index.ts +7 -122
  189. package/src/internal/drizzle-postgres.ts +4 -7
  190. package/src/internal/drizzle-sqlite.ts +4 -7
  191. package/dist/drizzle/crypto.mjs +0 -11
  192. package/dist/drizzle/crypto.mjs.map +0 -1
  193. package/dist/drizzle/d1-emails.d.mts +0 -62
  194. package/dist/drizzle/d1-emails.mjs +0 -626
  195. package/dist/drizzle/d1-emails.mjs.map +0 -1
  196. package/dist/drizzle/d1-generated-statement.mjs +0 -79
  197. package/dist/drizzle/d1-generated-statement.mjs.map +0 -1
  198. package/dist/drizzle/d1-oauth.d.mts +0 -331
  199. package/dist/drizzle/d1-oauth.mjs +0 -79
  200. package/dist/drizzle/d1-oauth.mjs.map +0 -1
  201. package/dist/drizzle/d1-passkey.d.mts +0 -37
  202. package/dist/drizzle/d1-passkey.mjs +0 -98
  203. package/dist/drizzle/d1-passkey.mjs.map +0 -1
  204. package/dist/drizzle/d1-password-prepared.d.mts +0 -25
  205. package/dist/drizzle/d1-password-prepared.mjs +0 -473
  206. package/dist/drizzle/d1-password-prepared.mjs.map +0 -1
  207. package/dist/drizzle/d1-passwords.d.mts +0 -70
  208. package/dist/drizzle/d1-passwords.mjs +0 -808
  209. package/dist/drizzle/d1-passwords.mjs.map +0 -1
  210. package/dist/drizzle/d1-phone.d.mts +0 -23
  211. package/dist/drizzle/d1-phone.mjs +0 -33
  212. package/dist/drizzle/d1-phone.mjs.map +0 -1
  213. package/dist/drizzle/d1-planning.d.mts +0 -11
  214. package/dist/drizzle/d1-planning.mjs +0 -43
  215. package/dist/drizzle/d1-planning.mjs.map +0 -1
  216. package/dist/drizzle/d1-proofs.d.mts +0 -80
  217. package/dist/drizzle/d1-proofs.mjs +0 -842
  218. package/dist/drizzle/d1-proofs.mjs.map +0 -1
  219. package/dist/drizzle/d1-sessions.d.mts +0 -68
  220. package/dist/drizzle/d1-sessions.mjs +0 -987
  221. package/dist/drizzle/d1-sessions.mjs.map +0 -1
  222. package/dist/drizzle/d1-totp.d.mts +0 -23
  223. package/dist/drizzle/d1-totp.mjs +0 -30
  224. package/dist/drizzle/d1-totp.mjs.map +0 -1
  225. package/dist/drizzle/email-registration.d.mts +0 -33
  226. package/dist/drizzle/email-registration.mjs +0 -281
  227. package/dist/drizzle/email-registration.mjs.map +0 -1
  228. package/dist/drizzle/email-sql.d.mts +0 -1
  229. package/dist/drizzle/email-sql.mjs +0 -9
  230. package/dist/drizzle/email-sql.mjs.map +0 -1
  231. package/dist/drizzle/mysql-emails.d.mts +0 -71
  232. package/dist/drizzle/mysql-emails.mjs +0 -43
  233. package/dist/drizzle/mysql-emails.mjs.map +0 -1
  234. package/dist/drizzle/mysql-password-prepared.d.mts +0 -30
  235. package/dist/drizzle/mysql-password-prepared.mjs +0 -21
  236. package/dist/drizzle/mysql-password-prepared.mjs.map +0 -1
  237. package/dist/drizzle/mysql-passwords.d.mts +0 -71
  238. package/dist/drizzle/mysql-passwords.mjs +0 -43
  239. package/dist/drizzle/mysql-passwords.mjs.map +0 -1
  240. package/dist/drizzle/mysql-proofs.d.mts +0 -75
  241. package/dist/drizzle/mysql-proofs.mjs +0 -28
  242. package/dist/drizzle/mysql-proofs.mjs.map +0 -1
  243. package/dist/drizzle/mysql-sessions.d.mts +0 -92
  244. package/dist/drizzle/mysql-sessions.mjs +0 -58
  245. package/dist/drizzle/mysql-sessions.mjs.map +0 -1
  246. package/dist/drizzle/oauth-connected-model.mjs.map +0 -1
  247. package/dist/drizzle/oauth-connected-target.d.mts +0 -6
  248. package/dist/drizzle/oauth-connected-target.mjs +0 -12
  249. package/dist/drizzle/oauth-connected-target.mjs.map +0 -1
  250. package/dist/drizzle/oauth-kernel.mjs +0 -11
  251. package/dist/drizzle/oauth-kernel.mjs.map +0 -1
  252. package/dist/drizzle/oauth-mysql.mjs +0 -8
  253. package/dist/drizzle/oauth-mysql.mjs.map +0 -1
  254. package/dist/drizzle/passkey-kernel.mjs +0 -8
  255. package/dist/drizzle/passkey-kernel.mjs.map +0 -1
  256. package/dist/drizzle/passkey-model.mjs.map +0 -1
  257. package/dist/drizzle/passkey-registration-ceremony-model.mjs +0 -2
  258. package/dist/drizzle/passkey-state.mjs +0 -7
  259. package/dist/drizzle/passkey-state.mjs.map +0 -1
  260. package/dist/drizzle/passkey-target.d.mts +0 -2
  261. package/dist/drizzle/passkey-target.mjs +0 -7
  262. package/dist/drizzle/passkey-target.mjs.map +0 -1
  263. package/dist/drizzle/passkey-write-target.d.mts +0 -5
  264. package/dist/drizzle/passkey-write-target.mjs +0 -7
  265. package/dist/drizzle/passkey-write-target.mjs.map +0 -1
  266. package/dist/drizzle/password-prepared-model.d.mts +0 -92
  267. package/dist/drizzle/password-prepared-model.mjs +0 -11
  268. package/dist/drizzle/password-prepared-model.mjs.map +0 -1
  269. package/dist/drizzle/password-prepared-sql.mjs +0 -395
  270. package/dist/drizzle/password-prepared-sql.mjs.map +0 -1
  271. package/dist/drizzle/password-prepared-state.mjs +0 -104
  272. package/dist/drizzle/password-prepared-state.mjs.map +0 -1
  273. package/dist/drizzle/password-prepared-target.d.mts +0 -13
  274. package/dist/drizzle/password-prepared-target.mjs +0 -62
  275. package/dist/drizzle/password-prepared-target.mjs.map +0 -1
  276. package/dist/drizzle/password-registration.d.mts +0 -7
  277. package/dist/drizzle/password-registration.mjs +0 -137
  278. package/dist/drizzle/password-registration.mjs.map +0 -1
  279. package/dist/drizzle/password-sql.d.mts +0 -1
  280. package/dist/drizzle/password-sql.mjs +0 -10
  281. package/dist/drizzle/password-sql.mjs.map +0 -1
  282. package/dist/drizzle/pg-emails.d.mts +0 -72
  283. package/dist/drizzle/pg-emails.mjs +0 -43
  284. package/dist/drizzle/pg-emails.mjs.map +0 -1
  285. package/dist/drizzle/pg-password-prepared.d.mts +0 -31
  286. package/dist/drizzle/pg-password-prepared.mjs +0 -21
  287. package/dist/drizzle/pg-password-prepared.mjs.map +0 -1
  288. package/dist/drizzle/pg-passwords.d.mts +0 -72
  289. package/dist/drizzle/pg-passwords.mjs +0 -43
  290. package/dist/drizzle/pg-passwords.mjs.map +0 -1
  291. package/dist/drizzle/pg-proofs.d.mts +0 -76
  292. package/dist/drizzle/pg-proofs.mjs +0 -27
  293. package/dist/drizzle/pg-proofs.mjs.map +0 -1
  294. package/dist/drizzle/pg-sessions.d.mts +0 -93
  295. package/dist/drizzle/pg-sessions.mjs +0 -58
  296. package/dist/drizzle/pg-sessions.mjs.map +0 -1
  297. package/dist/drizzle/phone-state.mjs +0 -14
  298. package/dist/drizzle/phone-state.mjs.map +0 -1
  299. package/dist/drizzle/phone-target.d.mts +0 -15
  300. package/dist/drizzle/proof-sql.d.mts +0 -1
  301. package/dist/drizzle/proof-sql.mjs +0 -8
  302. package/dist/drizzle/proof-sql.mjs.map +0 -1
  303. package/dist/drizzle/query-operations.mjs +0 -31
  304. package/dist/drizzle/query-operations.mjs.map +0 -1
  305. package/dist/drizzle/session-sql.d.mts +0 -1
  306. package/dist/drizzle/session-sql.mjs +0 -9
  307. package/dist/drizzle/session-sql.mjs.map +0 -1
  308. package/dist/drizzle/session-target.d.mts +0 -30
  309. package/dist/drizzle/session-target.mjs +0 -49
  310. package/dist/drizzle/session-target.mjs.map +0 -1
  311. package/dist/drizzle/sqlite-emails.mjs +0 -50
  312. package/dist/drizzle/sqlite-emails.mjs.map +0 -1
  313. package/dist/drizzle/sqlite-password-prepared.mjs +0 -26
  314. package/dist/drizzle/sqlite-password-prepared.mjs.map +0 -1
  315. package/dist/drizzle/sqlite-passwords.mjs +0 -54
  316. package/dist/drizzle/sqlite-passwords.mjs.map +0 -1
  317. package/dist/drizzle/sqlite-proofs.mjs +0 -34
  318. package/dist/drizzle/sqlite-proofs.mjs.map +0 -1
  319. package/dist/drizzle/sqlite-sessions.mjs +0 -79
  320. package/dist/drizzle/sqlite-sessions.mjs.map +0 -1
  321. package/dist/drizzle/standalone-guard.d.mts +0 -2
  322. package/dist/drizzle/standalone-guard.mjs +0 -21
  323. package/dist/drizzle/standalone-guard.mjs.map +0 -1
  324. package/dist/drizzle/totp-state.d.mts +0 -37
  325. package/dist/drizzle/totp-state.mjs +0 -287
  326. package/dist/drizzle/totp-state.mjs.map +0 -1
  327. package/dist/drizzle/totp-target.d.mts +0 -15
  328. package/dist/drizzle/transaction-execution.d.mts +0 -2
  329. package/dist/drizzle/transaction-execution.mjs +0 -11
  330. package/dist/drizzle/transaction-execution.mjs.map +0 -1
  331. package/dist/drizzle/transaction-owner.d.mts +0 -1
  332. package/dist/drizzle/transaction-owner.mjs +0 -8
  333. package/dist/drizzle/transaction-owner.mjs.map +0 -1
  334. package/src/drizzle/crypto.ts +0 -14
  335. package/src/drizzle/d1-emails.ts +0 -1945
  336. package/src/drizzle/d1-generated-statement.ts +0 -129
  337. package/src/drizzle/d1-oauth.ts +0 -360
  338. package/src/drizzle/d1-passkey.ts +0 -383
  339. package/src/drizzle/d1-password-prepared.ts +0 -1266
  340. package/src/drizzle/d1-passwords.ts +0 -2061
  341. package/src/drizzle/d1-phone.ts +0 -103
  342. package/src/drizzle/d1-planning.ts +0 -104
  343. package/src/drizzle/d1-proofs.ts +0 -2354
  344. package/src/drizzle/d1-sessions.ts +0 -2940
  345. package/src/drizzle/d1-totp.ts +0 -88
  346. package/src/drizzle/email-registration.ts +0 -850
  347. package/src/drizzle/email-sql.ts +0 -25
  348. package/src/drizzle/mysql-emails.ts +0 -343
  349. package/src/drizzle/mysql-password-prepared.ts +0 -198
  350. package/src/drizzle/mysql-passwords.ts +0 -343
  351. package/src/drizzle/mysql-proofs.ts +0 -196
  352. package/src/drizzle/mysql-sessions.ts +0 -780
  353. package/src/drizzle/oauth-connected-target.ts +0 -21
  354. package/src/drizzle/oauth-kernel.ts +0 -10
  355. package/src/drizzle/oauth-mysql.ts +0 -10
  356. package/src/drizzle/passkey-kernel.ts +0 -4
  357. package/src/drizzle/passkey-state.ts +0 -3
  358. package/src/drizzle/passkey-target.ts +0 -23
  359. package/src/drizzle/passkey-write-target.ts +0 -9
  360. package/src/drizzle/password-prepared-model.ts +0 -241
  361. package/src/drizzle/password-prepared-sql.ts +0 -1202
  362. package/src/drizzle/password-prepared-state.ts +0 -231
  363. package/src/drizzle/password-prepared-target.ts +0 -169
  364. package/src/drizzle/password-registration.ts +0 -369
  365. package/src/drizzle/password-sql.ts +0 -16
  366. package/src/drizzle/pg-emails.ts +0 -343
  367. package/src/drizzle/pg-password-prepared.ts +0 -199
  368. package/src/drizzle/pg-passwords.ts +0 -342
  369. package/src/drizzle/pg-proofs.ts +0 -206
  370. package/src/drizzle/pg-sessions.ts +0 -789
  371. package/src/drizzle/phone-state.ts +0 -21
  372. package/src/drizzle/proof-sql.ts +0 -10
  373. package/src/drizzle/query-operations.ts +0 -49
  374. package/src/drizzle/session-sql.ts +0 -15
  375. package/src/drizzle/session-target.ts +0 -337
  376. package/src/drizzle/sqlite-emails.ts +0 -393
  377. package/src/drizzle/sqlite-password-prepared.ts +0 -230
  378. package/src/drizzle/sqlite-passwords.ts +0 -497
  379. package/src/drizzle/sqlite-proofs.ts +0 -229
  380. package/src/drizzle/sqlite-sessions.ts +0 -1013
  381. package/src/drizzle/totp-state.ts +0 -525
  382. package/src/drizzle/transaction-execution.ts +0 -13
  383. package/src/drizzle/transaction-owner.ts +0 -11
@@ -1,1202 +0,0 @@
1
- import {
2
- type NativeDatabase,
3
- CurrentPasswordPreparedTransaction,
4
- PasswordPreparedPostconditions,
5
- PasswordPreparedJournalGuards,
6
- } from "@yielded/auth-persistence/Adapter";
7
- import { CurrentCommitJournal, LifecycleHooks, HookConfigurationError } from "@yielded/auth/Hooks";
8
- import {
9
- PasswordUnavailable,
10
- PasswordRejected,
11
- PasswordPreparedVersion,
12
- decodePasswordPreparedReady,
13
- encodePasswordPreparedReady,
14
- snapshotPasswordPreparedReady,
15
- snapshotPasswordPreparedReservation,
16
- type PasswordPreparedReady,
17
- type PasswordPreparedReservation,
18
- snapshotPasswordCredential,
19
- snapshotPasswordRequirement,
20
- type PasswordMutationDecision,
21
- type PreparePasswordCommit,
22
- type PasswordPreparedPersistence,
23
- type PasswordPreparedMutation,
24
- } from "@yielded/auth/Password";
25
- import { reportPersistenceFailure } from "@yielded/auth/Persistence";
26
- import { type ProofCompletionPlan, ProofUnavailable, ProofBinding } from "@yielded/auth/Proofs";
27
- import { AuthenticationRevision } from "@yielded/auth/Sessions";
28
- /* oxlint-disable no-explicit-any -- concrete driver makers retain consumer table types. */
29
- import { and, count, eq, gt, isNotNull, isNull, lte, or, type SQL } from "drizzle-orm";
30
- import { Cause, DateTime, Effect, Option, Predicate, Redacted, Schema } from "effect";
31
-
32
- import { column } from "./model";
33
- import {
34
- requiredPasswordPreparedConstraints,
35
- type AnyPasswordPreparedPersistenceMapping,
36
- type PasswordPreparedState,
37
- } from "./password-prepared-model";
38
- import {
39
- ContextInput,
40
- CompletionInput,
41
- encodeReservation,
42
- evidenceCurrent,
43
- identifierScope,
44
- reservationOf,
45
- sameRevision,
46
- snapshotMutation,
47
- snapshotReserve,
48
- unavailable,
49
- } from "./password-prepared-state";
50
- import {
51
- CurrentPasswordSql,
52
- passwordSqlKernel as kernel,
53
- type PasswordSqlConfiguration,
54
- type PasswordSqlQuery,
55
- } from "./password-sql";
56
- import { checkProofCompletionIn, completeProofPlanIn } from "./proof-sql";
57
- import { validateDrizzleStorage } from "./storage-validation";
58
-
59
- const translateFailure = <A, E, R>(
60
- effect: Effect.Effect<A, E, R>,
61
- ): Effect.Effect<A, PasswordUnavailable, R> =>
62
- reportPersistenceFailure(
63
- effect,
64
- (error) =>
65
- Schema.is(PasswordUnavailable)(error) ||
66
- Schema.is(ProofUnavailable)(error) ||
67
- Schema.is(HookConfigurationError)(error),
68
- ).pipe(Effect.catchCause((cause) => Effect.failCause(Cause.map(cause, () => unavailable()))));
69
-
70
- const translateContextFailure = <A, E, R>(
71
- effect: Effect.Effect<A, E, R>,
72
- ): Effect.Effect<A, PasswordUnavailable | PasswordRejected, R> =>
73
- reportPersistenceFailure(
74
- effect,
75
- (error) =>
76
- Schema.is(PasswordUnavailable)(error) ||
77
- Schema.is(PasswordRejected)(error) ||
78
- Schema.is(ProofUnavailable)(error) ||
79
- Schema.is(HookConfigurationError)(error),
80
- ).pipe(
81
- Effect.catchCause((cause) =>
82
- Effect.failCause(
83
- Cause.map(cause, (error) => (Schema.is(PasswordRejected)(error) ? error : unavailable())),
84
- ),
85
- ),
86
- );
87
-
88
- type Mapping = AnyPasswordPreparedPersistenceMapping;
89
- const nowMillis = DateTime.now.pipe(Effect.map(DateTime.toEpochMillis));
90
-
91
- const read = (query: PasswordSqlQuery, locking: boolean) =>
92
- locking && typeof query.for === "function" ? query.for("update") : query;
93
-
94
- const columns = (mapping: Mapping) => {
95
- const table = mapping.intent;
96
-
97
- return {
98
- moduleId: column(table.table, table.moduleId),
99
- intentId: column(table.table, table.intentId),
100
- commandId: column(table.table, table.commandId),
101
- subjectId: column(table.table, table.subjectId),
102
- action: column(table.table, table.action),
103
- generation: column(table.table, table.generation),
104
- version: column(table.table, table.version),
105
- state: column(table.table, table.state),
106
- digest: column(table.table, table.digest),
107
- snapshot: column(table.table, table.snapshot),
108
- identifierScope: column(table.table, table.identifierScope),
109
- createdAt: column(table.table, table.createdAt),
110
- admittedAt: column(table.table, table.admittedAt),
111
- admissionRetainUntil: column(table.table, table.admissionRetainUntil),
112
- preparationExpiresAt: column(table.table, table.preparationExpiresAt),
113
- expiresAt: column(table.table, table.expiresAt),
114
- retainUntil: column(table.table, table.retainUntil),
115
- };
116
- };
117
-
118
- const valid = (mapping: Mapping) =>
119
- Object.entries(requiredPasswordPreparedConstraints).every(
120
- ([key, value]) =>
121
- mapping.constraints[key as keyof typeof requiredPasswordPreparedConstraints] === value,
122
- );
123
-
124
- const lockAnchor = Effect.fn("DrizzlePasswordPrepared.lockAnchor")(function* (
125
- mapping: Mapping,
126
- configuration: PasswordSqlConfiguration,
127
- moduleId: string,
128
- create = true,
129
- ) {
130
- const database = yield* CurrentPasswordSql;
131
-
132
- const a = mapping.admission,
133
- key = column(a.table, a.moduleId);
134
-
135
- if (create)
136
- yield* configuration.insertIfAbsent(
137
- database.insert(a.table).values(a.encodeInsert(moduleId)),
138
- a.moduleId,
139
- moduleId,
140
- );
141
-
142
- const rows = yield* read(
143
- database.select().from(a.table).where(eq(key, moduleId)).limit(2),
144
- configuration.locking,
145
- );
146
-
147
- if (rows.length > 1 || (create && rows.length !== 1)) return yield* unavailable();
148
-
149
- return rows.length === 1;
150
- });
151
-
152
- const bindingJson = Schema.encodeSync(Schema.fromJsonString(ProofBinding));
153
-
154
- const captureAuthority = Effect.fn("DrizzlePasswordPrepared.captureAuthority")(function* (
155
- mapping: Mapping,
156
- configuration: Pick<PasswordSqlConfiguration, "locking">,
157
- input: {
158
- readonly moduleId: string;
159
- readonly action: PasswordPreparedReservation["action"];
160
- readonly subjectId: string;
161
- readonly reset?: PasswordPreparedReservation["reset"];
162
- },
163
- ) {
164
- const database = yield* CurrentPasswordSql;
165
-
166
- const p = mapping.password;
167
- const locked = yield* kernel.lockSubject(p, input.subjectId, configuration.locking);
168
-
169
- if (locked.row === undefined || !p.subject.isActiveStatus(locked.row[p.subject.status]))
170
- return undefined;
171
-
172
- const ic = kernel.identifierColumns(p),
173
- ac = kernel.authorityCredentialColumns(p);
174
-
175
- let identifier: any;
176
-
177
- if (input.action !== "add-password") {
178
- if (input.reset !== undefined)
179
- identifier = (yield* kernel.lockIdentifier(
180
- p,
181
- input.reset.binding.identifier,
182
- configuration.locking,
183
- ))[0];
184
- else {
185
- const discovered = (yield* read(
186
- database
187
- .select()
188
- .from(p.identifier.table)
189
- .where(eq(ic.subjectId, locked.nativeSubjectId))
190
- .orderBy(ic.namespace, ic.value),
191
- false,
192
- )).find((row: any) => p.identifier.isCurrent(row));
193
-
194
- if (discovered !== undefined)
195
- identifier = (yield* kernel.lockIdentifier(
196
- p,
197
- {
198
- namespace: discovered[p.identifier.namespace],
199
- value: discovered[p.identifier.value],
200
- } as any,
201
- configuration.locking,
202
- ))[0];
203
- }
204
- if (
205
- identifier === undefined ||
206
- !p.identifier.isCurrent(identifier) ||
207
- !p.subjectId.equals(identifier[p.identifier.subjectId], locked.nativeSubjectId)
208
- )
209
- return undefined;
210
- }
211
-
212
- const credential = (yield* kernel.readPasswordCredential(
213
- p,
214
- input.moduleId,
215
- locked.nativeSubjectId,
216
- configuration.locking,
217
- ))[0];
218
-
219
- if ((input.action === "add-password") !== (credential === undefined)) return undefined;
220
-
221
- const snapshot =
222
- credential === undefined
223
- ? undefined
224
- : yield* p.credential
225
- .decode({ moduleId: input.moduleId, subject: locked.row, identifier, credential })
226
- .pipe(Effect.flatMap(snapshotPasswordCredential));
227
-
228
- if (
229
- snapshot !== undefined &&
230
- (snapshot.moduleId !== input.moduleId ||
231
- snapshot.revision.subjectId !== input.subjectId ||
232
- snapshot.revision.securityRevision !== locked.row[p.subject.securityRevision] ||
233
- snapshot.credentialId !== credential[p.credential.credentialId] ||
234
- snapshot.credentialRevision !== credential[p.credential.credentialRevision] ||
235
- snapshot.verifierVersion !== credential[p.credential.verifierVersion] ||
236
- Redacted.value(snapshot.verifier) !== credential[p.credential.verifier] ||
237
- snapshot.normalization !== credential[p.credential.normalization] ||
238
- snapshot.identifier.namespace !== identifier[p.identifier.namespace] ||
239
- snapshot.identifier.value !== identifier[p.identifier.value] ||
240
- snapshot.identifierBindingRevision !== identifier[p.identifier.bindingRevision])
241
- )
242
- return undefined;
243
-
244
- const factors = yield* read(
245
- database
246
- .select()
247
- .from(p.authorityCredential.table)
248
- .where(eq(ac.subjectId, locked.nativeSubjectId))
249
- .orderBy(ac.credentialId),
250
- configuration.locking,
251
- );
252
-
253
- const active = factors.filter(
254
- (row: any) =>
255
- p.authorityCredential.status === undefined ||
256
- p.authorityCredential.isActiveStatus?.(row[p.authorityCredential.status]) === true,
257
- );
258
-
259
- if (active.length > 64) return yield* unavailable();
260
-
261
- const revision =
262
- snapshot?.revision ??
263
- AuthenticationRevision.make({
264
- subjectId: input.subjectId as any,
265
- securityRevision: locked.row[p.subject.securityRevision],
266
- credentials: active.map((row: any) => ({
267
- credentialId: row[p.authorityCredential.credentialId],
268
- revision: row[p.authorityCredential.revision],
269
- })),
270
- });
271
-
272
- if (
273
- revision.credentials.some(
274
- (expected) =>
275
- !active.some(
276
- (row: any) =>
277
- row[p.authorityCredential.credentialId] === expected.credentialId &&
278
- row[p.authorityCredential.revision] === expected.revision,
279
- ),
280
- )
281
- )
282
- return undefined;
283
-
284
- const requirement = yield* p.subject
285
- .decodeActionRequirement(locked.row, input.action)
286
- .pipe(Effect.flatMap(snapshotPasswordRequirement));
287
-
288
- return { ...locked, identifier, snapshot, revision, requirement };
289
- });
290
-
291
- const currentAuthority = Effect.fn("DrizzlePasswordPrepared.currentAuthority")(function* (
292
- mapping: Mapping,
293
- configuration: Pick<PasswordSqlConfiguration, "locking">,
294
- record: PasswordPreparedReservation | PasswordPreparedReady,
295
- ) {
296
- const current = yield* captureAuthority(mapping, configuration, {
297
- moduleId: record.moduleId,
298
- action: record.action,
299
- subjectId: record.revision.subjectId,
300
- ...(record.reset === undefined ? {} : { reset: record.reset }),
301
- });
302
-
303
- if (
304
- current === undefined ||
305
- !sameRevision(current.revision, record.revision) ||
306
- (current.snapshot === undefined
307
- ? record.credential !== undefined
308
- : record.credential === undefined ||
309
- !kernel.sameCredentialSnapshot(current.snapshot, record.credential))
310
- )
311
- return undefined;
312
-
313
- return current;
314
- });
315
-
316
- const rowCondition = (mapping: Mapping, row: any) => {
317
- const c = columns(mapping);
318
-
319
- return and(
320
- ...Object.entries(c).map(([key, value]) => {
321
- const field = mapping.intent[key as keyof typeof c],
322
- item = row[field];
323
-
324
- return Predicate.isNullish(item) ? isNull(value) : eq(value, item);
325
- }),
326
- )!;
327
- };
328
-
329
- const readIntent = Effect.fn("Drizzle.readIntent")(function* (
330
- mapping: Mapping,
331
- condition: SQL,
332
- locking: boolean,
333
- ) {
334
- const database = yield* CurrentPasswordSql;
335
-
336
- return yield* read(
337
- database.select().from(mapping.intent.table).where(condition).limit(2),
338
- locking,
339
- );
340
- });
341
-
342
- const recordMatches = Effect.fn("DrizzlePasswordPrepared.recordMatches")(function* (
343
- mapping: Mapping,
344
- row: any,
345
- record: PasswordPreparedReservation | PasswordPreparedReady,
346
- nativeSubjectId: unknown,
347
- snapshot: string,
348
- ) {
349
- const t = mapping.intent,
350
- p = mapping.password;
351
-
352
- if (
353
- row === undefined ||
354
- row[t.moduleId] !== record.moduleId ||
355
- row[t.intentId] !== record.intentId ||
356
- row[t.commandId] !== record.commandId ||
357
- !p.subjectId.equals(row[t.subjectId], nativeSubjectId) ||
358
- row[t.action] !== record.action ||
359
- row[t.generation] !== record.generation ||
360
- row[t.version] !== record.version ||
361
- row[t.state] !== t.states[record._tag] ||
362
- row[t.snapshot] !== snapshot ||
363
- row[t.identifierScope] !== identifierScope(record) ||
364
- (record._tag === "Ready"
365
- ? row[t.digest] !== record.digest
366
- : !Predicate.isNullish(row[t.digest]))
367
- )
368
- return false;
369
- for (const [key, instant] of [
370
- [t.createdAt, record.createdAtMillis],
371
- [t.preparationExpiresAt, record.preparationExpiresAtMillis],
372
- [t.retainUntil, record.retainUntilMillis],
373
- ] as const)
374
- if ((yield* p.decodeInstant(row[key])) !== instant) return false;
375
-
376
- return record._tag === "Ready"
377
- ? (yield* p.decodeInstant(row[t.expiresAt])) === record.expiresAtMillis
378
- : Predicate.isNullish(row[t.expiresAt]);
379
- });
380
-
381
- const terminal = Effect.fn("DrizzlePasswordPrepared.terminal")(function* (
382
- mapping: Mapping,
383
- row: any,
384
- state: Exclude<PasswordPreparedState, "Preparing" | "Ready">,
385
- ) {
386
- const database = yield* CurrentPasswordSql;
387
-
388
- yield* database
389
- .update(mapping.intent.table)
390
- .set(mapping.intent.encodeTerminal(state))
391
- .where(rowCondition(mapping, row));
392
-
393
- const c = columns(mapping),
394
- t = mapping.intent;
395
-
396
- const rows = yield* readIntent(
397
- mapping,
398
- and(eq(c.moduleId, row[t.moduleId]), eq(c.intentId, row[t.intentId]))!,
399
- false,
400
- );
401
-
402
- const expected = { ...row, [t.state]: t.states[state], [t.snapshot]: null, [t.digest]: null };
403
-
404
- if (
405
- rows.length !== 1 ||
406
- (yield* readIntent(mapping, rowCondition(mapping, expected), false)).length !== 1
407
- )
408
- return yield* unavailable();
409
- });
410
-
411
- export const makeSqlPasswordPreparedPersistence = Effect.fn("makeSqlPasswordPreparedPersistence")(
412
- function* (
413
- mapping: Mapping,
414
- configuration: PasswordSqlConfiguration,
415
- ): Effect.fn.Return<
416
- PasswordPreparedPersistence,
417
- PasswordUnavailable,
418
- LifecycleHooks | CurrentPasswordSql | NativeDatabase
419
- > {
420
- const database = yield* CurrentPasswordSql;
421
-
422
- if (!configuration.coordinated)
423
- yield* validateDrizzleStorage({
424
- ...mapping,
425
- proof: configuration.proof?.mapping,
426
- }).pipe(Effect.mapError(unavailable));
427
- const hooks = yield* LifecycleHooks;
428
-
429
- const p = mapping.password,
430
- c = columns(mapping),
431
- t = mapping.intent;
432
-
433
- const owned = <A, E, R>(body: Effect.Effect<A, E, R>) =>
434
- valid(mapping)
435
- ? kernel.owned(
436
- database,
437
- p,
438
- configuration,
439
- Effect.gen(function* () {
440
- const journal = yield* CurrentCommitJournal;
441
- const guards = yield* Effect.serviceOption(PasswordPreparedJournalGuards);
442
-
443
- if (Option.isSome(guards) && !guards.value.register(journal.prepare(undefined)))
444
- return yield* unavailable();
445
-
446
- return yield* body;
447
- }),
448
- )
449
- : Effect.fail(unavailable());
450
-
451
- const complete = <A>(
452
- uncaptured: PasswordPreparedMutation & { readonly completion?: ProofCompletionPlan },
453
- prepare: PreparePasswordCommit<PasswordMutationDecision, A>,
454
- ) =>
455
- Effect.gen(function* () {
456
- const input = yield* snapshotMutation(uncaptured);
457
-
458
- const completion =
459
- uncaptured.completion === undefined
460
- ? undefined
461
- : {
462
- prepare: uncaptured.completion.prepare,
463
- input: yield* Schema.encodeEffect(Schema.fromJsonString(CompletionInput))(
464
- uncaptured.completion.input,
465
- ).pipe(
466
- Effect.flatMap(Schema.decodeEffect(Schema.fromJsonString(CompletionInput))),
467
- Effect.mapError(unavailable),
468
- ),
469
- };
470
-
471
- if (
472
- (input.intent.action === "reset-password") !== (completion !== undefined) ||
473
- (completion !== undefined && configuration.proof === undefined)
474
- )
475
- return yield* unavailable();
476
-
477
- return yield* owned(
478
- Effect.gen(function* () {
479
- const transaction = yield* CurrentPasswordSql;
480
- const journal = yield* CurrentCommitJournal;
481
-
482
- yield* lockAnchor(mapping, configuration, input.intent.moduleId);
483
-
484
- const authority = yield* kernel.validateMutationAuthority(
485
- p,
486
- configuration,
487
- input.mutation,
488
- input.intent.action,
489
- );
490
-
491
- if (authority === undefined) return prepare("rejected", journal);
492
- const current = yield* currentAuthority(mapping, configuration, input.intent);
493
-
494
- if (current === undefined) return prepare("rejected", journal);
495
-
496
- const rows = yield* readIntent(
497
- mapping,
498
- and(eq(c.moduleId, input.intent.moduleId), eq(c.intentId, input.intent.intentId))!,
499
- configuration.locking,
500
- );
501
-
502
- const row = rows[0],
503
- encoded = yield* encodePasswordPreparedReady(input.intent);
504
-
505
- if (
506
- rows.length !== 1 ||
507
- !(yield* recordMatches(
508
- mapping,
509
- row,
510
- input.intent,
511
- current.nativeSubjectId,
512
- encoded,
513
- )) ||
514
- !evidenceCurrent(input, current.requirement, yield* nowMillis) ||
515
- (yield* kernel.commandExists(
516
- p,
517
- input.intent.moduleId,
518
- input.intent.commandId,
519
- configuration.locking,
520
- )).length !== 0
521
- )
522
- return prepare("rejected", journal);
523
- if (
524
- completion !== undefined &&
525
- (input.intent.reset === undefined ||
526
- completion.input.continuationId !== input.intent.reset.continuationId ||
527
- bindingJson(completion.input.binding) !== bindingJson(input.intent.reset.binding) ||
528
- !kernel.proofCompletionMatchesPassword({ ...input.mutation, completion }))
529
- )
530
- return prepare("rejected", journal);
531
-
532
- const credentialRevision = yield* kernel.allocate(
533
- configuration.mode,
534
- p.allocateRevision,
535
- p.allocateRevisionSync,
536
- );
537
-
538
- const verifierVersion = yield* kernel.allocate(
539
- configuration.mode,
540
- p.allocateRevision,
541
- p.allocateRevisionSync,
542
- );
543
-
544
- const nextSecurityRevision = yield* kernel.allocateNextSecurityRevision(
545
- p,
546
- configuration.mode,
547
- input.intent.revision.securityRevision,
548
- );
549
-
550
- if (
551
- nextSecurityRevision === input.intent.revision.securityRevision ||
552
- credentialRevision === input.intent.credential?.credentialRevision ||
553
- verifierVersion === input.intent.credential?.verifierVersion
554
- )
555
- return yield* unavailable();
556
-
557
- const credentialId =
558
- input.intent.action === "add-password"
559
- ? yield* kernel.allocate(
560
- configuration.mode,
561
- p.allocateCredentialId,
562
- p.allocateCredentialIdSync,
563
- )
564
- : undefined;
565
-
566
- let appliedAt: number | undefined;
567
-
568
- const assertApplied = Effect.fn("DrizzlePasswordPrepared.assertApplied")(() =>
569
- Effect.flatMap(CurrentPasswordPreparedTransaction, (currentTransaction) =>
570
- Effect.gen(function* () {
571
- if (appliedAt === undefined) return;
572
-
573
- if (
574
- !(yield* kernel.checkMutationApplied(
575
- p,
576
- input.mutation,
577
- current.nativeSubjectId,
578
- {
579
- credentialId: credentialId ?? input.intent.credential!.credentialId,
580
- credentialRevision,
581
- verifierVersion,
582
- nextSecurityRevision,
583
- },
584
- appliedAt,
585
- )) ||
586
- (yield* readIntent(
587
- mapping,
588
- rowCondition(mapping, {
589
- ...row,
590
- [t.state]: t.states.Consumed,
591
- [t.snapshot]: null,
592
- [t.digest]: null,
593
- }),
594
- false,
595
- )).length !== 1 ||
596
- !evidenceCurrent(input, current.requirement, yield* nowMillis)
597
- )
598
- return yield* unavailable();
599
- }).pipe(Effect.provideService(CurrentPasswordSql, currentTransaction)),
600
- ),
601
- );
602
-
603
- const validateApplied = Effect.gen(function* () {
604
- yield* assertApplied().pipe(
605
- Effect.provideService(CurrentPasswordPreparedTransaction, transaction),
606
- );
607
- if (appliedAt === undefined) return;
608
- const postconditions = yield* Effect.serviceOption(PasswordPreparedPostconditions);
609
-
610
- if (
611
- Option.isSome(postconditions) &&
612
- !postconditions.value.register(assertApplied().pipe(translateFailure))
613
- )
614
- return yield* unavailable();
615
- });
616
-
617
- const apply = Effect.fn("DrizzlePasswordPrepared.apply")(function* () {
618
- const finalNow = yield* nowMillis;
619
-
620
- if (!evidenceCurrent(input, current.requirement, finalNow)) return false;
621
-
622
- const changed =
623
- input.intent.action === "add-password"
624
- ? yield* kernel.addPasswordIn(
625
- p,
626
- configuration,
627
- input.mutation,
628
- {
629
- credentialId: credentialId!,
630
- credentialRevision,
631
- verifierVersion,
632
- nextSecurityRevision,
633
- },
634
- finalNow,
635
- )
636
- : yield* kernel.writeReplacement(
637
- p,
638
- input.mutation,
639
- current.nativeSubjectId,
640
- { credentialRevision, verifierVersion, nextSecurityRevision },
641
- finalNow,
642
- );
643
-
644
- if (!changed) return yield* unavailable();
645
- appliedAt = finalNow;
646
- yield* terminal(mapping, row, "Consumed");
647
- if (!evidenceCurrent(input, current.requirement, yield* nowMillis))
648
- return yield* unavailable();
649
-
650
- return true;
651
- });
652
-
653
- if (completion !== undefined) {
654
- let receipt: ReturnType<typeof prepare> | undefined;
655
-
656
- yield* completeProofPlanIn(
657
- configuration.proof!.mapping,
658
- configuration.proof!.configuration,
659
- completion,
660
- Effect.gen(function* () {
661
- return yield* apply();
662
- }),
663
- (decision) => {
664
- receipt = prepare(decision === "completed" ? "changed" : "rejected", journal);
665
-
666
- return decision;
667
- },
668
- );
669
-
670
- yield* validateApplied;
671
-
672
- return receipt ?? prepare("rejected", journal);
673
- }
674
-
675
- const changed = yield* apply();
676
-
677
- yield* validateApplied;
678
-
679
- return prepare(changed ? "changed" : "rejected", journal);
680
- }),
681
- );
682
- });
683
-
684
- const services: PasswordPreparedPersistence = {
685
- reserve: (uncaptured, prepare) =>
686
- Effect.gen(function* () {
687
- const input = yield* snapshotReserve(uncaptured);
688
-
689
- if (
690
- (input.action === "reset-password") !==
691
- (input.reset !== undefined && input.completion !== undefined) ||
692
- (input.action === "reset-password" && configuration.proof === undefined) ||
693
- input.generation !== input.policy.generation ||
694
- input.policy.retentionMillis <
695
- Math.max(
696
- input.policy.preparationLifetimeMillis + input.policy.lifetimeMillis,
697
- input.policy.admission.action.windowMillis,
698
- input.policy.admission.identifier.windowMillis,
699
- input.policy.admission.subject.windowMillis,
700
- ) ||
701
- ((input.invalidation.existingSessions === "immediate" ||
702
- input.invalidation.existingSessions === "cache-expiry") &&
703
- p.sessionInvalidation !== "same-authority-immediate")
704
- )
705
- return yield* unavailable();
706
-
707
- return yield* owned(
708
- Effect.gen(function* () {
709
- const transaction = yield* CurrentPasswordSql;
710
- const journal = yield* CurrentCommitJournal;
711
-
712
- yield* lockAnchor(mapping, configuration, input.moduleId);
713
-
714
- const version = PasswordPreparedVersion.make(
715
- yield* kernel.allocate(
716
- configuration.mode,
717
- mapping.allocateVersion,
718
- mapping.allocateVersionSync,
719
- ),
720
- );
721
-
722
- const authority = yield* captureAuthority(mapping, configuration, input);
723
-
724
- if (authority === undefined) return yield* unavailable();
725
- if (input.reset !== undefined) {
726
- if (
727
- input.completion === undefined ||
728
- input.completion.moduleId !== `${input.moduleId}/reset` ||
729
- input.completion.purpose !== "password-reset" ||
730
- input.reset.continuationId !== input.completion.continuationId ||
731
- bindingJson(input.reset.binding) !== bindingJson(input.completion.binding) ||
732
- input.reset.binding._tag !== "Subject" ||
733
- !sameRevision(input.reset.binding.revision, authority.revision) ||
734
- authority.snapshot?.identifierVerifiedAtMillis === undefined ||
735
- !(yield* checkProofCompletionIn(
736
- configuration.proof!.mapping,
737
- configuration.proof!.configuration,
738
- input.completion,
739
- ))
740
- )
741
- return yield* unavailable();
742
- }
743
- if (
744
- (yield* readIntent(
745
- mapping,
746
- and(eq(c.moduleId, input.moduleId), eq(c.commandId, input.commandId))!,
747
- configuration.locking,
748
- )).length
749
- )
750
- return prepare({ _tag: "Existing" }, journal);
751
-
752
- const now = yield* nowMillis,
753
- nativeNow = p.encodeInstant(now);
754
-
755
- const scope = identifierScope({
756
- ...(authority.snapshot === undefined ? {} : { credential: authority.snapshot }),
757
- revision: authority.revision,
758
- });
759
-
760
- const active =
761
- (yield* read(
762
- transaction
763
- .select({ total: count() })
764
- .from(t.table)
765
- .where(
766
- and(
767
- eq(c.moduleId, input.moduleId),
768
- eq(c.subjectId, authority.nativeSubjectId),
769
- or(
770
- and(
771
- eq(c.state, t.states.Preparing),
772
- gt(c.preparationExpiresAt, nativeNow),
773
- ),
774
- and(eq(c.state, t.states.Ready), gt(c.expiresAt, nativeNow)),
775
- ),
776
- ),
777
- ),
778
- false,
779
- ))[0]?.total ?? 0;
780
-
781
- if (active >= input.policy.maximumPendingPerSubject) return yield* unavailable();
782
- for (const [condition, budget] of [
783
- [eq(c.action, input.action), input.policy.admission.action],
784
- [eq(c.identifierScope, scope), input.policy.admission.identifier],
785
- [eq(c.subjectId, authority.nativeSubjectId), input.policy.admission.subject],
786
- ] as const) {
787
- const total =
788
- (yield* read(
789
- transaction
790
- .select({ total: count() })
791
- .from(t.table)
792
- .where(
793
- and(
794
- eq(c.moduleId, input.moduleId),
795
- condition,
796
- gt(c.admittedAt, p.encodeInstant(now - budget.windowMillis)),
797
- ),
798
- ),
799
- false,
800
- ))[0]?.total ?? 0;
801
-
802
- if (total >= budget.limit) return yield* unavailable();
803
- }
804
-
805
- const reservation = yield* snapshotPasswordPreparedReservation({
806
- _tag: "Preparing",
807
- moduleId: input.moduleId,
808
- generation: input.generation,
809
- intentId: input.intentId,
810
- version,
811
- commandId: input.commandId,
812
- action: input.action,
813
- revision: authority.revision,
814
- ...(authority.snapshot === undefined ? {} : { credential: authority.snapshot }),
815
- capturedRequirement: authority.requirement,
816
- ...(input.reset === undefined ? {} : { reset: input.reset }),
817
- invalidation: input.invalidation,
818
- createdAtMillis: now,
819
- preparationExpiresAtMillis: now + input.policy.preparationLifetimeMillis,
820
- retainUntilMillis: now + input.policy.retentionMillis,
821
- });
822
-
823
- const snapshot = yield* encodeReservation(reservation);
824
-
825
- yield* transaction.insert(t.table).values(
826
- t.encodeInsert({
827
- reservation,
828
- nativeSubjectId: authority.nativeSubjectId,
829
- identifierScope: scope,
830
- snapshot,
831
- admittedAtMillis: now,
832
- admissionRetainUntilMillis:
833
- now +
834
- Math.max(
835
- input.policy.admission.action.windowMillis,
836
- input.policy.admission.identifier.windowMillis,
837
- input.policy.admission.subject.windowMillis,
838
- ),
839
- }),
840
- );
841
-
842
- const rows = yield* readIntent(
843
- mapping,
844
- and(eq(c.moduleId, input.moduleId), eq(c.intentId, input.intentId))!,
845
- false,
846
- );
847
-
848
- if (
849
- rows.length !== 1 ||
850
- !(yield* recordMatches(
851
- mapping,
852
- rows[0],
853
- reservation,
854
- authority.nativeSubjectId,
855
- snapshot,
856
- ))
857
- )
858
- return yield* unavailable();
859
-
860
- const admittedUntil =
861
- now +
862
- Math.max(
863
- input.policy.admission.action.windowMillis,
864
- input.policy.admission.identifier.windowMillis,
865
- input.policy.admission.subject.windowMillis,
866
- );
867
-
868
- if (
869
- (yield* p.decodeInstant(rows[0][t.admittedAt])) !== now ||
870
- (yield* p.decodeInstant(rows[0][t.admissionRetainUntil])) !== admittedUntil ||
871
- (yield* nowMillis) >= reservation.preparationExpiresAtMillis ||
872
- (input.completion !== undefined &&
873
- !(yield* checkProofCompletionIn(
874
- configuration.proof!.mapping,
875
- configuration.proof!.configuration,
876
- input.completion,
877
- )))
878
- )
879
- return yield* unavailable();
880
-
881
- return prepare({ _tag: "Reserved", reservation }, journal);
882
- }),
883
- );
884
- }).pipe(
885
- Effect.provideService(CurrentPasswordSql, database),
886
- Effect.provideService(LifecycleHooks, hooks),
887
- translateFailure,
888
- ),
889
- publishReady: (uncaptured, prepare) =>
890
- Effect.gen(function* () {
891
- const reservation = yield* snapshotPasswordPreparedReservation(uncaptured.reservation),
892
- ready = yield* snapshotPasswordPreparedReady(uncaptured.ready);
893
-
894
- const snapshot = yield* encodeReservation(reservation),
895
- readySnapshot = yield* encodePasswordPreparedReady(ready);
896
-
897
- if ((yield* encodeReservation(reservationOf(ready))) !== snapshot)
898
- return yield* unavailable();
899
-
900
- return yield* owned(
901
- Effect.gen(function* () {
902
- const transaction = yield* CurrentPasswordSql;
903
- const journal = yield* CurrentCommitJournal;
904
-
905
- yield* lockAnchor(mapping, configuration, reservation.moduleId);
906
- const authority = yield* currentAuthority(mapping, configuration, reservation);
907
-
908
- if (authority === undefined) return prepare("rejected", journal);
909
-
910
- const rows = yield* readIntent(
911
- mapping,
912
- and(eq(c.moduleId, reservation.moduleId), eq(c.intentId, reservation.intentId))!,
913
- configuration.locking,
914
- ),
915
- row = rows[0];
916
-
917
- const now = yield* nowMillis;
918
-
919
- if (
920
- rows.length !== 1 ||
921
- !(yield* recordMatches(
922
- mapping,
923
- row,
924
- reservation,
925
- authority.nativeSubjectId,
926
- snapshot,
927
- )) ||
928
- now < ready.issuedAtMillis ||
929
- now >= reservation.preparationExpiresAtMillis ||
930
- now >= ready.expiresAtMillis
931
- )
932
- return prepare("rejected", journal);
933
- yield* transaction
934
- .update(t.table)
935
- .set(t.encodeReady({ ready, snapshot: readySnapshot }))
936
- .where(rowCondition(mapping, row));
937
-
938
- const saved = yield* readIntent(
939
- mapping,
940
- and(eq(c.moduleId, ready.moduleId), eq(c.intentId, ready.intentId))!,
941
- false,
942
- );
943
-
944
- if (
945
- saved.length !== 1 ||
946
- !(yield* recordMatches(
947
- mapping,
948
- saved[0],
949
- ready,
950
- authority.nativeSubjectId,
951
- readySnapshot,
952
- )) ||
953
- (yield* readIntent(
954
- mapping,
955
- and(
956
- eq(c.moduleId, ready.moduleId),
957
- eq(c.intentId, ready.intentId),
958
- eq(c.admittedAt, row[t.admittedAt]),
959
- eq(c.admissionRetainUntil, row[t.admissionRetainUntil]),
960
- )!,
961
- false,
962
- )).length !== 1
963
- )
964
- return yield* unavailable();
965
- if (
966
- (yield* nowMillis) >= reservation.preparationExpiresAtMillis ||
967
- (yield* nowMillis) >= ready.expiresAtMillis
968
- )
969
- return yield* unavailable();
970
-
971
- return prepare("published", journal);
972
- }),
973
- );
974
- }).pipe(
975
- Effect.provideService(CurrentPasswordSql, database),
976
- Effect.provideService(LifecycleHooks, hooks),
977
- translateFailure,
978
- ),
979
- context: (uncaptured) =>
980
- Effect.gen(function* () {
981
- const input = yield* Schema.decodeEffect(ContextInput)({ ...uncaptured }).pipe(
982
- Effect.mapError(unavailable),
983
- );
984
-
985
- const record = yield* kernel.safeRead(
986
- database,
987
- configuration,
988
- Effect.gen(function* () {
989
- if (
990
- !valid(mapping) ||
991
- !(yield* lockAnchor(mapping, configuration, input.moduleId, false))
992
- )
993
- return undefined;
994
-
995
- const rows = yield* readIntent(
996
- mapping,
997
- and(
998
- eq(c.moduleId, input.moduleId),
999
- eq(c.generation, input.generation),
1000
- eq(c.digest, input.digest),
1001
- eq(c.state, t.states.Ready),
1002
- )!,
1003
- false,
1004
- );
1005
-
1006
- if (rows.length !== 1) return undefined;
1007
- const selected = yield* decodePasswordPreparedReady(rows[0][t.snapshot]);
1008
- const authority = yield* currentAuthority(mapping, configuration, selected);
1009
-
1010
- if (authority === undefined) return undefined;
1011
-
1012
- const locked = yield* readIntent(
1013
- mapping,
1014
- rowCondition(mapping, rows[0]),
1015
- configuration.locking,
1016
- );
1017
-
1018
- const now = yield* nowMillis;
1019
-
1020
- if (
1021
- locked.length !== 1 ||
1022
- now < selected.issuedAtMillis ||
1023
- now >= selected.expiresAtMillis ||
1024
- selected.moduleId !== input.moduleId ||
1025
- selected.generation !== input.generation ||
1026
- selected.digest !== input.digest ||
1027
- !(yield* recordMatches(
1028
- mapping,
1029
- locked[0],
1030
- selected,
1031
- authority.nativeSubjectId,
1032
- yield* encodePasswordPreparedReady(selected),
1033
- ))
1034
- )
1035
- return undefined;
1036
-
1037
- return { record: selected, currentRequirement: authority.requirement };
1038
- }),
1039
- );
1040
-
1041
- return record ?? (yield* PasswordRejected.make({}));
1042
- }).pipe(
1043
- Effect.provideService(CurrentPasswordSql, database),
1044
- Effect.provideService(LifecycleHooks, hooks),
1045
- translateContextFailure,
1046
- ),
1047
- complete: (input, prepare) =>
1048
- complete(input, prepare).pipe(
1049
- Effect.provideService(CurrentPasswordSql, database),
1050
- Effect.provideService(LifecycleHooks, hooks),
1051
- translateFailure,
1052
- ),
1053
- resetWithProof: (input, prepare) =>
1054
- complete(input, prepare).pipe(
1055
- Effect.provideService(CurrentPasswordSql, database),
1056
- Effect.provideService(LifecycleHooks, hooks),
1057
- translateFailure,
1058
- ),
1059
- cancel: (uncaptured, prepare) =>
1060
- Effect.gen(function* () {
1061
- const record = yield* snapshotPasswordPreparedReady(uncaptured.record),
1062
- snapshot = yield* encodePasswordPreparedReady(record);
1063
-
1064
- return yield* owned(
1065
- Effect.gen(function* () {
1066
- const journal = yield* CurrentCommitJournal;
1067
-
1068
- yield* lockAnchor(mapping, configuration, record.moduleId);
1069
- const authority = yield* currentAuthority(mapping, configuration, record);
1070
-
1071
- if (authority === undefined) return prepare(false, journal);
1072
-
1073
- const rows = yield* readIntent(
1074
- mapping,
1075
- and(eq(c.moduleId, record.moduleId), eq(c.intentId, record.intentId))!,
1076
- configuration.locking,
1077
- );
1078
-
1079
- const now = yield* nowMillis;
1080
-
1081
- if (
1082
- rows.length !== 1 ||
1083
- now < record.issuedAtMillis ||
1084
- now >= record.expiresAtMillis ||
1085
- !(yield* recordMatches(
1086
- mapping,
1087
- rows[0],
1088
- record,
1089
- authority.nativeSubjectId,
1090
- snapshot,
1091
- ))
1092
- )
1093
- return prepare(false, journal);
1094
- yield* terminal(mapping, rows[0], "Cancelled");
1095
-
1096
- return prepare(true, journal);
1097
- }),
1098
- );
1099
- }).pipe(
1100
- Effect.provideService(CurrentPasswordSql, database),
1101
- Effect.provideService(LifecycleHooks, hooks),
1102
- translateFailure,
1103
- ),
1104
- cleanup: (uncaptured, prepare) =>
1105
- Effect.gen(function* () {
1106
- const input = { ...uncaptured };
1107
-
1108
- if (!Number.isSafeInteger(input.limit) || input.limit < 1 || input.limit > 1000)
1109
- return yield* unavailable();
1110
-
1111
- return yield* owned(
1112
- Effect.gen(function* () {
1113
- const transaction = yield* CurrentPasswordSql;
1114
- const journal = yield* CurrentCommitJournal;
1115
-
1116
- if (!(yield* lockAnchor(mapping, configuration, input.moduleId, false)))
1117
- return prepare({ removed: 0, hasMore: false }, journal);
1118
- const now = p.encodeInstant(yield* nowMillis);
1119
-
1120
- const due = and(
1121
- eq(c.moduleId, input.moduleId),
1122
- or(
1123
- and(lte(c.retainUntil, now), lte(c.admissionRetainUntil, now)),
1124
- and(
1125
- isNotNull(c.snapshot),
1126
- or(
1127
- and(eq(c.state, t.states.Preparing), lte(c.preparationExpiresAt, now)),
1128
- and(eq(c.state, t.states.Ready), lte(c.expiresAt, now)),
1129
- ),
1130
- ),
1131
- ),
1132
- )!;
1133
-
1134
- const rows = yield* read(
1135
- transaction
1136
- .select()
1137
- .from(t.table)
1138
- .where(due)
1139
- .orderBy(c.createdAt, c.intentId)
1140
- .limit(input.limit + 1),
1141
- configuration.locking,
1142
- );
1143
-
1144
- let removed = 0;
1145
-
1146
- for (const row of rows.slice(0, input.limit)) {
1147
- const expired =
1148
- (yield* readIntent(
1149
- mapping,
1150
- and(
1151
- rowCondition(mapping, row),
1152
- lte(c.retainUntil, now),
1153
- lte(c.admissionRetainUntil, now),
1154
- )!,
1155
- false,
1156
- )).length === 1;
1157
-
1158
- if (expired) {
1159
- yield* transaction.delete(t.table).where(rowCondition(mapping, row));
1160
- if (
1161
- (yield* readIntent(
1162
- mapping,
1163
- and(eq(c.moduleId, input.moduleId), eq(c.intentId, row[t.intentId]))!,
1164
- false,
1165
- )).length
1166
- )
1167
- return yield* unavailable();
1168
- removed++;
1169
- } else yield* terminal(mapping, row, "Expired");
1170
- }
1171
-
1172
- return prepare(
1173
- {
1174
- removed,
1175
- hasMore:
1176
- (yield* read(transaction.select().from(t.table).where(due).limit(1), false))
1177
- .length > 0,
1178
- },
1179
- journal,
1180
- );
1181
- }),
1182
- );
1183
- }).pipe(
1184
- Effect.provideService(CurrentPasswordSql, database),
1185
- Effect.provideService(LifecycleHooks, hooks),
1186
- translateFailure,
1187
- ),
1188
- };
1189
-
1190
- return services;
1191
- },
1192
- );
1193
-
1194
- export const passwordPreparedSqlKernel = {
1195
- columns,
1196
- recordMatches,
1197
- captureAuthority,
1198
- currentAuthority,
1199
- rowCondition,
1200
- valid,
1201
- identifierScope,
1202
- };