@yielded/auth-persistence-drizzle 0.1.0-beta.1 → 0.1.0-beta.12

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 (222) hide show
  1. package/dist/D1.d.mts +27 -22
  2. package/dist/D1.mjs +10 -4
  3. package/dist/D1.mjs.map +1 -1
  4. package/dist/Libsql.d.mts +66 -61
  5. package/dist/Libsql.mjs +20 -15
  6. package/dist/Libsql.mjs.map +1 -1
  7. package/dist/Mysql2.d.mts +58 -46
  8. package/dist/Mysql2.mjs +13 -6
  9. package/dist/Mysql2.mjs.map +1 -1
  10. package/dist/Pglite.d.mts +43 -32
  11. package/dist/Pglite.mjs +12 -7
  12. package/dist/Pglite.mjs.map +1 -1
  13. package/dist/Postgres.d.mts +59 -48
  14. package/dist/Postgres.mjs +12 -7
  15. package/dist/Postgres.mjs.map +1 -1
  16. package/dist/SqliteBun.d.mts +58 -53
  17. package/dist/SqliteBun.mjs +20 -14
  18. package/dist/SqliteBun.mjs.map +1 -1
  19. package/dist/SqliteDo.d.mts +66 -60
  20. package/dist/SqliteDo.mjs +26 -14
  21. package/dist/SqliteDo.mjs.map +1 -1
  22. package/dist/SqliteNode.d.mts +58 -53
  23. package/dist/SqliteNode.mjs +20 -14
  24. package/dist/SqliteNode.mjs.map +1 -1
  25. package/dist/SqliteWasm.d.mts +66 -61
  26. package/dist/SqliteWasm.mjs +20 -14
  27. package/dist/SqliteWasm.mjs.map +1 -1
  28. package/dist/drizzle/d1-database.d.mts +11 -0
  29. package/dist/drizzle/d1-database.mjs +8 -0
  30. package/dist/drizzle/d1-database.mjs.map +1 -0
  31. package/dist/drizzle/d1-emails.d.mts +8 -7
  32. package/dist/drizzle/d1-emails.mjs +7 -4
  33. package/dist/drizzle/d1-emails.mjs.map +1 -1
  34. package/dist/drizzle/d1-identity.mjs +12 -9
  35. package/dist/drizzle/d1-identity.mjs.map +1 -1
  36. package/dist/drizzle/d1-oauth.d.mts +14 -13
  37. package/dist/drizzle/d1-oauth.mjs +7 -4
  38. package/dist/drizzle/d1-oauth.mjs.map +1 -1
  39. package/dist/drizzle/d1-passkey.d.mts +3 -14
  40. package/dist/drizzle/d1-passkey.mjs +2 -1
  41. package/dist/drizzle/d1-passkey.mjs.map +1 -1
  42. package/dist/drizzle/d1-password-prepared.d.mts +4 -3
  43. package/dist/drizzle/d1-password-prepared.mjs +3 -1
  44. package/dist/drizzle/d1-password-prepared.mjs.map +1 -1
  45. package/dist/drizzle/d1-passwords.d.mts +6 -5
  46. package/dist/drizzle/d1-passwords.mjs +5 -2
  47. package/dist/drizzle/d1-passwords.mjs.map +1 -1
  48. package/dist/drizzle/d1-phone.d.mts +3 -4
  49. package/dist/drizzle/d1-phone.mjs +2 -1
  50. package/dist/drizzle/d1-phone.mjs.map +1 -1
  51. package/dist/drizzle/d1-planning.d.mts +1 -1
  52. package/dist/drizzle/d1-proofs.d.mts +4 -3
  53. package/dist/drizzle/d1-proofs.mjs +3 -1
  54. package/dist/drizzle/d1-proofs.mjs.map +1 -1
  55. package/dist/drizzle/d1-sessions.d.mts +11 -10
  56. package/dist/drizzle/d1-sessions.mjs +15 -9
  57. package/dist/drizzle/d1-sessions.mjs.map +1 -1
  58. package/dist/drizzle/d1-totp.d.mts +3 -4
  59. package/dist/drizzle/d1-totp.mjs +2 -1
  60. package/dist/drizzle/d1-totp.mjs.map +1 -1
  61. package/dist/drizzle/email-registration.mjs +2 -1
  62. package/dist/drizzle/email-registration.mjs.map +1 -1
  63. package/dist/drizzle/email-target.d.mts +7 -6
  64. package/dist/drizzle/email-target.mjs +10 -10
  65. package/dist/drizzle/email-target.mjs.map +1 -1
  66. package/dist/drizzle/mysql-database.d.mts +8 -0
  67. package/dist/drizzle/mysql-database.mjs +8 -0
  68. package/dist/drizzle/mysql-database.mjs.map +1 -0
  69. package/dist/drizzle/mysql-emails.d.mts +7 -6
  70. package/dist/drizzle/mysql-emails.mjs +12 -8
  71. package/dist/drizzle/mysql-emails.mjs.map +1 -1
  72. package/dist/drizzle/mysql-identity.mjs +12 -9
  73. package/dist/drizzle/mysql-identity.mjs.map +1 -1
  74. package/dist/drizzle/mysql-password-prepared.d.mts +3 -2
  75. package/dist/drizzle/mysql-password-prepared.mjs +6 -2
  76. package/dist/drizzle/mysql-password-prepared.mjs.map +1 -1
  77. package/dist/drizzle/mysql-passwords.d.mts +6 -4
  78. package/dist/drizzle/mysql-passwords.mjs +11 -7
  79. package/dist/drizzle/mysql-passwords.mjs.map +1 -1
  80. package/dist/drizzle/mysql-proofs.d.mts +3 -2
  81. package/dist/drizzle/mysql-proofs.mjs +8 -4
  82. package/dist/drizzle/mysql-proofs.mjs.map +1 -1
  83. package/dist/drizzle/mysql-sessions.d.mts +11 -10
  84. package/dist/drizzle/mysql-sessions.mjs +16 -12
  85. package/dist/drizzle/mysql-sessions.mjs.map +1 -1
  86. package/dist/drizzle/native-database.mjs +10 -0
  87. package/dist/drizzle/native-database.mjs.map +1 -0
  88. package/dist/drizzle/oauth-connected-drivers.mjs +7 -5
  89. package/dist/drizzle/oauth-connected-drivers.mjs.map +1 -1
  90. package/dist/drizzle/oauth-connected-target.d.mts +6 -7
  91. package/dist/drizzle/oauth-connected-target.mjs +4 -5
  92. package/dist/drizzle/oauth-connected-target.mjs.map +1 -1
  93. package/dist/drizzle/oauth-drivers.mjs +8 -6
  94. package/dist/drizzle/oauth-drivers.mjs.map +1 -1
  95. package/dist/drizzle/oauth-target.d.mts +12 -11
  96. package/dist/drizzle/oauth-target.mjs +13 -12
  97. package/dist/drizzle/oauth-target.mjs.map +1 -1
  98. package/dist/drizzle/passkey-drivers.mjs +8 -6
  99. package/dist/drizzle/passkey-drivers.mjs.map +1 -1
  100. package/dist/drizzle/passkey-write-drivers.mjs +5 -3
  101. package/dist/drizzle/passkey-write-drivers.mjs.map +1 -1
  102. package/dist/drizzle/passkey-write-target.d.mts +1 -1
  103. package/dist/drizzle/password-prepared-sql.mjs +2 -1
  104. package/dist/drizzle/password-prepared-sql.mjs.map +1 -1
  105. package/dist/drizzle/password-prepared-target.d.mts +3 -2
  106. package/dist/drizzle/password-prepared-target.mjs +4 -3
  107. package/dist/drizzle/password-prepared-target.mjs.map +1 -1
  108. package/dist/drizzle/password-registration.mjs +2 -1
  109. package/dist/drizzle/password-registration.mjs.map +1 -1
  110. package/dist/drizzle/password-target.d.mts +5 -4
  111. package/dist/drizzle/password-target.mjs +8 -8
  112. package/dist/drizzle/password-target.mjs.map +1 -1
  113. package/dist/drizzle/pg-database.d.mts +9 -0
  114. package/dist/drizzle/pg-database.mjs +8 -0
  115. package/dist/drizzle/pg-database.mjs.map +1 -0
  116. package/dist/drizzle/pg-emails.d.mts +7 -6
  117. package/dist/drizzle/pg-emails.mjs +12 -8
  118. package/dist/drizzle/pg-emails.mjs.map +1 -1
  119. package/dist/drizzle/pg-identity.mjs +12 -9
  120. package/dist/drizzle/pg-identity.mjs.map +1 -1
  121. package/dist/drizzle/pg-password-prepared.d.mts +3 -2
  122. package/dist/drizzle/pg-password-prepared.mjs +6 -2
  123. package/dist/drizzle/pg-password-prepared.mjs.map +1 -1
  124. package/dist/drizzle/pg-passwords.d.mts +6 -4
  125. package/dist/drizzle/pg-passwords.mjs +11 -7
  126. package/dist/drizzle/pg-passwords.mjs.map +1 -1
  127. package/dist/drizzle/pg-proofs.d.mts +3 -2
  128. package/dist/drizzle/pg-proofs.mjs +8 -4
  129. package/dist/drizzle/pg-proofs.mjs.map +1 -1
  130. package/dist/drizzle/pg-sessions.d.mts +11 -10
  131. package/dist/drizzle/pg-sessions.mjs +16 -12
  132. package/dist/drizzle/pg-sessions.mjs.map +1 -1
  133. package/dist/drizzle/phone-target.d.mts +4 -3
  134. package/dist/drizzle/phone-target.mjs +12 -11
  135. package/dist/drizzle/phone-target.mjs.map +1 -1
  136. package/dist/drizzle/proof-target.d.mts +3 -2
  137. package/dist/drizzle/proof-target.mjs +5 -5
  138. package/dist/drizzle/proof-target.mjs.map +1 -1
  139. package/dist/drizzle/session-sql.d.mts +1 -0
  140. package/dist/drizzle/session-target.d.mts +10 -8
  141. package/dist/drizzle/session-target.mjs +11 -11
  142. package/dist/drizzle/session-target.mjs.map +1 -1
  143. package/dist/drizzle/sqlite-emails.mjs +9 -5
  144. package/dist/drizzle/sqlite-emails.mjs.map +1 -1
  145. package/dist/drizzle/sqlite-identity.mjs +14 -11
  146. package/dist/drizzle/sqlite-identity.mjs.map +1 -1
  147. package/dist/drizzle/sqlite-password-prepared.mjs +7 -3
  148. package/dist/drizzle/sqlite-password-prepared.mjs.map +1 -1
  149. package/dist/drizzle/sqlite-passwords.mjs +10 -6
  150. package/dist/drizzle/sqlite-passwords.mjs.map +1 -1
  151. package/dist/drizzle/sqlite-proofs.mjs +7 -3
  152. package/dist/drizzle/sqlite-proofs.mjs.map +1 -1
  153. package/dist/drizzle/sqlite-sessions.mjs +16 -12
  154. package/dist/drizzle/sqlite-sessions.mjs.map +1 -1
  155. package/dist/drizzle/standalone-guard.d.mts +2 -0
  156. package/dist/drizzle/standalone-guard.mjs +8 -4
  157. package/dist/drizzle/standalone-guard.mjs.map +1 -1
  158. package/dist/drizzle/totp-target.d.mts +4 -3
  159. package/dist/drizzle/totp-target.mjs +31 -28
  160. package/dist/drizzle/totp-target.mjs.map +1 -1
  161. package/package.json +1 -1
  162. package/src/D1.ts +37 -10
  163. package/src/Libsql.ts +45 -17
  164. package/src/Mysql2.ts +39 -13
  165. package/src/Pglite.ts +47 -13
  166. package/src/Postgres.ts +47 -13
  167. package/src/SqliteBun.ts +58 -30
  168. package/src/SqliteDo.ts +61 -19
  169. package/src/SqliteNode.ts +55 -28
  170. package/src/SqliteWasm.ts +55 -28
  171. package/src/drizzle/d1-database.ts +10 -0
  172. package/src/drizzle/d1-emails.ts +84 -84
  173. package/src/drizzle/d1-identity.ts +17 -20
  174. package/src/drizzle/d1-oauth.ts +19 -8
  175. package/src/drizzle/d1-passkey.ts +5 -1
  176. package/src/drizzle/d1-password-prepared.ts +38 -37
  177. package/src/drizzle/d1-passwords.ts +74 -76
  178. package/src/drizzle/d1-phone.ts +5 -1
  179. package/src/drizzle/d1-proofs.ts +29 -30
  180. package/src/drizzle/d1-sessions.ts +51 -38
  181. package/src/drizzle/d1-totp.ts +5 -1
  182. package/src/drizzle/email-registration.ts +6 -2
  183. package/src/drizzle/email-target.ts +17 -19
  184. package/src/drizzle/mysql-database.ts +8 -0
  185. package/src/drizzle/mysql-emails.ts +28 -16
  186. package/src/drizzle/mysql-identity.ts +18 -21
  187. package/src/drizzle/mysql-password-prepared.ts +10 -8
  188. package/src/drizzle/mysql-passwords.ts +21 -9
  189. package/src/drizzle/mysql-proofs.ts +16 -5
  190. package/src/drizzle/mysql-sessions.ts +40 -17
  191. package/src/drizzle/native-database.ts +22 -0
  192. package/src/drizzle/oauth-connected-drivers.ts +18 -6
  193. package/src/drizzle/oauth-connected-target.ts +16 -17
  194. package/src/drizzle/oauth-drivers.ts +26 -10
  195. package/src/drizzle/oauth-target.ts +30 -42
  196. package/src/drizzle/passkey-drivers.ts +21 -13
  197. package/src/drizzle/passkey-write-drivers.ts +11 -6
  198. package/src/drizzle/password-prepared-sql.ts +2 -4
  199. package/src/drizzle/password-prepared-target.ts +9 -6
  200. package/src/drizzle/password-registration.ts +7 -8
  201. package/src/drizzle/password-target.ts +19 -18
  202. package/src/drizzle/pg-database.ts +10 -0
  203. package/src/drizzle/pg-emails.ts +28 -16
  204. package/src/drizzle/pg-identity.ts +18 -22
  205. package/src/drizzle/pg-password-prepared.ts +10 -8
  206. package/src/drizzle/pg-passwords.ts +21 -9
  207. package/src/drizzle/pg-proofs.ts +16 -5
  208. package/src/drizzle/pg-sessions.ts +40 -17
  209. package/src/drizzle/phone-target.ts +22 -17
  210. package/src/drizzle/proof-target.ts +9 -12
  211. package/src/drizzle/session-target.ts +32 -50
  212. package/src/drizzle/sqlite-emails.ts +30 -13
  213. package/src/drizzle/sqlite-identity.ts +22 -42
  214. package/src/drizzle/sqlite-password-prepared.ts +23 -9
  215. package/src/drizzle/sqlite-passwords.ts +29 -15
  216. package/src/drizzle/sqlite-proofs.ts +28 -5
  217. package/src/drizzle/sqlite-sessions.ts +49 -23
  218. package/src/drizzle/standalone-guard.ts +18 -6
  219. package/src/drizzle/totp-target.ts +61 -60
  220. package/dist/drizzle/d1-identity.d.mts +0 -30
  221. package/dist/drizzle/mysql-identity.d.mts +0 -21
  222. package/dist/drizzle/pg-identity.d.mts +0 -22
@@ -1,4 +1,3 @@
1
- import { LifecycleHooks } from "@yielded/auth/Hooks";
2
1
  import * as M from "@yielded/auth/OAuth";
3
2
  import {
4
3
  OAuthConnectedPersistence,
@@ -185,32 +184,24 @@ export const makeRevocations = (
185
184
  );
186
185
 
187
186
  export const makeTargetOAuthConnectedServices = (
188
- database: any,
189
187
  mapping: S.Mapping,
190
188
  configuration: OAuthTargetConfiguration,
191
189
  ) => {
192
190
  const retained = captured(mapping);
193
191
 
194
- return Effect.map(LifecycleHooks, (hooks) => ({
195
- oauthConnectedPersistence: makeConnected(
196
- retained,
197
- makeOAuthExecution(database, hooks, configuration),
198
- ),
192
+ return Effect.map(makeOAuthExecution(configuration), (execution) => ({
193
+ oauthConnectedPersistence: makeConnected(retained, execution),
199
194
  }));
200
195
  };
201
196
 
202
197
  export const makeTargetOAuthConnectedRevocationServices = (
203
- database: any,
204
198
  mapping: S.Revocations,
205
199
  configuration: OAuthTargetConfiguration,
206
200
  ) => {
207
201
  const retained = captured(mapping);
208
202
 
209
- return Effect.map(LifecycleHooks, (hooks) => ({
210
- oauthConnectedRevocations: makeRevocations(
211
- retained,
212
- makeOAuthExecution(database, hooks, configuration),
213
- ),
203
+ return Effect.map(makeOAuthExecution(configuration), (execution) => ({
204
+ oauthConnectedRevocations: makeRevocations(retained, execution),
214
205
  }));
215
206
  };
216
207
 
@@ -256,16 +247,24 @@ export const coordinateTargetOAuthConnectedRevocations = <Transaction, A, E, R>(
256
247
  owner,
257
248
  );
258
249
 
259
- export const oauthConnectedPersistenceLayer = (
260
- services: ReturnType<typeof makeTargetOAuthConnectedServices>,
250
+ export const oauthConnectedPersistenceLayer = <E, R>(
251
+ services: Effect.Effect<
252
+ Effect.Success<ReturnType<typeof makeTargetOAuthConnectedServices>>,
253
+ E,
254
+ R
255
+ >,
261
256
  ) =>
262
257
  Layer.effect(
263
258
  OAuthConnectedPersistence,
264
259
  Effect.map(services, (value) => value.oauthConnectedPersistence),
265
260
  );
266
261
 
267
- export const oauthConnectedRevocationsLayer = (
268
- services: ReturnType<typeof makeTargetOAuthConnectedRevocationServices>,
262
+ export const oauthConnectedRevocationsLayer = <E, R>(
263
+ services: Effect.Effect<
264
+ Effect.Success<ReturnType<typeof makeTargetOAuthConnectedRevocationServices>>,
265
+ E,
266
+ R
267
+ >,
269
268
  ) =>
270
269
  Layer.effect(
271
270
  OAuthConnectedRevocations,
@@ -1,3 +1,4 @@
1
+ import { NativeDatabase } from "@yielded/auth-persistence/Adapter";
1
2
  import type { LifecycleHooks } from "@yielded/auth/Hooks";
2
3
  import {
3
4
  OAuthAccountsPersistence,
@@ -7,6 +8,7 @@ import {
7
8
  import type { Table } from "drizzle-orm";
8
9
  import { Effect, Context } from "effect";
9
10
 
11
+ import { nativeDatabase } from "./native-database";
10
12
  import { makeOAuthConnectedTarget } from "./oauth-connected-drivers";
11
13
  import type {
12
14
  OAuthAccountsMapping,
@@ -35,7 +37,13 @@ type TransactionOf<D> = D extends { readonly transaction: (...args: any[]) => an
35
37
  : never;
36
38
 
37
39
  /** Driver-specific entry points instantiate both the database and table family. */
38
- export const makeOAuthTarget = <D, T extends Table, Synchronous extends boolean = false>(
40
+ export const makeOAuthTarget = <
41
+ DatabaseId,
42
+ D,
43
+ T extends Table,
44
+ Synchronous extends boolean = false,
45
+ >(
46
+ databaseService: Context.Service<DatabaseId, D>,
39
47
  configuration: OAuthTargetConfiguration,
40
48
  ) => {
41
49
  function coordinateOAuthSignIn<
@@ -516,7 +524,7 @@ export const makeOAuthTarget = <D, T extends Table, Synchronous extends boolean
516
524
  }
517
525
 
518
526
  return {
519
- ...makeOAuthConnectedTarget<D, T, {}, Synchronous>(configuration),
527
+ ...makeOAuthConnectedTarget<DatabaseId, D, T, {}, Synchronous>(databaseService, configuration),
520
528
  coordinateOAuthSignIn,
521
529
  coordinateOAuthRegistrationIntents,
522
530
  coordinateOAuthAccounts,
@@ -530,13 +538,17 @@ export const makeOAuthTarget = <D, T extends Table, Synchronous extends boolean
530
538
  U extends T,
531
539
  N,
532
540
  >(
533
- database: D,
534
541
  mapping: OAuthAccountsMapping<S, O, C, AC, F, TA, U, N>,
535
- ) => makeTargetOAuthAccountsServices(database, mapping, configuration),
542
+ ) =>
543
+ makeTargetOAuthAccountsServices(mapping, configuration).pipe(
544
+ Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),
545
+ ),
536
546
  makeOAuthSignInServices: <S extends T, O extends T, C extends T, AC extends T, F extends T, N>(
537
- database: D,
538
547
  mapping: OAuthSignInMapping<S, O, C, AC, F, N>,
539
- ) => makeTargetOAuthSignInServices(database, mapping, configuration),
548
+ ) =>
549
+ makeTargetOAuthSignInServices(mapping, configuration).pipe(
550
+ Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),
551
+ ),
540
552
  makeOAuthRegistrationIntentServices: <
541
553
  S extends T,
542
554
  O extends T,
@@ -547,9 +559,11 @@ export const makeOAuthTarget = <D, T extends Table, Synchronous extends boolean
547
559
  I extends T,
548
560
  N,
549
561
  >(
550
- database: D,
551
562
  mapping: OAuthRegistrationIntentMapping<S, O, C, AC, F, TA, I, N>,
552
- ) => makeTargetOAuthRegistrationIntentServices(database, mapping, configuration),
563
+ ) =>
564
+ makeTargetOAuthRegistrationIntentServices(mapping, configuration).pipe(
565
+ Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),
566
+ ),
553
567
  makeOAuthRegistrationServices: <
554
568
  Registration,
555
569
  S extends T,
@@ -561,9 +575,11 @@ export const makeOAuthTarget = <D, T extends Table, Synchronous extends boolean
561
575
  R extends T,
562
576
  N,
563
577
  >(
564
- database: D,
565
578
  mapping: OAuthRegistrationMapping<Registration, S, O, C, AC, TA, I, R, N>,
566
- ) => makeTargetOAuthRegistrationServices<Registration>(database, mapping, configuration),
579
+ ) =>
580
+ makeTargetOAuthRegistrationServices<Registration>(mapping, configuration).pipe(
581
+ Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),
582
+ ),
567
583
  coordinateOAuthRegistration,
568
584
  };
569
585
  };
@@ -1,3 +1,4 @@
1
+ import type { NativeDatabase } from "@yielded/auth-persistence/Adapter";
1
2
  import { LifecycleHooks } from "@yielded/auth/Hooks";
2
3
  import {
3
4
  OAuthAccountRevision,
@@ -83,17 +84,16 @@ export type OAuthCoordinatorError<E> = TransactionCoordinatorError<E, OAuthUnava
83
84
  export type OAuthExecution = TransactionExecution<OAuthUnavailable, CurrentOAuthTransaction, never>;
84
85
 
85
86
  export const sqlClientOAuthStandaloneGuard = (
86
- database: Parameters<typeof sqlClientTransactionStandaloneGuard>[1],
87
- ) => sqlClientTransactionStandaloneGuard(unavailable, database);
87
+ service: Parameters<typeof sqlClientTransactionStandaloneGuard>[1],
88
+ ) => sqlClientTransactionStandaloneGuard(unavailable, service);
88
89
 
89
- export const makeOAuthExecution = (
90
- database: OAuthNativeDatabase,
91
- hooks: LifecycleHooks["Service"],
90
+ export const makeOAuthExecution = Effect.fnUntraced(function* (
92
91
  configuration: OAuthTargetConfiguration,
93
- ): OAuthExecution => {
94
- const execution = makeTransactionExecution(
92
+ ): Effect.fn.Return<OAuthExecution, never, LifecycleHooks | NativeDatabase> {
93
+ const hooks = yield* LifecycleHooks;
94
+
95
+ const execution = yield* makeTransactionExecution(
95
96
  CurrentOAuthTransaction,
96
- database,
97
97
  configuration,
98
98
  unavailable,
99
99
  nonce,
@@ -104,7 +104,7 @@ export const makeOAuthExecution = (
104
104
  run: (operation, mutation) =>
105
105
  execution.run(operation, mutation).pipe(Effect.provideService(LifecycleHooks, hooks)),
106
106
  };
107
- };
107
+ });
108
108
 
109
109
  const prepareValue = <Value, A>(value: Value, prepare: PrepareOAuthCommit<Value, A>) =>
110
110
  Effect.flatMap(CurrentOAuthTransaction, (owner) =>
@@ -388,47 +388,35 @@ export const makeOAuthRegistration = <Registration>(
388
388
  );
389
389
 
390
390
  export const makeTargetOAuthSignInServices = (
391
- database: any,
392
391
  mapping: any,
393
392
  configuration: OAuthTargetConfiguration,
394
393
  ) => {
395
394
  const captured = captureOAuthMapping(mapping);
396
395
 
397
- return Effect.map(LifecycleHooks, (hooks) => ({
398
- oauthSignInPersistence: makeOAuthSignIn(
399
- captured,
400
- makeOAuthExecution(database, hooks, configuration),
401
- ),
396
+ return Effect.map(makeOAuthExecution(configuration), (execution) => ({
397
+ oauthSignInPersistence: makeOAuthSignIn(captured, execution),
402
398
  }));
403
399
  };
404
400
 
405
401
  export const makeTargetOAuthRegistrationIntentServices = (
406
- database: any,
407
402
  mapping: any,
408
403
  configuration: OAuthTargetConfiguration,
409
404
  ) => {
410
405
  const captured = captureOAuthMapping(mapping);
411
406
 
412
- return Effect.map(LifecycleHooks, (hooks) => ({
413
- oauthRegistrationIntents: makeOAuthRegistrationIntents(
414
- captured,
415
- makeOAuthExecution(database, hooks, configuration),
416
- ),
407
+ return Effect.map(makeOAuthExecution(configuration), (execution) => ({
408
+ oauthRegistrationIntents: makeOAuthRegistrationIntents(captured, execution),
417
409
  }));
418
410
  };
419
411
 
420
412
  export const makeTargetOAuthRegistrationServices = <Registration>(
421
- database: any,
422
413
  mapping: any,
423
414
  configuration: OAuthTargetConfiguration,
424
415
  ) => {
425
416
  const captured = captureOAuthMapping(mapping);
426
417
 
427
- return Effect.map(LifecycleHooks, (hooks) => ({
428
- registrationAuthority: makeOAuthRegistration<Registration>(
429
- captured,
430
- makeOAuthExecution(database, hooks, configuration),
431
- ),
418
+ return Effect.map(makeOAuthExecution(configuration), (execution) => ({
419
+ registrationAuthority: makeOAuthRegistration<Registration>(captured, execution),
432
420
  }));
433
421
  };
434
422
 
@@ -698,50 +686,50 @@ export const makeOAuthAccounts = (
698
686
  );
699
687
 
700
688
  export const makeTargetOAuthAccountsServices = (
701
- database: any,
702
689
  mapping: any,
703
690
  configuration: OAuthTargetConfiguration,
704
691
  ) => {
705
692
  const captured = captureOAuthMapping(mapping);
706
693
 
707
- return Effect.map(LifecycleHooks, (hooks) => ({
708
- oauthAccountsPersistence: makeOAuthAccounts(
709
- captured,
710
- makeOAuthExecution(database, hooks, configuration),
711
- ),
694
+ return Effect.map(makeOAuthExecution(configuration), (execution) => ({
695
+ oauthAccountsPersistence: makeOAuthAccounts(captured, execution),
712
696
  }));
713
697
  };
714
698
 
715
- export const oauthAccountsPersistenceLayer = (
716
- services: ReturnType<typeof makeTargetOAuthAccountsServices>,
699
+ export const oauthAccountsPersistenceLayer = <E, R>(
700
+ services: Effect.Effect<Effect.Success<ReturnType<typeof makeTargetOAuthAccountsServices>>, E, R>,
717
701
  ) =>
718
702
  Layer.effect(
719
703
  OAuthAccountsPersistence,
720
704
  Effect.map(services, (value) => value.oauthAccountsPersistence),
721
705
  );
722
706
 
723
- export const oauthSignInPersistenceLayer = (
724
- services: ReturnType<typeof makeTargetOAuthSignInServices>,
707
+ export const oauthSignInPersistenceLayer = <E, R>(
708
+ services: Effect.Effect<Effect.Success<ReturnType<typeof makeTargetOAuthSignInServices>>, E, R>,
725
709
  ) =>
726
710
  Layer.effect(
727
711
  OAuthSignInPersistence,
728
712
  Effect.map(services, (value) => value.oauthSignInPersistence),
729
713
  );
730
714
 
731
- export const oauthRegistrationIntentsLayer = (
732
- services: ReturnType<typeof makeTargetOAuthRegistrationIntentServices>,
715
+ export const oauthRegistrationIntentsLayer = <E, R>(
716
+ services: Effect.Effect<
717
+ Effect.Success<ReturnType<typeof makeTargetOAuthRegistrationIntentServices>>,
718
+ E,
719
+ R
720
+ >,
733
721
  ) =>
734
722
  Layer.effect(
735
723
  OAuthRegistrationIntents,
736
724
  Effect.map(services, (value) => value.oauthRegistrationIntents),
737
725
  );
738
726
 
739
- export const oauthRegistrationAuthorityLayer = <Id, Registration>(
727
+ export const oauthRegistrationAuthorityLayer = <Id, Registration, E, R>(
740
728
  tag: Context.Key<Id, OAuthRegistrationAuthority<Registration>>,
741
729
  services: Effect.Effect<
742
730
  { readonly registrationAuthority: OAuthRegistrationAuthority<Registration> },
743
- never,
744
- LifecycleHooks
731
+ E,
732
+ R
745
733
  >,
746
734
  ) =>
747
735
  Layer.effect(
@@ -1,8 +1,10 @@
1
+ import { NativeDatabase } from "@yielded/auth-persistence/Adapter";
1
2
  import type { LifecycleHooks } from "@yielded/auth/Hooks";
2
3
  import { PasskeyPersistence } from "@yielded/auth/Passkey";
3
4
  import type { Table } from "drizzle-orm";
4
5
  import { Effect, Context } from "effect";
5
6
 
7
+ import { nativeDatabase } from "./native-database";
6
8
  import type {
7
9
  PasskeyCredentialMapping,
8
10
  PasskeyEnrollmentContextMapping,
@@ -33,11 +35,13 @@ type TransactionOf<D> = D extends { readonly transaction: (...args: any[]) => an
33
35
  : never;
34
36
 
35
37
  export const makePasskeyTarget = <
38
+ DatabaseId,
36
39
  D,
37
40
  T extends Table,
38
41
  Extra = unknown,
39
42
  Synchronous extends boolean = false,
40
43
  >(
44
+ databaseService: Context.Service<DatabaseId, D>,
41
45
  configuration: PasskeyTargetConfiguration,
42
46
  ) => {
43
47
  function coordinatePasskeyPersistence<
@@ -304,9 +308,8 @@ export const makePasskeyTarget = <
304
308
  }
305
309
 
306
310
  return {
307
- ...makePasskeyWriteTarget<D, T, Extra, Synchronous>(configuration),
311
+ ...makePasskeyWriteTarget<DatabaseId, D, T, Extra, Synchronous>(databaseService, configuration),
308
312
  makePasskeyCredentialServices: <
309
- Database extends D,
310
313
  S extends T,
311
314
  C extends T,
312
315
  F extends T,
@@ -315,11 +318,12 @@ export const makePasskeyTarget = <
315
318
  N,
316
319
  RSetup = never,
317
320
  >(
318
- database: Database,
319
321
  mapping: PasskeyMappingSource<PasskeyCredentialMapping<S, C, F, O, H, N> & Extra, RSetup>,
320
- ) => makeTargetPasskeyCredentials(database, mapping, configuration),
322
+ ) =>
323
+ makeTargetPasskeyCredentials(mapping, configuration).pipe(
324
+ Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),
325
+ ),
321
326
  makePasskeyEnrollmentContextServices: <
322
- Database extends D,
323
327
  S extends T,
324
328
  C extends T,
325
329
  F extends T,
@@ -329,14 +333,15 @@ export const makePasskeyTarget = <
329
333
  N,
330
334
  RSetup = never,
331
335
  >(
332
- database: Database,
333
336
  mapping: PasskeyMappingSource<
334
337
  PasskeyEnrollmentContextMapping<PasskeyCredentialMapping<S, C, F, O, H, N>, M, N> & Extra,
335
338
  RSetup
336
339
  >,
337
- ) => makeTargetPasskeyEnrollmentContext(database, mapping, configuration),
340
+ ) =>
341
+ makeTargetPasskeyEnrollmentContext(mapping, configuration).pipe(
342
+ Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),
343
+ ),
338
344
  makePasskeyPersistenceServices: <
339
- Database extends D,
340
345
  S extends T,
341
346
  C extends T,
342
347
  F extends T,
@@ -349,7 +354,6 @@ export const makePasskeyTarget = <
349
354
  N,
350
355
  RSetup = never,
351
356
  >(
352
- database: Database,
353
357
  mapping: PasskeyMappingSource<
354
358
  PasskeyPersistenceMapping<
355
359
  PasskeyCredentialMapping<S, C, F, O, H, N>,
@@ -362,9 +366,11 @@ export const makePasskeyTarget = <
362
366
  Extra,
363
367
  RSetup
364
368
  >,
365
- ) => makeTargetPasskeyPersistence(database, mapping, configuration),
369
+ ) =>
370
+ makeTargetPasskeyPersistence(mapping, configuration).pipe(
371
+ Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),
372
+ ),
366
373
  makePasskeyRegistrationCeremonyServices: <
367
- Database extends D,
368
374
  M extends T,
369
375
  Flow extends T,
370
376
  Admission extends T,
@@ -373,12 +379,14 @@ export const makePasskeyTarget = <
373
379
  H extends T,
374
380
  RSetup = never,
375
381
  >(
376
- database: Database,
377
382
  mapping: PasskeyMappingSource<
378
383
  PasskeyRegistrationCeremonyMapping<M, Flow, Admission, Charge, Intent, H> & Extra,
379
384
  RSetup
380
385
  >,
381
- ) => makeTargetPasskeyRegistration(database, mapping, configuration),
386
+ ) =>
387
+ makeTargetPasskeyRegistration(mapping, configuration).pipe(
388
+ Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),
389
+ ),
382
390
  coordinatePasskeyPersistence,
383
391
  coordinatePasskeyRegistrationCeremony,
384
392
  };
@@ -1,8 +1,10 @@
1
+ import { NativeDatabase } from "@yielded/auth-persistence/Adapter";
1
2
  import type { LifecycleHooks } from "@yielded/auth/Hooks";
2
3
  import { PasskeyManagementPersistence, PasskeyPersistence } from "@yielded/auth/Passkey";
3
4
  import type { Table } from "drizzle-orm";
4
5
  import { Context, Effect } from "effect";
5
6
 
7
+ import { nativeDatabase } from "./native-database";
6
8
  import type { PasskeyMappingSource } from "./passkey-model";
7
9
  import type { PasskeyCoordinatorError, PasskeyTargetConfiguration } from "./passkey-target";
8
10
  import type {
@@ -23,11 +25,13 @@ type TransactionOf<D> = D extends { readonly transaction: (...args: any[]) => an
23
25
  : never;
24
26
 
25
27
  export const makePasskeyWriteTarget = <
28
+ DatabaseId,
26
29
  D,
27
30
  T extends Table,
28
31
  Extra = unknown,
29
32
  Synchronous extends boolean = false,
30
33
  >(
34
+ databaseService: Context.Service<DatabaseId, D>,
31
35
  configuration: PasskeyTargetConfiguration,
32
36
  ) => {
33
37
  function coordinatePasskeyManagement<
@@ -180,7 +184,6 @@ export const makePasskeyWriteTarget = <
180
184
  }
181
185
 
182
186
  const makePasskeyManagementServices = <
183
- Database extends D,
184
187
  S extends T,
185
188
  C extends T,
186
189
  F extends T,
@@ -194,12 +197,14 @@ export const makePasskeyWriteTarget = <
194
197
  N,
195
198
  RSetup = never,
196
199
  >(
197
- database: Database,
198
200
  mapping: PasskeyMappingSource<
199
201
  PasskeyManagementMapping<S, C, F, O, H, M, Flow, Admission, Charge, Command, N> & Extra,
200
202
  RSetup
201
203
  >,
202
- ) => makeTargetPasskeyManagement(database, mapping, configuration);
204
+ ) =>
205
+ makeTargetPasskeyManagement(mapping, configuration).pipe(
206
+ Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),
207
+ );
203
208
 
204
209
  function coordinatePasskeyRegistration<
205
210
  Database extends D,
@@ -357,7 +362,6 @@ export const makePasskeyWriteTarget = <
357
362
  }
358
363
 
359
364
  const makePasskeyRegistrationServices = <
360
- Database extends D,
361
365
  S extends T,
362
366
  C extends T,
363
367
  F extends T,
@@ -372,7 +376,6 @@ export const makePasskeyWriteTarget = <
372
376
  Value,
373
377
  RSetup = never,
374
378
  >(
375
- database: Database,
376
379
  mapping: PasskeyMappingSource<
377
380
  PasskeyRegistrationMapping<S, C, F, O, H, M, Flow, Admission, Charge, Intent, N, Value> &
378
381
  Extra,
@@ -384,7 +387,9 @@ export const makePasskeyWriteTarget = <
384
387
  Extra,
385
388
  Value,
386
389
  RSetup
387
- >(database, mapping, configuration);
390
+ >(mapping, configuration).pipe(
391
+ Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),
392
+ );
388
393
 
389
394
  return {
390
395
  makePasskeyManagementServices,
@@ -50,7 +50,6 @@ import {
50
50
  CurrentPasswordSql,
51
51
  passwordSqlKernel as kernel,
52
52
  type PasswordSqlConfiguration,
53
- type PasswordSqlDatabase,
54
53
  type PasswordSqlQuery,
55
54
  } from "./password-sql";
56
55
  import { checkProofCompletionIn, completeProofPlanIn } from "./proof-sql";
@@ -85,7 +84,6 @@ const translateContextFailure = <A, E, R>(
85
84
  );
86
85
 
87
86
  type Mapping = AnyPasswordPreparedPersistenceMapping;
88
- type Database = PasswordSqlDatabase;
89
87
  const nowMillis = DateTime.now.pipe(Effect.map(DateTime.toEpochMillis));
90
88
 
91
89
  const read = (query: PasswordSqlQuery, locking: boolean) =>
@@ -410,10 +408,10 @@ const terminal = Effect.fn("DrizzlePasswordPrepared.terminal")(function* (
410
408
 
411
409
  export const makeSqlPasswordPreparedPersistence = Effect.fn("makeSqlPasswordPreparedPersistence")(
412
410
  function* (
413
- database: Database,
414
411
  mapping: Mapping,
415
412
  configuration: PasswordSqlConfiguration,
416
- ): Effect.fn.Return<PasswordPreparedPersistence, never, LifecycleHooks> {
413
+ ): Effect.fn.Return<PasswordPreparedPersistence, never, LifecycleHooks | CurrentPasswordSql> {
414
+ const database = yield* CurrentPasswordSql;
417
415
  const hooks = yield* LifecycleHooks;
418
416
 
419
417
  const p = mapping.password,
@@ -16,6 +16,7 @@ import { type Context, Cause, Effect, Layer } from "effect";
16
16
  import type * as SqlError from "effect/sql/SqlError";
17
17
 
18
18
  import { makeSqlPasswordPreparedPersistence } from "./password-prepared-sql";
19
+ import { CurrentPasswordSql } from "./password-sql";
19
20
  import type { PasswordSqlDatabase } from "./password-sql";
20
21
  import {
21
22
  passwordOptions,
@@ -24,7 +25,6 @@ import {
24
25
  } from "./password-target";
25
26
 
26
27
  export const makeTargetPasswordPreparedPersistenceServices = (
27
- database: any,
28
28
  mapping: any,
29
29
  configuration: PasswordTargetConfiguration,
30
30
  proofMapping?: any,
@@ -32,7 +32,6 @@ export const makeTargetPasswordPreparedPersistenceServices = (
32
32
  Effect.gen(function* () {
33
33
  return {
34
34
  passwordPreparedPersistence: yield* makeSqlPasswordPreparedPersistence(
35
- database,
36
35
  mapping,
37
36
  passwordOptions(configuration, proofMapping),
38
37
  ),
@@ -69,9 +68,13 @@ export const coordinateTargetPasswordPreparedPersistence = <Transaction, A, E, R
69
68
  let acceptingPostconditions = true;
70
69
 
71
70
  const services = yield* makeSqlPasswordPreparedPersistence(
72
- transaction as unknown as PasswordSqlDatabase,
73
71
  mapping,
74
72
  passwordOptions(configuration, proofMapping, true),
73
+ ).pipe(
74
+ Effect.provideService(
75
+ CurrentPasswordSql,
76
+ transaction as unknown as PasswordSqlDatabase,
77
+ ),
75
78
  );
76
79
 
77
80
  const protect = <Out, Err, Env>(effect: Effect.Effect<Out, Err, Env>) =>
@@ -146,12 +149,12 @@ export const coordinateTargetPasswordPreparedPersistence = <Transaction, A, E, R
146
149
  return result.value;
147
150
  });
148
151
 
149
- export const passwordPreparedPersistenceLayer = <Id>(
152
+ export const passwordPreparedPersistenceLayer = <Id, E, R>(
150
153
  tag: Context.Key<Id, PasswordPreparedPersistence>,
151
154
  services: Effect.Effect<
152
155
  { readonly passwordPreparedPersistence: PasswordPreparedPersistence },
153
- never,
154
- LifecycleHooks
156
+ E,
157
+ R
155
158
  >,
156
159
  ) =>
157
160
  Layer.effect(
@@ -23,14 +23,9 @@ import {
23
23
  type AnyPasswordRegistrationMapping,
24
24
  requiredPasswordRegistrationConstraints,
25
25
  } from "./password-model";
26
- import {
27
- CurrentPasswordSql,
28
- type PasswordSqlDatabase,
29
- type PasswordSqlQuery,
30
- } from "./password-sql";
26
+ import { CurrentPasswordSql, type PasswordSqlQuery } from "./password-sql";
31
27
  import { CurrentProofSql, type ProofSqlDatabase } from "./proof-sql";
32
28
 
33
- type Database = PasswordSqlDatabase;
34
29
  type Mapping<Registration> = AnyPasswordRegistrationMapping<Registration>;
35
30
  const unavailable = () => PasswordUnavailable.make({});
36
31
 
@@ -219,10 +214,14 @@ const registerIn = Effect.fn("DrizzlePasswordRegistration.registerIn")(function*
219
214
  export const makeSqlPasswordRegistrationAuthority = Effect.fn(
220
215
  "makeSqlPasswordRegistrationAuthority",
221
216
  )(function* <Registration>(
222
- database: Database,
223
217
  mapping: Mapping<Registration>,
224
218
  configuration: PasswordRegistrationConfiguration,
225
- ): Effect.fn.Return<PasswordRegistrationAuthority<Registration>, never, LifecycleHooks> {
219
+ ): Effect.fn.Return<
220
+ PasswordRegistrationAuthority<Registration>,
221
+ never,
222
+ LifecycleHooks | CurrentPasswordSql
223
+ > {
224
+ const database = yield* CurrentPasswordSql;
226
225
  const hooks = yield* LifecycleHooks;
227
226
 
228
227
  return {