@yielded/auth-persistence-drizzle 0.1.0-beta.1 → 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/dist/D1.d.mts +27 -22
- package/dist/D1.mjs +10 -4
- package/dist/D1.mjs.map +1 -1
- package/dist/Libsql.d.mts +66 -61
- 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 +43 -32
- 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 +58 -53
- package/dist/SqliteBun.mjs +20 -14
- package/dist/SqliteBun.mjs.map +1 -1
- package/dist/SqliteDo.d.mts +66 -60
- 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 +66 -61
- 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 +14 -13
- 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 +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 +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-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 +74 -76
- 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-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
|
@@ -2,12 +2,12 @@ import { requireStandalone } from "@yielded/auth-persistence/Adapter";
|
|
|
2
2
|
import { Context, Effect, Predicate } from "effect";
|
|
3
3
|
import type * as SqlClient from "effect/sql/SqlClient";
|
|
4
4
|
|
|
5
|
-
type TransactionService = Context.Key<
|
|
5
|
+
export type TransactionService = Context.Key<
|
|
6
6
|
SqlClient.TransactionConnection,
|
|
7
7
|
SqlClient.TransactionConnection.Service
|
|
8
8
|
>;
|
|
9
9
|
|
|
10
|
-
const transactionService = (database: unknown): TransactionService | undefined => {
|
|
10
|
+
export const transactionService = (database: unknown): TransactionService | undefined => {
|
|
11
11
|
if (
|
|
12
12
|
!Predicate.hasProperty(database, "$client") ||
|
|
13
13
|
!Predicate.hasProperty(database.$client, "transactionService") ||
|
|
@@ -19,14 +19,26 @@ const transactionService = (database: unknown): TransactionService | undefined =
|
|
|
19
19
|
return database.$client.transactionService;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
+
/** Capture the foreign client's marker while acquiring standalone services. */
|
|
23
|
+
export const acquireTransactionService = <Id, Database>(service: Context.Key<Id, Database>) =>
|
|
24
|
+
Effect.map(Effect.service(service), (database): TransactionService | undefined => {
|
|
25
|
+
if (
|
|
26
|
+
!Predicate.hasProperty(database, "$client") ||
|
|
27
|
+
!Predicate.hasProperty(database.$client, "transactionService") ||
|
|
28
|
+
!Context.isKey(database.$client.transactionService)
|
|
29
|
+
) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return database.$client.transactionService;
|
|
34
|
+
});
|
|
35
|
+
|
|
22
36
|
/** Bind the client-specific transaction marker at foreign adapter construction. */
|
|
23
37
|
export const sqlClientStandaloneGuard = <Failure>(
|
|
24
|
-
|
|
38
|
+
service: TransactionService | undefined,
|
|
25
39
|
unavailable: () => Failure,
|
|
26
40
|
): Effect.Effect<void, Failure> => {
|
|
27
|
-
const service = transactionService(database);
|
|
28
|
-
|
|
29
41
|
if (service === undefined) return Effect.suspend(() => Effect.fail(unavailable()));
|
|
30
42
|
|
|
31
|
-
return requireStandalone(unavailable,
|
|
43
|
+
return requireStandalone(unavailable, service);
|
|
32
44
|
};
|
|
@@ -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
|
TotpConfigurationError,
|
|
@@ -13,6 +14,7 @@ import { Context, Effect, Schema } from "effect";
|
|
|
13
14
|
import type { Statement } from "effect/sql/Statement";
|
|
14
15
|
|
|
15
16
|
import type { PersistenceMappingError } from "./model";
|
|
17
|
+
import { nativeDatabase } from "./native-database";
|
|
16
18
|
import type { SuppliedService } from "./SuppliedService";
|
|
17
19
|
import {
|
|
18
20
|
type TotpMapping,
|
|
@@ -44,8 +46,8 @@ export type TotpCoordinatorError<E> =
|
|
|
44
46
|
| PersistenceMappingError;
|
|
45
47
|
|
|
46
48
|
export const sqlClientTotpStandaloneGuard = (
|
|
47
|
-
|
|
48
|
-
) => sqlClientTransactionStandaloneGuard(unavailable,
|
|
49
|
+
service: Parameters<typeof sqlClientTransactionStandaloneGuard>[1],
|
|
50
|
+
) => sqlClientTransactionStandaloneGuard(unavailable, service);
|
|
49
51
|
|
|
50
52
|
const validateMapping = <M>(original: M, configuration: TotpTargetConfiguration): M => {
|
|
51
53
|
const mapping = original as any;
|
|
@@ -66,55 +68,58 @@ const validateMapping = <M>(original: M, configuration: TotpTargetConfiguration)
|
|
|
66
68
|
});
|
|
67
69
|
};
|
|
68
70
|
|
|
69
|
-
const services = (
|
|
71
|
+
const services = Effect.fnUntraced(function* (
|
|
70
72
|
mapping: any,
|
|
71
73
|
execution: TransactionExecution<TotpUnavailable, CurrentTotpTransaction>,
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
totpPersistence: TotpPersistence.of({
|
|
75
|
-
snapshot: Effect.fn("TotpNative.snapshot")(
|
|
76
|
-
function* (input) {
|
|
77
|
-
const captured = { ...input };
|
|
74
|
+
): Effect.fn.Return<TotpPersistenceServices, never, LifecycleHooks> {
|
|
75
|
+
const hooks = yield* LifecycleHooks;
|
|
78
76
|
|
|
79
|
-
|
|
80
|
-
|
|
77
|
+
return {
|
|
78
|
+
totpPersistence: TotpPersistence.of({
|
|
79
|
+
snapshot: Effect.fn("TotpNative.snapshot")(
|
|
80
|
+
function* (input) {
|
|
81
|
+
const captured = { ...input };
|
|
82
|
+
|
|
83
|
+
invariant(captured.moduleId === mapping.moduleId);
|
|
84
|
+
yield* execution.admit;
|
|
81
85
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
86
|
+
return yield* execution
|
|
87
|
+
.run(
|
|
88
|
+
Effect.map(captureTotp(mapping, captured.subjectId), (value) => value?.snapshot),
|
|
89
|
+
false,
|
|
90
|
+
)
|
|
91
|
+
.pipe(Effect.provideService(LifecycleHooks, hooks));
|
|
92
|
+
},
|
|
93
|
+
Effect.catchDefect(() => Effect.fail(unavailable())),
|
|
94
|
+
),
|
|
95
|
+
mutate: (original, prepare) =>
|
|
96
|
+
Effect.suspend(() => {
|
|
97
|
+
// Detach caller-owned payloads before any driver or hook can suspend.
|
|
98
|
+
const codec = Schema.toCodecIso(TotpMutation);
|
|
99
|
+
const input = Schema.decodeSync(codec)(Schema.encodeSync(codec)(original));
|
|
96
100
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
return execution.admit.pipe(
|
|
102
|
+
Effect.andThen(
|
|
103
|
+
execution.run(
|
|
104
|
+
Effect.gen(function* () {
|
|
105
|
+
const decision = yield* mutateTotp(mapping, input),
|
|
106
|
+
owner = yield* CurrentTotpTransaction;
|
|
103
107
|
|
|
104
|
-
|
|
105
|
-
|
|
108
|
+
owner.guards.push(owner.journal.prepare(undefined));
|
|
109
|
+
const receipt = prepare(decision, owner.journal);
|
|
106
110
|
|
|
107
|
-
|
|
108
|
-
|
|
111
|
+
invariant(receipt?._tag === "PreparedCommit" && Effect.isEffect(receipt.read));
|
|
112
|
+
owner.guards.push(receipt as any);
|
|
109
113
|
|
|
110
|
-
|
|
111
|
-
|
|
114
|
+
return receipt;
|
|
115
|
+
}),
|
|
116
|
+
),
|
|
112
117
|
),
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
)
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
+
Effect.provideService(LifecycleHooks, hooks),
|
|
119
|
+
);
|
|
120
|
+
}).pipe(Effect.catchDefect(() => Effect.fail(unavailable()))),
|
|
121
|
+
}),
|
|
122
|
+
};
|
|
118
123
|
});
|
|
119
124
|
|
|
120
125
|
export const makeTargetTotpPersistence = <
|
|
@@ -124,12 +129,10 @@ export const makeTargetTotpPersistence = <
|
|
|
124
129
|
N,
|
|
125
130
|
RSetup = never,
|
|
126
131
|
>(
|
|
127
|
-
database: TransactionNativeDatabase,
|
|
128
132
|
source: TotpMappingSource<TotpMapping<S, F, C, N>, RSetup>,
|
|
129
133
|
configuration: TotpTargetConfiguration,
|
|
130
134
|
) =>
|
|
131
135
|
Effect.gen(function* () {
|
|
132
|
-
const hooks = yield* LifecycleHooks;
|
|
133
136
|
const original = yield* Effect.isEffect(source) ? source : Effect.succeed(source);
|
|
134
137
|
|
|
135
138
|
const mapping = yield* Effect.try({
|
|
@@ -137,15 +140,14 @@ export const makeTargetTotpPersistence = <
|
|
|
137
140
|
catch: () => TotpConfigurationError.make({}),
|
|
138
141
|
});
|
|
139
142
|
|
|
140
|
-
const execution = makeTransactionExecution(
|
|
143
|
+
const execution = yield* makeTransactionExecution(
|
|
141
144
|
CurrentTotpTransaction,
|
|
142
|
-
database,
|
|
143
145
|
configuration,
|
|
144
146
|
unavailable,
|
|
145
147
|
randomId,
|
|
146
148
|
);
|
|
147
149
|
|
|
148
|
-
return services(mapping, execution
|
|
150
|
+
return yield* services(mapping, execution);
|
|
149
151
|
});
|
|
150
152
|
|
|
151
153
|
export const coordinateTargetTotp = <M, A, E, R, RSetup = never>(
|
|
@@ -159,7 +161,6 @@ export const coordinateTargetTotp = <M, A, E, R, RSetup = never>(
|
|
|
159
161
|
) => Effect.Effect<A, E, R>,
|
|
160
162
|
): Effect.Effect<A, TotpCoordinatorError<E>, R | RSetup | LifecycleHooks> =>
|
|
161
163
|
Effect.gen(function* () {
|
|
162
|
-
const hooks = yield* LifecycleHooks;
|
|
163
164
|
const original = yield* Effect.isEffect(source) ? source : Effect.succeed(source);
|
|
164
165
|
|
|
165
166
|
const mapping = yield* Effect.try({
|
|
@@ -174,8 +175,11 @@ export const coordinateTargetTotp = <M, A, E, R, RSetup = never>(
|
|
|
174
175
|
Effect.void,
|
|
175
176
|
unavailable,
|
|
176
177
|
randomId,
|
|
177
|
-
(execution) => services(mapping, execution
|
|
178
|
-
|
|
178
|
+
(execution) => services(mapping, execution),
|
|
179
|
+
(transaction, acquireServices, append) =>
|
|
180
|
+
Effect.flatMap(acquireServices, (boundServices) =>
|
|
181
|
+
body(transaction, boundServices, append),
|
|
182
|
+
),
|
|
179
183
|
);
|
|
180
184
|
});
|
|
181
185
|
|
|
@@ -185,11 +189,13 @@ type TransactionOf<D> = D extends { readonly transaction: (...args: any[]) => an
|
|
|
185
189
|
|
|
186
190
|
/** Concrete driver wrappers select transaction mode; cryptography always precedes these owners. */
|
|
187
191
|
export const makeTotpTarget = <
|
|
192
|
+
DatabaseId,
|
|
188
193
|
D extends { readonly transaction: any },
|
|
189
194
|
T extends Table,
|
|
190
195
|
Extra = unknown,
|
|
191
196
|
Synchronous extends boolean = false,
|
|
192
197
|
>(
|
|
198
|
+
databaseService: Context.Service<DatabaseId, D>,
|
|
193
199
|
configuration: TotpTargetConfiguration,
|
|
194
200
|
) => {
|
|
195
201
|
function coordinateTotpPersistence<
|
|
@@ -292,17 +298,12 @@ export const makeTotpTarget = <
|
|
|
292
298
|
}
|
|
293
299
|
|
|
294
300
|
return {
|
|
295
|
-
makeTotpPersistenceServices: <
|
|
296
|
-
Database extends D,
|
|
297
|
-
S extends T,
|
|
298
|
-
F extends T,
|
|
299
|
-
C extends T,
|
|
300
|
-
N,
|
|
301
|
-
RSetup = never,
|
|
302
|
-
>(
|
|
303
|
-
database: Database,
|
|
301
|
+
makeTotpPersistenceServices: <S extends T, F extends T, C extends T, N, RSetup = never>(
|
|
304
302
|
mapping: TotpMappingSource<TotpMapping<S, F, C, N> & Extra, RSetup>,
|
|
305
|
-
) =>
|
|
303
|
+
) =>
|
|
304
|
+
makeTargetTotpPersistence(mapping, configuration).pipe(
|
|
305
|
+
Effect.provideServiceEffect(NativeDatabase, nativeDatabase(databaseService)),
|
|
306
|
+
),
|
|
306
307
|
coordinateTotpPersistence,
|
|
307
308
|
};
|
|
308
309
|
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { D1ExternalIdentityMapping, D1SubjectProvisioningMapping } from "./model.mjs";
|
|
2
|
-
import { ExternalIdentity, IdentityConflict, IdentityUnavailable, SubjectProvisioningInput } from "@yielded/auth/Identity";
|
|
3
|
-
import { AnyRelations } from "drizzle-orm";
|
|
4
|
-
import { Effect } from "effect";
|
|
5
|
-
import { SubjectId } from "@yielded/auth/Schema";
|
|
6
|
-
import { AnySQLiteTable } from "drizzle-orm/sqlite-core";
|
|
7
|
-
import { D1Client } from "@effect/sql-d1/D1Client";
|
|
8
|
-
import { EffectSQLiteD1Database } from "drizzle-orm/effect-d1";
|
|
9
|
-
//#region src/drizzle/d1-identity.d.ts
|
|
10
|
-
/**
|
|
11
|
-
* D1 provisioning is an ordered atomic batch. The receipt captures the
|
|
12
|
-
* database-generated subject id from the first insert via last_insert_rowid;
|
|
13
|
-
* the optional identifier then reads that stable id from the receipt.
|
|
14
|
-
*/
|
|
15
|
-
export declare const makeD1SubjectProvisioningServices: <Subject extends AnySQLiteTable, Identifier extends AnySQLiteTable, Request extends AnySQLiteTable, NativeId>(database: EffectSQLiteD1Database<AnyRelations> & {
|
|
16
|
-
readonly $client: D1Client;
|
|
17
|
-
}, mapping: D1SubjectProvisioningMapping<Subject, Identifier, Request, NativeId>) => {
|
|
18
|
-
readonly subjectProvisioner: {
|
|
19
|
-
readonly provision: (input: SubjectProvisioningInput) => Effect.Effect<import("@yielded/auth/Identity").ProvisioningResult, IdentityConflict | IdentityUnavailable>;
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
export declare const makeD1ExternalIdentityServices: <Subject extends AnySQLiteTable, External extends AnySQLiteTable, NativeId>(database: EffectSQLiteD1Database<AnyRelations> & {
|
|
23
|
-
readonly $client: D1Client;
|
|
24
|
-
}, mapping: D1ExternalIdentityMapping<Subject, External, NativeId>) => {
|
|
25
|
-
readonly externalIdentityMutation: {
|
|
26
|
-
readonly bind: (subjectId: SubjectId, identity: ExternalIdentity) => Effect.Effect<void, IdentityConflict | IdentityUnavailable>;
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
//#endregion
|
|
30
|
-
//# sourceMappingURL=d1-identity.d.mts.map
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ExternalIdentityTables, SubjectProvisioningTables } from "./model.mjs";
|
|
2
|
-
import { ExternalIdentity, IdentityConflict, IdentityUnavailable, SubjectProvisioningInput } from "@yielded/auth/Identity";
|
|
3
|
-
import { AnyRelations } from "drizzle-orm";
|
|
4
|
-
import { Effect } from "effect";
|
|
5
|
-
import { SubjectId } from "@yielded/auth/Schema";
|
|
6
|
-
import { EffectMysql2Database } from "drizzle-orm/effect-mysql2";
|
|
7
|
-
import { AnyMySqlTable } from "drizzle-orm/mysql-core";
|
|
8
|
-
//#region src/drizzle/mysql-identity.d.ts
|
|
9
|
-
type Database = EffectMysql2Database<AnyRelations>;
|
|
10
|
-
export declare const makeMysqlSubjectProvisioningServices: <Subject extends AnyMySqlTable, Identifier extends AnyMySqlTable, Request extends AnyMySqlTable, NativeId>(database: Database, mapping: SubjectProvisioningTables<Subject, Identifier, Request, NativeId>) => {
|
|
11
|
-
readonly subjectProvisioner: {
|
|
12
|
-
readonly provision: (input: SubjectProvisioningInput) => Effect.Effect<import("@yielded/auth/Identity").ProvisioningResult, IdentityConflict | IdentityUnavailable>;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
export declare const makeMysqlExternalIdentityServices: <Subject extends AnyMySqlTable, External extends AnyMySqlTable, NativeId>(database: Database, mapping: ExternalIdentityTables<Subject, External, NativeId>) => {
|
|
16
|
-
readonly externalIdentityMutation: {
|
|
17
|
-
readonly bind: (subjectId: SubjectId, identity: ExternalIdentity) => Effect.Effect<void, IdentityConflict | IdentityUnavailable>;
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
//#endregion
|
|
21
|
-
//# sourceMappingURL=mysql-identity.d.mts.map
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { ExternalIdentityTables, SubjectProvisioningTables } from "./model.mjs";
|
|
2
|
-
import { ExternalIdentity, IdentityConflict, IdentityUnavailable, SubjectProvisioningInput } from "@yielded/auth/Identity";
|
|
3
|
-
import { AnyRelations } from "drizzle-orm";
|
|
4
|
-
import { Effect } from "effect";
|
|
5
|
-
import { SubjectId } from "@yielded/auth/Schema";
|
|
6
|
-
import { EffectPgDatabase } from "drizzle-orm/effect-pglite";
|
|
7
|
-
import { AnyPgTable } from "drizzle-orm/pg-core";
|
|
8
|
-
import { EffectPgDatabase as EffectPgDatabase$1 } from "drizzle-orm/effect-postgres";
|
|
9
|
-
//#region src/drizzle/pg-identity.d.ts
|
|
10
|
-
type Database = EffectPgDatabase$1<AnyRelations> | EffectPgDatabase<AnyRelations>;
|
|
11
|
-
export declare const makePgSubjectProvisioningServices: <Subject extends AnyPgTable, Identifier extends AnyPgTable, Request extends AnyPgTable, NativeId>(database: Database, mapping: SubjectProvisioningTables<Subject, Identifier, Request, NativeId>) => {
|
|
12
|
-
readonly subjectProvisioner: {
|
|
13
|
-
readonly provision: (input: SubjectProvisioningInput) => Effect.Effect<import("@yielded/auth/Identity").ProvisioningResult, IdentityConflict | IdentityUnavailable>;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
export declare const makePgExternalIdentityServices: <Subject extends AnyPgTable, External extends AnyPgTable, NativeId>(database: Database, mapping: ExternalIdentityTables<Subject, External, NativeId>) => {
|
|
17
|
-
readonly externalIdentityMutation: {
|
|
18
|
-
readonly bind: (subjectId: SubjectId, identity: ExternalIdentity) => Effect.Effect<void, IdentityConflict | IdentityUnavailable>;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
//#endregion
|
|
22
|
-
//# sourceMappingURL=pg-identity.d.mts.map
|