@yielded/auth-persistence-drizzle 0.1.0-beta.0 → 0.1.0-beta.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -1
- package/dist/D1.d.mts +155 -40
- package/dist/D1.mjs +10 -6
- package/dist/D1.mjs.map +1 -1
- package/dist/Libsql.d.mts +251 -129
- package/dist/Libsql.mjs +20 -21
- package/dist/Libsql.mjs.map +1 -1
- package/dist/Mysql2.d.mts +208 -56
- package/dist/Mysql2.mjs +13 -8
- package/dist/Mysql2.mjs.map +1 -1
- package/dist/Pglite.d.mts +209 -57
- package/dist/Pglite.mjs +13 -9
- package/dist/Pglite.mjs.map +1 -1
- package/dist/Postgres.d.mts +207 -55
- package/dist/Postgres.mjs +13 -9
- package/dist/Postgres.mjs.map +1 -1
- package/dist/SqliteBun.d.mts +249 -126
- package/dist/SqliteBun.mjs +20 -18
- package/dist/SqliteBun.mjs.map +1 -1
- package/dist/SqliteDo.d.mts +248 -158
- package/dist/SqliteDo.mjs +26 -44
- package/dist/SqliteDo.mjs.map +1 -1
- package/dist/SqliteNode.d.mts +247 -124
- package/dist/SqliteNode.mjs +20 -18
- package/dist/SqliteNode.mjs.map +1 -1
- package/dist/SqliteWasm.d.mts +251 -128
- package/dist/SqliteWasm.mjs +20 -18
- package/dist/SqliteWasm.mjs.map +1 -1
- package/dist/drizzle/D1BatchStatements.d.mts +1 -1
- package/dist/drizzle/D1BatchStatements.mjs.map +1 -1
- package/dist/drizzle/d1-database.d.mts +11 -0
- package/dist/drizzle/d1-database.mjs +8 -0
- package/dist/drizzle/d1-database.mjs.map +1 -0
- package/dist/drizzle/d1-emails.d.mts +8 -7
- package/dist/drizzle/d1-emails.mjs +7 -4
- package/dist/drizzle/d1-emails.mjs.map +1 -1
- package/dist/drizzle/d1-generated-statement.mjs.map +1 -1
- package/dist/drizzle/d1-identity.mjs +12 -9
- package/dist/drizzle/d1-identity.mjs.map +1 -1
- package/dist/drizzle/d1-oauth.d.mts +41 -10
- package/dist/drizzle/d1-oauth.mjs +8 -5
- package/dist/drizzle/d1-oauth.mjs.map +1 -1
- package/dist/drizzle/d1-passkey.d.mts +3 -14
- package/dist/drizzle/d1-passkey.mjs +2 -1
- package/dist/drizzle/d1-passkey.mjs.map +1 -1
- package/dist/drizzle/d1-password-prepared.d.mts +4 -3
- package/dist/drizzle/d1-password-prepared.mjs +3 -1
- package/dist/drizzle/d1-password-prepared.mjs.map +1 -1
- package/dist/drizzle/d1-passwords.d.mts +7 -6
- package/dist/drizzle/d1-passwords.mjs +5 -2
- package/dist/drizzle/d1-passwords.mjs.map +1 -1
- package/dist/drizzle/d1-phone.d.mts +3 -4
- package/dist/drizzle/d1-phone.mjs +2 -1
- package/dist/drizzle/d1-phone.mjs.map +1 -1
- package/dist/drizzle/d1-planning.d.mts +1 -1
- package/dist/drizzle/d1-proofs.d.mts +5 -4
- package/dist/drizzle/d1-proofs.mjs +3 -1
- package/dist/drizzle/d1-proofs.mjs.map +1 -1
- package/dist/drizzle/d1-sessions.d.mts +14 -13
- package/dist/drizzle/d1-sessions.mjs +15 -9
- package/dist/drizzle/d1-sessions.mjs.map +1 -1
- package/dist/drizzle/d1-totp.d.mts +3 -4
- package/dist/drizzle/d1-totp.mjs +2 -1
- package/dist/drizzle/d1-totp.mjs.map +1 -1
- package/dist/drizzle/email-registration.d.mts +1 -1
- package/dist/drizzle/email-registration.mjs +2 -1
- package/dist/drizzle/email-registration.mjs.map +1 -1
- package/dist/drizzle/email-target.d.mts +8 -7
- package/dist/drizzle/email-target.mjs +10 -10
- package/dist/drizzle/email-target.mjs.map +1 -1
- package/dist/drizzle/model.d.mts +2 -126
- package/dist/drizzle/model.mjs +2 -21
- package/dist/drizzle/model.mjs.map +1 -1
- package/dist/drizzle/mysql-database.d.mts +8 -0
- package/dist/drizzle/mysql-database.mjs +8 -0
- package/dist/drizzle/mysql-database.mjs.map +1 -0
- package/dist/drizzle/mysql-emails.d.mts +8 -7
- package/dist/drizzle/mysql-emails.mjs +12 -8
- package/dist/drizzle/mysql-emails.mjs.map +1 -1
- package/dist/drizzle/mysql-identity.mjs +12 -9
- package/dist/drizzle/mysql-identity.mjs.map +1 -1
- package/dist/drizzle/mysql-password-prepared.d.mts +4 -3
- package/dist/drizzle/mysql-password-prepared.mjs +6 -2
- package/dist/drizzle/mysql-password-prepared.mjs.map +1 -1
- package/dist/drizzle/mysql-passwords.d.mts +7 -5
- package/dist/drizzle/mysql-passwords.mjs +11 -7
- package/dist/drizzle/mysql-passwords.mjs.map +1 -1
- package/dist/drizzle/mysql-proofs.d.mts +4 -3
- package/dist/drizzle/mysql-proofs.mjs +8 -4
- package/dist/drizzle/mysql-proofs.mjs.map +1 -1
- package/dist/drizzle/mysql-sessions.d.mts +12 -11
- package/dist/drizzle/mysql-sessions.mjs +16 -12
- package/dist/drizzle/mysql-sessions.mjs.map +1 -1
- package/dist/drizzle/native-database.mjs +10 -0
- package/dist/drizzle/native-database.mjs.map +1 -0
- package/dist/drizzle/oauth-accounts.mjs +1 -1
- package/dist/drizzle/oauth-connected-access.mjs +14 -12
- package/dist/drizzle/oauth-connected-access.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-custody.mjs +2 -2
- package/dist/drizzle/oauth-connected-drivers.mjs +11 -6
- package/dist/drizzle/oauth-connected-drivers.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-flow.mjs +2 -2
- package/dist/drizzle/oauth-connected-input.mjs +14 -1
- package/dist/drizzle/oauth-connected-input.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-maintenance.mjs +1 -1
- package/dist/drizzle/oauth-connected-management.mjs +2 -2
- package/dist/drizzle/oauth-connected-model.d.mts +17 -3
- package/dist/drizzle/oauth-connected-model.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-settlement.mjs +51 -41
- package/dist/drizzle/oauth-connected-settlement.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-sign-in.mjs +263 -0
- package/dist/drizzle/oauth-connected-sign-in.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-state.d.mts +110 -2
- package/dist/drizzle/oauth-connected-state.mjs +9 -4
- package/dist/drizzle/oauth-connected-state.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-target.d.mts +142 -15
- package/dist/drizzle/oauth-connected-target.mjs +9 -6
- package/dist/drizzle/oauth-connected-target.mjs.map +1 -1
- package/dist/drizzle/oauth-drivers.mjs +9 -7
- package/dist/drizzle/oauth-drivers.mjs.map +1 -1
- package/dist/drizzle/oauth-flow.d.mts +1 -1
- package/dist/drizzle/oauth-flow.mjs +1 -1
- package/dist/drizzle/oauth-input.mjs +1 -1
- package/dist/drizzle/oauth-model.d.mts +1 -1
- package/dist/drizzle/oauth-owner.d.mts +1 -1
- package/dist/drizzle/oauth-registration.d.mts +2 -2
- package/dist/drizzle/oauth-registration.mjs +1 -1
- package/dist/drizzle/oauth-state.mjs +5 -4
- package/dist/drizzle/oauth-state.mjs.map +1 -1
- package/dist/drizzle/oauth-target.d.mts +14 -13
- package/dist/drizzle/oauth-target.mjs +14 -13
- package/dist/drizzle/oauth-target.mjs.map +1 -1
- package/dist/drizzle/passkey-drivers.mjs +8 -6
- package/dist/drizzle/passkey-drivers.mjs.map +1 -1
- package/dist/drizzle/passkey-write-drivers.mjs +5 -3
- package/dist/drizzle/passkey-write-drivers.mjs.map +1 -1
- package/dist/drizzle/passkey-write-target.d.mts +1 -1
- package/dist/drizzle/password-prepared-sql.mjs +2 -1
- package/dist/drizzle/password-prepared-sql.mjs.map +1 -1
- package/dist/drizzle/password-prepared-state.mjs +1 -1
- package/dist/drizzle/password-prepared-target.d.mts +4 -3
- package/dist/drizzle/password-prepared-target.mjs +4 -3
- package/dist/drizzle/password-prepared-target.mjs.map +1 -1
- package/dist/drizzle/password-registration.mjs +2 -1
- package/dist/drizzle/password-registration.mjs.map +1 -1
- package/dist/drizzle/password-target.d.mts +6 -5
- package/dist/drizzle/password-target.mjs +8 -8
- package/dist/drizzle/password-target.mjs.map +1 -1
- package/dist/drizzle/pg-database.d.mts +9 -0
- package/dist/drizzle/pg-database.mjs +8 -0
- package/dist/drizzle/pg-database.mjs.map +1 -0
- package/dist/drizzle/pg-emails.d.mts +8 -7
- package/dist/drizzle/pg-emails.mjs +12 -8
- package/dist/drizzle/pg-emails.mjs.map +1 -1
- package/dist/drizzle/pg-identity.mjs +92 -0
- package/dist/drizzle/pg-identity.mjs.map +1 -0
- package/dist/drizzle/pg-password-prepared.d.mts +4 -3
- package/dist/drizzle/pg-password-prepared.mjs +6 -2
- package/dist/drizzle/pg-password-prepared.mjs.map +1 -1
- package/dist/drizzle/pg-passwords.d.mts +7 -5
- package/dist/drizzle/pg-passwords.mjs +11 -7
- package/dist/drizzle/pg-passwords.mjs.map +1 -1
- package/dist/drizzle/pg-proofs.d.mts +4 -3
- package/dist/drizzle/pg-proofs.mjs +8 -4
- package/dist/drizzle/pg-proofs.mjs.map +1 -1
- package/dist/drizzle/pg-sessions.d.mts +12 -11
- package/dist/drizzle/pg-sessions.mjs +16 -12
- package/dist/drizzle/pg-sessions.mjs.map +1 -1
- package/dist/drizzle/phone-model.d.mts +1 -1
- package/dist/drizzle/phone-target.d.mts +5 -4
- package/dist/drizzle/phone-target.mjs +12 -11
- package/dist/drizzle/phone-target.mjs.map +1 -1
- package/dist/drizzle/proof-target.d.mts +4 -3
- package/dist/drizzle/proof-target.mjs +5 -5
- package/dist/drizzle/proof-target.mjs.map +1 -1
- package/dist/drizzle/session-sql.d.mts +1 -0
- package/dist/drizzle/session-target.d.mts +11 -9
- package/dist/drizzle/session-target.mjs +11 -11
- package/dist/drizzle/session-target.mjs.map +1 -1
- package/dist/drizzle/sqlite-emails.mjs +9 -5
- package/dist/drizzle/sqlite-emails.mjs.map +1 -1
- package/dist/drizzle/sqlite-identity.mjs +14 -11
- package/dist/drizzle/sqlite-identity.mjs.map +1 -1
- package/dist/drizzle/sqlite-password-prepared.mjs +7 -3
- package/dist/drizzle/sqlite-password-prepared.mjs.map +1 -1
- package/dist/drizzle/sqlite-passwords.mjs +10 -6
- package/dist/drizzle/sqlite-passwords.mjs.map +1 -1
- package/dist/drizzle/sqlite-proofs.mjs +7 -3
- package/dist/drizzle/sqlite-proofs.mjs.map +1 -1
- package/dist/drizzle/sqlite-sessions.mjs +16 -12
- package/dist/drizzle/sqlite-sessions.mjs.map +1 -1
- package/dist/drizzle/standalone-guard.d.mts +2 -0
- package/dist/drizzle/standalone-guard.mjs +8 -4
- package/dist/drizzle/standalone-guard.mjs.map +1 -1
- package/dist/drizzle/totp-model.d.mts +1 -1
- package/dist/drizzle/totp-target.d.mts +5 -4
- package/dist/drizzle/totp-target.mjs +31 -28
- package/dist/drizzle/totp-target.mjs.map +1 -1
- package/dist/drizzle/transaction-mysql.mjs +1 -1
- package/dist/drizzle/transaction-mysql.mjs.map +1 -1
- package/dist/index.d.mts +2 -4
- package/dist/index.mjs +2 -4
- package/dist/internal/drizzle-postgres.mjs.map +1 -1
- package/dist/internal/drizzle-sqlite.mjs.map +1 -1
- package/package.json +1 -1
- package/src/D1.ts +37 -26
- package/src/Libsql.ts +45 -61
- package/src/Mysql2.ts +39 -35
- package/src/Pglite.ts +48 -30
- package/src/Postgres.ts +48 -30
- package/src/SqliteBun.ts +59 -68
- package/src/SqliteDo.ts +61 -274
- package/src/SqliteNode.ts +56 -66
- package/src/SqliteWasm.ts +56 -66
- package/src/drizzle/D1BatchStatements.ts +1 -1
- package/src/drizzle/d1-database.ts +10 -0
- package/src/drizzle/d1-emails.ts +86 -88
- package/src/drizzle/d1-generated-statement.ts +1 -1
- package/src/drizzle/d1-identity.ts +17 -20
- package/src/drizzle/d1-oauth.ts +19 -8
- package/src/drizzle/d1-passkey.ts +5 -1
- package/src/drizzle/d1-password-prepared.ts +40 -42
- package/src/drizzle/d1-passwords.ts +76 -80
- package/src/drizzle/d1-phone.ts +5 -1
- package/src/drizzle/d1-proofs.ts +31 -34
- package/src/drizzle/d1-sessions.ts +53 -40
- package/src/drizzle/d1-totp.ts +5 -1
- package/src/drizzle/email-registration.ts +6 -2
- package/src/drizzle/email-target.ts +18 -20
- package/src/drizzle/model.ts +1 -208
- package/src/drizzle/mysql-database.ts +8 -0
- package/src/drizzle/mysql-emails.ts +29 -17
- package/src/drizzle/mysql-identity.ts +18 -21
- package/src/drizzle/mysql-password-prepared.ts +11 -9
- package/src/drizzle/mysql-passwords.ts +22 -10
- package/src/drizzle/mysql-proofs.ts +17 -6
- package/src/drizzle/mysql-sessions.ts +41 -18
- package/src/drizzle/native-database.ts +22 -0
- package/src/drizzle/oauth-connected-access.ts +8 -1
- package/src/drizzle/oauth-connected-drivers.ts +21 -6
- package/src/drizzle/oauth-connected-input.ts +13 -0
- package/src/drizzle/oauth-connected-model.ts +17 -0
- package/src/drizzle/oauth-connected-settlement.ts +65 -42
- package/src/drizzle/oauth-connected-sign-in.ts +438 -0
- package/src/drizzle/oauth-connected-state.ts +19 -7
- package/src/drizzle/oauth-connected-target.ts +26 -18
- package/src/drizzle/oauth-drivers.ts +26 -10
- package/src/drizzle/oauth-state.ts +5 -4
- package/src/drizzle/oauth-target.ts +31 -43
- package/src/drizzle/passkey-drivers.ts +21 -13
- package/src/drizzle/passkey-write-drivers.ts +11 -6
- package/src/drizzle/password-prepared-sql.ts +2 -4
- package/src/drizzle/password-prepared-target.ts +10 -7
- package/src/drizzle/password-registration.ts +7 -8
- package/src/drizzle/password-target.ts +20 -19
- package/src/drizzle/pg-database.ts +10 -0
- package/src/drizzle/pg-emails.ts +29 -17
- package/src/drizzle/pg-identity.ts +297 -0
- package/src/drizzle/pg-password-prepared.ts +11 -9
- package/src/drizzle/pg-passwords.ts +22 -10
- package/src/drizzle/pg-proofs.ts +17 -6
- package/src/drizzle/pg-sessions.ts +41 -18
- package/src/drizzle/phone-target.ts +23 -18
- package/src/drizzle/proof-target.ts +10 -13
- package/src/drizzle/session-target.ts +33 -51
- package/src/drizzle/sqlite-emails.ts +31 -14
- package/src/drizzle/sqlite-identity.ts +22 -42
- package/src/drizzle/sqlite-password-prepared.ts +24 -10
- package/src/drizzle/sqlite-passwords.ts +30 -16
- package/src/drizzle/sqlite-proofs.ts +29 -6
- package/src/drizzle/sqlite-sessions.ts +50 -24
- package/src/drizzle/standalone-guard.ts +19 -7
- package/src/drizzle/totp-target.ts +62 -61
- package/src/drizzle/transaction-mysql.ts +1 -1
- package/src/index.ts +0 -24
- package/src/internal/drizzle-postgres.ts +1 -1
- package/src/internal/drizzle-sqlite.ts +1 -1
- package/dist/drizzle/d1-identity.d.mts +0 -30
- package/dist/drizzle/mysql-identity.d.mts +0 -21
- package/dist/drizzle/mysql.d.mts +0 -69
- package/dist/drizzle/mysql.mjs +0 -218
- package/dist/drizzle/mysql.mjs.map +0 -1
- package/dist/drizzle/pg.d.mts +0 -80
- package/dist/drizzle/pg.mjs +0 -289
- package/dist/drizzle/pg.mjs.map +0 -1
- package/dist/drizzle/sqlite.d.mts +0 -77
- package/dist/drizzle/sqlite.mjs +0 -217
- package/dist/drizzle/sqlite.mjs.map +0 -1
- package/src/drizzle/mysql.ts +0 -687
- package/src/drizzle/pg.ts +0 -984
- package/src/drizzle/sqlite.ts +0 -705
|
@@ -9,7 +9,7 @@ import type { EffectSQLiteNodeDatabase as NodeDatabase } from "drizzle-orm/effec
|
|
|
9
9
|
import type { EffectSQLiteWasmDatabase as WasmDatabase } from "drizzle-orm/effect-sqlite-wasm";
|
|
10
10
|
import type { AnySQLiteTable } from "drizzle-orm/sqlite-core";
|
|
11
11
|
import { Effect, Context } from "effect";
|
|
12
|
-
import type { SqlError } from "effect/
|
|
12
|
+
import type { SqlError } from "effect/sql/SqlError";
|
|
13
13
|
|
|
14
14
|
import type {
|
|
15
15
|
EmailAddressMapping,
|
|
@@ -17,6 +17,7 @@ import type {
|
|
|
17
17
|
EmailSignInMapping,
|
|
18
18
|
} from "./email-model";
|
|
19
19
|
import type { EmailRegistrationAuthority } from "./email-registration";
|
|
20
|
+
import { CurrentEmailSql } from "./email-sql";
|
|
20
21
|
import type { EmailSqlQuery } from "./email-sql";
|
|
21
22
|
import {
|
|
22
23
|
coordinateTargetEmailAddress,
|
|
@@ -26,8 +27,14 @@ import {
|
|
|
26
27
|
makeTargetEmailSignInServices,
|
|
27
28
|
type EmailTargetConfiguration,
|
|
28
29
|
} from "./email-target";
|
|
30
|
+
import { nativeDatabase } from "./native-database";
|
|
29
31
|
import type { ProofPersistenceMapping } from "./proof-model";
|
|
30
32
|
import type { ProofSqlQuery } from "./proof-sql";
|
|
33
|
+
import {
|
|
34
|
+
type TransactionService,
|
|
35
|
+
acquireTransactionService,
|
|
36
|
+
transactionService,
|
|
37
|
+
} from "./standalone-guard";
|
|
31
38
|
import type { SuppliedService } from "./SuppliedService";
|
|
32
39
|
|
|
33
40
|
export type SqliteEmailDatabase =
|
|
@@ -73,13 +80,24 @@ export const sqliteEmailConfiguration = (
|
|
|
73
80
|
});
|
|
74
81
|
|
|
75
82
|
export const makeSqliteEmailTarget = <
|
|
83
|
+
DatabaseId,
|
|
76
84
|
D extends SqliteEmailDatabase,
|
|
77
85
|
Synchronous extends boolean = false,
|
|
78
86
|
>(
|
|
79
|
-
|
|
87
|
+
databaseService: Context.Service<DatabaseId, D>,
|
|
88
|
+
configuration:
|
|
89
|
+
| EmailTargetConfiguration
|
|
90
|
+
| ((service: TransactionService | undefined) => EmailTargetConfiguration),
|
|
80
91
|
) => {
|
|
81
92
|
const configurationFor = (database: D) =>
|
|
82
|
-
typeof configuration === "function"
|
|
93
|
+
typeof configuration === "function"
|
|
94
|
+
? configuration(transactionService(database))
|
|
95
|
+
: configuration;
|
|
96
|
+
|
|
97
|
+
const standaloneConfiguration =
|
|
98
|
+
typeof configuration === "function"
|
|
99
|
+
? Effect.map(acquireTransactionService(databaseService), configuration)
|
|
100
|
+
: Effect.succeed(configuration);
|
|
83
101
|
|
|
84
102
|
function coordinateEmailAddress<
|
|
85
103
|
Database extends D,
|
|
@@ -325,9 +343,11 @@ export const makeSqliteEmailTarget = <
|
|
|
325
343
|
C extends AnySQLiteTable,
|
|
326
344
|
NativeId,
|
|
327
345
|
>(
|
|
328
|
-
database: D,
|
|
329
346
|
mapping: EmailSignInMapping<S, I, C, NativeId>,
|
|
330
|
-
) =>
|
|
347
|
+
) =>
|
|
348
|
+
Effect.flatMap(standaloneConfiguration, (configuration) =>
|
|
349
|
+
makeTargetEmailSignInServices(mapping, configuration),
|
|
350
|
+
).pipe(Effect.provideServiceEffect(CurrentEmailSql, nativeDatabase(databaseService))),
|
|
331
351
|
makeEmailAddressServices: <
|
|
332
352
|
S extends AnySQLiteTable,
|
|
333
353
|
I extends AnySQLiteTable,
|
|
@@ -336,11 +356,12 @@ export const makeSqliteEmailTarget = <
|
|
|
336
356
|
M extends AnySQLiteTable,
|
|
337
357
|
NativeId,
|
|
338
358
|
>(
|
|
339
|
-
database: D,
|
|
340
359
|
mapping: EmailAddressMapping<S, I, C, AC, M, NativeId>,
|
|
341
360
|
proofMapping: ProofMapping,
|
|
342
361
|
) =>
|
|
343
|
-
|
|
362
|
+
Effect.flatMap(standaloneConfiguration, (configuration) =>
|
|
363
|
+
makeTargetEmailAddressServices(mapping, proofMapping, configuration),
|
|
364
|
+
).pipe(Effect.provideServiceEffect(CurrentEmailSql, nativeDatabase(databaseService))),
|
|
344
365
|
coordinateEmailAddress,
|
|
345
366
|
makeEmailRegistrationServices: <
|
|
346
367
|
Registration,
|
|
@@ -351,16 +372,12 @@ export const makeSqliteEmailTarget = <
|
|
|
351
372
|
Rq extends AnySQLiteTable,
|
|
352
373
|
NativeId,
|
|
353
374
|
>(
|
|
354
|
-
database: D,
|
|
355
375
|
mapping: EmailRegistrationMapping<Registration, S, I, C, AC, Rq, NativeId>,
|
|
356
376
|
proofMapping: ProofMapping,
|
|
357
377
|
) =>
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
proofMapping,
|
|
362
|
-
configurationFor(database),
|
|
363
|
-
),
|
|
378
|
+
Effect.flatMap(standaloneConfiguration, (configuration) =>
|
|
379
|
+
makeTargetEmailRegistrationServices<Registration>(mapping, proofMapping, configuration),
|
|
380
|
+
).pipe(Effect.provideServiceEffect(CurrentEmailSql, nativeDatabase(databaseService))),
|
|
364
381
|
coordinateEmailRegistration,
|
|
365
382
|
};
|
|
366
383
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { NativeDatabase } from "@yielded/auth-persistence/Adapter";
|
|
1
2
|
import {
|
|
2
3
|
ExternalIdentityMutation,
|
|
3
4
|
type ExternalIdentity,
|
|
@@ -10,7 +11,7 @@ import {
|
|
|
10
11
|
import { reportPersistenceFailure } from "@yielded/auth/Persistence";
|
|
11
12
|
import type { SubjectId } from "@yielded/auth/Schema";
|
|
12
13
|
/* oxlint-disable no-explicit-any -- Drizzle generic query types are narrowed at this technology boundary. */
|
|
13
|
-
import { and, eq
|
|
14
|
+
import { and, eq } from "drizzle-orm";
|
|
14
15
|
import type { QueryEffectHKTBase } from "drizzle-orm/effect-core";
|
|
15
16
|
import type { AnySQLiteTable, SQLiteColumn } from "drizzle-orm/sqlite-core";
|
|
16
17
|
import type { SQLiteEffectDatabase } from "drizzle-orm/sqlite-core/effect/db";
|
|
@@ -27,16 +28,7 @@ import {
|
|
|
27
28
|
} from "./model";
|
|
28
29
|
|
|
29
30
|
type ClosedQueryEffectHKT = QueryEffectHKTBase & { readonly context: never };
|
|
30
|
-
type
|
|
31
|
-
HKT,
|
|
32
|
-
RunResult,
|
|
33
|
-
AnyRelations
|
|
34
|
-
>;
|
|
35
|
-
type RuntimeDatabase<HKT extends ClosedQueryEffectHKT, RunResult> = SQLiteEffectDatabase<
|
|
36
|
-
HKT,
|
|
37
|
-
RunResult,
|
|
38
|
-
any
|
|
39
|
-
>;
|
|
31
|
+
type RuntimeDatabase = SQLiteEffectDatabase<ClosedQueryEffectHKT, unknown, any>;
|
|
40
32
|
const unavailable = () => IdentityUnavailable.make();
|
|
41
33
|
const isIdentityFailure = Schema.is(Schema.Union([IdentityConflict, IdentityUnavailable]));
|
|
42
34
|
|
|
@@ -49,19 +41,18 @@ const mapUnavailable = <A, E, R>(effect: Effect.Effect<A, E, R>) =>
|
|
|
49
41
|
),
|
|
50
42
|
);
|
|
51
43
|
|
|
52
|
-
export const makeSqliteSubjectProvisioningServices = <
|
|
44
|
+
export const makeSqliteSubjectProvisioningServices = Effect.fnUntraced(function* <
|
|
53
45
|
Subject extends AnySQLiteTable,
|
|
54
46
|
Identifier extends AnySQLiteTable,
|
|
55
47
|
Request extends AnySQLiteTable,
|
|
56
48
|
NativeId,
|
|
57
|
-
HKT extends ClosedQueryEffectHKT = ClosedQueryEffectHKT,
|
|
58
|
-
RunResult = unknown,
|
|
59
49
|
>(
|
|
60
|
-
database: Database<HKT, RunResult>,
|
|
61
50
|
mapping: SubjectProvisioningTables<Subject, Identifier, Request, NativeId>,
|
|
62
51
|
mode: "interactive" | "synchronous",
|
|
63
|
-
)
|
|
64
|
-
const
|
|
52
|
+
) {
|
|
53
|
+
const database = yield* NativeDatabase;
|
|
54
|
+
|
|
55
|
+
const db = database as unknown as RuntimeDatabase;
|
|
65
56
|
const requestTable = mapping.provisioningRequest.table;
|
|
66
57
|
|
|
67
58
|
const requestIdColumn = column(
|
|
@@ -158,14 +149,7 @@ export const makeSqliteSubjectProvisioningServices = <
|
|
|
158
149
|
|
|
159
150
|
const nativeId = yield* attempt.pipe(
|
|
160
151
|
Effect.catchCause(
|
|
161
|
-
(
|
|
162
|
-
cause,
|
|
163
|
-
): Effect.Effect<
|
|
164
|
-
NativeId,
|
|
165
|
-
| Effect.Error<typeof attempt>
|
|
166
|
-
| Effect.Error<ReturnType<typeof findReceipt>>
|
|
167
|
-
| IdentityConflict
|
|
168
|
-
> => {
|
|
152
|
+
(cause): Effect.Effect<NativeId, Effect.Error<typeof attempt> | IdentityConflict> => {
|
|
169
153
|
if (
|
|
170
154
|
cause.reasons.length === 0 ||
|
|
171
155
|
!cause.reasons.every(
|
|
@@ -207,19 +191,16 @@ export const makeSqliteSubjectProvisioningServices = <
|
|
|
207
191
|
}, mapUnavailable);
|
|
208
192
|
|
|
209
193
|
return { subjectProvisioner: SubjectProvisioner.of({ provision }) } as const;
|
|
210
|
-
};
|
|
194
|
+
});
|
|
211
195
|
|
|
212
|
-
export const makeSqliteExternalIdentityServices = <
|
|
196
|
+
export const makeSqliteExternalIdentityServices = Effect.fnUntraced(function* <
|
|
213
197
|
Subject extends AnySQLiteTable,
|
|
214
198
|
External extends AnySQLiteTable,
|
|
215
199
|
NativeId,
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
database
|
|
220
|
-
mapping: ExternalIdentityTables<Subject, External, NativeId>,
|
|
221
|
-
) => {
|
|
222
|
-
const db = database as RuntimeDatabase<HKT, RunResult>;
|
|
200
|
+
>(mapping: ExternalIdentityTables<Subject, External, NativeId>) {
|
|
201
|
+
const database = yield* NativeDatabase;
|
|
202
|
+
|
|
203
|
+
const db = database as unknown as RuntimeDatabase;
|
|
223
204
|
const externalTable = mapping.externalIdentity.table;
|
|
224
205
|
|
|
225
206
|
const externalProviderColumn = column(
|
|
@@ -324,21 +305,20 @@ export const makeSqliteExternalIdentityServices = <
|
|
|
324
305
|
}, mapUnavailable);
|
|
325
306
|
|
|
326
307
|
return { externalIdentityMutation: ExternalIdentityMutation.of({ bind }) } as const;
|
|
327
|
-
};
|
|
308
|
+
});
|
|
328
309
|
|
|
329
|
-
export const makeSqliteIdentityServices = <
|
|
310
|
+
export const makeSqliteIdentityServices = Effect.fnUntraced(function* <
|
|
330
311
|
Subject extends AnySQLiteTable,
|
|
331
312
|
Identifier extends AnySQLiteTable,
|
|
332
313
|
External extends AnySQLiteTable,
|
|
333
314
|
Request extends AnySQLiteTable,
|
|
334
315
|
NativeId,
|
|
335
|
-
HKT extends ClosedQueryEffectHKT = ClosedQueryEffectHKT,
|
|
336
|
-
RunResult = unknown,
|
|
337
316
|
>(
|
|
338
|
-
database: Database<HKT, RunResult>,
|
|
339
317
|
mapping: IdentityTables<Subject, Identifier, External, Request, NativeId>,
|
|
340
318
|
mode: "interactive" | "synchronous",
|
|
341
|
-
)
|
|
342
|
-
|
|
343
|
-
|
|
319
|
+
) {
|
|
320
|
+
return {
|
|
321
|
+
...(yield* makeSqliteSubjectProvisioningServices(mapping, mode)),
|
|
322
|
+
...(yield* makeSqliteExternalIdentityServices(mapping)),
|
|
323
|
+
};
|
|
344
324
|
});
|
|
@@ -2,8 +2,9 @@ import type { LifecycleHooks, HookConfigurationError } from "@yielded/auth/Hooks
|
|
|
2
2
|
import type { PasswordUnavailable, PasswordPreparedPersistence } from "@yielded/auth/Password";
|
|
3
3
|
import type { AnySQLiteTable } from "drizzle-orm/sqlite-core";
|
|
4
4
|
import { Effect, Context } from "effect";
|
|
5
|
-
import type { SqlError } from "effect/
|
|
5
|
+
import type { SqlError } from "effect/sql/SqlError";
|
|
6
6
|
|
|
7
|
+
import { nativeDatabase } from "./native-database";
|
|
7
8
|
import type {
|
|
8
9
|
PasswordPreparedPersistenceMapping,
|
|
9
10
|
PasswordPreparedProofMapping,
|
|
@@ -12,21 +13,38 @@ import {
|
|
|
12
13
|
makeTargetPasswordPreparedPersistenceServices,
|
|
13
14
|
coordinateTargetPasswordPreparedPersistence,
|
|
14
15
|
} from "./password-prepared-target";
|
|
16
|
+
import { CurrentPasswordSql } from "./password-sql";
|
|
15
17
|
import type { PasswordTargetConfiguration } from "./password-target";
|
|
16
18
|
import type { SqlitePasswordDatabase } from "./sqlite-passwords";
|
|
19
|
+
import {
|
|
20
|
+
type TransactionService,
|
|
21
|
+
acquireTransactionService,
|
|
22
|
+
transactionService,
|
|
23
|
+
} from "./standalone-guard";
|
|
17
24
|
import type { SuppliedService } from "./SuppliedService";
|
|
18
25
|
type TransactionOf<D extends SqlitePasswordDatabase> = Parameters<
|
|
19
26
|
Parameters<D["transaction"]>[0]
|
|
20
27
|
>[0];
|
|
21
28
|
|
|
22
29
|
export const makeSqlitePasswordPreparedTarget = <
|
|
30
|
+
DatabaseId,
|
|
23
31
|
D extends SqlitePasswordDatabase,
|
|
24
32
|
Synchronous extends boolean = false,
|
|
25
33
|
>(
|
|
26
|
-
|
|
34
|
+
databaseService: Context.Service<DatabaseId, D>,
|
|
35
|
+
configuration:
|
|
36
|
+
| PasswordTargetConfiguration
|
|
37
|
+
| ((service: TransactionService | undefined) => PasswordTargetConfiguration),
|
|
27
38
|
) => {
|
|
28
39
|
const configurationFor = (database: D) =>
|
|
29
|
-
typeof configuration === "function"
|
|
40
|
+
typeof configuration === "function"
|
|
41
|
+
? configuration(transactionService(database))
|
|
42
|
+
: configuration;
|
|
43
|
+
|
|
44
|
+
const standaloneConfiguration =
|
|
45
|
+
typeof configuration === "function"
|
|
46
|
+
? Effect.map(acquireTransactionService(databaseService), configuration)
|
|
47
|
+
: Effect.succeed(configuration);
|
|
30
48
|
|
|
31
49
|
function coordinatePasswordPreparedPersistence<
|
|
32
50
|
Database extends D,
|
|
@@ -245,16 +263,12 @@ export const makeSqlitePasswordPreparedTarget = <
|
|
|
245
263
|
PCr extends AnySQLiteTable = AnySQLiteTable,
|
|
246
264
|
PNativeId = unknown,
|
|
247
265
|
>(
|
|
248
|
-
database: D,
|
|
249
266
|
mapping: PasswordPreparedPersistenceMapping<S, I, C, AC, A, RS, CE, M, T, B, NativeId>,
|
|
250
267
|
proofMapping?: PasswordPreparedProofMapping<PS, PC, PM, PSub, PI, PCr, PNativeId>,
|
|
251
268
|
) =>
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
configurationFor(database),
|
|
256
|
-
proofMapping,
|
|
257
|
-
),
|
|
269
|
+
Effect.flatMap(standaloneConfiguration, (configuration) =>
|
|
270
|
+
makeTargetPasswordPreparedPersistenceServices(mapping, configuration, proofMapping),
|
|
271
|
+
).pipe(Effect.provideServiceEffect(CurrentPasswordSql, nativeDatabase(databaseService))),
|
|
258
272
|
coordinatePasswordPreparedPersistence,
|
|
259
273
|
};
|
|
260
274
|
};
|
|
@@ -9,10 +9,12 @@ import type { EffectSQLiteNodeDatabase as NodeDatabase } from "drizzle-orm/effec
|
|
|
9
9
|
import type { EffectSQLiteWasmDatabase as WasmDatabase } from "drizzle-orm/effect-sqlite-wasm";
|
|
10
10
|
import type { AnySQLiteTable } from "drizzle-orm/sqlite-core";
|
|
11
11
|
import { Effect, Context } from "effect";
|
|
12
|
-
import type { SqlError } from "effect/
|
|
12
|
+
import type { SqlError } from "effect/sql/SqlError";
|
|
13
13
|
|
|
14
|
+
import { nativeDatabase } from "./native-database";
|
|
14
15
|
import type { PasswordPersistenceMapping, PasswordRegistrationMapping } from "./password-model";
|
|
15
16
|
import type { PasswordRegistrationAuthority } from "./password-registration";
|
|
17
|
+
import { CurrentPasswordSql } from "./password-sql";
|
|
16
18
|
import type { PasswordSqlQuery } from "./password-sql";
|
|
17
19
|
import {
|
|
18
20
|
coordinateTargetPasswordPersistence,
|
|
@@ -23,6 +25,11 @@ import {
|
|
|
23
25
|
} from "./password-target";
|
|
24
26
|
import type { ProofPersistenceMapping } from "./proof-model";
|
|
25
27
|
import type { ProofSqlQuery } from "./proof-sql";
|
|
28
|
+
import {
|
|
29
|
+
type TransactionService,
|
|
30
|
+
acquireTransactionService,
|
|
31
|
+
transactionService,
|
|
32
|
+
} from "./standalone-guard";
|
|
26
33
|
import type { SuppliedService } from "./SuppliedService";
|
|
27
34
|
|
|
28
35
|
export type SqlitePasswordDatabase =
|
|
@@ -79,7 +86,6 @@ export const makeSqlitePasswordPersistenceServices = <
|
|
|
79
86
|
M extends AnySQLiteTable,
|
|
80
87
|
NativeId,
|
|
81
88
|
>(
|
|
82
|
-
database: SqlitePasswordDatabase,
|
|
83
89
|
mapping: Mapping<S, I, C, AC, A, RS, CE, M, NativeId>,
|
|
84
90
|
configuration: PasswordTargetConfiguration,
|
|
85
91
|
proofMapping?: ProofPersistenceMapping<
|
|
@@ -96,7 +102,7 @@ export const makeSqlitePasswordPersistenceServices = <
|
|
|
96
102
|
any,
|
|
97
103
|
any
|
|
98
104
|
>,
|
|
99
|
-
) => makeTargetPasswordPersistenceServices(
|
|
105
|
+
) => makeTargetPasswordPersistenceServices(mapping, configuration, proofMapping);
|
|
100
106
|
|
|
101
107
|
export const coordinateSqlitePasswordPersistence = <
|
|
102
108
|
D extends SqlitePasswordDatabase,
|
|
@@ -142,10 +148,9 @@ export const makeSqlitePasswordRegistrationServices = <
|
|
|
142
148
|
Rq extends AnySQLiteTable,
|
|
143
149
|
NativeId,
|
|
144
150
|
>(
|
|
145
|
-
database: SqlitePasswordDatabase,
|
|
146
151
|
mapping: PasswordRegistrationMapping<Registration, S, I, C, AC, Rq, NativeId>,
|
|
147
152
|
configuration: PasswordTargetConfiguration,
|
|
148
|
-
) => makeTargetPasswordRegistrationServices<Registration>(
|
|
153
|
+
) => makeTargetPasswordRegistrationServices<Registration>(mapping, configuration);
|
|
149
154
|
|
|
150
155
|
export const coordinateSqlitePasswordRegistration = <
|
|
151
156
|
Registration,
|
|
@@ -176,13 +181,24 @@ export const coordinateSqlitePasswordRegistration = <
|
|
|
176
181
|
);
|
|
177
182
|
|
|
178
183
|
export const makeSqlitePasswordTarget = <
|
|
184
|
+
DatabaseId,
|
|
179
185
|
D extends SqlitePasswordDatabase,
|
|
180
186
|
Synchronous extends boolean = false,
|
|
181
187
|
>(
|
|
182
|
-
|
|
188
|
+
databaseService: Context.Service<DatabaseId, D>,
|
|
189
|
+
configuration:
|
|
190
|
+
| PasswordTargetConfiguration
|
|
191
|
+
| ((service: TransactionService | undefined) => PasswordTargetConfiguration),
|
|
183
192
|
) => {
|
|
184
193
|
const configurationFor = (database: D) =>
|
|
185
|
-
typeof configuration === "function"
|
|
194
|
+
typeof configuration === "function"
|
|
195
|
+
? configuration(transactionService(database))
|
|
196
|
+
: configuration;
|
|
197
|
+
|
|
198
|
+
const standaloneConfiguration =
|
|
199
|
+
typeof configuration === "function"
|
|
200
|
+
? Effect.map(acquireTransactionService(databaseService), configuration)
|
|
201
|
+
: Effect.succeed(configuration);
|
|
186
202
|
|
|
187
203
|
function coordinatePasswordPersistence<
|
|
188
204
|
Database extends D,
|
|
@@ -456,7 +472,6 @@ export const makeSqlitePasswordTarget = <
|
|
|
456
472
|
M extends AnySQLiteTable,
|
|
457
473
|
NativeId,
|
|
458
474
|
>(
|
|
459
|
-
database: D,
|
|
460
475
|
mapping: Mapping<S, I, C, AC, A, RS, CE, M, NativeId>,
|
|
461
476
|
proofMapping?: ProofPersistenceMapping<
|
|
462
477
|
any,
|
|
@@ -473,12 +488,9 @@ export const makeSqlitePasswordTarget = <
|
|
|
473
488
|
any
|
|
474
489
|
>,
|
|
475
490
|
) =>
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
configurationFor(database),
|
|
480
|
-
proofMapping,
|
|
481
|
-
),
|
|
491
|
+
Effect.flatMap(standaloneConfiguration, (configuration) =>
|
|
492
|
+
makeSqlitePasswordPersistenceServices(mapping, configuration, proofMapping),
|
|
493
|
+
).pipe(Effect.provideServiceEffect(CurrentPasswordSql, nativeDatabase(databaseService))),
|
|
482
494
|
coordinatePasswordPersistence,
|
|
483
495
|
makePasswordRegistrationServices: <
|
|
484
496
|
Registration,
|
|
@@ -489,9 +501,11 @@ export const makeSqlitePasswordTarget = <
|
|
|
489
501
|
Rq extends AnySQLiteTable,
|
|
490
502
|
NativeId,
|
|
491
503
|
>(
|
|
492
|
-
database: D,
|
|
493
504
|
mapping: PasswordRegistrationMapping<Registration, S, I, C, AC, Rq, NativeId>,
|
|
494
|
-
) =>
|
|
505
|
+
) =>
|
|
506
|
+
Effect.flatMap(standaloneConfiguration, (configuration) =>
|
|
507
|
+
makeSqlitePasswordRegistrationServices(mapping, configuration),
|
|
508
|
+
).pipe(Effect.provideServiceEffect(CurrentPasswordSql, nativeDatabase(databaseService))),
|
|
495
509
|
coordinatePasswordRegistration,
|
|
496
510
|
};
|
|
497
511
|
};
|
|
@@ -8,14 +8,21 @@ import type { EffectSQLiteNodeDatabase } from "drizzle-orm/effect-sqlite-node";
|
|
|
8
8
|
import type { EffectSQLiteWasmDatabase } from "drizzle-orm/effect-sqlite-wasm";
|
|
9
9
|
import type { AnySQLiteTable } from "drizzle-orm/sqlite-core";
|
|
10
10
|
import { Effect, Context } from "effect";
|
|
11
|
-
import type { SqlError } from "effect/
|
|
11
|
+
import type { SqlError } from "effect/sql/SqlError";
|
|
12
12
|
|
|
13
|
+
import { nativeDatabase } from "./native-database";
|
|
13
14
|
import type { ProofPersistenceMapping } from "./proof-model";
|
|
15
|
+
import { CurrentProofSql } from "./proof-sql";
|
|
14
16
|
import {
|
|
15
17
|
coordinateTargetProofPersistence,
|
|
16
18
|
makeTargetProofPersistenceServices,
|
|
17
19
|
type ProofTargetConfiguration,
|
|
18
20
|
} from "./proof-target";
|
|
21
|
+
import {
|
|
22
|
+
type TransactionService,
|
|
23
|
+
acquireTransactionService,
|
|
24
|
+
transactionService,
|
|
25
|
+
} from "./standalone-guard";
|
|
19
26
|
import type { SuppliedService } from "./SuppliedService";
|
|
20
27
|
|
|
21
28
|
type Database =
|
|
@@ -52,11 +59,25 @@ export const sqliteProofConfiguration = (
|
|
|
52
59
|
...(coordinatorGuard === undefined ? {} : { coordinatorGuard }),
|
|
53
60
|
});
|
|
54
61
|
|
|
55
|
-
export const makeSqliteProofTarget = <
|
|
56
|
-
|
|
62
|
+
export const makeSqliteProofTarget = <
|
|
63
|
+
DatabaseId,
|
|
64
|
+
D extends Database,
|
|
65
|
+
Synchronous extends boolean = false,
|
|
66
|
+
>(
|
|
67
|
+
databaseService: Context.Service<DatabaseId, D>,
|
|
68
|
+
configuration:
|
|
69
|
+
| ProofTargetConfiguration
|
|
70
|
+
| ((service: TransactionService | undefined) => ProofTargetConfiguration),
|
|
57
71
|
) => {
|
|
58
72
|
const configurationFor = (database: D) =>
|
|
59
|
-
typeof configuration === "function"
|
|
73
|
+
typeof configuration === "function"
|
|
74
|
+
? configuration(transactionService(database))
|
|
75
|
+
: configuration;
|
|
76
|
+
|
|
77
|
+
const standaloneConfiguration =
|
|
78
|
+
typeof configuration === "function"
|
|
79
|
+
? Effect.map(acquireTransactionService(databaseService), configuration)
|
|
80
|
+
: Effect.succeed(configuration);
|
|
60
81
|
|
|
61
82
|
function coordinateProofPersistence<
|
|
62
83
|
Database extends D,
|
|
@@ -194,9 +215,11 @@ export const makeSqliteProofTarget = <D extends Database, Synchronous extends bo
|
|
|
194
215
|
Cr extends AnySQLiteTable,
|
|
195
216
|
NativeId,
|
|
196
217
|
>(
|
|
197
|
-
database: D,
|
|
198
218
|
mapping: Mapping<Rq, S, G, Cn, Rs, A, F, C, Sub, I, Cr, NativeId>,
|
|
199
|
-
) =>
|
|
219
|
+
) =>
|
|
220
|
+
Effect.flatMap(standaloneConfiguration, (configuration) =>
|
|
221
|
+
makeTargetProofPersistenceServices(mapping, configuration),
|
|
222
|
+
).pipe(Effect.provideServiceEffect(CurrentProofSql, nativeDatabase(databaseService))),
|
|
200
223
|
coordinateProofPersistence,
|
|
201
224
|
};
|
|
202
225
|
};
|
|
@@ -16,14 +16,16 @@ import type { EffectSQLiteNodeDatabase } from "drizzle-orm/effect-sqlite-node";
|
|
|
16
16
|
import type { EffectSQLiteWasmDatabase } from "drizzle-orm/effect-sqlite-wasm";
|
|
17
17
|
import type { AnySQLiteTable } from "drizzle-orm/sqlite-core";
|
|
18
18
|
import { Context, Effect } from "effect";
|
|
19
|
-
import type { SqlError } from "effect/
|
|
19
|
+
import type { SqlError } from "effect/sql/SqlError";
|
|
20
20
|
|
|
21
|
+
import { nativeDatabase } from "./native-database";
|
|
21
22
|
import type {
|
|
22
23
|
AuthenticationAuthorityMapping,
|
|
23
24
|
PendingAuthenticationMapping,
|
|
24
25
|
SignedSessionValidityMapping,
|
|
25
26
|
StatefulSessionMapping,
|
|
26
27
|
} from "./session-model";
|
|
28
|
+
import { CurrentSessionSql } from "./session-sql";
|
|
27
29
|
import {
|
|
28
30
|
coordinateTargetAuthenticationAuthority,
|
|
29
31
|
coordinateTargetPendingAuthentication,
|
|
@@ -37,6 +39,11 @@ import {
|
|
|
37
39
|
makeTargetSessionStepUpServices,
|
|
38
40
|
coordinateTargetSessionStepUp,
|
|
39
41
|
} from "./session-target";
|
|
42
|
+
import {
|
|
43
|
+
type TransactionService,
|
|
44
|
+
acquireTransactionService,
|
|
45
|
+
transactionService,
|
|
46
|
+
} from "./standalone-guard";
|
|
40
47
|
import type { SuppliedService } from "./SuppliedService";
|
|
41
48
|
|
|
42
49
|
type Database =
|
|
@@ -66,10 +73,9 @@ export const makeSqliteAuthenticationAuthorityServices = <
|
|
|
66
73
|
P extends AnySQLiteTable,
|
|
67
74
|
NativeId,
|
|
68
75
|
>(
|
|
69
|
-
database: Database,
|
|
70
76
|
mapping: AuthenticationAuthorityMapping<Claims, S, C, F, P, NativeId>,
|
|
71
77
|
configuration: SessionTargetConfiguration,
|
|
72
|
-
) => makeTargetAuthenticationAuthorityServices<Claims>(
|
|
78
|
+
) => makeTargetAuthenticationAuthorityServices<Claims>(mapping, configuration);
|
|
73
79
|
|
|
74
80
|
export const makeSqlitePendingAuthenticationServices = <
|
|
75
81
|
Claims,
|
|
@@ -79,10 +85,9 @@ export const makeSqlitePendingAuthenticationServices = <
|
|
|
79
85
|
F extends AnySQLiteTable,
|
|
80
86
|
NativeId,
|
|
81
87
|
>(
|
|
82
|
-
database: Database,
|
|
83
88
|
mapping: PendingAuthenticationMapping<Claims, S, C, P, F, NativeId>,
|
|
84
89
|
configuration: SessionTargetConfiguration,
|
|
85
|
-
) => makeTargetPendingAuthenticationServices<Claims>(
|
|
90
|
+
) => makeTargetPendingAuthenticationServices<Claims>(mapping, configuration);
|
|
86
91
|
|
|
87
92
|
export const makeSqliteStatefulSessionServices = <
|
|
88
93
|
Claims,
|
|
@@ -94,10 +99,9 @@ export const makeSqliteStatefulSessionServices = <
|
|
|
94
99
|
NativeId,
|
|
95
100
|
NativeSessionId,
|
|
96
101
|
>(
|
|
97
|
-
database: Database,
|
|
98
102
|
mapping: StatefulSessionMapping<Claims, S, C, Session, F, P, NativeId, NativeSessionId>,
|
|
99
103
|
configuration: SessionTargetConfiguration,
|
|
100
|
-
) => makeTargetStatefulSessionServices<Claims>(
|
|
104
|
+
) => makeTargetStatefulSessionServices<Claims>(mapping, configuration);
|
|
101
105
|
|
|
102
106
|
export const makeSqliteSignedSessionValidityServices = <
|
|
103
107
|
S extends AnySQLiteTable,
|
|
@@ -105,10 +109,9 @@ export const makeSqliteSignedSessionValidityServices = <
|
|
|
105
109
|
NativeId,
|
|
106
110
|
NativeSessionId,
|
|
107
111
|
>(
|
|
108
|
-
database: Database,
|
|
109
112
|
mapping: SignedSessionValidityMapping<S, T, NativeId, NativeSessionId>,
|
|
110
113
|
configuration: SessionTargetConfiguration,
|
|
111
|
-
) => makeTargetSignedSessionValidityServices(
|
|
114
|
+
) => makeTargetSignedSessionValidityServices(mapping, configuration);
|
|
112
115
|
|
|
113
116
|
export const coordinateSqliteAuthenticationAuthority = <
|
|
114
117
|
Claims,
|
|
@@ -221,11 +224,25 @@ export const coordinateSqliteSignedSessionValidity = <
|
|
|
221
224
|
owner,
|
|
222
225
|
);
|
|
223
226
|
|
|
224
|
-
export const makeSqliteSessionTarget = <
|
|
225
|
-
|
|
227
|
+
export const makeSqliteSessionTarget = <
|
|
228
|
+
DatabaseId,
|
|
229
|
+
D extends Database,
|
|
230
|
+
Synchronous extends boolean = false,
|
|
231
|
+
>(
|
|
232
|
+
databaseService: Context.Service<DatabaseId, D>,
|
|
233
|
+
configuration:
|
|
234
|
+
| SessionTargetConfiguration
|
|
235
|
+
| ((service: TransactionService | undefined) => SessionTargetConfiguration),
|
|
226
236
|
) => {
|
|
227
237
|
const configurationFor = (database: D) =>
|
|
228
|
-
typeof configuration === "function"
|
|
238
|
+
typeof configuration === "function"
|
|
239
|
+
? configuration(transactionService(database))
|
|
240
|
+
: configuration;
|
|
241
|
+
|
|
242
|
+
const standaloneConfiguration =
|
|
243
|
+
typeof configuration === "function"
|
|
244
|
+
? Effect.map(acquireTransactionService(databaseService), configuration)
|
|
245
|
+
: Effect.succeed(configuration);
|
|
229
246
|
|
|
230
247
|
function coordinateSessionStepUp<
|
|
231
248
|
Database extends D,
|
|
@@ -854,7 +871,6 @@ export const makeSqliteSessionTarget = <D extends Database, Synchronous extends
|
|
|
854
871
|
NativeId,
|
|
855
872
|
NativeSessionId,
|
|
856
873
|
>(
|
|
857
|
-
database: D,
|
|
858
874
|
mapping: SessionStepUpMapping<
|
|
859
875
|
NoInfer<Claims>,
|
|
860
876
|
S,
|
|
@@ -866,7 +882,10 @@ export const makeSqliteSessionTarget = <D extends Database, Synchronous extends
|
|
|
866
882
|
NativeSessionId
|
|
867
883
|
>,
|
|
868
884
|
target: Context.Service<Id, SessionStepUpPersistence<Claims>>,
|
|
869
|
-
) =>
|
|
885
|
+
) =>
|
|
886
|
+
Effect.flatMap(standaloneConfiguration, (configuration) =>
|
|
887
|
+
makeSqliteSessionStepUpServices(mapping, target, configuration),
|
|
888
|
+
).pipe(Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(databaseService))),
|
|
870
889
|
coordinateSessionStepUp,
|
|
871
890
|
makeAuthenticationAuthorityServices: <
|
|
872
891
|
Claims,
|
|
@@ -876,9 +895,11 @@ export const makeSqliteSessionTarget = <D extends Database, Synchronous extends
|
|
|
876
895
|
P extends AnySQLiteTable,
|
|
877
896
|
NativeId,
|
|
878
897
|
>(
|
|
879
|
-
database: D,
|
|
880
898
|
mapping: AuthenticationAuthorityMapping<Claims, S, C, F, P, NativeId>,
|
|
881
|
-
) =>
|
|
899
|
+
) =>
|
|
900
|
+
Effect.flatMap(standaloneConfiguration, (configuration) =>
|
|
901
|
+
makeSqliteAuthenticationAuthorityServices(mapping, configuration),
|
|
902
|
+
).pipe(Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(databaseService))),
|
|
882
903
|
makePendingAuthenticationServices: <
|
|
883
904
|
Claims,
|
|
884
905
|
S extends AnySQLiteTable,
|
|
@@ -887,9 +908,11 @@ export const makeSqliteSessionTarget = <D extends Database, Synchronous extends
|
|
|
887
908
|
F extends AnySQLiteTable,
|
|
888
909
|
NativeId,
|
|
889
910
|
>(
|
|
890
|
-
database: D,
|
|
891
911
|
mapping: PendingAuthenticationMapping<Claims, S, C, P, F, NativeId>,
|
|
892
|
-
) =>
|
|
912
|
+
) =>
|
|
913
|
+
Effect.flatMap(standaloneConfiguration, (configuration) =>
|
|
914
|
+
makeSqlitePendingAuthenticationServices(mapping, configuration),
|
|
915
|
+
).pipe(Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(databaseService))),
|
|
893
916
|
makeStatefulSessionServices: <
|
|
894
917
|
Claims,
|
|
895
918
|
S extends AnySQLiteTable,
|
|
@@ -900,18 +923,22 @@ export const makeSqliteSessionTarget = <D extends Database, Synchronous extends
|
|
|
900
923
|
NativeId,
|
|
901
924
|
NativeSessionId,
|
|
902
925
|
>(
|
|
903
|
-
database: D,
|
|
904
926
|
mapping: StatefulSessionMapping<Claims, S, C, Session, F, P, NativeId, NativeSessionId>,
|
|
905
|
-
) =>
|
|
927
|
+
) =>
|
|
928
|
+
Effect.flatMap(standaloneConfiguration, (configuration) =>
|
|
929
|
+
makeSqliteStatefulSessionServices(mapping, configuration),
|
|
930
|
+
).pipe(Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(databaseService))),
|
|
906
931
|
makeSignedSessionValidityServices: <
|
|
907
932
|
S extends AnySQLiteTable,
|
|
908
933
|
T extends AnySQLiteTable,
|
|
909
934
|
NativeId,
|
|
910
935
|
NativeSessionId,
|
|
911
936
|
>(
|
|
912
|
-
database: D,
|
|
913
937
|
mapping: SignedSessionValidityMapping<S, T, NativeId, NativeSessionId>,
|
|
914
|
-
) =>
|
|
938
|
+
) =>
|
|
939
|
+
Effect.flatMap(standaloneConfiguration, (configuration) =>
|
|
940
|
+
makeSqliteSignedSessionValidityServices(mapping, configuration),
|
|
941
|
+
).pipe(Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(databaseService))),
|
|
915
942
|
coordinateAuthenticationAuthority,
|
|
916
943
|
coordinatePendingAuthentication,
|
|
917
944
|
coordinateStatefulSessions,
|
|
@@ -932,11 +959,10 @@ export const makeSqliteSessionStepUpServices = <
|
|
|
932
959
|
NativeId,
|
|
933
960
|
NativeSessionId,
|
|
934
961
|
>(
|
|
935
|
-
database: Database,
|
|
936
962
|
mapping: SessionStepUpMapping<NoInfer<Claims>, S, C, I, Session, T, NativeId, NativeSessionId>,
|
|
937
963
|
target: Context.Service<Id, SessionStepUpPersistence<Claims>>,
|
|
938
964
|
configuration: SessionTargetConfiguration,
|
|
939
|
-
) => makeTargetSessionStepUpServices(
|
|
965
|
+
) => makeTargetSessionStepUpServices(mapping, target, configuration);
|
|
940
966
|
|
|
941
967
|
export const coordinateSqliteSessionStepUp = <
|
|
942
968
|
Claims,
|