tina4-nodejs 3.13.162 → 3.13.164
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 +413 -177
- package/packages/cli/src/bin.ts +8 -3
- package/packages/cli/src/commands/test.ts +2 -2
- package/packages/core/dist/index.js +381 -172
- package/packages/core/src/devAdmin.ts +8 -3
- package/packages/core/src/index.ts +1 -1
- package/packages/core/src/mcp.ts +10 -4
- package/packages/core/src/portTakeover.ts +44 -10
- package/packages/core/src/queueBackends/kafkaBackend.ts +56 -10
- package/packages/core/src/server.ts +79 -5
- package/packages/core/src/testing.ts +181 -69
- package/packages/frond/dist/index.js +66 -19
- package/packages/frond/src/engine.ts +74 -23
- package/packages/orm/dist/index.js +380 -172
- package/types/core/src/index.d.ts +1 -1
- package/types/core/src/mcp.d.ts +2 -2
- package/types/core/src/portTakeover.d.ts +3 -1
- package/types/core/src/testing.d.ts +27 -4
- package/types/frond/src/engine.d.ts +31 -2
package/packages/cli/dist/bin.js
CHANGED
|
@@ -5964,11 +5964,11 @@ var init_firebird = __esm({
|
|
|
5964
5964
|
*/
|
|
5965
5965
|
async decodeBlobs(row) {
|
|
5966
5966
|
if (row === null || typeof row !== "object") return row;
|
|
5967
|
-
const
|
|
5968
|
-
for (const key of Object.keys(
|
|
5969
|
-
if (typeof
|
|
5970
|
-
|
|
5971
|
-
|
|
5967
|
+
const record2 = row;
|
|
5968
|
+
for (const key of Object.keys(record2)) {
|
|
5969
|
+
if (typeof record2[key] === "function") {
|
|
5970
|
+
record2[key] = await this.readBlob(
|
|
5971
|
+
record2[key]
|
|
5972
5972
|
);
|
|
5973
5973
|
}
|
|
5974
5974
|
}
|
|
@@ -12054,8 +12054,14 @@ var init_engine = __esm({
|
|
|
12054
12054
|
// and every future ``new Frond()`` inherits it automatically.
|
|
12055
12055
|
// Mirrors Python's _class_globals / _class_filters / _class_tests.
|
|
12056
12056
|
static classFilters = /* @__PURE__ */ new Map();
|
|
12057
|
-
|
|
12057
|
+
// Globals are read LIVE at render time (not copied at construction), so a
|
|
12058
|
+
// Frond.addGlobal() made after an engine exists still reaches it. A plain
|
|
12059
|
+
// object rather than a Map so render() can spread it in one step.
|
|
12060
|
+
static classGlobals = {};
|
|
12058
12061
|
static classTests = /* @__PURE__ */ new Map();
|
|
12062
|
+
// Bumped on every class-level filter/test change, so an engine knows when
|
|
12063
|
+
// to rebuild its merged filter/test maps (see syncRegistries).
|
|
12064
|
+
static classRegistryVersion = 0;
|
|
12059
12065
|
// ── Live-block registries (server-rendered {% live %} regions) ──
|
|
12060
12066
|
// A {% live %} block registers three things when its page first renders:
|
|
12061
12067
|
// liveFragments[name] -> the raw body source, re-rendered on every
|
|
@@ -12075,20 +12081,27 @@ var init_engine = __esm({
|
|
|
12075
12081
|
static liveBroadcaster = null;
|
|
12076
12082
|
/**
|
|
12077
12083
|
* Register a custom filter at the class level — available to every
|
|
12078
|
-
*
|
|
12084
|
+
* instance, existing ones included: an engine merges the class filters
|
|
12085
|
+
* again at its next render (ADR-0107). Callable as ``Frond.addFilter()``
|
|
12079
12086
|
* (static) or ``frond.addFilter()`` (instance). See instance method
|
|
12080
12087
|
* below for the dual-call semantics.
|
|
12081
12088
|
*/
|
|
12082
12089
|
static addFilter(name, fn) {
|
|
12083
12090
|
_Frond.classFilters.set(name, fn);
|
|
12091
|
+
_Frond.classRegistryVersion++;
|
|
12084
12092
|
}
|
|
12085
12093
|
/**
|
|
12086
12094
|
* Register a global variable available in all templates of every
|
|
12087
|
-
*
|
|
12095
|
+
* instance, existing ones included: class globals are read at render time
|
|
12096
|
+
* (ADR-0106). Callable as ``Frond.addGlobal()`` (static) or
|
|
12088
12097
|
* ``frond.addGlobal()`` (instance).
|
|
12089
12098
|
*/
|
|
12090
12099
|
static addGlobal(name, value) {
|
|
12091
|
-
_Frond.classGlobals
|
|
12100
|
+
_Frond.classGlobals[name] = value;
|
|
12101
|
+
}
|
|
12102
|
+
/** True when a class-level global with this name is registered. */
|
|
12103
|
+
static hasGlobal(name) {
|
|
12104
|
+
return Object.prototype.hasOwnProperty.call(_Frond.classGlobals, name);
|
|
12092
12105
|
}
|
|
12093
12106
|
/**
|
|
12094
12107
|
* Register a custom test (``{% if x is positive %}``) at the class
|
|
@@ -12097,6 +12110,7 @@ var init_engine = __esm({
|
|
|
12097
12110
|
*/
|
|
12098
12111
|
static addTest(name, fn) {
|
|
12099
12112
|
_Frond.classTests.set(name, fn);
|
|
12113
|
+
_Frond.classRegistryVersion++;
|
|
12100
12114
|
}
|
|
12101
12115
|
/**
|
|
12102
12116
|
* Clear the class-level globals/filters/tests registries.
|
|
@@ -12106,15 +12120,25 @@ var init_engine = __esm({
|
|
|
12106
12120
|
*/
|
|
12107
12121
|
static clearRegistry() {
|
|
12108
12122
|
_Frond.classFilters.clear();
|
|
12109
|
-
_Frond.classGlobals
|
|
12123
|
+
_Frond.classGlobals = {};
|
|
12110
12124
|
_Frond.classTests.clear();
|
|
12125
|
+
_Frond.classRegistryVersion++;
|
|
12111
12126
|
_Frond.liveFragments.clear();
|
|
12112
12127
|
_Frond.liveSources.clear();
|
|
12113
12128
|
_Frond.liveWsPaths.clear();
|
|
12114
12129
|
}
|
|
12115
12130
|
templateDir;
|
|
12116
|
-
filters
|
|
12131
|
+
/** Effective filters: built-in < class < instance (see syncRegistries). */
|
|
12132
|
+
filters = {};
|
|
12133
|
+
/** Filters / tests registered on THIS instance only (ADR-0052). */
|
|
12134
|
+
localFilters = {};
|
|
12135
|
+
localTests = {};
|
|
12136
|
+
/** The class-registry version `filters` / `tests` were last merged at. */
|
|
12137
|
+
registryVersion = -1;
|
|
12138
|
+
/** Globals registered on THIS instance only (ADR-0052). */
|
|
12117
12139
|
globals;
|
|
12140
|
+
/** Built-in globals (formToken, range, dump, csp_nonce, ...). */
|
|
12141
|
+
builtinGlobals;
|
|
12118
12142
|
tests;
|
|
12119
12143
|
_sandbox;
|
|
12120
12144
|
_allowedFilters;
|
|
@@ -12144,9 +12168,10 @@ var init_engine = __esm({
|
|
|
12144
12168
|
}
|
|
12145
12169
|
constructor(templateDir = "src/templates") {
|
|
12146
12170
|
this.templateDir = resolve5(templateDir);
|
|
12147
|
-
this.filters = { ...BUILTIN_FILTERS };
|
|
12148
12171
|
this.globals = {};
|
|
12172
|
+
this.builtinGlobals = {};
|
|
12149
12173
|
this.tests = {};
|
|
12174
|
+
this.syncRegistries();
|
|
12150
12175
|
this._sandbox = false;
|
|
12151
12176
|
this._allowedFilters = null;
|
|
12152
12177
|
this._allowedTags = null;
|
|
@@ -12194,16 +12219,25 @@ var init_engine = __esm({
|
|
|
12194
12219
|
return { output, next };
|
|
12195
12220
|
}
|
|
12196
12221
|
};
|
|
12197
|
-
this.
|
|
12198
|
-
this.
|
|
12199
|
-
this.
|
|
12200
|
-
this.
|
|
12201
|
-
this.
|
|
12202
|
-
this.
|
|
12203
|
-
this.
|
|
12204
|
-
|
|
12205
|
-
|
|
12206
|
-
|
|
12222
|
+
this.builtinGlobals.formToken = (descriptor) => _generateFormToken(descriptor || "");
|
|
12223
|
+
this.builtinGlobals.form_token = (descriptor) => _generateFormToken(descriptor || "");
|
|
12224
|
+
this.builtinGlobals.formTokenValue = (descriptor) => _generateFormTokenValue(descriptor || "");
|
|
12225
|
+
this.builtinGlobals.form_token_value = (descriptor) => _generateFormTokenValue(descriptor || "");
|
|
12226
|
+
this.builtinGlobals.range = frondRange;
|
|
12227
|
+
this.builtinGlobals.dump = (value) => renderDump(value);
|
|
12228
|
+
this.builtinGlobals.csp_nonce = () => _cspNonceProvider();
|
|
12229
|
+
}
|
|
12230
|
+
/**
|
|
12231
|
+
* Rebuild the merged filter/test maps when the class registry changed.
|
|
12232
|
+
* Same layering as globals -- built-ins < class < this instance. Filter
|
|
12233
|
+
* lookup is on the hot path, so the merge is a plain object rebuilt only
|
|
12234
|
+
* when the class-registry version moves, never a per-lookup chain.
|
|
12235
|
+
*/
|
|
12236
|
+
syncRegistries() {
|
|
12237
|
+
if (this.registryVersion === _Frond.classRegistryVersion) return;
|
|
12238
|
+
this.filters = { ...BUILTIN_FILTERS, ...Object.fromEntries(_Frond.classFilters), ...this.localFilters };
|
|
12239
|
+
this.tests = { ...Object.fromEntries(_Frond.classTests), ...this.localTests };
|
|
12240
|
+
this.registryVersion = _Frond.classRegistryVersion;
|
|
12207
12241
|
}
|
|
12208
12242
|
sandbox(filters, tags, vars) {
|
|
12209
12243
|
this._sandbox = true;
|
|
@@ -12224,6 +12258,7 @@ var init_engine = __esm({
|
|
|
12224
12258
|
* for process-global registration. tina4: ADR-0052.
|
|
12225
12259
|
*/
|
|
12226
12260
|
addFilter(name, fn) {
|
|
12261
|
+
this.localFilters[name] = fn;
|
|
12227
12262
|
this.filters[name] = fn;
|
|
12228
12263
|
}
|
|
12229
12264
|
/**
|
|
@@ -12236,6 +12271,7 @@ var init_engine = __esm({
|
|
|
12236
12271
|
* Register a custom test on this instance only.
|
|
12237
12272
|
*/
|
|
12238
12273
|
addTest(name, fn) {
|
|
12274
|
+
this.localTests[name] = fn;
|
|
12239
12275
|
this.tests[name] = fn;
|
|
12240
12276
|
}
|
|
12241
12277
|
/**
|
|
@@ -12251,8 +12287,19 @@ var init_engine = __esm({
|
|
|
12251
12287
|
const n = parseInt(raw, 10);
|
|
12252
12288
|
return isNaN(n) || n < 0 ? 0 : n;
|
|
12253
12289
|
}
|
|
12290
|
+
/**
|
|
12291
|
+
* Layer the globals under the render data: built-ins < class globals (read
|
|
12292
|
+
* live, so registration order never matters) < this instance's own globals
|
|
12293
|
+
* < the data passed to render(). Every render starts here, so this is also
|
|
12294
|
+
* where the filter/test maps catch up with any class registration made
|
|
12295
|
+
* since the last render.
|
|
12296
|
+
*/
|
|
12297
|
+
withGlobals(data) {
|
|
12298
|
+
this.syncRegistries();
|
|
12299
|
+
return { ...this.builtinGlobals, ..._Frond.classGlobals, ...this.globals, ...data || {} };
|
|
12300
|
+
}
|
|
12254
12301
|
render(template, data) {
|
|
12255
|
-
const context =
|
|
12302
|
+
const context = this.withGlobals(data);
|
|
12256
12303
|
const filePath = join8(this.templateDir, template);
|
|
12257
12304
|
if (!existsSync6(filePath)) {
|
|
12258
12305
|
throw new Error(`Template not found: ${filePath}`);
|
|
@@ -12275,7 +12322,7 @@ var init_engine = __esm({
|
|
|
12275
12322
|
return this.executeWithSource(source, tokens, context);
|
|
12276
12323
|
}
|
|
12277
12324
|
renderString(source, data) {
|
|
12278
|
-
const context =
|
|
12325
|
+
const context = this.withGlobals(data);
|
|
12279
12326
|
const key = createHash3("md5").update(source).digest("hex");
|
|
12280
12327
|
const ttlMs = this.cacheTtlSeconds() * 1e3;
|
|
12281
12328
|
const cached = this.compiledStrings.get(key);
|
|
@@ -13459,12 +13506,12 @@ function crudSortProp(model, requested, pkProp) {
|
|
|
13459
13506
|
}
|
|
13460
13507
|
return pkProp;
|
|
13461
13508
|
}
|
|
13462
|
-
function cellValue(
|
|
13463
|
-
return
|
|
13509
|
+
function cellValue(record2, col) {
|
|
13510
|
+
return record2[col];
|
|
13464
13511
|
}
|
|
13465
|
-
function buildCells(columns,
|
|
13512
|
+
function buildCells(columns, record2, editable, aligns) {
|
|
13466
13513
|
return columns.map((col, index) => {
|
|
13467
|
-
const raw = cellValue(
|
|
13514
|
+
const raw = cellValue(record2, col);
|
|
13468
13515
|
const value = h(raw === null || raw === void 0 ? "" : raw);
|
|
13469
13516
|
const css = aligns[index];
|
|
13470
13517
|
return editable ? `<td class="${css}" contenteditable="true" data-field="${h(col)}">${value}</td>` : `<td class="${css}">${value}</td>`;
|
|
@@ -13627,9 +13674,9 @@ function headerCell(opts, col, align) {
|
|
|
13627
13674
|
function tableData(opts) {
|
|
13628
13675
|
const aligns = opts.columns.map((col) => columnAlignment(opts.model, col));
|
|
13629
13676
|
const headers = opts.columns.map((col, index) => headerCell(opts, col, aligns[index]));
|
|
13630
|
-
const rows = opts.records.map((
|
|
13631
|
-
id: h(cellValue(
|
|
13632
|
-
cells: buildCells(opts.columns,
|
|
13677
|
+
const rows = opts.records.map((record2) => ({
|
|
13678
|
+
id: h(cellValue(record2, opts.pk) ?? ""),
|
|
13679
|
+
cells: buildCells(opts.columns, record2, opts.editable, aligns)
|
|
13633
13680
|
}));
|
|
13634
13681
|
return {
|
|
13635
13682
|
headers,
|
|
@@ -14828,9 +14875,9 @@ async function eagerLoadHasRelation(instances, model, relatedClass, relationName
|
|
|
14828
14875
|
if (nested.length > 0 && related.length > 0) await relatedClass._eagerLoad(related, nested);
|
|
14829
14876
|
const fkProp = reverseMappedColumn(relatedClass, relation.foreignKey);
|
|
14830
14877
|
const grouped = {};
|
|
14831
|
-
for (const
|
|
14832
|
-
const key = _joinKey(
|
|
14833
|
-
(grouped[key] ??= []).push(
|
|
14878
|
+
for (const record2 of related) {
|
|
14879
|
+
const key = _joinKey(record2[fkProp]);
|
|
14880
|
+
(grouped[key] ??= []).push(record2);
|
|
14834
14881
|
}
|
|
14835
14882
|
for (const instance of instances) {
|
|
14836
14883
|
const records = grouped[_joinKey(instance[pk])] ?? [];
|
|
@@ -14846,7 +14893,7 @@ async function eagerLoadBelongsToRelation(instances, model, relatedClass, relati
|
|
|
14846
14893
|
const related = await eagerQueryRelated(relatedClass, relatedPkColumn, values);
|
|
14847
14894
|
if (nested.length > 0 && related.length > 0) await relatedClass._eagerLoad(related, nested);
|
|
14848
14895
|
const lookup2 = {};
|
|
14849
|
-
for (const
|
|
14896
|
+
for (const record2 of related) lookup2[_joinKey(record2[relatedPk])] = record2;
|
|
14850
14897
|
for (const instance of instances) {
|
|
14851
14898
|
const value = instance[fkProp];
|
|
14852
14899
|
relationshipCache(instance)[relationName] = value !== void 0 && value !== null ? lookup2[_joinKey(value)] ?? null : null;
|
|
@@ -18092,7 +18139,7 @@ var init_bolt = __esm({
|
|
|
18092
18139
|
const session = this.database ? this.driver.session({ database: this.database }) : this.driver.session();
|
|
18093
18140
|
try {
|
|
18094
18141
|
const result = await session.run(cypher, params ?? {});
|
|
18095
|
-
return result.records.map((
|
|
18142
|
+
return result.records.map((record2) => record2.toObject());
|
|
18096
18143
|
} catch (exc) {
|
|
18097
18144
|
this.lastError = errorMessage(exc);
|
|
18098
18145
|
const code = exc?.code ?? "";
|
|
@@ -23994,27 +24041,33 @@ function sleepSync(ms) {
|
|
|
23994
24041
|
if (ms <= 0) return;
|
|
23995
24042
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
23996
24043
|
}
|
|
23997
|
-
function
|
|
24044
|
+
function bindable(host, port) {
|
|
24045
|
+
try {
|
|
24046
|
+
execFileSync(process.execPath, ["-e", BIND_PROBE, host, String(port)], { stdio: "ignore", timeout: 5e3 });
|
|
24047
|
+
return true;
|
|
24048
|
+
} catch {
|
|
24049
|
+
return false;
|
|
24050
|
+
}
|
|
24051
|
+
}
|
|
24052
|
+
function refusal(port, dev, noTakeover, host) {
|
|
24053
|
+
if (dev && !noTakeover) return null;
|
|
24054
|
+
if (host !== void 0 && bindable(host, port)) {
|
|
24055
|
+
return { status: TAKEOVER_NOTHING, port, killed: [], message: "" };
|
|
24056
|
+
}
|
|
24057
|
+
if (noTakeover) {
|
|
24058
|
+
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.` };
|
|
24059
|
+
}
|
|
24060
|
+
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.` };
|
|
24061
|
+
}
|
|
24062
|
+
function takeOverPort(port, dev, noTakeover, baseDir, grace = 500, host) {
|
|
23998
24063
|
const make = (status2, killed2 = [], message = "") => ({
|
|
23999
24064
|
status: status2,
|
|
24000
24065
|
port,
|
|
24001
24066
|
killed: killed2,
|
|
24002
24067
|
message
|
|
24003
24068
|
});
|
|
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
|
-
}
|
|
24069
|
+
const early = refusal(port, dev, noTakeover, host);
|
|
24070
|
+
if (early !== null) return early;
|
|
24018
24071
|
if (inContainer()) return make(TAKEOVER_SKIPPED_CONTAINER);
|
|
24019
24072
|
const tokens = portHolders(port);
|
|
24020
24073
|
if (tokens.length === 0) return make(TAKEOVER_NOTHING);
|
|
@@ -24046,7 +24099,7 @@ function takeOverPort(port, dev, noTakeover, baseDir, grace = 500) {
|
|
|
24046
24099
|
`Reclaimed port ${port} from Tina4 dev server (PID: ${killed.join(", ")}).`
|
|
24047
24100
|
);
|
|
24048
24101
|
}
|
|
24049
|
-
var TAKEOVER_NOTHING, TAKEOVER_KILLED, TAKEOVER_REFUSED_FOREIGN, TAKEOVER_REFUSED_OPTOUT, TAKEOVER_REFUSED_PROD, TAKEOVER_SKIPPED_CONTAINER, TAKEOVER_REFUSALS;
|
|
24102
|
+
var TAKEOVER_NOTHING, TAKEOVER_KILLED, TAKEOVER_REFUSED_FOREIGN, TAKEOVER_REFUSED_OPTOUT, TAKEOVER_REFUSED_PROD, TAKEOVER_SKIPPED_CONTAINER, TAKEOVER_REFUSALS, BIND_PROBE;
|
|
24050
24103
|
var init_portTakeover = __esm({
|
|
24051
24104
|
"../core/src/portTakeover.ts"() {
|
|
24052
24105
|
"use strict";
|
|
@@ -24061,6 +24114,7 @@ var init_portTakeover = __esm({
|
|
|
24061
24114
|
TAKEOVER_REFUSED_OPTOUT,
|
|
24062
24115
|
TAKEOVER_REFUSED_PROD
|
|
24063
24116
|
];
|
|
24117
|
+
BIND_PROBE = 'const s = require("node:net").createServer();s.on("error", () => process.exit(1));s.listen({ host: process.argv[1], port: Number(process.argv[2]) }, () => s.close(() => process.exit(0)));';
|
|
24064
24118
|
}
|
|
24065
24119
|
});
|
|
24066
24120
|
|
|
@@ -26111,7 +26165,7 @@ var init_session = __esm({
|
|
|
26111
26165
|
save() {
|
|
26112
26166
|
if (!this.sessionId || !this.data) return true;
|
|
26113
26167
|
if (this.isFresh()) return true;
|
|
26114
|
-
let
|
|
26168
|
+
let record2 = this.data;
|
|
26115
26169
|
if (this.stored) {
|
|
26116
26170
|
const current = this.safeRead(this.sessionId);
|
|
26117
26171
|
if (this.lastReadFailed) return false;
|
|
@@ -26120,9 +26174,9 @@ var init_session = __esm({
|
|
|
26120
26174
|
this.ended = true;
|
|
26121
26175
|
return true;
|
|
26122
26176
|
}
|
|
26123
|
-
if (!this.cleared)
|
|
26177
|
+
if (!this.cleared) record2 = this.merged(current);
|
|
26124
26178
|
}
|
|
26125
|
-
if (this.safeWrite(this.sessionId,
|
|
26179
|
+
if (this.safeWrite(this.sessionId, record2, this.ttl)) {
|
|
26126
26180
|
this.dirty = false;
|
|
26127
26181
|
this.stored = true;
|
|
26128
26182
|
this.cleared = false;
|
|
@@ -26139,19 +26193,19 @@ var init_session = __esm({
|
|
|
26139
26193
|
*/
|
|
26140
26194
|
merged(current) {
|
|
26141
26195
|
const data = this.data;
|
|
26142
|
-
const
|
|
26196
|
+
const record2 = { ...current };
|
|
26143
26197
|
for (const [key, value] of Object.entries(data)) {
|
|
26144
26198
|
const print = fingerprint(value);
|
|
26145
26199
|
if (print === void 0 || !this.loaded.has(key) || this.loaded.get(key) !== print) {
|
|
26146
|
-
|
|
26200
|
+
record2[key] = value;
|
|
26147
26201
|
}
|
|
26148
26202
|
}
|
|
26149
26203
|
for (const key of this.loaded.keys()) {
|
|
26150
26204
|
if (!Object.prototype.hasOwnProperty.call(data, key)) {
|
|
26151
|
-
delete
|
|
26205
|
+
delete record2[key];
|
|
26152
26206
|
}
|
|
26153
26207
|
}
|
|
26154
|
-
return
|
|
26208
|
+
return record2;
|
|
26155
26209
|
}
|
|
26156
26210
|
/**
|
|
26157
26211
|
* End the session for this request without touching the store: no id and
|
|
@@ -31329,7 +31383,7 @@ data: ${channel.buffer.shift()}
|
|
|
31329
31383
|
}
|
|
31330
31384
|
return { resources };
|
|
31331
31385
|
}
|
|
31332
|
-
_handleResourcesRead(params) {
|
|
31386
|
+
async _handleResourcesRead(params) {
|
|
31333
31387
|
const uri = params.uri;
|
|
31334
31388
|
if (!uri) {
|
|
31335
31389
|
throw new Error("Missing resource URI");
|
|
@@ -31338,7 +31392,7 @@ data: ${channel.buffer.shift()}
|
|
|
31338
31392
|
if (!resource) {
|
|
31339
31393
|
throw new Error(`Unknown resource: ${uri}`);
|
|
31340
31394
|
}
|
|
31341
|
-
const result = resource.handler();
|
|
31395
|
+
const result = await resource.handler();
|
|
31342
31396
|
let text;
|
|
31343
31397
|
if (typeof result === "string") {
|
|
31344
31398
|
text = result;
|
|
@@ -34872,6 +34926,12 @@ const outBytes = new Uint8Array(workerData.sab, 8);
|
|
|
34872
34926
|
// (test/kafkaErrorCodes.test.ts) can assert the floors.
|
|
34873
34927
|
const PRODUCE_VERSION = 3;
|
|
34874
34928
|
const FETCH_VERSION = 4;
|
|
34929
|
+
// How long the broker long-polls an empty partition before answering (ms).
|
|
34930
|
+
// Deliberately 1000, not tina4-php / tina4-python's 5000: Node's pop() is
|
|
34931
|
+
// synchronous (Atomics.wait on this worker), so the long-poll blocks the whole
|
|
34932
|
+
// event loop, not one request. The tombstone-skip deadline caps it further while
|
|
34933
|
+
// stepping so a stream of tombstones cannot hold pop() past ~1s.
|
|
34934
|
+
const FETCH_MAX_WAIT_MS = 1000;
|
|
34875
34935
|
|
|
34876
34936
|
let correlationId = 0;
|
|
34877
34937
|
let brokerSock = null;
|
|
@@ -35058,12 +35118,13 @@ async function produce(topic, valueBytes) {
|
|
|
35058
35118
|
}
|
|
35059
35119
|
|
|
35060
35120
|
// \u2500\u2500 fetch \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
35061
|
-
function fetchRequest(topic, offset) {
|
|
35121
|
+
function fetchRequest(topic, offset, maxWaitMs) {
|
|
35122
|
+
if (maxWaitMs === undefined) maxWaitMs = FETCH_MAX_WAIT_MS;
|
|
35062
35123
|
const topicBuf = Buffer.from(topic, "utf-8");
|
|
35063
35124
|
const buf = Buffer.alloc(4 + 4 + 4 + 4 + 1 + 4 + 2 + topicBuf.length + 4 + 4 + 8 + 4);
|
|
35064
35125
|
let p = 0;
|
|
35065
35126
|
buf.writeInt32BE(-1, p); p += 4; // replicaId
|
|
35066
|
-
buf.writeInt32BE(
|
|
35127
|
+
buf.writeInt32BE(maxWaitMs, p); p += 4; // maxWaitMs (long-poll bound; capped by the tombstone-skip deadline)
|
|
35067
35128
|
buf.writeInt32BE(1, p); p += 4; // minBytes
|
|
35068
35129
|
buf.writeInt32BE(1048576, p); p += 4; // maxBytes
|
|
35069
35130
|
buf.writeInt8(0, p); p += 1; // isolation READ_UNCOMMITTED
|
|
@@ -35076,8 +35137,12 @@ function fetchRequest(topic, offset) {
|
|
|
35076
35137
|
buf.writeInt32BE(1048576, p); p += 4;
|
|
35077
35138
|
return frame(1, FETCH_VERSION, buf);
|
|
35078
35139
|
}
|
|
35079
|
-
// Decode the
|
|
35080
|
-
//
|
|
35140
|
+
// Decode the FIRST record of the partition's record-set (the cross-framework
|
|
35141
|
+
// contract: only a batch's first record is decoded -- the Tina4 producer writes
|
|
35142
|
+
// one record per batch). Returns its value and absolute offset (baseOffset +
|
|
35143
|
+
// offsetDelta); a tombstone (null value) comes back with value null and its
|
|
35144
|
+
// offset so the caller can step past it. null = no usable record at all (empty /
|
|
35145
|
+
// old-format / short response).
|
|
35081
35146
|
function firstRecord(buf, start, end) {
|
|
35082
35147
|
let pos = start;
|
|
35083
35148
|
while (pos + 12 <= end) {
|
|
@@ -35093,8 +35158,7 @@ function firstRecord(buf, start, end) {
|
|
|
35093
35158
|
for (let i = 0; i < recordsCount && r < batchEnd; i++) {
|
|
35094
35159
|
const recLen = readVarint(buf, r);
|
|
35095
35160
|
let rp = recLen.next;
|
|
35096
|
-
|
|
35097
|
-
rp += 1;
|
|
35161
|
+
rp += 1; // record attributes byte
|
|
35098
35162
|
rp = readVarint(buf, rp).next; // timestampDelta
|
|
35099
35163
|
const offDelta = readVarint(buf, rp); rp = offDelta.next;
|
|
35100
35164
|
const keyLen = readVarint(buf, rp); rp = keyLen.next;
|
|
@@ -35106,15 +35170,23 @@ function firstRecord(buf, start, end) {
|
|
|
35106
35170
|
offset: Number(baseOffset) + offDelta.value,
|
|
35107
35171
|
};
|
|
35108
35172
|
}
|
|
35109
|
-
|
|
35173
|
+
// Tombstone (null value) or empty value: hand back a marker carrying its
|
|
35174
|
+
// offset instead of null. Returning null here used to mean "no record", so
|
|
35175
|
+
// pop() never advanced and re-fetched the tombstone for ever -- nothing
|
|
35176
|
+
// after it was delivered. The caller (fetchPastTombstones) steps the
|
|
35177
|
+
// offset on and re-fetches.
|
|
35178
|
+
return {
|
|
35179
|
+
value: null,
|
|
35180
|
+
offset: Number(baseOffset) + offDelta.value,
|
|
35181
|
+
};
|
|
35110
35182
|
}
|
|
35111
35183
|
pos = batchEnd;
|
|
35112
35184
|
}
|
|
35113
35185
|
return null;
|
|
35114
35186
|
}
|
|
35115
|
-
async function fetchAt(topic, offset) {
|
|
35187
|
+
async function fetchAt(topic, offset, maxWaitMs) {
|
|
35116
35188
|
const sock = await broker();
|
|
35117
|
-
const resp = await rpc(sock, fetchRequest(topic, offset));
|
|
35189
|
+
const resp = await rpc(sock, fetchRequest(topic, offset, maxWaitMs));
|
|
35118
35190
|
let pos = 4; // correlationId
|
|
35119
35191
|
pos += 4; // throttleTimeMs
|
|
35120
35192
|
const topicCount = resp.readInt32BE(pos); pos += 4;
|
|
@@ -35250,9 +35322,37 @@ async function broker() {
|
|
|
35250
35322
|
// Resume from the committed offset on the FIRST read of a topic in this worker,
|
|
35251
35323
|
// then advance the in-memory cursor; the committed offset only moves on a
|
|
35252
35324
|
// commit, so it lags and a crash before commit replays (at-least-once).
|
|
35325
|
+
// Fetch from the cursor, stepping past tombstones, until a record with a value
|
|
35326
|
+
// arrives, the topic is exhausted, or the deadline passes. A tombstone (null
|
|
35327
|
+
// value: Debezium deletes, compacted-topic delete markers) carries no job;
|
|
35328
|
+
// returning "nothing" without moving the offset re-fetched it for ever, so
|
|
35329
|
+
// nothing after it was ever delivered. The 1 s deadline holds while skipping
|
|
35330
|
+
// (the same steady-state bound as tina4-php/tina4-python), and the whole loop
|
|
35331
|
+
// stays inside this one worker round-trip (ADR-0022) -- well under
|
|
35332
|
+
// CALL_TIMEOUT_MS. Nothing is committed here: acknowledging the next record
|
|
35333
|
+
// commits past the skipped tombstones, as before.
|
|
35334
|
+
async function fetchPastTombstones(topic) {
|
|
35335
|
+
const deadline = Date.now() + 1000;
|
|
35336
|
+
let maxWaitMs = FETCH_MAX_WAIT_MS;
|
|
35337
|
+
while (true) {
|
|
35338
|
+
const offset = offsets[topic];
|
|
35339
|
+
const rec = await fetchAt(topic, offset, maxWaitMs);
|
|
35340
|
+
if (rec === null || rec.value !== null) return rec; // nothing, or a real record
|
|
35341
|
+
// Anti-spin: the decoder reads only a batch's first record, so a tombstone
|
|
35342
|
+
// sharing a batch with later records comes back at an offset already passed.
|
|
35343
|
+
// That must never loop this fetch.
|
|
35344
|
+
const next = rec.offset + 1;
|
|
35345
|
+
if (next <= offset) return null;
|
|
35346
|
+
offsets[topic] = next;
|
|
35347
|
+
const remaining = deadline - Date.now();
|
|
35348
|
+
if (remaining <= 0) return null;
|
|
35349
|
+
maxWaitMs = remaining;
|
|
35350
|
+
}
|
|
35351
|
+
}
|
|
35352
|
+
|
|
35253
35353
|
async function fetchNext(topic) {
|
|
35254
35354
|
if (!(topic in offsets)) offsets[topic] = await offsetFetch(topic);
|
|
35255
|
-
const rec = await
|
|
35355
|
+
const rec = await fetchPastTombstones(topic);
|
|
35256
35356
|
if (rec === null) return null;
|
|
35257
35357
|
offsets[topic] = rec.offset + 1;
|
|
35258
35358
|
return rec;
|
|
@@ -35757,7 +35857,7 @@ var init_liteBackend = __esm({
|
|
|
35757
35857
|
writeReserved(queue, job) {
|
|
35758
35858
|
const now = this.nowIso();
|
|
35759
35859
|
const vt = this.visibilityTimeout || 0;
|
|
35760
|
-
const
|
|
35860
|
+
const record2 = {
|
|
35761
35861
|
id: job.id,
|
|
35762
35862
|
payload: job.payload,
|
|
35763
35863
|
status: "reserved",
|
|
@@ -35769,7 +35869,7 @@ var init_liteBackend = __esm({
|
|
|
35769
35869
|
createdAt: job.createdAt ?? now,
|
|
35770
35870
|
topic: job.topic ?? queue
|
|
35771
35871
|
};
|
|
35772
|
-
writeFileSync12(this.reservedPath(queue,
|
|
35872
|
+
writeFileSync12(this.reservedPath(queue, record2.id), JSON.stringify(record2, null, 2));
|
|
35773
35873
|
}
|
|
35774
35874
|
/**
|
|
35775
35875
|
* Return expired reservations to the queue (at-least-once delivery).
|
|
@@ -35791,29 +35891,29 @@ var init_liteBackend = __esm({
|
|
|
35791
35891
|
}
|
|
35792
35892
|
for (const filename of filenames) {
|
|
35793
35893
|
const filePath = join25(reservedDir, filename);
|
|
35794
|
-
let
|
|
35894
|
+
let record2;
|
|
35795
35895
|
try {
|
|
35796
|
-
|
|
35896
|
+
record2 = JSON.parse(readFileSync16(filePath, "utf-8"));
|
|
35797
35897
|
} catch {
|
|
35798
35898
|
continue;
|
|
35799
35899
|
}
|
|
35800
|
-
if (
|
|
35900
|
+
if (record2.availableAt && record2.availableAt > now) continue;
|
|
35801
35901
|
try {
|
|
35802
35902
|
unlinkSync8(filePath);
|
|
35803
35903
|
} catch {
|
|
35804
35904
|
continue;
|
|
35805
35905
|
}
|
|
35806
|
-
const attempts = (
|
|
35906
|
+
const attempts = (record2.attempts ?? 0) + 1;
|
|
35807
35907
|
const error2 = "reservation timed out \u2014 consumer did not acknowledge within the visibility timeout";
|
|
35808
35908
|
const job = {
|
|
35809
|
-
id:
|
|
35810
|
-
payload:
|
|
35909
|
+
id: record2.id,
|
|
35910
|
+
payload: record2.payload,
|
|
35811
35911
|
status: "reserved",
|
|
35812
|
-
createdAt:
|
|
35912
|
+
createdAt: record2.createdAt ?? now,
|
|
35813
35913
|
attempts,
|
|
35814
35914
|
delayUntil: null,
|
|
35815
|
-
priority:
|
|
35816
|
-
topic:
|
|
35915
|
+
priority: record2.priority ?? 0,
|
|
35916
|
+
topic: record2.topic ?? queue,
|
|
35817
35917
|
error: error2
|
|
35818
35918
|
};
|
|
35819
35919
|
if (attempts >= maxRetries) {
|
|
@@ -40302,6 +40402,7 @@ var init_devAdmin = __esm({
|
|
|
40302
40402
|
const mem = process.memoryUsage();
|
|
40303
40403
|
const heapUsedMb = Math.round(mem.heapUsed / 1048576);
|
|
40304
40404
|
const rssMb = Math.round(mem.rss / 1048576);
|
|
40405
|
+
const peakRssMb = Math.round(process.resourceUsage().maxRSS / 1024);
|
|
40305
40406
|
let dbTableCount;
|
|
40306
40407
|
let dbConnected = false;
|
|
40307
40408
|
try {
|
|
@@ -40318,12 +40419,14 @@ var init_devAdmin = __esm({
|
|
|
40318
40419
|
architecture: process.arch,
|
|
40319
40420
|
os: `${process.platform} ${process.arch}`,
|
|
40320
40421
|
pid: process.pid,
|
|
40321
|
-
|
|
40422
|
+
// The dashboard's "Memory": the process's current RSS, as tina4-python
|
|
40423
|
+
// reports it. V8's heapUsed (below) leaves out Buffers and native memory.
|
|
40424
|
+
memory_mb: rssMb,
|
|
40322
40425
|
db_tables: dbTableCount !== void 0 ? dbTableCount : "N/A",
|
|
40323
40426
|
db_connected: dbConnected,
|
|
40324
40427
|
memory: {
|
|
40325
|
-
current_mb:
|
|
40326
|
-
peak_mb:
|
|
40428
|
+
current_mb: rssMb,
|
|
40429
|
+
peak_mb: peakRssMb,
|
|
40327
40430
|
limit: "V8 default",
|
|
40328
40431
|
rss: `${rssMb} MB`,
|
|
40329
40432
|
heapUsed: `${heapUsedMb} MB`,
|
|
@@ -43260,6 +43363,33 @@ var init_docsAutoDiscovery = __esm({
|
|
|
43260
43363
|
});
|
|
43261
43364
|
|
|
43262
43365
|
// ../core/src/server.ts
|
|
43366
|
+
var server_exports = {};
|
|
43367
|
+
__export(server_exports, {
|
|
43368
|
+
CI_ENVIRONMENT_VARIABLES: () => CI_ENVIRONMENT_VARIABLES,
|
|
43369
|
+
CI_NOT_SET_VALUES: () => CI_NOT_SET_VALUES,
|
|
43370
|
+
DEFAULT_SHUTDOWN_TIMEOUT_SECONDS: () => DEFAULT_SHUTDOWN_TIMEOUT_SECONDS,
|
|
43371
|
+
_checkLegacyEnvVars: () => _checkLegacyEnvVars,
|
|
43372
|
+
autoMigrateOnStartup: () => autoMigrateOnStartup,
|
|
43373
|
+
bannerSurfaceLines: () => bannerSurfaceLines,
|
|
43374
|
+
buildDispatchContext: () => buildDispatchContext,
|
|
43375
|
+
getLiveDispatchContext: () => getLiveDispatchContext,
|
|
43376
|
+
handle: () => handle,
|
|
43377
|
+
httpReason: () => httpReason,
|
|
43378
|
+
isBannerSuppressed: () => isBannerSuppressed,
|
|
43379
|
+
killPort: () => killPort,
|
|
43380
|
+
loopbackBindHosts: () => loopbackBindHosts,
|
|
43381
|
+
resetTemplateCache: () => resetTemplateCache,
|
|
43382
|
+
resolveHandlerArgs: () => resolveHandlerArgs,
|
|
43383
|
+
resolvePortAndHost: () => resolvePortAndHost,
|
|
43384
|
+
resolveTemplate: () => resolveTemplate,
|
|
43385
|
+
runDispatch: () => runDispatch,
|
|
43386
|
+
shouldOpenBrowser: () => shouldOpenBrowser,
|
|
43387
|
+
shutdownTimeoutSeconds: () => shutdownTimeoutSeconds,
|
|
43388
|
+
start: () => start,
|
|
43389
|
+
startServer: () => startServer,
|
|
43390
|
+
stop: () => stop,
|
|
43391
|
+
templateAutoRoutingEnabled: () => templateAutoRoutingEnabled
|
|
43392
|
+
});
|
|
43263
43393
|
import { randomBytes as randomBytes9 } from "node:crypto";
|
|
43264
43394
|
import { resolve as resolve20, dirname as dirname16, join as join32, relative as relative10 } from "node:path";
|
|
43265
43395
|
import { existsSync as existsSync27, readdirSync as readdirSync18, readFileSync as readFileSync23, statSync as statSync19 } from "node:fs";
|
|
@@ -43299,6 +43429,32 @@ function swaggerAdvertised() {
|
|
|
43299
43429
|
}
|
|
43300
43430
|
return TRUTHY3.includes(raw);
|
|
43301
43431
|
}
|
|
43432
|
+
function stripUrlCredentials(text) {
|
|
43433
|
+
return text.replace(/:\/\/[^/\s]*@/g, "://");
|
|
43434
|
+
}
|
|
43435
|
+
function isModuleNotFound(err) {
|
|
43436
|
+
const code = err?.code;
|
|
43437
|
+
return code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND";
|
|
43438
|
+
}
|
|
43439
|
+
function reportOrmBootFailure(stage, err, dbConfig) {
|
|
43440
|
+
const message = stripUrlCredentials(err instanceof Error ? err.message : String(err));
|
|
43441
|
+
if (stage === "connect") {
|
|
43442
|
+
const url = (process.env.TINA4_DATABASE_URL ?? "").trim();
|
|
43443
|
+
const target = url ? stripUrlCredentials(url) : `${dbConfig.type ?? "sqlite"} ${dbConfig.path ?? "./data/tina4.db"}`;
|
|
43444
|
+
bootDbConnectError = message;
|
|
43445
|
+
console.warn(`
|
|
43446
|
+
Database could not be reached (${target}): ${message}`);
|
|
43447
|
+
} else if (stage === "import" && isModuleNotFound(err)) {
|
|
43448
|
+
console.warn(`
|
|
43449
|
+
ORM not available (install @tina4/orm to enable): ${message}`);
|
|
43450
|
+
} else if (stage === "import") {
|
|
43451
|
+
console.warn(`
|
|
43452
|
+
ORM failed to load:`, err);
|
|
43453
|
+
} else {
|
|
43454
|
+
console.warn(`
|
|
43455
|
+
ORM model setup failed:`, err);
|
|
43456
|
+
}
|
|
43457
|
+
}
|
|
43302
43458
|
async function autoMigrateOnStartup(migrationDir = "migrations", base = process.cwd()) {
|
|
43303
43459
|
const dir = resolve20(base, migrationDir);
|
|
43304
43460
|
if (!existsSync27(dir)) return;
|
|
@@ -43317,9 +43473,20 @@ async function autoMigrateOnStartup(migrationDir = "migrations", base = process.
|
|
|
43317
43473
|
let orm;
|
|
43318
43474
|
try {
|
|
43319
43475
|
orm = await Promise.resolve().then(() => (init_src(), src_exports));
|
|
43476
|
+
} catch (err) {
|
|
43477
|
+
Log.debug(`Startup migrations skipped (ORM not available): ${stripUrlCredentials(err instanceof Error ? err.message : String(err))}`);
|
|
43478
|
+
return;
|
|
43479
|
+
}
|
|
43480
|
+
try {
|
|
43320
43481
|
orm.getAdapter();
|
|
43321
43482
|
} catch (err) {
|
|
43322
|
-
|
|
43483
|
+
const configuredUrl = (process.env.TINA4_DATABASE_URL ?? "").trim();
|
|
43484
|
+
const cause = stripUrlCredentials(bootDbConnectError ?? (err instanceof Error ? err.message : String(err)));
|
|
43485
|
+
if (configuredUrl) {
|
|
43486
|
+
Log.debug(`Startup migrations skipped (database configured but could not connect to ${stripUrlCredentials(configuredUrl)}): ${cause}`);
|
|
43487
|
+
} else {
|
|
43488
|
+
Log.debug(`Startup migrations skipped (no database configured): ${cause}`);
|
|
43489
|
+
}
|
|
43323
43490
|
return;
|
|
43324
43491
|
}
|
|
43325
43492
|
try {
|
|
@@ -44242,9 +44409,10 @@ function wireLocaleGlobal(frondEngine, base) {
|
|
|
44242
44409
|
if (!existsSync27(localeDir)) return;
|
|
44243
44410
|
try {
|
|
44244
44411
|
const localeFiles = readdirSync18(localeDir).filter((file) => file.endsWith(".json"));
|
|
44245
|
-
|
|
44412
|
+
const FrondClass = frondEngine.constructor;
|
|
44413
|
+
if (localeFiles.length === 0 || FrondClass.hasGlobal("t") || frondEngine.globals?.t) return;
|
|
44246
44414
|
const i18nInstance = new I18n(process.env.TINA4_LOCALE ?? "en", localeDir);
|
|
44247
|
-
|
|
44415
|
+
FrondClass.addGlobal("t", (key, params) => i18nInstance.t(key, params));
|
|
44248
44416
|
} catch {
|
|
44249
44417
|
}
|
|
44250
44418
|
}
|
|
@@ -44577,13 +44745,17 @@ async function initializeOrm(config, router, base, ormDir, modelsDir) {
|
|
|
44577
44745
|
const hasOrmDir = existsSync27(ormDir);
|
|
44578
44746
|
const hasModelsDir = existsSync27(modelsDir);
|
|
44579
44747
|
if (hasOrmDir || hasModelsDir) {
|
|
44748
|
+
let ormStage = "import";
|
|
44749
|
+
const dbConfig = config?.database ?? {};
|
|
44580
44750
|
try {
|
|
44581
44751
|
const orm = await Promise.resolve().then(() => (init_src(), src_exports));
|
|
44582
|
-
|
|
44752
|
+
ormStage = "connect";
|
|
44753
|
+
bootDbConnectError = null;
|
|
44583
44754
|
await orm.initDatabase({
|
|
44584
44755
|
type: dbConfig.type ?? "sqlite",
|
|
44585
44756
|
path: dbConfig.path ?? "./data/tina4.db"
|
|
44586
44757
|
});
|
|
44758
|
+
ormStage = "models";
|
|
44587
44759
|
let models = hasOrmDir ? await orm.discoverModels(ormDir) : [];
|
|
44588
44760
|
if (hasModelsDir) {
|
|
44589
44761
|
const extraModels = await orm.discoverModels(modelsDir);
|
|
@@ -44618,8 +44790,7 @@ async function initializeOrm(config, router, base, ormDir, modelsDir) {
|
|
|
44618
44790
|
}
|
|
44619
44791
|
}
|
|
44620
44792
|
} catch (err) {
|
|
44621
|
-
|
|
44622
|
-
ORM not available (install @tina4/orm to enable):`, err);
|
|
44793
|
+
reportOrmBootFailure(ormStage, err, dbConfig);
|
|
44623
44794
|
}
|
|
44624
44795
|
await autoMigrateOnStartup("migrations", base);
|
|
44625
44796
|
}
|
|
@@ -44657,7 +44828,7 @@ async function configureSwagger(router, ormDir, modelsDir) {
|
|
|
44657
44828
|
}
|
|
44658
44829
|
return enabled;
|
|
44659
44830
|
}
|
|
44660
|
-
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;
|
|
44831
|
+
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;
|
|
44661
44832
|
var init_server = __esm({
|
|
44662
44833
|
"../core/src/server.ts"() {
|
|
44663
44834
|
"use strict";
|
|
@@ -44692,6 +44863,7 @@ var init_server = __esm({
|
|
|
44692
44863
|
BUILTIN_PUBLIC_DIR = resolve20(__dirname, "..", "public");
|
|
44693
44864
|
swaggerAssetsEnabled = false;
|
|
44694
44865
|
DEFAULT_SHUTDOWN_TIMEOUT_SECONDS = 30;
|
|
44866
|
+
bootDbConnectError = null;
|
|
44695
44867
|
frondCache2 = /* @__PURE__ */ new Map();
|
|
44696
44868
|
_LEGACY_ENV_VARS = {
|
|
44697
44869
|
DATABASE_URL: "TINA4_DATABASE_URL",
|
|
@@ -49902,26 +50074,26 @@ var init_aiClient = __esm({
|
|
|
49902
50074
|
if (!part || typeof part !== "object" || Array.isArray(part)) {
|
|
49903
50075
|
throw new AiConfigError("AI content part must be an object with type and text/source");
|
|
49904
50076
|
}
|
|
49905
|
-
const
|
|
49906
|
-
switch (
|
|
50077
|
+
const record2 = part;
|
|
50078
|
+
switch (record2.type) {
|
|
49907
50079
|
case "text":
|
|
49908
|
-
this.validateTextPart(
|
|
50080
|
+
this.validateTextPart(record2);
|
|
49909
50081
|
return;
|
|
49910
50082
|
case "image":
|
|
49911
|
-
this.validateImagePart(
|
|
50083
|
+
this.validateImagePart(record2);
|
|
49912
50084
|
return;
|
|
49913
50085
|
case "tool_result":
|
|
49914
|
-
this.validateToolResultPart(
|
|
50086
|
+
this.validateToolResultPart(record2);
|
|
49915
50087
|
return;
|
|
49916
50088
|
default:
|
|
49917
|
-
throw new AiConfigError(`AI content part has unknown type '${String(
|
|
50089
|
+
throw new AiConfigError(`AI content part has unknown type '${String(record2.type)}'`);
|
|
49918
50090
|
}
|
|
49919
50091
|
}
|
|
49920
|
-
static validateTextPart(
|
|
49921
|
-
if (typeof
|
|
50092
|
+
static validateTextPart(record2) {
|
|
50093
|
+
if (typeof record2.text !== "string") throw new AiConfigError("AI text content part requires a string 'text' field");
|
|
49922
50094
|
}
|
|
49923
|
-
static validateImagePart(
|
|
49924
|
-
const source =
|
|
50095
|
+
static validateImagePart(record2) {
|
|
50096
|
+
const source = record2.source;
|
|
49925
50097
|
if (typeof source !== "string" || source.length === 0) {
|
|
49926
50098
|
throw new AiConfigError("AI image content part requires a non-empty string 'source' field");
|
|
49927
50099
|
}
|
|
@@ -49932,11 +50104,11 @@ var init_aiClient = __esm({
|
|
|
49932
50104
|
throw new AiConfigError("AI image data URI must be data:<media_type>;base64,<payload>");
|
|
49933
50105
|
}
|
|
49934
50106
|
}
|
|
49935
|
-
static validateToolResultPart(
|
|
49936
|
-
if (typeof
|
|
50107
|
+
static validateToolResultPart(record2) {
|
|
50108
|
+
if (typeof record2.tool_use_id !== "string" || record2.tool_use_id.length === 0) {
|
|
49937
50109
|
throw new AiConfigError("AI tool_result part requires a non-empty string 'tool_use_id'");
|
|
49938
50110
|
}
|
|
49939
|
-
if (typeof
|
|
50111
|
+
if (typeof record2.content !== "string") throw new AiConfigError("AI tool_result part requires a string 'content'");
|
|
49940
50112
|
}
|
|
49941
50113
|
/**
|
|
49942
50114
|
* Validate the outbound tool declarations (ADR-0061). Each tool needs a
|
|
@@ -49952,14 +50124,14 @@ var init_aiClient = __esm({
|
|
|
49952
50124
|
if (!tool || typeof tool !== "object" || Array.isArray(tool)) {
|
|
49953
50125
|
throw new AiConfigError("AI tool must be an object with name, description, parameters");
|
|
49954
50126
|
}
|
|
49955
|
-
const
|
|
49956
|
-
if (typeof
|
|
50127
|
+
const record2 = tool;
|
|
50128
|
+
if (typeof record2.name !== "string" || record2.name.length === 0) {
|
|
49957
50129
|
throw new AiConfigError("AI tool requires a non-empty string 'name'");
|
|
49958
50130
|
}
|
|
49959
|
-
if (typeof
|
|
50131
|
+
if (typeof record2.description !== "string") {
|
|
49960
50132
|
throw new AiConfigError("AI tool requires a string 'description'");
|
|
49961
50133
|
}
|
|
49962
|
-
if (!
|
|
50134
|
+
if (!record2.parameters || typeof record2.parameters !== "object" || Array.isArray(record2.parameters)) {
|
|
49963
50135
|
throw new AiConfigError("AI tool requires a JSON-Schema object 'parameters'");
|
|
49964
50136
|
}
|
|
49965
50137
|
}
|
|
@@ -49976,8 +50148,8 @@ var init_aiClient = __esm({
|
|
|
49976
50148
|
return;
|
|
49977
50149
|
}
|
|
49978
50150
|
if (choice && typeof choice === "object" && !Array.isArray(choice)) {
|
|
49979
|
-
const
|
|
49980
|
-
if (typeof
|
|
50151
|
+
const record2 = choice;
|
|
50152
|
+
if (typeof record2.name !== "string" || record2.name.length === 0) {
|
|
49981
50153
|
throw new AiConfigError("AI toolChoice object requires a non-empty string 'name'");
|
|
49982
50154
|
}
|
|
49983
50155
|
return;
|
|
@@ -51042,38 +51214,37 @@ function runAll(options = {}) {
|
|
|
51042
51214
|
const { quiet = false, failfast = false } = options;
|
|
51043
51215
|
const results = { passed: 0, failed: 0, errors: 0, details: [] };
|
|
51044
51216
|
for (const entry of registry2) {
|
|
51045
|
-
if (!quiet)
|
|
51046
|
-
console.log(`
|
|
51217
|
+
if (!quiet) console.log(`
|
|
51047
51218
|
${entry.name}`);
|
|
51219
|
+
for (const assertion of entry.assertions) {
|
|
51220
|
+
const label = assertionLabel(assertion, entry.name);
|
|
51221
|
+
const ok = record(results, label, quiet, () => judge(assertion, callSync(entry.fn, assertion.args)));
|
|
51222
|
+
if (!ok && failfast) {
|
|
51223
|
+
printSummary(results, quiet);
|
|
51224
|
+
return results;
|
|
51225
|
+
}
|
|
51048
51226
|
}
|
|
51227
|
+
}
|
|
51228
|
+
printSummary(results, quiet);
|
|
51229
|
+
return results;
|
|
51230
|
+
}
|
|
51231
|
+
async function runAllAsync(options = {}) {
|
|
51232
|
+
const { quiet = false, failfast = false, timeoutMs = 3e4 } = options;
|
|
51233
|
+
checkTimeout(timeoutMs);
|
|
51234
|
+
const results = { passed: 0, failed: 0, errors: 0, details: [] };
|
|
51235
|
+
for (const entry of registry2) {
|
|
51236
|
+
if (!quiet) console.log(`
|
|
51237
|
+
${entry.name}`);
|
|
51049
51238
|
for (const assertion of entry.assertions) {
|
|
51050
51239
|
const label = assertionLabel(assertion, entry.name);
|
|
51051
|
-
|
|
51052
|
-
|
|
51053
|
-
|
|
51054
|
-
|
|
51055
|
-
|
|
51056
|
-
|
|
51057
|
-
|
|
51058
|
-
|
|
51059
|
-
if (err instanceof TestAssertionError) {
|
|
51060
|
-
results.failed++;
|
|
51061
|
-
results.details.push({ name: label, status: "failed", message: err.message });
|
|
51062
|
-
if (!quiet) {
|
|
51063
|
-
console.log(` \x1B[31mx\x1B[0m ${label}: ${err.message}`);
|
|
51064
|
-
}
|
|
51065
|
-
} else {
|
|
51066
|
-
results.errors++;
|
|
51067
|
-
const msg = err instanceof Error ? `${err.constructor.name}: ${err.message}` : String(err);
|
|
51068
|
-
results.details.push({ name: label, status: "error", message: msg });
|
|
51069
|
-
if (!quiet) {
|
|
51070
|
-
console.log(` \x1B[33m!\x1B[0m ${label}: ${msg}`);
|
|
51071
|
-
}
|
|
51072
|
-
}
|
|
51073
|
-
if (failfast) {
|
|
51074
|
-
printSummary(results, quiet);
|
|
51075
|
-
return results;
|
|
51076
|
-
}
|
|
51240
|
+
const outcome = await callAsync(entry.fn, assertion.args, timeoutMs);
|
|
51241
|
+
const ok = record(results, label, quiet, () => {
|
|
51242
|
+
if (outcome instanceof TestRunError) throw outcome;
|
|
51243
|
+
judge(assertion, outcome);
|
|
51244
|
+
});
|
|
51245
|
+
if (!ok && failfast) {
|
|
51246
|
+
printSummary(results, quiet);
|
|
51247
|
+
return results;
|
|
51077
51248
|
}
|
|
51078
51249
|
}
|
|
51079
51250
|
}
|
|
@@ -51083,47 +51254,103 @@ function runAll(options = {}) {
|
|
|
51083
51254
|
function reset() {
|
|
51084
51255
|
registry2.length = 0;
|
|
51085
51256
|
}
|
|
51086
|
-
function
|
|
51087
|
-
|
|
51257
|
+
function isThenable(value) {
|
|
51258
|
+
return value !== null && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
|
|
51259
|
+
}
|
|
51260
|
+
function callSync(fn, args) {
|
|
51261
|
+
let value;
|
|
51262
|
+
try {
|
|
51263
|
+
value = fn(...args);
|
|
51264
|
+
} catch (error2) {
|
|
51265
|
+
return { threw: true, error: error2 };
|
|
51266
|
+
}
|
|
51267
|
+
if (isThenable(value)) {
|
|
51268
|
+
Promise.resolve(value).then(void 0, () => void 0);
|
|
51269
|
+
throw new TestRunError(
|
|
51270
|
+
"returned a Promise (async test function): runAll() cannot judge it, use await runAllAsync()"
|
|
51271
|
+
);
|
|
51272
|
+
}
|
|
51273
|
+
return { threw: false, value };
|
|
51274
|
+
}
|
|
51275
|
+
function checkTimeout(timeoutMs) {
|
|
51276
|
+
if (timeoutMs === Infinity) return;
|
|
51277
|
+
if (!(timeoutMs > 0 && timeoutMs <= MAX_TIMER_MS)) {
|
|
51278
|
+
throw new RangeError(
|
|
51279
|
+
`timeoutMs must be Infinity or a number of milliseconds in (0, ${MAX_TIMER_MS}], got ${timeoutMs}`
|
|
51280
|
+
);
|
|
51281
|
+
}
|
|
51282
|
+
}
|
|
51283
|
+
async function callAsync(fn, args, timeoutMs) {
|
|
51284
|
+
let timer;
|
|
51285
|
+
try {
|
|
51286
|
+
const value = fn(...args);
|
|
51287
|
+
if (!isThenable(value)) return { threw: false, value };
|
|
51288
|
+
if (timeoutMs === Infinity) return { threw: false, value: await value };
|
|
51289
|
+
const timeout = new Promise((_, reject) => {
|
|
51290
|
+
timer = setTimeout(
|
|
51291
|
+
() => reject(new TestRunError(`did not settle within ${timeoutMs} ms`)),
|
|
51292
|
+
timeoutMs
|
|
51293
|
+
);
|
|
51294
|
+
});
|
|
51295
|
+
return { threw: false, value: await Promise.race([Promise.resolve(value), timeout]) };
|
|
51296
|
+
} catch (error2) {
|
|
51297
|
+
if (error2 instanceof TestRunError) return error2;
|
|
51298
|
+
return { threw: true, error: error2 };
|
|
51299
|
+
} finally {
|
|
51300
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
51301
|
+
}
|
|
51302
|
+
}
|
|
51303
|
+
function record(results, label, quiet, check) {
|
|
51304
|
+
try {
|
|
51305
|
+
check();
|
|
51306
|
+
results.passed++;
|
|
51307
|
+
results.details.push({ name: label, status: "passed" });
|
|
51308
|
+
if (!quiet) console.log(` \x1B[32m+\x1B[0m ${label}`);
|
|
51309
|
+
return true;
|
|
51310
|
+
} catch (err) {
|
|
51311
|
+
if (err instanceof TestAssertionError) {
|
|
51312
|
+
results.failed++;
|
|
51313
|
+
results.details.push({ name: label, status: "failed", message: err.message });
|
|
51314
|
+
if (!quiet) console.log(` \x1B[31mx\x1B[0m ${label}: ${err.message}`);
|
|
51315
|
+
} else {
|
|
51316
|
+
results.errors++;
|
|
51317
|
+
const msg = err instanceof Error ? `${err.constructor.name}: ${err.message}` : String(err);
|
|
51318
|
+
results.details.push({ name: label, status: "error", message: msg });
|
|
51319
|
+
if (!quiet) console.log(` \x1B[33m!\x1B[0m ${label}: ${msg}`);
|
|
51320
|
+
}
|
|
51321
|
+
return false;
|
|
51322
|
+
}
|
|
51323
|
+
}
|
|
51324
|
+
function judgeRaises(assertion, outcome) {
|
|
51325
|
+
const ExcClass = assertion.exception;
|
|
51326
|
+
if (!outcome.threw) throw new TestAssertionError(`expected ${ExcClass.name} to be raised`);
|
|
51327
|
+
const err = outcome.error;
|
|
51328
|
+
if (err instanceof ExcClass) return;
|
|
51329
|
+
throw new TestAssertionError(
|
|
51330
|
+
`expected ${ExcClass.name}, got ${err instanceof Error ? err.constructor.name : typeof err}: ${err}`
|
|
51331
|
+
);
|
|
51332
|
+
}
|
|
51333
|
+
function judge(assertion, outcome) {
|
|
51334
|
+
const { type: type2 } = assertion;
|
|
51335
|
+
if (type2 === "raises") return judgeRaises(assertion, outcome);
|
|
51336
|
+
if (outcome.threw) throw outcome.error;
|
|
51337
|
+
const result = outcome.value;
|
|
51088
51338
|
switch (type2) {
|
|
51089
51339
|
case "equal": {
|
|
51090
|
-
const result = fn(...args);
|
|
51091
51340
|
const expected = assertion.expected;
|
|
51092
51341
|
if (result !== expected) {
|
|
51093
51342
|
throw new TestAssertionError(
|
|
51094
51343
|
`expected ${JSON.stringify(expected)}, got ${JSON.stringify(result)}`
|
|
51095
51344
|
);
|
|
51096
51345
|
}
|
|
51097
|
-
|
|
51098
|
-
}
|
|
51099
|
-
case "raises": {
|
|
51100
|
-
const ExcClass = assertion.exception;
|
|
51101
|
-
try {
|
|
51102
|
-
fn(...args);
|
|
51103
|
-
} catch (err) {
|
|
51104
|
-
if (err instanceof ExcClass) {
|
|
51105
|
-
return;
|
|
51106
|
-
}
|
|
51107
|
-
throw new TestAssertionError(
|
|
51108
|
-
`expected ${ExcClass.name}, got ${err instanceof Error ? err.constructor.name : typeof err}: ${err}`
|
|
51109
|
-
);
|
|
51110
|
-
}
|
|
51111
|
-
throw new TestAssertionError(`expected ${ExcClass.name} to be raised`);
|
|
51112
|
-
}
|
|
51113
|
-
case "true": {
|
|
51114
|
-
const result = fn(...args);
|
|
51115
|
-
if (!result) {
|
|
51116
|
-
throw new TestAssertionError(`expected truthy, got ${JSON.stringify(result)}`);
|
|
51117
|
-
}
|
|
51118
|
-
break;
|
|
51119
|
-
}
|
|
51120
|
-
case "false": {
|
|
51121
|
-
const result = fn(...args);
|
|
51122
|
-
if (result) {
|
|
51123
|
-
throw new TestAssertionError(`expected falsy, got ${JSON.stringify(result)}`);
|
|
51124
|
-
}
|
|
51125
|
-
break;
|
|
51346
|
+
return;
|
|
51126
51347
|
}
|
|
51348
|
+
case "true":
|
|
51349
|
+
if (!result) throw new TestAssertionError(`expected truthy, got ${JSON.stringify(result)}`);
|
|
51350
|
+
return;
|
|
51351
|
+
case "false":
|
|
51352
|
+
if (result) throw new TestAssertionError(`expected falsy, got ${JSON.stringify(result)}`);
|
|
51353
|
+
return;
|
|
51127
51354
|
default:
|
|
51128
51355
|
throw new Error(`unknown assertion type: ${type2}`);
|
|
51129
51356
|
}
|
|
@@ -51152,7 +51379,7 @@ function printSummary(results, quiet) {
|
|
|
51152
51379
|
`
|
|
51153
51380
|
);
|
|
51154
51381
|
}
|
|
51155
|
-
var registry2, TestAssertionError;
|
|
51382
|
+
var registry2, TestAssertionError, TestRunError, MAX_TIMER_MS;
|
|
51156
51383
|
var init_testing = __esm({
|
|
51157
51384
|
"../core/src/testing.ts"() {
|
|
51158
51385
|
"use strict";
|
|
@@ -51163,6 +51390,13 @@ var init_testing = __esm({
|
|
|
51163
51390
|
this.name = "TestAssertionError";
|
|
51164
51391
|
}
|
|
51165
51392
|
};
|
|
51393
|
+
TestRunError = class extends Error {
|
|
51394
|
+
constructor(message) {
|
|
51395
|
+
super(message);
|
|
51396
|
+
this.name = "TestRunError";
|
|
51397
|
+
}
|
|
51398
|
+
};
|
|
51399
|
+
MAX_TIMER_MS = 2147483647;
|
|
51166
51400
|
}
|
|
51167
51401
|
});
|
|
51168
51402
|
|
|
@@ -51978,6 +52212,7 @@ __export(src_exports3, {
|
|
|
51978
52212
|
resolveTemplate: () => resolveTemplate,
|
|
51979
52213
|
responseCache: () => responseCache,
|
|
51980
52214
|
runAll: () => runAll,
|
|
52215
|
+
runAllAsync: () => runAllAsync,
|
|
51981
52216
|
runRouteMiddlewares: () => runRouteMiddlewares,
|
|
51982
52217
|
runWithCspNonce: () => runWithCspNonce,
|
|
51983
52218
|
runtimeDir: () => runtimeDir,
|
|
@@ -52589,7 +52824,7 @@ function walkSource(dir) {
|
|
|
52589
52824
|
async function runInlineTests(cwd) {
|
|
52590
52825
|
const srcDir = resolve27(cwd, "src");
|
|
52591
52826
|
if (!existsSync33(srcDir)) return false;
|
|
52592
|
-
const {
|
|
52827
|
+
const { runAllAsync: runAllAsync2, reset: reset2 } = await Promise.resolve().then(() => (init_src3(), src_exports3));
|
|
52593
52828
|
reset2();
|
|
52594
52829
|
let discovered = 0;
|
|
52595
52830
|
for (const file of walkSource(srcDir)) {
|
|
@@ -52610,7 +52845,7 @@ async function runInlineTests(cwd) {
|
|
|
52610
52845
|
}
|
|
52611
52846
|
}
|
|
52612
52847
|
if (discovered === 0) return false;
|
|
52613
|
-
const results =
|
|
52848
|
+
const results = await runAllAsync2();
|
|
52614
52849
|
return results.failed + results.errors > 0;
|
|
52615
52850
|
}
|
|
52616
52851
|
async function runTests(testPath) {
|
|
@@ -53190,9 +53425,9 @@ function readCliVersion() {
|
|
|
53190
53425
|
}
|
|
53191
53426
|
return "0.0.0";
|
|
53192
53427
|
}
|
|
53193
|
-
async function killProcessOnPort(port) {
|
|
53428
|
+
async function killProcessOnPort(port, host) {
|
|
53194
53429
|
const { takeOverPort: takeOverPort2, isDev: isDev2, noTakeoverOptedOut: noTakeoverOptedOut2, TAKEOVER_KILLED: TAKEOVER_KILLED2, TAKEOVER_REFUSALS: TAKEOVER_REFUSALS2 } = await Promise.resolve().then(() => (init_portTakeover(), portTakeover_exports));
|
|
53195
|
-
const result = takeOverPort2(port, isDev2(), noTakeoverOptedOut2());
|
|
53430
|
+
const result = takeOverPort2(port, isDev2(), noTakeoverOptedOut2(), void 0, void 0, host);
|
|
53196
53431
|
if (result.status === TAKEOVER_KILLED2) {
|
|
53197
53432
|
console.log(` ${result.message}`);
|
|
53198
53433
|
return true;
|
|
@@ -53360,7 +53595,8 @@ var COMMANDS = {
|
|
|
53360
53595
|
const noBrowser = a.includes("--no-browser");
|
|
53361
53596
|
const noReload = a.includes("--no-reload");
|
|
53362
53597
|
if (a.includes("--no-kill")) process.env.TINA4_NO_TAKEOVER = "true";
|
|
53363
|
-
await
|
|
53598
|
+
const { resolvePortAndHost: resolvePortAndHost2 } = await Promise.resolve().then(() => (init_server(), server_exports));
|
|
53599
|
+
await killProcessOnPort(port, resolvePortAndHost2({ port }).host);
|
|
53364
53600
|
await serveProject({ port, noBrowser, noReload });
|
|
53365
53601
|
},
|
|
53366
53602
|
flags: SERVE_FLAGS,
|