@yielded/auth-persistence-drizzle 0.1.0-beta.1 → 0.1.0-beta.13
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 +23 -18
- package/dist/D1.mjs +10 -4
- package/dist/D1.mjs.map +1 -1
- package/dist/Libsql.d.mts +58 -53
- package/dist/Libsql.mjs +20 -15
- package/dist/Libsql.mjs.map +1 -1
- package/dist/Mysql2.d.mts +58 -46
- package/dist/Mysql2.mjs +13 -6
- package/dist/Mysql2.mjs.map +1 -1
- package/dist/Pglite.d.mts +52 -41
- package/dist/Pglite.mjs +12 -7
- package/dist/Pglite.mjs.map +1 -1
- package/dist/Postgres.d.mts +59 -48
- package/dist/Postgres.mjs +12 -7
- package/dist/Postgres.mjs.map +1 -1
- package/dist/SqliteBun.d.mts +67 -62
- package/dist/SqliteBun.mjs +20 -14
- package/dist/SqliteBun.mjs.map +1 -1
- package/dist/SqliteDo.d.mts +58 -52
- package/dist/SqliteDo.mjs +26 -14
- package/dist/SqliteDo.mjs.map +1 -1
- package/dist/SqliteNode.d.mts +58 -53
- package/dist/SqliteNode.mjs +20 -14
- package/dist/SqliteNode.mjs.map +1 -1
- package/dist/SqliteWasm.d.mts +58 -53
- package/dist/SqliteWasm.mjs +20 -14
- package/dist/SqliteWasm.mjs.map +1 -1
- package/dist/drizzle/d1-database.d.mts +11 -0
- package/dist/drizzle/d1-database.mjs +8 -0
- package/dist/drizzle/d1-database.mjs.map +1 -0
- package/dist/drizzle/d1-emails.d.mts +8 -7
- package/dist/drizzle/d1-emails.mjs +7 -4
- package/dist/drizzle/d1-emails.mjs.map +1 -1
- package/dist/drizzle/d1-identity.mjs +12 -9
- package/dist/drizzle/d1-identity.mjs.map +1 -1
- package/dist/drizzle/d1-oauth.d.mts +10 -9
- package/dist/drizzle/d1-oauth.mjs +7 -4
- package/dist/drizzle/d1-oauth.mjs.map +1 -1
- package/dist/drizzle/d1-passkey.d.mts +3 -14
- package/dist/drizzle/d1-passkey.mjs +2 -1
- package/dist/drizzle/d1-passkey.mjs.map +1 -1
- package/dist/drizzle/d1-password-prepared.d.mts +4 -3
- package/dist/drizzle/d1-password-prepared.mjs +3 -1
- package/dist/drizzle/d1-password-prepared.mjs.map +1 -1
- package/dist/drizzle/d1-passwords.d.mts +6 -5
- package/dist/drizzle/d1-passwords.mjs +11 -7
- package/dist/drizzle/d1-passwords.mjs.map +1 -1
- package/dist/drizzle/d1-phone.d.mts +3 -4
- package/dist/drizzle/d1-phone.mjs +2 -1
- package/dist/drizzle/d1-phone.mjs.map +1 -1
- package/dist/drizzle/d1-planning.d.mts +1 -1
- package/dist/drizzle/d1-proofs.d.mts +4 -3
- package/dist/drizzle/d1-proofs.mjs +3 -1
- package/dist/drizzle/d1-proofs.mjs.map +1 -1
- package/dist/drizzle/d1-sessions.d.mts +11 -10
- package/dist/drizzle/d1-sessions.mjs +15 -9
- package/dist/drizzle/d1-sessions.mjs.map +1 -1
- package/dist/drizzle/d1-totp.d.mts +3 -4
- package/dist/drizzle/d1-totp.mjs +2 -1
- package/dist/drizzle/d1-totp.mjs.map +1 -1
- package/dist/drizzle/email-registration.mjs +2 -1
- package/dist/drizzle/email-registration.mjs.map +1 -1
- package/dist/drizzle/email-target.d.mts +7 -6
- package/dist/drizzle/email-target.mjs +10 -10
- package/dist/drizzle/email-target.mjs.map +1 -1
- package/dist/drizzle/mysql-database.d.mts +8 -0
- package/dist/drizzle/mysql-database.mjs +8 -0
- package/dist/drizzle/mysql-database.mjs.map +1 -0
- package/dist/drizzle/mysql-emails.d.mts +7 -6
- package/dist/drizzle/mysql-emails.mjs +12 -8
- package/dist/drizzle/mysql-emails.mjs.map +1 -1
- package/dist/drizzle/mysql-identity.mjs +12 -9
- package/dist/drizzle/mysql-identity.mjs.map +1 -1
- package/dist/drizzle/mysql-password-prepared.d.mts +3 -2
- package/dist/drizzle/mysql-password-prepared.mjs +6 -2
- package/dist/drizzle/mysql-password-prepared.mjs.map +1 -1
- package/dist/drizzle/mysql-passwords.d.mts +6 -4
- package/dist/drizzle/mysql-passwords.mjs +11 -7
- package/dist/drizzle/mysql-passwords.mjs.map +1 -1
- package/dist/drizzle/mysql-proofs.d.mts +3 -2
- package/dist/drizzle/mysql-proofs.mjs +8 -4
- package/dist/drizzle/mysql-proofs.mjs.map +1 -1
- package/dist/drizzle/mysql-sessions.d.mts +11 -10
- package/dist/drizzle/mysql-sessions.mjs +16 -12
- package/dist/drizzle/mysql-sessions.mjs.map +1 -1
- package/dist/drizzle/native-database.mjs +10 -0
- package/dist/drizzle/native-database.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-drivers.mjs +7 -5
- package/dist/drizzle/oauth-connected-drivers.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-settlement.mjs +3 -2
- package/dist/drizzle/oauth-connected-settlement.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-sign-in.mjs +4 -3
- package/dist/drizzle/oauth-connected-sign-in.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-target.d.mts +6 -7
- package/dist/drizzle/oauth-connected-target.mjs +4 -5
- package/dist/drizzle/oauth-connected-target.mjs.map +1 -1
- package/dist/drizzle/oauth-drivers.mjs +8 -6
- package/dist/drizzle/oauth-drivers.mjs.map +1 -1
- package/dist/drizzle/oauth-target.d.mts +12 -11
- package/dist/drizzle/oauth-target.mjs +13 -12
- package/dist/drizzle/oauth-target.mjs.map +1 -1
- package/dist/drizzle/passkey-drivers.mjs +8 -6
- package/dist/drizzle/passkey-drivers.mjs.map +1 -1
- package/dist/drizzle/passkey-write-drivers.mjs +5 -3
- package/dist/drizzle/passkey-write-drivers.mjs.map +1 -1
- package/dist/drizzle/passkey-write-target.d.mts +1 -1
- package/dist/drizzle/password-prepared-sql.mjs +2 -1
- package/dist/drizzle/password-prepared-sql.mjs.map +1 -1
- package/dist/drizzle/password-prepared-target.d.mts +3 -2
- package/dist/drizzle/password-prepared-target.mjs +4 -3
- package/dist/drizzle/password-prepared-target.mjs.map +1 -1
- package/dist/drizzle/password-registration.mjs +2 -1
- package/dist/drizzle/password-registration.mjs.map +1 -1
- package/dist/drizzle/password-target.d.mts +5 -4
- package/dist/drizzle/password-target.mjs +8 -8
- package/dist/drizzle/password-target.mjs.map +1 -1
- package/dist/drizzle/pg-database.d.mts +9 -0
- package/dist/drizzle/pg-database.mjs +8 -0
- package/dist/drizzle/pg-database.mjs.map +1 -0
- package/dist/drizzle/pg-emails.d.mts +7 -6
- package/dist/drizzle/pg-emails.mjs +12 -8
- package/dist/drizzle/pg-emails.mjs.map +1 -1
- package/dist/drizzle/pg-identity.mjs +12 -9
- package/dist/drizzle/pg-identity.mjs.map +1 -1
- package/dist/drizzle/pg-password-prepared.d.mts +3 -2
- package/dist/drizzle/pg-password-prepared.mjs +6 -2
- package/dist/drizzle/pg-password-prepared.mjs.map +1 -1
- package/dist/drizzle/pg-passwords.d.mts +6 -4
- package/dist/drizzle/pg-passwords.mjs +11 -7
- package/dist/drizzle/pg-passwords.mjs.map +1 -1
- package/dist/drizzle/pg-proofs.d.mts +3 -2
- package/dist/drizzle/pg-proofs.mjs +8 -4
- package/dist/drizzle/pg-proofs.mjs.map +1 -1
- package/dist/drizzle/pg-sessions.d.mts +11 -10
- package/dist/drizzle/pg-sessions.mjs +16 -12
- package/dist/drizzle/pg-sessions.mjs.map +1 -1
- package/dist/drizzle/phone-target.d.mts +4 -3
- package/dist/drizzle/phone-target.mjs +12 -11
- package/dist/drizzle/phone-target.mjs.map +1 -1
- package/dist/drizzle/proof-target.d.mts +3 -2
- package/dist/drizzle/proof-target.mjs +5 -5
- package/dist/drizzle/proof-target.mjs.map +1 -1
- package/dist/drizzle/session-sql.d.mts +1 -0
- package/dist/drizzle/session-target.d.mts +10 -8
- package/dist/drizzle/session-target.mjs +11 -11
- package/dist/drizzle/session-target.mjs.map +1 -1
- package/dist/drizzle/sqlite-emails.mjs +9 -5
- package/dist/drizzle/sqlite-emails.mjs.map +1 -1
- package/dist/drizzle/sqlite-identity.mjs +14 -11
- package/dist/drizzle/sqlite-identity.mjs.map +1 -1
- package/dist/drizzle/sqlite-password-prepared.mjs +7 -3
- package/dist/drizzle/sqlite-password-prepared.mjs.map +1 -1
- package/dist/drizzle/sqlite-passwords.mjs +10 -6
- package/dist/drizzle/sqlite-passwords.mjs.map +1 -1
- package/dist/drizzle/sqlite-proofs.mjs +7 -3
- package/dist/drizzle/sqlite-proofs.mjs.map +1 -1
- package/dist/drizzle/sqlite-sessions.mjs +16 -12
- package/dist/drizzle/sqlite-sessions.mjs.map +1 -1
- package/dist/drizzle/standalone-guard.d.mts +2 -0
- package/dist/drizzle/standalone-guard.mjs +8 -4
- package/dist/drizzle/standalone-guard.mjs.map +1 -1
- package/dist/drizzle/totp-target.d.mts +4 -3
- package/dist/drizzle/totp-target.mjs +31 -28
- package/dist/drizzle/totp-target.mjs.map +1 -1
- package/package.json +1 -1
- package/src/D1.ts +37 -10
- package/src/Libsql.ts +45 -17
- package/src/Mysql2.ts +39 -13
- package/src/Pglite.ts +47 -13
- package/src/Postgres.ts +47 -13
- package/src/SqliteBun.ts +58 -30
- package/src/SqliteDo.ts +61 -19
- package/src/SqliteNode.ts +55 -28
- package/src/SqliteWasm.ts +55 -28
- package/src/drizzle/d1-database.ts +10 -0
- package/src/drizzle/d1-emails.ts +84 -84
- package/src/drizzle/d1-identity.ts +17 -20
- package/src/drizzle/d1-oauth.ts +19 -8
- package/src/drizzle/d1-passkey.ts +5 -1
- package/src/drizzle/d1-password-prepared.ts +38 -37
- package/src/drizzle/d1-passwords.ts +118 -108
- package/src/drizzle/d1-phone.ts +5 -1
- package/src/drizzle/d1-proofs.ts +29 -30
- package/src/drizzle/d1-sessions.ts +51 -38
- package/src/drizzle/d1-totp.ts +5 -1
- package/src/drizzle/email-registration.ts +6 -2
- package/src/drizzle/email-target.ts +17 -19
- package/src/drizzle/mysql-database.ts +8 -0
- package/src/drizzle/mysql-emails.ts +28 -16
- package/src/drizzle/mysql-identity.ts +18 -21
- package/src/drizzle/mysql-password-prepared.ts +10 -8
- package/src/drizzle/mysql-passwords.ts +21 -9
- package/src/drizzle/mysql-proofs.ts +16 -5
- package/src/drizzle/mysql-sessions.ts +40 -17
- package/src/drizzle/native-database.ts +22 -0
- package/src/drizzle/oauth-connected-drivers.ts +18 -6
- package/src/drizzle/oauth-connected-settlement.ts +5 -3
- package/src/drizzle/oauth-connected-sign-in.ts +7 -3
- package/src/drizzle/oauth-connected-target.ts +16 -17
- package/src/drizzle/oauth-drivers.ts +26 -10
- package/src/drizzle/oauth-target.ts +30 -42
- package/src/drizzle/passkey-drivers.ts +21 -13
- package/src/drizzle/passkey-write-drivers.ts +11 -6
- package/src/drizzle/password-prepared-sql.ts +2 -4
- package/src/drizzle/password-prepared-target.ts +9 -6
- package/src/drizzle/password-registration.ts +7 -8
- package/src/drizzle/password-target.ts +19 -18
- package/src/drizzle/pg-database.ts +10 -0
- package/src/drizzle/pg-emails.ts +28 -16
- package/src/drizzle/pg-identity.ts +18 -22
- package/src/drizzle/pg-password-prepared.ts +10 -8
- package/src/drizzle/pg-passwords.ts +21 -9
- package/src/drizzle/pg-proofs.ts +16 -5
- package/src/drizzle/pg-sessions.ts +40 -17
- package/src/drizzle/phone-target.ts +22 -17
- package/src/drizzle/proof-target.ts +9 -12
- package/src/drizzle/session-target.ts +32 -50
- package/src/drizzle/sqlite-emails.ts +30 -13
- package/src/drizzle/sqlite-identity.ts +22 -42
- package/src/drizzle/sqlite-password-prepared.ts +23 -9
- package/src/drizzle/sqlite-passwords.ts +29 -15
- package/src/drizzle/sqlite-proofs.ts +28 -5
- package/src/drizzle/sqlite-sessions.ts +49 -23
- package/src/drizzle/standalone-guard.ts +18 -6
- package/src/drizzle/totp-target.ts +61 -60
- package/dist/drizzle/d1-identity.d.mts +0 -30
- package/dist/drizzle/mysql-identity.d.mts +0 -21
- package/dist/drizzle/pg-identity.d.mts +0 -22
|
@@ -8,8 +8,10 @@ import type { AnyPgTable } from "drizzle-orm/pg-core";
|
|
|
8
8
|
import { Effect, Context } from "effect";
|
|
9
9
|
import type { SqlError } from "effect/sql/SqlError";
|
|
10
10
|
|
|
11
|
+
import { nativeDatabase } from "./native-database";
|
|
11
12
|
import type { PasswordPersistenceMapping, PasswordRegistrationMapping } from "./password-model";
|
|
12
13
|
import type { PasswordRegistrationAuthority } from "./password-registration";
|
|
14
|
+
import { CurrentPasswordSql } from "./password-sql";
|
|
13
15
|
import type { PasswordSqlQuery } from "./password-sql";
|
|
14
16
|
import {
|
|
15
17
|
coordinateTargetPasswordPersistence,
|
|
@@ -18,24 +20,30 @@ import {
|
|
|
18
20
|
makeTargetPasswordRegistrationServices,
|
|
19
21
|
sqlClientPasswordStandaloneGuard,
|
|
20
22
|
} from "./password-target";
|
|
23
|
+
import { Database as DatabaseService } from "./pg-database";
|
|
21
24
|
import type { ProofPersistenceMapping } from "./proof-model";
|
|
22
25
|
import type { ProofSqlQuery } from "./proof-sql";
|
|
23
26
|
import { sqlClientProofStandaloneGuard } from "./proof-target";
|
|
27
|
+
import {
|
|
28
|
+
type TransactionService,
|
|
29
|
+
acquireTransactionService,
|
|
30
|
+
transactionService,
|
|
31
|
+
} from "./standalone-guard";
|
|
24
32
|
import type { SuppliedService } from "./SuppliedService";
|
|
25
33
|
|
|
26
34
|
type Database = PostgresDatabase<AnyRelations> | PgliteDatabase<AnyRelations>;
|
|
27
35
|
type TransactionOf<D extends Database> = Parameters<Parameters<D["transaction"]>[0]>[0];
|
|
28
36
|
|
|
29
|
-
const configuration = (
|
|
37
|
+
const configuration = (service: TransactionService | undefined) => ({
|
|
30
38
|
mode: "interactive" as const,
|
|
31
39
|
locking: true,
|
|
32
|
-
standaloneGuard: sqlClientPasswordStandaloneGuard(
|
|
40
|
+
standaloneGuard: sqlClientPasswordStandaloneGuard(service),
|
|
33
41
|
insertIfAbsent: (query: PasswordSqlQuery) => query.onConflictDoNothing(),
|
|
34
42
|
generatedSubjectRows: (query: PasswordSqlQuery) => query.returning(),
|
|
35
43
|
proof: {
|
|
36
44
|
mode: "interactive" as const,
|
|
37
45
|
locking: true,
|
|
38
|
-
standaloneGuard: sqlClientProofStandaloneGuard(
|
|
46
|
+
standaloneGuard: sqlClientProofStandaloneGuard(service),
|
|
39
47
|
insertIfAbsent: (query: ProofSqlQuery) => query.onConflictDoNothing(),
|
|
40
48
|
},
|
|
41
49
|
});
|
|
@@ -63,7 +71,6 @@ export const makePgPasswordPersistenceServices = <
|
|
|
63
71
|
M extends AnyPgTable,
|
|
64
72
|
NativeId,
|
|
65
73
|
>(
|
|
66
|
-
database: Database,
|
|
67
74
|
mapping: PasswordMapping<S, I, C, AC, A, RS, CE, M, NativeId>,
|
|
68
75
|
proofMapping?: ProofPersistenceMapping<
|
|
69
76
|
any,
|
|
@@ -80,7 +87,10 @@ export const makePgPasswordPersistenceServices = <
|
|
|
80
87
|
any
|
|
81
88
|
>,
|
|
82
89
|
) =>
|
|
83
|
-
|
|
90
|
+
Effect.flatMap(
|
|
91
|
+
Effect.map(acquireTransactionService(DatabaseService), configuration),
|
|
92
|
+
(configuration) => makeTargetPasswordPersistenceServices(mapping, configuration, proofMapping),
|
|
93
|
+
).pipe(Effect.provideServiceEffect(CurrentPasswordSql, nativeDatabase(DatabaseService)));
|
|
84
94
|
|
|
85
95
|
export function coordinatePgPasswordPersistence<
|
|
86
96
|
D extends Database,
|
|
@@ -188,7 +198,7 @@ export function coordinatePgPasswordPersistence<
|
|
|
188
198
|
coordinateTargetPasswordPersistence<TransactionOf<D>, Out, E, Exclude<R, PasswordPersistence>>(
|
|
189
199
|
database,
|
|
190
200
|
options.mapping,
|
|
191
|
-
configuration(database),
|
|
201
|
+
configuration(transactionService(database)),
|
|
192
202
|
options.proofMapping,
|
|
193
203
|
(
|
|
194
204
|
transaction: TransactionOf<D>,
|
|
@@ -214,10 +224,12 @@ export const makePgPasswordRegistrationServices = <
|
|
|
214
224
|
Rq extends AnyPgTable,
|
|
215
225
|
NativeId,
|
|
216
226
|
>(
|
|
217
|
-
database: Database,
|
|
218
227
|
mapping: PasswordRegistrationMapping<Registration, S, I, C, AC, Rq, NativeId>,
|
|
219
228
|
) =>
|
|
220
|
-
|
|
229
|
+
Effect.flatMap(
|
|
230
|
+
Effect.map(acquireTransactionService(DatabaseService), configuration),
|
|
231
|
+
(configuration) => makeTargetPasswordRegistrationServices<Registration>(mapping, configuration),
|
|
232
|
+
).pipe(Effect.provideServiceEffect(CurrentPasswordSql, nativeDatabase(DatabaseService)));
|
|
221
233
|
|
|
222
234
|
export function coordinatePgPasswordRegistration<
|
|
223
235
|
TargetId,
|
|
@@ -319,7 +331,7 @@ export function coordinatePgPasswordRegistration<
|
|
|
319
331
|
>(
|
|
320
332
|
database,
|
|
321
333
|
options.mapping,
|
|
322
|
-
configuration(database),
|
|
334
|
+
configuration(transactionService(database)),
|
|
323
335
|
(
|
|
324
336
|
transaction: TransactionOf<D>,
|
|
325
337
|
services: { readonly registrationAuthority: PasswordRegistrationAuthority<Registration> },
|
package/src/drizzle/pg-proofs.ts
CHANGED
|
@@ -7,13 +7,21 @@ import type { AnyPgTable } from "drizzle-orm/pg-core";
|
|
|
7
7
|
import { Effect, Context } from "effect";
|
|
8
8
|
import type { SqlError } from "effect/sql/SqlError";
|
|
9
9
|
|
|
10
|
+
import { nativeDatabase } from "./native-database";
|
|
11
|
+
import { Database as DatabaseService } from "./pg-database";
|
|
10
12
|
import type { ProofPersistenceMapping } from "./proof-model";
|
|
13
|
+
import { CurrentProofSql } from "./proof-sql";
|
|
11
14
|
import type { ProofSqlQuery } from "./proof-sql";
|
|
12
15
|
import {
|
|
13
16
|
coordinateTargetProofPersistence,
|
|
14
17
|
makeTargetProofPersistenceServices,
|
|
15
18
|
sqlClientProofStandaloneGuard,
|
|
16
19
|
} from "./proof-target";
|
|
20
|
+
import {
|
|
21
|
+
type TransactionService,
|
|
22
|
+
acquireTransactionService,
|
|
23
|
+
transactionService,
|
|
24
|
+
} from "./standalone-guard";
|
|
17
25
|
import type { SuppliedService } from "./SuppliedService";
|
|
18
26
|
|
|
19
27
|
type Database = PostgresDatabase<AnyRelations> | PgliteDatabase<AnyRelations>;
|
|
@@ -46,10 +54,10 @@ type Mapping<
|
|
|
46
54
|
NativeSubjectId
|
|
47
55
|
>;
|
|
48
56
|
|
|
49
|
-
const configuration = (
|
|
57
|
+
const configuration = (service: TransactionService | undefined) => ({
|
|
50
58
|
mode: "interactive" as const,
|
|
51
59
|
locking: true,
|
|
52
|
-
standaloneGuard: sqlClientProofStandaloneGuard(
|
|
60
|
+
standaloneGuard: sqlClientProofStandaloneGuard(service),
|
|
53
61
|
insertIfAbsent: (query: ProofSqlQuery) => query.onConflictDoNothing(),
|
|
54
62
|
});
|
|
55
63
|
|
|
@@ -67,9 +75,12 @@ export const makePgProofPersistenceServices = <
|
|
|
67
75
|
Cr extends AnyPgTable,
|
|
68
76
|
NativeId,
|
|
69
77
|
>(
|
|
70
|
-
database: Database,
|
|
71
78
|
mapping: Mapping<Rq, S, G, Cn, Rs, A, F, C, Sub, I, Cr, NativeId>,
|
|
72
|
-
) =>
|
|
79
|
+
) =>
|
|
80
|
+
Effect.flatMap(
|
|
81
|
+
Effect.map(acquireTransactionService(DatabaseService), configuration),
|
|
82
|
+
(configuration) => makeTargetProofPersistenceServices(mapping, configuration),
|
|
83
|
+
).pipe(Effect.provideServiceEffect(CurrentProofSql, nativeDatabase(DatabaseService)));
|
|
73
84
|
|
|
74
85
|
export function coordinatePgProofPersistence<
|
|
75
86
|
D extends Database,
|
|
@@ -174,7 +185,7 @@ export function coordinatePgProofPersistence<
|
|
|
174
185
|
coordinateTargetProofPersistence<TransactionOf<D>, A, E, Exclude<R, ProofPersistence>>(
|
|
175
186
|
database,
|
|
176
187
|
options.mapping,
|
|
177
|
-
configuration(database),
|
|
188
|
+
configuration(transactionService(database)),
|
|
178
189
|
(
|
|
179
190
|
transaction: TransactionOf<D>,
|
|
180
191
|
services: { readonly proofPersistence: ProofPersistence["Service"] },
|
|
@@ -15,12 +15,15 @@ import type { AnyPgTable } from "drizzle-orm/pg-core";
|
|
|
15
15
|
import { Effect, Context } from "effect";
|
|
16
16
|
import type { SqlError } from "effect/sql/SqlError";
|
|
17
17
|
|
|
18
|
+
import { nativeDatabase } from "./native-database";
|
|
19
|
+
import { Database as DatabaseService } from "./pg-database";
|
|
18
20
|
import type {
|
|
19
21
|
AuthenticationAuthorityMapping,
|
|
20
22
|
PendingAuthenticationMapping,
|
|
21
23
|
SignedSessionValidityMapping,
|
|
22
24
|
StatefulSessionMapping,
|
|
23
25
|
} from "./session-model";
|
|
26
|
+
import { CurrentSessionSql } from "./session-sql";
|
|
24
27
|
import {
|
|
25
28
|
coordinateTargetAuthenticationAuthority,
|
|
26
29
|
coordinateTargetPendingAuthentication,
|
|
@@ -34,15 +37,20 @@ import {
|
|
|
34
37
|
makeTargetSessionStepUpServices,
|
|
35
38
|
coordinateTargetSessionStepUp,
|
|
36
39
|
} from "./session-target";
|
|
40
|
+
import {
|
|
41
|
+
type TransactionService,
|
|
42
|
+
acquireTransactionService,
|
|
43
|
+
transactionService,
|
|
44
|
+
} from "./standalone-guard";
|
|
37
45
|
import type { SuppliedService } from "./SuppliedService";
|
|
38
46
|
|
|
39
47
|
type Database = PostgresDatabase<AnyRelations> | PgliteDatabase<AnyRelations>;
|
|
40
48
|
type TransactionOf<D extends Database> = Parameters<Parameters<D["transaction"]>[0]>[0];
|
|
41
49
|
|
|
42
|
-
const configuration = (
|
|
50
|
+
const configuration = (service: TransactionService | undefined) => ({
|
|
43
51
|
mode: "interactive" as const,
|
|
44
52
|
locking: true,
|
|
45
|
-
standaloneGuard: sqlClientSessionStandaloneGuard(
|
|
53
|
+
standaloneGuard: sqlClientSessionStandaloneGuard(service),
|
|
46
54
|
});
|
|
47
55
|
|
|
48
56
|
export const makePgAuthenticationAuthorityServices = <
|
|
@@ -53,7 +61,6 @@ export const makePgAuthenticationAuthorityServices = <
|
|
|
53
61
|
Pending extends AnyPgTable,
|
|
54
62
|
NativeSubjectId,
|
|
55
63
|
>(
|
|
56
|
-
database: Database,
|
|
57
64
|
mapping: AuthenticationAuthorityMapping<
|
|
58
65
|
Claims,
|
|
59
66
|
Subject,
|
|
@@ -62,7 +69,11 @@ export const makePgAuthenticationAuthorityServices = <
|
|
|
62
69
|
Pending,
|
|
63
70
|
NativeSubjectId
|
|
64
71
|
>,
|
|
65
|
-
) =>
|
|
72
|
+
) =>
|
|
73
|
+
Effect.flatMap(
|
|
74
|
+
Effect.map(acquireTransactionService(DatabaseService), configuration),
|
|
75
|
+
(configuration) => makeTargetAuthenticationAuthorityServices<Claims>(mapping, configuration),
|
|
76
|
+
).pipe(Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(DatabaseService)));
|
|
66
77
|
|
|
67
78
|
export const makePgPendingAuthenticationServices = <
|
|
68
79
|
Claims,
|
|
@@ -72,7 +83,6 @@ export const makePgPendingAuthenticationServices = <
|
|
|
72
83
|
Flow extends AnyPgTable,
|
|
73
84
|
NativeSubjectId,
|
|
74
85
|
>(
|
|
75
|
-
database: Database,
|
|
76
86
|
mapping: PendingAuthenticationMapping<
|
|
77
87
|
Claims,
|
|
78
88
|
Subject,
|
|
@@ -81,7 +91,11 @@ export const makePgPendingAuthenticationServices = <
|
|
|
81
91
|
Flow,
|
|
82
92
|
NativeSubjectId
|
|
83
93
|
>,
|
|
84
|
-
) =>
|
|
94
|
+
) =>
|
|
95
|
+
Effect.flatMap(
|
|
96
|
+
Effect.map(acquireTransactionService(DatabaseService), configuration),
|
|
97
|
+
(configuration) => makeTargetPendingAuthenticationServices<Claims>(mapping, configuration),
|
|
98
|
+
).pipe(Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(DatabaseService)));
|
|
85
99
|
|
|
86
100
|
export const makePgStatefulSessionServices = <
|
|
87
101
|
Claims,
|
|
@@ -93,7 +107,6 @@ export const makePgStatefulSessionServices = <
|
|
|
93
107
|
NativeSubjectId,
|
|
94
108
|
NativeSessionId,
|
|
95
109
|
>(
|
|
96
|
-
database: Database,
|
|
97
110
|
mapping: StatefulSessionMapping<
|
|
98
111
|
Claims,
|
|
99
112
|
Subject,
|
|
@@ -104,7 +117,11 @@ export const makePgStatefulSessionServices = <
|
|
|
104
117
|
NativeSubjectId,
|
|
105
118
|
NativeSessionId
|
|
106
119
|
>,
|
|
107
|
-
) =>
|
|
120
|
+
) =>
|
|
121
|
+
Effect.flatMap(
|
|
122
|
+
Effect.map(acquireTransactionService(DatabaseService), configuration),
|
|
123
|
+
(configuration) => makeTargetStatefulSessionServices<Claims>(mapping, configuration),
|
|
124
|
+
).pipe(Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(DatabaseService)));
|
|
108
125
|
|
|
109
126
|
export const makePgSignedSessionValidityServices = <
|
|
110
127
|
Subject extends AnyPgTable,
|
|
@@ -112,9 +129,12 @@ export const makePgSignedSessionValidityServices = <
|
|
|
112
129
|
NativeSubjectId,
|
|
113
130
|
NativeSessionId,
|
|
114
131
|
>(
|
|
115
|
-
database: Database,
|
|
116
132
|
mapping: SignedSessionValidityMapping<Subject, Tombstone, NativeSubjectId, NativeSessionId>,
|
|
117
|
-
) =>
|
|
133
|
+
) =>
|
|
134
|
+
Effect.flatMap(
|
|
135
|
+
Effect.map(acquireTransactionService(DatabaseService), configuration),
|
|
136
|
+
(configuration) => makeTargetSignedSessionValidityServices(mapping, configuration),
|
|
137
|
+
).pipe(Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(DatabaseService)));
|
|
118
138
|
|
|
119
139
|
export function coordinatePgAuthenticationAuthority<
|
|
120
140
|
Claims,
|
|
@@ -207,7 +227,7 @@ export function coordinatePgAuthenticationAuthority<
|
|
|
207
227
|
>(
|
|
208
228
|
database,
|
|
209
229
|
options.mapping,
|
|
210
|
-
configuration(database),
|
|
230
|
+
configuration(transactionService(database)),
|
|
211
231
|
(
|
|
212
232
|
transaction: TransactionOf<D>,
|
|
213
233
|
services: { readonly authenticationAuthority: AuthenticationAuthority["Service"] },
|
|
@@ -314,7 +334,7 @@ export function coordinatePgPendingAuthentication<
|
|
|
314
334
|
coordinateTargetPendingAuthentication<Claims, TransactionOf<D>, A, E, Exclude<R, TargetId>>(
|
|
315
335
|
database,
|
|
316
336
|
options.mapping,
|
|
317
|
-
configuration(database),
|
|
337
|
+
configuration(transactionService(database)),
|
|
318
338
|
(
|
|
319
339
|
transaction: TransactionOf<D>,
|
|
320
340
|
services: { readonly pendingAuthentication: PendingAuthentication<Claims> },
|
|
@@ -466,7 +486,7 @@ export function coordinatePgStatefulSessions<
|
|
|
466
486
|
>(
|
|
467
487
|
database,
|
|
468
488
|
options.mapping,
|
|
469
|
-
configuration(database),
|
|
489
|
+
configuration(transactionService(database)),
|
|
470
490
|
(
|
|
471
491
|
transaction: TransactionOf<D>,
|
|
472
492
|
services: {
|
|
@@ -574,7 +594,7 @@ export function coordinatePgSignedSessionValidity<
|
|
|
574
594
|
coordinateTargetSignedSessionValidity<TransactionOf<D>, A, E, Exclude<R, TargetId>>(
|
|
575
595
|
database,
|
|
576
596
|
options.mapping,
|
|
577
|
-
configuration(database),
|
|
597
|
+
configuration(transactionService(database)),
|
|
578
598
|
(
|
|
579
599
|
transaction: TransactionOf<D>,
|
|
580
600
|
services: { readonly signedSessionValidity: SignedSessionValidity },
|
|
@@ -603,10 +623,13 @@ export const makePgSessionStepUpServices = <
|
|
|
603
623
|
NativeId,
|
|
604
624
|
NativeSessionId,
|
|
605
625
|
>(
|
|
606
|
-
database: Database,
|
|
607
626
|
mapping: SessionStepUpMapping<NoInfer<Claims>, S, C, I, Session, T, NativeId, NativeSessionId>,
|
|
608
627
|
target: Context.Service<Id, SessionStepUpPersistence<Claims>>,
|
|
609
|
-
) =>
|
|
628
|
+
) =>
|
|
629
|
+
Effect.flatMap(
|
|
630
|
+
Effect.map(acquireTransactionService(DatabaseService), configuration),
|
|
631
|
+
(configuration) => makeTargetSessionStepUpServices(mapping, target, configuration),
|
|
632
|
+
).pipe(Effect.provideServiceEffect(CurrentSessionSql, nativeDatabase(DatabaseService)));
|
|
610
633
|
|
|
611
634
|
export function coordinatePgSessionStepUp<
|
|
612
635
|
Claims,
|
|
@@ -733,7 +756,7 @@ export function coordinatePgSessionStepUp<
|
|
|
733
756
|
database,
|
|
734
757
|
options.mapping,
|
|
735
758
|
options.target,
|
|
736
|
-
configuration(database),
|
|
759
|
+
configuration(transactionService(database)),
|
|
737
760
|
(
|
|
738
761
|
transaction: TransactionOf<D>,
|
|
739
762
|
services: { readonly sessionStepUpPersistence: SessionStepUpPersistence<Claims> },
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { randomId } from "@yielded/auth-crypto";
|
|
2
|
+
import { NativeDatabase } from "@yielded/auth-persistence/Adapter";
|
|
2
3
|
import { LifecycleHooks } from "@yielded/auth/Hooks";
|
|
3
4
|
import {
|
|
4
5
|
PhoneConfigurationError,
|
|
@@ -21,6 +22,7 @@ import type { Statement } from "effect/sql/Statement";
|
|
|
21
22
|
import { CurrentD1PlanningDatabase } from "./d1-planning";
|
|
22
23
|
import { compileD1ProofCompletionPlan } from "./d1-proofs";
|
|
23
24
|
import type { PersistenceMappingError } from "./model";
|
|
25
|
+
import { nativeDatabase } from "./native-database";
|
|
24
26
|
import {
|
|
25
27
|
phoneProofs,
|
|
26
28
|
type PhoneMapping,
|
|
@@ -59,8 +61,8 @@ export type PhoneCoordinatorError<E> =
|
|
|
59
61
|
| PersistenceMappingError;
|
|
60
62
|
|
|
61
63
|
export const sqlClientPhoneStandaloneGuard = (
|
|
62
|
-
|
|
63
|
-
) => sqlClientTransactionStandaloneGuard(unavailable,
|
|
64
|
+
service: Parameters<typeof sqlClientTransactionStandaloneGuard>[1],
|
|
65
|
+
) => sqlClientTransactionStandaloneGuard(unavailable, service);
|
|
64
66
|
|
|
65
67
|
const validateMapping = <M>(original: M, configuration: PhoneTargetConfiguration): M => {
|
|
66
68
|
const mapping = original as any;
|
|
@@ -95,12 +97,13 @@ const validateMapping = <M>(original: M, configuration: PhoneTargetConfiguration
|
|
|
95
97
|
});
|
|
96
98
|
};
|
|
97
99
|
|
|
98
|
-
const services = (
|
|
100
|
+
const services = Effect.fnUntraced(function* (
|
|
99
101
|
mapping: any,
|
|
100
102
|
execution: TransactionExecution<PhoneUnavailable, CurrentPhoneTransaction>,
|
|
101
|
-
hooks: LifecycleHooks["Service"],
|
|
102
103
|
configuration: PhoneTargetConfiguration,
|
|
103
|
-
): PhonePersistenceServices
|
|
104
|
+
): Effect.fn.Return<PhonePersistenceServices, never, LifecycleHooks> {
|
|
105
|
+
const hooks = yield* LifecycleHooks;
|
|
106
|
+
|
|
104
107
|
const run = <A, E, R>(effect: Effect.Effect<A, E, R>, mutation = true) =>
|
|
105
108
|
execution.admit.pipe(
|
|
106
109
|
Effect.andThen(execution.run(effect, mutation)),
|
|
@@ -253,7 +256,7 @@ const services = (
|
|
|
253
256
|
}).pipe(Effect.catchDefect(() => Effect.fail(unavailable()))),
|
|
254
257
|
}),
|
|
255
258
|
};
|
|
256
|
-
};
|
|
259
|
+
});
|
|
257
260
|
|
|
258
261
|
export const makeTargetPhonePersistence = <
|
|
259
262
|
S extends Table,
|
|
@@ -263,12 +266,10 @@ export const makeTargetPhonePersistence = <
|
|
|
263
266
|
N,
|
|
264
267
|
RSetup = never,
|
|
265
268
|
>(
|
|
266
|
-
database: TransactionNativeDatabase,
|
|
267
269
|
source: PhoneMappingSource<PhoneMapping<S, I, C, F, N>, RSetup>,
|
|
268
270
|
configuration: PhoneTargetConfiguration,
|
|
269
271
|
) =>
|
|
270
272
|
Effect.gen(function* () {
|
|
271
|
-
const hooks = yield* LifecycleHooks;
|
|
272
273
|
const original = yield* Effect.isEffect(source) ? source : Effect.succeed(source);
|
|
273
274
|
|
|
274
275
|
const mapping = yield* Effect.try({
|
|
@@ -276,15 +277,14 @@ export const makeTargetPhonePersistence = <
|
|
|
276
277
|
catch: () => PhoneConfigurationError.make({}),
|
|
277
278
|
});
|
|
278
279
|
|
|
279
|
-
const execution = makeTransactionExecution(
|
|
280
|
+
const execution = yield* makeTransactionExecution(
|
|
280
281
|
CurrentPhoneTransaction,
|
|
281
|
-
database,
|
|
282
282
|
configuration,
|
|
283
283
|
unavailable,
|
|
284
284
|
randomId,
|
|
285
285
|
);
|
|
286
286
|
|
|
287
|
-
return services(mapping, execution,
|
|
287
|
+
return yield* services(mapping, execution, configuration);
|
|
288
288
|
});
|
|
289
289
|
|
|
290
290
|
export const coordinateTargetPhone = <M, A, E, R, RSetup = never>(
|
|
@@ -298,7 +298,6 @@ export const coordinateTargetPhone = <M, A, E, R, RSetup = never>(
|
|
|
298
298
|
) => Effect.Effect<A, E, R>,
|
|
299
299
|
): Effect.Effect<A, PhoneCoordinatorError<E>, R | RSetup | LifecycleHooks> =>
|
|
300
300
|
Effect.gen(function* () {
|
|
301
|
-
const hooks = yield* LifecycleHooks;
|
|
302
301
|
const original = yield* Effect.isEffect(source) ? source : Effect.succeed(source);
|
|
303
302
|
|
|
304
303
|
const mapping = yield* Effect.try({
|
|
@@ -313,8 +312,11 @@ export const coordinateTargetPhone = <M, A, E, R, RSetup = never>(
|
|
|
313
312
|
Effect.void,
|
|
314
313
|
unavailable,
|
|
315
314
|
randomId,
|
|
316
|
-
(execution) => services(mapping, execution,
|
|
317
|
-
|
|
315
|
+
(execution) => services(mapping, execution, configuration),
|
|
316
|
+
(transaction, acquireServices, append) =>
|
|
317
|
+
Effect.flatMap(acquireServices, (boundServices) =>
|
|
318
|
+
body(transaction, boundServices, append),
|
|
319
|
+
),
|
|
318
320
|
);
|
|
319
321
|
});
|
|
320
322
|
|
|
@@ -324,11 +326,13 @@ type TransactionOf<D> = D extends { readonly transaction: (...args: any[]) => an
|
|
|
324
326
|
|
|
325
327
|
/** Concrete driver wrappers select transaction mode; cryptography always precedes these owners. */
|
|
326
328
|
export const makePhoneTarget = <
|
|
329
|
+
DatabaseId,
|
|
327
330
|
D extends { readonly transaction: any },
|
|
328
331
|
T extends Table,
|
|
329
332
|
Extra = unknown,
|
|
330
333
|
Synchronous extends boolean = false,
|
|
331
334
|
>(
|
|
335
|
+
databaseService: Context.Service<DatabaseId, D>,
|
|
332
336
|
configuration: PhoneTargetConfiguration,
|
|
333
337
|
) => {
|
|
334
338
|
function coordinatePhonePersistence<
|
|
@@ -456,7 +460,6 @@ export const makePhoneTarget = <
|
|
|
456
460
|
|
|
457
461
|
return {
|
|
458
462
|
makePhonePersistenceServices: <
|
|
459
|
-
Database extends D,
|
|
460
463
|
S extends T,
|
|
461
464
|
I extends T,
|
|
462
465
|
F extends T,
|
|
@@ -464,9 +467,11 @@ export const makePhoneTarget = <
|
|
|
464
467
|
N,
|
|
465
468
|
RSetup = never,
|
|
466
469
|
>(
|
|
467
|
-
database: Database,
|
|
468
470
|
mapping: PhoneMappingSource<PhoneMapping<S, I, C, F, N> & Extra, RSetup>,
|
|
469
|
-
) =>
|
|
471
|
+
) =>
|
|
472
|
+
makeTargetPhonePersistence(mapping, configuration).pipe(
|
|
473
|
+
Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),
|
|
474
|
+
),
|
|
470
475
|
coordinatePhonePersistence,
|
|
471
476
|
};
|
|
472
477
|
};
|
|
@@ -10,12 +10,13 @@ import { Effect, Layer } from "effect";
|
|
|
10
10
|
import type * as SqlError from "effect/sql/SqlError";
|
|
11
11
|
|
|
12
12
|
import {
|
|
13
|
+
CurrentProofSql,
|
|
13
14
|
makeSqlProofPersistence,
|
|
14
15
|
type ProofSqlConfiguration,
|
|
15
16
|
type ProofSqlDatabase,
|
|
16
17
|
type ProofSqlQuery,
|
|
17
18
|
} from "./proof-sql";
|
|
18
|
-
import { sqlClientStandaloneGuard } from "./standalone-guard";
|
|
19
|
+
import { sqlClientStandaloneGuard, type TransactionService } from "./standalone-guard";
|
|
19
20
|
|
|
20
21
|
export interface ProofTargetConfiguration {
|
|
21
22
|
readonly mode: "interactive" | "synchronous";
|
|
@@ -42,9 +43,9 @@ export type ProofCoordinatorError<E> =
|
|
|
42
43
|
| SqlError.SqlError;
|
|
43
44
|
|
|
44
45
|
export const sqlClientProofStandaloneGuard = (
|
|
45
|
-
|
|
46
|
+
service: TransactionService | undefined,
|
|
46
47
|
): Effect.Effect<void, ProofUnavailable> =>
|
|
47
|
-
sqlClientStandaloneGuard(
|
|
48
|
+
sqlClientStandaloneGuard(service, () => ProofUnavailable.make({}));
|
|
48
49
|
|
|
49
50
|
const options = (
|
|
50
51
|
configuration: ProofTargetConfiguration,
|
|
@@ -59,13 +60,12 @@ const options = (
|
|
|
59
60
|
});
|
|
60
61
|
|
|
61
62
|
export const makeTargetProofPersistenceServices = (
|
|
62
|
-
database: any,
|
|
63
63
|
mapping: any,
|
|
64
64
|
configuration: ProofTargetConfiguration,
|
|
65
65
|
) =>
|
|
66
66
|
Effect.gen(function* () {
|
|
67
67
|
return {
|
|
68
|
-
proofPersistence: yield* makeSqlProofPersistence(
|
|
68
|
+
proofPersistence: yield* makeSqlProofPersistence(mapping, options(configuration)),
|
|
69
69
|
};
|
|
70
70
|
});
|
|
71
71
|
|
|
@@ -96,9 +96,10 @@ export const coordinateTargetProofPersistence = <Transaction, A, E, R>(
|
|
|
96
96
|
Effect.gen(function* () {
|
|
97
97
|
return yield* owner(transaction, {
|
|
98
98
|
proofPersistence: yield* makeSqlProofPersistence(
|
|
99
|
-
transaction as unknown as ProofSqlDatabase,
|
|
100
99
|
mapping,
|
|
101
100
|
options(configuration, true),
|
|
101
|
+
).pipe(
|
|
102
|
+
Effect.provideService(CurrentProofSql, transaction as unknown as ProofSqlDatabase),
|
|
102
103
|
),
|
|
103
104
|
});
|
|
104
105
|
}),
|
|
@@ -109,12 +110,8 @@ export const coordinateTargetProofPersistence = <Transaction, A, E, R>(
|
|
|
109
110
|
return result.value;
|
|
110
111
|
});
|
|
111
112
|
|
|
112
|
-
export const proofPersistenceLayer = (
|
|
113
|
-
services: Effect.Effect<
|
|
114
|
-
{ readonly proofPersistence: ProofPersistence["Service"] },
|
|
115
|
-
never,
|
|
116
|
-
LifecycleHooks
|
|
117
|
-
>,
|
|
113
|
+
export const proofPersistenceLayer = <E, R>(
|
|
114
|
+
services: Effect.Effect<{ readonly proofPersistence: ProofPersistence["Service"] }, E, R>,
|
|
118
115
|
) =>
|
|
119
116
|
Layer.effect(
|
|
120
117
|
ProofPersistence,
|