@yielded/auth-persistence-drizzle 0.1.0-beta.22 → 0.1.0-beta.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/D1.d.mts +11 -11
- package/dist/D1.mjs +2 -1
- package/dist/D1.mjs.map +1 -1
- package/dist/Libsql.d.mts +40 -56
- package/dist/Libsql.mjs +2 -1
- package/dist/Libsql.mjs.map +1 -1
- package/dist/Mysql2.d.mts +16 -17
- package/dist/Pglite.d.mts +18 -18
- package/dist/Pglite.mjs +2 -1
- package/dist/Pglite.mjs.map +1 -1
- package/dist/Postgres.d.mts +24 -24
- package/dist/Postgres.mjs +2 -1
- package/dist/Postgres.mjs.map +1 -1
- package/dist/SqliteBun.d.mts +39 -55
- package/dist/SqliteBun.mjs +2 -1
- package/dist/SqliteBun.mjs.map +1 -1
- package/dist/SqliteDo.d.mts +48 -64
- package/dist/SqliteDo.mjs +2 -1
- package/dist/SqliteDo.mjs.map +1 -1
- package/dist/SqliteNode.d.mts +45 -61
- package/dist/SqliteNode.mjs +2 -1
- package/dist/SqliteNode.mjs.map +1 -1
- package/dist/SqliteWasm.d.mts +48 -64
- package/dist/SqliteWasm.mjs +2 -1
- package/dist/SqliteWasm.mjs.map +1 -1
- package/dist/drizzle/crypto.mjs +1 -1
- package/dist/drizzle/d1-emails.d.mts +1 -1
- package/dist/drizzle/d1-oauth.d.mts +14 -14
- package/dist/drizzle/d1-passkey.d.mts +1 -1
- package/dist/drizzle/d1-password-prepared.d.mts +4 -4
- package/dist/drizzle/d1-password-prepared.mjs.map +1 -1
- package/dist/drizzle/d1-passwords.d.mts +18 -35
- package/dist/drizzle/d1-passwords.mjs +78 -290
- package/dist/drizzle/d1-passwords.mjs.map +1 -1
- package/dist/drizzle/d1-phone.d.mts +1 -1
- package/dist/drizzle/d1-proofs.d.mts +2 -2
- package/dist/drizzle/d1-sessions.d.mts +3 -3
- package/dist/drizzle/d1-sessions.mjs +11 -6
- package/dist/drizzle/d1-sessions.mjs.map +1 -1
- package/dist/drizzle/d1-totp.d.mts +1 -1
- package/dist/drizzle/mysql-password-prepared.d.mts +5 -5
- package/dist/drizzle/mysql-password-prepared.mjs.map +1 -1
- package/dist/drizzle/mysql-passwords.d.mts +16 -32
- package/dist/drizzle/mysql-passwords.mjs.map +1 -1
- package/dist/drizzle/mysql-sessions.d.mts +1 -1
- package/dist/drizzle/native-sql-table.mjs +135 -0
- package/dist/drizzle/native-sql-table.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-model.d.mts +20 -281
- package/dist/drizzle/oauth-connected-model.mjs +3 -17
- package/dist/drizzle/oauth-connected-model.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-reference.d.mts +1 -3
- package/dist/drizzle/oauth-connected-reference.mjs +4 -53
- package/dist/drizzle/oauth-connected-reference.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-target.d.mts +3 -990
- package/dist/drizzle/oauth-connected-target.mjs +8 -92
- package/dist/drizzle/oauth-connected-target.mjs.map +1 -1
- package/dist/drizzle/oauth-kernel.mjs +11 -0
- package/dist/drizzle/oauth-kernel.mjs.map +1 -0
- package/dist/drizzle/oauth-model.d.mts +35 -438
- package/dist/drizzle/oauth-model.mjs +6 -44
- package/dist/drizzle/oauth-model.mjs.map +1 -1
- package/dist/drizzle/oauth-mysql.mjs +2 -2
- package/dist/drizzle/oauth-mysql.mjs.map +1 -1
- package/dist/drizzle/oauth-proxy.d.mts +10 -0
- package/dist/drizzle/oauth-proxy.mjs +54 -0
- package/dist/drizzle/oauth-proxy.mjs.map +1 -0
- package/dist/drizzle/oauth-target.d.mts +6 -107
- package/dist/drizzle/oauth-target.mjs +15 -245
- package/dist/drizzle/oauth-target.mjs.map +1 -1
- package/dist/drizzle/password-model.d.mts +5 -8
- package/dist/drizzle/password-prepared-model.d.mts +5 -5
- package/dist/drizzle/password-prepared-model.mjs.map +1 -1
- package/dist/drizzle/password-prepared-state.mjs +1 -1
- package/dist/drizzle/password-sql.mjs +2 -1
- package/dist/drizzle/password-sql.mjs.map +1 -1
- package/dist/drizzle/password-target.mjs +13 -2
- package/dist/drizzle/password-target.mjs.map +1 -1
- package/dist/drizzle/pg-password-prepared.d.mts +5 -5
- package/dist/drizzle/pg-password-prepared.mjs.map +1 -1
- package/dist/drizzle/pg-passwords.d.mts +16 -32
- package/dist/drizzle/pg-passwords.mjs.map +1 -1
- package/dist/drizzle/pg-sessions.d.mts +1 -1
- package/dist/drizzle/phone-target.d.mts +2 -2
- package/dist/drizzle/phone-target.mjs +1 -1
- package/dist/drizzle/query-operations.mjs +3 -1
- package/dist/drizzle/query-operations.mjs.map +1 -1
- package/dist/drizzle/session-sql.mjs +2 -1
- package/dist/drizzle/session-sql.mjs.map +1 -1
- package/dist/drizzle/sqlite-password-prepared.mjs.map +1 -1
- package/dist/drizzle/sqlite-passwords.mjs.map +1 -1
- package/dist/drizzle/storage-validation.mjs +10 -198
- package/dist/drizzle/storage-validation.mjs.map +1 -1
- package/dist/drizzle/totp-target.d.mts +3 -3
- package/dist/drizzle/totp-target.mjs +2 -2
- package/dist/drizzle/transaction-execution.d.mts +2 -2
- package/dist/drizzle/transaction-owner.d.mts +1 -2
- package/dist/index.d.mts +3 -2
- package/dist/internal/drizzle-postgres-oauth-proxy.d.mts +138 -0
- package/dist/internal/drizzle-postgres-oauth-proxy.mjs +29 -0
- package/dist/internal/drizzle-postgres-oauth-proxy.mjs.map +1 -0
- package/dist/internal/drizzle-postgres.mjs +2 -0
- package/dist/internal/drizzle-postgres.mjs.map +1 -1
- package/dist/internal/drizzle-sqlite-oauth-proxy.d.mts +146 -0
- package/dist/internal/drizzle-sqlite-oauth-proxy.mjs +29 -0
- package/dist/internal/drizzle-sqlite-oauth-proxy.mjs.map +1 -0
- package/dist/internal/drizzle-sqlite.mjs +2 -0
- package/dist/internal/drizzle-sqlite.mjs.map +1 -1
- package/package.json +1 -1
- package/src/D1.ts +2 -0
- package/src/Libsql.ts +2 -0
- package/src/Pglite.ts +2 -0
- package/src/Postgres.ts +2 -0
- package/src/SqliteBun.ts +2 -0
- package/src/SqliteDo.ts +2 -0
- package/src/SqliteNode.ts +2 -0
- package/src/SqliteWasm.ts +2 -0
- package/src/drizzle/d1-password-prepared.ts +2 -23
- package/src/drizzle/d1-passwords.ts +158 -780
- package/src/drizzle/d1-sessions.ts +21 -6
- package/src/drizzle/mysql-password-prepared.ts +4 -16
- package/src/drizzle/mysql-passwords.ts +5 -20
- package/src/drizzle/native-sql-table.ts +259 -0
- package/src/drizzle/oauth-connected-model.ts +97 -315
- package/src/drizzle/oauth-connected-reference.ts +13 -93
- package/src/drizzle/oauth-connected-target.ts +14 -271
- package/src/drizzle/oauth-kernel.ts +10 -0
- package/src/drizzle/oauth-model.ts +188 -541
- package/src/drizzle/oauth-mysql.ts +2 -2
- package/src/drizzle/oauth-proxy.ts +101 -0
- package/src/drizzle/oauth-target.ts +33 -737
- package/src/drizzle/password-model.ts +0 -33
- package/src/drizzle/password-prepared-model.ts +0 -18
- package/src/drizzle/password-sql.ts +3 -0
- package/src/drizzle/password-target.ts +41 -4
- package/src/drizzle/pg-password-prepared.ts +4 -16
- package/src/drizzle/pg-passwords.ts +5 -20
- package/src/drizzle/query-operations.ts +4 -0
- package/src/drizzle/session-sql.ts +2 -1
- package/src/drizzle/sqlite-password-prepared.ts +4 -52
- package/src/drizzle/sqlite-passwords.ts +7 -28
- package/src/drizzle/storage-validation.ts +13 -222
- package/src/index.ts +2 -8
- package/src/internal/drizzle-postgres-oauth-proxy.ts +37 -0
- package/src/internal/drizzle-postgres.ts +2 -0
- package/src/internal/drizzle-sqlite-oauth-proxy.ts +44 -0
- package/src/internal/drizzle-sqlite.ts +2 -0
- package/dist/_virtual/_rolldown/runtime.mjs +0 -13
- package/dist/drizzle/oauth-accounts.mjs +0 -359
- package/dist/drizzle/oauth-accounts.mjs.map +0 -1
- package/dist/drizzle/oauth-connected-access.mjs +0 -212
- package/dist/drizzle/oauth-connected-access.mjs.map +0 -1
- package/dist/drizzle/oauth-connected-collection.mjs +0 -202
- package/dist/drizzle/oauth-connected-collection.mjs.map +0 -1
- package/dist/drizzle/oauth-connected-custody.mjs +0 -147
- package/dist/drizzle/oauth-connected-custody.mjs.map +0 -1
- package/dist/drizzle/oauth-connected-flow.mjs +0 -297
- package/dist/drizzle/oauth-connected-flow.mjs.map +0 -1
- package/dist/drizzle/oauth-connected-input.mjs +0 -122
- package/dist/drizzle/oauth-connected-input.mjs.map +0 -1
- package/dist/drizzle/oauth-connected-maintenance.mjs +0 -214
- package/dist/drizzle/oauth-connected-maintenance.mjs.map +0 -1
- package/dist/drizzle/oauth-connected-management.mjs +0 -229
- package/dist/drizzle/oauth-connected-management.mjs.map +0 -1
- package/dist/drizzle/oauth-connected-settlement.mjs +0 -128
- package/dist/drizzle/oauth-connected-settlement.mjs.map +0 -1
- package/dist/drizzle/oauth-connected-sign-in.mjs +0 -265
- package/dist/drizzle/oauth-connected-sign-in.mjs.map +0 -1
- package/dist/drizzle/oauth-connected-state.d.mts +0 -2062
- package/dist/drizzle/oauth-connected-state.mjs +0 -430
- package/dist/drizzle/oauth-connected-state.mjs.map +0 -1
- package/dist/drizzle/oauth-flow.d.mts +0 -22
- package/dist/drizzle/oauth-flow.mjs +0 -253
- package/dist/drizzle/oauth-flow.mjs.map +0 -1
- package/dist/drizzle/oauth-input.mjs +0 -127
- package/dist/drizzle/oauth-input.mjs.map +0 -1
- package/dist/drizzle/oauth-owner.d.mts +0 -10
- package/dist/drizzle/oauth-owner.mjs +0 -10
- package/dist/drizzle/oauth-owner.mjs.map +0 -1
- package/dist/drizzle/oauth-registration.d.mts +0 -5
- package/dist/drizzle/oauth-registration.mjs +0 -374
- package/dist/drizzle/oauth-registration.mjs.map +0 -1
- package/dist/drizzle/oauth-state.mjs +0 -107
- package/dist/drizzle/oauth-state.mjs.map +0 -1
- package/src/drizzle/oauth-accounts.ts +0 -805
- package/src/drizzle/oauth-connected-access.ts +0 -361
- package/src/drizzle/oauth-connected-collection.ts +0 -324
- package/src/drizzle/oauth-connected-custody.ts +0 -279
- package/src/drizzle/oauth-connected-flow.ts +0 -529
- package/src/drizzle/oauth-connected-input.ts +0 -147
- package/src/drizzle/oauth-connected-maintenance.ts +0 -346
- package/src/drizzle/oauth-connected-management.ts +0 -365
- package/src/drizzle/oauth-connected-settlement.ts +0 -251
- package/src/drizzle/oauth-connected-sign-in.ts +0 -443
- package/src/drizzle/oauth-connected-state.ts +0 -872
- package/src/drizzle/oauth-flow.ts +0 -462
- package/src/drizzle/oauth-input.ts +0 -201
- package/src/drizzle/oauth-owner.ts +0 -29
- package/src/drizzle/oauth-registration.ts +0 -640
- package/src/drizzle/oauth-state.ts +0 -218
|
@@ -3,238 +3,24 @@ import {
|
|
|
3
3
|
PersistenceMappingError,
|
|
4
4
|
validateStorageBatch,
|
|
5
5
|
type StorageValidation,
|
|
6
|
+
storageKeyPlans,
|
|
6
7
|
} from "@yielded/auth-persistence/Adapter";
|
|
7
8
|
import { getTableColumns, getTableName, is, Table } from "drizzle-orm";
|
|
8
9
|
import { getTableConfig as getMysqlTableConfig, MySqlTable } from "drizzle-orm/mysql-core";
|
|
9
10
|
import { getTableConfig as getPgTableConfig, PgTable } from "drizzle-orm/pg-core";
|
|
10
|
-
import { Effect
|
|
11
|
+
import { Effect } from "effect";
|
|
11
12
|
import { SqlClient } from "effect/sql/SqlClient";
|
|
12
13
|
|
|
13
|
-
// These are mapping contracts, not a parser for arbitrary constraint declarations.
|
|
14
|
-
// Role aliases are explicit because their documentation names differ from mapping fields.
|
|
15
|
-
const uniquePlans: Readonly<Record<string, readonly [string, ReadonlyArray<string>]>> = {
|
|
16
|
-
"unique(abuseEvent.moduleId,abuseEvent.action,abuseEvent.scopeKind,abuseEvent.scopeKey,abuseEvent.commandId)":
|
|
17
|
-
["abuseEvent", ["moduleId", "action", "scopeKind", "scopeKey", "commandId"]],
|
|
18
|
-
"unique(admission.moduleId)": ["admission", ["moduleId"]],
|
|
19
|
-
"unique(attempt.moduleId,attempt.attemptId)": ["attempt", ["moduleId", "attemptId"]],
|
|
20
|
-
"unique(authority.subjectId,authority.credentialId)": [
|
|
21
|
-
"authority",
|
|
22
|
-
["subjectId", "credentialId"],
|
|
23
|
-
],
|
|
24
|
-
"unique(authorityCredential.subjectId,authorityCredential.credentialId)": [
|
|
25
|
-
"authorityCredential",
|
|
26
|
-
["subjectId", "credentialId"],
|
|
27
|
-
],
|
|
28
|
-
"unique(charge.moduleId,charge.action,charge.scopeKind,charge.scopeKey,charge.attemptId)": [
|
|
29
|
-
"charge",
|
|
30
|
-
["moduleId", "action", "scopeKind", "scopeKey", "attemptId"],
|
|
31
|
-
],
|
|
32
|
-
"unique(command.moduleId,command.commandId)": ["command", ["moduleId", "commandId"]],
|
|
33
|
-
"unique(connectedAdmission.admissionId)": ["admission", ["admissionId"]],
|
|
34
|
-
"unique(connectedClient.clientKey)": ["client", ["clientKey"]],
|
|
35
|
-
"unique(connectedCohort.cohortKey)": ["cohort", ["cohortKey"]],
|
|
36
|
-
"unique(connectedCommand.moduleId,connectedCommand.commandId)": [
|
|
37
|
-
"command",
|
|
38
|
-
["moduleId", "commandId"],
|
|
39
|
-
],
|
|
40
|
-
"unique(connectedFlow.moduleId,connectedFlow.commandId)": ["flow", ["moduleId", "commandId"]],
|
|
41
|
-
"unique(connectedFlow.moduleId,connectedFlow.flowId)": ["flow", ["moduleId", "flowId"]],
|
|
42
|
-
"unique(connectedFlow.stateDigest)": ["flow", ["stateDigest"]],
|
|
43
|
-
"unique(connectedGrant.moduleId,connectedGrant.grantId)": ["grant", ["moduleId", "grantId"]],
|
|
44
|
-
"unique(connectedGrant.moduleId,connectedGrant.subjectId,connectedGrant.profileKey,connectedGrant.activeIdentityKey)":
|
|
45
|
-
["grant", ["moduleId", "subjectId", "profileKey", "activeIdentityKey"]],
|
|
46
|
-
"unique(connectedRevocation.jobId)": ["job", ["jobId"]],
|
|
47
|
-
"unique(continuation.moduleId,continuation.continuationId)": [
|
|
48
|
-
"continuation",
|
|
49
|
-
["moduleId", "continuationId"],
|
|
50
|
-
],
|
|
51
|
-
"unique(continuation.moduleId,continuation.digest)": ["continuation", ["moduleId", "digest"]],
|
|
52
|
-
"unique(credential.credentialId)": ["credential", ["credentialId"]],
|
|
53
|
-
"unique(credential.identityKey)": ["credential", ["identityKey"]],
|
|
54
|
-
"unique(credential.moduleId,credential.credentialId)": [
|
|
55
|
-
"credential",
|
|
56
|
-
["moduleId", "credentialId"],
|
|
57
|
-
],
|
|
58
|
-
"unique(credential.moduleId,credential.subjectId)": ["credential", ["moduleId", "subjectId"]],
|
|
59
|
-
"unique(emailCommand.moduleId,emailCommand.commandId)": ["command", ["moduleId", "commandId"]],
|
|
60
|
-
"unique(emailCredential.moduleId,emailCredential.credentialId)": [
|
|
61
|
-
"credential",
|
|
62
|
-
["moduleId", "credentialId"],
|
|
63
|
-
],
|
|
64
|
-
"unique(emailCredential.moduleId,emailCredential.identifierNamespace,emailCredential.identifierValue)":
|
|
65
|
-
["credential", ["moduleId", "identifierNamespace", "identifierValue"]],
|
|
66
|
-
"unique(emailRegistration.moduleId,emailRegistration.commandId)": [
|
|
67
|
-
"registration",
|
|
68
|
-
["moduleId", "commandId"],
|
|
69
|
-
],
|
|
70
|
-
"unique(emailRegistration.pendingReference)": ["registration", ["pendingReference"]],
|
|
71
|
-
"unique(failureEvent.moduleId,failureEvent.seriesKey,failureEvent.commandId)": [
|
|
72
|
-
"failureEvent",
|
|
73
|
-
["moduleId", "seriesKey", "commandId"],
|
|
74
|
-
],
|
|
75
|
-
"unique(flow.flowId)": ["flow", ["flowId"]],
|
|
76
|
-
"unique(flow.moduleId,flow.commandId)": ["flow", ["moduleId", "commandId"]],
|
|
77
|
-
"unique(flow.moduleId,flow.flowId)": ["flow", ["moduleId", "flowId"]],
|
|
78
|
-
"unique(flow.stateDigest)": ["flow", ["stateDigest"]],
|
|
79
|
-
"unique(generation.moduleId,generation.deliveryId)": ["generation", ["moduleId", "deliveryId"]],
|
|
80
|
-
"unique(generation.moduleId,generation.proofId)": ["generation", ["moduleId", "proofId"]],
|
|
81
|
-
"unique(identifier.namespace,identifier.value)": ["identifier", ["namespace", "value"]],
|
|
82
|
-
"unique(intent.digest)": ["intent", ["digest"]],
|
|
83
|
-
"unique(intent.flowId)": ["intent", ["flowId"]],
|
|
84
|
-
"unique(intent.moduleId,intent.commandId)": ["intent", ["moduleId", "commandId"]],
|
|
85
|
-
"unique(intent.moduleId,intent.flowId)": ["intent", ["moduleId", "flowId"]],
|
|
86
|
-
"unique(intent.moduleId,intent.intentId)": ["intent", ["moduleId", "intentId"]],
|
|
87
|
-
"unique(intent.moduleId,intent.reference)": ["intent", ["moduleId", "reference"]],
|
|
88
|
-
"unique(ownership.identityKey)": ["ownership", ["identityKey"]],
|
|
89
|
-
"unique(pending.digest)": ["pending", ["digest"]],
|
|
90
|
-
"unique(pending.flowId)": ["pending", ["flowId"]],
|
|
91
|
-
"unique(rateScope.moduleId,rateScope.action,rateScope.scopeKind,rateScope.scopeKey)": [
|
|
92
|
-
"rateScope",
|
|
93
|
-
["moduleId", "action", "scopeKind", "scopeKey"],
|
|
94
|
-
],
|
|
95
|
-
"unique(rateScope.moduleId,rateScope.purpose,rateScope.action,rateScope.scopeKind,rateScope.scopeKey)":
|
|
96
|
-
["rateScope", ["moduleId", "purpose", "action", "scopeKind", "scopeKey"]],
|
|
97
|
-
"unique(registration.moduleId,registration.requestId)": [
|
|
98
|
-
"registration",
|
|
99
|
-
["moduleId", "requestId"],
|
|
100
|
-
],
|
|
101
|
-
"unique(registration.recoveryReference)": ["registration", ["recoveryReference"]],
|
|
102
|
-
"unique(registrationCommand.moduleId,registrationCommand.commandId)": [
|
|
103
|
-
"command",
|
|
104
|
-
["moduleId", "commandId"],
|
|
105
|
-
],
|
|
106
|
-
"unique(request.moduleId,request.requestId)": ["request", ["moduleId", "requestId"]],
|
|
107
|
-
"unique(series.moduleId,series.purpose,series.scopeKey)": [
|
|
108
|
-
"series",
|
|
109
|
-
["moduleId", "purpose", "scopeKey"],
|
|
110
|
-
],
|
|
111
|
-
"unique(session.digest)": ["session", ["digest"]],
|
|
112
|
-
"unique(tombstone.subjectId,tombstone.sessionId)": ["tombstone", ["subjectId", "sessionId"]],
|
|
113
|
-
"unique(tuple.identityKey)": ["ownership.tuple", ["identityKey"]],
|
|
114
|
-
"unique(unlinkCommand.moduleId,unlinkCommand.commandId)": ["command", ["moduleId", "commandId"]],
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
const arrayRoles: Readonly<Record<string, string>> = {
|
|
118
|
-
credentialId: "credential",
|
|
119
|
-
factor: "authority",
|
|
120
|
-
credentialOwnership: "credentialOwnership",
|
|
121
|
-
handleOwnership: "handleOwnership",
|
|
122
|
-
boundSubjectHandle: "handleOwnership",
|
|
123
|
-
flow: "flow",
|
|
124
|
-
command: "flow",
|
|
125
|
-
admission: "admission",
|
|
126
|
-
charge: "charge",
|
|
127
|
-
intentFlow: "intent",
|
|
128
|
-
intentCommand: "intent",
|
|
129
|
-
handle: "handle",
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
const nestedMappings = [
|
|
133
|
-
"read",
|
|
134
|
-
"signIn",
|
|
135
|
-
"password",
|
|
136
|
-
"proof",
|
|
137
|
-
"proofs",
|
|
138
|
-
"revocation",
|
|
139
|
-
"pending",
|
|
140
|
-
"session",
|
|
141
|
-
"source",
|
|
142
|
-
];
|
|
143
|
-
|
|
144
|
-
const constraintGroups = [
|
|
145
|
-
"constraints",
|
|
146
|
-
"tupleConstraints",
|
|
147
|
-
"registrationConstraints",
|
|
148
|
-
"managementConstraints",
|
|
149
|
-
];
|
|
150
|
-
|
|
151
|
-
const MappingRecord = Schema.Record(Schema.String, Schema.Unknown);
|
|
152
|
-
const record = Schema.decodeUnknownSync(MappingRecord);
|
|
153
|
-
|
|
154
|
-
const plans = (mapping: Readonly<Record<string, unknown>>) => {
|
|
155
|
-
const result: Array<{ readonly table: Table; readonly keys: ReadonlyArray<string> }> = [];
|
|
156
|
-
|
|
157
|
-
for (const group of constraintGroups) {
|
|
158
|
-
if (mapping[group] === undefined) continue;
|
|
159
|
-
for (const [name, declaration] of Object.entries(record(mapping[group]))) {
|
|
160
|
-
if (declaration === "notNull(provisioningRequest.subjectId)") continue;
|
|
161
|
-
let role: string;
|
|
162
|
-
let keys: ReadonlyArray<string>;
|
|
163
|
-
|
|
164
|
-
if (typeof declaration === "string") {
|
|
165
|
-
const plan = uniquePlans[declaration];
|
|
166
|
-
|
|
167
|
-
if (plan !== undefined) [role, keys] = plan;
|
|
168
|
-
else if (declaration === "unique(id)") {
|
|
169
|
-
role = "subject";
|
|
170
|
-
keys = ["id"];
|
|
171
|
-
} else if (declaration === "unique(scope)") {
|
|
172
|
-
role = name;
|
|
173
|
-
keys = ["scope"];
|
|
174
|
-
} else if (declaration === "unique(credentialId)") {
|
|
175
|
-
role = "credential";
|
|
176
|
-
keys = ["id"];
|
|
177
|
-
} else if (declaration === "unique(namespace,value)") {
|
|
178
|
-
role = "identifier";
|
|
179
|
-
keys = ["namespace", "value"];
|
|
180
|
-
} else if (declaration === "unique(provider,issuer,subject)") {
|
|
181
|
-
role = "externalIdentity";
|
|
182
|
-
keys = ["provider", "issuer", "subject"];
|
|
183
|
-
} else if (declaration === "unique(requestId)") {
|
|
184
|
-
role = "provisioningRequest";
|
|
185
|
-
keys = ["requestId"];
|
|
186
|
-
} else throw new Error("Unknown storage constraint");
|
|
187
|
-
} else if (Array.isArray(declaration) && declaration.every(Predicate.isString)) {
|
|
188
|
-
const mappedRole =
|
|
189
|
-
group === "managementConstraints" && name === "command" ? "command" : arrayRoles[name];
|
|
190
|
-
|
|
191
|
-
if (mappedRole === undefined) throw new Error("Unknown storage constraint");
|
|
192
|
-
role = mappedRole;
|
|
193
|
-
keys = declaration;
|
|
194
|
-
} else throw new Error("Invalid storage constraint");
|
|
195
|
-
|
|
196
|
-
let target: unknown = mapping;
|
|
197
|
-
|
|
198
|
-
for (const segment of role.split(".")) target = record(target)[segment];
|
|
199
|
-
// Session authority places its pending tables in one nested mapping.
|
|
200
|
-
if (target === undefined && Schema.is(MappingRecord)(mapping.pending))
|
|
201
|
-
target = mapping.pending[role];
|
|
202
|
-
let mapped = record(target);
|
|
203
|
-
|
|
204
|
-
if (role === "pending" && mapped.table === undefined) mapped = record(mapped.pending);
|
|
205
|
-
// OAuth ownership can be integrated into its tuple authority or separate.
|
|
206
|
-
if (role === "ownership" && mapped.table === undefined)
|
|
207
|
-
mapped = record(mapped.external ?? mapped.tuple);
|
|
208
|
-
if (!is(mapped.table, Table)) throw new Error("Missing storage table");
|
|
209
|
-
const columns = getTableColumns(mapped.table);
|
|
210
|
-
|
|
211
|
-
result.push({
|
|
212
|
-
table: mapped.table,
|
|
213
|
-
keys: keys.map((key) => {
|
|
214
|
-
const value = mapped[key];
|
|
215
|
-
|
|
216
|
-
if (typeof value !== "string" || columns[value] === undefined)
|
|
217
|
-
throw new Error("Missing mapped key");
|
|
218
|
-
|
|
219
|
-
return value;
|
|
220
|
-
}),
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
for (const nested of nestedMappings) {
|
|
225
|
-
const value = mapping[nested];
|
|
226
|
-
|
|
227
|
-
if (Schema.is(MappingRecord)(value) && value.table === undefined) result.push(...plans(value));
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
return result;
|
|
231
|
-
};
|
|
232
|
-
|
|
233
14
|
/** Validate at acquisition using the root database supplied by the adapter. */
|
|
234
15
|
export const validateDrizzleStorage = Effect.fnUntraced(
|
|
235
16
|
function* (mapping: unknown) {
|
|
236
17
|
const physical = yield* Effect.try({
|
|
237
|
-
try: () =>
|
|
18
|
+
try: () =>
|
|
19
|
+
storageKeyPlans(mapping, (table) => {
|
|
20
|
+
if (!is(table, Table)) throw new Error("Missing storage table");
|
|
21
|
+
|
|
22
|
+
return getTableColumns(table);
|
|
23
|
+
}),
|
|
238
24
|
catch: () =>
|
|
239
25
|
PersistenceMappingError.make({
|
|
240
26
|
operation: "mapping",
|
|
@@ -247,6 +33,11 @@ export const validateDrizzleStorage = Effect.fnUntraced(
|
|
|
247
33
|
const batches = new Map<"pg" | "mysql" | "sqlite", StorageValidation[]>();
|
|
248
34
|
|
|
249
35
|
for (const plan of physical) {
|
|
36
|
+
if (!is(plan.table, Table))
|
|
37
|
+
return yield* PersistenceMappingError.make({
|
|
38
|
+
operation: "mapping",
|
|
39
|
+
cause: "Missing storage table",
|
|
40
|
+
});
|
|
250
41
|
const pg = is(plan.table, PgTable);
|
|
251
42
|
const mysql = is(plan.table, MySqlTable);
|
|
252
43
|
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export type { OAuthProxyColumns } from "./drizzle/oauth-proxy";
|
|
2
|
+
|
|
1
3
|
export {
|
|
2
4
|
type AnyEmailAddressMapping,
|
|
3
5
|
type AnyEmailRegistrationMapping,
|
|
@@ -35,27 +37,19 @@ export {
|
|
|
35
37
|
type AnyPasswordPersistenceMapping,
|
|
36
38
|
type AnyPasswordRegistrationMapping,
|
|
37
39
|
type D1PasswordPersistenceMapping,
|
|
38
|
-
type PasswordAttemptAction,
|
|
39
|
-
type PasswordAttemptRecord,
|
|
40
|
-
type PasswordAttemptState,
|
|
41
|
-
type PasswordAttemptTable,
|
|
42
40
|
type PasswordAuthorityCredentialTable,
|
|
43
|
-
type PasswordChargeTable,
|
|
44
41
|
type PasswordCommandTable,
|
|
45
42
|
type PasswordConstraintClassifier,
|
|
46
43
|
type PasswordCredentialTable,
|
|
47
44
|
type PasswordD1Clock,
|
|
48
45
|
type PasswordIdentifierTable,
|
|
49
46
|
type PasswordPersistenceMapping,
|
|
50
|
-
type PasswordRateScopeKind,
|
|
51
|
-
type PasswordRateScopeTable,
|
|
52
47
|
type PasswordRegistrationConstraintClassifier,
|
|
53
48
|
type PasswordRegistrationIntent,
|
|
54
49
|
type PasswordRegistrationMapping,
|
|
55
50
|
type PasswordRegistrationProvisioning,
|
|
56
51
|
type PasswordRegistrationState,
|
|
57
52
|
type PasswordRegistrationTable,
|
|
58
|
-
type PasswordScopeKeys,
|
|
59
53
|
type PasswordSubjectTable,
|
|
60
54
|
type RequiredPasswordConstraints,
|
|
61
55
|
type RequiredPasswordRegistrationConstraints,
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { sql } from "drizzle-orm";
|
|
2
|
+
import { bigint, check, pgTable, primaryKey, text, type PgTable } from "drizzle-orm/pg-core";
|
|
3
|
+
|
|
4
|
+
import { oauthProxyLayer, type OAuthProxyColumns } from "../drizzle/oauth-proxy";
|
|
5
|
+
|
|
6
|
+
/** Export the returned table from your Drizzle Kit schema before applying the Layer. */
|
|
7
|
+
const table = (name: string) =>
|
|
8
|
+
pgTable(
|
|
9
|
+
name,
|
|
10
|
+
{
|
|
11
|
+
namespace: text("namespace").notNull(),
|
|
12
|
+
flowId: text("flow_id").notNull(),
|
|
13
|
+
version: text("version").notNull(),
|
|
14
|
+
stage: text("stage").notNull(),
|
|
15
|
+
context: text("context").notNull(),
|
|
16
|
+
expiresAtMillis: bigint("expires_at_millis", { mode: "number" }).notNull(),
|
|
17
|
+
handoffExpiresAtMillis: bigint("handoff_expires_at_millis", { mode: "number" }),
|
|
18
|
+
payload: text("payload").notNull(),
|
|
19
|
+
},
|
|
20
|
+
(columns) => [
|
|
21
|
+
primaryKey({ columns: [columns.namespace, columns.flowId] }),
|
|
22
|
+
check(
|
|
23
|
+
`${name}_stage`,
|
|
24
|
+
sql`${columns.stage} in ('Pending', 'Exchanging', 'Ready', 'Consumed')`,
|
|
25
|
+
),
|
|
26
|
+
check(
|
|
27
|
+
`${name}_handoff`,
|
|
28
|
+
sql`(${columns.stage} = 'Ready' and ${columns.handoffExpiresAtMillis} is not null)
|
|
29
|
+
or (${columns.stage} <> 'Ready' and ${columns.handoffExpiresAtMillis} is null)`,
|
|
30
|
+
),
|
|
31
|
+
],
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const layer = <T extends PgTable>(table: T, columns?: OAuthProxyColumns<T>) =>
|
|
35
|
+
oauthProxyLayer("pg", table, columns);
|
|
36
|
+
|
|
37
|
+
export const OAuthProxyPersistence = { table, layer };
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
import type { Effect } from "effect";
|
|
18
18
|
import type { SqlClient } from "effect/sql/SqlClient";
|
|
19
19
|
|
|
20
|
+
import { makeDrizzleSqlTables } from "../drizzle/native-sql-table";
|
|
20
21
|
import { drizzleQueryOperations } from "../drizzle/query-operations";
|
|
21
22
|
|
|
22
23
|
const makeTable = (definition: StorageTable) =>
|
|
@@ -78,6 +79,7 @@ export const postgresPersistence = <R>(acquire: Effect.Effect<object, never, R |
|
|
|
78
79
|
makeTable,
|
|
79
80
|
describe,
|
|
80
81
|
operations: drizzleQueryOperations,
|
|
82
|
+
nativeTables: makeDrizzleSqlTables,
|
|
81
83
|
acquire,
|
|
82
84
|
passkeys: makeComposedPasskeys(drizzleQueryOperations),
|
|
83
85
|
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { sql } from "drizzle-orm";
|
|
2
|
+
import {
|
|
3
|
+
check,
|
|
4
|
+
integer,
|
|
5
|
+
primaryKey,
|
|
6
|
+
sqliteTable,
|
|
7
|
+
text,
|
|
8
|
+
type SQLiteTable,
|
|
9
|
+
} from "drizzle-orm/sqlite-core";
|
|
10
|
+
|
|
11
|
+
import { oauthProxyLayer, type OAuthProxyColumns } from "../drizzle/oauth-proxy";
|
|
12
|
+
|
|
13
|
+
/** Export the returned table from your Drizzle Kit schema before applying the Layer. */
|
|
14
|
+
const table = (name: string) =>
|
|
15
|
+
sqliteTable(
|
|
16
|
+
name,
|
|
17
|
+
{
|
|
18
|
+
namespace: text("namespace").notNull(),
|
|
19
|
+
flowId: text("flow_id").notNull(),
|
|
20
|
+
version: text("version").notNull(),
|
|
21
|
+
stage: text("stage").notNull(),
|
|
22
|
+
context: text("context").notNull(),
|
|
23
|
+
expiresAtMillis: integer("expires_at_millis").notNull(),
|
|
24
|
+
handoffExpiresAtMillis: integer("handoff_expires_at_millis"),
|
|
25
|
+
payload: text("payload").notNull(),
|
|
26
|
+
},
|
|
27
|
+
(columns) => [
|
|
28
|
+
primaryKey({ columns: [columns.namespace, columns.flowId] }),
|
|
29
|
+
check(
|
|
30
|
+
`${name}_stage`,
|
|
31
|
+
sql`${columns.stage} in ('Pending', 'Exchanging', 'Ready', 'Consumed')`,
|
|
32
|
+
),
|
|
33
|
+
check(
|
|
34
|
+
`${name}_handoff`,
|
|
35
|
+
sql`(${columns.stage} = 'Ready' and ${columns.handoffExpiresAtMillis} is not null)
|
|
36
|
+
or (${columns.stage} <> 'Ready' and ${columns.handoffExpiresAtMillis} is null)`,
|
|
37
|
+
),
|
|
38
|
+
],
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const layer = <T extends SQLiteTable>(table: T, columns?: OAuthProxyColumns<T>) =>
|
|
42
|
+
oauthProxyLayer("sqlite", table, columns);
|
|
43
|
+
|
|
44
|
+
export const OAuthProxyPersistence = { table, layer };
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
import type { Effect } from "effect";
|
|
17
17
|
import type { SqlClient } from "effect/sql/SqlClient";
|
|
18
18
|
|
|
19
|
+
import { makeDrizzleSqlTables } from "../drizzle/native-sql-table";
|
|
19
20
|
import { drizzleQueryOperations } from "../drizzle/query-operations";
|
|
20
21
|
|
|
21
22
|
const makeTable = (definition: StorageTable) =>
|
|
@@ -76,6 +77,7 @@ export const sqlitePersistence = <R>(acquire: Effect.Effect<object, never, R | S
|
|
|
76
77
|
makeTable,
|
|
77
78
|
describe,
|
|
78
79
|
operations: drizzleQueryOperations,
|
|
80
|
+
nativeTables: makeDrizzleSqlTables,
|
|
79
81
|
acquire,
|
|
80
82
|
passkeys: makeComposedPasskeys(drizzleQueryOperations),
|
|
81
83
|
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
//#region \0rolldown/runtime.js
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __exportAll = (all, no_symbols) => {
|
|
4
|
-
let target = {};
|
|
5
|
-
for (var name in all) __defProp(target, name, {
|
|
6
|
-
get: all[name],
|
|
7
|
-
enumerable: true
|
|
8
|
-
});
|
|
9
|
-
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
|
-
return target;
|
|
11
|
-
};
|
|
12
|
-
//#endregion
|
|
13
|
-
export { __exportAll };
|