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
|
@@ -5963,11 +5963,11 @@ var init_firebird = __esm({
|
|
|
5963
5963
|
*/
|
|
5964
5964
|
async decodeBlobs(row) {
|
|
5965
5965
|
if (row === null || typeof row !== "object") return row;
|
|
5966
|
-
const
|
|
5967
|
-
for (const key of Object.keys(
|
|
5968
|
-
if (typeof
|
|
5969
|
-
|
|
5970
|
-
|
|
5966
|
+
const record2 = row;
|
|
5967
|
+
for (const key of Object.keys(record2)) {
|
|
5968
|
+
if (typeof record2[key] === "function") {
|
|
5969
|
+
record2[key] = await this.readBlob(
|
|
5970
|
+
record2[key]
|
|
5971
5971
|
);
|
|
5972
5972
|
}
|
|
5973
5973
|
}
|
|
@@ -12053,8 +12053,14 @@ var init_engine = __esm({
|
|
|
12053
12053
|
// and every future ``new Frond()`` inherits it automatically.
|
|
12054
12054
|
// Mirrors Python's _class_globals / _class_filters / _class_tests.
|
|
12055
12055
|
static classFilters = /* @__PURE__ */ new Map();
|
|
12056
|
-
|
|
12056
|
+
// Globals are read LIVE at render time (not copied at construction), so a
|
|
12057
|
+
// Frond.addGlobal() made after an engine exists still reaches it. A plain
|
|
12058
|
+
// object rather than a Map so render() can spread it in one step.
|
|
12059
|
+
static classGlobals = {};
|
|
12057
12060
|
static classTests = /* @__PURE__ */ new Map();
|
|
12061
|
+
// Bumped on every class-level filter/test change, so an engine knows when
|
|
12062
|
+
// to rebuild its merged filter/test maps (see syncRegistries).
|
|
12063
|
+
static classRegistryVersion = 0;
|
|
12058
12064
|
// ── Live-block registries (server-rendered {% live %} regions) ──
|
|
12059
12065
|
// A {% live %} block registers three things when its page first renders:
|
|
12060
12066
|
// liveFragments[name] -> the raw body source, re-rendered on every
|
|
@@ -12074,20 +12080,27 @@ var init_engine = __esm({
|
|
|
12074
12080
|
static liveBroadcaster = null;
|
|
12075
12081
|
/**
|
|
12076
12082
|
* Register a custom filter at the class level — available to every
|
|
12077
|
-
*
|
|
12083
|
+
* instance, existing ones included: an engine merges the class filters
|
|
12084
|
+
* again at its next render (ADR-0107). Callable as ``Frond.addFilter()``
|
|
12078
12085
|
* (static) or ``frond.addFilter()`` (instance). See instance method
|
|
12079
12086
|
* below for the dual-call semantics.
|
|
12080
12087
|
*/
|
|
12081
12088
|
static addFilter(name, fn) {
|
|
12082
12089
|
_Frond.classFilters.set(name, fn);
|
|
12090
|
+
_Frond.classRegistryVersion++;
|
|
12083
12091
|
}
|
|
12084
12092
|
/**
|
|
12085
12093
|
* Register a global variable available in all templates of every
|
|
12086
|
-
*
|
|
12094
|
+
* instance, existing ones included: class globals are read at render time
|
|
12095
|
+
* (ADR-0106). Callable as ``Frond.addGlobal()`` (static) or
|
|
12087
12096
|
* ``frond.addGlobal()`` (instance).
|
|
12088
12097
|
*/
|
|
12089
12098
|
static addGlobal(name, value) {
|
|
12090
|
-
_Frond.classGlobals
|
|
12099
|
+
_Frond.classGlobals[name] = value;
|
|
12100
|
+
}
|
|
12101
|
+
/** True when a class-level global with this name is registered. */
|
|
12102
|
+
static hasGlobal(name) {
|
|
12103
|
+
return Object.prototype.hasOwnProperty.call(_Frond.classGlobals, name);
|
|
12091
12104
|
}
|
|
12092
12105
|
/**
|
|
12093
12106
|
* Register a custom test (``{% if x is positive %}``) at the class
|
|
@@ -12096,6 +12109,7 @@ var init_engine = __esm({
|
|
|
12096
12109
|
*/
|
|
12097
12110
|
static addTest(name, fn) {
|
|
12098
12111
|
_Frond.classTests.set(name, fn);
|
|
12112
|
+
_Frond.classRegistryVersion++;
|
|
12099
12113
|
}
|
|
12100
12114
|
/**
|
|
12101
12115
|
* Clear the class-level globals/filters/tests registries.
|
|
@@ -12105,15 +12119,25 @@ var init_engine = __esm({
|
|
|
12105
12119
|
*/
|
|
12106
12120
|
static clearRegistry() {
|
|
12107
12121
|
_Frond.classFilters.clear();
|
|
12108
|
-
_Frond.classGlobals
|
|
12122
|
+
_Frond.classGlobals = {};
|
|
12109
12123
|
_Frond.classTests.clear();
|
|
12124
|
+
_Frond.classRegistryVersion++;
|
|
12110
12125
|
_Frond.liveFragments.clear();
|
|
12111
12126
|
_Frond.liveSources.clear();
|
|
12112
12127
|
_Frond.liveWsPaths.clear();
|
|
12113
12128
|
}
|
|
12114
12129
|
templateDir;
|
|
12115
|
-
filters
|
|
12130
|
+
/** Effective filters: built-in < class < instance (see syncRegistries). */
|
|
12131
|
+
filters = {};
|
|
12132
|
+
/** Filters / tests registered on THIS instance only (ADR-0052). */
|
|
12133
|
+
localFilters = {};
|
|
12134
|
+
localTests = {};
|
|
12135
|
+
/** The class-registry version `filters` / `tests` were last merged at. */
|
|
12136
|
+
registryVersion = -1;
|
|
12137
|
+
/** Globals registered on THIS instance only (ADR-0052). */
|
|
12116
12138
|
globals;
|
|
12139
|
+
/** Built-in globals (formToken, range, dump, csp_nonce, ...). */
|
|
12140
|
+
builtinGlobals;
|
|
12117
12141
|
tests;
|
|
12118
12142
|
_sandbox;
|
|
12119
12143
|
_allowedFilters;
|
|
@@ -12143,9 +12167,10 @@ var init_engine = __esm({
|
|
|
12143
12167
|
}
|
|
12144
12168
|
constructor(templateDir = "src/templates") {
|
|
12145
12169
|
this.templateDir = resolve4(templateDir);
|
|
12146
|
-
this.filters = { ...BUILTIN_FILTERS };
|
|
12147
12170
|
this.globals = {};
|
|
12171
|
+
this.builtinGlobals = {};
|
|
12148
12172
|
this.tests = {};
|
|
12173
|
+
this.syncRegistries();
|
|
12149
12174
|
this._sandbox = false;
|
|
12150
12175
|
this._allowedFilters = null;
|
|
12151
12176
|
this._allowedTags = null;
|
|
@@ -12193,16 +12218,25 @@ var init_engine = __esm({
|
|
|
12193
12218
|
return { output, next };
|
|
12194
12219
|
}
|
|
12195
12220
|
};
|
|
12196
|
-
this.
|
|
12197
|
-
this.
|
|
12198
|
-
this.
|
|
12199
|
-
this.
|
|
12200
|
-
this.
|
|
12201
|
-
this.
|
|
12202
|
-
this.
|
|
12203
|
-
|
|
12204
|
-
|
|
12205
|
-
|
|
12221
|
+
this.builtinGlobals.formToken = (descriptor) => _generateFormToken(descriptor || "");
|
|
12222
|
+
this.builtinGlobals.form_token = (descriptor) => _generateFormToken(descriptor || "");
|
|
12223
|
+
this.builtinGlobals.formTokenValue = (descriptor) => _generateFormTokenValue(descriptor || "");
|
|
12224
|
+
this.builtinGlobals.form_token_value = (descriptor) => _generateFormTokenValue(descriptor || "");
|
|
12225
|
+
this.builtinGlobals.range = frondRange;
|
|
12226
|
+
this.builtinGlobals.dump = (value) => renderDump(value);
|
|
12227
|
+
this.builtinGlobals.csp_nonce = () => _cspNonceProvider();
|
|
12228
|
+
}
|
|
12229
|
+
/**
|
|
12230
|
+
* Rebuild the merged filter/test maps when the class registry changed.
|
|
12231
|
+
* Same layering as globals -- built-ins < class < this instance. Filter
|
|
12232
|
+
* lookup is on the hot path, so the merge is a plain object rebuilt only
|
|
12233
|
+
* when the class-registry version moves, never a per-lookup chain.
|
|
12234
|
+
*/
|
|
12235
|
+
syncRegistries() {
|
|
12236
|
+
if (this.registryVersion === _Frond.classRegistryVersion) return;
|
|
12237
|
+
this.filters = { ...BUILTIN_FILTERS, ...Object.fromEntries(_Frond.classFilters), ...this.localFilters };
|
|
12238
|
+
this.tests = { ...Object.fromEntries(_Frond.classTests), ...this.localTests };
|
|
12239
|
+
this.registryVersion = _Frond.classRegistryVersion;
|
|
12206
12240
|
}
|
|
12207
12241
|
sandbox(filters, tags, vars) {
|
|
12208
12242
|
this._sandbox = true;
|
|
@@ -12223,6 +12257,7 @@ var init_engine = __esm({
|
|
|
12223
12257
|
* for process-global registration. tina4: ADR-0052.
|
|
12224
12258
|
*/
|
|
12225
12259
|
addFilter(name, fn) {
|
|
12260
|
+
this.localFilters[name] = fn;
|
|
12226
12261
|
this.filters[name] = fn;
|
|
12227
12262
|
}
|
|
12228
12263
|
/**
|
|
@@ -12235,6 +12270,7 @@ var init_engine = __esm({
|
|
|
12235
12270
|
* Register a custom test on this instance only.
|
|
12236
12271
|
*/
|
|
12237
12272
|
addTest(name, fn) {
|
|
12273
|
+
this.localTests[name] = fn;
|
|
12238
12274
|
this.tests[name] = fn;
|
|
12239
12275
|
}
|
|
12240
12276
|
/**
|
|
@@ -12250,8 +12286,19 @@ var init_engine = __esm({
|
|
|
12250
12286
|
const n = parseInt(raw, 10);
|
|
12251
12287
|
return isNaN(n) || n < 0 ? 0 : n;
|
|
12252
12288
|
}
|
|
12289
|
+
/**
|
|
12290
|
+
* Layer the globals under the render data: built-ins < class globals (read
|
|
12291
|
+
* live, so registration order never matters) < this instance's own globals
|
|
12292
|
+
* < the data passed to render(). Every render starts here, so this is also
|
|
12293
|
+
* where the filter/test maps catch up with any class registration made
|
|
12294
|
+
* since the last render.
|
|
12295
|
+
*/
|
|
12296
|
+
withGlobals(data) {
|
|
12297
|
+
this.syncRegistries();
|
|
12298
|
+
return { ...this.builtinGlobals, ..._Frond.classGlobals, ...this.globals, ...data || {} };
|
|
12299
|
+
}
|
|
12253
12300
|
render(template, data) {
|
|
12254
|
-
const context =
|
|
12301
|
+
const context = this.withGlobals(data);
|
|
12255
12302
|
const filePath = join7(this.templateDir, template);
|
|
12256
12303
|
if (!existsSync5(filePath)) {
|
|
12257
12304
|
throw new Error(`Template not found: ${filePath}`);
|
|
@@ -12274,7 +12321,7 @@ var init_engine = __esm({
|
|
|
12274
12321
|
return this.executeWithSource(source, tokens, context);
|
|
12275
12322
|
}
|
|
12276
12323
|
renderString(source, data) {
|
|
12277
|
-
const context =
|
|
12324
|
+
const context = this.withGlobals(data);
|
|
12278
12325
|
const key = createHash3("md5").update(source).digest("hex");
|
|
12279
12326
|
const ttlMs = this.cacheTtlSeconds() * 1e3;
|
|
12280
12327
|
const cached = this.compiledStrings.get(key);
|
|
@@ -13458,12 +13505,12 @@ function crudSortProp(model, requested, pkProp) {
|
|
|
13458
13505
|
}
|
|
13459
13506
|
return pkProp;
|
|
13460
13507
|
}
|
|
13461
|
-
function cellValue(
|
|
13462
|
-
return
|
|
13508
|
+
function cellValue(record2, col) {
|
|
13509
|
+
return record2[col];
|
|
13463
13510
|
}
|
|
13464
|
-
function buildCells(columns,
|
|
13511
|
+
function buildCells(columns, record2, editable, aligns) {
|
|
13465
13512
|
return columns.map((col, index) => {
|
|
13466
|
-
const raw = cellValue(
|
|
13513
|
+
const raw = cellValue(record2, col);
|
|
13467
13514
|
const value = h(raw === null || raw === void 0 ? "" : raw);
|
|
13468
13515
|
const css = aligns[index];
|
|
13469
13516
|
return editable ? `<td class="${css}" contenteditable="true" data-field="${h(col)}">${value}</td>` : `<td class="${css}">${value}</td>`;
|
|
@@ -13626,9 +13673,9 @@ function headerCell(opts, col, align) {
|
|
|
13626
13673
|
function tableData(opts) {
|
|
13627
13674
|
const aligns = opts.columns.map((col) => columnAlignment(opts.model, col));
|
|
13628
13675
|
const headers = opts.columns.map((col, index) => headerCell(opts, col, aligns[index]));
|
|
13629
|
-
const rows = opts.records.map((
|
|
13630
|
-
id: h(cellValue(
|
|
13631
|
-
cells: buildCells(opts.columns,
|
|
13676
|
+
const rows = opts.records.map((record2) => ({
|
|
13677
|
+
id: h(cellValue(record2, opts.pk) ?? ""),
|
|
13678
|
+
cells: buildCells(opts.columns, record2, opts.editable, aligns)
|
|
13632
13679
|
}));
|
|
13633
13680
|
return {
|
|
13634
13681
|
headers,
|
|
@@ -14827,9 +14874,9 @@ async function eagerLoadHasRelation(instances, model, relatedClass, relationName
|
|
|
14827
14874
|
if (nested.length > 0 && related.length > 0) await relatedClass._eagerLoad(related, nested);
|
|
14828
14875
|
const fkProp = reverseMappedColumn(relatedClass, relation.foreignKey);
|
|
14829
14876
|
const grouped = {};
|
|
14830
|
-
for (const
|
|
14831
|
-
const key = _joinKey(
|
|
14832
|
-
(grouped[key] ??= []).push(
|
|
14877
|
+
for (const record2 of related) {
|
|
14878
|
+
const key = _joinKey(record2[fkProp]);
|
|
14879
|
+
(grouped[key] ??= []).push(record2);
|
|
14833
14880
|
}
|
|
14834
14881
|
for (const instance of instances) {
|
|
14835
14882
|
const records = grouped[_joinKey(instance[pk])] ?? [];
|
|
@@ -14845,7 +14892,7 @@ async function eagerLoadBelongsToRelation(instances, model, relatedClass, relati
|
|
|
14845
14892
|
const related = await eagerQueryRelated(relatedClass, relatedPkColumn, values);
|
|
14846
14893
|
if (nested.length > 0 && related.length > 0) await relatedClass._eagerLoad(related, nested);
|
|
14847
14894
|
const lookup2 = {};
|
|
14848
|
-
for (const
|
|
14895
|
+
for (const record2 of related) lookup2[_joinKey(record2[relatedPk])] = record2;
|
|
14849
14896
|
for (const instance of instances) {
|
|
14850
14897
|
const value = instance[fkProp];
|
|
14851
14898
|
relationshipCache(instance)[relationName] = value !== void 0 && value !== null ? lookup2[_joinKey(value)] ?? null : null;
|
|
@@ -18091,7 +18138,7 @@ var init_bolt = __esm({
|
|
|
18091
18138
|
const session = this.database ? this.driver.session({ database: this.database }) : this.driver.session();
|
|
18092
18139
|
try {
|
|
18093
18140
|
const result = await session.run(cypher, params ?? {});
|
|
18094
|
-
return result.records.map((
|
|
18141
|
+
return result.records.map((record2) => record2.toObject());
|
|
18095
18142
|
} catch (exc) {
|
|
18096
18143
|
this.lastError = errorMessage(exc);
|
|
18097
18144
|
const code = exc?.code ?? "";
|
|
@@ -23973,27 +24020,33 @@ function sleepSync(ms) {
|
|
|
23973
24020
|
if (ms <= 0) return;
|
|
23974
24021
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
23975
24022
|
}
|
|
23976
|
-
function
|
|
24023
|
+
function bindable(host, port) {
|
|
24024
|
+
try {
|
|
24025
|
+
execFileSync(process.execPath, ["-e", BIND_PROBE, host, String(port)], { stdio: "ignore", timeout: 5e3 });
|
|
24026
|
+
return true;
|
|
24027
|
+
} catch {
|
|
24028
|
+
return false;
|
|
24029
|
+
}
|
|
24030
|
+
}
|
|
24031
|
+
function refusal(port, dev, noTakeover, host) {
|
|
24032
|
+
if (dev && !noTakeover) return null;
|
|
24033
|
+
if (host !== void 0 && bindable(host, port)) {
|
|
24034
|
+
return { status: TAKEOVER_NOTHING, port, killed: [], message: "" };
|
|
24035
|
+
}
|
|
24036
|
+
if (noTakeover) {
|
|
24037
|
+
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.` };
|
|
24038
|
+
}
|
|
24039
|
+
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.` };
|
|
24040
|
+
}
|
|
24041
|
+
function takeOverPort(port, dev, noTakeover, baseDir, grace = 500, host) {
|
|
23977
24042
|
const make = (status2, killed2 = [], message = "") => ({
|
|
23978
24043
|
status: status2,
|
|
23979
24044
|
port,
|
|
23980
24045
|
killed: killed2,
|
|
23981
24046
|
message
|
|
23982
24047
|
});
|
|
23983
|
-
|
|
23984
|
-
|
|
23985
|
-
TAKEOVER_REFUSED_OPTOUT,
|
|
23986
|
-
[],
|
|
23987
|
-
`Port ${port} is in use and takeover is disabled (TINA4_NO_TAKEOVER/--no-kill) -- free it or choose another port.`
|
|
23988
|
-
);
|
|
23989
|
-
}
|
|
23990
|
-
if (!dev) {
|
|
23991
|
-
return make(
|
|
23992
|
-
TAKEOVER_REFUSED_PROD,
|
|
23993
|
-
[],
|
|
23994
|
-
`Port ${port} is in use; takeover is disabled outside dev mode -- free it or choose another port.`
|
|
23995
|
-
);
|
|
23996
|
-
}
|
|
24048
|
+
const early = refusal(port, dev, noTakeover, host);
|
|
24049
|
+
if (early !== null) return early;
|
|
23997
24050
|
if (inContainer()) return make(TAKEOVER_SKIPPED_CONTAINER);
|
|
23998
24051
|
const tokens = portHolders(port);
|
|
23999
24052
|
if (tokens.length === 0) return make(TAKEOVER_NOTHING);
|
|
@@ -24025,7 +24078,7 @@ function takeOverPort(port, dev, noTakeover, baseDir, grace = 500) {
|
|
|
24025
24078
|
`Reclaimed port ${port} from Tina4 dev server (PID: ${killed.join(", ")}).`
|
|
24026
24079
|
);
|
|
24027
24080
|
}
|
|
24028
|
-
var TAKEOVER_NOTHING, TAKEOVER_KILLED, TAKEOVER_REFUSED_FOREIGN, TAKEOVER_REFUSED_OPTOUT, TAKEOVER_REFUSED_PROD, TAKEOVER_SKIPPED_CONTAINER, TAKEOVER_REFUSALS;
|
|
24081
|
+
var TAKEOVER_NOTHING, TAKEOVER_KILLED, TAKEOVER_REFUSED_FOREIGN, TAKEOVER_REFUSED_OPTOUT, TAKEOVER_REFUSED_PROD, TAKEOVER_SKIPPED_CONTAINER, TAKEOVER_REFUSALS, BIND_PROBE;
|
|
24029
24082
|
var init_portTakeover = __esm({
|
|
24030
24083
|
"src/portTakeover.ts"() {
|
|
24031
24084
|
"use strict";
|
|
@@ -24040,6 +24093,7 @@ var init_portTakeover = __esm({
|
|
|
24040
24093
|
TAKEOVER_REFUSED_OPTOUT,
|
|
24041
24094
|
TAKEOVER_REFUSED_PROD
|
|
24042
24095
|
];
|
|
24096
|
+
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)));';
|
|
24043
24097
|
}
|
|
24044
24098
|
});
|
|
24045
24099
|
|
|
@@ -26090,7 +26144,7 @@ var init_session = __esm({
|
|
|
26090
26144
|
save() {
|
|
26091
26145
|
if (!this.sessionId || !this.data) return true;
|
|
26092
26146
|
if (this.isFresh()) return true;
|
|
26093
|
-
let
|
|
26147
|
+
let record2 = this.data;
|
|
26094
26148
|
if (this.stored) {
|
|
26095
26149
|
const current = this.safeRead(this.sessionId);
|
|
26096
26150
|
if (this.lastReadFailed) return false;
|
|
@@ -26099,9 +26153,9 @@ var init_session = __esm({
|
|
|
26099
26153
|
this.ended = true;
|
|
26100
26154
|
return true;
|
|
26101
26155
|
}
|
|
26102
|
-
if (!this.cleared)
|
|
26156
|
+
if (!this.cleared) record2 = this.merged(current);
|
|
26103
26157
|
}
|
|
26104
|
-
if (this.safeWrite(this.sessionId,
|
|
26158
|
+
if (this.safeWrite(this.sessionId, record2, this.ttl)) {
|
|
26105
26159
|
this.dirty = false;
|
|
26106
26160
|
this.stored = true;
|
|
26107
26161
|
this.cleared = false;
|
|
@@ -26118,19 +26172,19 @@ var init_session = __esm({
|
|
|
26118
26172
|
*/
|
|
26119
26173
|
merged(current) {
|
|
26120
26174
|
const data = this.data;
|
|
26121
|
-
const
|
|
26175
|
+
const record2 = { ...current };
|
|
26122
26176
|
for (const [key, value] of Object.entries(data)) {
|
|
26123
26177
|
const print = fingerprint(value);
|
|
26124
26178
|
if (print === void 0 || !this.loaded.has(key) || this.loaded.get(key) !== print) {
|
|
26125
|
-
|
|
26179
|
+
record2[key] = value;
|
|
26126
26180
|
}
|
|
26127
26181
|
}
|
|
26128
26182
|
for (const key of this.loaded.keys()) {
|
|
26129
26183
|
if (!Object.prototype.hasOwnProperty.call(data, key)) {
|
|
26130
|
-
delete
|
|
26184
|
+
delete record2[key];
|
|
26131
26185
|
}
|
|
26132
26186
|
}
|
|
26133
|
-
return
|
|
26187
|
+
return record2;
|
|
26134
26188
|
}
|
|
26135
26189
|
/**
|
|
26136
26190
|
* End the session for this request without touching the store: no id and
|
|
@@ -31285,7 +31339,7 @@ data: ${channel.buffer.shift()}
|
|
|
31285
31339
|
}
|
|
31286
31340
|
return { resources };
|
|
31287
31341
|
}
|
|
31288
|
-
_handleResourcesRead(params) {
|
|
31342
|
+
async _handleResourcesRead(params) {
|
|
31289
31343
|
const uri = params.uri;
|
|
31290
31344
|
if (!uri) {
|
|
31291
31345
|
throw new Error("Missing resource URI");
|
|
@@ -31294,7 +31348,7 @@ data: ${channel.buffer.shift()}
|
|
|
31294
31348
|
if (!resource) {
|
|
31295
31349
|
throw new Error(`Unknown resource: ${uri}`);
|
|
31296
31350
|
}
|
|
31297
|
-
const result = resource.handler();
|
|
31351
|
+
const result = await resource.handler();
|
|
31298
31352
|
let text;
|
|
31299
31353
|
if (typeof result === "string") {
|
|
31300
31354
|
text = result;
|
|
@@ -34828,6 +34882,12 @@ const outBytes = new Uint8Array(workerData.sab, 8);
|
|
|
34828
34882
|
// (test/kafkaErrorCodes.test.ts) can assert the floors.
|
|
34829
34883
|
const PRODUCE_VERSION = 3;
|
|
34830
34884
|
const FETCH_VERSION = 4;
|
|
34885
|
+
// How long the broker long-polls an empty partition before answering (ms).
|
|
34886
|
+
// Deliberately 1000, not tina4-php / tina4-python's 5000: Node's pop() is
|
|
34887
|
+
// synchronous (Atomics.wait on this worker), so the long-poll blocks the whole
|
|
34888
|
+
// event loop, not one request. The tombstone-skip deadline caps it further while
|
|
34889
|
+
// stepping so a stream of tombstones cannot hold pop() past ~1s.
|
|
34890
|
+
const FETCH_MAX_WAIT_MS = 1000;
|
|
34831
34891
|
|
|
34832
34892
|
let correlationId = 0;
|
|
34833
34893
|
let brokerSock = null;
|
|
@@ -35014,12 +35074,13 @@ async function produce(topic, valueBytes) {
|
|
|
35014
35074
|
}
|
|
35015
35075
|
|
|
35016
35076
|
// \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
|
|
35017
|
-
function fetchRequest(topic, offset) {
|
|
35077
|
+
function fetchRequest(topic, offset, maxWaitMs) {
|
|
35078
|
+
if (maxWaitMs === undefined) maxWaitMs = FETCH_MAX_WAIT_MS;
|
|
35018
35079
|
const topicBuf = Buffer.from(topic, "utf-8");
|
|
35019
35080
|
const buf = Buffer.alloc(4 + 4 + 4 + 4 + 1 + 4 + 2 + topicBuf.length + 4 + 4 + 8 + 4);
|
|
35020
35081
|
let p = 0;
|
|
35021
35082
|
buf.writeInt32BE(-1, p); p += 4; // replicaId
|
|
35022
|
-
buf.writeInt32BE(
|
|
35083
|
+
buf.writeInt32BE(maxWaitMs, p); p += 4; // maxWaitMs (long-poll bound; capped by the tombstone-skip deadline)
|
|
35023
35084
|
buf.writeInt32BE(1, p); p += 4; // minBytes
|
|
35024
35085
|
buf.writeInt32BE(1048576, p); p += 4; // maxBytes
|
|
35025
35086
|
buf.writeInt8(0, p); p += 1; // isolation READ_UNCOMMITTED
|
|
@@ -35032,8 +35093,12 @@ function fetchRequest(topic, offset) {
|
|
|
35032
35093
|
buf.writeInt32BE(1048576, p); p += 4;
|
|
35033
35094
|
return frame(1, FETCH_VERSION, buf);
|
|
35034
35095
|
}
|
|
35035
|
-
// Decode the
|
|
35036
|
-
//
|
|
35096
|
+
// Decode the FIRST record of the partition's record-set (the cross-framework
|
|
35097
|
+
// contract: only a batch's first record is decoded -- the Tina4 producer writes
|
|
35098
|
+
// one record per batch). Returns its value and absolute offset (baseOffset +
|
|
35099
|
+
// offsetDelta); a tombstone (null value) comes back with value null and its
|
|
35100
|
+
// offset so the caller can step past it. null = no usable record at all (empty /
|
|
35101
|
+
// old-format / short response).
|
|
35037
35102
|
function firstRecord(buf, start, end) {
|
|
35038
35103
|
let pos = start;
|
|
35039
35104
|
while (pos + 12 <= end) {
|
|
@@ -35049,8 +35114,7 @@ function firstRecord(buf, start, end) {
|
|
|
35049
35114
|
for (let i = 0; i < recordsCount && r < batchEnd; i++) {
|
|
35050
35115
|
const recLen = readVarint(buf, r);
|
|
35051
35116
|
let rp = recLen.next;
|
|
35052
|
-
|
|
35053
|
-
rp += 1;
|
|
35117
|
+
rp += 1; // record attributes byte
|
|
35054
35118
|
rp = readVarint(buf, rp).next; // timestampDelta
|
|
35055
35119
|
const offDelta = readVarint(buf, rp); rp = offDelta.next;
|
|
35056
35120
|
const keyLen = readVarint(buf, rp); rp = keyLen.next;
|
|
@@ -35062,15 +35126,23 @@ function firstRecord(buf, start, end) {
|
|
|
35062
35126
|
offset: Number(baseOffset) + offDelta.value,
|
|
35063
35127
|
};
|
|
35064
35128
|
}
|
|
35065
|
-
|
|
35129
|
+
// Tombstone (null value) or empty value: hand back a marker carrying its
|
|
35130
|
+
// offset instead of null. Returning null here used to mean "no record", so
|
|
35131
|
+
// pop() never advanced and re-fetched the tombstone for ever -- nothing
|
|
35132
|
+
// after it was delivered. The caller (fetchPastTombstones) steps the
|
|
35133
|
+
// offset on and re-fetches.
|
|
35134
|
+
return {
|
|
35135
|
+
value: null,
|
|
35136
|
+
offset: Number(baseOffset) + offDelta.value,
|
|
35137
|
+
};
|
|
35066
35138
|
}
|
|
35067
35139
|
pos = batchEnd;
|
|
35068
35140
|
}
|
|
35069
35141
|
return null;
|
|
35070
35142
|
}
|
|
35071
|
-
async function fetchAt(topic, offset) {
|
|
35143
|
+
async function fetchAt(topic, offset, maxWaitMs) {
|
|
35072
35144
|
const sock = await broker();
|
|
35073
|
-
const resp = await rpc(sock, fetchRequest(topic, offset));
|
|
35145
|
+
const resp = await rpc(sock, fetchRequest(topic, offset, maxWaitMs));
|
|
35074
35146
|
let pos = 4; // correlationId
|
|
35075
35147
|
pos += 4; // throttleTimeMs
|
|
35076
35148
|
const topicCount = resp.readInt32BE(pos); pos += 4;
|
|
@@ -35206,9 +35278,37 @@ async function broker() {
|
|
|
35206
35278
|
// Resume from the committed offset on the FIRST read of a topic in this worker,
|
|
35207
35279
|
// then advance the in-memory cursor; the committed offset only moves on a
|
|
35208
35280
|
// commit, so it lags and a crash before commit replays (at-least-once).
|
|
35281
|
+
// Fetch from the cursor, stepping past tombstones, until a record with a value
|
|
35282
|
+
// arrives, the topic is exhausted, or the deadline passes. A tombstone (null
|
|
35283
|
+
// value: Debezium deletes, compacted-topic delete markers) carries no job;
|
|
35284
|
+
// returning "nothing" without moving the offset re-fetched it for ever, so
|
|
35285
|
+
// nothing after it was ever delivered. The 1 s deadline holds while skipping
|
|
35286
|
+
// (the same steady-state bound as tina4-php/tina4-python), and the whole loop
|
|
35287
|
+
// stays inside this one worker round-trip (ADR-0022) -- well under
|
|
35288
|
+
// CALL_TIMEOUT_MS. Nothing is committed here: acknowledging the next record
|
|
35289
|
+
// commits past the skipped tombstones, as before.
|
|
35290
|
+
async function fetchPastTombstones(topic) {
|
|
35291
|
+
const deadline = Date.now() + 1000;
|
|
35292
|
+
let maxWaitMs = FETCH_MAX_WAIT_MS;
|
|
35293
|
+
while (true) {
|
|
35294
|
+
const offset = offsets[topic];
|
|
35295
|
+
const rec = await fetchAt(topic, offset, maxWaitMs);
|
|
35296
|
+
if (rec === null || rec.value !== null) return rec; // nothing, or a real record
|
|
35297
|
+
// Anti-spin: the decoder reads only a batch's first record, so a tombstone
|
|
35298
|
+
// sharing a batch with later records comes back at an offset already passed.
|
|
35299
|
+
// That must never loop this fetch.
|
|
35300
|
+
const next = rec.offset + 1;
|
|
35301
|
+
if (next <= offset) return null;
|
|
35302
|
+
offsets[topic] = next;
|
|
35303
|
+
const remaining = deadline - Date.now();
|
|
35304
|
+
if (remaining <= 0) return null;
|
|
35305
|
+
maxWaitMs = remaining;
|
|
35306
|
+
}
|
|
35307
|
+
}
|
|
35308
|
+
|
|
35209
35309
|
async function fetchNext(topic) {
|
|
35210
35310
|
if (!(topic in offsets)) offsets[topic] = await offsetFetch(topic);
|
|
35211
|
-
const rec = await
|
|
35311
|
+
const rec = await fetchPastTombstones(topic);
|
|
35212
35312
|
if (rec === null) return null;
|
|
35213
35313
|
offsets[topic] = rec.offset + 1;
|
|
35214
35314
|
return rec;
|
|
@@ -35713,7 +35813,7 @@ var init_liteBackend = __esm({
|
|
|
35713
35813
|
writeReserved(queue, job) {
|
|
35714
35814
|
const now = this.nowIso();
|
|
35715
35815
|
const vt = this.visibilityTimeout || 0;
|
|
35716
|
-
const
|
|
35816
|
+
const record2 = {
|
|
35717
35817
|
id: job.id,
|
|
35718
35818
|
payload: job.payload,
|
|
35719
35819
|
status: "reserved",
|
|
@@ -35725,7 +35825,7 @@ var init_liteBackend = __esm({
|
|
|
35725
35825
|
createdAt: job.createdAt ?? now,
|
|
35726
35826
|
topic: job.topic ?? queue
|
|
35727
35827
|
};
|
|
35728
|
-
writeFileSync11(this.reservedPath(queue,
|
|
35828
|
+
writeFileSync11(this.reservedPath(queue, record2.id), JSON.stringify(record2, null, 2));
|
|
35729
35829
|
}
|
|
35730
35830
|
/**
|
|
35731
35831
|
* Return expired reservations to the queue (at-least-once delivery).
|
|
@@ -35747,29 +35847,29 @@ var init_liteBackend = __esm({
|
|
|
35747
35847
|
}
|
|
35748
35848
|
for (const filename of filenames) {
|
|
35749
35849
|
const filePath = join23(reservedDir, filename);
|
|
35750
|
-
let
|
|
35850
|
+
let record2;
|
|
35751
35851
|
try {
|
|
35752
|
-
|
|
35852
|
+
record2 = JSON.parse(readFileSync16(filePath, "utf-8"));
|
|
35753
35853
|
} catch {
|
|
35754
35854
|
continue;
|
|
35755
35855
|
}
|
|
35756
|
-
if (
|
|
35856
|
+
if (record2.availableAt && record2.availableAt > now) continue;
|
|
35757
35857
|
try {
|
|
35758
35858
|
unlinkSync8(filePath);
|
|
35759
35859
|
} catch {
|
|
35760
35860
|
continue;
|
|
35761
35861
|
}
|
|
35762
|
-
const attempts = (
|
|
35862
|
+
const attempts = (record2.attempts ?? 0) + 1;
|
|
35763
35863
|
const error2 = "reservation timed out \u2014 consumer did not acknowledge within the visibility timeout";
|
|
35764
35864
|
const job = {
|
|
35765
|
-
id:
|
|
35766
|
-
payload:
|
|
35865
|
+
id: record2.id,
|
|
35866
|
+
payload: record2.payload,
|
|
35767
35867
|
status: "reserved",
|
|
35768
|
-
createdAt:
|
|
35868
|
+
createdAt: record2.createdAt ?? now,
|
|
35769
35869
|
attempts,
|
|
35770
35870
|
delayUntil: null,
|
|
35771
|
-
priority:
|
|
35772
|
-
topic:
|
|
35871
|
+
priority: record2.priority ?? 0,
|
|
35872
|
+
topic: record2.topic ?? queue,
|
|
35773
35873
|
error: error2
|
|
35774
35874
|
};
|
|
35775
35875
|
if (attempts >= maxRetries) {
|
|
@@ -40258,6 +40358,7 @@ var init_devAdmin = __esm({
|
|
|
40258
40358
|
const mem = process.memoryUsage();
|
|
40259
40359
|
const heapUsedMb = Math.round(mem.heapUsed / 1048576);
|
|
40260
40360
|
const rssMb = Math.round(mem.rss / 1048576);
|
|
40361
|
+
const peakRssMb = Math.round(process.resourceUsage().maxRSS / 1024);
|
|
40261
40362
|
let dbTableCount;
|
|
40262
40363
|
let dbConnected = false;
|
|
40263
40364
|
try {
|
|
@@ -40274,12 +40375,14 @@ var init_devAdmin = __esm({
|
|
|
40274
40375
|
architecture: process.arch,
|
|
40275
40376
|
os: `${process.platform} ${process.arch}`,
|
|
40276
40377
|
pid: process.pid,
|
|
40277
|
-
|
|
40378
|
+
// The dashboard's "Memory": the process's current RSS, as tina4-python
|
|
40379
|
+
// reports it. V8's heapUsed (below) leaves out Buffers and native memory.
|
|
40380
|
+
memory_mb: rssMb,
|
|
40278
40381
|
db_tables: dbTableCount !== void 0 ? dbTableCount : "N/A",
|
|
40279
40382
|
db_connected: dbConnected,
|
|
40280
40383
|
memory: {
|
|
40281
|
-
current_mb:
|
|
40282
|
-
peak_mb:
|
|
40384
|
+
current_mb: rssMb,
|
|
40385
|
+
peak_mb: peakRssMb,
|
|
40283
40386
|
limit: "V8 default",
|
|
40284
40387
|
rss: `${rssMb} MB`,
|
|
40285
40388
|
heapUsed: `${heapUsedMb} MB`,
|
|
@@ -43255,6 +43358,32 @@ function swaggerAdvertised() {
|
|
|
43255
43358
|
}
|
|
43256
43359
|
return TRUTHY3.includes(raw);
|
|
43257
43360
|
}
|
|
43361
|
+
function stripUrlCredentials(text) {
|
|
43362
|
+
return text.replace(/:\/\/[^/\s]*@/g, "://");
|
|
43363
|
+
}
|
|
43364
|
+
function isModuleNotFound(err) {
|
|
43365
|
+
const code = err?.code;
|
|
43366
|
+
return code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND";
|
|
43367
|
+
}
|
|
43368
|
+
function reportOrmBootFailure(stage, err, dbConfig) {
|
|
43369
|
+
const message = stripUrlCredentials(err instanceof Error ? err.message : String(err));
|
|
43370
|
+
if (stage === "connect") {
|
|
43371
|
+
const url = (process.env.TINA4_DATABASE_URL ?? "").trim();
|
|
43372
|
+
const target = url ? stripUrlCredentials(url) : `${dbConfig.type ?? "sqlite"} ${dbConfig.path ?? "./data/tina4.db"}`;
|
|
43373
|
+
bootDbConnectError = message;
|
|
43374
|
+
console.warn(`
|
|
43375
|
+
Database could not be reached (${target}): ${message}`);
|
|
43376
|
+
} else if (stage === "import" && isModuleNotFound(err)) {
|
|
43377
|
+
console.warn(`
|
|
43378
|
+
ORM not available (install @tina4/orm to enable): ${message}`);
|
|
43379
|
+
} else if (stage === "import") {
|
|
43380
|
+
console.warn(`
|
|
43381
|
+
ORM failed to load:`, err);
|
|
43382
|
+
} else {
|
|
43383
|
+
console.warn(`
|
|
43384
|
+
ORM model setup failed:`, err);
|
|
43385
|
+
}
|
|
43386
|
+
}
|
|
43258
43387
|
async function autoMigrateOnStartup(migrationDir = "migrations", base = process.cwd()) {
|
|
43259
43388
|
const dir = resolve19(base, migrationDir);
|
|
43260
43389
|
if (!existsSync26(dir)) return;
|
|
@@ -43273,9 +43402,20 @@ async function autoMigrateOnStartup(migrationDir = "migrations", base = process.
|
|
|
43273
43402
|
let orm;
|
|
43274
43403
|
try {
|
|
43275
43404
|
orm = await Promise.resolve().then(() => (init_src(), src_exports));
|
|
43405
|
+
} catch (err) {
|
|
43406
|
+
Log.debug(`Startup migrations skipped (ORM not available): ${stripUrlCredentials(err instanceof Error ? err.message : String(err))}`);
|
|
43407
|
+
return;
|
|
43408
|
+
}
|
|
43409
|
+
try {
|
|
43276
43410
|
orm.getAdapter();
|
|
43277
43411
|
} catch (err) {
|
|
43278
|
-
|
|
43412
|
+
const configuredUrl = (process.env.TINA4_DATABASE_URL ?? "").trim();
|
|
43413
|
+
const cause = stripUrlCredentials(bootDbConnectError ?? (err instanceof Error ? err.message : String(err)));
|
|
43414
|
+
if (configuredUrl) {
|
|
43415
|
+
Log.debug(`Startup migrations skipped (database configured but could not connect to ${stripUrlCredentials(configuredUrl)}): ${cause}`);
|
|
43416
|
+
} else {
|
|
43417
|
+
Log.debug(`Startup migrations skipped (no database configured): ${cause}`);
|
|
43418
|
+
}
|
|
43279
43419
|
return;
|
|
43280
43420
|
}
|
|
43281
43421
|
try {
|
|
@@ -44198,9 +44338,10 @@ function wireLocaleGlobal(frondEngine, base) {
|
|
|
44198
44338
|
if (!existsSync26(localeDir)) return;
|
|
44199
44339
|
try {
|
|
44200
44340
|
const localeFiles = readdirSync18(localeDir).filter((file) => file.endsWith(".json"));
|
|
44201
|
-
|
|
44341
|
+
const FrondClass = frondEngine.constructor;
|
|
44342
|
+
if (localeFiles.length === 0 || FrondClass.hasGlobal("t") || frondEngine.globals?.t) return;
|
|
44202
44343
|
const i18nInstance = new I18n(process.env.TINA4_LOCALE ?? "en", localeDir);
|
|
44203
|
-
|
|
44344
|
+
FrondClass.addGlobal("t", (key, params) => i18nInstance.t(key, params));
|
|
44204
44345
|
} catch {
|
|
44205
44346
|
}
|
|
44206
44347
|
}
|
|
@@ -44533,13 +44674,17 @@ async function initializeOrm(config, router, base, ormDir, modelsDir) {
|
|
|
44533
44674
|
const hasOrmDir = existsSync26(ormDir);
|
|
44534
44675
|
const hasModelsDir = existsSync26(modelsDir);
|
|
44535
44676
|
if (hasOrmDir || hasModelsDir) {
|
|
44677
|
+
let ormStage = "import";
|
|
44678
|
+
const dbConfig = config?.database ?? {};
|
|
44536
44679
|
try {
|
|
44537
44680
|
const orm = await Promise.resolve().then(() => (init_src(), src_exports));
|
|
44538
|
-
|
|
44681
|
+
ormStage = "connect";
|
|
44682
|
+
bootDbConnectError = null;
|
|
44539
44683
|
await orm.initDatabase({
|
|
44540
44684
|
type: dbConfig.type ?? "sqlite",
|
|
44541
44685
|
path: dbConfig.path ?? "./data/tina4.db"
|
|
44542
44686
|
});
|
|
44687
|
+
ormStage = "models";
|
|
44543
44688
|
let models = hasOrmDir ? await orm.discoverModels(ormDir) : [];
|
|
44544
44689
|
if (hasModelsDir) {
|
|
44545
44690
|
const extraModels = await orm.discoverModels(modelsDir);
|
|
@@ -44574,8 +44719,7 @@ async function initializeOrm(config, router, base, ormDir, modelsDir) {
|
|
|
44574
44719
|
}
|
|
44575
44720
|
}
|
|
44576
44721
|
} catch (err) {
|
|
44577
|
-
|
|
44578
|
-
ORM not available (install @tina4/orm to enable):`, err);
|
|
44722
|
+
reportOrmBootFailure(ormStage, err, dbConfig);
|
|
44579
44723
|
}
|
|
44580
44724
|
await autoMigrateOnStartup("migrations", base);
|
|
44581
44725
|
}
|
|
@@ -44613,7 +44757,7 @@ async function configureSwagger(router, ormDir, modelsDir) {
|
|
|
44613
44757
|
}
|
|
44614
44758
|
return enabled;
|
|
44615
44759
|
}
|
|
44616
|
-
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;
|
|
44760
|
+
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;
|
|
44617
44761
|
var init_server = __esm({
|
|
44618
44762
|
"src/server.ts"() {
|
|
44619
44763
|
"use strict";
|
|
@@ -44648,6 +44792,7 @@ var init_server = __esm({
|
|
|
44648
44792
|
BUILTIN_PUBLIC_DIR = resolve19(__dirname, "..", "public");
|
|
44649
44793
|
swaggerAssetsEnabled = false;
|
|
44650
44794
|
DEFAULT_SHUTDOWN_TIMEOUT_SECONDS = 30;
|
|
44795
|
+
bootDbConnectError = null;
|
|
44651
44796
|
frondCache2 = /* @__PURE__ */ new Map();
|
|
44652
44797
|
_LEGACY_ENV_VARS = {
|
|
44653
44798
|
DATABASE_URL: "TINA4_DATABASE_URL",
|
|
@@ -49840,26 +49985,26 @@ var init_aiClient = __esm({
|
|
|
49840
49985
|
if (!part || typeof part !== "object" || Array.isArray(part)) {
|
|
49841
49986
|
throw new AiConfigError("AI content part must be an object with type and text/source");
|
|
49842
49987
|
}
|
|
49843
|
-
const
|
|
49844
|
-
switch (
|
|
49988
|
+
const record2 = part;
|
|
49989
|
+
switch (record2.type) {
|
|
49845
49990
|
case "text":
|
|
49846
|
-
this.validateTextPart(
|
|
49991
|
+
this.validateTextPart(record2);
|
|
49847
49992
|
return;
|
|
49848
49993
|
case "image":
|
|
49849
|
-
this.validateImagePart(
|
|
49994
|
+
this.validateImagePart(record2);
|
|
49850
49995
|
return;
|
|
49851
49996
|
case "tool_result":
|
|
49852
|
-
this.validateToolResultPart(
|
|
49997
|
+
this.validateToolResultPart(record2);
|
|
49853
49998
|
return;
|
|
49854
49999
|
default:
|
|
49855
|
-
throw new AiConfigError(`AI content part has unknown type '${String(
|
|
50000
|
+
throw new AiConfigError(`AI content part has unknown type '${String(record2.type)}'`);
|
|
49856
50001
|
}
|
|
49857
50002
|
}
|
|
49858
|
-
static validateTextPart(
|
|
49859
|
-
if (typeof
|
|
50003
|
+
static validateTextPart(record2) {
|
|
50004
|
+
if (typeof record2.text !== "string") throw new AiConfigError("AI text content part requires a string 'text' field");
|
|
49860
50005
|
}
|
|
49861
|
-
static validateImagePart(
|
|
49862
|
-
const source =
|
|
50006
|
+
static validateImagePart(record2) {
|
|
50007
|
+
const source = record2.source;
|
|
49863
50008
|
if (typeof source !== "string" || source.length === 0) {
|
|
49864
50009
|
throw new AiConfigError("AI image content part requires a non-empty string 'source' field");
|
|
49865
50010
|
}
|
|
@@ -49870,11 +50015,11 @@ var init_aiClient = __esm({
|
|
|
49870
50015
|
throw new AiConfigError("AI image data URI must be data:<media_type>;base64,<payload>");
|
|
49871
50016
|
}
|
|
49872
50017
|
}
|
|
49873
|
-
static validateToolResultPart(
|
|
49874
|
-
if (typeof
|
|
50018
|
+
static validateToolResultPart(record2) {
|
|
50019
|
+
if (typeof record2.tool_use_id !== "string" || record2.tool_use_id.length === 0) {
|
|
49875
50020
|
throw new AiConfigError("AI tool_result part requires a non-empty string 'tool_use_id'");
|
|
49876
50021
|
}
|
|
49877
|
-
if (typeof
|
|
50022
|
+
if (typeof record2.content !== "string") throw new AiConfigError("AI tool_result part requires a string 'content'");
|
|
49878
50023
|
}
|
|
49879
50024
|
/**
|
|
49880
50025
|
* Validate the outbound tool declarations (ADR-0061). Each tool needs a
|
|
@@ -49890,14 +50035,14 @@ var init_aiClient = __esm({
|
|
|
49890
50035
|
if (!tool || typeof tool !== "object" || Array.isArray(tool)) {
|
|
49891
50036
|
throw new AiConfigError("AI tool must be an object with name, description, parameters");
|
|
49892
50037
|
}
|
|
49893
|
-
const
|
|
49894
|
-
if (typeof
|
|
50038
|
+
const record2 = tool;
|
|
50039
|
+
if (typeof record2.name !== "string" || record2.name.length === 0) {
|
|
49895
50040
|
throw new AiConfigError("AI tool requires a non-empty string 'name'");
|
|
49896
50041
|
}
|
|
49897
|
-
if (typeof
|
|
50042
|
+
if (typeof record2.description !== "string") {
|
|
49898
50043
|
throw new AiConfigError("AI tool requires a string 'description'");
|
|
49899
50044
|
}
|
|
49900
|
-
if (!
|
|
50045
|
+
if (!record2.parameters || typeof record2.parameters !== "object" || Array.isArray(record2.parameters)) {
|
|
49901
50046
|
throw new AiConfigError("AI tool requires a JSON-Schema object 'parameters'");
|
|
49902
50047
|
}
|
|
49903
50048
|
}
|
|
@@ -49914,8 +50059,8 @@ var init_aiClient = __esm({
|
|
|
49914
50059
|
return;
|
|
49915
50060
|
}
|
|
49916
50061
|
if (choice && typeof choice === "object" && !Array.isArray(choice)) {
|
|
49917
|
-
const
|
|
49918
|
-
if (typeof
|
|
50062
|
+
const record2 = choice;
|
|
50063
|
+
if (typeof record2.name !== "string" || record2.name.length === 0) {
|
|
49919
50064
|
throw new AiConfigError("AI toolChoice object requires a non-empty string 'name'");
|
|
49920
50065
|
}
|
|
49921
50066
|
return;
|
|
@@ -50980,38 +51125,37 @@ function runAll(options = {}) {
|
|
|
50980
51125
|
const { quiet = false, failfast = false } = options;
|
|
50981
51126
|
const results = { passed: 0, failed: 0, errors: 0, details: [] };
|
|
50982
51127
|
for (const entry of registry2) {
|
|
50983
|
-
if (!quiet)
|
|
50984
|
-
console.log(`
|
|
51128
|
+
if (!quiet) console.log(`
|
|
50985
51129
|
${entry.name}`);
|
|
51130
|
+
for (const assertion of entry.assertions) {
|
|
51131
|
+
const label = assertionLabel(assertion, entry.name);
|
|
51132
|
+
const ok = record(results, label, quiet, () => judge(assertion, callSync(entry.fn, assertion.args)));
|
|
51133
|
+
if (!ok && failfast) {
|
|
51134
|
+
printSummary(results, quiet);
|
|
51135
|
+
return results;
|
|
51136
|
+
}
|
|
50986
51137
|
}
|
|
51138
|
+
}
|
|
51139
|
+
printSummary(results, quiet);
|
|
51140
|
+
return results;
|
|
51141
|
+
}
|
|
51142
|
+
async function runAllAsync(options = {}) {
|
|
51143
|
+
const { quiet = false, failfast = false, timeoutMs = 3e4 } = options;
|
|
51144
|
+
checkTimeout(timeoutMs);
|
|
51145
|
+
const results = { passed: 0, failed: 0, errors: 0, details: [] };
|
|
51146
|
+
for (const entry of registry2) {
|
|
51147
|
+
if (!quiet) console.log(`
|
|
51148
|
+
${entry.name}`);
|
|
50987
51149
|
for (const assertion of entry.assertions) {
|
|
50988
51150
|
const label = assertionLabel(assertion, entry.name);
|
|
50989
|
-
|
|
50990
|
-
|
|
50991
|
-
|
|
50992
|
-
|
|
50993
|
-
|
|
50994
|
-
|
|
50995
|
-
|
|
50996
|
-
|
|
50997
|
-
if (err instanceof TestAssertionError) {
|
|
50998
|
-
results.failed++;
|
|
50999
|
-
results.details.push({ name: label, status: "failed", message: err.message });
|
|
51000
|
-
if (!quiet) {
|
|
51001
|
-
console.log(` \x1B[31mx\x1B[0m ${label}: ${err.message}`);
|
|
51002
|
-
}
|
|
51003
|
-
} else {
|
|
51004
|
-
results.errors++;
|
|
51005
|
-
const msg = err instanceof Error ? `${err.constructor.name}: ${err.message}` : String(err);
|
|
51006
|
-
results.details.push({ name: label, status: "error", message: msg });
|
|
51007
|
-
if (!quiet) {
|
|
51008
|
-
console.log(` \x1B[33m!\x1B[0m ${label}: ${msg}`);
|
|
51009
|
-
}
|
|
51010
|
-
}
|
|
51011
|
-
if (failfast) {
|
|
51012
|
-
printSummary(results, quiet);
|
|
51013
|
-
return results;
|
|
51014
|
-
}
|
|
51151
|
+
const outcome = await callAsync(entry.fn, assertion.args, timeoutMs);
|
|
51152
|
+
const ok = record(results, label, quiet, () => {
|
|
51153
|
+
if (outcome instanceof TestRunError) throw outcome;
|
|
51154
|
+
judge(assertion, outcome);
|
|
51155
|
+
});
|
|
51156
|
+
if (!ok && failfast) {
|
|
51157
|
+
printSummary(results, quiet);
|
|
51158
|
+
return results;
|
|
51015
51159
|
}
|
|
51016
51160
|
}
|
|
51017
51161
|
}
|
|
@@ -51021,47 +51165,103 @@ function runAll(options = {}) {
|
|
|
51021
51165
|
function reset() {
|
|
51022
51166
|
registry2.length = 0;
|
|
51023
51167
|
}
|
|
51024
|
-
function
|
|
51025
|
-
|
|
51168
|
+
function isThenable(value) {
|
|
51169
|
+
return value !== null && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
|
|
51170
|
+
}
|
|
51171
|
+
function callSync(fn, args) {
|
|
51172
|
+
let value;
|
|
51173
|
+
try {
|
|
51174
|
+
value = fn(...args);
|
|
51175
|
+
} catch (error2) {
|
|
51176
|
+
return { threw: true, error: error2 };
|
|
51177
|
+
}
|
|
51178
|
+
if (isThenable(value)) {
|
|
51179
|
+
Promise.resolve(value).then(void 0, () => void 0);
|
|
51180
|
+
throw new TestRunError(
|
|
51181
|
+
"returned a Promise (async test function): runAll() cannot judge it, use await runAllAsync()"
|
|
51182
|
+
);
|
|
51183
|
+
}
|
|
51184
|
+
return { threw: false, value };
|
|
51185
|
+
}
|
|
51186
|
+
function checkTimeout(timeoutMs) {
|
|
51187
|
+
if (timeoutMs === Infinity) return;
|
|
51188
|
+
if (!(timeoutMs > 0 && timeoutMs <= MAX_TIMER_MS)) {
|
|
51189
|
+
throw new RangeError(
|
|
51190
|
+
`timeoutMs must be Infinity or a number of milliseconds in (0, ${MAX_TIMER_MS}], got ${timeoutMs}`
|
|
51191
|
+
);
|
|
51192
|
+
}
|
|
51193
|
+
}
|
|
51194
|
+
async function callAsync(fn, args, timeoutMs) {
|
|
51195
|
+
let timer;
|
|
51196
|
+
try {
|
|
51197
|
+
const value = fn(...args);
|
|
51198
|
+
if (!isThenable(value)) return { threw: false, value };
|
|
51199
|
+
if (timeoutMs === Infinity) return { threw: false, value: await value };
|
|
51200
|
+
const timeout = new Promise((_, reject) => {
|
|
51201
|
+
timer = setTimeout(
|
|
51202
|
+
() => reject(new TestRunError(`did not settle within ${timeoutMs} ms`)),
|
|
51203
|
+
timeoutMs
|
|
51204
|
+
);
|
|
51205
|
+
});
|
|
51206
|
+
return { threw: false, value: await Promise.race([Promise.resolve(value), timeout]) };
|
|
51207
|
+
} catch (error2) {
|
|
51208
|
+
if (error2 instanceof TestRunError) return error2;
|
|
51209
|
+
return { threw: true, error: error2 };
|
|
51210
|
+
} finally {
|
|
51211
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
51212
|
+
}
|
|
51213
|
+
}
|
|
51214
|
+
function record(results, label, quiet, check) {
|
|
51215
|
+
try {
|
|
51216
|
+
check();
|
|
51217
|
+
results.passed++;
|
|
51218
|
+
results.details.push({ name: label, status: "passed" });
|
|
51219
|
+
if (!quiet) console.log(` \x1B[32m+\x1B[0m ${label}`);
|
|
51220
|
+
return true;
|
|
51221
|
+
} catch (err) {
|
|
51222
|
+
if (err instanceof TestAssertionError) {
|
|
51223
|
+
results.failed++;
|
|
51224
|
+
results.details.push({ name: label, status: "failed", message: err.message });
|
|
51225
|
+
if (!quiet) console.log(` \x1B[31mx\x1B[0m ${label}: ${err.message}`);
|
|
51226
|
+
} else {
|
|
51227
|
+
results.errors++;
|
|
51228
|
+
const msg = err instanceof Error ? `${err.constructor.name}: ${err.message}` : String(err);
|
|
51229
|
+
results.details.push({ name: label, status: "error", message: msg });
|
|
51230
|
+
if (!quiet) console.log(` \x1B[33m!\x1B[0m ${label}: ${msg}`);
|
|
51231
|
+
}
|
|
51232
|
+
return false;
|
|
51233
|
+
}
|
|
51234
|
+
}
|
|
51235
|
+
function judgeRaises(assertion, outcome) {
|
|
51236
|
+
const ExcClass = assertion.exception;
|
|
51237
|
+
if (!outcome.threw) throw new TestAssertionError(`expected ${ExcClass.name} to be raised`);
|
|
51238
|
+
const err = outcome.error;
|
|
51239
|
+
if (err instanceof ExcClass) return;
|
|
51240
|
+
throw new TestAssertionError(
|
|
51241
|
+
`expected ${ExcClass.name}, got ${err instanceof Error ? err.constructor.name : typeof err}: ${err}`
|
|
51242
|
+
);
|
|
51243
|
+
}
|
|
51244
|
+
function judge(assertion, outcome) {
|
|
51245
|
+
const { type: type2 } = assertion;
|
|
51246
|
+
if (type2 === "raises") return judgeRaises(assertion, outcome);
|
|
51247
|
+
if (outcome.threw) throw outcome.error;
|
|
51248
|
+
const result = outcome.value;
|
|
51026
51249
|
switch (type2) {
|
|
51027
51250
|
case "equal": {
|
|
51028
|
-
const result = fn(...args);
|
|
51029
51251
|
const expected = assertion.expected;
|
|
51030
51252
|
if (result !== expected) {
|
|
51031
51253
|
throw new TestAssertionError(
|
|
51032
51254
|
`expected ${JSON.stringify(expected)}, got ${JSON.stringify(result)}`
|
|
51033
51255
|
);
|
|
51034
51256
|
}
|
|
51035
|
-
|
|
51036
|
-
}
|
|
51037
|
-
case "raises": {
|
|
51038
|
-
const ExcClass = assertion.exception;
|
|
51039
|
-
try {
|
|
51040
|
-
fn(...args);
|
|
51041
|
-
} catch (err) {
|
|
51042
|
-
if (err instanceof ExcClass) {
|
|
51043
|
-
return;
|
|
51044
|
-
}
|
|
51045
|
-
throw new TestAssertionError(
|
|
51046
|
-
`expected ${ExcClass.name}, got ${err instanceof Error ? err.constructor.name : typeof err}: ${err}`
|
|
51047
|
-
);
|
|
51048
|
-
}
|
|
51049
|
-
throw new TestAssertionError(`expected ${ExcClass.name} to be raised`);
|
|
51050
|
-
}
|
|
51051
|
-
case "true": {
|
|
51052
|
-
const result = fn(...args);
|
|
51053
|
-
if (!result) {
|
|
51054
|
-
throw new TestAssertionError(`expected truthy, got ${JSON.stringify(result)}`);
|
|
51055
|
-
}
|
|
51056
|
-
break;
|
|
51057
|
-
}
|
|
51058
|
-
case "false": {
|
|
51059
|
-
const result = fn(...args);
|
|
51060
|
-
if (result) {
|
|
51061
|
-
throw new TestAssertionError(`expected falsy, got ${JSON.stringify(result)}`);
|
|
51062
|
-
}
|
|
51063
|
-
break;
|
|
51257
|
+
return;
|
|
51064
51258
|
}
|
|
51259
|
+
case "true":
|
|
51260
|
+
if (!result) throw new TestAssertionError(`expected truthy, got ${JSON.stringify(result)}`);
|
|
51261
|
+
return;
|
|
51262
|
+
case "false":
|
|
51263
|
+
if (result) throw new TestAssertionError(`expected falsy, got ${JSON.stringify(result)}`);
|
|
51264
|
+
return;
|
|
51065
51265
|
default:
|
|
51066
51266
|
throw new Error(`unknown assertion type: ${type2}`);
|
|
51067
51267
|
}
|
|
@@ -51090,7 +51290,7 @@ function printSummary(results, quiet) {
|
|
|
51090
51290
|
`
|
|
51091
51291
|
);
|
|
51092
51292
|
}
|
|
51093
|
-
var registry2, TestAssertionError;
|
|
51293
|
+
var registry2, TestAssertionError, TestRunError, MAX_TIMER_MS;
|
|
51094
51294
|
var init_testing = __esm({
|
|
51095
51295
|
"src/testing.ts"() {
|
|
51096
51296
|
"use strict";
|
|
@@ -51101,6 +51301,13 @@ var init_testing = __esm({
|
|
|
51101
51301
|
this.name = "TestAssertionError";
|
|
51102
51302
|
}
|
|
51103
51303
|
};
|
|
51304
|
+
TestRunError = class extends Error {
|
|
51305
|
+
constructor(message) {
|
|
51306
|
+
super(message);
|
|
51307
|
+
this.name = "TestRunError";
|
|
51308
|
+
}
|
|
51309
|
+
};
|
|
51310
|
+
MAX_TIMER_MS = 2147483647;
|
|
51104
51311
|
}
|
|
51105
51312
|
});
|
|
51106
51313
|
|
|
@@ -51916,6 +52123,7 @@ __export(index_exports, {
|
|
|
51916
52123
|
resolveTemplate: () => resolveTemplate,
|
|
51917
52124
|
responseCache: () => responseCache,
|
|
51918
52125
|
runAll: () => runAll,
|
|
52126
|
+
runAllAsync: () => runAllAsync,
|
|
51919
52127
|
runRouteMiddlewares: () => runRouteMiddlewares,
|
|
51920
52128
|
runWithCspNonce: () => runWithCspNonce,
|
|
51921
52129
|
runtimeDir: () => runtimeDir,
|
|
@@ -52318,6 +52526,7 @@ export {
|
|
|
52318
52526
|
resolveTemplate,
|
|
52319
52527
|
responseCache,
|
|
52320
52528
|
runAll,
|
|
52529
|
+
runAllAsync,
|
|
52321
52530
|
runRouteMiddlewares,
|
|
52322
52531
|
runWithCspNonce,
|
|
52323
52532
|
runtimeDir,
|