@getstrata/core 1.1.9 → 2.0.0
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/CHANGELOG.md +15 -0
- package/dist/core/database/transaction.d.ts +2 -1
- package/dist/core/database/transactionControl.d.ts +5 -0
- package/dist/core/http/loginThrottleMiddleware.d.ts +3 -0
- package/dist/core/http/metricsMiddleware.d.ts +1 -2
- package/dist/core/http/requestMetaContext.d.ts +2 -0
- package/dist/core/http/throttleMiddleware.d.ts +11 -2
- package/dist/core/metrics/prometheus.d.ts +11 -1
- package/dist/core/queue/jobRunner.d.ts +3 -1
- package/dist/core/queue/redisQueue.d.ts +20 -3
- package/dist/core/tenant/databaseTenantContext.d.ts +5 -1
- package/dist/entries/audit/exportAuditLogs.js +522 -62
- package/dist/entries/auth/basicAuthGuard.js +245 -219
- package/dist/entries/auth/oauth/samlProvider.js +185 -161
- package/dist/entries/auth/oneTimeToken.js +130 -127
- package/dist/entries/auth/passwordLogin.js +185 -180
- package/dist/entries/auth/saml/samlServiceProvider.js +185 -161
- package/dist/entries/auth/scimAuthMiddleware.js +525 -11
- package/dist/entries/database/migrations.js +132 -129
- package/dist/entries/database/schema.js +58 -39
- package/dist/entries/http/metricsMiddleware.js +124 -27
- package/dist/entries/http/response.js +107 -0
- package/dist/entries/http/routeMiddleware.js +40 -0
- package/dist/entries/http/throttleMiddleware.js +124 -11
- package/dist/entries/jobs/exportAuditLogsJob.js +522 -62
- package/dist/entries/metrics/prometheus.js +71 -11
- package/dist/entries/queue/createAppQueue.js +215 -21
- package/dist/entries/queue/jobRunner.js +3 -2
- package/dist/entries/queue/publicQueue.js +215 -21
- package/dist/entries/queue/queueMetrics.js +215 -21
- package/dist/entries/queue/redisQueue.js +223 -22
- package/dist/entries/tenant/databaseTenantContext.js +477 -16
- package/dist/entries/tenant/tenantDatabaseScope.js +523 -9
- package/dist/framework/public-api.d.ts +2 -2
- package/dist/index.js +954 -457
- package/package.json +1 -1
|
@@ -11,6 +11,25 @@ var __esm = (fn, res, err) => () => {
|
|
|
11
11
|
return res;
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
+
// ../../src/core/database/boundConnection.ts
|
|
15
|
+
function boundConnectionState() {
|
|
16
|
+
const globalRecord = globalThis;
|
|
17
|
+
const existing = globalRecord[BOUND_CONNECTION_KEY];
|
|
18
|
+
if (existing) {
|
|
19
|
+
return existing;
|
|
20
|
+
}
|
|
21
|
+
const created = { connection: null };
|
|
22
|
+
globalRecord[BOUND_CONNECTION_KEY] = created;
|
|
23
|
+
return created;
|
|
24
|
+
}
|
|
25
|
+
function getBoundDatabaseConnection() {
|
|
26
|
+
return boundConnectionState().connection;
|
|
27
|
+
}
|
|
28
|
+
var BOUND_CONNECTION_KEY;
|
|
29
|
+
var init_boundConnection = __esm(() => {
|
|
30
|
+
BOUND_CONNECTION_KEY = Symbol.for("@getstrata/boundDatabaseConnection");
|
|
31
|
+
});
|
|
32
|
+
|
|
14
33
|
// ../../src/core/runtime/asyncContextStore.ts
|
|
15
34
|
import { AsyncLocalStorage } from "async_hooks";
|
|
16
35
|
function createAsyncContextStore(key) {
|
|
@@ -42,46 +61,14 @@ var init_connectionContext = __esm(() => {
|
|
|
42
61
|
activeConnection = createAsyncContextStore("@getstrata/databaseConnectionContext");
|
|
43
62
|
});
|
|
44
63
|
|
|
45
|
-
// ../../src/core/runtime/optionalPeer.ts
|
|
46
|
-
function missingOptionalPeer(packageName, reason, error) {
|
|
47
|
-
return new Error(`Install ${packageName} ${reason} (\`bun add ${packageName}\`).`, {
|
|
48
|
-
cause: error
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// ../../src/core/security/timingSafeCompare.ts
|
|
53
|
-
import { timingSafeEqual } from "crypto";
|
|
54
|
-
function timingSafeCompareString(left, right) {
|
|
55
|
-
const leftBuffer = Buffer.from(left);
|
|
56
|
-
const rightBuffer = Buffer.from(right);
|
|
57
|
-
if (leftBuffer.length !== rightBuffer.length) {
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
return timingSafeEqual(leftBuffer, rightBuffer);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// ../../src/core/database/boundConnection.ts
|
|
64
|
-
var BOUND_CONNECTION_KEY = Symbol.for("@getstrata/boundDatabaseConnection");
|
|
65
|
-
function boundConnectionState() {
|
|
66
|
-
const globalRecord = globalThis;
|
|
67
|
-
const existing = globalRecord[BOUND_CONNECTION_KEY];
|
|
68
|
-
if (existing) {
|
|
69
|
-
return existing;
|
|
70
|
-
}
|
|
71
|
-
const created = { connection: null };
|
|
72
|
-
globalRecord[BOUND_CONNECTION_KEY] = created;
|
|
73
|
-
return created;
|
|
74
|
-
}
|
|
75
|
-
function getBoundDatabaseConnection() {
|
|
76
|
-
return boundConnectionState().connection;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
64
|
// ../../src/core/database/queryProxy.ts
|
|
80
|
-
|
|
81
|
-
var
|
|
65
|
+
var POOL_CONNECTION_METHODS;
|
|
66
|
+
var init_queryProxy = __esm(() => {
|
|
67
|
+
init_connectionContext();
|
|
68
|
+
POOL_CONNECTION_METHODS = new Set(["begin", "close", "connect"]);
|
|
69
|
+
});
|
|
82
70
|
|
|
83
71
|
// ../../src/core/database/defaultConnection.ts
|
|
84
|
-
var DEFAULT_CONNECTION_KEY = Symbol.for("@getstrata/defaultDatabaseConnection");
|
|
85
72
|
function defaultConnectionState() {
|
|
86
73
|
const globalRecord = globalThis;
|
|
87
74
|
const existing = globalRecord[DEFAULT_CONNECTION_KEY];
|
|
@@ -99,9 +86,18 @@ function getDefaultDatabasePool() {
|
|
|
99
86
|
}
|
|
100
87
|
return pool;
|
|
101
88
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
89
|
+
function getDefaultDatabaseQuery() {
|
|
90
|
+
const query = defaultConnectionState().query;
|
|
91
|
+
if (!query) {
|
|
92
|
+
throw new Error("Default database query handle is not registered. Call registerDefaultDatabasePool() during app bootstrap.");
|
|
93
|
+
}
|
|
94
|
+
return query;
|
|
95
|
+
}
|
|
96
|
+
var DEFAULT_CONNECTION_KEY;
|
|
97
|
+
var init_defaultConnection = __esm(() => {
|
|
98
|
+
init_queryProxy();
|
|
99
|
+
DEFAULT_CONNECTION_KEY = Symbol.for("@getstrata/defaultDatabaseConnection");
|
|
100
|
+
});
|
|
105
101
|
|
|
106
102
|
// ../../src/core/database/schema/driver.ts
|
|
107
103
|
function normalizeConnectionName(connection) {
|
|
@@ -142,6 +138,7 @@ function resolveDatabaseDriver(options = {}) {
|
|
|
142
138
|
}
|
|
143
139
|
return "pgsql";
|
|
144
140
|
}
|
|
141
|
+
var init_driver = () => {};
|
|
145
142
|
|
|
146
143
|
// ../../src/core/database/dialect.ts
|
|
147
144
|
function assertSafeIdentifier(identifier) {
|
|
@@ -153,133 +150,160 @@ function assertSafeIdentifier(identifier) {
|
|
|
153
150
|
function quoteIdentifierFor(dialect, column) {
|
|
154
151
|
return dialect.quoteIdentifier(column);
|
|
155
152
|
}
|
|
156
|
-
var postgresDialect = {
|
|
157
|
-
driver: "pgsql",
|
|
158
|
-
placeholder(index) {
|
|
159
|
-
return `$${index}`;
|
|
160
|
-
},
|
|
161
|
-
quoteIdentifier(identifier) {
|
|
162
|
-
return `"${assertSafeIdentifier(identifier)}"`;
|
|
163
|
-
},
|
|
164
|
-
nowExpression() {
|
|
165
|
-
return "NOW()";
|
|
166
|
-
},
|
|
167
|
-
timestampValue(value) {
|
|
168
|
-
return value.toISOString();
|
|
169
|
-
},
|
|
170
|
-
returningClause(columns) {
|
|
171
|
-
return ` RETURNING ${columns}`;
|
|
172
|
-
},
|
|
173
|
-
ilikeOperator() {
|
|
174
|
-
return "ILIKE";
|
|
175
|
-
},
|
|
176
|
-
nullsLastSuffix() {
|
|
177
|
-
return " NULLS LAST";
|
|
178
|
-
},
|
|
179
|
-
castToText(expression) {
|
|
180
|
-
return `${expression}::text`;
|
|
181
|
-
},
|
|
182
|
-
upsertSuffix(conflictColumns, updateColumns) {
|
|
183
|
-
const target = conflictColumns.map((column) => quoteIdentifierFor(this, column)).join(", ");
|
|
184
|
-
if (updateColumns.length === 0) {
|
|
185
|
-
return ` ON CONFLICT (${target}) DO NOTHING`;
|
|
186
|
-
}
|
|
187
|
-
const assignments = updateColumns.map((column) => {
|
|
188
|
-
const quoted = quoteIdentifierFor(this, column);
|
|
189
|
-
return `${quoted} = excluded.${quoted}`;
|
|
190
|
-
}).join(", ");
|
|
191
|
-
return ` ON CONFLICT (${target}) DO UPDATE SET ${assignments}`;
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
var mysqlDialect = {
|
|
195
|
-
driver: "mysql",
|
|
196
|
-
placeholder() {
|
|
197
|
-
return "?";
|
|
198
|
-
},
|
|
199
|
-
quoteIdentifier(identifier) {
|
|
200
|
-
return `\`${assertSafeIdentifier(identifier)}\``;
|
|
201
|
-
},
|
|
202
|
-
nowExpression() {
|
|
203
|
-
return "CURRENT_TIMESTAMP";
|
|
204
|
-
},
|
|
205
|
-
timestampValue(value) {
|
|
206
|
-
return value.toISOString().slice(0, 19).replace("T", " ");
|
|
207
|
-
},
|
|
208
|
-
returningClause() {
|
|
209
|
-
return "";
|
|
210
|
-
},
|
|
211
|
-
ilikeOperator() {
|
|
212
|
-
return "LIKE";
|
|
213
|
-
},
|
|
214
|
-
nullsLastSuffix() {
|
|
215
|
-
return "";
|
|
216
|
-
},
|
|
217
|
-
castToText(expression) {
|
|
218
|
-
return `CAST(${expression} AS CHAR)`;
|
|
219
|
-
},
|
|
220
|
-
upsertSuffix(conflictColumns, updateColumns) {
|
|
221
|
-
if (updateColumns.length === 0) {
|
|
222
|
-
const anchor = quoteIdentifierFor(this, conflictColumns[0] ?? "");
|
|
223
|
-
return ` ON DUPLICATE KEY UPDATE ${anchor} = ${anchor}`;
|
|
224
|
-
}
|
|
225
|
-
const assignments = updateColumns.map((column) => {
|
|
226
|
-
const quoted = quoteIdentifierFor(this, column);
|
|
227
|
-
return `${quoted} = VALUES(${quoted})`;
|
|
228
|
-
}).join(", ");
|
|
229
|
-
return ` ON DUPLICATE KEY UPDATE ${assignments}`;
|
|
230
|
-
}
|
|
231
|
-
};
|
|
232
|
-
var sqliteDialect = {
|
|
233
|
-
driver: "sqlite",
|
|
234
|
-
placeholder() {
|
|
235
|
-
return "?";
|
|
236
|
-
},
|
|
237
|
-
quoteIdentifier(identifier) {
|
|
238
|
-
return `"${assertSafeIdentifier(identifier)}"`;
|
|
239
|
-
},
|
|
240
|
-
nowExpression() {
|
|
241
|
-
return "strftime('%Y-%m-%dT%H:%M:%fZ', 'now')";
|
|
242
|
-
},
|
|
243
|
-
timestampValue(value) {
|
|
244
|
-
return value.toISOString();
|
|
245
|
-
},
|
|
246
|
-
returningClause(columns) {
|
|
247
|
-
return ` RETURNING ${columns}`;
|
|
248
|
-
},
|
|
249
|
-
ilikeOperator() {
|
|
250
|
-
return "LIKE";
|
|
251
|
-
},
|
|
252
|
-
nullsLastSuffix() {
|
|
253
|
-
return "";
|
|
254
|
-
},
|
|
255
|
-
castToText(expression) {
|
|
256
|
-
return `CAST(${expression} AS TEXT)`;
|
|
257
|
-
},
|
|
258
|
-
upsertSuffix(conflictColumns, updateColumns) {
|
|
259
|
-
const target = conflictColumns.map((column) => quoteIdentifierFor(this, column)).join(", ");
|
|
260
|
-
if (updateColumns.length === 0) {
|
|
261
|
-
return ` ON CONFLICT (${target}) DO NOTHING`;
|
|
262
|
-
}
|
|
263
|
-
const assignments = updateColumns.map((column) => {
|
|
264
|
-
const quoted = quoteIdentifierFor(this, column);
|
|
265
|
-
return `${quoted} = excluded.${quoted}`;
|
|
266
|
-
}).join(", ");
|
|
267
|
-
return ` ON CONFLICT (${target}) DO UPDATE SET ${assignments}`;
|
|
268
|
-
}
|
|
269
|
-
};
|
|
270
|
-
var dialects = {
|
|
271
|
-
pgsql: postgresDialect,
|
|
272
|
-
mysql: mysqlDialect,
|
|
273
|
-
sqlite: sqliteDialect
|
|
274
|
-
};
|
|
275
|
-
var dialectContext = createAsyncContextStore("@getstrata/sqlDialect");
|
|
276
|
-
var dialectOverride = null;
|
|
277
153
|
function dialectFor(driver) {
|
|
278
154
|
return dialects[driver];
|
|
279
155
|
}
|
|
280
156
|
function currentSqlDialect() {
|
|
281
157
|
return dialectContext.getStore() ?? dialectOverride ?? dialectFor(resolveDatabaseDriver());
|
|
282
158
|
}
|
|
159
|
+
var postgresDialect, mysqlDialect, sqliteDialect, dialects, dialectContext, dialectOverride = null;
|
|
160
|
+
var init_dialect = __esm(() => {
|
|
161
|
+
init_asyncContextStore();
|
|
162
|
+
init_driver();
|
|
163
|
+
postgresDialect = {
|
|
164
|
+
driver: "pgsql",
|
|
165
|
+
placeholder(index) {
|
|
166
|
+
return `$${index}`;
|
|
167
|
+
},
|
|
168
|
+
quoteIdentifier(identifier) {
|
|
169
|
+
return `"${assertSafeIdentifier(identifier)}"`;
|
|
170
|
+
},
|
|
171
|
+
nowExpression() {
|
|
172
|
+
return "NOW()";
|
|
173
|
+
},
|
|
174
|
+
timestampValue(value) {
|
|
175
|
+
return value.toISOString();
|
|
176
|
+
},
|
|
177
|
+
returningClause(columns) {
|
|
178
|
+
return ` RETURNING ${columns}`;
|
|
179
|
+
},
|
|
180
|
+
ilikeOperator() {
|
|
181
|
+
return "ILIKE";
|
|
182
|
+
},
|
|
183
|
+
nullsLastSuffix() {
|
|
184
|
+
return " NULLS LAST";
|
|
185
|
+
},
|
|
186
|
+
castToText(expression) {
|
|
187
|
+
return `${expression}::text`;
|
|
188
|
+
},
|
|
189
|
+
upsertSuffix(conflictColumns, updateColumns) {
|
|
190
|
+
const target = conflictColumns.map((column) => quoteIdentifierFor(this, column)).join(", ");
|
|
191
|
+
if (updateColumns.length === 0) {
|
|
192
|
+
return ` ON CONFLICT (${target}) DO NOTHING`;
|
|
193
|
+
}
|
|
194
|
+
const assignments = updateColumns.map((column) => {
|
|
195
|
+
const quoted = quoteIdentifierFor(this, column);
|
|
196
|
+
return `${quoted} = excluded.${quoted}`;
|
|
197
|
+
}).join(", ");
|
|
198
|
+
return ` ON CONFLICT (${target}) DO UPDATE SET ${assignments}`;
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
mysqlDialect = {
|
|
202
|
+
driver: "mysql",
|
|
203
|
+
placeholder() {
|
|
204
|
+
return "?";
|
|
205
|
+
},
|
|
206
|
+
quoteIdentifier(identifier) {
|
|
207
|
+
return `\`${assertSafeIdentifier(identifier)}\``;
|
|
208
|
+
},
|
|
209
|
+
nowExpression() {
|
|
210
|
+
return "CURRENT_TIMESTAMP";
|
|
211
|
+
},
|
|
212
|
+
timestampValue(value) {
|
|
213
|
+
return value.toISOString().slice(0, 19).replace("T", " ");
|
|
214
|
+
},
|
|
215
|
+
returningClause() {
|
|
216
|
+
return "";
|
|
217
|
+
},
|
|
218
|
+
ilikeOperator() {
|
|
219
|
+
return "LIKE";
|
|
220
|
+
},
|
|
221
|
+
nullsLastSuffix() {
|
|
222
|
+
return "";
|
|
223
|
+
},
|
|
224
|
+
castToText(expression) {
|
|
225
|
+
return `CAST(${expression} AS CHAR)`;
|
|
226
|
+
},
|
|
227
|
+
upsertSuffix(conflictColumns, updateColumns) {
|
|
228
|
+
if (updateColumns.length === 0) {
|
|
229
|
+
const anchor = quoteIdentifierFor(this, conflictColumns[0] ?? "");
|
|
230
|
+
return ` ON DUPLICATE KEY UPDATE ${anchor} = ${anchor}`;
|
|
231
|
+
}
|
|
232
|
+
const assignments = updateColumns.map((column) => {
|
|
233
|
+
const quoted = quoteIdentifierFor(this, column);
|
|
234
|
+
return `${quoted} = VALUES(${quoted})`;
|
|
235
|
+
}).join(", ");
|
|
236
|
+
return ` ON DUPLICATE KEY UPDATE ${assignments}`;
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
sqliteDialect = {
|
|
240
|
+
driver: "sqlite",
|
|
241
|
+
placeholder() {
|
|
242
|
+
return "?";
|
|
243
|
+
},
|
|
244
|
+
quoteIdentifier(identifier) {
|
|
245
|
+
return `"${assertSafeIdentifier(identifier)}"`;
|
|
246
|
+
},
|
|
247
|
+
nowExpression() {
|
|
248
|
+
return "strftime('%Y-%m-%dT%H:%M:%fZ', 'now')";
|
|
249
|
+
},
|
|
250
|
+
timestampValue(value) {
|
|
251
|
+
return value.toISOString();
|
|
252
|
+
},
|
|
253
|
+
returningClause(columns) {
|
|
254
|
+
return ` RETURNING ${columns}`;
|
|
255
|
+
},
|
|
256
|
+
ilikeOperator() {
|
|
257
|
+
return "LIKE";
|
|
258
|
+
},
|
|
259
|
+
nullsLastSuffix() {
|
|
260
|
+
return "";
|
|
261
|
+
},
|
|
262
|
+
castToText(expression) {
|
|
263
|
+
return `CAST(${expression} AS TEXT)`;
|
|
264
|
+
},
|
|
265
|
+
upsertSuffix(conflictColumns, updateColumns) {
|
|
266
|
+
const target = conflictColumns.map((column) => quoteIdentifierFor(this, column)).join(", ");
|
|
267
|
+
if (updateColumns.length === 0) {
|
|
268
|
+
return ` ON CONFLICT (${target}) DO NOTHING`;
|
|
269
|
+
}
|
|
270
|
+
const assignments = updateColumns.map((column) => {
|
|
271
|
+
const quoted = quoteIdentifierFor(this, column);
|
|
272
|
+
return `${quoted} = excluded.${quoted}`;
|
|
273
|
+
}).join(", ");
|
|
274
|
+
return ` ON CONFLICT (${target}) DO UPDATE SET ${assignments}`;
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
dialects = {
|
|
278
|
+
pgsql: postgresDialect,
|
|
279
|
+
mysql: mysqlDialect,
|
|
280
|
+
sqlite: sqliteDialect
|
|
281
|
+
};
|
|
282
|
+
dialectContext = createAsyncContextStore("@getstrata/sqlDialect");
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
// ../../src/core/runtime/optionalPeer.ts
|
|
286
|
+
function missingOptionalPeer(packageName, reason, error) {
|
|
287
|
+
return new Error(`Install ${packageName} ${reason} (\`bun add ${packageName}\`).`, {
|
|
288
|
+
cause: error
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// ../../src/core/security/timingSafeCompare.ts
|
|
293
|
+
import { timingSafeEqual } from "crypto";
|
|
294
|
+
function timingSafeCompareString(left, right) {
|
|
295
|
+
const leftBuffer = Buffer.from(left);
|
|
296
|
+
const rightBuffer = Buffer.from(right);
|
|
297
|
+
if (leftBuffer.length !== rightBuffer.length) {
|
|
298
|
+
return false;
|
|
299
|
+
}
|
|
300
|
+
return timingSafeEqual(leftBuffer, rightBuffer);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// ../../src/core/auth/saml/samlAssertionReplay.ts
|
|
304
|
+
init_boundConnection();
|
|
305
|
+
init_defaultConnection();
|
|
306
|
+
init_dialect();
|
|
283
307
|
|
|
284
308
|
// ../../src/core/database/errors.ts
|
|
285
309
|
import {
|
|
@@ -26,12 +26,6 @@ function createAsyncContextStore(key) {
|
|
|
26
26
|
}
|
|
27
27
|
var init_asyncContextStore = () => {};
|
|
28
28
|
|
|
29
|
-
// ../../src/core/auth/oneTimeToken.ts
|
|
30
|
-
import { randomBytes } from "crypto";
|
|
31
|
-
|
|
32
|
-
// ../../src/core/database/dialect.ts
|
|
33
|
-
init_asyncContextStore();
|
|
34
|
-
|
|
35
29
|
// ../../src/core/database/schema/driver.ts
|
|
36
30
|
function normalizeConnectionName(connection) {
|
|
37
31
|
const normalized = connection.trim().toLowerCase();
|
|
@@ -71,6 +65,7 @@ function resolveDatabaseDriver(options = {}) {
|
|
|
71
65
|
}
|
|
72
66
|
return "pgsql";
|
|
73
67
|
}
|
|
68
|
+
var init_driver = () => {};
|
|
74
69
|
|
|
75
70
|
// ../../src/core/database/dialect.ts
|
|
76
71
|
function assertSafeIdentifier(identifier) {
|
|
@@ -82,133 +77,141 @@ function assertSafeIdentifier(identifier) {
|
|
|
82
77
|
function quoteIdentifierFor(dialect, column) {
|
|
83
78
|
return dialect.quoteIdentifier(column);
|
|
84
79
|
}
|
|
85
|
-
var postgresDialect = {
|
|
86
|
-
driver: "pgsql",
|
|
87
|
-
placeholder(index) {
|
|
88
|
-
return `$${index}`;
|
|
89
|
-
},
|
|
90
|
-
quoteIdentifier(identifier) {
|
|
91
|
-
return `"${assertSafeIdentifier(identifier)}"`;
|
|
92
|
-
},
|
|
93
|
-
nowExpression() {
|
|
94
|
-
return "NOW()";
|
|
95
|
-
},
|
|
96
|
-
timestampValue(value) {
|
|
97
|
-
return value.toISOString();
|
|
98
|
-
},
|
|
99
|
-
returningClause(columns) {
|
|
100
|
-
return ` RETURNING ${columns}`;
|
|
101
|
-
},
|
|
102
|
-
ilikeOperator() {
|
|
103
|
-
return "ILIKE";
|
|
104
|
-
},
|
|
105
|
-
nullsLastSuffix() {
|
|
106
|
-
return " NULLS LAST";
|
|
107
|
-
},
|
|
108
|
-
castToText(expression) {
|
|
109
|
-
return `${expression}::text`;
|
|
110
|
-
},
|
|
111
|
-
upsertSuffix(conflictColumns, updateColumns) {
|
|
112
|
-
const target = conflictColumns.map((column) => quoteIdentifierFor(this, column)).join(", ");
|
|
113
|
-
if (updateColumns.length === 0) {
|
|
114
|
-
return ` ON CONFLICT (${target}) DO NOTHING`;
|
|
115
|
-
}
|
|
116
|
-
const assignments = updateColumns.map((column) => {
|
|
117
|
-
const quoted = quoteIdentifierFor(this, column);
|
|
118
|
-
return `${quoted} = excluded.${quoted}`;
|
|
119
|
-
}).join(", ");
|
|
120
|
-
return ` ON CONFLICT (${target}) DO UPDATE SET ${assignments}`;
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
var mysqlDialect = {
|
|
124
|
-
driver: "mysql",
|
|
125
|
-
placeholder() {
|
|
126
|
-
return "?";
|
|
127
|
-
},
|
|
128
|
-
quoteIdentifier(identifier) {
|
|
129
|
-
return `\`${assertSafeIdentifier(identifier)}\``;
|
|
130
|
-
},
|
|
131
|
-
nowExpression() {
|
|
132
|
-
return "CURRENT_TIMESTAMP";
|
|
133
|
-
},
|
|
134
|
-
timestampValue(value) {
|
|
135
|
-
return value.toISOString().slice(0, 19).replace("T", " ");
|
|
136
|
-
},
|
|
137
|
-
returningClause() {
|
|
138
|
-
return "";
|
|
139
|
-
},
|
|
140
|
-
ilikeOperator() {
|
|
141
|
-
return "LIKE";
|
|
142
|
-
},
|
|
143
|
-
nullsLastSuffix() {
|
|
144
|
-
return "";
|
|
145
|
-
},
|
|
146
|
-
castToText(expression) {
|
|
147
|
-
return `CAST(${expression} AS CHAR)`;
|
|
148
|
-
},
|
|
149
|
-
upsertSuffix(conflictColumns, updateColumns) {
|
|
150
|
-
if (updateColumns.length === 0) {
|
|
151
|
-
const anchor = quoteIdentifierFor(this, conflictColumns[0] ?? "");
|
|
152
|
-
return ` ON DUPLICATE KEY UPDATE ${anchor} = ${anchor}`;
|
|
153
|
-
}
|
|
154
|
-
const assignments = updateColumns.map((column) => {
|
|
155
|
-
const quoted = quoteIdentifierFor(this, column);
|
|
156
|
-
return `${quoted} = VALUES(${quoted})`;
|
|
157
|
-
}).join(", ");
|
|
158
|
-
return ` ON DUPLICATE KEY UPDATE ${assignments}`;
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
var sqliteDialect = {
|
|
162
|
-
driver: "sqlite",
|
|
163
|
-
placeholder() {
|
|
164
|
-
return "?";
|
|
165
|
-
},
|
|
166
|
-
quoteIdentifier(identifier) {
|
|
167
|
-
return `"${assertSafeIdentifier(identifier)}"`;
|
|
168
|
-
},
|
|
169
|
-
nowExpression() {
|
|
170
|
-
return "strftime('%Y-%m-%dT%H:%M:%fZ', 'now')";
|
|
171
|
-
},
|
|
172
|
-
timestampValue(value) {
|
|
173
|
-
return value.toISOString();
|
|
174
|
-
},
|
|
175
|
-
returningClause(columns) {
|
|
176
|
-
return ` RETURNING ${columns}`;
|
|
177
|
-
},
|
|
178
|
-
ilikeOperator() {
|
|
179
|
-
return "LIKE";
|
|
180
|
-
},
|
|
181
|
-
nullsLastSuffix() {
|
|
182
|
-
return "";
|
|
183
|
-
},
|
|
184
|
-
castToText(expression) {
|
|
185
|
-
return `CAST(${expression} AS TEXT)`;
|
|
186
|
-
},
|
|
187
|
-
upsertSuffix(conflictColumns, updateColumns) {
|
|
188
|
-
const target = conflictColumns.map((column) => quoteIdentifierFor(this, column)).join(", ");
|
|
189
|
-
if (updateColumns.length === 0) {
|
|
190
|
-
return ` ON CONFLICT (${target}) DO NOTHING`;
|
|
191
|
-
}
|
|
192
|
-
const assignments = updateColumns.map((column) => {
|
|
193
|
-
const quoted = quoteIdentifierFor(this, column);
|
|
194
|
-
return `${quoted} = excluded.${quoted}`;
|
|
195
|
-
}).join(", ");
|
|
196
|
-
return ` ON CONFLICT (${target}) DO UPDATE SET ${assignments}`;
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
var dialects = {
|
|
200
|
-
pgsql: postgresDialect,
|
|
201
|
-
mysql: mysqlDialect,
|
|
202
|
-
sqlite: sqliteDialect
|
|
203
|
-
};
|
|
204
|
-
var dialectContext = createAsyncContextStore("@getstrata/sqlDialect");
|
|
205
|
-
var dialectOverride = null;
|
|
206
80
|
function dialectFor(driver) {
|
|
207
81
|
return dialects[driver];
|
|
208
82
|
}
|
|
209
83
|
function currentSqlDialect() {
|
|
210
84
|
return dialectContext.getStore() ?? dialectOverride ?? dialectFor(resolveDatabaseDriver());
|
|
211
85
|
}
|
|
86
|
+
var postgresDialect, mysqlDialect, sqliteDialect, dialects, dialectContext, dialectOverride = null;
|
|
87
|
+
var init_dialect = __esm(() => {
|
|
88
|
+
init_asyncContextStore();
|
|
89
|
+
init_driver();
|
|
90
|
+
postgresDialect = {
|
|
91
|
+
driver: "pgsql",
|
|
92
|
+
placeholder(index) {
|
|
93
|
+
return `$${index}`;
|
|
94
|
+
},
|
|
95
|
+
quoteIdentifier(identifier) {
|
|
96
|
+
return `"${assertSafeIdentifier(identifier)}"`;
|
|
97
|
+
},
|
|
98
|
+
nowExpression() {
|
|
99
|
+
return "NOW()";
|
|
100
|
+
},
|
|
101
|
+
timestampValue(value) {
|
|
102
|
+
return value.toISOString();
|
|
103
|
+
},
|
|
104
|
+
returningClause(columns) {
|
|
105
|
+
return ` RETURNING ${columns}`;
|
|
106
|
+
},
|
|
107
|
+
ilikeOperator() {
|
|
108
|
+
return "ILIKE";
|
|
109
|
+
},
|
|
110
|
+
nullsLastSuffix() {
|
|
111
|
+
return " NULLS LAST";
|
|
112
|
+
},
|
|
113
|
+
castToText(expression) {
|
|
114
|
+
return `${expression}::text`;
|
|
115
|
+
},
|
|
116
|
+
upsertSuffix(conflictColumns, updateColumns) {
|
|
117
|
+
const target = conflictColumns.map((column) => quoteIdentifierFor(this, column)).join(", ");
|
|
118
|
+
if (updateColumns.length === 0) {
|
|
119
|
+
return ` ON CONFLICT (${target}) DO NOTHING`;
|
|
120
|
+
}
|
|
121
|
+
const assignments = updateColumns.map((column) => {
|
|
122
|
+
const quoted = quoteIdentifierFor(this, column);
|
|
123
|
+
return `${quoted} = excluded.${quoted}`;
|
|
124
|
+
}).join(", ");
|
|
125
|
+
return ` ON CONFLICT (${target}) DO UPDATE SET ${assignments}`;
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
mysqlDialect = {
|
|
129
|
+
driver: "mysql",
|
|
130
|
+
placeholder() {
|
|
131
|
+
return "?";
|
|
132
|
+
},
|
|
133
|
+
quoteIdentifier(identifier) {
|
|
134
|
+
return `\`${assertSafeIdentifier(identifier)}\``;
|
|
135
|
+
},
|
|
136
|
+
nowExpression() {
|
|
137
|
+
return "CURRENT_TIMESTAMP";
|
|
138
|
+
},
|
|
139
|
+
timestampValue(value) {
|
|
140
|
+
return value.toISOString().slice(0, 19).replace("T", " ");
|
|
141
|
+
},
|
|
142
|
+
returningClause() {
|
|
143
|
+
return "";
|
|
144
|
+
},
|
|
145
|
+
ilikeOperator() {
|
|
146
|
+
return "LIKE";
|
|
147
|
+
},
|
|
148
|
+
nullsLastSuffix() {
|
|
149
|
+
return "";
|
|
150
|
+
},
|
|
151
|
+
castToText(expression) {
|
|
152
|
+
return `CAST(${expression} AS CHAR)`;
|
|
153
|
+
},
|
|
154
|
+
upsertSuffix(conflictColumns, updateColumns) {
|
|
155
|
+
if (updateColumns.length === 0) {
|
|
156
|
+
const anchor = quoteIdentifierFor(this, conflictColumns[0] ?? "");
|
|
157
|
+
return ` ON DUPLICATE KEY UPDATE ${anchor} = ${anchor}`;
|
|
158
|
+
}
|
|
159
|
+
const assignments = updateColumns.map((column) => {
|
|
160
|
+
const quoted = quoteIdentifierFor(this, column);
|
|
161
|
+
return `${quoted} = VALUES(${quoted})`;
|
|
162
|
+
}).join(", ");
|
|
163
|
+
return ` ON DUPLICATE KEY UPDATE ${assignments}`;
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
sqliteDialect = {
|
|
167
|
+
driver: "sqlite",
|
|
168
|
+
placeholder() {
|
|
169
|
+
return "?";
|
|
170
|
+
},
|
|
171
|
+
quoteIdentifier(identifier) {
|
|
172
|
+
return `"${assertSafeIdentifier(identifier)}"`;
|
|
173
|
+
},
|
|
174
|
+
nowExpression() {
|
|
175
|
+
return "strftime('%Y-%m-%dT%H:%M:%fZ', 'now')";
|
|
176
|
+
},
|
|
177
|
+
timestampValue(value) {
|
|
178
|
+
return value.toISOString();
|
|
179
|
+
},
|
|
180
|
+
returningClause(columns) {
|
|
181
|
+
return ` RETURNING ${columns}`;
|
|
182
|
+
},
|
|
183
|
+
ilikeOperator() {
|
|
184
|
+
return "LIKE";
|
|
185
|
+
},
|
|
186
|
+
nullsLastSuffix() {
|
|
187
|
+
return "";
|
|
188
|
+
},
|
|
189
|
+
castToText(expression) {
|
|
190
|
+
return `CAST(${expression} AS TEXT)`;
|
|
191
|
+
},
|
|
192
|
+
upsertSuffix(conflictColumns, updateColumns) {
|
|
193
|
+
const target = conflictColumns.map((column) => quoteIdentifierFor(this, column)).join(", ");
|
|
194
|
+
if (updateColumns.length === 0) {
|
|
195
|
+
return ` ON CONFLICT (${target}) DO NOTHING`;
|
|
196
|
+
}
|
|
197
|
+
const assignments = updateColumns.map((column) => {
|
|
198
|
+
const quoted = quoteIdentifierFor(this, column);
|
|
199
|
+
return `${quoted} = excluded.${quoted}`;
|
|
200
|
+
}).join(", ");
|
|
201
|
+
return ` ON CONFLICT (${target}) DO UPDATE SET ${assignments}`;
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
dialects = {
|
|
205
|
+
pgsql: postgresDialect,
|
|
206
|
+
mysql: mysqlDialect,
|
|
207
|
+
sqlite: sqliteDialect
|
|
208
|
+
};
|
|
209
|
+
dialectContext = createAsyncContextStore("@getstrata/sqlDialect");
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
// ../../src/core/auth/oneTimeToken.ts
|
|
213
|
+
init_dialect();
|
|
214
|
+
import { randomBytes } from "crypto";
|
|
212
215
|
|
|
213
216
|
// ../../src/core/auth/tokenHash.ts
|
|
214
217
|
import { createHmac } from "crypto";
|