@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 +1 @@
1
- {"version":3,"file":"pg-passwords.mjs","names":[],"sources":["../../src/drizzle/pg-passwords.ts"],"sourcesContent":["import type { LifecycleHooks, HookConfigurationError } from \"@yielded/auth/Hooks\";\nimport { type PasswordUnavailable, PasswordPersistence } from \"@yielded/auth/Password\";\n/* oxlint-disable no-explicit-any -- proof mapping tables are independently typed by the proof owner; this driver forwards them unchanged to the shared target. */\nimport type { AnyRelations } from \"drizzle-orm\";\nimport type { EffectPgDatabase as PgliteDatabase } from \"drizzle-orm/effect-pglite\";\nimport type { EffectPgDatabase as PostgresDatabase } from \"drizzle-orm/effect-postgres\";\nimport type { AnyPgTable } from \"drizzle-orm/pg-core\";\nimport { Effect, Context } from \"effect\";\nimport type { SqlError } from \"effect/sql/SqlError\";\n\nimport type { PasswordPersistenceMapping, PasswordRegistrationMapping } from \"./password-model\";\nimport type { PasswordRegistrationAuthority } from \"./password-registration\";\nimport type { PasswordSqlQuery } from \"./password-sql\";\nimport {\n coordinateTargetPasswordPersistence,\n coordinateTargetPasswordRegistration,\n makeTargetPasswordPersistenceServices,\n makeTargetPasswordRegistrationServices,\n sqlClientPasswordStandaloneGuard,\n} from \"./password-target\";\nimport type { ProofPersistenceMapping } from \"./proof-model\";\nimport type { ProofSqlQuery } from \"./proof-sql\";\nimport { sqlClientProofStandaloneGuard } from \"./proof-target\";\nimport type { SuppliedService } from \"./SuppliedService\";\n\ntype Database = PostgresDatabase<AnyRelations> | PgliteDatabase<AnyRelations>;\ntype TransactionOf<D extends Database> = Parameters<Parameters<D[\"transaction\"]>[0]>[0];\n\nconst configuration = (database: Database) => ({\n mode: \"interactive\" as const,\n locking: true,\n standaloneGuard: sqlClientPasswordStandaloneGuard(database),\n insertIfAbsent: (query: PasswordSqlQuery) => query.onConflictDoNothing(),\n generatedSubjectRows: (query: PasswordSqlQuery) => query.returning(),\n proof: {\n mode: \"interactive\" as const,\n locking: true,\n standaloneGuard: sqlClientProofStandaloneGuard(database),\n insertIfAbsent: (query: ProofSqlQuery) => query.onConflictDoNothing(),\n },\n});\n\ntype PasswordMapping<\n S extends AnyPgTable,\n I extends AnyPgTable,\n C extends AnyPgTable,\n AC extends AnyPgTable,\n A extends AnyPgTable,\n RS extends AnyPgTable,\n CE extends AnyPgTable,\n M extends AnyPgTable,\n NativeId,\n> = PasswordPersistenceMapping<S, I, C, AC, A, RS, CE, M, NativeId>;\n\nexport const makePgPasswordPersistenceServices = <\n S extends AnyPgTable,\n I extends AnyPgTable,\n C extends AnyPgTable,\n AC extends AnyPgTable,\n A extends AnyPgTable,\n RS extends AnyPgTable,\n CE extends AnyPgTable,\n M extends AnyPgTable,\n NativeId,\n>(\n database: Database,\n mapping: PasswordMapping<S, I, C, AC, A, RS, CE, M, NativeId>,\n proofMapping?: ProofPersistenceMapping<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n >,\n) =>\n makeTargetPasswordPersistenceServices(database, mapping, configuration(database), proofMapping);\n\nexport function coordinatePgPasswordPersistence<\n D extends Database,\n S extends AnyPgTable,\n I extends AnyPgTable,\n C extends AnyPgTable,\n AC extends AnyPgTable,\n A extends AnyPgTable,\n RS extends AnyPgTable,\n CE extends AnyPgTable,\n M extends AnyPgTable,\n NativeId,\n PM extends\n | ProofPersistenceMapping<any, any, any, any, any, any, any, any, any, any, any, any>\n | undefined,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PasswordMapping<S, I, C, AC, A, RS, CE, M, NativeId>;\n readonly proofMapping?: PM;\n readonly transaction?: never;\n },\n body: Effect.Effect<Out, E, R>,\n): Effect.Effect<\n Out,\n E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, PasswordPersistence> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinatePgPasswordPersistence<\n D extends Database,\n S extends AnyPgTable,\n I extends AnyPgTable,\n C extends AnyPgTable,\n AC extends AnyPgTable,\n A extends AnyPgTable,\n RS extends AnyPgTable,\n CE extends AnyPgTable,\n M extends AnyPgTable,\n NativeId,\n PM extends\n | ProofPersistenceMapping<any, any, any, any, any, any, any, any, any, any, any, any>\n | undefined,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PasswordMapping<S, I, C, AC, A, RS, CE, M, NativeId>;\n readonly proofMapping?: PM;\n readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<Out, E, R>,\n): Effect.Effect<\n Out,\n E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, PasswordPersistence | TxId> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinatePgPasswordPersistence<\n D extends Database,\n S extends AnyPgTable,\n I extends AnyPgTable,\n C extends AnyPgTable,\n AC extends AnyPgTable,\n A extends AnyPgTable,\n RS extends AnyPgTable,\n CE extends AnyPgTable,\n M extends AnyPgTable,\n NativeId,\n PM extends\n | ProofPersistenceMapping<any, any, any, any, any, any, any, any, any, any, any, any>\n | undefined,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PasswordMapping<S, I, C, AC, A, RS, CE, M, NativeId>;\n readonly proofMapping?: PM;\n readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<Out, E, R>,\n): Effect.Effect<\n Out,\n E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, PasswordPersistence> | LifecycleHooks | DatabaseRequirements\n> {\n return Effect.flatMap(acquire, (database) =>\n coordinateTargetPasswordPersistence<TransactionOf<D>, Out, E, Exclude<R, PasswordPersistence>>(\n database,\n options.mapping,\n configuration(database),\n options.proofMapping,\n (\n transaction: TransactionOf<D>,\n services: { readonly passwordPersistence: PasswordPersistence[\"Service\"] },\n ) => {\n const provided = Context.make(PasswordPersistence, services.passwordPersistence);\n const work = Effect.provideContext(body, provided);\n\n return options.transaction === undefined\n ? work\n : Effect.provideService(work, options.transaction, options.transaction.of(transaction));\n },\n ),\n );\n}\n\nexport const makePgPasswordRegistrationServices = <\n Registration,\n S extends AnyPgTable,\n I extends AnyPgTable,\n C extends AnyPgTable,\n AC extends AnyPgTable,\n Rq extends AnyPgTable,\n NativeId,\n>(\n database: Database,\n mapping: PasswordRegistrationMapping<Registration, S, I, C, AC, Rq, NativeId>,\n) =>\n makeTargetPasswordRegistrationServices<Registration>(database, mapping, configuration(database));\n\nexport function coordinatePgPasswordRegistration<\n TargetId,\n Registration,\n D extends Database,\n S extends AnyPgTable,\n I extends AnyPgTable,\n C extends AnyPgTable,\n AC extends AnyPgTable,\n Rq extends AnyPgTable,\n NativeId,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PasswordRegistrationMapping<NoInfer<Registration>, S, I, C, AC, Rq, NativeId>;\n readonly target: SuppliedService<TargetId, PasswordRegistrationAuthority<Registration>>;\n readonly transaction?: never;\n },\n body: Effect.Effect<Out, E, R>,\n): Effect.Effect<\n Out,\n E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, TargetId> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinatePgPasswordRegistration<\n TargetId,\n Registration,\n D extends Database,\n S extends AnyPgTable,\n I extends AnyPgTable,\n C extends AnyPgTable,\n AC extends AnyPgTable,\n Rq extends AnyPgTable,\n NativeId,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PasswordRegistrationMapping<NoInfer<Registration>, S, I, C, AC, Rq, NativeId>;\n readonly target: SuppliedService<TargetId, PasswordRegistrationAuthority<Registration>>;\n readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<Out, E, R>,\n): Effect.Effect<\n Out,\n E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, TargetId | TxId> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinatePgPasswordRegistration<\n TargetId,\n Registration,\n D extends Database,\n S extends AnyPgTable,\n I extends AnyPgTable,\n C extends AnyPgTable,\n AC extends AnyPgTable,\n Rq extends AnyPgTable,\n NativeId,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PasswordRegistrationMapping<NoInfer<Registration>, S, I, C, AC, Rq, NativeId>;\n readonly target: SuppliedService<TargetId, PasswordRegistrationAuthority<Registration>>;\n readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<Out, E, R>,\n): Effect.Effect<\n Out,\n E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, TargetId> | LifecycleHooks | DatabaseRequirements\n> {\n return Effect.flatMap(acquire, (database) =>\n coordinateTargetPasswordRegistration<\n Registration,\n TransactionOf<D>,\n Out,\n E,\n Exclude<R, TargetId>\n >(\n database,\n options.mapping,\n configuration(database),\n (\n transaction: TransactionOf<D>,\n services: { readonly registrationAuthority: PasswordRegistrationAuthority<Registration> },\n ) => {\n const provided = Context.make(options.target, services.registrationAuthority);\n const work = Effect.provideContext(body, provided);\n\n return options.transaction === undefined\n ? work\n : Effect.provideService(work, options.transaction, options.transaction.of(transaction));\n },\n ),\n );\n}\n\nexport { configuration as pgPasswordConfiguration };\n"],"mappings":";;;;;AA4BA,MAAM,iBAAiB,cAAwB;CAC7C,MAAM;CACN,SAAS;CACT,iBAAiB,iCAAiC,QAAQ;CAC1D,iBAAiB,UAA4B,MAAM,oBAAoB;CACvE,uBAAuB,UAA4B,MAAM,UAAU;CACnE,OAAO;EACL,MAAM;EACN,SAAS;EACT,iBAAiB,8BAA8B,QAAQ;EACvD,iBAAiB,UAAyB,MAAM,oBAAoB;CACtE;AACF;AAcA,MAAa,qCAWX,UACA,SACA,iBAeA,sCAAsC,UAAU,SAAS,cAAc,QAAQ,GAAG,YAAY;AAsEhG,SAAgB,gCAsBd,SACA,SAKA,MAKA;CACA,OAAO,OAAO,QAAQ,UAAU,aAC9B,oCACE,UACA,QAAQ,SACR,cAAc,QAAQ,GACtB,QAAQ,eAEN,aACA,aACG;EACH,MAAM,WAAW,QAAQ,KAAK,qBAAqB,SAAS,mBAAmB;EAC/E,MAAM,OAAO,OAAO,eAAe,MAAM,QAAQ;EAEjD,OAAO,QAAQ,gBAAgB,KAAA,IAC3B,OACA,OAAO,eAAe,MAAM,QAAQ,aAAa,QAAQ,YAAY,GAAG,WAAW,CAAC;CAC1F,CACF,CACF;AACF;AAEA,MAAa,sCASX,UACA,YAEA,uCAAqD,UAAU,SAAS,cAAc,QAAQ,CAAC;AA8DjG,SAAgB,iCAkBd,SACA,SAKA,MAKA;CACA,OAAO,OAAO,QAAQ,UAAU,aAC9B,qCAOE,UACA,QAAQ,SACR,cAAc,QAAQ,IAEpB,aACA,aACG;EACH,MAAM,WAAW,QAAQ,KAAK,QAAQ,QAAQ,SAAS,qBAAqB;EAC5E,MAAM,OAAO,OAAO,eAAe,MAAM,QAAQ;EAEjD,OAAO,QAAQ,gBAAgB,KAAA,IAC3B,OACA,OAAO,eAAe,MAAM,QAAQ,aAAa,QAAQ,YAAY,GAAG,WAAW,CAAC;CAC1F,CACF,CACF;AACF"}
1
+ {"version":3,"file":"pg-passwords.mjs","names":["DatabaseService"],"sources":["../../src/drizzle/pg-passwords.ts"],"sourcesContent":["import type { LifecycleHooks, HookConfigurationError } from \"@yielded/auth/Hooks\";\nimport { type PasswordUnavailable, PasswordPersistence } from \"@yielded/auth/Password\";\n/* oxlint-disable no-explicit-any -- proof mapping tables are independently typed by the proof owner; this driver forwards them unchanged to the shared target. */\nimport type { AnyRelations } from \"drizzle-orm\";\nimport type { EffectPgDatabase as PgliteDatabase } from \"drizzle-orm/effect-pglite\";\nimport type { EffectPgDatabase as PostgresDatabase } from \"drizzle-orm/effect-postgres\";\nimport type { AnyPgTable } from \"drizzle-orm/pg-core\";\nimport { Effect, Context } from \"effect\";\nimport type { SqlError } from \"effect/sql/SqlError\";\n\nimport { nativeDatabase } from \"./native-database\";\nimport type { PasswordPersistenceMapping, PasswordRegistrationMapping } from \"./password-model\";\nimport type { PasswordRegistrationAuthority } from \"./password-registration\";\nimport { CurrentPasswordSql } from \"./password-sql\";\nimport type { PasswordSqlQuery } from \"./password-sql\";\nimport {\n coordinateTargetPasswordPersistence,\n coordinateTargetPasswordRegistration,\n makeTargetPasswordPersistenceServices,\n makeTargetPasswordRegistrationServices,\n sqlClientPasswordStandaloneGuard,\n} from \"./password-target\";\nimport { Database as DatabaseService } from \"./pg-database\";\nimport type { ProofPersistenceMapping } from \"./proof-model\";\nimport type { ProofSqlQuery } from \"./proof-sql\";\nimport { sqlClientProofStandaloneGuard } from \"./proof-target\";\nimport {\n type TransactionService,\n acquireTransactionService,\n transactionService,\n} from \"./standalone-guard\";\nimport type { SuppliedService } from \"./SuppliedService\";\n\ntype Database = PostgresDatabase<AnyRelations> | PgliteDatabase<AnyRelations>;\ntype TransactionOf<D extends Database> = Parameters<Parameters<D[\"transaction\"]>[0]>[0];\n\nconst configuration = (service: TransactionService | undefined) => ({\n mode: \"interactive\" as const,\n locking: true,\n standaloneGuard: sqlClientPasswordStandaloneGuard(service),\n insertIfAbsent: (query: PasswordSqlQuery) => query.onConflictDoNothing(),\n generatedSubjectRows: (query: PasswordSqlQuery) => query.returning(),\n proof: {\n mode: \"interactive\" as const,\n locking: true,\n standaloneGuard: sqlClientProofStandaloneGuard(service),\n insertIfAbsent: (query: ProofSqlQuery) => query.onConflictDoNothing(),\n },\n});\n\ntype PasswordMapping<\n S extends AnyPgTable,\n I extends AnyPgTable,\n C extends AnyPgTable,\n AC extends AnyPgTable,\n A extends AnyPgTable,\n RS extends AnyPgTable,\n CE extends AnyPgTable,\n M extends AnyPgTable,\n NativeId,\n> = PasswordPersistenceMapping<S, I, C, AC, A, RS, CE, M, NativeId>;\n\nexport const makePgPasswordPersistenceServices = <\n S extends AnyPgTable,\n I extends AnyPgTable,\n C extends AnyPgTable,\n AC extends AnyPgTable,\n A extends AnyPgTable,\n RS extends AnyPgTable,\n CE extends AnyPgTable,\n M extends AnyPgTable,\n NativeId,\n>(\n mapping: PasswordMapping<S, I, C, AC, A, RS, CE, M, NativeId>,\n proofMapping?: ProofPersistenceMapping<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n >,\n) =>\n Effect.flatMap(\n Effect.map(acquireTransactionService(DatabaseService), configuration),\n (configuration) => makeTargetPasswordPersistenceServices(mapping, configuration, proofMapping),\n ).pipe(Effect.provideServiceEffect(CurrentPasswordSql, nativeDatabase(DatabaseService)));\n\nexport function coordinatePgPasswordPersistence<\n D extends Database,\n S extends AnyPgTable,\n I extends AnyPgTable,\n C extends AnyPgTable,\n AC extends AnyPgTable,\n A extends AnyPgTable,\n RS extends AnyPgTable,\n CE extends AnyPgTable,\n M extends AnyPgTable,\n NativeId,\n PM extends\n | ProofPersistenceMapping<any, any, any, any, any, any, any, any, any, any, any, any>\n | undefined,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PasswordMapping<S, I, C, AC, A, RS, CE, M, NativeId>;\n readonly proofMapping?: PM;\n readonly transaction?: never;\n },\n body: Effect.Effect<Out, E, R>,\n): Effect.Effect<\n Out,\n E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, PasswordPersistence> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinatePgPasswordPersistence<\n D extends Database,\n S extends AnyPgTable,\n I extends AnyPgTable,\n C extends AnyPgTable,\n AC extends AnyPgTable,\n A extends AnyPgTable,\n RS extends AnyPgTable,\n CE extends AnyPgTable,\n M extends AnyPgTable,\n NativeId,\n PM extends\n | ProofPersistenceMapping<any, any, any, any, any, any, any, any, any, any, any, any>\n | undefined,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PasswordMapping<S, I, C, AC, A, RS, CE, M, NativeId>;\n readonly proofMapping?: PM;\n readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<Out, E, R>,\n): Effect.Effect<\n Out,\n E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, PasswordPersistence | TxId> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinatePgPasswordPersistence<\n D extends Database,\n S extends AnyPgTable,\n I extends AnyPgTable,\n C extends AnyPgTable,\n AC extends AnyPgTable,\n A extends AnyPgTable,\n RS extends AnyPgTable,\n CE extends AnyPgTable,\n M extends AnyPgTable,\n NativeId,\n PM extends\n | ProofPersistenceMapping<any, any, any, any, any, any, any, any, any, any, any, any>\n | undefined,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PasswordMapping<S, I, C, AC, A, RS, CE, M, NativeId>;\n readonly proofMapping?: PM;\n readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<Out, E, R>,\n): Effect.Effect<\n Out,\n E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, PasswordPersistence> | LifecycleHooks | DatabaseRequirements\n> {\n return Effect.flatMap(acquire, (database) =>\n coordinateTargetPasswordPersistence<TransactionOf<D>, Out, E, Exclude<R, PasswordPersistence>>(\n database,\n options.mapping,\n configuration(transactionService(database)),\n options.proofMapping,\n (\n transaction: TransactionOf<D>,\n services: { readonly passwordPersistence: PasswordPersistence[\"Service\"] },\n ) => {\n const provided = Context.make(PasswordPersistence, services.passwordPersistence);\n const work = Effect.provideContext(body, provided);\n\n return options.transaction === undefined\n ? work\n : Effect.provideService(work, options.transaction, options.transaction.of(transaction));\n },\n ),\n );\n}\n\nexport const makePgPasswordRegistrationServices = <\n Registration,\n S extends AnyPgTable,\n I extends AnyPgTable,\n C extends AnyPgTable,\n AC extends AnyPgTable,\n Rq extends AnyPgTable,\n NativeId,\n>(\n mapping: PasswordRegistrationMapping<Registration, S, I, C, AC, Rq, NativeId>,\n) =>\n Effect.flatMap(\n Effect.map(acquireTransactionService(DatabaseService), configuration),\n (configuration) => makeTargetPasswordRegistrationServices<Registration>(mapping, configuration),\n ).pipe(Effect.provideServiceEffect(CurrentPasswordSql, nativeDatabase(DatabaseService)));\n\nexport function coordinatePgPasswordRegistration<\n TargetId,\n Registration,\n D extends Database,\n S extends AnyPgTable,\n I extends AnyPgTable,\n C extends AnyPgTable,\n AC extends AnyPgTable,\n Rq extends AnyPgTable,\n NativeId,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PasswordRegistrationMapping<NoInfer<Registration>, S, I, C, AC, Rq, NativeId>;\n readonly target: SuppliedService<TargetId, PasswordRegistrationAuthority<Registration>>;\n readonly transaction?: never;\n },\n body: Effect.Effect<Out, E, R>,\n): Effect.Effect<\n Out,\n E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, TargetId> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinatePgPasswordRegistration<\n TargetId,\n Registration,\n D extends Database,\n S extends AnyPgTable,\n I extends AnyPgTable,\n C extends AnyPgTable,\n AC extends AnyPgTable,\n Rq extends AnyPgTable,\n NativeId,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PasswordRegistrationMapping<NoInfer<Registration>, S, I, C, AC, Rq, NativeId>;\n readonly target: SuppliedService<TargetId, PasswordRegistrationAuthority<Registration>>;\n readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<Out, E, R>,\n): Effect.Effect<\n Out,\n E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, TargetId | TxId> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinatePgPasswordRegistration<\n TargetId,\n Registration,\n D extends Database,\n S extends AnyPgTable,\n I extends AnyPgTable,\n C extends AnyPgTable,\n AC extends AnyPgTable,\n Rq extends AnyPgTable,\n NativeId,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PasswordRegistrationMapping<NoInfer<Registration>, S, I, C, AC, Rq, NativeId>;\n readonly target: SuppliedService<TargetId, PasswordRegistrationAuthority<Registration>>;\n readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<Out, E, R>,\n): Effect.Effect<\n Out,\n E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, TargetId> | LifecycleHooks | DatabaseRequirements\n> {\n return Effect.flatMap(acquire, (database) =>\n coordinateTargetPasswordRegistration<\n Registration,\n TransactionOf<D>,\n Out,\n E,\n Exclude<R, TargetId>\n >(\n database,\n options.mapping,\n configuration(transactionService(database)),\n (\n transaction: TransactionOf<D>,\n services: { readonly registrationAuthority: PasswordRegistrationAuthority<Registration> },\n ) => {\n const provided = Context.make(options.target, services.registrationAuthority);\n const work = Effect.provideContext(body, provided);\n\n return options.transaction === undefined\n ? work\n : Effect.provideService(work, options.transaction, options.transaction.of(transaction));\n },\n ),\n );\n}\n\nexport { configuration as pgPasswordConfiguration };\n"],"mappings":";;;;;;;;;AAoCA,MAAM,iBAAiB,aAA6C;CAClE,MAAM;CACN,SAAS;CACT,iBAAiB,iCAAiC,OAAO;CACzD,iBAAiB,UAA4B,MAAM,oBAAoB;CACvE,uBAAuB,UAA4B,MAAM,UAAU;CACnE,OAAO;EACL,MAAM;EACN,SAAS;EACT,iBAAiB,8BAA8B,OAAO;EACtD,iBAAiB,UAAyB,MAAM,oBAAoB;CACtE;AACF;AAcA,MAAa,qCAWX,SACA,iBAeA,OAAO,QACL,OAAO,IAAI,0BAA0BA,QAAe,GAAG,aAAa,IACnE,kBAAkB,sCAAsC,SAAS,eAAe,YAAY,CAC/F,CAAC,CAAC,KAAK,OAAO,qBAAqB,oBAAoB,eAAeA,QAAe,CAAC,CAAC;AAsEzF,SAAgB,gCAsBd,SACA,SAKA,MAKA;CACA,OAAO,OAAO,QAAQ,UAAU,aAC9B,oCACE,UACA,QAAQ,SACR,cAAc,mBAAmB,QAAQ,CAAC,GAC1C,QAAQ,eAEN,aACA,aACG;EACH,MAAM,WAAW,QAAQ,KAAK,qBAAqB,SAAS,mBAAmB;EAC/E,MAAM,OAAO,OAAO,eAAe,MAAM,QAAQ;EAEjD,OAAO,QAAQ,gBAAgB,KAAA,IAC3B,OACA,OAAO,eAAe,MAAM,QAAQ,aAAa,QAAQ,YAAY,GAAG,WAAW,CAAC;CAC1F,CACF,CACF;AACF;AAEA,MAAa,sCASX,YAEA,OAAO,QACL,OAAO,IAAI,0BAA0BA,QAAe,GAAG,aAAa,IACnE,kBAAkB,uCAAqD,SAAS,aAAa,CAChG,CAAC,CAAC,KAAK,OAAO,qBAAqB,oBAAoB,eAAeA,QAAe,CAAC,CAAC;AA8DzF,SAAgB,iCAkBd,SACA,SAKA,MAKA;CACA,OAAO,OAAO,QAAQ,UAAU,aAC9B,qCAOE,UACA,QAAQ,SACR,cAAc,mBAAmB,QAAQ,CAAC,IAExC,aACA,aACG;EACH,MAAM,WAAW,QAAQ,KAAK,QAAQ,QAAQ,SAAS,qBAAqB;EAC5E,MAAM,OAAO,OAAO,eAAe,MAAM,QAAQ;EAEjD,OAAO,QAAQ,gBAAgB,KAAA,IAC3B,OACA,OAAO,eAAe,MAAM,QAAQ,aAAa,QAAQ,YAAY,GAAG,WAAW,CAAC;CAC1F,CACF,CACF;AACF"}
@@ -1,5 +1,6 @@
1
1
  import { ProofPersistenceMapping } from "./proof-model.mjs";
2
2
  import { SuppliedService } from "./SuppliedService.mjs";
3
+ import { Database as Database$1 } from "./pg-database.mjs";
3
4
  import { AnyRelations } from "drizzle-orm";
4
5
  import { Effect } from "effect";
5
6
  import { HookConfigurationError, LifecycleHooks } from "@yielded/auth/Hooks";
@@ -12,7 +13,7 @@ import { SqlError } from "effect/sql/SqlError";
12
13
  type Database = EffectPgDatabase$1<AnyRelations> | EffectPgDatabase<AnyRelations>;
13
14
  type TransactionOf<D extends Database> = Parameters<Parameters<D["transaction"]>[0]>[0];
14
15
  type Mapping<Request extends AnyPgTable, Series extends AnyPgTable, Generation extends AnyPgTable, Continuation extends AnyPgTable, RateScope extends AnyPgTable, AbuseEvent extends AnyPgTable, FailureEvent extends AnyPgTable, Command extends AnyPgTable, Subject extends AnyPgTable, Identifier extends AnyPgTable, Credential extends AnyPgTable, NativeSubjectId> = ProofPersistenceMapping<Request, Series, Generation, Continuation, RateScope, AbuseEvent, FailureEvent, Command, Subject, Identifier, Credential, NativeSubjectId>;
15
- export declare const makePgProofPersistenceServices: <Rq extends AnyPgTable, S extends AnyPgTable, G extends AnyPgTable, Cn extends AnyPgTable, Rs extends AnyPgTable, A extends AnyPgTable, F extends AnyPgTable, C extends AnyPgTable, Sub extends AnyPgTable, I extends AnyPgTable, Cr extends AnyPgTable, NativeId>(database: Database, mapping: Mapping<Rq, S, G, Cn, Rs, A, F, C, Sub, I, Cr, NativeId>) => Effect.Effect<{
16
+ export declare const makePgProofPersistenceServices: <Rq extends AnyPgTable, S extends AnyPgTable, G extends AnyPgTable, Cn extends AnyPgTable, Rs extends AnyPgTable, A extends AnyPgTable, F extends AnyPgTable, C extends AnyPgTable, Sub extends AnyPgTable, I extends AnyPgTable, Cr extends AnyPgTable, NativeId>(mapping: Mapping<Rq, S, G, Cn, Rs, A, F, C, Sub, I, Cr, NativeId>) => Effect.Effect<{
16
17
  proofPersistence: {
17
18
  readonly issue: <A_1>(input: {
18
19
  readonly record: import("@yielded/auth/Proofs").ProofRecord;
@@ -62,7 +63,7 @@ export declare const makePgProofPersistenceServices: <Rq extends AnyPgTable, S e
62
63
  readonly limit: number;
63
64
  }, prepare: import("@yielded/auth/Proofs").PrepareProofCommit<import("@yielded/auth/Proofs").ProofCleanupResult, A_1>) => Effect.Effect<import("@yielded/auth/Hooks").PreparedCommit<A_1>, ProofUnavailable>;
64
65
  };
65
- }, never, LifecycleHooks>;
66
+ }, never, Database$1 | LifecycleHooks>;
66
67
  export declare function coordinatePgProofPersistence<D extends Database, Rq extends AnyPgTable, S extends AnyPgTable, G extends AnyPgTable, Cn extends AnyPgTable, Rs extends AnyPgTable, Aev extends AnyPgTable, F extends AnyPgTable, C extends AnyPgTable, Sub extends AnyPgTable, I extends AnyPgTable, Cr extends AnyPgTable, NativeId, A, E, R, DatabaseError, DatabaseRequirements>(acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>, options: {
67
68
  readonly mapping: Mapping<Rq, S, G, Cn, Rs, Aev, F, C, Sub, I, Cr, NativeId>;
68
69
  readonly transaction?: never;
@@ -1,16 +1,20 @@
1
+ import { acquireTransactionService, transactionService } from "./standalone-guard.mjs";
2
+ import { CurrentProofSql } from "./proof-sql.mjs";
1
3
  import { coordinateTargetProofPersistence, makeTargetProofPersistenceServices, sqlClientProofStandaloneGuard } from "./proof-target.mjs";
4
+ import { nativeDatabase } from "./native-database.mjs";
5
+ import { Database } from "./pg-database.mjs";
2
6
  import { Context, Effect } from "effect";
3
7
  import { ProofPersistence } from "@yielded/auth/Proofs";
4
8
  //#region src/drizzle/pg-proofs.ts
5
- const configuration = (database) => ({
9
+ const configuration = (service) => ({
6
10
  mode: "interactive",
7
11
  locking: true,
8
- standaloneGuard: sqlClientProofStandaloneGuard(database),
12
+ standaloneGuard: sqlClientProofStandaloneGuard(service),
9
13
  insertIfAbsent: (query) => query.onConflictDoNothing()
10
14
  });
11
- const makePgProofPersistenceServices = (database, mapping) => makeTargetProofPersistenceServices(database, mapping, configuration(database));
15
+ const makePgProofPersistenceServices = (mapping) => Effect.flatMap(Effect.map(acquireTransactionService(Database), configuration), (configuration) => makeTargetProofPersistenceServices(mapping, configuration)).pipe(Effect.provideServiceEffect(CurrentProofSql, nativeDatabase(Database)));
12
16
  function coordinatePgProofPersistence(acquire, options, body) {
13
- return Effect.flatMap(acquire, (database) => coordinateTargetProofPersistence(database, options.mapping, configuration(database), (transaction, services) => {
17
+ return Effect.flatMap(acquire, (database) => coordinateTargetProofPersistence(database, options.mapping, configuration(transactionService(database)), (transaction, services) => {
14
18
  const provided = Context.make(ProofPersistence, services.proofPersistence);
15
19
  const work = Effect.provideContext(body, provided);
16
20
  return options.transaction === void 0 ? work : Effect.provideService(work, options.transaction, options.transaction.of(transaction));
@@ -1 +1 @@
1
- {"version":3,"file":"pg-proofs.mjs","names":[],"sources":["../../src/drizzle/pg-proofs.ts"],"sourcesContent":["import type { LifecycleHooks, HookConfigurationError } from \"@yielded/auth/Hooks\";\nimport { type ProofUnavailable, ProofPersistence } from \"@yielded/auth/Proofs\";\nimport type { AnyRelations } from \"drizzle-orm\";\nimport type { EffectPgDatabase as PgliteDatabase } from \"drizzle-orm/effect-pglite\";\nimport type { EffectPgDatabase as PostgresDatabase } from \"drizzle-orm/effect-postgres\";\nimport type { AnyPgTable } from \"drizzle-orm/pg-core\";\nimport { Effect, Context } from \"effect\";\nimport type { SqlError } from \"effect/sql/SqlError\";\n\nimport type { ProofPersistenceMapping } from \"./proof-model\";\nimport type { ProofSqlQuery } from \"./proof-sql\";\nimport {\n coordinateTargetProofPersistence,\n makeTargetProofPersistenceServices,\n sqlClientProofStandaloneGuard,\n} from \"./proof-target\";\nimport type { SuppliedService } from \"./SuppliedService\";\n\ntype Database = PostgresDatabase<AnyRelations> | PgliteDatabase<AnyRelations>;\ntype TransactionOf<D extends Database> = Parameters<Parameters<D[\"transaction\"]>[0]>[0];\ntype Mapping<\n Request extends AnyPgTable,\n Series extends AnyPgTable,\n Generation extends AnyPgTable,\n Continuation extends AnyPgTable,\n RateScope extends AnyPgTable,\n AbuseEvent extends AnyPgTable,\n FailureEvent extends AnyPgTable,\n Command extends AnyPgTable,\n Subject extends AnyPgTable,\n Identifier extends AnyPgTable,\n Credential extends AnyPgTable,\n NativeSubjectId,\n> = ProofPersistenceMapping<\n Request,\n Series,\n Generation,\n Continuation,\n RateScope,\n AbuseEvent,\n FailureEvent,\n Command,\n Subject,\n Identifier,\n Credential,\n NativeSubjectId\n>;\n\nconst configuration = (database: Database) => ({\n mode: \"interactive\" as const,\n locking: true,\n standaloneGuard: sqlClientProofStandaloneGuard(database),\n insertIfAbsent: (query: ProofSqlQuery) => query.onConflictDoNothing(),\n});\n\nexport const makePgProofPersistenceServices = <\n Rq extends AnyPgTable,\n S extends AnyPgTable,\n G extends AnyPgTable,\n Cn extends AnyPgTable,\n Rs extends AnyPgTable,\n A extends AnyPgTable,\n F extends AnyPgTable,\n C extends AnyPgTable,\n Sub extends AnyPgTable,\n I extends AnyPgTable,\n Cr extends AnyPgTable,\n NativeId,\n>(\n database: Database,\n mapping: Mapping<Rq, S, G, Cn, Rs, A, F, C, Sub, I, Cr, NativeId>,\n) => makeTargetProofPersistenceServices(database, mapping, configuration(database));\n\nexport function coordinatePgProofPersistence<\n D extends Database,\n Rq extends AnyPgTable,\n S extends AnyPgTable,\n G extends AnyPgTable,\n Cn extends AnyPgTable,\n Rs extends AnyPgTable,\n Aev extends AnyPgTable,\n F extends AnyPgTable,\n C extends AnyPgTable,\n Sub extends AnyPgTable,\n I extends AnyPgTable,\n Cr extends AnyPgTable,\n NativeId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: Mapping<Rq, S, G, Cn, Rs, Aev, F, C, Sub, I, Cr, NativeId>;\n readonly transaction?: never;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | ProofUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, ProofPersistence> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinatePgProofPersistence<\n D extends Database,\n Rq extends AnyPgTable,\n S extends AnyPgTable,\n G extends AnyPgTable,\n Cn extends AnyPgTable,\n Rs extends AnyPgTable,\n Aev extends AnyPgTable,\n F extends AnyPgTable,\n C extends AnyPgTable,\n Sub extends AnyPgTable,\n I extends AnyPgTable,\n Cr extends AnyPgTable,\n NativeId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: Mapping<Rq, S, G, Cn, Rs, Aev, F, C, Sub, I, Cr, NativeId>;\n readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | ProofUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, ProofPersistence | TxId> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinatePgProofPersistence<\n D extends Database,\n Rq extends AnyPgTable,\n S extends AnyPgTable,\n G extends AnyPgTable,\n Cn extends AnyPgTable,\n Rs extends AnyPgTable,\n Aev extends AnyPgTable,\n F extends AnyPgTable,\n C extends AnyPgTable,\n Sub extends AnyPgTable,\n I extends AnyPgTable,\n Cr extends AnyPgTable,\n NativeId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: Mapping<Rq, S, G, Cn, Rs, Aev, F, C, Sub, I, Cr, NativeId>;\n readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | ProofUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, ProofPersistence> | LifecycleHooks | DatabaseRequirements\n> {\n return Effect.flatMap(acquire, (database) =>\n coordinateTargetProofPersistence<TransactionOf<D>, A, E, Exclude<R, ProofPersistence>>(\n database,\n options.mapping,\n configuration(database),\n (\n transaction: TransactionOf<D>,\n services: { readonly proofPersistence: ProofPersistence[\"Service\"] },\n ) => {\n const provided = Context.make(ProofPersistence, services.proofPersistence);\n const work = Effect.provideContext(body, provided);\n\n return options.transaction === undefined\n ? work\n : Effect.provideService(work, options.transaction, options.transaction.of(transaction));\n },\n ),\n );\n}\n"],"mappings":";;;;AAgDA,MAAM,iBAAiB,cAAwB;CAC7C,MAAM;CACN,SAAS;CACT,iBAAiB,8BAA8B,QAAQ;CACvD,iBAAiB,UAAyB,MAAM,oBAAoB;AACtE;AAEA,MAAa,kCAcX,UACA,YACG,mCAAmC,UAAU,SAAS,cAAc,QAAQ,CAAC;AAoElF,SAAgB,6BAsBd,SACA,SAIA,MAKA;CACA,OAAO,OAAO,QAAQ,UAAU,aAC9B,iCACE,UACA,QAAQ,SACR,cAAc,QAAQ,IAEpB,aACA,aACG;EACH,MAAM,WAAW,QAAQ,KAAK,kBAAkB,SAAS,gBAAgB;EACzE,MAAM,OAAO,OAAO,eAAe,MAAM,QAAQ;EAEjD,OAAO,QAAQ,gBAAgB,KAAA,IAC3B,OACA,OAAO,eAAe,MAAM,QAAQ,aAAa,QAAQ,YAAY,GAAG,WAAW,CAAC;CAC1F,CACF,CACF;AACF"}
1
+ {"version":3,"file":"pg-proofs.mjs","names":["DatabaseService"],"sources":["../../src/drizzle/pg-proofs.ts"],"sourcesContent":["import type { LifecycleHooks, HookConfigurationError } from \"@yielded/auth/Hooks\";\nimport { type ProofUnavailable, ProofPersistence } from \"@yielded/auth/Proofs\";\nimport type { AnyRelations } from \"drizzle-orm\";\nimport type { EffectPgDatabase as PgliteDatabase } from \"drizzle-orm/effect-pglite\";\nimport type { EffectPgDatabase as PostgresDatabase } from \"drizzle-orm/effect-postgres\";\nimport type { AnyPgTable } from \"drizzle-orm/pg-core\";\nimport { Effect, Context } from \"effect\";\nimport type { SqlError } from \"effect/sql/SqlError\";\n\nimport { nativeDatabase } from \"./native-database\";\nimport { Database as DatabaseService } from \"./pg-database\";\nimport type { ProofPersistenceMapping } from \"./proof-model\";\nimport { CurrentProofSql } from \"./proof-sql\";\nimport type { ProofSqlQuery } from \"./proof-sql\";\nimport {\n coordinateTargetProofPersistence,\n makeTargetProofPersistenceServices,\n sqlClientProofStandaloneGuard,\n} from \"./proof-target\";\nimport {\n type TransactionService,\n acquireTransactionService,\n transactionService,\n} from \"./standalone-guard\";\nimport type { SuppliedService } from \"./SuppliedService\";\n\ntype Database = PostgresDatabase<AnyRelations> | PgliteDatabase<AnyRelations>;\ntype TransactionOf<D extends Database> = Parameters<Parameters<D[\"transaction\"]>[0]>[0];\ntype Mapping<\n Request extends AnyPgTable,\n Series extends AnyPgTable,\n Generation extends AnyPgTable,\n Continuation extends AnyPgTable,\n RateScope extends AnyPgTable,\n AbuseEvent extends AnyPgTable,\n FailureEvent extends AnyPgTable,\n Command extends AnyPgTable,\n Subject extends AnyPgTable,\n Identifier extends AnyPgTable,\n Credential extends AnyPgTable,\n NativeSubjectId,\n> = ProofPersistenceMapping<\n Request,\n Series,\n Generation,\n Continuation,\n RateScope,\n AbuseEvent,\n FailureEvent,\n Command,\n Subject,\n Identifier,\n Credential,\n NativeSubjectId\n>;\n\nconst configuration = (service: TransactionService | undefined) => ({\n mode: \"interactive\" as const,\n locking: true,\n standaloneGuard: sqlClientProofStandaloneGuard(service),\n insertIfAbsent: (query: ProofSqlQuery) => query.onConflictDoNothing(),\n});\n\nexport const makePgProofPersistenceServices = <\n Rq extends AnyPgTable,\n S extends AnyPgTable,\n G extends AnyPgTable,\n Cn extends AnyPgTable,\n Rs extends AnyPgTable,\n A extends AnyPgTable,\n F extends AnyPgTable,\n C extends AnyPgTable,\n Sub extends AnyPgTable,\n I extends AnyPgTable,\n Cr extends AnyPgTable,\n NativeId,\n>(\n mapping: Mapping<Rq, S, G, Cn, Rs, A, F, C, Sub, I, Cr, NativeId>,\n) =>\n Effect.flatMap(\n Effect.map(acquireTransactionService(DatabaseService), configuration),\n (configuration) => makeTargetProofPersistenceServices(mapping, configuration),\n ).pipe(Effect.provideServiceEffect(CurrentProofSql, nativeDatabase(DatabaseService)));\n\nexport function coordinatePgProofPersistence<\n D extends Database,\n Rq extends AnyPgTable,\n S extends AnyPgTable,\n G extends AnyPgTable,\n Cn extends AnyPgTable,\n Rs extends AnyPgTable,\n Aev extends AnyPgTable,\n F extends AnyPgTable,\n C extends AnyPgTable,\n Sub extends AnyPgTable,\n I extends AnyPgTable,\n Cr extends AnyPgTable,\n NativeId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: Mapping<Rq, S, G, Cn, Rs, Aev, F, C, Sub, I, Cr, NativeId>;\n readonly transaction?: never;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | ProofUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, ProofPersistence> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinatePgProofPersistence<\n D extends Database,\n Rq extends AnyPgTable,\n S extends AnyPgTable,\n G extends AnyPgTable,\n Cn extends AnyPgTable,\n Rs extends AnyPgTable,\n Aev extends AnyPgTable,\n F extends AnyPgTable,\n C extends AnyPgTable,\n Sub extends AnyPgTable,\n I extends AnyPgTable,\n Cr extends AnyPgTable,\n NativeId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: Mapping<Rq, S, G, Cn, Rs, Aev, F, C, Sub, I, Cr, NativeId>;\n readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | ProofUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, ProofPersistence | TxId> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinatePgProofPersistence<\n D extends Database,\n Rq extends AnyPgTable,\n S extends AnyPgTable,\n G extends AnyPgTable,\n Cn extends AnyPgTable,\n Rs extends AnyPgTable,\n Aev extends AnyPgTable,\n F extends AnyPgTable,\n C extends AnyPgTable,\n Sub extends AnyPgTable,\n I extends AnyPgTable,\n Cr extends AnyPgTable,\n NativeId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: Mapping<Rq, S, G, Cn, Rs, Aev, F, C, Sub, I, Cr, NativeId>;\n readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | ProofUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, ProofPersistence> | LifecycleHooks | DatabaseRequirements\n> {\n return Effect.flatMap(acquire, (database) =>\n coordinateTargetProofPersistence<TransactionOf<D>, A, E, Exclude<R, ProofPersistence>>(\n database,\n options.mapping,\n configuration(transactionService(database)),\n (\n transaction: TransactionOf<D>,\n services: { readonly proofPersistence: ProofPersistence[\"Service\"] },\n ) => {\n const provided = Context.make(ProofPersistence, services.proofPersistence);\n const work = Effect.provideContext(body, provided);\n\n return options.transaction === undefined\n ? work\n : Effect.provideService(work, options.transaction, options.transaction.of(transaction));\n },\n ),\n );\n}\n"],"mappings":";;;;;;;;AAwDA,MAAM,iBAAiB,aAA6C;CAClE,MAAM;CACN,SAAS;CACT,iBAAiB,8BAA8B,OAAO;CACtD,iBAAiB,UAAyB,MAAM,oBAAoB;AACtE;AAEA,MAAa,kCAcX,YAEA,OAAO,QACL,OAAO,IAAI,0BAA0BA,QAAe,GAAG,aAAa,IACnE,kBAAkB,mCAAmC,SAAS,aAAa,CAC9E,CAAC,CAAC,KAAK,OAAO,qBAAqB,iBAAiB,eAAeA,QAAe,CAAC,CAAC;AAoEtF,SAAgB,6BAsBd,SACA,SAIA,MAKA;CACA,OAAO,OAAO,QAAQ,UAAU,aAC9B,iCACE,UACA,QAAQ,SACR,cAAc,mBAAmB,QAAQ,CAAC,IAExC,aACA,aACG;EACH,MAAM,WAAW,QAAQ,KAAK,kBAAkB,SAAS,gBAAgB;EACzE,MAAM,OAAO,OAAO,eAAe,MAAM,QAAQ;EAEjD,OAAO,QAAQ,gBAAgB,KAAA,IAC3B,OACA,OAAO,eAAe,MAAM,QAAQ,aAAa,QAAQ,YAAY,GAAG,WAAW,CAAC;CAC1F,CACF,CACF;AACF"}
@@ -1,6 +1,7 @@
1
1
  import { AuthenticationAuthorityMapping, PendingAuthenticationMapping, SignedSessionValidityMapping, StatefulSessionMapping } from "./session-model.mjs";
2
2
  import { SessionStepUpMapping } from "./step-up-model.mjs";
3
3
  import { SuppliedService } from "./SuppliedService.mjs";
4
+ import { Database as Database$1 } from "./pg-database.mjs";
4
5
  import { AnyRelations } from "drizzle-orm";
5
6
  import { Context, Effect } from "effect";
6
7
  import { HookConfigurationError, LifecycleHooks } from "@yielded/auth/Hooks";
@@ -12,7 +13,7 @@ import { SqlError } from "effect/sql/SqlError";
12
13
  //#region src/drizzle/pg-sessions.d.ts
13
14
  type Database = EffectPgDatabase$1<AnyRelations> | EffectPgDatabase<AnyRelations>;
14
15
  type TransactionOf<D extends Database> = Parameters<Parameters<D["transaction"]>[0]>[0];
15
- export declare const makePgAuthenticationAuthorityServices: <Claims, Subject extends AnyPgTable, Credential extends AnyPgTable, Flow extends AnyPgTable, Pending extends AnyPgTable, NativeSubjectId>(database: Database, mapping: AuthenticationAuthorityMapping<Claims, Subject, Credential, Flow, Pending, NativeSubjectId>) => Effect.Effect<{
16
+ export declare const makePgAuthenticationAuthorityServices: <Claims, Subject extends AnyPgTable, Credential extends AnyPgTable, Flow extends AnyPgTable, Pending extends AnyPgTable, NativeSubjectId>(mapping: AuthenticationAuthorityMapping<Claims, Subject, Credential, Flow, Pending, NativeSubjectId>) => Effect.Effect<{
16
17
  authenticationAuthority: {
17
18
  readonly capture: (subjectId: import("@yielded/auth/Schema").SubjectId, credentialIds: ReadonlyArray<string>) => Effect.Effect<import("@yielded/auth/Sessions").AuthenticationRevision, import("@yielded/auth/Sessions").StaleAuthentication | SessionUnavailable>;
18
19
  readonly requirements: (evidence: import("@yielded/auth/Sessions").AuthenticationEvidence) => Effect.Effect<import("@yielded/auth/Sessions").AuthenticationRequirement, import("@yielded/auth/Sessions").StaleAuthentication | SessionUnavailable>;
@@ -24,17 +25,17 @@ export declare const makePgAuthenticationAuthorityServices: <Claims, Subject ext
24
25
  readonly pending?: import("@yielded/auth/Sessions").PendingConsumption;
25
26
  }, prepare: import("@yielded/auth/Sessions").PrepareSessionCommit<void, A>) => Effect.Effect<import("@yielded/auth/Hooks").PreparedCommit<A>, import("@yielded/auth/Sessions").StaleAuthentication | import("@yielded/auth/Sessions").PendingAuthenticationInvalid | SessionUnavailable>;
26
27
  };
27
- }, never, LifecycleHooks>;
28
- export declare const makePgPendingAuthenticationServices: <Claims, Subject extends AnyPgTable, Credential extends AnyPgTable, Pending extends AnyPgTable, Flow extends AnyPgTable, NativeSubjectId>(database: Database, mapping: PendingAuthenticationMapping<Claims, Subject, Credential, Pending, Flow, NativeSubjectId>) => Effect.Effect<{
28
+ }, never, Database$1 | LifecycleHooks>;
29
+ export declare const makePgPendingAuthenticationServices: <Claims, Subject extends AnyPgTable, Credential extends AnyPgTable, Pending extends AnyPgTable, Flow extends AnyPgTable, NativeSubjectId>(mapping: PendingAuthenticationMapping<Claims, Subject, Credential, Pending, Flow, NativeSubjectId>) => Effect.Effect<{
29
30
  pendingAuthentication: PendingAuthentication<Claims>;
30
- }, never, LifecycleHooks>;
31
- export declare const makePgStatefulSessionServices: <Claims, Subject extends AnyPgTable, Credential extends AnyPgTable, Session extends AnyPgTable, Flow extends AnyPgTable, Pending extends AnyPgTable, NativeSubjectId, NativeSessionId>(database: Database, mapping: StatefulSessionMapping<Claims, Subject, Credential, Session, Flow, Pending, NativeSubjectId, NativeSessionId>) => Effect.Effect<{
31
+ }, never, Database$1 | LifecycleHooks>;
32
+ export declare const makePgStatefulSessionServices: <Claims, Subject extends AnyPgTable, Credential extends AnyPgTable, Session extends AnyPgTable, Flow extends AnyPgTable, Pending extends AnyPgTable, NativeSubjectId, NativeSessionId>(mapping: StatefulSessionMapping<Claims, Subject, Credential, Session, Flow, Pending, NativeSubjectId, NativeSessionId>) => Effect.Effect<{
32
33
  readonly statefulSessionPersistence: StatefulSessionPersistence<Claims>;
33
34
  readonly sessionRepository: SessionRepository;
34
- }, never, LifecycleHooks>;
35
- export declare const makePgSignedSessionValidityServices: <Subject extends AnyPgTable, Tombstone extends AnyPgTable, NativeSubjectId, NativeSessionId>(database: Database, mapping: SignedSessionValidityMapping<Subject, Tombstone, NativeSubjectId, NativeSessionId>) => Effect.Effect<{
35
+ }, never, Database$1 | LifecycleHooks>;
36
+ export declare const makePgSignedSessionValidityServices: <Subject extends AnyPgTable, Tombstone extends AnyPgTable, NativeSubjectId, NativeSessionId>(mapping: SignedSessionValidityMapping<Subject, Tombstone, NativeSubjectId, NativeSessionId>) => Effect.Effect<{
36
37
  signedSessionValidity: SignedSessionValidity;
37
- }, never, LifecycleHooks>;
38
+ }, never, Database$1 | LifecycleHooks>;
38
39
  export declare function coordinatePgAuthenticationAuthority<Claims, D extends Database, S extends AnyPgTable, C extends AnyPgTable, F extends AnyPgTable, P extends AnyPgTable, NativeId, A, E, R, DatabaseError, DatabaseRequirements>(acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>, options: {
39
40
  readonly mapping: AuthenticationAuthorityMapping<Claims, S, C, F, P, NativeId>;
40
41
  readonly transaction?: never;
@@ -75,9 +76,9 @@ export declare function coordinatePgSignedSessionValidity<TargetId, D extends Da
75
76
  readonly target: SuppliedService<TargetId, SignedSessionValidity>;
76
77
  readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;
77
78
  }, body: Effect.Effect<A, E, R>): Effect.Effect<A, E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError, Exclude<R, TargetId | TxId> | LifecycleHooks | DatabaseRequirements>;
78
- export declare const makePgSessionStepUpServices: <Claims, Id, S extends AnyPgTable, C extends AnyPgTable, I extends AnyPgTable, Session extends AnyPgTable, T extends AnyPgTable, NativeId, NativeSessionId>(database: Database, mapping: SessionStepUpMapping<NoInfer<Claims>, S, C, I, Session, T, NativeId, NativeSessionId>, target: Context.Service<Id, SessionStepUpPersistence<Claims>>) => Effect.Effect<{
79
+ export declare const makePgSessionStepUpServices: <Claims, Id, S extends AnyPgTable, C extends AnyPgTable, I extends AnyPgTable, Session extends AnyPgTable, T extends AnyPgTable, NativeId, NativeSessionId>(mapping: SessionStepUpMapping<NoInfer<Claims>, S, C, I, Session, T, NativeId, NativeSessionId>, target: Context.Service<Id, SessionStepUpPersistence<Claims>>) => Effect.Effect<{
79
80
  sessionStepUpPersistence: SessionStepUpPersistence<Claims>;
80
- }, never, LifecycleHooks>;
81
+ }, never, Database$1 | LifecycleHooks>;
81
82
  export declare function coordinatePgSessionStepUp<Claims, Id, S extends AnyPgTable, C extends AnyPgTable, I extends AnyPgTable, Session extends AnyPgTable, T extends AnyPgTable, NativeId, NativeSessionId, D extends Database, A, E, R, DatabaseError, DatabaseRequirements>(acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>, options: {
82
83
  readonly mapping: SessionStepUpMapping<NoInfer<Claims>, S, C, I, Session, T, NativeId, NativeSessionId>;
83
84
  readonly target: SuppliedService<Id, SessionStepUpPersistence<Claims>>;
@@ -1,47 +1,51 @@
1
+ import { CurrentSessionSql } from "./session-sql.mjs";
2
+ import { acquireTransactionService, transactionService } from "./standalone-guard.mjs";
1
3
  import { coordinateTargetAuthenticationAuthority, coordinateTargetPendingAuthentication, coordinateTargetSessionStepUp, coordinateTargetSignedSessionValidity, coordinateTargetStatefulSessions, makeTargetAuthenticationAuthorityServices, makeTargetPendingAuthenticationServices, makeTargetSessionStepUpServices, makeTargetSignedSessionValidityServices, makeTargetStatefulSessionServices, sqlClientSessionStandaloneGuard } from "./session-target.mjs";
4
+ import { nativeDatabase } from "./native-database.mjs";
5
+ import { Database } from "./pg-database.mjs";
2
6
  import { Context, Effect } from "effect";
3
7
  import { AuthenticationAuthority } from "@yielded/auth/Sessions";
4
8
  //#region src/drizzle/pg-sessions.ts
5
- const configuration = (database) => ({
9
+ const configuration = (service) => ({
6
10
  mode: "interactive",
7
11
  locking: true,
8
- standaloneGuard: sqlClientSessionStandaloneGuard(database)
12
+ standaloneGuard: sqlClientSessionStandaloneGuard(service)
9
13
  });
10
- const makePgAuthenticationAuthorityServices = (database, mapping) => makeTargetAuthenticationAuthorityServices(database, mapping, configuration(database));
11
- const makePgPendingAuthenticationServices = (database, mapping) => makeTargetPendingAuthenticationServices(database, mapping, configuration(database));
12
- const makePgStatefulSessionServices = (database, mapping) => makeTargetStatefulSessionServices(database, mapping, configuration(database));
13
- const makePgSignedSessionValidityServices = (database, mapping) => makeTargetSignedSessionValidityServices(database, mapping, configuration(database));
14
+ const makePgAuthenticationAuthorityServices = (mapping) => Effect.flatMap(Effect.map(acquireTransactionService(Database), configuration), (configuration) => makeTargetAuthenticationAuthorityServices(mapping, configuration)).pipe(Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(Database)));
15
+ const makePgPendingAuthenticationServices = (mapping) => Effect.flatMap(Effect.map(acquireTransactionService(Database), configuration), (configuration) => makeTargetPendingAuthenticationServices(mapping, configuration)).pipe(Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(Database)));
16
+ const makePgStatefulSessionServices = (mapping) => Effect.flatMap(Effect.map(acquireTransactionService(Database), configuration), (configuration) => makeTargetStatefulSessionServices(mapping, configuration)).pipe(Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(Database)));
17
+ const makePgSignedSessionValidityServices = (mapping) => Effect.flatMap(Effect.map(acquireTransactionService(Database), configuration), (configuration) => makeTargetSignedSessionValidityServices(mapping, configuration)).pipe(Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(Database)));
14
18
  function coordinatePgAuthenticationAuthority(acquire, options, body) {
15
- return Effect.flatMap(acquire, (database) => coordinateTargetAuthenticationAuthority(database, options.mapping, configuration(database), (transaction, services) => {
19
+ return Effect.flatMap(acquire, (database) => coordinateTargetAuthenticationAuthority(database, options.mapping, configuration(transactionService(database)), (transaction, services) => {
16
20
  const provided = Context.make(AuthenticationAuthority, services.authenticationAuthority);
17
21
  const work = Effect.provideContext(body, provided);
18
22
  return options.transaction === void 0 ? work : Effect.provideService(work, options.transaction, options.transaction.of(transaction));
19
23
  }));
20
24
  }
21
25
  function coordinatePgPendingAuthentication(acquire, options, body) {
22
- return Effect.flatMap(acquire, (database) => coordinateTargetPendingAuthentication(database, options.mapping, configuration(database), (transaction, services) => {
26
+ return Effect.flatMap(acquire, (database) => coordinateTargetPendingAuthentication(database, options.mapping, configuration(transactionService(database)), (transaction, services) => {
23
27
  const provided = Context.make(options.target, services.pendingAuthentication);
24
28
  const work = Effect.provideContext(body, provided);
25
29
  return options.transaction === void 0 ? work : Effect.provideService(work, options.transaction, options.transaction.of(transaction));
26
30
  }));
27
31
  }
28
32
  function coordinatePgStatefulSessions(acquire, options, body) {
29
- return Effect.flatMap(acquire, (database) => coordinateTargetStatefulSessions(database, options.mapping, configuration(database), (transaction, services) => {
33
+ return Effect.flatMap(acquire, (database) => coordinateTargetStatefulSessions(database, options.mapping, configuration(transactionService(database)), (transaction, services) => {
30
34
  const provided = Context.make(options.persistence, services.statefulSessionPersistence).pipe(Context.add(options.repository, services.sessionRepository));
31
35
  const work = Effect.provideContext(body, provided);
32
36
  return options.transaction === void 0 ? work : Effect.provideService(work, options.transaction, options.transaction.of(transaction));
33
37
  }));
34
38
  }
35
39
  function coordinatePgSignedSessionValidity(acquire, options, body) {
36
- return Effect.flatMap(acquire, (database) => coordinateTargetSignedSessionValidity(database, options.mapping, configuration(database), (transaction, services) => {
40
+ return Effect.flatMap(acquire, (database) => coordinateTargetSignedSessionValidity(database, options.mapping, configuration(transactionService(database)), (transaction, services) => {
37
41
  const provided = Context.make(options.target, services.signedSessionValidity);
38
42
  const work = Effect.provideContext(body, provided);
39
43
  return options.transaction === void 0 ? work : Effect.provideService(work, options.transaction, options.transaction.of(transaction));
40
44
  }));
41
45
  }
42
- const makePgSessionStepUpServices = (database, mapping, target) => makeTargetSessionStepUpServices(database, mapping, target, configuration(database));
46
+ const makePgSessionStepUpServices = (mapping, target) => Effect.flatMap(Effect.map(acquireTransactionService(Database), configuration), (configuration) => makeTargetSessionStepUpServices(mapping, target, configuration)).pipe(Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(Database)));
43
47
  function coordinatePgSessionStepUp(acquire, options, body) {
44
- return Effect.flatMap(acquire, (database) => coordinateTargetSessionStepUp(database, options.mapping, options.target, configuration(database), (transaction, services) => {
48
+ return Effect.flatMap(acquire, (database) => coordinateTargetSessionStepUp(database, options.mapping, options.target, configuration(transactionService(database)), (transaction, services) => {
45
49
  const provided = Context.make(options.target, services.sessionStepUpPersistence);
46
50
  const work = Effect.provideContext(body, provided);
47
51
  return options.transaction === void 0 ? work : Effect.provideService(work, options.transaction, options.transaction.of(transaction));
@@ -1 +1 @@
1
- {"version":3,"file":"pg-sessions.mjs","names":[],"sources":["../../src/drizzle/pg-sessions.ts"],"sourcesContent":["import type { LifecycleHooks, HookConfigurationError } from \"@yielded/auth/Hooks\";\nimport {\n AuthenticationAuthority,\n type SessionUnavailable,\n type PendingAuthentication,\n type SessionRepository,\n type SignedSessionValidity,\n type StatefulSessionPersistence,\n type SessionStepUpPersistence,\n} from \"@yielded/auth/Sessions\";\nimport type { AnyRelations } from \"drizzle-orm\";\nimport type { EffectPgDatabase as PgliteDatabase } from \"drizzle-orm/effect-pglite\";\nimport type { EffectPgDatabase as PostgresDatabase } from \"drizzle-orm/effect-postgres\";\nimport type { AnyPgTable } from \"drizzle-orm/pg-core\";\nimport { Effect, Context } from \"effect\";\nimport type { SqlError } from \"effect/sql/SqlError\";\n\nimport type {\n AuthenticationAuthorityMapping,\n PendingAuthenticationMapping,\n SignedSessionValidityMapping,\n StatefulSessionMapping,\n} from \"./session-model\";\nimport {\n coordinateTargetAuthenticationAuthority,\n coordinateTargetPendingAuthentication,\n coordinateTargetSignedSessionValidity,\n coordinateTargetStatefulSessions,\n makeTargetAuthenticationAuthorityServices,\n makeTargetPendingAuthenticationServices,\n makeTargetSignedSessionValidityServices,\n makeTargetStatefulSessionServices,\n sqlClientSessionStandaloneGuard,\n makeTargetSessionStepUpServices,\n coordinateTargetSessionStepUp,\n} from \"./session-target\";\nimport type { SuppliedService } from \"./SuppliedService\";\n\ntype Database = PostgresDatabase<AnyRelations> | PgliteDatabase<AnyRelations>;\ntype TransactionOf<D extends Database> = Parameters<Parameters<D[\"transaction\"]>[0]>[0];\n\nconst configuration = (database: Database) => ({\n mode: \"interactive\" as const,\n locking: true,\n standaloneGuard: sqlClientSessionStandaloneGuard(database),\n});\n\nexport const makePgAuthenticationAuthorityServices = <\n Claims,\n Subject extends AnyPgTable,\n Credential extends AnyPgTable,\n Flow extends AnyPgTable,\n Pending extends AnyPgTable,\n NativeSubjectId,\n>(\n database: Database,\n mapping: AuthenticationAuthorityMapping<\n Claims,\n Subject,\n Credential,\n Flow,\n Pending,\n NativeSubjectId\n >,\n) => makeTargetAuthenticationAuthorityServices<Claims>(database, mapping, configuration(database));\n\nexport const makePgPendingAuthenticationServices = <\n Claims,\n Subject extends AnyPgTable,\n Credential extends AnyPgTable,\n Pending extends AnyPgTable,\n Flow extends AnyPgTable,\n NativeSubjectId,\n>(\n database: Database,\n mapping: PendingAuthenticationMapping<\n Claims,\n Subject,\n Credential,\n Pending,\n Flow,\n NativeSubjectId\n >,\n) => makeTargetPendingAuthenticationServices<Claims>(database, mapping, configuration(database));\n\nexport const makePgStatefulSessionServices = <\n Claims,\n Subject extends AnyPgTable,\n Credential extends AnyPgTable,\n Session extends AnyPgTable,\n Flow extends AnyPgTable,\n Pending extends AnyPgTable,\n NativeSubjectId,\n NativeSessionId,\n>(\n database: Database,\n mapping: StatefulSessionMapping<\n Claims,\n Subject,\n Credential,\n Session,\n Flow,\n Pending,\n NativeSubjectId,\n NativeSessionId\n >,\n) => makeTargetStatefulSessionServices<Claims>(database, mapping, configuration(database));\n\nexport const makePgSignedSessionValidityServices = <\n Subject extends AnyPgTable,\n Tombstone extends AnyPgTable,\n NativeSubjectId,\n NativeSessionId,\n>(\n database: Database,\n mapping: SignedSessionValidityMapping<Subject, Tombstone, NativeSubjectId, NativeSessionId>,\n) => makeTargetSignedSessionValidityServices(database, mapping, configuration(database));\n\nexport function coordinatePgAuthenticationAuthority<\n Claims,\n D extends Database,\n S extends AnyPgTable,\n C extends AnyPgTable,\n F extends AnyPgTable,\n P extends AnyPgTable,\n NativeId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: AuthenticationAuthorityMapping<Claims, S, C, F, P, NativeId>;\n readonly transaction?: never;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, AuthenticationAuthority> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinatePgAuthenticationAuthority<\n Claims,\n D extends Database,\n S extends AnyPgTable,\n C extends AnyPgTable,\n F extends AnyPgTable,\n P extends AnyPgTable,\n NativeId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: AuthenticationAuthorityMapping<Claims, S, C, F, P, NativeId>;\n readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, AuthenticationAuthority | TxId> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinatePgAuthenticationAuthority<\n Claims,\n D extends Database,\n S extends AnyPgTable,\n C extends AnyPgTable,\n F extends AnyPgTable,\n P extends AnyPgTable,\n NativeId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: AuthenticationAuthorityMapping<Claims, S, C, F, P, NativeId>;\n readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, AuthenticationAuthority> | LifecycleHooks | DatabaseRequirements\n> {\n return Effect.flatMap(acquire, (database) =>\n coordinateTargetAuthenticationAuthority<\n Claims,\n TransactionOf<D>,\n A,\n E,\n Exclude<R, AuthenticationAuthority>\n >(\n database,\n options.mapping,\n configuration(database),\n (\n transaction: TransactionOf<D>,\n services: { readonly authenticationAuthority: AuthenticationAuthority[\"Service\"] },\n ) => {\n const provided = Context.make(AuthenticationAuthority, services.authenticationAuthority);\n const work = Effect.provideContext(body, provided);\n\n return options.transaction === undefined\n ? work\n : Effect.provideService(work, options.transaction, options.transaction.of(transaction));\n },\n ),\n );\n}\n\nexport function coordinatePgPendingAuthentication<\n TargetId,\n Claims,\n D extends Database,\n S extends AnyPgTable,\n C extends AnyPgTable,\n P extends AnyPgTable,\n F extends AnyPgTable,\n NativeId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PendingAuthenticationMapping<NoInfer<Claims>, S, C, P, F, NativeId>;\n readonly target: SuppliedService<TargetId, PendingAuthentication<Claims>>;\n readonly transaction?: never;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, TargetId> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinatePgPendingAuthentication<\n TargetId,\n Claims,\n D extends Database,\n S extends AnyPgTable,\n C extends AnyPgTable,\n P extends AnyPgTable,\n F extends AnyPgTable,\n NativeId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PendingAuthenticationMapping<NoInfer<Claims>, S, C, P, F, NativeId>;\n readonly target: SuppliedService<TargetId, PendingAuthentication<Claims>>;\n readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, TargetId | TxId> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinatePgPendingAuthentication<\n TargetId,\n Claims,\n D extends Database,\n S extends AnyPgTable,\n C extends AnyPgTable,\n P extends AnyPgTable,\n F extends AnyPgTable,\n NativeId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PendingAuthenticationMapping<NoInfer<Claims>, S, C, P, F, NativeId>;\n readonly target: SuppliedService<TargetId, PendingAuthentication<Claims>>;\n readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, TargetId> | LifecycleHooks | DatabaseRequirements\n> {\n return Effect.flatMap(acquire, (database) =>\n coordinateTargetPendingAuthentication<Claims, TransactionOf<D>, A, E, Exclude<R, TargetId>>(\n database,\n options.mapping,\n configuration(database),\n (\n transaction: TransactionOf<D>,\n services: { readonly pendingAuthentication: PendingAuthentication<Claims> },\n ) => {\n const provided = Context.make(options.target, services.pendingAuthentication);\n const work = Effect.provideContext(body, provided);\n\n return options.transaction === undefined\n ? work\n : Effect.provideService(work, options.transaction, options.transaction.of(transaction));\n },\n ),\n );\n}\n\nexport function coordinatePgStatefulSessions<\n PersistenceId,\n RepositoryId,\n Claims,\n D extends Database,\n S extends AnyPgTable,\n C extends AnyPgTable,\n Session extends AnyPgTable,\n F extends AnyPgTable,\n P extends AnyPgTable,\n NativeId,\n NativeSessionId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: StatefulSessionMapping<\n NoInfer<Claims>,\n S,\n C,\n Session,\n F,\n P,\n NativeId,\n NativeSessionId\n >;\n readonly persistence: SuppliedService<PersistenceId, StatefulSessionPersistence<Claims>>;\n readonly repository: SuppliedService<RepositoryId, SessionRepository>;\n readonly transaction?: never;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, PersistenceId | RepositoryId> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinatePgStatefulSessions<\n PersistenceId,\n RepositoryId,\n Claims,\n D extends Database,\n S extends AnyPgTable,\n C extends AnyPgTable,\n Session extends AnyPgTable,\n F extends AnyPgTable,\n P extends AnyPgTable,\n NativeId,\n NativeSessionId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: StatefulSessionMapping<\n NoInfer<Claims>,\n S,\n C,\n Session,\n F,\n P,\n NativeId,\n NativeSessionId\n >;\n readonly persistence: SuppliedService<PersistenceId, StatefulSessionPersistence<Claims>>;\n readonly repository: SuppliedService<RepositoryId, SessionRepository>;\n readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, PersistenceId | RepositoryId | TxId> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinatePgStatefulSessions<\n PersistenceId,\n RepositoryId,\n Claims,\n D extends Database,\n S extends AnyPgTable,\n C extends AnyPgTable,\n Session extends AnyPgTable,\n F extends AnyPgTable,\n P extends AnyPgTable,\n NativeId,\n NativeSessionId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: StatefulSessionMapping<\n NoInfer<Claims>,\n S,\n C,\n Session,\n F,\n P,\n NativeId,\n NativeSessionId\n >;\n readonly persistence: SuppliedService<PersistenceId, StatefulSessionPersistence<Claims>>;\n readonly repository: SuppliedService<RepositoryId, SessionRepository>;\n readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, PersistenceId | RepositoryId> | LifecycleHooks | DatabaseRequirements\n> {\n return Effect.flatMap(acquire, (database) =>\n coordinateTargetStatefulSessions<\n Claims,\n TransactionOf<D>,\n A,\n E,\n Exclude<R, PersistenceId | RepositoryId>\n >(\n database,\n options.mapping,\n configuration(database),\n (\n transaction: TransactionOf<D>,\n services: {\n readonly statefulSessionPersistence: StatefulSessionPersistence<Claims>;\n readonly sessionRepository: SessionRepository;\n },\n ) => {\n const provided = Context.make(\n options.persistence,\n services.statefulSessionPersistence,\n ).pipe(Context.add(options.repository, services.sessionRepository));\n\n const work = Effect.provideContext(body, provided);\n\n return options.transaction === undefined\n ? work\n : Effect.provideService(work, options.transaction, options.transaction.of(transaction));\n },\n ),\n );\n}\n\nexport function coordinatePgSignedSessionValidity<\n TargetId,\n D extends Database,\n S extends AnyPgTable,\n T extends AnyPgTable,\n NativeId,\n NativeSessionId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: SignedSessionValidityMapping<S, T, NativeId, NativeSessionId>;\n readonly target: SuppliedService<TargetId, SignedSessionValidity>;\n readonly transaction?: never;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, TargetId> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinatePgSignedSessionValidity<\n TargetId,\n D extends Database,\n S extends AnyPgTable,\n T extends AnyPgTable,\n NativeId,\n NativeSessionId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: SignedSessionValidityMapping<S, T, NativeId, NativeSessionId>;\n readonly target: SuppliedService<TargetId, SignedSessionValidity>;\n readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, TargetId | TxId> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinatePgSignedSessionValidity<\n TargetId,\n D extends Database,\n S extends AnyPgTable,\n T extends AnyPgTable,\n NativeId,\n NativeSessionId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: SignedSessionValidityMapping<S, T, NativeId, NativeSessionId>;\n readonly target: SuppliedService<TargetId, SignedSessionValidity>;\n readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, TargetId> | LifecycleHooks | DatabaseRequirements\n> {\n return Effect.flatMap(acquire, (database) =>\n coordinateTargetSignedSessionValidity<TransactionOf<D>, A, E, Exclude<R, TargetId>>(\n database,\n options.mapping,\n configuration(database),\n (\n transaction: TransactionOf<D>,\n services: { readonly signedSessionValidity: SignedSessionValidity },\n ) => {\n const provided = Context.make(options.target, services.signedSessionValidity);\n const work = Effect.provideContext(body, provided);\n\n return options.transaction === undefined\n ? work\n : Effect.provideService(work, options.transaction, options.transaction.of(transaction));\n },\n ),\n );\n}\n\nimport type { SessionStepUpMapping } from \"./step-up-model\";\n\nexport const makePgSessionStepUpServices = <\n Claims,\n Id,\n S extends AnyPgTable,\n C extends AnyPgTable,\n I extends AnyPgTable,\n Session extends AnyPgTable,\n T extends AnyPgTable,\n NativeId,\n NativeSessionId,\n>(\n database: Database,\n mapping: SessionStepUpMapping<NoInfer<Claims>, S, C, I, Session, T, NativeId, NativeSessionId>,\n target: Context.Service<Id, SessionStepUpPersistence<Claims>>,\n) => makeTargetSessionStepUpServices(database, mapping, target, configuration(database));\n\nexport function coordinatePgSessionStepUp<\n Claims,\n Id,\n S extends AnyPgTable,\n C extends AnyPgTable,\n I extends AnyPgTable,\n Session extends AnyPgTable,\n T extends AnyPgTable,\n NativeId,\n NativeSessionId,\n D extends Database,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: SessionStepUpMapping<\n NoInfer<Claims>,\n S,\n C,\n I,\n Session,\n T,\n NativeId,\n NativeSessionId\n >;\n readonly target: SuppliedService<Id, SessionStepUpPersistence<Claims>>;\n readonly transaction?: never;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, Id> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinatePgSessionStepUp<\n Claims,\n Id,\n S extends AnyPgTable,\n C extends AnyPgTable,\n I extends AnyPgTable,\n Session extends AnyPgTable,\n T extends AnyPgTable,\n NativeId,\n NativeSessionId,\n D extends Database,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: SessionStepUpMapping<\n NoInfer<Claims>,\n S,\n C,\n I,\n Session,\n T,\n NativeId,\n NativeSessionId\n >;\n readonly target: SuppliedService<Id, SessionStepUpPersistence<Claims>>;\n readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, Id | TxId> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinatePgSessionStepUp<\n Claims,\n Id,\n S extends AnyPgTable,\n C extends AnyPgTable,\n I extends AnyPgTable,\n Session extends AnyPgTable,\n T extends AnyPgTable,\n NativeId,\n NativeSessionId,\n D extends Database,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: SessionStepUpMapping<\n NoInfer<Claims>,\n S,\n C,\n I,\n Session,\n T,\n NativeId,\n NativeSessionId\n >;\n readonly target: SuppliedService<Id, SessionStepUpPersistence<Claims>>;\n readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, Id> | LifecycleHooks | DatabaseRequirements\n> {\n return Effect.flatMap(acquire, (database) =>\n coordinateTargetSessionStepUp<Claims, Id, TransactionOf<D>, A, E, Exclude<R, Id>>(\n database,\n options.mapping,\n options.target,\n configuration(database),\n (\n transaction: TransactionOf<D>,\n services: { readonly sessionStepUpPersistence: SessionStepUpPersistence<Claims> },\n ) => {\n const provided = Context.make(options.target, services.sessionStepUpPersistence);\n const work = Effect.provideContext(body, provided);\n\n return options.transaction === undefined\n ? work\n : Effect.provideService(work, options.transaction, options.transaction.of(transaction));\n },\n ),\n );\n}\n"],"mappings":";;;;AAyCA,MAAM,iBAAiB,cAAwB;CAC7C,MAAM;CACN,SAAS;CACT,iBAAiB,gCAAgC,QAAQ;AAC3D;AAEA,MAAa,yCAQX,UACA,YAQG,0CAAkD,UAAU,SAAS,cAAc,QAAQ,CAAC;AAEjG,MAAa,uCAQX,UACA,YAQG,wCAAgD,UAAU,SAAS,cAAc,QAAQ,CAAC;AAE/F,MAAa,iCAUX,UACA,YAUG,kCAA0C,UAAU,SAAS,cAAc,QAAQ,CAAC;AAEzF,MAAa,uCAMX,UACA,YACG,wCAAwC,UAAU,SAAS,cAAc,QAAQ,CAAC;AAwDvF,SAAgB,oCAgBd,SACA,SAIA,MAKA;CACA,OAAO,OAAO,QAAQ,UAAU,aAC9B,wCAOE,UACA,QAAQ,SACR,cAAc,QAAQ,IAEpB,aACA,aACG;EACH,MAAM,WAAW,QAAQ,KAAK,yBAAyB,SAAS,uBAAuB;EACvF,MAAM,OAAO,OAAO,eAAe,MAAM,QAAQ;EAEjD,OAAO,QAAQ,gBAAgB,KAAA,IAC3B,OACA,OAAO,eAAe,MAAM,QAAQ,aAAa,QAAQ,YAAY,GAAG,WAAW,CAAC;CAC1F,CACF,CACF;AACF;AA4DA,SAAgB,kCAiBd,SACA,SAKA,MAKA;CACA,OAAO,OAAO,QAAQ,UAAU,aAC9B,sCACE,UACA,QAAQ,SACR,cAAc,QAAQ,IAEpB,aACA,aACG;EACH,MAAM,WAAW,QAAQ,KAAK,QAAQ,QAAQ,SAAS,qBAAqB;EAC5E,MAAM,OAAO,OAAO,eAAe,MAAM,QAAQ;EAEjD,OAAO,QAAQ,gBAAgB,KAAA,IAC3B,OACA,OAAO,eAAe,MAAM,QAAQ,aAAa,QAAQ,YAAY,GAAG,WAAW,CAAC;CAC1F,CACF,CACF;AACF;AAsFA,SAAgB,6BAoBd,SACA,SAeA,MAKA;CACA,OAAO,OAAO,QAAQ,UAAU,aAC9B,iCAOE,UACA,QAAQ,SACR,cAAc,QAAQ,IAEpB,aACA,aAIG;EACH,MAAM,WAAW,QAAQ,KACvB,QAAQ,aACR,SAAS,0BACX,CAAC,CAAC,KAAK,QAAQ,IAAI,QAAQ,YAAY,SAAS,iBAAiB,CAAC;EAElE,MAAM,OAAO,OAAO,eAAe,MAAM,QAAQ;EAEjD,OAAO,QAAQ,gBAAgB,KAAA,IAC3B,OACA,OAAO,eAAe,MAAM,QAAQ,aAAa,QAAQ,YAAY,GAAG,WAAW,CAAC;CAC1F,CACF,CACF;AACF;AAwDA,SAAgB,kCAed,SACA,SAKA,MAKA;CACA,OAAO,OAAO,QAAQ,UAAU,aAC9B,sCACE,UACA,QAAQ,SACR,cAAc,QAAQ,IAEpB,aACA,aACG;EACH,MAAM,WAAW,QAAQ,KAAK,QAAQ,QAAQ,SAAS,qBAAqB;EAC5E,MAAM,OAAO,OAAO,eAAe,MAAM,QAAQ;EAEjD,OAAO,QAAQ,gBAAgB,KAAA,IAC3B,OACA,OAAO,eAAe,MAAM,QAAQ,aAAa,QAAQ,YAAY,GAAG,WAAW,CAAC;CAC1F,CACF,CACF;AACF;AAIA,MAAa,+BAWX,UACA,SACA,WACG,gCAAgC,UAAU,SAAS,QAAQ,cAAc,QAAQ,CAAC;AAkFvF,SAAgB,0BAmBd,SACA,SAcA,MAKA;CACA,OAAO,OAAO,QAAQ,UAAU,aAC9B,8BACE,UACA,QAAQ,SACR,QAAQ,QACR,cAAc,QAAQ,IAEpB,aACA,aACG;EACH,MAAM,WAAW,QAAQ,KAAK,QAAQ,QAAQ,SAAS,wBAAwB;EAC/E,MAAM,OAAO,OAAO,eAAe,MAAM,QAAQ;EAEjD,OAAO,QAAQ,gBAAgB,KAAA,IAC3B,OACA,OAAO,eAAe,MAAM,QAAQ,aAAa,QAAQ,YAAY,GAAG,WAAW,CAAC;CAC1F,CACF,CACF;AACF"}
1
+ {"version":3,"file":"pg-sessions.mjs","names":["DatabaseService"],"sources":["../../src/drizzle/pg-sessions.ts"],"sourcesContent":["import type { LifecycleHooks, HookConfigurationError } from \"@yielded/auth/Hooks\";\nimport {\n AuthenticationAuthority,\n type SessionUnavailable,\n type PendingAuthentication,\n type SessionRepository,\n type SignedSessionValidity,\n type StatefulSessionPersistence,\n type SessionStepUpPersistence,\n} from \"@yielded/auth/Sessions\";\nimport type { AnyRelations } from \"drizzle-orm\";\nimport type { EffectPgDatabase as PgliteDatabase } from \"drizzle-orm/effect-pglite\";\nimport type { EffectPgDatabase as PostgresDatabase } from \"drizzle-orm/effect-postgres\";\nimport type { AnyPgTable } from \"drizzle-orm/pg-core\";\nimport { Effect, Context } from \"effect\";\nimport type { SqlError } from \"effect/sql/SqlError\";\n\nimport { nativeDatabase } from \"./native-database\";\nimport { Database as DatabaseService } from \"./pg-database\";\nimport type {\n AuthenticationAuthorityMapping,\n PendingAuthenticationMapping,\n SignedSessionValidityMapping,\n StatefulSessionMapping,\n} from \"./session-model\";\nimport { CurrentSessionSql } from \"./session-sql\";\nimport {\n coordinateTargetAuthenticationAuthority,\n coordinateTargetPendingAuthentication,\n coordinateTargetSignedSessionValidity,\n coordinateTargetStatefulSessions,\n makeTargetAuthenticationAuthorityServices,\n makeTargetPendingAuthenticationServices,\n makeTargetSignedSessionValidityServices,\n makeTargetStatefulSessionServices,\n sqlClientSessionStandaloneGuard,\n makeTargetSessionStepUpServices,\n coordinateTargetSessionStepUp,\n} from \"./session-target\";\nimport {\n type TransactionService,\n acquireTransactionService,\n transactionService,\n} from \"./standalone-guard\";\nimport type { SuppliedService } from \"./SuppliedService\";\n\ntype Database = PostgresDatabase<AnyRelations> | PgliteDatabase<AnyRelations>;\ntype TransactionOf<D extends Database> = Parameters<Parameters<D[\"transaction\"]>[0]>[0];\n\nconst configuration = (service: TransactionService | undefined) => ({\n mode: \"interactive\" as const,\n locking: true,\n standaloneGuard: sqlClientSessionStandaloneGuard(service),\n});\n\nexport const makePgAuthenticationAuthorityServices = <\n Claims,\n Subject extends AnyPgTable,\n Credential extends AnyPgTable,\n Flow extends AnyPgTable,\n Pending extends AnyPgTable,\n NativeSubjectId,\n>(\n mapping: AuthenticationAuthorityMapping<\n Claims,\n Subject,\n Credential,\n Flow,\n Pending,\n NativeSubjectId\n >,\n) =>\n Effect.flatMap(\n Effect.map(acquireTransactionService(DatabaseService), configuration),\n (configuration) => makeTargetAuthenticationAuthorityServices<Claims>(mapping, configuration),\n ).pipe(Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(DatabaseService)));\n\nexport const makePgPendingAuthenticationServices = <\n Claims,\n Subject extends AnyPgTable,\n Credential extends AnyPgTable,\n Pending extends AnyPgTable,\n Flow extends AnyPgTable,\n NativeSubjectId,\n>(\n mapping: PendingAuthenticationMapping<\n Claims,\n Subject,\n Credential,\n Pending,\n Flow,\n NativeSubjectId\n >,\n) =>\n Effect.flatMap(\n Effect.map(acquireTransactionService(DatabaseService), configuration),\n (configuration) => makeTargetPendingAuthenticationServices<Claims>(mapping, configuration),\n ).pipe(Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(DatabaseService)));\n\nexport const makePgStatefulSessionServices = <\n Claims,\n Subject extends AnyPgTable,\n Credential extends AnyPgTable,\n Session extends AnyPgTable,\n Flow extends AnyPgTable,\n Pending extends AnyPgTable,\n NativeSubjectId,\n NativeSessionId,\n>(\n mapping: StatefulSessionMapping<\n Claims,\n Subject,\n Credential,\n Session,\n Flow,\n Pending,\n NativeSubjectId,\n NativeSessionId\n >,\n) =>\n Effect.flatMap(\n Effect.map(acquireTransactionService(DatabaseService), configuration),\n (configuration) => makeTargetStatefulSessionServices<Claims>(mapping, configuration),\n ).pipe(Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(DatabaseService)));\n\nexport const makePgSignedSessionValidityServices = <\n Subject extends AnyPgTable,\n Tombstone extends AnyPgTable,\n NativeSubjectId,\n NativeSessionId,\n>(\n mapping: SignedSessionValidityMapping<Subject, Tombstone, NativeSubjectId, NativeSessionId>,\n) =>\n Effect.flatMap(\n Effect.map(acquireTransactionService(DatabaseService), configuration),\n (configuration) => makeTargetSignedSessionValidityServices(mapping, configuration),\n ).pipe(Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(DatabaseService)));\n\nexport function coordinatePgAuthenticationAuthority<\n Claims,\n D extends Database,\n S extends AnyPgTable,\n C extends AnyPgTable,\n F extends AnyPgTable,\n P extends AnyPgTable,\n NativeId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: AuthenticationAuthorityMapping<Claims, S, C, F, P, NativeId>;\n readonly transaction?: never;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, AuthenticationAuthority> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinatePgAuthenticationAuthority<\n Claims,\n D extends Database,\n S extends AnyPgTable,\n C extends AnyPgTable,\n F extends AnyPgTable,\n P extends AnyPgTable,\n NativeId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: AuthenticationAuthorityMapping<Claims, S, C, F, P, NativeId>;\n readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, AuthenticationAuthority | TxId> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinatePgAuthenticationAuthority<\n Claims,\n D extends Database,\n S extends AnyPgTable,\n C extends AnyPgTable,\n F extends AnyPgTable,\n P extends AnyPgTable,\n NativeId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: AuthenticationAuthorityMapping<Claims, S, C, F, P, NativeId>;\n readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, AuthenticationAuthority> | LifecycleHooks | DatabaseRequirements\n> {\n return Effect.flatMap(acquire, (database) =>\n coordinateTargetAuthenticationAuthority<\n Claims,\n TransactionOf<D>,\n A,\n E,\n Exclude<R, AuthenticationAuthority>\n >(\n database,\n options.mapping,\n configuration(transactionService(database)),\n (\n transaction: TransactionOf<D>,\n services: { readonly authenticationAuthority: AuthenticationAuthority[\"Service\"] },\n ) => {\n const provided = Context.make(AuthenticationAuthority, services.authenticationAuthority);\n const work = Effect.provideContext(body, provided);\n\n return options.transaction === undefined\n ? work\n : Effect.provideService(work, options.transaction, options.transaction.of(transaction));\n },\n ),\n );\n}\n\nexport function coordinatePgPendingAuthentication<\n TargetId,\n Claims,\n D extends Database,\n S extends AnyPgTable,\n C extends AnyPgTable,\n P extends AnyPgTable,\n F extends AnyPgTable,\n NativeId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PendingAuthenticationMapping<NoInfer<Claims>, S, C, P, F, NativeId>;\n readonly target: SuppliedService<TargetId, PendingAuthentication<Claims>>;\n readonly transaction?: never;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, TargetId> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinatePgPendingAuthentication<\n TargetId,\n Claims,\n D extends Database,\n S extends AnyPgTable,\n C extends AnyPgTable,\n P extends AnyPgTable,\n F extends AnyPgTable,\n NativeId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PendingAuthenticationMapping<NoInfer<Claims>, S, C, P, F, NativeId>;\n readonly target: SuppliedService<TargetId, PendingAuthentication<Claims>>;\n readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, TargetId | TxId> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinatePgPendingAuthentication<\n TargetId,\n Claims,\n D extends Database,\n S extends AnyPgTable,\n C extends AnyPgTable,\n P extends AnyPgTable,\n F extends AnyPgTable,\n NativeId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PendingAuthenticationMapping<NoInfer<Claims>, S, C, P, F, NativeId>;\n readonly target: SuppliedService<TargetId, PendingAuthentication<Claims>>;\n readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, TargetId> | LifecycleHooks | DatabaseRequirements\n> {\n return Effect.flatMap(acquire, (database) =>\n coordinateTargetPendingAuthentication<Claims, TransactionOf<D>, A, E, Exclude<R, TargetId>>(\n database,\n options.mapping,\n configuration(transactionService(database)),\n (\n transaction: TransactionOf<D>,\n services: { readonly pendingAuthentication: PendingAuthentication<Claims> },\n ) => {\n const provided = Context.make(options.target, services.pendingAuthentication);\n const work = Effect.provideContext(body, provided);\n\n return options.transaction === undefined\n ? work\n : Effect.provideService(work, options.transaction, options.transaction.of(transaction));\n },\n ),\n );\n}\n\nexport function coordinatePgStatefulSessions<\n PersistenceId,\n RepositoryId,\n Claims,\n D extends Database,\n S extends AnyPgTable,\n C extends AnyPgTable,\n Session extends AnyPgTable,\n F extends AnyPgTable,\n P extends AnyPgTable,\n NativeId,\n NativeSessionId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: StatefulSessionMapping<\n NoInfer<Claims>,\n S,\n C,\n Session,\n F,\n P,\n NativeId,\n NativeSessionId\n >;\n readonly persistence: SuppliedService<PersistenceId, StatefulSessionPersistence<Claims>>;\n readonly repository: SuppliedService<RepositoryId, SessionRepository>;\n readonly transaction?: never;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, PersistenceId | RepositoryId> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinatePgStatefulSessions<\n PersistenceId,\n RepositoryId,\n Claims,\n D extends Database,\n S extends AnyPgTable,\n C extends AnyPgTable,\n Session extends AnyPgTable,\n F extends AnyPgTable,\n P extends AnyPgTable,\n NativeId,\n NativeSessionId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: StatefulSessionMapping<\n NoInfer<Claims>,\n S,\n C,\n Session,\n F,\n P,\n NativeId,\n NativeSessionId\n >;\n readonly persistence: SuppliedService<PersistenceId, StatefulSessionPersistence<Claims>>;\n readonly repository: SuppliedService<RepositoryId, SessionRepository>;\n readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, PersistenceId | RepositoryId | TxId> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinatePgStatefulSessions<\n PersistenceId,\n RepositoryId,\n Claims,\n D extends Database,\n S extends AnyPgTable,\n C extends AnyPgTable,\n Session extends AnyPgTable,\n F extends AnyPgTable,\n P extends AnyPgTable,\n NativeId,\n NativeSessionId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: StatefulSessionMapping<\n NoInfer<Claims>,\n S,\n C,\n Session,\n F,\n P,\n NativeId,\n NativeSessionId\n >;\n readonly persistence: SuppliedService<PersistenceId, StatefulSessionPersistence<Claims>>;\n readonly repository: SuppliedService<RepositoryId, SessionRepository>;\n readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, PersistenceId | RepositoryId> | LifecycleHooks | DatabaseRequirements\n> {\n return Effect.flatMap(acquire, (database) =>\n coordinateTargetStatefulSessions<\n Claims,\n TransactionOf<D>,\n A,\n E,\n Exclude<R, PersistenceId | RepositoryId>\n >(\n database,\n options.mapping,\n configuration(transactionService(database)),\n (\n transaction: TransactionOf<D>,\n services: {\n readonly statefulSessionPersistence: StatefulSessionPersistence<Claims>;\n readonly sessionRepository: SessionRepository;\n },\n ) => {\n const provided = Context.make(\n options.persistence,\n services.statefulSessionPersistence,\n ).pipe(Context.add(options.repository, services.sessionRepository));\n\n const work = Effect.provideContext(body, provided);\n\n return options.transaction === undefined\n ? work\n : Effect.provideService(work, options.transaction, options.transaction.of(transaction));\n },\n ),\n );\n}\n\nexport function coordinatePgSignedSessionValidity<\n TargetId,\n D extends Database,\n S extends AnyPgTable,\n T extends AnyPgTable,\n NativeId,\n NativeSessionId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: SignedSessionValidityMapping<S, T, NativeId, NativeSessionId>;\n readonly target: SuppliedService<TargetId, SignedSessionValidity>;\n readonly transaction?: never;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, TargetId> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinatePgSignedSessionValidity<\n TargetId,\n D extends Database,\n S extends AnyPgTable,\n T extends AnyPgTable,\n NativeId,\n NativeSessionId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: SignedSessionValidityMapping<S, T, NativeId, NativeSessionId>;\n readonly target: SuppliedService<TargetId, SignedSessionValidity>;\n readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, TargetId | TxId> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinatePgSignedSessionValidity<\n TargetId,\n D extends Database,\n S extends AnyPgTable,\n T extends AnyPgTable,\n NativeId,\n NativeSessionId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: SignedSessionValidityMapping<S, T, NativeId, NativeSessionId>;\n readonly target: SuppliedService<TargetId, SignedSessionValidity>;\n readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, TargetId> | LifecycleHooks | DatabaseRequirements\n> {\n return Effect.flatMap(acquire, (database) =>\n coordinateTargetSignedSessionValidity<TransactionOf<D>, A, E, Exclude<R, TargetId>>(\n database,\n options.mapping,\n configuration(transactionService(database)),\n (\n transaction: TransactionOf<D>,\n services: { readonly signedSessionValidity: SignedSessionValidity },\n ) => {\n const provided = Context.make(options.target, services.signedSessionValidity);\n const work = Effect.provideContext(body, provided);\n\n return options.transaction === undefined\n ? work\n : Effect.provideService(work, options.transaction, options.transaction.of(transaction));\n },\n ),\n );\n}\n\nimport type { SessionStepUpMapping } from \"./step-up-model\";\n\nexport const makePgSessionStepUpServices = <\n Claims,\n Id,\n S extends AnyPgTable,\n C extends AnyPgTable,\n I extends AnyPgTable,\n Session extends AnyPgTable,\n T extends AnyPgTable,\n NativeId,\n NativeSessionId,\n>(\n mapping: SessionStepUpMapping<NoInfer<Claims>, S, C, I, Session, T, NativeId, NativeSessionId>,\n target: Context.Service<Id, SessionStepUpPersistence<Claims>>,\n) =>\n Effect.flatMap(\n Effect.map(acquireTransactionService(DatabaseService), configuration),\n (configuration) => makeTargetSessionStepUpServices(mapping, target, configuration),\n ).pipe(Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(DatabaseService)));\n\nexport function coordinatePgSessionStepUp<\n Claims,\n Id,\n S extends AnyPgTable,\n C extends AnyPgTable,\n I extends AnyPgTable,\n Session extends AnyPgTable,\n T extends AnyPgTable,\n NativeId,\n NativeSessionId,\n D extends Database,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: SessionStepUpMapping<\n NoInfer<Claims>,\n S,\n C,\n I,\n Session,\n T,\n NativeId,\n NativeSessionId\n >;\n readonly target: SuppliedService<Id, SessionStepUpPersistence<Claims>>;\n readonly transaction?: never;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, Id> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinatePgSessionStepUp<\n Claims,\n Id,\n S extends AnyPgTable,\n C extends AnyPgTable,\n I extends AnyPgTable,\n Session extends AnyPgTable,\n T extends AnyPgTable,\n NativeId,\n NativeSessionId,\n D extends Database,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: SessionStepUpMapping<\n NoInfer<Claims>,\n S,\n C,\n I,\n Session,\n T,\n NativeId,\n NativeSessionId\n >;\n readonly target: SuppliedService<Id, SessionStepUpPersistence<Claims>>;\n readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, Id | TxId> | LifecycleHooks | DatabaseRequirements\n>;\n\nexport function coordinatePgSessionStepUp<\n Claims,\n Id,\n S extends AnyPgTable,\n C extends AnyPgTable,\n I extends AnyPgTable,\n Session extends AnyPgTable,\n T extends AnyPgTable,\n NativeId,\n NativeSessionId,\n D extends Database,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: SessionStepUpMapping<\n NoInfer<Claims>,\n S,\n C,\n I,\n Session,\n T,\n NativeId,\n NativeSessionId\n >;\n readonly target: SuppliedService<Id, SessionStepUpPersistence<Claims>>;\n readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, Id> | LifecycleHooks | DatabaseRequirements\n> {\n return Effect.flatMap(acquire, (database) =>\n coordinateTargetSessionStepUp<Claims, Id, TransactionOf<D>, A, E, Exclude<R, Id>>(\n database,\n options.mapping,\n options.target,\n configuration(transactionService(database)),\n (\n transaction: TransactionOf<D>,\n services: { readonly sessionStepUpPersistence: SessionStepUpPersistence<Claims> },\n ) => {\n const provided = Context.make(options.target, services.sessionStepUpPersistence);\n const work = Effect.provideContext(body, provided);\n\n return options.transaction === undefined\n ? work\n : Effect.provideService(work, options.transaction, options.transaction.of(transaction));\n },\n ),\n );\n}\n"],"mappings":";;;;;;;;AAiDA,MAAM,iBAAiB,aAA6C;CAClE,MAAM;CACN,SAAS;CACT,iBAAiB,gCAAgC,OAAO;AAC1D;AAEA,MAAa,yCAQX,YASA,OAAO,QACL,OAAO,IAAI,0BAA0BA,QAAe,GAAG,aAAa,IACnE,kBAAkB,0CAAkD,SAAS,aAAa,CAC7F,CAAC,CAAC,KAAK,OAAO,qBAAqB,mBAAmB,eAAeA,QAAe,CAAC,CAAC;AAExF,MAAa,uCAQX,YASA,OAAO,QACL,OAAO,IAAI,0BAA0BA,QAAe,GAAG,aAAa,IACnE,kBAAkB,wCAAgD,SAAS,aAAa,CAC3F,CAAC,CAAC,KAAK,OAAO,qBAAqB,mBAAmB,eAAeA,QAAe,CAAC,CAAC;AAExF,MAAa,iCAUX,YAWA,OAAO,QACL,OAAO,IAAI,0BAA0BA,QAAe,GAAG,aAAa,IACnE,kBAAkB,kCAA0C,SAAS,aAAa,CACrF,CAAC,CAAC,KAAK,OAAO,qBAAqB,mBAAmB,eAAeA,QAAe,CAAC,CAAC;AAExF,MAAa,uCAMX,YAEA,OAAO,QACL,OAAO,IAAI,0BAA0BA,QAAe,GAAG,aAAa,IACnE,kBAAkB,wCAAwC,SAAS,aAAa,CACnF,CAAC,CAAC,KAAK,OAAO,qBAAqB,mBAAmB,eAAeA,QAAe,CAAC,CAAC;AAwDxF,SAAgB,oCAgBd,SACA,SAIA,MAKA;CACA,OAAO,OAAO,QAAQ,UAAU,aAC9B,wCAOE,UACA,QAAQ,SACR,cAAc,mBAAmB,QAAQ,CAAC,IAExC,aACA,aACG;EACH,MAAM,WAAW,QAAQ,KAAK,yBAAyB,SAAS,uBAAuB;EACvF,MAAM,OAAO,OAAO,eAAe,MAAM,QAAQ;EAEjD,OAAO,QAAQ,gBAAgB,KAAA,IAC3B,OACA,OAAO,eAAe,MAAM,QAAQ,aAAa,QAAQ,YAAY,GAAG,WAAW,CAAC;CAC1F,CACF,CACF;AACF;AA4DA,SAAgB,kCAiBd,SACA,SAKA,MAKA;CACA,OAAO,OAAO,QAAQ,UAAU,aAC9B,sCACE,UACA,QAAQ,SACR,cAAc,mBAAmB,QAAQ,CAAC,IAExC,aACA,aACG;EACH,MAAM,WAAW,QAAQ,KAAK,QAAQ,QAAQ,SAAS,qBAAqB;EAC5E,MAAM,OAAO,OAAO,eAAe,MAAM,QAAQ;EAEjD,OAAO,QAAQ,gBAAgB,KAAA,IAC3B,OACA,OAAO,eAAe,MAAM,QAAQ,aAAa,QAAQ,YAAY,GAAG,WAAW,CAAC;CAC1F,CACF,CACF;AACF;AAsFA,SAAgB,6BAoBd,SACA,SAeA,MAKA;CACA,OAAO,OAAO,QAAQ,UAAU,aAC9B,iCAOE,UACA,QAAQ,SACR,cAAc,mBAAmB,QAAQ,CAAC,IAExC,aACA,aAIG;EACH,MAAM,WAAW,QAAQ,KACvB,QAAQ,aACR,SAAS,0BACX,CAAC,CAAC,KAAK,QAAQ,IAAI,QAAQ,YAAY,SAAS,iBAAiB,CAAC;EAElE,MAAM,OAAO,OAAO,eAAe,MAAM,QAAQ;EAEjD,OAAO,QAAQ,gBAAgB,KAAA,IAC3B,OACA,OAAO,eAAe,MAAM,QAAQ,aAAa,QAAQ,YAAY,GAAG,WAAW,CAAC;CAC1F,CACF,CACF;AACF;AAwDA,SAAgB,kCAed,SACA,SAKA,MAKA;CACA,OAAO,OAAO,QAAQ,UAAU,aAC9B,sCACE,UACA,QAAQ,SACR,cAAc,mBAAmB,QAAQ,CAAC,IAExC,aACA,aACG;EACH,MAAM,WAAW,QAAQ,KAAK,QAAQ,QAAQ,SAAS,qBAAqB;EAC5E,MAAM,OAAO,OAAO,eAAe,MAAM,QAAQ;EAEjD,OAAO,QAAQ,gBAAgB,KAAA,IAC3B,OACA,OAAO,eAAe,MAAM,QAAQ,aAAa,QAAQ,YAAY,GAAG,WAAW,CAAC;CAC1F,CACF,CACF;AACF;AAIA,MAAa,+BAWX,SACA,WAEA,OAAO,QACL,OAAO,IAAI,0BAA0BA,QAAe,GAAG,aAAa,IACnE,kBAAkB,gCAAgC,SAAS,QAAQ,aAAa,CACnF,CAAC,CAAC,KAAK,OAAO,qBAAqB,mBAAmB,eAAeA,QAAe,CAAC,CAAC;AAkFxF,SAAgB,0BAmBd,SACA,SAcA,MAKA;CACA,OAAO,OAAO,QAAQ,UAAU,aAC9B,8BACE,UACA,QAAQ,SACR,QAAQ,QACR,cAAc,mBAAmB,QAAQ,CAAC,IAExC,aACA,aACG;EACH,MAAM,WAAW,QAAQ,KAAK,QAAQ,QAAQ,SAAS,wBAAwB;EAC/E,MAAM,OAAO,OAAO,eAAe,MAAM,QAAQ;EAEjD,OAAO,QAAQ,gBAAgB,KAAA,IAC3B,OACA,OAAO,eAAe,MAAM,QAAQ,aAAa,QAAQ,YAAY,GAAG,WAAW,CAAC;CAC1F,CACF,CACF;AACF"}
@@ -1,14 +1,15 @@
1
- import { PersistenceMappingError } from "./model.mjs";
1
+ import { PersistenceMappingError as PersistenceMappingError$1 } from "./model.mjs";
2
2
  import "./transaction-owner.mjs";
3
3
  import { TransactionCoordinatorError } from "./transaction-execution.mjs";
4
4
  import "./phone-model.mjs";
5
5
  import "./SuppliedService.mjs";
6
+ import { NativeDatabase } from "@yielded/auth-persistence/Adapter";
6
7
  import { Table } from "drizzle-orm";
7
- import { Effect } from "effect";
8
+ import { Context, Effect } from "effect";
8
9
  import { LifecycleHooks } from "@yielded/auth/Hooks";
9
10
  import { PhoneAdmission, PhoneConfigurationError, PhoneOtpUnavailable, PhonePersistence, PhoneSignInTargets } from "@yielded/auth/PhoneOtp";
10
11
  import { Statement } from "effect/sql/Statement";
11
12
  //#region src/drizzle/phone-target.d.ts
12
- export type PhoneCoordinatorError<E> = TransactionCoordinatorError<E, PhoneOtpUnavailable> | PhoneConfigurationError | PersistenceMappingError;
13
+ export type PhoneCoordinatorError<E> = TransactionCoordinatorError<E, PhoneOtpUnavailable> | PhoneConfigurationError | PersistenceMappingError$1;
13
14
  //#endregion
14
15
  //# sourceMappingURL=phone-target.d.mts.map
@@ -3,8 +3,10 @@ import { CurrentProofSql, completeProofPlanIn } from "./proof-sql.mjs";
3
3
  import { coordinateTransactionOwner, makeTransactionExecution, sqlClientTransactionStandaloneGuard } from "./transaction-execution.mjs";
4
4
  import { phoneProofs, requiredPhoneConstraints } from "./phone-model.mjs";
5
5
  import { CurrentD1PlanningDatabase } from "./d1-planning.mjs";
6
+ import { nativeDatabase } from "./native-database.mjs";
6
7
  import { compileD1ProofCompletionPlan } from "./d1-proofs.mjs";
7
8
  import { CurrentPhoneTransaction, admitPhone, capturePhone, cleanupPhoneAdmission, equal, invariant, lookupPhone, preparePhoneMutation, unavailable } from "./phone-state.mjs";
9
+ import { NativeDatabase } from "@yielded/auth-persistence/Adapter";
8
10
  import { sql } from "drizzle-orm";
9
11
  import { Context, Effect, Schema } from "effect";
10
12
  import { LifecycleHooks } from "@yielded/auth/Hooks";
@@ -12,7 +14,7 @@ import { ProofBinding } from "@yielded/auth/Proofs";
12
14
  import { randomId } from "@yielded/auth-crypto";
13
15
  import { PhoneActionAuthorization, PhoneAdmission, PhoneAdmissionPolicy, PhoneConfigurationError, PhoneLifecyclePolicy, PhoneLifecycleTarget, PhonePersistence, PhoneSignInTargets } from "@yielded/auth/PhoneOtp";
14
16
  //#region src/drizzle/phone-target.ts
15
- const sqlClientPhoneStandaloneGuard = (database) => sqlClientTransactionStandaloneGuard(unavailable, database);
17
+ const sqlClientPhoneStandaloneGuard = (service) => sqlClientTransactionStandaloneGuard(unavailable, service);
16
18
  const validateMapping = (original, configuration) => {
17
19
  const mapping = original;
18
20
  invariant(mapping.moduleId.length > 0);
@@ -37,7 +39,8 @@ const validateMapping = (original, configuration) => {
37
39
  subjectIds: Object.freeze({ ...mapping.subjectIds })
38
40
  });
39
41
  };
40
- const services = (mapping, execution, hooks, configuration) => {
42
+ const services = Effect.fnUntraced(function* (mapping, execution, configuration) {
43
+ const hooks = yield* LifecycleHooks;
41
44
  const run = (effect, mutation = true) => execution.admit.pipe(Effect.andThen(execution.run(effect, mutation)), Effect.provideService(LifecycleHooks, hooks));
42
45
  return {
43
46
  phoneAdmission: PhoneAdmission.of({
@@ -128,28 +131,26 @@ const services = (mapping, execution, hooks, configuration) => {
128
131
  }).pipe(Effect.catchDefect(() => Effect.fail(unavailable())))
129
132
  })
130
133
  };
131
- };
132
- const makeTargetPhonePersistence = (database, source, configuration) => Effect.gen(function* () {
133
- const hooks = yield* LifecycleHooks;
134
+ });
135
+ const makeTargetPhonePersistence = (source, configuration) => Effect.gen(function* () {
134
136
  const original = yield* Effect.isEffect(source) ? source : Effect.succeed(source);
135
137
  const mapping = yield* Effect.try({
136
138
  try: () => validateMapping(original, configuration),
137
139
  catch: () => PhoneConfigurationError.make({})
138
140
  });
139
- const execution = makeTransactionExecution(CurrentPhoneTransaction, database, configuration, unavailable, randomId);
140
- return services(mapping, execution, hooks, configuration);
141
+ const execution = yield* makeTransactionExecution(CurrentPhoneTransaction, configuration, unavailable, randomId);
142
+ return yield* services(mapping, execution, configuration);
141
143
  });
142
144
  const coordinateTargetPhone = (database, source, configuration, body) => Effect.gen(function* () {
143
- const hooks = yield* LifecycleHooks;
144
145
  const original = yield* Effect.isEffect(source) ? source : Effect.succeed(source);
145
146
  const mapping = yield* Effect.try({
146
147
  try: () => validateMapping(original, configuration),
147
148
  catch: () => PhoneConfigurationError.make({})
148
149
  });
149
- return yield* coordinateTransactionOwner(database, CurrentPhoneTransaction, configuration, Effect.void, unavailable, randomId, (execution) => services(mapping, execution, hooks, configuration), body);
150
+ return yield* coordinateTransactionOwner(database, CurrentPhoneTransaction, configuration, Effect.void, unavailable, randomId, (execution) => services(mapping, execution, configuration), (transaction, acquireServices, append) => Effect.flatMap(acquireServices, (boundServices) => body(transaction, boundServices, append)));
150
151
  });
151
152
  /** Concrete driver wrappers select transaction mode; cryptography always precedes these owners. */
152
- const makePhoneTarget = (configuration) => {
153
+ const makePhoneTarget = (databaseService, configuration) => {
153
154
  function coordinatePhonePersistence(acquire, options, body) {
154
155
  return Effect.flatMap(acquire, (database) => coordinateTargetPhone(database, options.mapping, configuration, (transaction, services) => {
155
156
  const provided = Context.make(PhonePersistence, services.phonePersistence).pipe(Context.add(PhoneAdmission, services.phoneAdmission), Context.add(PhoneSignInTargets, services.phoneSignInTargets));
@@ -158,7 +159,7 @@ const makePhoneTarget = (configuration) => {
158
159
  }));
159
160
  }
160
161
  return {
161
- makePhonePersistenceServices: (database, mapping) => makeTargetPhonePersistence(database, mapping, configuration),
162
+ makePhonePersistenceServices: (mapping) => makeTargetPhonePersistence(mapping, configuration).pipe(Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService))),
162
163
  coordinatePhonePersistence
163
164
  };
164
165
  };