@yielded/auth-persistence-drizzle 0.1.0-beta.23 → 0.1.0-beta.25
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 +9 -9
- package/dist/D1.mjs +2 -1
- package/dist/D1.mjs.map +1 -1
- package/dist/Libsql.d.mts +48 -64
- package/dist/Libsql.mjs +2 -1
- package/dist/Libsql.mjs.map +1 -1
- package/dist/Mysql2.d.mts +26 -27
- package/dist/Pglite.d.mts +28 -28
- package/dist/Pglite.mjs +2 -1
- package/dist/Pglite.mjs.map +1 -1
- package/dist/Postgres.d.mts +29 -29
- package/dist/Postgres.mjs +2 -1
- package/dist/Postgres.mjs.map +1 -1
- package/dist/SqliteBun.d.mts +49 -65
- package/dist/SqliteBun.mjs +2 -1
- package/dist/SqliteBun.mjs.map +1 -1
- package/dist/SqliteDo.d.mts +47 -63
- package/dist/SqliteDo.mjs +2 -1
- package/dist/SqliteDo.mjs.map +1 -1
- package/dist/SqliteNode.d.mts +51 -67
- package/dist/SqliteNode.mjs +2 -1
- package/dist/SqliteNode.mjs.map +1 -1
- package/dist/SqliteWasm.d.mts +47 -63
- 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 +15 -15
- 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 +1 -1
- package/dist/drizzle/d1-password-prepared.mjs.map +1 -1
- package/dist/drizzle/d1-passwords.d.mts +17 -33
- package/dist/drizzle/d1-passwords.mjs +57 -199
- 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 +1 -1
- package/dist/drizzle/d1-sessions.d.mts +2 -2
- 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 +26 -1
- package/dist/drizzle/native-sql-table.mjs.map +1 -1
- 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 -6
- 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-sql.mjs +1 -1
- package/dist/drizzle/password-prepared-sql.mjs.map +1 -1
- package/dist/drizzle/password-prepared-state.mjs +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 +1 -1
- 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/sqlite-password-prepared.mjs.map +1 -1
- package/dist/drizzle/sqlite-passwords.mjs.map +1 -1
- package/dist/drizzle/storage-validation.mjs +10 -185
- package/dist/drizzle/storage-validation.mjs.map +1 -1
- package/dist/drizzle/totp-target.d.mts +2 -2
- 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-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/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 +4 -6
- package/src/drizzle/d1-passwords.ts +125 -459
- package/src/drizzle/d1-sessions.ts +21 -6
- package/src/drizzle/mysql-password-prepared.ts +4 -8
- package/src/drizzle/mysql-passwords.ts +5 -10
- package/src/drizzle/native-sql-table.ts +30 -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 -13
- package/src/drizzle/password-prepared-model.ts +0 -6
- package/src/drizzle/password-prepared-sql.ts +2 -1
- package/src/drizzle/pg-password-prepared.ts +4 -8
- package/src/drizzle/pg-passwords.ts +5 -10
- package/src/drizzle/query-operations.ts +4 -0
- package/src/drizzle/sqlite-password-prepared.ts +4 -8
- package/src/drizzle/sqlite-passwords.ts +7 -14
- package/src/drizzle/storage-validation.ts +13 -214
- package/src/index.ts +2 -4
- package/src/internal/drizzle-postgres-oauth-proxy.ts +37 -0
- package/src/internal/drizzle-sqlite-oauth-proxy.ts +44 -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,230 +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(command.moduleId,command.commandId)": ["command", ["moduleId", "commandId"]],
|
|
29
|
-
"unique(connectedAdmission.admissionId)": ["admission", ["admissionId"]],
|
|
30
|
-
"unique(connectedClient.clientKey)": ["client", ["clientKey"]],
|
|
31
|
-
"unique(connectedCohort.cohortKey)": ["cohort", ["cohortKey"]],
|
|
32
|
-
"unique(connectedCommand.moduleId,connectedCommand.commandId)": [
|
|
33
|
-
"command",
|
|
34
|
-
["moduleId", "commandId"],
|
|
35
|
-
],
|
|
36
|
-
"unique(connectedFlow.moduleId,connectedFlow.commandId)": ["flow", ["moduleId", "commandId"]],
|
|
37
|
-
"unique(connectedFlow.moduleId,connectedFlow.flowId)": ["flow", ["moduleId", "flowId"]],
|
|
38
|
-
"unique(connectedFlow.stateDigest)": ["flow", ["stateDigest"]],
|
|
39
|
-
"unique(connectedGrant.moduleId,connectedGrant.grantId)": ["grant", ["moduleId", "grantId"]],
|
|
40
|
-
"unique(connectedGrant.moduleId,connectedGrant.subjectId,connectedGrant.profileKey,connectedGrant.activeIdentityKey)":
|
|
41
|
-
["grant", ["moduleId", "subjectId", "profileKey", "activeIdentityKey"]],
|
|
42
|
-
"unique(connectedRevocation.jobId)": ["job", ["jobId"]],
|
|
43
|
-
"unique(continuation.moduleId,continuation.continuationId)": [
|
|
44
|
-
"continuation",
|
|
45
|
-
["moduleId", "continuationId"],
|
|
46
|
-
],
|
|
47
|
-
"unique(continuation.moduleId,continuation.digest)": ["continuation", ["moduleId", "digest"]],
|
|
48
|
-
"unique(credential.credentialId)": ["credential", ["credentialId"]],
|
|
49
|
-
"unique(credential.identityKey)": ["credential", ["identityKey"]],
|
|
50
|
-
"unique(credential.moduleId,credential.credentialId)": [
|
|
51
|
-
"credential",
|
|
52
|
-
["moduleId", "credentialId"],
|
|
53
|
-
],
|
|
54
|
-
"unique(credential.moduleId,credential.subjectId)": ["credential", ["moduleId", "subjectId"]],
|
|
55
|
-
"unique(emailCommand.moduleId,emailCommand.commandId)": ["command", ["moduleId", "commandId"]],
|
|
56
|
-
"unique(emailCredential.moduleId,emailCredential.credentialId)": [
|
|
57
|
-
"credential",
|
|
58
|
-
["moduleId", "credentialId"],
|
|
59
|
-
],
|
|
60
|
-
"unique(emailCredential.moduleId,emailCredential.identifierNamespace,emailCredential.identifierValue)":
|
|
61
|
-
["credential", ["moduleId", "identifierNamespace", "identifierValue"]],
|
|
62
|
-
"unique(emailRegistration.moduleId,emailRegistration.commandId)": [
|
|
63
|
-
"registration",
|
|
64
|
-
["moduleId", "commandId"],
|
|
65
|
-
],
|
|
66
|
-
"unique(emailRegistration.pendingReference)": ["registration", ["pendingReference"]],
|
|
67
|
-
"unique(failureEvent.moduleId,failureEvent.seriesKey,failureEvent.commandId)": [
|
|
68
|
-
"failureEvent",
|
|
69
|
-
["moduleId", "seriesKey", "commandId"],
|
|
70
|
-
],
|
|
71
|
-
"unique(flow.flowId)": ["flow", ["flowId"]],
|
|
72
|
-
"unique(flow.moduleId,flow.commandId)": ["flow", ["moduleId", "commandId"]],
|
|
73
|
-
"unique(flow.moduleId,flow.flowId)": ["flow", ["moduleId", "flowId"]],
|
|
74
|
-
"unique(flow.stateDigest)": ["flow", ["stateDigest"]],
|
|
75
|
-
"unique(generation.moduleId,generation.deliveryId)": ["generation", ["moduleId", "deliveryId"]],
|
|
76
|
-
"unique(generation.moduleId,generation.proofId)": ["generation", ["moduleId", "proofId"]],
|
|
77
|
-
"unique(identifier.namespace,identifier.value)": ["identifier", ["namespace", "value"]],
|
|
78
|
-
"unique(intent.digest)": ["intent", ["digest"]],
|
|
79
|
-
"unique(intent.flowId)": ["intent", ["flowId"]],
|
|
80
|
-
"unique(intent.moduleId,intent.commandId)": ["intent", ["moduleId", "commandId"]],
|
|
81
|
-
"unique(intent.moduleId,intent.flowId)": ["intent", ["moduleId", "flowId"]],
|
|
82
|
-
"unique(intent.moduleId,intent.intentId)": ["intent", ["moduleId", "intentId"]],
|
|
83
|
-
"unique(intent.moduleId,intent.reference)": ["intent", ["moduleId", "reference"]],
|
|
84
|
-
"unique(ownership.identityKey)": ["ownership", ["identityKey"]],
|
|
85
|
-
"unique(pending.digest)": ["pending", ["digest"]],
|
|
86
|
-
"unique(pending.flowId)": ["pending", ["flowId"]],
|
|
87
|
-
"unique(rateScope.moduleId,rateScope.purpose,rateScope.action,rateScope.scopeKind,rateScope.scopeKey)":
|
|
88
|
-
["rateScope", ["moduleId", "purpose", "action", "scopeKind", "scopeKey"]],
|
|
89
|
-
"unique(registration.moduleId,registration.requestId)": [
|
|
90
|
-
"registration",
|
|
91
|
-
["moduleId", "requestId"],
|
|
92
|
-
],
|
|
93
|
-
"unique(registration.recoveryReference)": ["registration", ["recoveryReference"]],
|
|
94
|
-
"unique(registrationCommand.moduleId,registrationCommand.commandId)": [
|
|
95
|
-
"command",
|
|
96
|
-
["moduleId", "commandId"],
|
|
97
|
-
],
|
|
98
|
-
"unique(request.moduleId,request.requestId)": ["request", ["moduleId", "requestId"]],
|
|
99
|
-
"unique(series.moduleId,series.purpose,series.scopeKey)": [
|
|
100
|
-
"series",
|
|
101
|
-
["moduleId", "purpose", "scopeKey"],
|
|
102
|
-
],
|
|
103
|
-
"unique(session.digest)": ["session", ["digest"]],
|
|
104
|
-
"unique(tombstone.subjectId,tombstone.sessionId)": ["tombstone", ["subjectId", "sessionId"]],
|
|
105
|
-
"unique(tuple.identityKey)": ["ownership.tuple", ["identityKey"]],
|
|
106
|
-
"unique(unlinkCommand.moduleId,unlinkCommand.commandId)": ["command", ["moduleId", "commandId"]],
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
const arrayRoles: Readonly<Record<string, string>> = {
|
|
110
|
-
credentialId: "credential",
|
|
111
|
-
factor: "authority",
|
|
112
|
-
credentialOwnership: "credentialOwnership",
|
|
113
|
-
handleOwnership: "handleOwnership",
|
|
114
|
-
boundSubjectHandle: "handleOwnership",
|
|
115
|
-
flow: "flow",
|
|
116
|
-
command: "flow",
|
|
117
|
-
admission: "admission",
|
|
118
|
-
charge: "charge",
|
|
119
|
-
intentFlow: "intent",
|
|
120
|
-
intentCommand: "intent",
|
|
121
|
-
handle: "handle",
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
const nestedMappings = [
|
|
125
|
-
"read",
|
|
126
|
-
"signIn",
|
|
127
|
-
"password",
|
|
128
|
-
"proof",
|
|
129
|
-
"proofs",
|
|
130
|
-
"revocation",
|
|
131
|
-
"pending",
|
|
132
|
-
"session",
|
|
133
|
-
"source",
|
|
134
|
-
];
|
|
135
|
-
|
|
136
|
-
const constraintGroups = [
|
|
137
|
-
"constraints",
|
|
138
|
-
"tupleConstraints",
|
|
139
|
-
"registrationConstraints",
|
|
140
|
-
"managementConstraints",
|
|
141
|
-
];
|
|
142
|
-
|
|
143
|
-
const MappingRecord = Schema.Record(Schema.String, Schema.Unknown);
|
|
144
|
-
const record = Schema.decodeUnknownSync(MappingRecord);
|
|
145
|
-
|
|
146
|
-
const plans = (mapping: Readonly<Record<string, unknown>>) => {
|
|
147
|
-
const result: Array<{ readonly table: Table; readonly keys: ReadonlyArray<string> }> = [];
|
|
148
|
-
|
|
149
|
-
for (const group of constraintGroups) {
|
|
150
|
-
if (mapping[group] === undefined) continue;
|
|
151
|
-
for (const [name, declaration] of Object.entries(record(mapping[group]))) {
|
|
152
|
-
if (declaration === "notNull(provisioningRequest.subjectId)") continue;
|
|
153
|
-
let role: string;
|
|
154
|
-
let keys: ReadonlyArray<string>;
|
|
155
|
-
|
|
156
|
-
if (typeof declaration === "string") {
|
|
157
|
-
const plan = uniquePlans[declaration];
|
|
158
|
-
|
|
159
|
-
if (plan !== undefined) [role, keys] = plan;
|
|
160
|
-
else if (declaration === "unique(id)") {
|
|
161
|
-
role = "subject";
|
|
162
|
-
keys = ["id"];
|
|
163
|
-
} else if (declaration === "unique(scope)") {
|
|
164
|
-
role = name;
|
|
165
|
-
keys = ["scope"];
|
|
166
|
-
} else if (declaration === "unique(credentialId)") {
|
|
167
|
-
role = "credential";
|
|
168
|
-
keys = ["id"];
|
|
169
|
-
} else if (declaration === "unique(namespace,value)") {
|
|
170
|
-
role = "identifier";
|
|
171
|
-
keys = ["namespace", "value"];
|
|
172
|
-
} else if (declaration === "unique(provider,issuer,subject)") {
|
|
173
|
-
role = "externalIdentity";
|
|
174
|
-
keys = ["provider", "issuer", "subject"];
|
|
175
|
-
} else if (declaration === "unique(requestId)") {
|
|
176
|
-
role = "provisioningRequest";
|
|
177
|
-
keys = ["requestId"];
|
|
178
|
-
} else throw new Error("Unknown storage constraint");
|
|
179
|
-
} else if (Array.isArray(declaration) && declaration.every(Predicate.isString)) {
|
|
180
|
-
const mappedRole =
|
|
181
|
-
group === "managementConstraints" && name === "command" ? "command" : arrayRoles[name];
|
|
182
|
-
|
|
183
|
-
if (mappedRole === undefined) throw new Error("Unknown storage constraint");
|
|
184
|
-
role = mappedRole;
|
|
185
|
-
keys = declaration;
|
|
186
|
-
} else throw new Error("Invalid storage constraint");
|
|
187
|
-
|
|
188
|
-
let target: unknown = mapping;
|
|
189
|
-
|
|
190
|
-
for (const segment of role.split(".")) target = record(target)[segment];
|
|
191
|
-
// Session authority places its pending tables in one nested mapping.
|
|
192
|
-
if (target === undefined && Schema.is(MappingRecord)(mapping.pending))
|
|
193
|
-
target = mapping.pending[role];
|
|
194
|
-
let mapped = record(target);
|
|
195
|
-
|
|
196
|
-
if (role === "pending" && mapped.table === undefined) mapped = record(mapped.pending);
|
|
197
|
-
// OAuth ownership can be integrated into its tuple authority or separate.
|
|
198
|
-
if (role === "ownership" && mapped.table === undefined)
|
|
199
|
-
mapped = record(mapped.external ?? mapped.tuple);
|
|
200
|
-
if (!is(mapped.table, Table)) throw new Error("Missing storage table");
|
|
201
|
-
const columns = getTableColumns(mapped.table);
|
|
202
|
-
|
|
203
|
-
result.push({
|
|
204
|
-
table: mapped.table,
|
|
205
|
-
keys: keys.map((key) => {
|
|
206
|
-
const value = mapped[key];
|
|
207
|
-
|
|
208
|
-
if (typeof value !== "string" || columns[value] === undefined)
|
|
209
|
-
throw new Error("Missing mapped key");
|
|
210
|
-
|
|
211
|
-
return value;
|
|
212
|
-
}),
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
for (const nested of nestedMappings) {
|
|
217
|
-
const value = mapping[nested];
|
|
218
|
-
|
|
219
|
-
if (Schema.is(MappingRecord)(value) && value.table === undefined) result.push(...plans(value));
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
return result;
|
|
223
|
-
};
|
|
224
|
-
|
|
225
14
|
/** Validate at acquisition using the root database supplied by the adapter. */
|
|
226
15
|
export const validateDrizzleStorage = Effect.fnUntraced(
|
|
227
16
|
function* (mapping: unknown) {
|
|
228
17
|
const physical = yield* Effect.try({
|
|
229
|
-
try: () =>
|
|
18
|
+
try: () =>
|
|
19
|
+
storageKeyPlans(mapping, (table) => {
|
|
20
|
+
if (!is(table, Table)) throw new Error("Missing storage table");
|
|
21
|
+
|
|
22
|
+
return getTableColumns(table);
|
|
23
|
+
}),
|
|
230
24
|
catch: () =>
|
|
231
25
|
PersistenceMappingError.make({
|
|
232
26
|
operation: "mapping",
|
|
@@ -239,6 +33,11 @@ export const validateDrizzleStorage = Effect.fnUntraced(
|
|
|
239
33
|
const batches = new Map<"pg" | "mysql" | "sqlite", StorageValidation[]>();
|
|
240
34
|
|
|
241
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
|
+
});
|
|
242
41
|
const pg = is(plan.table, PgTable);
|
|
243
42
|
const mysql = is(plan.table, MySqlTable);
|
|
244
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,10 +37,6 @@ 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
41
|
type PasswordCommandTable,
|
|
44
42
|
type PasswordConstraintClassifier,
|
|
@@ -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 };
|
|
@@ -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 };
|
|
@@ -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 };
|