tina4-nodejs 3.13.150 → 3.13.152
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/CLAUDE.md +2 -2
- package/package.json +5 -9
- package/packages/cli/dist/bin.js +1326 -586
- package/packages/cli/src/bin.ts +179 -7
- package/packages/cli/src/commands/generate.ts +36 -17
- package/packages/cli/src/commands/migrateCreate.ts +15 -3
- package/packages/cli/src/commands/queue.ts +8 -0
- package/packages/cli/src/util.ts +25 -15
- package/packages/core/dist/index.js +1172 -574
- package/packages/core/src/aiClient.ts +2 -1
- package/packages/core/src/api.ts +2 -1
- package/packages/core/src/auth.ts +1 -1
- package/packages/core/src/authGate.ts +3 -4
- package/packages/core/src/cache.ts +6 -1
- package/packages/core/src/devAdmin.ts +180 -123
- package/packages/core/src/dispatchPipeline.ts +4 -0
- package/packages/core/src/docs.ts +5 -3
- package/packages/core/src/errorOverlay.ts +18 -9
- package/packages/core/src/index.ts +2 -1
- package/packages/core/src/mcp.ts +53 -16
- package/packages/core/src/messenger.ts +22 -30
- package/packages/core/src/middleware.ts +8 -1
- package/packages/core/src/optionalPackage.ts +2 -2
- package/packages/core/src/plan.ts +3 -3
- package/packages/core/src/push.ts +1 -1
- package/packages/core/src/request.ts +185 -25
- package/packages/core/src/router.ts +3 -2
- package/packages/core/src/server.ts +36 -12
- package/packages/core/src/session.ts +44 -0
- package/packages/core/src/slashTrim.ts +39 -0
- package/packages/core/src/wsdl.ts +66 -48
- package/packages/core/templates/crud/form.twig +5 -5
- package/packages/core/templates/crud/table.twig +2 -2
- package/packages/core/templates/errors/302.twig +4 -3
- package/packages/frond/dist/index.js +206 -64
- package/packages/frond/src/engine.ts +278 -69
- package/packages/frond/src/index.ts +1 -1
- package/packages/orm/dist/index.js +1156 -560
- package/packages/orm/src/adapters/postgres.ts +79 -19
- package/packages/orm/src/crudRender.ts +5 -5
- package/packages/orm/src/crudTable.ts +1 -1
- package/packages/orm/src/database.ts +15 -29
- package/packages/orm/src/databaseResult.ts +11 -1
- package/packages/orm/src/docstore.ts +24 -8
- package/packages/orm/src/realtime/index.ts +1 -0
- package/packages/orm/src/realtime/realtime.ts +2 -1
- package/packages/orm/src/realtime/s3Client.ts +276 -0
- package/packages/orm/src/realtime/storage.ts +19 -60
- package/packages/orm/src/sqlTranslator.ts +58 -42
- package/packages/swagger/dist/index.js +25 -4
- package/packages/swagger/src/generator.ts +7 -4
- package/packages/swagger/src/ui.ts +2 -1
- package/types/cli/src/bin.d.ts +16 -0
- package/types/cli/src/commands/generate.d.ts +11 -0
- package/types/cli/src/commands/migrateCreate.d.ts +2 -0
- package/types/cli/src/commands/queue.d.ts +2 -0
- package/types/cli/src/util.d.ts +2 -1
- package/types/core/src/authGate.d.ts +3 -3
- package/types/core/src/devAdmin.d.ts +40 -0
- package/types/core/src/index.d.ts +2 -1
- package/types/core/src/middleware.d.ts +1 -0
- package/types/core/src/optionalPackage.d.ts +2 -2
- package/types/core/src/request.d.ts +5 -1
- package/types/core/src/session.d.ts +25 -0
- package/types/core/src/slashTrim.d.ts +6 -0
- package/types/frond/src/engine.d.ts +11 -0
- package/types/frond/src/index.d.ts +1 -1
- package/types/orm/src/adapters/postgres.d.ts +6 -0
- package/types/orm/src/realtime/index.d.ts +1 -0
- package/types/orm/src/realtime/s3Client.d.ts +48 -0
- package/types/orm/src/realtime/storage.d.ts +9 -7
package/packages/cli/dist/bin.js
CHANGED
|
@@ -14,6 +14,30 @@ var __export = (target, all) => {
|
|
|
14
14
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
+
// ../core/src/slashTrim.ts
|
|
18
|
+
function rtrimSlashes(s) {
|
|
19
|
+
let end = s.length;
|
|
20
|
+
while (end > 0 && s.charCodeAt(end - 1) === SLASH) end--;
|
|
21
|
+
return end === s.length ? s : s.slice(0, end);
|
|
22
|
+
}
|
|
23
|
+
function trimChar(s, code) {
|
|
24
|
+
let start2 = 0;
|
|
25
|
+
let end = s.length;
|
|
26
|
+
while (start2 < end && s.charCodeAt(start2) === code) start2++;
|
|
27
|
+
while (end > start2 && s.charCodeAt(end - 1) === code) end--;
|
|
28
|
+
return start2 === 0 && end === s.length ? s : s.slice(start2, end);
|
|
29
|
+
}
|
|
30
|
+
function trimSlashes(s) {
|
|
31
|
+
return trimChar(s, SLASH);
|
|
32
|
+
}
|
|
33
|
+
var SLASH;
|
|
34
|
+
var init_slashTrim = __esm({
|
|
35
|
+
"../core/src/slashTrim.ts"() {
|
|
36
|
+
"use strict";
|
|
37
|
+
SLASH = 47;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
17
41
|
// ../core/src/constants.ts
|
|
18
42
|
var HTTP_OK, HTTP_CREATED, HTTP_ACCEPTED, HTTP_NO_CONTENT, HTTP_MOVED, HTTP_REDIRECT, HTTP_NOT_MODIFIED, HTTP_BAD_REQUEST, HTTP_UNAUTHORIZED, HTTP_FORBIDDEN, HTTP_NOT_FOUND, HTTP_METHOD_NOT_ALLOWED, HTTP_CONFLICT, HTTP_GONE, HTTP_UNPROCESSABLE, HTTP_TOO_MANY, HTTP_SERVER_ERROR, HTTP_BAD_GATEWAY, HTTP_UNAVAILABLE, APPLICATION_JSON, APPLICATION_XML, APPLICATION_FORM, APPLICATION_OCTET, TEXT_HTML, TEXT_PLAIN, TEXT_CSV, TEXT_XML;
|
|
19
43
|
var init_constants = __esm({
|
|
@@ -1102,7 +1126,7 @@ function resolveAlgorithm(algorithm) {
|
|
|
1102
1126
|
return chosen;
|
|
1103
1127
|
}
|
|
1104
1128
|
function base64urlEncode(data) {
|
|
1105
|
-
return data.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(
|
|
1129
|
+
return data.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/={1,2}$/, "");
|
|
1106
1130
|
}
|
|
1107
1131
|
function base64urlDecode(str) {
|
|
1108
1132
|
let s = str.replace(/-/g, "+").replace(/_/g, "/");
|
|
@@ -1381,6 +1405,12 @@ var init_types = __esm({
|
|
|
1381
1405
|
});
|
|
1382
1406
|
|
|
1383
1407
|
// ../orm/src/databaseResult.ts
|
|
1408
|
+
function stripTypeArgs(colType) {
|
|
1409
|
+
const open = colType.indexOf("(");
|
|
1410
|
+
if (open < 0) return colType;
|
|
1411
|
+
const close = colType.indexOf(")", open);
|
|
1412
|
+
return close < 0 ? colType : colType.slice(0, open) + colType.slice(close + 1);
|
|
1413
|
+
}
|
|
1384
1414
|
var DatabaseResult;
|
|
1385
1415
|
var init_databaseResult = __esm({
|
|
1386
1416
|
"../orm/src/databaseResult.ts"() {
|
|
@@ -1563,7 +1593,7 @@ var init_databaseResult = __esm({
|
|
|
1563
1593
|
const [size, decimals] = this._parseTypeSize(colType);
|
|
1564
1594
|
return {
|
|
1565
1595
|
name: col.name,
|
|
1566
|
-
type: colType
|
|
1596
|
+
type: stripTypeArgs(colType),
|
|
1567
1597
|
size,
|
|
1568
1598
|
decimals,
|
|
1569
1599
|
nullable: col.nullable ?? true,
|
|
@@ -2120,12 +2150,49 @@ var init_point = __esm({
|
|
|
2120
2150
|
});
|
|
2121
2151
|
|
|
2122
2152
|
// ../orm/src/sqlTranslator.ts
|
|
2123
|
-
|
|
2153
|
+
function skipQuoted(sql, i, backslashEscapes) {
|
|
2154
|
+
const c = sql[i];
|
|
2155
|
+
const escapeString = c === "'" && (sql[i - 1] === "E" || sql[i - 1] === "e") && !isIdentChar(sql[i - 2]);
|
|
2156
|
+
const backslash = c !== "`" && (escapeString || backslashEscapes);
|
|
2157
|
+
const n = sql.length;
|
|
2158
|
+
i++;
|
|
2159
|
+
while (i < n) {
|
|
2160
|
+
if (backslash && sql[i] === "\\") {
|
|
2161
|
+
i += 2;
|
|
2162
|
+
continue;
|
|
2163
|
+
}
|
|
2164
|
+
if (sql[i] === c) {
|
|
2165
|
+
if (sql[i + 1] === c) {
|
|
2166
|
+
i += 2;
|
|
2167
|
+
continue;
|
|
2168
|
+
}
|
|
2169
|
+
return i + 1;
|
|
2170
|
+
}
|
|
2171
|
+
i++;
|
|
2172
|
+
}
|
|
2173
|
+
return i;
|
|
2174
|
+
}
|
|
2175
|
+
function skipLineComment(sql, i) {
|
|
2176
|
+
while (i < sql.length && sql[i] !== "\n") i++;
|
|
2177
|
+
return i;
|
|
2178
|
+
}
|
|
2179
|
+
function skipBlockComment(sql, i) {
|
|
2180
|
+
const end = sql.indexOf("*/", i + 2);
|
|
2181
|
+
return end === -1 ? sql.length : end + 2;
|
|
2182
|
+
}
|
|
2183
|
+
function skipDollarQuote(sql, i) {
|
|
2184
|
+
const tag = sql.slice(i).match(/^\$([A-Za-z_][A-Za-z0-9_]*)?\$/);
|
|
2185
|
+
if (!tag) return i;
|
|
2186
|
+
const end = sql.indexOf(tag[0], i + tag[0].length);
|
|
2187
|
+
return end === -1 ? sql.length : end + tag[0].length;
|
|
2188
|
+
}
|
|
2189
|
+
var isIdentChar, SQLTranslator, QueryCache;
|
|
2124
2190
|
var init_sqlTranslator = __esm({
|
|
2125
2191
|
"../orm/src/sqlTranslator.ts"() {
|
|
2126
2192
|
"use strict";
|
|
2127
2193
|
init_databaseUrl();
|
|
2128
2194
|
init_point();
|
|
2195
|
+
isIdentChar = (ch) => !!ch && /[A-Za-z0-9_]/.test(ch);
|
|
2129
2196
|
SQLTranslator = class _SQLTranslator {
|
|
2130
2197
|
static SPATIAL_ENGINES = /* @__PURE__ */ new Set(["postgres", "postgresql"]);
|
|
2131
2198
|
static SPATIAL_IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z_][A-Za-z0-9_]*)*$/;
|
|
@@ -2406,47 +2473,26 @@ var init_sqlTranslator = __esm({
|
|
|
2406
2473
|
static placeholderPositions(sql, options = {}) {
|
|
2407
2474
|
const positions = [];
|
|
2408
2475
|
const n = sql.length;
|
|
2409
|
-
const isIdent = (ch) => !!ch && /[A-Za-z0-9_]/.test(ch);
|
|
2410
2476
|
let i = 0;
|
|
2411
2477
|
while (i < n) {
|
|
2412
2478
|
const c = sql[i];
|
|
2413
2479
|
const next = sql[i + 1];
|
|
2414
2480
|
if (c === "'" || c === '"' || c === "`") {
|
|
2415
|
-
|
|
2416
|
-
const escapeString = c === "'" && (prev === "E" || prev === "e") && !isIdent(sql[i - 2]);
|
|
2417
|
-
const backslash = c !== "`" && (escapeString || options.backslashEscapes === true);
|
|
2418
|
-
i++;
|
|
2419
|
-
while (i < n) {
|
|
2420
|
-
if (backslash && sql[i] === "\\") {
|
|
2421
|
-
i += 2;
|
|
2422
|
-
continue;
|
|
2423
|
-
}
|
|
2424
|
-
if (sql[i] === c) {
|
|
2425
|
-
if (sql[i + 1] === c) {
|
|
2426
|
-
i += 2;
|
|
2427
|
-
continue;
|
|
2428
|
-
}
|
|
2429
|
-
i++;
|
|
2430
|
-
break;
|
|
2431
|
-
}
|
|
2432
|
-
i++;
|
|
2433
|
-
}
|
|
2481
|
+
i = skipQuoted(sql, i, options.backslashEscapes === true);
|
|
2434
2482
|
continue;
|
|
2435
2483
|
}
|
|
2436
2484
|
if (c === "-" && next === "-") {
|
|
2437
|
-
|
|
2485
|
+
i = skipLineComment(sql, i);
|
|
2438
2486
|
continue;
|
|
2439
2487
|
}
|
|
2440
2488
|
if (c === "/" && next === "*") {
|
|
2441
|
-
|
|
2442
|
-
i = end === -1 ? n : end + 2;
|
|
2489
|
+
i = skipBlockComment(sql, i);
|
|
2443
2490
|
continue;
|
|
2444
2491
|
}
|
|
2445
|
-
if (c === "$" && !
|
|
2446
|
-
const
|
|
2447
|
-
if (
|
|
2448
|
-
|
|
2449
|
-
i = end === -1 ? n : end + tag[0].length;
|
|
2492
|
+
if (c === "$" && !isIdentChar(sql[i - 1])) {
|
|
2493
|
+
const past = skipDollarQuote(sql, i);
|
|
2494
|
+
if (past !== i) {
|
|
2495
|
+
i = past;
|
|
2450
2496
|
continue;
|
|
2451
2497
|
}
|
|
2452
2498
|
}
|
|
@@ -2479,7 +2525,7 @@ var init_sqlTranslator = __esm({
|
|
|
2479
2525
|
* → { sql: "INSERT INTO t (x) VALUES (1)", columns: ["id", "name"] }
|
|
2480
2526
|
*/
|
|
2481
2527
|
static parseReturning(sql) {
|
|
2482
|
-
const m = sql.match(/\bRETURNING\s+(
|
|
2528
|
+
const m = sql.match(/\bRETURNING\s+(\S.*)$/i);
|
|
2483
2529
|
if (!m) return { sql, columns: [] };
|
|
2484
2530
|
const columns = m[1].split(",").map((c) => c.trim());
|
|
2485
2531
|
return {
|
|
@@ -2533,7 +2579,12 @@ var init_sqlTranslator = __esm({
|
|
|
2533
2579
|
// The `d` flag records group indices, so the head can be sliced at the exact
|
|
2534
2580
|
// start of the VALUES group rather than by hunting for a parenthesis (the
|
|
2535
2581
|
// column list has parentheses too).
|
|
2536
|
-
static INSERT_VALUES =
|
|
2582
|
+
static INSERT_VALUES = (
|
|
2583
|
+
// ReDoS-safe: the table ref matches `\S(?:[\s\S]*?\S)?` (bounded by non-space
|
|
2584
|
+
// at both ends) so the separator `\s+` before VALUES can't overlap it the way
|
|
2585
|
+
// the old `.+?\s+` did (polynomial on `INSERT INTO ` + a long space run).
|
|
2586
|
+
/^\s*INSERT\s+INTO\s+\S(?:[\s\S]*?\S)?\s+VALUES\s*\(([^()]*)\)\s*$/dis
|
|
2587
|
+
);
|
|
2537
2588
|
/**
|
|
2538
2589
|
* Engines whose lastInsertId reports the FIRST generated id of a multi-row
|
|
2539
2590
|
* INSERT rather than the last. Verified live, not assumed: a 3-row insert
|
|
@@ -4218,6 +4269,9 @@ var init_postgres = __esm({
|
|
|
4218
4269
|
await withConnectTimeout(
|
|
4219
4270
|
() => {
|
|
4220
4271
|
this.client = typeof this.config === "string" ? new Client({ connectionString: this.config, ...timeoutOption }) : new Client({ ...this.config, ...timeoutOption });
|
|
4272
|
+
this.client.on("error", () => {
|
|
4273
|
+
this.connectionIsDead = true;
|
|
4274
|
+
});
|
|
4221
4275
|
return this.client.connect();
|
|
4222
4276
|
},
|
|
4223
4277
|
budgetMs,
|
|
@@ -4241,6 +4295,52 @@ var init_postgres = __esm({
|
|
|
4241
4295
|
throw new Error("PostgreSQL adapter not connected. Call connect() first.");
|
|
4242
4296
|
}
|
|
4243
4297
|
}
|
|
4298
|
+
// ── Reconnect after a dropped link (parity with the Python master, #236/#242) ──
|
|
4299
|
+
// pg's Client does not reconnect itself: once the server drops the link it must
|
|
4300
|
+
// be rebuilt. A statement that hits a dropped link reconnects and retries once
|
|
4301
|
+
// when nothing uncommitted went down with it; inside an explicit transaction the
|
|
4302
|
+
// error surfaces. A reconnect that itself fails leaves the link dead (not null-
|
|
4303
|
+
// guarded away), so the NEXT statement retries and recovers once a server returns.
|
|
4304
|
+
connectionIsDead = false;
|
|
4305
|
+
isConnectionError(e) {
|
|
4306
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
4307
|
+
return /connection terminated|terminating connection|server closed the connection|encountered a connection error|connection closed|not queryable|ECONNRESET|EPIPE|socket hang up/i.test(msg);
|
|
4308
|
+
}
|
|
4309
|
+
async reconnect() {
|
|
4310
|
+
void Promise.resolve(this.client?.end()).catch(() => {
|
|
4311
|
+
});
|
|
4312
|
+
this.client = null;
|
|
4313
|
+
this.connectionIsDead = false;
|
|
4314
|
+
await this.connect();
|
|
4315
|
+
}
|
|
4316
|
+
async ensureLiveConnection() {
|
|
4317
|
+
if (!this._inTransaction && (this.client === null || this.connectionIsDead)) {
|
|
4318
|
+
await this.reconnect();
|
|
4319
|
+
}
|
|
4320
|
+
}
|
|
4321
|
+
async runQuery(sql, params) {
|
|
4322
|
+
await this.ensureLiveConnection();
|
|
4323
|
+
this.ensureConnected();
|
|
4324
|
+
try {
|
|
4325
|
+
return await this.client.query(sql, params);
|
|
4326
|
+
} catch (e) {
|
|
4327
|
+
if (!this.isConnectionError(e)) throw e;
|
|
4328
|
+
this.connectionIsDead = true;
|
|
4329
|
+
if (this._inTransaction) throw e;
|
|
4330
|
+
await this.reconnect();
|
|
4331
|
+
return await this.client.query(sql, params);
|
|
4332
|
+
}
|
|
4333
|
+
}
|
|
4334
|
+
// Transaction control (BEGIN/COMMIT/ROLLBACK) runs RAW - no reconnect, no
|
|
4335
|
+
// pre-heal. A failed BEGIN/COMMIT/ROLLBACK must surface so the connection-pool
|
|
4336
|
+
// layer can discard the connection and restore capacity; reconnecting or
|
|
4337
|
+
// retrying here would mask that failure (databasePoolIsolation contract).
|
|
4338
|
+
// Dropped-link recovery stays on the DATA path (runQuery): the next data
|
|
4339
|
+
// statement heals the link.
|
|
4340
|
+
async rawQuery(sql) {
|
|
4341
|
+
this.ensureConnected();
|
|
4342
|
+
await this.client.query(sql);
|
|
4343
|
+
}
|
|
4244
4344
|
/** Convert ? placeholders to $1, $2, ... for pg. */
|
|
4245
4345
|
/** Ensure bytea columns are Buffer (already the case with pg). No-op guard. */
|
|
4246
4346
|
decodeBlobs(row) {
|
|
@@ -4290,7 +4390,6 @@ var init_postgres = __esm({
|
|
|
4290
4390
|
return null;
|
|
4291
4391
|
}
|
|
4292
4392
|
execute(sql, params) {
|
|
4293
|
-
this.ensureConnected();
|
|
4294
4393
|
const convertedSql = this.convertPlaceholders(sql);
|
|
4295
4394
|
throw new Error("Use executeAsync() for PostgreSQL \u2014 async adapter requires async methods.");
|
|
4296
4395
|
}
|
|
@@ -4325,9 +4424,8 @@ var init_postgres = __esm({
|
|
|
4325
4424
|
}
|
|
4326
4425
|
/** Async execute for real usage. */
|
|
4327
4426
|
async executeAsync(sql, params) {
|
|
4328
|
-
this.ensureConnected();
|
|
4329
4427
|
const convertedSql = this.bindable(sql, params);
|
|
4330
|
-
const result = await this.
|
|
4428
|
+
const result = await this.runQuery(convertedSql, params);
|
|
4331
4429
|
if (result.rows?.[0]?.id !== void 0) {
|
|
4332
4430
|
this._lastInsertId = this.normalizeId(result.rows[0].id);
|
|
4333
4431
|
}
|
|
@@ -4338,9 +4436,8 @@ var init_postgres = __esm({
|
|
|
4338
4436
|
}
|
|
4339
4437
|
/** Async query for real usage. */
|
|
4340
4438
|
async queryAsync(sql, params) {
|
|
4341
|
-
this.ensureConnected();
|
|
4342
4439
|
const convertedSql = this.bindable(sql, params);
|
|
4343
|
-
const result = await this.
|
|
4440
|
+
const result = await this.runQuery(convertedSql, params);
|
|
4344
4441
|
return result.rows.map((row) => this.decodeBlobs(row));
|
|
4345
4442
|
}
|
|
4346
4443
|
fetch(sql, params, limit, skip) {
|
|
@@ -4368,7 +4465,6 @@ var init_postgres = __esm({
|
|
|
4368
4465
|
throw new Error("Use insertAsync() for PostgreSQL.");
|
|
4369
4466
|
}
|
|
4370
4467
|
async insertAsync(table2, data) {
|
|
4371
|
-
this.ensureConnected();
|
|
4372
4468
|
if (Array.isArray(data)) {
|
|
4373
4469
|
const batch = buildInsertRows(ANSI_DIALECT, table2, data);
|
|
4374
4470
|
if (!batch) return { success: true, affectedRows: 0 };
|
|
@@ -4382,7 +4478,7 @@ var init_postgres = __esm({
|
|
|
4382
4478
|
}
|
|
4383
4479
|
const { sql, values } = buildInsertRow(POSTGRES_DIALECT, table2, data, " RETURNING *");
|
|
4384
4480
|
try {
|
|
4385
|
-
const result = await this.
|
|
4481
|
+
const result = await this.runQuery(sql, values);
|
|
4386
4482
|
const insertedRow = result.rows[0];
|
|
4387
4483
|
const id = this.normalizeId(insertedRow?.id);
|
|
4388
4484
|
if (id !== null) this._lastInsertId = id;
|
|
@@ -4399,13 +4495,12 @@ var init_postgres = __esm({
|
|
|
4399
4495
|
throw new Error("Use updateAsync() for PostgreSQL.");
|
|
4400
4496
|
}
|
|
4401
4497
|
async updateAsync(table2, data, filter, params) {
|
|
4402
|
-
this.ensureConnected();
|
|
4403
4498
|
const { sql, values } = buildUpdate(POSTGRES_DIALECT, table2, data, filter, params, {
|
|
4404
4499
|
startAt: 1,
|
|
4405
4500
|
convertFragment: (fragment, startAt) => this.convertPlaceholders(fragment, startAt)
|
|
4406
4501
|
});
|
|
4407
4502
|
try {
|
|
4408
|
-
const result = await this.
|
|
4503
|
+
const result = await this.runQuery(sql, values);
|
|
4409
4504
|
return { success: true, affectedRows: result.rowCount ?? 0 };
|
|
4410
4505
|
} catch (e) {
|
|
4411
4506
|
return { success: false, affectedRows: 0, error: e.message };
|
|
@@ -4415,13 +4510,12 @@ var init_postgres = __esm({
|
|
|
4415
4510
|
throw new Error("Use deleteAsync() for PostgreSQL.");
|
|
4416
4511
|
}
|
|
4417
4512
|
async deleteAsync(table2, filter, params) {
|
|
4418
|
-
this.ensureConnected();
|
|
4419
4513
|
const { sql, values } = buildDelete(POSTGRES_DIALECT, table2, filter, params, {
|
|
4420
4514
|
startAt: 1,
|
|
4421
4515
|
convertFragment: (fragment) => this.bindable(fragment, params)
|
|
4422
4516
|
});
|
|
4423
4517
|
try {
|
|
4424
|
-
const result = await this.
|
|
4518
|
+
const result = await this.runQuery(sql, values);
|
|
4425
4519
|
return { success: true, affectedRows: result.rowCount ?? 0 };
|
|
4426
4520
|
} catch (e) {
|
|
4427
4521
|
return { success: false, affectedRows: 0, error: e.message };
|
|
@@ -4431,22 +4525,28 @@ var init_postgres = __esm({
|
|
|
4431
4525
|
throw new Error("Use startTransactionAsync() for PostgreSQL.");
|
|
4432
4526
|
}
|
|
4433
4527
|
async startTransactionAsync() {
|
|
4434
|
-
await this.
|
|
4528
|
+
await this.rawQuery("BEGIN");
|
|
4435
4529
|
this._inTransaction = true;
|
|
4436
4530
|
}
|
|
4437
4531
|
commit() {
|
|
4438
4532
|
throw new Error("Use commitAsync() for PostgreSQL.");
|
|
4439
4533
|
}
|
|
4440
4534
|
async commitAsync() {
|
|
4441
|
-
|
|
4442
|
-
|
|
4535
|
+
try {
|
|
4536
|
+
await this.rawQuery("COMMIT");
|
|
4537
|
+
} finally {
|
|
4538
|
+
this._inTransaction = false;
|
|
4539
|
+
}
|
|
4443
4540
|
}
|
|
4444
4541
|
rollback() {
|
|
4445
4542
|
throw new Error("Use rollbackAsync() for PostgreSQL.");
|
|
4446
4543
|
}
|
|
4447
4544
|
async rollbackAsync() {
|
|
4448
|
-
|
|
4449
|
-
|
|
4545
|
+
try {
|
|
4546
|
+
await this.rawQuery("ROLLBACK");
|
|
4547
|
+
} finally {
|
|
4548
|
+
this._inTransaction = false;
|
|
4549
|
+
}
|
|
4450
4550
|
}
|
|
4451
4551
|
getTables() {
|
|
4452
4552
|
throw new Error("Use tablesAsync() for PostgreSQL.");
|
|
@@ -7273,7 +7373,7 @@ __export(database_exports, {
|
|
|
7273
7373
|
import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
|
|
7274
7374
|
function stripTrailingSemicolons(sql) {
|
|
7275
7375
|
if (!sql) return sql;
|
|
7276
|
-
let stripped = sql.
|
|
7376
|
+
let stripped = sql.trimEnd();
|
|
7277
7377
|
while (stripped.endsWith(";")) {
|
|
7278
7378
|
stripped = stripped.slice(0, -1).replace(/\s+$/, "");
|
|
7279
7379
|
}
|
|
@@ -7440,6 +7540,13 @@ async function createAdapterFromUrl(url, username, password) {
|
|
|
7440
7540
|
}
|
|
7441
7541
|
async function buildAdapterFromUrl(url, username, password) {
|
|
7442
7542
|
const parsed = parseDatabaseUrl(url, username, password);
|
|
7543
|
+
const serverConfig = {
|
|
7544
|
+
host: parsed.host ?? void 0,
|
|
7545
|
+
port: parsed.port ?? void 0,
|
|
7546
|
+
user: parsed.username ?? void 0,
|
|
7547
|
+
password: parsed.password ?? void 0,
|
|
7548
|
+
database: parsed.database || void 0
|
|
7549
|
+
};
|
|
7443
7550
|
switch (parsed.engine) {
|
|
7444
7551
|
case "sqlite": {
|
|
7445
7552
|
const { SQLiteAdapter: SQLiteAdapter2 } = await Promise.resolve().then(() => (init_sqlite(), sqlite_exports));
|
|
@@ -7447,49 +7554,25 @@ async function buildAdapterFromUrl(url, username, password) {
|
|
|
7447
7554
|
}
|
|
7448
7555
|
case "postgres": {
|
|
7449
7556
|
const { PostgresAdapter: PostgresAdapter2 } = await Promise.resolve().then(() => (init_postgres(), postgres_exports));
|
|
7450
|
-
const adapter = new PostgresAdapter2(
|
|
7451
|
-
host: parsed.host ?? void 0,
|
|
7452
|
-
port: parsed.port ?? void 0,
|
|
7453
|
-
user: parsed.username ?? void 0,
|
|
7454
|
-
password: parsed.password ?? void 0,
|
|
7455
|
-
database: parsed.database || void 0
|
|
7456
|
-
});
|
|
7557
|
+
const adapter = new PostgresAdapter2(serverConfig);
|
|
7457
7558
|
await adapter.connect();
|
|
7458
7559
|
return adapter;
|
|
7459
7560
|
}
|
|
7460
7561
|
case "mysql": {
|
|
7461
7562
|
const { MysqlAdapter: MysqlAdapter2 } = await Promise.resolve().then(() => (init_mysql(), mysql_exports));
|
|
7462
|
-
const adapter = new MysqlAdapter2(
|
|
7463
|
-
host: parsed.host ?? void 0,
|
|
7464
|
-
port: parsed.port ?? void 0,
|
|
7465
|
-
user: parsed.username ?? void 0,
|
|
7466
|
-
password: parsed.password ?? void 0,
|
|
7467
|
-
database: parsed.database || void 0
|
|
7468
|
-
});
|
|
7563
|
+
const adapter = new MysqlAdapter2(serverConfig);
|
|
7469
7564
|
await adapter.connect();
|
|
7470
7565
|
return adapter;
|
|
7471
7566
|
}
|
|
7472
7567
|
case "mssql": {
|
|
7473
7568
|
const { MssqlAdapter: MssqlAdapter2 } = await Promise.resolve().then(() => (init_mssql(), mssql_exports));
|
|
7474
|
-
const adapter = new MssqlAdapter2(
|
|
7475
|
-
host: parsed.host ?? void 0,
|
|
7476
|
-
port: parsed.port ?? void 0,
|
|
7477
|
-
user: parsed.username ?? void 0,
|
|
7478
|
-
password: parsed.password ?? void 0,
|
|
7479
|
-
database: parsed.database || void 0
|
|
7480
|
-
});
|
|
7569
|
+
const adapter = new MssqlAdapter2(serverConfig);
|
|
7481
7570
|
await adapter.connect();
|
|
7482
7571
|
return adapter;
|
|
7483
7572
|
}
|
|
7484
7573
|
case "firebird": {
|
|
7485
7574
|
const { FirebirdAdapter: FirebirdAdapter2 } = await Promise.resolve().then(() => (init_firebird(), firebird_exports));
|
|
7486
|
-
const adapter = new FirebirdAdapter2(
|
|
7487
|
-
host: parsed.host ?? void 0,
|
|
7488
|
-
port: parsed.port ?? void 0,
|
|
7489
|
-
user: parsed.username ?? void 0,
|
|
7490
|
-
password: parsed.password ?? void 0,
|
|
7491
|
-
database: parsed.database || void 0
|
|
7492
|
-
});
|
|
7575
|
+
const adapter = new FirebirdAdapter2(serverConfig);
|
|
7493
7576
|
await adapter.connect();
|
|
7494
7577
|
return adapter;
|
|
7495
7578
|
}
|
|
@@ -10225,9 +10308,11 @@ __export(engine_exports, {
|
|
|
10225
10308
|
escapeHtml: () => escapeHtml,
|
|
10226
10309
|
expressionFormCache: () => expressionFormCache,
|
|
10227
10310
|
filterChainCache: () => filterChainCache,
|
|
10311
|
+
frondRange: () => frondRange,
|
|
10228
10312
|
pathParseCache: () => pathParseCache,
|
|
10229
10313
|
setCspNonceProvider: () => setCspNonceProvider,
|
|
10230
|
-
setFormTokenSessionId: () => setFormTokenSessionId
|
|
10314
|
+
setFormTokenSessionId: () => setFormTokenSessionId,
|
|
10315
|
+
setFormTokenSessionProvider: () => setFormTokenSessionProvider
|
|
10231
10316
|
});
|
|
10232
10317
|
import { createHash as createHash3, createHmac as createHmac2, randomBytes as randomBytes2 } from "node:crypto";
|
|
10233
10318
|
import { readFileSync as readFileSync4, existsSync as existsSync6, statSync as statSync4, realpathSync } from "node:fs";
|
|
@@ -10312,6 +10397,14 @@ function renderDump(value) {
|
|
|
10312
10397
|
const escaped = dumped.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
10313
10398
|
return new SafeString(`<pre>${escaped}</pre>`);
|
|
10314
10399
|
}
|
|
10400
|
+
function stripTags(input) {
|
|
10401
|
+
let s = input, prev;
|
|
10402
|
+
do {
|
|
10403
|
+
prev = s;
|
|
10404
|
+
s = s.replace(STRIP_TAGS_RE, "");
|
|
10405
|
+
} while (s !== prev);
|
|
10406
|
+
return s;
|
|
10407
|
+
}
|
|
10315
10408
|
function liveAttr(value) {
|
|
10316
10409
|
return String(value).replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
10317
10410
|
}
|
|
@@ -10329,35 +10422,58 @@ function sweepExpiredCache(cache) {
|
|
|
10329
10422
|
if (expiresAt2 <= now) cache.delete(key);
|
|
10330
10423
|
}
|
|
10331
10424
|
}
|
|
10332
|
-
function
|
|
10425
|
+
function extractRawBlocks(source) {
|
|
10333
10426
|
const rawBlocks = [];
|
|
10334
|
-
|
|
10427
|
+
let out = "";
|
|
10428
|
+
let pos = 0;
|
|
10429
|
+
RAW_OPEN_RE.lastIndex = 0;
|
|
10430
|
+
let om;
|
|
10431
|
+
while ((om = RAW_OPEN_RE.exec(source)) !== null) {
|
|
10432
|
+
const openStart = om.index;
|
|
10433
|
+
const openEnd = RAW_OPEN_RE.lastIndex;
|
|
10434
|
+
RAW_CLOSE_RE.lastIndex = openEnd;
|
|
10435
|
+
const cm = RAW_CLOSE_RE.exec(source);
|
|
10436
|
+
if (cm === null) break;
|
|
10335
10437
|
const idx = rawBlocks.length;
|
|
10336
|
-
rawBlocks.push(
|
|
10337
|
-
|
|
10338
|
-
|
|
10438
|
+
rawBlocks.push(source.slice(openEnd, cm.index));
|
|
10439
|
+
out += source.slice(pos, openStart) + `\0RAW_${idx}\0`;
|
|
10440
|
+
pos = RAW_CLOSE_RE.lastIndex;
|
|
10441
|
+
RAW_OPEN_RE.lastIndex = pos;
|
|
10442
|
+
}
|
|
10443
|
+
out += source.slice(pos);
|
|
10444
|
+
return { source: out, rawBlocks };
|
|
10445
|
+
}
|
|
10446
|
+
function tokenize(rawSource) {
|
|
10447
|
+
const { source, rawBlocks } = extractRawBlocks(rawSource);
|
|
10339
10448
|
const tokens = [];
|
|
10449
|
+
const n = source.length;
|
|
10340
10450
|
let pos = 0;
|
|
10341
|
-
|
|
10342
|
-
|
|
10343
|
-
while (
|
|
10344
|
-
const
|
|
10345
|
-
if (
|
|
10346
|
-
|
|
10451
|
+
let scan = 0;
|
|
10452
|
+
const exhausted = { "%}": false, "}}": false, "#}": false };
|
|
10453
|
+
while (scan < n) {
|
|
10454
|
+
const brace = source.indexOf("{", scan);
|
|
10455
|
+
if (brace === -1) break;
|
|
10456
|
+
const kind = TAG_KINDS[source[brace + 1]];
|
|
10457
|
+
if (!kind) {
|
|
10458
|
+
scan = brace + 1;
|
|
10459
|
+
continue;
|
|
10347
10460
|
}
|
|
10348
|
-
|
|
10349
|
-
|
|
10350
|
-
|
|
10351
|
-
} else if (raw.startsWith("{{")) {
|
|
10352
|
-
tokens.push(["VAR", raw]);
|
|
10353
|
-
} else if (raw.startsWith("{%")) {
|
|
10354
|
-
tokens.push(["BLOCK", raw]);
|
|
10461
|
+
if (exhausted[kind.close]) {
|
|
10462
|
+
scan = brace + 1;
|
|
10463
|
+
continue;
|
|
10355
10464
|
}
|
|
10356
|
-
|
|
10357
|
-
|
|
10358
|
-
|
|
10359
|
-
|
|
10465
|
+
const close = source.indexOf(kind.close, brace + 2);
|
|
10466
|
+
if (close === -1) {
|
|
10467
|
+
exhausted[kind.close] = true;
|
|
10468
|
+
scan = brace + 1;
|
|
10469
|
+
continue;
|
|
10470
|
+
}
|
|
10471
|
+
if (brace > pos) tokens.push(["TEXT", source.slice(pos, brace)]);
|
|
10472
|
+
tokens.push([kind.type, source.slice(brace, close + 2)]);
|
|
10473
|
+
pos = close + 2;
|
|
10474
|
+
scan = close + 2;
|
|
10360
10475
|
}
|
|
10476
|
+
if (pos < n) tokens.push(["TEXT", source.slice(pos)]);
|
|
10361
10477
|
if (rawBlocks.length > 0) {
|
|
10362
10478
|
for (let i = 0; i < tokens.length; i++) {
|
|
10363
10479
|
if (tokens[i][0] === "TEXT" && tokens[i][1].includes("\0RAW_")) {
|
|
@@ -10683,26 +10799,123 @@ function evalConcatOrComparison(expr, context) {
|
|
|
10683
10799
|
}
|
|
10684
10800
|
return EXPR_NOT_MATCHED;
|
|
10685
10801
|
}
|
|
10802
|
+
function topLevelPositions(expr) {
|
|
10803
|
+
const positions = [];
|
|
10804
|
+
let inQuote = null;
|
|
10805
|
+
let depth = 0;
|
|
10806
|
+
for (let pos = 0; pos < expr.length; pos++) {
|
|
10807
|
+
const ch = expr[pos];
|
|
10808
|
+
if (inQuote) {
|
|
10809
|
+
if (ch === inQuote) inQuote = null;
|
|
10810
|
+
} else if (ch === '"' || ch === "'") {
|
|
10811
|
+
inQuote = ch;
|
|
10812
|
+
} else if ("([{".includes(ch)) {
|
|
10813
|
+
depth++;
|
|
10814
|
+
} else if (")]}".includes(ch)) {
|
|
10815
|
+
depth--;
|
|
10816
|
+
} else if (depth === 0) {
|
|
10817
|
+
positions.push(pos);
|
|
10818
|
+
}
|
|
10819
|
+
}
|
|
10820
|
+
return positions;
|
|
10821
|
+
}
|
|
10822
|
+
function followsOperand(expr, pos) {
|
|
10823
|
+
return /[\w)\]'"]$/.test(expr.slice(0, pos).trimEnd());
|
|
10824
|
+
}
|
|
10825
|
+
function topLevelArithmeticOperators(expr) {
|
|
10826
|
+
const operators = [];
|
|
10827
|
+
let skipUntil = -1;
|
|
10828
|
+
for (const pos of topLevelPositions(expr)) {
|
|
10829
|
+
if (pos < skipUntil || !"+-*/%".includes(expr[pos])) continue;
|
|
10830
|
+
const pair = expr.slice(pos, pos + 2);
|
|
10831
|
+
const op = pair === "**" || pair === "//" ? pair : expr[pos];
|
|
10832
|
+
skipUntil = pos + op.length;
|
|
10833
|
+
if (followsOperand(expr, pos)) operators.push([pos, op]);
|
|
10834
|
+
}
|
|
10835
|
+
return operators;
|
|
10836
|
+
}
|
|
10837
|
+
function splitArithmetic(expr) {
|
|
10838
|
+
const operators = topLevelArithmeticOperators(expr);
|
|
10839
|
+
for (const level of ARITHMETIC_LEVELS) {
|
|
10840
|
+
const matches = operators.filter(([, op]) => level.includes(op));
|
|
10841
|
+
if (matches.length > 0) return level[0] === "**" ? matches[0] : matches[matches.length - 1];
|
|
10842
|
+
}
|
|
10843
|
+
return null;
|
|
10844
|
+
}
|
|
10686
10845
|
function evalArithmeticExpression(expr, context) {
|
|
10687
|
-
|
|
10688
|
-
|
|
10689
|
-
|
|
10690
|
-
|
|
10691
|
-
|
|
10692
|
-
|
|
10693
|
-
|
|
10694
|
-
|
|
10695
|
-
|
|
10696
|
-
|
|
10697
|
-
|
|
10698
|
-
|
|
10699
|
-
|
|
10700
|
-
|
|
10701
|
-
|
|
10702
|
-
|
|
10846
|
+
const split = splitArithmetic(expr);
|
|
10847
|
+
if (!split) return EXPR_NOT_MATCHED;
|
|
10848
|
+
const [pos, op] = split;
|
|
10849
|
+
const lVal = evalExpr(expr.slice(0, pos).trim(), context);
|
|
10850
|
+
const rVal = evalExpr(expr.slice(pos + op.length).trim(), context);
|
|
10851
|
+
let lNum = lVal != null ? Number(lVal) : 0;
|
|
10852
|
+
let rNum = rVal != null ? Number(rVal) : 0;
|
|
10853
|
+
if (isNaN(lNum)) lNum = 0;
|
|
10854
|
+
if (isNaN(rNum)) rNum = 0;
|
|
10855
|
+
return ARITHMETIC_OPERATIONS[op](lNum, rNum);
|
|
10856
|
+
}
|
|
10857
|
+
function frondRange(start2, end, step = 1) {
|
|
10858
|
+
const numeric = (value) => typeof value === "number" || typeof value === "string" && NUMERIC_RE.test(value);
|
|
10859
|
+
if (!numeric(start2) || !numeric(end) || !numeric(step)) return [];
|
|
10860
|
+
const first = Math.trunc(Number(start2));
|
|
10861
|
+
const last = Math.trunc(Number(end));
|
|
10862
|
+
const stride = Math.abs(Math.trunc(Number(step)));
|
|
10863
|
+
if (stride === 0) return [];
|
|
10864
|
+
const values = [];
|
|
10865
|
+
if (first <= last) for (let value = first; value <= last; value += stride) values.push(value);
|
|
10866
|
+
else for (let value = first; value >= last; value -= stride) values.push(value);
|
|
10867
|
+
return values;
|
|
10868
|
+
}
|
|
10869
|
+
function findRangeOperator(expr) {
|
|
10870
|
+
let pos = findOutsideQuotes(expr, "..");
|
|
10871
|
+
while (pos >= 0) {
|
|
10872
|
+
const partOfEllipsis = expr.startsWith("...", pos) || pos > 0 && expr[pos - 1] === ".";
|
|
10873
|
+
if (pos > 0 && !partOfEllipsis) return findOutsideQuotes(expr.slice(pos + 2), "|") >= 0 ? -1 : pos;
|
|
10874
|
+
const next = findOutsideQuotes(expr.slice(pos + 2), "..");
|
|
10875
|
+
pos = next >= 0 ? pos + 2 + next : -1;
|
|
10876
|
+
}
|
|
10877
|
+
return -1;
|
|
10878
|
+
}
|
|
10879
|
+
function evalRangeExpression(expr, context) {
|
|
10880
|
+
const pos = findRangeOperator(expr);
|
|
10881
|
+
if (pos < 0) return EXPR_NOT_MATCHED;
|
|
10882
|
+
return frondRange(evalExpr(expr.slice(0, pos).trim(), context), evalExpr(expr.slice(pos + 2).trim(), context));
|
|
10883
|
+
}
|
|
10884
|
+
function closingBracketIndex(expr) {
|
|
10885
|
+
let depth = 0;
|
|
10886
|
+
let inQuote = null;
|
|
10887
|
+
for (let i = 0; i < expr.length; i++) {
|
|
10888
|
+
const ch = expr[i];
|
|
10889
|
+
if (inQuote) {
|
|
10890
|
+
if (ch === inQuote) inQuote = null;
|
|
10891
|
+
} else if (ch === '"' || ch === "'") {
|
|
10892
|
+
inQuote = ch;
|
|
10893
|
+
} else if ("([{".includes(ch)) {
|
|
10894
|
+
depth++;
|
|
10895
|
+
} else if (")]}".includes(ch) && --depth === 0) {
|
|
10896
|
+
return i;
|
|
10703
10897
|
}
|
|
10704
10898
|
}
|
|
10705
|
-
return
|
|
10899
|
+
return -1;
|
|
10900
|
+
}
|
|
10901
|
+
function mapLiteralKey(rawKey, context) {
|
|
10902
|
+
const quoted = rawKey.length >= 2 && (rawKey[0] === '"' || rawKey[0] === "'") && rawKey.endsWith(rawKey[0]);
|
|
10903
|
+
if (quoted) return rawKey.slice(1, -1);
|
|
10904
|
+
return BARE_KEY_RE.test(rawKey) ? rawKey : String(evalExpr(rawKey, context));
|
|
10905
|
+
}
|
|
10906
|
+
function evalMapLiteral(inner, context) {
|
|
10907
|
+
const map = {};
|
|
10908
|
+
for (const pair of inner === "" ? [] : splitArgs(inner)) {
|
|
10909
|
+
const colon = findOutsideQuotes(pair, ":");
|
|
10910
|
+
if (colon > 0) map[mapLiteralKey(pair.slice(0, colon).trim(), context)] = evalExpr(pair.slice(colon + 1).trim(), context);
|
|
10911
|
+
}
|
|
10912
|
+
return map;
|
|
10913
|
+
}
|
|
10914
|
+
function evalCollectionLiteral(expr, context) {
|
|
10915
|
+
if (expr[0] !== "[" && expr[0] !== "{" || closingBracketIndex(expr) !== expr.length - 1) return EXPR_NOT_MATCHED;
|
|
10916
|
+
const inner = expr.slice(1, -1).trim();
|
|
10917
|
+
if (expr[0] === "{") return evalMapLiteral(inner, context);
|
|
10918
|
+
return inner === "" ? [] : splitArgs(inner).map((item) => evalExpr(item.trim(), context));
|
|
10706
10919
|
}
|
|
10707
10920
|
function evalFilterExpression(expr, context) {
|
|
10708
10921
|
if (findOutsideQuotes(expr, "|") >= 0) {
|
|
@@ -11124,12 +11337,12 @@ function splitArgs(raw) {
|
|
|
11124
11337
|
current += ch;
|
|
11125
11338
|
continue;
|
|
11126
11339
|
}
|
|
11127
|
-
if (ch === "(" || ch === "[") {
|
|
11340
|
+
if (ch === "(" || ch === "[" || ch === "{") {
|
|
11128
11341
|
depth++;
|
|
11129
11342
|
current += ch;
|
|
11130
11343
|
continue;
|
|
11131
11344
|
}
|
|
11132
|
-
if (ch === ")" || ch === "]") {
|
|
11345
|
+
if (ch === ")" || ch === "]" || ch === "}") {
|
|
11133
11346
|
depth--;
|
|
11134
11347
|
current += ch;
|
|
11135
11348
|
continue;
|
|
@@ -11294,11 +11507,14 @@ function formatMatch(match, flags, width, prec, type2, arg) {
|
|
|
11294
11507
|
return padFormattedValue(formatValue(type2, precision, arg), flags, width);
|
|
11295
11508
|
}
|
|
11296
11509
|
function _b64url(data) {
|
|
11297
|
-
return data.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(
|
|
11510
|
+
return data.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/={1,2}$/, "");
|
|
11298
11511
|
}
|
|
11299
11512
|
function setFormTokenSessionId(sessionId) {
|
|
11300
11513
|
_formTokenSessionId = sessionId || "";
|
|
11301
11514
|
}
|
|
11515
|
+
function setFormTokenSessionProvider(fn) {
|
|
11516
|
+
_formTokenSessionProvider = fn;
|
|
11517
|
+
}
|
|
11302
11518
|
function setCspNonceProvider(fn) {
|
|
11303
11519
|
_cspNonceProvider = fn;
|
|
11304
11520
|
}
|
|
@@ -11323,8 +11539,9 @@ function _buildFormTokenJwt(descriptor = "") {
|
|
|
11323
11539
|
payload.context = descriptor;
|
|
11324
11540
|
}
|
|
11325
11541
|
}
|
|
11326
|
-
|
|
11327
|
-
|
|
11542
|
+
const sessionId = _formTokenSessionProvider() || _formTokenSessionId;
|
|
11543
|
+
if (sessionId) {
|
|
11544
|
+
payload.session_id = sessionId;
|
|
11328
11545
|
}
|
|
11329
11546
|
const h2 = _b64url(Buffer.from(JSON.stringify(header)));
|
|
11330
11547
|
const p = _b64url(Buffer.from(JSON.stringify(payload)));
|
|
@@ -11340,7 +11557,7 @@ function _generateFormToken(descriptor = "") {
|
|
|
11340
11557
|
function _generateFormTokenValue(descriptor = "") {
|
|
11341
11558
|
return new SafeString(_buildFormTokenJwt(descriptor));
|
|
11342
11559
|
}
|
|
11343
|
-
var SafeString, KNOWN_TAGS, TERMINATOR_TAGS, GATEABLE_TAGS, BLOCK_TAG_ENDS, JSON_UNSAFE_RE, JSON_UNSAFE_MAP, NUMERIC_RE, METHOD_CALL_RE, FN_CALL_RE, IS_NOT_RE, IS_RE, NOT_IN_RE, IN_RE, DIVISIBLE_BY_RE, FILTER_WITH_ARGS_RE, FILTER_COMPARISON_RE, TITLE_WORD_RE, STRIP_TAGS_RE, FAST_FILTERS, FORMAT_RE,
|
|
11560
|
+
var SafeString, KNOWN_TAGS, TERMINATOR_TAGS, GATEABLE_TAGS, BLOCK_TAG_ENDS, JSON_UNSAFE_RE, JSON_UNSAFE_MAP, NUMERIC_RE, METHOD_CALL_RE, FN_CALL_RE, IS_NOT_RE, IS_RE, NOT_IN_RE, IN_RE, DIVISIBLE_BY_RE, FILTER_WITH_ARGS_RE, FILTER_COMPARISON_RE, TITLE_WORD_RE, STRIP_TAGS_RE, FAST_FILTERS, FORMAT_RE, THOUSANDS_RE, LIVE_RE, LIVE_WS_RE, LIVE_SRC_RE, EXTENDS_RE, EXTENDS_RE_GLOBAL, filterChainCache, pathParseCache, TEMPLATE_CACHE_MAX, MEMO_CACHE_MAX, RAW_OPEN_RE, RAW_CLOSE_RE, TAG_KINDS, EXPR_NOT_MATCHED, ARITHMETIC_OPERATIONS, ARITHMETIC_LEVELS, BARE_KEY_RE, EXPR_EVALUATORS, expressionFormCache, VarRef, JS_SAFE_RE, MEDIA_TYPE_RE, SANDBOX_EXPR_KEYWORDS, SANDBOX_IDENT_RE, SANDBOX_STRING_RE, UNSAFE_KEYS, BUILTIN_FILTERS, _formTokenSessionId, _formTokenSessionProvider, _cspNonceProvider, Frond;
|
|
11344
11561
|
var init_engine = __esm({
|
|
11345
11562
|
"../frond/src/engine.ts"() {
|
|
11346
11563
|
"use strict";
|
|
@@ -11442,7 +11659,7 @@ var init_engine = __esm({
|
|
|
11442
11659
|
int: (value) => value ? parseInt(String(value), 10) || 0 : 0,
|
|
11443
11660
|
float: (value) => value ? parseFloat(String(value)) || 0 : 0,
|
|
11444
11661
|
abs: (value) => typeof value === "number" ? Math.abs(value) : value,
|
|
11445
|
-
striptags: (value) => String(value)
|
|
11662
|
+
striptags: (value) => stripTags(String(value)),
|
|
11446
11663
|
first: (value) => Array.isArray(value) ? value[0] ?? null : null,
|
|
11447
11664
|
last: (value) => Array.isArray(value) ? value[value.length - 1] ?? null : null,
|
|
11448
11665
|
keys: (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? Object.keys(value) : [],
|
|
@@ -11456,20 +11673,23 @@ var init_engine = __esm({
|
|
|
11456
11673
|
filter: (value) => Array.isArray(value) ? value.filter(Boolean) : value
|
|
11457
11674
|
};
|
|
11458
11675
|
FORMAT_RE = /%%|%([-+ 0]*)(\d+)?(?:\.(\d+))?([sdifFeEgGxXob])/g;
|
|
11459
|
-
LEADING_WS_RE = /^\s+/;
|
|
11460
|
-
TRAILING_WS_RE = /\s+$/;
|
|
11461
11676
|
THOUSANDS_RE = /\B(?=(\d{3})+(?!\d))/g;
|
|
11462
11677
|
LIVE_RE = /^live\s+["']([^"']+)["']([\s\S]*)$/;
|
|
11463
11678
|
LIVE_WS_RE = /ws\s+["']([^"']+)["']/;
|
|
11464
11679
|
LIVE_SRC_RE = /src\s+["']([^"']+)["']/;
|
|
11465
|
-
EXTENDS_RE = /\{%[-\s]*extends\s+["'](
|
|
11466
|
-
EXTENDS_RE_GLOBAL = /\{%[-\s]*extends\s+["'](
|
|
11680
|
+
EXTENDS_RE = /\{%[-\s]*extends\s+["']([^"']+)["']\s*[-]?%\}/;
|
|
11681
|
+
EXTENDS_RE_GLOBAL = /\{%[-\s]*extends\s+["']([^"']+)["']\s*[-]?%\}/g;
|
|
11467
11682
|
filterChainCache = /* @__PURE__ */ new Map();
|
|
11468
11683
|
pathParseCache = /* @__PURE__ */ new Map();
|
|
11469
11684
|
TEMPLATE_CACHE_MAX = 256;
|
|
11470
11685
|
MEMO_CACHE_MAX = 1024;
|
|
11471
|
-
|
|
11472
|
-
|
|
11686
|
+
RAW_OPEN_RE = /\{%-?\s*raw\s*-?%\}/g;
|
|
11687
|
+
RAW_CLOSE_RE = /\{%-?\s*endraw\s*-?%\}/g;
|
|
11688
|
+
TAG_KINDS = {
|
|
11689
|
+
"%": { close: "%}", type: "BLOCK" },
|
|
11690
|
+
"{": { close: "}}", type: "VAR" },
|
|
11691
|
+
"#": { close: "#}", type: "COMMENT" }
|
|
11692
|
+
};
|
|
11473
11693
|
EXPR_NOT_MATCHED = /* @__PURE__ */ Symbol("frond-expression-not-matched");
|
|
11474
11694
|
ARITHMETIC_OPERATIONS = {
|
|
11475
11695
|
"+": (left, right) => left + right,
|
|
@@ -11480,10 +11700,14 @@ var init_engine = __esm({
|
|
|
11480
11700
|
"%": (left, right) => right !== 0 ? left % right : 0,
|
|
11481
11701
|
"**": (left, right) => left ** right
|
|
11482
11702
|
};
|
|
11703
|
+
ARITHMETIC_LEVELS = [["+", "-"], ["*", "//", "/", "%"], ["**"]];
|
|
11704
|
+
BARE_KEY_RE = /^[A-Za-z_]\w*$/;
|
|
11483
11705
|
EXPR_EVALUATORS = [
|
|
11706
|
+
evalCollectionLiteral,
|
|
11484
11707
|
evalPrimary,
|
|
11485
11708
|
evalConditional,
|
|
11486
11709
|
evalConcatOrComparison,
|
|
11710
|
+
evalRangeExpression,
|
|
11487
11711
|
evalArithmeticExpression,
|
|
11488
11712
|
evalFilterExpression,
|
|
11489
11713
|
evalFunctionExpression
|
|
@@ -11539,8 +11763,8 @@ var init_engine = __esm({
|
|
|
11539
11763
|
},
|
|
11540
11764
|
title: (v) => String(v).replace(TITLE_WORD_RE, (c) => c.toUpperCase()),
|
|
11541
11765
|
trim: (v) => String(v).trim(),
|
|
11542
|
-
ltrim: (v) => String(v).
|
|
11543
|
-
rtrim: (v) => String(v).
|
|
11766
|
+
ltrim: (v) => String(v).trimStart(),
|
|
11767
|
+
rtrim: (v) => String(v).trimEnd(),
|
|
11544
11768
|
length: (v) => {
|
|
11545
11769
|
if (Array.isArray(v)) return v.length;
|
|
11546
11770
|
if (typeof v === "string") return v.length;
|
|
@@ -11581,7 +11805,7 @@ var init_engine = __esm({
|
|
|
11581
11805
|
safe: (v) => v,
|
|
11582
11806
|
escape: (v, ...a) => escapeStrategy(v, a[0] ?? "html"),
|
|
11583
11807
|
e: (v, ...a) => escapeStrategy(v, a[0] ?? "html"),
|
|
11584
|
-
striptags: (v) => String(v)
|
|
11808
|
+
striptags: (v) => stripTags(String(v)),
|
|
11585
11809
|
nl2br: (v) => new SafeString(htmlEscape(String(v)).replace(/\n/g, "<br />\n")),
|
|
11586
11810
|
abs: (v) => typeof v === "number" ? Math.abs(v) : v,
|
|
11587
11811
|
round: (v, decimals) => {
|
|
@@ -11694,6 +11918,7 @@ var init_engine = __esm({
|
|
|
11694
11918
|
js_escape: (v) => new SafeString(jsEscape(v))
|
|
11695
11919
|
};
|
|
11696
11920
|
_formTokenSessionId = "";
|
|
11921
|
+
_formTokenSessionProvider = () => "";
|
|
11697
11922
|
_cspNonceProvider = () => "";
|
|
11698
11923
|
Frond = class _Frond {
|
|
11699
11924
|
// ── Class-level registries ──────────────────────────────────
|
|
@@ -11847,6 +12072,7 @@ var init_engine = __esm({
|
|
|
11847
12072
|
this.globals.form_token = (descriptor) => _generateFormToken(descriptor || "");
|
|
11848
12073
|
this.globals.formTokenValue = (descriptor) => _generateFormTokenValue(descriptor || "");
|
|
11849
12074
|
this.globals.form_token_value = (descriptor) => _generateFormTokenValue(descriptor || "");
|
|
12075
|
+
this.globals.range = frondRange;
|
|
11850
12076
|
this.globals.dump = (value) => renderDump(value);
|
|
11851
12077
|
this.globals.csp_nonce = () => _cspNonceProvider();
|
|
11852
12078
|
for (const [k, v] of _Frond.classFilters) this.filters[k] = v;
|
|
@@ -12183,20 +12409,20 @@ var init_engine = __esm({
|
|
|
12183
12409
|
}
|
|
12184
12410
|
renderVarToken(tokens, index, context, output) {
|
|
12185
12411
|
const [content, stripB, stripA] = stripTag(tokens[index][1]);
|
|
12186
|
-
if (stripB && output.length > 0) output[output.length - 1] = output[output.length - 1].
|
|
12412
|
+
if (stripB && output.length > 0) output[output.length - 1] = output[output.length - 1].trimEnd();
|
|
12187
12413
|
const result = this.evalVar(content, context);
|
|
12188
12414
|
output.push(result !== null && result !== void 0 ? String(result) : "");
|
|
12189
12415
|
if (stripA && index + 1 < tokens.length && tokens[index + 1][0] === "TEXT") {
|
|
12190
|
-
tokens[index + 1] = ["TEXT", tokens[index + 1][1].
|
|
12416
|
+
tokens[index + 1] = ["TEXT", tokens[index + 1][1].trimStart()];
|
|
12191
12417
|
}
|
|
12192
12418
|
return index + 1;
|
|
12193
12419
|
}
|
|
12194
12420
|
renderBlockToken(tokens, index, context, output) {
|
|
12195
12421
|
const [content, stripB, stripA] = stripTag(tokens[index][1]);
|
|
12196
|
-
if (stripB && output.length > 0) output[output.length - 1] = output[output.length - 1].
|
|
12422
|
+
if (stripB && output.length > 0) output[output.length - 1] = output[output.length - 1].trimEnd();
|
|
12197
12423
|
const tag = content.split(/\s+/)[0] || "";
|
|
12198
12424
|
if (stripA && index + 1 < tokens.length && tokens[index + 1][0] === "TEXT") {
|
|
12199
|
-
tokens[index + 1] = ["TEXT", tokens[index + 1][1].
|
|
12425
|
+
tokens[index + 1] = ["TEXT", tokens[index + 1][1].trimStart()];
|
|
12200
12426
|
}
|
|
12201
12427
|
let next;
|
|
12202
12428
|
if (tag === "if" && this.tagPermitted(tag)) {
|
|
@@ -12213,7 +12439,7 @@ var init_engine = __esm({
|
|
|
12213
12439
|
next = block.next;
|
|
12214
12440
|
}
|
|
12215
12441
|
if (stripA && next < tokens.length && tokens[next][0] === "TEXT") {
|
|
12216
|
-
tokens[next] = ["TEXT", tokens[next][1].
|
|
12442
|
+
tokens[next] = ["TEXT", tokens[next][1].trimStart()];
|
|
12217
12443
|
}
|
|
12218
12444
|
return next;
|
|
12219
12445
|
}
|
|
@@ -12472,7 +12698,7 @@ var init_engine = __esm({
|
|
|
12472
12698
|
pushIfBranch(branches, condition, branchTokens, stripBefore) {
|
|
12473
12699
|
if (stripBefore && branchTokens.length > 0 && branchTokens[branchTokens.length - 1][0] === "TEXT") {
|
|
12474
12700
|
const last = branchTokens[branchTokens.length - 1];
|
|
12475
|
-
branchTokens[branchTokens.length - 1] = ["TEXT", last[1].
|
|
12701
|
+
branchTokens[branchTokens.length - 1] = ["TEXT", last[1].trimEnd()];
|
|
12476
12702
|
}
|
|
12477
12703
|
branches.push([condition, branchTokens]);
|
|
12478
12704
|
}
|
|
@@ -12500,7 +12726,7 @@ var init_engine = __esm({
|
|
|
12500
12726
|
} else if (tag === "endif") {
|
|
12501
12727
|
this.pushIfBranch(branches, currentCond, currentTokens, tagStripB);
|
|
12502
12728
|
if (tagStripA && i + 1 < tokens.length && tokens[i + 1][0] === "TEXT") {
|
|
12503
|
-
tokens[i + 1] = ["TEXT", tokens[i + 1][1].
|
|
12729
|
+
tokens[i + 1] = ["TEXT", tokens[i + 1][1].trimStart()];
|
|
12504
12730
|
}
|
|
12505
12731
|
return { branches, next: i + 1 };
|
|
12506
12732
|
} else if ((tag === "elseif" || tag === "elif") && depth === 0) {
|
|
@@ -13286,7 +13512,7 @@ function tableData(opts) {
|
|
|
13286
13512
|
readonly: !opts.editable,
|
|
13287
13513
|
inline_script: opts.inlineScript,
|
|
13288
13514
|
table_name: h(opts.tableName),
|
|
13289
|
-
|
|
13515
|
+
table_id: opts.tableId ? String(opts.tableId) : ""
|
|
13290
13516
|
};
|
|
13291
13517
|
}
|
|
13292
13518
|
var init_crudTable = __esm({
|
|
@@ -13394,13 +13620,13 @@ function renderModalForm(mode, columns, pk, edit) {
|
|
|
13394
13620
|
value: "",
|
|
13395
13621
|
placeholder: h(`Enter ${label.toLowerCase()}`),
|
|
13396
13622
|
type: "text",
|
|
13397
|
-
|
|
13623
|
+
required: false,
|
|
13398
13624
|
input: true
|
|
13399
13625
|
};
|
|
13400
13626
|
});
|
|
13401
13627
|
return renderCrudTemplate("form", {
|
|
13402
13628
|
wrap: true,
|
|
13403
|
-
|
|
13629
|
+
form_id: `form-${mode}`,
|
|
13404
13630
|
action: "",
|
|
13405
13631
|
form_method: "POST",
|
|
13406
13632
|
method_override: null,
|
|
@@ -13457,7 +13683,7 @@ function fieldInputShape(field, base) {
|
|
|
13457
13683
|
case "text":
|
|
13458
13684
|
return { ...base, textarea: true };
|
|
13459
13685
|
case "boolean":
|
|
13460
|
-
return { ...base, checkbox: true,
|
|
13686
|
+
return { ...base, checkbox: true, checked: !!value };
|
|
13461
13687
|
case "select":
|
|
13462
13688
|
return { ...base, select: true, options_html: buildOptions(field.options, value) };
|
|
13463
13689
|
case "date":
|
|
@@ -13480,7 +13706,7 @@ function buildCustomField(field) {
|
|
|
13480
13706
|
label: h(String(label)),
|
|
13481
13707
|
value: h(field.value ?? ""),
|
|
13482
13708
|
placeholder: "",
|
|
13483
|
-
|
|
13709
|
+
required: !!field.required
|
|
13484
13710
|
};
|
|
13485
13711
|
return fieldInputShape(field, base);
|
|
13486
13712
|
}
|
|
@@ -13488,7 +13714,7 @@ function generateForm(fields, options = {}) {
|
|
|
13488
13714
|
const verb = String(options.method ?? "POST").toUpperCase();
|
|
13489
13715
|
return renderCrudTemplate("form", {
|
|
13490
13716
|
wrap: true,
|
|
13491
|
-
|
|
13717
|
+
form_id: "",
|
|
13492
13718
|
action: h(options.action ?? "/"),
|
|
13493
13719
|
form_method: h(verb),
|
|
13494
13720
|
method_override: ["PUT", "PATCH", "DELETE"].includes(verb) ? verb : null,
|
|
@@ -16591,6 +16817,12 @@ import { dirname as dirname6, isAbsolute as isAbsolute4, join as join10 } from "
|
|
|
16591
16817
|
function iso(d) {
|
|
16592
16818
|
return d.toISOString();
|
|
16593
16819
|
}
|
|
16820
|
+
function setOwn(obj, key, value) {
|
|
16821
|
+
Object.defineProperty(obj, key, { value, writable: true, enumerable: true, configurable: true });
|
|
16822
|
+
}
|
|
16823
|
+
function getOwn(obj, key) {
|
|
16824
|
+
return Object.hasOwn(obj, key) ? obj[key] : void 0;
|
|
16825
|
+
}
|
|
16594
16826
|
function encodeValue(value) {
|
|
16595
16827
|
if (value instanceof ObjectId) return value.toString();
|
|
16596
16828
|
if (value instanceof Date) return iso(value);
|
|
@@ -16598,7 +16830,7 @@ function encodeValue(value) {
|
|
|
16598
16830
|
if (value !== null && typeof value === "object") {
|
|
16599
16831
|
const out = {};
|
|
16600
16832
|
for (const [k, v] of Object.entries(value)) {
|
|
16601
|
-
out
|
|
16833
|
+
setOwn(out, k, encodeValue(v));
|
|
16602
16834
|
}
|
|
16603
16835
|
return out;
|
|
16604
16836
|
}
|
|
@@ -16617,7 +16849,7 @@ function decodeValue(value) {
|
|
|
16617
16849
|
if (value !== null && typeof value === "object") {
|
|
16618
16850
|
const out = {};
|
|
16619
16851
|
for (const [k, v] of Object.entries(value)) {
|
|
16620
|
-
out
|
|
16852
|
+
setOwn(out, k, decodeValue(v));
|
|
16621
16853
|
}
|
|
16622
16854
|
return out;
|
|
16623
16855
|
}
|
|
@@ -16763,31 +16995,32 @@ function project(doc, projection) {
|
|
|
16763
16995
|
const exclude = new Set(Object.entries(projection).filter(([, v]) => !v).map(([k]) => k));
|
|
16764
16996
|
if (include.size > 0) {
|
|
16765
16997
|
const out2 = {};
|
|
16766
|
-
for (const k of include) if (k
|
|
16998
|
+
for (const k of include) if (Object.hasOwn(doc, k)) setOwn(out2, k, doc[k]);
|
|
16767
16999
|
const idVal = projection._id;
|
|
16768
17000
|
if ((idVal === void 0 || idVal) && "_id" in doc) out2._id = doc._id;
|
|
16769
17001
|
return out2;
|
|
16770
17002
|
}
|
|
16771
17003
|
const out = {};
|
|
16772
|
-
for (const [k, v] of Object.entries(doc)) if (!exclude.has(k)) out
|
|
17004
|
+
for (const [k, v] of Object.entries(doc)) if (!exclude.has(k)) setOwn(out, k, v);
|
|
16773
17005
|
return out;
|
|
16774
17006
|
}
|
|
16775
17007
|
function setPath(doc, dotted, value) {
|
|
16776
17008
|
const parts = dotted.split(".");
|
|
16777
17009
|
let node = doc;
|
|
16778
17010
|
for (const p of parts.slice(0, -1)) {
|
|
16779
|
-
|
|
16780
|
-
|
|
17011
|
+
const child = getOwn(node, p);
|
|
17012
|
+
if (child === void 0 || child === null || typeof child !== "object") {
|
|
17013
|
+
setOwn(node, p, {});
|
|
16781
17014
|
}
|
|
16782
17015
|
node = node[p];
|
|
16783
17016
|
}
|
|
16784
|
-
node
|
|
17017
|
+
setOwn(node, parts[parts.length - 1], value);
|
|
16785
17018
|
}
|
|
16786
17019
|
function unsetPath(doc, dotted) {
|
|
16787
17020
|
const parts = dotted.split(".");
|
|
16788
17021
|
let node = doc;
|
|
16789
17022
|
for (const p of parts.slice(0, -1)) {
|
|
16790
|
-
const next = node
|
|
17023
|
+
const next = getOwn(node, p);
|
|
16791
17024
|
if (next === null || typeof next !== "object") return;
|
|
16792
17025
|
node = next;
|
|
16793
17026
|
}
|
|
@@ -18139,20 +18372,210 @@ var init_attachment = __esm({
|
|
|
18139
18372
|
}
|
|
18140
18373
|
});
|
|
18141
18374
|
|
|
18375
|
+
// ../orm/src/realtime/s3Client.ts
|
|
18376
|
+
import { createHash as createHash4, createHmac as createHmac3 } from "node:crypto";
|
|
18377
|
+
function retryAfterSeconds(raw) {
|
|
18378
|
+
if (raw == null) return null;
|
|
18379
|
+
const n = Number(raw);
|
|
18380
|
+
return Number.isFinite(n) ? Math.max(0, n) : null;
|
|
18381
|
+
}
|
|
18382
|
+
function uriEncode(value, isPath) {
|
|
18383
|
+
let out = "";
|
|
18384
|
+
for (const byte of Buffer.from(value, "utf8")) {
|
|
18385
|
+
const ch = String.fromCharCode(byte);
|
|
18386
|
+
if (UNRESERVED.test(ch) || isPath && ch === "/") out += ch;
|
|
18387
|
+
else out += "%" + byte.toString(16).toUpperCase().padStart(2, "0");
|
|
18388
|
+
}
|
|
18389
|
+
return out;
|
|
18390
|
+
}
|
|
18391
|
+
function sha256Hex2(data) {
|
|
18392
|
+
return createHash4("sha256").update(data).digest("hex");
|
|
18393
|
+
}
|
|
18394
|
+
function hmac(key, msg) {
|
|
18395
|
+
return createHmac3("sha256", key).update(msg, "utf8").digest();
|
|
18396
|
+
}
|
|
18397
|
+
var ALGORITHM, SERVICE, UNRESERVED, MAX_RETRIES, BACKOFF_BASE, BACKOFF_CAP, S3Error, S3ConfigError, sleep, S3Client;
|
|
18398
|
+
var init_s3Client = __esm({
|
|
18399
|
+
"../orm/src/realtime/s3Client.ts"() {
|
|
18400
|
+
"use strict";
|
|
18401
|
+
ALGORITHM = "AWS4-HMAC-SHA256";
|
|
18402
|
+
SERVICE = "s3";
|
|
18403
|
+
UNRESERVED = /[A-Za-z0-9\-_.~]/;
|
|
18404
|
+
MAX_RETRIES = 2;
|
|
18405
|
+
BACKOFF_BASE = 0.5;
|
|
18406
|
+
BACKOFF_CAP = 20;
|
|
18407
|
+
S3Error = class extends Error {
|
|
18408
|
+
constructor(status2, message) {
|
|
18409
|
+
super(message);
|
|
18410
|
+
this.status = status2;
|
|
18411
|
+
this.name = "S3Error";
|
|
18412
|
+
}
|
|
18413
|
+
status;
|
|
18414
|
+
/** Seconds from a Retry-After header in its delta-seconds form, else null. */
|
|
18415
|
+
retryAfter = null;
|
|
18416
|
+
};
|
|
18417
|
+
S3ConfigError = class extends Error {
|
|
18418
|
+
constructor(message) {
|
|
18419
|
+
super(message);
|
|
18420
|
+
this.name = "S3ConfigError";
|
|
18421
|
+
}
|
|
18422
|
+
};
|
|
18423
|
+
sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
18424
|
+
S3Client = class {
|
|
18425
|
+
scheme;
|
|
18426
|
+
host;
|
|
18427
|
+
// authority (host[:port]) — matches the Host header
|
|
18428
|
+
prefix;
|
|
18429
|
+
// path an endpoint carries (https://host/s3 -> "/s3"), "" if none
|
|
18430
|
+
region;
|
|
18431
|
+
accessKey;
|
|
18432
|
+
secretKey;
|
|
18433
|
+
timeout;
|
|
18434
|
+
constructor(opts = {}) {
|
|
18435
|
+
this.region = opts.region || "us-east-1";
|
|
18436
|
+
this.accessKey = opts.accessKey || "";
|
|
18437
|
+
this.secretKey = opts.secretKey || "";
|
|
18438
|
+
this.timeout = opts.timeout ?? 3e4;
|
|
18439
|
+
let base = opts.endpoint || `https://s3.${this.region}.amazonaws.com`;
|
|
18440
|
+
while (base.endsWith("/")) base = base.slice(0, -1);
|
|
18441
|
+
const m = /^([a-z][a-z0-9+.-]*):\/\/([^/]+)(\/.*)?$/i.exec(base);
|
|
18442
|
+
this.scheme = m ? m[1] : "https";
|
|
18443
|
+
this.host = m ? m[2] : base;
|
|
18444
|
+
let p = m && m[3] ? m[3] : "";
|
|
18445
|
+
while (p.endsWith("/")) p = p.slice(0, -1);
|
|
18446
|
+
this.prefix = p;
|
|
18447
|
+
}
|
|
18448
|
+
// -- public API (the subset S3Storage uses) --------------------------------
|
|
18449
|
+
async putObject(bucket, key, data, contentType = "application/octet-stream") {
|
|
18450
|
+
const body = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
|
18451
|
+
await this.request("PUT", this.canonicalUri(bucket, key), body, { "content-type": contentType });
|
|
18452
|
+
}
|
|
18453
|
+
async getObject(bucket, key) {
|
|
18454
|
+
return (await this.request("GET", this.canonicalUri(bucket, key), Buffer.alloc(0))).body;
|
|
18455
|
+
}
|
|
18456
|
+
async deleteObject(bucket, key) {
|
|
18457
|
+
await this.request("DELETE", this.canonicalUri(bucket, key), Buffer.alloc(0));
|
|
18458
|
+
}
|
|
18459
|
+
async headObject(bucket, key) {
|
|
18460
|
+
await this.request("HEAD", this.canonicalUri(bucket, key), Buffer.alloc(0));
|
|
18461
|
+
}
|
|
18462
|
+
/** Create the bucket (path-style `PUT /<bucket>`); an already-owned bucket (409) is success. */
|
|
18463
|
+
async createBucket(bucket) {
|
|
18464
|
+
try {
|
|
18465
|
+
await this.request("PUT", `${this.prefix}/${uriEncode(bucket, true)}`, Buffer.alloc(0));
|
|
18466
|
+
} catch (e) {
|
|
18467
|
+
if (!(e instanceof S3Error) || e.status !== 409) throw e;
|
|
18468
|
+
}
|
|
18469
|
+
}
|
|
18470
|
+
/** A URL that fetches the object directly, signed via SigV4 query params. */
|
|
18471
|
+
presignedGetUrl(bucket, key, expires = 3600) {
|
|
18472
|
+
this.requireCredentials();
|
|
18473
|
+
const { amzDate, dateStamp } = this.now();
|
|
18474
|
+
const uri = this.canonicalUri(bucket, key);
|
|
18475
|
+
const scope = `${dateStamp}/${this.region}/${SERVICE}/aws4_request`;
|
|
18476
|
+
const query = {
|
|
18477
|
+
"X-Amz-Algorithm": ALGORITHM,
|
|
18478
|
+
"X-Amz-Credential": `${this.accessKey}/${scope}`,
|
|
18479
|
+
"X-Amz-Date": amzDate,
|
|
18480
|
+
"X-Amz-Expires": String(expires),
|
|
18481
|
+
"X-Amz-SignedHeaders": "host"
|
|
18482
|
+
};
|
|
18483
|
+
const canonicalQs = this.canonicalQuery(query);
|
|
18484
|
+
const canonicalRequest = ["GET", uri, canonicalQs, `host:${this.host}
|
|
18485
|
+
`, "host", "UNSIGNED-PAYLOAD"].join("\n");
|
|
18486
|
+
const signature = this.sign(canonicalRequest, amzDate, dateStamp, scope);
|
|
18487
|
+
return `${this.scheme}://${this.host}${uri}?${canonicalQs}&X-Amz-Signature=${signature}`;
|
|
18488
|
+
}
|
|
18489
|
+
// -- signing + transport ----------------------------------------------------
|
|
18490
|
+
requireCredentials() {
|
|
18491
|
+
if (!this.accessKey || !this.secretKey) {
|
|
18492
|
+
throw new S3ConfigError(
|
|
18493
|
+
"S3 credentials are not set: set TINA4_STORAGE_KEY and TINA4_STORAGE_SECRET"
|
|
18494
|
+
);
|
|
18495
|
+
}
|
|
18496
|
+
}
|
|
18497
|
+
now() {
|
|
18498
|
+
const iso2 = (/* @__PURE__ */ new Date()).toISOString().replace(/[:-]|\.\d{3}/g, "");
|
|
18499
|
+
return { amzDate: iso2, dateStamp: iso2.slice(0, 8) };
|
|
18500
|
+
}
|
|
18501
|
+
canonicalUri(bucket, key) {
|
|
18502
|
+
return `${this.prefix}/${uriEncode(bucket, true)}/${uriEncode(key, true)}`;
|
|
18503
|
+
}
|
|
18504
|
+
canonicalQuery(query) {
|
|
18505
|
+
return Object.keys(query).sort().map((k) => `${uriEncode(k, false)}=${uriEncode(query[k], false)}`).join("&");
|
|
18506
|
+
}
|
|
18507
|
+
signingKey(dateStamp) {
|
|
18508
|
+
const kDate = hmac(`AWS4${this.secretKey}`, dateStamp);
|
|
18509
|
+
const kRegion = hmac(kDate, this.region);
|
|
18510
|
+
const kService = hmac(kRegion, SERVICE);
|
|
18511
|
+
return hmac(kService, "aws4_request");
|
|
18512
|
+
}
|
|
18513
|
+
sign(canonicalRequest, amzDate, dateStamp, scope) {
|
|
18514
|
+
const stringToSign = [ALGORITHM, amzDate, scope, sha256Hex2(canonicalRequest)].join("\n");
|
|
18515
|
+
return createHmac3("sha256", this.signingKey(dateStamp)).update(stringToSign, "utf8").digest("hex");
|
|
18516
|
+
}
|
|
18517
|
+
async request(method, uri, body, extraHeaders = {}) {
|
|
18518
|
+
this.requireCredentials();
|
|
18519
|
+
for (let attempt = 0; ; attempt++) {
|
|
18520
|
+
const last = attempt === MAX_RETRIES;
|
|
18521
|
+
let delay2 = null;
|
|
18522
|
+
try {
|
|
18523
|
+
return await this.send(method, uri, body, extraHeaders);
|
|
18524
|
+
} catch (e) {
|
|
18525
|
+
if (e instanceof S3Error) {
|
|
18526
|
+
if (last || !(e.status === 429 || e.status >= 500)) throw e;
|
|
18527
|
+
delay2 = e.retryAfter;
|
|
18528
|
+
} else {
|
|
18529
|
+
if (last) throw e;
|
|
18530
|
+
delay2 = null;
|
|
18531
|
+
}
|
|
18532
|
+
}
|
|
18533
|
+
if (delay2 == null) delay2 = Math.random() * (BACKOFF_BASE * 2 ** attempt);
|
|
18534
|
+
await sleep(Math.min(delay2, BACKOFF_CAP) * 1e3);
|
|
18535
|
+
}
|
|
18536
|
+
}
|
|
18537
|
+
async send(method, uri, body, extraHeaders = {}) {
|
|
18538
|
+
const { amzDate, dateStamp } = this.now();
|
|
18539
|
+
const payloadHash = sha256Hex2(body);
|
|
18540
|
+
const signed = {
|
|
18541
|
+
host: this.host,
|
|
18542
|
+
"x-amz-content-sha256": payloadHash,
|
|
18543
|
+
"x-amz-date": amzDate
|
|
18544
|
+
};
|
|
18545
|
+
const signedKeys = Object.keys(signed).sort();
|
|
18546
|
+
const canonicalHeaders = signedKeys.map((k) => `${k}:${signed[k]}
|
|
18547
|
+
`).join("");
|
|
18548
|
+
const signedHeaders = signedKeys.join(";");
|
|
18549
|
+
const canonicalRequest = [method, uri, "", canonicalHeaders, signedHeaders, payloadHash].join("\n");
|
|
18550
|
+
const scope = `${dateStamp}/${this.region}/${SERVICE}/aws4_request`;
|
|
18551
|
+
const signature = this.sign(canonicalRequest, amzDate, dateStamp, scope);
|
|
18552
|
+
const authorization = `${ALGORITHM} Credential=${this.accessKey}/${scope}, SignedHeaders=${signedHeaders}, Signature=${signature}`;
|
|
18553
|
+
const headers = {
|
|
18554
|
+
Authorization: authorization,
|
|
18555
|
+
"x-amz-content-sha256": payloadHash,
|
|
18556
|
+
"x-amz-date": amzDate,
|
|
18557
|
+
...extraHeaders
|
|
18558
|
+
};
|
|
18559
|
+
const url = `${this.scheme}://${this.host}${uri}`;
|
|
18560
|
+
const init = { method, headers, redirect: "manual" };
|
|
18561
|
+
if (method === "PUT" || method === "POST") init.body = body;
|
|
18562
|
+
if (AbortSignal.timeout) init.signal = AbortSignal.timeout(this.timeout);
|
|
18563
|
+
const response = await fetch(url, init);
|
|
18564
|
+
if (response.status < 200 || response.status >= 300) {
|
|
18565
|
+
const err = new S3Error(response.status, `${method} ${uri}: HTTP ${response.status}`);
|
|
18566
|
+
err.retryAfter = retryAfterSeconds(response.headers.get("retry-after"));
|
|
18567
|
+
throw err;
|
|
18568
|
+
}
|
|
18569
|
+
return { status: response.status, body: Buffer.from(await response.arrayBuffer()) };
|
|
18570
|
+
}
|
|
18571
|
+
};
|
|
18572
|
+
}
|
|
18573
|
+
});
|
|
18574
|
+
|
|
18142
18575
|
// ../orm/src/realtime/storage.ts
|
|
18143
18576
|
import { randomBytes as randomBytes5 } from "node:crypto";
|
|
18144
18577
|
import { mkdirSync as mkdirSync6, readFileSync as readFileSync5, writeFileSync as writeFileSync3, unlinkSync as unlinkSync2, statSync as statSync5 } from "node:fs";
|
|
18145
18578
|
import { resolve as resolve7, sep as sep3 } from "node:path";
|
|
18146
|
-
import { createRequire as createRequire6 } from "node:module";
|
|
18147
|
-
function loadAwsSdk(packageName) {
|
|
18148
|
-
try {
|
|
18149
|
-
return require2(packageName);
|
|
18150
|
-
} catch (error2) {
|
|
18151
|
-
const missing = error2?.code === "MODULE_NOT_FOUND" && String(error2?.message ?? "").includes(`'${packageName}'`);
|
|
18152
|
-
if (!missing) throw error2;
|
|
18153
|
-
throw optionalPackageMissing("S3Storage", S3_PACKAGES);
|
|
18154
|
-
}
|
|
18155
|
-
}
|
|
18156
18579
|
function storageKey(filename = "") {
|
|
18157
18580
|
let ext = "";
|
|
18158
18581
|
if (filename && filename.includes(".")) {
|
|
@@ -18177,14 +18600,12 @@ function selectStorage(storage) {
|
|
|
18177
18600
|
}
|
|
18178
18601
|
return new LocalStorage();
|
|
18179
18602
|
}
|
|
18180
|
-
var
|
|
18603
|
+
var UNSAFE, LocalStorage, S3Storage;
|
|
18181
18604
|
var init_storage = __esm({
|
|
18182
18605
|
"../orm/src/realtime/storage.ts"() {
|
|
18183
18606
|
"use strict";
|
|
18184
18607
|
init_src3();
|
|
18185
|
-
|
|
18186
|
-
require2 = createRequire6(import.meta.url);
|
|
18187
|
-
S3_PACKAGES = ["@aws-sdk/client-s3", "@aws-sdk/s3-request-presigner"];
|
|
18608
|
+
init_s3Client();
|
|
18188
18609
|
UNSAFE = /[^A-Za-z0-9]/g;
|
|
18189
18610
|
LocalStorage = class {
|
|
18190
18611
|
directory;
|
|
@@ -18234,51 +18655,36 @@ var init_storage = __esm({
|
|
|
18234
18655
|
constructor(opts = {}) {
|
|
18235
18656
|
this.bucket = opts.bucket || process.env.TINA4_STORAGE_BUCKET || "";
|
|
18236
18657
|
if (!this.bucket) throw new Error("S3Storage requires TINA4_STORAGE_BUCKET");
|
|
18237
|
-
const { S3Client } = loadAwsSdk("@aws-sdk/client-s3");
|
|
18238
|
-
loadAwsSdk("@aws-sdk/s3-request-presigner");
|
|
18239
|
-
const endpoint = opts.endpoint || process.env.TINA4_STORAGE_URL;
|
|
18240
18658
|
this.client = new S3Client({
|
|
18241
|
-
endpoint: endpoint || void 0,
|
|
18242
|
-
forcePathStyle: true,
|
|
18659
|
+
endpoint: opts.endpoint || process.env.TINA4_STORAGE_URL || void 0,
|
|
18243
18660
|
region: opts.region || process.env.TINA4_STORAGE_REGION || "us-east-1",
|
|
18244
|
-
|
|
18245
|
-
|
|
18246
|
-
secretAccessKey: opts.secret || process.env.TINA4_STORAGE_SECRET || ""
|
|
18247
|
-
}
|
|
18661
|
+
accessKey: opts.key || process.env.TINA4_STORAGE_KEY || "",
|
|
18662
|
+
secretKey: opts.secret || process.env.TINA4_STORAGE_SECRET || ""
|
|
18248
18663
|
});
|
|
18249
18664
|
}
|
|
18250
18665
|
async put(key, data, mime = "application/octet-stream") {
|
|
18251
|
-
|
|
18252
|
-
await this.client.send(new PutObjectCommand({ Bucket: this.bucket, Key: key, Body: data, ContentType: mime }));
|
|
18666
|
+
await this.client.putObject(this.bucket, key, data, mime);
|
|
18253
18667
|
}
|
|
18254
18668
|
async get(key) {
|
|
18255
18669
|
try {
|
|
18256
|
-
|
|
18257
|
-
const res = await this.client.send(new GetObjectCommand({ Bucket: this.bucket, Key: key }));
|
|
18258
|
-
const chunks = [];
|
|
18259
|
-
for await (const chunk of res.Body) chunks.push(Buffer.from(chunk));
|
|
18260
|
-
return Buffer.concat(chunks);
|
|
18670
|
+
return await this.client.getObject(this.bucket, key);
|
|
18261
18671
|
} catch {
|
|
18262
18672
|
return null;
|
|
18263
18673
|
}
|
|
18264
18674
|
}
|
|
18265
18675
|
async url(key, ttl = 3600) {
|
|
18266
|
-
|
|
18267
|
-
const { getSignedUrl } = loadAwsSdk("@aws-sdk/s3-request-presigner");
|
|
18268
|
-
return getSignedUrl(this.client, new GetObjectCommand({ Bucket: this.bucket, Key: key }), { expiresIn: ttl });
|
|
18676
|
+
return this.client.presignedGetUrl(this.bucket, key, ttl);
|
|
18269
18677
|
}
|
|
18270
18678
|
async delete(key) {
|
|
18271
18679
|
try {
|
|
18272
|
-
|
|
18273
|
-
await this.client.send(new DeleteObjectCommand({ Bucket: this.bucket, Key: key }));
|
|
18680
|
+
await this.client.deleteObject(this.bucket, key);
|
|
18274
18681
|
} catch (e) {
|
|
18275
18682
|
Log.error(`S3Storage delete failed for ${key}: ${e.message}`);
|
|
18276
18683
|
}
|
|
18277
18684
|
}
|
|
18278
18685
|
async exists(key) {
|
|
18279
18686
|
try {
|
|
18280
|
-
|
|
18281
|
-
await this.client.send(new HeadObjectCommand({ Bucket: this.bucket, Key: key }));
|
|
18687
|
+
await this.client.headObject(this.bucket, key);
|
|
18282
18688
|
return true;
|
|
18283
18689
|
} catch {
|
|
18284
18690
|
return false;
|
|
@@ -18289,7 +18695,7 @@ var init_storage = __esm({
|
|
|
18289
18695
|
});
|
|
18290
18696
|
|
|
18291
18697
|
// ../orm/src/realtime/realtime.ts
|
|
18292
|
-
import { createHmac as
|
|
18698
|
+
import { createHmac as createHmac4 } from "node:crypto";
|
|
18293
18699
|
function iceServers() {
|
|
18294
18700
|
const stun = process.env.TINA4_RTC_STUN_URLS || DEFAULT_STUN;
|
|
18295
18701
|
const servers = [{ urls: splitUrls(stun) }];
|
|
@@ -18298,14 +18704,14 @@ function iceServers() {
|
|
|
18298
18704
|
if (turnUrl && secret) {
|
|
18299
18705
|
const ttl = parseInt(process.env.TINA4_RTC_TURN_TTL || "3600", 10);
|
|
18300
18706
|
const username = String(Math.floor(Date.now() / 1e3) + ttl);
|
|
18301
|
-
const credential =
|
|
18707
|
+
const credential = createHmac4("sha1", secret).update(username).digest("base64");
|
|
18302
18708
|
servers.push({ urls: splitUrls(turnUrl), username, credential });
|
|
18303
18709
|
}
|
|
18304
18710
|
return servers;
|
|
18305
18711
|
}
|
|
18306
18712
|
async function realtime(options = {}) {
|
|
18307
18713
|
const features = options.features ?? ["calls"];
|
|
18308
|
-
const raw = (options.prefix ?? "")
|
|
18714
|
+
const raw = trimSlashes(options.prefix ?? "");
|
|
18309
18715
|
const p = raw ? `/${raw}` : "";
|
|
18310
18716
|
_authorize = options.authorize;
|
|
18311
18717
|
if (features.includes("chat") || features.includes("files")) {
|
|
@@ -18577,6 +18983,7 @@ var DEFAULT_STUN, _authorize;
|
|
|
18577
18983
|
var init_realtime = __esm({
|
|
18578
18984
|
"../orm/src/realtime/realtime.ts"() {
|
|
18579
18985
|
"use strict";
|
|
18986
|
+
init_slashTrim();
|
|
18580
18987
|
init_src3();
|
|
18581
18988
|
init_workspace();
|
|
18582
18989
|
init_channel();
|
|
@@ -18594,6 +19001,7 @@ var init_realtime2 = __esm({
|
|
|
18594
19001
|
"use strict";
|
|
18595
19002
|
init_realtime();
|
|
18596
19003
|
init_storage();
|
|
19004
|
+
init_s3Client();
|
|
18597
19005
|
init_workspace();
|
|
18598
19006
|
init_channel();
|
|
18599
19007
|
init_channelMember();
|
|
@@ -18959,6 +19367,7 @@ function mayStore(req2, vary, cacheControl, setCookie) {
|
|
|
18959
19367
|
if (requestHeader(req2, "authorization") !== void 0) return sharedCacheAllowed(cacheControl);
|
|
18960
19368
|
if (requestHeader(req2, "cookie") !== void 0) return sharedCacheAllowed(cacheControl);
|
|
18961
19369
|
if (hasSetCookie(setCookie)) return sharedCacheAllowed(cacheControl);
|
|
19370
|
+
if (req2.session?.isFresh && !req2.session.isFresh()) return sharedCacheAllowed(cacheControl);
|
|
18962
19371
|
return true;
|
|
18963
19372
|
}
|
|
18964
19373
|
function varyMatches(entry, req2) {
|
|
@@ -20311,7 +20720,7 @@ function coerceParam(raw, type2) {
|
|
|
20311
20720
|
}
|
|
20312
20721
|
function joinGroupPath(prefix, path10) {
|
|
20313
20722
|
const full = `${prefix}/${path10.replace(/^\/+/, "")}`;
|
|
20314
|
-
const trimmed = `/${full
|
|
20723
|
+
const trimmed = `/${trimSlashes(full)}`;
|
|
20315
20724
|
return trimmed.replace(/\/+/g, "/");
|
|
20316
20725
|
}
|
|
20317
20726
|
async function resolveStringMiddleware(spec) {
|
|
@@ -20376,6 +20785,7 @@ var WsRouteRef, RouteRef, Router, RouteGroup, TINA4_DEFAULT_ROUTER, globalRouter
|
|
|
20376
20785
|
var init_router = __esm({
|
|
20377
20786
|
"../core/src/router.ts"() {
|
|
20378
20787
|
"use strict";
|
|
20788
|
+
init_slashTrim();
|
|
20379
20789
|
init_dotenv();
|
|
20380
20790
|
init_middleware();
|
|
20381
20791
|
WsRouteRef = class {
|
|
@@ -20585,7 +20995,7 @@ var init_router = __esm({
|
|
|
20585
20995
|
const direct = this.matchRoute(routes, path10);
|
|
20586
20996
|
if (direct) return direct;
|
|
20587
20997
|
if (isTrailingSlashRedirectEnabled() && path10.length > 1 && path10.endsWith("/")) {
|
|
20588
|
-
const stripped = path10
|
|
20998
|
+
const stripped = rtrimSlashes(path10);
|
|
20589
20999
|
if (stripped.length > 0) {
|
|
20590
21000
|
const retry = this.matchRoute(routes, stripped);
|
|
20591
21001
|
if (retry) return retry;
|
|
@@ -22261,7 +22671,8 @@ var init_middleware = __esm({
|
|
|
22261
22671
|
"Content-Security-Policy": resolveCspHeader(currentCspNonce()),
|
|
22262
22672
|
"Referrer-Policy": process.env.TINA4_REFERRER_POLICY ?? "strict-origin-when-cross-origin",
|
|
22263
22673
|
"X-XSS-Protection": "0",
|
|
22264
|
-
"Permissions-Policy": process.env.TINA4_PERMISSIONS_POLICY ?? "camera=(), microphone=(), geolocation=()"
|
|
22674
|
+
"Permissions-Policy": process.env.TINA4_PERMISSIONS_POLICY ?? "camera=(), microphone=(), geolocation=()",
|
|
22675
|
+
"Cross-Origin-Opener-Policy": process.env.TINA4_COOP ?? "same-origin-allow-popups"
|
|
22265
22676
|
};
|
|
22266
22677
|
}
|
|
22267
22678
|
static beforeSecurity(req2, res) {
|
|
@@ -22278,7 +22689,7 @@ var init_middleware = __esm({
|
|
|
22278
22689
|
if (process.env.TINA4_CSP === void 0) {
|
|
22279
22690
|
_SecurityHeadersMiddleware.warnCspDefaultOnce();
|
|
22280
22691
|
}
|
|
22281
|
-
for (const name of ["Content-Security-Policy", "Referrer-Policy", "X-XSS-Protection", "Permissions-Policy"]) {
|
|
22692
|
+
for (const name of ["Content-Security-Policy", "Referrer-Policy", "X-XSS-Protection", "Permissions-Policy", "Cross-Origin-Opener-Policy"]) {
|
|
22282
22693
|
res.header(name, canonical[name]);
|
|
22283
22694
|
}
|
|
22284
22695
|
return [req2, res];
|
|
@@ -22362,7 +22773,7 @@ var init_middleware = __esm({
|
|
|
22362
22773
|
});
|
|
22363
22774
|
|
|
22364
22775
|
// ../core/src/request.ts
|
|
22365
|
-
import { mkdirSync as mkdirSync8, realpathSync as realpathSync2, writeFileSync as writeFileSync5 } from "node:fs";
|
|
22776
|
+
import { closeSync as closeSync3, constants as constants2, fstatSync as fstatSync2, ftruncateSync, lstatSync, mkdirSync as mkdirSync8, openSync as openSync3, realpathSync as realpathSync2, unlinkSync as unlinkSync4, writeFileSync as writeFileSync5 } from "node:fs";
|
|
22366
22777
|
import { dirname as dirname7, join as join12 } from "node:path";
|
|
22367
22778
|
function makeCaseInsensitiveHeaders(raw) {
|
|
22368
22779
|
return new Proxy(raw, {
|
|
@@ -22398,7 +22809,8 @@ function createRequest(req2) {
|
|
|
22398
22809
|
try {
|
|
22399
22810
|
const url = new URL(req2.url ?? "/", `${proto}://${host}`);
|
|
22400
22811
|
for (const [key, value] of url.searchParams) {
|
|
22401
|
-
|
|
22812
|
+
if (isUnsafeFieldName(key)) continue;
|
|
22813
|
+
Reflect.set(query, key, value);
|
|
22402
22814
|
}
|
|
22403
22815
|
path10 = url.pathname;
|
|
22404
22816
|
queryString = url.search.replace(/^\?/, "");
|
|
@@ -22410,7 +22822,8 @@ function createRequest(req2) {
|
|
|
22410
22822
|
queryString = questionIdx >= 0 ? rawTarget.slice(questionIdx + 1) : "";
|
|
22411
22823
|
try {
|
|
22412
22824
|
for (const [key, value] of new URLSearchParams(queryString)) {
|
|
22413
|
-
|
|
22825
|
+
if (isUnsafeFieldName(key)) continue;
|
|
22826
|
+
Reflect.set(query, key, value);
|
|
22414
22827
|
}
|
|
22415
22828
|
} catch {
|
|
22416
22829
|
}
|
|
@@ -22429,7 +22842,8 @@ function createRequest(req2) {
|
|
|
22429
22842
|
if (cookieHeader) {
|
|
22430
22843
|
for (const pair of cookieHeader.split(";")) {
|
|
22431
22844
|
const [k, ...v] = pair.trim().split("=");
|
|
22432
|
-
|
|
22845
|
+
const name = k ? k.trim() : "";
|
|
22846
|
+
if (name && !isUnsafeFieldName(name)) Reflect.set(cookies, name, v.join("=").trim());
|
|
22433
22847
|
}
|
|
22434
22848
|
}
|
|
22435
22849
|
w.cookies = cookies;
|
|
@@ -22520,13 +22934,7 @@ async function parseBody(req2) {
|
|
|
22520
22934
|
req2.body = str;
|
|
22521
22935
|
}
|
|
22522
22936
|
} else if (contentType.includes("application/x-www-form-urlencoded")) {
|
|
22523
|
-
|
|
22524
|
-
const params = new URLSearchParams(str);
|
|
22525
|
-
const obj = {};
|
|
22526
|
-
for (const [key, value] of params) {
|
|
22527
|
-
obj[key] = value;
|
|
22528
|
-
}
|
|
22529
|
-
req2.body = obj;
|
|
22937
|
+
req2.body = nestFormFields([...new URLSearchParams(raw.toString("utf-8"))]);
|
|
22530
22938
|
} else {
|
|
22531
22939
|
req2.body = raw.toString("utf-8");
|
|
22532
22940
|
}
|
|
@@ -22536,7 +22944,7 @@ function extractBoundary(contentType) {
|
|
|
22536
22944
|
return match ? match[1] ?? match[2] : null;
|
|
22537
22945
|
}
|
|
22538
22946
|
function parseMultipart(body, boundary) {
|
|
22539
|
-
const
|
|
22947
|
+
const pairs = [];
|
|
22540
22948
|
const files = {};
|
|
22541
22949
|
const delimiter4 = Buffer.from(`--${boundary}`);
|
|
22542
22950
|
const closeDelimiter = Buffer.from(`--${boundary}--`);
|
|
@@ -22544,7 +22952,7 @@ function parseMultipart(body, boundary) {
|
|
|
22544
22952
|
const doubleCrlf = Buffer.from("\r\n\r\n");
|
|
22545
22953
|
let offset = 0;
|
|
22546
22954
|
const firstIdx = bufferIndexOf(body, delimiter4, offset);
|
|
22547
|
-
if (firstIdx === -1) return { fields, files };
|
|
22955
|
+
if (firstIdx === -1) return { fields: {}, files };
|
|
22548
22956
|
offset = firstIdx + delimiter4.length;
|
|
22549
22957
|
if (body[offset] === 13 && body[offset + 1] === 10) {
|
|
22550
22958
|
offset += 2;
|
|
@@ -22568,14 +22976,15 @@ function parseMultipart(body, boundary) {
|
|
|
22568
22976
|
content: Buffer.from(content),
|
|
22569
22977
|
size: content.length
|
|
22570
22978
|
};
|
|
22571
|
-
if (
|
|
22979
|
+
if (isUnsafeFieldName(disposition.name)) {
|
|
22980
|
+
} else if (files[disposition.name]) {
|
|
22572
22981
|
const existing = files[disposition.name];
|
|
22573
|
-
files
|
|
22982
|
+
Reflect.set(files, disposition.name, Array.isArray(existing) ? [...existing, file] : [existing, file]);
|
|
22574
22983
|
} else {
|
|
22575
|
-
files
|
|
22984
|
+
Reflect.set(files, disposition.name, file);
|
|
22576
22985
|
}
|
|
22577
22986
|
} else if (disposition.name) {
|
|
22578
|
-
|
|
22987
|
+
pairs.push([disposition.name, content.toString("utf-8")]);
|
|
22579
22988
|
}
|
|
22580
22989
|
offset = nextDelimIdx + delimiter4.length;
|
|
22581
22990
|
if (body[offset] === 45 && body[offset + 1] === 45) {
|
|
@@ -22585,7 +22994,7 @@ function parseMultipart(body, boundary) {
|
|
|
22585
22994
|
offset += 2;
|
|
22586
22995
|
}
|
|
22587
22996
|
}
|
|
22588
|
-
return { fields, files };
|
|
22997
|
+
return { fields: nestFormFields(pairs), files };
|
|
22589
22998
|
}
|
|
22590
22999
|
function saveUpload(file, targetDir, filename) {
|
|
22591
23000
|
const raw = String(filename ?? file.filename ?? "");
|
|
@@ -22601,7 +23010,21 @@ function saveUpload(file, targetDir, filename) {
|
|
|
22601
23010
|
if (realParent !== realDir) {
|
|
22602
23011
|
throw new Error(`refusing to write outside ${targetDir}: ${JSON.stringify(raw)}`);
|
|
22603
23012
|
}
|
|
22604
|
-
|
|
23013
|
+
if (lstatSync(dest, { throwIfNoEntry: false })?.isSymbolicLink()) unlinkSync4(dest);
|
|
23014
|
+
const flags = constants2.O_WRONLY | constants2.O_CREAT | (constants2.O_NOFOLLOW ?? 0);
|
|
23015
|
+
let fd = openSync3(dest, flags, 384);
|
|
23016
|
+
try {
|
|
23017
|
+
if (fstatSync2(fd).nlink > 1) {
|
|
23018
|
+
closeSync3(fd);
|
|
23019
|
+
fd = -1;
|
|
23020
|
+
unlinkSync4(dest);
|
|
23021
|
+
fd = openSync3(dest, flags | constants2.O_EXCL, 384);
|
|
23022
|
+
}
|
|
23023
|
+
ftruncateSync(fd, 0);
|
|
23024
|
+
writeFileSync5(fd, file.content);
|
|
23025
|
+
} finally {
|
|
23026
|
+
if (fd >= 0) closeSync3(fd);
|
|
23027
|
+
}
|
|
22605
23028
|
return dest;
|
|
22606
23029
|
}
|
|
22607
23030
|
function bufferIndexOf(haystack, needle, offset) {
|
|
@@ -22626,10 +23049,98 @@ function parseDisposition(headers) {
|
|
|
22626
23049
|
};
|
|
22627
23050
|
}
|
|
22628
23051
|
function parsePartContentType(headers) {
|
|
22629
|
-
const match = headers.match(/Content-Type
|
|
22630
|
-
|
|
23052
|
+
const match = headers.match(/Content-Type:([^\r\n]*)/i);
|
|
23053
|
+
const value = match?.[1]?.trim();
|
|
23054
|
+
return value ? value : null;
|
|
23055
|
+
}
|
|
23056
|
+
function nestFormFields(pairs) {
|
|
23057
|
+
const kept = pairs.filter(([name]) => !/(^|[[\]])__proto__([[\]]|$)/.test(name));
|
|
23058
|
+
if (kept.length > FORM_FIELD_LIMIT) return Object.fromEntries(kept);
|
|
23059
|
+
const nested = /* @__PURE__ */ new WeakSet();
|
|
23060
|
+
const node = () => {
|
|
23061
|
+
const created = /* @__PURE__ */ Object.create(null);
|
|
23062
|
+
nested.add(created);
|
|
23063
|
+
return created;
|
|
23064
|
+
};
|
|
23065
|
+
const isNode = (value) => typeof value === "object" && value !== null && nested.has(value);
|
|
23066
|
+
const own = (params, key) => Object.prototype.hasOwnProperty.call(params, key) ? params[key] : void 0;
|
|
23067
|
+
const list = (params, key) => {
|
|
23068
|
+
let current = own(params, key);
|
|
23069
|
+
if (current === void 0) {
|
|
23070
|
+
current = [];
|
|
23071
|
+
Reflect.set(params, key, current);
|
|
23072
|
+
}
|
|
23073
|
+
if (!Array.isArray(current)) throw new RangeError(`expected an array for '${key}'`);
|
|
23074
|
+
return current;
|
|
23075
|
+
};
|
|
23076
|
+
const object = (params, key) => {
|
|
23077
|
+
let current = own(params, key);
|
|
23078
|
+
if (current === void 0) {
|
|
23079
|
+
current = node();
|
|
23080
|
+
Reflect.set(params, key, current);
|
|
23081
|
+
}
|
|
23082
|
+
if (!isNode(current)) throw new RangeError(`expected an object for '${key}'`);
|
|
23083
|
+
return current;
|
|
23084
|
+
};
|
|
23085
|
+
const hasKey = (params, key) => {
|
|
23086
|
+
if (key.includes("[]")) return false;
|
|
23087
|
+
let level = params;
|
|
23088
|
+
for (const part of key.split(/[[\]]+/).filter(Boolean)) {
|
|
23089
|
+
if (!isNode(level) || own(level, part) === void 0) return false;
|
|
23090
|
+
level = level[part];
|
|
23091
|
+
}
|
|
23092
|
+
return true;
|
|
23093
|
+
};
|
|
23094
|
+
const splitName = (name, depth) => {
|
|
23095
|
+
if (depth === 0) {
|
|
23096
|
+
const start2 = name.indexOf("[", 1);
|
|
23097
|
+
return start2 === -1 ? [name, ""] : [name.slice(0, start2), name.slice(start2)];
|
|
23098
|
+
}
|
|
23099
|
+
if (name.startsWith("[]")) return ["[]", name.slice(2)];
|
|
23100
|
+
const close = name.indexOf("]", 1);
|
|
23101
|
+
return name.startsWith("[") && close !== -1 ? [name.slice(1, close), name.slice(close + 1)] : [name, ""];
|
|
23102
|
+
};
|
|
23103
|
+
const putListItem = (items, after, value, depth) => {
|
|
23104
|
+
let childKey = after[2] === "[" && after.endsWith("]") ? after.slice(3, -1) : "";
|
|
23105
|
+
if (childKey === "" || childKey.includes("[") || childKey.includes("]")) childKey = after.slice(2);
|
|
23106
|
+
const last = items[items.length - 1];
|
|
23107
|
+
if (isNode(last) && !hasKey(last, childKey)) put2(last, childKey, value, depth + 1);
|
|
23108
|
+
else items.push(put2(node(), childKey, value, depth + 1));
|
|
23109
|
+
};
|
|
23110
|
+
const put2 = (params, name, value, depth) => {
|
|
23111
|
+
const [key, after] = splitName(name, depth);
|
|
23112
|
+
if (key === "") return void 0;
|
|
23113
|
+
if (after === "" && key === "[]" && depth !== 0) return [value];
|
|
23114
|
+
if (after === "") Reflect.set(params, key, value);
|
|
23115
|
+
else if (after === "[") Reflect.set(params, name, value);
|
|
23116
|
+
else if (after === "[]") list(params, key).push(value);
|
|
23117
|
+
else if (after.startsWith("[]")) putListItem(list(params, key), after, value, depth);
|
|
23118
|
+
else put2(object(params, key), after, value, depth + 1);
|
|
23119
|
+
return params;
|
|
23120
|
+
};
|
|
23121
|
+
const tooDeep = (name) => {
|
|
23122
|
+
let count = 0;
|
|
23123
|
+
for (let at = name.indexOf("["); at !== -1; at = name.indexOf("[", at + 1)) {
|
|
23124
|
+
if (++count >= FORM_DEPTH_LIMIT) return true;
|
|
23125
|
+
}
|
|
23126
|
+
return false;
|
|
23127
|
+
};
|
|
23128
|
+
const fields = node();
|
|
23129
|
+
for (const [name, value] of kept) {
|
|
23130
|
+
if (name.length > FORM_NAME_LIMIT || tooDeep(name)) {
|
|
23131
|
+
Reflect.set(fields, name, value);
|
|
23132
|
+
continue;
|
|
23133
|
+
}
|
|
23134
|
+
try {
|
|
23135
|
+
put2(fields, name, value, 0);
|
|
23136
|
+
} catch (error2) {
|
|
23137
|
+
if (!(error2 instanceof RangeError)) throw error2;
|
|
23138
|
+
Reflect.set(fields, name, value);
|
|
23139
|
+
}
|
|
23140
|
+
}
|
|
23141
|
+
return fields;
|
|
22631
23142
|
}
|
|
22632
|
-
var DEFAULT_MAX_UPLOAD_SIZE, warnedLimits, PayloadTooLargeError;
|
|
23143
|
+
var DEFAULT_MAX_UPLOAD_SIZE, warnedLimits, PayloadTooLargeError, FORM_DEPTH_LIMIT, FORM_FIELD_LIMIT, FORM_NAME_LIMIT, isUnsafeFieldName;
|
|
22633
23144
|
var init_request = __esm({
|
|
22634
23145
|
"../core/src/request.ts"() {
|
|
22635
23146
|
"use strict";
|
|
@@ -22644,6 +23155,10 @@ var init_request = __esm({
|
|
|
22644
23155
|
this.name = "PayloadTooLargeError";
|
|
22645
23156
|
}
|
|
22646
23157
|
};
|
|
23158
|
+
FORM_DEPTH_LIMIT = 32;
|
|
23159
|
+
FORM_FIELD_LIMIT = 4096;
|
|
23160
|
+
FORM_NAME_LIMIT = 1024;
|
|
23161
|
+
isUnsafeFieldName = (key) => key === "__proto__" || key === "constructor" || key === "prototype";
|
|
22647
23162
|
}
|
|
22648
23163
|
});
|
|
22649
23164
|
|
|
@@ -22925,8 +23440,8 @@ var init_ssoIdentity = __esm({
|
|
|
22925
23440
|
});
|
|
22926
23441
|
|
|
22927
23442
|
// ../core/src/authGate.ts
|
|
22928
|
-
function enforceRouteAuth(req2, res, match
|
|
22929
|
-
if (!(match.secure === true && match.noAuth !== true
|
|
23443
|
+
function enforceRouteAuth(req2, res, match) {
|
|
23444
|
+
if (!(match.secure === true && match.noAuth !== true)) {
|
|
22930
23445
|
return false;
|
|
22931
23446
|
}
|
|
22932
23447
|
const authHeader = req2.headers.authorization ?? "";
|
|
@@ -23170,7 +23685,7 @@ __export(portTakeover_exports, {
|
|
|
23170
23685
|
writePidfile: () => writePidfile
|
|
23171
23686
|
});
|
|
23172
23687
|
import { execFileSync } from "node:child_process";
|
|
23173
|
-
import { existsSync as existsSync11, readFileSync as readFileSync7, writeFileSync as writeFileSync7, mkdirSync as mkdirSync10, unlinkSync as
|
|
23688
|
+
import { existsSync as existsSync11, readFileSync as readFileSync7, writeFileSync as writeFileSync7, mkdirSync as mkdirSync10, unlinkSync as unlinkSync5 } from "node:fs";
|
|
23174
23689
|
import { join as join14 } from "node:path";
|
|
23175
23690
|
function isTruthy3(value) {
|
|
23176
23691
|
return ["true", "1", "yes", "on"].includes(String(value ?? "").trim().toLowerCase());
|
|
@@ -23224,7 +23739,7 @@ function readPidfile(port, baseDir) {
|
|
|
23224
23739
|
}
|
|
23225
23740
|
function removePidfile(port, baseDir) {
|
|
23226
23741
|
try {
|
|
23227
|
-
|
|
23742
|
+
unlinkSync5(pidfilePath(port, baseDir));
|
|
23228
23743
|
} catch {
|
|
23229
23744
|
}
|
|
23230
23745
|
}
|
|
@@ -23325,21 +23840,6 @@ var init_portTakeover = __esm({
|
|
|
23325
23840
|
}
|
|
23326
23841
|
});
|
|
23327
23842
|
|
|
23328
|
-
// ../core/src/etag.ts
|
|
23329
|
-
function etagMatches(ifNoneMatch, etag) {
|
|
23330
|
-
const strip = (tag) => tag.trim().replace(/^W\//, "");
|
|
23331
|
-
const target = strip(etag);
|
|
23332
|
-
return ifNoneMatch.split(",").some((candidate) => {
|
|
23333
|
-
const trimmed = candidate.trim();
|
|
23334
|
-
return trimmed === "*" || strip(trimmed) === target;
|
|
23335
|
-
});
|
|
23336
|
-
}
|
|
23337
|
-
var init_etag = __esm({
|
|
23338
|
-
"../core/src/etag.ts"() {
|
|
23339
|
-
"use strict";
|
|
23340
|
-
}
|
|
23341
|
-
});
|
|
23342
|
-
|
|
23343
23843
|
// ../core/src/sessionHandlers/syncBridge.ts
|
|
23344
23844
|
import { Worker } from "node:worker_threads";
|
|
23345
23845
|
function getBridge(key, workerSource, workerData) {
|
|
@@ -23699,7 +24199,7 @@ var init_valkeyHandler = __esm({
|
|
|
23699
24199
|
});
|
|
23700
24200
|
|
|
23701
24201
|
// ../core/src/sessionHandlers/memcachedHandler.ts
|
|
23702
|
-
import { createHash as
|
|
24202
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
23703
24203
|
var MAX_KEY_BYTES, MAX_RELATIVE_EXPTIME, MemcachedSessionHandler;
|
|
23704
24204
|
var init_memcachedHandler = __esm({
|
|
23705
24205
|
"../core/src/sessionHandlers/memcachedHandler.ts"() {
|
|
@@ -23721,7 +24221,7 @@ var init_memcachedHandler = __esm({
|
|
|
23721
24221
|
key(sessionId) {
|
|
23722
24222
|
const candidate = `${this.prefix}${sessionId}`;
|
|
23723
24223
|
if (Buffer.byteLength(candidate) > MAX_KEY_BYTES || /[\x00-\x20\x7f]/.test(candidate)) {
|
|
23724
|
-
return `${this.prefix}${
|
|
24224
|
+
return `${this.prefix}${createHash6("sha256").update(sessionId).digest("hex")}`;
|
|
23725
24225
|
}
|
|
23726
24226
|
return candidate;
|
|
23727
24227
|
}
|
|
@@ -24187,7 +24687,7 @@ var init_mongoHandler = __esm({
|
|
|
24187
24687
|
});
|
|
24188
24688
|
|
|
24189
24689
|
// ../core/src/sessionHandlers/sqlClient.ts
|
|
24190
|
-
import { createRequire as
|
|
24690
|
+
import { createRequire as createRequire6 } from "node:module";
|
|
24191
24691
|
function driverPath(engine) {
|
|
24192
24692
|
const packageName = DRIVER_PACKAGE4[engine];
|
|
24193
24693
|
try {
|
|
@@ -24226,7 +24726,7 @@ var init_sqlClient = __esm({
|
|
|
24226
24726
|
mssql: "tedious",
|
|
24227
24727
|
firebird: "node-firebird"
|
|
24228
24728
|
};
|
|
24229
|
-
requireFromHere =
|
|
24729
|
+
requireFromHere = createRequire6(import.meta.url);
|
|
24230
24730
|
SQL_WORKER = `
|
|
24231
24731
|
const target = workerData.target;
|
|
24232
24732
|
const engine = target.engine;
|
|
@@ -24708,14 +25208,18 @@ __export(session_exports, {
|
|
|
24708
25208
|
Session: () => Session,
|
|
24709
25209
|
VALID_SESSION_BACKENDS: () => VALID_SESSION_BACKENDS,
|
|
24710
25210
|
buildSessionCookie: () => buildSessionCookie,
|
|
25211
|
+
currentFormTokenSessionId: () => currentFormTokenSessionId,
|
|
24711
25212
|
isSecureScheme: () => isSecureScheme,
|
|
24712
25213
|
isValidSessionId: () => isValidSessionId,
|
|
25214
|
+
runWithFormTokenSession: () => runWithFormTokenSession,
|
|
24713
25215
|
sessionCookieName: () => sessionCookieName,
|
|
24714
25216
|
sessionCookieToSend: () => sessionCookieToSend,
|
|
24715
|
-
sessionStrictMode: () => sessionStrictMode
|
|
25217
|
+
sessionStrictMode: () => sessionStrictMode,
|
|
25218
|
+
setFormTokenSession: () => setFormTokenSession
|
|
24716
25219
|
});
|
|
24717
|
-
import {
|
|
24718
|
-
import {
|
|
25220
|
+
import { AsyncLocalStorage as AsyncLocalStorage4 } from "node:async_hooks";
|
|
25221
|
+
import { createHash as createHash7, randomBytes as randomBytes6 } from "node:crypto";
|
|
25222
|
+
import { existsSync as existsSync12, mkdirSync as mkdirSync11, readFileSync as readFileSync8, writeFileSync as writeFileSync8, unlinkSync as unlinkSync6, readdirSync as readdirSync6 } from "node:fs";
|
|
24719
25223
|
import { join as join15 } from "node:path";
|
|
24720
25224
|
function isValidSessionId(sessionId) {
|
|
24721
25225
|
return typeof sessionId === "string" && SESSION_ID_PATTERN.test(sessionId);
|
|
@@ -24781,7 +25285,21 @@ function sessionCookieToSend(sess, existingSid, rawReq, rawRes) {
|
|
|
24781
25285
|
const socketEncrypted = rawReq.socket?.encrypted === true;
|
|
24782
25286
|
return buildSessionCookie(newSid, ttl, void 0, forwardedProto, socketEncrypted);
|
|
24783
25287
|
}
|
|
24784
|
-
|
|
25288
|
+
function runWithFormTokenSession(fn) {
|
|
25289
|
+
return sessionStore.run({ session: null }, fn);
|
|
25290
|
+
}
|
|
25291
|
+
function setFormTokenSession(session) {
|
|
25292
|
+
const store = sessionStore.getStore();
|
|
25293
|
+
if (store) store.session = session;
|
|
25294
|
+
}
|
|
25295
|
+
function currentFormTokenSessionId() {
|
|
25296
|
+
const session = sessionStore.getStore()?.session;
|
|
25297
|
+
const sid = session?.getSessionId();
|
|
25298
|
+
if (!session || !sid) return "";
|
|
25299
|
+
if (session.isFresh()) session.set("_tina4_csrf", true);
|
|
25300
|
+
return sid;
|
|
25301
|
+
}
|
|
25302
|
+
var SESSION_ID_PATTERN, VALID_SESSION_BACKENDS, CANONICAL_SESSION_BACKENDS, RETIRED_SESSION_BACKENDS, FileSessionHandler, RedisSessionHandler, FLASH_PREFIX, Session, sessionStore;
|
|
24785
25303
|
var init_session = __esm({
|
|
24786
25304
|
"../core/src/session.ts"() {
|
|
24787
25305
|
"use strict";
|
|
@@ -24855,7 +25373,7 @@ var init_session = __esm({
|
|
|
24855
25373
|
`Invalid session id ${JSON.stringify(id)} \u2014 a session id is opaque and must match ${SESSION_ID_PATTERN.source}. It is never a path, so it is refused rather than resolved to a file.`
|
|
24856
25374
|
);
|
|
24857
25375
|
}
|
|
24858
|
-
return join15(this.storagePath, `${
|
|
25376
|
+
return join15(this.storagePath, `${createHash7("sha256").update(id).digest("hex")}.json`);
|
|
24859
25377
|
}
|
|
24860
25378
|
read(sessionId) {
|
|
24861
25379
|
const filePath = this.filePath(sessionId);
|
|
@@ -24865,7 +25383,7 @@ var init_session = __esm({
|
|
|
24865
25383
|
const wrapper = JSON.parse(raw);
|
|
24866
25384
|
if (wrapper._expires && wrapper._expires > 0 && Date.now() / 1e3 > wrapper._expires) {
|
|
24867
25385
|
try {
|
|
24868
|
-
|
|
25386
|
+
unlinkSync6(filePath);
|
|
24869
25387
|
} catch {
|
|
24870
25388
|
}
|
|
24871
25389
|
return null;
|
|
@@ -24884,7 +25402,7 @@ var init_session = __esm({
|
|
|
24884
25402
|
destroy(sessionId) {
|
|
24885
25403
|
const filePath = this.filePath(sessionId);
|
|
24886
25404
|
try {
|
|
24887
|
-
if (existsSync12(filePath))
|
|
25405
|
+
if (existsSync12(filePath)) unlinkSync6(filePath);
|
|
24888
25406
|
} catch {
|
|
24889
25407
|
}
|
|
24890
25408
|
}
|
|
@@ -24900,11 +25418,11 @@ var init_session = __esm({
|
|
|
24900
25418
|
const raw = readFileSync8(fullPath, "utf-8");
|
|
24901
25419
|
const wrapper = JSON.parse(raw);
|
|
24902
25420
|
if (wrapper._expires && wrapper._expires > 0 && now > wrapper._expires) {
|
|
24903
|
-
|
|
25421
|
+
unlinkSync6(fullPath);
|
|
24904
25422
|
}
|
|
24905
25423
|
} catch {
|
|
24906
25424
|
try {
|
|
24907
|
-
|
|
25425
|
+
unlinkSync6(fullPath);
|
|
24908
25426
|
} catch {
|
|
24909
25427
|
}
|
|
24910
25428
|
}
|
|
@@ -25424,12 +25942,28 @@ var init_session = __esm({
|
|
|
25424
25942
|
this.loaded = /* @__PURE__ */ new Map();
|
|
25425
25943
|
}
|
|
25426
25944
|
};
|
|
25945
|
+
sessionStore = new AsyncLocalStorage4();
|
|
25946
|
+
}
|
|
25947
|
+
});
|
|
25948
|
+
|
|
25949
|
+
// ../core/src/etag.ts
|
|
25950
|
+
function etagMatches(ifNoneMatch, etag) {
|
|
25951
|
+
const strip = (tag) => tag.trim().replace(/^W\//, "");
|
|
25952
|
+
const target = strip(etag);
|
|
25953
|
+
return ifNoneMatch.split(",").some((candidate) => {
|
|
25954
|
+
const trimmed = candidate.trim();
|
|
25955
|
+
return trimmed === "*" || strip(trimmed) === target;
|
|
25956
|
+
});
|
|
25957
|
+
}
|
|
25958
|
+
var init_etag = __esm({
|
|
25959
|
+
"../core/src/etag.ts"() {
|
|
25960
|
+
"use strict";
|
|
25427
25961
|
}
|
|
25428
25962
|
});
|
|
25429
25963
|
|
|
25430
25964
|
// ../core/src/dispatchPipeline.ts
|
|
25431
25965
|
import { gzipSync } from "node:zlib";
|
|
25432
|
-
import { createHash as
|
|
25966
|
+
import { createHash as createHash8 } from "node:crypto";
|
|
25433
25967
|
async function resetRequestCaches2() {
|
|
25434
25968
|
if (_resetRequestCaches === void 0) {
|
|
25435
25969
|
_resetRequestCaches = Promise.resolve().then(() => (init_src(), src_exports)).then((orm) => orm.resetRequestCaches).catch(() => null);
|
|
@@ -25502,7 +26036,7 @@ function applyResponseValidator(rawReq, rawRes, body) {
|
|
|
25502
26036
|
if ((rawRes.statusCode || 200) !== 200 || body.length === 0) return false;
|
|
25503
26037
|
let etag = rawRes.getHeader("etag");
|
|
25504
26038
|
if (!etag) {
|
|
25505
|
-
etag = `"${
|
|
26039
|
+
etag = `"${createHash8("md5").update(body).digest("hex").slice(0, 16)}"`;
|
|
25506
26040
|
rawRes.setHeader("ETag", etag);
|
|
25507
26041
|
}
|
|
25508
26042
|
if (!responseIsNotModified(rawReq, rawRes, String(etag))) return false;
|
|
@@ -25577,6 +26111,7 @@ async function sessionAutoStart(rawReq, rawRes, req2) {
|
|
|
25577
26111
|
return;
|
|
25578
26112
|
}
|
|
25579
26113
|
req2.session = sess;
|
|
26114
|
+
setFormTokenSession(sess);
|
|
25580
26115
|
const origEnd = rawRes.end.bind(rawRes);
|
|
25581
26116
|
let finalised = false;
|
|
25582
26117
|
rawRes.end = function(...args) {
|
|
@@ -25605,6 +26140,7 @@ var _resetRequestCaches, COMPRESSIBLE_PREFIXES;
|
|
|
25605
26140
|
var init_dispatchPipeline = __esm({
|
|
25606
26141
|
"../core/src/dispatchPipeline.ts"() {
|
|
25607
26142
|
"use strict";
|
|
26143
|
+
init_session();
|
|
25608
26144
|
init_logger();
|
|
25609
26145
|
init_etag();
|
|
25610
26146
|
COMPRESSIBLE_PREFIXES = [
|
|
@@ -25754,14 +26290,21 @@ function parseStack(stack) {
|
|
|
25754
26290
|
const frames = [];
|
|
25755
26291
|
const lines = stack.split("\n");
|
|
25756
26292
|
for (const line of lines) {
|
|
25757
|
-
|
|
25758
|
-
if (
|
|
25759
|
-
|
|
25760
|
-
|
|
26293
|
+
const t = line.trim();
|
|
26294
|
+
if (!t.startsWith("at ")) continue;
|
|
26295
|
+
const rest = t.slice(3);
|
|
26296
|
+
let func = "{anonymous}";
|
|
26297
|
+
let loc = rest;
|
|
26298
|
+
if (rest.endsWith(")")) {
|
|
26299
|
+
const open = rest.lastIndexOf(" (");
|
|
26300
|
+
if (open >= 0) {
|
|
26301
|
+
func = rest.slice(0, open);
|
|
26302
|
+
loc = rest.slice(open + 2, -1);
|
|
26303
|
+
}
|
|
25761
26304
|
}
|
|
25762
|
-
|
|
25763
|
-
if (
|
|
25764
|
-
frames.push({ func
|
|
26305
|
+
const lc = loc.match(/:(\d+):(\d+)$/);
|
|
26306
|
+
if (lc && lc.index !== void 0) {
|
|
26307
|
+
frames.push({ func, file: loc.slice(0, lc.index), line: parseInt(lc[1], 10), column: parseInt(lc[2], 10) });
|
|
25765
26308
|
}
|
|
25766
26309
|
}
|
|
25767
26310
|
return frames;
|
|
@@ -26086,7 +26629,7 @@ var init_rateLimiter = __esm({
|
|
|
26086
26629
|
});
|
|
26087
26630
|
|
|
26088
26631
|
// ../core/src/devMailbox.ts
|
|
26089
|
-
import { mkdirSync as mkdirSync12, readdirSync as readdirSync7, readFileSync as readFileSync11, writeFileSync as writeFileSync9, unlinkSync as
|
|
26632
|
+
import { mkdirSync as mkdirSync12, readdirSync as readdirSync7, readFileSync as readFileSync11, writeFileSync as writeFileSync9, unlinkSync as unlinkSync7, existsSync as existsSync13 } from "node:fs";
|
|
26090
26633
|
import { join as join17 } from "node:path";
|
|
26091
26634
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
26092
26635
|
var DevMailbox;
|
|
@@ -26218,7 +26761,7 @@ var init_devMailbox = __esm({
|
|
|
26218
26761
|
const filePath = join17(this.mailboxDir, folder, `${msgId}.json`);
|
|
26219
26762
|
if (existsSync13(filePath)) {
|
|
26220
26763
|
try {
|
|
26221
|
-
|
|
26764
|
+
unlinkSync7(filePath);
|
|
26222
26765
|
deleted = true;
|
|
26223
26766
|
} catch {
|
|
26224
26767
|
}
|
|
@@ -26237,7 +26780,7 @@ var init_devMailbox = __esm({
|
|
|
26237
26780
|
if (existsSync13(dir)) {
|
|
26238
26781
|
const files = readdirSync7(dir).filter((file) => file.endsWith(".json"));
|
|
26239
26782
|
for (const file of files) {
|
|
26240
|
-
|
|
26783
|
+
unlinkSync7(join17(dir, file));
|
|
26241
26784
|
}
|
|
26242
26785
|
}
|
|
26243
26786
|
} catch {
|
|
@@ -26658,26 +27201,31 @@ function parseFlags(args, booleanFlags) {
|
|
|
26658
27201
|
const positional = [];
|
|
26659
27202
|
let i = 0;
|
|
26660
27203
|
while (i < args.length) {
|
|
26661
|
-
|
|
26662
|
-
|
|
26663
|
-
const key = arg.slice(2);
|
|
26664
|
-
if (booleanFlags?.has(key)) {
|
|
26665
|
-
flags[key] = true;
|
|
26666
|
-
i += 1;
|
|
26667
|
-
} else if (i + 1 < args.length && !args[i + 1].startsWith("--")) {
|
|
26668
|
-
flags[key] = args[i + 1];
|
|
26669
|
-
i += 2;
|
|
26670
|
-
} else {
|
|
26671
|
-
flags[key] = true;
|
|
26672
|
-
i += 1;
|
|
26673
|
-
}
|
|
27204
|
+
if (args[i].startsWith("--")) {
|
|
27205
|
+
i += readFlag(args, i, flags, booleanFlags);
|
|
26674
27206
|
} else {
|
|
26675
|
-
positional.push(
|
|
27207
|
+
positional.push(args[i]);
|
|
26676
27208
|
i += 1;
|
|
26677
27209
|
}
|
|
26678
27210
|
}
|
|
26679
27211
|
return { flags, positional };
|
|
26680
27212
|
}
|
|
27213
|
+
function readFlag(args, i, flags, booleanFlags) {
|
|
27214
|
+
const arg = args[i];
|
|
27215
|
+
const eq = arg.indexOf("=");
|
|
27216
|
+
if (eq !== -1) {
|
|
27217
|
+
flags[arg.slice(2, eq)] = arg.slice(eq + 1);
|
|
27218
|
+
return 1;
|
|
27219
|
+
}
|
|
27220
|
+
const key = arg.slice(2);
|
|
27221
|
+
const next = args[i + 1];
|
|
27222
|
+
if (!booleanFlags?.has(key) && next !== void 0 && !next.startsWith("--")) {
|
|
27223
|
+
flags[key] = next;
|
|
27224
|
+
return 2;
|
|
27225
|
+
}
|
|
27226
|
+
flags[key] = true;
|
|
27227
|
+
return 1;
|
|
27228
|
+
}
|
|
26681
27229
|
function findOnPath(names) {
|
|
26682
27230
|
for (const dir of (process.env.PATH ?? "").split(delimiter2)) {
|
|
26683
27231
|
if (!dir) continue;
|
|
@@ -26711,6 +27259,7 @@ __export(generate_exports, {
|
|
|
26711
27259
|
DEFAULT_FIELDS: () => DEFAULT_FIELDS,
|
|
26712
27260
|
GENERATORS: () => GENERATORS,
|
|
26713
27261
|
RESOLUTION_ENVELOPE_VERSION: () => RESOLUTION_ENVELOPE_VERSION,
|
|
27262
|
+
RESOLUTION_FLAGS: () => RESOLUTION_FLAGS,
|
|
26714
27263
|
SQL_RESERVED_TABLE_NAMES: () => SQL_RESERVED_TABLE_NAMES,
|
|
26715
27264
|
aiFill: () => aiFill,
|
|
26716
27265
|
currentResolution: () => currentResolution,
|
|
@@ -27027,6 +27576,10 @@ async function generate(what, name, extraArgs = []) {
|
|
|
27027
27576
|
extraArgs = [name, ...extraArgs];
|
|
27028
27577
|
name = "";
|
|
27029
27578
|
}
|
|
27579
|
+
if (GENERATORS[what] && !noNameGenerators.has(what) && name.startsWith("-")) {
|
|
27580
|
+
console.log(`Invalid ${what} name: '${name}' - names can't start with '-'.`);
|
|
27581
|
+
process.exit(1);
|
|
27582
|
+
}
|
|
27030
27583
|
if (!noNameGenerators.has(what) && !name) {
|
|
27031
27584
|
console.error(` Usage: tina4nodejs generate ${what} <name> [options]`);
|
|
27032
27585
|
process.exit(1);
|
|
@@ -27343,7 +27896,7 @@ function generateCrud(name, flags) {
|
|
|
27343
27896
|
if (!__resolution.jsonMode) console.log(`
|
|
27344
27897
|
Generating CRUD for ${name}...
|
|
27345
27898
|
`);
|
|
27346
|
-
generateModel(name, flags, false);
|
|
27899
|
+
if (!flags["skip-model"]) generateModel(name, flags, false);
|
|
27347
27900
|
generateCrudAdminRoute(name, table2, isPublic);
|
|
27348
27901
|
if (!flags["no-templates"]) copyCrudTemplates();
|
|
27349
27902
|
generateCrudGateTest(name, table2, isPublic);
|
|
@@ -28653,7 +29206,7 @@ for (const stmt of statements(downSql)) db.execute(stmt);
|
|
|
28653
29206
|
assert("DOWN drops the ${table2} table", db.tableExists("${table2}") === false);`;
|
|
28654
29207
|
writeTest(`${table2}_migration`, standaloneTest(doc, body));
|
|
28655
29208
|
}
|
|
28656
|
-
var FIELD_TYPE_MAP, SQL_RESERVED_TABLE_NAMES, RESOLUTION_ENVELOPE_VERSION, __resolution, TINA4_EDIT_MARKER, DEFAULT_FIELDS, GENERATORS, GENERATOR_LIST, NEXT_STEPS;
|
|
29209
|
+
var FIELD_TYPE_MAP, SQL_RESERVED_TABLE_NAMES, RESOLUTION_ENVELOPE_VERSION, __resolution, TINA4_EDIT_MARKER, DEFAULT_FIELDS, GENERATORS, RESOLUTION_FLAGS, GENERATOR_LIST, NEXT_STEPS;
|
|
28657
29210
|
var init_generate = __esm({
|
|
28658
29211
|
"src/commands/generate.ts"() {
|
|
28659
29212
|
"use strict";
|
|
@@ -28766,22 +29319,23 @@ var init_generate = __esm({
|
|
|
28766
29319
|
TINA4_EDIT_MARKER = /^\s*(?:\/\/|--|\{#|#)\s*tina4:edit\s+(.+?)(?:\s*#\})?\s*$/;
|
|
28767
29320
|
DEFAULT_FIELDS = [["name", "string"]];
|
|
28768
29321
|
GENERATORS = {
|
|
28769
|
-
model: { handler: generateModel, usage: '<Name> [--fields "name:string,price:float"] [--table-name <name>]', summary: "ORM model + matching migration" },
|
|
28770
|
-
route: { handler: generateRoute, usage: "<name> [--model Name] [--public]", summary: "CRUD route file, secure by default (--public opens writes)" },
|
|
28771
|
-
crud: { handler: generateCrud, usage: '<Name> [--fields "..."] [--public] [--no-templates]', summary: "Model + migration + AutoCrud-backed admin page (toCrud) + editable crud/ templates + gate test" },
|
|
28772
|
-
migration: { handler: (n, f) => generateMigration(n, f, void 0, void 0, !f["no-test"]), usage: "<description>", summary: "Timestamped migration file (UP/DOWN)" },
|
|
28773
|
-
middleware: { handler: generateMiddleware, usage: "<Name>", summary: "Middleware with before/after hooks" },
|
|
28774
|
-
test: { handler: generateTest, usage: "<name> [--model Name]", summary: "Test file" },
|
|
28775
|
-
form: { handler: generateForm2, usage: '<Name> [--fields "..."]', summary: "Form template with inputs matching model fields" },
|
|
28776
|
-
view: { handler: generateView, usage: '<Name> [--fields "..."]', summary: "List + detail view templates" },
|
|
28777
|
-
auth: { handler: (_n, f) => generateAuth(f), usage: "", summary: "Login/register routes (public) + User model + templates" },
|
|
28778
|
-
service: { handler: generateService, usage: '<Name> [--every 5m | --cron "..."]', summary: "Scheduled ServiceRunner task (src/services/)" },
|
|
28779
|
-
queue: { handler: generateQueue, usage: "<topic>", summary: "Producer + consumer daemon worker (src/services/)" },
|
|
28780
|
-
validator: { handler: generateValidator, usage: "<Name>", summary: "Request-body Validator (src/validators/)" },
|
|
28781
|
-
seeder: { handler: generateSeeder, usage: "<Model>", summary: "FakeData + seedOrm seeder (src/seeds/)" },
|
|
28782
|
-
websocket: { handler: generateWebsocket, usage: "<path>", summary: "websocket() handler (src/routes/)" },
|
|
28783
|
-
listener: { handler: generateListener, usage: "<event>", summary: "Events.on(event) listener (src/listeners/)" }
|
|
28784
|
-
};
|
|
29322
|
+
model: { handler: generateModel, flags: { fields: true, "table-name": true, "no-migration": false }, usage: '<Name> [--fields "name:string,price:float"] [--table-name <name>]', summary: "ORM model + matching migration" },
|
|
29323
|
+
route: { handler: generateRoute, flags: { model: true, public: false, "table-name": true }, usage: "<name> [--model Name] [--public]", summary: "CRUD route file, secure by default (--public opens writes)" },
|
|
29324
|
+
crud: { handler: generateCrud, flags: { fields: true, "table-name": true, public: false, "no-templates": false, "no-migration": false, "skip-model": false }, usage: '<Name> [--fields "..."] [--public] [--no-templates] [--skip-model]', summary: "Model + migration + AutoCrud-backed admin page (toCrud) + editable crud/ templates + gate test" },
|
|
29325
|
+
migration: { handler: (n, f) => generateMigration(n, f, void 0, void 0, !f["no-test"]), flags: { fields: true, "table-name": true, "no-test": false }, usage: "<description>", summary: "Timestamped migration file (UP/DOWN)" },
|
|
29326
|
+
middleware: { handler: generateMiddleware, flags: {}, usage: "<Name>", summary: "Middleware with before/after hooks" },
|
|
29327
|
+
test: { handler: generateTest, flags: { model: true, public: false, "secure-writes": false }, usage: "<name> [--model Name]", summary: "Test file" },
|
|
29328
|
+
form: { handler: generateForm2, flags: { fields: true, "table-name": true }, usage: '<Name> [--fields "..."]', summary: "Form template with inputs matching model fields" },
|
|
29329
|
+
view: { handler: generateView, flags: { fields: true, "table-name": true }, usage: '<Name> [--fields "..."]', summary: "List + detail view templates" },
|
|
29330
|
+
auth: { handler: (_n, f) => generateAuth(f), flags: {}, usage: "", summary: "Login/register routes (public) + User model + templates" },
|
|
29331
|
+
service: { handler: generateService, flags: { every: true, cron: true }, usage: '<Name> [--every 5m | --cron "..."]', summary: "Scheduled ServiceRunner task (src/services/)" },
|
|
29332
|
+
queue: { handler: generateQueue, flags: {}, usage: "<topic>", summary: "Producer + consumer daemon worker (src/services/)" },
|
|
29333
|
+
validator: { handler: generateValidator, flags: {}, usage: "<Name>", summary: "Request-body Validator (src/validators/)" },
|
|
29334
|
+
seeder: { handler: generateSeeder, flags: { "table-name": true }, usage: "<Model>", summary: "FakeData + seedOrm seeder (src/seeds/)" },
|
|
29335
|
+
websocket: { handler: generateWebsocket, flags: {}, usage: "<path>", summary: "websocket() handler (src/routes/)" },
|
|
29336
|
+
listener: { handler: generateListener, flags: {}, usage: "<event>", summary: "Events.on(event) listener (src/listeners/)" }
|
|
29337
|
+
};
|
|
29338
|
+
RESOLUTION_FLAGS = { json: false, "dry-run": false };
|
|
28785
29339
|
GENERATOR_LIST = Object.keys(GENERATORS).join(", ");
|
|
28786
29340
|
NEXT_STEPS = {
|
|
28787
29341
|
model: ({ name, table: table2 }) => [
|
|
@@ -28906,7 +29460,7 @@ import * as fs4 from "node:fs";
|
|
|
28906
29460
|
import * as path3 from "node:path";
|
|
28907
29461
|
import * as os from "node:os";
|
|
28908
29462
|
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
28909
|
-
import { createRequire as
|
|
29463
|
+
import { createRequire as createRequire7 } from "node:module";
|
|
28910
29464
|
import { randomBytes as randomBytes7 } from "node:crypto";
|
|
28911
29465
|
function reqSibling(pkg) {
|
|
28912
29466
|
return req(`../../${pkg}/src/index.ts`);
|
|
@@ -29065,21 +29619,45 @@ function safePath(projectRoot3, relPath) {
|
|
|
29065
29619
|
if (resolved !== projectRoot3 && !resolved.startsWith(rootPrefix)) {
|
|
29066
29620
|
throw new Error(`Path escapes project directory: ${relPath}`);
|
|
29067
29621
|
}
|
|
29068
|
-
let
|
|
29622
|
+
let realRoot;
|
|
29069
29623
|
try {
|
|
29070
|
-
|
|
29624
|
+
realRoot = fs4.realpathSync(projectRoot3);
|
|
29071
29625
|
} catch {
|
|
29072
|
-
|
|
29626
|
+
return resolved;
|
|
29073
29627
|
}
|
|
29074
|
-
|
|
29075
|
-
|
|
29076
|
-
|
|
29077
|
-
|
|
29078
|
-
throw new Error(`Path escapes project directory: ${relPath}`);
|
|
29079
|
-
}
|
|
29628
|
+
const real = realPathOf(resolved);
|
|
29629
|
+
const realPrefix = realRoot.endsWith(path3.sep) ? realRoot : realRoot + path3.sep;
|
|
29630
|
+
if (real === null || real !== realRoot && !real.startsWith(realPrefix)) {
|
|
29631
|
+
throw new Error(`Path escapes project directory: ${relPath}`);
|
|
29080
29632
|
}
|
|
29081
29633
|
return resolved;
|
|
29082
29634
|
}
|
|
29635
|
+
function realPathOf(p, hops = 0) {
|
|
29636
|
+
let probe = p;
|
|
29637
|
+
while (!fs4.existsSync(probe) && !isSymlink(probe) && path3.dirname(probe) !== probe) {
|
|
29638
|
+
probe = path3.dirname(probe);
|
|
29639
|
+
}
|
|
29640
|
+
try {
|
|
29641
|
+
return fs4.realpathSync.native(probe);
|
|
29642
|
+
} catch {
|
|
29643
|
+
if (hops >= 40) return null;
|
|
29644
|
+
let target;
|
|
29645
|
+
try {
|
|
29646
|
+
target = fs4.readlinkSync(probe);
|
|
29647
|
+
} catch {
|
|
29648
|
+
return null;
|
|
29649
|
+
}
|
|
29650
|
+
const base = path3.isAbsolute(target) ? target : path3.dirname(probe) + path3.sep + target;
|
|
29651
|
+
return realPathOf(base + p.slice(probe.length), hops + 1);
|
|
29652
|
+
}
|
|
29653
|
+
}
|
|
29654
|
+
function isSymlink(p) {
|
|
29655
|
+
try {
|
|
29656
|
+
return fs4.lstatSync(p).isSymbolicLink();
|
|
29657
|
+
} catch {
|
|
29658
|
+
return false;
|
|
29659
|
+
}
|
|
29660
|
+
}
|
|
29083
29661
|
function redactEnv(key, value) {
|
|
29084
29662
|
const sensitive = ["secret", "password", "token", "key", "credential", "api_key"];
|
|
29085
29663
|
if (sensitive.some((s) => key.toLowerCase().includes(s))) {
|
|
@@ -29924,8 +30502,10 @@ function registerDevTools(server) {
|
|
|
29924
30502
|
return { error: `Invalid path ${JSON.stringify(rel)}: ${proseErr}` };
|
|
29925
30503
|
}
|
|
29926
30504
|
rel = normalizeCoderPath(projectRoot4, rel);
|
|
29927
|
-
|
|
29928
|
-
|
|
30505
|
+
let resolved;
|
|
30506
|
+
try {
|
|
30507
|
+
resolved = safePath(projectRoot4, rel);
|
|
30508
|
+
} catch {
|
|
29929
30509
|
return { error: `Path escapes project directory: ${rel}` };
|
|
29930
30510
|
}
|
|
29931
30511
|
if (!fs4.existsSync(resolved) || !fs4.statSync(resolved).isFile()) {
|
|
@@ -30222,8 +30802,9 @@ var req, PARSE_ERROR, INVALID_REQUEST, METHOD_NOT_FOUND, INVALID_PARAMS, INTERNA
|
|
|
30222
30802
|
var init_mcp = __esm({
|
|
30223
30803
|
"../core/src/mcp.ts"() {
|
|
30224
30804
|
"use strict";
|
|
30805
|
+
init_slashTrim();
|
|
30225
30806
|
init_version();
|
|
30226
|
-
req =
|
|
30807
|
+
req = createRequire7(import.meta.url);
|
|
30227
30808
|
PARSE_ERROR = -32700;
|
|
30228
30809
|
INVALID_REQUEST = -32600;
|
|
30229
30810
|
METHOD_NOT_FOUND = -32601;
|
|
@@ -30248,7 +30829,7 @@ var init_mcp = __esm({
|
|
|
30248
30829
|
// threaded, so this in-process map is the whole coordination mechanism.
|
|
30249
30830
|
_sseChannels = /* @__PURE__ */ new Map();
|
|
30250
30831
|
constructor(mcpPath, name = "Tina4 MCP", version = "1.0.0") {
|
|
30251
|
-
this.path = mcpPath
|
|
30832
|
+
this.path = rtrimSlashes(mcpPath);
|
|
30252
30833
|
this.name = name;
|
|
30253
30834
|
this.version = version;
|
|
30254
30835
|
_McpServer._instances.push(this);
|
|
@@ -32331,7 +32912,7 @@ __export(websocket_exports, {
|
|
|
32331
32912
|
wsToken: () => wsToken
|
|
32332
32913
|
});
|
|
32333
32914
|
import { createServer as createServer2 } from "node:http";
|
|
32334
|
-
import { createHash as
|
|
32915
|
+
import { createHash as createHash9 } from "node:crypto";
|
|
32335
32916
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
32336
32917
|
function buildCloseFrame(code, reason = "") {
|
|
32337
32918
|
const reasonBytes = Buffer.from(reason, "utf-8");
|
|
@@ -32341,7 +32922,7 @@ function buildCloseFrame(code, reason = "") {
|
|
|
32341
32922
|
return buildFrame(OP_CLOSE, payload);
|
|
32342
32923
|
}
|
|
32343
32924
|
function computeAcceptKey(key) {
|
|
32344
|
-
return
|
|
32925
|
+
return createHash9("sha1").update(key + MAGIC_STRING).digest("base64");
|
|
32345
32926
|
}
|
|
32346
32927
|
function originAllowed(headers) {
|
|
32347
32928
|
const raw = (process.env.TINA4_WS_ALLOWED_ORIGINS ?? "").trim();
|
|
@@ -34032,7 +34613,7 @@ var init_job = __esm({
|
|
|
34032
34613
|
});
|
|
34033
34614
|
|
|
34034
34615
|
// ../core/src/queueBackends/liteBackend.ts
|
|
34035
|
-
import { mkdirSync as mkdirSync16, readdirSync as readdirSync12, readFileSync as readFileSync16, writeFileSync as writeFileSync12, unlinkSync as
|
|
34616
|
+
import { mkdirSync as mkdirSync16, readdirSync as readdirSync12, readFileSync as readFileSync16, writeFileSync as writeFileSync12, unlinkSync as unlinkSync8, existsSync as existsSync20 } from "node:fs";
|
|
34036
34617
|
import { join as join25 } from "node:path";
|
|
34037
34618
|
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
34038
34619
|
var LiteBackend;
|
|
@@ -34202,7 +34783,7 @@ var init_liteBackend = __esm({
|
|
|
34202
34783
|
}
|
|
34203
34784
|
if (record.availableAt && record.availableAt > now) continue;
|
|
34204
34785
|
try {
|
|
34205
|
-
|
|
34786
|
+
unlinkSync8(filePath);
|
|
34206
34787
|
} catch {
|
|
34207
34788
|
continue;
|
|
34208
34789
|
}
|
|
@@ -34236,10 +34817,10 @@ var init_liteBackend = __esm({
|
|
|
34236
34817
|
job.priority = job.priority ?? 0;
|
|
34237
34818
|
this.writeReserved(queue, job);
|
|
34238
34819
|
try {
|
|
34239
|
-
|
|
34820
|
+
unlinkSync8(filePath);
|
|
34240
34821
|
} catch {
|
|
34241
34822
|
try {
|
|
34242
|
-
|
|
34823
|
+
unlinkSync8(this.reservedPath(queue, job.id));
|
|
34243
34824
|
} catch {
|
|
34244
34825
|
}
|
|
34245
34826
|
continue;
|
|
@@ -34261,10 +34842,10 @@ var init_liteBackend = __esm({
|
|
|
34261
34842
|
job.priority = job.priority ?? 0;
|
|
34262
34843
|
this.writeReserved(queue, job);
|
|
34263
34844
|
try {
|
|
34264
|
-
|
|
34845
|
+
unlinkSync8(filePath);
|
|
34265
34846
|
} catch {
|
|
34266
34847
|
try {
|
|
34267
|
-
|
|
34848
|
+
unlinkSync8(this.reservedPath(queue, job.id));
|
|
34268
34849
|
} catch {
|
|
34269
34850
|
}
|
|
34270
34851
|
continue;
|
|
@@ -34279,7 +34860,7 @@ var init_liteBackend = __esm({
|
|
|
34279
34860
|
*/
|
|
34280
34861
|
clearReservation(queue, jobId) {
|
|
34281
34862
|
try {
|
|
34282
|
-
|
|
34863
|
+
unlinkSync8(this.reservedPath(queue, jobId));
|
|
34283
34864
|
} catch {
|
|
34284
34865
|
}
|
|
34285
34866
|
}
|
|
@@ -34322,7 +34903,7 @@ var init_liteBackend = __esm({
|
|
|
34322
34903
|
try {
|
|
34323
34904
|
const files = readdirSync12(dir).filter((f) => f.endsWith(".queue-data"));
|
|
34324
34905
|
for (const file of files) {
|
|
34325
|
-
|
|
34906
|
+
unlinkSync8(join25(dir, file));
|
|
34326
34907
|
count++;
|
|
34327
34908
|
}
|
|
34328
34909
|
} catch {
|
|
@@ -34332,7 +34913,7 @@ var init_liteBackend = __esm({
|
|
|
34332
34913
|
if (existsSync20(failedDir)) {
|
|
34333
34914
|
const files = readdirSync12(failedDir).filter((f) => f.endsWith(".queue-data"));
|
|
34334
34915
|
for (const file of files) {
|
|
34335
|
-
|
|
34916
|
+
unlinkSync8(join25(failedDir, file));
|
|
34336
34917
|
count++;
|
|
34337
34918
|
}
|
|
34338
34919
|
}
|
|
@@ -34343,7 +34924,7 @@ var init_liteBackend = __esm({
|
|
|
34343
34924
|
if (existsSync20(reservedDir)) {
|
|
34344
34925
|
const files = readdirSync12(reservedDir).filter((f) => f.endsWith(".queue-data"));
|
|
34345
34926
|
for (const file of files) {
|
|
34346
|
-
|
|
34927
|
+
unlinkSync8(join25(reservedDir, file));
|
|
34347
34928
|
count++;
|
|
34348
34929
|
}
|
|
34349
34930
|
}
|
|
@@ -34401,7 +34982,7 @@ var init_liteBackend = __esm({
|
|
|
34401
34982
|
const prefix = this.nextPrefix();
|
|
34402
34983
|
const queueDir = join25(this.basePath, q);
|
|
34403
34984
|
writeFileSync12(join25(queueDir, `${prefix}_${jobId}.queue-data`), JSON.stringify(job, null, 2));
|
|
34404
|
-
|
|
34985
|
+
unlinkSync8(filePath);
|
|
34405
34986
|
return true;
|
|
34406
34987
|
}
|
|
34407
34988
|
}
|
|
@@ -34437,7 +35018,7 @@ var init_liteBackend = __esm({
|
|
|
34437
35018
|
const files = readdirSync12(failedDir).filter((f) => f.endsWith(".queue-data"));
|
|
34438
35019
|
for (const file of files) {
|
|
34439
35020
|
try {
|
|
34440
|
-
|
|
35021
|
+
unlinkSync8(join25(failedDir, file));
|
|
34441
35022
|
count++;
|
|
34442
35023
|
} catch {
|
|
34443
35024
|
}
|
|
@@ -34452,7 +35033,7 @@ var init_liteBackend = __esm({
|
|
|
34452
35033
|
try {
|
|
34453
35034
|
const job = JSON.parse(readFileSync16(join25(dir, file), "utf-8"));
|
|
34454
35035
|
if (job.status === status2) {
|
|
34455
|
-
|
|
35036
|
+
unlinkSync8(join25(dir, file));
|
|
34456
35037
|
count++;
|
|
34457
35038
|
}
|
|
34458
35039
|
} catch {
|
|
@@ -34487,7 +35068,7 @@ var init_liteBackend = __esm({
|
|
|
34487
35068
|
job.delayUntil = null;
|
|
34488
35069
|
const prefix = this.nextPrefix();
|
|
34489
35070
|
writeFileSync12(join25(queueDir, `${prefix}_${job.id}.queue-data`), JSON.stringify(job, null, 2));
|
|
34490
|
-
|
|
35071
|
+
unlinkSync8(filePath);
|
|
34491
35072
|
count++;
|
|
34492
35073
|
} catch {
|
|
34493
35074
|
}
|
|
@@ -34519,10 +35100,10 @@ var init_liteBackend = __esm({
|
|
|
34519
35100
|
job.priority = job.priority ?? 0;
|
|
34520
35101
|
this.writeReserved(queue, job);
|
|
34521
35102
|
try {
|
|
34522
|
-
|
|
35103
|
+
unlinkSync8(filePath);
|
|
34523
35104
|
} catch {
|
|
34524
35105
|
try {
|
|
34525
|
-
|
|
35106
|
+
unlinkSync8(this.reservedPath(queue, job.id));
|
|
34526
35107
|
} catch {
|
|
34527
35108
|
}
|
|
34528
35109
|
continue;
|
|
@@ -34624,7 +35205,7 @@ var init_liteBackend = __esm({
|
|
|
34624
35205
|
retryJob(queue, job, delaySeconds) {
|
|
34625
35206
|
this.clearReservation(queue, job.id);
|
|
34626
35207
|
try {
|
|
34627
|
-
|
|
35208
|
+
unlinkSync8(join25(this.ensureFailedDir(queue), `${job.id}.queue-data`));
|
|
34628
35209
|
} catch {
|
|
34629
35210
|
}
|
|
34630
35211
|
job.attempts = (job.attempts || 0) + 1;
|
|
@@ -35174,7 +35755,8 @@ function archiveDir() {
|
|
|
35174
35755
|
return p;
|
|
35175
35756
|
}
|
|
35176
35757
|
function slugify(title) {
|
|
35177
|
-
const
|
|
35758
|
+
const dashed = (title || "").trim().toLowerCase().replace(/[^A-Za-z0-9_-]+/g, "-");
|
|
35759
|
+
const slug = trimChar(dashed, 45);
|
|
35178
35760
|
return slug.slice(0, 80) || `plan-${Math.floor(Date.now() / 1e3)}`;
|
|
35179
35761
|
}
|
|
35180
35762
|
function parse(text) {
|
|
@@ -35311,6 +35893,7 @@ var PLAN_DIR, CURRENT_FILE, ARCHIVE_SUBDIR, STEP_RE, Plan;
|
|
|
35311
35893
|
var init_plan = __esm({
|
|
35312
35894
|
"../core/src/plan.ts"() {
|
|
35313
35895
|
"use strict";
|
|
35896
|
+
init_slashTrim();
|
|
35314
35897
|
PLAN_DIR = "plan";
|
|
35315
35898
|
CURRENT_FILE = ".current";
|
|
35316
35899
|
ARCHIVE_SUBDIR = "done";
|
|
@@ -36550,7 +37133,7 @@ function relativePath(absPath, projectRoot3, frameworkRoots) {
|
|
|
36550
37133
|
}
|
|
36551
37134
|
function tokenise(text) {
|
|
36552
37135
|
if (!text) return [];
|
|
36553
|
-
const expanded = text.replace(
|
|
37136
|
+
const expanded = text.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/([A-Z])(?=[A-Z][a-z])/g, "$1 ").toLowerCase();
|
|
36554
37137
|
return expanded.split(/[\s_\-./:,;()\[\]{}\\]+/).filter((p) => p.length > 0);
|
|
36555
37138
|
}
|
|
36556
37139
|
function summariseDoc(doc) {
|
|
@@ -36781,7 +37364,7 @@ function returnFromSignature(signature) {
|
|
|
36781
37364
|
const rest = signature.slice(close + 1).trim();
|
|
36782
37365
|
return rest.startsWith(":") ? rest.slice(1).trim() : "";
|
|
36783
37366
|
}
|
|
36784
|
-
var STDLIB_ALLOWLIST, _DOCS_CACHE, __FILENAME, __DIRNAME, USER_DIRS,
|
|
37367
|
+
var STDLIB_ALLOWLIST, _DOCS_CACHE, __FILENAME, __DIRNAME, USER_DIRS, FENCE_RE, CALL_RE, sharedFrameworkIndex, Docs;
|
|
36785
37368
|
var init_docs = __esm({
|
|
36786
37369
|
"../core/src/docs.ts"() {
|
|
36787
37370
|
"use strict";
|
|
@@ -36920,7 +37503,6 @@ var init_docs = __esm({
|
|
|
36920
37503
|
__FILENAME = fileURLToPath7(import.meta.url);
|
|
36921
37504
|
__DIRNAME = path8.dirname(__FILENAME);
|
|
36922
37505
|
USER_DIRS = ["src/orm", "src/routes", "src/app", "src/services", "src/models"];
|
|
36923
|
-
CAMEL_SPLIT = /([a-z0-9])([A-Z])|([A-Z]+)([A-Z][a-z])/g;
|
|
36924
37506
|
FENCE_RE = new RegExp(
|
|
36925
37507
|
String.fromCharCode(96, 96, 96) + "[a-zA-Z0-9_+-]*\\n([\\s\\S]*?)\\n" + String.fromCharCode(96, 96, 96),
|
|
36926
37508
|
"g"
|
|
@@ -37294,7 +37876,7 @@ ${end}
|
|
|
37294
37876
|
|
|
37295
37877
|
// ../core/src/devAdmin.ts
|
|
37296
37878
|
import { cpus as osCpus } from "node:os";
|
|
37297
|
-
import { readFileSync as readFileSync20, writeFileSync as writeFileSync16, existsSync as existsSync24, readdirSync as readdirSync16, mkdirSync as mkdirSync19, copyFileSync as copyFileSync3, statSync as statSync18, openSync as
|
|
37879
|
+
import { readFileSync as readFileSync20, writeFileSync as writeFileSync16, existsSync as existsSync24, readdirSync as readdirSync16, mkdirSync as mkdirSync19, copyFileSync as copyFileSync3, statSync as statSync18, openSync as openSync5, closeSync as closeSync5, fstatSync as fstatSync3, fchmodSync as fchmodSync2, ftruncateSync as ftruncateSync2, constants as constants4, realpathSync as realpathSync6, lstatSync as lstatSync3 } from "node:fs";
|
|
37298
37880
|
import { join as join29, dirname as dirname15, resolve as resolve17, relative as relative9, sep as sep8, basename as basename6 } from "node:path";
|
|
37299
37881
|
import { fileURLToPath as fileURLToPath8 } from "node:url";
|
|
37300
37882
|
import { timingSafeEqual as timingSafeEqual2 } from "node:crypto";
|
|
@@ -37493,8 +38075,41 @@ function quoteTableRef(name) {
|
|
|
37493
38075
|
}
|
|
37494
38076
|
return parts.map((p) => `"${p}"`).join(".");
|
|
37495
38077
|
}
|
|
38078
|
+
function parseSeedRequest(url, body) {
|
|
38079
|
+
const b = body ?? {};
|
|
38080
|
+
const table2 = String(url.searchParams.get("table") ?? b.table ?? "");
|
|
38081
|
+
const count = parseInt(String(url.searchParams.get("count") ?? b.count ?? "10"), 10) || 10;
|
|
38082
|
+
const seedRaw = url.searchParams.get("seed") ?? b.seed;
|
|
38083
|
+
const seed = seedRaw !== void 0 && seedRaw !== null && String(seedRaw) !== "" ? Number.isNaN(parseInt(String(seedRaw), 10)) ? void 0 : parseInt(String(seedRaw), 10) : void 0;
|
|
38084
|
+
const clear = String(url.searchParams.get("clear") ?? b.clear ?? "") === "true" || b.clear === true;
|
|
38085
|
+
const strict = String(url.searchParams.get("strict") ?? b.strict ?? "") === "true" || b.strict === true;
|
|
38086
|
+
return { table: table2, count, seed, clear, strict };
|
|
38087
|
+
}
|
|
38088
|
+
function buildSeedFieldMap(columns, fake) {
|
|
38089
|
+
const rules = [
|
|
38090
|
+
[(n) => n.includes("email"), () => fake.email()],
|
|
38091
|
+
[(n) => n.includes("name"), () => fake.name()],
|
|
38092
|
+
[(n) => n.includes("phone"), () => fake.phone()],
|
|
38093
|
+
[(n) => n.includes("address") || n.includes("city") || n.includes("country"), () => fake.address()],
|
|
38094
|
+
[(n) => n.includes("url") || n.includes("website"), () => fake.url()],
|
|
38095
|
+
[(_n, t) => t.includes("int"), () => fake.integer(1, 1e3)],
|
|
38096
|
+
[(_n, t) => /real|float|double|numeric|decimal/.test(t), () => fake.numeric(0, 1e3, 2)],
|
|
38097
|
+
[(_n, t) => t.includes("bool"), () => fake.boolean()],
|
|
38098
|
+
[(_n, t) => t.includes("date") || t.includes("time"), () => fake.date()]
|
|
38099
|
+
];
|
|
38100
|
+
const sentence = () => fake.sentence(3);
|
|
38101
|
+
const fieldMap = {};
|
|
38102
|
+
for (const col of columns) {
|
|
38103
|
+
if (col.name.toLowerCase() === "id" || col.primaryKey === true) continue;
|
|
38104
|
+
const name = col.name.toLowerCase();
|
|
38105
|
+
const type2 = col.type.toLowerCase();
|
|
38106
|
+
const rule = rules.find(([matches]) => matches(name, type2));
|
|
38107
|
+
fieldMap[col.name] = rule ? rule[1] : sentence;
|
|
38108
|
+
}
|
|
38109
|
+
return fieldMap;
|
|
38110
|
+
}
|
|
37496
38111
|
function supervisorBaseUrl() {
|
|
37497
|
-
const explicit = (process.env.TINA4_SUPERVISOR_URL ?? "")
|
|
38112
|
+
const explicit = rtrimSlashes(process.env.TINA4_SUPERVISOR_URL ?? "");
|
|
37498
38113
|
if (explicit) return explicit;
|
|
37499
38114
|
const agentPort = (process.env.TINA4_AGENT_PORT ?? "").trim();
|
|
37500
38115
|
if (/^\d+$/.test(agentPort)) return `http://127.0.0.1:${parseInt(agentPort, 10)}`;
|
|
@@ -37502,6 +38117,42 @@ function supervisorBaseUrl() {
|
|
|
37502
38117
|
if (/^\d+$/.test(fwPort)) return `http://127.0.0.1:${parseInt(fwPort, 10) + 2e3}`;
|
|
37503
38118
|
return "http://127.0.0.1:9145";
|
|
37504
38119
|
}
|
|
38120
|
+
function buildSupervisorBody(method, body) {
|
|
38121
|
+
if (method !== "POST" && method !== "PUT" && method !== "PATCH" && method !== "DELETE") return void 0;
|
|
38122
|
+
if (body === void 0 || body === null) return void 0;
|
|
38123
|
+
if (typeof body === "string") return body;
|
|
38124
|
+
if (typeof body !== "object") return void 0;
|
|
38125
|
+
let outBody = body;
|
|
38126
|
+
if (!Array.isArray(body)) {
|
|
38127
|
+
const pf = body.plan_file;
|
|
38128
|
+
if (typeof pf === "string" && pf && !pf.includes("/")) outBody = { ...body, plan_file: `plan/${pf}` };
|
|
38129
|
+
}
|
|
38130
|
+
return JSON.stringify(outBody);
|
|
38131
|
+
}
|
|
38132
|
+
async function streamEventStream(res, upstream, timer) {
|
|
38133
|
+
res.raw.writeHead(upstream.status || 200, {
|
|
38134
|
+
"Content-Type": upstream.headers.get("content-type") ?? "text/event-stream",
|
|
38135
|
+
"Cache-Control": "no-cache",
|
|
38136
|
+
Connection: "keep-alive"
|
|
38137
|
+
});
|
|
38138
|
+
if (typeof res.raw.flushHeaders === "function") res.raw.flushHeaders();
|
|
38139
|
+
if (!upstream.body) {
|
|
38140
|
+
res.raw.end();
|
|
38141
|
+
clearTimeout(timer);
|
|
38142
|
+
return;
|
|
38143
|
+
}
|
|
38144
|
+
const reader = upstream.body.getReader();
|
|
38145
|
+
try {
|
|
38146
|
+
while (true) {
|
|
38147
|
+
const { done, value } = await reader.read();
|
|
38148
|
+
if (done) break;
|
|
38149
|
+
if (value) res.raw.write(Buffer.from(value));
|
|
38150
|
+
}
|
|
38151
|
+
} finally {
|
|
38152
|
+
clearTimeout(timer);
|
|
38153
|
+
res.raw.end();
|
|
38154
|
+
}
|
|
38155
|
+
}
|
|
37505
38156
|
async function proxyToSupervisor(req2, res, downstreamPath) {
|
|
37506
38157
|
const base = supervisorBaseUrl();
|
|
37507
38158
|
let qs = "";
|
|
@@ -37512,24 +38163,7 @@ async function proxyToSupervisor(req2, res, downstreamPath) {
|
|
|
37512
38163
|
}
|
|
37513
38164
|
const target = `${base}${downstreamPath}${qs}`;
|
|
37514
38165
|
const method = (req2.method ?? "GET").toUpperCase();
|
|
37515
|
-
|
|
37516
|
-
if (method === "POST" || method === "PUT" || method === "PATCH" || method === "DELETE") {
|
|
37517
|
-
const body = req2.body;
|
|
37518
|
-
if (body !== void 0 && body !== null) {
|
|
37519
|
-
if (typeof body === "string") {
|
|
37520
|
-
bodyText = body;
|
|
37521
|
-
} else if (typeof body === "object") {
|
|
37522
|
-
let outBody = body;
|
|
37523
|
-
if (!Array.isArray(body)) {
|
|
37524
|
-
const pf = body.plan_file;
|
|
37525
|
-
if (typeof pf === "string" && pf && !pf.includes("/")) {
|
|
37526
|
-
outBody = { ...body, plan_file: `plan/${pf}` };
|
|
37527
|
-
}
|
|
37528
|
-
}
|
|
37529
|
-
bodyText = JSON.stringify(outBody);
|
|
37530
|
-
}
|
|
37531
|
-
}
|
|
37532
|
-
}
|
|
38166
|
+
const bodyText = buildSupervisorBody(method, req2.body);
|
|
37533
38167
|
const timeoutMs = downstreamPath === "/execute" || downstreamPath === "/chat" ? 6e5 : 3e4;
|
|
37534
38168
|
const ctrl = new AbortController();
|
|
37535
38169
|
const timer = setTimeout(() => ctrl.abort(), timeoutMs);
|
|
@@ -37555,30 +38189,7 @@ async function proxyToSupervisor(req2, res, downstreamPath) {
|
|
|
37555
38189
|
}
|
|
37556
38190
|
const ct = (upstream.headers.get("content-type") ?? "").toLowerCase();
|
|
37557
38191
|
if (ct.includes("text/event-stream")) {
|
|
37558
|
-
res
|
|
37559
|
-
"Content-Type": upstream.headers.get("content-type") ?? "text/event-stream",
|
|
37560
|
-
"Cache-Control": "no-cache",
|
|
37561
|
-
Connection: "keep-alive"
|
|
37562
|
-
});
|
|
37563
|
-
if (typeof res.raw.flushHeaders === "function") {
|
|
37564
|
-
res.raw.flushHeaders();
|
|
37565
|
-
}
|
|
37566
|
-
if (!upstream.body) {
|
|
37567
|
-
res.raw.end();
|
|
37568
|
-
clearTimeout(timer);
|
|
37569
|
-
return;
|
|
37570
|
-
}
|
|
37571
|
-
const reader = upstream.body.getReader();
|
|
37572
|
-
try {
|
|
37573
|
-
while (true) {
|
|
37574
|
-
const { done, value } = await reader.read();
|
|
37575
|
-
if (done) break;
|
|
37576
|
-
if (value) res.raw.write(Buffer.from(value));
|
|
37577
|
-
}
|
|
37578
|
-
} finally {
|
|
37579
|
-
clearTimeout(timer);
|
|
37580
|
-
res.raw.end();
|
|
37581
|
-
}
|
|
38192
|
+
await streamEventStream(res, upstream, timer);
|
|
37582
38193
|
return;
|
|
37583
38194
|
}
|
|
37584
38195
|
clearTimeout(timer);
|
|
@@ -37695,13 +38306,13 @@ function handleGalleryDeploy(router) {
|
|
|
37695
38306
|
res.json({ deployed: name, files: copied });
|
|
37696
38307
|
};
|
|
37697
38308
|
}
|
|
37698
|
-
function
|
|
38309
|
+
function realPathOf2(target) {
|
|
37699
38310
|
let existing = target;
|
|
37700
38311
|
const tail = [];
|
|
37701
38312
|
for (; ; ) {
|
|
37702
38313
|
let present = false;
|
|
37703
38314
|
try {
|
|
37704
|
-
|
|
38315
|
+
lstatSync3(existing);
|
|
37705
38316
|
present = true;
|
|
37706
38317
|
} catch {
|
|
37707
38318
|
}
|
|
@@ -37713,9 +38324,9 @@ function realPathOf(target) {
|
|
|
37713
38324
|
}
|
|
37714
38325
|
function safeJoin(projectRoot3, rel, extraRoots = []) {
|
|
37715
38326
|
try {
|
|
37716
|
-
const root =
|
|
37717
|
-
const resolved =
|
|
37718
|
-
const roots = [root, ...extraRoots.filter(Boolean).map((r) =>
|
|
38327
|
+
const root = realPathOf2(resolve17(projectRoot3));
|
|
38328
|
+
const resolved = realPathOf2(resolve17(root, rel));
|
|
38329
|
+
const roots = [root, ...extraRoots.filter(Boolean).map((r) => realPathOf2(resolve17(r)))];
|
|
37719
38330
|
for (const r of roots) {
|
|
37720
38331
|
if (resolved === r || resolved.startsWith(r.endsWith(sep8) ? r : r + sep8)) return resolved;
|
|
37721
38332
|
}
|
|
@@ -37724,7 +38335,7 @@ function safeJoin(projectRoot3, rel, extraRoots = []) {
|
|
|
37724
38335
|
return null;
|
|
37725
38336
|
}
|
|
37726
38337
|
function resolvedRelative(projectRoot3, resolvedPath) {
|
|
37727
|
-
return relative9(
|
|
38338
|
+
return relative9(realPathOf2(resolve17(projectRoot3)), resolvedPath);
|
|
37728
38339
|
}
|
|
37729
38340
|
function devFilesHidden(name) {
|
|
37730
38341
|
if (DEV_FILES_IGNORED.has(name)) return true;
|
|
@@ -37752,7 +38363,7 @@ async function devGitInfo(root) {
|
|
|
37752
38363
|
if (!inside || inside.trim() !== "true") return empty;
|
|
37753
38364
|
const branch = (git(["rev-parse", "--abbrev-ref", "HEAD"]) ?? "").trim();
|
|
37754
38365
|
const topRaw = git(["rev-parse", "--show-toplevel"]);
|
|
37755
|
-
const gitRoot = topRaw && topRaw.trim() !== "" ? topRaw.trim().replace(/\\/g, "/")
|
|
38366
|
+
const gitRoot = topRaw && topRaw.trim() !== "" ? rtrimSlashes(topRaw.trim().replace(/\\/g, "/")) : null;
|
|
37756
38367
|
const status2 = /* @__PURE__ */ new Map();
|
|
37757
38368
|
const porcelain = git(["status", "--porcelain", "-uall"]);
|
|
37758
38369
|
if (porcelain) {
|
|
@@ -37771,6 +38382,44 @@ async function devGitInfo(root) {
|
|
|
37771
38382
|
return empty;
|
|
37772
38383
|
}
|
|
37773
38384
|
}
|
|
38385
|
+
function devGitLabel(gitPath, isDir, gitStatus) {
|
|
38386
|
+
const code = gitStatus.get(gitPath);
|
|
38387
|
+
if (code !== void 0) return devGitStatusLabel(code);
|
|
38388
|
+
if (isDir) {
|
|
38389
|
+
const prefix = gitPath + "/";
|
|
38390
|
+
for (const [gf, gc] of gitStatus) {
|
|
38391
|
+
if (gf.startsWith(prefix)) return gc === "??" ? "untracked" : "modified";
|
|
38392
|
+
}
|
|
38393
|
+
}
|
|
38394
|
+
return "clean";
|
|
38395
|
+
}
|
|
38396
|
+
function devDirHasVisibleChild(full) {
|
|
38397
|
+
try {
|
|
38398
|
+
for (const c of readdirSync16(full)) {
|
|
38399
|
+
if (!devFilesHidden(c)) return true;
|
|
38400
|
+
}
|
|
38401
|
+
} catch {
|
|
38402
|
+
}
|
|
38403
|
+
return false;
|
|
38404
|
+
}
|
|
38405
|
+
function buildFileEntry(name, full, entryRel, cwdInGit, gitStatus) {
|
|
38406
|
+
let isDir = false;
|
|
38407
|
+
let size = null;
|
|
38408
|
+
try {
|
|
38409
|
+
const st = statSync18(full);
|
|
38410
|
+
isDir = st.isDirectory();
|
|
38411
|
+
if (!isDir) size = st.size;
|
|
38412
|
+
} catch {
|
|
38413
|
+
}
|
|
38414
|
+
return {
|
|
38415
|
+
name,
|
|
38416
|
+
path: entryRel,
|
|
38417
|
+
is_dir: isDir,
|
|
38418
|
+
has_children: isDir ? devDirHasVisibleChild(full) : null,
|
|
38419
|
+
git_status: devGitLabel(cwdInGit + entryRel, isDir, gitStatus),
|
|
38420
|
+
size
|
|
38421
|
+
};
|
|
38422
|
+
}
|
|
37774
38423
|
function devAdminLanguage(rel) {
|
|
37775
38424
|
const base = (rel.split(/[\\/]/).pop() ?? "").toLowerCase();
|
|
37776
38425
|
if (base === "dockerfile" || base === "dockerfile.dev" || base === "dockerfile.prod") {
|
|
@@ -37785,14 +38434,14 @@ function devAdminLanguage(rel) {
|
|
|
37785
38434
|
function readDevFile(target) {
|
|
37786
38435
|
let fd;
|
|
37787
38436
|
try {
|
|
37788
|
-
fd =
|
|
37789
|
-
if (!
|
|
38437
|
+
fd = openSync5(target, constants4.O_RDONLY | constants4.O_NOFOLLOW | constants4.O_NONBLOCK);
|
|
38438
|
+
if (!fstatSync3(fd).isFile()) return null;
|
|
37790
38439
|
return readFileSync20(fd);
|
|
37791
38440
|
} catch (error2) {
|
|
37792
38441
|
if (["ENOENT", "ENOTDIR", "ELOOP"].includes(error2.code ?? "")) return null;
|
|
37793
38442
|
throw error2;
|
|
37794
38443
|
} finally {
|
|
37795
|
-
if (fd !== void 0)
|
|
38444
|
+
if (fd !== void 0) closeSync5(fd);
|
|
37796
38445
|
}
|
|
37797
38446
|
}
|
|
37798
38447
|
function mcpSecureEqual(expected, provided) {
|
|
@@ -38023,6 +38672,7 @@ var cpuCount, DEV_MCP_PREFIXES, DEV_PUBLIC_ASSETS, DEV_SECRET_BASENAMES, DEV_SEC
|
|
|
38023
38672
|
var init_devAdmin = __esm({
|
|
38024
38673
|
"../core/src/devAdmin.ts"() {
|
|
38025
38674
|
"use strict";
|
|
38675
|
+
init_slashTrim();
|
|
38026
38676
|
init_devMailbox();
|
|
38027
38677
|
init_upstreamResponse();
|
|
38028
38678
|
init_dotenv();
|
|
@@ -38500,7 +39150,8 @@ var init_devAdmin = __esm({
|
|
|
38500
39150
|
router.addRoute({
|
|
38501
39151
|
method: route.method,
|
|
38502
39152
|
pattern: route.pattern,
|
|
38503
|
-
handler: route.handler
|
|
39153
|
+
handler: route.handler,
|
|
39154
|
+
noAuth: true
|
|
38504
39155
|
});
|
|
38505
39156
|
}
|
|
38506
39157
|
if (mcpEnabled()) {
|
|
@@ -38524,7 +39175,8 @@ var init_devAdmin = __esm({
|
|
|
38524
39175
|
router.addRoute({
|
|
38525
39176
|
method: route.method,
|
|
38526
39177
|
pattern: route.pattern,
|
|
38527
|
-
handler: route.handler
|
|
39178
|
+
handler: route.handler,
|
|
39179
|
+
noAuth: true
|
|
38528
39180
|
});
|
|
38529
39181
|
}
|
|
38530
39182
|
getDefaultDevServer();
|
|
@@ -38856,13 +39508,7 @@ var init_devAdmin = __esm({
|
|
|
38856
39508
|
};
|
|
38857
39509
|
handleSeed = async (req2, res) => {
|
|
38858
39510
|
const url = new URL(req2.url ?? "/", "http://localhost");
|
|
38859
|
-
const
|
|
38860
|
-
const table2 = url.searchParams.get("table") ?? body?.table ?? "";
|
|
38861
|
-
const count = parseInt(String(url.searchParams.get("count") ?? body?.count ?? "10"), 10) || 10;
|
|
38862
|
-
const seedRaw = url.searchParams.get("seed") ?? body?.seed;
|
|
38863
|
-
const seed = seedRaw !== void 0 && seedRaw !== null && String(seedRaw) !== "" ? Number.isNaN(parseInt(String(seedRaw), 10)) ? void 0 : parseInt(String(seedRaw), 10) : void 0;
|
|
38864
|
-
const clear = String(url.searchParams.get("clear") ?? body?.clear ?? "") === "true" || body?.clear === true;
|
|
38865
|
-
const strict = String(url.searchParams.get("strict") ?? body?.strict ?? "") === "true" || body?.strict === true;
|
|
39511
|
+
const { table: table2, count, seed, clear, strict } = parseSeedRequest(url, req2.body);
|
|
38866
39512
|
if (!table2) {
|
|
38867
39513
|
res.json({ error: "Missing table parameter" });
|
|
38868
39514
|
return;
|
|
@@ -38877,33 +39523,7 @@ var init_devAdmin = __esm({
|
|
|
38877
39523
|
res.json({ error: `Table '${table2}' not found or has no columns` });
|
|
38878
39524
|
return;
|
|
38879
39525
|
}
|
|
38880
|
-
const fieldMap =
|
|
38881
|
-
for (const col of columns) {
|
|
38882
|
-
const name = col.name.toLowerCase();
|
|
38883
|
-
const type2 = col.type.toLowerCase();
|
|
38884
|
-
if (name === "id" || col.primaryKey === true) continue;
|
|
38885
|
-
if (name.includes("email")) {
|
|
38886
|
-
fieldMap[col.name] = () => fake.email();
|
|
38887
|
-
} else if (name.includes("name")) {
|
|
38888
|
-
fieldMap[col.name] = () => fake.name();
|
|
38889
|
-
} else if (name.includes("phone")) {
|
|
38890
|
-
fieldMap[col.name] = () => fake.phone();
|
|
38891
|
-
} else if (name.includes("address") || name.includes("city") || name.includes("country")) {
|
|
38892
|
-
fieldMap[col.name] = () => fake.address();
|
|
38893
|
-
} else if (name.includes("url") || name.includes("website")) {
|
|
38894
|
-
fieldMap[col.name] = () => fake.url();
|
|
38895
|
-
} else if (type2.includes("int")) {
|
|
38896
|
-
fieldMap[col.name] = () => fake.integer(1, 1e3);
|
|
38897
|
-
} else if (type2.includes("real") || type2.includes("float") || type2.includes("double") || type2.includes("numeric") || type2.includes("decimal")) {
|
|
38898
|
-
fieldMap[col.name] = () => fake.numeric(0, 1e3, 2);
|
|
38899
|
-
} else if (type2.includes("bool")) {
|
|
38900
|
-
fieldMap[col.name] = () => fake.boolean();
|
|
38901
|
-
} else if (type2.includes("date") || type2.includes("time")) {
|
|
38902
|
-
fieldMap[col.name] = () => fake.date();
|
|
38903
|
-
} else {
|
|
38904
|
-
fieldMap[col.name] = () => fake.sentence(3);
|
|
38905
|
-
}
|
|
38906
|
-
}
|
|
39526
|
+
const fieldMap = buildSeedFieldMap(columns, fake);
|
|
38907
39527
|
const summary = await seedTable2(db, table2, count, fieldMap, void 0, { clear, strict });
|
|
38908
39528
|
res.json({ seeded: summary.seeded, failed: summary.failed, errors: summary.errors, table: table2 });
|
|
38909
39529
|
} catch (e) {
|
|
@@ -39076,9 +39696,9 @@ var init_devAdmin = __esm({
|
|
|
39076
39696
|
};
|
|
39077
39697
|
handleTest = async (_req, res) => {
|
|
39078
39698
|
try {
|
|
39079
|
-
const { execFile } = await import("node:child_process");
|
|
39699
|
+
const { execFile: execFile2 } = await import("node:child_process");
|
|
39080
39700
|
const { promisify } = await import("node:util");
|
|
39081
|
-
const run = promisify(
|
|
39701
|
+
const run = promisify(execFile2);
|
|
39082
39702
|
try {
|
|
39083
39703
|
const { stdout, stderr } = await run("npm", ["test"], {
|
|
39084
39704
|
cwd: resolve17(process.cwd()),
|
|
@@ -39196,9 +39816,9 @@ var init_devAdmin = __esm({
|
|
|
39196
39816
|
}
|
|
39197
39817
|
try {
|
|
39198
39818
|
const envPath = join29(process.cwd(), ".env");
|
|
39199
|
-
const fd =
|
|
39819
|
+
const fd = openSync5(envPath, constants4.O_RDWR | constants4.O_APPEND | constants4.O_CREAT | (constants4.O_NOFOLLOW ?? 0) | (constants4.O_NONBLOCK ?? 0), 384);
|
|
39200
39820
|
try {
|
|
39201
|
-
const info =
|
|
39821
|
+
const info = fstatSync3(fd);
|
|
39202
39822
|
if (!info.isFile() || info.nlink !== 1) throw new Error("Refusing a non-regular or multiply-linked configuration file");
|
|
39203
39823
|
fchmodSync2(fd, 384);
|
|
39204
39824
|
const lines = readFileSync20(fd, "utf-8").split("\n");
|
|
@@ -39228,10 +39848,10 @@ var init_devAdmin = __esm({
|
|
|
39228
39848
|
for (const [key, found] of Object.entries(keysFound)) {
|
|
39229
39849
|
if (!found) newLines.push(`${key}=${values[key]}`);
|
|
39230
39850
|
}
|
|
39231
|
-
|
|
39851
|
+
ftruncateSync2(fd, 0);
|
|
39232
39852
|
writeFileSync16(fd, newLines.join("\n") + "\n");
|
|
39233
39853
|
} finally {
|
|
39234
|
-
|
|
39854
|
+
closeSync5(fd);
|
|
39235
39855
|
}
|
|
39236
39856
|
res.json({ success: true });
|
|
39237
39857
|
} catch (e) {
|
|
@@ -39354,48 +39974,7 @@ var init_devAdmin = __esm({
|
|
|
39354
39974
|
const full = join29(target, name);
|
|
39355
39975
|
const entryRel = relative9(root, full).replace(/\\/g, "/");
|
|
39356
39976
|
if (isSecretPath(entryRel)) continue;
|
|
39357
|
-
|
|
39358
|
-
let size = null;
|
|
39359
|
-
try {
|
|
39360
|
-
const st = statSync18(full);
|
|
39361
|
-
isDir = st.isDirectory();
|
|
39362
|
-
if (!isDir) size = st.size;
|
|
39363
|
-
} catch {
|
|
39364
|
-
}
|
|
39365
|
-
const gitPath = cwdInGit + entryRel;
|
|
39366
|
-
let gitLabel = "clean";
|
|
39367
|
-
const code = gitStatus.get(gitPath);
|
|
39368
|
-
if (code !== void 0) {
|
|
39369
|
-
gitLabel = devGitStatusLabel(code);
|
|
39370
|
-
} else if (isDir) {
|
|
39371
|
-
const prefix = gitPath + "/";
|
|
39372
|
-
for (const [gf, gc] of gitStatus) {
|
|
39373
|
-
if (gf.startsWith(prefix)) {
|
|
39374
|
-
gitLabel = gc === "??" ? "untracked" : "modified";
|
|
39375
|
-
break;
|
|
39376
|
-
}
|
|
39377
|
-
}
|
|
39378
|
-
}
|
|
39379
|
-
let hasChildren = null;
|
|
39380
|
-
if (isDir) {
|
|
39381
|
-
hasChildren = false;
|
|
39382
|
-
try {
|
|
39383
|
-
for (const c of readdirSync16(full)) {
|
|
39384
|
-
if (devFilesHidden(c)) continue;
|
|
39385
|
-
hasChildren = true;
|
|
39386
|
-
break;
|
|
39387
|
-
}
|
|
39388
|
-
} catch {
|
|
39389
|
-
}
|
|
39390
|
-
}
|
|
39391
|
-
entries.push({
|
|
39392
|
-
name,
|
|
39393
|
-
path: entryRel,
|
|
39394
|
-
is_dir: isDir,
|
|
39395
|
-
has_children: hasChildren,
|
|
39396
|
-
git_status: gitLabel,
|
|
39397
|
-
size
|
|
39398
|
-
});
|
|
39977
|
+
entries.push(buildFileEntry(name, full, entryRel, cwdInGit, gitStatus));
|
|
39399
39978
|
}
|
|
39400
39979
|
res.json({ path: relative9(root, target).replace(/\\/g, "/") || ".", branch, entries });
|
|
39401
39980
|
};
|
|
@@ -40424,7 +41003,10 @@ function generate2(routes, models = []) {
|
|
|
40424
41003
|
openapi: resolveOpenApiVersion(),
|
|
40425
41004
|
info: buildInfo(),
|
|
40426
41005
|
servers: resolveServers(),
|
|
40427
|
-
|
|
41006
|
+
// Prototype-less: route paths are developer-defined, but a null prototype
|
|
41007
|
+
// makes `spec.paths[path][method] = op` structurally pollution-proof
|
|
41008
|
+
// regardless (js/prototype-polluting-assignment). Serialises to JSON the same.
|
|
41009
|
+
paths: /* @__PURE__ */ Object.create(null),
|
|
40428
41010
|
components: {
|
|
40429
41011
|
schemas: {},
|
|
40430
41012
|
// Configurable security schemes (v3.13.42): bearerFormat via env, optional
|
|
@@ -40489,7 +41071,7 @@ function buildOperation(route, spec, ctx) {
|
|
|
40489
41071
|
const openApiPath = patternToOpenAPI(route.pattern);
|
|
40490
41072
|
const method = route.method.toLowerCase();
|
|
40491
41073
|
if (!spec.paths[openApiPath]) {
|
|
40492
|
-
spec.paths[openApiPath] =
|
|
41074
|
+
spec.paths[openApiPath] = /* @__PURE__ */ Object.create(null);
|
|
40493
41075
|
}
|
|
40494
41076
|
const tags = route.meta?.tags ?? inferTags(route.pattern);
|
|
40495
41077
|
for (const t of tags) {
|
|
@@ -40795,7 +41377,7 @@ function inferModelFromPath(pattern) {
|
|
|
40795
41377
|
return null;
|
|
40796
41378
|
}
|
|
40797
41379
|
function operationIdBase(method, openApiPath) {
|
|
40798
|
-
const clean = openApiPath
|
|
41380
|
+
const clean = trimSlashes(openApiPath).replace(/\//g, "_").replace(/\.\.\./g, "").replace(/[{}]/g, "").replace(/\*/g, "wildcard");
|
|
40799
41381
|
return clean ? `${method}_${clean}` : method;
|
|
40800
41382
|
}
|
|
40801
41383
|
function uniqueOperationId(method, openApiPath, seen) {
|
|
@@ -40813,6 +41395,7 @@ var WRITE_METHODS, INTERNAL_PREFIXES, registeredSchemes, registeredSchemas, PARA
|
|
|
40813
41395
|
var init_generator = __esm({
|
|
40814
41396
|
"../swagger/src/generator.ts"() {
|
|
40815
41397
|
"use strict";
|
|
41398
|
+
init_slashTrim();
|
|
40816
41399
|
WRITE_METHODS = /* @__PURE__ */ new Set(["post", "put", "patch", "delete"]);
|
|
40817
41400
|
INTERNAL_PREFIXES = ["/swagger", "/__dev", "/__feedback", "/ai", "/rag", "/vision", "/embed", "/image"];
|
|
40818
41401
|
registeredSchemes = {};
|
|
@@ -40834,7 +41417,7 @@ var init_generator = __esm({
|
|
|
40834
41417
|
|
|
40835
41418
|
// ../swagger/src/ui.ts
|
|
40836
41419
|
function swaggerUiCdn() {
|
|
40837
|
-
return (process.env.TINA4_SWAGGER_UI_CDN ?? "https://cdn.jsdelivr.net/npm/swagger-ui-dist@5")
|
|
41420
|
+
return rtrimSlashes(process.env.TINA4_SWAGGER_UI_CDN ?? "https://cdn.jsdelivr.net/npm/swagger-ui-dist@5");
|
|
40838
41421
|
}
|
|
40839
41422
|
function swaggerEnabled() {
|
|
40840
41423
|
const raw = (process.env.TINA4_SWAGGER_ENABLED ?? "").trim().toLowerCase();
|
|
@@ -40890,6 +41473,7 @@ var SWAGGER_UI_HTML;
|
|
|
40890
41473
|
var init_ui = __esm({
|
|
40891
41474
|
"../swagger/src/ui.ts"() {
|
|
40892
41475
|
"use strict";
|
|
41476
|
+
init_slashTrim();
|
|
40893
41477
|
SWAGGER_UI_HTML = (specUrl, nonce) => `<!DOCTYPE html>
|
|
40894
41478
|
<html lang="en">
|
|
40895
41479
|
<head>
|
|
@@ -40944,7 +41528,7 @@ __export(sso_exports, {
|
|
|
40944
41528
|
SsoError: () => SsoError,
|
|
40945
41529
|
liveSessionIdentity: () => liveSessionIdentity
|
|
40946
41530
|
});
|
|
40947
|
-
import { createHash as
|
|
41531
|
+
import { createHash as createHash11, randomBytes as randomBytes8, timingSafeEqual as timingSafeEqual3 } from "node:crypto";
|
|
40948
41532
|
function expiresAt(tokens) {
|
|
40949
41533
|
const lifetime = Number(tokens.expires_in ?? 0);
|
|
40950
41534
|
return lifetime > 0 ? Math.floor(Date.now() / 1e3) + lifetime : 0;
|
|
@@ -41075,7 +41659,7 @@ var init_sso = __esm({
|
|
|
41075
41659
|
const state = randomBytes8(32).toString("base64url");
|
|
41076
41660
|
const nonce = randomBytes8(32).toString("base64url");
|
|
41077
41661
|
const verifier = randomBytes8(64).toString("base64url");
|
|
41078
|
-
const challenge =
|
|
41662
|
+
const challenge = createHash11("sha256").update(verifier).digest("base64url");
|
|
41079
41663
|
session.set(_Sso.PENDING_KEY, { state, nonce, verifier, return_to: _Sso.safeReturn(returnTo), created_at: Math.floor(Date.now() / 1e3) });
|
|
41080
41664
|
const metadata = await this.discover();
|
|
41081
41665
|
const query = new URLSearchParams({
|
|
@@ -41307,7 +41891,7 @@ import { resolve as resolve20, dirname as dirname16, join as join32, relative as
|
|
|
41307
41891
|
import { existsSync as existsSync27, readdirSync as readdirSync18, readFileSync as readFileSync23, statSync as statSync19 } from "node:fs";
|
|
41308
41892
|
import { isatty } from "node:tty";
|
|
41309
41893
|
import { fileURLToPath as fileURLToPath9 } from "node:url";
|
|
41310
|
-
import { execFileSync as execFileSync3,
|
|
41894
|
+
import { execFileSync as execFileSync3, execFile } from "node:child_process";
|
|
41311
41895
|
import cluster from "node:cluster";
|
|
41312
41896
|
import os2 from "node:os";
|
|
41313
41897
|
function isSwaggerAssetPath(pathname) {
|
|
@@ -41443,10 +42027,11 @@ function shouldOpenBrowser(isDevelopment, noBrowser = false) {
|
|
|
41443
42027
|
});
|
|
41444
42028
|
}
|
|
41445
42029
|
function openBrowser(url) {
|
|
42030
|
+
if (!/^https?:\/\/([A-Za-z0-9.-]+|\[[0-9A-Fa-f:]+\])(:\d{1,5})?\/?$/.test(url)) return;
|
|
41446
42031
|
setTimeout(() => {
|
|
41447
|
-
if (process.platform === "darwin")
|
|
41448
|
-
else if (process.platform === "win32")
|
|
41449
|
-
else
|
|
42032
|
+
if (process.platform === "darwin") execFile("open", [url]);
|
|
42033
|
+
else if (process.platform === "win32") execFile("rundll32", ["url.dll,FileProtocolHandler", url]);
|
|
42034
|
+
else execFile("xdg-open", [url]);
|
|
41450
42035
|
}, 2e3);
|
|
41451
42036
|
}
|
|
41452
42037
|
function resolvePortAndHost(config) {
|
|
@@ -41561,7 +42146,7 @@ function resetTemplateCache() {
|
|
|
41561
42146
|
}
|
|
41562
42147
|
function resolveTemplate(pathname, templatesDir) {
|
|
41563
42148
|
if (!templateAutoRoutingEnabled()) return null;
|
|
41564
|
-
const cleanPath = pathname
|
|
42149
|
+
const cleanPath = trimSlashes(pathname) || "index";
|
|
41565
42150
|
const isDev2 = (process.env.TINA4_DEBUG ?? "false").toLowerCase() === "true";
|
|
41566
42151
|
if (isDev2) {
|
|
41567
42152
|
if (cleanPath.split("/").some((seg) => seg.startsWith("_"))) return null;
|
|
@@ -41829,7 +42414,7 @@ async function runGlobalMiddlewarePass(middleware, req2, res) {
|
|
|
41829
42414
|
}
|
|
41830
42415
|
function resolveHandlerArgs(handler, req2, res, routeParams) {
|
|
41831
42416
|
const fnStr = handler.toString();
|
|
41832
|
-
const argMatch = fnStr.match(/^(?:async\s*)?(?:function
|
|
42417
|
+
const argMatch = fnStr.match(/^(?:async\s*)?(?:function(?:\s+\w+)?\s*)?\(([^)]*)\)/);
|
|
41833
42418
|
const argNames = argMatch?.[1]?.split(",").map((a) => a.trim().replace(/[:=].*/, "")) ?? [];
|
|
41834
42419
|
const filteredArgs = argNames.filter((n) => n.length > 0);
|
|
41835
42420
|
if (filteredArgs.length === 0) return [];
|
|
@@ -41858,7 +42443,7 @@ async function runMatchedRoute(ctx) {
|
|
|
41858
42443
|
const { req: req2, res, match, postMatchMiddleware } = ctx;
|
|
41859
42444
|
req2.params = match.params;
|
|
41860
42445
|
if (await runGlobalMiddlewarePass(postMatchMiddleware, req2, res)) return;
|
|
41861
|
-
if (enforceRouteAuth(req2, res, match
|
|
42446
|
+
if (enforceRouteAuth(req2, res, match)) return;
|
|
41862
42447
|
const routeMiddlewareClasses = (match.middlewares ?? []).filter(isMiddlewareClass);
|
|
41863
42448
|
let handlerSkipped = false;
|
|
41864
42449
|
if (match.middlewares && match.middlewares.length > 0) {
|
|
@@ -42065,8 +42650,9 @@ async function buildDispatchContext(router, base) {
|
|
|
42065
42650
|
const templatesDir = resolve20(root, "src/templates");
|
|
42066
42651
|
let frondEngine = null;
|
|
42067
42652
|
try {
|
|
42068
|
-
const { Frond: Frond2, setCspNonceProvider: setCspNonceProvider2 } = await Promise.resolve().then(() => (init_engine(), engine_exports));
|
|
42653
|
+
const { Frond: Frond2, setCspNonceProvider: setCspNonceProvider2, setFormTokenSessionProvider: setFormTokenSessionProvider2 } = await Promise.resolve().then(() => (init_engine(), engine_exports));
|
|
42069
42654
|
setCspNonceProvider2(currentCspNonce);
|
|
42655
|
+
setFormTokenSessionProvider2(currentFormTokenSessionId);
|
|
42070
42656
|
frondEngine = new Frond2(templatesDir);
|
|
42071
42657
|
} catch {
|
|
42072
42658
|
}
|
|
@@ -42181,7 +42767,10 @@ async function runDispatch(ctx, rawReq, rawRes) {
|
|
|
42181
42767
|
const requestNonce = generateNonce();
|
|
42182
42768
|
return Log.runWithRequestId(
|
|
42183
42769
|
requestId,
|
|
42184
|
-
() => runWithCspNonce(
|
|
42770
|
+
() => runWithCspNonce(
|
|
42771
|
+
requestNonce,
|
|
42772
|
+
() => runWithFormTokenSession(() => dispatchInner(ctx, rawReq, rawRes, requestId))
|
|
42773
|
+
)
|
|
42185
42774
|
);
|
|
42186
42775
|
}
|
|
42187
42776
|
function loopbackBindHosts(host) {
|
|
@@ -42309,8 +42898,9 @@ async function startServer(config) {
|
|
|
42309
42898
|
let frondEngine = null;
|
|
42310
42899
|
setDefaultTemplatesDir(templatesDir);
|
|
42311
42900
|
try {
|
|
42312
|
-
const { Frond: Frond2, setCspNonceProvider: setCspNonceProvider2 } = await Promise.resolve().then(() => (init_engine(), engine_exports));
|
|
42901
|
+
const { Frond: Frond2, setCspNonceProvider: setCspNonceProvider2, setFormTokenSessionProvider: setFormTokenSessionProvider2 } = await Promise.resolve().then(() => (init_engine(), engine_exports));
|
|
42313
42902
|
setCspNonceProvider2(currentCspNonce);
|
|
42903
|
+
setFormTokenSessionProvider2(currentFormTokenSessionId);
|
|
42314
42904
|
frondEngine = new Frond2(templatesDir);
|
|
42315
42905
|
router.addRoute({
|
|
42316
42906
|
method: "GET",
|
|
@@ -42659,6 +43249,7 @@ var __filename, __dirname, BUILTIN_ERROR_TEMPLATES_DIR, BUILTIN_PUBLIC_DIR, swag
|
|
|
42659
43249
|
var init_server = __esm({
|
|
42660
43250
|
"../core/src/server.ts"() {
|
|
42661
43251
|
"use strict";
|
|
43252
|
+
init_slashTrim();
|
|
42662
43253
|
init_transport();
|
|
42663
43254
|
init_router();
|
|
42664
43255
|
init_authGate();
|
|
@@ -42666,6 +43257,7 @@ var init_server = __esm({
|
|
|
42666
43257
|
init_portTakeover();
|
|
42667
43258
|
init_request();
|
|
42668
43259
|
init_dispatchPipeline();
|
|
43260
|
+
init_session();
|
|
42669
43261
|
init_response();
|
|
42670
43262
|
init_middleware();
|
|
42671
43263
|
init_static();
|
|
@@ -44281,6 +44873,7 @@ var ApiStreamError, RETRY_STATUSES, DOWNLOAD_CHUNK_SIZE, MAX_REDIRECTS, STRIP_ON
|
|
|
44281
44873
|
var init_api = __esm({
|
|
44282
44874
|
"../core/src/api.ts"() {
|
|
44283
44875
|
"use strict";
|
|
44876
|
+
init_slashTrim();
|
|
44284
44877
|
init_version();
|
|
44285
44878
|
init_ssrf();
|
|
44286
44879
|
ApiStreamError = class extends Error {
|
|
@@ -44378,7 +44971,7 @@ var init_api = __esm({
|
|
|
44378
44971
|
* turns on a per-client, in-memory cookie jar.
|
|
44379
44972
|
*/
|
|
44380
44973
|
constructor(baseUrl = "", authHeaderOrOptions = "", timeout = 30) {
|
|
44381
|
-
this.baseUrl = baseUrl
|
|
44974
|
+
this.baseUrl = rtrimSlashes(baseUrl);
|
|
44382
44975
|
this.headers = {};
|
|
44383
44976
|
this.maxRetries = 0;
|
|
44384
44977
|
this.retryBackoff = 0.5;
|
|
@@ -45144,6 +45737,23 @@ function sendCommand(socket, command) {
|
|
|
45144
45737
|
});
|
|
45145
45738
|
});
|
|
45146
45739
|
}
|
|
45740
|
+
function pushAlternativeBody(lines, altBoundary, text, body) {
|
|
45741
|
+
lines.push(`Content-Type: multipart/alternative; boundary="${altBoundary}"`);
|
|
45742
|
+
lines.push("");
|
|
45743
|
+
lines.push(`--${altBoundary}`);
|
|
45744
|
+
lines.push("Content-Type: text/plain; charset=UTF-8");
|
|
45745
|
+
lines.push("Content-Transfer-Encoding: 7bit");
|
|
45746
|
+
lines.push("");
|
|
45747
|
+
lines.push(text);
|
|
45748
|
+
lines.push("");
|
|
45749
|
+
lines.push(`--${altBoundary}`);
|
|
45750
|
+
lines.push("Content-Type: text/html; charset=UTF-8");
|
|
45751
|
+
lines.push("Content-Transfer-Encoding: 7bit");
|
|
45752
|
+
lines.push("");
|
|
45753
|
+
lines.push(body);
|
|
45754
|
+
lines.push("");
|
|
45755
|
+
lines.push(`--${altBoundary}--`);
|
|
45756
|
+
}
|
|
45147
45757
|
function buildMimeMessage(options) {
|
|
45148
45758
|
const boundary = `----=_Tina4_${Date.now()}_${Math.random().toString(36).substring(2)}`;
|
|
45149
45759
|
const altBoundary = `----=_Tina4Alt_${Date.now()}_${Math.random().toString(36).substring(2)}`;
|
|
@@ -45173,21 +45783,7 @@ function buildMimeMessage(options) {
|
|
|
45173
45783
|
lines.push("");
|
|
45174
45784
|
lines.push(`--${boundary}`);
|
|
45175
45785
|
if (hasTextAlt) {
|
|
45176
|
-
lines.
|
|
45177
|
-
lines.push("");
|
|
45178
|
-
lines.push(`--${altBoundary}`);
|
|
45179
|
-
lines.push("Content-Type: text/plain; charset=UTF-8");
|
|
45180
|
-
lines.push("Content-Transfer-Encoding: 7bit");
|
|
45181
|
-
lines.push("");
|
|
45182
|
-
lines.push(options.text);
|
|
45183
|
-
lines.push("");
|
|
45184
|
-
lines.push(`--${altBoundary}`);
|
|
45185
|
-
lines.push("Content-Type: text/html; charset=UTF-8");
|
|
45186
|
-
lines.push("Content-Transfer-Encoding: 7bit");
|
|
45187
|
-
lines.push("");
|
|
45188
|
-
lines.push(options.body);
|
|
45189
|
-
lines.push("");
|
|
45190
|
-
lines.push(`--${altBoundary}--`);
|
|
45786
|
+
pushAlternativeBody(lines, altBoundary, options.text, options.body);
|
|
45191
45787
|
} else {
|
|
45192
45788
|
const contentType = options.html ? "text/html" : "text/plain";
|
|
45193
45789
|
lines.push(`Content-Type: ${contentType}; charset=UTF-8`);
|
|
@@ -45212,21 +45808,7 @@ function buildMimeMessage(options) {
|
|
|
45212
45808
|
lines.push("");
|
|
45213
45809
|
lines.push(`--${boundary}--`);
|
|
45214
45810
|
} else if (hasTextAlt) {
|
|
45215
|
-
lines.
|
|
45216
|
-
lines.push("");
|
|
45217
|
-
lines.push(`--${altBoundary}`);
|
|
45218
|
-
lines.push("Content-Type: text/plain; charset=UTF-8");
|
|
45219
|
-
lines.push("Content-Transfer-Encoding: 7bit");
|
|
45220
|
-
lines.push("");
|
|
45221
|
-
lines.push(options.text);
|
|
45222
|
-
lines.push("");
|
|
45223
|
-
lines.push(`--${altBoundary}`);
|
|
45224
|
-
lines.push("Content-Type: text/html; charset=UTF-8");
|
|
45225
|
-
lines.push("Content-Transfer-Encoding: 7bit");
|
|
45226
|
-
lines.push("");
|
|
45227
|
-
lines.push(options.body);
|
|
45228
|
-
lines.push("");
|
|
45229
|
-
lines.push(`--${altBoundary}--`);
|
|
45811
|
+
pushAlternativeBody(lines, altBoundary, options.text, options.body);
|
|
45230
45812
|
} else {
|
|
45231
45813
|
const contentType = options.html ? "text/html" : "text/plain";
|
|
45232
45814
|
lines.push(`Content-Type: ${contentType}; charset=UTF-8`);
|
|
@@ -45991,61 +46573,72 @@ function decodeEntities(raw) {
|
|
|
45991
46573
|
function parseXmlDocument(xml) {
|
|
45992
46574
|
const stack = [];
|
|
45993
46575
|
let root = null;
|
|
45994
|
-
let position = 0;
|
|
45995
46576
|
const addText = (text) => {
|
|
45996
46577
|
const current = stack[stack.length - 1];
|
|
45997
46578
|
if (current.children.length === 0) current.text += text;
|
|
45998
46579
|
};
|
|
45999
|
-
|
|
46000
|
-
const
|
|
46580
|
+
const skipComment = (at) => {
|
|
46581
|
+
const close = xml.indexOf("-->", at + 4);
|
|
46582
|
+
if (close === -1) malformed();
|
|
46583
|
+
return close + 3;
|
|
46584
|
+
};
|
|
46585
|
+
const readCData = (at) => {
|
|
46586
|
+
const close = xml.indexOf("]]>", at + 9);
|
|
46587
|
+
if (close === -1 || stack.length === 0) malformed();
|
|
46588
|
+
addText(xml.slice(at + 9, close));
|
|
46589
|
+
return close + 3;
|
|
46590
|
+
};
|
|
46591
|
+
const skipProcessingInstruction = (at) => {
|
|
46592
|
+
const close = xml.indexOf("?>", at + 2);
|
|
46593
|
+
if (close === -1) malformed();
|
|
46594
|
+
const target = xml.slice(at + 2, close).split(/\s/, 1)[0];
|
|
46595
|
+
if (target.toLowerCase() === "xml" && at !== 0) malformed();
|
|
46596
|
+
return close + 2;
|
|
46597
|
+
};
|
|
46598
|
+
const closeElement = (at) => {
|
|
46599
|
+
END_TAG.lastIndex = at;
|
|
46600
|
+
const match = END_TAG.exec(xml);
|
|
46601
|
+
const open = stack.pop();
|
|
46602
|
+
if (!match || !open || open.qualifiedName !== match[1]) malformed();
|
|
46603
|
+
return END_TAG.lastIndex;
|
|
46604
|
+
};
|
|
46605
|
+
const openElement = (at) => {
|
|
46606
|
+
START_TAG.lastIndex = at;
|
|
46607
|
+
const match = START_TAG.exec(xml);
|
|
46608
|
+
if (!match || stack.length === 0 && root !== null) malformed();
|
|
46609
|
+
for (const attribute of match[2].matchAll(ATTRIBUTE_VALUE)) decodeEntities(attribute[1] ?? attribute[2]);
|
|
46610
|
+
const qualifiedName = match[1];
|
|
46611
|
+
const element = {
|
|
46612
|
+
name: qualifiedName.slice(qualifiedName.indexOf(":") + 1),
|
|
46613
|
+
qualifiedName,
|
|
46614
|
+
children: [],
|
|
46615
|
+
text: ""
|
|
46616
|
+
};
|
|
46617
|
+
if (stack.length > 0) stack[stack.length - 1].children.push(element);
|
|
46618
|
+
else root = element;
|
|
46619
|
+
if (match[3] !== "/") stack.push(element);
|
|
46620
|
+
return START_TAG.lastIndex;
|
|
46621
|
+
};
|
|
46622
|
+
const readText = (at) => {
|
|
46623
|
+
const nextTag = xml.indexOf("<", at);
|
|
46001
46624
|
const textEnd = nextTag === -1 ? xml.length : nextTag;
|
|
46002
|
-
if (textEnd >
|
|
46003
|
-
const raw = xml.slice(
|
|
46625
|
+
if (textEnd > at) {
|
|
46626
|
+
const raw = xml.slice(at, textEnd);
|
|
46004
46627
|
if (stack.length > 0) addText(decodeEntities(raw));
|
|
46005
46628
|
else if (raw.trim() !== "") malformed();
|
|
46006
|
-
position = textEnd;
|
|
46007
|
-
if (nextTag === -1) break;
|
|
46008
|
-
}
|
|
46009
|
-
if (xml.startsWith("<!--", position)) {
|
|
46010
|
-
const close = xml.indexOf("-->", position + 4);
|
|
46011
|
-
if (close === -1) malformed();
|
|
46012
|
-
position = close + 3;
|
|
46013
|
-
} else if (xml.startsWith("<![CDATA[", position)) {
|
|
46014
|
-
const close = xml.indexOf("]]>", position + 9);
|
|
46015
|
-
if (close === -1 || stack.length === 0) malformed();
|
|
46016
|
-
addText(xml.slice(position + 9, close));
|
|
46017
|
-
position = close + 3;
|
|
46018
|
-
} else if (xml.startsWith("<?", position)) {
|
|
46019
|
-
const close = xml.indexOf("?>", position + 2);
|
|
46020
|
-
if (close === -1) malformed();
|
|
46021
|
-
const target = xml.slice(position + 2, close).split(/\s/, 1)[0];
|
|
46022
|
-
if (target.toLowerCase() === "xml" && position !== 0) malformed();
|
|
46023
|
-
position = close + 2;
|
|
46024
|
-
} else if (xml.startsWith("<!", position)) {
|
|
46025
|
-
malformed();
|
|
46026
|
-
} else if (xml.startsWith("</", position)) {
|
|
46027
|
-
END_TAG.lastIndex = position;
|
|
46028
|
-
const match = END_TAG.exec(xml);
|
|
46029
|
-
const open = stack.pop();
|
|
46030
|
-
if (!match || !open || open.qualifiedName !== match[1]) malformed();
|
|
46031
|
-
position = END_TAG.lastIndex;
|
|
46032
|
-
} else {
|
|
46033
|
-
START_TAG.lastIndex = position;
|
|
46034
|
-
const match = START_TAG.exec(xml);
|
|
46035
|
-
if (!match || stack.length === 0 && root !== null) malformed();
|
|
46036
|
-
for (const attribute of match[2].matchAll(ATTRIBUTE_VALUE)) decodeEntities(attribute[1] ?? attribute[2]);
|
|
46037
|
-
const qualifiedName = match[1];
|
|
46038
|
-
const element = {
|
|
46039
|
-
name: qualifiedName.slice(qualifiedName.indexOf(":") + 1),
|
|
46040
|
-
qualifiedName,
|
|
46041
|
-
children: [],
|
|
46042
|
-
text: ""
|
|
46043
|
-
};
|
|
46044
|
-
if (stack.length > 0) stack[stack.length - 1].children.push(element);
|
|
46045
|
-
else root = element;
|
|
46046
|
-
if (match[3] !== "/") stack.push(element);
|
|
46047
|
-
position = START_TAG.lastIndex;
|
|
46048
46629
|
}
|
|
46630
|
+
return textEnd;
|
|
46631
|
+
};
|
|
46632
|
+
let position = 0;
|
|
46633
|
+
while (position < xml.length) {
|
|
46634
|
+
position = readText(position);
|
|
46635
|
+
if (position >= xml.length) break;
|
|
46636
|
+
if (xml.startsWith("<!--", position)) position = skipComment(position);
|
|
46637
|
+
else if (xml.startsWith("<![CDATA[", position)) position = readCData(position);
|
|
46638
|
+
else if (xml.startsWith("<?", position)) position = skipProcessingInstruction(position);
|
|
46639
|
+
else if (xml.startsWith("<!", position)) malformed();
|
|
46640
|
+
else if (xml.startsWith("</", position)) position = closeElement(position);
|
|
46641
|
+
else position = openElement(position);
|
|
46049
46642
|
}
|
|
46050
46643
|
if (root === null || stack.length > 0) malformed();
|
|
46051
46644
|
return root;
|
|
@@ -47547,13 +48140,13 @@ export default class User {
|
|
|
47547
48140
|
import {
|
|
47548
48141
|
createCipheriv,
|
|
47549
48142
|
createECDH,
|
|
47550
|
-
createHmac as
|
|
48143
|
+
createHmac as createHmac5,
|
|
47551
48144
|
createPrivateKey,
|
|
47552
48145
|
createSign as createSign2,
|
|
47553
48146
|
randomBytes as randomBytes12
|
|
47554
48147
|
} from "node:crypto";
|
|
47555
48148
|
function encodeBase64Url(value) {
|
|
47556
|
-
return Buffer.from(value).toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(
|
|
48149
|
+
return Buffer.from(value).toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/={1,2}$/, "");
|
|
47557
48150
|
}
|
|
47558
48151
|
function decodeBase64Url(value, name) {
|
|
47559
48152
|
if (typeof value !== "string" || value.length === 0) {
|
|
@@ -47583,15 +48176,15 @@ function vapidPrivateKey(rawPrivate, rawPublic) {
|
|
|
47583
48176
|
format: "jwk"
|
|
47584
48177
|
});
|
|
47585
48178
|
}
|
|
47586
|
-
function
|
|
47587
|
-
return
|
|
48179
|
+
function hmac2(salt, value) {
|
|
48180
|
+
return createHmac5("sha256", salt).update(value).digest();
|
|
47588
48181
|
}
|
|
47589
48182
|
function hkdfExpand(prk, info, length) {
|
|
47590
48183
|
const chunks = [];
|
|
47591
48184
|
let previous = Buffer.alloc(0);
|
|
47592
48185
|
for (let counter = 1; Buffer.concat(chunks).length < length; counter++) {
|
|
47593
48186
|
if (counter > 255) throw new PushError("HKDF output is too large");
|
|
47594
|
-
previous =
|
|
48187
|
+
previous = hmac2(prk, Buffer.concat([previous, info, Buffer.from([counter])]));
|
|
47595
48188
|
chunks.push(previous);
|
|
47596
48189
|
}
|
|
47597
48190
|
return Buffer.concat(chunks).subarray(0, length);
|
|
@@ -47628,10 +48221,10 @@ function encryptPayload(payload, subscription) {
|
|
|
47628
48221
|
clientPublic,
|
|
47629
48222
|
serverPublic
|
|
47630
48223
|
]);
|
|
47631
|
-
const prkKey =
|
|
48224
|
+
const prkKey = hmac2(authSecret, sharedSecret);
|
|
47632
48225
|
const ikm = hkdfExpand(prkKey, keyInfo, 32);
|
|
47633
48226
|
const salt = randomBytes12(16);
|
|
47634
|
-
const contentPrk =
|
|
48227
|
+
const contentPrk = hmac2(salt, ikm);
|
|
47635
48228
|
const cek = hkdfExpand(contentPrk, Buffer.from("Content-Encoding: aes128gcm\0", "ascii"), 16);
|
|
47636
48229
|
const nonce = hkdfExpand(contentPrk, Buffer.from("Content-Encoding: nonce\0", "ascii"), 12);
|
|
47637
48230
|
const cipher = createCipheriv("aes-128-gcm", cek, nonce);
|
|
@@ -47804,6 +48397,7 @@ var AiError, AiConfigError, AiTimeoutError, AiParseError, AiHTTPError, Ai, Aggre
|
|
|
47804
48397
|
var init_aiClient = __esm({
|
|
47805
48398
|
"../core/src/aiClient.ts"() {
|
|
47806
48399
|
"use strict";
|
|
48400
|
+
init_slashTrim();
|
|
47807
48401
|
init_api();
|
|
47808
48402
|
AiError = class extends Error {
|
|
47809
48403
|
};
|
|
@@ -48008,7 +48602,7 @@ var init_aiClient = __esm({
|
|
|
48008
48602
|
throw new AiConfigError("AI URL must be an http or https URL");
|
|
48009
48603
|
}
|
|
48010
48604
|
if (url.protocol !== "http:" && url.protocol !== "https:") throw new AiConfigError("AI URL must be an http or https URL");
|
|
48011
|
-
const path10 = url.pathname
|
|
48605
|
+
const path10 = rtrimSlashes(url.pathname);
|
|
48012
48606
|
if (path10 === "" || path10 === "/v1" || path10 === "/api" || path10 === "/v1beta/openai") {
|
|
48013
48607
|
const suffix = provider === "anthropic" ? "/messages" : capability === "embed" ? "/embeddings" : "/chat/completions";
|
|
48014
48608
|
url.pathname = (path10 || "/v1") + suffix;
|
|
@@ -50378,6 +50972,7 @@ __export(src_exports3, {
|
|
|
50378
50972
|
backgroundTaskCount: () => backgroundTaskCount,
|
|
50379
50973
|
buildEnvelope: () => buildEnvelope,
|
|
50380
50974
|
buildFrame: () => buildFrame,
|
|
50975
|
+
buildSeedFieldMap: () => buildSeedFieldMap,
|
|
50381
50976
|
buildSessionCookie: () => buildSessionCookie,
|
|
50382
50977
|
cacheBackendStats: () => cacheBackendStats,
|
|
50383
50978
|
cacheClear: () => cacheClear,
|
|
@@ -50483,6 +51078,7 @@ __export(src_exports3, {
|
|
|
50483
51078
|
parseFrame: () => parseFrame,
|
|
50484
51079
|
parseLineStream: () => parseLineStream,
|
|
50485
51080
|
parseMultipart: () => parseMultipart,
|
|
51081
|
+
parseSeedRequest: () => parseSeedRequest,
|
|
50486
51082
|
parseSseStream: () => parseSseStream,
|
|
50487
51083
|
parseUpgradeHeaders: () => parseUpgradeHeaders,
|
|
50488
51084
|
patch: () => patch,
|
|
@@ -50923,12 +51519,23 @@ async function runMigrations(migrationDir) {
|
|
|
50923
51519
|
|
|
50924
51520
|
// src/commands/migrateCreate.ts
|
|
50925
51521
|
init_generate();
|
|
51522
|
+
var MIGRATE_CREATE_FLAGS = {
|
|
51523
|
+
fields: true,
|
|
51524
|
+
"table-name": true,
|
|
51525
|
+
json: false,
|
|
51526
|
+
"dry-run": false
|
|
51527
|
+
};
|
|
50926
51528
|
async function createMigration2(args = []) {
|
|
50927
51529
|
const positionals = [];
|
|
50928
51530
|
const flags = [];
|
|
50929
|
-
for (
|
|
50930
|
-
|
|
50931
|
-
|
|
51531
|
+
for (let i = 0; i < args.length; i++) {
|
|
51532
|
+
const arg = args[i];
|
|
51533
|
+
if (arg.startsWith("--")) {
|
|
51534
|
+
flags.push(arg);
|
|
51535
|
+
if (!arg.includes("=") && MIGRATE_CREATE_FLAGS[arg.slice(2)] && i + 1 < args.length) flags.push(args[++i]);
|
|
51536
|
+
} else {
|
|
51537
|
+
positionals.push(arg);
|
|
51538
|
+
}
|
|
50932
51539
|
}
|
|
50933
51540
|
const description = positionals.join(" ").trim();
|
|
50934
51541
|
if (!description) {
|
|
@@ -51190,7 +51797,7 @@ async function runTests(testPath) {
|
|
|
51190
51797
|
// src/commands/lint.ts
|
|
51191
51798
|
init_util();
|
|
51192
51799
|
import { existsSync as existsSync34, readdirSync as readdirSync21, readFileSync as readFileSync28, statSync as statSync22, writeFileSync as writeFileSync20 } from "node:fs";
|
|
51193
|
-
import { createRequire as
|
|
51800
|
+
import { createRequire as createRequire8 } from "node:module";
|
|
51194
51801
|
import { dirname as dirname18, join as join36, relative as relative12 } from "node:path";
|
|
51195
51802
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
51196
51803
|
var LINT_EXTENSIONS = [".ts", ".mts", ".cts", ".js", ".mjs", ".cjs"];
|
|
@@ -51262,10 +51869,10 @@ function findEslintConfig(cwd) {
|
|
|
51262
51869
|
function resolvePackageBin(cwd, pkg, binRelative) {
|
|
51263
51870
|
const direct = join36(cwd, "node_modules", pkg, binRelative);
|
|
51264
51871
|
if (existsSync34(direct)) return direct;
|
|
51265
|
-
const
|
|
51872
|
+
const require2 = createRequire8(join36(cwd, "package.json"));
|
|
51266
51873
|
let entry;
|
|
51267
51874
|
try {
|
|
51268
|
-
entry =
|
|
51875
|
+
entry = require2.resolve(pkg);
|
|
51269
51876
|
} catch {
|
|
51270
51877
|
return null;
|
|
51271
51878
|
}
|
|
@@ -51599,6 +52206,12 @@ var QUEUE_SUBCOMMANDS = {
|
|
|
51599
52206
|
retry: queueRetry,
|
|
51600
52207
|
clear: queueClear
|
|
51601
52208
|
};
|
|
52209
|
+
var QUEUE_FLAGS = {
|
|
52210
|
+
work: { once: false, poll: true, services: true },
|
|
52211
|
+
stats: { json: false },
|
|
52212
|
+
retry: {},
|
|
52213
|
+
clear: {}
|
|
52214
|
+
};
|
|
51602
52215
|
var QUEUE_SUBCOMMAND_NAMES = Object.keys(QUEUE_SUBCOMMANDS);
|
|
51603
52216
|
async function queueCommand(args = []) {
|
|
51604
52217
|
const list = QUEUE_SUBCOMMAND_NAMES.join(", ");
|
|
@@ -51621,7 +52234,7 @@ async function queueCommand(args = []) {
|
|
|
51621
52234
|
|
|
51622
52235
|
// src/commands/build.ts
|
|
51623
52236
|
init_util();
|
|
51624
|
-
import { accessSync as accessSync2, constants as
|
|
52237
|
+
import { accessSync as accessSync2, constants as constants5, existsSync as existsSync36, statSync as statSync24 } from "node:fs";
|
|
51625
52238
|
import { basename as basename9, delimiter as delimiter3, join as join39 } from "node:path";
|
|
51626
52239
|
import { spawnSync as spawnSync4 } from "node:child_process";
|
|
51627
52240
|
function parseFlags3(args) {
|
|
@@ -51636,7 +52249,7 @@ function whichDocker() {
|
|
|
51636
52249
|
for (const ext of exts) {
|
|
51637
52250
|
const candidate = join39(dir, `docker${ext}`);
|
|
51638
52251
|
try {
|
|
51639
|
-
accessSync2(candidate,
|
|
52252
|
+
accessSync2(candidate, constants5.X_OK);
|
|
51640
52253
|
if (statSync24(candidate).isFile()) return candidate;
|
|
51641
52254
|
} catch {
|
|
51642
52255
|
}
|
|
@@ -51802,8 +52415,7 @@ function printHelp() {
|
|
|
51802
52415
|
" --no-browser Don't open the browser on serve",
|
|
51803
52416
|
" --no-reload Disable file watcher / live-reload on serve",
|
|
51804
52417
|
" --all Install AI context for all tools (with ai command)",
|
|
51805
|
-
" --
|
|
51806
|
-
" --help Show this help message",
|
|
52418
|
+
" --help, -h Show this help, or one command's usage (tina4nodejs <command> --help)",
|
|
51807
52419
|
"",
|
|
51808
52420
|
" https://tina4.com",
|
|
51809
52421
|
""
|
|
@@ -51837,7 +52449,7 @@ async function openConsole() {
|
|
|
51837
52449
|
}
|
|
51838
52450
|
async function installAiContext(args) {
|
|
51839
52451
|
const { showMenu: showMenu2, installSelected: installSelected2, installAll: installAll2 } = await Promise.resolve().then(() => (init_ai(), ai_exports));
|
|
51840
|
-
const root = args
|
|
52452
|
+
const root = args.find((a) => !a.startsWith("-")) || ".";
|
|
51841
52453
|
if (args.includes("--all")) {
|
|
51842
52454
|
installAll2(root);
|
|
51843
52455
|
} else {
|
|
@@ -51847,6 +52459,15 @@ async function installAiContext(args) {
|
|
|
51847
52459
|
}
|
|
51848
52460
|
}
|
|
51849
52461
|
}
|
|
52462
|
+
var SERVE_FLAGS = {
|
|
52463
|
+
port: true,
|
|
52464
|
+
"no-browser": false,
|
|
52465
|
+
"no-reload": false,
|
|
52466
|
+
"no-kill": false,
|
|
52467
|
+
// Not read by serve, but the Dockerfile `init` scaffolds runs
|
|
52468
|
+
// `tina4nodejs serve --production`, so refusing it would break every image.
|
|
52469
|
+
production: false
|
|
52470
|
+
};
|
|
51850
52471
|
var COMMANDS = {
|
|
51851
52472
|
init: {
|
|
51852
52473
|
handler: async (a) => {
|
|
@@ -51866,6 +52487,7 @@ var COMMANDS = {
|
|
|
51866
52487
|
await killProcessOnPort(port);
|
|
51867
52488
|
await serveProject({ port, noBrowser, noReload });
|
|
51868
52489
|
},
|
|
52490
|
+
flags: SERVE_FLAGS,
|
|
51869
52491
|
usage: "[--port P] [--no-browser] [--no-reload]",
|
|
51870
52492
|
summary: "Start the dev server with hot-reload (default: 0.0.0.0:7148)"
|
|
51871
52493
|
},
|
|
@@ -51882,6 +52504,7 @@ var COMMANDS = {
|
|
|
51882
52504
|
handler: async (a) => {
|
|
51883
52505
|
await createMigration2(a);
|
|
51884
52506
|
},
|
|
52507
|
+
flags: MIGRATE_CREATE_FLAGS,
|
|
51885
52508
|
usage: "<desc>",
|
|
51886
52509
|
args: ["description"],
|
|
51887
52510
|
summary: "Create a new migration file (delegates to generate migration)"
|
|
@@ -51915,6 +52538,7 @@ var COMMANDS = {
|
|
|
51915
52538
|
handler: (a) => {
|
|
51916
52539
|
runLint(a);
|
|
51917
52540
|
},
|
|
52541
|
+
flags: { fix: false, "no-install": false },
|
|
51918
52542
|
usage: "[--fix] [--no-install]",
|
|
51919
52543
|
summary: "Lint the project (eslint, installed dev-only on demand; else tsc/node --check baseline)"
|
|
51920
52544
|
},
|
|
@@ -51930,6 +52554,7 @@ var COMMANDS = {
|
|
|
51930
52554
|
handler: (a) => {
|
|
51931
52555
|
buildImage(a);
|
|
51932
52556
|
},
|
|
52557
|
+
flags: { tag: true, file: true },
|
|
51933
52558
|
usage: "[--tag NAME] [--file PATH]",
|
|
51934
52559
|
summary: "Build the deployable Docker image"
|
|
51935
52560
|
},
|
|
@@ -51958,6 +52583,7 @@ var COMMANDS = {
|
|
|
51958
52583
|
handler: async (a) => {
|
|
51959
52584
|
await installAiContext(a);
|
|
51960
52585
|
},
|
|
52586
|
+
flags: { all: false },
|
|
51961
52587
|
usage: "[--all]",
|
|
51962
52588
|
summary: "Install AI coding assistant context files"
|
|
51963
52589
|
},
|
|
@@ -51965,6 +52591,7 @@ var COMMANDS = {
|
|
|
51965
52591
|
handler: (a) => {
|
|
51966
52592
|
runCommands(a);
|
|
51967
52593
|
},
|
|
52594
|
+
flags: { json: false },
|
|
51968
52595
|
usage: "[--json]",
|
|
51969
52596
|
summary: "List available commands (add --json for the machine manifest)"
|
|
51970
52597
|
},
|
|
@@ -51972,6 +52599,8 @@ var COMMANDS = {
|
|
|
51972
52599
|
handler: () => {
|
|
51973
52600
|
printHelp();
|
|
51974
52601
|
},
|
|
52602
|
+
// Not option-checked: `help --help` / `help -h` print the reference too.
|
|
52603
|
+
flags: null,
|
|
51975
52604
|
summary: "Show this help message"
|
|
51976
52605
|
}
|
|
51977
52606
|
};
|
|
@@ -52025,6 +52654,114 @@ ${CLIENT_INSTALL_HINT}
|
|
|
52025
52654
|
}
|
|
52026
52655
|
return result.status ?? EXIT_CLIENT_UNAVAILABLE;
|
|
52027
52656
|
}
|
|
52657
|
+
var HELP_FLAGS = ["--help", "-h"];
|
|
52658
|
+
function printCommandHelp(command, args) {
|
|
52659
|
+
if (command === "generate") {
|
|
52660
|
+
const kind = args.find((a) => !a.startsWith("-"))?.toLowerCase();
|
|
52661
|
+
const gen = kind ? GENERATORS[kind] : void 0;
|
|
52662
|
+
if (gen) {
|
|
52663
|
+
console.log(`Usage: tina4nodejs generate ${kind} ${gen.usage}`.trimEnd());
|
|
52664
|
+
console.log(`
|
|
52665
|
+
${gen.summary}`);
|
|
52666
|
+
return;
|
|
52667
|
+
}
|
|
52668
|
+
console.log("Usage: tina4nodejs generate <what> <name> [options]\n\nGenerators:");
|
|
52669
|
+
const pad = Math.max(...Object.keys(GENERATORS).map((n) => n.length));
|
|
52670
|
+
for (const [name, g] of Object.entries(GENERATORS)) console.log(` ${name.padEnd(pad)} ${g.summary}`);
|
|
52671
|
+
return;
|
|
52672
|
+
}
|
|
52673
|
+
const spec = COMMANDS[command];
|
|
52674
|
+
console.log(`Usage: tina4nodejs ${command} ${spec.usage ?? ""}`.trimEnd());
|
|
52675
|
+
console.log(`
|
|
52676
|
+
${spec.summary}`);
|
|
52677
|
+
if (spec.subcommands?.length) console.log(` Subcommands: ${spec.subcommands.join(", ")}`);
|
|
52678
|
+
}
|
|
52679
|
+
function acceptedOptions(command, args) {
|
|
52680
|
+
const sub = (args[0] ?? "").toLowerCase();
|
|
52681
|
+
if (command === "generate") {
|
|
52682
|
+
const gen = GENERATORS[sub];
|
|
52683
|
+
return gen ? { ...gen.flags, ...RESOLUTION_FLAGS } : null;
|
|
52684
|
+
}
|
|
52685
|
+
if (command === "queue") return QUEUE_FLAGS[sub] ?? null;
|
|
52686
|
+
const flags = COMMANDS[command].flags;
|
|
52687
|
+
return flags === void 0 ? {} : flags;
|
|
52688
|
+
}
|
|
52689
|
+
function editDistance(a, b) {
|
|
52690
|
+
const d = Array.from({ length: a.length + 1 }, (_, i) => [i, ...Array(b.length).fill(0)]);
|
|
52691
|
+
for (let j = 1; j <= b.length; j++) d[0][j] = j;
|
|
52692
|
+
for (let i = 1; i <= a.length; i++) {
|
|
52693
|
+
for (let j = 1; j <= b.length; j++) d[i][j] = distanceCell(d, a, b, i, j);
|
|
52694
|
+
}
|
|
52695
|
+
return d[a.length][b.length];
|
|
52696
|
+
}
|
|
52697
|
+
function distanceCell(d, a, b, i, j) {
|
|
52698
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
52699
|
+
const best = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);
|
|
52700
|
+
const swapped = i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1];
|
|
52701
|
+
return swapped ? Math.min(best, d[i - 2][j - 2] + 1) : best;
|
|
52702
|
+
}
|
|
52703
|
+
function closestOption(name, accepted) {
|
|
52704
|
+
let best = null;
|
|
52705
|
+
let bestDistance = Math.max(1, Math.floor(name.length / 3)) + 1;
|
|
52706
|
+
for (const option of accepted) {
|
|
52707
|
+
const distance = editDistance(name, option);
|
|
52708
|
+
if (distance < bestDistance) {
|
|
52709
|
+
best = option;
|
|
52710
|
+
bestDistance = distance;
|
|
52711
|
+
}
|
|
52712
|
+
}
|
|
52713
|
+
return best;
|
|
52714
|
+
}
|
|
52715
|
+
function unknownOptionMessage(option, name, accepted, label) {
|
|
52716
|
+
const close = closestOption(name, Object.keys(accepted));
|
|
52717
|
+
return `Unknown option ${option} for "${label}".${close ? ` Did you mean --${close}?` : ""}
|
|
52718
|
+
Run "tina4nodejs ${label} --help" for its options.`;
|
|
52719
|
+
}
|
|
52720
|
+
function optionProblem(args, i, accepted, label) {
|
|
52721
|
+
const arg = args[i];
|
|
52722
|
+
if (!arg.startsWith("-") || arg === "-") return [null, 1];
|
|
52723
|
+
const [option, inlineValue] = splitOption(arg);
|
|
52724
|
+
const name = option.replace(/^-+/, "");
|
|
52725
|
+
if (!isAccepted(option, name, accepted)) {
|
|
52726
|
+
return [unknownOptionMessage(option, name, accepted, label), 1];
|
|
52727
|
+
}
|
|
52728
|
+
if (inlineValue || !accepted[name]) return [null, 1];
|
|
52729
|
+
if (!hasValueAfter(args, i)) {
|
|
52730
|
+
return [`Option --${name} for "${label}" needs a value: --${name} <value>`, 1];
|
|
52731
|
+
}
|
|
52732
|
+
return [null, 2];
|
|
52733
|
+
}
|
|
52734
|
+
function isAccepted(option, name, accepted) {
|
|
52735
|
+
return option.startsWith("--") && Object.hasOwn(accepted, name);
|
|
52736
|
+
}
|
|
52737
|
+
function splitOption(arg) {
|
|
52738
|
+
const eq = arg.indexOf("=");
|
|
52739
|
+
return eq === -1 ? [arg, false] : [arg.slice(0, eq), true];
|
|
52740
|
+
}
|
|
52741
|
+
function hasValueAfter(args, i) {
|
|
52742
|
+
return i + 1 < args.length && !args[i + 1].startsWith("-");
|
|
52743
|
+
}
|
|
52744
|
+
function checkOptions(command, args) {
|
|
52745
|
+
const accepted = acceptedOptions(command, args);
|
|
52746
|
+
if (accepted === null) return;
|
|
52747
|
+
const label = command === "generate" || command === "queue" ? `${command} ${args[0].toLowerCase()}` : command;
|
|
52748
|
+
for (let i = 0; i < args.length; ) {
|
|
52749
|
+
const [problem, consumed] = optionProblem(args, i, accepted, label);
|
|
52750
|
+
if (problem) {
|
|
52751
|
+
console.log(problem);
|
|
52752
|
+
process.exit(1);
|
|
52753
|
+
}
|
|
52754
|
+
i += consumed;
|
|
52755
|
+
}
|
|
52756
|
+
}
|
|
52757
|
+
async function runCommand(command, spec, cmdArgs) {
|
|
52758
|
+
if (command !== "help" && cmdArgs.some((a) => HELP_FLAGS.includes(a))) {
|
|
52759
|
+
printCommandHelp(command, cmdArgs);
|
|
52760
|
+
return;
|
|
52761
|
+
}
|
|
52762
|
+
checkOptions(command, cmdArgs);
|
|
52763
|
+
await spec.handler(cmdArgs);
|
|
52764
|
+
}
|
|
52028
52765
|
async function main() {
|
|
52029
52766
|
const args = process.argv.slice(2);
|
|
52030
52767
|
let command = args[0];
|
|
@@ -52034,7 +52771,7 @@ async function main() {
|
|
|
52034
52771
|
}
|
|
52035
52772
|
const spec = COMMANDS[command];
|
|
52036
52773
|
if (spec) {
|
|
52037
|
-
await spec
|
|
52774
|
+
await runCommand(command, spec, cmdArgs);
|
|
52038
52775
|
return;
|
|
52039
52776
|
}
|
|
52040
52777
|
if (command in DELEGATED) {
|
|
@@ -52057,7 +52794,10 @@ export {
|
|
|
52057
52794
|
DELEGATION_GUARD_ENV,
|
|
52058
52795
|
EXIT_CLIENT_UNAVAILABLE,
|
|
52059
52796
|
EXIT_UNKNOWN_COMMAND,
|
|
52797
|
+
acceptedOptions,
|
|
52060
52798
|
buildCommandManifest,
|
|
52799
|
+
closestOption,
|
|
52061
52800
|
delegateToClient,
|
|
52801
|
+
optionProblem,
|
|
52062
52802
|
runCommands
|
|
52063
52803
|
};
|