@effect-auth/core 0.1.0-alpha.15 → 0.1.0-alpha.18

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 (627) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +332 -131
  3. package/dist/AbuseProtection.d.ts +100 -0
  4. package/dist/AbuseProtection.d.ts.map +1 -0
  5. package/dist/AbuseProtection.js +71 -0
  6. package/dist/AbuseProtection.js.map +1 -0
  7. package/dist/AccessGrant.d.ts +344 -0
  8. package/dist/AccessGrant.d.ts.map +1 -0
  9. package/dist/AccessGrant.js +687 -0
  10. package/dist/AccessGrant.js.map +1 -0
  11. package/dist/ApiKey.d.ts +2 -14
  12. package/dist/ApiKey.d.ts.map +1 -1
  13. package/dist/ApiKey.js +36 -27
  14. package/dist/ApiKey.js.map +1 -1
  15. package/dist/Assurance.d.ts +415 -0
  16. package/dist/Assurance.d.ts.map +1 -0
  17. package/dist/Assurance.js +764 -0
  18. package/dist/Assurance.js.map +1 -0
  19. package/dist/AtomicPlanExecutor.d.ts +28 -0
  20. package/dist/AtomicPlanExecutor.d.ts.map +1 -0
  21. package/dist/AtomicPlanExecutor.js +5 -0
  22. package/dist/AtomicPlanExecutor.js.map +1 -0
  23. package/dist/AuditLog.d.ts +2314 -52
  24. package/dist/AuditLog.d.ts.map +1 -1
  25. package/dist/AuditLog.js +511 -33
  26. package/dist/AuditLog.js.map +1 -1
  27. package/dist/AuthConfig.d.ts.map +1 -1
  28. package/dist/AuthConfig.js.map +1 -1
  29. package/dist/AuthFlow.d.ts +326 -220
  30. package/dist/AuthFlow.d.ts.map +1 -1
  31. package/dist/AuthFlow.js +611 -263
  32. package/dist/AuthFlow.js.map +1 -1
  33. package/dist/AuthKernel.d.ts +1 -1
  34. package/dist/AuthRateLimit.d.ts +96 -0
  35. package/dist/AuthRateLimit.d.ts.map +1 -0
  36. package/dist/AuthRateLimit.js +212 -0
  37. package/dist/AuthRateLimit.js.map +1 -0
  38. package/dist/Challenge.d.ts +0 -3
  39. package/dist/Challenge.d.ts.map +1 -1
  40. package/dist/Challenge.js +1 -4
  41. package/dist/Challenge.js.map +1 -1
  42. package/dist/Client.d.ts +205 -10
  43. package/dist/Client.d.ts.map +1 -1
  44. package/dist/Client.js +397 -16
  45. package/dist/Client.js.map +1 -1
  46. package/dist/CloudflareTurnstile.d.ts +28 -0
  47. package/dist/CloudflareTurnstile.d.ts.map +1 -0
  48. package/dist/CloudflareTurnstile.js +205 -0
  49. package/dist/CloudflareTurnstile.js.map +1 -0
  50. package/dist/Crypto.d.ts +0 -3
  51. package/dist/Crypto.d.ts.map +1 -1
  52. package/dist/Crypto.js +5 -7
  53. package/dist/Crypto.js.map +1 -1
  54. package/dist/DelegatedAccessStorageMigrations.d.ts +7 -0
  55. package/dist/DelegatedAccessStorageMigrations.d.ts.map +1 -0
  56. package/dist/DelegatedAccessStorageMigrations.js +159 -0
  57. package/dist/DelegatedAccessStorageMigrations.js.map +1 -0
  58. package/dist/DisposableEmailDomains.d.ts +19 -0
  59. package/dist/DisposableEmailDomains.d.ts.map +1 -0
  60. package/dist/DisposableEmailDomains.js +85 -0
  61. package/dist/DisposableEmailDomains.js.map +1 -0
  62. package/dist/DomainVerification.d.ts +0 -9
  63. package/dist/DomainVerification.d.ts.map +1 -1
  64. package/dist/DomainVerification.js +36 -22
  65. package/dist/DomainVerification.js.map +1 -1
  66. package/dist/DrizzleBunSqliteStorage.d.ts +18 -0
  67. package/dist/DrizzleBunSqliteStorage.d.ts.map +1 -0
  68. package/dist/DrizzleBunSqliteStorage.js +11 -0
  69. package/dist/DrizzleBunSqliteStorage.js.map +1 -0
  70. package/dist/DrizzleD1SqliteStorage.d.ts +28 -0
  71. package/dist/DrizzleD1SqliteStorage.d.ts.map +1 -0
  72. package/dist/DrizzleD1SqliteStorage.js +10 -0
  73. package/dist/DrizzleD1SqliteStorage.js.map +1 -0
  74. package/dist/DrizzleDurableObjectSqliteStorage.d.ts +19 -0
  75. package/dist/DrizzleDurableObjectSqliteStorage.d.ts.map +1 -0
  76. package/dist/DrizzleDurableObjectSqliteStorage.js +14 -0
  77. package/dist/DrizzleDurableObjectSqliteStorage.js.map +1 -0
  78. package/dist/DrizzleEffectSqliteStorage.d.ts +31 -0
  79. package/dist/DrizzleEffectSqliteStorage.d.ts.map +1 -0
  80. package/dist/DrizzleEffectSqliteStorage.js +108 -0
  81. package/dist/DrizzleEffectSqliteStorage.js.map +1 -0
  82. package/dist/DrizzleNodeSqliteStorage.d.ts +18 -0
  83. package/dist/DrizzleNodeSqliteStorage.d.ts.map +1 -0
  84. package/dist/DrizzleNodeSqliteStorage.js +11 -0
  85. package/dist/DrizzleNodeSqliteStorage.js.map +1 -0
  86. package/dist/DrizzleWasmSqliteStorage.d.ts +23 -0
  87. package/dist/DrizzleWasmSqliteStorage.d.ts.map +1 -0
  88. package/dist/DrizzleWasmSqliteStorage.js +15 -0
  89. package/dist/DrizzleWasmSqliteStorage.js.map +1 -0
  90. package/dist/EffectQbPostgresDelegatedAccessStorage.d.ts +34 -0
  91. package/dist/EffectQbPostgresDelegatedAccessStorage.d.ts.map +1 -0
  92. package/dist/EffectQbPostgresDelegatedAccessStorage.js +499 -0
  93. package/dist/EffectQbPostgresDelegatedAccessStorage.js.map +1 -0
  94. package/dist/EffectQbPostgresStorage.d.ts +171 -0
  95. package/dist/EffectQbPostgresStorage.d.ts.map +1 -0
  96. package/dist/EffectQbPostgresStorage.js +4280 -0
  97. package/dist/EffectQbPostgresStorage.js.map +1 -0
  98. package/dist/EffectQbSqliteDelegatedAccessStorage.d.ts +112 -0
  99. package/dist/EffectQbSqliteDelegatedAccessStorage.d.ts.map +1 -0
  100. package/dist/EffectQbSqliteDelegatedAccessStorage.js +602 -0
  101. package/dist/EffectQbSqliteDelegatedAccessStorage.js.map +1 -0
  102. package/dist/EffectQbSqliteStorage.d.ts +184 -27
  103. package/dist/EffectQbSqliteStorage.d.ts.map +1 -1
  104. package/dist/EffectQbSqliteStorage.js +1729 -135
  105. package/dist/EffectQbSqliteStorage.js.map +1 -1
  106. package/dist/EmailAuth.d.ts +65 -0
  107. package/dist/EmailAuth.d.ts.map +1 -0
  108. package/dist/EmailAuth.js +171 -0
  109. package/dist/EmailAuth.js.map +1 -0
  110. package/dist/EmailIdentityAuth.d.ts +30 -0
  111. package/dist/EmailIdentityAuth.d.ts.map +1 -0
  112. package/dist/EmailIdentityAuth.js +142 -0
  113. package/dist/EmailIdentityAuth.js.map +1 -0
  114. package/dist/EmailOtp.d.ts +10 -11
  115. package/dist/EmailOtp.d.ts.map +1 -1
  116. package/dist/EmailOtp.js +44 -81
  117. package/dist/EmailOtp.js.map +1 -1
  118. package/dist/EmailRisk.d.ts +48 -0
  119. package/dist/EmailRisk.d.ts.map +1 -0
  120. package/dist/EmailRisk.js +33 -0
  121. package/dist/EmailRisk.js.map +1 -0
  122. package/dist/EmailVerification.d.ts +10 -16
  123. package/dist/EmailVerification.d.ts.map +1 -1
  124. package/dist/EmailVerification.js +85 -42
  125. package/dist/EmailVerification.js.map +1 -1
  126. package/dist/Guard.d.ts +11 -0
  127. package/dist/Guard.d.ts.map +1 -0
  128. package/dist/Guard.js +11 -0
  129. package/dist/Guard.js.map +1 -0
  130. package/dist/HibpPwnedPasswords.d.ts +56 -0
  131. package/dist/HibpPwnedPasswords.d.ts.map +1 -0
  132. package/dist/HibpPwnedPasswords.js +232 -0
  133. package/dist/HibpPwnedPasswords.js.map +1 -0
  134. package/dist/HttpApi/AdminPermissionDefinition.d.ts +4 -0
  135. package/dist/HttpApi/AdminPermissionDefinition.d.ts.map +1 -0
  136. package/dist/HttpApi/AdminPermissionDefinition.js +4 -0
  137. package/dist/HttpApi/AdminPermissionDefinition.js.map +1 -0
  138. package/dist/HttpApi/AdminSecurityTimeline.d.ts +4 -0
  139. package/dist/HttpApi/AdminSecurityTimeline.d.ts.map +1 -0
  140. package/dist/HttpApi/AdminSecurityTimeline.js +4 -0
  141. package/dist/HttpApi/AdminSecurityTimeline.js.map +1 -0
  142. package/dist/HttpApi/AdminSession.d.ts +4 -0
  143. package/dist/HttpApi/AdminSession.d.ts.map +1 -0
  144. package/dist/HttpApi/AdminSession.js +4 -0
  145. package/dist/HttpApi/AdminSession.js.map +1 -0
  146. package/dist/HttpApi/AdminTrustedDevice.d.ts +4 -0
  147. package/dist/HttpApi/AdminTrustedDevice.d.ts.map +1 -0
  148. package/dist/HttpApi/AdminTrustedDevice.js +4 -0
  149. package/dist/HttpApi/AdminTrustedDevice.js.map +1 -0
  150. package/dist/HttpApi/Api.d.ts +1172 -1172
  151. package/dist/HttpApi/Api.d.ts.map +1 -1
  152. package/dist/HttpApi/Api.js +2160 -896
  153. package/dist/HttpApi/Api.js.map +1 -1
  154. package/dist/HttpApi/ApiKey.d.ts +4 -0
  155. package/dist/HttpApi/ApiKey.d.ts.map +1 -0
  156. package/dist/HttpApi/ApiKey.js +4 -0
  157. package/dist/HttpApi/ApiKey.js.map +1 -0
  158. package/dist/HttpApi/Audit.d.ts +6 -0
  159. package/dist/HttpApi/Audit.d.ts.map +1 -0
  160. package/dist/HttpApi/Audit.js +10 -0
  161. package/dist/HttpApi/Audit.js.map +1 -0
  162. package/dist/HttpApi/ClientApi.d.ts +917 -0
  163. package/dist/HttpApi/ClientApi.d.ts.map +1 -0
  164. package/dist/HttpApi/ClientApi.js +101 -0
  165. package/dist/HttpApi/ClientApi.js.map +1 -0
  166. package/dist/HttpApi/EmailAuth.d.ts +6 -0
  167. package/dist/HttpApi/EmailAuth.d.ts.map +1 -0
  168. package/dist/HttpApi/EmailAuth.js +6 -0
  169. package/dist/HttpApi/EmailAuth.js.map +1 -0
  170. package/dist/HttpApi/EmailGuards.d.ts +115 -0
  171. package/dist/HttpApi/EmailGuards.d.ts.map +1 -0
  172. package/dist/HttpApi/EmailGuards.js +191 -0
  173. package/dist/HttpApi/EmailGuards.js.map +1 -0
  174. package/dist/HttpApi/EmailOtp.d.ts +6 -0
  175. package/dist/HttpApi/EmailOtp.d.ts.map +1 -0
  176. package/dist/HttpApi/EmailOtp.js +6 -0
  177. package/dist/HttpApi/EmailOtp.js.map +1 -0
  178. package/dist/HttpApi/EmailVerification.d.ts +6 -0
  179. package/dist/HttpApi/EmailVerification.d.ts.map +1 -0
  180. package/dist/HttpApi/EmailVerification.js +6 -0
  181. package/dist/HttpApi/EmailVerification.js.map +1 -0
  182. package/dist/HttpApi/Endpoints.d.ts +629 -301
  183. package/dist/HttpApi/Endpoints.d.ts.map +1 -1
  184. package/dist/HttpApi/Endpoints.js +178 -120
  185. package/dist/HttpApi/Endpoints.js.map +1 -1
  186. package/dist/HttpApi/Errors.d.ts +26 -7
  187. package/dist/HttpApi/Errors.d.ts.map +1 -1
  188. package/dist/HttpApi/Errors.js +26 -4
  189. package/dist/HttpApi/Errors.js.map +1 -1
  190. package/dist/HttpApi/Identity.d.ts +6 -0
  191. package/dist/HttpApi/Identity.d.ts.map +1 -0
  192. package/dist/HttpApi/Identity.js +6 -0
  193. package/dist/HttpApi/Identity.js.map +1 -0
  194. package/dist/HttpApi/IdentityGuards.d.ts +31 -0
  195. package/dist/HttpApi/IdentityGuards.d.ts.map +1 -0
  196. package/dist/HttpApi/IdentityGuards.js +33 -0
  197. package/dist/HttpApi/IdentityGuards.js.map +1 -0
  198. package/dist/HttpApi/Jwt.d.ts +4 -0
  199. package/dist/HttpApi/Jwt.d.ts.map +1 -0
  200. package/dist/HttpApi/Jwt.js +4 -0
  201. package/dist/HttpApi/Jwt.js.map +1 -0
  202. package/dist/HttpApi/JwtDiscovery.d.ts +4 -0
  203. package/dist/HttpApi/JwtDiscovery.d.ts.map +1 -0
  204. package/dist/HttpApi/JwtDiscovery.js +4 -0
  205. package/dist/HttpApi/JwtDiscovery.js.map +1 -0
  206. package/dist/HttpApi/LoginApproval.d.ts +5 -0
  207. package/dist/HttpApi/LoginApproval.d.ts.map +1 -0
  208. package/dist/HttpApi/LoginApproval.js +5 -0
  209. package/dist/HttpApi/LoginApproval.js.map +1 -0
  210. package/dist/HttpApi/LoginNotification.d.ts +5 -0
  211. package/dist/HttpApi/LoginNotification.d.ts.map +1 -0
  212. package/dist/HttpApi/LoginNotification.js +5 -0
  213. package/dist/HttpApi/LoginNotification.js.map +1 -0
  214. package/dist/HttpApi/MagicLink.d.ts +6 -0
  215. package/dist/HttpApi/MagicLink.d.ts.map +1 -0
  216. package/dist/HttpApi/MagicLink.js +6 -0
  217. package/dist/HttpApi/MagicLink.js.map +1 -0
  218. package/dist/HttpApi/Mfa.d.ts +5 -0
  219. package/dist/HttpApi/Mfa.d.ts.map +1 -0
  220. package/dist/HttpApi/Mfa.js +5 -0
  221. package/dist/HttpApi/Mfa.js.map +1 -0
  222. package/dist/HttpApi/Middleware.d.ts +14 -0
  223. package/dist/HttpApi/Middleware.d.ts.map +1 -0
  224. package/dist/HttpApi/Middleware.js +5 -0
  225. package/dist/HttpApi/Middleware.js.map +1 -0
  226. package/dist/HttpApi/OAuth.d.ts +4 -0
  227. package/dist/HttpApi/OAuth.d.ts.map +1 -0
  228. package/dist/HttpApi/OAuth.js +4 -0
  229. package/dist/HttpApi/OAuth.js.map +1 -0
  230. package/dist/HttpApi/OAuthProviderAuthorization.d.ts +4 -0
  231. package/dist/HttpApi/OAuthProviderAuthorization.d.ts.map +1 -0
  232. package/dist/HttpApi/OAuthProviderAuthorization.js +4 -0
  233. package/dist/HttpApi/OAuthProviderAuthorization.js.map +1 -0
  234. package/dist/HttpApi/OAuthToken.d.ts +4 -0
  235. package/dist/HttpApi/OAuthToken.d.ts.map +1 -0
  236. package/dist/HttpApi/OAuthToken.js +4 -0
  237. package/dist/HttpApi/OAuthToken.js.map +1 -0
  238. package/dist/HttpApi/OidcDiscovery.d.ts +4 -0
  239. package/dist/HttpApi/OidcDiscovery.d.ts.map +1 -0
  240. package/dist/HttpApi/OidcDiscovery.js +4 -0
  241. package/dist/HttpApi/OidcDiscovery.js.map +1 -0
  242. package/dist/HttpApi/Operations/AdminPermissionDefinition.d.ts +28 -0
  243. package/dist/HttpApi/Operations/AdminPermissionDefinition.d.ts.map +1 -0
  244. package/dist/HttpApi/Operations/AdminPermissionDefinition.js +5 -0
  245. package/dist/HttpApi/Operations/AdminPermissionDefinition.js.map +1 -0
  246. package/dist/HttpApi/Operations/AdminSession.d.ts +16 -0
  247. package/dist/HttpApi/Operations/AdminSession.d.ts.map +1 -0
  248. package/dist/HttpApi/Operations/AdminSession.js +5 -0
  249. package/dist/HttpApi/Operations/AdminSession.js.map +1 -0
  250. package/dist/HttpApi/Operations/ApiKey.d.ts +16 -0
  251. package/dist/HttpApi/Operations/ApiKey.d.ts.map +1 -0
  252. package/dist/HttpApi/Operations/ApiKey.js +5 -0
  253. package/dist/HttpApi/Operations/ApiKey.js.map +1 -0
  254. package/dist/HttpApi/Operations/Discovery.d.ts +19 -0
  255. package/dist/HttpApi/Operations/Discovery.d.ts.map +1 -0
  256. package/dist/HttpApi/Operations/Discovery.js +7 -0
  257. package/dist/HttpApi/Operations/Discovery.js.map +1 -0
  258. package/dist/HttpApi/Operations/EmailAuth.d.ts +12 -0
  259. package/dist/HttpApi/Operations/EmailAuth.d.ts.map +1 -0
  260. package/dist/HttpApi/Operations/EmailAuth.js +5 -0
  261. package/dist/HttpApi/Operations/EmailAuth.js.map +1 -0
  262. package/dist/HttpApi/Operations/EmailOtp.d.ts +14 -0
  263. package/dist/HttpApi/Operations/EmailOtp.d.ts.map +1 -0
  264. package/dist/HttpApi/Operations/EmailOtp.js +5 -0
  265. package/dist/HttpApi/Operations/EmailOtp.js.map +1 -0
  266. package/dist/HttpApi/Operations/EmailVerification.d.ts +14 -0
  267. package/dist/HttpApi/Operations/EmailVerification.d.ts.map +1 -0
  268. package/dist/HttpApi/Operations/EmailVerification.js +5 -0
  269. package/dist/HttpApi/Operations/EmailVerification.js.map +1 -0
  270. package/dist/HttpApi/Operations/HttpOperation.d.ts +4 -0
  271. package/dist/HttpApi/Operations/HttpOperation.d.ts.map +1 -0
  272. package/dist/HttpApi/Operations/HttpOperation.js +2 -0
  273. package/dist/HttpApi/Operations/HttpOperation.js.map +1 -0
  274. package/dist/HttpApi/Operations/Identity.d.ts +22 -0
  275. package/dist/HttpApi/Operations/Identity.d.ts.map +1 -0
  276. package/dist/HttpApi/Operations/Identity.js +5 -0
  277. package/dist/HttpApi/Operations/Identity.js.map +1 -0
  278. package/dist/HttpApi/Operations/Jwt.d.ts +14 -0
  279. package/dist/HttpApi/Operations/Jwt.d.ts.map +1 -0
  280. package/dist/HttpApi/Operations/Jwt.js +5 -0
  281. package/dist/HttpApi/Operations/Jwt.js.map +1 -0
  282. package/dist/HttpApi/Operations/LoginApproval.d.ts +16 -0
  283. package/dist/HttpApi/Operations/LoginApproval.d.ts.map +1 -0
  284. package/dist/HttpApi/Operations/LoginApproval.js +5 -0
  285. package/dist/HttpApi/Operations/LoginApproval.js.map +1 -0
  286. package/dist/HttpApi/Operations/MagicLink.d.ts +14 -0
  287. package/dist/HttpApi/Operations/MagicLink.d.ts.map +1 -0
  288. package/dist/HttpApi/Operations/MagicLink.js +5 -0
  289. package/dist/HttpApi/Operations/MagicLink.js.map +1 -0
  290. package/dist/HttpApi/Operations/Mfa.d.ts +24 -0
  291. package/dist/HttpApi/Operations/Mfa.d.ts.map +1 -0
  292. package/dist/HttpApi/Operations/Mfa.js +5 -0
  293. package/dist/HttpApi/Operations/Mfa.js.map +1 -0
  294. package/dist/HttpApi/Operations/OAuth.d.ts +20 -0
  295. package/dist/HttpApi/Operations/OAuth.d.ts.map +1 -0
  296. package/dist/HttpApi/Operations/OAuth.js +5 -0
  297. package/dist/HttpApi/Operations/OAuth.js.map +1 -0
  298. package/dist/HttpApi/Operations/OAuthProviderAuthorization.d.ts +12 -0
  299. package/dist/HttpApi/Operations/OAuthProviderAuthorization.d.ts.map +1 -0
  300. package/dist/HttpApi/Operations/OAuthProviderAuthorization.js +5 -0
  301. package/dist/HttpApi/Operations/OAuthProviderAuthorization.js.map +1 -0
  302. package/dist/HttpApi/Operations/OAuthToken.d.ts +16 -0
  303. package/dist/HttpApi/Operations/OAuthToken.d.ts.map +1 -0
  304. package/dist/HttpApi/Operations/OAuthToken.js +5 -0
  305. package/dist/HttpApi/Operations/OAuthToken.js.map +1 -0
  306. package/dist/HttpApi/Operations/Passkey.d.ts +22 -0
  307. package/dist/HttpApi/Operations/Passkey.d.ts.map +1 -0
  308. package/dist/HttpApi/Operations/Passkey.js +5 -0
  309. package/dist/HttpApi/Operations/Passkey.js.map +1 -0
  310. package/dist/HttpApi/Operations/Password.d.ts +22 -0
  311. package/dist/HttpApi/Operations/Password.d.ts.map +1 -0
  312. package/dist/HttpApi/Operations/Password.js +5 -0
  313. package/dist/HttpApi/Operations/Password.js.map +1 -0
  314. package/dist/HttpApi/Operations/RecoveryCodes.d.ts +20 -0
  315. package/dist/HttpApi/Operations/RecoveryCodes.d.ts.map +1 -0
  316. package/dist/HttpApi/Operations/RecoveryCodes.js +5 -0
  317. package/dist/HttpApi/Operations/RecoveryCodes.js.map +1 -0
  318. package/dist/HttpApi/Operations/RefreshToken.d.ts +12 -0
  319. package/dist/HttpApi/Operations/RefreshToken.d.ts.map +1 -0
  320. package/dist/HttpApi/Operations/RefreshToken.js +5 -0
  321. package/dist/HttpApi/Operations/RefreshToken.js.map +1 -0
  322. package/dist/HttpApi/Operations/Security.d.ts +12 -0
  323. package/dist/HttpApi/Operations/Security.d.ts.map +1 -0
  324. package/dist/HttpApi/Operations/Security.js +5 -0
  325. package/dist/HttpApi/Operations/Security.js.map +1 -0
  326. package/dist/HttpApi/Operations/SecurityTimeline.d.ts +19 -0
  327. package/dist/HttpApi/Operations/SecurityTimeline.d.ts.map +1 -0
  328. package/dist/HttpApi/Operations/SecurityTimeline.js +7 -0
  329. package/dist/HttpApi/Operations/SecurityTimeline.js.map +1 -0
  330. package/dist/HttpApi/Operations/Session.d.ts +22 -0
  331. package/dist/HttpApi/Operations/Session.d.ts.map +1 -0
  332. package/dist/HttpApi/Operations/Session.js +5 -0
  333. package/dist/HttpApi/Operations/Session.js.map +1 -0
  334. package/dist/HttpApi/Operations/StepUp.d.ts +22 -0
  335. package/dist/HttpApi/Operations/StepUp.d.ts.map +1 -0
  336. package/dist/HttpApi/Operations/StepUp.js +5 -0
  337. package/dist/HttpApi/Operations/StepUp.js.map +1 -0
  338. package/dist/HttpApi/Operations/Totp.d.ts +20 -0
  339. package/dist/HttpApi/Operations/Totp.d.ts.map +1 -0
  340. package/dist/HttpApi/Operations/Totp.js +5 -0
  341. package/dist/HttpApi/Operations/Totp.js.map +1 -0
  342. package/dist/HttpApi/Operations/TrustedDevice.d.ts +23 -0
  343. package/dist/HttpApi/Operations/TrustedDevice.d.ts.map +1 -0
  344. package/dist/HttpApi/Operations/TrustedDevice.js +7 -0
  345. package/dist/HttpApi/Operations/TrustedDevice.js.map +1 -0
  346. package/dist/HttpApi/Operations/index.d.ts +27 -0
  347. package/dist/HttpApi/Operations/index.d.ts.map +1 -0
  348. package/dist/HttpApi/Operations/index.js +27 -0
  349. package/dist/HttpApi/Operations/index.js.map +1 -0
  350. package/dist/HttpApi/Passkey.d.ts +5 -0
  351. package/dist/HttpApi/Passkey.d.ts.map +1 -0
  352. package/dist/HttpApi/Passkey.js +5 -0
  353. package/dist/HttpApi/Passkey.js.map +1 -0
  354. package/dist/HttpApi/Password.d.ts +220 -0
  355. package/dist/HttpApi/Password.d.ts.map +1 -0
  356. package/dist/HttpApi/Password.js +237 -0
  357. package/dist/HttpApi/Password.js.map +1 -0
  358. package/dist/HttpApi/PasswordContract.d.ts +307 -0
  359. package/dist/HttpApi/PasswordContract.d.ts.map +1 -0
  360. package/dist/HttpApi/PasswordContract.js +63 -0
  361. package/dist/HttpApi/PasswordContract.js.map +1 -0
  362. package/dist/HttpApi/PasswordGuards.d.ts +82 -0
  363. package/dist/HttpApi/PasswordGuards.d.ts.map +1 -0
  364. package/dist/HttpApi/PasswordGuards.js +179 -0
  365. package/dist/HttpApi/PasswordGuards.js.map +1 -0
  366. package/dist/HttpApi/RecoveryCodes.d.ts +5 -0
  367. package/dist/HttpApi/RecoveryCodes.d.ts.map +1 -0
  368. package/dist/HttpApi/RecoveryCodes.js +5 -0
  369. package/dist/HttpApi/RecoveryCodes.js.map +1 -0
  370. package/dist/HttpApi/RefreshToken.d.ts +4 -0
  371. package/dist/HttpApi/RefreshToken.d.ts.map +1 -0
  372. package/dist/HttpApi/RefreshToken.js +4 -0
  373. package/dist/HttpApi/RefreshToken.js.map +1 -0
  374. package/dist/HttpApi/RequestGuards.d.ts +42 -0
  375. package/dist/HttpApi/RequestGuards.d.ts.map +1 -0
  376. package/dist/HttpApi/RequestGuards.js +194 -0
  377. package/dist/HttpApi/RequestGuards.js.map +1 -0
  378. package/dist/HttpApi/Schemas.d.ts +361 -84
  379. package/dist/HttpApi/Schemas.d.ts.map +1 -1
  380. package/dist/HttpApi/Schemas.js +190 -27
  381. package/dist/HttpApi/Schemas.js.map +1 -1
  382. package/dist/HttpApi/Security.d.ts +12 -93
  383. package/dist/HttpApi/Security.d.ts.map +1 -1
  384. package/dist/HttpApi/Security.js +65 -356
  385. package/dist/HttpApi/Security.js.map +1 -1
  386. package/dist/HttpApi/SecurityTimeline.d.ts +4 -0
  387. package/dist/HttpApi/SecurityTimeline.d.ts.map +1 -0
  388. package/dist/HttpApi/SecurityTimeline.js +4 -0
  389. package/dist/HttpApi/SecurityTimeline.js.map +1 -0
  390. package/dist/HttpApi/Session.d.ts +5 -0
  391. package/dist/HttpApi/Session.d.ts.map +1 -0
  392. package/dist/HttpApi/Session.js +5 -0
  393. package/dist/HttpApi/Session.js.map +1 -0
  394. package/dist/HttpApi/SessionGuards.d.ts +15 -0
  395. package/dist/HttpApi/SessionGuards.d.ts.map +1 -0
  396. package/dist/HttpApi/SessionGuards.js +37 -0
  397. package/dist/HttpApi/SessionGuards.js.map +1 -0
  398. package/dist/HttpApi/StepUp.d.ts +5 -0
  399. package/dist/HttpApi/StepUp.d.ts.map +1 -0
  400. package/dist/HttpApi/StepUp.js +5 -0
  401. package/dist/HttpApi/StepUp.js.map +1 -0
  402. package/dist/HttpApi/Totp.d.ts +5 -0
  403. package/dist/HttpApi/Totp.d.ts.map +1 -0
  404. package/dist/HttpApi/Totp.js +5 -0
  405. package/dist/HttpApi/Totp.js.map +1 -0
  406. package/dist/HttpApi/Transport.d.ts +4 -6
  407. package/dist/HttpApi/Transport.d.ts.map +1 -1
  408. package/dist/HttpApi/Transport.js +62 -36
  409. package/dist/HttpApi/Transport.js.map +1 -1
  410. package/dist/HttpApi/TrustedDevice.d.ts +4 -0
  411. package/dist/HttpApi/TrustedDevice.d.ts.map +1 -0
  412. package/dist/HttpApi/TrustedDevice.js +4 -0
  413. package/dist/HttpApi/TrustedDevice.js.map +1 -0
  414. package/dist/HttpApi/index.d.ts +9 -3
  415. package/dist/HttpApi/index.d.ts.map +1 -1
  416. package/dist/HttpApi/index.js +8 -2
  417. package/dist/HttpApi/index.js.map +1 -1
  418. package/dist/Identity.d.ts +138 -0
  419. package/dist/Identity.d.ts.map +1 -0
  420. package/dist/Identity.js +105 -0
  421. package/dist/Identity.js.map +1 -0
  422. package/dist/IdentityManagement.d.ts +189 -0
  423. package/dist/IdentityManagement.d.ts.map +1 -0
  424. package/dist/IdentityManagement.js +317 -0
  425. package/dist/IdentityManagement.js.map +1 -0
  426. package/dist/IncidentAction.d.ts +1 -4
  427. package/dist/IncidentAction.d.ts.map +1 -1
  428. package/dist/IncidentAction.js +15 -9
  429. package/dist/IncidentAction.js.map +1 -1
  430. package/dist/Internal.d.ts +2 -0
  431. package/dist/Internal.d.ts.map +1 -1
  432. package/dist/Internal.js +30 -0
  433. package/dist/Internal.js.map +1 -1
  434. package/dist/Invitation.d.ts +362 -0
  435. package/dist/Invitation.d.ts.map +1 -0
  436. package/dist/Invitation.js +633 -0
  437. package/dist/Invitation.js.map +1 -0
  438. package/dist/IpQualityScore.d.ts +38 -0
  439. package/dist/IpQualityScore.d.ts.map +1 -0
  440. package/dist/IpQualityScore.js +215 -0
  441. package/dist/IpQualityScore.js.map +1 -0
  442. package/dist/Jwt.d.ts +9 -30
  443. package/dist/Jwt.d.ts.map +1 -1
  444. package/dist/Jwt.js +72 -60
  445. package/dist/Jwt.js.map +1 -1
  446. package/dist/LoginApproval.d.ts +16 -31
  447. package/dist/LoginApproval.d.ts.map +1 -1
  448. package/dist/LoginApproval.js +47 -41
  449. package/dist/LoginApproval.js.map +1 -1
  450. package/dist/LoginNotification.d.ts +8 -12
  451. package/dist/LoginNotification.d.ts.map +1 -1
  452. package/dist/LoginNotification.js +30 -17
  453. package/dist/LoginNotification.js.map +1 -1
  454. package/dist/LoginRisk.d.ts +11 -13
  455. package/dist/LoginRisk.d.ts.map +1 -1
  456. package/dist/LoginRisk.js +66 -26
  457. package/dist/LoginRisk.js.map +1 -1
  458. package/dist/LoginRiskEnrichment.d.ts +145 -0
  459. package/dist/LoginRiskEnrichment.d.ts.map +1 -0
  460. package/dist/LoginRiskEnrichment.js +220 -0
  461. package/dist/LoginRiskEnrichment.js.map +1 -0
  462. package/dist/MachineAuth.d.ts.map +1 -1
  463. package/dist/MachineAuth.js.map +1 -1
  464. package/dist/MagicLink.d.ts +9 -8
  465. package/dist/MagicLink.d.ts.map +1 -1
  466. package/dist/MagicLink.js +40 -73
  467. package/dist/MagicLink.js.map +1 -1
  468. package/dist/Mailer.d.ts +20 -13
  469. package/dist/Mailer.d.ts.map +1 -1
  470. package/dist/Mailer.js +10 -12
  471. package/dist/Mailer.js.map +1 -1
  472. package/dist/OAuth.d.ts +100 -103
  473. package/dist/OAuth.d.ts.map +1 -1
  474. package/dist/OAuth.js +404 -217
  475. package/dist/OAuth.js.map +1 -1
  476. package/dist/Passkey.d.ts +17 -19
  477. package/dist/Passkey.d.ts.map +1 -1
  478. package/dist/Passkey.js +86 -39
  479. package/dist/Passkey.js.map +1 -1
  480. package/dist/PasskeyBrowser.d.ts +39 -0
  481. package/dist/PasskeyBrowser.d.ts.map +1 -0
  482. package/dist/PasskeyBrowser.js +206 -0
  483. package/dist/PasskeyBrowser.js.map +1 -0
  484. package/dist/PasskeySimpleWebAuthn.d.ts.map +1 -1
  485. package/dist/PasskeySimpleWebAuthn.js +19 -7
  486. package/dist/PasskeySimpleWebAuthn.js.map +1 -1
  487. package/dist/Password.d.ts +71 -37
  488. package/dist/Password.d.ts.map +1 -1
  489. package/dist/Password.js +296 -82
  490. package/dist/Password.js.map +1 -1
  491. package/dist/PasswordRisk.d.ts +63 -0
  492. package/dist/PasswordRisk.d.ts.map +1 -0
  493. package/dist/PasswordRisk.js +37 -0
  494. package/dist/PasswordRisk.js.map +1 -0
  495. package/dist/Permission.d.ts +308 -0
  496. package/dist/Permission.d.ts.map +1 -0
  497. package/dist/Permission.js +827 -0
  498. package/dist/Permission.js.map +1 -0
  499. package/dist/Policy.d.ts +31 -18
  500. package/dist/Policy.d.ts.map +1 -1
  501. package/dist/Policy.js +58 -14
  502. package/dist/Policy.js.map +1 -1
  503. package/dist/PostgresDelegatedAccessStorageMigrations.d.ts +7 -0
  504. package/dist/PostgresDelegatedAccessStorageMigrations.d.ts.map +1 -0
  505. package/dist/PostgresDelegatedAccessStorageMigrations.js +119 -0
  506. package/dist/PostgresDelegatedAccessStorageMigrations.js.map +1 -0
  507. package/dist/PostgresStorageMigrations.d.ts +15 -0
  508. package/dist/PostgresStorageMigrations.d.ts.map +1 -0
  509. package/dist/PostgresStorageMigrations.js +620 -0
  510. package/dist/PostgresStorageMigrations.js.map +1 -0
  511. package/dist/Privacy.d.ts +0 -3
  512. package/dist/Privacy.d.ts.map +1 -1
  513. package/dist/Privacy.js +2 -5
  514. package/dist/Privacy.js.map +1 -1
  515. package/dist/RateLimiter.d.ts +0 -3
  516. package/dist/RateLimiter.d.ts.map +1 -1
  517. package/dist/RateLimiter.js +1 -4
  518. package/dist/RateLimiter.js.map +1 -1
  519. package/dist/RecoveryCode.d.ts +84 -12
  520. package/dist/RecoveryCode.d.ts.map +1 -1
  521. package/dist/RecoveryCode.js +273 -75
  522. package/dist/RecoveryCode.js.map +1 -1
  523. package/dist/RecoveryPolicy.d.ts +81 -0
  524. package/dist/RecoveryPolicy.d.ts.map +1 -0
  525. package/dist/RecoveryPolicy.js +119 -0
  526. package/dist/RecoveryPolicy.js.map +1 -0
  527. package/dist/RefreshToken.d.ts +1 -10
  528. package/dist/RefreshToken.d.ts.map +1 -1
  529. package/dist/RefreshToken.js +31 -22
  530. package/dist/RefreshToken.js.map +1 -1
  531. package/dist/Retention.d.ts.map +1 -1
  532. package/dist/Retention.js.map +1 -1
  533. package/dist/SecurityTimeline.d.ts +1 -4
  534. package/dist/SecurityTimeline.d.ts.map +1 -1
  535. package/dist/SecurityTimeline.js +110 -17
  536. package/dist/SecurityTimeline.js.map +1 -1
  537. package/dist/Sessions.d.ts +124 -29
  538. package/dist/Sessions.d.ts.map +1 -1
  539. package/dist/Sessions.js +626 -94
  540. package/dist/Sessions.js.map +1 -1
  541. package/dist/StepUp.d.ts +132 -11
  542. package/dist/StepUp.d.ts.map +1 -1
  543. package/dist/StepUp.js +387 -19
  544. package/dist/StepUp.js.map +1 -1
  545. package/dist/Storage.d.ts +89 -23
  546. package/dist/Storage.d.ts.map +1 -1
  547. package/dist/Storage.js +10 -12
  548. package/dist/Storage.js.map +1 -1
  549. package/dist/StorageMigrations.d.ts +6 -1
  550. package/dist/StorageMigrations.d.ts.map +1 -1
  551. package/dist/StorageMigrations.js +224 -0
  552. package/dist/StorageMigrations.js.map +1 -1
  553. package/dist/StorageSchemaGenerator.d.ts +486 -0
  554. package/dist/StorageSchemaGenerator.d.ts.map +1 -0
  555. package/dist/StorageSchemaGenerator.js +1022 -0
  556. package/dist/StorageSchemaGenerator.js.map +1 -0
  557. package/dist/StrongFactor.d.ts +64 -0
  558. package/dist/StrongFactor.d.ts.map +1 -0
  559. package/dist/StrongFactor.js +100 -0
  560. package/dist/StrongFactor.js.map +1 -0
  561. package/dist/Testing.d.ts +1 -1
  562. package/dist/Testing.js +2 -2
  563. package/dist/Testing.js.map +1 -1
  564. package/dist/Totp.d.ts +88 -13
  565. package/dist/Totp.d.ts.map +1 -1
  566. package/dist/Totp.js +194 -36
  567. package/dist/Totp.js.map +1 -1
  568. package/dist/TrustedDevice.d.ts +0 -9
  569. package/dist/TrustedDevice.d.ts.map +1 -1
  570. package/dist/TrustedDevice.js +15 -17
  571. package/dist/TrustedDevice.js.map +1 -1
  572. package/dist/WaitUntil.d.ts +0 -3
  573. package/dist/WaitUntil.d.ts.map +1 -1
  574. package/dist/WaitUntil.js +1 -4
  575. package/dist/WaitUntil.js.map +1 -1
  576. package/dist/Webhook.d.ts +42 -12
  577. package/dist/Webhook.d.ts.map +1 -1
  578. package/dist/Webhook.js +165 -26
  579. package/dist/Webhook.js.map +1 -1
  580. package/dist/alchemy/cloudflare/Email.d.ts +4 -4
  581. package/dist/alchemy/cloudflare/Email.d.ts.map +1 -1
  582. package/dist/alchemy/cloudflare/Email.js +10 -5
  583. package/dist/alchemy/cloudflare/Email.js.map +1 -1
  584. package/dist/alchemy/cloudflare/RateLimitDurableObject.d.ts +4 -4
  585. package/dist/alchemy/cloudflare/RateLimitDurableObject.d.ts.map +1 -1
  586. package/dist/alchemy/cloudflare/RateLimitDurableObject.js +5 -4
  587. package/dist/alchemy/cloudflare/RateLimitDurableObject.js.map +1 -1
  588. package/dist/cloudflare/Email.d.ts.map +1 -1
  589. package/dist/cloudflare/Email.js +1 -1
  590. package/dist/cloudflare/Email.js.map +1 -1
  591. package/dist/cloudflare/RateLimitDurableObject.d.ts +6 -5
  592. package/dist/cloudflare/RateLimitDurableObject.d.ts.map +1 -1
  593. package/dist/cloudflare/RateLimitDurableObject.js.map +1 -1
  594. package/dist/cloudflare/RequestMetadata.d.ts +49 -0
  595. package/dist/cloudflare/RequestMetadata.d.ts.map +1 -0
  596. package/dist/cloudflare/RequestMetadata.js +71 -0
  597. package/dist/cloudflare/RequestMetadata.js.map +1 -0
  598. package/dist/index.d.ts +0 -35
  599. package/dist/index.d.ts.map +1 -1
  600. package/dist/index.js +0 -35
  601. package/dist/index.js.map +1 -1
  602. package/dist/internal/AuthFlowFinalizer.d.ts +31 -0
  603. package/dist/internal/AuthFlowFinalizer.d.ts.map +1 -0
  604. package/dist/internal/AuthFlowFinalizer.js +182 -0
  605. package/dist/internal/AuthFlowFinalizer.js.map +1 -0
  606. package/dist/internal/RateLimitDurableObject.d.ts.map +1 -1
  607. package/dist/internal/RateLimitDurableObject.js +3 -0
  608. package/dist/internal/RateLimitDurableObject.js.map +1 -1
  609. package/migrations/0001_auth_storage.sql +1 -0
  610. package/migrations/0006_auth_totp_factor.sql +1 -0
  611. package/migrations/0024_auth_permission.sql +39 -0
  612. package/migrations/0025_auth_permission_definition.sql +19 -0
  613. package/migrations/0026_auth_user_identity.sql +59 -0
  614. package/migrations/0027_auth_audit_log_storage_order.sql +46 -0
  615. package/migrations/0028_auth_oauth_client_secret_key.sql +39 -0
  616. package/migrations/delegated-access/0001_auth_delegated_access.sql +152 -0
  617. package/migrations/postgres/0001_auth_core.sql +77 -0
  618. package/migrations/postgres/0002_auth_security_oauth.sql +65 -0
  619. package/migrations/postgres/0003_auth_credentials_tokens.sql +43 -0
  620. package/migrations/postgres/0004_auth_security_history.sql +103 -0
  621. package/migrations/postgres/0005_auth_webhooks.sql +29 -0
  622. package/migrations/postgres/0006_auth_domain_timeline.sql +50 -0
  623. package/migrations/postgres/0007_auth_oauth_clients.sql +85 -0
  624. package/migrations/postgres/0008_auth_oauth_tokens.sql +63 -0
  625. package/migrations/postgres/0009_auth_permissions.sql +66 -0
  626. package/migrations/postgres/delegated-access/0001_auth_delegated_access.sql +112 -0
  627. package/package.json +309 -2
@@ -0,0 +1,1022 @@
1
+ import { postgresAuthStorageMigrations } from "./PostgresStorageMigrations.js";
2
+ export const storageSchemaGeneratorApiVersion = "effect-auth.storage-schema-generator/v1";
3
+ export const storageSchemaGeneratorVersion = "1.1.0";
4
+ export const storageSchemaVersion = "0009_auth_permissions";
5
+ export const supportedStorageDatabases = ["postgres"];
6
+ export const supportedStorageAdapters = ["effect-qb", "drizzle"];
7
+ export const supportedStorageGeneratorModes = ["fresh"];
8
+ export const storageModuleCatalog = [
9
+ {
10
+ id: "core",
11
+ description: "Users and login identities.",
12
+ dependencies: [],
13
+ tables: ["auth_user", "auth_user_identity"],
14
+ },
15
+ {
16
+ id: "credentials",
17
+ description: "Password and other typed credentials.",
18
+ dependencies: ["core"],
19
+ tables: ["auth_credential"],
20
+ },
21
+ {
22
+ id: "sessions",
23
+ description: "Authenticated sessions.",
24
+ dependencies: ["core"],
25
+ tables: ["auth_session"],
26
+ },
27
+ {
28
+ id: "verification",
29
+ description: "Short-lived verification challenges.",
30
+ dependencies: ["core"],
31
+ tables: ["auth_verification"],
32
+ },
33
+ {
34
+ id: "totp",
35
+ description: "TOTP factors.",
36
+ dependencies: ["core"],
37
+ tables: ["auth_totp_factor"],
38
+ },
39
+ {
40
+ id: "recovery-codes",
41
+ description: "MFA recovery codes.",
42
+ dependencies: ["core"],
43
+ tables: ["auth_recovery_code"],
44
+ },
45
+ {
46
+ id: "refresh-tokens",
47
+ description: "Rotating refresh-token families.",
48
+ dependencies: ["core"],
49
+ tables: ["auth_refresh_token"],
50
+ },
51
+ {
52
+ id: "oauth-accounts",
53
+ description: "External OAuth account links.",
54
+ dependencies: ["core"],
55
+ tables: ["auth_oauth_account"],
56
+ },
57
+ {
58
+ id: "passkeys",
59
+ description: "WebAuthn passkey credentials.",
60
+ dependencies: ["core"],
61
+ tables: ["auth_passkey_credential"],
62
+ },
63
+ {
64
+ id: "api-keys",
65
+ description: "User API keys.",
66
+ dependencies: ["core"],
67
+ tables: ["auth_api_key"],
68
+ },
69
+ {
70
+ id: "jwt",
71
+ description: "JWT revocations.",
72
+ dependencies: [],
73
+ tables: ["auth_jwt_revocation"],
74
+ },
75
+ {
76
+ id: "audit-log",
77
+ description: "Append-only authentication audit events.",
78
+ dependencies: ["core"],
79
+ tables: ["auth_audit_log"],
80
+ },
81
+ {
82
+ id: "login-approval",
83
+ description: "Out-of-band login approval reviews.",
84
+ dependencies: ["core", "verification"],
85
+ tables: ["auth_login_approval_review"],
86
+ },
87
+ {
88
+ id: "login-risk",
89
+ description: "Login risk history.",
90
+ dependencies: ["core"],
91
+ tables: ["auth_login_risk_history"],
92
+ },
93
+ {
94
+ id: "trusted-devices",
95
+ description: "Trusted-device tokens.",
96
+ dependencies: ["core"],
97
+ tables: ["auth_trusted_device"],
98
+ },
99
+ {
100
+ id: "webhooks",
101
+ description: "Webhook delivery and replay state.",
102
+ dependencies: [],
103
+ tables: ["auth_webhook_outbox", "auth_webhook_replay"],
104
+ },
105
+ {
106
+ id: "domain-verification",
107
+ description: "Domain ownership proofs.",
108
+ dependencies: [],
109
+ tables: ["auth_domain_verification"],
110
+ },
111
+ {
112
+ id: "security-timeline",
113
+ description: "User security timeline entries.",
114
+ dependencies: ["core"],
115
+ tables: ["auth_security_timeline"],
116
+ },
117
+ {
118
+ id: "oauth-provider",
119
+ description: "OAuth authorization-server clients, grants, and tokens.",
120
+ dependencies: ["core", "verification"],
121
+ tables: [
122
+ "auth_oauth_client",
123
+ "auth_oauth_consent",
124
+ "auth_oauth_authorization_code",
125
+ "auth_oauth_client_secret",
126
+ "auth_oauth_provider_mode_token",
127
+ ],
128
+ },
129
+ {
130
+ id: "oauth-token-vault",
131
+ description: "Encrypted upstream OAuth provider tokens.",
132
+ dependencies: ["oauth-accounts"],
133
+ tables: ["auth_oauth_provider_token_vault"],
134
+ },
135
+ {
136
+ id: "permissions",
137
+ description: "Permission, role, and grant definitions.",
138
+ dependencies: [],
139
+ tables: [
140
+ "auth_permission_definition",
141
+ "auth_role_definition",
142
+ "auth_permission_grant",
143
+ "auth_role_grant",
144
+ "auth_role_permission",
145
+ ],
146
+ },
147
+ ];
148
+ export const storageFeatureCatalog = [
149
+ {
150
+ id: "password",
151
+ description: "Password authentication.",
152
+ modules: ["credentials", "sessions", "verification"],
153
+ },
154
+ {
155
+ id: "email-verification",
156
+ description: "Email ownership verification.",
157
+ modules: ["verification"],
158
+ },
159
+ {
160
+ id: "email-otp",
161
+ description: "Email one-time passwords.",
162
+ modules: ["sessions", "verification"],
163
+ },
164
+ {
165
+ id: "magic-link",
166
+ description: "Email magic links.",
167
+ modules: ["sessions", "verification"],
168
+ },
169
+ {
170
+ id: "sessions",
171
+ description: "Cookie or token-backed sessions.",
172
+ modules: ["sessions"],
173
+ },
174
+ {
175
+ id: "login-approval",
176
+ description: "Out-of-band login approvals.",
177
+ modules: ["sessions", "login-approval"],
178
+ },
179
+ {
180
+ id: "trusted-devices",
181
+ description: "Trusted-device recognition.",
182
+ modules: ["trusted-devices"],
183
+ },
184
+ {
185
+ id: "passkeys",
186
+ description: "Passkey authentication.",
187
+ modules: ["sessions", "verification", "passkeys"],
188
+ },
189
+ {
190
+ id: "totp",
191
+ description: "TOTP multi-factor authentication.",
192
+ modules: ["sessions", "verification", "totp"],
193
+ },
194
+ {
195
+ id: "recovery-codes",
196
+ description: "MFA recovery codes.",
197
+ modules: ["sessions", "verification", "recovery-codes"],
198
+ },
199
+ {
200
+ id: "api-keys",
201
+ description: "User API keys.",
202
+ modules: ["api-keys"],
203
+ },
204
+ {
205
+ id: "refresh-tokens",
206
+ description: "Refresh-token rotation.",
207
+ modules: ["refresh-tokens"],
208
+ },
209
+ {
210
+ id: "jwt",
211
+ description: "JWT revocation.",
212
+ modules: ["jwt"],
213
+ },
214
+ {
215
+ id: "oauth",
216
+ description: "OAuth client login and account linking.",
217
+ modules: ["sessions", "verification", "oauth-accounts"],
218
+ },
219
+ {
220
+ id: "oauth-provider",
221
+ description: "OAuth authorization-server mode.",
222
+ modules: ["sessions", "oauth-provider"],
223
+ },
224
+ {
225
+ id: "oauth-token-vault",
226
+ description: "Encrypted upstream provider-token storage.",
227
+ modules: ["oauth-token-vault"],
228
+ },
229
+ {
230
+ id: "audit-log",
231
+ description: "Authentication audit logging.",
232
+ modules: ["audit-log"],
233
+ },
234
+ {
235
+ id: "login-risk",
236
+ description: "Login risk history.",
237
+ modules: ["login-risk"],
238
+ },
239
+ {
240
+ id: "security-timeline",
241
+ description: "User security timelines.",
242
+ modules: ["security-timeline"],
243
+ },
244
+ {
245
+ id: "webhooks",
246
+ description: "Reliable webhook delivery.",
247
+ modules: ["webhooks"],
248
+ },
249
+ {
250
+ id: "domain-verification",
251
+ description: "Domain ownership verification.",
252
+ modules: ["domain-verification"],
253
+ },
254
+ {
255
+ id: "permissions",
256
+ description: "Roles and permissions.",
257
+ modules: ["permissions"],
258
+ },
259
+ ];
260
+ export const storageSchemaGeneratorCatalog = {
261
+ apiVersion: storageSchemaGeneratorApiVersion,
262
+ generatorVersion: storageSchemaGeneratorVersion,
263
+ schemaVersion: storageSchemaVersion,
264
+ databases: supportedStorageDatabases,
265
+ adapters: supportedStorageAdapters,
266
+ adapterOutputs: {
267
+ "effect-qb": ["migration-sql"],
268
+ drizzle: ["migration-sql", "drizzle-schema"],
269
+ },
270
+ modes: supportedStorageGeneratorModes,
271
+ outputKinds: ["migration-sql", "drizzle-schema"],
272
+ sqlLayouts: ["single", "module"],
273
+ drizzleLayouts: ["single", "module", "table"],
274
+ features: storageFeatureCatalog,
275
+ modules: storageModuleCatalog,
276
+ };
277
+ export class StorageSchemaGeneratorError extends Error {
278
+ name = "StorageSchemaGeneratorError";
279
+ code;
280
+ path;
281
+ suggestions;
282
+ constructor(code, path, message, suggestions = []) {
283
+ super(message);
284
+ this.code = code;
285
+ this.path = path;
286
+ this.suggestions = suggestions;
287
+ }
288
+ toJSON() {
289
+ return {
290
+ name: this.name,
291
+ code: this.code,
292
+ path: this.path,
293
+ message: this.message,
294
+ suggestions: this.suggestions,
295
+ };
296
+ }
297
+ }
298
+ const moduleById = new Map(storageModuleCatalog.map((entry) => [entry.id, entry]));
299
+ const featureById = new Map(storageFeatureCatalog.map((feature) => [feature.id, feature]));
300
+ const moduleOrder = new Map(storageModuleCatalog.map((entry, index) => [entry.id, index]));
301
+ const featureOrder = new Map(storageFeatureCatalog.map((feature, index) => [feature.id, index]));
302
+ const tableModule = new Map();
303
+ for (const entry of storageModuleCatalog) {
304
+ for (const table of entry.tables) {
305
+ tableModule.set(table, entry.id);
306
+ }
307
+ }
308
+ const splitSqlStatements = (sql) => {
309
+ const statements = [];
310
+ let start = 0;
311
+ let singleQuoted = false;
312
+ let doubleQuoted = false;
313
+ for (let index = 0; index < sql.length; index += 1) {
314
+ const character = sql[index];
315
+ const next = sql[index + 1];
316
+ if (character === "'" && !doubleQuoted) {
317
+ if (singleQuoted && next === "'") {
318
+ index += 1;
319
+ }
320
+ else {
321
+ singleQuoted = !singleQuoted;
322
+ }
323
+ }
324
+ else if (character === '"' && !singleQuoted) {
325
+ if (doubleQuoted && next === '"') {
326
+ index += 1;
327
+ }
328
+ else {
329
+ doubleQuoted = !doubleQuoted;
330
+ }
331
+ }
332
+ else if (character === ";" && !singleQuoted && !doubleQuoted) {
333
+ const statement = sql.slice(start, index).trim();
334
+ if (statement.length > 0) {
335
+ statements.push(`${statement};`);
336
+ }
337
+ start = index + 1;
338
+ }
339
+ }
340
+ const remainder = sql.slice(start).trim();
341
+ if (remainder.length > 0) {
342
+ statements.push(remainder.endsWith(";") ? remainder : `${remainder};`);
343
+ }
344
+ return statements;
345
+ };
346
+ const canonicalTables = (() => {
347
+ const creates = new Map();
348
+ const indexes = new Map();
349
+ let order = 0;
350
+ for (const migration of postgresAuthStorageMigrations) {
351
+ for (const statement of splitSqlStatements(migration.sql)) {
352
+ const createMatch = /^create table ([a-z0-9_]+)\s*\(/i.exec(statement);
353
+ if (createMatch?.[1] !== undefined) {
354
+ creates.set(createMatch[1], { sql: statement, order });
355
+ indexes.set(createMatch[1], []);
356
+ order += 1;
357
+ continue;
358
+ }
359
+ const indexMatch = /^create (?:unique )?index [a-z0-9_]+\s+on ([a-z0-9_]+)\s*\(/i.exec(statement);
360
+ if (indexMatch?.[1] !== undefined) {
361
+ const tableIndexes = indexes.get(indexMatch[1]);
362
+ if (tableIndexes === undefined) {
363
+ throw new Error(`Index references unknown canonical table ${indexMatch[1]}`);
364
+ }
365
+ tableIndexes.push(statement);
366
+ }
367
+ }
368
+ }
369
+ const result = [];
370
+ for (const [name, create] of creates) {
371
+ const moduleId = tableModule.get(name);
372
+ if (moduleId === undefined) {
373
+ throw new Error(`Canonical table ${name} is missing from the module catalog`);
374
+ }
375
+ result.push({
376
+ name: name,
377
+ module: moduleId,
378
+ order: create.order,
379
+ createTable: create.sql,
380
+ indexes: indexes.get(name) ?? [],
381
+ });
382
+ }
383
+ for (const table of tableModule.keys()) {
384
+ if (!creates.has(table)) {
385
+ throw new Error(`Catalog table ${table} is missing from canonical migrations`);
386
+ }
387
+ }
388
+ // oxlint-disable-next-line unicorn/no-array-sort -- ES2023 toSorted is outside the supported target.
389
+ return result.sort((left, right) => left.order - right.order);
390
+ })();
391
+ const splitTopLevel = (value) => {
392
+ const parts = [];
393
+ let depth = 0;
394
+ let start = 0;
395
+ let singleQuoted = false;
396
+ let doubleQuoted = false;
397
+ for (let index = 0; index < value.length; index += 1) {
398
+ const character = value[index];
399
+ const next = value[index + 1];
400
+ if (character === "'" && !doubleQuoted) {
401
+ if (singleQuoted && next === "'") {
402
+ index += 1;
403
+ }
404
+ else {
405
+ singleQuoted = !singleQuoted;
406
+ }
407
+ }
408
+ else if (character === '"' && !singleQuoted) {
409
+ if (doubleQuoted && next === '"') {
410
+ index += 1;
411
+ }
412
+ else {
413
+ doubleQuoted = !doubleQuoted;
414
+ }
415
+ }
416
+ else if (!singleQuoted && !doubleQuoted) {
417
+ if (character === "(") {
418
+ depth += 1;
419
+ }
420
+ else if (character === ")") {
421
+ depth -= 1;
422
+ }
423
+ else if (character === "," && depth === 0) {
424
+ parts.push(value.slice(start, index).trim());
425
+ start = index + 1;
426
+ }
427
+ }
428
+ }
429
+ parts.push(value.slice(start).trim());
430
+ return parts.filter((part) => part.length > 0);
431
+ };
432
+ const parseCanonicalTable = (canonical) => {
433
+ const tableMatch = /^create table [a-z0-9_]+\s*\(([\s\S]*)\);$/i.exec(canonical.createTable);
434
+ if (tableMatch?.[1] === undefined) {
435
+ throw new Error(`Unable to parse canonical table ${canonical.name}`);
436
+ }
437
+ const columns = [];
438
+ const constraints = [];
439
+ for (const definition of splitTopLevel(tableMatch[1])) {
440
+ const constraintMatch = /^constraint ([a-z0-9_]+)\s+(primary key|unique|check)\s*\(([\s\S]*)\)$/i.exec(definition);
441
+ if (constraintMatch !== null) {
442
+ const [, name, rawKind, value] = constraintMatch;
443
+ if (name === undefined || rawKind === undefined || value === undefined) {
444
+ throw new Error(`Unable to parse constraint in ${canonical.name}`);
445
+ }
446
+ const kind = rawKind.toLowerCase();
447
+ constraints.push(kind === "check"
448
+ ? { name, kind: "check", expression: value.trim() }
449
+ : {
450
+ name,
451
+ kind: kind === "unique" ? "unique" : "primary-key",
452
+ columns: splitTopLevel(value).map((column) => column.trim().split(/\s+/u)[0].toLowerCase()),
453
+ });
454
+ continue;
455
+ }
456
+ const columnMatch = /^([a-z0-9_]+)\s+(text|bigint|integer|boolean|jsonb)\b([\s\S]*)$/i.exec(definition);
457
+ if (columnMatch === null) {
458
+ throw new Error(`Unable to parse column definition in ${canonical.name}: ${definition}`);
459
+ }
460
+ const [, name, rawType, modifiers = ""] = columnMatch;
461
+ if (name === undefined || rawType === undefined) {
462
+ throw new Error(`Unable to parse column in ${canonical.name}`);
463
+ }
464
+ const inlinePrimaryKey = /constraint ([a-z0-9_]+) primary key/i.exec(modifiers);
465
+ if (inlinePrimaryKey?.[1] !== undefined) {
466
+ constraints.push({
467
+ name: inlinePrimaryKey[1],
468
+ kind: "primary-key",
469
+ columns: [name],
470
+ });
471
+ }
472
+ const defaultMatch = /\bdefault\s+(false|true|-?\d+|'(?:''|[^'])*')/i.exec(modifiers);
473
+ const defaultValue = defaultMatch?.[1];
474
+ columns.push({
475
+ name,
476
+ type: rawType.toLowerCase(),
477
+ notNull: /\bnot null\b/i.test(modifiers) || inlinePrimaryKey !== null,
478
+ defaultValue: defaultValue === undefined
479
+ ? undefined
480
+ : /^(?:false|true)$/iu.test(defaultValue)
481
+ ? defaultValue.toLowerCase()
482
+ : defaultValue,
483
+ identity: /\bgenerated always as identity\b/i.test(modifiers),
484
+ collateC: /\bcollate "C"/i.test(modifiers),
485
+ });
486
+ }
487
+ return { canonical, columns, constraints };
488
+ };
489
+ const parsedTableByName = new Map(canonicalTables.map((table) => [table.name, parseCanonicalTable(table)]));
490
+ const compareByOrder = (order) => (left, right) => (order.get(left) ?? Number.MAX_SAFE_INTEGER) -
491
+ (order.get(right) ?? Number.MAX_SAFE_INTEGER);
492
+ const resolveModules = (directModules) => {
493
+ const resolved = new Set();
494
+ const include = (moduleId) => {
495
+ if (resolved.has(moduleId)) {
496
+ return;
497
+ }
498
+ const moduleEntry = moduleById.get(moduleId);
499
+ if (moduleEntry === undefined) {
500
+ throw new Error(`Unknown catalog module ${moduleId}`);
501
+ }
502
+ for (const dependency of moduleEntry.dependencies) {
503
+ include(dependency);
504
+ }
505
+ resolved.add(moduleId);
506
+ };
507
+ for (const moduleId of directModules) {
508
+ include(moduleId);
509
+ }
510
+ // oxlint-disable-next-line unicorn/no-array-sort -- ES2023 toSorted is outside the supported target.
511
+ return [...resolved].sort(compareByOrder(moduleOrder));
512
+ };
513
+ export const resolveStorageFeatures = (features) => {
514
+ // oxlint-disable-next-line unicorn/no-array-sort -- ES2023 toSorted is outside the supported target.
515
+ const normalizedFeatures = [...new Set(features)].sort(compareByOrder(featureOrder));
516
+ const directModules = new Set();
517
+ for (const featureId of normalizedFeatures) {
518
+ const feature = featureById.get(featureId);
519
+ if (feature === undefined) {
520
+ throw new StorageSchemaGeneratorError("UNKNOWN_FEATURE", "features", `Unsupported storage feature ${JSON.stringify(featureId)}.`, storageFeatureCatalog.map((entry) => entry.id));
521
+ }
522
+ for (const moduleId of feature.modules) {
523
+ directModules.add(moduleId);
524
+ }
525
+ }
526
+ const modules = resolveModules(directModules);
527
+ const selectedModules = new Set(modules);
528
+ const tables = canonicalTables
529
+ .filter((table) => selectedModules.has(table.module))
530
+ .map((table) => table.name);
531
+ return {
532
+ features: normalizedFeatures,
533
+ modules,
534
+ tables,
535
+ impliedModules: modules.filter((moduleId) => !directModules.has(moduleId)),
536
+ };
537
+ };
538
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
539
+ const assertKnownKeys = (value, keys, path, code) => {
540
+ const allowed = new Set(keys);
541
+ for (const key of Object.keys(value)) {
542
+ if (!allowed.has(key)) {
543
+ throw new StorageSchemaGeneratorError(code, path === "$" ? key : `${path}.${key}`, `Unknown property ${JSON.stringify(key)}.`, keys);
544
+ }
545
+ }
546
+ };
547
+ // oxlint-disable-next-line eslint/complexity -- validation keeps precise error paths in one pass
548
+ const normalizeRequest = (input) => {
549
+ if (!isRecord(input)) {
550
+ throw new StorageSchemaGeneratorError("INVALID_REQUEST", "$", "The generator request must be an object.");
551
+ }
552
+ const request = input;
553
+ assertKnownKeys(request, ["database", "adapter", "mode", "features", "outputs"], "$", "INVALID_REQUEST");
554
+ if (request.database !== "postgres") {
555
+ throw new StorageSchemaGeneratorError("UNSUPPORTED_DATABASE", "database", `Unsupported database ${JSON.stringify(request.database)}.`, ["postgres"]);
556
+ }
557
+ if (request.adapter !== "effect-qb" && request.adapter !== "drizzle") {
558
+ throw new StorageSchemaGeneratorError("UNSUPPORTED_ADAPTER", "adapter", `Unsupported adapter ${JSON.stringify(request.adapter)}.`, supportedStorageAdapters);
559
+ }
560
+ const { adapter } = request;
561
+ if (request.mode !== undefined && request.mode !== "fresh") {
562
+ throw new StorageSchemaGeneratorError("UNSUPPORTED_MODE", "mode", `Unsupported generation mode ${JSON.stringify(request.mode)}.`, ["fresh"]);
563
+ }
564
+ if (!Array.isArray(request.features) || request.features.length === 0) {
565
+ throw new StorageSchemaGeneratorError("INVALID_REQUEST", "features", "At least one storage feature is required.", storageFeatureCatalog.map((feature) => feature.id));
566
+ }
567
+ const features = [];
568
+ for (const [index, feature] of request.features.entries()) {
569
+ if (typeof feature !== "string" ||
570
+ !featureById.has(feature)) {
571
+ throw new StorageSchemaGeneratorError("UNKNOWN_FEATURE", `features[${index}]`, `Unsupported storage feature ${JSON.stringify(feature)}.`, storageFeatureCatalog.map((entry) => entry.id));
572
+ }
573
+ features.push(feature);
574
+ }
575
+ if (!Array.isArray(request.outputs) || request.outputs.length === 0) {
576
+ throw new StorageSchemaGeneratorError("INVALID_REQUEST", "outputs", "At least one output is required.", ["migration-sql", "drizzle-schema"]);
577
+ }
578
+ const outputs = [];
579
+ const outputKinds = new Set();
580
+ for (const [index, output] of request.outputs.entries()) {
581
+ const path = `outputs[${index}]`;
582
+ if (!isRecord(output)) {
583
+ throw new StorageSchemaGeneratorError("INVALID_OUTPUT", path, "Each output must be an object.");
584
+ }
585
+ assertKnownKeys(output, ["kind", "layout", "includeRelations"], path, "INVALID_OUTPUT");
586
+ if (output.kind === "migration-sql") {
587
+ if (output.layout !== "single" && output.layout !== "module") {
588
+ throw new StorageSchemaGeneratorError("INVALID_OUTPUT", `${path}.layout`, `Invalid migration SQL layout ${JSON.stringify(output.layout)}.`, ["single", "module"]);
589
+ }
590
+ outputs.push({ kind: "migration-sql", layout: output.layout });
591
+ }
592
+ else if (output.kind === "drizzle-schema") {
593
+ if (output.layout !== "single" &&
594
+ output.layout !== "module" &&
595
+ output.layout !== "table") {
596
+ throw new StorageSchemaGeneratorError("INVALID_OUTPUT", `${path}.layout`, `Invalid Drizzle schema layout ${JSON.stringify(output.layout)}.`, ["single", "module", "table"]);
597
+ }
598
+ if (output.includeRelations !== undefined &&
599
+ typeof output.includeRelations !== "boolean") {
600
+ throw new StorageSchemaGeneratorError("INVALID_OUTPUT", `${path}.includeRelations`, "includeRelations must be a boolean.");
601
+ }
602
+ outputs.push({
603
+ kind: "drizzle-schema",
604
+ layout: output.layout,
605
+ includeRelations: output.includeRelations === true,
606
+ });
607
+ }
608
+ else {
609
+ throw new StorageSchemaGeneratorError("INVALID_OUTPUT", `${path}.kind`, `Unsupported output kind ${JSON.stringify(output.kind)}.`, ["migration-sql", "drizzle-schema"]);
610
+ }
611
+ if (outputKinds.has(output.kind)) {
612
+ throw new StorageSchemaGeneratorError("DUPLICATE_OUTPUT", `${path}.kind`, `Only one ${String(output.kind)} output may be requested.`, ["Combine the requested files by choosing one layout."]);
613
+ }
614
+ outputKinds.add(output.kind);
615
+ }
616
+ if (adapter === "effect-qb") {
617
+ const unsupportedOutputIndex = outputs.findIndex((output) => output.kind !== "migration-sql");
618
+ if (unsupportedOutputIndex !== -1) {
619
+ throw new StorageSchemaGeneratorError("UNSUPPORTED_OUTPUT_FOR_ADAPTER", `outputs[${unsupportedOutputIndex}].kind`, "The effect-qb adapter owns its table declarations and only requires migration SQL.", ["migration-sql"]);
620
+ }
621
+ }
622
+ // oxlint-disable-next-line unicorn/no-array-sort -- ES2023 toSorted is outside the supported target.
623
+ outputs.sort((left, right) => {
624
+ if (left.kind !== right.kind) {
625
+ return left.kind === "migration-sql" ? -1 : 1;
626
+ }
627
+ return left.layout.localeCompare(right.layout);
628
+ });
629
+ return {
630
+ database: "postgres",
631
+ adapter,
632
+ mode: "fresh",
633
+ // oxlint-disable-next-line unicorn/no-array-sort -- ES2023 toSorted is outside the supported target.
634
+ features: [...new Set(features)].sort(compareByOrder(featureOrder)),
635
+ outputs,
636
+ };
637
+ };
638
+ const renderCanonicalSql = (tables) => `${tables
639
+ .flatMap((table) => [table.createTable, ...table.indexes])
640
+ .join("\n\n")}
641
+ `;
642
+ const sqlFiles = (layout, selection) => {
643
+ const selectedTables = new Set(selection.tables);
644
+ const tables = canonicalTables.filter((table) => selectedTables.has(table.name));
645
+ if (layout === "single") {
646
+ return [
647
+ {
648
+ path: "effect-auth.sql",
649
+ mediaType: "application/sql",
650
+ content: renderCanonicalSql(tables),
651
+ },
652
+ ];
653
+ }
654
+ return selection.modules.map((moduleId, index) => ({
655
+ path: `${String(index + 1).padStart(4, "0")}_effect_auth_${moduleId.replaceAll("-", "_")}.sql`,
656
+ mediaType: "application/sql",
657
+ content: renderCanonicalSql(tables.filter((table) => table.module === moduleId)),
658
+ }));
659
+ };
660
+ const camelCase = (value) => value.replaceAll(/_([a-z0-9])/g, (_, character) => character.toUpperCase());
661
+ const kebabCase = (value) => value.replaceAll("_", "-");
662
+ const escapeTemplate = (value) => value.replaceAll("`", "\\`").replaceAll("${", "\\${");
663
+ const renderColumn = (column) => {
664
+ let expression;
665
+ switch (column.type) {
666
+ case "bigint": {
667
+ expression = `bigint(${JSON.stringify(column.name)}, { mode: "number" })`;
668
+ break;
669
+ }
670
+ case "boolean": {
671
+ expression = `boolean(${JSON.stringify(column.name)})`;
672
+ break;
673
+ }
674
+ case "integer": {
675
+ expression = `integer(${JSON.stringify(column.name)})`;
676
+ break;
677
+ }
678
+ case "jsonb": {
679
+ expression = `jsonb(${JSON.stringify(column.name)})`;
680
+ break;
681
+ }
682
+ case "text": {
683
+ expression = `${column.collateC ? "textC" : "text"}(${JSON.stringify(column.name)})`;
684
+ break;
685
+ }
686
+ }
687
+ if (column.identity) {
688
+ expression += ".generatedAlwaysAsIdentity()";
689
+ }
690
+ if (column.notNull && !column.identity) {
691
+ expression += ".notNull()";
692
+ }
693
+ if (column.defaultValue !== undefined) {
694
+ const defaultValue = column.defaultValue.startsWith("'")
695
+ ? JSON.stringify(column.defaultValue.slice(1, -1).replaceAll("''", "'"))
696
+ : column.defaultValue;
697
+ expression += `.default(${defaultValue})`;
698
+ }
699
+ return ` ${camelCase(column.name)}: ${expression},`;
700
+ };
701
+ const renderSqlTemplate = (value) => `sql\`${escapeTemplate(value)}\``;
702
+ const renderIndexColumn = (value) => {
703
+ const match = /^([a-z0-9_]+)(?:\s+collate\s+"C")?$/i.exec(value.trim());
704
+ if (match?.[1] === undefined) {
705
+ return renderSqlTemplate(value.trim());
706
+ }
707
+ const column = camelCase(match[1]);
708
+ return /\bcollate\s+"C"/i.test(value)
709
+ ? `sql\`\${t.${column}} collate "C"\``
710
+ : `t.${column}`;
711
+ };
712
+ const renderIndex = (statement) => {
713
+ const match = /^create (unique )?index ([a-z0-9_]+)\s+on [a-z0-9_]+\s*\(([\s\S]*?)\)(?:\s+where\s+([\s\S]+?))?;$/i.exec(statement);
714
+ if (match === null || match[2] === undefined || match[3] === undefined) {
715
+ throw new Error(`Unable to render canonical index: ${statement}`);
716
+ }
717
+ const [, uniqueMarker, name, columns, where] = match;
718
+ let expression = `${uniqueMarker === undefined ? "index" : "uniqueIndex"}(${JSON.stringify(name)}).on(${splitTopLevel(columns).map(renderIndexColumn).join(", ")})`;
719
+ if (where !== undefined) {
720
+ expression += `.where(${renderSqlTemplate(where.trim())})`;
721
+ }
722
+ return ` ${expression},`;
723
+ };
724
+ const renderConstraint = (constraint) => {
725
+ switch (constraint.kind) {
726
+ case "check": {
727
+ return ` check(${JSON.stringify(constraint.name)}, ${renderSqlTemplate(constraint.expression ?? "")}),`;
728
+ }
729
+ case "primary-key": {
730
+ return ` primaryKey({ name: ${JSON.stringify(constraint.name)}, columns: [${(constraint.columns ?? [])
731
+ .map((column) => `t.${camelCase(column)}`)
732
+ .join(", ")}] }),`;
733
+ }
734
+ case "unique": {
735
+ return ` unique(${JSON.stringify(constraint.name)}).on(${(constraint.columns ?? [])
736
+ .map((column) => `t.${camelCase(column)}`)
737
+ .join(", ")}),`;
738
+ }
739
+ }
740
+ };
741
+ const drizzleImports = (tables) => {
742
+ const imports = new Set(["pgTable"]);
743
+ for (const table of tables) {
744
+ for (const column of table.columns) {
745
+ imports.add(column.type);
746
+ if (column.collateC) {
747
+ imports.add("customType");
748
+ }
749
+ }
750
+ for (const constraint of table.constraints) {
751
+ imports.add(constraint.kind === "primary-key"
752
+ ? "primaryKey"
753
+ : constraint.kind === "unique"
754
+ ? "unique"
755
+ : "check");
756
+ if (constraint.kind === "check") {
757
+ imports.add("sql");
758
+ }
759
+ }
760
+ for (const statement of table.canonical.indexes) {
761
+ imports.add(/^create unique index/i.test(statement) ? "uniqueIndex" : "index");
762
+ if (/\bwhere\b|\bcollate\b/i.test(statement)) {
763
+ imports.add("sql");
764
+ }
765
+ }
766
+ }
767
+ // oxlint-disable-next-line unicorn/no-array-sort -- ES2023 toSorted is outside the supported target.
768
+ return [...imports].sort();
769
+ };
770
+ const renderTable = (table) => {
771
+ const variable = camelCase(table.canonical.name);
772
+ const extras = [
773
+ ...table.constraints.map(renderConstraint),
774
+ ...table.canonical.indexes.map(renderIndex),
775
+ ];
776
+ return `export const ${variable} = pgTable(
777
+ ${JSON.stringify(table.canonical.name)},
778
+ {
779
+ ${table.columns.map(renderColumn).join("\n")}
780
+ },
781
+ (t) => [
782
+ ${extras.join("\n")}
783
+ ]
784
+ );`;
785
+ };
786
+ const renderDrizzleTables = (tables) => {
787
+ const imports = drizzleImports(tables);
788
+ const usesSql = imports.includes("sql");
789
+ const pgImports = imports.filter((name) => name !== "sql");
790
+ const importLines = [
791
+ ...(usesSql ? ['import { sql } from "drizzle-orm";'] : []),
792
+ `import { ${pgImports.join(", ")} } from "drizzle-orm/pg-core";`,
793
+ ];
794
+ const collatedText = tables.some((table) => table.columns.some((column) => column.collateC))
795
+ ? `
796
+ const textC = customType<{ data: string }>({
797
+ dataType: () => 'text collate "C"',
798
+ });`
799
+ : "";
800
+ return `${importLines.join("\n")}${collatedText}
801
+
802
+ ${tables.map(renderTable).join("\n\n")}
803
+ `;
804
+ };
805
+ // oxlint-disable-next-line eslint/complexity -- each branch describes one canonical relation family
806
+ const logicalRelations = (tables) => {
807
+ const byName = new Map(tables.map((table) => [table.canonical.name, table]));
808
+ const relations = [];
809
+ const addRelation = (sourceTable, sourceColumnName, targetTable, targetColumnName, name) => {
810
+ const source = byName.get(sourceTable);
811
+ const target = byName.get(targetTable);
812
+ const sourceColumn = source?.columns.find((column) => column.name === sourceColumnName);
813
+ const targetColumn = target?.columns.find((column) => column.name === targetColumnName);
814
+ if (source !== undefined &&
815
+ target !== undefined &&
816
+ sourceColumn !== undefined &&
817
+ targetColumn !== undefined) {
818
+ relations.push({ source, sourceColumn, target, targetColumn, name });
819
+ }
820
+ };
821
+ const user = byName.get("auth_user");
822
+ const userId = user?.columns.find((column) => column.name === "id");
823
+ if (user !== undefined && userId !== undefined) {
824
+ for (const table of tables) {
825
+ for (const column of table.columns) {
826
+ if (table !== user && column.name.endsWith("user_id")) {
827
+ const prefix = column.name
828
+ .slice(0, -"user_id".length)
829
+ .replace(/_$/, "");
830
+ relations.push({
831
+ source: table,
832
+ sourceColumn: column,
833
+ target: user,
834
+ targetColumn: userId,
835
+ name: prefix.length === 0 ? "user" : `${camelCase(prefix)}User`,
836
+ });
837
+ }
838
+ }
839
+ }
840
+ }
841
+ const oauthClient = byName.get("auth_oauth_client");
842
+ const oauthClientId = oauthClient?.columns.find((column) => column.name === "id");
843
+ if (oauthClient !== undefined && oauthClientId !== undefined) {
844
+ for (const tableName of [
845
+ "auth_oauth_consent",
846
+ "auth_oauth_authorization_code",
847
+ "auth_oauth_client_secret",
848
+ "auth_oauth_provider_mode_token",
849
+ ]) {
850
+ const source = byName.get(tableName);
851
+ const sourceColumn = source?.columns.find((column) => column.name === "client_id");
852
+ if (source !== undefined && sourceColumn !== undefined) {
853
+ relations.push({
854
+ source,
855
+ sourceColumn,
856
+ target: oauthClient,
857
+ targetColumn: oauthClientId,
858
+ name: "client",
859
+ });
860
+ }
861
+ }
862
+ }
863
+ const oauthAccount = byName.get("auth_oauth_account");
864
+ const oauthAccountId = oauthAccount?.columns.find((column) => column.name === "id");
865
+ const vault = byName.get("auth_oauth_provider_token_vault");
866
+ const vaultAccountId = vault?.columns.find((column) => column.name === "account_id");
867
+ if (oauthAccount !== undefined &&
868
+ oauthAccountId !== undefined &&
869
+ vault !== undefined &&
870
+ vaultAccountId !== undefined) {
871
+ relations.push({
872
+ source: vault,
873
+ sourceColumn: vaultAccountId,
874
+ target: oauthAccount,
875
+ targetColumn: oauthAccountId,
876
+ name: "account",
877
+ });
878
+ }
879
+ addRelation("auth_user_identity", "replaced_by_id", "auth_user_identity", "id", "replacedBy");
880
+ addRelation("auth_refresh_token", "replaced_by_id", "auth_refresh_token", "id", "replacedBy");
881
+ addRelation("auth_login_approval_review", "approval_challenge_id", "auth_verification", "id", "challenge");
882
+ addRelation("auth_oauth_provider_mode_token", "replaced_by_token_hash", "auth_oauth_provider_mode_token", "token_hash", "replacedBy");
883
+ addRelation("auth_permission_grant", "permission_id", "auth_permission_definition", "id", "permission");
884
+ addRelation("auth_role_grant", "role_id", "auth_role_definition", "id", "role");
885
+ addRelation("auth_role_permission", "role_id", "auth_role_definition", "id", "role");
886
+ addRelation("auth_role_permission", "permission_id", "auth_permission_definition", "id", "permission");
887
+ return relations;
888
+ };
889
+ const renderRelations = (tables, schemaExpression, importPath) => {
890
+ const relations = logicalRelations(tables);
891
+ const grouped = new Map();
892
+ for (const relation of relations) {
893
+ const existing = grouped.get(relation.source) ?? [];
894
+ existing.push(relation);
895
+ grouped.set(relation.source, existing);
896
+ }
897
+ const entries = [...grouped.entries()].map(([table, tableRelations]) => {
898
+ const sourceName = camelCase(table.canonical.name);
899
+ return ` ${sourceName}: {
900
+ ${tableRelations
901
+ .map((relation) => {
902
+ const targetName = camelCase(relation.target.canonical.name);
903
+ return ` ${relation.name}: r.one.${targetName}({
904
+ from: r.${sourceName}.${camelCase(relation.sourceColumn.name)},
905
+ to: r.${targetName}.${camelCase(relation.targetColumn.name)},
906
+ }),`;
907
+ })
908
+ .join("\n")}
909
+ },`;
910
+ });
911
+ const imports = [
912
+ 'import { defineRelations } from "drizzle-orm";',
913
+ ...(importPath === undefined
914
+ ? []
915
+ : [`import * as schema from ${JSON.stringify(importPath)};`]),
916
+ ];
917
+ return `${imports.join("\n")}
918
+
919
+ // Drizzle relations are application-level only and do not create PostgreSQL foreign keys.
920
+ export const relations = defineRelations(${schemaExpression}, (r) => ({
921
+ ${entries.join("\n")}
922
+ }));
923
+ `;
924
+ };
925
+ const exportFile = (paths) => `${paths.map((path) => `export * from ${JSON.stringify(path)};`).join("\n")}
926
+ `;
927
+ const drizzleFiles = (layout, includeRelations, selection) => {
928
+ const selected = new Set(selection.tables);
929
+ const tables = canonicalTables
930
+ .filter((table) => selected.has(table.name))
931
+ .map((table) => parsedTableByName.get(table.name));
932
+ if (layout === "single") {
933
+ let content = renderDrizzleTables(tables);
934
+ if (includeRelations) {
935
+ const schema = `{ ${tables
936
+ .map((table) => camelCase(table.canonical.name))
937
+ .join(", ")} }`;
938
+ content += `\n${renderRelations(tables, schema)}`;
939
+ }
940
+ return [{ path: "schema.ts", mediaType: "text/typescript", content }];
941
+ }
942
+ const directory = layout === "module" ? "modules" : "tables";
943
+ const groups = layout === "module"
944
+ ? selection.modules.map((moduleId) => ({
945
+ name: moduleId,
946
+ tables: tables.filter((table) => table.canonical.module === moduleId),
947
+ }))
948
+ : tables.map((table) => ({
949
+ name: kebabCase(table.canonical.name),
950
+ tables: [table],
951
+ }));
952
+ const files = groups.map((group) => ({
953
+ path: `${directory}/${group.name}.ts`,
954
+ mediaType: "text/typescript",
955
+ content: renderDrizzleTables(group.tables),
956
+ }));
957
+ files.push({
958
+ path: `${directory}/index.ts`,
959
+ mediaType: "text/typescript",
960
+ content: exportFile(groups.map((group) => `./${group.name}.js`)),
961
+ });
962
+ if (includeRelations) {
963
+ files.push({
964
+ path: "relations.ts",
965
+ mediaType: "text/typescript",
966
+ content: renderRelations(tables, "schema", `./${directory}/index.js`),
967
+ });
968
+ }
969
+ files.push({
970
+ path: "index.ts",
971
+ mediaType: "text/typescript",
972
+ content: exportFile([
973
+ `./${directory}/index.js`,
974
+ ...(includeRelations ? ["./relations.js"] : []),
975
+ ]),
976
+ });
977
+ return files;
978
+ };
979
+ const fingerprint = (value) => {
980
+ let hash = 2_166_136_261;
981
+ for (let index = 0; index < value.length; index += 1) {
982
+ hash ^= value.codePointAt(index) ?? 0;
983
+ hash = Math.imul(hash, 16_777_619);
984
+ }
985
+ const unsignedHash = hash < 0 ? hash + 4_294_967_296 : hash;
986
+ return `fnv1a32:${unsignedHash.toString(16).padStart(8, "0")}`;
987
+ };
988
+ export const parseStorageSchemaGeneratorRequest = (request) => normalizeRequest(request);
989
+ export const generateStorageArtifacts = (request) => {
990
+ const normalized = normalizeRequest(request);
991
+ const resolved = resolveStorageFeatures(normalized.features);
992
+ const files = [];
993
+ const warnings = [];
994
+ for (const output of normalized.outputs) {
995
+ if (output.kind === "migration-sql") {
996
+ files.push(...sqlFiles(output.layout, resolved));
997
+ }
998
+ else {
999
+ files.push(...drizzleFiles(output.layout, output.includeRelations, resolved));
1000
+ if (output.includeRelations) {
1001
+ warnings.push("Drizzle relations are application-level only and do not create PostgreSQL foreign keys.");
1002
+ }
1003
+ }
1004
+ }
1005
+ const fingerprintInput = JSON.stringify({
1006
+ request: normalized,
1007
+ resolved,
1008
+ files,
1009
+ warnings,
1010
+ });
1011
+ return {
1012
+ apiVersion: storageSchemaGeneratorApiVersion,
1013
+ generatorVersion: storageSchemaGeneratorVersion,
1014
+ schemaVersion: storageSchemaVersion,
1015
+ fingerprint: fingerprint(fingerprintInput),
1016
+ request: normalized,
1017
+ resolved,
1018
+ files,
1019
+ warnings,
1020
+ };
1021
+ };
1022
+ //# sourceMappingURL=StorageSchemaGenerator.js.map