@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
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { NativeDatabase } from "@yielded/auth-persistence/Adapter";
|
|
1
2
|
import type { LifecycleHooks } from "@yielded/auth/Hooks";
|
|
2
3
|
import { PasskeyPersistence } from "@yielded/auth/Passkey";
|
|
3
4
|
import type { Table } from "drizzle-orm";
|
|
4
5
|
import { Effect, Context } from "effect";
|
|
5
6
|
|
|
7
|
+
import { nativeDatabase } from "./native-database";
|
|
6
8
|
import type {
|
|
7
9
|
PasskeyCredentialMapping,
|
|
8
10
|
PasskeyEnrollmentContextMapping,
|
|
@@ -33,11 +35,13 @@ type TransactionOf<D> = D extends { readonly transaction: (...args: any[]) => an
|
|
|
33
35
|
: never;
|
|
34
36
|
|
|
35
37
|
export const makePasskeyTarget = <
|
|
38
|
+
DatabaseId,
|
|
36
39
|
D,
|
|
37
40
|
T extends Table,
|
|
38
41
|
Extra = unknown,
|
|
39
42
|
Synchronous extends boolean = false,
|
|
40
43
|
>(
|
|
44
|
+
databaseService: Context.Service<DatabaseId, D>,
|
|
41
45
|
configuration: PasskeyTargetConfiguration,
|
|
42
46
|
) => {
|
|
43
47
|
function coordinatePasskeyPersistence<
|
|
@@ -304,9 +308,8 @@ export const makePasskeyTarget = <
|
|
|
304
308
|
}
|
|
305
309
|
|
|
306
310
|
return {
|
|
307
|
-
...makePasskeyWriteTarget<D, T, Extra, Synchronous>(configuration),
|
|
311
|
+
...makePasskeyWriteTarget<DatabaseId, D, T, Extra, Synchronous>(databaseService, configuration),
|
|
308
312
|
makePasskeyCredentialServices: <
|
|
309
|
-
Database extends D,
|
|
310
313
|
S extends T,
|
|
311
314
|
C extends T,
|
|
312
315
|
F extends T,
|
|
@@ -315,11 +318,12 @@ export const makePasskeyTarget = <
|
|
|
315
318
|
N,
|
|
316
319
|
RSetup = never,
|
|
317
320
|
>(
|
|
318
|
-
database: Database,
|
|
319
321
|
mapping: PasskeyMappingSource<PasskeyCredentialMapping<S, C, F, O, H, N> & Extra, RSetup>,
|
|
320
|
-
) =>
|
|
322
|
+
) =>
|
|
323
|
+
makeTargetPasskeyCredentials(mapping, configuration).pipe(
|
|
324
|
+
Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),
|
|
325
|
+
),
|
|
321
326
|
makePasskeyEnrollmentContextServices: <
|
|
322
|
-
Database extends D,
|
|
323
327
|
S extends T,
|
|
324
328
|
C extends T,
|
|
325
329
|
F extends T,
|
|
@@ -329,14 +333,15 @@ export const makePasskeyTarget = <
|
|
|
329
333
|
N,
|
|
330
334
|
RSetup = never,
|
|
331
335
|
>(
|
|
332
|
-
database: Database,
|
|
333
336
|
mapping: PasskeyMappingSource<
|
|
334
337
|
PasskeyEnrollmentContextMapping<PasskeyCredentialMapping<S, C, F, O, H, N>, M, N> & Extra,
|
|
335
338
|
RSetup
|
|
336
339
|
>,
|
|
337
|
-
) =>
|
|
340
|
+
) =>
|
|
341
|
+
makeTargetPasskeyEnrollmentContext(mapping, configuration).pipe(
|
|
342
|
+
Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),
|
|
343
|
+
),
|
|
338
344
|
makePasskeyPersistenceServices: <
|
|
339
|
-
Database extends D,
|
|
340
345
|
S extends T,
|
|
341
346
|
C extends T,
|
|
342
347
|
F extends T,
|
|
@@ -349,7 +354,6 @@ export const makePasskeyTarget = <
|
|
|
349
354
|
N,
|
|
350
355
|
RSetup = never,
|
|
351
356
|
>(
|
|
352
|
-
database: Database,
|
|
353
357
|
mapping: PasskeyMappingSource<
|
|
354
358
|
PasskeyPersistenceMapping<
|
|
355
359
|
PasskeyCredentialMapping<S, C, F, O, H, N>,
|
|
@@ -362,9 +366,11 @@ export const makePasskeyTarget = <
|
|
|
362
366
|
Extra,
|
|
363
367
|
RSetup
|
|
364
368
|
>,
|
|
365
|
-
) =>
|
|
369
|
+
) =>
|
|
370
|
+
makeTargetPasskeyPersistence(mapping, configuration).pipe(
|
|
371
|
+
Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),
|
|
372
|
+
),
|
|
366
373
|
makePasskeyRegistrationCeremonyServices: <
|
|
367
|
-
Database extends D,
|
|
368
374
|
M extends T,
|
|
369
375
|
Flow extends T,
|
|
370
376
|
Admission extends T,
|
|
@@ -373,12 +379,14 @@ export const makePasskeyTarget = <
|
|
|
373
379
|
H extends T,
|
|
374
380
|
RSetup = never,
|
|
375
381
|
>(
|
|
376
|
-
database: Database,
|
|
377
382
|
mapping: PasskeyMappingSource<
|
|
378
383
|
PasskeyRegistrationCeremonyMapping<M, Flow, Admission, Charge, Intent, H> & Extra,
|
|
379
384
|
RSetup
|
|
380
385
|
>,
|
|
381
|
-
) =>
|
|
386
|
+
) =>
|
|
387
|
+
makeTargetPasskeyRegistration(mapping, configuration).pipe(
|
|
388
|
+
Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),
|
|
389
|
+
),
|
|
382
390
|
coordinatePasskeyPersistence,
|
|
383
391
|
coordinatePasskeyRegistrationCeremony,
|
|
384
392
|
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { NativeDatabase } from "@yielded/auth-persistence/Adapter";
|
|
1
2
|
import type { LifecycleHooks } from "@yielded/auth/Hooks";
|
|
2
3
|
import { PasskeyManagementPersistence, PasskeyPersistence } from "@yielded/auth/Passkey";
|
|
3
4
|
import type { Table } from "drizzle-orm";
|
|
4
5
|
import { Context, Effect } from "effect";
|
|
5
6
|
|
|
7
|
+
import { nativeDatabase } from "./native-database";
|
|
6
8
|
import type { PasskeyMappingSource } from "./passkey-model";
|
|
7
9
|
import type { PasskeyCoordinatorError, PasskeyTargetConfiguration } from "./passkey-target";
|
|
8
10
|
import type {
|
|
@@ -23,11 +25,13 @@ type TransactionOf<D> = D extends { readonly transaction: (...args: any[]) => an
|
|
|
23
25
|
: never;
|
|
24
26
|
|
|
25
27
|
export const makePasskeyWriteTarget = <
|
|
28
|
+
DatabaseId,
|
|
26
29
|
D,
|
|
27
30
|
T extends Table,
|
|
28
31
|
Extra = unknown,
|
|
29
32
|
Synchronous extends boolean = false,
|
|
30
33
|
>(
|
|
34
|
+
databaseService: Context.Service<DatabaseId, D>,
|
|
31
35
|
configuration: PasskeyTargetConfiguration,
|
|
32
36
|
) => {
|
|
33
37
|
function coordinatePasskeyManagement<
|
|
@@ -180,7 +184,6 @@ export const makePasskeyWriteTarget = <
|
|
|
180
184
|
}
|
|
181
185
|
|
|
182
186
|
const makePasskeyManagementServices = <
|
|
183
|
-
Database extends D,
|
|
184
187
|
S extends T,
|
|
185
188
|
C extends T,
|
|
186
189
|
F extends T,
|
|
@@ -194,12 +197,14 @@ export const makePasskeyWriteTarget = <
|
|
|
194
197
|
N,
|
|
195
198
|
RSetup = never,
|
|
196
199
|
>(
|
|
197
|
-
database: Database,
|
|
198
200
|
mapping: PasskeyMappingSource<
|
|
199
201
|
PasskeyManagementMapping<S, C, F, O, H, M, Flow, Admission, Charge, Command, N> & Extra,
|
|
200
202
|
RSetup
|
|
201
203
|
>,
|
|
202
|
-
) =>
|
|
204
|
+
) =>
|
|
205
|
+
makeTargetPasskeyManagement(mapping, configuration).pipe(
|
|
206
|
+
Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),
|
|
207
|
+
);
|
|
203
208
|
|
|
204
209
|
function coordinatePasskeyRegistration<
|
|
205
210
|
Database extends D,
|
|
@@ -357,7 +362,6 @@ export const makePasskeyWriteTarget = <
|
|
|
357
362
|
}
|
|
358
363
|
|
|
359
364
|
const makePasskeyRegistrationServices = <
|
|
360
|
-
Database extends D,
|
|
361
365
|
S extends T,
|
|
362
366
|
C extends T,
|
|
363
367
|
F extends T,
|
|
@@ -372,7 +376,6 @@ export const makePasskeyWriteTarget = <
|
|
|
372
376
|
Value,
|
|
373
377
|
RSetup = never,
|
|
374
378
|
>(
|
|
375
|
-
database: Database,
|
|
376
379
|
mapping: PasskeyMappingSource<
|
|
377
380
|
PasskeyRegistrationMapping<S, C, F, O, H, M, Flow, Admission, Charge, Intent, N, Value> &
|
|
378
381
|
Extra,
|
|
@@ -384,7 +387,9 @@ export const makePasskeyWriteTarget = <
|
|
|
384
387
|
Extra,
|
|
385
388
|
Value,
|
|
386
389
|
RSetup
|
|
387
|
-
>(
|
|
390
|
+
>(mapping, configuration).pipe(
|
|
391
|
+
Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),
|
|
392
|
+
);
|
|
388
393
|
|
|
389
394
|
return {
|
|
390
395
|
makePasskeyManagementServices,
|
|
@@ -50,7 +50,6 @@ import {
|
|
|
50
50
|
CurrentPasswordSql,
|
|
51
51
|
passwordSqlKernel as kernel,
|
|
52
52
|
type PasswordSqlConfiguration,
|
|
53
|
-
type PasswordSqlDatabase,
|
|
54
53
|
type PasswordSqlQuery,
|
|
55
54
|
} from "./password-sql";
|
|
56
55
|
import { checkProofCompletionIn, completeProofPlanIn } from "./proof-sql";
|
|
@@ -85,7 +84,6 @@ const translateContextFailure = <A, E, R>(
|
|
|
85
84
|
);
|
|
86
85
|
|
|
87
86
|
type Mapping = AnyPasswordPreparedPersistenceMapping;
|
|
88
|
-
type Database = PasswordSqlDatabase;
|
|
89
87
|
const nowMillis = DateTime.now.pipe(Effect.map(DateTime.toEpochMillis));
|
|
90
88
|
|
|
91
89
|
const read = (query: PasswordSqlQuery, locking: boolean) =>
|
|
@@ -410,10 +408,10 @@ const terminal = Effect.fn("DrizzlePasswordPrepared.terminal")(function* (
|
|
|
410
408
|
|
|
411
409
|
export const makeSqlPasswordPreparedPersistence = Effect.fn("makeSqlPasswordPreparedPersistence")(
|
|
412
410
|
function* (
|
|
413
|
-
database: Database,
|
|
414
411
|
mapping: Mapping,
|
|
415
412
|
configuration: PasswordSqlConfiguration,
|
|
416
|
-
): Effect.fn.Return<PasswordPreparedPersistence, never, LifecycleHooks> {
|
|
413
|
+
): Effect.fn.Return<PasswordPreparedPersistence, never, LifecycleHooks | CurrentPasswordSql> {
|
|
414
|
+
const database = yield* CurrentPasswordSql;
|
|
417
415
|
const hooks = yield* LifecycleHooks;
|
|
418
416
|
|
|
419
417
|
const p = mapping.password,
|
|
@@ -16,6 +16,7 @@ import { type Context, Cause, Effect, Layer } from "effect";
|
|
|
16
16
|
import type * as SqlError from "effect/sql/SqlError";
|
|
17
17
|
|
|
18
18
|
import { makeSqlPasswordPreparedPersistence } from "./password-prepared-sql";
|
|
19
|
+
import { CurrentPasswordSql } from "./password-sql";
|
|
19
20
|
import type { PasswordSqlDatabase } from "./password-sql";
|
|
20
21
|
import {
|
|
21
22
|
passwordOptions,
|
|
@@ -24,7 +25,6 @@ import {
|
|
|
24
25
|
} from "./password-target";
|
|
25
26
|
|
|
26
27
|
export const makeTargetPasswordPreparedPersistenceServices = (
|
|
27
|
-
database: any,
|
|
28
28
|
mapping: any,
|
|
29
29
|
configuration: PasswordTargetConfiguration,
|
|
30
30
|
proofMapping?: any,
|
|
@@ -32,7 +32,6 @@ export const makeTargetPasswordPreparedPersistenceServices = (
|
|
|
32
32
|
Effect.gen(function* () {
|
|
33
33
|
return {
|
|
34
34
|
passwordPreparedPersistence: yield* makeSqlPasswordPreparedPersistence(
|
|
35
|
-
database,
|
|
36
35
|
mapping,
|
|
37
36
|
passwordOptions(configuration, proofMapping),
|
|
38
37
|
),
|
|
@@ -69,9 +68,13 @@ export const coordinateTargetPasswordPreparedPersistence = <Transaction, A, E, R
|
|
|
69
68
|
let acceptingPostconditions = true;
|
|
70
69
|
|
|
71
70
|
const services = yield* makeSqlPasswordPreparedPersistence(
|
|
72
|
-
transaction as unknown as PasswordSqlDatabase,
|
|
73
71
|
mapping,
|
|
74
72
|
passwordOptions(configuration, proofMapping, true),
|
|
73
|
+
).pipe(
|
|
74
|
+
Effect.provideService(
|
|
75
|
+
CurrentPasswordSql,
|
|
76
|
+
transaction as unknown as PasswordSqlDatabase,
|
|
77
|
+
),
|
|
75
78
|
);
|
|
76
79
|
|
|
77
80
|
const protect = <Out, Err, Env>(effect: Effect.Effect<Out, Err, Env>) =>
|
|
@@ -146,12 +149,12 @@ export const coordinateTargetPasswordPreparedPersistence = <Transaction, A, E, R
|
|
|
146
149
|
return result.value;
|
|
147
150
|
});
|
|
148
151
|
|
|
149
|
-
export const passwordPreparedPersistenceLayer = <Id>(
|
|
152
|
+
export const passwordPreparedPersistenceLayer = <Id, E, R>(
|
|
150
153
|
tag: Context.Key<Id, PasswordPreparedPersistence>,
|
|
151
154
|
services: Effect.Effect<
|
|
152
155
|
{ readonly passwordPreparedPersistence: PasswordPreparedPersistence },
|
|
153
|
-
|
|
154
|
-
|
|
156
|
+
E,
|
|
157
|
+
R
|
|
155
158
|
>,
|
|
156
159
|
) =>
|
|
157
160
|
Layer.effect(
|
|
@@ -23,14 +23,9 @@ import {
|
|
|
23
23
|
type AnyPasswordRegistrationMapping,
|
|
24
24
|
requiredPasswordRegistrationConstraints,
|
|
25
25
|
} from "./password-model";
|
|
26
|
-
import {
|
|
27
|
-
CurrentPasswordSql,
|
|
28
|
-
type PasswordSqlDatabase,
|
|
29
|
-
type PasswordSqlQuery,
|
|
30
|
-
} from "./password-sql";
|
|
26
|
+
import { CurrentPasswordSql, type PasswordSqlQuery } from "./password-sql";
|
|
31
27
|
import { CurrentProofSql, type ProofSqlDatabase } from "./proof-sql";
|
|
32
28
|
|
|
33
|
-
type Database = PasswordSqlDatabase;
|
|
34
29
|
type Mapping<Registration> = AnyPasswordRegistrationMapping<Registration>;
|
|
35
30
|
const unavailable = () => PasswordUnavailable.make({});
|
|
36
31
|
|
|
@@ -219,10 +214,14 @@ const registerIn = Effect.fn("DrizzlePasswordRegistration.registerIn")(function*
|
|
|
219
214
|
export const makeSqlPasswordRegistrationAuthority = Effect.fn(
|
|
220
215
|
"makeSqlPasswordRegistrationAuthority",
|
|
221
216
|
)(function* <Registration>(
|
|
222
|
-
database: Database,
|
|
223
217
|
mapping: Mapping<Registration>,
|
|
224
218
|
configuration: PasswordRegistrationConfiguration,
|
|
225
|
-
): Effect.fn.Return<
|
|
219
|
+
): Effect.fn.Return<
|
|
220
|
+
PasswordRegistrationAuthority<Registration>,
|
|
221
|
+
never,
|
|
222
|
+
LifecycleHooks | CurrentPasswordSql
|
|
223
|
+
> {
|
|
224
|
+
const database = yield* CurrentPasswordSql;
|
|
226
225
|
const hooks = yield* LifecycleHooks;
|
|
227
226
|
|
|
228
227
|
return {
|
|
@@ -15,13 +15,14 @@ import {
|
|
|
15
15
|
type PasswordRegistrationConfiguration,
|
|
16
16
|
} from "./password-registration";
|
|
17
17
|
import {
|
|
18
|
+
CurrentPasswordSql,
|
|
18
19
|
makeSqlPasswordPersistence,
|
|
19
20
|
type PasswordSqlConfiguration,
|
|
20
21
|
type PasswordSqlDatabase,
|
|
21
22
|
type PasswordSqlQuery,
|
|
22
23
|
} from "./password-sql";
|
|
23
24
|
import type { ProofTargetConfiguration } from "./proof-target";
|
|
24
|
-
import { sqlClientStandaloneGuard } from "./standalone-guard";
|
|
25
|
+
import { sqlClientStandaloneGuard, type TransactionService } from "./standalone-guard";
|
|
25
26
|
|
|
26
27
|
export interface PasswordTargetConfiguration {
|
|
27
28
|
readonly mode: "interactive" | "synchronous";
|
|
@@ -50,9 +51,9 @@ export type PasswordCoordinatorError<E> =
|
|
|
50
51
|
| SqlError.SqlError;
|
|
51
52
|
|
|
52
53
|
export const sqlClientPasswordStandaloneGuard = (
|
|
53
|
-
|
|
54
|
+
service: TransactionService | undefined,
|
|
54
55
|
): Effect.Effect<void, PasswordUnavailable> =>
|
|
55
|
-
sqlClientStandaloneGuard(
|
|
56
|
+
sqlClientStandaloneGuard(service, () => PasswordUnavailable.make({}));
|
|
56
57
|
|
|
57
58
|
export const passwordOptions = (
|
|
58
59
|
configuration: PasswordTargetConfiguration,
|
|
@@ -96,7 +97,6 @@ const registrationOptions = (
|
|
|
96
97
|
});
|
|
97
98
|
|
|
98
99
|
export const makeTargetPasswordPersistenceServices = (
|
|
99
|
-
database: any,
|
|
100
100
|
mapping: any,
|
|
101
101
|
configuration: PasswordTargetConfiguration,
|
|
102
102
|
proofMapping?: any,
|
|
@@ -104,7 +104,6 @@ export const makeTargetPasswordPersistenceServices = (
|
|
|
104
104
|
Effect.gen(function* () {
|
|
105
105
|
return {
|
|
106
106
|
passwordPersistence: yield* makeSqlPasswordPersistence(
|
|
107
|
-
database,
|
|
108
107
|
mapping,
|
|
109
108
|
passwordOptions(configuration, proofMapping),
|
|
110
109
|
),
|
|
@@ -112,14 +111,12 @@ export const makeTargetPasswordPersistenceServices = (
|
|
|
112
111
|
});
|
|
113
112
|
|
|
114
113
|
export const makeTargetPasswordRegistrationServices = <Registration>(
|
|
115
|
-
database: any,
|
|
116
114
|
mapping: any,
|
|
117
115
|
configuration: PasswordTargetConfiguration,
|
|
118
116
|
) =>
|
|
119
117
|
Effect.gen(function* () {
|
|
120
118
|
return {
|
|
121
119
|
registrationAuthority: yield* makeSqlPasswordRegistrationAuthority<Registration>(
|
|
122
|
-
database,
|
|
123
120
|
mapping,
|
|
124
121
|
registrationOptions(configuration),
|
|
125
122
|
),
|
|
@@ -149,9 +146,13 @@ export const coordinateTargetPasswordPersistence = <Transaction, A, E, R>(
|
|
|
149
146
|
Effect.gen(function* () {
|
|
150
147
|
return yield* owner(transaction, {
|
|
151
148
|
passwordPersistence: yield* makeSqlPasswordPersistence(
|
|
152
|
-
transaction as unknown as PasswordSqlDatabase,
|
|
153
149
|
mapping,
|
|
154
150
|
passwordOptions(configuration, proofMapping, true),
|
|
151
|
+
).pipe(
|
|
152
|
+
Effect.provideService(
|
|
153
|
+
CurrentPasswordSql,
|
|
154
|
+
transaction as unknown as PasswordSqlDatabase,
|
|
155
|
+
),
|
|
155
156
|
),
|
|
156
157
|
});
|
|
157
158
|
}),
|
|
@@ -185,9 +186,13 @@ export const coordinateTargetPasswordRegistration = <Registration, Transaction,
|
|
|
185
186
|
Effect.gen(function* () {
|
|
186
187
|
return yield* owner(transaction, {
|
|
187
188
|
registrationAuthority: yield* makeSqlPasswordRegistrationAuthority<Registration>(
|
|
188
|
-
transaction as unknown as PasswordSqlDatabase,
|
|
189
189
|
mapping,
|
|
190
190
|
registrationOptions(configuration, true),
|
|
191
|
+
).pipe(
|
|
192
|
+
Effect.provideService(
|
|
193
|
+
CurrentPasswordSql,
|
|
194
|
+
transaction as unknown as PasswordSqlDatabase,
|
|
195
|
+
),
|
|
191
196
|
),
|
|
192
197
|
});
|
|
193
198
|
}),
|
|
@@ -198,24 +203,20 @@ export const coordinateTargetPasswordRegistration = <Registration, Transaction,
|
|
|
198
203
|
return result.value;
|
|
199
204
|
});
|
|
200
205
|
|
|
201
|
-
export const passwordPersistenceLayer = (
|
|
202
|
-
services: Effect.Effect<
|
|
203
|
-
{ readonly passwordPersistence: PasswordPersistence["Service"] },
|
|
204
|
-
never,
|
|
205
|
-
LifecycleHooks
|
|
206
|
-
>,
|
|
206
|
+
export const passwordPersistenceLayer = <E, R>(
|
|
207
|
+
services: Effect.Effect<{ readonly passwordPersistence: PasswordPersistence["Service"] }, E, R>,
|
|
207
208
|
) =>
|
|
208
209
|
Layer.effect(
|
|
209
210
|
PasswordPersistence,
|
|
210
211
|
Effect.map(services, (value) => value.passwordPersistence),
|
|
211
212
|
);
|
|
212
213
|
|
|
213
|
-
export const passwordRegistrationLayer = <Id, Registration>(
|
|
214
|
+
export const passwordRegistrationLayer = <Id, Registration, E, R>(
|
|
214
215
|
tag: Context.Key<Id, PasswordRegistrationAuthority<Registration>>,
|
|
215
216
|
services: Effect.Effect<
|
|
216
217
|
{ readonly registrationAuthority: PasswordRegistrationAuthority<Registration> },
|
|
217
|
-
|
|
218
|
-
|
|
218
|
+
E,
|
|
219
|
+
R
|
|
219
220
|
>,
|
|
220
221
|
) =>
|
|
221
222
|
Layer.effect(
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AnyRelations } from "drizzle-orm";
|
|
2
|
+
import type { EffectPgDatabase as PgliteDatabase } from "drizzle-orm/effect-pglite";
|
|
3
|
+
import type { EffectPgDatabase as PostgresDatabase } from "drizzle-orm/effect-postgres";
|
|
4
|
+
import { Context } from "effect";
|
|
5
|
+
|
|
6
|
+
/** Application-owned PostgreSQL database; Postgres and Pglite share this service. */
|
|
7
|
+
export class Database extends Context.Service<
|
|
8
|
+
Database,
|
|
9
|
+
PostgresDatabase<AnyRelations> | PgliteDatabase<AnyRelations>
|
|
10
|
+
>()("effect-auth/persistence-drizzle/Postgres/Database") {}
|
package/src/drizzle/pg-emails.ts
CHANGED
|
@@ -14,6 +14,7 @@ import type {
|
|
|
14
14
|
EmailSignInMapping,
|
|
15
15
|
} from "./email-model";
|
|
16
16
|
import type { EmailRegistrationAuthority } from "./email-registration";
|
|
17
|
+
import { CurrentEmailSql } from "./email-sql";
|
|
17
18
|
import type { EmailSqlQuery } from "./email-sql";
|
|
18
19
|
import {
|
|
19
20
|
coordinateTargetEmailAddress,
|
|
@@ -23,9 +24,16 @@ import {
|
|
|
23
24
|
makeTargetEmailSignInServices,
|
|
24
25
|
sqlClientEmailStandaloneGuard,
|
|
25
26
|
} from "./email-target";
|
|
27
|
+
import { nativeDatabase } from "./native-database";
|
|
28
|
+
import { Database as DatabaseService } from "./pg-database";
|
|
26
29
|
import type { ProofPersistenceMapping } from "./proof-model";
|
|
27
30
|
import type { ProofSqlQuery } from "./proof-sql";
|
|
28
31
|
import { sqlClientProofStandaloneGuard } from "./proof-target";
|
|
32
|
+
import {
|
|
33
|
+
type TransactionService,
|
|
34
|
+
acquireTransactionService,
|
|
35
|
+
transactionService,
|
|
36
|
+
} from "./standalone-guard";
|
|
29
37
|
import type { SuppliedService } from "./SuppliedService";
|
|
30
38
|
|
|
31
39
|
type Database = PostgresDatabase<AnyRelations> | PgliteDatabase<AnyRelations>;
|
|
@@ -45,15 +53,15 @@ type ProofMapping = ProofPersistenceMapping<
|
|
|
45
53
|
any
|
|
46
54
|
>;
|
|
47
55
|
|
|
48
|
-
const configuration = (
|
|
56
|
+
const configuration = (service: TransactionService | undefined) => ({
|
|
49
57
|
mode: "interactive" as const,
|
|
50
58
|
locking: true,
|
|
51
|
-
standaloneGuard: sqlClientEmailStandaloneGuard(
|
|
59
|
+
standaloneGuard: sqlClientEmailStandaloneGuard(service),
|
|
52
60
|
generatedSubjectRows: (query: EmailSqlQuery) => query.returning(),
|
|
53
61
|
proof: {
|
|
54
62
|
mode: "interactive" as const,
|
|
55
63
|
locking: true,
|
|
56
|
-
standaloneGuard: sqlClientProofStandaloneGuard(
|
|
64
|
+
standaloneGuard: sqlClientProofStandaloneGuard(service),
|
|
57
65
|
insertIfAbsent: (query: ProofSqlQuery) => query.onConflictDoNothing(),
|
|
58
66
|
},
|
|
59
67
|
});
|
|
@@ -64,9 +72,12 @@ export const makePgEmailSignInServices = <
|
|
|
64
72
|
C extends AnyPgTable,
|
|
65
73
|
NativeId,
|
|
66
74
|
>(
|
|
67
|
-
database: Database,
|
|
68
75
|
mapping: EmailSignInMapping<S, I, C, NativeId>,
|
|
69
|
-
) =>
|
|
76
|
+
) =>
|
|
77
|
+
Effect.flatMap(
|
|
78
|
+
Effect.map(acquireTransactionService(DatabaseService), configuration),
|
|
79
|
+
(configuration) => makeTargetEmailSignInServices(mapping, configuration),
|
|
80
|
+
).pipe(Effect.provideServiceEffect(CurrentEmailSql, nativeDatabase(DatabaseService)));
|
|
70
81
|
|
|
71
82
|
export const makePgEmailAddressServices = <
|
|
72
83
|
S extends AnyPgTable,
|
|
@@ -76,10 +87,13 @@ export const makePgEmailAddressServices = <
|
|
|
76
87
|
M extends AnyPgTable,
|
|
77
88
|
NativeId,
|
|
78
89
|
>(
|
|
79
|
-
database: Database,
|
|
80
90
|
mapping: EmailAddressMapping<S, I, C, AC, M, NativeId>,
|
|
81
91
|
proofMapping: ProofMapping,
|
|
82
|
-
) =>
|
|
92
|
+
) =>
|
|
93
|
+
Effect.flatMap(
|
|
94
|
+
Effect.map(acquireTransactionService(DatabaseService), configuration),
|
|
95
|
+
(configuration) => makeTargetEmailAddressServices(mapping, proofMapping, configuration),
|
|
96
|
+
).pipe(Effect.provideServiceEffect(CurrentEmailSql, nativeDatabase(DatabaseService)));
|
|
83
97
|
|
|
84
98
|
export function coordinatePgEmailAddress<
|
|
85
99
|
D extends Database,
|
|
@@ -170,7 +184,7 @@ export function coordinatePgEmailAddress<
|
|
|
170
184
|
database,
|
|
171
185
|
options.mapping,
|
|
172
186
|
options.proofMapping,
|
|
173
|
-
configuration(database),
|
|
187
|
+
configuration(transactionService(database)),
|
|
174
188
|
(
|
|
175
189
|
transaction: TransactionOf<D>,
|
|
176
190
|
services: { readonly emailAddressPersistence: EmailAddressPersistence["Service"] },
|
|
@@ -195,16 +209,14 @@ export const makePgEmailRegistrationServices = <
|
|
|
195
209
|
Rq extends AnyPgTable,
|
|
196
210
|
NativeId,
|
|
197
211
|
>(
|
|
198
|
-
database: Database,
|
|
199
212
|
mapping: EmailRegistrationMapping<Registration, S, I, C, AC, Rq, NativeId>,
|
|
200
213
|
proofMapping: ProofMapping,
|
|
201
214
|
) =>
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
);
|
|
215
|
+
Effect.flatMap(
|
|
216
|
+
Effect.map(acquireTransactionService(DatabaseService), configuration),
|
|
217
|
+
(configuration) =>
|
|
218
|
+
makeTargetEmailRegistrationServices<Registration>(mapping, proofMapping, configuration),
|
|
219
|
+
).pipe(Effect.provideServiceEffect(CurrentEmailSql, nativeDatabase(DatabaseService)));
|
|
208
220
|
|
|
209
221
|
export function coordinatePgEmailRegistration<
|
|
210
222
|
TargetId,
|
|
@@ -304,7 +316,7 @@ export function coordinatePgEmailRegistration<
|
|
|
304
316
|
database,
|
|
305
317
|
options.mapping,
|
|
306
318
|
options.proofMapping,
|
|
307
|
-
configuration(database),
|
|
319
|
+
configuration(transactionService(database)),
|
|
308
320
|
(
|
|
309
321
|
transaction: TransactionOf<D>,
|
|
310
322
|
services: { readonly registrationAuthority: EmailRegistrationAuthority<Registration> },
|
|
@@ -10,8 +10,7 @@ import {
|
|
|
10
10
|
import { reportPersistenceFailure } from "@yielded/auth/Persistence";
|
|
11
11
|
import type { SubjectId } from "@yielded/auth/Schema";
|
|
12
12
|
/* oxlint-disable no-explicit-any -- Drizzle's generic query builders lose the concrete consumer table through a runtime column map. Assertions stay in this adapter. */
|
|
13
|
-
import { and, eq
|
|
14
|
-
import type { EffectPgDatabase as PgliteDatabase } from "drizzle-orm/effect-pglite";
|
|
13
|
+
import { and, eq } from "drizzle-orm";
|
|
15
14
|
import type { EffectPgDatabase as PgDatabase } from "drizzle-orm/effect-postgres";
|
|
16
15
|
import { type AnyPgTable, type PgColumn } from "drizzle-orm/pg-core";
|
|
17
16
|
import { Cause, Effect, Schema } from "effect";
|
|
@@ -25,8 +24,8 @@ import {
|
|
|
25
24
|
type IdentityTables,
|
|
26
25
|
type SubjectProvisioningTables,
|
|
27
26
|
} from "./model";
|
|
27
|
+
import { Database as DatabaseService } from "./pg-database";
|
|
28
28
|
|
|
29
|
-
type Database = PgDatabase<AnyRelations> | PgliteDatabase<AnyRelations>;
|
|
30
29
|
type RuntimeDatabase = PgDatabase<any>;
|
|
31
30
|
|
|
32
31
|
const identityUnavailable = () => IdentityUnavailable.make();
|
|
@@ -41,15 +40,14 @@ const mapIdentityFailure = <A, E, R>(effect: Effect.Effect<A, E, R>) =>
|
|
|
41
40
|
),
|
|
42
41
|
);
|
|
43
42
|
|
|
44
|
-
export const makePgSubjectProvisioningServices = <
|
|
43
|
+
export const makePgSubjectProvisioningServices = Effect.fnUntraced(function* <
|
|
45
44
|
Subject extends AnyPgTable,
|
|
46
45
|
Identifier extends AnyPgTable,
|
|
47
46
|
Request extends AnyPgTable,
|
|
48
47
|
NativeId,
|
|
49
|
-
>(
|
|
50
|
-
database
|
|
51
|
-
|
|
52
|
-
) => {
|
|
48
|
+
>(mapping: SubjectProvisioningTables<Subject, Identifier, Request, NativeId>) {
|
|
49
|
+
const database = yield* DatabaseService;
|
|
50
|
+
|
|
53
51
|
const db = database as RuntimeDatabase;
|
|
54
52
|
const requestTable = mapping.provisioningRequest.table;
|
|
55
53
|
const requestIdColumn = column(requestTable, mapping.provisioningRequest.requestId);
|
|
@@ -174,16 +172,15 @@ export const makePgSubjectProvisioningServices = <
|
|
|
174
172
|
return {
|
|
175
173
|
subjectProvisioner: SubjectProvisioner.of({ provision }),
|
|
176
174
|
} as const;
|
|
177
|
-
};
|
|
175
|
+
});
|
|
178
176
|
|
|
179
|
-
export const makePgExternalIdentityServices = <
|
|
177
|
+
export const makePgExternalIdentityServices = Effect.fnUntraced(function* <
|
|
180
178
|
Subject extends AnyPgTable,
|
|
181
179
|
External extends AnyPgTable,
|
|
182
180
|
NativeId,
|
|
183
|
-
>(
|
|
184
|
-
database
|
|
185
|
-
|
|
186
|
-
) => {
|
|
181
|
+
>(mapping: ExternalIdentityTables<Subject, External, NativeId>) {
|
|
182
|
+
const database = yield* DatabaseService;
|
|
183
|
+
|
|
187
184
|
const db = database as RuntimeDatabase;
|
|
188
185
|
const externalTable = mapping.externalIdentity.table;
|
|
189
186
|
|
|
@@ -284,18 +281,17 @@ export const makePgExternalIdentityServices = <
|
|
|
284
281
|
}, mapIdentityFailure);
|
|
285
282
|
|
|
286
283
|
return { externalIdentityMutation: ExternalIdentityMutation.of({ bind }) } as const;
|
|
287
|
-
};
|
|
284
|
+
});
|
|
288
285
|
|
|
289
|
-
export const makePgIdentityServices = <
|
|
286
|
+
export const makePgIdentityServices = Effect.fnUntraced(function* <
|
|
290
287
|
Subject extends AnyPgTable,
|
|
291
288
|
Identifier extends AnyPgTable,
|
|
292
289
|
External extends AnyPgTable,
|
|
293
290
|
Request extends AnyPgTable,
|
|
294
291
|
NativeId,
|
|
295
|
-
>(
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
...makePgExternalIdentityServices(database, mapping),
|
|
292
|
+
>(mapping: IdentityTables<Subject, Identifier, External, Request, NativeId>) {
|
|
293
|
+
return {
|
|
294
|
+
...(yield* makePgSubjectProvisioningServices(mapping)),
|
|
295
|
+
...(yield* makePgExternalIdentityServices(mapping)),
|
|
296
|
+
};
|
|
301
297
|
});
|
|
@@ -7,6 +7,7 @@ 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";
|
|
10
11
|
import type {
|
|
11
12
|
PasswordPreparedPersistenceMapping,
|
|
12
13
|
PasswordPreparedProofMapping,
|
|
@@ -15,7 +16,10 @@ import {
|
|
|
15
16
|
makeTargetPasswordPreparedPersistenceServices,
|
|
16
17
|
coordinateTargetPasswordPreparedPersistence,
|
|
17
18
|
} from "./password-prepared-target";
|
|
19
|
+
import { CurrentPasswordSql } from "./password-sql";
|
|
20
|
+
import { Database as DatabaseService } from "./pg-database";
|
|
18
21
|
import { pgPasswordConfiguration as configuration } from "./pg-passwords";
|
|
22
|
+
import { acquireTransactionService, transactionService } from "./standalone-guard";
|
|
19
23
|
import type { SuppliedService } from "./SuppliedService";
|
|
20
24
|
type Database = PostgresDatabase<AnyRelations> | PgliteDatabase<AnyRelations>;
|
|
21
25
|
type TransactionOf<D extends Database> = Parameters<Parameters<D["transaction"]>[0]>[0];
|
|
@@ -40,16 +44,14 @@ export const makePgPasswordPreparedPersistenceServices = <
|
|
|
40
44
|
PCr extends AnyPgTable = AnyPgTable,
|
|
41
45
|
PNativeId = unknown,
|
|
42
46
|
>(
|
|
43
|
-
database: Database,
|
|
44
47
|
mapping: PasswordPreparedPersistenceMapping<S, I, C, AC, A, RS, CE, M, T, B, NativeId>,
|
|
45
48
|
proofMapping?: PasswordPreparedProofMapping<PS, PC, PM, PSub, PI, PCr, PNativeId>,
|
|
46
49
|
) =>
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
);
|
|
50
|
+
Effect.flatMap(
|
|
51
|
+
Effect.map(acquireTransactionService(DatabaseService), configuration),
|
|
52
|
+
(configuration) =>
|
|
53
|
+
makeTargetPasswordPreparedPersistenceServices(mapping, configuration, proofMapping),
|
|
54
|
+
).pipe(Effect.provideServiceEffect(CurrentPasswordSql, nativeDatabase(DatabaseService)));
|
|
53
55
|
|
|
54
56
|
export function coordinatePgPasswordPreparedPersistence<
|
|
55
57
|
TargetId,
|
|
@@ -187,7 +189,7 @@ export function coordinatePgPasswordPreparedPersistence<
|
|
|
187
189
|
coordinateTargetPasswordPreparedPersistence<TransactionOf<D>, Out, E, Exclude<R, TargetId>>(
|
|
188
190
|
database,
|
|
189
191
|
options.mapping,
|
|
190
|
-
configuration(database),
|
|
192
|
+
configuration(transactionService(database)),
|
|
191
193
|
options.proofMapping,
|
|
192
194
|
(
|
|
193
195
|
transaction: TransactionOf<D>,
|