tina4-nodejs 3.13.163 → 3.13.165
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 +12 -8
- package/package.json +1 -1
- package/packages/cli/dist/bin.js +899 -693
- package/packages/cli/src/bin.ts +13 -5
- package/packages/cli/src/commands/lint.ts +3 -1
- package/packages/core/dist/index.js +789 -613
- package/packages/core/src/batchSpawn.ts +129 -0
- package/packages/core/src/devAdmin.ts +15 -11
- package/packages/core/src/fakeData.ts +4 -1
- package/packages/core/src/mcp.ts +4 -1
- package/packages/core/src/portTakeover.ts +62 -10
- package/packages/core/src/projectIndex.ts +3 -4
- package/packages/core/src/projectIndexStorage.ts +9 -1
- package/packages/core/src/response.ts +4 -1
- package/packages/core/src/routeDiscovery.ts +8 -2
- package/packages/core/src/server.ts +97 -20
- package/packages/core/src/session.ts +5 -0
- package/packages/core/src/sessionHandlers/databaseHandler.ts +16 -0
- package/packages/frond/dist/index.js +66 -19
- package/packages/frond/src/engine.ts +74 -23
- package/packages/orm/dist/index.js +823 -647
- package/packages/orm/src/model.ts +2 -1
- package/types/core/src/batchSpawn.d.ts +28 -0
- package/types/core/src/portTakeover.d.ts +18 -1
- package/types/core/src/projectIndexStorage.d.ts +5 -0
- package/types/core/src/session.d.ts +5 -0
- package/types/core/src/sessionHandlers/databaseHandler.d.ts +8 -0
- package/types/frond/src/engine.d.ts +31 -2
package/packages/cli/dist/bin.js
CHANGED
|
@@ -148,16 +148,16 @@ function parseEnvContent(content) {
|
|
|
148
148
|
}
|
|
149
149
|
return result;
|
|
150
150
|
}
|
|
151
|
-
function loadEnv(
|
|
151
|
+
function loadEnv(path9, override = false) {
|
|
152
152
|
const fromEnv = (process.env.TINA4_ENV_FILE ?? "").trim();
|
|
153
|
-
if (
|
|
153
|
+
if (path9 === void 0 && fromEnv.length > 0) {
|
|
154
154
|
const named = resolve2(fromEnv);
|
|
155
155
|
return mergeFirstWins(
|
|
156
156
|
loadEnvFile(join2(dirname2(named), ".env.local"), override),
|
|
157
157
|
loadEnvFile(named, override)
|
|
158
158
|
);
|
|
159
159
|
}
|
|
160
|
-
const target = resolve2(
|
|
160
|
+
const target = resolve2(path9 ?? ".");
|
|
161
161
|
if (existsSync2(target) && statSync(target).isDirectory()) {
|
|
162
162
|
return mergeFirstWins(
|
|
163
163
|
loadEnvFile(join2(target, ".env.local"), override),
|
|
@@ -394,12 +394,12 @@ function resolveCallerName() {
|
|
|
394
394
|
return void 0;
|
|
395
395
|
}
|
|
396
396
|
}
|
|
397
|
-
function targetIsFile(
|
|
397
|
+
function targetIsFile(path9) {
|
|
398
398
|
try {
|
|
399
|
-
if (existsSync3(
|
|
399
|
+
if (existsSync3(path9) && statSync2(path9).isDirectory()) return false;
|
|
400
400
|
} catch {
|
|
401
401
|
}
|
|
402
|
-
const base = basename2(
|
|
402
|
+
const base = basename2(path9);
|
|
403
403
|
return base.includes(".") && !base.startsWith(".");
|
|
404
404
|
}
|
|
405
405
|
function resolveBool(explicit, envName, fallback) {
|
|
@@ -723,8 +723,8 @@ var init_logger = __esm({
|
|
|
723
723
|
rotateSize;
|
|
724
724
|
rotateKeep;
|
|
725
725
|
lock;
|
|
726
|
-
constructor(
|
|
727
|
-
this.path =
|
|
726
|
+
constructor(path9, rotateSize, rotateKeep, lockBuffer) {
|
|
727
|
+
this.path = path9;
|
|
728
728
|
this.rotateSize = rotateSize;
|
|
729
729
|
this.rotateKeep = rotateKeep;
|
|
730
730
|
this.lock = new SinkLock(lockBuffer);
|
|
@@ -1245,8 +1245,8 @@ function hashPassword(password, salt, iterations = 26e4) {
|
|
|
1245
1245
|
}
|
|
1246
1246
|
function checkPassword(password, hash) {
|
|
1247
1247
|
try {
|
|
1248
|
-
const
|
|
1249
|
-
const parts = hash.split(
|
|
1248
|
+
const delimiter5 = hash.includes("$") ? "$" : ":";
|
|
1249
|
+
const parts = hash.split(delimiter5);
|
|
1250
1250
|
if (parts.length !== 4 || parts[0] !== "pbkdf2_sha256") return false;
|
|
1251
1251
|
const iterations = parseInt(parts[1], 10);
|
|
1252
1252
|
const salt = parts[2];
|
|
@@ -1722,8 +1722,8 @@ var init_modelCollection = __esm({
|
|
|
1722
1722
|
|
|
1723
1723
|
// ../orm/src/databaseUrl.ts
|
|
1724
1724
|
import { inspect } from "node:util";
|
|
1725
|
-
function stripOneSlash(
|
|
1726
|
-
return
|
|
1725
|
+
function stripOneSlash(path9) {
|
|
1726
|
+
return path9.startsWith("/") ? path9.slice(1) : path9;
|
|
1727
1727
|
}
|
|
1728
1728
|
function decode(value) {
|
|
1729
1729
|
if (value === void 0 || value === "") return null;
|
|
@@ -3730,8 +3730,8 @@ function resolveSqlitePath(dbPath) {
|
|
|
3730
3730
|
return dbPath;
|
|
3731
3731
|
}
|
|
3732
3732
|
const cwd = resolve3(process.cwd());
|
|
3733
|
-
const
|
|
3734
|
-
const parent = dirname4(
|
|
3733
|
+
const path9 = join5(cwd, dbPath);
|
|
3734
|
+
const parent = dirname4(path9);
|
|
3735
3735
|
const absParent = resolve3(parent);
|
|
3736
3736
|
if (absParent !== cwd && !absParent.startsWith(cwd + sep)) {
|
|
3737
3737
|
throw new Error(
|
|
@@ -3739,7 +3739,7 @@ function resolveSqlitePath(dbPath) {
|
|
|
3739
3739
|
);
|
|
3740
3740
|
}
|
|
3741
3741
|
mkdirSync3(parent, { recursive: true, mode: 509 });
|
|
3742
|
-
return
|
|
3742
|
+
return path9;
|
|
3743
3743
|
}
|
|
3744
3744
|
function fieldTypeToSQLite(def) {
|
|
3745
3745
|
switch (def.type) {
|
|
@@ -7618,9 +7618,9 @@ async function initDatabase(config) {
|
|
|
7618
7618
|
const rawType = config?.type ?? "sqlite";
|
|
7619
7619
|
const type2 = rawType === "sqlserver" ? "mssql" : rawType;
|
|
7620
7620
|
if (config === void 0 && !process.env.TINA4_DATABASE_URL) {
|
|
7621
|
-
const
|
|
7621
|
+
const path9 = "./data/tina4.db";
|
|
7622
7622
|
console.warn(
|
|
7623
|
-
`[tina4] No TINA4_DATABASE_URL set \u2014 falling back to SQLite at ${
|
|
7623
|
+
`[tina4] No TINA4_DATABASE_URL set \u2014 falling back to SQLite at ${path9}. If you meant to use Postgres/MySQL/etc., set TINA4_DATABASE_URL in your .env and re-run. (Was the .env loaded? CLI commands must call loadEnv() first.)`
|
|
7624
7624
|
);
|
|
7625
7625
|
}
|
|
7626
7626
|
const finished = (adapter) => {
|
|
@@ -8835,6 +8835,7 @@ var init_database = __esm({
|
|
|
8835
8835
|
// ../orm/src/model.ts
|
|
8836
8836
|
import { readdirSync, statSync as statSync3 } from "node:fs";
|
|
8837
8837
|
import { join as join6, extname } from "node:path";
|
|
8838
|
+
import { pathToFileURL } from "node:url";
|
|
8838
8839
|
async function discoverModels(modelsDir) {
|
|
8839
8840
|
const models = [];
|
|
8840
8841
|
let files;
|
|
@@ -8850,7 +8851,7 @@ async function discoverModels(modelsDir) {
|
|
|
8850
8851
|
const ext = extname(file);
|
|
8851
8852
|
if (ext !== ".ts" && ext !== ".js") continue;
|
|
8852
8853
|
try {
|
|
8853
|
-
const moduleUrl =
|
|
8854
|
+
const moduleUrl = `${pathToFileURL(filePath).href}?t=${Date.now()}`;
|
|
8854
8855
|
const mod = await import(moduleUrl);
|
|
8855
8856
|
const ModelClass = mod.default ?? mod;
|
|
8856
8857
|
if (!ModelClass.tableName || !ModelClass.fields) {
|
|
@@ -9191,7 +9192,7 @@ async function removeMigrationRecord(name) {
|
|
|
9191
9192
|
[name]
|
|
9192
9193
|
);
|
|
9193
9194
|
}
|
|
9194
|
-
async function rollback(migrationsDir,
|
|
9195
|
+
async function rollback(migrationsDir, delimiter5) {
|
|
9195
9196
|
if (migrationsDir instanceof Map) {
|
|
9196
9197
|
const downFunctions = migrationsDir;
|
|
9197
9198
|
const migrations2 = await getLastBatchMigrations();
|
|
@@ -9210,7 +9211,7 @@ async function rollback(migrationsDir, delimiter4) {
|
|
|
9210
9211
|
return rolledBack2;
|
|
9211
9212
|
}
|
|
9212
9213
|
const dir = resolve4(migrationsDir ?? "migrations");
|
|
9213
|
-
const delim =
|
|
9214
|
+
const delim = delimiter5 ?? ";";
|
|
9214
9215
|
const db = getAdapter();
|
|
9215
9216
|
const migrations = await getLastBatchMigrations();
|
|
9216
9217
|
const rolledBack = [];
|
|
@@ -9333,13 +9334,13 @@ function hasExecutableSql(sql) {
|
|
|
9333
9334
|
function isUnappliedScaffold(sql) {
|
|
9334
9335
|
return TINA4_EDIT_MARKER_RE.test(sql) && !hasExecutableSql(sql);
|
|
9335
9336
|
}
|
|
9336
|
-
function splitStatements(sql,
|
|
9337
|
+
function splitStatements(sql, delimiter5 = ";") {
|
|
9337
9338
|
const state = {
|
|
9338
9339
|
sql: normalizeQuotes(sql),
|
|
9339
9340
|
statements: [],
|
|
9340
9341
|
current: "",
|
|
9341
|
-
delimiter:
|
|
9342
|
-
dlen:
|
|
9342
|
+
delimiter: delimiter5,
|
|
9343
|
+
dlen: delimiter5.length,
|
|
9343
9344
|
i: 0,
|
|
9344
9345
|
inDollarBlock: false,
|
|
9345
9346
|
inSlashBlock: false
|
|
@@ -9466,18 +9467,18 @@ async function releaseMigrationLock(db, lock) {
|
|
|
9466
9467
|
async function migrate(adapter, options) {
|
|
9467
9468
|
const db = adapter ?? getAdapter();
|
|
9468
9469
|
const dir = resolve4(options?.migrationsDir ?? "migrations");
|
|
9469
|
-
const
|
|
9470
|
+
const delimiter5 = options?.delimiter ?? ";";
|
|
9470
9471
|
if (!existsSync5(dir)) {
|
|
9471
9472
|
return { applied: [], skipped: [], failed: [] };
|
|
9472
9473
|
}
|
|
9473
9474
|
const lock = await acquireMigrationLock(db, dir);
|
|
9474
9475
|
try {
|
|
9475
|
-
return await runPendingMigrations(db, dir,
|
|
9476
|
+
return await runPendingMigrations(db, dir, delimiter5);
|
|
9476
9477
|
} finally {
|
|
9477
9478
|
await releaseMigrationLock(db, lock);
|
|
9478
9479
|
}
|
|
9479
9480
|
}
|
|
9480
|
-
async function runPendingMigrations(db, dir,
|
|
9481
|
+
async function runPendingMigrations(db, dir, delimiter5) {
|
|
9481
9482
|
const result = { applied: [], skipped: [], failed: [] };
|
|
9482
9483
|
await ensureMigrationTableOn(db);
|
|
9483
9484
|
const files = sortMigrationFiles(
|
|
@@ -9523,7 +9524,7 @@ async function runPendingMigrations(db, dir, delimiter4) {
|
|
|
9523
9524
|
);
|
|
9524
9525
|
continue;
|
|
9525
9526
|
}
|
|
9526
|
-
const statements = splitStatements(sqlContent,
|
|
9527
|
+
const statements = splitStatements(sqlContent, delimiter5);
|
|
9527
9528
|
try {
|
|
9528
9529
|
await adapterStartTransaction(db);
|
|
9529
9530
|
for (const stmt of statements) {
|
|
@@ -10703,15 +10704,15 @@ function findOutsideQuotes(expr, needle) {
|
|
|
10703
10704
|
}
|
|
10704
10705
|
return -1;
|
|
10705
10706
|
}
|
|
10706
|
-
function splitOutsideQuotes(expr,
|
|
10707
|
-
if (!expr.includes(
|
|
10707
|
+
function splitOutsideQuotes(expr, sep10) {
|
|
10708
|
+
if (!expr.includes(sep10)) return [expr];
|
|
10708
10709
|
const parts = [];
|
|
10709
10710
|
let currentStart = 0;
|
|
10710
10711
|
let inQuote = null;
|
|
10711
10712
|
let depth = 0;
|
|
10712
10713
|
let bracketDepth = 0;
|
|
10713
10714
|
let i = 0;
|
|
10714
|
-
const sepLen =
|
|
10715
|
+
const sepLen = sep10.length;
|
|
10715
10716
|
const lastStart = expr.length - sepLen;
|
|
10716
10717
|
while (i <= lastStart) {
|
|
10717
10718
|
const ch = expr[i];
|
|
@@ -10732,7 +10733,7 @@ function splitOutsideQuotes(expr, sep9) {
|
|
|
10732
10733
|
else if (ch === ")") depth--;
|
|
10733
10734
|
else if (ch === "[") bracketDepth++;
|
|
10734
10735
|
else if (ch === "]") bracketDepth--;
|
|
10735
|
-
if (depth === 0 && bracketDepth === 0 && expr.startsWith(
|
|
10736
|
+
if (depth === 0 && bracketDepth === 0 && expr.startsWith(sep10, i)) {
|
|
10736
10737
|
parts.push(expr.slice(currentStart, i));
|
|
10737
10738
|
i += sepLen;
|
|
10738
10739
|
currentStart = i;
|
|
@@ -11910,8 +11911,8 @@ var init_engine = __esm({
|
|
|
11910
11911
|
},
|
|
11911
11912
|
first: (v) => Array.isArray(v) ? v[0] ?? null : null,
|
|
11912
11913
|
last: (v) => Array.isArray(v) ? v[v.length - 1] ?? null : null,
|
|
11913
|
-
join: (v,
|
|
11914
|
-
split: (v,
|
|
11914
|
+
join: (v, sep10) => Array.isArray(v) ? v.map(String).join(sep10 !== void 0 ? String(sep10) : ", ") : String(v),
|
|
11915
|
+
split: (v, sep10) => String(v).split(sep10 !== void 0 ? String(sep10) : " "),
|
|
11915
11916
|
replace: (v, from, to) => {
|
|
11916
11917
|
const s = String(v);
|
|
11917
11918
|
if (from !== void 0 && typeof from === "object" && from !== null && !Array.isArray(from)) {
|
|
@@ -12054,8 +12055,14 @@ var init_engine = __esm({
|
|
|
12054
12055
|
// and every future ``new Frond()`` inherits it automatically.
|
|
12055
12056
|
// Mirrors Python's _class_globals / _class_filters / _class_tests.
|
|
12056
12057
|
static classFilters = /* @__PURE__ */ new Map();
|
|
12057
|
-
|
|
12058
|
+
// Globals are read LIVE at render time (not copied at construction), so a
|
|
12059
|
+
// Frond.addGlobal() made after an engine exists still reaches it. A plain
|
|
12060
|
+
// object rather than a Map so render() can spread it in one step.
|
|
12061
|
+
static classGlobals = {};
|
|
12058
12062
|
static classTests = /* @__PURE__ */ new Map();
|
|
12063
|
+
// Bumped on every class-level filter/test change, so an engine knows when
|
|
12064
|
+
// to rebuild its merged filter/test maps (see syncRegistries).
|
|
12065
|
+
static classRegistryVersion = 0;
|
|
12059
12066
|
// ── Live-block registries (server-rendered {% live %} regions) ──
|
|
12060
12067
|
// A {% live %} block registers three things when its page first renders:
|
|
12061
12068
|
// liveFragments[name] -> the raw body source, re-rendered on every
|
|
@@ -12075,20 +12082,27 @@ var init_engine = __esm({
|
|
|
12075
12082
|
static liveBroadcaster = null;
|
|
12076
12083
|
/**
|
|
12077
12084
|
* Register a custom filter at the class level — available to every
|
|
12078
|
-
*
|
|
12085
|
+
* instance, existing ones included: an engine merges the class filters
|
|
12086
|
+
* again at its next render (ADR-0107). Callable as ``Frond.addFilter()``
|
|
12079
12087
|
* (static) or ``frond.addFilter()`` (instance). See instance method
|
|
12080
12088
|
* below for the dual-call semantics.
|
|
12081
12089
|
*/
|
|
12082
12090
|
static addFilter(name, fn) {
|
|
12083
12091
|
_Frond.classFilters.set(name, fn);
|
|
12092
|
+
_Frond.classRegistryVersion++;
|
|
12084
12093
|
}
|
|
12085
12094
|
/**
|
|
12086
12095
|
* Register a global variable available in all templates of every
|
|
12087
|
-
*
|
|
12096
|
+
* instance, existing ones included: class globals are read at render time
|
|
12097
|
+
* (ADR-0106). Callable as ``Frond.addGlobal()`` (static) or
|
|
12088
12098
|
* ``frond.addGlobal()`` (instance).
|
|
12089
12099
|
*/
|
|
12090
12100
|
static addGlobal(name, value) {
|
|
12091
|
-
_Frond.classGlobals
|
|
12101
|
+
_Frond.classGlobals[name] = value;
|
|
12102
|
+
}
|
|
12103
|
+
/** True when a class-level global with this name is registered. */
|
|
12104
|
+
static hasGlobal(name) {
|
|
12105
|
+
return Object.prototype.hasOwnProperty.call(_Frond.classGlobals, name);
|
|
12092
12106
|
}
|
|
12093
12107
|
/**
|
|
12094
12108
|
* Register a custom test (``{% if x is positive %}``) at the class
|
|
@@ -12097,6 +12111,7 @@ var init_engine = __esm({
|
|
|
12097
12111
|
*/
|
|
12098
12112
|
static addTest(name, fn) {
|
|
12099
12113
|
_Frond.classTests.set(name, fn);
|
|
12114
|
+
_Frond.classRegistryVersion++;
|
|
12100
12115
|
}
|
|
12101
12116
|
/**
|
|
12102
12117
|
* Clear the class-level globals/filters/tests registries.
|
|
@@ -12106,15 +12121,25 @@ var init_engine = __esm({
|
|
|
12106
12121
|
*/
|
|
12107
12122
|
static clearRegistry() {
|
|
12108
12123
|
_Frond.classFilters.clear();
|
|
12109
|
-
_Frond.classGlobals
|
|
12124
|
+
_Frond.classGlobals = {};
|
|
12110
12125
|
_Frond.classTests.clear();
|
|
12126
|
+
_Frond.classRegistryVersion++;
|
|
12111
12127
|
_Frond.liveFragments.clear();
|
|
12112
12128
|
_Frond.liveSources.clear();
|
|
12113
12129
|
_Frond.liveWsPaths.clear();
|
|
12114
12130
|
}
|
|
12115
12131
|
templateDir;
|
|
12116
|
-
filters
|
|
12132
|
+
/** Effective filters: built-in < class < instance (see syncRegistries). */
|
|
12133
|
+
filters = {};
|
|
12134
|
+
/** Filters / tests registered on THIS instance only (ADR-0052). */
|
|
12135
|
+
localFilters = {};
|
|
12136
|
+
localTests = {};
|
|
12137
|
+
/** The class-registry version `filters` / `tests` were last merged at. */
|
|
12138
|
+
registryVersion = -1;
|
|
12139
|
+
/** Globals registered on THIS instance only (ADR-0052). */
|
|
12117
12140
|
globals;
|
|
12141
|
+
/** Built-in globals (formToken, range, dump, csp_nonce, ...). */
|
|
12142
|
+
builtinGlobals;
|
|
12118
12143
|
tests;
|
|
12119
12144
|
_sandbox;
|
|
12120
12145
|
_allowedFilters;
|
|
@@ -12144,9 +12169,10 @@ var init_engine = __esm({
|
|
|
12144
12169
|
}
|
|
12145
12170
|
constructor(templateDir = "src/templates") {
|
|
12146
12171
|
this.templateDir = resolve5(templateDir);
|
|
12147
|
-
this.filters = { ...BUILTIN_FILTERS };
|
|
12148
12172
|
this.globals = {};
|
|
12173
|
+
this.builtinGlobals = {};
|
|
12149
12174
|
this.tests = {};
|
|
12175
|
+
this.syncRegistries();
|
|
12150
12176
|
this._sandbox = false;
|
|
12151
12177
|
this._allowedFilters = null;
|
|
12152
12178
|
this._allowedTags = null;
|
|
@@ -12194,16 +12220,25 @@ var init_engine = __esm({
|
|
|
12194
12220
|
return { output, next };
|
|
12195
12221
|
}
|
|
12196
12222
|
};
|
|
12197
|
-
this.
|
|
12198
|
-
this.
|
|
12199
|
-
this.
|
|
12200
|
-
this.
|
|
12201
|
-
this.
|
|
12202
|
-
this.
|
|
12203
|
-
this.
|
|
12204
|
-
|
|
12205
|
-
|
|
12206
|
-
|
|
12223
|
+
this.builtinGlobals.formToken = (descriptor) => _generateFormToken(descriptor || "");
|
|
12224
|
+
this.builtinGlobals.form_token = (descriptor) => _generateFormToken(descriptor || "");
|
|
12225
|
+
this.builtinGlobals.formTokenValue = (descriptor) => _generateFormTokenValue(descriptor || "");
|
|
12226
|
+
this.builtinGlobals.form_token_value = (descriptor) => _generateFormTokenValue(descriptor || "");
|
|
12227
|
+
this.builtinGlobals.range = frondRange;
|
|
12228
|
+
this.builtinGlobals.dump = (value) => renderDump(value);
|
|
12229
|
+
this.builtinGlobals.csp_nonce = () => _cspNonceProvider();
|
|
12230
|
+
}
|
|
12231
|
+
/**
|
|
12232
|
+
* Rebuild the merged filter/test maps when the class registry changed.
|
|
12233
|
+
* Same layering as globals -- built-ins < class < this instance. Filter
|
|
12234
|
+
* lookup is on the hot path, so the merge is a plain object rebuilt only
|
|
12235
|
+
* when the class-registry version moves, never a per-lookup chain.
|
|
12236
|
+
*/
|
|
12237
|
+
syncRegistries() {
|
|
12238
|
+
if (this.registryVersion === _Frond.classRegistryVersion) return;
|
|
12239
|
+
this.filters = { ...BUILTIN_FILTERS, ...Object.fromEntries(_Frond.classFilters), ...this.localFilters };
|
|
12240
|
+
this.tests = { ...Object.fromEntries(_Frond.classTests), ...this.localTests };
|
|
12241
|
+
this.registryVersion = _Frond.classRegistryVersion;
|
|
12207
12242
|
}
|
|
12208
12243
|
sandbox(filters, tags, vars) {
|
|
12209
12244
|
this._sandbox = true;
|
|
@@ -12224,6 +12259,7 @@ var init_engine = __esm({
|
|
|
12224
12259
|
* for process-global registration. tina4: ADR-0052.
|
|
12225
12260
|
*/
|
|
12226
12261
|
addFilter(name, fn) {
|
|
12262
|
+
this.localFilters[name] = fn;
|
|
12227
12263
|
this.filters[name] = fn;
|
|
12228
12264
|
}
|
|
12229
12265
|
/**
|
|
@@ -12236,6 +12272,7 @@ var init_engine = __esm({
|
|
|
12236
12272
|
* Register a custom test on this instance only.
|
|
12237
12273
|
*/
|
|
12238
12274
|
addTest(name, fn) {
|
|
12275
|
+
this.localTests[name] = fn;
|
|
12239
12276
|
this.tests[name] = fn;
|
|
12240
12277
|
}
|
|
12241
12278
|
/**
|
|
@@ -12251,8 +12288,19 @@ var init_engine = __esm({
|
|
|
12251
12288
|
const n = parseInt(raw, 10);
|
|
12252
12289
|
return isNaN(n) || n < 0 ? 0 : n;
|
|
12253
12290
|
}
|
|
12291
|
+
/**
|
|
12292
|
+
* Layer the globals under the render data: built-ins < class globals (read
|
|
12293
|
+
* live, so registration order never matters) < this instance's own globals
|
|
12294
|
+
* < the data passed to render(). Every render starts here, so this is also
|
|
12295
|
+
* where the filter/test maps catch up with any class registration made
|
|
12296
|
+
* since the last render.
|
|
12297
|
+
*/
|
|
12298
|
+
withGlobals(data) {
|
|
12299
|
+
this.syncRegistries();
|
|
12300
|
+
return { ...this.builtinGlobals, ..._Frond.classGlobals, ...this.globals, ...data || {} };
|
|
12301
|
+
}
|
|
12254
12302
|
render(template, data) {
|
|
12255
|
-
const context =
|
|
12303
|
+
const context = this.withGlobals(data);
|
|
12256
12304
|
const filePath = join8(this.templateDir, template);
|
|
12257
12305
|
if (!existsSync6(filePath)) {
|
|
12258
12306
|
throw new Error(`Template not found: ${filePath}`);
|
|
@@ -12275,7 +12323,7 @@ var init_engine = __esm({
|
|
|
12275
12323
|
return this.executeWithSource(source, tokens, context);
|
|
12276
12324
|
}
|
|
12277
12325
|
renderString(source, data) {
|
|
12278
|
-
const context =
|
|
12326
|
+
const context = this.withGlobals(data);
|
|
12279
12327
|
const key = createHash3("md5").update(source).digest("hex");
|
|
12280
12328
|
const ttlMs = this.cacheTtlSeconds() * 1e3;
|
|
12281
12329
|
const cached = this.compiledStrings.get(key);
|
|
@@ -16026,6 +16074,7 @@ var init_baseModel = __esm({
|
|
|
16026
16074
|
import { randomInt, randomUUID } from "node:crypto";
|
|
16027
16075
|
import { existsSync as existsSync8, readdirSync as readdirSync3 } from "node:fs";
|
|
16028
16076
|
import { resolve as resolve6, join as join9 } from "node:path";
|
|
16077
|
+
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
16029
16078
|
function mulberry32(seed) {
|
|
16030
16079
|
let s = seed | 0;
|
|
16031
16080
|
return () => {
|
|
@@ -16529,7 +16578,7 @@ var init_fakeData = __esm({
|
|
|
16529
16578
|
for (const file of files) {
|
|
16530
16579
|
const fullPath = join9(dir, file);
|
|
16531
16580
|
try {
|
|
16532
|
-
const mod = await import(fullPath);
|
|
16581
|
+
const mod = await import(pathToFileURL2(fullPath).href);
|
|
16533
16582
|
if (typeof mod.default === "function") {
|
|
16534
16583
|
await mod.default();
|
|
16535
16584
|
}
|
|
@@ -17254,12 +17303,12 @@ function regexpFn(pattern, value) {
|
|
|
17254
17303
|
}
|
|
17255
17304
|
function resolveStorePath(dbPath) {
|
|
17256
17305
|
if (dbPath === ":memory:") return dbPath;
|
|
17257
|
-
let
|
|
17258
|
-
if (!isAbsolute4(
|
|
17259
|
-
|
|
17260
|
-
mkdirSync5(dirname6(
|
|
17306
|
+
let path9 = dbPath;
|
|
17307
|
+
if (!isAbsolute4(path9)) {
|
|
17308
|
+
path9 = join10(process.cwd(), path9);
|
|
17309
|
+
mkdirSync5(dirname6(path9), { recursive: true });
|
|
17261
17310
|
}
|
|
17262
|
-
return
|
|
17311
|
+
return path9;
|
|
17263
17312
|
}
|
|
17264
17313
|
function mongoUriSource() {
|
|
17265
17314
|
return MONGO_URI_VARS.find((name) => (process.env[name] ?? "").trim() !== "") ?? "";
|
|
@@ -17638,8 +17687,8 @@ var init_docstore = __esm({
|
|
|
17638
17687
|
path;
|
|
17639
17688
|
conn;
|
|
17640
17689
|
collections = /* @__PURE__ */ new Map();
|
|
17641
|
-
constructor(
|
|
17642
|
-
this.path =
|
|
17690
|
+
constructor(path9) {
|
|
17691
|
+
this.path = path9 || process.env.TINA4_DOC_STORE_PATH || "data/tina4_docstore.db";
|
|
17643
17692
|
const resolved = resolveStorePath(this.path);
|
|
17644
17693
|
this.conn = new DatabaseSync2(resolved);
|
|
17645
17694
|
this.conn.function("regexp", regexpFn);
|
|
@@ -17728,8 +17777,8 @@ var init_graphUrl = __esm({
|
|
|
17728
17777
|
this.engine = engine;
|
|
17729
17778
|
this.host = parsed.hostname || "localhost";
|
|
17730
17779
|
this.port = parsed.port ? parseInt(parsed.port, 10) : ENGINE_DEFAULT_PORT[engine];
|
|
17731
|
-
const
|
|
17732
|
-
this.graph =
|
|
17780
|
+
const path9 = (parsed.pathname || "").replace(/^\//, "");
|
|
17781
|
+
this.graph = path9 === "" ? null : path9;
|
|
17733
17782
|
this.username = parsed.username ? decodeURIComponent(parsed.username) : null;
|
|
17734
17783
|
this.password = parsed.password ? decodeURIComponent(parsed.password) : null;
|
|
17735
17784
|
this.params = {};
|
|
@@ -20890,8 +20939,8 @@ function coerceParam(raw, type2) {
|
|
|
20890
20939
|
return raw;
|
|
20891
20940
|
}
|
|
20892
20941
|
}
|
|
20893
|
-
function joinGroupPath(prefix,
|
|
20894
|
-
const full = `${prefix}/${
|
|
20942
|
+
function joinGroupPath(prefix, path9) {
|
|
20943
|
+
const full = `${prefix}/${path9.replace(/^\/+/, "")}`;
|
|
20895
20944
|
const trimmed = `/${trimSlashes(full)}`;
|
|
20896
20945
|
return trimmed.replace(/\/+/g, "/");
|
|
20897
20946
|
}
|
|
@@ -20932,26 +20981,26 @@ async function runRouteMiddlewares(middlewares, req2, res) {
|
|
|
20932
20981
|
}
|
|
20933
20982
|
return true;
|
|
20934
20983
|
}
|
|
20935
|
-
function get(
|
|
20936
|
-
return defaultRouter.get(
|
|
20984
|
+
function get(path9, handler, middlewares, meta) {
|
|
20985
|
+
return defaultRouter.get(path9, handler, middlewares, meta);
|
|
20937
20986
|
}
|
|
20938
|
-
function post(
|
|
20939
|
-
return defaultRouter.post(
|
|
20987
|
+
function post(path9, handler, middlewares, meta) {
|
|
20988
|
+
return defaultRouter.post(path9, handler, middlewares, meta);
|
|
20940
20989
|
}
|
|
20941
|
-
function put(
|
|
20942
|
-
return defaultRouter.put(
|
|
20990
|
+
function put(path9, handler, middlewares, meta) {
|
|
20991
|
+
return defaultRouter.put(path9, handler, middlewares, meta);
|
|
20943
20992
|
}
|
|
20944
|
-
function patch(
|
|
20945
|
-
return defaultRouter.patch(
|
|
20993
|
+
function patch(path9, handler, middlewares, meta) {
|
|
20994
|
+
return defaultRouter.patch(path9, handler, middlewares, meta);
|
|
20946
20995
|
}
|
|
20947
|
-
function del(
|
|
20948
|
-
return defaultRouter.delete(
|
|
20996
|
+
function del(path9, handler, middlewares, meta) {
|
|
20997
|
+
return defaultRouter.delete(path9, handler, middlewares, meta);
|
|
20949
20998
|
}
|
|
20950
|
-
function any(
|
|
20951
|
-
return defaultRouter.any(
|
|
20999
|
+
function any(path9, handler, middlewares, meta) {
|
|
21000
|
+
return defaultRouter.any(path9, handler, middlewares, meta);
|
|
20952
21001
|
}
|
|
20953
|
-
function websocket(
|
|
20954
|
-
return defaultRouter.websocket(
|
|
21002
|
+
function websocket(path9, handler, options) {
|
|
21003
|
+
return defaultRouter.websocket(path9, handler, options);
|
|
20955
21004
|
}
|
|
20956
21005
|
var WsRouteRef, RouteRef, Router, RouteGroup, TINA4_DEFAULT_ROUTER, globalRouterHost, defaultRouter;
|
|
20957
21006
|
var init_router = __esm({
|
|
@@ -21099,32 +21148,32 @@ var init_router = __esm({
|
|
|
21099
21148
|
/**
|
|
21100
21149
|
* Register a GET route programmatically.
|
|
21101
21150
|
*/
|
|
21102
|
-
get(
|
|
21103
|
-
return this.addRoute({ method: "GET", pattern:
|
|
21151
|
+
get(path9, handler, middlewares, meta) {
|
|
21152
|
+
return this.addRoute({ method: "GET", pattern: path9, handler, middlewares, meta });
|
|
21104
21153
|
}
|
|
21105
21154
|
/**
|
|
21106
21155
|
* Register a POST route programmatically.
|
|
21107
21156
|
*/
|
|
21108
|
-
post(
|
|
21109
|
-
return this.addRoute({ method: "POST", pattern:
|
|
21157
|
+
post(path9, handler, middlewares, meta) {
|
|
21158
|
+
return this.addRoute({ method: "POST", pattern: path9, handler, middlewares, meta });
|
|
21110
21159
|
}
|
|
21111
21160
|
/**
|
|
21112
21161
|
* Register a PUT route programmatically.
|
|
21113
21162
|
*/
|
|
21114
|
-
put(
|
|
21115
|
-
return this.addRoute({ method: "PUT", pattern:
|
|
21163
|
+
put(path9, handler, middlewares, meta) {
|
|
21164
|
+
return this.addRoute({ method: "PUT", pattern: path9, handler, middlewares, meta });
|
|
21116
21165
|
}
|
|
21117
21166
|
/**
|
|
21118
21167
|
* Register a PATCH route programmatically.
|
|
21119
21168
|
*/
|
|
21120
|
-
patch(
|
|
21121
|
-
return this.addRoute({ method: "PATCH", pattern:
|
|
21169
|
+
patch(path9, handler, middlewares, meta) {
|
|
21170
|
+
return this.addRoute({ method: "PATCH", pattern: path9, handler, middlewares, meta });
|
|
21122
21171
|
}
|
|
21123
21172
|
/**
|
|
21124
21173
|
* Register a DELETE route programmatically.
|
|
21125
21174
|
*/
|
|
21126
|
-
delete(
|
|
21127
|
-
return this.addRoute({ method: "DELETE", pattern:
|
|
21175
|
+
delete(path9, handler, middlewares, meta) {
|
|
21176
|
+
return this.addRoute({ method: "DELETE", pattern: path9, handler, middlewares, meta });
|
|
21128
21177
|
}
|
|
21129
21178
|
/**
|
|
21130
21179
|
* Register an explicit HEAD route. By default the framework auto-handles
|
|
@@ -21134,8 +21183,8 @@ var init_router = __esm({
|
|
|
21134
21183
|
* logic, custom validator headers without the cost of building the body.
|
|
21135
21184
|
* The framework still strips the response body for you on the way out.
|
|
21136
21185
|
*/
|
|
21137
|
-
head(
|
|
21138
|
-
return this.addRoute({ method: "HEAD", pattern:
|
|
21186
|
+
head(path9, handler, middlewares, meta) {
|
|
21187
|
+
return this.addRoute({ method: "HEAD", pattern: path9, handler, middlewares, meta });
|
|
21139
21188
|
}
|
|
21140
21189
|
/**
|
|
21141
21190
|
* Register an explicit OPTIONS route. By default the framework auto-
|
|
@@ -21143,16 +21192,16 @@ var init_router = __esm({
|
|
|
21143
21192
|
* registered for the path and returning 204 (RFC 9110 §9.3.7). Use
|
|
21144
21193
|
* this to take over that behaviour.
|
|
21145
21194
|
*/
|
|
21146
|
-
options(
|
|
21147
|
-
return this.addRoute({ method: "OPTIONS", pattern:
|
|
21195
|
+
options(path9, handler, middlewares, meta) {
|
|
21196
|
+
return this.addRoute({ method: "OPTIONS", pattern: path9, handler, middlewares, meta });
|
|
21148
21197
|
}
|
|
21149
21198
|
/**
|
|
21150
21199
|
* Register a route that matches ANY HTTP method.
|
|
21151
21200
|
*/
|
|
21152
|
-
any(
|
|
21201
|
+
any(path9, handler, middlewares, meta) {
|
|
21153
21202
|
let lastRef;
|
|
21154
21203
|
for (const method of ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"]) {
|
|
21155
|
-
lastRef = this.addRoute({ method, pattern:
|
|
21204
|
+
lastRef = this.addRoute({ method, pattern: path9, handler, middlewares, meta });
|
|
21156
21205
|
}
|
|
21157
21206
|
return lastRef;
|
|
21158
21207
|
}
|
|
@@ -21171,14 +21220,14 @@ var init_router = __esm({
|
|
|
21171
21220
|
* the trailing slash. Returning the de-slashed pattern lets callers issue
|
|
21172
21221
|
* a 308 redirect instead of a hard 404 — Python parity.
|
|
21173
21222
|
*/
|
|
21174
|
-
match(method,
|
|
21223
|
+
match(method, path9) {
|
|
21175
21224
|
const upperMethod = method.toUpperCase();
|
|
21176
21225
|
const routes = this.routes.get(upperMethod);
|
|
21177
21226
|
if (routes) {
|
|
21178
|
-
const direct = this.matchRoute(routes,
|
|
21227
|
+
const direct = this.matchRoute(routes, path9);
|
|
21179
21228
|
if (direct) return direct;
|
|
21180
|
-
if (isTrailingSlashRedirectEnabled() &&
|
|
21181
|
-
const stripped = rtrimSlashes(
|
|
21229
|
+
if (isTrailingSlashRedirectEnabled() && path9.length > 1 && path9.endsWith("/")) {
|
|
21230
|
+
const stripped = rtrimSlashes(path9);
|
|
21182
21231
|
if (stripped.length > 0) {
|
|
21183
21232
|
const retry = this.matchRoute(routes, stripped);
|
|
21184
21233
|
if (retry) return retry;
|
|
@@ -21188,7 +21237,7 @@ var init_router = __esm({
|
|
|
21188
21237
|
if (upperMethod === "HEAD") {
|
|
21189
21238
|
const getRoutes = this.routes.get("GET");
|
|
21190
21239
|
if (getRoutes) {
|
|
21191
|
-
return this.matchRoute(getRoutes,
|
|
21240
|
+
return this.matchRoute(getRoutes, path9);
|
|
21192
21241
|
}
|
|
21193
21242
|
}
|
|
21194
21243
|
return null;
|
|
@@ -21203,13 +21252,13 @@ var init_router = __esm({
|
|
|
21203
21252
|
* OPTIONS is appended whenever any method exists for the path (the
|
|
21204
21253
|
* framework auto-handles OPTIONS).
|
|
21205
21254
|
*/
|
|
21206
|
-
methodsAllowedForPath(
|
|
21255
|
+
methodsAllowedForPath(path9) {
|
|
21207
21256
|
const order = ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"];
|
|
21208
21257
|
const seen = /* @__PURE__ */ new Set();
|
|
21209
21258
|
for (const m of order) {
|
|
21210
21259
|
const routes = this.routes.get(m);
|
|
21211
21260
|
if (!routes) continue;
|
|
21212
|
-
if (this.matchRoute(routes,
|
|
21261
|
+
if (this.matchRoute(routes, path9)) {
|
|
21213
21262
|
seen.add(m);
|
|
21214
21263
|
}
|
|
21215
21264
|
}
|
|
@@ -21220,9 +21269,9 @@ var init_router = __esm({
|
|
|
21220
21269
|
return order.filter((m) => seen.has(m));
|
|
21221
21270
|
}
|
|
21222
21271
|
/** Inner match against a list of compiled routes, no trailing-slash logic. */
|
|
21223
|
-
matchRoute(routes,
|
|
21272
|
+
matchRoute(routes, path9) {
|
|
21224
21273
|
for (const route of routes) {
|
|
21225
|
-
const match = route.regex.exec(
|
|
21274
|
+
const match = route.regex.exec(path9);
|
|
21226
21275
|
if (match) {
|
|
21227
21276
|
const params = {};
|
|
21228
21277
|
for (let i = 0; i < route.paramNames.length; i++) {
|
|
@@ -21310,10 +21359,10 @@ var init_router = __esm({
|
|
|
21310
21359
|
* When secured, the upgrade handshake requires a valid JWT (Authorization
|
|
21311
21360
|
* header / `bearer` subprotocol / `?token=`) or the upgrade is rejected.
|
|
21312
21361
|
*/
|
|
21313
|
-
websocket(
|
|
21314
|
-
this.wsRoutes = this.wsRoutes.filter((r) => r.pattern !==
|
|
21362
|
+
websocket(path9, handler, options) {
|
|
21363
|
+
this.wsRoutes = this.wsRoutes.filter((r) => r.pattern !== path9);
|
|
21315
21364
|
const route = {
|
|
21316
|
-
pattern:
|
|
21365
|
+
pattern: path9,
|
|
21317
21366
|
handler,
|
|
21318
21367
|
// Public unless explicitly secured via options OR a handler `_secured` flag.
|
|
21319
21368
|
authRequired: Boolean(options?.secured ?? handler._secured ?? false)
|
|
@@ -21370,54 +21419,54 @@ var init_router = __esm({
|
|
|
21370
21419
|
* Register a route for a specific HTTP method.
|
|
21371
21420
|
* Core registration method — all convenience methods delegate here.
|
|
21372
21421
|
*/
|
|
21373
|
-
static add(method,
|
|
21422
|
+
static add(method, path9, handler, middleware, swaggerMeta, template) {
|
|
21374
21423
|
const m = method.toUpperCase();
|
|
21375
21424
|
if (m === "ANY") {
|
|
21376
|
-
return defaultRouter.any(
|
|
21425
|
+
return defaultRouter.any(path9, handler, middleware, swaggerMeta);
|
|
21377
21426
|
}
|
|
21378
|
-
return defaultRouter.addRoute({ method: m, pattern:
|
|
21427
|
+
return defaultRouter.addRoute({ method: m, pattern: path9, handler, middlewares: middleware, meta: swaggerMeta, template });
|
|
21379
21428
|
}
|
|
21380
21429
|
/**
|
|
21381
21430
|
* Register a GET route on the default global router.
|
|
21382
21431
|
*/
|
|
21383
|
-
static get(
|
|
21384
|
-
return defaultRouter.get(
|
|
21432
|
+
static get(path9, handler, middleware, swaggerMeta, template) {
|
|
21433
|
+
return defaultRouter.get(path9, handler, middleware, swaggerMeta);
|
|
21385
21434
|
}
|
|
21386
21435
|
/**
|
|
21387
21436
|
* Register a POST route on the default global router.
|
|
21388
21437
|
*/
|
|
21389
|
-
static post(
|
|
21390
|
-
return defaultRouter.post(
|
|
21438
|
+
static post(path9, handler, middleware, swaggerMeta, template) {
|
|
21439
|
+
return defaultRouter.post(path9, handler, middleware, swaggerMeta);
|
|
21391
21440
|
}
|
|
21392
21441
|
/**
|
|
21393
21442
|
* Register a PUT route on the default global router.
|
|
21394
21443
|
*/
|
|
21395
|
-
static put(
|
|
21396
|
-
return defaultRouter.put(
|
|
21444
|
+
static put(path9, handler, middleware, swaggerMeta, template) {
|
|
21445
|
+
return defaultRouter.put(path9, handler, middleware, swaggerMeta);
|
|
21397
21446
|
}
|
|
21398
21447
|
/**
|
|
21399
21448
|
* Register a PATCH route on the default global router.
|
|
21400
21449
|
*/
|
|
21401
|
-
static patch(
|
|
21402
|
-
return defaultRouter.patch(
|
|
21450
|
+
static patch(path9, handler, middleware, swaggerMeta, template) {
|
|
21451
|
+
return defaultRouter.patch(path9, handler, middleware, swaggerMeta);
|
|
21403
21452
|
}
|
|
21404
21453
|
/**
|
|
21405
21454
|
* Register a DELETE route on the default global router.
|
|
21406
21455
|
*/
|
|
21407
|
-
static delete(
|
|
21408
|
-
return defaultRouter.delete(
|
|
21456
|
+
static delete(path9, handler, middleware, swaggerMeta, template) {
|
|
21457
|
+
return defaultRouter.delete(path9, handler, middleware, swaggerMeta);
|
|
21409
21458
|
}
|
|
21410
21459
|
/**
|
|
21411
21460
|
* Register a route that matches ANY HTTP method on the default global router.
|
|
21412
21461
|
*/
|
|
21413
|
-
static any(
|
|
21414
|
-
return defaultRouter.any(
|
|
21462
|
+
static any(path9, handler, middleware, swaggerMeta, template) {
|
|
21463
|
+
return defaultRouter.any(path9, handler, middleware, swaggerMeta);
|
|
21415
21464
|
}
|
|
21416
21465
|
/**
|
|
21417
21466
|
* Register a WebSocket route on the default global router.
|
|
21418
21467
|
*/
|
|
21419
|
-
static websocket(
|
|
21420
|
-
return defaultRouter.websocket(
|
|
21468
|
+
static websocket(path9, handler, options) {
|
|
21469
|
+
return defaultRouter.websocket(path9, handler, options);
|
|
21421
21470
|
}
|
|
21422
21471
|
/**
|
|
21423
21472
|
* Match a WebSocket upgrade path against routes on the default global router.
|
|
@@ -21533,57 +21582,57 @@ var init_router = __esm({
|
|
|
21533
21582
|
const merged = [...group, ...route];
|
|
21534
21583
|
return merged.length > 0 ? merged : void 0;
|
|
21535
21584
|
}
|
|
21536
|
-
get(
|
|
21585
|
+
get(path9, handler, middlewares, meta) {
|
|
21537
21586
|
return this.router.addRoute({
|
|
21538
21587
|
method: "GET",
|
|
21539
|
-
pattern: joinGroupPath(this.prefix,
|
|
21588
|
+
pattern: joinGroupPath(this.prefix, path9),
|
|
21540
21589
|
handler,
|
|
21541
21590
|
middlewares: this.mergeMiddlewares(middlewares),
|
|
21542
21591
|
meta
|
|
21543
21592
|
});
|
|
21544
21593
|
}
|
|
21545
|
-
post(
|
|
21594
|
+
post(path9, handler, middlewares, meta) {
|
|
21546
21595
|
return this.router.addRoute({
|
|
21547
21596
|
method: "POST",
|
|
21548
|
-
pattern: joinGroupPath(this.prefix,
|
|
21597
|
+
pattern: joinGroupPath(this.prefix, path9),
|
|
21549
21598
|
handler,
|
|
21550
21599
|
middlewares: this.mergeMiddlewares(middlewares),
|
|
21551
21600
|
meta
|
|
21552
21601
|
});
|
|
21553
21602
|
}
|
|
21554
|
-
put(
|
|
21603
|
+
put(path9, handler, middlewares, meta) {
|
|
21555
21604
|
return this.router.addRoute({
|
|
21556
21605
|
method: "PUT",
|
|
21557
|
-
pattern: joinGroupPath(this.prefix,
|
|
21606
|
+
pattern: joinGroupPath(this.prefix, path9),
|
|
21558
21607
|
handler,
|
|
21559
21608
|
middlewares: this.mergeMiddlewares(middlewares),
|
|
21560
21609
|
meta
|
|
21561
21610
|
});
|
|
21562
21611
|
}
|
|
21563
|
-
patch(
|
|
21612
|
+
patch(path9, handler, middlewares, meta) {
|
|
21564
21613
|
return this.router.addRoute({
|
|
21565
21614
|
method: "PATCH",
|
|
21566
|
-
pattern: joinGroupPath(this.prefix,
|
|
21615
|
+
pattern: joinGroupPath(this.prefix, path9),
|
|
21567
21616
|
handler,
|
|
21568
21617
|
middlewares: this.mergeMiddlewares(middlewares),
|
|
21569
21618
|
meta
|
|
21570
21619
|
});
|
|
21571
21620
|
}
|
|
21572
|
-
delete(
|
|
21621
|
+
delete(path9, handler, middlewares, meta) {
|
|
21573
21622
|
return this.router.addRoute({
|
|
21574
21623
|
method: "DELETE",
|
|
21575
|
-
pattern: joinGroupPath(this.prefix,
|
|
21624
|
+
pattern: joinGroupPath(this.prefix, path9),
|
|
21576
21625
|
handler,
|
|
21577
21626
|
middlewares: this.mergeMiddlewares(middlewares),
|
|
21578
21627
|
meta
|
|
21579
21628
|
});
|
|
21580
21629
|
}
|
|
21581
|
-
any(
|
|
21630
|
+
any(path9, handler, middlewares, meta) {
|
|
21582
21631
|
let lastRef;
|
|
21583
21632
|
for (const method of ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"]) {
|
|
21584
21633
|
lastRef = this.router.addRoute({
|
|
21585
21634
|
method,
|
|
21586
|
-
pattern: joinGroupPath(this.prefix,
|
|
21635
|
+
pattern: joinGroupPath(this.prefix, path9),
|
|
21587
21636
|
handler,
|
|
21588
21637
|
middlewares: this.mergeMiddlewares(middlewares),
|
|
21589
21638
|
meta
|
|
@@ -21785,6 +21834,7 @@ var init_trustedProxy = __esm({
|
|
|
21785
21834
|
// ../core/src/response.ts
|
|
21786
21835
|
import fs2 from "node:fs";
|
|
21787
21836
|
import nodePath from "node:path";
|
|
21837
|
+
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
21788
21838
|
import { once } from "node:events";
|
|
21789
21839
|
async function closeSource(source) {
|
|
21790
21840
|
const s = source;
|
|
@@ -21827,7 +21877,7 @@ async function getFrond() {
|
|
|
21827
21877
|
return engine;
|
|
21828
21878
|
}
|
|
21829
21879
|
async function getFrameworkFrond() {
|
|
21830
|
-
const frameworkDir = nodePath.resolve(nodePath.dirname(import.meta.url
|
|
21880
|
+
const frameworkDir = nodePath.resolve(nodePath.dirname(fileURLToPath3(import.meta.url)), "..", "templates");
|
|
21831
21881
|
if (!_frameworkFrond && fs2.existsSync(frameworkDir)) {
|
|
21832
21882
|
try {
|
|
21833
21883
|
const { Frond: Frond2, setCspNonceProvider: setCspNonceProvider2 } = await Promise.resolve().then(() => (init_engine(), engine_exports));
|
|
@@ -22862,9 +22912,9 @@ var init_middleware = __esm({
|
|
|
22862
22912
|
const duration = Date.now() - (req2.startTime ?? Date.now());
|
|
22863
22913
|
const status2 = res.raw.statusCode;
|
|
22864
22914
|
const method = req2.method ?? "?";
|
|
22865
|
-
const
|
|
22915
|
+
const path9 = logPath(req2);
|
|
22866
22916
|
const color = status2 >= 400 ? "\x1B[31m" : status2 >= 300 ? "\x1B[33m" : "\x1B[32m";
|
|
22867
|
-
console.log(` ${color}${status2}\x1B[0m ${method} ${
|
|
22917
|
+
console.log(` ${color}${status2}\x1B[0m ${method} ${path9} \x1B[90m${duration}ms\x1B[0m`);
|
|
22868
22918
|
return [req2, res];
|
|
22869
22919
|
}
|
|
22870
22920
|
};
|
|
@@ -23029,7 +23079,7 @@ function createRequest(req2) {
|
|
|
23029
23079
|
const xfHost = trustedPeer ? req2.headers["x-forwarded-host"] : void 0;
|
|
23030
23080
|
const host = (Array.isArray(xfHost) ? xfHost[0] : xfHost) ?? (req2.headers.host ?? "localhost");
|
|
23031
23081
|
const query = {};
|
|
23032
|
-
let
|
|
23082
|
+
let path9;
|
|
23033
23083
|
let queryString;
|
|
23034
23084
|
let fullUrl;
|
|
23035
23085
|
try {
|
|
@@ -23038,13 +23088,13 @@ function createRequest(req2) {
|
|
|
23038
23088
|
if (isUnsafeFieldName(key)) continue;
|
|
23039
23089
|
Reflect.set(query, key, value);
|
|
23040
23090
|
}
|
|
23041
|
-
|
|
23091
|
+
path9 = url.pathname;
|
|
23042
23092
|
queryString = url.search.replace(/^\?/, "");
|
|
23043
23093
|
fullUrl = url.toString();
|
|
23044
23094
|
} catch {
|
|
23045
23095
|
const rawTarget = req2.url ?? "/";
|
|
23046
23096
|
const questionIdx = rawTarget.indexOf("?");
|
|
23047
|
-
|
|
23097
|
+
path9 = questionIdx >= 0 ? rawTarget.slice(0, questionIdx) : rawTarget;
|
|
23048
23098
|
queryString = questionIdx >= 0 ? rawTarget.slice(questionIdx + 1) : "";
|
|
23049
23099
|
try {
|
|
23050
23100
|
for (const [key, value] of new URLSearchParams(queryString)) {
|
|
@@ -23057,7 +23107,7 @@ function createRequest(req2) {
|
|
|
23057
23107
|
}
|
|
23058
23108
|
tReq.params = {};
|
|
23059
23109
|
w.query = query;
|
|
23060
|
-
w.path =
|
|
23110
|
+
w.path = path9;
|
|
23061
23111
|
w.queryString = queryString;
|
|
23062
23112
|
w.url = fullUrl;
|
|
23063
23113
|
tReq.body = void 0;
|
|
@@ -23172,14 +23222,14 @@ function extractBoundary(contentType) {
|
|
|
23172
23222
|
function parseMultipart(body, boundary) {
|
|
23173
23223
|
const pairs = [];
|
|
23174
23224
|
const files = {};
|
|
23175
|
-
const
|
|
23225
|
+
const delimiter5 = Buffer.from(`--${boundary}`);
|
|
23176
23226
|
const closeDelimiter = Buffer.from(`--${boundary}--`);
|
|
23177
23227
|
const crlf = Buffer.from("\r\n");
|
|
23178
23228
|
const doubleCrlf = Buffer.from("\r\n\r\n");
|
|
23179
23229
|
let offset = 0;
|
|
23180
|
-
const firstIdx = bufferIndexOf(body,
|
|
23230
|
+
const firstIdx = bufferIndexOf(body, delimiter5, offset);
|
|
23181
23231
|
if (firstIdx === -1) return { fields: {}, files };
|
|
23182
|
-
offset = firstIdx +
|
|
23232
|
+
offset = firstIdx + delimiter5.length;
|
|
23183
23233
|
if (body[offset] === 13 && body[offset + 1] === 10) {
|
|
23184
23234
|
offset += 2;
|
|
23185
23235
|
}
|
|
@@ -23188,7 +23238,7 @@ function parseMultipart(body, boundary) {
|
|
|
23188
23238
|
if (headersEnd === -1) break;
|
|
23189
23239
|
const headersStr = body.subarray(offset, headersEnd).toString("utf-8");
|
|
23190
23240
|
offset = headersEnd + doubleCrlf.length;
|
|
23191
|
-
const nextDelimIdx = bufferIndexOf(body,
|
|
23241
|
+
const nextDelimIdx = bufferIndexOf(body, delimiter5, offset);
|
|
23192
23242
|
if (nextDelimIdx === -1) break;
|
|
23193
23243
|
const contentEnd = nextDelimIdx - crlf.length;
|
|
23194
23244
|
const content = body.subarray(offset, contentEnd);
|
|
@@ -23212,7 +23262,7 @@ function parseMultipart(body, boundary) {
|
|
|
23212
23262
|
} else if (disposition.name) {
|
|
23213
23263
|
pairs.push([disposition.name, content.toString("utf-8")]);
|
|
23214
23264
|
}
|
|
23215
|
-
offset = nextDelimIdx +
|
|
23265
|
+
offset = nextDelimIdx + delimiter5.length;
|
|
23216
23266
|
if (body[offset] === 45 && body[offset + 1] === 45) {
|
|
23217
23267
|
break;
|
|
23218
23268
|
}
|
|
@@ -23772,6 +23822,7 @@ __export(routeDiscovery_exports, {
|
|
|
23772
23822
|
});
|
|
23773
23823
|
import { readdirSync as readdirSync5, statSync as statSync7, mkdirSync as mkdirSync9, writeFileSync as writeFileSync6, existsSync as existsSync10 } from "node:fs";
|
|
23774
23824
|
import { join as join13, relative, basename as basename3, extname as extname2 } from "node:path";
|
|
23825
|
+
import { pathToFileURL as pathToFileURL3 } from "node:url";
|
|
23775
23826
|
function boolExport(value) {
|
|
23776
23827
|
return typeof value === "boolean" ? value : void 0;
|
|
23777
23828
|
}
|
|
@@ -23793,7 +23844,7 @@ async function discoverRoutes(routesDir) {
|
|
|
23793
23844
|
const relativePath2 = relative(routesDir, filePath);
|
|
23794
23845
|
const pattern = filePathToPattern(relativePath2);
|
|
23795
23846
|
try {
|
|
23796
|
-
const moduleUrl =
|
|
23847
|
+
const moduleUrl = `${pathToFileURL3(filePath).href}?t=${currentMtime}`;
|
|
23797
23848
|
const mod = await import(moduleUrl);
|
|
23798
23849
|
const handler = mod.default ?? mod.handler;
|
|
23799
23850
|
if (typeof handler !== "function") {
|
|
@@ -23834,7 +23885,7 @@ function recordBrokenImport(filePath, error2) {
|
|
|
23834
23885
|
try {
|
|
23835
23886
|
const brokenDir = join13(process.cwd(), "data", ".broken");
|
|
23836
23887
|
if (!existsSync10(brokenDir)) mkdirSync9(brokenDir, { recursive: true });
|
|
23837
|
-
const slug = filePath.replace(/[
|
|
23888
|
+
const slug = filePath.replace(/[/\\:]/g, "_");
|
|
23838
23889
|
const payload = JSON.stringify({
|
|
23839
23890
|
type: "auto_discover_failure",
|
|
23840
23891
|
file: filePath,
|
|
@@ -23901,6 +23952,7 @@ __export(portTakeover_exports, {
|
|
|
23901
23952
|
isDev: () => isDev,
|
|
23902
23953
|
noTakeoverOptedOut: () => noTakeoverOptedOut,
|
|
23903
23954
|
pidfilePath: () => pidfilePath,
|
|
23955
|
+
probeBind: () => probeBind,
|
|
23904
23956
|
readPidfile: () => readPidfile,
|
|
23905
23957
|
removePidfile: () => removePidfile,
|
|
23906
23958
|
runtimeDir: () => runtimeDir,
|
|
@@ -23994,27 +24046,33 @@ function sleepSync(ms) {
|
|
|
23994
24046
|
if (ms <= 0) return;
|
|
23995
24047
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
23996
24048
|
}
|
|
23997
|
-
function
|
|
24049
|
+
function probeBind(host, port, timeout = 5e3) {
|
|
24050
|
+
try {
|
|
24051
|
+
execFileSync(process.execPath, ["-e", BIND_PROBE, host, String(port)], { stdio: "ignore", timeout });
|
|
24052
|
+
return "free";
|
|
24053
|
+
} catch (err) {
|
|
24054
|
+
return err.status === PROBE_HELD ? "held" : "unknown";
|
|
24055
|
+
}
|
|
24056
|
+
}
|
|
24057
|
+
function refusal(port, dev, noTakeover, host) {
|
|
24058
|
+
if (dev && !noTakeover) return null;
|
|
24059
|
+
if (host !== void 0 && probeBind(host, port) !== "held") {
|
|
24060
|
+
return { status: TAKEOVER_NOTHING, port, killed: [], message: "" };
|
|
24061
|
+
}
|
|
24062
|
+
if (noTakeover) {
|
|
24063
|
+
return { status: TAKEOVER_REFUSED_OPTOUT, port, killed: [], message: `Port ${port} is in use and takeover is disabled (TINA4_NO_TAKEOVER/--no-kill) -- free it or choose another port.` };
|
|
24064
|
+
}
|
|
24065
|
+
return { status: TAKEOVER_REFUSED_PROD, port, killed: [], message: `Port ${port} is in use; takeover is disabled outside dev mode -- free it or choose another port.` };
|
|
24066
|
+
}
|
|
24067
|
+
function takeOverPort(port, dev, noTakeover, baseDir, grace = 500, host) {
|
|
23998
24068
|
const make = (status2, killed2 = [], message = "") => ({
|
|
23999
24069
|
status: status2,
|
|
24000
24070
|
port,
|
|
24001
24071
|
killed: killed2,
|
|
24002
24072
|
message
|
|
24003
24073
|
});
|
|
24004
|
-
|
|
24005
|
-
|
|
24006
|
-
TAKEOVER_REFUSED_OPTOUT,
|
|
24007
|
-
[],
|
|
24008
|
-
`Port ${port} is in use and takeover is disabled (TINA4_NO_TAKEOVER/--no-kill) -- free it or choose another port.`
|
|
24009
|
-
);
|
|
24010
|
-
}
|
|
24011
|
-
if (!dev) {
|
|
24012
|
-
return make(
|
|
24013
|
-
TAKEOVER_REFUSED_PROD,
|
|
24014
|
-
[],
|
|
24015
|
-
`Port ${port} is in use; takeover is disabled outside dev mode -- free it or choose another port.`
|
|
24016
|
-
);
|
|
24017
|
-
}
|
|
24074
|
+
const early = refusal(port, dev, noTakeover, host);
|
|
24075
|
+
if (early !== null) return early;
|
|
24018
24076
|
if (inContainer()) return make(TAKEOVER_SKIPPED_CONTAINER);
|
|
24019
24077
|
const tokens = portHolders(port);
|
|
24020
24078
|
if (tokens.length === 0) return make(TAKEOVER_NOTHING);
|
|
@@ -24046,7 +24104,7 @@ function takeOverPort(port, dev, noTakeover, baseDir, grace = 500) {
|
|
|
24046
24104
|
`Reclaimed port ${port} from Tina4 dev server (PID: ${killed.join(", ")}).`
|
|
24047
24105
|
);
|
|
24048
24106
|
}
|
|
24049
|
-
var TAKEOVER_NOTHING, TAKEOVER_KILLED, TAKEOVER_REFUSED_FOREIGN, TAKEOVER_REFUSED_OPTOUT, TAKEOVER_REFUSED_PROD, TAKEOVER_SKIPPED_CONTAINER, TAKEOVER_REFUSALS;
|
|
24107
|
+
var TAKEOVER_NOTHING, TAKEOVER_KILLED, TAKEOVER_REFUSED_FOREIGN, TAKEOVER_REFUSED_OPTOUT, TAKEOVER_REFUSED_PROD, TAKEOVER_SKIPPED_CONTAINER, TAKEOVER_REFUSALS, PROBE_HELD, PROBE_OTHER, BIND_PROBE;
|
|
24050
24108
|
var init_portTakeover = __esm({
|
|
24051
24109
|
"../core/src/portTakeover.ts"() {
|
|
24052
24110
|
"use strict";
|
|
@@ -24061,6 +24119,9 @@ var init_portTakeover = __esm({
|
|
|
24061
24119
|
TAKEOVER_REFUSED_OPTOUT,
|
|
24062
24120
|
TAKEOVER_REFUSED_PROD
|
|
24063
24121
|
];
|
|
24122
|
+
PROBE_HELD = 3;
|
|
24123
|
+
PROBE_OTHER = 4;
|
|
24124
|
+
BIND_PROBE = `const s = require("node:net").createServer();s.on("error", (e) => process.exit(e && e.code === "EADDRINUSE" ? ${PROBE_HELD} : ${PROBE_OTHER}));s.listen({ host: process.argv[1], port: Number(process.argv[2]) }, () => s.close(() => process.exit(0)));`;
|
|
24064
24125
|
}
|
|
24065
24126
|
});
|
|
24066
24127
|
|
|
@@ -25238,6 +25299,21 @@ var init_databaseHandler = __esm({
|
|
|
25238
25299
|
}
|
|
25239
25300
|
return this.sqliteHandle;
|
|
25240
25301
|
}
|
|
25302
|
+
/**
|
|
25303
|
+
* Release the SQLite connection this handler opened, so its file (and the
|
|
25304
|
+
* WAL's -wal / -shm side files) is no longer held open: on Windows an open
|
|
25305
|
+
* file cannot be deleted or replaced. Idempotent, and the next read or write
|
|
25306
|
+
* reopens the connection. A server engine needs nothing here - each call goes
|
|
25307
|
+
* through the sync bridge, which holds no connection between calls.
|
|
25308
|
+
*/
|
|
25309
|
+
close() {
|
|
25310
|
+
if (this.sqliteHandle === null) return;
|
|
25311
|
+
try {
|
|
25312
|
+
this.sqliteHandle.close();
|
|
25313
|
+
} finally {
|
|
25314
|
+
this.sqliteHandle = null;
|
|
25315
|
+
}
|
|
25316
|
+
}
|
|
25241
25317
|
get engine() {
|
|
25242
25318
|
return this.target === null ? "sqlite" : this.target.engine;
|
|
25243
25319
|
}
|
|
@@ -26438,8 +26514,8 @@ function tryServeStatic(staticDir, req2, res) {
|
|
|
26438
26514
|
}
|
|
26439
26515
|
return false;
|
|
26440
26516
|
}
|
|
26441
|
-
function hasHiddenSegment(
|
|
26442
|
-
return
|
|
26517
|
+
function hasHiddenSegment(path9, separator = "/") {
|
|
26518
|
+
return path9.split(separator).some((segment) => segment.length > 0 && segment.startsWith("."));
|
|
26443
26519
|
}
|
|
26444
26520
|
function conditionalHeader(req2, name) {
|
|
26445
26521
|
const headers = req2.headers;
|
|
@@ -26763,10 +26839,10 @@ function createHealthRoute(version = "3.0.0") {
|
|
|
26763
26839
|
function createHealthRoutes(version = "3.0.0") {
|
|
26764
26840
|
startTime = Date.now();
|
|
26765
26841
|
const routes = [];
|
|
26766
|
-
const
|
|
26842
|
+
const path9 = healthPath();
|
|
26767
26843
|
routes.push({
|
|
26768
26844
|
method: "GET",
|
|
26769
|
-
pattern:
|
|
26845
|
+
pattern: path9,
|
|
26770
26846
|
handler: buildHandler(version),
|
|
26771
26847
|
meta: {
|
|
26772
26848
|
summary: "Health check",
|
|
@@ -26774,7 +26850,7 @@ function createHealthRoutes(version = "3.0.0") {
|
|
|
26774
26850
|
tags: ["System"]
|
|
26775
26851
|
}
|
|
26776
26852
|
});
|
|
26777
|
-
if (
|
|
26853
|
+
if (path9 !== "/health") {
|
|
26778
26854
|
routes.push({
|
|
26779
26855
|
method: "GET",
|
|
26780
26856
|
pattern: "/health",
|
|
@@ -26852,9 +26928,72 @@ var init_rateLimiter = __esm({
|
|
|
26852
26928
|
}
|
|
26853
26929
|
});
|
|
26854
26930
|
|
|
26931
|
+
// ../core/src/batchSpawn.ts
|
|
26932
|
+
import { spawnSync } from "node:child_process";
|
|
26933
|
+
import { existsSync as existsSync13, statSync as statSync10 } from "node:fs";
|
|
26934
|
+
import { delimiter, extname as extname4, join as join17 } from "node:path";
|
|
26935
|
+
function isBatchFile(file, platform = process.platform) {
|
|
26936
|
+
return platform === "win32" && /\.(cmd|bat)$/i.test(file);
|
|
26937
|
+
}
|
|
26938
|
+
function escapeBatchArgument(arg) {
|
|
26939
|
+
let quoted = String(arg).replace(/(\\*)"/g, '$1$1\\"').replace(/(\\*)$/, "$1$1");
|
|
26940
|
+
quoted = `"${quoted}"`;
|
|
26941
|
+
return quoted.replace(CMD_META, "^$1").replace(CMD_META, "^$1");
|
|
26942
|
+
}
|
|
26943
|
+
function escapeBatchCommand(file) {
|
|
26944
|
+
return file.replace(CMD_META, "^$1");
|
|
26945
|
+
}
|
|
26946
|
+
function findExecutable(name, platform = process.platform) {
|
|
26947
|
+
if (platform !== "win32" || /[\\/]/.test(name) || extname4(name) !== "") return name;
|
|
26948
|
+
const exts = (process.env.PATHEXT || ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean);
|
|
26949
|
+
const dirs = (process.env.PATH || "").split(delimiter).filter(Boolean);
|
|
26950
|
+
const candidates = dirs.flatMap((dir) => exts.map((ext) => join17(dir, name + ext.toLowerCase())));
|
|
26951
|
+
return candidates.find(isRegularFile) ?? name;
|
|
26952
|
+
}
|
|
26953
|
+
function isRegularFile(path9) {
|
|
26954
|
+
try {
|
|
26955
|
+
return existsSync13(path9) && statSync10(path9).isFile();
|
|
26956
|
+
} catch {
|
|
26957
|
+
return false;
|
|
26958
|
+
}
|
|
26959
|
+
}
|
|
26960
|
+
function spawnSyncAllowingBatch(file, args, options = {}) {
|
|
26961
|
+
if (!isBatchFile(file)) return spawnSync(file, args, options);
|
|
26962
|
+
const line = [escapeBatchCommand(file), ...args.map(escapeBatchArgument)].join(" ");
|
|
26963
|
+
const shell = process.env.comspec || "cmd.exe";
|
|
26964
|
+
return spawnSync(shell, ["/d", "/s", "/c", `"${line}"`], {
|
|
26965
|
+
...options,
|
|
26966
|
+
windowsVerbatimArguments: true
|
|
26967
|
+
});
|
|
26968
|
+
}
|
|
26969
|
+
function execFileSyncAllowingBatch(name, args, options = {}) {
|
|
26970
|
+
const result = spawnSyncAllowingBatch(findExecutable(name), args, { encoding: "utf-8", ...options });
|
|
26971
|
+
if (result.error) throw result.error;
|
|
26972
|
+
const stdout = String(result.stdout ?? "");
|
|
26973
|
+
const stderr = String(result.stderr ?? "");
|
|
26974
|
+
if (result.status !== 0) {
|
|
26975
|
+
const err = new Error(
|
|
26976
|
+
`Command failed: ${name} ${args.join(" ")} (exit ${result.status ?? result.signal})
|
|
26977
|
+
${stderr}`.trim()
|
|
26978
|
+
);
|
|
26979
|
+
err.status = result.status;
|
|
26980
|
+
err.stdout = stdout;
|
|
26981
|
+
err.stderr = stderr;
|
|
26982
|
+
throw err;
|
|
26983
|
+
}
|
|
26984
|
+
return stdout;
|
|
26985
|
+
}
|
|
26986
|
+
var CMD_META;
|
|
26987
|
+
var init_batchSpawn = __esm({
|
|
26988
|
+
"../core/src/batchSpawn.ts"() {
|
|
26989
|
+
"use strict";
|
|
26990
|
+
CMD_META = /([()\][%!^"`<>&|;, *?])/g;
|
|
26991
|
+
}
|
|
26992
|
+
});
|
|
26993
|
+
|
|
26855
26994
|
// ../core/src/devMailbox.ts
|
|
26856
|
-
import { mkdirSync as mkdirSync12, readdirSync as readdirSync7, readFileSync as readFileSync11, writeFileSync as writeFileSync9, unlinkSync as unlinkSync7, existsSync as
|
|
26857
|
-
import { join as
|
|
26995
|
+
import { mkdirSync as mkdirSync12, readdirSync as readdirSync7, readFileSync as readFileSync11, writeFileSync as writeFileSync9, unlinkSync as unlinkSync7, existsSync as existsSync14 } from "node:fs";
|
|
26996
|
+
import { join as join18 } from "node:path";
|
|
26858
26997
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
26859
26998
|
var DevMailbox;
|
|
26860
26999
|
var init_devMailbox = __esm({
|
|
@@ -26869,7 +27008,7 @@ var init_devMailbox = __esm({
|
|
|
26869
27008
|
* Ensure a folder directory exists.
|
|
26870
27009
|
*/
|
|
26871
27010
|
ensureFolder(folder) {
|
|
26872
|
-
const dir =
|
|
27011
|
+
const dir = join18(this.mailboxDir, folder);
|
|
26873
27012
|
mkdirSync12(dir, { recursive: true });
|
|
26874
27013
|
return dir;
|
|
26875
27014
|
}
|
|
@@ -26908,10 +27047,10 @@ var init_devMailbox = __esm({
|
|
|
26908
27047
|
read: false
|
|
26909
27048
|
};
|
|
26910
27049
|
const outboxDir = this.ensureFolder("outbox");
|
|
26911
|
-
writeFileSync9(
|
|
27050
|
+
writeFileSync9(join18(outboxDir, `${id}.json`), JSON.stringify(message, null, 2));
|
|
26912
27051
|
const inboxDir = this.ensureFolder("inbox");
|
|
26913
27052
|
const inboxMessage = { ...message, type: "inbox" };
|
|
26914
|
-
writeFileSync9(
|
|
27053
|
+
writeFileSync9(join18(inboxDir, `${id}.json`), JSON.stringify(inboxMessage, null, 2));
|
|
26915
27054
|
return { success: true, message: "Email captured to dev mailbox", id };
|
|
26916
27055
|
}
|
|
26917
27056
|
/**
|
|
@@ -26929,7 +27068,7 @@ var init_devMailbox = __esm({
|
|
|
26929
27068
|
const sliced = files.slice(offset, offset + limit);
|
|
26930
27069
|
for (const file of sliced) {
|
|
26931
27070
|
try {
|
|
26932
|
-
const msg = JSON.parse(readFileSync11(
|
|
27071
|
+
const msg = JSON.parse(readFileSync11(join18(dir, file), "utf-8"));
|
|
26933
27072
|
results.push(msg);
|
|
26934
27073
|
} catch {
|
|
26935
27074
|
}
|
|
@@ -26942,8 +27081,8 @@ var init_devMailbox = __esm({
|
|
|
26942
27081
|
read(msgId) {
|
|
26943
27082
|
const folders = ["inbox", "outbox"];
|
|
26944
27083
|
for (const folder of folders) {
|
|
26945
|
-
const filePath =
|
|
26946
|
-
if (
|
|
27084
|
+
const filePath = join18(this.mailboxDir, folder, `${msgId}.json`);
|
|
27085
|
+
if (existsSync14(filePath)) {
|
|
26947
27086
|
try {
|
|
26948
27087
|
const msg = JSON.parse(readFileSync11(filePath, "utf-8"));
|
|
26949
27088
|
msg.read = true;
|
|
@@ -26966,7 +27105,7 @@ var init_devMailbox = __esm({
|
|
|
26966
27105
|
const files = readdirSync7(dir).filter((f) => f.endsWith(".json"));
|
|
26967
27106
|
for (const file of files) {
|
|
26968
27107
|
try {
|
|
26969
|
-
const msg = JSON.parse(readFileSync11(
|
|
27108
|
+
const msg = JSON.parse(readFileSync11(join18(dir, file), "utf-8"));
|
|
26970
27109
|
if (!msg.read) count++;
|
|
26971
27110
|
} catch {
|
|
26972
27111
|
}
|
|
@@ -26982,8 +27121,8 @@ var init_devMailbox = __esm({
|
|
|
26982
27121
|
let deleted = false;
|
|
26983
27122
|
const folders = ["inbox", "outbox"];
|
|
26984
27123
|
for (const folder of folders) {
|
|
26985
|
-
const filePath =
|
|
26986
|
-
if (
|
|
27124
|
+
const filePath = join18(this.mailboxDir, folder, `${msgId}.json`);
|
|
27125
|
+
if (existsSync14(filePath)) {
|
|
26987
27126
|
try {
|
|
26988
27127
|
unlinkSync7(filePath);
|
|
26989
27128
|
deleted = true;
|
|
@@ -26999,12 +27138,12 @@ var init_devMailbox = __esm({
|
|
|
26999
27138
|
clear(folder) {
|
|
27000
27139
|
const folders = folder ? [folder] : ["inbox", "outbox"];
|
|
27001
27140
|
for (const f of folders) {
|
|
27002
|
-
const dir =
|
|
27141
|
+
const dir = join18(this.mailboxDir, f);
|
|
27003
27142
|
try {
|
|
27004
|
-
if (
|
|
27143
|
+
if (existsSync14(dir)) {
|
|
27005
27144
|
const files = readdirSync7(dir).filter((file) => file.endsWith(".json"));
|
|
27006
27145
|
for (const file of files) {
|
|
27007
|
-
unlinkSync7(
|
|
27146
|
+
unlinkSync7(join18(dir, file));
|
|
27008
27147
|
}
|
|
27009
27148
|
}
|
|
27010
27149
|
} catch {
|
|
@@ -27057,7 +27196,7 @@ Generated by DevMailbox.seed() for development purposes.`,
|
|
|
27057
27196
|
// first two are unread
|
|
27058
27197
|
};
|
|
27059
27198
|
const dir = this.ensureFolder("inbox");
|
|
27060
|
-
writeFileSync9(
|
|
27199
|
+
writeFileSync9(join18(dir, `${id}.json`), JSON.stringify(message, null, 2));
|
|
27061
27200
|
}
|
|
27062
27201
|
}
|
|
27063
27202
|
/**
|
|
@@ -27065,9 +27204,9 @@ Generated by DevMailbox.seed() for development purposes.`,
|
|
|
27065
27204
|
*/
|
|
27066
27205
|
count(folder) {
|
|
27067
27206
|
const countDir = (f) => {
|
|
27068
|
-
const dir =
|
|
27207
|
+
const dir = join18(this.mailboxDir, f);
|
|
27069
27208
|
try {
|
|
27070
|
-
if (
|
|
27209
|
+
if (existsSync14(dir)) {
|
|
27071
27210
|
return readdirSync7(dir).filter((file) => file.endsWith(".json")).length;
|
|
27072
27211
|
}
|
|
27073
27212
|
} catch {
|
|
@@ -27108,8 +27247,8 @@ var init_upstreamResponse = __esm({
|
|
|
27108
27247
|
// ../core/src/metrics.ts
|
|
27109
27248
|
import * as fs3 from "node:fs";
|
|
27110
27249
|
import * as path2 from "node:path";
|
|
27111
|
-
import { spawnSync } from "node:child_process";
|
|
27112
|
-
import { fileURLToPath as
|
|
27250
|
+
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
27251
|
+
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
27113
27252
|
function containsTypeScript(directory) {
|
|
27114
27253
|
if (!fs3.existsSync(directory) || !fs3.statSync(directory).isDirectory()) return false;
|
|
27115
27254
|
for (const entry of fs3.readdirSync(directory, { withFileTypes: true })) {
|
|
@@ -27120,7 +27259,7 @@ function containsTypeScript(directory) {
|
|
|
27120
27259
|
return false;
|
|
27121
27260
|
}
|
|
27122
27261
|
function resolveTarget(root = "src") {
|
|
27123
|
-
const resolved = containsTypeScript(root) ? path2.resolve(root) : path2.dirname(
|
|
27262
|
+
const resolved = containsTypeScript(root) ? path2.resolve(root) : path2.dirname(fileURLToPath4(import.meta.url));
|
|
27124
27263
|
const mode = containsTypeScript(root) ? "project" : "framework";
|
|
27125
27264
|
lastScanRoot = resolved;
|
|
27126
27265
|
return [resolved, mode];
|
|
@@ -27148,7 +27287,7 @@ function enginePath() {
|
|
|
27148
27287
|
function runEngine(target) {
|
|
27149
27288
|
const binary = enginePath();
|
|
27150
27289
|
if (!binary) throw new MetricsEngineError(`tina4 not found on PATH - ${INSTALL_HINT}`);
|
|
27151
|
-
const processResult =
|
|
27290
|
+
const processResult = spawnSync2(binary, ["metrics", "--path", target, "--json", "--no-history"], {
|
|
27152
27291
|
encoding: "utf8",
|
|
27153
27292
|
timeout: 6e4,
|
|
27154
27293
|
maxBuffer: 64 * 1024 * 1024
|
|
@@ -27241,9 +27380,9 @@ var init_metrics = __esm({
|
|
|
27241
27380
|
});
|
|
27242
27381
|
|
|
27243
27382
|
// ../core/src/feedback.ts
|
|
27244
|
-
import { readFileSync as readFileSync12, existsSync as
|
|
27245
|
-
import { dirname as dirname9, join as
|
|
27246
|
-
import { fileURLToPath as
|
|
27383
|
+
import { readFileSync as readFileSync12, existsSync as existsSync16 } from "node:fs";
|
|
27384
|
+
import { dirname as dirname9, join as join20, resolve as resolve10 } from "node:path";
|
|
27385
|
+
import { fileURLToPath as fileURLToPath5 } from "node:url";
|
|
27247
27386
|
function feedbackEnabled() {
|
|
27248
27387
|
const raw = (process.env.TINA4_ENABLE_FEEDBACK ?? "").trim().toLowerCase();
|
|
27249
27388
|
return raw === "1" || raw === "true" || raw === "yes" || raw === "on";
|
|
@@ -27292,8 +27431,8 @@ function feedbackRateLimitOk(user) {
|
|
|
27292
27431
|
}
|
|
27293
27432
|
function injectFeedbackWidget(request, html) {
|
|
27294
27433
|
if (!html) return html;
|
|
27295
|
-
const
|
|
27296
|
-
if (
|
|
27434
|
+
const path9 = (request.path ?? "") || "";
|
|
27435
|
+
if (path9.startsWith("/__dev") || path9.startsWith("/__feedback")) return html;
|
|
27297
27436
|
if (html.includes("data-tina4-feedback")) return html;
|
|
27298
27437
|
const [allowed] = feedbackIsWhitelisted(request);
|
|
27299
27438
|
if (!allowed) return html;
|
|
@@ -27369,11 +27508,11 @@ var init_feedback = __esm({
|
|
|
27369
27508
|
clearTimeout(timer);
|
|
27370
27509
|
await relayUpstreamResponse(res, upstream);
|
|
27371
27510
|
};
|
|
27372
|
-
__feedbackDirname = dirname9(
|
|
27511
|
+
__feedbackDirname = dirname9(fileURLToPath5(import.meta.url));
|
|
27373
27512
|
WIDGET_BUNDLE_PATH = resolve10(__feedbackDirname, "__feedback", "widget.js");
|
|
27374
27513
|
handleFeedbackWidgetJs = (_req, res) => {
|
|
27375
27514
|
let body;
|
|
27376
|
-
if (
|
|
27515
|
+
if (existsSync16(WIDGET_BUNDLE_PATH)) {
|
|
27377
27516
|
body = readFileSync12(WIDGET_BUNDLE_PATH);
|
|
27378
27517
|
} else {
|
|
27379
27518
|
body = "console.warn('tina4-feedback-widget bundle not built yet');";
|
|
@@ -27389,14 +27528,14 @@ var init_feedback = __esm({
|
|
|
27389
27528
|
});
|
|
27390
27529
|
|
|
27391
27530
|
// ../core/src/version.ts
|
|
27392
|
-
import { existsSync as
|
|
27393
|
-
import { dirname as dirname10, join as
|
|
27394
|
-
import { fileURLToPath as
|
|
27531
|
+
import { existsSync as existsSync17, readFileSync as readFileSync13 } from "node:fs";
|
|
27532
|
+
import { dirname as dirname10, join as join21 } from "node:path";
|
|
27533
|
+
import { fileURLToPath as fileURLToPath6 } from "node:url";
|
|
27395
27534
|
function resolveFrameworkVersion() {
|
|
27396
|
-
let dir = dirname10(
|
|
27535
|
+
let dir = dirname10(fileURLToPath6(import.meta.url));
|
|
27397
27536
|
for (let i = 0; i < 6; i++) {
|
|
27398
|
-
const pkgPath =
|
|
27399
|
-
if (
|
|
27537
|
+
const pkgPath = join21(dir, "package.json");
|
|
27538
|
+
if (existsSync17(pkgPath)) {
|
|
27400
27539
|
try {
|
|
27401
27540
|
const pkg = JSON.parse(readFileSync13(pkgPath, "utf-8"));
|
|
27402
27541
|
if (typeof pkg.version === "string" && pkg.version) return pkg.version;
|
|
@@ -27418,8 +27557,8 @@ var init_version = __esm({
|
|
|
27418
27557
|
});
|
|
27419
27558
|
|
|
27420
27559
|
// src/util.ts
|
|
27421
|
-
import { delimiter as
|
|
27422
|
-
import { statSync as
|
|
27560
|
+
import { delimiter as delimiter3, join as join22 } from "node:path";
|
|
27561
|
+
import { statSync as statSync12 } from "node:fs";
|
|
27423
27562
|
function parseFlags(args, booleanFlags) {
|
|
27424
27563
|
const flags = {};
|
|
27425
27564
|
const positional = [];
|
|
@@ -27451,12 +27590,12 @@ function readFlag(args, i, flags, booleanFlags) {
|
|
|
27451
27590
|
return 1;
|
|
27452
27591
|
}
|
|
27453
27592
|
function findOnPath(names) {
|
|
27454
|
-
for (const dir of (process.env.PATH ?? "").split(
|
|
27593
|
+
for (const dir of (process.env.PATH ?? "").split(delimiter3)) {
|
|
27455
27594
|
if (!dir) continue;
|
|
27456
27595
|
for (const name of names) {
|
|
27457
|
-
const candidate =
|
|
27596
|
+
const candidate = join22(dir, name);
|
|
27458
27597
|
try {
|
|
27459
|
-
if (
|
|
27598
|
+
if (statSync12(candidate).isFile()) return candidate;
|
|
27460
27599
|
} catch {
|
|
27461
27600
|
}
|
|
27462
27601
|
}
|
|
@@ -27501,27 +27640,27 @@ __export(generate_exports, {
|
|
|
27501
27640
|
toSnake: () => toSnake,
|
|
27502
27641
|
toTableName: () => toTableName
|
|
27503
27642
|
});
|
|
27504
|
-
import { existsSync as
|
|
27505
|
-
import { join as
|
|
27506
|
-
import { fileURLToPath as
|
|
27643
|
+
import { existsSync as existsSync18, mkdirSync as mkdirSync13, writeFileSync as writeFileSync10, readdirSync as readdirSync9, copyFileSync as copyFileSync2 } from "node:fs";
|
|
27644
|
+
import { join as join23, relative as relative2, resolve as resolve11, sep as sep5, dirname as dirname11 } from "node:path";
|
|
27645
|
+
import { fileURLToPath as fileURLToPath7 } from "node:url";
|
|
27507
27646
|
function ensureDir(dir) {
|
|
27508
27647
|
if (__resolution.dryRun) return;
|
|
27509
|
-
if (!
|
|
27648
|
+
if (!existsSync18(dir)) {
|
|
27510
27649
|
mkdirSync13(dir, { recursive: true });
|
|
27511
27650
|
}
|
|
27512
27651
|
}
|
|
27513
|
-
function writeFileSafe(
|
|
27514
|
-
captureEditHints(
|
|
27652
|
+
function writeFileSafe(path9, content) {
|
|
27653
|
+
captureEditHints(path9, content);
|
|
27515
27654
|
if (__resolution.dryRun) {
|
|
27516
27655
|
return;
|
|
27517
27656
|
}
|
|
27518
|
-
if (
|
|
27519
|
-
if (!__resolution.jsonMode) console.log(` File already exists: ${
|
|
27657
|
+
if (existsSync18(path9)) {
|
|
27658
|
+
if (!__resolution.jsonMode) console.log(` File already exists: ${path9}`);
|
|
27520
27659
|
return;
|
|
27521
27660
|
}
|
|
27522
|
-
writeFileSync10(
|
|
27523
|
-
__resolution.actionsTaken.push(`wrote ${
|
|
27524
|
-
if (!__resolution.jsonMode) console.log(` Created ${
|
|
27661
|
+
writeFileSync10(path9, content, "utf-8");
|
|
27662
|
+
__resolution.actionsTaken.push(`wrote ${path9}`);
|
|
27663
|
+
if (!__resolution.jsonMode) console.log(` Created ${path9}`);
|
|
27525
27664
|
}
|
|
27526
27665
|
function toSnake(name) {
|
|
27527
27666
|
return name.replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2").replace(/([a-z0-9])([A-Z])/g, "$1_$2").toLowerCase();
|
|
@@ -27613,9 +27752,9 @@ function pushRoute(routePattern) {
|
|
|
27613
27752
|
if (!__resolution.body.routes) __resolution.body.routes = [];
|
|
27614
27753
|
__resolution.body.routes.push(routePattern);
|
|
27615
27754
|
}
|
|
27616
|
-
function pushTestPath(
|
|
27755
|
+
function pushTestPath(path9) {
|
|
27617
27756
|
if (!__resolution.body.test_paths) __resolution.body.test_paths = [];
|
|
27618
|
-
__resolution.body.test_paths.push(
|
|
27757
|
+
__resolution.body.test_paths.push(path9);
|
|
27619
27758
|
}
|
|
27620
27759
|
function pushEditHint(hint) {
|
|
27621
27760
|
if (!__resolution.body.edit_hints) __resolution.body.edit_hints = [];
|
|
@@ -27846,7 +27985,7 @@ function generateModel(name, flags, emitTest = true) {
|
|
|
27846
27985
|
const table2 = resolveTable(name, flags, { announce: true });
|
|
27847
27986
|
const dir = resolve11("src/models");
|
|
27848
27987
|
ensureDir(dir);
|
|
27849
|
-
const
|
|
27988
|
+
const path9 = join23(dir, `${name}.ts`);
|
|
27850
27989
|
setResolutionField("class_name", name);
|
|
27851
27990
|
setResolutionField("table_name", table2);
|
|
27852
27991
|
setResolutionField("file_path", `src/models/${name}.ts`);
|
|
@@ -27869,7 +28008,7 @@ ${fieldLines.join("\n")}
|
|
|
27869
28008
|
};
|
|
27870
28009
|
}
|
|
27871
28010
|
`;
|
|
27872
|
-
writeFileSafe(
|
|
28011
|
+
writeFileSafe(path9, content);
|
|
27873
28012
|
if (!flags["no-migration"]) {
|
|
27874
28013
|
generateMigration(`create_${table2}`, flags, fields, table2, false);
|
|
27875
28014
|
}
|
|
@@ -27886,7 +28025,7 @@ function generateRoute(name, flags, emitTest = true) {
|
|
|
27886
28025
|
const model = flags.model;
|
|
27887
28026
|
const isPublic = Boolean(flags.public);
|
|
27888
28027
|
const base = resolve11("src/routes/api", routePath);
|
|
27889
|
-
const idDir =
|
|
28028
|
+
const idDir = join23(base, "[id]");
|
|
27890
28029
|
ensureDir(base);
|
|
27891
28030
|
ensureDir(idDir);
|
|
27892
28031
|
pushRoute(`/api/${routePath}`);
|
|
@@ -27902,7 +28041,7 @@ function generateRoute(name, flags, emitTest = true) {
|
|
|
27902
28041
|
const writeDoc = isPublic ? "Public (--public): no token required." : "Secure by default: requires a Bearer token (use --public to open).";
|
|
27903
28042
|
if (model) {
|
|
27904
28043
|
writeFileSafe(
|
|
27905
|
-
|
|
28044
|
+
join23(base, "get.ts"),
|
|
27906
28045
|
`import type { Tina4Request, Tina4Response } from "tina4-nodejs";
|
|
27907
28046
|
${modelImportBase}
|
|
27908
28047
|
export const meta = { summary: "List all ${routePath}", tags: ["${routePath}"] };
|
|
@@ -27919,7 +28058,7 @@ export default async function (req: Tina4Request, res: Tina4Response) {
|
|
|
27919
28058
|
);
|
|
27920
28059
|
} else {
|
|
27921
28060
|
writeFileSafe(
|
|
27922
|
-
|
|
28061
|
+
join23(base, "get.ts"),
|
|
27923
28062
|
`import type { Tina4Request, Tina4Response } from "tina4-nodejs";
|
|
27924
28063
|
|
|
27925
28064
|
export const meta = { summary: "List all ${routePath}", tags: ["${routePath}"] };
|
|
@@ -27938,7 +28077,7 @@ ${aiFill(`list_${routePath}`, {
|
|
|
27938
28077
|
}
|
|
27939
28078
|
if (model) {
|
|
27940
28079
|
writeFileSafe(
|
|
27941
|
-
|
|
28080
|
+
join23(base, "post.ts"),
|
|
27942
28081
|
`import type { Tina4Request, Tina4Response } from "tina4-nodejs";
|
|
27943
28082
|
${modelImportBase}${secureOptOut(isPublic)}export const meta = { summary: "Create a new ${singular}", tags: ["${routePath}"] };
|
|
27944
28083
|
|
|
@@ -27961,7 +28100,7 @@ ${extend(
|
|
|
27961
28100
|
);
|
|
27962
28101
|
} else {
|
|
27963
28102
|
writeFileSafe(
|
|
27964
|
-
|
|
28103
|
+
join23(base, "post.ts"),
|
|
27965
28104
|
`import type { Tina4Request, Tina4Response } from "tina4-nodejs";
|
|
27966
28105
|
|
|
27967
28106
|
${secureOptOut(isPublic)}export const meta = { summary: "Create a new ${singular}", tags: ["${routePath}"] };
|
|
@@ -27982,7 +28121,7 @@ ${aiFill(`create_${singular}`, {
|
|
|
27982
28121
|
}
|
|
27983
28122
|
if (model) {
|
|
27984
28123
|
writeFileSafe(
|
|
27985
|
-
|
|
28124
|
+
join23(idDir, "get.ts"),
|
|
27986
28125
|
`import type { Tina4Request, Tina4Response } from "tina4-nodejs";
|
|
27987
28126
|
${modelImportId}
|
|
27988
28127
|
export const meta = { summary: "Get a ${singular} by ID", tags: ["${routePath}"] };
|
|
@@ -28000,7 +28139,7 @@ export default async function (req: Tina4Request, res: Tina4Response) {
|
|
|
28000
28139
|
);
|
|
28001
28140
|
} else {
|
|
28002
28141
|
writeFileSafe(
|
|
28003
|
-
|
|
28142
|
+
join23(idDir, "get.ts"),
|
|
28004
28143
|
`import type { Tina4Request, Tina4Response } from "tina4-nodejs";
|
|
28005
28144
|
|
|
28006
28145
|
export const meta = { summary: "Get a ${singular} by ID", tags: ["${routePath}"] };
|
|
@@ -28019,7 +28158,7 @@ ${aiFill(`get_${singular}`, {
|
|
|
28019
28158
|
}
|
|
28020
28159
|
if (model) {
|
|
28021
28160
|
writeFileSafe(
|
|
28022
|
-
|
|
28161
|
+
join23(idDir, "put.ts"),
|
|
28023
28162
|
`import type { Tina4Request, Tina4Response } from "tina4-nodejs";
|
|
28024
28163
|
${modelImportId}${secureOptOut(isPublic)}export const meta = { summary: "Update a ${singular} by ID", tags: ["${routePath}"] };
|
|
28025
28164
|
|
|
@@ -28048,7 +28187,7 @@ ${extend(
|
|
|
28048
28187
|
);
|
|
28049
28188
|
} else {
|
|
28050
28189
|
writeFileSafe(
|
|
28051
|
-
|
|
28190
|
+
join23(idDir, "put.ts"),
|
|
28052
28191
|
`import type { Tina4Request, Tina4Response } from "tina4-nodejs";
|
|
28053
28192
|
|
|
28054
28193
|
${secureOptOut(isPublic)}export const meta = { summary: "Update a ${singular} by ID", tags: ["${routePath}"] };
|
|
@@ -28069,7 +28208,7 @@ ${aiFill(`update_${singular}`, {
|
|
|
28069
28208
|
}
|
|
28070
28209
|
if (model) {
|
|
28071
28210
|
writeFileSafe(
|
|
28072
|
-
|
|
28211
|
+
join23(idDir, "delete.ts"),
|
|
28073
28212
|
`import type { Tina4Request, Tina4Response } from "tina4-nodejs";
|
|
28074
28213
|
${modelImportId}${secureOptOut(isPublic)}export const meta = { summary: "Delete a ${singular} by ID", tags: ["${routePath}"] };
|
|
28075
28214
|
|
|
@@ -28088,7 +28227,7 @@ export default async function (req: Tina4Request, res: Tina4Response) {
|
|
|
28088
28227
|
);
|
|
28089
28228
|
} else {
|
|
28090
28229
|
writeFileSafe(
|
|
28091
|
-
|
|
28230
|
+
join23(idDir, "delete.ts"),
|
|
28092
28231
|
`import type { Tina4Request, Tina4Response } from "tina4-nodejs";
|
|
28093
28232
|
|
|
28094
28233
|
${secureOptOut(isPublic)}export const meta = { summary: "Delete a ${singular} by ID", tags: ["${routePath}"] };
|
|
@@ -28165,10 +28304,10 @@ export default async function (req: Tina4Request, res: Tina4Response) {
|
|
|
28165
28304
|
return res.html(await Crud.toCrud(req, { model: ${model}, title: "${model} Admin"${publicOpt} }));
|
|
28166
28305
|
}
|
|
28167
28306
|
`;
|
|
28168
|
-
writeFileSafe(
|
|
28307
|
+
writeFileSafe(join23(dir, "get.ts"), content);
|
|
28169
28308
|
}
|
|
28170
28309
|
function frameworkCrudTemplatesDir() {
|
|
28171
|
-
const here = dirname11(
|
|
28310
|
+
const here = dirname11(fileURLToPath7(import.meta.url));
|
|
28172
28311
|
const candidates = [
|
|
28173
28312
|
resolve11(here, "../../../core/templates/crud"),
|
|
28174
28313
|
// monorepo: packages/cli/src/commands -> packages/core/templates/crud
|
|
@@ -28177,7 +28316,7 @@ function frameworkCrudTemplatesDir() {
|
|
|
28177
28316
|
resolve11(here, "../templates/crud")
|
|
28178
28317
|
// flattened publish fallback
|
|
28179
28318
|
];
|
|
28180
|
-
return candidates.find((c) =>
|
|
28319
|
+
return candidates.find((c) => existsSync18(c)) ?? null;
|
|
28181
28320
|
}
|
|
28182
28321
|
function copyCrudTemplates() {
|
|
28183
28322
|
const sourceDir = frameworkCrudTemplatesDir();
|
|
@@ -28188,13 +28327,13 @@ function copyCrudTemplates() {
|
|
|
28188
28327
|
const targetDir = resolve11("src/templates/crud");
|
|
28189
28328
|
ensureDir(targetDir);
|
|
28190
28329
|
for (const file of readdirSync9(sourceDir).filter((f) => f.endsWith(".twig")).sort()) {
|
|
28191
|
-
const dest =
|
|
28192
|
-
if (
|
|
28330
|
+
const dest = join23(targetDir, file);
|
|
28331
|
+
if (existsSync18(dest)) {
|
|
28193
28332
|
if (!__resolution.jsonMode) console.log(` File already exists: ${dest}`);
|
|
28194
28333
|
continue;
|
|
28195
28334
|
}
|
|
28196
28335
|
if (__resolution.dryRun) continue;
|
|
28197
|
-
copyFileSync2(
|
|
28336
|
+
copyFileSync2(join23(sourceDir, file), dest);
|
|
28198
28337
|
__resolution.actionsTaken.push(`wrote ${dest}`);
|
|
28199
28338
|
if (!__resolution.jsonMode) console.log(` Created ${dest}`);
|
|
28200
28339
|
}
|
|
@@ -28252,7 +28391,7 @@ ${writeCase}
|
|
|
28252
28391
|
console.log(\`\\nResults: \${pass} passed, \${fail} failed\`);
|
|
28253
28392
|
process.exit(fail > 0 ? 1 : 0);
|
|
28254
28393
|
`;
|
|
28255
|
-
writeFileSafe(
|
|
28394
|
+
writeFileSafe(join23(dir, `${table2}.test.ts`), content);
|
|
28256
28395
|
}
|
|
28257
28396
|
function generateMigration(name, flags, fieldsOverride, tableOverride, emitTest = true) {
|
|
28258
28397
|
const ts = timestamp();
|
|
@@ -28272,7 +28411,7 @@ function generateMigration(name, flags, fieldsOverride, tableOverride, emitTest
|
|
|
28272
28411
|
const isCreate = name.startsWith("create_") || fieldsOverride !== void 0;
|
|
28273
28412
|
const isView = isCreate && fieldsOverride === void 0 && table2.endsWith("_view");
|
|
28274
28413
|
const fileName = `${ts}_${name}.sql`;
|
|
28275
|
-
const
|
|
28414
|
+
const path9 = join23(dir, fileName);
|
|
28276
28415
|
setResolutionField("migration_path", `migrations/${fileName}`);
|
|
28277
28416
|
if (__resolution.target === "migration") {
|
|
28278
28417
|
setResolutionField("file_path", `migrations/${fileName}`);
|
|
@@ -28313,8 +28452,8 @@ DROP TABLE IF EXISTS ${table2};`;
|
|
|
28313
28452
|
-- UP
|
|
28314
28453
|
${upSql}
|
|
28315
28454
|
`;
|
|
28316
|
-
writeFileSafe(
|
|
28317
|
-
const downPath =
|
|
28455
|
+
writeFileSafe(path9, content);
|
|
28456
|
+
const downPath = join23(dir, `${ts}_${name}.down.sql`);
|
|
28318
28457
|
const downContent = `-- Rollback: ${name}
|
|
28319
28458
|
-- Created: ${now}
|
|
28320
28459
|
|
|
@@ -28327,7 +28466,7 @@ function generateMiddleware(name, _flags) {
|
|
|
28327
28466
|
const snake = toSnake(name);
|
|
28328
28467
|
const dir = resolve11("src/middleware");
|
|
28329
28468
|
ensureDir(dir);
|
|
28330
|
-
const
|
|
28469
|
+
const path9 = join23(dir, `${snake}.ts`);
|
|
28331
28470
|
if (__resolution.target === "middleware") {
|
|
28332
28471
|
setResolutionField("class_name", name);
|
|
28333
28472
|
setResolutionField("file_path", `src/middleware/${snake}.ts`);
|
|
@@ -28365,7 +28504,7 @@ export async function after${name}(
|
|
|
28365
28504
|
await next();
|
|
28366
28505
|
}
|
|
28367
28506
|
`;
|
|
28368
|
-
writeFileSafe(
|
|
28507
|
+
writeFileSafe(path9, content);
|
|
28369
28508
|
emitMiddlewareTest(name, snake);
|
|
28370
28509
|
}
|
|
28371
28510
|
function generateTest(name, flags) {
|
|
@@ -28374,7 +28513,7 @@ function generateTest(name, flags) {
|
|
|
28374
28513
|
const model = flags.model;
|
|
28375
28514
|
const dir = resolve11("tests");
|
|
28376
28515
|
ensureDir(dir);
|
|
28377
|
-
const
|
|
28516
|
+
const path9 = join23(dir, `${snake}.test.ts`);
|
|
28378
28517
|
if (model && flags["secure-writes"]) {
|
|
28379
28518
|
const isPublic = Boolean(flags.public);
|
|
28380
28519
|
const posture = isPublic ? "open (--public)" : "gated";
|
|
@@ -28423,7 +28562,7 @@ ${writeCase}
|
|
|
28423
28562
|
console.log(\`\\nResults: \${pass} passed, \${fail} failed\`);
|
|
28424
28563
|
process.exit(fail > 0 ? 1 : 0);
|
|
28425
28564
|
`;
|
|
28426
|
-
writeFileSafe(
|
|
28565
|
+
writeFileSafe(path9, content2);
|
|
28427
28566
|
return;
|
|
28428
28567
|
}
|
|
28429
28568
|
let content;
|
|
@@ -28489,7 +28628,7 @@ const test${titleName} = tests(
|
|
|
28489
28628
|
void test${titleName};
|
|
28490
28629
|
`;
|
|
28491
28630
|
}
|
|
28492
|
-
writeFileSafe(
|
|
28631
|
+
writeFileSafe(path9, content);
|
|
28493
28632
|
void singular;
|
|
28494
28633
|
}
|
|
28495
28634
|
function generateForm2(name, flags) {
|
|
@@ -28512,7 +28651,7 @@ function generateForm2(name, flags) {
|
|
|
28512
28651
|
};
|
|
28513
28652
|
const dir = resolve11("src/templates/forms");
|
|
28514
28653
|
ensureDir(dir);
|
|
28515
|
-
const
|
|
28654
|
+
const path9 = join23(dir, `${table2}.twig`);
|
|
28516
28655
|
let fieldHtml = "";
|
|
28517
28656
|
for (const [fname, ftype] of fields) {
|
|
28518
28657
|
const itype = inputTypes[ftype] || "text";
|
|
@@ -28556,7 +28695,7 @@ function generateForm2(name, flags) {
|
|
|
28556
28695
|
</div>
|
|
28557
28696
|
{% endblock %}
|
|
28558
28697
|
`;
|
|
28559
|
-
writeFileSafe(
|
|
28698
|
+
writeFileSafe(path9, content);
|
|
28560
28699
|
}
|
|
28561
28700
|
function generateView(name, flags) {
|
|
28562
28701
|
const fields = fieldsOrDefault(flags.fields || "");
|
|
@@ -28565,7 +28704,7 @@ function generateView(name, flags) {
|
|
|
28565
28704
|
const cols = fields.map(([f]) => f);
|
|
28566
28705
|
const dir = resolve11("src/templates/pages");
|
|
28567
28706
|
ensureDir(dir);
|
|
28568
|
-
const listPath =
|
|
28707
|
+
const listPath = join23(dir, `${routeName}.twig`);
|
|
28569
28708
|
const th = cols.map((c) => ` <th>${c.replace(/_/g, " ").replace(/\b\w/g, (ch) => ch.toUpperCase())}</th>`).join("\n");
|
|
28570
28709
|
const td = cols.map((c) => ` <td>{{ item.${c} }}</td>`).join("\n");
|
|
28571
28710
|
const listContent = `{% extends "base.twig" %}
|
|
@@ -28602,7 +28741,7 @@ ${td}
|
|
|
28602
28741
|
{% endblock %}
|
|
28603
28742
|
`;
|
|
28604
28743
|
writeFileSafe(listPath, listContent);
|
|
28605
|
-
const detailPath =
|
|
28744
|
+
const detailPath = join23(dir, `${table2}.twig`);
|
|
28606
28745
|
const detailFields = cols.map((c) => ` <div class="mb-3"><strong>${c.replace(/_/g, " ").replace(/\b\w/g, (ch) => ch.toUpperCase())}:</strong> {{ item.${c} }}</div>`).join("\n");
|
|
28607
28746
|
const detailContent = `{% extends "base.twig" %}
|
|
28608
28747
|
{% block title %}${name} Detail{% endblock %}
|
|
@@ -28632,7 +28771,7 @@ function generateAuth(_flags) {
|
|
|
28632
28771
|
ensureDir(loginDir);
|
|
28633
28772
|
ensureDir(meDir);
|
|
28634
28773
|
writeFileSafe(
|
|
28635
|
-
|
|
28774
|
+
join23(registerDir, "post.ts"),
|
|
28636
28775
|
`import type { Tina4Request, Tina4Response } from "tina4-nodejs";
|
|
28637
28776
|
import { hashPassword } from "tina4-nodejs";
|
|
28638
28777
|
import User from "../../../../models/User.js";
|
|
@@ -28664,7 +28803,7 @@ export default async function (req: Tina4Request, res: Tina4Response) {
|
|
|
28664
28803
|
`
|
|
28665
28804
|
);
|
|
28666
28805
|
writeFileSafe(
|
|
28667
|
-
|
|
28806
|
+
join23(loginDir, "post.ts"),
|
|
28668
28807
|
`import type { Tina4Request, Tina4Response } from "tina4-nodejs";
|
|
28669
28808
|
import { checkPassword, getToken } from "tina4-nodejs";
|
|
28670
28809
|
import User from "../../../../models/User.js";
|
|
@@ -28697,7 +28836,7 @@ export default async function (req: Tina4Request, res: Tina4Response) {
|
|
|
28697
28836
|
`
|
|
28698
28837
|
);
|
|
28699
28838
|
writeFileSafe(
|
|
28700
|
-
|
|
28839
|
+
join23(meDir, "get.ts"),
|
|
28701
28840
|
`import type { Tina4Request, Tina4Response } from "tina4-nodejs";
|
|
28702
28841
|
import { authenticateRequest } from "tina4-nodejs";
|
|
28703
28842
|
|
|
@@ -28716,7 +28855,7 @@ export default async function (req: Tina4Request, res: Tina4Response) {
|
|
|
28716
28855
|
const formsDir = resolve11("src/templates/forms");
|
|
28717
28856
|
ensureDir(formsDir);
|
|
28718
28857
|
writeFileSafe(
|
|
28719
|
-
|
|
28858
|
+
join23(formsDir, "login.twig"),
|
|
28720
28859
|
`{% extends "base.twig" %}
|
|
28721
28860
|
{% block title %}Login{% endblock %}
|
|
28722
28861
|
{% block content %}
|
|
@@ -28744,7 +28883,7 @@ export default async function (req: Tina4Request, res: Tina4Response) {
|
|
|
28744
28883
|
`
|
|
28745
28884
|
);
|
|
28746
28885
|
writeFileSafe(
|
|
28747
|
-
|
|
28886
|
+
join23(formsDir, "register.twig"),
|
|
28748
28887
|
`{% extends "base.twig" %}
|
|
28749
28888
|
{% block title %}Register{% endblock %}
|
|
28750
28889
|
{% block content %}
|
|
@@ -28783,7 +28922,7 @@ function generateService(name, flags) {
|
|
|
28783
28922
|
const cron = flags.cron;
|
|
28784
28923
|
const dir = resolve11("src/services");
|
|
28785
28924
|
ensureDir(dir);
|
|
28786
|
-
const
|
|
28925
|
+
const path9 = join23(dir, `${snake}.ts`);
|
|
28787
28926
|
let scheduleField;
|
|
28788
28927
|
let note;
|
|
28789
28928
|
if (cron && cron !== true) {
|
|
@@ -28826,7 +28965,7 @@ export default {
|
|
|
28826
28965
|
${scheduleField}
|
|
28827
28966
|
};
|
|
28828
28967
|
`;
|
|
28829
|
-
writeFileSafe(
|
|
28968
|
+
writeFileSafe(path9, content);
|
|
28830
28969
|
emitServiceTest(name, snake, camel);
|
|
28831
28970
|
}
|
|
28832
28971
|
function generateQueue(name, _flags) {
|
|
@@ -28835,7 +28974,7 @@ function generateQueue(name, _flags) {
|
|
|
28835
28974
|
const pascal = toPascal(topic) || "Topic";
|
|
28836
28975
|
const dir = resolve11("src/services");
|
|
28837
28976
|
ensureDir(dir);
|
|
28838
|
-
const
|
|
28977
|
+
const path9 = join23(dir, `${slug}_consumer.ts`);
|
|
28839
28978
|
const body = aiFill(`handle${pascal}`, {
|
|
28840
28979
|
intent: `process ONE ${topic} job payload`,
|
|
28841
28980
|
given: "payload -> the produced job data (job.payload)",
|
|
@@ -28890,13 +29029,13 @@ export default {
|
|
|
28890
29029
|
daemon: true,
|
|
28891
29030
|
};
|
|
28892
29031
|
`;
|
|
28893
|
-
writeFileSafe(
|
|
29032
|
+
writeFileSafe(path9, content);
|
|
28894
29033
|
emitQueueTest(topic, slug, pascal);
|
|
28895
29034
|
}
|
|
28896
29035
|
function generateValidator(name, _flags) {
|
|
28897
29036
|
const dir = resolve11("src/validators");
|
|
28898
29037
|
ensureDir(dir);
|
|
28899
|
-
const
|
|
29038
|
+
const path9 = join23(dir, `${toSnake(name)}.ts`);
|
|
28900
29039
|
const rules = extend(
|
|
28901
29040
|
"add / adjust the validation rules for this payload",
|
|
28902
29041
|
`e.g. .email("email").minLength("name", 2).integer("age"); ground: tina4_context("validate request body with Validator", "nodejs")`
|
|
@@ -28917,14 +29056,14 @@ ${rules} validator.required("name"); // starter rule (matches the model's def
|
|
|
28917
29056
|
return validator;
|
|
28918
29057
|
}
|
|
28919
29058
|
`;
|
|
28920
|
-
writeFileSafe(
|
|
29059
|
+
writeFileSafe(path9, content);
|
|
28921
29060
|
emitValidatorTest(name, toSnake(name), toPascal(name));
|
|
28922
29061
|
}
|
|
28923
29062
|
function generateSeeder(name, flags) {
|
|
28924
29063
|
const table2 = resolveTable(name, flags, { announce: false });
|
|
28925
29064
|
const dir = resolve11("src/seeds");
|
|
28926
29065
|
ensureDir(dir);
|
|
28927
|
-
const
|
|
29066
|
+
const path9 = join23(dir, `${table2}_seeder.ts`);
|
|
28928
29067
|
const overrides = extend(
|
|
28929
29068
|
"override fields that need a specific shape (seedOrm auto-fills the rest)",
|
|
28930
29069
|
`e.g. return { email: (f) => f.email(), status: "active" }; ground: tina4_context("seed ORM model with FakeData", "nodejs")`
|
|
@@ -28958,7 +29097,7 @@ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href)
|
|
|
28958
29097
|
await run();
|
|
28959
29098
|
}
|
|
28960
29099
|
`;
|
|
28961
|
-
writeFileSafe(
|
|
29100
|
+
writeFileSafe(path9, content);
|
|
28962
29101
|
emitSeederTest(name, table2);
|
|
28963
29102
|
}
|
|
28964
29103
|
function generateWebsocket(name, _flags) {
|
|
@@ -28969,7 +29108,7 @@ function generateWebsocket(name, _flags) {
|
|
|
28969
29108
|
const handlerName = `${toCamel(toPascal(base))}Ws`;
|
|
28970
29109
|
const dir = resolve11("src/routes");
|
|
28971
29110
|
ensureDir(dir);
|
|
28972
|
-
const
|
|
29111
|
+
const path9 = join23(dir, `ws_${base}.ts`);
|
|
28973
29112
|
const body = aiFill(handlerName, {
|
|
28974
29113
|
intent: `handle an inbound "message" frame on ${wsPath}`,
|
|
28975
29114
|
given: "data -> the message payload (string); connection -> WebSocketConnection",
|
|
@@ -29011,7 +29150,7 @@ ${body}}
|
|
|
29011
29150
|
|
|
29012
29151
|
websocket("${wsPath}", ${handlerName});
|
|
29013
29152
|
`;
|
|
29014
|
-
writeFileSafe(
|
|
29153
|
+
writeFileSafe(path9, content);
|
|
29015
29154
|
emitWebsocketTest(wsPath, base, handlerName);
|
|
29016
29155
|
}
|
|
29017
29156
|
function generateListener(name, _flags) {
|
|
@@ -29020,7 +29159,7 @@ function generateListener(name, _flags) {
|
|
|
29020
29159
|
const handlerName = `on${toPascal(slug)}`;
|
|
29021
29160
|
const dir = resolve11("src/listeners");
|
|
29022
29161
|
ensureDir(dir);
|
|
29023
|
-
const
|
|
29162
|
+
const path9 = join23(dir, `${slug}.ts`);
|
|
29024
29163
|
const body = aiFill(handlerName, {
|
|
29025
29164
|
intent: `react to the '${event}' event`,
|
|
29026
29165
|
given: `args -> whatever Events.emit("${event}", ...args) passed`,
|
|
@@ -29046,13 +29185,13 @@ ${body}}
|
|
|
29046
29185
|
|
|
29047
29186
|
Events.on("${event}", ${handlerName});
|
|
29048
29187
|
`;
|
|
29049
|
-
writeFileSafe(
|
|
29188
|
+
writeFileSafe(path9, content);
|
|
29050
29189
|
emitListenerTest(event, slug);
|
|
29051
29190
|
}
|
|
29052
29191
|
function writeTest(testName, content) {
|
|
29053
29192
|
const dir = resolve11("tests");
|
|
29054
29193
|
ensureDir(dir);
|
|
29055
|
-
writeFileSafe(
|
|
29194
|
+
writeFileSafe(join23(dir, `${testName}.test.ts`), content);
|
|
29056
29195
|
}
|
|
29057
29196
|
function standaloneTest(doc, body) {
|
|
29058
29197
|
return `${doc}
|
|
@@ -29718,7 +29857,6 @@ __export(mcp_exports, {
|
|
|
29718
29857
|
import * as fs4 from "node:fs";
|
|
29719
29858
|
import * as path3 from "node:path";
|
|
29720
29859
|
import * as os from "node:os";
|
|
29721
|
-
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
29722
29860
|
import { createRequire as createRequire7 } from "node:module";
|
|
29723
29861
|
import { randomBytes as randomBytes7 } from "node:crypto";
|
|
29724
29862
|
function reqSibling(pkg) {
|
|
@@ -30047,7 +30185,7 @@ function verifyNodeSyntax(absPath, relPath) {
|
|
|
30047
30185
|
if (!target) return null;
|
|
30048
30186
|
const { cmd, args } = syntaxCheckCommand(absPath, target.ext);
|
|
30049
30187
|
try {
|
|
30050
|
-
const proc =
|
|
30188
|
+
const proc = spawnSyncAllowingBatch(findExecutable(cmd), args, {
|
|
30051
30189
|
encoding: "utf-8",
|
|
30052
30190
|
timeout: 5e3,
|
|
30053
30191
|
cwd: path3.dirname(path3.dirname(absPath))
|
|
@@ -30928,13 +31066,13 @@ function registerDevTools(server) {
|
|
|
30928
31066
|
"git_status",
|
|
30929
31067
|
() => {
|
|
30930
31068
|
try {
|
|
30931
|
-
const { execFileSync:
|
|
31069
|
+
const { execFileSync: execFileSync5 } = req("node:child_process");
|
|
30932
31070
|
const cwd = path3.resolve(process.cwd());
|
|
30933
31071
|
const run = (args) => {
|
|
30934
|
-
return
|
|
31072
|
+
return execFileSync5("git", args, { cwd, timeout: 3e3, encoding: "utf-8" }).toString().trim();
|
|
30935
31073
|
};
|
|
30936
31074
|
try {
|
|
30937
|
-
|
|
31075
|
+
execFileSync5("git", ["rev-parse", "--is-inside-work-tree"], { cwd, timeout: 3e3 });
|
|
30938
31076
|
} catch {
|
|
30939
31077
|
return { error: "Not a git repository" };
|
|
30940
31078
|
}
|
|
@@ -31062,6 +31200,7 @@ var init_mcp = __esm({
|
|
|
31062
31200
|
"../core/src/mcp.ts"() {
|
|
31063
31201
|
"use strict";
|
|
31064
31202
|
init_slashTrim();
|
|
31203
|
+
init_batchSpawn();
|
|
31065
31204
|
init_version();
|
|
31066
31205
|
req = createRequire7(import.meta.url);
|
|
31067
31206
|
PARSE_ERROR = -32700;
|
|
@@ -32523,7 +32662,7 @@ function pack(segments, maxLines) {
|
|
|
32523
32662
|
}
|
|
32524
32663
|
return chunks;
|
|
32525
32664
|
}
|
|
32526
|
-
function chunkCode(text,
|
|
32665
|
+
function chunkCode(text, path9 = "", maxLines = 60) {
|
|
32527
32666
|
const lines = splitLines(text);
|
|
32528
32667
|
let bounds = [];
|
|
32529
32668
|
for (let i = 0; i < lines.length; i++) {
|
|
@@ -32537,7 +32676,7 @@ function chunkCode(text, path10 = "", maxLines = 60) {
|
|
|
32537
32676
|
for (let k = 0; k < bounds.length; k++) {
|
|
32538
32677
|
segments.push(lines.slice(bounds[k], ends[k]));
|
|
32539
32678
|
}
|
|
32540
|
-
const header =
|
|
32679
|
+
const header = path9 ? `# file: ${path9}` : null;
|
|
32541
32680
|
const packed = pack(segments, maxLines);
|
|
32542
32681
|
const out = [];
|
|
32543
32682
|
for (let i = 0; i < packed.length; i++) {
|
|
@@ -32588,8 +32727,8 @@ __export(context_exports, {
|
|
|
32588
32727
|
fts5Supported: () => fts5Supported
|
|
32589
32728
|
});
|
|
32590
32729
|
import { DatabaseSync as DatabaseSync4 } from "node:sqlite";
|
|
32591
|
-
import { existsSync as
|
|
32592
|
-
import { basename as basename5, dirname as dirname13, extname as
|
|
32730
|
+
import { existsSync as existsSync20, mkdirSync as mkdirSync15, readFileSync as readFileSync15, readdirSync as readdirSync11, realpathSync as realpathSync5 } from "node:fs";
|
|
32731
|
+
import { basename as basename5, dirname as dirname13, extname as extname6, isAbsolute as isAbsolute6, join as join25, relative as relative4, resolve as resolve13 } from "node:path";
|
|
32593
32732
|
function fts5Supported() {
|
|
32594
32733
|
try {
|
|
32595
32734
|
const conn = new DatabaseSync4(":memory:");
|
|
@@ -32612,13 +32751,13 @@ function realResolve(abs) {
|
|
|
32612
32751
|
} catch {
|
|
32613
32752
|
}
|
|
32614
32753
|
try {
|
|
32615
|
-
return
|
|
32754
|
+
return join25(realpathSync5(dirname13(abs)), basename5(abs));
|
|
32616
32755
|
} catch {
|
|
32617
32756
|
return abs;
|
|
32618
32757
|
}
|
|
32619
32758
|
}
|
|
32620
32759
|
function dbKey(db) {
|
|
32621
|
-
return resolve13(db ? String(db) :
|
|
32760
|
+
return resolve13(db ? String(db) : join25(process.cwd(), ".tina4", "context.db"));
|
|
32622
32761
|
}
|
|
32623
32762
|
function defaultContext(root, db) {
|
|
32624
32763
|
const key = dbKey(db);
|
|
@@ -32724,7 +32863,7 @@ var init_context = __esm({
|
|
|
32724
32863
|
}
|
|
32725
32864
|
// ── indexing ───────────────────────────────────────────────
|
|
32726
32865
|
static chunksFor(label, text) {
|
|
32727
|
-
const ext =
|
|
32866
|
+
const ext = extname6(label).toLowerCase();
|
|
32728
32867
|
const special = SPECIAL_FILES.has(basename5(label).toLowerCase());
|
|
32729
32868
|
if (CODE_EXTS.has(ext) || CONFIG_EXTS.has(ext) || special) {
|
|
32730
32869
|
return chunkCode(text, label);
|
|
@@ -32763,7 +32902,7 @@ var init_context = __esm({
|
|
|
32763
32902
|
static eligible(filename) {
|
|
32764
32903
|
const fn = filename.toLowerCase();
|
|
32765
32904
|
if (fn.endsWith(".min.js")) return false;
|
|
32766
|
-
const ext =
|
|
32905
|
+
const ext = extname6(fn);
|
|
32767
32906
|
return CODE_EXTS.has(ext) || DOC_EXTS.has(ext) || CONFIG_EXTS.has(ext) || SPECIAL_FILES.has(fn);
|
|
32768
32907
|
}
|
|
32769
32908
|
/**
|
|
@@ -32791,11 +32930,11 @@ var init_context = __esm({
|
|
|
32791
32930
|
files.sort();
|
|
32792
32931
|
for (const fn of files) {
|
|
32793
32932
|
if (!_Context.eligible(fn)) continue;
|
|
32794
|
-
const full =
|
|
32933
|
+
const full = join25(dir, fn);
|
|
32795
32934
|
const rel = relative4(rootAbs, full);
|
|
32796
32935
|
total += this.indexPath(full, rel);
|
|
32797
32936
|
}
|
|
32798
|
-
for (const d of subdirs) walk2(
|
|
32937
|
+
for (const d of subdirs) walk2(join25(dir, d));
|
|
32799
32938
|
};
|
|
32800
32939
|
walk2(rootAbs);
|
|
32801
32940
|
return total;
|
|
@@ -32811,7 +32950,7 @@ var init_context = __esm({
|
|
|
32811
32950
|
reindexFile(changedPath) {
|
|
32812
32951
|
if (!this.available || this.root === null) return -1;
|
|
32813
32952
|
const raw = String(changedPath);
|
|
32814
|
-
const abs = isAbsolute6(raw) ? raw :
|
|
32953
|
+
const abs = isAbsolute6(raw) ? raw : join25(process.cwd(), raw);
|
|
32815
32954
|
const resolved = realResolve(resolve13(abs));
|
|
32816
32955
|
const rel = relative4(this.root, resolved);
|
|
32817
32956
|
if (rel === "" || rel.startsWith("..") || isAbsolute6(rel)) {
|
|
@@ -32824,7 +32963,7 @@ var init_context = __esm({
|
|
|
32824
32963
|
}
|
|
32825
32964
|
if (!_Context.eligible(basename5(rel))) return -1;
|
|
32826
32965
|
const stored = rel;
|
|
32827
|
-
if (!
|
|
32966
|
+
if (!existsSync20(abs)) {
|
|
32828
32967
|
this.conn.prepare("DELETE FROM chunks WHERE path = ?").run(stored);
|
|
32829
32968
|
return 0;
|
|
32830
32969
|
}
|
|
@@ -32842,8 +32981,8 @@ var init_context = __esm({
|
|
|
32842
32981
|
const expr = [...toks].sort().map((t) => `"${t}"`).join(" OR ");
|
|
32843
32982
|
return { expr, toks };
|
|
32844
32983
|
}
|
|
32845
|
-
static isTestlike(
|
|
32846
|
-
const s = (
|
|
32984
|
+
static isTestlike(path9) {
|
|
32985
|
+
const s = (path9 || "").toLowerCase();
|
|
32847
32986
|
return ["/test", "test/", "test_", "_test.", ".test.", "/example", "example/"].some((p) => s.includes(p));
|
|
32848
32987
|
}
|
|
32849
32988
|
static defines(foldedBody, symbols) {
|
|
@@ -33307,7 +33446,7 @@ function parseFrame(data) {
|
|
|
33307
33446
|
const payload = data.subarray(offset, offset + payloadLen);
|
|
33308
33447
|
return { fin: !!fin, opcode, payload: Buffer.from(payload), bytesConsumed: offset + payloadLen };
|
|
33309
33448
|
}
|
|
33310
|
-
function createRouteConnection(socket,
|
|
33449
|
+
function createRouteConnection(socket, path9, headers, params, auth) {
|
|
33311
33450
|
const id = randomUUID4().slice(0, 8);
|
|
33312
33451
|
const send = (message) => {
|
|
33313
33452
|
try {
|
|
@@ -33317,14 +33456,14 @@ function createRouteConnection(socket, path10, headers, params, auth) {
|
|
|
33317
33456
|
};
|
|
33318
33457
|
const conn = {
|
|
33319
33458
|
id,
|
|
33320
|
-
path:
|
|
33459
|
+
path: path9,
|
|
33321
33460
|
ip: socket.remoteAddress ?? "unknown",
|
|
33322
33461
|
headers,
|
|
33323
33462
|
params,
|
|
33324
33463
|
auth,
|
|
33325
33464
|
send,
|
|
33326
33465
|
sendJson: (data) => send(JSON.stringify(data)),
|
|
33327
|
-
broadcast: (message) => wsRouteManager.broadcastPath(
|
|
33466
|
+
broadcast: (message) => wsRouteManager.broadcastPath(path9, message),
|
|
33328
33467
|
broadcastToRoom: (room, message, excludeSelf = false) => wsRouteManager.broadcastToRoom(room, message, excludeSelf ? id : void 0),
|
|
33329
33468
|
getRoomConnections: (room) => wsRouteManager.getRoomConnections(room),
|
|
33330
33469
|
joinRoom: (room) => wsRouteManager.joinRoom(id, room),
|
|
@@ -33533,8 +33672,8 @@ var init_websocket = __esm({
|
|
|
33533
33672
|
* to the Router's `(conn, event, data)` style and registers it via
|
|
33534
33673
|
* `Router.websocket()`.
|
|
33535
33674
|
*/
|
|
33536
|
-
route(
|
|
33537
|
-
this._routeHandlers.set(
|
|
33675
|
+
route(path9, handler, options) {
|
|
33676
|
+
this._routeHandlers.set(path9, handler);
|
|
33538
33677
|
const adapter = async (conn, event, data) => {
|
|
33539
33678
|
if (event === "open") {
|
|
33540
33679
|
const result = handler(conn);
|
|
@@ -33557,7 +33696,7 @@ var init_websocket = __esm({
|
|
|
33557
33696
|
}
|
|
33558
33697
|
}
|
|
33559
33698
|
};
|
|
33560
|
-
Router.websocket(
|
|
33699
|
+
Router.websocket(path9, adapter, options);
|
|
33561
33700
|
}
|
|
33562
33701
|
/**
|
|
33563
33702
|
* Broadcast a message to all connected clients.
|
|
@@ -33567,18 +33706,18 @@ var init_websocket = __esm({
|
|
|
33567
33706
|
* When `path` is omitted/undefined, all clients receive the message
|
|
33568
33707
|
* (backward compatible).
|
|
33569
33708
|
*/
|
|
33570
|
-
broadcast(message, excludeIds,
|
|
33709
|
+
broadcast(message, excludeIds, path9) {
|
|
33571
33710
|
this.ensureBackplane();
|
|
33572
33711
|
const exclude = new Set(excludeIds ?? []);
|
|
33573
33712
|
for (const [id, client] of Array.from(this.clients)) {
|
|
33574
33713
|
if (exclude.has(id)) continue;
|
|
33575
|
-
if (
|
|
33714
|
+
if (path9 !== void 0 && client.path !== path9) continue;
|
|
33576
33715
|
this.safeSend(client, message);
|
|
33577
33716
|
}
|
|
33578
33717
|
this.backplane.publish(
|
|
33579
|
-
|
|
33718
|
+
path9 !== void 0 ? "path" : "all",
|
|
33580
33719
|
message,
|
|
33581
|
-
{ path:
|
|
33720
|
+
{ path: path9 ?? null, exclude: excludeIds?.[0] ?? null },
|
|
33582
33721
|
Log
|
|
33583
33722
|
);
|
|
33584
33723
|
}
|
|
@@ -34054,10 +34193,10 @@ var init_websocket = __esm({
|
|
|
34054
34193
|
}
|
|
34055
34194
|
}
|
|
34056
34195
|
/** Broadcast a text frame to every connection on the same path. */
|
|
34057
|
-
broadcastPath(
|
|
34196
|
+
broadcastPath(path9, message) {
|
|
34058
34197
|
const frame = buildFrame(OP_TEXT, Buffer.from(message, "utf-8"));
|
|
34059
34198
|
for (const state of this.connections.values()) {
|
|
34060
|
-
if (state.path !==
|
|
34199
|
+
if (state.path !== path9 || state.closed) continue;
|
|
34061
34200
|
try {
|
|
34062
34201
|
state.socket.write(frame);
|
|
34063
34202
|
} catch {
|
|
@@ -35670,8 +35809,8 @@ var init_job = __esm({
|
|
|
35670
35809
|
});
|
|
35671
35810
|
|
|
35672
35811
|
// ../core/src/queueBackends/liteBackend.ts
|
|
35673
|
-
import { mkdirSync as mkdirSync16, readdirSync as readdirSync12, readFileSync as readFileSync16, writeFileSync as writeFileSync12, unlinkSync as unlinkSync8, existsSync as
|
|
35674
|
-
import { join as
|
|
35812
|
+
import { mkdirSync as mkdirSync16, readdirSync as readdirSync12, readFileSync as readFileSync16, writeFileSync as writeFileSync12, unlinkSync as unlinkSync8, existsSync as existsSync21 } from "node:fs";
|
|
35813
|
+
import { join as join26 } from "node:path";
|
|
35675
35814
|
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
35676
35815
|
var LiteBackend;
|
|
35677
35816
|
var init_liteBackend = __esm({
|
|
@@ -35695,22 +35834,22 @@ var init_liteBackend = __esm({
|
|
|
35695
35834
|
this.visibilityTimeout = visibilityTimeout;
|
|
35696
35835
|
}
|
|
35697
35836
|
ensureDir(queue) {
|
|
35698
|
-
const dir =
|
|
35837
|
+
const dir = join26(this.basePath, queue);
|
|
35699
35838
|
mkdirSync16(dir, { recursive: true });
|
|
35700
35839
|
return dir;
|
|
35701
35840
|
}
|
|
35702
35841
|
ensureFailedDir(queue) {
|
|
35703
|
-
const dir =
|
|
35842
|
+
const dir = join26(this.basePath, queue, "failed");
|
|
35704
35843
|
mkdirSync16(dir, { recursive: true });
|
|
35705
35844
|
return dir;
|
|
35706
35845
|
}
|
|
35707
35846
|
ensureReservedDir(queue) {
|
|
35708
|
-
const dir =
|
|
35847
|
+
const dir = join26(this.basePath, queue, "reserved");
|
|
35709
35848
|
mkdirSync16(dir, { recursive: true });
|
|
35710
35849
|
return dir;
|
|
35711
35850
|
}
|
|
35712
35851
|
reservedPath(queue, jobId) {
|
|
35713
|
-
return
|
|
35852
|
+
return join26(this.ensureReservedDir(queue), `${jobId}.queue-data`);
|
|
35714
35853
|
}
|
|
35715
35854
|
nowIso() {
|
|
35716
35855
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -35753,7 +35892,7 @@ var init_liteBackend = __esm({
|
|
|
35753
35892
|
error: void 0
|
|
35754
35893
|
};
|
|
35755
35894
|
const prefix = this.nextPrefix();
|
|
35756
|
-
writeFileSync12(
|
|
35895
|
+
writeFileSync12(join26(dir, `${prefix}_${id}.queue-data`), JSON.stringify(job, null, 2));
|
|
35757
35896
|
return id;
|
|
35758
35897
|
}
|
|
35759
35898
|
/**
|
|
@@ -35772,7 +35911,7 @@ var init_liteBackend = __esm({
|
|
|
35772
35911
|
}
|
|
35773
35912
|
const candidates = [];
|
|
35774
35913
|
for (const filename of filenames) {
|
|
35775
|
-
const filePath =
|
|
35914
|
+
const filePath = join26(dir, filename);
|
|
35776
35915
|
let job;
|
|
35777
35916
|
try {
|
|
35778
35917
|
job = JSON.parse(readFileSync16(filePath, "utf-8"));
|
|
@@ -35836,7 +35975,7 @@ var init_liteBackend = __esm({
|
|
|
35836
35975
|
return;
|
|
35837
35976
|
}
|
|
35838
35977
|
for (const filename of filenames) {
|
|
35839
|
-
const filePath =
|
|
35978
|
+
const filePath = join26(reservedDir, filename);
|
|
35840
35979
|
let record2;
|
|
35841
35980
|
try {
|
|
35842
35981
|
record2 = JSON.parse(readFileSync16(filePath, "utf-8"));
|
|
@@ -35874,7 +36013,7 @@ var init_liteBackend = __esm({
|
|
|
35874
36013
|
this.reclaimExpired(queue, bridge.getMaxRetries(), this.nowIso());
|
|
35875
36014
|
const now = this.nowIso();
|
|
35876
36015
|
for (const [filename, job] of this.availableCandidates(queue, now)) {
|
|
35877
|
-
const filePath =
|
|
36016
|
+
const filePath = join26(dir, filename);
|
|
35878
36017
|
job.topic = queue;
|
|
35879
36018
|
job.priority = job.priority ?? 0;
|
|
35880
36019
|
this.writeReserved(queue, job);
|
|
@@ -35899,7 +36038,7 @@ var init_liteBackend = __esm({
|
|
|
35899
36038
|
const results = [];
|
|
35900
36039
|
for (const [filename, job] of this.availableCandidates(queue, now)) {
|
|
35901
36040
|
if (results.length >= count) break;
|
|
35902
|
-
const filePath =
|
|
36041
|
+
const filePath = join26(dir, filename);
|
|
35903
36042
|
job.topic = queue;
|
|
35904
36043
|
job.priority = job.priority ?? 0;
|
|
35905
36044
|
this.writeReserved(queue, job);
|
|
@@ -35952,7 +36091,7 @@ var init_liteBackend = __esm({
|
|
|
35952
36091
|
let count = 0;
|
|
35953
36092
|
for (const file of files) {
|
|
35954
36093
|
try {
|
|
35955
|
-
const job = JSON.parse(readFileSync16(
|
|
36094
|
+
const job = JSON.parse(readFileSync16(join26(scanDir, file), "utf-8"));
|
|
35956
36095
|
if (job.status === status2) count++;
|
|
35957
36096
|
} catch {
|
|
35958
36097
|
}
|
|
@@ -35965,28 +36104,28 @@ var init_liteBackend = __esm({
|
|
|
35965
36104
|
try {
|
|
35966
36105
|
const files = readdirSync12(dir).filter((f) => f.endsWith(".queue-data"));
|
|
35967
36106
|
for (const file of files) {
|
|
35968
|
-
unlinkSync8(
|
|
36107
|
+
unlinkSync8(join26(dir, file));
|
|
35969
36108
|
count++;
|
|
35970
36109
|
}
|
|
35971
36110
|
} catch {
|
|
35972
36111
|
}
|
|
35973
|
-
const failedDir =
|
|
36112
|
+
const failedDir = join26(dir, "failed");
|
|
35974
36113
|
try {
|
|
35975
|
-
if (
|
|
36114
|
+
if (existsSync21(failedDir)) {
|
|
35976
36115
|
const files = readdirSync12(failedDir).filter((f) => f.endsWith(".queue-data"));
|
|
35977
36116
|
for (const file of files) {
|
|
35978
|
-
unlinkSync8(
|
|
36117
|
+
unlinkSync8(join26(failedDir, file));
|
|
35979
36118
|
count++;
|
|
35980
36119
|
}
|
|
35981
36120
|
}
|
|
35982
36121
|
} catch {
|
|
35983
36122
|
}
|
|
35984
|
-
const reservedDir =
|
|
36123
|
+
const reservedDir = join26(dir, "reserved");
|
|
35985
36124
|
try {
|
|
35986
|
-
if (
|
|
36125
|
+
if (existsSync21(reservedDir)) {
|
|
35987
36126
|
const files = readdirSync12(reservedDir).filter((f) => f.endsWith(".queue-data"));
|
|
35988
36127
|
for (const file of files) {
|
|
35989
|
-
unlinkSync8(
|
|
36128
|
+
unlinkSync8(join26(reservedDir, file));
|
|
35990
36129
|
count++;
|
|
35991
36130
|
}
|
|
35992
36131
|
}
|
|
@@ -36009,7 +36148,7 @@ var init_liteBackend = __esm({
|
|
|
36009
36148
|
const files = readdirSync12(dir).filter((f) => f.endsWith(".queue-data")).sort();
|
|
36010
36149
|
for (const file of files) {
|
|
36011
36150
|
try {
|
|
36012
|
-
const job = JSON.parse(readFileSync16(
|
|
36151
|
+
const job = JSON.parse(readFileSync16(join26(dir, file), "utf-8"));
|
|
36013
36152
|
const attempts = job.attempts || 0;
|
|
36014
36153
|
if (attempts > 0 && attempts < maxRetries) {
|
|
36015
36154
|
results.push(job);
|
|
@@ -36032,9 +36171,9 @@ var init_liteBackend = __esm({
|
|
|
36032
36171
|
try {
|
|
36033
36172
|
const queues = readdirSync12(this.basePath);
|
|
36034
36173
|
for (const q of queues) {
|
|
36035
|
-
const failedDir =
|
|
36036
|
-
const filePath =
|
|
36037
|
-
if (
|
|
36174
|
+
const failedDir = join26(this.basePath, q, "failed");
|
|
36175
|
+
const filePath = join26(failedDir, `${jobId}.queue-data`);
|
|
36176
|
+
if (existsSync21(filePath)) {
|
|
36038
36177
|
const job = JSON.parse(readFileSync16(filePath, "utf-8"));
|
|
36039
36178
|
job.status = "pending";
|
|
36040
36179
|
job.attempts = (job.attempts || 0) + 1;
|
|
@@ -36042,8 +36181,8 @@ var init_liteBackend = __esm({
|
|
|
36042
36181
|
job.createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
36043
36182
|
job.delayUntil = delaySeconds ? new Date(Date.now() + delaySeconds * 1e3).toISOString() : null;
|
|
36044
36183
|
const prefix = this.nextPrefix();
|
|
36045
|
-
const queueDir =
|
|
36046
|
-
writeFileSync12(
|
|
36184
|
+
const queueDir = join26(this.basePath, q);
|
|
36185
|
+
writeFileSync12(join26(queueDir, `${prefix}_${jobId}.queue-data`), JSON.stringify(job, null, 2));
|
|
36047
36186
|
unlinkSync8(filePath);
|
|
36048
36187
|
return true;
|
|
36049
36188
|
}
|
|
@@ -36059,7 +36198,7 @@ var init_liteBackend = __esm({
|
|
|
36059
36198
|
const files = readdirSync12(failedDir).filter((f) => f.endsWith(".queue-data")).sort();
|
|
36060
36199
|
for (const file of files) {
|
|
36061
36200
|
try {
|
|
36062
|
-
const job = JSON.parse(readFileSync16(
|
|
36201
|
+
const job = JSON.parse(readFileSync16(join26(failedDir, file), "utf-8"));
|
|
36063
36202
|
if ((job.attempts || 0) >= maxRetries) {
|
|
36064
36203
|
job.status = "dead";
|
|
36065
36204
|
results.push(job);
|
|
@@ -36080,7 +36219,7 @@ var init_liteBackend = __esm({
|
|
|
36080
36219
|
const files = readdirSync12(failedDir).filter((f) => f.endsWith(".queue-data"));
|
|
36081
36220
|
for (const file of files) {
|
|
36082
36221
|
try {
|
|
36083
|
-
unlinkSync8(
|
|
36222
|
+
unlinkSync8(join26(failedDir, file));
|
|
36084
36223
|
count++;
|
|
36085
36224
|
} catch {
|
|
36086
36225
|
}
|
|
@@ -36093,9 +36232,9 @@ var init_liteBackend = __esm({
|
|
|
36093
36232
|
const files = readdirSync12(dir).filter((f) => f.endsWith(".queue-data"));
|
|
36094
36233
|
for (const file of files) {
|
|
36095
36234
|
try {
|
|
36096
|
-
const job = JSON.parse(readFileSync16(
|
|
36235
|
+
const job = JSON.parse(readFileSync16(join26(dir, file), "utf-8"));
|
|
36097
36236
|
if (job.status === status2) {
|
|
36098
|
-
unlinkSync8(
|
|
36237
|
+
unlinkSync8(join26(dir, file));
|
|
36099
36238
|
count++;
|
|
36100
36239
|
}
|
|
36101
36240
|
} catch {
|
|
@@ -36119,7 +36258,7 @@ var init_liteBackend = __esm({
|
|
|
36119
36258
|
const files = readdirSync12(failedDir).filter((f) => f.endsWith(".queue-data"));
|
|
36120
36259
|
for (const file of files) {
|
|
36121
36260
|
try {
|
|
36122
|
-
const filePath =
|
|
36261
|
+
const filePath = join26(failedDir, file);
|
|
36123
36262
|
const job = JSON.parse(readFileSync16(filePath, "utf-8"));
|
|
36124
36263
|
if ((job.attempts || 0) >= maxRetries) {
|
|
36125
36264
|
continue;
|
|
@@ -36129,7 +36268,7 @@ var init_liteBackend = __esm({
|
|
|
36129
36268
|
job.createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
36130
36269
|
job.delayUntil = null;
|
|
36131
36270
|
const prefix = this.nextPrefix();
|
|
36132
|
-
writeFileSync12(
|
|
36271
|
+
writeFileSync12(join26(queueDir, `${prefix}_${job.id}.queue-data`), JSON.stringify(job, null, 2));
|
|
36133
36272
|
unlinkSync8(filePath);
|
|
36134
36273
|
count++;
|
|
36135
36274
|
} catch {
|
|
@@ -36149,7 +36288,7 @@ var init_liteBackend = __esm({
|
|
|
36149
36288
|
}
|
|
36150
36289
|
for (const file of files) {
|
|
36151
36290
|
if (!file.includes(id)) continue;
|
|
36152
|
-
const filePath =
|
|
36291
|
+
const filePath = join26(dir, file);
|
|
36153
36292
|
let job;
|
|
36154
36293
|
try {
|
|
36155
36294
|
job = JSON.parse(readFileSync16(filePath, "utf-8"));
|
|
@@ -36197,7 +36336,7 @@ var init_liteBackend = __esm({
|
|
|
36197
36336
|
error: error2
|
|
36198
36337
|
};
|
|
36199
36338
|
const prefix = this.nextPrefix();
|
|
36200
|
-
writeFileSync12(
|
|
36339
|
+
writeFileSync12(join26(dir, `${prefix}_${job.id}.queue-data`), JSON.stringify(jobData, null, 2));
|
|
36201
36340
|
}
|
|
36202
36341
|
/**
|
|
36203
36342
|
* Move the job to the dead-letter (failed/) directory. Terminal until a
|
|
@@ -36217,7 +36356,7 @@ var init_liteBackend = __esm({
|
|
|
36217
36356
|
error: error2,
|
|
36218
36357
|
failedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
36219
36358
|
};
|
|
36220
|
-
writeFileSync12(
|
|
36359
|
+
writeFileSync12(join26(failedDir, `${job.id}.queue-data`), JSON.stringify(jobData, null, 2));
|
|
36221
36360
|
}
|
|
36222
36361
|
/**
|
|
36223
36362
|
* Record a failed attempt.
|
|
@@ -36267,7 +36406,7 @@ var init_liteBackend = __esm({
|
|
|
36267
36406
|
retryJob(queue, job, delaySeconds) {
|
|
36268
36407
|
this.clearReservation(queue, job.id);
|
|
36269
36408
|
try {
|
|
36270
|
-
unlinkSync8(
|
|
36409
|
+
unlinkSync8(join26(this.ensureFailedDir(queue), `${job.id}.queue-data`));
|
|
36271
36410
|
} catch {
|
|
36272
36411
|
}
|
|
36273
36412
|
job.attempts = (job.attempts || 0) + 1;
|
|
@@ -37407,6 +37546,9 @@ var init_projectIndexExtractors = __esm({
|
|
|
37407
37546
|
import * as fs6 from "node:fs";
|
|
37408
37547
|
import * as path6 from "node:path";
|
|
37409
37548
|
import * as crypto2 from "node:crypto";
|
|
37549
|
+
function indexKey(root, fullPath) {
|
|
37550
|
+
return path6.relative(root, fullPath).split(path6.sep).join("/");
|
|
37551
|
+
}
|
|
37410
37552
|
function projectRoot2() {
|
|
37411
37553
|
return path6.resolve(process.cwd());
|
|
37412
37554
|
}
|
|
@@ -37441,7 +37583,7 @@ function extract2(fullPath) {
|
|
|
37441
37583
|
return {};
|
|
37442
37584
|
}
|
|
37443
37585
|
const entry = {
|
|
37444
|
-
path:
|
|
37586
|
+
path: indexKey(projectRoot2(), fullPath),
|
|
37445
37587
|
size: st.size,
|
|
37446
37588
|
mtime: Math.floor(st.mtimeMs / 1e3),
|
|
37447
37589
|
language: languageFor(fullPath)
|
|
@@ -37548,7 +37690,6 @@ var projectIndex_exports = {};
|
|
|
37548
37690
|
__export(projectIndex_exports, {
|
|
37549
37691
|
ProjectIndex: () => ProjectIndex
|
|
37550
37692
|
});
|
|
37551
|
-
import * as path7 from "node:path";
|
|
37552
37693
|
import * as fs7 from "node:fs";
|
|
37553
37694
|
function scoreSearchEntry(query, rel, entry) {
|
|
37554
37695
|
let score = rel.toLowerCase().includes(query) ? 10 : 0;
|
|
@@ -37581,7 +37722,7 @@ var init_projectIndex = __esm({
|
|
|
37581
37722
|
const found = [];
|
|
37582
37723
|
walk(root, found);
|
|
37583
37724
|
for (const fp of found) {
|
|
37584
|
-
const rel =
|
|
37725
|
+
const rel = indexKey(root, fp);
|
|
37585
37726
|
seen.add(rel);
|
|
37586
37727
|
let mtime;
|
|
37587
37728
|
try {
|
|
@@ -37607,7 +37748,7 @@ var init_projectIndex = __esm({
|
|
|
37607
37748
|
updated,
|
|
37608
37749
|
removed: removed.length,
|
|
37609
37750
|
total: Object.keys(files).length,
|
|
37610
|
-
path:
|
|
37751
|
+
path: indexKey(root, indexPath())
|
|
37611
37752
|
};
|
|
37612
37753
|
},
|
|
37613
37754
|
search(query, limit = 20) {
|
|
@@ -38159,23 +38300,23 @@ __export(docs_exports, {
|
|
|
38159
38300
|
returnFromSignature: () => returnFromSignature
|
|
38160
38301
|
});
|
|
38161
38302
|
import * as fs8 from "node:fs";
|
|
38162
|
-
import * as
|
|
38163
|
-
import { fileURLToPath as
|
|
38303
|
+
import * as path7 from "node:path";
|
|
38304
|
+
import { fileURLToPath as fileURLToPath8 } from "node:url";
|
|
38164
38305
|
function detectFrameworkRoots() {
|
|
38165
|
-
const corePackageRoot =
|
|
38166
|
-
const packagesRoot =
|
|
38306
|
+
const corePackageRoot = path7.resolve(__DIRNAME, "..");
|
|
38307
|
+
const packagesRoot = path7.resolve(corePackageRoot, "..");
|
|
38167
38308
|
const roots = [];
|
|
38168
38309
|
for (const pkg of ["core", "orm", "swagger", "frond"]) {
|
|
38169
|
-
const dir =
|
|
38310
|
+
const dir = path7.join(packagesRoot, pkg, "src");
|
|
38170
38311
|
if (fs8.existsSync(dir)) roots.push(dir);
|
|
38171
38312
|
}
|
|
38172
38313
|
return roots;
|
|
38173
38314
|
}
|
|
38174
38315
|
function detectVersion(projectRoot3) {
|
|
38175
38316
|
for (const candidate of [
|
|
38176
|
-
|
|
38177
|
-
|
|
38178
|
-
|
|
38317
|
+
path7.join(projectRoot3, "package.json"),
|
|
38318
|
+
path7.resolve(__DIRNAME, "..", "..", "..", "package.json"),
|
|
38319
|
+
path7.resolve(__DIRNAME, "..", "package.json")
|
|
38179
38320
|
]) {
|
|
38180
38321
|
try {
|
|
38181
38322
|
const pkg = JSON.parse(fs8.readFileSync(candidate, "utf-8"));
|
|
@@ -38186,16 +38327,16 @@ function detectVersion(projectRoot3) {
|
|
|
38186
38327
|
return "0.0.0";
|
|
38187
38328
|
}
|
|
38188
38329
|
function relativePath(absPath, projectRoot3, frameworkRoots) {
|
|
38189
|
-
const norm =
|
|
38330
|
+
const norm = path7.resolve(absPath);
|
|
38190
38331
|
for (const fw of frameworkRoots) {
|
|
38191
|
-
const parent =
|
|
38192
|
-
if (norm.startsWith(parent +
|
|
38193
|
-
const monorepo =
|
|
38194
|
-
if (norm.startsWith(monorepo +
|
|
38195
|
-
return
|
|
38332
|
+
const parent = path7.dirname(fw);
|
|
38333
|
+
if (norm.startsWith(parent + path7.sep)) {
|
|
38334
|
+
const monorepo = path7.resolve(parent, "..", "..");
|
|
38335
|
+
if (norm.startsWith(monorepo + path7.sep)) return path7.relative(monorepo, norm);
|
|
38336
|
+
return path7.relative(parent, norm);
|
|
38196
38337
|
}
|
|
38197
38338
|
}
|
|
38198
|
-
if (norm.startsWith(projectRoot3 +
|
|
38339
|
+
if (norm.startsWith(projectRoot3 + path7.sep)) return path7.relative(projectRoot3, norm);
|
|
38199
38340
|
return norm;
|
|
38200
38341
|
}
|
|
38201
38342
|
function tokenise(text) {
|
|
@@ -38235,12 +38376,12 @@ function walkTsFiles(root) {
|
|
|
38235
38376
|
if (e.name.startsWith(".")) continue;
|
|
38236
38377
|
if (e.isDirectory()) {
|
|
38237
38378
|
if (e.name === "node_modules" || e.name === "tests" || e.name === "test" || e.name === "dist" || e.name === "build") continue;
|
|
38238
|
-
visit(
|
|
38379
|
+
visit(path7.join(dir, e.name));
|
|
38239
38380
|
} else if (e.isFile()) {
|
|
38240
38381
|
if (!e.name.endsWith(".ts") && !e.name.endsWith(".js") && !e.name.endsWith(".mjs")) continue;
|
|
38241
38382
|
if (e.name.endsWith(".test.ts") || e.name.endsWith(".test.js")) continue;
|
|
38242
38383
|
if (e.name.endsWith(".d.ts")) continue;
|
|
38243
|
-
found.push(
|
|
38384
|
+
found.push(path7.join(dir, e.name));
|
|
38244
38385
|
}
|
|
38245
38386
|
}
|
|
38246
38387
|
}
|
|
@@ -38567,8 +38708,8 @@ var init_docs = __esm({
|
|
|
38567
38708
|
"hash"
|
|
38568
38709
|
]);
|
|
38569
38710
|
_DOCS_CACHE = /* @__PURE__ */ new Map();
|
|
38570
|
-
__FILENAME =
|
|
38571
|
-
__DIRNAME =
|
|
38711
|
+
__FILENAME = fileURLToPath8(import.meta.url);
|
|
38712
|
+
__DIRNAME = path7.dirname(__FILENAME);
|
|
38572
38713
|
USER_DIRS = ["src/orm", "src/routes", "src/app", "src/services", "src/models"];
|
|
38573
38714
|
FENCE_RE = new RegExp(
|
|
38574
38715
|
String.fromCharCode(96, 96, 96) + "[a-zA-Z0-9_+-]*\\n([\\s\\S]*?)\\n" + String.fromCharCode(96, 96, 96),
|
|
@@ -38586,7 +38727,7 @@ var init_docs = __esm({
|
|
|
38586
38727
|
userMtime = 0;
|
|
38587
38728
|
frameworkMtime = 0;
|
|
38588
38729
|
constructor(projectRoot3) {
|
|
38589
|
-
this.projectRoot =
|
|
38730
|
+
this.projectRoot = path7.resolve(projectRoot3);
|
|
38590
38731
|
this.frameworkRoots = detectFrameworkRoots();
|
|
38591
38732
|
this.version = detectVersion(this.projectRoot);
|
|
38592
38733
|
}
|
|
@@ -38778,7 +38919,7 @@ var init_docs = __esm({
|
|
|
38778
38919
|
// ── Drift detector + sync ────────────────────────────────────────
|
|
38779
38920
|
static checkDocs(mdPath, projectRoot3) {
|
|
38780
38921
|
if (!fs8.existsSync(mdPath)) return { drift: [] };
|
|
38781
|
-
const docs = _Docs.cached(projectRoot3 ??
|
|
38922
|
+
const docs = _Docs.cached(projectRoot3 ?? path7.dirname(mdPath));
|
|
38782
38923
|
const idx = docs.index();
|
|
38783
38924
|
const known = /* @__PURE__ */ new Set();
|
|
38784
38925
|
for (const e of idx) known.add(e.name.toLowerCase());
|
|
@@ -38805,7 +38946,7 @@ var init_docs = __esm({
|
|
|
38805
38946
|
return { drift };
|
|
38806
38947
|
}
|
|
38807
38948
|
static syncDocs(mdPath, projectRoot3) {
|
|
38808
|
-
const docs = _Docs.cached(projectRoot3 ?? (fs8.existsSync(mdPath) ?
|
|
38949
|
+
const docs = _Docs.cached(projectRoot3 ?? (fs8.existsSync(mdPath) ? path7.dirname(mdPath) : process.cwd()));
|
|
38809
38950
|
const generated = docs.renderGeneratedBlock();
|
|
38810
38951
|
const begin = "<!-- BEGIN GENERATED API -->";
|
|
38811
38952
|
const end = "<!-- END GENERATED API -->";
|
|
@@ -38829,7 +38970,7 @@ ${end}
|
|
|
38829
38970
|
}
|
|
38830
38971
|
// ── Internals ────────────────────────────────────────────────────
|
|
38831
38972
|
static cached(projectRoot3) {
|
|
38832
|
-
const key =
|
|
38973
|
+
const key = path7.resolve(projectRoot3 ?? process.cwd());
|
|
38833
38974
|
let inst = _DOCS_CACHE.get(key);
|
|
38834
38975
|
if (!inst) {
|
|
38835
38976
|
inst = new _Docs(key);
|
|
@@ -38856,11 +38997,11 @@ ${end}
|
|
|
38856
38997
|
this.frameworkMtime = shared.mtime;
|
|
38857
38998
|
this.indexCache = null;
|
|
38858
38999
|
}
|
|
38859
|
-
const userMtime = this.maxMtime(USER_DIRS.map((d) =>
|
|
39000
|
+
const userMtime = this.maxMtime(USER_DIRS.map((d) => path7.join(this.projectRoot, d)));
|
|
38860
39001
|
if (this.indexCache === null || userMtime !== this.userMtime) {
|
|
38861
39002
|
this.userEntries = /* @__PURE__ */ new Map();
|
|
38862
39003
|
for (const sub of USER_DIRS) {
|
|
38863
|
-
const dir =
|
|
39004
|
+
const dir = path7.join(this.projectRoot, sub);
|
|
38864
39005
|
if (!fs8.existsSync(dir)) continue;
|
|
38865
39006
|
for (const f of walkTsFiles(dir)) {
|
|
38866
39007
|
buildEntriesForFile(f, "user", this.frameworkRoots, this.projectRoot, this.version, this.userEntries);
|
|
@@ -38943,9 +39084,9 @@ ${end}
|
|
|
38943
39084
|
|
|
38944
39085
|
// ../core/src/devAdmin.ts
|
|
38945
39086
|
import { cpus as osCpus } from "node:os";
|
|
38946
|
-
import { readFileSync as readFileSync20, writeFileSync as writeFileSync16, existsSync as
|
|
38947
|
-
import { join as
|
|
38948
|
-
import { fileURLToPath as
|
|
39087
|
+
import { readFileSync as readFileSync20, writeFileSync as writeFileSync16, existsSync as existsSync25, readdirSync as readdirSync16, mkdirSync as mkdirSync19, copyFileSync as copyFileSync3, statSync as statSync19, 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";
|
|
39088
|
+
import { join as join30, dirname as dirname15, resolve as resolve17, relative as relative8, sep as sep9, basename as basename6 } from "node:path";
|
|
39089
|
+
import { fileURLToPath as fileURLToPath9 } from "node:url";
|
|
38949
39090
|
import { timingSafeEqual as timingSafeEqual2 } from "node:crypto";
|
|
38950
39091
|
import net2 from "node:net";
|
|
38951
39092
|
function escapeHtml2(value) {
|
|
@@ -39023,15 +39164,15 @@ function devToolbarAllowed(req2) {
|
|
|
39023
39164
|
return devPeerAllowed(peer);
|
|
39024
39165
|
}
|
|
39025
39166
|
function devRequestDenial(req2) {
|
|
39026
|
-
const
|
|
39027
|
-
const isMcp = DEV_MCP_PREFIXES.some((prefix) =>
|
|
39167
|
+
const path9 = (req2.path ?? "").replace(/\/+/g, "/");
|
|
39168
|
+
const isMcp = DEV_MCP_PREFIXES.some((prefix) => path9 === prefix || path9.startsWith(prefix + "/"));
|
|
39028
39169
|
if (!devHostAllowed(req2.header("host"))) {
|
|
39029
39170
|
return { status: 403, error: "dev-admin: refused (host not allowed)" };
|
|
39030
39171
|
}
|
|
39031
39172
|
if (!devSameOriginOk(req2)) {
|
|
39032
39173
|
return { status: 403, error: "dev-admin: refused (cross-origin request)" };
|
|
39033
39174
|
}
|
|
39034
|
-
if (DEV_PUBLIC_ASSETS.has(
|
|
39175
|
+
if (DEV_PUBLIC_ASSETS.has(path9)) {
|
|
39035
39176
|
return null;
|
|
39036
39177
|
}
|
|
39037
39178
|
if (!isMcp) {
|
|
@@ -39123,12 +39264,12 @@ function mapQueueJob(job, topic, status2) {
|
|
|
39123
39264
|
};
|
|
39124
39265
|
}
|
|
39125
39266
|
function readQueueDir(dir, topic, status2) {
|
|
39126
|
-
if (!
|
|
39267
|
+
if (!existsSync25(dir)) return [];
|
|
39127
39268
|
const jobs = [];
|
|
39128
39269
|
for (const filename of readdirSync16(dir).sort()) {
|
|
39129
39270
|
if (!filename.endsWith(".queue-data")) continue;
|
|
39130
39271
|
try {
|
|
39131
|
-
jobs.push(mapQueueJob(JSON.parse(readFileSync20(
|
|
39272
|
+
jobs.push(mapQueueJob(JSON.parse(readFileSync20(join30(dir, filename), "utf-8")), topic, status2));
|
|
39132
39273
|
} catch {
|
|
39133
39274
|
}
|
|
39134
39275
|
}
|
|
@@ -39265,8 +39406,8 @@ async function proxyToSupervisor(req2, res, downstreamPath) {
|
|
|
39265
39406
|
function resolveDevEnvVar(key) {
|
|
39266
39407
|
const live = process.env[key];
|
|
39267
39408
|
if (live !== void 0 && live !== "") return live;
|
|
39268
|
-
const envPath =
|
|
39269
|
-
if (!
|
|
39409
|
+
const envPath = join30(process.cwd(), ".env");
|
|
39410
|
+
if (!existsSync25(envPath)) return "";
|
|
39270
39411
|
for (const line of readFileSync20(envPath, "utf-8").split("\n")) {
|
|
39271
39412
|
const t = line.trim();
|
|
39272
39413
|
if (!t || t.startsWith("#") || !t.includes("=")) continue;
|
|
@@ -39276,8 +39417,8 @@ function resolveDevEnvVar(key) {
|
|
|
39276
39417
|
return "";
|
|
39277
39418
|
}
|
|
39278
39419
|
function upsertDevEnvVar(key, value) {
|
|
39279
|
-
const envPath =
|
|
39280
|
-
const lines =
|
|
39420
|
+
const envPath = join30(process.cwd(), ".env");
|
|
39421
|
+
const lines = existsSync25(envPath) ? readFileSync20(envPath, "utf-8").split("\n") : [];
|
|
39281
39422
|
let found = false;
|
|
39282
39423
|
const out = [];
|
|
39283
39424
|
for (const line of lines) {
|
|
@@ -39307,9 +39448,9 @@ function formatUptime(seconds) {
|
|
|
39307
39448
|
return parts.join(" ");
|
|
39308
39449
|
}
|
|
39309
39450
|
function parseEnvFile() {
|
|
39310
|
-
const envPath =
|
|
39451
|
+
const envPath = join30(process.cwd(), ".env");
|
|
39311
39452
|
const result = {};
|
|
39312
|
-
if (!
|
|
39453
|
+
if (!existsSync25(envPath)) return result;
|
|
39313
39454
|
const lines = readFileSync20(envPath, "utf-8").split("\n");
|
|
39314
39455
|
for (const line of lines) {
|
|
39315
39456
|
const trimmed = line.trim();
|
|
@@ -39321,10 +39462,10 @@ function parseEnvFile() {
|
|
|
39321
39462
|
}
|
|
39322
39463
|
function walkDirRecursive(dir) {
|
|
39323
39464
|
const results = [];
|
|
39324
|
-
if (!
|
|
39465
|
+
if (!existsSync25(dir)) return results;
|
|
39325
39466
|
for (const entry of readdirSync16(dir)) {
|
|
39326
|
-
const full =
|
|
39327
|
-
if (
|
|
39467
|
+
const full = join30(dir, entry);
|
|
39468
|
+
if (statSync19(full).isDirectory()) {
|
|
39328
39469
|
results.push(...walkDirRecursive(full));
|
|
39329
39470
|
} else {
|
|
39330
39471
|
results.push(full);
|
|
@@ -39341,8 +39482,8 @@ function handleGalleryDeploy(router) {
|
|
|
39341
39482
|
return;
|
|
39342
39483
|
}
|
|
39343
39484
|
const galleryDir = resolve17(__devAdminDirname, "..", "gallery");
|
|
39344
|
-
const gallerySrc =
|
|
39345
|
-
if (!
|
|
39485
|
+
const gallerySrc = join30(galleryDir, name, "src");
|
|
39486
|
+
if (!existsSync25(gallerySrc)) {
|
|
39346
39487
|
res.json({ error: `Gallery item '${name}' not found` }, 404);
|
|
39347
39488
|
return;
|
|
39348
39489
|
}
|
|
@@ -39350,15 +39491,15 @@ function handleGalleryDeploy(router) {
|
|
|
39350
39491
|
const copied = [];
|
|
39351
39492
|
const allFiles = walkDirRecursive(gallerySrc);
|
|
39352
39493
|
for (const srcFile of allFiles) {
|
|
39353
|
-
const rel =
|
|
39354
|
-
const dest =
|
|
39494
|
+
const rel = relative8(gallerySrc, srcFile);
|
|
39495
|
+
const dest = join30(projectSrc, rel);
|
|
39355
39496
|
mkdirSync19(dirname15(dest), { recursive: true });
|
|
39356
39497
|
copyFileSync3(srcFile, dest);
|
|
39357
39498
|
copied.push(rel);
|
|
39358
39499
|
}
|
|
39359
39500
|
try {
|
|
39360
39501
|
const routesDir = resolve17(process.cwd(), "src", "routes");
|
|
39361
|
-
if (
|
|
39502
|
+
if (existsSync25(routesDir)) {
|
|
39362
39503
|
const { discoverRoutes: discoverRoutes2 } = await Promise.resolve().then(() => (init_routeDiscovery(), routeDiscovery_exports));
|
|
39363
39504
|
const routes = await discoverRoutes2(routesDir);
|
|
39364
39505
|
for (const route of routes) {
|
|
@@ -39387,7 +39528,7 @@ function realPathOf2(target) {
|
|
|
39387
39528
|
tail.unshift(basename6(existing));
|
|
39388
39529
|
existing = dirname15(existing);
|
|
39389
39530
|
}
|
|
39390
|
-
return
|
|
39531
|
+
return join30(realpathSync6(existing), ...tail);
|
|
39391
39532
|
}
|
|
39392
39533
|
function safeJoin(projectRoot3, rel, extraRoots = []) {
|
|
39393
39534
|
try {
|
|
@@ -39395,14 +39536,14 @@ function safeJoin(projectRoot3, rel, extraRoots = []) {
|
|
|
39395
39536
|
const resolved = realPathOf2(resolve17(root, rel));
|
|
39396
39537
|
const roots = [root, ...extraRoots.filter(Boolean).map((r) => realPathOf2(resolve17(r)))];
|
|
39397
39538
|
for (const r of roots) {
|
|
39398
|
-
if (resolved === r || resolved.startsWith(r.endsWith(
|
|
39539
|
+
if (resolved === r || resolved.startsWith(r.endsWith(sep9) ? r : r + sep9)) return resolved;
|
|
39399
39540
|
}
|
|
39400
39541
|
} catch {
|
|
39401
39542
|
}
|
|
39402
39543
|
return null;
|
|
39403
39544
|
}
|
|
39404
39545
|
function resolvedRelative(projectRoot3, resolvedPath) {
|
|
39405
|
-
return
|
|
39546
|
+
return relative8(realPathOf2(resolve17(projectRoot3)), resolvedPath);
|
|
39406
39547
|
}
|
|
39407
39548
|
function devFilesHidden(name) {
|
|
39408
39549
|
if (DEV_FILES_IGNORED.has(name)) return true;
|
|
@@ -39418,10 +39559,10 @@ function devGitStatusLabel(code) {
|
|
|
39418
39559
|
async function devGitInfo(root) {
|
|
39419
39560
|
const empty = { branch: "", gitRoot: null, status: /* @__PURE__ */ new Map() };
|
|
39420
39561
|
try {
|
|
39421
|
-
const { execFileSync:
|
|
39562
|
+
const { execFileSync: execFileSync5 } = await import("node:child_process");
|
|
39422
39563
|
const git = (args) => {
|
|
39423
39564
|
try {
|
|
39424
|
-
return
|
|
39565
|
+
return execFileSync5("git", args, { cwd: root, timeout: 3e3, encoding: "utf-8" }).toString();
|
|
39425
39566
|
} catch {
|
|
39426
39567
|
return null;
|
|
39427
39568
|
}
|
|
@@ -39473,7 +39614,7 @@ function buildFileEntry(name, full, entryRel, cwdInGit, gitStatus) {
|
|
|
39473
39614
|
let isDir = false;
|
|
39474
39615
|
let size = null;
|
|
39475
39616
|
try {
|
|
39476
|
-
const st =
|
|
39617
|
+
const st = statSync19(full);
|
|
39477
39618
|
isDir = st.isDirectory();
|
|
39478
39619
|
if (!isDir) size = st.size;
|
|
39479
39620
|
} catch {
|
|
@@ -39548,7 +39689,7 @@ function applyMcpOutcome(res, outcome) {
|
|
|
39548
39689
|
function renderToolbarHtml(ctx) {
|
|
39549
39690
|
const nodeVersion = process.version;
|
|
39550
39691
|
const method = escapeHtml2(ctx.method);
|
|
39551
|
-
const
|
|
39692
|
+
const path9 = escapeHtml2(ctx.path);
|
|
39552
39693
|
const matchedPattern = escapeHtml2(ctx.matchedPattern);
|
|
39553
39694
|
const reload = ctx.reload === false ? "0" : "1";
|
|
39554
39695
|
return `<link rel="stylesheet" href="/__dev/toolbar.css">
|
|
@@ -39565,7 +39706,7 @@ function renderToolbarHtml(ctx) {
|
|
|
39565
39706
|
</div>
|
|
39566
39707
|
</div>
|
|
39567
39708
|
<span class="t4-green">${method}</span>
|
|
39568
|
-
<span>${
|
|
39709
|
+
<span>${path9}</span>
|
|
39569
39710
|
<span class="t4-arrow">→ ${matchedPattern}</span>
|
|
39570
39711
|
<span class="t4-yellow">req:${ctx.requestId}</span>
|
|
39571
39712
|
<span class="t4-blue">${ctx.routeCount} routes</span>
|
|
@@ -39740,6 +39881,7 @@ var init_devAdmin = __esm({
|
|
|
39740
39881
|
"../core/src/devAdmin.ts"() {
|
|
39741
39882
|
"use strict";
|
|
39742
39883
|
init_slashTrim();
|
|
39884
|
+
init_batchSpawn();
|
|
39743
39885
|
init_devMailbox();
|
|
39744
39886
|
init_upstreamResponse();
|
|
39745
39887
|
init_dotenv();
|
|
@@ -39801,12 +39943,12 @@ var init_devAdmin = __esm({
|
|
|
39801
39943
|
RequestInspector = class {
|
|
39802
39944
|
static requests = [];
|
|
39803
39945
|
static maxRequests = 200;
|
|
39804
|
-
static capture(method,
|
|
39946
|
+
static capture(method, path9, status2, duration) {
|
|
39805
39947
|
const entry = {
|
|
39806
39948
|
id: `${Date.now()}_${this.requests.length}`,
|
|
39807
39949
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
39808
39950
|
method,
|
|
39809
|
-
path:
|
|
39951
|
+
path: path9,
|
|
39810
39952
|
status: status2,
|
|
39811
39953
|
durationMs: Math.round(duration * 100) / 100
|
|
39812
39954
|
};
|
|
@@ -39995,12 +40137,12 @@ var init_devAdmin = __esm({
|
|
|
39995
40137
|
};
|
|
39996
40138
|
WsTracker = class {
|
|
39997
40139
|
static connections = [];
|
|
39998
|
-
static add(remoteAddress,
|
|
40140
|
+
static add(remoteAddress, path9) {
|
|
39999
40141
|
const conn = {
|
|
40000
40142
|
id: `ws_${Date.now()}_${this.connections.length}`,
|
|
40001
40143
|
connectedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
40002
40144
|
remoteAddress,
|
|
40003
|
-
path:
|
|
40145
|
+
path: path9
|
|
40004
40146
|
};
|
|
40005
40147
|
this.connections.push(conn);
|
|
40006
40148
|
return conn.id;
|
|
@@ -40110,7 +40252,7 @@ var init_devAdmin = __esm({
|
|
|
40110
40252
|
const p = (url.searchParams.get("path") || "").toString();
|
|
40111
40253
|
const scanRoot = metricsScanRoot();
|
|
40112
40254
|
let target = p ? safeJoin(process.cwd(), p, [scanRoot]) : "";
|
|
40113
|
-
if (target === null && scanRoot) target = safeJoin(process.cwd(),
|
|
40255
|
+
if (target === null && scanRoot) target = safeJoin(process.cwd(), join30(scanRoot, p), [scanRoot]);
|
|
40114
40256
|
if (target === null) {
|
|
40115
40257
|
res.status(403).json({ error: "Path outside project" });
|
|
40116
40258
|
return;
|
|
@@ -40348,6 +40490,7 @@ var init_devAdmin = __esm({
|
|
|
40348
40490
|
const mem = process.memoryUsage();
|
|
40349
40491
|
const heapUsedMb = Math.round(mem.heapUsed / 1048576);
|
|
40350
40492
|
const rssMb = Math.round(mem.rss / 1048576);
|
|
40493
|
+
const peakRssMb = Math.round(process.resourceUsage().maxRSS / 1024);
|
|
40351
40494
|
let dbTableCount;
|
|
40352
40495
|
let dbConnected = false;
|
|
40353
40496
|
try {
|
|
@@ -40364,12 +40507,14 @@ var init_devAdmin = __esm({
|
|
|
40364
40507
|
architecture: process.arch,
|
|
40365
40508
|
os: `${process.platform} ${process.arch}`,
|
|
40366
40509
|
pid: process.pid,
|
|
40367
|
-
|
|
40510
|
+
// The dashboard's "Memory": the process's current RSS, as tina4-python
|
|
40511
|
+
// reports it. V8's heapUsed (below) leaves out Buffers and native memory.
|
|
40512
|
+
memory_mb: rssMb,
|
|
40368
40513
|
db_tables: dbTableCount !== void 0 ? dbTableCount : "N/A",
|
|
40369
40514
|
db_connected: dbConnected,
|
|
40370
40515
|
memory: {
|
|
40371
|
-
current_mb:
|
|
40372
|
-
peak_mb:
|
|
40516
|
+
current_mb: rssMb,
|
|
40517
|
+
peak_mb: peakRssMb,
|
|
40373
40518
|
limit: "V8 default",
|
|
40374
40519
|
rss: `${rssMb} MB`,
|
|
40375
40520
|
heapUsed: `${heapUsedMb} MB`,
|
|
@@ -40428,16 +40573,16 @@ var init_devAdmin = __esm({
|
|
|
40428
40573
|
failed: queue.size("failed"),
|
|
40429
40574
|
reserved: queue.size("reserved")
|
|
40430
40575
|
};
|
|
40431
|
-
const topicDir =
|
|
40576
|
+
const topicDir = join30(queueBasePath2(), topic);
|
|
40432
40577
|
const jobs = [];
|
|
40433
40578
|
if (!statusFilter || statusFilter === "pending") {
|
|
40434
40579
|
jobs.push(...readQueueDir(topicDir, topic, "pending"));
|
|
40435
40580
|
}
|
|
40436
40581
|
if (!statusFilter || statusFilter === "reserved") {
|
|
40437
|
-
jobs.push(...readQueueDir(
|
|
40582
|
+
jobs.push(...readQueueDir(join30(topicDir, "reserved"), topic, "reserved"));
|
|
40438
40583
|
}
|
|
40439
40584
|
if (!statusFilter || statusFilter === "failed" || statusFilter === "dead") {
|
|
40440
|
-
jobs.push(...readQueueDir(
|
|
40585
|
+
jobs.push(...readQueueDir(join30(topicDir, "failed"), topic, "dead_letter"));
|
|
40441
40586
|
}
|
|
40442
40587
|
res.json({ stats, jobs });
|
|
40443
40588
|
} catch (e) {
|
|
@@ -40453,10 +40598,10 @@ var init_devAdmin = __esm({
|
|
|
40453
40598
|
const { queueBasePath: queueBasePath2 } = await Promise.resolve().then(() => (init_queue(), queue_exports));
|
|
40454
40599
|
const queueDir = queueBasePath2();
|
|
40455
40600
|
let topics = [];
|
|
40456
|
-
if (
|
|
40601
|
+
if (existsSync25(queueDir)) {
|
|
40457
40602
|
topics = readdirSync16(queueDir).filter((d) => {
|
|
40458
40603
|
try {
|
|
40459
|
-
return
|
|
40604
|
+
return statSync19(join30(queueDir, d)).isDirectory();
|
|
40460
40605
|
} catch {
|
|
40461
40606
|
return false;
|
|
40462
40607
|
}
|
|
@@ -40741,7 +40886,7 @@ var init_devAdmin = __esm({
|
|
|
40741
40886
|
const count = parseInt(String(body.count ?? "10"), 10) || 10;
|
|
40742
40887
|
try {
|
|
40743
40888
|
const orm = await Promise.resolve().then(() => (init_src(), src_exports));
|
|
40744
|
-
const dirs = ["src/orm", "src/models"].map((d) => resolve17(process.cwd(), d)).filter((d) =>
|
|
40889
|
+
const dirs = ["src/orm", "src/models"].map((d) => resolve17(process.cwd(), d)).filter((d) => existsSync25(d));
|
|
40745
40890
|
const classes = [];
|
|
40746
40891
|
for (const dir of dirs) {
|
|
40747
40892
|
for (const m of await orm.discoverModels(dir)) classes.push(m.modelClass);
|
|
@@ -40882,7 +41027,7 @@ var init_devAdmin = __esm({
|
|
|
40882
41027
|
return;
|
|
40883
41028
|
}
|
|
40884
41029
|
try {
|
|
40885
|
-
const envPath =
|
|
41030
|
+
const envPath = join30(process.cwd(), ".env");
|
|
40886
41031
|
const fd = openSync5(envPath, constants4.O_RDWR | constants4.O_APPEND | constants4.O_CREAT | (constants4.O_NOFOLLOW ?? 0) | (constants4.O_NONBLOCK ?? 0), 384);
|
|
40887
41032
|
try {
|
|
40888
41033
|
const info = fstatSync3(fd);
|
|
@@ -40926,29 +41071,29 @@ var init_devAdmin = __esm({
|
|
|
40926
41071
|
res.json({ success: false, error: msg });
|
|
40927
41072
|
}
|
|
40928
41073
|
};
|
|
40929
|
-
__devAdminFilename =
|
|
41074
|
+
__devAdminFilename = fileURLToPath9(import.meta.url);
|
|
40930
41075
|
__devAdminDirname = dirname15(__devAdminFilename);
|
|
40931
41076
|
handleGalleryList = (_req, res) => {
|
|
40932
41077
|
const galleryDir = resolve17(__devAdminDirname, "..", "gallery");
|
|
40933
41078
|
const items = [];
|
|
40934
|
-
if (
|
|
41079
|
+
if (existsSync25(galleryDir)) {
|
|
40935
41080
|
const entries = readdirSync16(galleryDir).sort();
|
|
40936
41081
|
for (const entry of entries) {
|
|
40937
|
-
const entryPath =
|
|
40938
|
-
const metaFile =
|
|
40939
|
-
if (
|
|
41082
|
+
const entryPath = join30(galleryDir, entry);
|
|
41083
|
+
const metaFile = join30(entryPath, "meta.json");
|
|
41084
|
+
if (statSync19(entryPath).isDirectory() && existsSync25(metaFile)) {
|
|
40940
41085
|
try {
|
|
40941
41086
|
const meta = JSON.parse(readFileSync20(metaFile, "utf-8"));
|
|
40942
41087
|
meta.id = entry;
|
|
40943
|
-
const srcDir =
|
|
40944
|
-
if (
|
|
41088
|
+
const srcDir = join30(entryPath, "src");
|
|
41089
|
+
if (existsSync25(srcDir)) {
|
|
40945
41090
|
const allFiles = walkDirRecursive(srcDir);
|
|
40946
|
-
meta.files = allFiles.map((f) =>
|
|
41091
|
+
meta.files = allFiles.map((f) => relative8(srcDir, f));
|
|
40947
41092
|
}
|
|
40948
41093
|
const projectSrc = resolve17(process.cwd(), "src");
|
|
40949
|
-
if (
|
|
41094
|
+
if (existsSync25(srcDir) && meta.files) {
|
|
40950
41095
|
meta.deployed = meta.files.every(
|
|
40951
|
-
(f) =>
|
|
41096
|
+
(f) => existsSync25(join30(projectSrc, f))
|
|
40952
41097
|
);
|
|
40953
41098
|
} else {
|
|
40954
41099
|
meta.deployed = false;
|
|
@@ -41025,7 +41170,7 @@ var init_devAdmin = __esm({
|
|
|
41025
41170
|
const root = resolve17(process.cwd());
|
|
41026
41171
|
const target = safeJoin(root, rel);
|
|
41027
41172
|
const { branch, gitRoot, status: gitStatus } = await devGitInfo(root);
|
|
41028
|
-
if (!target || !
|
|
41173
|
+
if (!target || !existsSync25(target) || !statSync19(target).isDirectory()) {
|
|
41029
41174
|
res.json({ path: rel, branch, entries: [], error: "not a directory" });
|
|
41030
41175
|
return;
|
|
41031
41176
|
}
|
|
@@ -41038,12 +41183,12 @@ var init_devAdmin = __esm({
|
|
|
41038
41183
|
const entries = [];
|
|
41039
41184
|
for (const name of readdirSync16(target).sort()) {
|
|
41040
41185
|
if (devFilesHidden(name)) continue;
|
|
41041
|
-
const full =
|
|
41042
|
-
const entryRel =
|
|
41186
|
+
const full = join30(target, name);
|
|
41187
|
+
const entryRel = relative8(root, full).replace(/\\/g, "/");
|
|
41043
41188
|
if (isSecretPath(entryRel)) continue;
|
|
41044
41189
|
entries.push(buildFileEntry(name, full, entryRel, cwdInGit, gitStatus));
|
|
41045
41190
|
}
|
|
41046
|
-
res.json({ path:
|
|
41191
|
+
res.json({ path: relative8(root, target).replace(/\\/g, "/") || ".", branch, entries });
|
|
41047
41192
|
};
|
|
41048
41193
|
DEV_ADMIN_LANG_MAP = {
|
|
41049
41194
|
".py": "python",
|
|
@@ -41101,8 +41246,8 @@ var init_devAdmin = __esm({
|
|
|
41101
41246
|
return;
|
|
41102
41247
|
}
|
|
41103
41248
|
const content = data.toString("utf-8");
|
|
41104
|
-
const
|
|
41105
|
-
res.json({ path:
|
|
41249
|
+
const path9 = relative8(root, target);
|
|
41250
|
+
res.json({ path: path9, content, language: devAdminLanguage(path9), bytes: Buffer.byteLength(content, "utf-8") });
|
|
41106
41251
|
} catch (e) {
|
|
41107
41252
|
res.json({ error: e.message }, 500);
|
|
41108
41253
|
}
|
|
@@ -41119,14 +41264,14 @@ var init_devAdmin = __esm({
|
|
|
41119
41264
|
}
|
|
41120
41265
|
try {
|
|
41121
41266
|
mkdirSync19(dirname15(target), { recursive: true });
|
|
41122
|
-
const existed =
|
|
41267
|
+
const existed = existsSync25(target);
|
|
41123
41268
|
writeFileSync16(target, content, "utf-8");
|
|
41124
41269
|
try {
|
|
41125
41270
|
const { Plan: Plan2 } = await Promise.resolve().then(() => (init_plan(), plan_exports));
|
|
41126
|
-
Plan2.recordAction(existed ? "patched" : "created",
|
|
41271
|
+
Plan2.recordAction(existed ? "patched" : "created", relative8(root, target));
|
|
41127
41272
|
} catch {
|
|
41128
41273
|
}
|
|
41129
|
-
res.json({ ok: true, path:
|
|
41274
|
+
res.json({ ok: true, path: relative8(root, target), bytes: Buffer.byteLength(content, "utf-8") });
|
|
41130
41275
|
} catch (e) {
|
|
41131
41276
|
res.json({ error: e.message }, 500);
|
|
41132
41277
|
}
|
|
@@ -41184,7 +41329,7 @@ var init_devAdmin = __esm({
|
|
|
41184
41329
|
res.json({ error: "Invalid path" }, 400);
|
|
41185
41330
|
return;
|
|
41186
41331
|
}
|
|
41187
|
-
if (!
|
|
41332
|
+
if (!existsSync25(src)) {
|
|
41188
41333
|
res.json({ error: `Source not found: ${from}` }, 404);
|
|
41189
41334
|
return;
|
|
41190
41335
|
}
|
|
@@ -41192,7 +41337,7 @@ var init_devAdmin = __esm({
|
|
|
41192
41337
|
const { renameSync: renameSync3 } = await import("node:fs");
|
|
41193
41338
|
mkdirSync19(dirname15(dst), { recursive: true });
|
|
41194
41339
|
renameSync3(src, dst);
|
|
41195
|
-
res.json({ ok: true, from:
|
|
41340
|
+
res.json({ ok: true, from: relative8(root, src), to: relative8(root, dst) });
|
|
41196
41341
|
} catch (e) {
|
|
41197
41342
|
res.json({ error: e.message }, 500);
|
|
41198
41343
|
}
|
|
@@ -41206,14 +41351,14 @@ var init_devAdmin = __esm({
|
|
|
41206
41351
|
res.json({ error: "Invalid path" }, 400);
|
|
41207
41352
|
return;
|
|
41208
41353
|
}
|
|
41209
|
-
if (!
|
|
41354
|
+
if (!existsSync25(target)) {
|
|
41210
41355
|
res.json({ error: `Not found: ${rel}` }, 404);
|
|
41211
41356
|
return;
|
|
41212
41357
|
}
|
|
41213
41358
|
try {
|
|
41214
41359
|
const { rmSync: rmSync2 } = await import("node:fs");
|
|
41215
41360
|
rmSync2(target, { recursive: true, force: true });
|
|
41216
|
-
res.json({ ok: true, deleted:
|
|
41361
|
+
res.json({ ok: true, deleted: relative8(root, target) });
|
|
41217
41362
|
} catch (e) {
|
|
41218
41363
|
res.json({ error: e.message }, 500);
|
|
41219
41364
|
}
|
|
@@ -41248,13 +41393,11 @@ var init_devAdmin = __esm({
|
|
|
41248
41393
|
return;
|
|
41249
41394
|
}
|
|
41250
41395
|
try {
|
|
41251
|
-
const { execFileSync: execFileSync6 } = await import("node:child_process");
|
|
41252
41396
|
const args = ["install", dev ? "--save-dev" : "--save", pkg];
|
|
41253
|
-
const output =
|
|
41397
|
+
const output = execFileSyncAllowingBatch("npm", args, {
|
|
41254
41398
|
cwd: resolve17(process.cwd()),
|
|
41255
|
-
timeout: 12e4
|
|
41256
|
-
|
|
41257
|
-
}).toString();
|
|
41399
|
+
timeout: 12e4
|
|
41400
|
+
});
|
|
41258
41401
|
res.json({ ok: true, package: pkg, output });
|
|
41259
41402
|
} catch (e) {
|
|
41260
41403
|
res.json({ error: e.message }, 500);
|
|
@@ -41262,15 +41405,15 @@ var init_devAdmin = __esm({
|
|
|
41262
41405
|
};
|
|
41263
41406
|
handleGitStatus = async (_req, res) => {
|
|
41264
41407
|
try {
|
|
41265
|
-
const { execFileSync:
|
|
41408
|
+
const { execFileSync: execFileSync5 } = await import("node:child_process");
|
|
41266
41409
|
const cwd = resolve17(process.cwd());
|
|
41267
41410
|
try {
|
|
41268
|
-
|
|
41411
|
+
execFileSync5("git", ["rev-parse", "--is-inside-work-tree"], { cwd, timeout: 3e3 });
|
|
41269
41412
|
} catch {
|
|
41270
41413
|
res.json({ error: "Not a git repository" }, 400);
|
|
41271
41414
|
return;
|
|
41272
41415
|
}
|
|
41273
|
-
const run = (args) =>
|
|
41416
|
+
const run = (args) => execFileSync5("git", args, { cwd, timeout: 3e3, encoding: "utf-8" }).toString().trim();
|
|
41274
41417
|
res.json({
|
|
41275
41418
|
branch: run(["branch", "--show-current"]),
|
|
41276
41419
|
status: run(["status", "--porcelain"]).split(/\r?\n/).filter((l) => l),
|
|
@@ -41400,12 +41543,10 @@ var init_devAdmin = __esm({
|
|
|
41400
41543
|
return;
|
|
41401
41544
|
}
|
|
41402
41545
|
try {
|
|
41403
|
-
const
|
|
41404
|
-
const output = execFileSync6("npx", ["tina4nodejs", "generate", kind, name], {
|
|
41546
|
+
const output = execFileSyncAllowingBatch("npx", ["tina4nodejs", "generate", kind, name], {
|
|
41405
41547
|
cwd: resolve17(process.cwd()),
|
|
41406
|
-
timeout: 3e4
|
|
41407
|
-
|
|
41408
|
-
}).toString();
|
|
41548
|
+
timeout: 3e4
|
|
41549
|
+
});
|
|
41409
41550
|
res.json({ ok: true, kind, name, output });
|
|
41410
41551
|
} catch (e) {
|
|
41411
41552
|
res.json({ error: e.message }, 500);
|
|
@@ -41547,21 +41688,21 @@ var init_devAdmin = __esm({
|
|
|
41547
41688
|
});
|
|
41548
41689
|
};
|
|
41549
41690
|
handleDevAdminJs = async (_req, res) => {
|
|
41550
|
-
const { readFileSync: readFileSync30, existsSync:
|
|
41551
|
-
const { dirname: dirname20, join:
|
|
41552
|
-
const { fileURLToPath:
|
|
41553
|
-
const dir = dirname20(
|
|
41691
|
+
const { readFileSync: readFileSync30, existsSync: existsSync39 } = await import("node:fs");
|
|
41692
|
+
const { dirname: dirname20, join: join42, resolve: resolve29 } = await import("node:path");
|
|
41693
|
+
const { fileURLToPath: fileURLToPath13 } = await import("node:url");
|
|
41694
|
+
const dir = dirname20(fileURLToPath13(import.meta.url));
|
|
41554
41695
|
const candidates = [
|
|
41555
|
-
|
|
41696
|
+
join42(dir, "..", "public", "js", "tina4-dev-admin.min.js"),
|
|
41556
41697
|
// src/../public/js/
|
|
41557
|
-
|
|
41698
|
+
join42(dir, "..", "..", "public", "js", "tina4-dev-admin.min.js"),
|
|
41558
41699
|
// deeper nesting
|
|
41559
41700
|
resolve29(process.cwd(), "node_modules", "tina4-nodejs", "packages", "core", "public", "js", "tina4-dev-admin.min.js"),
|
|
41560
41701
|
resolve29(process.cwd(), "public", "js", "tina4-dev-admin.min.js")
|
|
41561
41702
|
// project public/
|
|
41562
41703
|
];
|
|
41563
41704
|
for (const jsPath of candidates) {
|
|
41564
|
-
if (
|
|
41705
|
+
if (existsSync39(jsPath)) {
|
|
41565
41706
|
try {
|
|
41566
41707
|
const content = readFileSync30(jsPath, "utf-8");
|
|
41567
41708
|
res.raw.writeHead(200, { "Content-Type": "application/javascript; charset=utf-8", "Cache-Control": "no-cache" });
|
|
@@ -41575,20 +41716,20 @@ var init_devAdmin = __esm({
|
|
|
41575
41716
|
res.raw.end("tina4-dev-admin.min.js not found");
|
|
41576
41717
|
};
|
|
41577
41718
|
handleDevAdminSplit = async (_req, res) => {
|
|
41578
|
-
const { readFileSync: readFileSync30, existsSync:
|
|
41579
|
-
const { dirname: dirname20, join:
|
|
41580
|
-
const { fileURLToPath:
|
|
41581
|
-
const dir = dirname20(
|
|
41719
|
+
const { readFileSync: readFileSync30, existsSync: existsSync39 } = await import("node:fs");
|
|
41720
|
+
const { dirname: dirname20, join: join42, resolve: resolve29 } = await import("node:path");
|
|
41721
|
+
const { fileURLToPath: fileURLToPath13 } = await import("node:url");
|
|
41722
|
+
const dir = dirname20(fileURLToPath13(import.meta.url));
|
|
41582
41723
|
const candidates = [
|
|
41583
|
-
|
|
41584
|
-
|
|
41724
|
+
join42(dir, "..", "public", "js", "tina4-dev-admin-split.html"),
|
|
41725
|
+
join42(dir, "..", "..", "public", "js", "tina4-dev-admin-split.html"),
|
|
41585
41726
|
resolve29(process.cwd(), "node_modules", "tina4-nodejs", "packages", "core", "public", "js", "tina4-dev-admin-split.html"),
|
|
41586
41727
|
resolve29(process.cwd(), "public", "js", "tina4-dev-admin-split.html")
|
|
41587
41728
|
];
|
|
41588
|
-
for (const
|
|
41589
|
-
if (
|
|
41729
|
+
for (const path9 of candidates) {
|
|
41730
|
+
if (existsSync39(path9)) {
|
|
41590
41731
|
try {
|
|
41591
|
-
const content = readFileSync30(
|
|
41732
|
+
const content = readFileSync30(path9, "utf-8");
|
|
41592
41733
|
res.raw.writeHead(200, { "Content-Type": "text/html; charset=utf-8", "Cache-Control": "no-cache" });
|
|
41593
41734
|
res.raw.end(content);
|
|
41594
41735
|
return;
|
|
@@ -41611,8 +41752,8 @@ var init_devAdmin = __esm({
|
|
|
41611
41752
|
});
|
|
41612
41753
|
|
|
41613
41754
|
// ../core/src/i18n.ts
|
|
41614
|
-
import { readFileSync as readFileSync21, readdirSync as readdirSync17, existsSync as
|
|
41615
|
-
import { join as
|
|
41755
|
+
import { readFileSync as readFileSync21, readdirSync as readdirSync17, existsSync as existsSync26 } from "node:fs";
|
|
41756
|
+
import { join as join31, resolve as resolve18 } from "node:path";
|
|
41616
41757
|
var I18n;
|
|
41617
41758
|
var init_i18n = __esm({
|
|
41618
41759
|
"../core/src/i18n.ts"() {
|
|
@@ -41631,9 +41772,9 @@ var init_i18n = __esm({
|
|
|
41631
41772
|
* Arg order is (locale, path) to match the Python master `I18n(locale, path)`
|
|
41632
41773
|
* (BUG-7, BREAKING in 3.13.x — was previously (localeDir, defaultLocale)).
|
|
41633
41774
|
*/
|
|
41634
|
-
constructor(locale,
|
|
41775
|
+
constructor(locale, path9) {
|
|
41635
41776
|
this._localeDir = resolve18(
|
|
41636
|
-
|
|
41777
|
+
path9 ?? process.env.TINA4_LOCALE_DIR ?? "src/locales"
|
|
41637
41778
|
);
|
|
41638
41779
|
this._defaultLocale = locale ?? process.env.TINA4_LOCALE ?? "en";
|
|
41639
41780
|
this._currentLocale = this._defaultLocale;
|
|
@@ -41689,7 +41830,7 @@ var init_i18n = __esm({
|
|
|
41689
41830
|
}
|
|
41690
41831
|
/** List available locale codes based on JSON files in the locale directory. */
|
|
41691
41832
|
availableLocales() {
|
|
41692
|
-
if (!
|
|
41833
|
+
if (!existsSync26(this._localeDir)) {
|
|
41693
41834
|
return [this._defaultLocale];
|
|
41694
41835
|
}
|
|
41695
41836
|
try {
|
|
@@ -41705,8 +41846,8 @@ var init_i18n = __esm({
|
|
|
41705
41846
|
if (this._translations.has(locale)) {
|
|
41706
41847
|
return;
|
|
41707
41848
|
}
|
|
41708
|
-
const filePath =
|
|
41709
|
-
if (
|
|
41849
|
+
const filePath = join31(this._localeDir, `${locale}.json`);
|
|
41850
|
+
if (existsSync26(filePath)) {
|
|
41710
41851
|
try {
|
|
41711
41852
|
const raw = readFileSync21(filePath, "utf-8");
|
|
41712
41853
|
const data = JSON.parse(raw);
|
|
@@ -41718,8 +41859,8 @@ var init_i18n = __esm({
|
|
|
41718
41859
|
}
|
|
41719
41860
|
}
|
|
41720
41861
|
for (const ext of [".yml", ".yaml"]) {
|
|
41721
|
-
const yamlPath =
|
|
41722
|
-
if (
|
|
41862
|
+
const yamlPath = join31(this._localeDir, `${locale}${ext}`);
|
|
41863
|
+
if (existsSync26(yamlPath)) {
|
|
41723
41864
|
try {
|
|
41724
41865
|
const raw = readFileSync21(yamlPath, "utf-8");
|
|
41725
41866
|
const data = _I18n._parseSimpleYaml(raw);
|
|
@@ -43244,11 +43385,11 @@ __export(docsAutoDiscovery_exports, {
|
|
|
43244
43385
|
writeMcpDiscovery: () => writeMcpDiscovery
|
|
43245
43386
|
});
|
|
43246
43387
|
import * as fs9 from "node:fs";
|
|
43247
|
-
import * as
|
|
43388
|
+
import * as path8 from "node:path";
|
|
43248
43389
|
function writeMcpDiscovery(projectRoot3, port) {
|
|
43249
|
-
const root =
|
|
43250
|
-
const tinaDir =
|
|
43251
|
-
const mcpPath =
|
|
43390
|
+
const root = path8.resolve(projectRoot3);
|
|
43391
|
+
const tinaDir = path8.join(root, TINA4_DIR);
|
|
43392
|
+
const mcpPath = path8.join(tinaDir, MCP_FILE);
|
|
43252
43393
|
const portStr = String(
|
|
43253
43394
|
port || Number(process.env.TINA4_PORT) || Number(process.env.PORT) || 7148
|
|
43254
43395
|
);
|
|
@@ -43275,9 +43416,9 @@ function writeMcpDiscovery(projectRoot3, port) {
|
|
|
43275
43416
|
fs9.writeFileSync(mcpPath, desiredJson, "utf-8");
|
|
43276
43417
|
wrote = true;
|
|
43277
43418
|
}
|
|
43278
|
-
const gitDir =
|
|
43419
|
+
const gitDir = path8.join(root, ".git");
|
|
43279
43420
|
if (fs9.existsSync(gitDir)) {
|
|
43280
|
-
const gitignorePath =
|
|
43421
|
+
const gitignorePath = path8.join(root, ".gitignore");
|
|
43281
43422
|
let contents = "";
|
|
43282
43423
|
if (fs9.existsSync(gitignorePath)) {
|
|
43283
43424
|
try {
|
|
@@ -43288,8 +43429,8 @@ function writeMcpDiscovery(projectRoot3, port) {
|
|
|
43288
43429
|
const lines = contents.split(/\r?\n/);
|
|
43289
43430
|
const already = lines.some((l) => l.trim() === GITIGNORE_LINE || l.trim() === ".tina4");
|
|
43290
43431
|
if (!already) {
|
|
43291
|
-
const
|
|
43292
|
-
fs9.writeFileSync(gitignorePath, `${contents}${
|
|
43432
|
+
const sep10 = contents.endsWith("\n") || contents === "" ? "" : "\n";
|
|
43433
|
+
fs9.writeFileSync(gitignorePath, `${contents}${sep10}${GITIGNORE_LINE}
|
|
43293
43434
|
`, "utf-8");
|
|
43294
43435
|
}
|
|
43295
43436
|
}
|
|
@@ -43306,12 +43447,39 @@ var init_docsAutoDiscovery = __esm({
|
|
|
43306
43447
|
});
|
|
43307
43448
|
|
|
43308
43449
|
// ../core/src/server.ts
|
|
43450
|
+
var server_exports = {};
|
|
43451
|
+
__export(server_exports, {
|
|
43452
|
+
CI_ENVIRONMENT_VARIABLES: () => CI_ENVIRONMENT_VARIABLES,
|
|
43453
|
+
CI_NOT_SET_VALUES: () => CI_NOT_SET_VALUES,
|
|
43454
|
+
DEFAULT_SHUTDOWN_TIMEOUT_SECONDS: () => DEFAULT_SHUTDOWN_TIMEOUT_SECONDS,
|
|
43455
|
+
_checkLegacyEnvVars: () => _checkLegacyEnvVars,
|
|
43456
|
+
autoMigrateOnStartup: () => autoMigrateOnStartup,
|
|
43457
|
+
bannerSurfaceLines: () => bannerSurfaceLines,
|
|
43458
|
+
buildDispatchContext: () => buildDispatchContext,
|
|
43459
|
+
getLiveDispatchContext: () => getLiveDispatchContext,
|
|
43460
|
+
handle: () => handle,
|
|
43461
|
+
httpReason: () => httpReason,
|
|
43462
|
+
isBannerSuppressed: () => isBannerSuppressed,
|
|
43463
|
+
killPort: () => killPort,
|
|
43464
|
+
loopbackBindHosts: () => loopbackBindHosts,
|
|
43465
|
+
resetTemplateCache: () => resetTemplateCache,
|
|
43466
|
+
resolveHandlerArgs: () => resolveHandlerArgs,
|
|
43467
|
+
resolvePortAndHost: () => resolvePortAndHost,
|
|
43468
|
+
resolveTemplate: () => resolveTemplate,
|
|
43469
|
+
runDispatch: () => runDispatch,
|
|
43470
|
+
shouldOpenBrowser: () => shouldOpenBrowser,
|
|
43471
|
+
shutdownTimeoutSeconds: () => shutdownTimeoutSeconds,
|
|
43472
|
+
start: () => start,
|
|
43473
|
+
startServer: () => startServer,
|
|
43474
|
+
stop: () => stop,
|
|
43475
|
+
templateAutoRoutingEnabled: () => templateAutoRoutingEnabled
|
|
43476
|
+
});
|
|
43309
43477
|
import { randomBytes as randomBytes9 } from "node:crypto";
|
|
43310
|
-
import { resolve as resolve20, dirname as dirname16, join as
|
|
43311
|
-
import { existsSync as
|
|
43478
|
+
import { resolve as resolve20, dirname as dirname16, join as join33, relative as relative9 } from "node:path";
|
|
43479
|
+
import { existsSync as existsSync28, readdirSync as readdirSync18, readFileSync as readFileSync23, statSync as statSync20 } from "node:fs";
|
|
43312
43480
|
import { isatty } from "node:tty";
|
|
43313
|
-
import { fileURLToPath as
|
|
43314
|
-
import {
|
|
43481
|
+
import { fileURLToPath as fileURLToPath10 } from "node:url";
|
|
43482
|
+
import { execFile } from "node:child_process";
|
|
43315
43483
|
import cluster from "node:cluster";
|
|
43316
43484
|
import os2 from "node:os";
|
|
43317
43485
|
function isSwaggerAssetPath(pathname) {
|
|
@@ -43345,9 +43513,35 @@ function swaggerAdvertised() {
|
|
|
43345
43513
|
}
|
|
43346
43514
|
return TRUTHY3.includes(raw);
|
|
43347
43515
|
}
|
|
43516
|
+
function stripUrlCredentials(text) {
|
|
43517
|
+
return text.replace(/:\/\/[^/\s]*@/g, "://");
|
|
43518
|
+
}
|
|
43519
|
+
function isModuleNotFound(err) {
|
|
43520
|
+
const code = err?.code;
|
|
43521
|
+
return code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND";
|
|
43522
|
+
}
|
|
43523
|
+
function reportOrmBootFailure(stage, err, dbConfig) {
|
|
43524
|
+
const message = stripUrlCredentials(err instanceof Error ? err.message : String(err));
|
|
43525
|
+
if (stage === "connect") {
|
|
43526
|
+
const url = (process.env.TINA4_DATABASE_URL ?? "").trim();
|
|
43527
|
+
const target = url ? stripUrlCredentials(url) : `${dbConfig.type ?? "sqlite"} ${dbConfig.path ?? "./data/tina4.db"}`;
|
|
43528
|
+
bootDbConnectError = message;
|
|
43529
|
+
console.warn(`
|
|
43530
|
+
Database could not be reached (${target}): ${message}`);
|
|
43531
|
+
} else if (stage === "import" && isModuleNotFound(err)) {
|
|
43532
|
+
console.warn(`
|
|
43533
|
+
ORM not available (install @tina4/orm to enable): ${message}`);
|
|
43534
|
+
} else if (stage === "import") {
|
|
43535
|
+
console.warn(`
|
|
43536
|
+
ORM failed to load:`, err);
|
|
43537
|
+
} else {
|
|
43538
|
+
console.warn(`
|
|
43539
|
+
ORM model setup failed:`, err);
|
|
43540
|
+
}
|
|
43541
|
+
}
|
|
43348
43542
|
async function autoMigrateOnStartup(migrationDir = "migrations", base = process.cwd()) {
|
|
43349
43543
|
const dir = resolve20(base, migrationDir);
|
|
43350
|
-
if (!
|
|
43544
|
+
if (!existsSync28(dir)) return;
|
|
43351
43545
|
let hasSql = false;
|
|
43352
43546
|
try {
|
|
43353
43547
|
hasSql = readdirSync18(dir).some((f) => f.endsWith(".sql") && !f.endsWith(".down.sql"));
|
|
@@ -43363,9 +43557,20 @@ async function autoMigrateOnStartup(migrationDir = "migrations", base = process.
|
|
|
43363
43557
|
let orm;
|
|
43364
43558
|
try {
|
|
43365
43559
|
orm = await Promise.resolve().then(() => (init_src(), src_exports));
|
|
43560
|
+
} catch (err) {
|
|
43561
|
+
Log.debug(`Startup migrations skipped (ORM not available): ${stripUrlCredentials(err instanceof Error ? err.message : String(err))}`);
|
|
43562
|
+
return;
|
|
43563
|
+
}
|
|
43564
|
+
try {
|
|
43366
43565
|
orm.getAdapter();
|
|
43367
43566
|
} catch (err) {
|
|
43368
|
-
|
|
43567
|
+
const configuredUrl = (process.env.TINA4_DATABASE_URL ?? "").trim();
|
|
43568
|
+
const cause = stripUrlCredentials(bootDbConnectError ?? (err instanceof Error ? err.message : String(err)));
|
|
43569
|
+
if (configuredUrl) {
|
|
43570
|
+
Log.debug(`Startup migrations skipped (database configured but could not connect to ${stripUrlCredentials(configuredUrl)}): ${cause}`);
|
|
43571
|
+
} else {
|
|
43572
|
+
Log.debug(`Startup migrations skipped (no database configured): ${cause}`);
|
|
43573
|
+
}
|
|
43369
43574
|
return;
|
|
43370
43575
|
}
|
|
43371
43576
|
try {
|
|
@@ -43426,17 +43631,8 @@ function killPort(port) {
|
|
|
43426
43631
|
}
|
|
43427
43632
|
}
|
|
43428
43633
|
function findAvailablePort(start2) {
|
|
43429
|
-
|
|
43430
|
-
|
|
43431
|
-
const s = require("net").createServer();
|
|
43432
|
-
s.listen(${start2}, "0.0.0.0", () => { s.close(); process.exit(0); });
|
|
43433
|
-
s.on("error", () => process.exit(1));
|
|
43434
|
-
`], { timeout: 1e3 });
|
|
43435
|
-
return start2;
|
|
43436
|
-
} catch {
|
|
43437
|
-
killPort(start2);
|
|
43438
|
-
return start2;
|
|
43439
|
-
}
|
|
43634
|
+
if (probeBind("0.0.0.0", start2) === "held") killPort(start2);
|
|
43635
|
+
return start2;
|
|
43440
43636
|
}
|
|
43441
43637
|
function shouldOpenBrowser(isDevelopment, noBrowser = false) {
|
|
43442
43638
|
if (!isDevelopment || isTruthy(process.env.TINA4_PRODUCTION) || cluster.isWorker) return false;
|
|
@@ -43498,12 +43694,12 @@ async function renderErrorPage(code, data, templatesDir) {
|
|
|
43498
43694
|
}
|
|
43499
43695
|
return instance;
|
|
43500
43696
|
};
|
|
43501
|
-
const userTemplatePath =
|
|
43502
|
-
if (
|
|
43697
|
+
const userTemplatePath = join33(templatesDir, templateFile);
|
|
43698
|
+
if (existsSync28(userTemplatePath)) {
|
|
43503
43699
|
return getCachedFrond(templatesDir).render(templateFile, data);
|
|
43504
43700
|
}
|
|
43505
|
-
const builtinTemplatePath =
|
|
43506
|
-
if (
|
|
43701
|
+
const builtinTemplatePath = join33(BUILTIN_ERROR_TEMPLATES_DIR, templateFile);
|
|
43702
|
+
if (existsSync28(builtinTemplatePath)) {
|
|
43507
43703
|
return getCachedFrond(BUILTIN_ERROR_TEMPLATES_DIR).render(templateFile, data);
|
|
43508
43704
|
}
|
|
43509
43705
|
return null;
|
|
@@ -43520,10 +43716,10 @@ function injectDevToolbar(html, ctx) {
|
|
|
43520
43716
|
}
|
|
43521
43717
|
function walkGalleryFiles(dir) {
|
|
43522
43718
|
const results = [];
|
|
43523
|
-
if (!
|
|
43719
|
+
if (!existsSync28(dir)) return results;
|
|
43524
43720
|
for (const f of readdirSync18(dir)) {
|
|
43525
|
-
const full =
|
|
43526
|
-
if (
|
|
43721
|
+
const full = join33(dir, f);
|
|
43722
|
+
if (statSync20(full).isDirectory()) results.push(...walkGalleryFiles(full));
|
|
43527
43723
|
else results.push(full);
|
|
43528
43724
|
}
|
|
43529
43725
|
return results;
|
|
@@ -43531,18 +43727,18 @@ function walkGalleryFiles(dir) {
|
|
|
43531
43727
|
function getGalleryDeployedState() {
|
|
43532
43728
|
const galleryDir = resolve20(__dirname, "..", "gallery");
|
|
43533
43729
|
const state = {};
|
|
43534
|
-
if (!
|
|
43730
|
+
if (!existsSync28(galleryDir)) return state;
|
|
43535
43731
|
try {
|
|
43536
43732
|
const entries = readdirSync18(galleryDir).sort();
|
|
43537
43733
|
for (const entry of entries) {
|
|
43538
|
-
const entryPath =
|
|
43539
|
-
const metaFile =
|
|
43540
|
-
if (
|
|
43541
|
-
const srcDir =
|
|
43542
|
-
if (
|
|
43734
|
+
const entryPath = join33(galleryDir, entry);
|
|
43735
|
+
const metaFile = join33(entryPath, "meta.json");
|
|
43736
|
+
if (statSync20(entryPath).isDirectory() && existsSync28(metaFile)) {
|
|
43737
|
+
const srcDir = join33(entryPath, "src");
|
|
43738
|
+
if (existsSync28(srcDir)) {
|
|
43543
43739
|
const files = walkGalleryFiles(srcDir);
|
|
43544
43740
|
const projectSrc = resolve20(process.cwd(), "src");
|
|
43545
|
-
state[entry] = files.every((f) =>
|
|
43741
|
+
state[entry] = files.every((f) => existsSync28(join33(projectSrc, relative9(srcDir, f))));
|
|
43546
43742
|
} else {
|
|
43547
43743
|
state[entry] = false;
|
|
43548
43744
|
}
|
|
@@ -43573,7 +43769,7 @@ function resolveTemplate(pathname, templatesDir) {
|
|
|
43573
43769
|
if (cleanPath.includes("\\") || cleanPath.split("/").some((seg) => seg === "" || seg === "." || seg === "..")) return null;
|
|
43574
43770
|
const pagesDir = resolve20(templatesDir, TEMPLATE_PAGES_DIR);
|
|
43575
43771
|
for (const ext of [".twig", ".html"]) {
|
|
43576
|
-
if (
|
|
43772
|
+
if (existsSync28(resolve20(pagesDir, cleanPath + ext))) {
|
|
43577
43773
|
return `${TEMPLATE_PAGES_DIR}/${cleanPath}${ext}`;
|
|
43578
43774
|
}
|
|
43579
43775
|
}
|
|
@@ -43582,7 +43778,7 @@ function resolveTemplate(pathname, templatesDir) {
|
|
|
43582
43778
|
if (!templateCache) {
|
|
43583
43779
|
templateCache = /* @__PURE__ */ new Map();
|
|
43584
43780
|
const pagesDir = resolve20(templatesDir, TEMPLATE_PAGES_DIR);
|
|
43585
|
-
if (
|
|
43781
|
+
if (existsSync28(pagesDir)) {
|
|
43586
43782
|
const scan = (dir, prefix) => {
|
|
43587
43783
|
for (const entry of readdirSync18(dir, { withFileTypes: true })) {
|
|
43588
43784
|
if (entry.name.startsWith("_")) continue;
|
|
@@ -44050,9 +44246,9 @@ function serveMethodNotAllowed(ctx) {
|
|
|
44050
44246
|
}
|
|
44051
44247
|
function serveStaticAsset(ctx) {
|
|
44052
44248
|
const custom = process.env.TINA4_PUBLIC_DIR;
|
|
44053
|
-
if (custom &&
|
|
44054
|
-
if (
|
|
44055
|
-
if (
|
|
44249
|
+
if (custom && existsSync28(custom) && tryServeStatic(custom, ctx.req, ctx.res)) return true;
|
|
44250
|
+
if (existsSync28(ctx.staticDir) && tryServeStatic(ctx.staticDir, ctx.req, ctx.res)) return true;
|
|
44251
|
+
if (existsSync28(ctx.srcPublicDir) && tryServeStatic(ctx.srcPublicDir, ctx.req, ctx.res)) return true;
|
|
44056
44252
|
if (ctx.swaggerAssetsEnabled || !isSwaggerAssetPath(ctx.pathname)) {
|
|
44057
44253
|
if (tryServeStatic(BUILTIN_PUBLIC_DIR, ctx.req, ctx.res)) return true;
|
|
44058
44254
|
}
|
|
@@ -44266,6 +44462,9 @@ function startProductionCluster(port, host) {
|
|
|
44266
44462
|
Debug: OFF (Log level: ${logLevel})
|
|
44267
44463
|
${reset2}`);
|
|
44268
44464
|
}
|
|
44465
|
+
if (process.env.NODE_CLUSTER_SCHED_POLICY === void 0) {
|
|
44466
|
+
cluster.schedulingPolicy = cluster.SCHED_RR;
|
|
44467
|
+
}
|
|
44269
44468
|
for (let i = 0; i < numCPUs; i++) cluster.fork();
|
|
44270
44469
|
cluster.on("exit", (worker, code) => {
|
|
44271
44470
|
if (code !== 0) {
|
|
@@ -44285,12 +44484,13 @@ ${reset2}`);
|
|
|
44285
44484
|
function wireLocaleGlobal(frondEngine, base) {
|
|
44286
44485
|
if (!frondEngine) return;
|
|
44287
44486
|
const localeDir = resolve20(base, process.env.TINA4_LOCALE_DIR ?? "src/locales");
|
|
44288
|
-
if (!
|
|
44487
|
+
if (!existsSync28(localeDir)) return;
|
|
44289
44488
|
try {
|
|
44290
44489
|
const localeFiles = readdirSync18(localeDir).filter((file) => file.endsWith(".json"));
|
|
44291
|
-
|
|
44490
|
+
const FrondClass = frondEngine.constructor;
|
|
44491
|
+
if (localeFiles.length === 0 || FrondClass.hasGlobal("t") || frondEngine.globals?.t) return;
|
|
44292
44492
|
const i18nInstance = new I18n(process.env.TINA4_LOCALE ?? "en", localeDir);
|
|
44293
|
-
|
|
44493
|
+
FrondClass.addGlobal("t", (key, params) => i18nInstance.t(key, params));
|
|
44294
44494
|
} catch {
|
|
44295
44495
|
}
|
|
44296
44496
|
}
|
|
@@ -44357,7 +44557,7 @@ async function startServer(config) {
|
|
|
44357
44557
|
middleware.use(requestLogger());
|
|
44358
44558
|
middleware.use(rateLimiter());
|
|
44359
44559
|
MiddlewareRunner.use(SecurityHeadersMiddleware);
|
|
44360
|
-
if (
|
|
44560
|
+
if (existsSync28(routesDir)) {
|
|
44361
44561
|
const routes = await discoverRoutes(routesDir);
|
|
44362
44562
|
for (const route of routes) {
|
|
44363
44563
|
router.addRoute(route);
|
|
@@ -44620,16 +44820,20 @@ ${reset2}
|
|
|
44620
44820
|
});
|
|
44621
44821
|
}
|
|
44622
44822
|
async function initializeOrm(config, router, base, ormDir, modelsDir) {
|
|
44623
|
-
const hasOrmDir =
|
|
44624
|
-
const hasModelsDir =
|
|
44823
|
+
const hasOrmDir = existsSync28(ormDir);
|
|
44824
|
+
const hasModelsDir = existsSync28(modelsDir);
|
|
44625
44825
|
if (hasOrmDir || hasModelsDir) {
|
|
44826
|
+
let ormStage = "import";
|
|
44827
|
+
const dbConfig = config?.database ?? {};
|
|
44626
44828
|
try {
|
|
44627
44829
|
const orm = await Promise.resolve().then(() => (init_src(), src_exports));
|
|
44628
|
-
|
|
44830
|
+
ormStage = "connect";
|
|
44831
|
+
bootDbConnectError = null;
|
|
44629
44832
|
await orm.initDatabase({
|
|
44630
44833
|
type: dbConfig.type ?? "sqlite",
|
|
44631
44834
|
path: dbConfig.path ?? "./data/tina4.db"
|
|
44632
44835
|
});
|
|
44836
|
+
ormStage = "models";
|
|
44633
44837
|
let models = hasOrmDir ? await orm.discoverModels(ormDir) : [];
|
|
44634
44838
|
if (hasModelsDir) {
|
|
44635
44839
|
const extraModels = await orm.discoverModels(modelsDir);
|
|
@@ -44664,8 +44868,7 @@ async function initializeOrm(config, router, base, ormDir, modelsDir) {
|
|
|
44664
44868
|
}
|
|
44665
44869
|
}
|
|
44666
44870
|
} catch (err) {
|
|
44667
|
-
|
|
44668
|
-
ORM not available (install @tina4/orm to enable):`, err);
|
|
44871
|
+
reportOrmBootFailure(ormStage, err, dbConfig);
|
|
44669
44872
|
}
|
|
44670
44873
|
await autoMigrateOnStartup("migrations", base);
|
|
44671
44874
|
}
|
|
@@ -44681,7 +44884,7 @@ async function configureSwagger(router, ormDir, modelsDir) {
|
|
|
44681
44884
|
let modelDefs = [];
|
|
44682
44885
|
try {
|
|
44683
44886
|
const orm = await Promise.resolve().then(() => (init_src(), src_exports));
|
|
44684
|
-
const allModelDirs = [ormDir, modelsDir].filter((d) =>
|
|
44887
|
+
const allModelDirs = [ormDir, modelsDir].filter((d) => existsSync28(d));
|
|
44685
44888
|
const seenTables = /* @__PURE__ */ new Set();
|
|
44686
44889
|
for (const dir of allModelDirs) {
|
|
44687
44890
|
const discovered = await orm.discoverModels(dir);
|
|
@@ -44703,7 +44906,7 @@ async function configureSwagger(router, ormDir, modelsDir) {
|
|
|
44703
44906
|
}
|
|
44704
44907
|
return enabled;
|
|
44705
44908
|
}
|
|
44706
|
-
var __filename, __dirname, BUILTIN_ERROR_TEMPLATES_DIR, BUILTIN_PUBLIC_DIR, swaggerAssetsEnabled, DEFAULT_SHUTDOWN_TIMEOUT_SECONDS, frondCache2, _LEGACY_ENV_VARS, CI_ENVIRONMENT_VARIABLES, CI_NOT_SET_VALUES, portDeprecationWarned, TEMPLATE_PAGES_DIR, HTTP_REASON_PHRASES, templateCache, _dispatchFn, _liveDispatchContext, _serverHandle, LOOP_WATCHDOG_TICK_MS, FALLBACK_STAGES;
|
|
44909
|
+
var __filename, __dirname, BUILTIN_ERROR_TEMPLATES_DIR, BUILTIN_PUBLIC_DIR, swaggerAssetsEnabled, DEFAULT_SHUTDOWN_TIMEOUT_SECONDS, bootDbConnectError, frondCache2, _LEGACY_ENV_VARS, CI_ENVIRONMENT_VARIABLES, CI_NOT_SET_VALUES, portDeprecationWarned, TEMPLATE_PAGES_DIR, HTTP_REASON_PHRASES, templateCache, _dispatchFn, _liveDispatchContext, _serverHandle, LOOP_WATCHDOG_TICK_MS, FALLBACK_STAGES;
|
|
44707
44910
|
var init_server = __esm({
|
|
44708
44911
|
"../core/src/server.ts"() {
|
|
44709
44912
|
"use strict";
|
|
@@ -44732,12 +44935,13 @@ var init_server = __esm({
|
|
|
44732
44935
|
init_background();
|
|
44733
44936
|
init_tcp();
|
|
44734
44937
|
init_version();
|
|
44735
|
-
__filename =
|
|
44938
|
+
__filename = fileURLToPath10(import.meta.url);
|
|
44736
44939
|
__dirname = dirname16(__filename);
|
|
44737
44940
|
BUILTIN_ERROR_TEMPLATES_DIR = resolve20(__dirname, "..", "templates");
|
|
44738
44941
|
BUILTIN_PUBLIC_DIR = resolve20(__dirname, "..", "public");
|
|
44739
44942
|
swaggerAssetsEnabled = false;
|
|
44740
44943
|
DEFAULT_SHUTDOWN_TIMEOUT_SECONDS = 30;
|
|
44944
|
+
bootDbConnectError = null;
|
|
44741
44945
|
frondCache2 = /* @__PURE__ */ new Map();
|
|
44742
44946
|
_LEGACY_ENV_VARS = {
|
|
44743
44947
|
DATABASE_URL: "TINA4_DATABASE_URL",
|
|
@@ -44973,7 +45177,7 @@ var init_mqttMessage = __esm({
|
|
|
44973
45177
|
import net3 from "node:net";
|
|
44974
45178
|
import tls from "node:tls";
|
|
44975
45179
|
import { randomBytes as randomBytes10 } from "node:crypto";
|
|
44976
|
-
import { existsSync as
|
|
45180
|
+
import { existsSync as existsSync29, readFileSync as readFileSync24 } from "node:fs";
|
|
44977
45181
|
var MqttError, MqttTimeoutError, CONNECT, CONNACK, PUBLISH, PUBACK, SUBSCRIBE, SUBACK, PINGREQ, PINGRESP, DISCONNECT, PROTOCOL_LEVEL, DEFAULT_PORT, DEFAULT_TLS_PORT, DEFAULT_URL, DEFAULT_KEEPALIVE, SUBSCRIPTION_REFUSED, MAX_REMAINING_LENGTH, QOS2_REFUSED_MESSAGE, CONNACK_RETURN_CODES, Mqtt;
|
|
44978
45182
|
var init_mqtt = __esm({
|
|
44979
45183
|
"../core/src/mqtt.ts"() {
|
|
@@ -45176,7 +45380,7 @@ var init_mqtt = __esm({
|
|
|
45176
45380
|
*/
|
|
45177
45381
|
async connect() {
|
|
45178
45382
|
this.closeSocket();
|
|
45179
|
-
if (this.secure && this.tlsVerify && this.caFile && !
|
|
45383
|
+
if (this.secure && this.tlsVerify && this.caFile && !existsSync29(this.caFile)) {
|
|
45180
45384
|
throw new MqttError(
|
|
45181
45385
|
`MQTT CA file not found: ${this.caFile} -- TINA4_MQTT_CA_FILE (or caFile) must point at the broker's CA certificate in PEM form`
|
|
45182
45386
|
);
|
|
@@ -45658,9 +45862,9 @@ var init_mqtt = __esm({
|
|
|
45658
45862
|
});
|
|
45659
45863
|
|
|
45660
45864
|
// ../core/src/service.ts
|
|
45661
|
-
import { readdirSync as readdirSync19, statSync as
|
|
45662
|
-
import { join as
|
|
45663
|
-
import { pathToFileURL } from "node:url";
|
|
45865
|
+
import { readdirSync as readdirSync19, statSync as statSync21, watchFile, unwatchFile } from "node:fs";
|
|
45866
|
+
import { join as join34, extname as extname9 } from "node:path";
|
|
45867
|
+
import { pathToFileURL as pathToFileURL4 } from "node:url";
|
|
45664
45868
|
function matchCronField(field, value) {
|
|
45665
45869
|
if (field === "*") return true;
|
|
45666
45870
|
if (field.includes("/")) {
|
|
@@ -45831,13 +46035,13 @@ var init_service = __esm({
|
|
|
45831
46035
|
return discovered;
|
|
45832
46036
|
}
|
|
45833
46037
|
for (const entry of entries) {
|
|
45834
|
-
const ext =
|
|
46038
|
+
const ext = extname9(entry);
|
|
45835
46039
|
if (ext !== ".ts" && ext !== ".js") continue;
|
|
45836
|
-
const fullPath =
|
|
45837
|
-
const stat =
|
|
46040
|
+
const fullPath = join34(dir, entry);
|
|
46041
|
+
const stat = statSync21(fullPath);
|
|
45838
46042
|
if (!stat.isFile()) continue;
|
|
45839
46043
|
try {
|
|
45840
|
-
const fileUrl =
|
|
46044
|
+
const fileUrl = pathToFileURL4(fullPath).href;
|
|
45841
46045
|
const mod = await import(fileUrl);
|
|
45842
46046
|
const exp = mod.default ?? mod;
|
|
45843
46047
|
if (exp.name && typeof exp.handler === "function") {
|
|
@@ -45958,13 +46162,13 @@ var init_service = __esm({
|
|
|
45958
46162
|
return;
|
|
45959
46163
|
}
|
|
45960
46164
|
for (const entry of entries) {
|
|
45961
|
-
const ext =
|
|
46165
|
+
const ext = extname9(entry);
|
|
45962
46166
|
if (ext !== ".ts" && ext !== ".js") continue;
|
|
45963
|
-
const fullPath =
|
|
46167
|
+
const fullPath = join34(dir, entry);
|
|
45964
46168
|
if (watchedFiles.has(fullPath)) continue;
|
|
45965
46169
|
watchedFiles.add(fullPath);
|
|
45966
46170
|
watchFile(fullPath, { interval: 1e3 }, async () => {
|
|
45967
|
-
const fileUrl =
|
|
46171
|
+
const fileUrl = pathToFileURL4(fullPath).href;
|
|
45968
46172
|
try {
|
|
45969
46173
|
const mod = await import(fileUrl + "?t=" + Date.now());
|
|
45970
46174
|
const exp = mod.default ?? mod;
|
|
@@ -46227,23 +46431,23 @@ function guessContentType(filename) {
|
|
|
46227
46431
|
}
|
|
46228
46432
|
function buildMultipartBody(boundary, fieldName, filename, fileContent, contentType, extraFields) {
|
|
46229
46433
|
const crlf = "\r\n";
|
|
46230
|
-
const
|
|
46434
|
+
const delimiter5 = `--${boundary}`;
|
|
46231
46435
|
const parts = [];
|
|
46232
46436
|
if (extraFields) {
|
|
46233
46437
|
for (const [key, value] of Object.entries(extraFields)) {
|
|
46234
|
-
parts.push(Buffer.from(
|
|
46438
|
+
parts.push(Buffer.from(delimiter5 + crlf, "utf-8"));
|
|
46235
46439
|
parts.push(Buffer.from(`Content-Disposition: form-data; name="${key}"` + crlf + crlf, "utf-8"));
|
|
46236
46440
|
parts.push(Buffer.from(String(value) + crlf, "utf-8"));
|
|
46237
46441
|
}
|
|
46238
46442
|
}
|
|
46239
|
-
parts.push(Buffer.from(
|
|
46443
|
+
parts.push(Buffer.from(delimiter5 + crlf, "utf-8"));
|
|
46240
46444
|
parts.push(
|
|
46241
46445
|
Buffer.from(`Content-Disposition: form-data; name="${fieldName}"; filename="${filename}"` + crlf, "utf-8")
|
|
46242
46446
|
);
|
|
46243
46447
|
parts.push(Buffer.from(`Content-Type: ${contentType}` + crlf + crlf, "utf-8"));
|
|
46244
46448
|
parts.push(fileContent);
|
|
46245
46449
|
parts.push(Buffer.from(crlf, "utf-8"));
|
|
46246
|
-
parts.push(Buffer.from(
|
|
46450
|
+
parts.push(Buffer.from(delimiter5 + "--" + crlf, "utf-8"));
|
|
46247
46451
|
return Buffer.concat(parts);
|
|
46248
46452
|
}
|
|
46249
46453
|
async function* parseLineStream(chunks) {
|
|
@@ -46490,8 +46694,8 @@ var init_api = __esm({
|
|
|
46490
46694
|
/**
|
|
46491
46695
|
* HTTP GET request.
|
|
46492
46696
|
*/
|
|
46493
|
-
async get(
|
|
46494
|
-
let url = this.buildUrl(
|
|
46697
|
+
async get(path9, params) {
|
|
46698
|
+
let url = this.buildUrl(path9);
|
|
46495
46699
|
if (params && Object.keys(params).length > 0) {
|
|
46496
46700
|
const qs = new URLSearchParams(params).toString();
|
|
46497
46701
|
url += (url.includes("?") ? "&" : "?") + qs;
|
|
@@ -46501,32 +46705,32 @@ var init_api = __esm({
|
|
|
46501
46705
|
/**
|
|
46502
46706
|
* HTTP POST request.
|
|
46503
46707
|
*/
|
|
46504
|
-
async post(
|
|
46505
|
-
return this.sendRequest("POST",
|
|
46708
|
+
async post(path9, body, contentType = "application/json") {
|
|
46709
|
+
return this.sendRequest("POST", path9, body, contentType);
|
|
46506
46710
|
}
|
|
46507
46711
|
/**
|
|
46508
46712
|
* HTTP PUT request.
|
|
46509
46713
|
*/
|
|
46510
|
-
async put(
|
|
46511
|
-
return this.sendRequest("PUT",
|
|
46714
|
+
async put(path9, body, contentType = "application/json") {
|
|
46715
|
+
return this.sendRequest("PUT", path9, body, contentType);
|
|
46512
46716
|
}
|
|
46513
46717
|
/**
|
|
46514
46718
|
* HTTP PATCH request.
|
|
46515
46719
|
*/
|
|
46516
|
-
async patch(
|
|
46517
|
-
return this.sendRequest("PATCH",
|
|
46720
|
+
async patch(path9, body, contentType = "application/json") {
|
|
46721
|
+
return this.sendRequest("PATCH", path9, body, contentType);
|
|
46518
46722
|
}
|
|
46519
46723
|
/**
|
|
46520
46724
|
* HTTP DELETE request.
|
|
46521
46725
|
*/
|
|
46522
|
-
async delete(
|
|
46523
|
-
return this.sendRequest("DELETE",
|
|
46726
|
+
async delete(path9, body) {
|
|
46727
|
+
return this.sendRequest("DELETE", path9, body);
|
|
46524
46728
|
}
|
|
46525
46729
|
/**
|
|
46526
46730
|
* Generic request method — public entry point for any HTTP method.
|
|
46527
46731
|
*/
|
|
46528
|
-
async sendRequest(method,
|
|
46529
|
-
const url = this.buildUrl(
|
|
46732
|
+
async sendRequest(method, path9, body, contentType = "application/json") {
|
|
46733
|
+
const url = this.buildUrl(path9);
|
|
46530
46734
|
return this.execute(method.toUpperCase(), url, body, contentType);
|
|
46531
46735
|
}
|
|
46532
46736
|
/**
|
|
@@ -46550,7 +46754,7 @@ var init_api = __esm({
|
|
|
46550
46754
|
* await api.upload("/avatars", { fileBytes: raw, filename: "me.png",
|
|
46551
46755
|
* extraFields: { user_id: "42" } });
|
|
46552
46756
|
*/
|
|
46553
|
-
async upload(
|
|
46757
|
+
async upload(path9, opts = {}) {
|
|
46554
46758
|
const { filePath, fieldName = "file", extraFields, headers, fileBytes, filename } = opts;
|
|
46555
46759
|
let content;
|
|
46556
46760
|
let uploadName;
|
|
@@ -46585,7 +46789,7 @@ var init_api = __esm({
|
|
|
46585
46789
|
const boundary = "----Tina4Boundary" + randomBytes11(16).toString("hex");
|
|
46586
46790
|
const bodyBuffer = buildMultipartBody(boundary, fieldName, uploadName, content, partContentType, extraFields);
|
|
46587
46791
|
const contentType = `multipart/form-data; boundary=${boundary}`;
|
|
46588
|
-
return this.execute("POST", this.buildUrl(
|
|
46792
|
+
return this.execute("POST", this.buildUrl(path9), bodyBuffer, contentType, headers);
|
|
46589
46793
|
}
|
|
46590
46794
|
/**
|
|
46591
46795
|
* Stream a GET response body to `destPath` in chunks.
|
|
@@ -46600,11 +46804,11 @@ var init_api = __esm({
|
|
|
46600
46804
|
* dest, HTTP error status, or a transport failure); the destination file is
|
|
46601
46805
|
* not written on error.
|
|
46602
46806
|
*/
|
|
46603
|
-
async download(
|
|
46807
|
+
async download(path9, destPath, params) {
|
|
46604
46808
|
if (!destPath) {
|
|
46605
46809
|
return { http_code: null, headers: {}, error: "download requires destPath", path: null };
|
|
46606
46810
|
}
|
|
46607
|
-
let url = this.buildUrl(
|
|
46811
|
+
let url = this.buildUrl(path9);
|
|
46608
46812
|
if (params && Object.keys(params).length > 0) {
|
|
46609
46813
|
const qs = new URLSearchParams(params).toString();
|
|
46610
46814
|
url += (url.includes("?") ? "&" : "?") + qs;
|
|
@@ -46688,8 +46892,8 @@ var init_api = __esm({
|
|
|
46688
46892
|
* bounds just the connect + headers phase (default
|
|
46689
46893
|
* `TINA4_API_CONNECT_TIMEOUT` or 10s).
|
|
46690
46894
|
*/
|
|
46691
|
-
async *streamBytes(
|
|
46692
|
-
const url = this.buildUrl(
|
|
46895
|
+
async *streamBytes(path9, opts = {}) {
|
|
46896
|
+
const url = this.buildUrl(path9);
|
|
46693
46897
|
const method = (opts.method ?? "GET").toUpperCase();
|
|
46694
46898
|
const contentType = opts.contentType ?? "application/json";
|
|
46695
46899
|
const { headers, data } = this.buildRequest(method, contentType, opts.body, opts.headers, url);
|
|
@@ -46724,8 +46928,8 @@ var init_api = __esm({
|
|
|
46724
46928
|
* yields a trailing line without a terminator on EOF. Built on
|
|
46725
46929
|
* {@link streamBytes} plus the shared {@link parseLineStream}.
|
|
46726
46930
|
*/
|
|
46727
|
-
async *streamLines(
|
|
46728
|
-
yield* parseLineStream(this.streamBytes(
|
|
46931
|
+
async *streamLines(path9, opts = {}) {
|
|
46932
|
+
yield* parseLineStream(this.streamBytes(path9, opts));
|
|
46729
46933
|
}
|
|
46730
46934
|
/**
|
|
46731
46935
|
* Stream the response as SSE (Server-Sent Events). Yields one
|
|
@@ -46734,8 +46938,8 @@ var init_api = __esm({
|
|
|
46734
46938
|
* with `data === "[DONE]"` and the iterator ends on the next EOF.
|
|
46735
46939
|
* Built on {@link streamLines} plus the shared {@link parseSseStream}.
|
|
46736
46940
|
*/
|
|
46737
|
-
async *streamSse(
|
|
46738
|
-
yield* parseSseStream(this.streamLines(
|
|
46941
|
+
async *streamSse(path9, opts = {}) {
|
|
46942
|
+
yield* parseSseStream(this.streamLines(path9, opts));
|
|
46739
46943
|
}
|
|
46740
46944
|
// ── Internal helpers ──────────────────────────────────────────────
|
|
46741
46945
|
/**
|
|
@@ -46801,14 +47005,14 @@ var init_api = __esm({
|
|
|
46801
47005
|
req2.end();
|
|
46802
47006
|
});
|
|
46803
47007
|
}
|
|
46804
|
-
buildUrl(
|
|
46805
|
-
if (
|
|
46806
|
-
return
|
|
47008
|
+
buildUrl(path9) {
|
|
47009
|
+
if (path9.startsWith("http://") || path9.startsWith("https://")) {
|
|
47010
|
+
return path9;
|
|
46807
47011
|
}
|
|
46808
|
-
if (!
|
|
47012
|
+
if (!path9) {
|
|
46809
47013
|
return this.baseUrl;
|
|
46810
47014
|
}
|
|
46811
|
-
return `${this.baseUrl}/${
|
|
47015
|
+
return `${this.baseUrl}/${path9.replace(/^\/+/, "")}`;
|
|
46812
47016
|
}
|
|
46813
47017
|
/**
|
|
46814
47018
|
* The headers configured on the client, as they may go to `targetUrl`.
|
|
@@ -48766,15 +48970,15 @@ __export(ai_exports, {
|
|
|
48766
48970
|
skillBlock: () => skillBlock,
|
|
48767
48971
|
writeOrMerge: () => writeOrMerge
|
|
48768
48972
|
});
|
|
48769
|
-
import { existsSync as
|
|
48973
|
+
import { existsSync as existsSync30, mkdirSync as mkdirSync22, writeFileSync as writeFileSync19, readFileSync as readFileSync26 } from "node:fs";
|
|
48770
48974
|
import { homedir } from "node:os";
|
|
48771
|
-
import { join as
|
|
48772
|
-
import { fileURLToPath as
|
|
48773
|
-
import { execSync as execSync2, execFileSync as
|
|
48975
|
+
import { join as join35, resolve as resolve21, relative as relative10, dirname as dirname17 } from "node:path";
|
|
48976
|
+
import { fileURLToPath as fileURLToPath11 } from "node:url";
|
|
48977
|
+
import { execSync as execSync2, execFileSync as execFileSync3 } from "node:child_process";
|
|
48774
48978
|
import { createInterface } from "node:readline";
|
|
48775
48979
|
function readVersion() {
|
|
48776
48980
|
try {
|
|
48777
|
-
const thisDir = dirname17(
|
|
48981
|
+
const thisDir = dirname17(fileURLToPath11(import.meta.url));
|
|
48778
48982
|
const rootPkg = resolve21(thisDir, "..", "..", "..", "package.json");
|
|
48779
48983
|
const pkg = JSON.parse(readFileSync26(rootPkg, "utf-8"));
|
|
48780
48984
|
return pkg.version ?? "0.0.0";
|
|
@@ -48826,7 +49030,7 @@ function downloadSkillsSync(jobs) {
|
|
|
48826
49030
|
})();
|
|
48827
49031
|
`;
|
|
48828
49032
|
try {
|
|
48829
|
-
const out =
|
|
49033
|
+
const out = execFileSync3(process.execPath, ["-e", child, JSON.stringify(jobs)], {
|
|
48830
49034
|
encoding: "utf-8",
|
|
48831
49035
|
timeout: 5e4,
|
|
48832
49036
|
maxBuffer: 8 * 1024 * 1024
|
|
@@ -48839,8 +49043,8 @@ function downloadSkillsSync(jobs) {
|
|
|
48839
49043
|
function installSkills(root = ".", targets) {
|
|
48840
49044
|
const ref = skillsRef();
|
|
48841
49045
|
const dests = targets ?? [
|
|
48842
|
-
|
|
48843
|
-
|
|
49046
|
+
join35(resolve21(root), ".claude", "skills"),
|
|
49047
|
+
join35(homedir(), ".claude", "skills")
|
|
48844
49048
|
];
|
|
48845
49049
|
const jobs = [];
|
|
48846
49050
|
const index = /* @__PURE__ */ new Map();
|
|
@@ -48858,9 +49062,9 @@ function installSkills(root = ".", targets) {
|
|
|
48858
49062
|
const base = `https://raw.githubusercontent.com/tina4stack/${spec.repo}/${ref}/.claude/skills/${skill}`;
|
|
48859
49063
|
skillMdUrl[skill] = `${base}/SKILL.md`;
|
|
48860
49064
|
for (const dest of dests) {
|
|
48861
|
-
add(`${base}/SKILL.md`,
|
|
49065
|
+
add(`${base}/SKILL.md`, join35(dest, skill, "SKILL.md"));
|
|
48862
49066
|
for (const r of spec.references) {
|
|
48863
|
-
add(`${base}/references/${r}`,
|
|
49067
|
+
add(`${base}/references/${r}`, join35(dest, skill, "references", r));
|
|
48864
49068
|
}
|
|
48865
49069
|
}
|
|
48866
49070
|
}
|
|
@@ -48872,7 +49076,7 @@ function installSkills(root = ".", targets) {
|
|
|
48872
49076
|
return installed;
|
|
48873
49077
|
}
|
|
48874
49078
|
function isInstalled(root, tool) {
|
|
48875
|
-
return
|
|
49079
|
+
return existsSync30(join35(resolve21(root), tool.contextFile));
|
|
48876
49080
|
}
|
|
48877
49081
|
function showMenu(root = ".") {
|
|
48878
49082
|
const r = resolve21(root);
|
|
@@ -48995,7 +49199,7 @@ function looksLikeOldFrameworkInstall(existing) {
|
|
|
48995
49199
|
function writeOrMerge(contextPath, contextFile, frameworkGuide) {
|
|
48996
49200
|
const block = skillBlock(contextFile);
|
|
48997
49201
|
const [start2, end] = markersFor(contextFile);
|
|
48998
|
-
if (!
|
|
49202
|
+
if (!existsSync30(contextPath)) {
|
|
48999
49203
|
writeFileSync19(contextPath, frameworkGuide.replace(/\s+$/, "") + "\n\n" + block + "\n", "utf-8");
|
|
49000
49204
|
return "Installed";
|
|
49001
49205
|
}
|
|
@@ -49016,14 +49220,14 @@ function writeOrMerge(contextPath, contextFile, frameworkGuide) {
|
|
|
49016
49220
|
}
|
|
49017
49221
|
function installForTool(root, tool, context) {
|
|
49018
49222
|
const created = [];
|
|
49019
|
-
const contextPath =
|
|
49223
|
+
const contextPath = join35(root, tool.contextFile);
|
|
49020
49224
|
if (tool.configDir) {
|
|
49021
|
-
mkdirSync22(
|
|
49225
|
+
mkdirSync22(join35(root, tool.configDir), { recursive: true });
|
|
49022
49226
|
}
|
|
49023
49227
|
const parentDir = dirname17(contextPath);
|
|
49024
49228
|
mkdirSync22(parentDir, { recursive: true });
|
|
49025
49229
|
const action = writeOrMerge(contextPath, tool.contextFile, context);
|
|
49026
|
-
const rel =
|
|
49230
|
+
const rel = relative10(root, contextPath);
|
|
49027
49231
|
created.push(rel);
|
|
49028
49232
|
console.log(` ${GREEN2}\u2713${RESET2} ${action} ${rel}`);
|
|
49029
49233
|
if (tool.name === "claude-code") {
|
|
@@ -49056,7 +49260,7 @@ function installTina4Ai() {
|
|
|
49056
49260
|
function installClaudeSkills(root) {
|
|
49057
49261
|
const created = [];
|
|
49058
49262
|
for (const skill of installSkills(root)) {
|
|
49059
|
-
created.push(
|
|
49263
|
+
created.push(join35(".claude", "skills", skill));
|
|
49060
49264
|
console.log(` ${GREEN2}\u2713${RESET2} Installed .claude/skills/${skill} (project + global)`);
|
|
49061
49265
|
}
|
|
49062
49266
|
return created;
|
|
@@ -49397,10 +49601,10 @@ import { tests, assertEqual, runAll } from "tina4-nodejs";
|
|
|
49397
49601
|
}
|
|
49398
49602
|
function generateClaudeCodeContext() {
|
|
49399
49603
|
try {
|
|
49400
|
-
const thisDir = dirname17(
|
|
49604
|
+
const thisDir = dirname17(fileURLToPath11(import.meta.url));
|
|
49401
49605
|
const repoRoot = resolve21(thisDir, "..", "..", "..");
|
|
49402
|
-
const claudeMdPath =
|
|
49403
|
-
if (
|
|
49606
|
+
const claudeMdPath = join35(repoRoot, "CLAUDE.md");
|
|
49607
|
+
if (existsSync30(claudeMdPath)) {
|
|
49404
49608
|
return readFileSync26(claudeMdPath, "utf-8");
|
|
49405
49609
|
}
|
|
49406
49610
|
} catch {
|
|
@@ -50061,10 +50265,10 @@ var init_aiClient = __esm({
|
|
|
50061
50265
|
throw new AiConfigError("AI URL must be an http or https URL");
|
|
50062
50266
|
}
|
|
50063
50267
|
if (url.protocol !== "http:" && url.protocol !== "https:") throw new AiConfigError("AI URL must be an http or https URL");
|
|
50064
|
-
const
|
|
50065
|
-
if (
|
|
50268
|
+
const path9 = rtrimSlashes(url.pathname);
|
|
50269
|
+
if (path9 === "" || path9 === "/v1" || path9 === "/api" || path9 === "/v1beta/openai") {
|
|
50066
50270
|
const suffix = provider === "anthropic" ? "/messages" : capability === "embed" ? "/embeddings" : "/chat/completions";
|
|
50067
|
-
url.pathname = (
|
|
50271
|
+
url.pathname = (path9 || "/v1") + suffix;
|
|
50068
50272
|
}
|
|
50069
50273
|
return url.toString();
|
|
50070
50274
|
}
|
|
@@ -50580,7 +50784,7 @@ var init_aiClient = __esm({
|
|
|
50580
50784
|
});
|
|
50581
50785
|
|
|
50582
50786
|
// ../core/src/queueBackends/rabbitmqBackend.ts
|
|
50583
|
-
import { execFileSync as
|
|
50787
|
+
import { execFileSync as execFileSync4 } from "node:child_process";
|
|
50584
50788
|
import { randomUUID as randomUUID9 } from "node:crypto";
|
|
50585
50789
|
function parseAmqpUrl(url) {
|
|
50586
50790
|
const config = {};
|
|
@@ -51001,7 +51205,7 @@ var init_rabbitmqBackend = __esm({
|
|
|
51001
51205
|
setTimeout(() => { sock.destroy(); process.exit(1); }, 10000).unref();
|
|
51002
51206
|
`;
|
|
51003
51207
|
try {
|
|
51004
|
-
const result =
|
|
51208
|
+
const result = execFileSync4(process.execPath, ["-e", script], {
|
|
51005
51209
|
encoding: "utf-8",
|
|
51006
51210
|
timeout: 15e3,
|
|
51007
51211
|
stdio: ["pipe", "pipe", "pipe"]
|
|
@@ -51377,27 +51581,27 @@ var init_testClient = __esm({
|
|
|
51377
51581
|
return this.ctxPromise;
|
|
51378
51582
|
}
|
|
51379
51583
|
/** Send a GET request. */
|
|
51380
|
-
async get(
|
|
51381
|
-
return this._request("GET",
|
|
51584
|
+
async get(path9, options) {
|
|
51585
|
+
return this._request("GET", path9, options);
|
|
51382
51586
|
}
|
|
51383
51587
|
/** Send a POST request. */
|
|
51384
|
-
async post(
|
|
51385
|
-
return this._request("POST",
|
|
51588
|
+
async post(path9, options) {
|
|
51589
|
+
return this._request("POST", path9, options);
|
|
51386
51590
|
}
|
|
51387
51591
|
/** Send a PUT request. */
|
|
51388
|
-
async put(
|
|
51389
|
-
return this._request("PUT",
|
|
51592
|
+
async put(path9, options) {
|
|
51593
|
+
return this._request("PUT", path9, options);
|
|
51390
51594
|
}
|
|
51391
51595
|
/** Send a PATCH request. */
|
|
51392
|
-
async patch(
|
|
51393
|
-
return this._request("PATCH",
|
|
51596
|
+
async patch(path9, options) {
|
|
51597
|
+
return this._request("PATCH", path9, options);
|
|
51394
51598
|
}
|
|
51395
51599
|
/** Send a DELETE request. */
|
|
51396
|
-
async delete(
|
|
51397
|
-
return this._request("DELETE",
|
|
51600
|
+
async delete(path9, options) {
|
|
51601
|
+
return this._request("DELETE", path9, options);
|
|
51398
51602
|
}
|
|
51399
51603
|
/** Build a mock request/response pair and dispatch it through the REAL pipeline (runDispatch). */
|
|
51400
|
-
async _request(method,
|
|
51604
|
+
async _request(method, path9, options) {
|
|
51401
51605
|
const { json, body, headers } = options ?? {};
|
|
51402
51606
|
let rawBody = "";
|
|
51403
51607
|
let contentType = "";
|
|
@@ -51423,7 +51627,7 @@ var init_testClient = __esm({
|
|
|
51423
51627
|
Object.defineProperty(socket, "remoteAddress", { value: "127.0.0.1" });
|
|
51424
51628
|
const rawReq = new IncomingMessage2(socket);
|
|
51425
51629
|
rawReq.method = method.toUpperCase();
|
|
51426
|
-
rawReq.url =
|
|
51630
|
+
rawReq.url = path9;
|
|
51427
51631
|
rawReq.headers = { ...reqHeaders, host: "localhost:7148" };
|
|
51428
51632
|
if (rawBody) {
|
|
51429
51633
|
rawReq.push(Buffer.from(rawBody));
|
|
@@ -51494,20 +51698,20 @@ var init_test = __esm({
|
|
|
51494
51698
|
if (this._client === null) this._client = new TestClient();
|
|
51495
51699
|
return this._client;
|
|
51496
51700
|
}
|
|
51497
|
-
async get(
|
|
51498
|
-
return this.client.get(
|
|
51701
|
+
async get(path9, options) {
|
|
51702
|
+
return this.client.get(path9, options);
|
|
51499
51703
|
}
|
|
51500
|
-
async post(
|
|
51501
|
-
return this.client.post(
|
|
51704
|
+
async post(path9, options) {
|
|
51705
|
+
return this.client.post(path9, options);
|
|
51502
51706
|
}
|
|
51503
|
-
async put(
|
|
51504
|
-
return this.client.put(
|
|
51707
|
+
async put(path9, options) {
|
|
51708
|
+
return this.client.put(path9, options);
|
|
51505
51709
|
}
|
|
51506
|
-
async patch(
|
|
51507
|
-
return this.client.patch(
|
|
51710
|
+
async patch(path9, options) {
|
|
51711
|
+
return this.client.patch(path9, options);
|
|
51508
51712
|
}
|
|
51509
|
-
async delete(
|
|
51510
|
-
return this.client.delete(
|
|
51713
|
+
async delete(path9, options) {
|
|
51714
|
+
return this.client.delete(path9, options);
|
|
51511
51715
|
}
|
|
51512
51716
|
// ── Positional assertions — (actual, expected, message) shape ────────
|
|
51513
51717
|
assertEqual(actual, expected, message) {
|
|
@@ -52433,7 +52637,7 @@ ${cdStep} npm install
|
|
|
52433
52637
|
|
|
52434
52638
|
// src/commands/serve.ts
|
|
52435
52639
|
import { resolve as resolve22 } from "node:path";
|
|
52436
|
-
import { existsSync as
|
|
52640
|
+
import { existsSync as existsSync31 } from "node:fs";
|
|
52437
52641
|
async function serveProject(options) {
|
|
52438
52642
|
if (options.noReload) {
|
|
52439
52643
|
process.env.TINA4_NO_RELOAD = "true";
|
|
@@ -52446,7 +52650,7 @@ async function serveProject(options) {
|
|
|
52446
52650
|
const modelsDir = resolve22(cwd, "src/models");
|
|
52447
52651
|
const templatesDir = resolve22(cwd, "src/templates");
|
|
52448
52652
|
const staticDir = resolve22(cwd, "public");
|
|
52449
|
-
if (!
|
|
52653
|
+
if (!existsSync31(routesDir) && !existsSync31(modelsDir) && !existsSync31(ormDir)) {
|
|
52450
52654
|
console.error(" Error: Not a Tina4 project. Run this from a project created with 'tina4 init'.");
|
|
52451
52655
|
process.exit(1);
|
|
52452
52656
|
}
|
|
@@ -52465,12 +52669,12 @@ async function serveProject(options) {
|
|
|
52465
52669
|
// src/commands/migrate.ts
|
|
52466
52670
|
init_dotenv();
|
|
52467
52671
|
init_util();
|
|
52468
|
-
import { existsSync as
|
|
52672
|
+
import { existsSync as existsSync32 } from "node:fs";
|
|
52469
52673
|
import { resolve as resolve23 } from "node:path";
|
|
52470
52674
|
async function runMigrations(migrationDir) {
|
|
52471
52675
|
loadEnv();
|
|
52472
52676
|
const dir = resolve23(migrationDir ?? "migrations");
|
|
52473
|
-
if (!
|
|
52677
|
+
if (!existsSync32(dir)) {
|
|
52474
52678
|
console.log(" No migrations/ directory found. Nothing to run.");
|
|
52475
52679
|
return;
|
|
52476
52680
|
}
|
|
@@ -52623,11 +52827,11 @@ async function migrateRollback(migrationDir) {
|
|
|
52623
52827
|
}
|
|
52624
52828
|
|
|
52625
52829
|
// src/commands/routes.ts
|
|
52626
|
-
import { existsSync as
|
|
52830
|
+
import { existsSync as existsSync33 } from "node:fs";
|
|
52627
52831
|
import { resolve as resolve26 } from "node:path";
|
|
52628
52832
|
async function listRoutes() {
|
|
52629
52833
|
const routesDir = resolve26("src/routes");
|
|
52630
|
-
if (!
|
|
52834
|
+
if (!existsSync33(routesDir)) {
|
|
52631
52835
|
console.error(" No src/routes/ directory found. Are you in a Tina4 project?");
|
|
52632
52836
|
process.exit(1);
|
|
52633
52837
|
}
|
|
@@ -52657,9 +52861,9 @@ async function listRoutes() {
|
|
|
52657
52861
|
console.log(" " + "-".repeat(70));
|
|
52658
52862
|
for (const route of routes) {
|
|
52659
52863
|
const method = route.method.toUpperCase().padEnd(10);
|
|
52660
|
-
const
|
|
52864
|
+
const path9 = route.pattern.padEnd(40);
|
|
52661
52865
|
const summary = route.meta?.summary ?? "";
|
|
52662
|
-
console.log(` ${method}${
|
|
52866
|
+
console.log(` ${method}${path9}${summary}`);
|
|
52663
52867
|
}
|
|
52664
52868
|
console.log(" " + "-".repeat(70));
|
|
52665
52869
|
console.log(` Total: ${routes.length} route(s)`);
|
|
@@ -52667,9 +52871,9 @@ async function listRoutes() {
|
|
|
52667
52871
|
}
|
|
52668
52872
|
|
|
52669
52873
|
// src/commands/test.ts
|
|
52670
|
-
import { existsSync as
|
|
52671
|
-
import { resolve as resolve27, join as
|
|
52672
|
-
import { pathToFileURL as
|
|
52874
|
+
import { existsSync as existsSync34, readdirSync as readdirSync20, readFileSync as readFileSync27, statSync as statSync22 } from "node:fs";
|
|
52875
|
+
import { resolve as resolve27, join as join36 } from "node:path";
|
|
52876
|
+
import { pathToFileURL as pathToFileURL5 } from "node:url";
|
|
52673
52877
|
import { execSync as execSync3 } from "node:child_process";
|
|
52674
52878
|
function walkSource(dir) {
|
|
52675
52879
|
const out = [];
|
|
@@ -52680,10 +52884,10 @@ function walkSource(dir) {
|
|
|
52680
52884
|
return out;
|
|
52681
52885
|
}
|
|
52682
52886
|
for (const name of entries) {
|
|
52683
|
-
const full =
|
|
52887
|
+
const full = join36(dir, name);
|
|
52684
52888
|
let st;
|
|
52685
52889
|
try {
|
|
52686
|
-
st =
|
|
52890
|
+
st = statSync22(full);
|
|
52687
52891
|
} catch {
|
|
52688
52892
|
continue;
|
|
52689
52893
|
}
|
|
@@ -52697,7 +52901,7 @@ function walkSource(dir) {
|
|
|
52697
52901
|
}
|
|
52698
52902
|
async function runInlineTests(cwd) {
|
|
52699
52903
|
const srcDir = resolve27(cwd, "src");
|
|
52700
|
-
if (!
|
|
52904
|
+
if (!existsSync34(srcDir)) return false;
|
|
52701
52905
|
const { runAllAsync: runAllAsync2, reset: reset2 } = await Promise.resolve().then(() => (init_src3(), src_exports3));
|
|
52702
52906
|
reset2();
|
|
52703
52907
|
let discovered = 0;
|
|
@@ -52711,7 +52915,7 @@ async function runInlineTests(cwd) {
|
|
|
52711
52915
|
if (!/\btests\s*\(/.test(text)) continue;
|
|
52712
52916
|
discovered++;
|
|
52713
52917
|
try {
|
|
52714
|
-
await import(
|
|
52918
|
+
await import(pathToFileURL5(file).href);
|
|
52715
52919
|
} catch (err) {
|
|
52716
52920
|
console.log(
|
|
52717
52921
|
` ! could not import ${file}: ${err instanceof Error ? err.message : String(err)}`
|
|
@@ -52728,7 +52932,7 @@ async function runTests(testPath) {
|
|
|
52728
52932
|
let fileFailed = false;
|
|
52729
52933
|
if (testPath) {
|
|
52730
52934
|
const file = resolve27(testPath);
|
|
52731
|
-
if (!
|
|
52935
|
+
if (!existsSync34(file)) {
|
|
52732
52936
|
console.error(` Error: Test file not found: ${testPath}`);
|
|
52733
52937
|
process.exit(1);
|
|
52734
52938
|
}
|
|
@@ -52745,13 +52949,13 @@ async function runTests(testPath) {
|
|
|
52745
52949
|
let testFiles = [];
|
|
52746
52950
|
for (const candidate of candidates) {
|
|
52747
52951
|
const fullPath = resolve27(cwd, candidate);
|
|
52748
|
-
if (!
|
|
52952
|
+
if (!existsSync34(fullPath)) continue;
|
|
52749
52953
|
if (candidate.endsWith(".ts")) {
|
|
52750
52954
|
testFiles.push(fullPath);
|
|
52751
52955
|
break;
|
|
52752
52956
|
}
|
|
52753
52957
|
try {
|
|
52754
|
-
const files = readdirSync20(fullPath).filter((f) => f.endsWith(".ts")).map((f) =>
|
|
52958
|
+
const files = readdirSync20(fullPath).filter((f) => f.endsWith(".ts")).map((f) => join36(fullPath, f));
|
|
52755
52959
|
testFiles.push(...files);
|
|
52756
52960
|
} catch {
|
|
52757
52961
|
}
|
|
@@ -52768,8 +52972,8 @@ async function runTests(testPath) {
|
|
|
52768
52972
|
console.log(` Found ${testFiles.length} test file(s)
|
|
52769
52973
|
`);
|
|
52770
52974
|
for (const file of testFiles) {
|
|
52771
|
-
const
|
|
52772
|
-
console.log(` Running: ${
|
|
52975
|
+
const relative12 = file.replace(cwd + "/", "");
|
|
52976
|
+
console.log(` Running: ${relative12}`);
|
|
52773
52977
|
try {
|
|
52774
52978
|
execSync3(`npx tsx "${file}"`, { cwd, stdio: "inherit" });
|
|
52775
52979
|
} catch {
|
|
@@ -52781,9 +52985,10 @@ async function runTests(testPath) {
|
|
|
52781
52985
|
|
|
52782
52986
|
// src/commands/lint.ts
|
|
52783
52987
|
init_util();
|
|
52784
|
-
|
|
52988
|
+
init_batchSpawn();
|
|
52989
|
+
import { existsSync as existsSync35, readdirSync as readdirSync21, readFileSync as readFileSync28, statSync as statSync23, writeFileSync as writeFileSync20 } from "node:fs";
|
|
52785
52990
|
import { createRequire as createRequire8 } from "node:module";
|
|
52786
|
-
import { dirname as dirname18, join as
|
|
52991
|
+
import { dirname as dirname18, join as join37, relative as relative11 } from "node:path";
|
|
52787
52992
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
52788
52993
|
var LINT_EXTENSIONS = [".ts", ".mts", ".cts", ".js", ".mjs", ".cjs"];
|
|
52789
52994
|
var JS_EXTENSIONS = [".js", ".mjs", ".cjs"];
|
|
@@ -52801,10 +53006,10 @@ function walkSource2(dir, out) {
|
|
|
52801
53006
|
}
|
|
52802
53007
|
for (const name of entries) {
|
|
52803
53008
|
if (SKIP_DIRS3.has(name)) continue;
|
|
52804
|
-
const full =
|
|
53009
|
+
const full = join37(dir, name);
|
|
52805
53010
|
let st;
|
|
52806
53011
|
try {
|
|
52807
|
-
st =
|
|
53012
|
+
st = statSync23(full);
|
|
52808
53013
|
} catch {
|
|
52809
53014
|
continue;
|
|
52810
53015
|
}
|
|
@@ -52817,15 +53022,15 @@ function walkSource2(dir, out) {
|
|
|
52817
53022
|
}
|
|
52818
53023
|
function collectAppFiles(cwd) {
|
|
52819
53024
|
const files = [];
|
|
52820
|
-
const srcDir =
|
|
53025
|
+
const srcDir = join37(cwd, "src");
|
|
52821
53026
|
try {
|
|
52822
|
-
if (
|
|
53027
|
+
if (statSync23(srcDir).isDirectory()) walkSource2(srcDir, files);
|
|
52823
53028
|
} catch {
|
|
52824
53029
|
}
|
|
52825
53030
|
for (const entry of ["app.ts", "app.mts", "app.js", "app.mjs"]) {
|
|
52826
|
-
const p =
|
|
53031
|
+
const p = join37(cwd, entry);
|
|
52827
53032
|
try {
|
|
52828
|
-
if (
|
|
53033
|
+
if (statSync23(p).isFile()) files.push(p);
|
|
52829
53034
|
} catch {
|
|
52830
53035
|
}
|
|
52831
53036
|
}
|
|
@@ -52846,15 +53051,15 @@ export default [js.configs.recommended, ...tseslint.configs.recommended];
|
|
|
52846
53051
|
`;
|
|
52847
53052
|
function findEslintConfig(cwd) {
|
|
52848
53053
|
for (const name of ESLINT_FLAT_CONFIGS) {
|
|
52849
|
-
const p =
|
|
52850
|
-
if (
|
|
53054
|
+
const p = join37(cwd, name);
|
|
53055
|
+
if (existsSync35(p)) return p;
|
|
52851
53056
|
}
|
|
52852
53057
|
return null;
|
|
52853
53058
|
}
|
|
52854
53059
|
function resolvePackageBin(cwd, pkg, binRelative) {
|
|
52855
|
-
const direct =
|
|
52856
|
-
if (
|
|
52857
|
-
const require2 = createRequire8(
|
|
53060
|
+
const direct = join37(cwd, "node_modules", pkg, binRelative);
|
|
53061
|
+
if (existsSync35(direct)) return direct;
|
|
53062
|
+
const require2 = createRequire8(join37(cwd, "package.json"));
|
|
52858
53063
|
let entry;
|
|
52859
53064
|
try {
|
|
52860
53065
|
entry = require2.resolve(pkg);
|
|
@@ -52863,12 +53068,12 @@ function resolvePackageBin(cwd, pkg, binRelative) {
|
|
|
52863
53068
|
}
|
|
52864
53069
|
let dir = dirname18(entry);
|
|
52865
53070
|
for (let i = 0; i < 8; i++) {
|
|
52866
|
-
const pkgJson =
|
|
52867
|
-
if (
|
|
53071
|
+
const pkgJson = join37(dir, "package.json");
|
|
53072
|
+
if (existsSync35(pkgJson)) {
|
|
52868
53073
|
try {
|
|
52869
53074
|
if (JSON.parse(readFileSync28(pkgJson, "utf-8")).name === pkg) {
|
|
52870
|
-
const bin =
|
|
52871
|
-
return
|
|
53075
|
+
const bin = join37(dir, binRelative);
|
|
53076
|
+
return existsSync35(bin) ? bin : null;
|
|
52872
53077
|
}
|
|
52873
53078
|
} catch {
|
|
52874
53079
|
}
|
|
@@ -52883,7 +53088,7 @@ function resolveEslintBin(cwd) {
|
|
|
52883
53088
|
return resolvePackageBin(cwd, "eslint", "bin/eslint.js");
|
|
52884
53089
|
}
|
|
52885
53090
|
function hasPackage(cwd, pkg) {
|
|
52886
|
-
return
|
|
53091
|
+
return existsSync35(join37(cwd, "node_modules", ...pkg.split("/"), "package.json"));
|
|
52887
53092
|
}
|
|
52888
53093
|
function resolveNpm() {
|
|
52889
53094
|
const windows = process.platform === "win32";
|
|
@@ -52901,12 +53106,12 @@ function bootstrapEslint(cwd, noInstall) {
|
|
|
52901
53106
|
}
|
|
52902
53107
|
if (!bin) {
|
|
52903
53108
|
console.log(" \xB7 installing eslint (npm i -D eslint @eslint/js typescript-eslint)...");
|
|
52904
|
-
const rc =
|
|
53109
|
+
const rc = spawnSyncAllowingBatch(npm, ["install", "-D", "eslint", "@eslint/js", "typescript-eslint"], { cwd, stdio: "inherit" }).status;
|
|
52905
53110
|
if (rc === 0) bin = resolveEslintBin(cwd);
|
|
52906
53111
|
else console.log(" \xB7 could not install eslint \u2014 using the zero-dependency baseline.");
|
|
52907
53112
|
}
|
|
52908
53113
|
if (bin && !config && hasPackage(cwd, "@eslint/js") && hasPackage(cwd, "typescript-eslint")) {
|
|
52909
|
-
const scaffold =
|
|
53114
|
+
const scaffold = join37(cwd, ESLINT_SCAFFOLD_FILE);
|
|
52910
53115
|
try {
|
|
52911
53116
|
writeFileSync20(scaffold, ESLINT_SCAFFOLD, "utf-8");
|
|
52912
53117
|
config = scaffold;
|
|
@@ -52951,7 +53156,7 @@ function runJavaScript(cwd, files) {
|
|
|
52951
53156
|
if ((result.status ?? 1) === 0) continue;
|
|
52952
53157
|
const stderr = (result.stderr || "").trim();
|
|
52953
53158
|
const detail = stderr.split("\n").reverse().find((line) => line.includes("Error:")) || "syntax error";
|
|
52954
|
-
console.log(` \u2717 ${
|
|
53159
|
+
console.log(` \u2717 ${relative11(cwd, file)}: ${detail.trim()}`);
|
|
52955
53160
|
syntaxErrors++;
|
|
52956
53161
|
}
|
|
52957
53162
|
if (syntaxErrors > 0) {
|
|
@@ -52975,7 +53180,7 @@ function runLint(args) {
|
|
|
52975
53180
|
if (fix) {
|
|
52976
53181
|
console.log(" \xB7 --fix needs eslint \u2014 the baseline check has no autofix.");
|
|
52977
53182
|
}
|
|
52978
|
-
if (
|
|
53183
|
+
if (existsSync35(join37(cwd, "tsconfig.json")) && runTypescript(cwd, files)) return;
|
|
52979
53184
|
runJavaScript(cwd, files);
|
|
52980
53185
|
}
|
|
52981
53186
|
|
|
@@ -52983,15 +53188,15 @@ function runLint(args) {
|
|
|
52983
53188
|
init_generate();
|
|
52984
53189
|
|
|
52985
53190
|
// src/commands/seed.ts
|
|
52986
|
-
import { existsSync as
|
|
52987
|
-
import { resolve as resolve28, join as
|
|
53191
|
+
import { existsSync as existsSync36, readdirSync as readdirSync22 } from "node:fs";
|
|
53192
|
+
import { resolve as resolve28, join as join38 } from "node:path";
|
|
52988
53193
|
import { execSync as execSync4 } from "node:child_process";
|
|
52989
53194
|
async function runSeeds(seedPath) {
|
|
52990
53195
|
const cwd = process.cwd();
|
|
52991
53196
|
const seedDir = resolve28(cwd, "src/seeds");
|
|
52992
53197
|
if (seedPath) {
|
|
52993
53198
|
const file = resolve28(seedPath);
|
|
52994
|
-
if (!
|
|
53199
|
+
if (!existsSync36(file)) {
|
|
52995
53200
|
console.error(` Error: Seed file not found: ${seedPath}`);
|
|
52996
53201
|
process.exit(1);
|
|
52997
53202
|
}
|
|
@@ -53004,14 +53209,14 @@ async function runSeeds(seedPath) {
|
|
|
53004
53209
|
}
|
|
53005
53210
|
return;
|
|
53006
53211
|
}
|
|
53007
|
-
if (!
|
|
53212
|
+
if (!existsSync36(seedDir)) {
|
|
53008
53213
|
console.log(" No seeds directory found.");
|
|
53009
53214
|
console.log(" Create seed files in src/seeds/ (e.g. src/seeds/001-users.ts)");
|
|
53010
53215
|
return;
|
|
53011
53216
|
}
|
|
53012
53217
|
let seedFiles;
|
|
53013
53218
|
try {
|
|
53014
|
-
seedFiles = readdirSync22(seedDir).filter((f) => f.endsWith(".ts")).sort().map((f) =>
|
|
53219
|
+
seedFiles = readdirSync22(seedDir).filter((f) => f.endsWith(".ts")).sort().map((f) => join38(seedDir, f));
|
|
53015
53220
|
} catch {
|
|
53016
53221
|
console.log(" Could not read src/seeds/ directory.");
|
|
53017
53222
|
return;
|
|
@@ -53024,8 +53229,8 @@ async function runSeeds(seedPath) {
|
|
|
53024
53229
|
`);
|
|
53025
53230
|
let failed = false;
|
|
53026
53231
|
for (const file of seedFiles) {
|
|
53027
|
-
const
|
|
53028
|
-
console.log(` Seeding: ${
|
|
53232
|
+
const relative12 = file.replace(cwd + "/", "");
|
|
53233
|
+
console.log(` Seeding: ${relative12}`);
|
|
53029
53234
|
try {
|
|
53030
53235
|
execSync4(`npx tsx "${file}"`, { cwd, stdio: "inherit" });
|
|
53031
53236
|
} catch {
|
|
@@ -53043,27 +53248,27 @@ async function runSeeds(seedPath) {
|
|
|
53043
53248
|
init_dotenv();
|
|
53044
53249
|
init_queue();
|
|
53045
53250
|
init_util();
|
|
53046
|
-
import { readdirSync as readdirSync23, statSync as
|
|
53047
|
-
import { extname as
|
|
53048
|
-
import { pathToFileURL as
|
|
53251
|
+
import { readdirSync as readdirSync23, statSync as statSync24 } from "node:fs";
|
|
53252
|
+
import { extname as extname10, join as join39 } from "node:path";
|
|
53253
|
+
import { pathToFileURL as pathToFileURL6 } from "node:url";
|
|
53049
53254
|
var BOOLEAN_FLAGS = /* @__PURE__ */ new Set(["once", "json"]);
|
|
53050
53255
|
var parseFlags2 = (args) => parseFlags(args, BOOLEAN_FLAGS);
|
|
53051
53256
|
async function resolveQueueHandler(servicesDir, topic) {
|
|
53052
53257
|
let entries;
|
|
53053
53258
|
try {
|
|
53054
|
-
if (!
|
|
53259
|
+
if (!statSync24(servicesDir).isDirectory()) return null;
|
|
53055
53260
|
entries = readdirSync23(servicesDir);
|
|
53056
53261
|
} catch {
|
|
53057
53262
|
return null;
|
|
53058
53263
|
}
|
|
53059
53264
|
for (const entry of entries.sort()) {
|
|
53060
53265
|
if (entry.startsWith("_")) continue;
|
|
53061
|
-
const ext =
|
|
53266
|
+
const ext = extname10(entry);
|
|
53062
53267
|
if (ext !== ".ts" && ext !== ".js") continue;
|
|
53063
|
-
const fullPath =
|
|
53268
|
+
const fullPath = join39(servicesDir, entry);
|
|
53064
53269
|
try {
|
|
53065
|
-
if (!
|
|
53066
|
-
const mod = await import(
|
|
53270
|
+
if (!statSync24(fullPath).isFile()) continue;
|
|
53271
|
+
const mod = await import(pathToFileURL6(fullPath).href);
|
|
53067
53272
|
const config = mod.default ?? mod;
|
|
53068
53273
|
if (config && typeof config === "object" && config.topic === topic && typeof config.handle === "function") {
|
|
53069
53274
|
return config.handle;
|
|
@@ -53219,8 +53424,8 @@ async function queueCommand(args = []) {
|
|
|
53219
53424
|
|
|
53220
53425
|
// src/commands/build.ts
|
|
53221
53426
|
init_util();
|
|
53222
|
-
import { accessSync as accessSync2, constants as constants5, existsSync as
|
|
53223
|
-
import { basename as basename9, delimiter as
|
|
53427
|
+
import { accessSync as accessSync2, constants as constants5, existsSync as existsSync37, statSync as statSync25 } from "node:fs";
|
|
53428
|
+
import { basename as basename9, delimiter as delimiter4, join as join40 } from "node:path";
|
|
53224
53429
|
import { spawnSync as spawnSync4 } from "node:child_process";
|
|
53225
53430
|
function parseFlags3(args) {
|
|
53226
53431
|
return parseFlags(args).flags;
|
|
@@ -53229,13 +53434,13 @@ function whichDocker() {
|
|
|
53229
53434
|
const pathValue = process.env.PATH || process.env.Path || "";
|
|
53230
53435
|
if (!pathValue) return null;
|
|
53231
53436
|
const exts = process.platform === "win32" ? (process.env.PATHEXT || ".EXE;.CMD;.BAT;.COM").split(";") : [""];
|
|
53232
|
-
for (const dir of pathValue.split(
|
|
53437
|
+
for (const dir of pathValue.split(delimiter4)) {
|
|
53233
53438
|
if (!dir) continue;
|
|
53234
53439
|
for (const ext of exts) {
|
|
53235
|
-
const candidate =
|
|
53440
|
+
const candidate = join40(dir, `docker${ext}`);
|
|
53236
53441
|
try {
|
|
53237
53442
|
accessSync2(candidate, constants5.X_OK);
|
|
53238
|
-
if (
|
|
53443
|
+
if (statSync25(candidate).isFile()) return candidate;
|
|
53239
53444
|
} catch {
|
|
53240
53445
|
}
|
|
53241
53446
|
}
|
|
@@ -53250,7 +53455,7 @@ function buildImage(args) {
|
|
|
53250
53455
|
tag = `${dirName || "tina4app"}:latest`;
|
|
53251
53456
|
}
|
|
53252
53457
|
const dockerfile = typeof flags.file === "string" && flags.file ? flags.file : "Dockerfile";
|
|
53253
|
-
if (!
|
|
53458
|
+
if (!existsSync37(dockerfile) || !statSync25(dockerfile).isFile()) {
|
|
53254
53459
|
console.log(` \u2717 No ${dockerfile} found.`);
|
|
53255
53460
|
console.log(" A Tina4 app deploys as a container. Scaffold a Dockerfile first:");
|
|
53256
53461
|
console.log(" tina4 deploy docker (or: tina4nodejs init)");
|
|
@@ -53277,16 +53482,16 @@ function buildImage(args) {
|
|
|
53277
53482
|
}
|
|
53278
53483
|
|
|
53279
53484
|
// src/bin.ts
|
|
53485
|
+
init_batchSpawn();
|
|
53280
53486
|
init_util();
|
|
53281
|
-
import {
|
|
53282
|
-
import {
|
|
53283
|
-
import {
|
|
53284
|
-
import { fileURLToPath as fileURLToPath11, pathToFileURL as pathToFileURL4 } from "node:url";
|
|
53487
|
+
import { existsSync as existsSync38, readFileSync as readFileSync29 } from "node:fs";
|
|
53488
|
+
import { dirname as dirname19, join as join41 } from "node:path";
|
|
53489
|
+
import { fileURLToPath as fileURLToPath12, pathToFileURL as pathToFileURL7 } from "node:url";
|
|
53285
53490
|
function readCliVersion() {
|
|
53286
|
-
let dir = dirname19(
|
|
53491
|
+
let dir = dirname19(fileURLToPath12(import.meta.url));
|
|
53287
53492
|
for (let i = 0; i < 6; i++) {
|
|
53288
|
-
const pkgPath =
|
|
53289
|
-
if (
|
|
53493
|
+
const pkgPath = join41(dir, "package.json");
|
|
53494
|
+
if (existsSync38(pkgPath)) {
|
|
53290
53495
|
try {
|
|
53291
53496
|
const pkg = JSON.parse(readFileSync29(pkgPath, "utf-8"));
|
|
53292
53497
|
if (typeof pkg.version === "string" && pkg.version) return pkg.version;
|
|
@@ -53299,9 +53504,9 @@ function readCliVersion() {
|
|
|
53299
53504
|
}
|
|
53300
53505
|
return "0.0.0";
|
|
53301
53506
|
}
|
|
53302
|
-
async function killProcessOnPort(port) {
|
|
53507
|
+
async function killProcessOnPort(port, host) {
|
|
53303
53508
|
const { takeOverPort: takeOverPort2, isDev: isDev2, noTakeoverOptedOut: noTakeoverOptedOut2, TAKEOVER_KILLED: TAKEOVER_KILLED2, TAKEOVER_REFUSALS: TAKEOVER_REFUSALS2 } = await Promise.resolve().then(() => (init_portTakeover(), portTakeover_exports));
|
|
53304
|
-
const result = takeOverPort2(port, isDev2(), noTakeoverOptedOut2());
|
|
53509
|
+
const result = takeOverPort2(port, isDev2(), noTakeoverOptedOut2(), void 0, void 0, host);
|
|
53305
53510
|
if (result.status === TAKEOVER_KILLED2) {
|
|
53306
53511
|
console.log(` ${result.message}`);
|
|
53307
53512
|
return true;
|
|
@@ -53469,7 +53674,8 @@ var COMMANDS = {
|
|
|
53469
53674
|
const noBrowser = a.includes("--no-browser");
|
|
53470
53675
|
const noReload = a.includes("--no-reload");
|
|
53471
53676
|
if (a.includes("--no-kill")) process.env.TINA4_NO_TAKEOVER = "true";
|
|
53472
|
-
await
|
|
53677
|
+
const { resolvePortAndHost: resolvePortAndHost2 } = await Promise.resolve().then(() => (init_server(), server_exports));
|
|
53678
|
+
await killProcessOnPort(port, resolvePortAndHost2({ port }).host);
|
|
53473
53679
|
await serveProject({ port, noBrowser, noReload });
|
|
53474
53680
|
},
|
|
53475
53681
|
flags: SERVE_FLAGS,
|
|
@@ -53629,7 +53835,7 @@ ${CLIENT_INSTALL_HINT}
|
|
|
53629
53835
|
);
|
|
53630
53836
|
return EXIT_CLIENT_UNAVAILABLE;
|
|
53631
53837
|
}
|
|
53632
|
-
const result =
|
|
53838
|
+
const result = spawnSyncAllowingBatch(client, [command, ...args], {
|
|
53633
53839
|
stdio: "inherit",
|
|
53634
53840
|
env: { ...process.env, [DELEGATION_GUARD_ENV]: command }
|
|
53635
53841
|
});
|
|
@@ -53766,7 +53972,7 @@ async function main() {
|
|
|
53766
53972
|
printHelp();
|
|
53767
53973
|
process.exit(EXIT_UNKNOWN_COMMAND);
|
|
53768
53974
|
}
|
|
53769
|
-
if (process.argv[1] && import.meta.url ===
|
|
53975
|
+
if (process.argv[1] && import.meta.url === pathToFileURL7(process.argv[1]).href) {
|
|
53770
53976
|
main().catch((err) => {
|
|
53771
53977
|
console.error(err);
|
|
53772
53978
|
process.exit(1);
|