@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.
- package/dist/D1.d.mts +27 -22
- package/dist/D1.mjs +10 -4
- package/dist/D1.mjs.map +1 -1
- package/dist/Libsql.d.mts +66 -61
- package/dist/Libsql.mjs +20 -15
- package/dist/Libsql.mjs.map +1 -1
- package/dist/Mysql2.d.mts +58 -46
- package/dist/Mysql2.mjs +13 -6
- package/dist/Mysql2.mjs.map +1 -1
- package/dist/Pglite.d.mts +43 -32
- package/dist/Pglite.mjs +12 -7
- package/dist/Pglite.mjs.map +1 -1
- package/dist/Postgres.d.mts +59 -48
- package/dist/Postgres.mjs +12 -7
- package/dist/Postgres.mjs.map +1 -1
- package/dist/SqliteBun.d.mts +58 -53
- package/dist/SqliteBun.mjs +20 -14
- package/dist/SqliteBun.mjs.map +1 -1
- package/dist/SqliteDo.d.mts +66 -60
- package/dist/SqliteDo.mjs +26 -14
- package/dist/SqliteDo.mjs.map +1 -1
- package/dist/SqliteNode.d.mts +58 -53
- package/dist/SqliteNode.mjs +20 -14
- package/dist/SqliteNode.mjs.map +1 -1
- package/dist/SqliteWasm.d.mts +66 -61
- package/dist/SqliteWasm.mjs +20 -14
- package/dist/SqliteWasm.mjs.map +1 -1
- package/dist/drizzle/d1-database.d.mts +11 -0
- package/dist/drizzle/d1-database.mjs +8 -0
- package/dist/drizzle/d1-database.mjs.map +1 -0
- package/dist/drizzle/d1-emails.d.mts +8 -7
- package/dist/drizzle/d1-emails.mjs +7 -4
- package/dist/drizzle/d1-emails.mjs.map +1 -1
- package/dist/drizzle/d1-identity.mjs +12 -9
- package/dist/drizzle/d1-identity.mjs.map +1 -1
- package/dist/drizzle/d1-oauth.d.mts +14 -13
- package/dist/drizzle/d1-oauth.mjs +7 -4
- package/dist/drizzle/d1-oauth.mjs.map +1 -1
- package/dist/drizzle/d1-passkey.d.mts +3 -14
- package/dist/drizzle/d1-passkey.mjs +2 -1
- package/dist/drizzle/d1-passkey.mjs.map +1 -1
- package/dist/drizzle/d1-password-prepared.d.mts +4 -3
- package/dist/drizzle/d1-password-prepared.mjs +3 -1
- package/dist/drizzle/d1-password-prepared.mjs.map +1 -1
- package/dist/drizzle/d1-passwords.d.mts +6 -5
- package/dist/drizzle/d1-passwords.mjs +5 -2
- package/dist/drizzle/d1-passwords.mjs.map +1 -1
- package/dist/drizzle/d1-phone.d.mts +3 -4
- package/dist/drizzle/d1-phone.mjs +2 -1
- package/dist/drizzle/d1-phone.mjs.map +1 -1
- package/dist/drizzle/d1-planning.d.mts +1 -1
- package/dist/drizzle/d1-proofs.d.mts +4 -3
- package/dist/drizzle/d1-proofs.mjs +3 -1
- package/dist/drizzle/d1-proofs.mjs.map +1 -1
- package/dist/drizzle/d1-sessions.d.mts +11 -10
- package/dist/drizzle/d1-sessions.mjs +15 -9
- package/dist/drizzle/d1-sessions.mjs.map +1 -1
- package/dist/drizzle/d1-totp.d.mts +3 -4
- package/dist/drizzle/d1-totp.mjs +2 -1
- package/dist/drizzle/d1-totp.mjs.map +1 -1
- package/dist/drizzle/email-registration.mjs +2 -1
- package/dist/drizzle/email-registration.mjs.map +1 -1
- package/dist/drizzle/email-target.d.mts +7 -6
- package/dist/drizzle/email-target.mjs +10 -10
- package/dist/drizzle/email-target.mjs.map +1 -1
- package/dist/drizzle/mysql-database.d.mts +8 -0
- package/dist/drizzle/mysql-database.mjs +8 -0
- package/dist/drizzle/mysql-database.mjs.map +1 -0
- package/dist/drizzle/mysql-emails.d.mts +7 -6
- package/dist/drizzle/mysql-emails.mjs +12 -8
- package/dist/drizzle/mysql-emails.mjs.map +1 -1
- package/dist/drizzle/mysql-identity.mjs +12 -9
- package/dist/drizzle/mysql-identity.mjs.map +1 -1
- package/dist/drizzle/mysql-password-prepared.d.mts +3 -2
- package/dist/drizzle/mysql-password-prepared.mjs +6 -2
- package/dist/drizzle/mysql-password-prepared.mjs.map +1 -1
- package/dist/drizzle/mysql-passwords.d.mts +6 -4
- package/dist/drizzle/mysql-passwords.mjs +11 -7
- package/dist/drizzle/mysql-passwords.mjs.map +1 -1
- package/dist/drizzle/mysql-proofs.d.mts +3 -2
- package/dist/drizzle/mysql-proofs.mjs +8 -4
- package/dist/drizzle/mysql-proofs.mjs.map +1 -1
- package/dist/drizzle/mysql-sessions.d.mts +11 -10
- package/dist/drizzle/mysql-sessions.mjs +16 -12
- package/dist/drizzle/mysql-sessions.mjs.map +1 -1
- package/dist/drizzle/native-database.mjs +10 -0
- package/dist/drizzle/native-database.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-drivers.mjs +7 -5
- package/dist/drizzle/oauth-connected-drivers.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-target.d.mts +6 -7
- package/dist/drizzle/oauth-connected-target.mjs +4 -5
- package/dist/drizzle/oauth-connected-target.mjs.map +1 -1
- package/dist/drizzle/oauth-drivers.mjs +8 -6
- package/dist/drizzle/oauth-drivers.mjs.map +1 -1
- package/dist/drizzle/oauth-target.d.mts +12 -11
- package/dist/drizzle/oauth-target.mjs +13 -12
- package/dist/drizzle/oauth-target.mjs.map +1 -1
- package/dist/drizzle/passkey-drivers.mjs +8 -6
- package/dist/drizzle/passkey-drivers.mjs.map +1 -1
- package/dist/drizzle/passkey-write-drivers.mjs +5 -3
- package/dist/drizzle/passkey-write-drivers.mjs.map +1 -1
- package/dist/drizzle/passkey-write-target.d.mts +1 -1
- package/dist/drizzle/password-prepared-sql.mjs +2 -1
- package/dist/drizzle/password-prepared-sql.mjs.map +1 -1
- package/dist/drizzle/password-prepared-target.d.mts +3 -2
- package/dist/drizzle/password-prepared-target.mjs +4 -3
- package/dist/drizzle/password-prepared-target.mjs.map +1 -1
- package/dist/drizzle/password-registration.mjs +2 -1
- package/dist/drizzle/password-registration.mjs.map +1 -1
- package/dist/drizzle/password-target.d.mts +5 -4
- package/dist/drizzle/password-target.mjs +8 -8
- package/dist/drizzle/password-target.mjs.map +1 -1
- package/dist/drizzle/pg-database.d.mts +9 -0
- package/dist/drizzle/pg-database.mjs +8 -0
- package/dist/drizzle/pg-database.mjs.map +1 -0
- package/dist/drizzle/pg-emails.d.mts +7 -6
- package/dist/drizzle/pg-emails.mjs +12 -8
- package/dist/drizzle/pg-emails.mjs.map +1 -1
- package/dist/drizzle/pg-identity.mjs +12 -9
- package/dist/drizzle/pg-identity.mjs.map +1 -1
- package/dist/drizzle/pg-password-prepared.d.mts +3 -2
- package/dist/drizzle/pg-password-prepared.mjs +6 -2
- package/dist/drizzle/pg-password-prepared.mjs.map +1 -1
- package/dist/drizzle/pg-passwords.d.mts +6 -4
- package/dist/drizzle/pg-passwords.mjs +11 -7
- package/dist/drizzle/pg-passwords.mjs.map +1 -1
- package/dist/drizzle/pg-proofs.d.mts +3 -2
- package/dist/drizzle/pg-proofs.mjs +8 -4
- package/dist/drizzle/pg-proofs.mjs.map +1 -1
- package/dist/drizzle/pg-sessions.d.mts +11 -10
- package/dist/drizzle/pg-sessions.mjs +16 -12
- package/dist/drizzle/pg-sessions.mjs.map +1 -1
- package/dist/drizzle/phone-target.d.mts +4 -3
- package/dist/drizzle/phone-target.mjs +12 -11
- package/dist/drizzle/phone-target.mjs.map +1 -1
- package/dist/drizzle/proof-target.d.mts +3 -2
- package/dist/drizzle/proof-target.mjs +5 -5
- package/dist/drizzle/proof-target.mjs.map +1 -1
- package/dist/drizzle/session-sql.d.mts +1 -0
- package/dist/drizzle/session-target.d.mts +10 -8
- package/dist/drizzle/session-target.mjs +11 -11
- package/dist/drizzle/session-target.mjs.map +1 -1
- package/dist/drizzle/sqlite-emails.mjs +9 -5
- package/dist/drizzle/sqlite-emails.mjs.map +1 -1
- package/dist/drizzle/sqlite-identity.mjs +14 -11
- package/dist/drizzle/sqlite-identity.mjs.map +1 -1
- package/dist/drizzle/sqlite-password-prepared.mjs +7 -3
- package/dist/drizzle/sqlite-password-prepared.mjs.map +1 -1
- package/dist/drizzle/sqlite-passwords.mjs +10 -6
- package/dist/drizzle/sqlite-passwords.mjs.map +1 -1
- package/dist/drizzle/sqlite-proofs.mjs +7 -3
- package/dist/drizzle/sqlite-proofs.mjs.map +1 -1
- package/dist/drizzle/sqlite-sessions.mjs +16 -12
- package/dist/drizzle/sqlite-sessions.mjs.map +1 -1
- package/dist/drizzle/standalone-guard.d.mts +2 -0
- package/dist/drizzle/standalone-guard.mjs +8 -4
- package/dist/drizzle/standalone-guard.mjs.map +1 -1
- package/dist/drizzle/totp-target.d.mts +4 -3
- package/dist/drizzle/totp-target.mjs +31 -28
- package/dist/drizzle/totp-target.mjs.map +1 -1
- package/package.json +1 -1
- package/src/D1.ts +37 -10
- package/src/Libsql.ts +45 -17
- package/src/Mysql2.ts +39 -13
- package/src/Pglite.ts +47 -13
- package/src/Postgres.ts +47 -13
- package/src/SqliteBun.ts +58 -30
- package/src/SqliteDo.ts +61 -19
- package/src/SqliteNode.ts +55 -28
- package/src/SqliteWasm.ts +55 -28
- package/src/drizzle/d1-database.ts +10 -0
- package/src/drizzle/d1-emails.ts +84 -84
- package/src/drizzle/d1-identity.ts +17 -20
- package/src/drizzle/d1-oauth.ts +19 -8
- package/src/drizzle/d1-passkey.ts +5 -1
- package/src/drizzle/d1-password-prepared.ts +38 -37
- package/src/drizzle/d1-passwords.ts +74 -76
- package/src/drizzle/d1-phone.ts +5 -1
- package/src/drizzle/d1-proofs.ts +29 -30
- package/src/drizzle/d1-sessions.ts +51 -38
- package/src/drizzle/d1-totp.ts +5 -1
- package/src/drizzle/email-registration.ts +6 -2
- package/src/drizzle/email-target.ts +17 -19
- package/src/drizzle/mysql-database.ts +8 -0
- package/src/drizzle/mysql-emails.ts +28 -16
- package/src/drizzle/mysql-identity.ts +18 -21
- package/src/drizzle/mysql-password-prepared.ts +10 -8
- package/src/drizzle/mysql-passwords.ts +21 -9
- package/src/drizzle/mysql-proofs.ts +16 -5
- package/src/drizzle/mysql-sessions.ts +40 -17
- package/src/drizzle/native-database.ts +22 -0
- package/src/drizzle/oauth-connected-drivers.ts +18 -6
- package/src/drizzle/oauth-connected-target.ts +16 -17
- package/src/drizzle/oauth-drivers.ts +26 -10
- package/src/drizzle/oauth-target.ts +30 -42
- package/src/drizzle/passkey-drivers.ts +21 -13
- package/src/drizzle/passkey-write-drivers.ts +11 -6
- package/src/drizzle/password-prepared-sql.ts +2 -4
- package/src/drizzle/password-prepared-target.ts +9 -6
- package/src/drizzle/password-registration.ts +7 -8
- package/src/drizzle/password-target.ts +19 -18
- package/src/drizzle/pg-database.ts +10 -0
- package/src/drizzle/pg-emails.ts +28 -16
- package/src/drizzle/pg-identity.ts +18 -22
- package/src/drizzle/pg-password-prepared.ts +10 -8
- package/src/drizzle/pg-passwords.ts +21 -9
- package/src/drizzle/pg-proofs.ts +16 -5
- package/src/drizzle/pg-sessions.ts +40 -17
- package/src/drizzle/phone-target.ts +22 -17
- package/src/drizzle/proof-target.ts +9 -12
- package/src/drizzle/session-target.ts +32 -50
- package/src/drizzle/sqlite-emails.ts +30 -13
- package/src/drizzle/sqlite-identity.ts +22 -42
- package/src/drizzle/sqlite-password-prepared.ts +23 -9
- package/src/drizzle/sqlite-passwords.ts +29 -15
- package/src/drizzle/sqlite-proofs.ts +28 -5
- package/src/drizzle/sqlite-sessions.ts +49 -23
- package/src/drizzle/standalone-guard.ts +18 -6
- package/src/drizzle/totp-target.ts +61 -60
- package/dist/drizzle/d1-identity.d.mts +0 -30
- package/dist/drizzle/mysql-identity.d.mts +0 -21
- 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>(
|
|
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 = (
|
|
9
|
+
const configuration = (service) => ({
|
|
6
10
|
mode: "interactive",
|
|
7
11
|
locking: true,
|
|
8
|
-
standaloneGuard: sqlClientProofStandaloneGuard(
|
|
12
|
+
standaloneGuard: sqlClientProofStandaloneGuard(service),
|
|
9
13
|
insertIfAbsent: (query) => query.onConflictDoNothing()
|
|
10
14
|
});
|
|
11
|
-
const makePgProofPersistenceServices = (
|
|
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 = (
|
|
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>(
|
|
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>(
|
|
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>(
|
|
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>(
|
|
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>(
|
|
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 = (
|
|
9
|
+
const configuration = (service) => ({
|
|
6
10
|
mode: "interactive",
|
|
7
11
|
locking: true,
|
|
8
|
-
standaloneGuard: sqlClientSessionStandaloneGuard(
|
|
12
|
+
standaloneGuard: sqlClientSessionStandaloneGuard(service)
|
|
9
13
|
});
|
|
10
|
-
const makePgAuthenticationAuthorityServices = (
|
|
11
|
-
const makePgPendingAuthenticationServices = (
|
|
12
|
-
const makePgStatefulSessionServices = (
|
|
13
|
-
const makePgSignedSessionValidityServices = (
|
|
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 = (
|
|
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 = (
|
|
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,
|
|
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 = (
|
|
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,
|
|
140
|
-
return services(mapping, execution,
|
|
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,
|
|
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: (
|
|
162
|
+
makePhonePersistenceServices: (mapping) => makeTargetPhonePersistence(mapping, configuration).pipe(Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService))),
|
|
162
163
|
coordinatePhonePersistence
|
|
163
164
|
};
|
|
164
165
|
};
|