@yielded/auth-persistence-drizzle 0.1.0-beta.14 → 0.1.0-beta.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/D1.d.mts +123 -9
- package/dist/Libsql.d.mts +141 -27
- package/dist/Mysql2.d.mts +124 -10
- package/dist/Pglite.d.mts +124 -10
- package/dist/Postgres.d.mts +129 -15
- package/dist/SqliteBun.d.mts +135 -21
- package/dist/SqliteDo.d.mts +135 -21
- package/dist/SqliteNode.d.mts +135 -21
- package/dist/SqliteWasm.d.mts +135 -21
- package/dist/drizzle/d1-emails.d.mts +3 -3
- package/dist/drizzle/d1-emails.mjs +56 -11
- package/dist/drizzle/d1-emails.mjs.map +1 -1
- package/dist/drizzle/d1-identity.mjs +9 -2
- package/dist/drizzle/d1-identity.mjs.map +1 -1
- package/dist/drizzle/d1-oauth.d.mts +6 -6
- package/dist/drizzle/d1-oauth.mjs +8 -8
- package/dist/drizzle/d1-oauth.mjs.map +1 -1
- package/dist/drizzle/d1-passkey.d.mts +2 -1
- package/dist/drizzle/d1-passkey.mjs +10 -8
- package/dist/drizzle/d1-passkey.mjs.map +1 -1
- package/dist/drizzle/d1-password-prepared.d.mts +1 -1
- package/dist/drizzle/d1-password-prepared.mjs +16 -5
- package/dist/drizzle/d1-password-prepared.mjs.map +1 -1
- package/dist/drizzle/d1-passwords.d.mts +2 -2
- package/dist/drizzle/d1-passwords.mjs +19 -6
- package/dist/drizzle/d1-passwords.mjs.map +1 -1
- package/dist/drizzle/d1-phone.d.mts +2 -1
- package/dist/drizzle/d1-phone.mjs +4 -2
- package/dist/drizzle/d1-phone.mjs.map +1 -1
- package/dist/drizzle/d1-proofs.d.mts +1 -1
- package/dist/drizzle/d1-proofs.mjs +18 -7
- package/dist/drizzle/d1-proofs.mjs.map +1 -1
- package/dist/drizzle/d1-sessions.d.mts +6 -5
- package/dist/drizzle/d1-sessions.mjs +29 -19
- package/dist/drizzle/d1-sessions.mjs.map +1 -1
- package/dist/drizzle/d1-totp.d.mts +2 -1
- package/dist/drizzle/d1-totp.mjs +4 -2
- package/dist/drizzle/d1-totp.mjs.map +1 -1
- package/dist/drizzle/email-registration.d.mts +5 -1
- package/dist/drizzle/email-registration.mjs +48 -4
- package/dist/drizzle/email-registration.mjs.map +1 -1
- package/dist/drizzle/email-target.d.mts +1 -0
- package/dist/drizzle/email-target.mjs +9 -0
- package/dist/drizzle/email-target.mjs.map +1 -1
- package/dist/drizzle/mysql-emails.d.mts +4 -4
- package/dist/drizzle/mysql-emails.mjs +8 -7
- package/dist/drizzle/mysql-emails.mjs.map +1 -1
- package/dist/drizzle/mysql-identity.mjs +11 -4
- package/dist/drizzle/mysql-identity.mjs.map +1 -1
- package/dist/drizzle/mysql-password-prepared.d.mts +2 -2
- package/dist/drizzle/mysql-password-prepared.mjs +4 -3
- package/dist/drizzle/mysql-password-prepared.mjs.map +1 -1
- package/dist/drizzle/mysql-passwords.d.mts +3 -3
- package/dist/drizzle/mysql-passwords.mjs +7 -6
- package/dist/drizzle/mysql-passwords.mjs.map +1 -1
- package/dist/drizzle/mysql-proofs.d.mts +2 -2
- package/dist/drizzle/mysql-proofs.mjs +4 -3
- package/dist/drizzle/mysql-proofs.mjs.map +1 -1
- package/dist/drizzle/mysql-sessions.d.mts +6 -6
- package/dist/drizzle/mysql-sessions.mjs +16 -15
- package/dist/drizzle/mysql-sessions.mjs.map +1 -1
- package/dist/drizzle/native-database.mjs +1 -1
- package/dist/drizzle/native-database.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-drivers.mjs +10 -8
- package/dist/drizzle/oauth-connected-drivers.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-flow.mjs +62 -13
- package/dist/drizzle/oauth-connected-flow.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-input.mjs +6 -0
- package/dist/drizzle/oauth-connected-input.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-maintenance.mjs +3 -3
- package/dist/drizzle/oauth-connected-maintenance.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-target.d.mts +116 -2
- package/dist/drizzle/oauth-connected-target.mjs +5 -3
- package/dist/drizzle/oauth-connected-target.mjs.map +1 -1
- package/dist/drizzle/oauth-drivers.mjs +8 -8
- package/dist/drizzle/oauth-drivers.mjs.map +1 -1
- package/dist/drizzle/oauth-target.d.mts +3 -3
- package/dist/drizzle/oauth-target.mjs +8 -6
- package/dist/drizzle/oauth-target.mjs.map +1 -1
- package/dist/drizzle/passkey-drivers.mjs +4 -4
- package/dist/drizzle/passkey-drivers.mjs.map +1 -1
- package/dist/drizzle/passkey-write-drivers.mjs +4 -4
- package/dist/drizzle/passkey-write-drivers.mjs.map +1 -1
- package/dist/drizzle/passkey-write-target.d.mts +1 -1
- package/dist/drizzle/password-prepared-sql.mjs +5 -0
- package/dist/drizzle/password-prepared-sql.mjs.map +1 -1
- package/dist/drizzle/password-prepared-target.d.mts +2 -1
- package/dist/drizzle/password-prepared-target.mjs +5 -0
- package/dist/drizzle/password-prepared-target.mjs.map +1 -1
- package/dist/drizzle/password-registration.d.mts +1 -1
- package/dist/drizzle/password-registration.mjs +2 -0
- package/dist/drizzle/password-registration.mjs.map +1 -1
- package/dist/drizzle/password-target.d.mts +1 -0
- package/dist/drizzle/password-target.mjs +6 -0
- package/dist/drizzle/password-target.mjs.map +1 -1
- package/dist/drizzle/pg-emails.d.mts +4 -4
- package/dist/drizzle/pg-emails.mjs +8 -7
- package/dist/drizzle/pg-emails.mjs.map +1 -1
- package/dist/drizzle/pg-identity.mjs +12 -5
- package/dist/drizzle/pg-identity.mjs.map +1 -1
- package/dist/drizzle/pg-password-prepared.d.mts +2 -2
- package/dist/drizzle/pg-password-prepared.mjs +4 -3
- package/dist/drizzle/pg-password-prepared.mjs.map +1 -1
- package/dist/drizzle/pg-passwords.d.mts +3 -3
- package/dist/drizzle/pg-passwords.mjs +7 -6
- package/dist/drizzle/pg-passwords.mjs.map +1 -1
- package/dist/drizzle/pg-proofs.d.mts +2 -2
- package/dist/drizzle/pg-proofs.mjs +4 -3
- package/dist/drizzle/pg-proofs.mjs.map +1 -1
- package/dist/drizzle/pg-sessions.d.mts +6 -6
- package/dist/drizzle/pg-sessions.mjs +16 -15
- package/dist/drizzle/pg-sessions.mjs.map +1 -1
- package/dist/drizzle/phone-target.mjs +11 -2
- package/dist/drizzle/phone-target.mjs.map +1 -1
- package/dist/drizzle/proof-target.d.mts +1 -0
- package/dist/drizzle/proof-target.mjs +2 -0
- package/dist/drizzle/proof-target.mjs.map +1 -1
- package/dist/drizzle/query-operations.mjs +2 -0
- package/dist/drizzle/query-operations.mjs.map +1 -1
- package/dist/drizzle/session-target.d.mts +1 -0
- package/dist/drizzle/session-target.mjs +9 -6
- package/dist/drizzle/session-target.mjs.map +1 -1
- package/dist/drizzle/sqlite-emails.mjs +8 -7
- package/dist/drizzle/sqlite-emails.mjs.map +1 -1
- package/dist/drizzle/sqlite-identity.mjs +7 -2
- package/dist/drizzle/sqlite-identity.mjs.map +1 -1
- package/dist/drizzle/sqlite-password-prepared.mjs +4 -3
- package/dist/drizzle/sqlite-password-prepared.mjs.map +1 -1
- package/dist/drizzle/sqlite-passwords.mjs +7 -6
- package/dist/drizzle/sqlite-passwords.mjs.map +1 -1
- package/dist/drizzle/sqlite-proofs.mjs +4 -3
- package/dist/drizzle/sqlite-proofs.mjs.map +1 -1
- package/dist/drizzle/sqlite-sessions.mjs +16 -15
- package/dist/drizzle/sqlite-sessions.mjs.map +1 -1
- package/dist/drizzle/storage-validation.mjs +234 -0
- package/dist/drizzle/storage-validation.mjs.map +1 -0
- package/dist/drizzle/totp-target.mjs +5 -2
- package/dist/drizzle/totp-target.mjs.map +1 -1
- package/dist/drizzle/transaction-mysql.mjs +1 -1
- package/package.json +1 -1
- package/src/drizzle/d1-emails.ts +158 -40
- package/src/drizzle/d1-identity.ts +13 -0
- package/src/drizzle/d1-oauth.ts +8 -8
- package/src/drizzle/d1-passkey.ts +10 -8
- package/src/drizzle/d1-password-prepared.ts +14 -2
- package/src/drizzle/d1-passwords.ts +22 -4
- package/src/drizzle/d1-phone.ts +4 -2
- package/src/drizzle/d1-proofs.ts +55 -3
- package/src/drizzle/d1-sessions.ts +67 -18
- package/src/drizzle/d1-totp.ts +4 -2
- package/src/drizzle/email-registration.ts +160 -12
- package/src/drizzle/email-target.ts +22 -4
- package/src/drizzle/mysql-emails.ts +17 -7
- package/src/drizzle/mysql-identity.ts +13 -0
- package/src/drizzle/mysql-password-prepared.ts +7 -3
- package/src/drizzle/mysql-passwords.ts +13 -6
- package/src/drizzle/mysql-proofs.ts +7 -3
- package/src/drizzle/mysql-sessions.ts +31 -15
- package/src/drizzle/native-database.ts +5 -4
- package/src/drizzle/oauth-connected-drivers.ts +10 -8
- package/src/drizzle/oauth-connected-flow.ts +98 -10
- package/src/drizzle/oauth-connected-input.ts +7 -0
- package/src/drizzle/oauth-connected-maintenance.ts +3 -2
- package/src/drizzle/oauth-connected-target.ts +4 -2
- package/src/drizzle/oauth-drivers.ts +8 -8
- package/src/drizzle/oauth-target.ts +13 -7
- package/src/drizzle/passkey-drivers.ts +4 -4
- package/src/drizzle/passkey-write-drivers.ts +8 -5
- package/src/drizzle/password-prepared-sql.ts +13 -1
- package/src/drizzle/password-prepared-target.ts +7 -1
- package/src/drizzle/password-registration.ts +10 -3
- package/src/drizzle/password-target.ts +22 -4
- package/src/drizzle/pg-emails.ts +17 -7
- package/src/drizzle/pg-identity.ts +13 -0
- package/src/drizzle/pg-password-prepared.ts +7 -3
- package/src/drizzle/pg-passwords.ts +13 -6
- package/src/drizzle/pg-proofs.ts +7 -3
- package/src/drizzle/pg-sessions.ts +31 -15
- package/src/drizzle/phone-target.ts +30 -5
- package/src/drizzle/proof-target.ts +10 -2
- package/src/drizzle/query-operations.ts +2 -0
- package/src/drizzle/session-target.ts +20 -3
- package/src/drizzle/sqlite-emails.ts +17 -7
- package/src/drizzle/sqlite-identity.ts +5 -0
- package/src/drizzle/sqlite-password-prepared.ts +7 -3
- package/src/drizzle/sqlite-passwords.ts +13 -6
- package/src/drizzle/sqlite-proofs.ts +7 -3
- package/src/drizzle/sqlite-sessions.ts +31 -15
- package/src/drizzle/storage-validation.ts +285 -0
- package/src/drizzle/totp-target.ts +16 -4
|
@@ -2,6 +2,7 @@ import { CurrentSessionSql } from "./session-sql.mjs";
|
|
|
2
2
|
import { acquireTransactionService, transactionService } from "./standalone-guard.mjs";
|
|
3
3
|
import { coordinateTargetAuthenticationAuthority, coordinateTargetPendingAuthentication, coordinateTargetSessionStepUp, coordinateTargetSignedSessionValidity, coordinateTargetStatefulSessions, makeTargetAuthenticationAuthorityServices, makeTargetPendingAuthenticationServices, makeTargetSessionStepUpServices, makeTargetSignedSessionValidityServices, makeTargetStatefulSessionServices } from "./session-target.mjs";
|
|
4
4
|
import { nativeDatabase } from "./native-database.mjs";
|
|
5
|
+
import { NativeDatabase } from "@yielded/auth-persistence/Adapter";
|
|
5
6
|
import { Context, Effect } from "effect";
|
|
6
7
|
import { AuthenticationAuthority } from "@yielded/auth/Sessions";
|
|
7
8
|
//#region src/drizzle/sqlite-sessions.ts
|
|
@@ -23,47 +24,47 @@ const makeSqliteSessionTarget = (databaseService, configuration) => {
|
|
|
23
24
|
const configurationFor = (database) => typeof configuration === "function" ? configuration(transactionService(database)) : configuration;
|
|
24
25
|
const standaloneConfiguration = typeof configuration === "function" ? Effect.map(acquireTransactionService(databaseService), configuration) : Effect.succeed(configuration);
|
|
25
26
|
function coordinateSessionStepUp(acquire, options, body) {
|
|
26
|
-
return Effect.flatMap(acquire, (database) => coordinateSqliteSessionStepUp(database, options.mapping, options.target, configurationFor(database), (transaction, services) => {
|
|
27
|
+
return Effect.flatMap(nativeDatabase(acquire), (database) => coordinateSqliteSessionStepUp(database, options.mapping, options.target, configurationFor(database), (transaction, services) => {
|
|
27
28
|
const provided = Context.make(options.target, services.sessionStepUpPersistence);
|
|
28
29
|
const work = Effect.provideContext(body, provided);
|
|
29
30
|
return options.transaction === void 0 ? work : Effect.provideService(work, options.transaction, options.transaction.of(transaction));
|
|
30
|
-
}));
|
|
31
|
+
}).pipe(Effect.provideService(NativeDatabase, database)));
|
|
31
32
|
}
|
|
32
33
|
function coordinateAuthenticationAuthority(acquire, options, body) {
|
|
33
|
-
return Effect.flatMap(acquire, (database) => coordinateSqliteAuthenticationAuthority(database, options.mapping, configurationFor(database), (transaction, services) => {
|
|
34
|
+
return Effect.flatMap(nativeDatabase(acquire), (database) => coordinateSqliteAuthenticationAuthority(database, options.mapping, configurationFor(database), (transaction, services) => {
|
|
34
35
|
const provided = Context.make(AuthenticationAuthority, services.authenticationAuthority);
|
|
35
36
|
const work = Effect.provideContext(body, provided);
|
|
36
37
|
return options.transaction === void 0 ? work : Effect.provideService(work, options.transaction, options.transaction.of(transaction));
|
|
37
|
-
}));
|
|
38
|
+
}).pipe(Effect.provideService(NativeDatabase, database)));
|
|
38
39
|
}
|
|
39
40
|
function coordinatePendingAuthentication(acquire, options, body) {
|
|
40
|
-
return Effect.flatMap(acquire, (database) => coordinateSqlitePendingAuthentication(database, options.mapping, configurationFor(database), (transaction, services) => {
|
|
41
|
+
return Effect.flatMap(nativeDatabase(acquire), (database) => coordinateSqlitePendingAuthentication(database, options.mapping, configurationFor(database), (transaction, services) => {
|
|
41
42
|
const provided = Context.make(options.target, services.pendingAuthentication);
|
|
42
43
|
const work = Effect.provideContext(body, provided);
|
|
43
44
|
return options.transaction === void 0 ? work : Effect.provideService(work, options.transaction, options.transaction.of(transaction));
|
|
44
|
-
}));
|
|
45
|
+
}).pipe(Effect.provideService(NativeDatabase, database)));
|
|
45
46
|
}
|
|
46
47
|
function coordinateStatefulSessions(acquire, options, body) {
|
|
47
|
-
return Effect.flatMap(acquire, (database) => coordinateSqliteStatefulSessions(database, options.mapping, configurationFor(database), (transaction, services) => {
|
|
48
|
+
return Effect.flatMap(nativeDatabase(acquire), (database) => coordinateSqliteStatefulSessions(database, options.mapping, configurationFor(database), (transaction, services) => {
|
|
48
49
|
const provided = Context.make(options.persistence, services.statefulSessionPersistence).pipe(Context.add(options.repository, services.sessionRepository));
|
|
49
50
|
const work = Effect.provideContext(body, provided);
|
|
50
51
|
return options.transaction === void 0 ? work : Effect.provideService(work, options.transaction, options.transaction.of(transaction));
|
|
51
|
-
}));
|
|
52
|
+
}).pipe(Effect.provideService(NativeDatabase, database)));
|
|
52
53
|
}
|
|
53
54
|
function coordinateSignedSessionValidity(acquire, options, body) {
|
|
54
|
-
return Effect.flatMap(acquire, (database) => coordinateSqliteSignedSessionValidity(database, options.mapping, configurationFor(database), (transaction, services) => {
|
|
55
|
+
return Effect.flatMap(nativeDatabase(acquire), (database) => coordinateSqliteSignedSessionValidity(database, options.mapping, configurationFor(database), (transaction, services) => {
|
|
55
56
|
const provided = Context.make(options.target, services.signedSessionValidity);
|
|
56
57
|
const work = Effect.provideContext(body, provided);
|
|
57
58
|
return options.transaction === void 0 ? work : Effect.provideService(work, options.transaction, options.transaction.of(transaction));
|
|
58
|
-
}));
|
|
59
|
+
}).pipe(Effect.provideService(NativeDatabase, database)));
|
|
59
60
|
}
|
|
60
61
|
return {
|
|
61
|
-
makeSessionStepUpServices: (mapping, target) => Effect.flatMap(standaloneConfiguration, (configuration) => makeSqliteSessionStepUpServices(mapping, target, configuration)).pipe(Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(databaseService))),
|
|
62
|
+
makeSessionStepUpServices: (mapping, target) => Effect.flatMap(standaloneConfiguration, (configuration) => makeSqliteSessionStepUpServices(mapping, target, configuration)).pipe(Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(databaseService)), Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService))),
|
|
62
63
|
coordinateSessionStepUp,
|
|
63
|
-
makeAuthenticationAuthorityServices: (mapping) => Effect.flatMap(standaloneConfiguration, (configuration) => makeSqliteAuthenticationAuthorityServices(mapping, configuration)).pipe(Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(databaseService))),
|
|
64
|
-
makePendingAuthenticationServices: (mapping) => Effect.flatMap(standaloneConfiguration, (configuration) => makeSqlitePendingAuthenticationServices(mapping, configuration)).pipe(Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(databaseService))),
|
|
65
|
-
makeStatefulSessionServices: (mapping) => Effect.flatMap(standaloneConfiguration, (configuration) => makeSqliteStatefulSessionServices(mapping, configuration)).pipe(Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(databaseService))),
|
|
66
|
-
makeSignedSessionValidityServices: (mapping) => Effect.flatMap(standaloneConfiguration, (configuration) => makeSqliteSignedSessionValidityServices(mapping, configuration)).pipe(Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(databaseService))),
|
|
64
|
+
makeAuthenticationAuthorityServices: (mapping) => Effect.flatMap(standaloneConfiguration, (configuration) => makeSqliteAuthenticationAuthorityServices(mapping, configuration)).pipe(Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(databaseService)), Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService))),
|
|
65
|
+
makePendingAuthenticationServices: (mapping) => Effect.flatMap(standaloneConfiguration, (configuration) => makeSqlitePendingAuthenticationServices(mapping, configuration)).pipe(Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(databaseService)), Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService))),
|
|
66
|
+
makeStatefulSessionServices: (mapping) => Effect.flatMap(standaloneConfiguration, (configuration) => makeSqliteStatefulSessionServices(mapping, configuration)).pipe(Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(databaseService)), Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService))),
|
|
67
|
+
makeSignedSessionValidityServices: (mapping) => Effect.flatMap(standaloneConfiguration, (configuration) => makeSqliteSignedSessionValidityServices(mapping, configuration)).pipe(Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(databaseService)), Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService))),
|
|
67
68
|
coordinateAuthenticationAuthority,
|
|
68
69
|
coordinatePendingAuthentication,
|
|
69
70
|
coordinateStatefulSessions,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-sessions.mjs","names":[],"sources":["../../src/drizzle/sqlite-sessions.ts"],"sourcesContent":["import type { LifecycleHooks, HookConfigurationError } from \"@yielded/auth/Hooks\";\nimport {\n AuthenticationAuthority,\n type SessionUnavailable,\n type PendingAuthentication,\n type SessionRepository,\n type SignedSessionValidity,\n type StatefulSessionPersistence,\n type SessionStepUpPersistence,\n} from \"@yielded/auth/Sessions\";\nimport type { AnyRelations } from \"drizzle-orm\";\nimport type { 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(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 ),\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(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 ),\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(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 ),\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(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 ),\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(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 ),\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(Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(databaseService))),\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(Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(databaseService))),\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(Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(databaseService))),\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(Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(databaseService))),\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(Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(databaseService))),\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":";;;;;;;AAwDA,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,MA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F;EACA,sCAQE,YAEA,OAAO,QAAQ,0BAA0B,kBACvC,0CAA0C,SAAS,aAAa,CAClE,CAAC,CAAC,KAAK,OAAO,qBAAqB,mBAAmB,eAAe,eAAe,CAAC,CAAC;EACxF,oCAQE,YAEA,OAAO,QAAQ,0BAA0B,kBACvC,wCAAwC,SAAS,aAAa,CAChE,CAAC,CAAC,KAAK,OAAO,qBAAqB,mBAAmB,eAAe,eAAe,CAAC,CAAC;EACxF,8BAUE,YAEA,OAAO,QAAQ,0BAA0B,kBACvC,kCAAkC,SAAS,aAAa,CAC1D,CAAC,CAAC,KAAK,OAAO,qBAAqB,mBAAmB,eAAe,eAAe,CAAC,CAAC;EACxF,oCAME,YAEA,OAAO,QAAQ,0BAA0B,kBACvC,wCAAwC,SAAS,aAAa,CAChE,CAAC,CAAC,KAAK,OAAO,qBAAqB,mBAAmB,eAAe,eAAe,CAAC,CAAC;EACxF;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
|
+
{"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,UACA,SACA,eACA,UAKA,wCACE,UACA,SACA,eACA,KACF;AAEF,MAAa,yCAYX,UACA,SACA,eACA,UAKA,sCACE,UACA,SACA,eACA,KACF;AAEF,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@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { NativeDatabase, PersistenceMappingError, validateStorage } from "@yielded/auth-persistence/Adapter";
|
|
2
|
+
import { Table, getTableColumns, getTableName, is } from "drizzle-orm";
|
|
3
|
+
import { Effect, Predicate, Schema } from "effect";
|
|
4
|
+
import { MySqlTable, getTableConfig } from "drizzle-orm/mysql-core";
|
|
5
|
+
import { PgTable, getTableConfig as getTableConfig$1 } from "drizzle-orm/pg-core";
|
|
6
|
+
import { SqlClient } from "effect/sql/SqlClient";
|
|
7
|
+
//#region src/drizzle/storage-validation.ts
|
|
8
|
+
const uniquePlans = {
|
|
9
|
+
"unique(abuseEvent.moduleId,abuseEvent.action,abuseEvent.scopeKind,abuseEvent.scopeKey,abuseEvent.commandId)": ["abuseEvent", [
|
|
10
|
+
"moduleId",
|
|
11
|
+
"action",
|
|
12
|
+
"scopeKind",
|
|
13
|
+
"scopeKey",
|
|
14
|
+
"commandId"
|
|
15
|
+
]],
|
|
16
|
+
"unique(admission.moduleId)": ["admission", ["moduleId"]],
|
|
17
|
+
"unique(attempt.moduleId,attempt.attemptId)": ["attempt", ["moduleId", "attemptId"]],
|
|
18
|
+
"unique(authority.subjectId,authority.credentialId)": ["authority", ["subjectId", "credentialId"]],
|
|
19
|
+
"unique(authorityCredential.subjectId,authorityCredential.credentialId)": ["authorityCredential", ["subjectId", "credentialId"]],
|
|
20
|
+
"unique(charge.moduleId,charge.action,charge.scopeKind,charge.scopeKey,charge.attemptId)": ["charge", [
|
|
21
|
+
"moduleId",
|
|
22
|
+
"action",
|
|
23
|
+
"scopeKind",
|
|
24
|
+
"scopeKey",
|
|
25
|
+
"attemptId"
|
|
26
|
+
]],
|
|
27
|
+
"unique(command.moduleId,command.commandId)": ["command", ["moduleId", "commandId"]],
|
|
28
|
+
"unique(connectedAdmission.admissionId)": ["admission", ["admissionId"]],
|
|
29
|
+
"unique(connectedClient.clientKey)": ["client", ["clientKey"]],
|
|
30
|
+
"unique(connectedCohort.cohortKey)": ["cohort", ["cohortKey"]],
|
|
31
|
+
"unique(connectedCommand.moduleId,connectedCommand.commandId)": ["command", ["moduleId", "commandId"]],
|
|
32
|
+
"unique(connectedFlow.moduleId,connectedFlow.commandId)": ["flow", ["moduleId", "commandId"]],
|
|
33
|
+
"unique(connectedFlow.moduleId,connectedFlow.flowId)": ["flow", ["moduleId", "flowId"]],
|
|
34
|
+
"unique(connectedFlow.stateDigest)": ["flow", ["stateDigest"]],
|
|
35
|
+
"unique(connectedGrant.moduleId,connectedGrant.grantId)": ["grant", ["moduleId", "grantId"]],
|
|
36
|
+
"unique(connectedGrant.moduleId,connectedGrant.subjectId,connectedGrant.profileKey,connectedGrant.activeIdentityKey)": ["grant", [
|
|
37
|
+
"moduleId",
|
|
38
|
+
"subjectId",
|
|
39
|
+
"profileKey",
|
|
40
|
+
"activeIdentityKey"
|
|
41
|
+
]],
|
|
42
|
+
"unique(connectedRevocation.jobId)": ["job", ["jobId"]],
|
|
43
|
+
"unique(continuation.moduleId,continuation.continuationId)": ["continuation", ["moduleId", "continuationId"]],
|
|
44
|
+
"unique(continuation.moduleId,continuation.digest)": ["continuation", ["moduleId", "digest"]],
|
|
45
|
+
"unique(credential.credentialId)": ["credential", ["credentialId"]],
|
|
46
|
+
"unique(credential.identityKey)": ["credential", ["identityKey"]],
|
|
47
|
+
"unique(credential.moduleId,credential.credentialId)": ["credential", ["moduleId", "credentialId"]],
|
|
48
|
+
"unique(credential.moduleId,credential.subjectId)": ["credential", ["moduleId", "subjectId"]],
|
|
49
|
+
"unique(emailCommand.moduleId,emailCommand.commandId)": ["command", ["moduleId", "commandId"]],
|
|
50
|
+
"unique(emailCredential.moduleId,emailCredential.credentialId)": ["credential", ["moduleId", "credentialId"]],
|
|
51
|
+
"unique(emailCredential.moduleId,emailCredential.identifierNamespace,emailCredential.identifierValue)": ["credential", [
|
|
52
|
+
"moduleId",
|
|
53
|
+
"identifierNamespace",
|
|
54
|
+
"identifierValue"
|
|
55
|
+
]],
|
|
56
|
+
"unique(emailRegistration.moduleId,emailRegistration.commandId)": ["registration", ["moduleId", "commandId"]],
|
|
57
|
+
"unique(emailRegistration.pendingReference)": ["registration", ["pendingReference"]],
|
|
58
|
+
"unique(failureEvent.moduleId,failureEvent.seriesKey,failureEvent.commandId)": ["failureEvent", [
|
|
59
|
+
"moduleId",
|
|
60
|
+
"seriesKey",
|
|
61
|
+
"commandId"
|
|
62
|
+
]],
|
|
63
|
+
"unique(flow.flowId)": ["flow", ["flowId"]],
|
|
64
|
+
"unique(flow.moduleId,flow.commandId)": ["flow", ["moduleId", "commandId"]],
|
|
65
|
+
"unique(flow.moduleId,flow.flowId)": ["flow", ["moduleId", "flowId"]],
|
|
66
|
+
"unique(flow.stateDigest)": ["flow", ["stateDigest"]],
|
|
67
|
+
"unique(generation.moduleId,generation.deliveryId)": ["generation", ["moduleId", "deliveryId"]],
|
|
68
|
+
"unique(generation.moduleId,generation.proofId)": ["generation", ["moduleId", "proofId"]],
|
|
69
|
+
"unique(identifier.namespace,identifier.value)": ["identifier", ["namespace", "value"]],
|
|
70
|
+
"unique(intent.digest)": ["intent", ["digest"]],
|
|
71
|
+
"unique(intent.flowId)": ["intent", ["flowId"]],
|
|
72
|
+
"unique(intent.moduleId,intent.commandId)": ["intent", ["moduleId", "commandId"]],
|
|
73
|
+
"unique(intent.moduleId,intent.flowId)": ["intent", ["moduleId", "flowId"]],
|
|
74
|
+
"unique(intent.moduleId,intent.intentId)": ["intent", ["moduleId", "intentId"]],
|
|
75
|
+
"unique(intent.moduleId,intent.reference)": ["intent", ["moduleId", "reference"]],
|
|
76
|
+
"unique(ownership.identityKey)": ["ownership", ["identityKey"]],
|
|
77
|
+
"unique(pending.digest)": ["pending", ["digest"]],
|
|
78
|
+
"unique(pending.flowId)": ["pending", ["flowId"]],
|
|
79
|
+
"unique(rateScope.moduleId,rateScope.action,rateScope.scopeKind,rateScope.scopeKey)": ["rateScope", [
|
|
80
|
+
"moduleId",
|
|
81
|
+
"action",
|
|
82
|
+
"scopeKind",
|
|
83
|
+
"scopeKey"
|
|
84
|
+
]],
|
|
85
|
+
"unique(rateScope.moduleId,rateScope.purpose,rateScope.action,rateScope.scopeKind,rateScope.scopeKey)": ["rateScope", [
|
|
86
|
+
"moduleId",
|
|
87
|
+
"purpose",
|
|
88
|
+
"action",
|
|
89
|
+
"scopeKind",
|
|
90
|
+
"scopeKey"
|
|
91
|
+
]],
|
|
92
|
+
"unique(registration.moduleId,registration.requestId)": ["registration", ["moduleId", "requestId"]],
|
|
93
|
+
"unique(registration.recoveryReference)": ["registration", ["recoveryReference"]],
|
|
94
|
+
"unique(registrationCommand.moduleId,registrationCommand.commandId)": ["command", ["moduleId", "commandId"]],
|
|
95
|
+
"unique(request.moduleId,request.requestId)": ["request", ["moduleId", "requestId"]],
|
|
96
|
+
"unique(series.moduleId,series.purpose,series.scopeKey)": ["series", [
|
|
97
|
+
"moduleId",
|
|
98
|
+
"purpose",
|
|
99
|
+
"scopeKey"
|
|
100
|
+
]],
|
|
101
|
+
"unique(session.digest)": ["session", ["digest"]],
|
|
102
|
+
"unique(tombstone.subjectId,tombstone.sessionId)": ["tombstone", ["subjectId", "sessionId"]],
|
|
103
|
+
"unique(tuple.identityKey)": ["ownership.tuple", ["identityKey"]],
|
|
104
|
+
"unique(unlinkCommand.moduleId,unlinkCommand.commandId)": ["command", ["moduleId", "commandId"]]
|
|
105
|
+
};
|
|
106
|
+
const arrayRoles = {
|
|
107
|
+
credentialId: "credential",
|
|
108
|
+
factor: "authority",
|
|
109
|
+
credentialOwnership: "credentialOwnership",
|
|
110
|
+
handleOwnership: "handleOwnership",
|
|
111
|
+
boundSubjectHandle: "handleOwnership",
|
|
112
|
+
flow: "flow",
|
|
113
|
+
command: "flow",
|
|
114
|
+
admission: "admission",
|
|
115
|
+
charge: "charge",
|
|
116
|
+
intentFlow: "intent",
|
|
117
|
+
intentCommand: "intent",
|
|
118
|
+
handle: "handle"
|
|
119
|
+
};
|
|
120
|
+
const nestedMappings = [
|
|
121
|
+
"read",
|
|
122
|
+
"signIn",
|
|
123
|
+
"password",
|
|
124
|
+
"proof",
|
|
125
|
+
"proofs",
|
|
126
|
+
"revocation",
|
|
127
|
+
"pending",
|
|
128
|
+
"session",
|
|
129
|
+
"source"
|
|
130
|
+
];
|
|
131
|
+
const constraintGroups = [
|
|
132
|
+
"constraints",
|
|
133
|
+
"tupleConstraints",
|
|
134
|
+
"registrationConstraints",
|
|
135
|
+
"managementConstraints"
|
|
136
|
+
];
|
|
137
|
+
const MappingRecord = Schema.Record(Schema.String, Schema.Unknown);
|
|
138
|
+
const record = Schema.decodeUnknownSync(MappingRecord);
|
|
139
|
+
const plans = (mapping) => {
|
|
140
|
+
const result = [];
|
|
141
|
+
for (const group of constraintGroups) {
|
|
142
|
+
if (mapping[group] === void 0) continue;
|
|
143
|
+
for (const [name, declaration] of Object.entries(record(mapping[group]))) {
|
|
144
|
+
if (declaration === "notNull(provisioningRequest.subjectId)") continue;
|
|
145
|
+
let role;
|
|
146
|
+
let keys;
|
|
147
|
+
if (typeof declaration === "string") {
|
|
148
|
+
const plan = uniquePlans[declaration];
|
|
149
|
+
if (plan !== void 0) [role, keys] = plan;
|
|
150
|
+
else if (declaration === "unique(id)") {
|
|
151
|
+
role = "subject";
|
|
152
|
+
keys = ["id"];
|
|
153
|
+
} else if (declaration === "unique(scope)") {
|
|
154
|
+
role = name;
|
|
155
|
+
keys = ["scope"];
|
|
156
|
+
} else if (declaration === "unique(credentialId)") {
|
|
157
|
+
role = "credential";
|
|
158
|
+
keys = ["id"];
|
|
159
|
+
} else if (declaration === "unique(namespace,value)") {
|
|
160
|
+
role = "identifier";
|
|
161
|
+
keys = ["namespace", "value"];
|
|
162
|
+
} else if (declaration === "unique(provider,issuer,subject)") {
|
|
163
|
+
role = "externalIdentity";
|
|
164
|
+
keys = [
|
|
165
|
+
"provider",
|
|
166
|
+
"issuer",
|
|
167
|
+
"subject"
|
|
168
|
+
];
|
|
169
|
+
} else if (declaration === "unique(requestId)") {
|
|
170
|
+
role = "provisioningRequest";
|
|
171
|
+
keys = ["requestId"];
|
|
172
|
+
} else throw new Error("Unknown storage constraint");
|
|
173
|
+
} else if (Array.isArray(declaration) && declaration.every(Predicate.isString)) {
|
|
174
|
+
const mappedRole = group === "managementConstraints" && name === "command" ? "command" : arrayRoles[name];
|
|
175
|
+
if (mappedRole === void 0) throw new Error("Unknown storage constraint");
|
|
176
|
+
role = mappedRole;
|
|
177
|
+
keys = declaration;
|
|
178
|
+
} else throw new Error("Invalid storage constraint");
|
|
179
|
+
let target = mapping;
|
|
180
|
+
for (const segment of role.split(".")) target = record(target)[segment];
|
|
181
|
+
if (target === void 0 && Schema.is(MappingRecord)(mapping.pending)) target = mapping.pending[role];
|
|
182
|
+
let mapped = record(target);
|
|
183
|
+
if (role === "pending" && mapped.table === void 0) mapped = record(mapped.pending);
|
|
184
|
+
if (role === "ownership" && mapped.table === void 0) mapped = record(mapped.external ?? mapped.tuple);
|
|
185
|
+
if (!is(mapped.table, Table)) throw new Error("Missing storage table");
|
|
186
|
+
const columns = getTableColumns(mapped.table);
|
|
187
|
+
result.push({
|
|
188
|
+
table: mapped.table,
|
|
189
|
+
keys: keys.map((key) => {
|
|
190
|
+
const value = mapped[key];
|
|
191
|
+
if (typeof value !== "string" || columns[value] === void 0) throw new Error("Missing mapped key");
|
|
192
|
+
return value;
|
|
193
|
+
})
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
for (const nested of nestedMappings) {
|
|
198
|
+
const value = mapping[nested];
|
|
199
|
+
if (Schema.is(MappingRecord)(value) && value.table === void 0) result.push(...plans(value));
|
|
200
|
+
}
|
|
201
|
+
return result;
|
|
202
|
+
};
|
|
203
|
+
/** Validate at acquisition using the root database supplied by the adapter. */
|
|
204
|
+
const validateDrizzleStorage = Effect.fnUntraced(function* (mapping) {
|
|
205
|
+
const physical = yield* Effect.try({
|
|
206
|
+
try: () => plans(record(mapping)),
|
|
207
|
+
catch: () => PersistenceMappingError.make({
|
|
208
|
+
operation: "mapping",
|
|
209
|
+
cause: "Invalid storage key mapping"
|
|
210
|
+
})
|
|
211
|
+
});
|
|
212
|
+
const { $client: client } = yield* NativeDatabase;
|
|
213
|
+
for (const plan of physical) {
|
|
214
|
+
const pg = is(plan.table, PgTable);
|
|
215
|
+
const mysql = is(plan.table, MySqlTable);
|
|
216
|
+
const schema = pg ? getTableConfig$1(plan.table).schema : mysql ? getTableConfig(plan.table).schema : void 0;
|
|
217
|
+
const columns = getTableColumns(plan.table);
|
|
218
|
+
yield* validateStorage(pg ? "pg" : mysql ? "mysql" : "sqlite", {
|
|
219
|
+
name: getTableName(plan.table),
|
|
220
|
+
...schema === void 0 ? {} : { schema },
|
|
221
|
+
columns: Object.fromEntries(plan.keys.map((key) => [key, { name: columns[key].name }]))
|
|
222
|
+
}, [plan.keys]).pipe(Effect.provideService(SqlClient, client), Effect.mapError(() => PersistenceMappingError.make({
|
|
223
|
+
operation: "mapping",
|
|
224
|
+
cause: "Required SQL storage key is unavailable"
|
|
225
|
+
})));
|
|
226
|
+
}
|
|
227
|
+
}, Effect.catchDefect(() => Effect.fail(PersistenceMappingError.make({
|
|
228
|
+
operation: "mapping",
|
|
229
|
+
cause: "Cannot inspect SQL storage metadata"
|
|
230
|
+
}))));
|
|
231
|
+
//#endregion
|
|
232
|
+
export { validateDrizzleStorage };
|
|
233
|
+
|
|
234
|
+
//# sourceMappingURL=storage-validation.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-validation.mjs","names":["getPgTableConfig","getMysqlTableConfig"],"sources":["../../src/drizzle/storage-validation.ts"],"sourcesContent":["import {\n NativeDatabase,\n PersistenceMappingError,\n validateStorage,\n} from \"@yielded/auth-persistence/Adapter\";\nimport { getTableColumns, getTableName, is, Table } from \"drizzle-orm\";\nimport { getTableConfig as getMysqlTableConfig, MySqlTable } from \"drizzle-orm/mysql-core\";\nimport { getTableConfig as getPgTableConfig, PgTable } from \"drizzle-orm/pg-core\";\nimport { Effect, Predicate, Schema } from \"effect\";\nimport { SqlClient } from \"effect/sql/SqlClient\";\n\n// These are mapping contracts, not a parser for arbitrary constraint declarations.\n// Role aliases are explicit because their documentation names differ from mapping fields.\nconst uniquePlans: Readonly<Record<string, readonly [string, ReadonlyArray<string>]>> = {\n \"unique(abuseEvent.moduleId,abuseEvent.action,abuseEvent.scopeKind,abuseEvent.scopeKey,abuseEvent.commandId)\":\n [\"abuseEvent\", [\"moduleId\", \"action\", \"scopeKind\", \"scopeKey\", \"commandId\"]],\n \"unique(admission.moduleId)\": [\"admission\", [\"moduleId\"]],\n \"unique(attempt.moduleId,attempt.attemptId)\": [\"attempt\", [\"moduleId\", \"attemptId\"]],\n \"unique(authority.subjectId,authority.credentialId)\": [\n \"authority\",\n [\"subjectId\", \"credentialId\"],\n ],\n \"unique(authorityCredential.subjectId,authorityCredential.credentialId)\": [\n \"authorityCredential\",\n [\"subjectId\", \"credentialId\"],\n ],\n \"unique(charge.moduleId,charge.action,charge.scopeKind,charge.scopeKey,charge.attemptId)\": [\n \"charge\",\n [\"moduleId\", \"action\", \"scopeKind\", \"scopeKey\", \"attemptId\"],\n ],\n \"unique(command.moduleId,command.commandId)\": [\"command\", [\"moduleId\", \"commandId\"]],\n \"unique(connectedAdmission.admissionId)\": [\"admission\", [\"admissionId\"]],\n \"unique(connectedClient.clientKey)\": [\"client\", [\"clientKey\"]],\n \"unique(connectedCohort.cohortKey)\": [\"cohort\", [\"cohortKey\"]],\n \"unique(connectedCommand.moduleId,connectedCommand.commandId)\": [\n \"command\",\n [\"moduleId\", \"commandId\"],\n ],\n \"unique(connectedFlow.moduleId,connectedFlow.commandId)\": [\"flow\", [\"moduleId\", \"commandId\"]],\n \"unique(connectedFlow.moduleId,connectedFlow.flowId)\": [\"flow\", [\"moduleId\", \"flowId\"]],\n \"unique(connectedFlow.stateDigest)\": [\"flow\", [\"stateDigest\"]],\n \"unique(connectedGrant.moduleId,connectedGrant.grantId)\": [\"grant\", [\"moduleId\", \"grantId\"]],\n \"unique(connectedGrant.moduleId,connectedGrant.subjectId,connectedGrant.profileKey,connectedGrant.activeIdentityKey)\":\n [\"grant\", [\"moduleId\", \"subjectId\", \"profileKey\", \"activeIdentityKey\"]],\n \"unique(connectedRevocation.jobId)\": [\"job\", [\"jobId\"]],\n \"unique(continuation.moduleId,continuation.continuationId)\": [\n \"continuation\",\n [\"moduleId\", \"continuationId\"],\n ],\n \"unique(continuation.moduleId,continuation.digest)\": [\"continuation\", [\"moduleId\", \"digest\"]],\n \"unique(credential.credentialId)\": [\"credential\", [\"credentialId\"]],\n \"unique(credential.identityKey)\": [\"credential\", [\"identityKey\"]],\n \"unique(credential.moduleId,credential.credentialId)\": [\n \"credential\",\n [\"moduleId\", \"credentialId\"],\n ],\n \"unique(credential.moduleId,credential.subjectId)\": [\"credential\", [\"moduleId\", \"subjectId\"]],\n \"unique(emailCommand.moduleId,emailCommand.commandId)\": [\"command\", [\"moduleId\", \"commandId\"]],\n \"unique(emailCredential.moduleId,emailCredential.credentialId)\": [\n \"credential\",\n [\"moduleId\", \"credentialId\"],\n ],\n \"unique(emailCredential.moduleId,emailCredential.identifierNamespace,emailCredential.identifierValue)\":\n [\"credential\", [\"moduleId\", \"identifierNamespace\", \"identifierValue\"]],\n \"unique(emailRegistration.moduleId,emailRegistration.commandId)\": [\n \"registration\",\n [\"moduleId\", \"commandId\"],\n ],\n \"unique(emailRegistration.pendingReference)\": [\"registration\", [\"pendingReference\"]],\n \"unique(failureEvent.moduleId,failureEvent.seriesKey,failureEvent.commandId)\": [\n \"failureEvent\",\n [\"moduleId\", \"seriesKey\", \"commandId\"],\n ],\n \"unique(flow.flowId)\": [\"flow\", [\"flowId\"]],\n \"unique(flow.moduleId,flow.commandId)\": [\"flow\", [\"moduleId\", \"commandId\"]],\n \"unique(flow.moduleId,flow.flowId)\": [\"flow\", [\"moduleId\", \"flowId\"]],\n \"unique(flow.stateDigest)\": [\"flow\", [\"stateDigest\"]],\n \"unique(generation.moduleId,generation.deliveryId)\": [\"generation\", [\"moduleId\", \"deliveryId\"]],\n \"unique(generation.moduleId,generation.proofId)\": [\"generation\", [\"moduleId\", \"proofId\"]],\n \"unique(identifier.namespace,identifier.value)\": [\"identifier\", [\"namespace\", \"value\"]],\n \"unique(intent.digest)\": [\"intent\", [\"digest\"]],\n \"unique(intent.flowId)\": [\"intent\", [\"flowId\"]],\n \"unique(intent.moduleId,intent.commandId)\": [\"intent\", [\"moduleId\", \"commandId\"]],\n \"unique(intent.moduleId,intent.flowId)\": [\"intent\", [\"moduleId\", \"flowId\"]],\n \"unique(intent.moduleId,intent.intentId)\": [\"intent\", [\"moduleId\", \"intentId\"]],\n \"unique(intent.moduleId,intent.reference)\": [\"intent\", [\"moduleId\", \"reference\"]],\n \"unique(ownership.identityKey)\": [\"ownership\", [\"identityKey\"]],\n \"unique(pending.digest)\": [\"pending\", [\"digest\"]],\n \"unique(pending.flowId)\": [\"pending\", [\"flowId\"]],\n \"unique(rateScope.moduleId,rateScope.action,rateScope.scopeKind,rateScope.scopeKey)\": [\n \"rateScope\",\n [\"moduleId\", \"action\", \"scopeKind\", \"scopeKey\"],\n ],\n \"unique(rateScope.moduleId,rateScope.purpose,rateScope.action,rateScope.scopeKind,rateScope.scopeKey)\":\n [\"rateScope\", [\"moduleId\", \"purpose\", \"action\", \"scopeKind\", \"scopeKey\"]],\n \"unique(registration.moduleId,registration.requestId)\": [\n \"registration\",\n [\"moduleId\", \"requestId\"],\n ],\n \"unique(registration.recoveryReference)\": [\"registration\", [\"recoveryReference\"]],\n \"unique(registrationCommand.moduleId,registrationCommand.commandId)\": [\n \"command\",\n [\"moduleId\", \"commandId\"],\n ],\n \"unique(request.moduleId,request.requestId)\": [\"request\", [\"moduleId\", \"requestId\"]],\n \"unique(series.moduleId,series.purpose,series.scopeKey)\": [\n \"series\",\n [\"moduleId\", \"purpose\", \"scopeKey\"],\n ],\n \"unique(session.digest)\": [\"session\", [\"digest\"]],\n \"unique(tombstone.subjectId,tombstone.sessionId)\": [\"tombstone\", [\"subjectId\", \"sessionId\"]],\n \"unique(tuple.identityKey)\": [\"ownership.tuple\", [\"identityKey\"]],\n \"unique(unlinkCommand.moduleId,unlinkCommand.commandId)\": [\"command\", [\"moduleId\", \"commandId\"]],\n};\n\nconst arrayRoles: Readonly<Record<string, string>> = {\n credentialId: \"credential\",\n factor: \"authority\",\n credentialOwnership: \"credentialOwnership\",\n handleOwnership: \"handleOwnership\",\n boundSubjectHandle: \"handleOwnership\",\n flow: \"flow\",\n command: \"flow\",\n admission: \"admission\",\n charge: \"charge\",\n intentFlow: \"intent\",\n intentCommand: \"intent\",\n handle: \"handle\",\n};\n\nconst nestedMappings = [\n \"read\",\n \"signIn\",\n \"password\",\n \"proof\",\n \"proofs\",\n \"revocation\",\n \"pending\",\n \"session\",\n \"source\",\n];\n\nconst constraintGroups = [\n \"constraints\",\n \"tupleConstraints\",\n \"registrationConstraints\",\n \"managementConstraints\",\n];\n\nconst MappingRecord = Schema.Record(Schema.String, Schema.Unknown);\nconst record = Schema.decodeUnknownSync(MappingRecord);\n\nconst plans = (mapping: Readonly<Record<string, unknown>>) => {\n const result: Array<{ readonly table: Table; readonly keys: ReadonlyArray<string> }> = [];\n\n for (const group of constraintGroups) {\n if (mapping[group] === undefined) continue;\n for (const [name, declaration] of Object.entries(record(mapping[group]))) {\n if (declaration === \"notNull(provisioningRequest.subjectId)\") continue;\n let role: string;\n let keys: ReadonlyArray<string>;\n\n if (typeof declaration === \"string\") {\n const plan = uniquePlans[declaration];\n\n if (plan !== undefined) [role, keys] = plan;\n else if (declaration === \"unique(id)\") {\n role = \"subject\";\n keys = [\"id\"];\n } else if (declaration === \"unique(scope)\") {\n role = name;\n keys = [\"scope\"];\n } else if (declaration === \"unique(credentialId)\") {\n role = \"credential\";\n keys = [\"id\"];\n } else if (declaration === \"unique(namespace,value)\") {\n role = \"identifier\";\n keys = [\"namespace\", \"value\"];\n } else if (declaration === \"unique(provider,issuer,subject)\") {\n role = \"externalIdentity\";\n keys = [\"provider\", \"issuer\", \"subject\"];\n } else if (declaration === \"unique(requestId)\") {\n role = \"provisioningRequest\";\n keys = [\"requestId\"];\n } else throw new Error(\"Unknown storage constraint\");\n } else if (Array.isArray(declaration) && declaration.every(Predicate.isString)) {\n const mappedRole =\n group === \"managementConstraints\" && name === \"command\" ? \"command\" : arrayRoles[name];\n\n if (mappedRole === undefined) throw new Error(\"Unknown storage constraint\");\n role = mappedRole;\n keys = declaration;\n } else throw new Error(\"Invalid storage constraint\");\n\n let target: unknown = mapping;\n\n for (const segment of role.split(\".\")) target = record(target)[segment];\n // Session authority places its pending tables in one nested mapping.\n if (target === undefined && Schema.is(MappingRecord)(mapping.pending))\n target = mapping.pending[role];\n let mapped = record(target);\n\n if (role === \"pending\" && mapped.table === undefined) mapped = record(mapped.pending);\n // OAuth ownership can be integrated into its tuple authority or separate.\n if (role === \"ownership\" && mapped.table === undefined)\n mapped = record(mapped.external ?? mapped.tuple);\n if (!is(mapped.table, Table)) throw new Error(\"Missing storage table\");\n const columns = getTableColumns(mapped.table);\n\n result.push({\n table: mapped.table,\n keys: keys.map((key) => {\n const value = mapped[key];\n\n if (typeof value !== \"string\" || columns[value] === undefined)\n throw new Error(\"Missing mapped key\");\n\n return value;\n }),\n });\n }\n }\n for (const nested of nestedMappings) {\n const value = mapping[nested];\n\n if (Schema.is(MappingRecord)(value) && value.table === undefined) result.push(...plans(value));\n }\n\n return result;\n};\n\n/** Validate at acquisition using the root database supplied by the adapter. */\nexport const validateDrizzleStorage = Effect.fnUntraced(\n function* (mapping: unknown) {\n const physical = yield* Effect.try({\n try: () => plans(record(mapping)),\n catch: () =>\n PersistenceMappingError.make({\n operation: \"mapping\",\n cause: \"Invalid storage key mapping\",\n }),\n });\n\n const { $client: client } = yield* NativeDatabase;\n\n for (const plan of physical) {\n const pg = is(plan.table, PgTable);\n const mysql = is(plan.table, MySqlTable);\n\n const schema = pg\n ? getPgTableConfig(plan.table).schema\n : mysql\n ? getMysqlTableConfig(plan.table).schema\n : undefined;\n\n const columns = getTableColumns(plan.table);\n\n yield* validateStorage(\n pg ? \"pg\" : mysql ? \"mysql\" : \"sqlite\",\n {\n name: getTableName(plan.table),\n ...(schema === undefined ? {} : { schema }),\n columns: Object.fromEntries(plan.keys.map((key) => [key, { name: columns[key]!.name }])),\n },\n [plan.keys],\n ).pipe(\n Effect.provideService(SqlClient, client),\n Effect.mapError(() =>\n PersistenceMappingError.make({\n operation: \"mapping\",\n cause: \"Required SQL storage key is unavailable\",\n }),\n ),\n );\n }\n },\n Effect.catchDefect(() =>\n Effect.fail(\n PersistenceMappingError.make({\n operation: \"mapping\",\n cause: \"Cannot inspect SQL storage metadata\",\n }),\n ),\n ),\n);\n"],"mappings":";;;;;;;AAaA,MAAM,cAAkF;CACtF,+GACE,CAAC,cAAc;EAAC;EAAY;EAAU;EAAa;EAAY;CAAW,CAAC;CAC7E,8BAA8B,CAAC,aAAa,CAAC,UAAU,CAAC;CACxD,8CAA8C,CAAC,WAAW,CAAC,YAAY,WAAW,CAAC;CACnF,sDAAsD,CACpD,aACA,CAAC,aAAa,cAAc,CAC9B;CACA,0EAA0E,CACxE,uBACA,CAAC,aAAa,cAAc,CAC9B;CACA,2FAA2F,CACzF,UACA;EAAC;EAAY;EAAU;EAAa;EAAY;CAAW,CAC7D;CACA,8CAA8C,CAAC,WAAW,CAAC,YAAY,WAAW,CAAC;CACnF,0CAA0C,CAAC,aAAa,CAAC,aAAa,CAAC;CACvE,qCAAqC,CAAC,UAAU,CAAC,WAAW,CAAC;CAC7D,qCAAqC,CAAC,UAAU,CAAC,WAAW,CAAC;CAC7D,gEAAgE,CAC9D,WACA,CAAC,YAAY,WAAW,CAC1B;CACA,0DAA0D,CAAC,QAAQ,CAAC,YAAY,WAAW,CAAC;CAC5F,uDAAuD,CAAC,QAAQ,CAAC,YAAY,QAAQ,CAAC;CACtF,qCAAqC,CAAC,QAAQ,CAAC,aAAa,CAAC;CAC7D,0DAA0D,CAAC,SA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,eAAoB,KAAK,KAAK,CAAC,CAAC,SAChC,KAAA;EAEN,MAAM,UAAU,gBAAgB,KAAK,KAAK;EAE1C,OAAO,gBACL,KAAK,OAAO,QAAQ,UAAU,UAC9B;GACE,MAAM,aAAa,KAAK,KAAK;GAC7B,GAAI,WAAW,KAAA,IAAY,CAAC,IAAI,EAAE,OAAO;GACzC,SAAS,OAAO,YAAY,KAAK,KAAK,KAAK,QAAQ,CAAC,KAAK,EAAE,MAAM,QAAQ,IAAI,CAAE,KAAK,CAAC,CAAC,CAAC;EACzF,GACA,CAAC,KAAK,IAAI,CACZ,CAAC,CAAC,KACA,OAAO,eAAe,WAAW,MAAM,GACvC,OAAO,eACL,wBAAwB,KAAK;GAC3B,WAAW;GACX,OAAO;EACT,CAAC,CACH,CACF;CACF;AACF,GACA,OAAO,kBACL,OAAO,KACL,wBAAwB,KAAK;CAC3B,WAAW;CACX,OAAO;AACT,CAAC,CACH,CACF,CACF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { validateDrizzleStorage } from "./storage-validation.mjs";
|
|
1
2
|
import { coordinateTransactionOwner, makeTransactionExecution, sqlClientTransactionStandaloneGuard } from "./transaction-execution.mjs";
|
|
2
3
|
import { requiredTotpConstraints } from "./totp-model.mjs";
|
|
3
4
|
import { CurrentTotpTransaction, captureTotp, invariant, mutateTotp, unavailable } from "./totp-state.mjs";
|
|
@@ -53,6 +54,7 @@ const makeTargetTotpPersistence = (source, configuration) => Effect.gen(function
|
|
|
53
54
|
try: () => validateMapping(original, configuration),
|
|
54
55
|
catch: () => TotpConfigurationError.make({})
|
|
55
56
|
});
|
|
57
|
+
yield* validateDrizzleStorage(mapping).pipe(Effect.mapError(() => TotpConfigurationError.make({})));
|
|
56
58
|
const execution = yield* makeTransactionExecution(CurrentTotpTransaction, configuration, unavailable, randomId);
|
|
57
59
|
return yield* services(mapping, execution);
|
|
58
60
|
});
|
|
@@ -62,16 +64,17 @@ const coordinateTargetTotp = (database, source, configuration, body) => Effect.g
|
|
|
62
64
|
try: () => validateMapping(original, configuration),
|
|
63
65
|
catch: () => TotpConfigurationError.make({})
|
|
64
66
|
});
|
|
67
|
+
yield* validateDrizzleStorage(mapping).pipe(Effect.mapError(() => TotpConfigurationError.make({})));
|
|
65
68
|
return yield* coordinateTransactionOwner(database, CurrentTotpTransaction, configuration, Effect.void, unavailable, randomId, (execution) => services(mapping, execution), (transaction, acquireServices, append) => Effect.flatMap(acquireServices, (boundServices) => body(transaction, boundServices, append)));
|
|
66
69
|
});
|
|
67
70
|
/** Concrete driver wrappers select transaction mode; cryptography always precedes these owners. */
|
|
68
71
|
const makeTotpTarget = (databaseService, configuration) => {
|
|
69
72
|
function coordinateTotpPersistence(acquire, options, body) {
|
|
70
|
-
return Effect.flatMap(acquire, (database) => coordinateTargetTotp(database, options.mapping, configuration, (transaction, services) => {
|
|
73
|
+
return Effect.flatMap(nativeDatabase(acquire), (database) => coordinateTargetTotp(database, options.mapping, configuration, (transaction, services) => {
|
|
71
74
|
const provided = Context.make(TotpPersistence, services.totpPersistence);
|
|
72
75
|
const work = Effect.provideContext(body, provided);
|
|
73
76
|
return options.transaction === void 0 ? work : Effect.provideService(work, options.transaction, options.transaction.of(transaction));
|
|
74
|
-
}));
|
|
77
|
+
}).pipe(Effect.provideService(NativeDatabase, database)));
|
|
75
78
|
}
|
|
76
79
|
return {
|
|
77
80
|
makeTotpPersistenceServices: (mapping) => makeTargetTotpPersistence(mapping, configuration).pipe(Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService))),
|