@yielded/auth-persistence-drizzle 0.1.0-beta.18 → 0.1.0-beta.20
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/README.md +8 -1
- package/dist/D1.d.mts +8 -8
- package/dist/Libsql.d.mts +38 -38
- package/dist/Mysql2.d.mts +51 -51
- package/dist/Pglite.d.mts +51 -51
- package/dist/Postgres.d.mts +38 -38
- package/dist/SqliteBun.d.mts +51 -51
- package/dist/SqliteDo.d.mts +112 -134
- package/dist/SqliteDo.mjs +30 -45
- package/dist/SqliteDo.mjs.map +1 -1
- package/dist/SqliteNode.d.mts +44 -44
- package/dist/SqliteWasm.d.mts +38 -38
- package/dist/drizzle/crypto.mjs +11 -0
- package/dist/drizzle/crypto.mjs.map +1 -0
- package/dist/drizzle/d1-identity.mjs +2 -2
- package/dist/drizzle/d1-identity.mjs.map +1 -1
- package/dist/drizzle/d1-oauth.d.mts +11 -11
- package/dist/drizzle/d1-oauth.mjs.map +1 -1
- package/dist/drizzle/d1-passkey.d.mts +6 -6
- package/dist/drizzle/d1-passkey.mjs.map +1 -1
- package/dist/drizzle/d1-passwords.d.mts +1 -1
- package/dist/drizzle/d1-phone.d.mts +3 -3
- package/dist/drizzle/d1-phone.mjs.map +1 -1
- package/dist/drizzle/d1-proofs.d.mts +1 -1
- package/dist/drizzle/d1-sessions.d.mts +1 -1
- package/dist/drizzle/d1-totp.d.mts +3 -3
- package/dist/drizzle/d1-totp.mjs.map +1 -1
- package/dist/drizzle/mysql-identity.mjs +2 -2
- package/dist/drizzle/mysql-identity.mjs.map +1 -1
- package/dist/drizzle/oauth-accounts.mjs +9 -8
- package/dist/drizzle/oauth-accounts.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-collection.mjs +1 -1
- package/dist/drizzle/oauth-connected-collection.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-custody.mjs +5 -4
- package/dist/drizzle/oauth-connected-custody.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-drivers.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-flow.mjs +8 -7
- package/dist/drizzle/oauth-connected-flow.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-management.mjs +3 -2
- package/dist/drizzle/oauth-connected-management.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-reference.mjs +8 -4
- package/dist/drizzle/oauth-connected-reference.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-settlement.mjs +4 -4
- package/dist/drizzle/oauth-connected-settlement.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-sign-in.mjs +11 -10
- package/dist/drizzle/oauth-connected-sign-in.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-state.d.mts +13 -13
- package/dist/drizzle/oauth-connected-state.mjs +23 -20
- package/dist/drizzle/oauth-connected-state.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-target.d.mts +9 -9
- package/dist/drizzle/oauth-connected-target.mjs.map +1 -1
- package/dist/drizzle/oauth-drivers.mjs.map +1 -1
- package/dist/drizzle/oauth-flow.mjs +1 -1
- package/dist/drizzle/oauth-flow.mjs.map +1 -1
- package/dist/drizzle/oauth-model.d.mts +4 -4
- package/dist/drizzle/oauth-model.mjs.map +1 -1
- package/dist/drizzle/oauth-registration.mjs +2 -2
- package/dist/drizzle/oauth-registration.mjs.map +1 -1
- package/dist/drizzle/oauth-state.mjs +11 -12
- package/dist/drizzle/oauth-state.mjs.map +1 -1
- package/dist/drizzle/oauth-target.d.mts +4 -4
- package/dist/drizzle/oauth-target.mjs.map +1 -1
- package/dist/drizzle/passkey-drivers.mjs.map +1 -1
- 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-state.mjs +1 -1
- package/dist/drizzle/pg-identity.mjs +2 -2
- package/dist/drizzle/pg-identity.mjs.map +1 -1
- package/dist/drizzle/phone-model.d.mts +2 -2
- package/dist/drizzle/phone-model.mjs +3 -3
- package/dist/drizzle/phone-model.mjs.map +1 -1
- package/dist/drizzle/phone-target.d.mts +1 -1
- package/dist/drizzle/phone-target.mjs +2 -2
- package/dist/drizzle/phone-target.mjs.map +1 -1
- package/dist/drizzle/sqlite-do-database.d.mts +29 -0
- package/dist/drizzle/sqlite-do-database.mjs +45 -0
- package/dist/drizzle/sqlite-do-database.mjs.map +1 -0
- package/dist/drizzle/sqlite-emails.mjs.map +1 -1
- package/dist/drizzle/sqlite-identity.mjs +2 -2
- package/dist/drizzle/sqlite-identity.mjs.map +1 -1
- package/dist/drizzle/sqlite-passwords.mjs.map +1 -1
- package/dist/drizzle/sqlite-proofs.mjs.map +1 -1
- package/dist/drizzle/sqlite-sessions.mjs.map +1 -1
- package/dist/drizzle/storage-validation.mjs +17 -9
- package/dist/drizzle/storage-validation.mjs.map +1 -1
- package/dist/drizzle/totp-state.mjs +8 -8
- package/dist/drizzle/totp-state.mjs.map +1 -1
- package/dist/drizzle/totp-target.d.mts +1 -1
- package/dist/drizzle/totp-target.mjs +2 -2
- package/dist/drizzle/totp-target.mjs.map +1 -1
- package/package.json +1 -1
- package/src/SqliteDo.ts +63 -70
- package/src/drizzle/crypto.ts +14 -0
- package/src/drizzle/d1-identity.ts +2 -2
- package/src/drizzle/d1-oauth.ts +14 -5
- package/src/drizzle/d1-passkey.ts +5 -1
- package/src/drizzle/d1-phone.ts +2 -1
- package/src/drizzle/d1-totp.ts +6 -2
- package/src/drizzle/mysql-identity.ts +2 -2
- package/src/drizzle/oauth-accounts.ts +14 -13
- package/src/drizzle/oauth-connected-collection.ts +1 -1
- package/src/drizzle/oauth-connected-custody.ts +8 -6
- package/src/drizzle/oauth-connected-drivers.ts +9 -3
- package/src/drizzle/oauth-connected-flow.ts +6 -6
- package/src/drizzle/oauth-connected-management.ts +1 -1
- package/src/drizzle/oauth-connected-reference.ts +14 -9
- package/src/drizzle/oauth-connected-settlement.ts +4 -4
- package/src/drizzle/oauth-connected-sign-in.ts +11 -10
- package/src/drizzle/oauth-connected-state.ts +40 -25
- package/src/drizzle/oauth-connected-target.ts +9 -5
- package/src/drizzle/oauth-drivers.ts +13 -5
- package/src/drizzle/oauth-flow.ts +1 -1
- package/src/drizzle/oauth-model.ts +4 -4
- package/src/drizzle/oauth-registration.ts +2 -2
- package/src/drizzle/oauth-state.ts +17 -15
- package/src/drizzle/oauth-target.ts +11 -3
- package/src/drizzle/passkey-drivers.ts +7 -3
- package/src/drizzle/passkey-write-drivers.ts +11 -2
- package/src/drizzle/pg-identity.ts +2 -2
- package/src/drizzle/phone-model.ts +3 -3
- package/src/drizzle/phone-target.ts +11 -4
- package/src/drizzle/sqlite-do-database.ts +87 -0
- package/src/drizzle/sqlite-emails.ts +1 -1
- package/src/drizzle/sqlite-identity.ts +2 -2
- package/src/drizzle/sqlite-passwords.ts +1 -1
- package/src/drizzle/sqlite-proofs.ts +2 -2
- package/src/drizzle/sqlite-sessions.ts +2 -2
- package/src/drizzle/storage-validation.ts +15 -6
- package/src/drizzle/totp-state.ts +8 -8
- package/src/drizzle/totp-target.ts +11 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-emails.mjs","names":[],"sources":["../../src/drizzle/sqlite-emails.ts"],"sourcesContent":["import { NativeDatabase } from \"@yielded/auth-persistence/Adapter\";\nimport { EmailAddressPersistence, type EmailUnavailable } from \"@yielded/auth/Email\";\nimport type { LifecycleHooks, HookConfigurationError } from \"@yielded/auth/Hooks\";\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 { EffectLibsqlDatabase } from \"drizzle-orm/effect-libsql\";\nimport type { EffectSQLiteBunDatabase } from \"drizzle-orm/effect-sqlite-bun\";\nimport type { EffectSQLiteDoDatabase as DODatabase } from \"drizzle-orm/effect-sqlite-do\";\nimport type { EffectSQLiteNodeDatabase as NodeDatabase } from \"drizzle-orm/effect-sqlite-node\";\nimport type { EffectSQLiteWasmDatabase as WasmDatabase } from \"drizzle-orm/effect-sqlite-wasm\";\nimport type { AnySQLiteTable } from \"drizzle-orm/sqlite-core\";\nimport { Effect, Context } from \"effect\";\nimport type { SqlError } from \"effect/sql/SqlError\";\n\nimport type {\n EmailAddressMapping,\n EmailRegistrationMapping,\n EmailSignInMapping,\n} from \"./email-model\";\nimport type { EmailRegistrationAuthority } from \"./email-registration\";\nimport { CurrentEmailSql } from \"./email-sql\";\nimport type { EmailSqlQuery } from \"./email-sql\";\nimport {\n coordinateTargetEmailAddress,\n coordinateTargetEmailRegistration,\n makeTargetEmailAddressServices,\n makeTargetEmailRegistrationServices,\n makeTargetEmailSignInServices,\n type EmailTargetConfiguration,\n} from \"./email-target\";\nimport { nativeDatabase } from \"./native-database\";\nimport type { ProofPersistenceMapping } from \"./proof-model\";\nimport type { ProofSqlQuery } from \"./proof-sql\";\nimport {\n type TransactionService,\n acquireTransactionService,\n transactionService,\n} from \"./standalone-guard\";\nimport type { SuppliedService } from \"./SuppliedService\";\n\nexport type SqliteEmailDatabase =\n | NodeDatabase<AnyRelations>\n | EffectSQLiteBunDatabase<AnyRelations>\n | EffectLibsqlDatabase<AnyRelations>\n | WasmDatabase<AnyRelations>\n | DODatabase<AnyRelations>;\n\ntype TransactionOf<D extends SqliteEmailDatabase> = Parameters<Parameters<D[\"transaction\"]>[0]>[0];\ntype 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\nexport const sqliteEmailConfiguration = (\n mode: \"interactive\" | \"synchronous\",\n standaloneGuard: EmailTargetConfiguration[\"standaloneGuard\"],\n proofStandaloneGuard: EmailTargetConfiguration[\"proof\"][\"standaloneGuard\"],\n coordinatorGuard?: EmailTargetConfiguration[\"coordinatorGuard\"],\n): EmailTargetConfiguration => ({\n mode,\n locking: false,\n standaloneGuard,\n ...(coordinatorGuard === undefined ? {} : { coordinatorGuard }),\n generatedSubjectRows: (query: EmailSqlQuery) => query.returning(),\n proof: {\n mode,\n locking: false,\n standaloneGuard: proofStandaloneGuard,\n insertIfAbsent: (query: ProofSqlQuery) => query.onConflictDoNothing(),\n },\n});\n\nexport const makeSqliteEmailTarget = <\n DatabaseId,\n D extends SqliteEmailDatabase,\n Synchronous extends boolean = false,\n>(\n databaseService: Context.Service<DatabaseId, D>,\n configuration:\n | EmailTargetConfiguration\n | ((service: TransactionService | undefined) => EmailTargetConfiguration),\n) => {\n const configurationFor = (database: D) =>\n typeof configuration === \"function\"\n ? configuration(transactionService(database))\n : configuration;\n\n const standaloneConfiguration =\n typeof configuration === \"function\"\n ? Effect.map(acquireTransactionService(databaseService), configuration)\n : Effect.succeed(configuration);\n\n function coordinateEmailAddress<\n Database extends D,\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n M extends AnySQLiteTable,\n NativeId,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n >(\n acquire: Effect.Effect<Database, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: EmailAddressMapping<S, I, C, AC, M, NativeId>;\n readonly proofMapping: ProofMapping;\n readonly transaction?: never;\n },\n body: Effect.Effect<Out, E, Synchronous extends true ? NoInfer<EmailAddressPersistence> : R>,\n ): Effect.Effect<\n Out,\n E | EmailUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, EmailAddressPersistence>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinateEmailAddress<\n Database extends D,\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n M extends AnySQLiteTable,\n NativeId,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n >(\n acquire: Effect.Effect<Database, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: EmailAddressMapping<S, I, C, AC, M, NativeId>;\n readonly proofMapping: ProofMapping;\n readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<Database>>, TxShape>;\n },\n body: Effect.Effect<\n Out,\n E,\n Synchronous extends true ? NoInfer<EmailAddressPersistence | TxId> : R\n >,\n ): Effect.Effect<\n Out,\n E | EmailUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, EmailAddressPersistence | TxId>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinateEmailAddress<\n Database extends D,\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n M extends AnySQLiteTable,\n NativeId,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n >(\n acquire: Effect.Effect<Database, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: EmailAddressMapping<S, I, C, AC, M, NativeId>;\n readonly proofMapping: ProofMapping;\n readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<Database>>, TxShape>;\n },\n body: Effect.Effect<Out, E, R>,\n ): Effect.Effect<\n Out,\n E | EmailUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, EmailAddressPersistence> | LifecycleHooks | DatabaseRequirements\n > {\n return Effect.flatMap(nativeDatabase(acquire), (database) =>\n coordinateTargetEmailAddress<\n TransactionOf<Database>,\n Out,\n E,\n Exclude<R, EmailAddressPersistence>\n >(\n database,\n options.mapping,\n options.proofMapping,\n configurationFor(database),\n (\n transaction: TransactionOf<Database>,\n services: { readonly emailAddressPersistence: EmailAddressPersistence[\"Service\"] },\n ) => {\n const provided = Context.make(EmailAddressPersistence, services.emailAddressPersistence);\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 ).pipe(Effect.provideService(NativeDatabase, database)),\n );\n }\n function coordinateEmailRegistration<\n Database extends D,\n TargetId,\n Registration,\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n Rq extends AnySQLiteTable,\n NativeId,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n >(\n acquire: Effect.Effect<Database, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: EmailRegistrationMapping<NoInfer<Registration>, S, I, C, AC, Rq, NativeId>;\n readonly proofMapping: ProofMapping;\n readonly target: SuppliedService<TargetId, EmailRegistrationAuthority<Registration>>;\n readonly transaction?: never;\n },\n body: Effect.Effect<Out, E, Synchronous extends true ? NoInfer<TargetId> : R>,\n ): Effect.Effect<\n Out,\n E | EmailUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, TargetId>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinateEmailRegistration<\n Database extends D,\n TargetId,\n Registration,\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n Rq extends AnySQLiteTable,\n NativeId,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n >(\n acquire: Effect.Effect<Database, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: EmailRegistrationMapping<NoInfer<Registration>, S, I, C, AC, Rq, NativeId>;\n readonly proofMapping: ProofMapping;\n readonly target: SuppliedService<TargetId, EmailRegistrationAuthority<Registration>>;\n readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<Database>>, TxShape>;\n },\n body: Effect.Effect<Out, E, Synchronous extends true ? NoInfer<TargetId | TxId> : R>,\n ): Effect.Effect<\n Out,\n E | EmailUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, TargetId | TxId>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinateEmailRegistration<\n Database extends D,\n TargetId,\n Registration,\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n Rq extends AnySQLiteTable,\n NativeId,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n >(\n acquire: Effect.Effect<Database, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: EmailRegistrationMapping<NoInfer<Registration>, S, I, C, AC, Rq, NativeId>;\n readonly proofMapping: ProofMapping;\n readonly target: SuppliedService<TargetId, EmailRegistrationAuthority<Registration>>;\n readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<Database>>, TxShape>;\n },\n body: Effect.Effect<Out, E, R>,\n ): Effect.Effect<\n Out,\n E | EmailUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, TargetId> | LifecycleHooks | DatabaseRequirements\n > {\n return Effect.flatMap(nativeDatabase(acquire), (database) =>\n coordinateTargetEmailRegistration<\n Registration,\n TransactionOf<Database>,\n Out,\n E,\n Exclude<R, TargetId>\n >(\n database,\n options.mapping,\n options.proofMapping,\n configurationFor(database),\n (\n transaction: TransactionOf<Database>,\n services: { readonly registrationAuthority: EmailRegistrationAuthority<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 ).pipe(Effect.provideService(NativeDatabase, database)),\n );\n }\n\n return {\n makeEmailSignInServices: <\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n NativeId,\n >(\n mapping: EmailSignInMapping<S, I, C, NativeId>,\n ) =>\n Effect.flatMap(standaloneConfiguration, (configuration) =>\n makeTargetEmailSignInServices(mapping, configuration),\n ).pipe(\n Effect.provideServiceEffect(CurrentEmailSql, nativeDatabase(databaseService)),\n Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),\n ),\n makeEmailAddressServices: <\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n M extends AnySQLiteTable,\n NativeId,\n >(\n mapping: EmailAddressMapping<S, I, C, AC, M, NativeId>,\n proofMapping: ProofMapping,\n ) =>\n Effect.flatMap(standaloneConfiguration, (configuration) =>\n makeTargetEmailAddressServices(mapping, proofMapping, configuration),\n ).pipe(\n Effect.provideServiceEffect(CurrentEmailSql, nativeDatabase(databaseService)),\n Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),\n ),\n coordinateEmailAddress,\n makeEmailRegistrationServices: <\n Registration,\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n Rq extends AnySQLiteTable,\n NativeId,\n >(\n mapping: EmailRegistrationMapping<Registration, S, I, C, AC, Rq, NativeId>,\n proofMapping: ProofMapping,\n ) =>\n Effect.flatMap(standaloneConfiguration, (configuration) =>\n makeTargetEmailRegistrationServices<Registration>(mapping, proofMapping, configuration),\n ).pipe(\n Effect.provideServiceEffect(CurrentEmailSql, nativeDatabase(databaseService)),\n Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),\n ),\n coordinateEmailRegistration,\n };\n};\n"],"mappings":";;;;;;;;AA+DA,MAAa,4BACX,MACA,iBACA,sBACA,sBAC8B;CAC9B;CACA,SAAS;CACT;CACA,GAAI,qBAAqB,KAAA,IAAY,CAAC,IAAI,EAAE,iBAAiB;CAC7D,uBAAuB,UAAyB,MAAM,UAAU;CAChE,OAAO;EACL;EACA,SAAS;EACT,iBAAiB;EACjB,iBAAiB,UAAyB,MAAM,oBAAoB;CACtE;AACF;AAEA,MAAa,yBAKX,iBACA,kBAGG;CACH,MAAM,oBAAoB,aACxB,OAAO,kBAAkB,aACrB,cAAc,mBAAmB,QAAQ,CAAC,IAC1C;CAEN,MAAM,0BACJ,OAAO,kBAAkB,aACrB,OAAO,IAAI,0BAA0B,eAAe,GAAG,aAAa,IACpE,OAAO,QAAQ,aAAa;CAgElC,SAAS,uBAgBP,SACA,SAKA,MAKA;EACA,OAAO,O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A,gCASE,SACA,iBAEA,OAAO,QAAQ,0BAA0B,kBACvC,oCAAkD,SAAS,cAAc,aAAa,CACxF,CAAC,CAAC,KACA,OAAO,qBAAqB,iBAAiB,eAAe,eAAe,CAAC,GAC5E,OAAO,qBAAqB,gBAAgB,eAAe,eAAe,CAAC,CAC7E;EACF;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"sqlite-emails.mjs","names":[],"sources":["../../src/drizzle/sqlite-emails.ts"],"sourcesContent":["import { NativeDatabase } from \"@yielded/auth-persistence/Adapter\";\nimport { EmailAddressPersistence, type EmailUnavailable } from \"@yielded/auth/Email\";\nimport type { LifecycleHooks, HookConfigurationError } from \"@yielded/auth/Hooks\";\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 { EffectLibsqlDatabase } from \"drizzle-orm/effect-libsql\";\nimport type { EffectSQLiteBunDatabase } from \"drizzle-orm/effect-sqlite-bun\";\nimport type { EffectSQLiteNodeDatabase as NodeDatabase } from \"drizzle-orm/effect-sqlite-node\";\nimport type { EffectSQLiteWasmDatabase as WasmDatabase } from \"drizzle-orm/effect-sqlite-wasm\";\nimport type { AnySQLiteTable } from \"drizzle-orm/sqlite-core\";\nimport { Effect, Context } from \"effect\";\nimport type { SqlError } from \"effect/sql/SqlError\";\n\nimport type {\n EmailAddressMapping,\n EmailRegistrationMapping,\n EmailSignInMapping,\n} from \"./email-model\";\nimport type { EmailRegistrationAuthority } from \"./email-registration\";\nimport { CurrentEmailSql } from \"./email-sql\";\nimport type { EmailSqlQuery } from \"./email-sql\";\nimport {\n coordinateTargetEmailAddress,\n coordinateTargetEmailRegistration,\n makeTargetEmailAddressServices,\n makeTargetEmailRegistrationServices,\n makeTargetEmailSignInServices,\n type EmailTargetConfiguration,\n} from \"./email-target\";\nimport { nativeDatabase } from \"./native-database\";\nimport type { ProofPersistenceMapping } from \"./proof-model\";\nimport type { ProofSqlQuery } from \"./proof-sql\";\nimport type { DatabaseValue as DODatabase } from \"./sqlite-do-database\";\nimport {\n type TransactionService,\n acquireTransactionService,\n transactionService,\n} from \"./standalone-guard\";\nimport type { SuppliedService } from \"./SuppliedService\";\n\nexport type SqliteEmailDatabase =\n | NodeDatabase<AnyRelations>\n | EffectSQLiteBunDatabase<AnyRelations>\n | EffectLibsqlDatabase<AnyRelations>\n | WasmDatabase<AnyRelations>\n | DODatabase<AnyRelations>;\n\ntype TransactionOf<D extends SqliteEmailDatabase> = Parameters<Parameters<D[\"transaction\"]>[0]>[0];\ntype 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\nexport const sqliteEmailConfiguration = (\n mode: \"interactive\" | \"synchronous\",\n standaloneGuard: EmailTargetConfiguration[\"standaloneGuard\"],\n proofStandaloneGuard: EmailTargetConfiguration[\"proof\"][\"standaloneGuard\"],\n coordinatorGuard?: EmailTargetConfiguration[\"coordinatorGuard\"],\n): EmailTargetConfiguration => ({\n mode,\n locking: false,\n standaloneGuard,\n ...(coordinatorGuard === undefined ? {} : { coordinatorGuard }),\n generatedSubjectRows: (query: EmailSqlQuery) => query.returning(),\n proof: {\n mode,\n locking: false,\n standaloneGuard: proofStandaloneGuard,\n insertIfAbsent: (query: ProofSqlQuery) => query.onConflictDoNothing(),\n },\n});\n\nexport const makeSqliteEmailTarget = <\n DatabaseId,\n D extends SqliteEmailDatabase,\n Synchronous extends boolean = false,\n>(\n databaseService: Context.Service<DatabaseId, D>,\n configuration:\n | EmailTargetConfiguration\n | ((service: TransactionService | undefined) => EmailTargetConfiguration),\n) => {\n const configurationFor = (database: D) =>\n typeof configuration === \"function\"\n ? configuration(transactionService(database))\n : configuration;\n\n const standaloneConfiguration =\n typeof configuration === \"function\"\n ? Effect.map(acquireTransactionService(databaseService), configuration)\n : Effect.succeed(configuration);\n\n function coordinateEmailAddress<\n Database extends D,\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n M extends AnySQLiteTable,\n NativeId,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n >(\n acquire: Effect.Effect<Database, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: EmailAddressMapping<S, I, C, AC, M, NativeId>;\n readonly proofMapping: ProofMapping;\n readonly transaction?: never;\n },\n body: Effect.Effect<Out, E, Synchronous extends true ? NoInfer<EmailAddressPersistence> : R>,\n ): Effect.Effect<\n Out,\n E | EmailUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, EmailAddressPersistence>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinateEmailAddress<\n Database extends D,\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n M extends AnySQLiteTable,\n NativeId,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n >(\n acquire: Effect.Effect<Database, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: EmailAddressMapping<S, I, C, AC, M, NativeId>;\n readonly proofMapping: ProofMapping;\n readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<Database>>, TxShape>;\n },\n body: Effect.Effect<\n Out,\n E,\n Synchronous extends true ? NoInfer<EmailAddressPersistence | TxId> : R\n >,\n ): Effect.Effect<\n Out,\n E | EmailUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, EmailAddressPersistence | TxId>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinateEmailAddress<\n Database extends D,\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n M extends AnySQLiteTable,\n NativeId,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n >(\n acquire: Effect.Effect<Database, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: EmailAddressMapping<S, I, C, AC, M, NativeId>;\n readonly proofMapping: ProofMapping;\n readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<Database>>, TxShape>;\n },\n body: Effect.Effect<Out, E, R>,\n ): Effect.Effect<\n Out,\n E | EmailUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, EmailAddressPersistence> | LifecycleHooks | DatabaseRequirements\n > {\n return Effect.flatMap(nativeDatabase(acquire), (database) =>\n coordinateTargetEmailAddress<\n TransactionOf<Database>,\n Out,\n E,\n Exclude<R, EmailAddressPersistence>\n >(\n database,\n options.mapping,\n options.proofMapping,\n configurationFor(database),\n (\n transaction: TransactionOf<Database>,\n services: { readonly emailAddressPersistence: EmailAddressPersistence[\"Service\"] },\n ) => {\n const provided = Context.make(EmailAddressPersistence, services.emailAddressPersistence);\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 ).pipe(Effect.provideService(NativeDatabase, database)),\n );\n }\n function coordinateEmailRegistration<\n Database extends D,\n TargetId,\n Registration,\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n Rq extends AnySQLiteTable,\n NativeId,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n >(\n acquire: Effect.Effect<Database, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: EmailRegistrationMapping<NoInfer<Registration>, S, I, C, AC, Rq, NativeId>;\n readonly proofMapping: ProofMapping;\n readonly target: SuppliedService<TargetId, EmailRegistrationAuthority<Registration>>;\n readonly transaction?: never;\n },\n body: Effect.Effect<Out, E, Synchronous extends true ? NoInfer<TargetId> : R>,\n ): Effect.Effect<\n Out,\n E | EmailUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, TargetId>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinateEmailRegistration<\n Database extends D,\n TargetId,\n Registration,\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n Rq extends AnySQLiteTable,\n NativeId,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n >(\n acquire: Effect.Effect<Database, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: EmailRegistrationMapping<NoInfer<Registration>, S, I, C, AC, Rq, NativeId>;\n readonly proofMapping: ProofMapping;\n readonly target: SuppliedService<TargetId, EmailRegistrationAuthority<Registration>>;\n readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<Database>>, TxShape>;\n },\n body: Effect.Effect<Out, E, Synchronous extends true ? NoInfer<TargetId | TxId> : R>,\n ): Effect.Effect<\n Out,\n E | EmailUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, TargetId | TxId>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinateEmailRegistration<\n Database extends D,\n TargetId,\n Registration,\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n Rq extends AnySQLiteTable,\n NativeId,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n >(\n acquire: Effect.Effect<Database, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: EmailRegistrationMapping<NoInfer<Registration>, S, I, C, AC, Rq, NativeId>;\n readonly proofMapping: ProofMapping;\n readonly target: SuppliedService<TargetId, EmailRegistrationAuthority<Registration>>;\n readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<Database>>, TxShape>;\n },\n body: Effect.Effect<Out, E, R>,\n ): Effect.Effect<\n Out,\n E | EmailUnavailable | HookConfigurationError | SqlError | DatabaseError,\n Exclude<R, TargetId> | LifecycleHooks | DatabaseRequirements\n > {\n return Effect.flatMap(nativeDatabase(acquire), (database) =>\n coordinateTargetEmailRegistration<\n Registration,\n TransactionOf<Database>,\n Out,\n E,\n Exclude<R, TargetId>\n >(\n database,\n options.mapping,\n options.proofMapping,\n configurationFor(database),\n (\n transaction: TransactionOf<Database>,\n services: { readonly registrationAuthority: EmailRegistrationAuthority<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 ).pipe(Effect.provideService(NativeDatabase, database)),\n );\n }\n\n return {\n makeEmailSignInServices: <\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n NativeId,\n >(\n mapping: EmailSignInMapping<S, I, C, NativeId>,\n ) =>\n Effect.flatMap(standaloneConfiguration, (configuration) =>\n makeTargetEmailSignInServices(mapping, configuration),\n ).pipe(\n Effect.provideServiceEffect(CurrentEmailSql, nativeDatabase(databaseService)),\n Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),\n ),\n makeEmailAddressServices: <\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n M extends AnySQLiteTable,\n NativeId,\n >(\n mapping: EmailAddressMapping<S, I, C, AC, M, NativeId>,\n proofMapping: ProofMapping,\n ) =>\n Effect.flatMap(standaloneConfiguration, (configuration) =>\n makeTargetEmailAddressServices(mapping, proofMapping, configuration),\n ).pipe(\n Effect.provideServiceEffect(CurrentEmailSql, nativeDatabase(databaseService)),\n Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),\n ),\n coordinateEmailAddress,\n makeEmailRegistrationServices: <\n Registration,\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n Rq extends AnySQLiteTable,\n NativeId,\n >(\n mapping: EmailRegistrationMapping<Registration, S, I, C, AC, Rq, NativeId>,\n proofMapping: ProofMapping,\n ) =>\n Effect.flatMap(standaloneConfiguration, (configuration) =>\n makeTargetEmailRegistrationServices<Registration>(mapping, proofMapping, configuration),\n ).pipe(\n Effect.provideServiceEffect(CurrentEmailSql, nativeDatabase(databaseService)),\n Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),\n ),\n coordinateEmailRegistration,\n };\n};\n"],"mappings":";;;;;;;;AA+DA,MAAa,4BACX,MACA,iBACA,sBACA,sBAC8B;CAC9B;CACA,SAAS;CACT;CACA,GAAI,qBAAqB,KAAA,IAAY,CAAC,IAAI,EAAE,iBAAiB;CAC7D,uBAAuB,UAAyB,MAAM,UAAU;CAChE,OAAO;EACL;EACA,SAAS;EACT,iBAAiB;EACjB,iBAAiB,UAAyB,MAAM,oBAAoB;CACtE;AACF;AAEA,MAAa,yBAKX,iBACA,kBAGG;CACH,MAAM,oBAAoB,aACxB,OAAO,kBAAkB,aACrB,cAAc,mBAAmB,QAAQ,CAAC,IAC1C;CAEN,MAAM,0BACJ,OAAO,kBAAkB,aACrB,OAAO,IAAI,0BAA0B,eAAe,GAAG,aAAa,IACpE,OAAO,QAAQ,aAAa;CAgElC,SAAS,uBAgBP,SACA,SAKA,MAKA;EACA,OAAO,OAAO,QAAQ,eAAe,OAAO,IAAI,aAC9C,6BAME,UACA,QAAQ,SACR,QAAQ,cACR,iBAAiB,QAAQ,IAEvB,aACA,aACG;GACH,MAAM,WAAW,QAAQ,KAAK,yBAAyB,SAAS,uBAAuB;GACvF,MAAM,OAAO,OAAO,eAAe,MAAM,QAAQ;GAEjD,OAAO,QAAQ,gBAAgB,KAAA,IAC3B,OACA,OAAO,eAAe,MAAM,QAAQ,aAAa,QAAQ,YAAY,GAAG,WAAW,CAAC;EAC1F,CACF,CAAC,CAAC,KAAK,OAAO,eAAe,gBAAgB,QAAQ,CAAC,CACxD;CACF;CAiEA,SAAS,4BAkBP,SACA,SAMA,MAKA;EACA,OAAO,OAAO,QAAQ,eAAe,OAAO,IAAI,aAC9C,kCAOE,UACA,QAAQ,SACR,QAAQ,cACR,iBAAiB,QAAQ,IAEvB,aACA,aACG;GACH,MAAM,WAAW,QAAQ,KAAK,QAAQ,QAAQ,SAAS,qBAAqB;GAC5E,MAAM,OAAO,OAAO,eAAe,MAAM,QAAQ;GAEjD,OAAO,QAAQ,gBAAgB,KAAA,IAC3B,OACA,OAAO,eAAe,MAAM,QAAQ,aAAa,QAAQ,YAAY,GAAG,WAAW,CAAC;EAC1F,CACF,CAAC,CAAC,KAAK,OAAO,eAAe,gBAAgB,QAAQ,CAAC,CACxD;CACF;CAEA,OAAO;EACL,0BAME,YAEA,OAAO,QAAQ,0BAA0B,kBACvC,8BAA8B,SAAS,aAAa,CACtD,CAAC,CAAC,KACA,OAAO,qBAAqB,iBAAiB,eAAe,eAAe,CAAC,GAC5E,OAAO,qBAAqB,gBAAgB,eAAe,eAAe,CAAC,CAC7E;EACF,2BAQE,SACA,iBAEA,OAAO,QAAQ,0BAA0B,kBACvC,+BAA+B,SAAS,cAAc,aAAa,CACrE,CAAC,CAAC,KACA,OAAO,qBAAqB,iBAAiB,eAAe,eAAe,CAAC,GAC5E,OAAO,qBAAqB,gBAAgB,eAAe,eAAe,CAAC,CAC7E;EACF;EACA,gCASE,SACA,iBAEA,OAAO,QAAQ,0BAA0B,kBACvC,oCAAkD,SAAS,cAAc,aAAa,CACxF,CAAC,CAAC,KACA,OAAO,qBAAqB,iBAAiB,eAAe,eAAe,CAAC,GAC5E,OAAO,qBAAqB,gBAAgB,eAAe,eAAe,CAAC,CAC7E;EACF;CACF;AACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PersistenceMappingError as PersistenceMappingError$1, column, isMappedConstraintConflict, provisioningFingerprint } from "./model.mjs";
|
|
2
2
|
import { validateDrizzleStorage } from "./storage-validation.mjs";
|
|
3
|
-
import { NativeDatabase } from "@yielded/auth-persistence/Adapter";
|
|
3
|
+
import { NativeDatabase, withStorageValidation } from "@yielded/auth-persistence/Adapter";
|
|
4
4
|
import { ExternalIdentityMutation, IdentityConflict, IdentityUnavailable, SubjectProvisioned, SubjectProvisioner } from "@yielded/auth/Identity";
|
|
5
5
|
import { and, eq } from "drizzle-orm";
|
|
6
6
|
import { Cause, Effect, Schema } from "effect";
|
|
@@ -91,7 +91,7 @@ const makeSqliteIdentityServices = Effect.fnUntraced(function* (mapping, mode) {
|
|
|
91
91
|
...yield* makeSqliteSubjectProvisioningServices(mapping, mode),
|
|
92
92
|
...yield* makeSqliteExternalIdentityServices(mapping)
|
|
93
93
|
};
|
|
94
|
-
});
|
|
94
|
+
}, withStorageValidation);
|
|
95
95
|
//#endregion
|
|
96
96
|
export { makeSqliteExternalIdentityServices, makeSqliteIdentityServices, makeSqliteSubjectProvisioningServices };
|
|
97
97
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-identity.mjs","names":["PersistenceMappingError"],"sources":["../../src/drizzle/sqlite-identity.ts"],"sourcesContent":["import { NativeDatabase } from \"@yielded/auth-persistence/Adapter\";\nimport {\n ExternalIdentityMutation,\n type ExternalIdentity,\n IdentityConflict,\n IdentityUnavailable,\n SubjectProvisioned,\n SubjectProvisioner,\n type SubjectProvisioningInput,\n} from \"@yielded/auth/Identity\";\nimport { reportPersistenceFailure } from \"@yielded/auth/Persistence\";\nimport type { SubjectId } from \"@yielded/auth/Schema\";\n/* oxlint-disable no-explicit-any -- Drizzle generic query types are narrowed at this technology boundary. */\nimport { and, eq } from \"drizzle-orm\";\nimport type { QueryEffectHKTBase } from \"drizzle-orm/effect-core\";\nimport type { AnySQLiteTable, SQLiteColumn } from \"drizzle-orm/sqlite-core\";\nimport type { SQLiteEffectDatabase } from \"drizzle-orm/sqlite-core/effect/db\";\nimport { Cause, Effect, Schema } from \"effect\";\n\nimport {\n column,\n isMappedConstraintConflict,\n PersistenceMappingError,\n provisioningFingerprint,\n type ExternalIdentityTables,\n type IdentityTables,\n type SubjectProvisioningTables,\n} from \"./model\";\nimport { validateDrizzleStorage } from \"./storage-validation\";\n\ntype ClosedQueryEffectHKT = QueryEffectHKTBase & { readonly context: never };\ntype RuntimeDatabase = SQLiteEffectDatabase<ClosedQueryEffectHKT, unknown, any>;\nconst unavailable = () => IdentityUnavailable.make();\nconst isIdentityFailure = Schema.is(Schema.Union([IdentityConflict, IdentityUnavailable]));\n\nconst mapUnavailable = <A, E, R>(effect: Effect.Effect<A, E, R>) =>\n reportPersistenceFailure(effect, isIdentityFailure).pipe(\n Effect.catchCause((cause) =>\n Effect.failCause(\n Cause.map(cause, (error) => (isIdentityFailure(error) ? error : unavailable())),\n ),\n ),\n );\n\nexport const makeSqliteSubjectProvisioningServices = Effect.fnUntraced(function* <\n Subject extends AnySQLiteTable,\n Identifier extends AnySQLiteTable,\n Request extends AnySQLiteTable,\n NativeId,\n>(\n mapping: SubjectProvisioningTables<Subject, Identifier, Request, NativeId>,\n mode: \"interactive\" | \"synchronous\",\n) {\n const database = yield* NativeDatabase;\n\n yield* validateDrizzleStorage(mapping).pipe(Effect.mapError(() => IdentityUnavailable.make()));\n\n const db = database as unknown as RuntimeDatabase;\n const requestTable = mapping.provisioningRequest.table;\n\n const requestIdColumn = column(\n requestTable,\n mapping.provisioningRequest.requestId,\n ) as SQLiteColumn;\n\n const requestFingerprintColumn = column(\n requestTable,\n mapping.provisioningRequest.fingerprint,\n ) as SQLiteColumn;\n\n const requestSubjectColumn = column(\n requestTable,\n mapping.provisioningRequest.subjectId,\n ) as SQLiteColumn;\n\n const identifierTable = mapping.identifier.table;\n\n const identifierNamespaceColumn = column(\n identifierTable,\n mapping.identifier.namespace,\n ) as SQLiteColumn;\n\n const identifierValueColumn = column(identifierTable, mapping.identifier.value) as SQLiteColumn;\n const subjectIdColumn = column(mapping.subject.table, mapping.subject.id) as SQLiteColumn;\n\n const findReceipt = Effect.fn(\"DrizzleSqliteIdentity.findReceipt\")(function* (requestId: string) {\n const rows = yield* db\n .select({ fingerprint: requestFingerprintColumn, subjectId: requestSubjectColumn })\n .from(requestTable as any)\n .where(eq(requestIdColumn, requestId))\n .limit(1);\n\n return rows[0];\n });\n\n const provision = Effect.fn(\"DrizzleSqliteIdentity.provision\")(function* (\n input: SubjectProvisioningInput,\n ) {\n if (\n mode === \"synchronous\" &&\n mapping.subject.allocateId !== undefined &&\n mapping.subject.allocateIdSync === undefined\n ) {\n return yield* unavailable();\n }\n const fingerprint = provisioningFingerprint(input);\n const existing = yield* findReceipt(input.requestId);\n\n if (existing !== undefined) {\n if (existing.fingerprint !== fingerprint) return yield* IdentityConflict.make();\n const subjectId = yield* mapping.subjectId.toSubject(existing.subjectId as NativeId);\n\n return SubjectProvisioned.make({ subjectId });\n }\n\n const attempt = db.transaction((tx) =>\n Effect.gen(function* () {\n const allocated =\n mode === \"synchronous\"\n ? mapping.subject.allocateIdSync?.()\n : mapping.subject.allocateId === undefined\n ? mapping.subject.allocateIdSync?.()\n : yield* mapping.subject.allocateId;\n\n const inserted = yield* tx\n .insert(mapping.subject.table as any)\n .values(mapping.subject.encodeInsert(input, allocated) as any)\n .returning({ id: subjectIdColumn });\n\n const nativeId = (inserted[0]?.id ?? allocated) as NativeId | undefined;\n\n if (nativeId === undefined)\n return yield* PersistenceMappingError.make({\n operation: \"provisionSubject.generatedId\",\n cause: new Error(\"subject insert did not return its native id\"),\n });\n if (input.identifier !== undefined)\n yield* tx\n .insert(identifierTable as any)\n .values(\n mapping.identifier.encodeInsert(input.identifier, nativeId, input.verifiedAt) as any,\n );\n yield* tx\n .insert(requestTable as any)\n .values(\n mapping.provisioningRequest.encodeInsert(input.requestId, fingerprint, nativeId) as any,\n );\n\n return nativeId;\n }),\n );\n\n const nativeId = yield* attempt.pipe(\n Effect.catchCause(\n (cause): Effect.Effect<NativeId, Effect.Error<typeof attempt> | IdentityConflict> => {\n if (\n cause.reasons.length === 0 ||\n !cause.reasons.every(\n (reason) =>\n Cause.isFailReason(reason) &&\n isMappedConstraintConflict(mapping.isConstraintConflict, reason.error),\n )\n )\n return Effect.failCause(cause);\n\n return findReceipt(input.requestId).pipe(\n Effect.flatMap((receipt) => {\n if (receipt !== undefined && receipt.fingerprint === fingerprint)\n return Effect.succeed(receipt.subjectId as NativeId);\n if (input.identifier === undefined) return IdentityConflict.make();\n\n return db\n .select({\n subjectId: column(identifierTable, mapping.identifier.subjectId) as SQLiteColumn,\n })\n .from(identifierTable as any)\n .where(\n and(\n eq(identifierNamespaceColumn, input.identifier.namespace),\n eq(identifierValueColumn, input.identifier.value),\n ),\n )\n .limit(1)\n .pipe(Effect.flatMap(() => IdentityConflict.make()));\n }),\n );\n },\n ),\n );\n\n const subjectId = yield* mapping.subjectId.toSubject(nativeId);\n\n return SubjectProvisioned.make({ subjectId });\n }, mapUnavailable);\n\n return { subjectProvisioner: SubjectProvisioner.of({ provision }) } as const;\n});\n\nexport const makeSqliteExternalIdentityServices = Effect.fnUntraced(function* <\n Subject extends AnySQLiteTable,\n External extends AnySQLiteTable,\n NativeId,\n>(mapping: ExternalIdentityTables<Subject, External, NativeId>) {\n const database = yield* NativeDatabase;\n\n yield* validateDrizzleStorage(mapping).pipe(Effect.mapError(() => IdentityUnavailable.make()));\n\n const db = database as unknown as RuntimeDatabase;\n const externalTable = mapping.externalIdentity.table;\n\n const externalProviderColumn = column(\n externalTable,\n mapping.externalIdentity.provider,\n ) as SQLiteColumn;\n\n const externalIssuerColumn = column(\n externalTable,\n mapping.externalIdentity.issuer,\n ) as SQLiteColumn;\n\n const externalSubjectColumn = column(\n externalTable,\n mapping.externalIdentity.subject,\n ) as SQLiteColumn;\n\n const externalSubjectIdColumn = column(\n externalTable,\n mapping.externalIdentity.subjectId,\n ) as SQLiteColumn;\n\n const subjectIdColumn = column(mapping.subject.table, mapping.subject.id) as SQLiteColumn;\n const subjectStatusColumn = column(mapping.subject.table, mapping.subject.status) as SQLiteColumn;\n\n const bind = Effect.fn(\"DrizzleSqliteIdentity.bindExternalIdentity\")(function* (\n subjectId: SubjectId,\n identity: ExternalIdentity,\n ) {\n const nativeId = yield* mapping.subjectId.toNative(subjectId);\n\n const decision = yield* db\n .transaction((tx) =>\n Effect.gen(function* () {\n const subjects = yield* tx\n .select({ status: subjectStatusColumn })\n .from(mapping.subject.table as any)\n .where(eq(subjectIdColumn, nativeId))\n .limit(1);\n\n if (subjects[0] === undefined || !mapping.subject.isActiveStatus(subjects[0].status))\n return { _tag: \"conflict\" } as const;\n\n const links = yield* tx\n .select({ subjectId: externalSubjectIdColumn })\n .from(externalTable as any)\n .where(\n and(\n eq(externalProviderColumn, identity.provider),\n eq(externalIssuerColumn, identity.issuer),\n eq(externalSubjectColumn, identity.subject),\n ),\n )\n .limit(1);\n\n if (links[0] !== undefined)\n return mapping.subjectId.equals(links[0].subjectId as NativeId, nativeId)\n ? ({ _tag: \"bound\" } as const)\n : ({ _tag: \"conflict\" } as const);\n yield* tx\n .insert(externalTable as any)\n .values(mapping.externalIdentity.encodeInsert(identity, nativeId) as any);\n\n return { _tag: \"bound\" } as const;\n }),\n )\n .pipe(\n Effect.catchCause((cause) => {\n if (\n cause.reasons.length === 0 ||\n !cause.reasons.every(\n (reason) =>\n Cause.isFailReason(reason) &&\n isMappedConstraintConflict(mapping.isConstraintConflict, reason.error),\n )\n )\n return Effect.failCause(cause);\n\n return db\n .select({ subjectId: externalSubjectIdColumn })\n .from(externalTable as any)\n .where(\n and(\n eq(externalProviderColumn, identity.provider),\n eq(externalIssuerColumn, identity.issuer),\n eq(externalSubjectColumn, identity.subject),\n ),\n )\n .limit(1)\n .pipe(\n Effect.map((rows) =>\n rows[0] !== undefined &&\n mapping.subjectId.equals(rows[0].subjectId as NativeId, nativeId)\n ? ({ _tag: \"bound\" } as const)\n : ({ _tag: \"conflict\" } as const),\n ),\n );\n }),\n );\n\n if (decision._tag === \"conflict\") return yield* IdentityConflict.make();\n }, mapUnavailable);\n\n return { externalIdentityMutation: ExternalIdentityMutation.of({ bind }) } as const;\n});\n\nexport const makeSqliteIdentityServices = Effect.fnUntraced(function* <\n Subject extends AnySQLiteTable,\n Identifier extends AnySQLiteTable,\n External extends AnySQLiteTable,\n Request extends AnySQLiteTable,\n NativeId,\n>(\n mapping: IdentityTables<Subject, Identifier, External, Request, NativeId>,\n mode: \"interactive\" | \"synchronous\",\n) {\n return {\n ...(yield* makeSqliteSubjectProvisioningServices(mapping, mode)),\n ...(yield* makeSqliteExternalIdentityServices(mapping)),\n };\n});\n"],"mappings":";;;;;;;;AAgCA,MAAM,oBAAoB,oBAAoB,KAAK;AACnD,MAAM,oBAAoB,OAAO,GAAG,OAAO,MAAM,CAAC,kBAAkB,mBAAmB,CAAC,CAAC;AAEzF,MAAM,kBAA2B,WAC/B,yBAAyB,QAAQ,iBAAiB,CAAC,CAAC,KAClD,OAAO,YAAY,UACjB,OAAO,UACL,MAAM,IAAI,QAAQ,UAAW,kBAAkB,KAAK,IAAI,QAAQ,YAAY,CAAE,CAChF,CACF,CACF;AAEF,MAAa,wCAAwC,OAAO,WAAW,WAMrE,SACA,MACA;CACA,MAAM,WAAW,OAAO;CAExB,OAAO,uBAAuB,OAAO,CAAC,CAAC,KAAK,OAAO,eAAe,oBAAoB,KAAK,CAAC,CAAC;CAE7F,MAAM,KAAK;CACX,MAAM,eAAe,QAAQ,oBAAoB;CAEjD,MAAM,kBAAkB,OACtB,cACA,QAAQ,oBAAoB,SAC9B;CAEA,MAAM,2BAA2B,OAC/B,cACA,QAAQ,oBAAoB,WAC9B;CAEA,MAAM,uBAAuB,OAC3B,cACA,QAAQ,oBAAoB,SAC9B;CAEA,MAAM,kBAAkB,QAAQ,WAAW;CAE3C,MAAM,4BAA4B,OAChC,iBACA,QAAQ,WAAW,SACrB;CAEA,MAAM,wBAAwB,OAAO,iBAAiB,QAAQ,WAAW,KAAK;CAC9E,MAAM,kBAAkB,OAAO,QAAQ,QAAQ,OAAO,QAAQ,QAAQ,EAAE;CAExE,MAAM,cAAc,OAAO,GAAG,mCAAmC,CAAC,CAAC,WAAW,WAAmB;EAO/F,QAAO,OANa,GACjB,OAAO;GAAE,aAAa;GAA0B,WAAW;EAAqB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,GACJ,OAAO,aAAoB,CAAC,CAC5B,OAAO,QAAQ,iBAAiB,aAAa,UAAU,QAAQ,CAAQ;GAE1E,OAAO,EAAE,MAAM,QAAQ;EACzB,CAAC,CACH,CAAC,CACA,KACC,OAAO,YAAY,UAAU;GAC3B,IACE,MAAM,QAAQ,WAAW,KACzB,CAAC,MAAM,QAAQ,OACZ,WACC,MAAM,aAAa,MAAM,KACzB,2BAA2B,QAAQ,sBAAsB,OAAO,KAAK,CACzE,GAEA,OAAO,OAAO,UAAU,KAAK;GAE/B,OAAO,GACJ,OAAO,EAAE,WAAW,wBAAwB,CAAC,CAAC,CAC9C,KAAK,aAAoB,CAAC,CAC1B,MACC,IACE,GAAG,wBAAwB,SAAS,QAAQ,GAC5C,GAAG,sBAAsB,SAAS,MAAM,GACxC,GAAG,uBAAuB,SAAS,OAAO,CAC5C,CACF,CAAC,CACA,MAAM,CAAC,CAAC,CACR,KACC,OAAO,KAAK,SACV,KAAK,OAAO,KAAA,KACZ,QAAQ,UAAU,OAAO,KAAK,EAAE,CAAC,WAAuB,QAAQ,IAC3D,EAAE,MAAM,QAAQ,IAChB,EAAE,MAAM,WAAW,CAC1B,CACF;EACJ,CAAC,CACH,EAAA,CAEW,SAAS,YAAY,OAAO,OAAO,iBAAiB,KAAK;CACxE,GAAG,cAAc;CAEjB,OAAO,EAAE,0BAA0B,yBAAyB,GAAG,EAAE,KAAK,CAAC,EAAE;AAC3E,CAAC;AAED,MAAa,6BAA6B,OAAO,WAAW,WAO1D,SACA,MACA;CACA,OAAO;EACL,GAAI,OAAO,sCAAsC,SAAS,IAAI;EAC9D,GAAI,OAAO,mCAAmC,OAAO;CACvD;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"sqlite-identity.mjs","names":["PersistenceMappingError"],"sources":["../../src/drizzle/sqlite-identity.ts"],"sourcesContent":["import { withStorageValidation, NativeDatabase } from \"@yielded/auth-persistence/Adapter\";\nimport {\n ExternalIdentityMutation,\n type ExternalIdentity,\n IdentityConflict,\n IdentityUnavailable,\n SubjectProvisioned,\n SubjectProvisioner,\n type SubjectProvisioningInput,\n} from \"@yielded/auth/Identity\";\nimport { reportPersistenceFailure } from \"@yielded/auth/Persistence\";\nimport type { SubjectId } from \"@yielded/auth/Schema\";\n/* oxlint-disable no-explicit-any -- Drizzle generic query types are narrowed at this technology boundary. */\nimport { and, eq } from \"drizzle-orm\";\nimport type { QueryEffectHKTBase } from \"drizzle-orm/effect-core\";\nimport type { AnySQLiteTable, SQLiteColumn } from \"drizzle-orm/sqlite-core\";\nimport type { SQLiteEffectDatabase } from \"drizzle-orm/sqlite-core/effect/db\";\nimport { Cause, Effect, Schema } from \"effect\";\n\nimport {\n column,\n isMappedConstraintConflict,\n PersistenceMappingError,\n provisioningFingerprint,\n type ExternalIdentityTables,\n type IdentityTables,\n type SubjectProvisioningTables,\n} from \"./model\";\nimport { validateDrizzleStorage } from \"./storage-validation\";\n\ntype ClosedQueryEffectHKT = QueryEffectHKTBase & { readonly context: never };\ntype RuntimeDatabase = SQLiteEffectDatabase<ClosedQueryEffectHKT, unknown, any>;\nconst unavailable = () => IdentityUnavailable.make();\nconst isIdentityFailure = Schema.is(Schema.Union([IdentityConflict, IdentityUnavailable]));\n\nconst mapUnavailable = <A, E, R>(effect: Effect.Effect<A, E, R>) =>\n reportPersistenceFailure(effect, isIdentityFailure).pipe(\n Effect.catchCause((cause) =>\n Effect.failCause(\n Cause.map(cause, (error) => (isIdentityFailure(error) ? error : unavailable())),\n ),\n ),\n );\n\nexport const makeSqliteSubjectProvisioningServices = Effect.fnUntraced(function* <\n Subject extends AnySQLiteTable,\n Identifier extends AnySQLiteTable,\n Request extends AnySQLiteTable,\n NativeId,\n>(\n mapping: SubjectProvisioningTables<Subject, Identifier, Request, NativeId>,\n mode: \"interactive\" | \"synchronous\",\n) {\n const database = yield* NativeDatabase;\n\n yield* validateDrizzleStorage(mapping).pipe(Effect.mapError(() => IdentityUnavailable.make()));\n\n const db = database as unknown as RuntimeDatabase;\n const requestTable = mapping.provisioningRequest.table;\n\n const requestIdColumn = column(\n requestTable,\n mapping.provisioningRequest.requestId,\n ) as SQLiteColumn;\n\n const requestFingerprintColumn = column(\n requestTable,\n mapping.provisioningRequest.fingerprint,\n ) as SQLiteColumn;\n\n const requestSubjectColumn = column(\n requestTable,\n mapping.provisioningRequest.subjectId,\n ) as SQLiteColumn;\n\n const identifierTable = mapping.identifier.table;\n\n const identifierNamespaceColumn = column(\n identifierTable,\n mapping.identifier.namespace,\n ) as SQLiteColumn;\n\n const identifierValueColumn = column(identifierTable, mapping.identifier.value) as SQLiteColumn;\n const subjectIdColumn = column(mapping.subject.table, mapping.subject.id) as SQLiteColumn;\n\n const findReceipt = Effect.fn(\"DrizzleSqliteIdentity.findReceipt\")(function* (requestId: string) {\n const rows = yield* db\n .select({ fingerprint: requestFingerprintColumn, subjectId: requestSubjectColumn })\n .from(requestTable as any)\n .where(eq(requestIdColumn, requestId))\n .limit(1);\n\n return rows[0];\n });\n\n const provision = Effect.fn(\"DrizzleSqliteIdentity.provision\")(function* (\n input: SubjectProvisioningInput,\n ) {\n if (\n mode === \"synchronous\" &&\n mapping.subject.allocateId !== undefined &&\n mapping.subject.allocateIdSync === undefined\n ) {\n return yield* unavailable();\n }\n const fingerprint = provisioningFingerprint(input);\n const existing = yield* findReceipt(input.requestId);\n\n if (existing !== undefined) {\n if (existing.fingerprint !== fingerprint) return yield* IdentityConflict.make();\n const subjectId = yield* mapping.subjectId.toSubject(existing.subjectId as NativeId);\n\n return SubjectProvisioned.make({ subjectId });\n }\n\n const attempt = db.transaction((tx) =>\n Effect.gen(function* () {\n const allocated =\n mode === \"synchronous\"\n ? mapping.subject.allocateIdSync?.()\n : mapping.subject.allocateId === undefined\n ? mapping.subject.allocateIdSync?.()\n : yield* mapping.subject.allocateId;\n\n const inserted = yield* tx\n .insert(mapping.subject.table as any)\n .values(mapping.subject.encodeInsert(input, allocated) as any)\n .returning({ id: subjectIdColumn });\n\n const nativeId = (inserted[0]?.id ?? allocated) as NativeId | undefined;\n\n if (nativeId === undefined)\n return yield* PersistenceMappingError.make({\n operation: \"provisionSubject.generatedId\",\n cause: new Error(\"subject insert did not return its native id\"),\n });\n if (input.identifier !== undefined)\n yield* tx\n .insert(identifierTable as any)\n .values(\n mapping.identifier.encodeInsert(input.identifier, nativeId, input.verifiedAt) as any,\n );\n yield* tx\n .insert(requestTable as any)\n .values(\n mapping.provisioningRequest.encodeInsert(input.requestId, fingerprint, nativeId) as any,\n );\n\n return nativeId;\n }),\n );\n\n const nativeId = yield* attempt.pipe(\n Effect.catchCause(\n (cause): Effect.Effect<NativeId, Effect.Error<typeof attempt> | IdentityConflict> => {\n if (\n cause.reasons.length === 0 ||\n !cause.reasons.every(\n (reason) =>\n Cause.isFailReason(reason) &&\n isMappedConstraintConflict(mapping.isConstraintConflict, reason.error),\n )\n )\n return Effect.failCause(cause);\n\n return findReceipt(input.requestId).pipe(\n Effect.flatMap((receipt) => {\n if (receipt !== undefined && receipt.fingerprint === fingerprint)\n return Effect.succeed(receipt.subjectId as NativeId);\n if (input.identifier === undefined) return IdentityConflict.make();\n\n return db\n .select({\n subjectId: column(identifierTable, mapping.identifier.subjectId) as SQLiteColumn,\n })\n .from(identifierTable as any)\n .where(\n and(\n eq(identifierNamespaceColumn, input.identifier.namespace),\n eq(identifierValueColumn, input.identifier.value),\n ),\n )\n .limit(1)\n .pipe(Effect.flatMap(() => IdentityConflict.make()));\n }),\n );\n },\n ),\n );\n\n const subjectId = yield* mapping.subjectId.toSubject(nativeId);\n\n return SubjectProvisioned.make({ subjectId });\n }, mapUnavailable);\n\n return { subjectProvisioner: SubjectProvisioner.of({ provision }) } as const;\n});\n\nexport const makeSqliteExternalIdentityServices = Effect.fnUntraced(function* <\n Subject extends AnySQLiteTable,\n External extends AnySQLiteTable,\n NativeId,\n>(mapping: ExternalIdentityTables<Subject, External, NativeId>) {\n const database = yield* NativeDatabase;\n\n yield* validateDrizzleStorage(mapping).pipe(Effect.mapError(() => IdentityUnavailable.make()));\n\n const db = database as unknown as RuntimeDatabase;\n const externalTable = mapping.externalIdentity.table;\n\n const externalProviderColumn = column(\n externalTable,\n mapping.externalIdentity.provider,\n ) as SQLiteColumn;\n\n const externalIssuerColumn = column(\n externalTable,\n mapping.externalIdentity.issuer,\n ) as SQLiteColumn;\n\n const externalSubjectColumn = column(\n externalTable,\n mapping.externalIdentity.subject,\n ) as SQLiteColumn;\n\n const externalSubjectIdColumn = column(\n externalTable,\n mapping.externalIdentity.subjectId,\n ) as SQLiteColumn;\n\n const subjectIdColumn = column(mapping.subject.table, mapping.subject.id) as SQLiteColumn;\n const subjectStatusColumn = column(mapping.subject.table, mapping.subject.status) as SQLiteColumn;\n\n const bind = Effect.fn(\"DrizzleSqliteIdentity.bindExternalIdentity\")(function* (\n subjectId: SubjectId,\n identity: ExternalIdentity,\n ) {\n const nativeId = yield* mapping.subjectId.toNative(subjectId);\n\n const decision = yield* db\n .transaction((tx) =>\n Effect.gen(function* () {\n const subjects = yield* tx\n .select({ status: subjectStatusColumn })\n .from(mapping.subject.table as any)\n .where(eq(subjectIdColumn, nativeId))\n .limit(1);\n\n if (subjects[0] === undefined || !mapping.subject.isActiveStatus(subjects[0].status))\n return { _tag: \"conflict\" } as const;\n\n const links = yield* tx\n .select({ subjectId: externalSubjectIdColumn })\n .from(externalTable as any)\n .where(\n and(\n eq(externalProviderColumn, identity.provider),\n eq(externalIssuerColumn, identity.issuer),\n eq(externalSubjectColumn, identity.subject),\n ),\n )\n .limit(1);\n\n if (links[0] !== undefined)\n return mapping.subjectId.equals(links[0].subjectId as NativeId, nativeId)\n ? ({ _tag: \"bound\" } as const)\n : ({ _tag: \"conflict\" } as const);\n yield* tx\n .insert(externalTable as any)\n .values(mapping.externalIdentity.encodeInsert(identity, nativeId) as any);\n\n return { _tag: \"bound\" } as const;\n }),\n )\n .pipe(\n Effect.catchCause((cause) => {\n if (\n cause.reasons.length === 0 ||\n !cause.reasons.every(\n (reason) =>\n Cause.isFailReason(reason) &&\n isMappedConstraintConflict(mapping.isConstraintConflict, reason.error),\n )\n )\n return Effect.failCause(cause);\n\n return db\n .select({ subjectId: externalSubjectIdColumn })\n .from(externalTable as any)\n .where(\n and(\n eq(externalProviderColumn, identity.provider),\n eq(externalIssuerColumn, identity.issuer),\n eq(externalSubjectColumn, identity.subject),\n ),\n )\n .limit(1)\n .pipe(\n Effect.map((rows) =>\n rows[0] !== undefined &&\n mapping.subjectId.equals(rows[0].subjectId as NativeId, nativeId)\n ? ({ _tag: \"bound\" } as const)\n : ({ _tag: \"conflict\" } as const),\n ),\n );\n }),\n );\n\n if (decision._tag === \"conflict\") return yield* IdentityConflict.make();\n }, mapUnavailable);\n\n return { externalIdentityMutation: ExternalIdentityMutation.of({ bind }) } as const;\n});\n\nexport const makeSqliteIdentityServices = Effect.fnUntraced(function* <\n Subject extends AnySQLiteTable,\n Identifier extends AnySQLiteTable,\n External extends AnySQLiteTable,\n Request extends AnySQLiteTable,\n NativeId,\n>(\n mapping: IdentityTables<Subject, Identifier, External, Request, NativeId>,\n mode: \"interactive\" | \"synchronous\",\n) {\n return {\n ...(yield* makeSqliteSubjectProvisioningServices(mapping, mode)),\n ...(yield* makeSqliteExternalIdentityServices(mapping)),\n };\n}, withStorageValidation);\n"],"mappings":";;;;;;;;AAgCA,MAAM,oBAAoB,oBAAoB,KAAK;AACnD,MAAM,oBAAoB,OAAO,GAAG,OAAO,MAAM,CAAC,kBAAkB,mBAAmB,CAAC,CAAC;AAEzF,MAAM,kBAA2B,WAC/B,yBAAyB,QAAQ,iBAAiB,CAAC,CAAC,KAClD,OAAO,YAAY,UACjB,OAAO,UACL,MAAM,IAAI,QAAQ,UAAW,kBAAkB,KAAK,IAAI,QAAQ,YAAY,CAAE,CAChF,CACF,CACF;AAEF,MAAa,wCAAwC,OAAO,WAAW,WAMrE,SACA,MACA;CACA,MAAM,WAAW,OAAO;CAExB,OAAO,uBAAuB,OAAO,CAAC,CAAC,KAAK,OAAO,eAAe,oBAAoB,KAA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,IAC3D,EAAE,MAAM,QAAQ,IAChB,EAAE,MAAM,WAAW,CAC1B,CACF;EACJ,CAAC,CACH,EAAA,CAEW,SAAS,YAAY,OAAO,OAAO,iBAAiB,KAAK;CACxE,GAAG,cAAc;CAEjB,OAAO,EAAE,0BAA0B,yBAAyB,GAAG,EAAE,KAAK,CAAC,EAAE;AAC3E,CAAC;AAED,MAAa,6BAA6B,OAAO,WAAW,WAO1D,SACA,MACA;CACA,OAAO;EACL,GAAI,OAAO,sCAAsC,SAAS,IAAI;EAC9D,GAAI,OAAO,mCAAmC,OAAO;CACvD;AACF,GAAG,qBAAqB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-passwords.mjs","names":[],"sources":["../../src/drizzle/sqlite-passwords.ts"],"sourcesContent":["import { NativeDatabase } from \"@yielded/auth-persistence/Adapter\";\nimport 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 { EffectLibsqlDatabase } from \"drizzle-orm/effect-libsql\";\nimport type { EffectSQLiteBunDatabase } from \"drizzle-orm/effect-sqlite-bun\";\nimport type { EffectSQLiteDoDatabase as DODatabase } from \"drizzle-orm/effect-sqlite-do\";\nimport type { EffectSQLiteNodeDatabase as NodeDatabase } from \"drizzle-orm/effect-sqlite-node\";\nimport type { EffectSQLiteWasmDatabase as WasmDatabase } from \"drizzle-orm/effect-sqlite-wasm\";\nimport type { AnySQLiteTable } from \"drizzle-orm/sqlite-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 type PasswordTargetConfiguration,\n} from \"./password-target\";\nimport type { ProofPersistenceMapping } from \"./proof-model\";\nimport type { ProofSqlQuery } from \"./proof-sql\";\nimport {\n type TransactionService,\n acquireTransactionService,\n transactionService,\n} from \"./standalone-guard\";\nimport type { SuppliedService } from \"./SuppliedService\";\n\nexport type SqlitePasswordDatabase =\n | NodeDatabase<AnyRelations>\n | EffectSQLiteBunDatabase<AnyRelations>\n | EffectLibsqlDatabase<AnyRelations>\n | WasmDatabase<AnyRelations>\n | DODatabase<AnyRelations>;\n\ntype TransactionOf<D extends SqlitePasswordDatabase> = Parameters<\n Parameters<D[\"transaction\"]>[0]\n>[0];\n\nexport const sqlitePasswordConfiguration = (\n mode: \"interactive\" | \"synchronous\",\n standaloneGuard: PasswordTargetConfiguration[\"standaloneGuard\"],\n proofStandaloneGuard: PasswordTargetConfiguration[\"proof\"][\"standaloneGuard\"],\n coordinatorGuard?: PasswordTargetConfiguration[\"coordinatorGuard\"],\n): PasswordTargetConfiguration => ({\n mode,\n locking: false,\n standaloneGuard,\n ...(coordinatorGuard === undefined ? {} : { coordinatorGuard }),\n insertIfAbsent: (query: PasswordSqlQuery) => query.onConflictDoNothing(),\n generatedSubjectRows: (query: PasswordSqlQuery) => query.returning(),\n proof: {\n mode,\n locking: false,\n standaloneGuard: proofStandaloneGuard,\n insertIfAbsent: (query: ProofSqlQuery) => query.onConflictDoNothing(),\n },\n});\n\ntype Mapping<\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n A extends AnySQLiteTable,\n RS extends AnySQLiteTable,\n CE extends AnySQLiteTable,\n M extends AnySQLiteTable,\n NativeId,\n> = PasswordPersistenceMapping<S, I, C, AC, A, RS, CE, M, NativeId>;\n\nexport const makeSqlitePasswordPersistenceServices = <\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n A extends AnySQLiteTable,\n RS extends AnySQLiteTable,\n CE extends AnySQLiteTable,\n M extends AnySQLiteTable,\n NativeId,\n>(\n mapping: Mapping<S, I, C, AC, A, RS, CE, M, NativeId>,\n configuration: PasswordTargetConfiguration,\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) => makeTargetPasswordPersistenceServices(mapping, configuration, proofMapping);\n\nexport const coordinateSqlitePasswordPersistence = <\n D extends SqlitePasswordDatabase,\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n A extends AnySQLiteTable,\n RS extends AnySQLiteTable,\n CE extends AnySQLiteTable,\n M extends AnySQLiteTable,\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>(\n database: D,\n mapping: Mapping<S, I, C, AC, A, RS, CE, M, NativeId>,\n configuration: PasswordTargetConfiguration,\n proofMapping: PM,\n owner: (\n transaction: TransactionOf<D>,\n services: { readonly passwordPersistence: PasswordPersistence[\"Service\"] },\n ) => Effect.Effect<Out, E, R>,\n) =>\n coordinateTargetPasswordPersistence<TransactionOf<D>, Out, E, R>(\n database,\n mapping,\n configuration,\n proofMapping,\n owner,\n );\n\nexport const makeSqlitePasswordRegistrationServices = <\n Registration,\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n Rq extends AnySQLiteTable,\n NativeId,\n>(\n mapping: PasswordRegistrationMapping<Registration, S, I, C, AC, Rq, NativeId>,\n configuration: PasswordTargetConfiguration,\n) => makeTargetPasswordRegistrationServices<Registration>(mapping, configuration);\n\nexport const coordinateSqlitePasswordRegistration = <\n Registration,\n D extends SqlitePasswordDatabase,\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n Rq extends AnySQLiteTable,\n NativeId,\n Out,\n E,\n R,\n>(\n database: D,\n mapping: PasswordRegistrationMapping<Registration, S, I, C, AC, Rq, NativeId>,\n configuration: PasswordTargetConfiguration,\n owner: (\n transaction: TransactionOf<D>,\n services: { readonly registrationAuthority: PasswordRegistrationAuthority<Registration> },\n ) => Effect.Effect<Out, E, R>,\n) =>\n coordinateTargetPasswordRegistration<Registration, TransactionOf<D>, Out, E, R>(\n database,\n mapping,\n configuration,\n owner,\n );\n\nexport const makeSqlitePasswordTarget = <\n DatabaseId,\n D extends SqlitePasswordDatabase,\n Synchronous extends boolean = false,\n>(\n databaseService: Context.Service<DatabaseId, D>,\n configuration:\n | PasswordTargetConfiguration\n | ((service: TransactionService | undefined) => PasswordTargetConfiguration),\n) => {\n const configurationFor = (database: D) =>\n typeof configuration === \"function\"\n ? configuration(transactionService(database))\n : configuration;\n\n const standaloneConfiguration =\n typeof configuration === \"function\"\n ? Effect.map(acquireTransactionService(databaseService), configuration)\n : Effect.succeed(configuration);\n\n function coordinatePasswordPersistence<\n Database extends D,\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n A extends AnySQLiteTable,\n RS extends AnySQLiteTable,\n CE extends AnySQLiteTable,\n M extends AnySQLiteTable,\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<Database, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: Mapping<S, I, C, AC, A, RS, CE, M, NativeId>;\n readonly proofMapping?: PM;\n readonly transaction?: never;\n },\n body: Effect.Effect<Out, E, Synchronous extends true ? NoInfer<PasswordPersistence> : R>,\n ): Effect.Effect<\n Out,\n E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, PasswordPersistence>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinatePasswordPersistence<\n Database extends D,\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n A extends AnySQLiteTable,\n RS extends AnySQLiteTable,\n CE extends AnySQLiteTable,\n M extends AnySQLiteTable,\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<Database, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: Mapping<S, I, C, AC, A, RS, CE, M, NativeId>;\n readonly proofMapping?: PM;\n readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<Database>>, TxShape>;\n },\n body: Effect.Effect<Out, E, Synchronous extends true ? NoInfer<PasswordPersistence | TxId> : R>,\n ): Effect.Effect<\n Out,\n E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, PasswordPersistence | TxId>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinatePasswordPersistence<\n Database extends D,\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n A extends AnySQLiteTable,\n RS extends AnySQLiteTable,\n CE extends AnySQLiteTable,\n M extends AnySQLiteTable,\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<Database, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: Mapping<S, I, C, AC, A, RS, CE, M, NativeId>;\n readonly proofMapping?: PM;\n readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<Database>>, 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(nativeDatabase(acquire), (database) =>\n coordinateSqlitePasswordPersistence(\n database,\n options.mapping,\n configurationFor(database),\n options.proofMapping,\n (\n transaction: TransactionOf<Database>,\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 ).pipe(Effect.provideService(NativeDatabase, database)),\n );\n }\n function coordinatePasswordRegistration<\n Database extends D,\n TargetId,\n Registration,\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n Rq extends AnySQLiteTable,\n NativeId,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n >(\n acquire: Effect.Effect<Database, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PasswordRegistrationMapping<\n NoInfer<Registration>,\n S,\n I,\n C,\n AC,\n Rq,\n NativeId\n >;\n readonly target: SuppliedService<TargetId, PasswordRegistrationAuthority<Registration>>;\n readonly transaction?: never;\n },\n body: Effect.Effect<Out, E, Synchronous extends true ? NoInfer<TargetId> : R>,\n ): Effect.Effect<\n Out,\n E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, TargetId>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinatePasswordRegistration<\n Database extends D,\n TargetId,\n Registration,\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n Rq extends AnySQLiteTable,\n NativeId,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n >(\n acquire: Effect.Effect<Database, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PasswordRegistrationMapping<\n NoInfer<Registration>,\n S,\n I,\n C,\n AC,\n Rq,\n NativeId\n >;\n readonly target: SuppliedService<TargetId, PasswordRegistrationAuthority<Registration>>;\n readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<Database>>, TxShape>;\n },\n body: Effect.Effect<Out, E, Synchronous extends true ? NoInfer<TargetId | TxId> : R>,\n ): Effect.Effect<\n Out,\n E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, TargetId | TxId>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinatePasswordRegistration<\n Database extends D,\n TargetId,\n Registration,\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n Rq extends AnySQLiteTable,\n NativeId,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n >(\n acquire: Effect.Effect<Database, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PasswordRegistrationMapping<\n NoInfer<Registration>,\n S,\n I,\n C,\n AC,\n Rq,\n NativeId\n >;\n readonly target: SuppliedService<TargetId, PasswordRegistrationAuthority<Registration>>;\n readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<Database>>, 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(nativeDatabase(acquire), (database) =>\n coordinateSqlitePasswordRegistration(\n database,\n options.mapping,\n configurationFor(database),\n (\n transaction: TransactionOf<Database>,\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 ).pipe(Effect.provideService(NativeDatabase, database)),\n );\n }\n\n return {\n makePasswordPersistenceServices: <\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n A extends AnySQLiteTable,\n RS extends AnySQLiteTable,\n CE extends AnySQLiteTable,\n M extends AnySQLiteTable,\n NativeId,\n >(\n mapping: Mapping<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(standaloneConfiguration, (configuration) =>\n makeSqlitePasswordPersistenceServices(mapping, configuration, proofMapping),\n ).pipe(\n Effect.provideServiceEffect(CurrentPasswordSql, nativeDatabase(databaseService)),\n Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),\n ),\n coordinatePasswordPersistence,\n makePasswordRegistrationServices: <\n Registration,\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n Rq extends AnySQLiteTable,\n NativeId,\n >(\n mapping: PasswordRegistrationMapping<Registration, S, I, C, AC, Rq, NativeId>,\n ) =>\n Effect.flatMap(standaloneConfiguration, (configuration) =>\n makeSqlitePasswordRegistrationServices(mapping, configuration),\n ).pipe(\n Effect.provideServiceEffect(CurrentPasswordSql, nativeDatabase(databaseService)),\n Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),\n ),\n coordinatePasswordRegistration,\n };\n};\n"],"mappings":";;;;;;;;AA8CA,MAAa,+BACX,MACA,iBACA,sBACA,sBACiC;CACjC;CACA,SAAS;CACT;CACA,GAAI,qBAAqB,KAAA,IAAY,CAAC,IAAI,EAAE,iBAAiB;CAC7D,iBAAiB,UAA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Q,SAAS,qBAAqB;GAC5E,MAAM,OAAO,OAAO,eAAe,MAAM,QAAQ;GAEjD,OAAO,QAAQ,gBAAgB,KAAA,IAC3B,OACA,OAAO,eAAe,MAAM,QAAQ,aAAa,QAAQ,YAAY,GAAG,WAAW,CAAC;EAC1F,CACF,CAAC,CAAC,KAAK,OAAO,eAAe,gBAAgB,QAAQ,CAAC,CACxD;CACF;CAEA,OAAO;EACL,kCAWE,SACA,iBAeA,OAAO,QAAQ,0BAA0B,kBACvC,sCAAsC,SAAS,eAAe,YAAY,CAC5E,CAAC,CAAC,KACA,OAAO,qBAAqB,oBAAoB,eAAe,eAAe,CAAC,GAC/E,OAAO,qBAAqB,gBAAgB,eAAe,eAAe,CAAC,CAC7E;EACF;EACA,mCASE,YAEA,OAAO,QAAQ,0BAA0B,kBACvC,uCAAuC,SAAS,aAAa,CAC/D,CAAC,CAAC,KACA,OAAO,qBAAqB,oBAAoB,eAAe,eAAe,CAAC,GAC/E,OAAO,qBAAqB,gBAAgB,eAAe,eAAe,CAAC,CAC7E;EACF;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"sqlite-passwords.mjs","names":[],"sources":["../../src/drizzle/sqlite-passwords.ts"],"sourcesContent":["import { NativeDatabase } from \"@yielded/auth-persistence/Adapter\";\nimport 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 { EffectLibsqlDatabase } from \"drizzle-orm/effect-libsql\";\nimport type { EffectSQLiteBunDatabase } from \"drizzle-orm/effect-sqlite-bun\";\nimport type { EffectSQLiteNodeDatabase as NodeDatabase } from \"drizzle-orm/effect-sqlite-node\";\nimport type { EffectSQLiteWasmDatabase as WasmDatabase } from \"drizzle-orm/effect-sqlite-wasm\";\nimport type { AnySQLiteTable } from \"drizzle-orm/sqlite-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 type PasswordTargetConfiguration,\n} from \"./password-target\";\nimport type { ProofPersistenceMapping } from \"./proof-model\";\nimport type { ProofSqlQuery } from \"./proof-sql\";\nimport type { DatabaseValue as DODatabase } from \"./sqlite-do-database\";\nimport {\n type TransactionService,\n acquireTransactionService,\n transactionService,\n} from \"./standalone-guard\";\nimport type { SuppliedService } from \"./SuppliedService\";\n\nexport type SqlitePasswordDatabase =\n | NodeDatabase<AnyRelations>\n | EffectSQLiteBunDatabase<AnyRelations>\n | EffectLibsqlDatabase<AnyRelations>\n | WasmDatabase<AnyRelations>\n | DODatabase<AnyRelations>;\n\ntype TransactionOf<D extends SqlitePasswordDatabase> = Parameters<\n Parameters<D[\"transaction\"]>[0]\n>[0];\n\nexport const sqlitePasswordConfiguration = (\n mode: \"interactive\" | \"synchronous\",\n standaloneGuard: PasswordTargetConfiguration[\"standaloneGuard\"],\n proofStandaloneGuard: PasswordTargetConfiguration[\"proof\"][\"standaloneGuard\"],\n coordinatorGuard?: PasswordTargetConfiguration[\"coordinatorGuard\"],\n): PasswordTargetConfiguration => ({\n mode,\n locking: false,\n standaloneGuard,\n ...(coordinatorGuard === undefined ? {} : { coordinatorGuard }),\n insertIfAbsent: (query: PasswordSqlQuery) => query.onConflictDoNothing(),\n generatedSubjectRows: (query: PasswordSqlQuery) => query.returning(),\n proof: {\n mode,\n locking: false,\n standaloneGuard: proofStandaloneGuard,\n insertIfAbsent: (query: ProofSqlQuery) => query.onConflictDoNothing(),\n },\n});\n\ntype Mapping<\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n A extends AnySQLiteTable,\n RS extends AnySQLiteTable,\n CE extends AnySQLiteTable,\n M extends AnySQLiteTable,\n NativeId,\n> = PasswordPersistenceMapping<S, I, C, AC, A, RS, CE, M, NativeId>;\n\nexport const makeSqlitePasswordPersistenceServices = <\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n A extends AnySQLiteTable,\n RS extends AnySQLiteTable,\n CE extends AnySQLiteTable,\n M extends AnySQLiteTable,\n NativeId,\n>(\n mapping: Mapping<S, I, C, AC, A, RS, CE, M, NativeId>,\n configuration: PasswordTargetConfiguration,\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) => makeTargetPasswordPersistenceServices(mapping, configuration, proofMapping);\n\nexport const coordinateSqlitePasswordPersistence = <\n D extends SqlitePasswordDatabase,\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n A extends AnySQLiteTable,\n RS extends AnySQLiteTable,\n CE extends AnySQLiteTable,\n M extends AnySQLiteTable,\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>(\n database: D,\n mapping: Mapping<S, I, C, AC, A, RS, CE, M, NativeId>,\n configuration: PasswordTargetConfiguration,\n proofMapping: PM,\n owner: (\n transaction: TransactionOf<D>,\n services: { readonly passwordPersistence: PasswordPersistence[\"Service\"] },\n ) => Effect.Effect<Out, E, R>,\n) =>\n coordinateTargetPasswordPersistence<TransactionOf<D>, Out, E, R>(\n database,\n mapping,\n configuration,\n proofMapping,\n owner,\n );\n\nexport const makeSqlitePasswordRegistrationServices = <\n Registration,\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n Rq extends AnySQLiteTable,\n NativeId,\n>(\n mapping: PasswordRegistrationMapping<Registration, S, I, C, AC, Rq, NativeId>,\n configuration: PasswordTargetConfiguration,\n) => makeTargetPasswordRegistrationServices<Registration>(mapping, configuration);\n\nexport const coordinateSqlitePasswordRegistration = <\n Registration,\n D extends SqlitePasswordDatabase,\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n Rq extends AnySQLiteTable,\n NativeId,\n Out,\n E,\n R,\n>(\n database: D,\n mapping: PasswordRegistrationMapping<Registration, S, I, C, AC, Rq, NativeId>,\n configuration: PasswordTargetConfiguration,\n owner: (\n transaction: TransactionOf<D>,\n services: { readonly registrationAuthority: PasswordRegistrationAuthority<Registration> },\n ) => Effect.Effect<Out, E, R>,\n) =>\n coordinateTargetPasswordRegistration<Registration, TransactionOf<D>, Out, E, R>(\n database,\n mapping,\n configuration,\n owner,\n );\n\nexport const makeSqlitePasswordTarget = <\n DatabaseId,\n D extends SqlitePasswordDatabase,\n Synchronous extends boolean = false,\n>(\n databaseService: Context.Service<DatabaseId, D>,\n configuration:\n | PasswordTargetConfiguration\n | ((service: TransactionService | undefined) => PasswordTargetConfiguration),\n) => {\n const configurationFor = (database: D) =>\n typeof configuration === \"function\"\n ? configuration(transactionService(database))\n : configuration;\n\n const standaloneConfiguration =\n typeof configuration === \"function\"\n ? Effect.map(acquireTransactionService(databaseService), configuration)\n : Effect.succeed(configuration);\n\n function coordinatePasswordPersistence<\n Database extends D,\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n A extends AnySQLiteTable,\n RS extends AnySQLiteTable,\n CE extends AnySQLiteTable,\n M extends AnySQLiteTable,\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<Database, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: Mapping<S, I, C, AC, A, RS, CE, M, NativeId>;\n readonly proofMapping?: PM;\n readonly transaction?: never;\n },\n body: Effect.Effect<Out, E, Synchronous extends true ? NoInfer<PasswordPersistence> : R>,\n ): Effect.Effect<\n Out,\n E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, PasswordPersistence>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinatePasswordPersistence<\n Database extends D,\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n A extends AnySQLiteTable,\n RS extends AnySQLiteTable,\n CE extends AnySQLiteTable,\n M extends AnySQLiteTable,\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<Database, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: Mapping<S, I, C, AC, A, RS, CE, M, NativeId>;\n readonly proofMapping?: PM;\n readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<Database>>, TxShape>;\n },\n body: Effect.Effect<Out, E, Synchronous extends true ? NoInfer<PasswordPersistence | TxId> : R>,\n ): Effect.Effect<\n Out,\n E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, PasswordPersistence | TxId>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinatePasswordPersistence<\n Database extends D,\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n A extends AnySQLiteTable,\n RS extends AnySQLiteTable,\n CE extends AnySQLiteTable,\n M extends AnySQLiteTable,\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<Database, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: Mapping<S, I, C, AC, A, RS, CE, M, NativeId>;\n readonly proofMapping?: PM;\n readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<Database>>, 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(nativeDatabase(acquire), (database) =>\n coordinateSqlitePasswordPersistence(\n database,\n options.mapping,\n configurationFor(database),\n options.proofMapping,\n (\n transaction: TransactionOf<Database>,\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 ).pipe(Effect.provideService(NativeDatabase, database)),\n );\n }\n function coordinatePasswordRegistration<\n Database extends D,\n TargetId,\n Registration,\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n Rq extends AnySQLiteTable,\n NativeId,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n >(\n acquire: Effect.Effect<Database, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PasswordRegistrationMapping<\n NoInfer<Registration>,\n S,\n I,\n C,\n AC,\n Rq,\n NativeId\n >;\n readonly target: SuppliedService<TargetId, PasswordRegistrationAuthority<Registration>>;\n readonly transaction?: never;\n },\n body: Effect.Effect<Out, E, Synchronous extends true ? NoInfer<TargetId> : R>,\n ): Effect.Effect<\n Out,\n E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, TargetId>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinatePasswordRegistration<\n Database extends D,\n TargetId,\n Registration,\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n Rq extends AnySQLiteTable,\n NativeId,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n >(\n acquire: Effect.Effect<Database, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PasswordRegistrationMapping<\n NoInfer<Registration>,\n S,\n I,\n C,\n AC,\n Rq,\n NativeId\n >;\n readonly target: SuppliedService<TargetId, PasswordRegistrationAuthority<Registration>>;\n readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<Database>>, TxShape>;\n },\n body: Effect.Effect<Out, E, Synchronous extends true ? NoInfer<TargetId | TxId> : R>,\n ): Effect.Effect<\n Out,\n E | PasswordUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, TargetId | TxId>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinatePasswordRegistration<\n Database extends D,\n TargetId,\n Registration,\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n Rq extends AnySQLiteTable,\n NativeId,\n Out,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n >(\n acquire: Effect.Effect<Database, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: PasswordRegistrationMapping<\n NoInfer<Registration>,\n S,\n I,\n C,\n AC,\n Rq,\n NativeId\n >;\n readonly target: SuppliedService<TargetId, PasswordRegistrationAuthority<Registration>>;\n readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<Database>>, 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(nativeDatabase(acquire), (database) =>\n coordinateSqlitePasswordRegistration(\n database,\n options.mapping,\n configurationFor(database),\n (\n transaction: TransactionOf<Database>,\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 ).pipe(Effect.provideService(NativeDatabase, database)),\n );\n }\n\n return {\n makePasswordPersistenceServices: <\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n A extends AnySQLiteTable,\n RS extends AnySQLiteTable,\n CE extends AnySQLiteTable,\n M extends AnySQLiteTable,\n NativeId,\n >(\n mapping: Mapping<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(standaloneConfiguration, (configuration) =>\n makeSqlitePasswordPersistenceServices(mapping, configuration, proofMapping),\n ).pipe(\n Effect.provideServiceEffect(CurrentPasswordSql, nativeDatabase(databaseService)),\n Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),\n ),\n coordinatePasswordPersistence,\n makePasswordRegistrationServices: <\n Registration,\n S extends AnySQLiteTable,\n I extends AnySQLiteTable,\n C extends AnySQLiteTable,\n AC extends AnySQLiteTable,\n Rq extends AnySQLiteTable,\n NativeId,\n >(\n mapping: PasswordRegistrationMapping<Registration, S, I, C, AC, Rq, NativeId>,\n ) =>\n Effect.flatMap(standaloneConfiguration, (configuration) =>\n makeSqlitePasswordRegistrationServices(mapping, configuration),\n ).pipe(\n Effect.provideServiceEffect(CurrentPasswordSql, nativeDatabase(databaseService)),\n Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),\n ),\n coordinatePasswordRegistration,\n };\n};\n"],"mappings":";;;;;;;;AA8CA,MAAa,+BACX,MACA,iBACA,sBACA,sBACiC;CACjC;CACA,SAAS;CACT;CACA,GAAI,qBAAqB,KAAA,IAAY,CAAC,IAAI,EAAE,iBAAiB;CAC7D,iBAAiB,UAA4B,MAAM,oBAAoB;CACvE,uBAAuB,UAA4B,MAAM,UAAU;CACnE,OAAO;EACL;EACA,SAAS;EACT,iBAAiB;EACjB,iBAAiB,UAAyB,MAAM,oBAAoB;CACtE;AACF;AAcA,MAAa,yCAWX,SACA,eACA,iBAcG,sCAAsC,SAAS,eAAe,YAAY;AAE/E,MAAa,uCAkBX,UACA,SACA,eACA,cACA,UAKA,oCACE,UACA,SACA,eACA,cACA,KACF;AAEF,MAAa,0CASX,SACA,kBACG,uCAAqD,SAAS,aAAa;AAEhF,MAAa,wCAaX,UACA,SACA,eACA,UAKA,qCACE,UACA,SACA,eACA,KACF;AAEF,MAAa,4BAKX,iBACA,kBAGG;CACH,MAAM,oBAAoB,aACxB,OAAO,kBAAkB,aACrB,cAAc,mBAAmB,QAAQ,CAAC,IAC1C;CAEN,MAAM,0BACJ,OAAO,kBAAkB,aACrB,OAAO,IAAI,0BAA0B,eAAe,GAAG,aAAa,IACpE,OAAO,QAAQ,aAAa;CAwElC,SAAS,8BAsBP,SACA,SAKA,MAKA;EACA,OAAO,OAAO,QAAQ,eAAe,OAAO,IAAI,aAC9C,oCACE,UACA,QAAQ,SACR,iBAAiB,QAAQ,GACzB,QAAQ,eAEN,aACA,aACG;GACH,MAAM,WAAW,QAAQ,KAAK,qBAAqB,SAAS,mBAAmB;GAC/E,MAAM,OAAO,OAAO,eAAe,MAAM,QAAQ;GAEjD,OAAO,QAAQ,gBAAgB,KAAA,IAC3B,OACA,OAAO,eAAe,MAAM,QAAQ,aAAa,QAAQ,YAAY,GAAG,WAAW,CAAC;EAC1F,CACF,CAAC,CAAC,KAAK,OAAO,eAAe,gBAAgB,QAAQ,CAAC,CACxD;CACF;CA+EA,SAAS,+BAkBP,SACA,SAaA,MAKA;EACA,OAAO,OAAO,QAAQ,eAAe,OAAO,IAAI,aAC9C,qCACE,UACA,QAAQ,SACR,iBAAiB,QAAQ,IAEvB,aACA,aACG;GACH,MAAM,WAAW,QAAQ,KAAK,QAAQ,QAAQ,SAAS,qBAAqB;GAC5E,MAAM,OAAO,OAAO,eAAe,MAAM,QAAQ;GAEjD,OAAO,QAAQ,gBAAgB,KAAA,IAC3B,OACA,OAAO,eAAe,MAAM,QAAQ,aAAa,QAAQ,YAAY,GAAG,WAAW,CAAC;EAC1F,CACF,CAAC,CAAC,KAAK,OAAO,eAAe,gBAAgB,QAAQ,CAAC,CACxD;CACF;CAEA,OAAO;EACL,kCAWE,SACA,iBAeA,OAAO,QAAQ,0BAA0B,kBACvC,sCAAsC,SAAS,eAAe,YAAY,CAC5E,CAAC,CAAC,KACA,OAAO,qBAAqB,oBAAoB,eAAe,eAAe,CAAC,GAC/E,OAAO,qBAAqB,gBAAgB,eAAe,eAAe,CAAC,CAC7E;EACF;EACA,mCASE,YAEA,OAAO,QAAQ,0BAA0B,kBACvC,uCAAuC,SAAS,aAAa,CAC/D,CAAC,CAAC,KACA,OAAO,qBAAqB,oBAAoB,eAAe,eAAe,CAAC,GAC/E,OAAO,qBAAqB,gBAAgB,eAAe,eAAe,CAAC,CAC7E;EACF;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-proofs.mjs","names":[],"sources":["../../src/drizzle/sqlite-proofs.ts"],"sourcesContent":["import { NativeDatabase } from \"@yielded/auth-persistence/Adapter\";\nimport type { LifecycleHooks, HookConfigurationError } from \"@yielded/auth/Hooks\";\nimport { type ProofUnavailable, ProofPersistence } from \"@yielded/auth/Proofs\";\nimport type { AnyRelations } from \"drizzle-orm\";\nimport type { EffectLibsqlDatabase } from \"drizzle-orm/effect-libsql\";\nimport type { EffectSQLiteBunDatabase } from \"drizzle-orm/effect-sqlite-bun\";\nimport type {
|
|
1
|
+
{"version":3,"file":"sqlite-proofs.mjs","names":[],"sources":["../../src/drizzle/sqlite-proofs.ts"],"sourcesContent":["import { NativeDatabase } from \"@yielded/auth-persistence/Adapter\";\nimport type { LifecycleHooks, HookConfigurationError } from \"@yielded/auth/Hooks\";\nimport { type ProofUnavailable, ProofPersistence } from \"@yielded/auth/Proofs\";\nimport type { AnyRelations } from \"drizzle-orm\";\nimport type { EffectLibsqlDatabase } from \"drizzle-orm/effect-libsql\";\nimport type { EffectSQLiteBunDatabase } from \"drizzle-orm/effect-sqlite-bun\";\nimport type { EffectSQLiteNodeDatabase } from \"drizzle-orm/effect-sqlite-node\";\nimport type { EffectSQLiteWasmDatabase } from \"drizzle-orm/effect-sqlite-wasm\";\nimport type { AnySQLiteTable } from \"drizzle-orm/sqlite-core\";\nimport { Effect, Context } from \"effect\";\nimport type { SqlError } from \"effect/sql/SqlError\";\n\nimport { nativeDatabase } from \"./native-database\";\nimport type { ProofPersistenceMapping } from \"./proof-model\";\nimport { CurrentProofSql } from \"./proof-sql\";\nimport {\n coordinateTargetProofPersistence,\n makeTargetProofPersistenceServices,\n type ProofTargetConfiguration,\n} from \"./proof-target\";\nimport type { DatabaseValue } from \"./sqlite-do-database\";\nimport {\n type TransactionService,\n acquireTransactionService,\n transactionService,\n} from \"./standalone-guard\";\nimport type { SuppliedService } from \"./SuppliedService\";\n\ntype Database =\n | EffectLibsqlDatabase<AnyRelations>\n | EffectSQLiteBunDatabase<AnyRelations>\n | DatabaseValue<AnyRelations>\n | EffectSQLiteNodeDatabase<AnyRelations>\n | EffectSQLiteWasmDatabase<AnyRelations>;\ntype TransactionOf<D extends Database> = Parameters<Parameters<D[\"transaction\"]>[0]>[0];\ntype Mapping<\n Rq extends AnySQLiteTable,\n S extends AnySQLiteTable,\n G extends AnySQLiteTable,\n Cn extends AnySQLiteTable,\n Rs extends AnySQLiteTable,\n A extends AnySQLiteTable,\n F extends AnySQLiteTable,\n C extends AnySQLiteTable,\n Sub extends AnySQLiteTable,\n I extends AnySQLiteTable,\n Cr extends AnySQLiteTable,\n NativeId,\n> = ProofPersistenceMapping<Rq, S, G, Cn, Rs, A, F, C, Sub, I, Cr, NativeId>;\n\nexport const sqliteProofConfiguration = (\n mode: \"interactive\" | \"synchronous\",\n standaloneGuard: Effect.Effect<void, ProofUnavailable>,\n coordinatorGuard?: Effect.Effect<void, ProofUnavailable>,\n): ProofTargetConfiguration => ({\n mode,\n locking: false,\n standaloneGuard,\n insertIfAbsent: (query) => query.onConflictDoNothing(),\n ...(coordinatorGuard === undefined ? {} : { coordinatorGuard }),\n});\n\nexport const makeSqliteProofTarget = <\n DatabaseId,\n D extends Database,\n Synchronous extends boolean = false,\n>(\n databaseService: Context.Service<DatabaseId, D>,\n configuration:\n | ProofTargetConfiguration\n | ((service: TransactionService | undefined) => ProofTargetConfiguration),\n) => {\n const configurationFor = (database: D) =>\n typeof configuration === \"function\"\n ? configuration(transactionService(database))\n : configuration;\n\n const standaloneConfiguration =\n typeof configuration === \"function\"\n ? Effect.map(acquireTransactionService(databaseService), configuration)\n : Effect.succeed(configuration);\n\n function coordinateProofPersistence<\n Database extends D,\n Rq extends AnySQLiteTable,\n S extends AnySQLiteTable,\n G extends AnySQLiteTable,\n Cn extends AnySQLiteTable,\n Rs extends AnySQLiteTable,\n Aev extends AnySQLiteTable,\n F extends AnySQLiteTable,\n C extends AnySQLiteTable,\n Sub extends AnySQLiteTable,\n I extends AnySQLiteTable,\n Cr extends AnySQLiteTable,\n NativeId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n >(\n acquire: Effect.Effect<Database, 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, Synchronous extends true ? NoInfer<ProofPersistence> : R>,\n ): Effect.Effect<\n A,\n E | ProofUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, ProofPersistence>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinateProofPersistence<\n Database extends D,\n Rq extends AnySQLiteTable,\n S extends AnySQLiteTable,\n G extends AnySQLiteTable,\n Cn extends AnySQLiteTable,\n Rs extends AnySQLiteTable,\n Aev extends AnySQLiteTable,\n F extends AnySQLiteTable,\n C extends AnySQLiteTable,\n Sub extends AnySQLiteTable,\n I extends AnySQLiteTable,\n Cr extends AnySQLiteTable,\n NativeId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n >(\n acquire: Effect.Effect<Database, 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<Database>>, TxShape>;\n },\n body: Effect.Effect<A, E, Synchronous extends true ? NoInfer<ProofPersistence | TxId> : R>,\n ): Effect.Effect<\n A,\n E | ProofUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, ProofPersistence | TxId>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinateProofPersistence<\n Database extends D,\n Rq extends AnySQLiteTable,\n S extends AnySQLiteTable,\n G extends AnySQLiteTable,\n Cn extends AnySQLiteTable,\n Rs extends AnySQLiteTable,\n Aev extends AnySQLiteTable,\n F extends AnySQLiteTable,\n C extends AnySQLiteTable,\n Sub extends AnySQLiteTable,\n I extends AnySQLiteTable,\n Cr extends AnySQLiteTable,\n NativeId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n >(\n acquire: Effect.Effect<Database, 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<Database>>, 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(nativeDatabase(acquire), (database) =>\n coordinateTargetProofPersistence<TransactionOf<Database>, A, E, Exclude<R, ProofPersistence>>(\n database,\n options.mapping,\n configurationFor(database),\n (\n transaction: TransactionOf<Database>,\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 ).pipe(Effect.provideService(NativeDatabase, database)),\n );\n }\n\n return {\n makeProofPersistenceServices: <\n Rq extends AnySQLiteTable,\n S extends AnySQLiteTable,\n G extends AnySQLiteTable,\n Cn extends AnySQLiteTable,\n Rs extends AnySQLiteTable,\n A extends AnySQLiteTable,\n F extends AnySQLiteTable,\n C extends AnySQLiteTable,\n Sub extends AnySQLiteTable,\n I extends AnySQLiteTable,\n Cr extends AnySQLiteTable,\n NativeId,\n >(\n mapping: Mapping<Rq, S, G, Cn, Rs, A, F, C, Sub, I, Cr, NativeId>,\n ) =>\n Effect.flatMap(standaloneConfiguration, (configuration) =>\n makeTargetProofPersistenceServices(mapping, configuration),\n ).pipe(\n Effect.provideServiceEffect(CurrentProofSql, nativeDatabase(databaseService)),\n Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),\n ),\n coordinateProofPersistence,\n };\n};\n"],"mappings":";;;;;;;;AAkDA,MAAa,4BACX,MACA,iBACA,sBAC8B;CAC9B;CACA,SAAS;CACT;CACA,iBAAiB,UAAU,MAAM,oBAAoB;CACrD,GAAI,qBAAqB,KAAA,IAAY,CAAC,IAAI,EAAE,iBAAiB;AAC/D;AAEA,MAAa,yBAKX,iBACA,kBAGG;CACH,MAAM,oBAAoB,aACxB,OAAO,kBAAkB,aACrB,cAAc,mBAAmB,QAAQ,CAAC,IAC1C;CAEN,MAAM,0BACJ,OAAO,kBAAkB,aACrB,OAAO,IAAI,0BAA0B,eAAe,GAAG,aAAa,IACpE,OAAO,QAAQ,aAAa;CAsElC,SAAS,2BAsBP,SACA,SAIA,MAKA;EACA,OAAO,OAAO,QAAQ,eAAe,OAAO,IAAI,aAC9C,iCACE,UACA,QAAQ,SACR,iBAAiB,QAAQ,IAEvB,aACA,aACG;GACH,MAAM,WAAW,QAAQ,KAAK,kBAAkB,SAAS,gBAAgB;GACzE,MAAM,OAAO,OAAO,eAAe,MAAM,QAAQ;GAEjD,OAAO,QAAQ,gBAAgB,KAAA,IAC3B,OACA,OAAO,eAAe,MAAM,QAAQ,aAAa,QAAQ,YAAY,GAAG,WAAW,CAAC;EAC1F,CACF,CAAC,CAAC,KAAK,OAAO,eAAe,gBAAgB,QAAQ,CAAC,CACxD;CACF;CAEA,OAAO;EACL,+BAcE,YAEA,OAAO,QAAQ,0BAA0B,kBACvC,mCAAmC,SAAS,aAAa,CAC3D,CAAC,CAAC,KACA,OAAO,qBAAqB,iBAAiB,eAAe,eAAe,CAAC,GAC5E,OAAO,qBAAqB,gBAAgB,eAAe,eAAe,CAAC,CAC7E;EACF;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-sessions.mjs","names":[],"sources":["../../src/drizzle/sqlite-sessions.ts"],"sourcesContent":["import { NativeDatabase } from \"@yielded/auth-persistence/Adapter\";\nimport 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 { EffectLibsqlDatabase } from \"drizzle-orm/effect-libsql\";\nimport type { EffectSQLiteBunDatabase } from \"drizzle-orm/effect-sqlite-bun\";\nimport type { EffectSQLiteDoDatabase } from \"drizzle-orm/effect-sqlite-do\";\nimport type { EffectSQLiteNodeDatabase } from \"drizzle-orm/effect-sqlite-node\";\nimport type { EffectSQLiteWasmDatabase } from \"drizzle-orm/effect-sqlite-wasm\";\nimport type { AnySQLiteTable } from \"drizzle-orm/sqlite-core\";\nimport { Context, Effect } from \"effect\";\nimport type { SqlError } from \"effect/sql/SqlError\";\n\nimport { nativeDatabase } from \"./native-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 type SessionTargetConfiguration,\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 =\n | EffectLibsqlDatabase<AnyRelations>\n | EffectSQLiteBunDatabase<AnyRelations>\n | EffectSQLiteDoDatabase<AnyRelations>\n | EffectSQLiteNodeDatabase<AnyRelations>\n | EffectSQLiteWasmDatabase<AnyRelations>;\ntype TransactionOf<D extends Database> = Parameters<Parameters<D[\"transaction\"]>[0]>[0];\n\nexport const sqliteSessionConfiguration = (\n mode: \"interactive\" | \"synchronous\",\n standaloneGuard: Effect.Effect<void, SessionUnavailable>,\n coordinatorGuard?: Effect.Effect<void, SessionUnavailable>,\n): SessionTargetConfiguration => ({\n mode,\n locking: false,\n standaloneGuard,\n ...(coordinatorGuard === undefined ? {} : { coordinatorGuard }),\n});\n\nexport const makeSqliteAuthenticationAuthorityServices = <\n Claims,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n F extends AnySQLiteTable,\n P extends AnySQLiteTable,\n NativeId,\n>(\n mapping: AuthenticationAuthorityMapping<Claims, S, C, F, P, NativeId>,\n configuration: SessionTargetConfiguration,\n) => makeTargetAuthenticationAuthorityServices<Claims>(mapping, configuration);\n\nexport const makeSqlitePendingAuthenticationServices = <\n Claims,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n P extends AnySQLiteTable,\n F extends AnySQLiteTable,\n NativeId,\n>(\n mapping: PendingAuthenticationMapping<Claims, S, C, P, F, NativeId>,\n configuration: SessionTargetConfiguration,\n) => makeTargetPendingAuthenticationServices<Claims>(mapping, configuration);\n\nexport const makeSqliteStatefulSessionServices = <\n Claims,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n Session extends AnySQLiteTable,\n F extends AnySQLiteTable,\n P extends AnySQLiteTable,\n NativeId,\n NativeSessionId,\n>(\n mapping: StatefulSessionMapping<Claims, S, C, Session, F, P, NativeId, NativeSessionId>,\n configuration: SessionTargetConfiguration,\n) => makeTargetStatefulSessionServices<Claims>(mapping, configuration);\n\nexport const makeSqliteSignedSessionValidityServices = <\n S extends AnySQLiteTable,\n T extends AnySQLiteTable,\n NativeId,\n NativeSessionId,\n>(\n mapping: SignedSessionValidityMapping<S, T, NativeId, NativeSessionId>,\n configuration: SessionTargetConfiguration,\n) => makeTargetSignedSessionValidityServices(mapping, configuration);\n\nexport const coordinateSqliteAuthenticationAuthority = <\n Claims,\n D extends Database,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n F extends AnySQLiteTable,\n P extends AnySQLiteTable,\n NativeId,\n A,\n E,\n R,\n>(\n database: D,\n mapping: AuthenticationAuthorityMapping<Claims, S, C, F, P, NativeId>,\n configuration: SessionTargetConfiguration,\n owner: (\n transaction: TransactionOf<D>,\n services: { readonly authenticationAuthority: AuthenticationAuthority[\"Service\"] },\n ) => Effect.Effect<A, E, R>,\n) =>\n coordinateTargetAuthenticationAuthority<Claims, TransactionOf<D>, A, E, R>(\n database,\n mapping,\n configuration,\n owner,\n );\n\nexport const coordinateSqlitePendingAuthentication = <\n Claims,\n D extends Database,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n P extends AnySQLiteTable,\n F extends AnySQLiteTable,\n NativeId,\n A,\n E,\n R,\n>(\n database: D,\n mapping: PendingAuthenticationMapping<Claims, S, C, P, F, NativeId>,\n configuration: SessionTargetConfiguration,\n owner: (\n transaction: TransactionOf<D>,\n services: { readonly pendingAuthentication: PendingAuthentication<Claims> },\n ) => Effect.Effect<A, E, R>,\n) =>\n coordinateTargetPendingAuthentication<Claims, TransactionOf<D>, A, E, R>(\n database,\n mapping,\n configuration,\n owner,\n );\n\nexport const coordinateSqliteStatefulSessions = <\n Claims,\n D extends Database,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n Session extends AnySQLiteTable,\n F extends AnySQLiteTable,\n P extends AnySQLiteTable,\n NativeId,\n NativeSessionId,\n A,\n E,\n R,\n>(\n database: D,\n mapping: StatefulSessionMapping<Claims, S, C, Session, F, P, NativeId, NativeSessionId>,\n configuration: SessionTargetConfiguration,\n owner: (\n transaction: TransactionOf<D>,\n services: {\n readonly statefulSessionPersistence: StatefulSessionPersistence<Claims>;\n readonly sessionRepository: SessionRepository;\n },\n ) => Effect.Effect<A, E, R>,\n) =>\n coordinateTargetStatefulSessions<Claims, TransactionOf<D>, A, E, R>(\n database,\n mapping,\n configuration,\n owner,\n );\n\nexport const coordinateSqliteSignedSessionValidity = <\n D extends Database,\n S extends AnySQLiteTable,\n T extends AnySQLiteTable,\n NativeId,\n NativeSessionId,\n A,\n E,\n R,\n>(\n database: D,\n mapping: SignedSessionValidityMapping<S, T, NativeId, NativeSessionId>,\n configuration: SessionTargetConfiguration,\n owner: (\n transaction: TransactionOf<D>,\n services: { readonly signedSessionValidity: SignedSessionValidity },\n ) => Effect.Effect<A, E, R>,\n) =>\n coordinateTargetSignedSessionValidity<TransactionOf<D>, A, E, R>(\n database,\n mapping,\n configuration,\n owner,\n );\n\nexport const makeSqliteSessionTarget = <\n DatabaseId,\n D extends Database,\n Synchronous extends boolean = false,\n>(\n databaseService: Context.Service<DatabaseId, D>,\n configuration:\n | SessionTargetConfiguration\n | ((service: TransactionService | undefined) => SessionTargetConfiguration),\n) => {\n const configurationFor = (database: D) =>\n typeof configuration === \"function\"\n ? configuration(transactionService(database))\n : configuration;\n\n const standaloneConfiguration =\n typeof configuration === \"function\"\n ? Effect.map(acquireTransactionService(databaseService), configuration)\n : Effect.succeed(configuration);\n\n function coordinateSessionStepUp<\n Database extends D,\n Claims,\n Id,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n I extends AnySQLiteTable,\n Session extends AnySQLiteTable,\n T extends AnySQLiteTable,\n NativeId,\n NativeSessionId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n >(\n acquire: Effect.Effect<Database, 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, Synchronous extends true ? NoInfer<Id> : R>,\n ): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n (Synchronous extends true ? never : Exclude<R, Id>) | LifecycleHooks | DatabaseRequirements\n >;\n function coordinateSessionStepUp<\n Database extends D,\n Claims,\n Id,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n I extends AnySQLiteTable,\n Session extends AnySQLiteTable,\n T extends AnySQLiteTable,\n NativeId,\n NativeSessionId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n >(\n acquire: Effect.Effect<Database, 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<Database>>, TxShape>;\n },\n body: Effect.Effect<A, E, Synchronous extends true ? NoInfer<Id | TxId> : R>,\n ): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, Id | TxId>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinateSessionStepUp<\n Database extends D,\n Claims,\n Id,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n I extends AnySQLiteTable,\n Session extends AnySQLiteTable,\n T extends AnySQLiteTable,\n NativeId,\n NativeSessionId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n >(\n acquire: Effect.Effect<Database, 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<Database>>, 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(nativeDatabase(acquire), (database) =>\n coordinateSqliteSessionStepUp(\n database,\n options.mapping,\n options.target,\n configurationFor(database),\n (\n transaction: TransactionOf<Database>,\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 ).pipe(Effect.provideService(NativeDatabase, database)),\n );\n }\n function coordinateAuthenticationAuthority<\n Database extends D,\n Claims,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n F extends AnySQLiteTable,\n P extends AnySQLiteTable,\n NativeId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n >(\n acquire: Effect.Effect<Database, 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, Synchronous extends true ? NoInfer<AuthenticationAuthority> : R>,\n ): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, AuthenticationAuthority>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinateAuthenticationAuthority<\n Database extends D,\n Claims,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n F extends AnySQLiteTable,\n P extends AnySQLiteTable,\n NativeId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n >(\n acquire: Effect.Effect<Database, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: AuthenticationAuthorityMapping<Claims, S, C, F, P, NativeId>;\n readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<Database>>, TxShape>;\n },\n body: Effect.Effect<\n A,\n E,\n Synchronous extends true ? NoInfer<AuthenticationAuthority | TxId> : R\n >,\n ): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, AuthenticationAuthority | TxId>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinateAuthenticationAuthority<\n Database extends D,\n Claims,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n F extends AnySQLiteTable,\n P extends AnySQLiteTable,\n NativeId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n >(\n acquire: Effect.Effect<Database, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: AuthenticationAuthorityMapping<Claims, S, C, F, P, NativeId>;\n readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<Database>>, 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(nativeDatabase(acquire), (database) =>\n coordinateSqliteAuthenticationAuthority(\n database,\n options.mapping,\n configurationFor(database),\n (\n transaction: TransactionOf<Database>,\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 ).pipe(Effect.provideService(NativeDatabase, database)),\n );\n }\n function coordinatePendingAuthentication<\n Database extends D,\n TargetId,\n Claims,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n P extends AnySQLiteTable,\n F extends AnySQLiteTable,\n NativeId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n >(\n acquire: Effect.Effect<Database, 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, Synchronous extends true ? NoInfer<TargetId> : R>,\n ): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, TargetId>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinatePendingAuthentication<\n Database extends D,\n TargetId,\n Claims,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n P extends AnySQLiteTable,\n F extends AnySQLiteTable,\n NativeId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n >(\n acquire: Effect.Effect<Database, 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<Database>>, TxShape>;\n },\n body: Effect.Effect<A, E, Synchronous extends true ? NoInfer<TargetId | TxId> : R>,\n ): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, TargetId | TxId>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinatePendingAuthentication<\n Database extends D,\n TargetId,\n Claims,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n P extends AnySQLiteTable,\n F extends AnySQLiteTable,\n NativeId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n >(\n acquire: Effect.Effect<Database, 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<Database>>, 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(nativeDatabase(acquire), (database) =>\n coordinateSqlitePendingAuthentication(\n database,\n options.mapping,\n configurationFor(database),\n (\n transaction: TransactionOf<Database>,\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 ).pipe(Effect.provideService(NativeDatabase, database)),\n );\n }\n function coordinateStatefulSessions<\n Database extends D,\n PersistenceId,\n RepositoryId,\n Claims,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n Session extends AnySQLiteTable,\n F extends AnySQLiteTable,\n P extends AnySQLiteTable,\n NativeId,\n NativeSessionId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n >(\n acquire: Effect.Effect<Database, 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, Synchronous extends true ? NoInfer<PersistenceId | RepositoryId> : R>,\n ): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, PersistenceId | RepositoryId>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinateStatefulSessions<\n Database extends D,\n PersistenceId,\n RepositoryId,\n Claims,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n Session extends AnySQLiteTable,\n F extends AnySQLiteTable,\n P extends AnySQLiteTable,\n NativeId,\n NativeSessionId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n >(\n acquire: Effect.Effect<Database, 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<Database>>, TxShape>;\n },\n body: Effect.Effect<\n A,\n E,\n Synchronous extends true ? NoInfer<PersistenceId | RepositoryId | TxId> : R\n >,\n ): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, PersistenceId | RepositoryId | TxId>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinateStatefulSessions<\n Database extends D,\n PersistenceId,\n RepositoryId,\n Claims,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n Session extends AnySQLiteTable,\n F extends AnySQLiteTable,\n P extends AnySQLiteTable,\n NativeId,\n NativeSessionId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n >(\n acquire: Effect.Effect<Database, 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<Database>>, 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(nativeDatabase(acquire), (database) =>\n coordinateSqliteStatefulSessions(\n database,\n options.mapping,\n configurationFor(database),\n (\n transaction: TransactionOf<Database>,\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 ).pipe(Effect.provideService(NativeDatabase, database)),\n );\n }\n function coordinateSignedSessionValidity<\n Database extends D,\n TargetId,\n S extends AnySQLiteTable,\n T extends AnySQLiteTable,\n NativeId,\n NativeSessionId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n >(\n acquire: Effect.Effect<Database, 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, Synchronous extends true ? NoInfer<TargetId> : R>,\n ): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, TargetId>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinateSignedSessionValidity<\n Database extends D,\n TargetId,\n S extends AnySQLiteTable,\n T extends AnySQLiteTable,\n NativeId,\n NativeSessionId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n >(\n acquire: Effect.Effect<Database, 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<Database>>, TxShape>;\n },\n body: Effect.Effect<A, E, Synchronous extends true ? NoInfer<TargetId | TxId> : R>,\n ): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, TargetId | TxId>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinateSignedSessionValidity<\n Database extends D,\n TargetId,\n S extends AnySQLiteTable,\n T extends AnySQLiteTable,\n NativeId,\n NativeSessionId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n >(\n acquire: Effect.Effect<Database, 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<Database>>, 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(nativeDatabase(acquire), (database) =>\n coordinateSqliteSignedSessionValidity(\n database,\n options.mapping,\n configurationFor(database),\n (\n transaction: TransactionOf<Database>,\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 ).pipe(Effect.provideService(NativeDatabase, database)),\n );\n }\n\n return {\n makeSessionStepUpServices: <\n Claims,\n Id,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n I extends AnySQLiteTable,\n Session extends AnySQLiteTable,\n T extends AnySQLiteTable,\n NativeId,\n NativeSessionId,\n >(\n mapping: SessionStepUpMapping<\n NoInfer<Claims>,\n S,\n C,\n I,\n Session,\n T,\n NativeId,\n NativeSessionId\n >,\n target: Context.Service<Id, SessionStepUpPersistence<Claims>>,\n ) =>\n Effect.flatMap(standaloneConfiguration, (configuration) =>\n makeSqliteSessionStepUpServices(mapping, target, configuration),\n ).pipe(\n Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(databaseService)),\n Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),\n ),\n coordinateSessionStepUp,\n makeAuthenticationAuthorityServices: <\n Claims,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n F extends AnySQLiteTable,\n P extends AnySQLiteTable,\n NativeId,\n >(\n mapping: AuthenticationAuthorityMapping<Claims, S, C, F, P, NativeId>,\n ) =>\n Effect.flatMap(standaloneConfiguration, (configuration) =>\n makeSqliteAuthenticationAuthorityServices(mapping, configuration),\n ).pipe(\n Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(databaseService)),\n Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),\n ),\n makePendingAuthenticationServices: <\n Claims,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n P extends AnySQLiteTable,\n F extends AnySQLiteTable,\n NativeId,\n >(\n mapping: PendingAuthenticationMapping<Claims, S, C, P, F, NativeId>,\n ) =>\n Effect.flatMap(standaloneConfiguration, (configuration) =>\n makeSqlitePendingAuthenticationServices(mapping, configuration),\n ).pipe(\n Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(databaseService)),\n Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),\n ),\n makeStatefulSessionServices: <\n Claims,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n Session extends AnySQLiteTable,\n F extends AnySQLiteTable,\n P extends AnySQLiteTable,\n NativeId,\n NativeSessionId,\n >(\n mapping: StatefulSessionMapping<Claims, S, C, Session, F, P, NativeId, NativeSessionId>,\n ) =>\n Effect.flatMap(standaloneConfiguration, (configuration) =>\n makeSqliteStatefulSessionServices(mapping, configuration),\n ).pipe(\n Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(databaseService)),\n Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),\n ),\n makeSignedSessionValidityServices: <\n S extends AnySQLiteTable,\n T extends AnySQLiteTable,\n NativeId,\n NativeSessionId,\n >(\n mapping: SignedSessionValidityMapping<S, T, NativeId, NativeSessionId>,\n ) =>\n Effect.flatMap(standaloneConfiguration, (configuration) =>\n makeSqliteSignedSessionValidityServices(mapping, configuration),\n ).pipe(\n Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(databaseService)),\n Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),\n ),\n coordinateAuthenticationAuthority,\n coordinatePendingAuthentication,\n coordinateStatefulSessions,\n coordinateSignedSessionValidity,\n };\n};\n\nimport type { SessionStepUpMapping } from \"./step-up-model\";\n\nexport const makeSqliteSessionStepUpServices = <\n Claims,\n Id,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n I extends AnySQLiteTable,\n Session extends AnySQLiteTable,\n T extends AnySQLiteTable,\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 configuration: SessionTargetConfiguration,\n) => makeTargetSessionStepUpServices(mapping, target, configuration);\n\nexport const coordinateSqliteSessionStepUp = <\n Claims,\n Id,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n I extends AnySQLiteTable,\n Session extends AnySQLiteTable,\n T extends AnySQLiteTable,\n NativeId,\n NativeSessionId,\n D extends Database,\n A,\n E,\n R,\n>(\n database: D,\n mapping: SessionStepUpMapping<NoInfer<Claims>, S, C, I, Session, T, NativeId, NativeSessionId>,\n target: Context.Service<Id, SessionStepUpPersistence<Claims>>,\n configuration: SessionTargetConfiguration,\n owner: (\n transaction: TransactionOf<D>,\n services: { readonly sessionStepUpPersistence: SessionStepUpPersistence<Claims> },\n ) => Effect.Effect<A, E, R>,\n) =>\n coordinateTargetSessionStepUp<Claims, Id, TransactionOf<D>, A, E, R>(\n database,\n mapping,\n target,\n configuration,\n owner,\n );\n"],"mappings":";;;;;;;;AAyDA,MAAa,8BACX,MACA,iBACA,sBACgC;CAChC;CACA,SAAS;CACT;CACA,GAAI,qBAAqB,KAAA,IAAY,CAAC,IAAI,EAAE,iBAAiB;AAC/D;AAEA,MAAa,6CAQX,SACA,kBACG,0CAAkD,SAAS,aAAa;AAE7E,MAAa,2CAQX,SACA,kBACG,wCAAgD,SAAS,aAAa;AAE3E,MAAa,qCAUX,SACA,kBACG,kCAA0C,SAAS,aAAa;AAErE,MAAa,2CAMX,SACA,kBACG,wCAAwC,SAAS,aAAa;AAEnE,MAAa,2CAYX,UAC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ACG,gCAAgC,SAAS,QAAQ,aAAa;AAEnE,MAAa,iCAeX,UACA,SACA,QACA,eACA,UAKA,8BACE,UACA,SACA,QACA,eACA,KACF"}
|
|
1
|
+
{"version":3,"file":"sqlite-sessions.mjs","names":[],"sources":["../../src/drizzle/sqlite-sessions.ts"],"sourcesContent":["import { NativeDatabase } from \"@yielded/auth-persistence/Adapter\";\nimport 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 { EffectLibsqlDatabase } from \"drizzle-orm/effect-libsql\";\nimport type { EffectSQLiteBunDatabase } from \"drizzle-orm/effect-sqlite-bun\";\nimport type { EffectSQLiteNodeDatabase } from \"drizzle-orm/effect-sqlite-node\";\nimport type { EffectSQLiteWasmDatabase } from \"drizzle-orm/effect-sqlite-wasm\";\nimport type { AnySQLiteTable } from \"drizzle-orm/sqlite-core\";\nimport { Context, Effect } from \"effect\";\nimport type { SqlError } from \"effect/sql/SqlError\";\n\nimport { nativeDatabase } from \"./native-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 type SessionTargetConfiguration,\n makeTargetSessionStepUpServices,\n coordinateTargetSessionStepUp,\n} from \"./session-target\";\nimport type { DatabaseValue } from \"./sqlite-do-database\";\nimport {\n type TransactionService,\n acquireTransactionService,\n transactionService,\n} from \"./standalone-guard\";\nimport type { SuppliedService } from \"./SuppliedService\";\n\ntype Database =\n | EffectLibsqlDatabase<AnyRelations>\n | EffectSQLiteBunDatabase<AnyRelations>\n | DatabaseValue<AnyRelations>\n | EffectSQLiteNodeDatabase<AnyRelations>\n | EffectSQLiteWasmDatabase<AnyRelations>;\ntype TransactionOf<D extends Database> = Parameters<Parameters<D[\"transaction\"]>[0]>[0];\n\nexport const sqliteSessionConfiguration = (\n mode: \"interactive\" | \"synchronous\",\n standaloneGuard: Effect.Effect<void, SessionUnavailable>,\n coordinatorGuard?: Effect.Effect<void, SessionUnavailable>,\n): SessionTargetConfiguration => ({\n mode,\n locking: false,\n standaloneGuard,\n ...(coordinatorGuard === undefined ? {} : { coordinatorGuard }),\n});\n\nexport const makeSqliteAuthenticationAuthorityServices = <\n Claims,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n F extends AnySQLiteTable,\n P extends AnySQLiteTable,\n NativeId,\n>(\n mapping: AuthenticationAuthorityMapping<Claims, S, C, F, P, NativeId>,\n configuration: SessionTargetConfiguration,\n) => makeTargetAuthenticationAuthorityServices<Claims>(mapping, configuration);\n\nexport const makeSqlitePendingAuthenticationServices = <\n Claims,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n P extends AnySQLiteTable,\n F extends AnySQLiteTable,\n NativeId,\n>(\n mapping: PendingAuthenticationMapping<Claims, S, C, P, F, NativeId>,\n configuration: SessionTargetConfiguration,\n) => makeTargetPendingAuthenticationServices<Claims>(mapping, configuration);\n\nexport const makeSqliteStatefulSessionServices = <\n Claims,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n Session extends AnySQLiteTable,\n F extends AnySQLiteTable,\n P extends AnySQLiteTable,\n NativeId,\n NativeSessionId,\n>(\n mapping: StatefulSessionMapping<Claims, S, C, Session, F, P, NativeId, NativeSessionId>,\n configuration: SessionTargetConfiguration,\n) => makeTargetStatefulSessionServices<Claims>(mapping, configuration);\n\nexport const makeSqliteSignedSessionValidityServices = <\n S extends AnySQLiteTable,\n T extends AnySQLiteTable,\n NativeId,\n NativeSessionId,\n>(\n mapping: SignedSessionValidityMapping<S, T, NativeId, NativeSessionId>,\n configuration: SessionTargetConfiguration,\n) => makeTargetSignedSessionValidityServices(mapping, configuration);\n\nexport const coordinateSqliteAuthenticationAuthority = <\n Claims,\n D extends Database,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n F extends AnySQLiteTable,\n P extends AnySQLiteTable,\n NativeId,\n A,\n E,\n R,\n>(\n database: D,\n mapping: AuthenticationAuthorityMapping<Claims, S, C, F, P, NativeId>,\n configuration: SessionTargetConfiguration,\n owner: (\n transaction: TransactionOf<D>,\n services: { readonly authenticationAuthority: AuthenticationAuthority[\"Service\"] },\n ) => Effect.Effect<A, E, R>,\n) =>\n coordinateTargetAuthenticationAuthority<Claims, TransactionOf<D>, A, E, R>(\n database,\n mapping,\n configuration,\n owner,\n );\n\nexport const coordinateSqlitePendingAuthentication = <\n Claims,\n D extends Database,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n P extends AnySQLiteTable,\n F extends AnySQLiteTable,\n NativeId,\n A,\n E,\n R,\n>(\n database: D,\n mapping: PendingAuthenticationMapping<Claims, S, C, P, F, NativeId>,\n configuration: SessionTargetConfiguration,\n owner: (\n transaction: TransactionOf<D>,\n services: { readonly pendingAuthentication: PendingAuthentication<Claims> },\n ) => Effect.Effect<A, E, R>,\n) =>\n coordinateTargetPendingAuthentication<Claims, TransactionOf<D>, A, E, R>(\n database,\n mapping,\n configuration,\n owner,\n );\n\nexport const coordinateSqliteStatefulSessions = <\n Claims,\n D extends Database,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n Session extends AnySQLiteTable,\n F extends AnySQLiteTable,\n P extends AnySQLiteTable,\n NativeId,\n NativeSessionId,\n A,\n E,\n R,\n>(\n database: D,\n mapping: StatefulSessionMapping<Claims, S, C, Session, F, P, NativeId, NativeSessionId>,\n configuration: SessionTargetConfiguration,\n owner: (\n transaction: TransactionOf<D>,\n services: {\n readonly statefulSessionPersistence: StatefulSessionPersistence<Claims>;\n readonly sessionRepository: SessionRepository;\n },\n ) => Effect.Effect<A, E, R>,\n) =>\n coordinateTargetStatefulSessions<Claims, TransactionOf<D>, A, E, R>(\n database,\n mapping,\n configuration,\n owner,\n );\n\nexport const coordinateSqliteSignedSessionValidity = <\n D extends Database,\n S extends AnySQLiteTable,\n T extends AnySQLiteTable,\n NativeId,\n NativeSessionId,\n A,\n E,\n R,\n>(\n database: D,\n mapping: SignedSessionValidityMapping<S, T, NativeId, NativeSessionId>,\n configuration: SessionTargetConfiguration,\n owner: (\n transaction: TransactionOf<D>,\n services: { readonly signedSessionValidity: SignedSessionValidity },\n ) => Effect.Effect<A, E, R>,\n) =>\n coordinateTargetSignedSessionValidity<TransactionOf<D>, A, E, R>(\n database,\n mapping,\n configuration,\n owner,\n );\n\nexport const makeSqliteSessionTarget = <\n DatabaseId,\n D extends Database,\n Synchronous extends boolean = false,\n>(\n databaseService: Context.Service<DatabaseId, D>,\n configuration:\n | SessionTargetConfiguration\n | ((service: TransactionService | undefined) => SessionTargetConfiguration),\n) => {\n const configurationFor = (database: D) =>\n typeof configuration === \"function\"\n ? configuration(transactionService(database))\n : configuration;\n\n const standaloneConfiguration =\n typeof configuration === \"function\"\n ? Effect.map(acquireTransactionService(databaseService), configuration)\n : Effect.succeed(configuration);\n\n function coordinateSessionStepUp<\n Database extends D,\n Claims,\n Id,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n I extends AnySQLiteTable,\n Session extends AnySQLiteTable,\n T extends AnySQLiteTable,\n NativeId,\n NativeSessionId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n >(\n acquire: Effect.Effect<Database, 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, Synchronous extends true ? NoInfer<Id> : R>,\n ): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n (Synchronous extends true ? never : Exclude<R, Id>) | LifecycleHooks | DatabaseRequirements\n >;\n function coordinateSessionStepUp<\n Database extends D,\n Claims,\n Id,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n I extends AnySQLiteTable,\n Session extends AnySQLiteTable,\n T extends AnySQLiteTable,\n NativeId,\n NativeSessionId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n >(\n acquire: Effect.Effect<Database, 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<Database>>, TxShape>;\n },\n body: Effect.Effect<A, E, Synchronous extends true ? NoInfer<Id | TxId> : R>,\n ): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, Id | TxId>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinateSessionStepUp<\n Database extends D,\n Claims,\n Id,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n I extends AnySQLiteTable,\n Session extends AnySQLiteTable,\n T extends AnySQLiteTable,\n NativeId,\n NativeSessionId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n >(\n acquire: Effect.Effect<Database, 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<Database>>, 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(nativeDatabase(acquire), (database) =>\n coordinateSqliteSessionStepUp(\n database,\n options.mapping,\n options.target,\n configurationFor(database),\n (\n transaction: TransactionOf<Database>,\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 ).pipe(Effect.provideService(NativeDatabase, database)),\n );\n }\n function coordinateAuthenticationAuthority<\n Database extends D,\n Claims,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n F extends AnySQLiteTable,\n P extends AnySQLiteTable,\n NativeId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n >(\n acquire: Effect.Effect<Database, 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, Synchronous extends true ? NoInfer<AuthenticationAuthority> : R>,\n ): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, AuthenticationAuthority>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinateAuthenticationAuthority<\n Database extends D,\n Claims,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n F extends AnySQLiteTable,\n P extends AnySQLiteTable,\n NativeId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n >(\n acquire: Effect.Effect<Database, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: AuthenticationAuthorityMapping<Claims, S, C, F, P, NativeId>;\n readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<Database>>, TxShape>;\n },\n body: Effect.Effect<\n A,\n E,\n Synchronous extends true ? NoInfer<AuthenticationAuthority | TxId> : R\n >,\n ): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, AuthenticationAuthority | TxId>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinateAuthenticationAuthority<\n Database extends D,\n Claims,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n F extends AnySQLiteTable,\n P extends AnySQLiteTable,\n NativeId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n >(\n acquire: Effect.Effect<Database, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: AuthenticationAuthorityMapping<Claims, S, C, F, P, NativeId>;\n readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<Database>>, 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(nativeDatabase(acquire), (database) =>\n coordinateSqliteAuthenticationAuthority(\n database,\n options.mapping,\n configurationFor(database),\n (\n transaction: TransactionOf<Database>,\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 ).pipe(Effect.provideService(NativeDatabase, database)),\n );\n }\n function coordinatePendingAuthentication<\n Database extends D,\n TargetId,\n Claims,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n P extends AnySQLiteTable,\n F extends AnySQLiteTable,\n NativeId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n >(\n acquire: Effect.Effect<Database, 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, Synchronous extends true ? NoInfer<TargetId> : R>,\n ): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, TargetId>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinatePendingAuthentication<\n Database extends D,\n TargetId,\n Claims,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n P extends AnySQLiteTable,\n F extends AnySQLiteTable,\n NativeId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n >(\n acquire: Effect.Effect<Database, 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<Database>>, TxShape>;\n },\n body: Effect.Effect<A, E, Synchronous extends true ? NoInfer<TargetId | TxId> : R>,\n ): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, TargetId | TxId>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinatePendingAuthentication<\n Database extends D,\n TargetId,\n Claims,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n P extends AnySQLiteTable,\n F extends AnySQLiteTable,\n NativeId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n >(\n acquire: Effect.Effect<Database, 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<Database>>, 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(nativeDatabase(acquire), (database) =>\n coordinateSqlitePendingAuthentication(\n database,\n options.mapping,\n configurationFor(database),\n (\n transaction: TransactionOf<Database>,\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 ).pipe(Effect.provideService(NativeDatabase, database)),\n );\n }\n function coordinateStatefulSessions<\n Database extends D,\n PersistenceId,\n RepositoryId,\n Claims,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n Session extends AnySQLiteTable,\n F extends AnySQLiteTable,\n P extends AnySQLiteTable,\n NativeId,\n NativeSessionId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n >(\n acquire: Effect.Effect<Database, 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, Synchronous extends true ? NoInfer<PersistenceId | RepositoryId> : R>,\n ): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, PersistenceId | RepositoryId>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinateStatefulSessions<\n Database extends D,\n PersistenceId,\n RepositoryId,\n Claims,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n Session extends AnySQLiteTable,\n F extends AnySQLiteTable,\n P extends AnySQLiteTable,\n NativeId,\n NativeSessionId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n >(\n acquire: Effect.Effect<Database, 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<Database>>, TxShape>;\n },\n body: Effect.Effect<\n A,\n E,\n Synchronous extends true ? NoInfer<PersistenceId | RepositoryId | TxId> : R\n >,\n ): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, PersistenceId | RepositoryId | TxId>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinateStatefulSessions<\n Database extends D,\n PersistenceId,\n RepositoryId,\n Claims,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n Session extends AnySQLiteTable,\n F extends AnySQLiteTable,\n P extends AnySQLiteTable,\n NativeId,\n NativeSessionId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n >(\n acquire: Effect.Effect<Database, 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<Database>>, 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(nativeDatabase(acquire), (database) =>\n coordinateSqliteStatefulSessions(\n database,\n options.mapping,\n configurationFor(database),\n (\n transaction: TransactionOf<Database>,\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 ).pipe(Effect.provideService(NativeDatabase, database)),\n );\n }\n function coordinateSignedSessionValidity<\n Database extends D,\n TargetId,\n S extends AnySQLiteTable,\n T extends AnySQLiteTable,\n NativeId,\n NativeSessionId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n >(\n acquire: Effect.Effect<Database, 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, Synchronous extends true ? NoInfer<TargetId> : R>,\n ): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, TargetId>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinateSignedSessionValidity<\n Database extends D,\n TargetId,\n S extends AnySQLiteTable,\n T extends AnySQLiteTable,\n NativeId,\n NativeSessionId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n >(\n acquire: Effect.Effect<Database, 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<Database>>, TxShape>;\n },\n body: Effect.Effect<A, E, Synchronous extends true ? NoInfer<TargetId | TxId> : R>,\n ): Effect.Effect<\n A,\n E | SessionUnavailable | HookConfigurationError | SqlError | DatabaseError,\n | (Synchronous extends true ? never : Exclude<R, TargetId | TxId>)\n | LifecycleHooks\n | DatabaseRequirements\n >;\n function coordinateSignedSessionValidity<\n Database extends D,\n TargetId,\n S extends AnySQLiteTable,\n T extends AnySQLiteTable,\n NativeId,\n NativeSessionId,\n A,\n E,\n R,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n >(\n acquire: Effect.Effect<Database, 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<Database>>, 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(nativeDatabase(acquire), (database) =>\n coordinateSqliteSignedSessionValidity(\n database,\n options.mapping,\n configurationFor(database),\n (\n transaction: TransactionOf<Database>,\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 ).pipe(Effect.provideService(NativeDatabase, database)),\n );\n }\n\n return {\n makeSessionStepUpServices: <\n Claims,\n Id,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n I extends AnySQLiteTable,\n Session extends AnySQLiteTable,\n T extends AnySQLiteTable,\n NativeId,\n NativeSessionId,\n >(\n mapping: SessionStepUpMapping<\n NoInfer<Claims>,\n S,\n C,\n I,\n Session,\n T,\n NativeId,\n NativeSessionId\n >,\n target: Context.Service<Id, SessionStepUpPersistence<Claims>>,\n ) =>\n Effect.flatMap(standaloneConfiguration, (configuration) =>\n makeSqliteSessionStepUpServices(mapping, target, configuration),\n ).pipe(\n Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(databaseService)),\n Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),\n ),\n coordinateSessionStepUp,\n makeAuthenticationAuthorityServices: <\n Claims,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n F extends AnySQLiteTable,\n P extends AnySQLiteTable,\n NativeId,\n >(\n mapping: AuthenticationAuthorityMapping<Claims, S, C, F, P, NativeId>,\n ) =>\n Effect.flatMap(standaloneConfiguration, (configuration) =>\n makeSqliteAuthenticationAuthorityServices(mapping, configuration),\n ).pipe(\n Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(databaseService)),\n Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),\n ),\n makePendingAuthenticationServices: <\n Claims,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n P extends AnySQLiteTable,\n F extends AnySQLiteTable,\n NativeId,\n >(\n mapping: PendingAuthenticationMapping<Claims, S, C, P, F, NativeId>,\n ) =>\n Effect.flatMap(standaloneConfiguration, (configuration) =>\n makeSqlitePendingAuthenticationServices(mapping, configuration),\n ).pipe(\n Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(databaseService)),\n Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),\n ),\n makeStatefulSessionServices: <\n Claims,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n Session extends AnySQLiteTable,\n F extends AnySQLiteTable,\n P extends AnySQLiteTable,\n NativeId,\n NativeSessionId,\n >(\n mapping: StatefulSessionMapping<Claims, S, C, Session, F, P, NativeId, NativeSessionId>,\n ) =>\n Effect.flatMap(standaloneConfiguration, (configuration) =>\n makeSqliteStatefulSessionServices(mapping, configuration),\n ).pipe(\n Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(databaseService)),\n Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),\n ),\n makeSignedSessionValidityServices: <\n S extends AnySQLiteTable,\n T extends AnySQLiteTable,\n NativeId,\n NativeSessionId,\n >(\n mapping: SignedSessionValidityMapping<S, T, NativeId, NativeSessionId>,\n ) =>\n Effect.flatMap(standaloneConfiguration, (configuration) =>\n makeSqliteSignedSessionValidityServices(mapping, configuration),\n ).pipe(\n Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(databaseService)),\n Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),\n ),\n coordinateAuthenticationAuthority,\n coordinatePendingAuthentication,\n coordinateStatefulSessions,\n coordinateSignedSessionValidity,\n };\n};\n\nimport type { SessionStepUpMapping } from \"./step-up-model\";\n\nexport const makeSqliteSessionStepUpServices = <\n Claims,\n Id,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n I extends AnySQLiteTable,\n Session extends AnySQLiteTable,\n T extends AnySQLiteTable,\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 configuration: SessionTargetConfiguration,\n) => makeTargetSessionStepUpServices(mapping, target, configuration);\n\nexport const coordinateSqliteSessionStepUp = <\n Claims,\n Id,\n S extends AnySQLiteTable,\n C extends AnySQLiteTable,\n I extends AnySQLiteTable,\n Session extends AnySQLiteTable,\n T extends AnySQLiteTable,\n NativeId,\n NativeSessionId,\n D extends Database,\n A,\n E,\n R,\n>(\n database: D,\n mapping: SessionStepUpMapping<NoInfer<Claims>, S, C, I, Session, T, NativeId, NativeSessionId>,\n target: Context.Service<Id, SessionStepUpPersistence<Claims>>,\n configuration: SessionTargetConfiguration,\n owner: (\n transaction: TransactionOf<D>,\n services: { readonly sessionStepUpPersistence: SessionStepUpPersistence<Claims> },\n ) => Effect.Effect<A, E, R>,\n) =>\n coordinateTargetSessionStepUp<Claims, Id, TransactionOf<D>, A, E, R>(\n database,\n mapping,\n target,\n configuration,\n owner,\n );\n"],"mappings":";;;;;;;;AAyDA,MAAa,8BACX,MACA,iBACA,sBACgC;CAChC;CACA,SAAS;CACT;CACA,GAAI,qBAAqB,KAAA,IAAY,CAAC,IAAI,EAAE,iBAAiB;AAC/D;AAEA,MAAa,6CAQX,SACA,kBACG,0CAAkD,SAAS,aAAa;AAE7E,MAAa,2CAQX,SACA,kBACG,wCAAgD,SAAS,aAAa;AAE3E,MAAa,qCAUX,SACA,kBACG,kCAA0C,SAAS,aAAa;AAErE,MAAa,2CAMX,SACA,kBACG,wCAAwC,SAAS,aAAa;AAEnE,MAAa,2CAYX,UACA,SACA,eACA,UAKA,wCACE,UACA,SACA,eACA,KACF;AAEF,MAAa,yCAYX,UACA,SACA,eACA,UAKA,sCACE,UACA,SACA,eACA,KACF;AAEF,MAAa,oCAcX,UACA,SACA,eACA,UAQA,iCACE,UACA,SACA,eACA,KACF;AAEF,MAAa,yCAUX,UACA,SACA,eACA,UAKA,sCACE,UACA,SACA,eACA,KACF;AAEF,MAAa,2BAKX,iBACA,kBAGG;CACH,MAAM,oBAAoB,aACxB,OAAO,kBAAkB,aACrB,cAAc,mBAAmB,QAAQ,CAAC,IAC1C;CAEN,MAAM,0BACJ,OAAO,kBAAkB,aACrB,OAAO,IAAI,0BAA0B,eAAe,GAAG,aAAa,IACpE,OAAO,QAAQ,aAAa;CAkFlC,SAAS,wBAmBP,SACA,SAcA,MAKA;EACA,OAAO,OAAO,QAAQ,eAAe,OAAO,IAAI,aAC9C,8BACE,UACA,QAAQ,SACR,QAAQ,QACR,iBAAiB,QAAQ,IAEvB,aACA,aACG;GACH,MAAM,WAAW,QAAQ,KAAK,QAAQ,QAAQ,SAAS,wBAAwB;GAC/E,MAAM,OAAO,OAAO,eAAe,MAAM,QAAQ;GAEjD,OAAO,QAAQ,gBAAgB,KAAA,IAC3B,OACA,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qB,gBAAgB,eAAe,eAAe,CAAC,CAC7E;EACF,8BAUE,YAEA,OAAO,QAAQ,0BAA0B,kBACvC,kCAAkC,SAAS,aAAa,CAC1D,CAAC,CAAC,KACA,OAAO,qBAAqB,mBAAmB,eAAe,eAAe,CAAC,GAC9E,OAAO,qBAAqB,gBAAgB,eAAe,eAAe,CAAC,CAC7E;EACF,oCAME,YAEA,OAAO,QAAQ,0BAA0B,kBACvC,wCAAwC,SAAS,aAAa,CAChE,CAAC,CAAC,KACA,OAAO,qBAAqB,mBAAmB,eAAe,eAAe,CAAC,GAC9E,OAAO,qBAAqB,gBAAgB,eAAe,eAAe,CAAC,CAC7E;EACF;EACA;EACA;EACA;CACF;AACF;AAIA,MAAa,mCAWX,SACA,QACA,kBACG,gCAAgC,SAAS,QAAQ,aAAa;AAEnE,MAAa,iCAeX,UACA,SACA,QACA,eACA,UAKA,8BACE,UACA,SACA,QACA,eACA,KACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NativeDatabase, PersistenceMappingError,
|
|
1
|
+
import { NativeDatabase, PersistenceMappingError, validateStorageBatch } from "@yielded/auth-persistence/Adapter";
|
|
2
2
|
import { Table, getTableColumns, getTableName, is } from "drizzle-orm";
|
|
3
3
|
import { Effect, Predicate, Schema } from "effect";
|
|
4
4
|
import { MySqlTable, getTableConfig } from "drizzle-orm/mysql-core";
|
|
@@ -210,20 +210,28 @@ const validateDrizzleStorage = Effect.fnUntraced(function* (mapping) {
|
|
|
210
210
|
})
|
|
211
211
|
});
|
|
212
212
|
const { $client: client } = yield* NativeDatabase;
|
|
213
|
+
const batches = /* @__PURE__ */ new Map();
|
|
213
214
|
for (const plan of physical) {
|
|
214
215
|
const pg = is(plan.table, PgTable);
|
|
215
216
|
const mysql = is(plan.table, MySqlTable);
|
|
216
217
|
const schema = pg ? getTableConfig$1(plan.table).schema : mysql ? getTableConfig(plan.table).schema : void 0;
|
|
217
218
|
const columns = getTableColumns(plan.table);
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
219
|
+
const dialect = pg ? "pg" : mysql ? "mysql" : "sqlite";
|
|
220
|
+
const batch = batches.get(dialect) ?? [];
|
|
221
|
+
batch.push({
|
|
222
|
+
table: {
|
|
223
|
+
name: getTableName(plan.table),
|
|
224
|
+
...schema === void 0 ? {} : { schema },
|
|
225
|
+
columns: Object.fromEntries(plan.keys.map((key) => [key, { name: columns[key].name }]))
|
|
226
|
+
},
|
|
227
|
+
required: [plan.keys]
|
|
228
|
+
});
|
|
229
|
+
batches.set(dialect, batch);
|
|
226
230
|
}
|
|
231
|
+
for (const [dialect, requirements] of batches) yield* validateStorageBatch(dialect, requirements).pipe(Effect.provideService(SqlClient, client), Effect.mapError(() => PersistenceMappingError.make({
|
|
232
|
+
operation: "mapping",
|
|
233
|
+
cause: "Required SQL storage key is unavailable"
|
|
234
|
+
})));
|
|
227
235
|
}, Effect.catchDefect(() => Effect.fail(PersistenceMappingError.make({
|
|
228
236
|
operation: "mapping",
|
|
229
237
|
cause: "Cannot inspect SQL storage metadata"
|