tina4-nodejs 3.13.160 → 3.13.162
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +2 -2
- package/package.json +1 -1
- package/packages/cli/dist/bin.js +44 -7
- package/packages/core/dist/index.js +44 -7
- package/packages/core/src/server.ts +71 -15
- package/packages/core/src/testClient.ts +30 -1
- package/packages/orm/dist/index.js +44 -7
package/CLAUDE.md
CHANGED
|
@@ -14,13 +14,13 @@ Even if the skill text is not currently loaded, these are non-negotiable:
|
|
|
14
14
|
|
|
15
15
|
The full discipline lives in `.claude/skills/tina4-maintainer/SKILL.md`; this block is the always-on floor.
|
|
16
16
|
|
|
17
|
-
# CLAUDE.md - AI Developer Guide for tina4-nodejs (v3.13.
|
|
17
|
+
# CLAUDE.md - AI Developer Guide for tina4-nodejs (v3.13.162)
|
|
18
18
|
|
|
19
19
|
> This file helps AI assistants (Claude, Copilot, Cursor, etc.) understand and work on this codebase effectively.
|
|
20
20
|
|
|
21
21
|
## What This Project Is
|
|
22
22
|
|
|
23
|
-
Tina4 for Node.js/TypeScript v3.13.
|
|
23
|
+
Tina4 for Node.js/TypeScript v3.13.162 - The Intelligent Native Application 4ramework. A convention-over-configuration structural paradigm. The developer writes TypeScript; Tina4 is invisible infrastructure.
|
|
24
24
|
|
|
25
25
|
The philosophy: zero ceremony, batteries included, file system as source of truth.
|
|
26
26
|
|
package/package.json
CHANGED
package/packages/cli/dist/bin.js
CHANGED
|
@@ -44398,7 +44398,6 @@ async function startServer(config) {
|
|
|
44398
44398
|
server.listen(port, host, async () => {
|
|
44399
44399
|
if (!cluster.isWorker) writePidfile(port);
|
|
44400
44400
|
const siblingServers = await startLoopbackSiblings(port, host, dispatch);
|
|
44401
|
-
await startAllTcpServices(host);
|
|
44402
44401
|
const displayHost = host === "0.0.0.0" ? "localhost" : host;
|
|
44403
44402
|
const isDebug = isTruthy(process.env.TINA4_DEBUG);
|
|
44404
44403
|
const logLevel = (process.env.TINA4_LOG_LEVEL ?? "DEBUG").toUpperCase();
|
|
@@ -44479,9 +44478,7 @@ ${reset2}
|
|
|
44479
44478
|
aiServer?.closeIdleConnections();
|
|
44480
44479
|
for (const sibling of siblingServers) sibling.closeIdleConnections();
|
|
44481
44480
|
});
|
|
44482
|
-
const
|
|
44483
|
-
if (shuttingDown) return;
|
|
44484
|
-
shuttingDown = true;
|
|
44481
|
+
const runTeardown = async (signal) => {
|
|
44485
44482
|
Log.info(`Received ${signal}, shutting down gracefully...`);
|
|
44486
44483
|
if (!cluster.isWorker) removePidfile(port);
|
|
44487
44484
|
stopAllBackgroundTasks();
|
|
@@ -44516,16 +44513,40 @@ ${reset2}
|
|
|
44516
44513
|
}
|
|
44517
44514
|
Log.info("Server stopped.");
|
|
44518
44515
|
Log.reset();
|
|
44516
|
+
};
|
|
44517
|
+
const degradeTeardownFailure = (signal, err) => {
|
|
44518
|
+
const detail = err instanceof Error ? err.message : String(err);
|
|
44519
|
+
try {
|
|
44520
|
+
Log.error(`Teardown step failed during ${signal} shutdown (exiting cleanly): ${detail}`);
|
|
44521
|
+
} catch {
|
|
44522
|
+
try {
|
|
44523
|
+
process.stderr.write(
|
|
44524
|
+
`tina4: teardown step failed during ${signal} shutdown (exiting cleanly): ${detail}
|
|
44525
|
+
`
|
|
44526
|
+
);
|
|
44527
|
+
} catch {
|
|
44528
|
+
}
|
|
44529
|
+
}
|
|
44530
|
+
};
|
|
44531
|
+
const gracefulShutdown = async (signal) => {
|
|
44532
|
+
if (shuttingDown) return;
|
|
44533
|
+
shuttingDown = true;
|
|
44534
|
+
try {
|
|
44535
|
+
await runTeardown(signal);
|
|
44536
|
+
} catch (err) {
|
|
44537
|
+
degradeTeardownFailure(signal, err);
|
|
44538
|
+
}
|
|
44519
44539
|
process.exit(0);
|
|
44520
44540
|
};
|
|
44521
44541
|
const onSigterm = () => {
|
|
44522
|
-
void gracefulShutdown("SIGTERM");
|
|
44542
|
+
void gracefulShutdown("SIGTERM").catch(() => process.exit(0));
|
|
44523
44543
|
};
|
|
44524
44544
|
const onSigint = () => {
|
|
44525
|
-
void gracefulShutdown("SIGINT");
|
|
44545
|
+
void gracefulShutdown("SIGINT").catch(() => process.exit(0));
|
|
44526
44546
|
};
|
|
44527
44547
|
process.on("SIGTERM", onSigterm);
|
|
44528
44548
|
process.on("SIGINT", onSigint);
|
|
44549
|
+
await startAllTcpServices(host);
|
|
44529
44550
|
const loopWatchdog = startLoopWatchdog();
|
|
44530
44551
|
resolvePromise({
|
|
44531
44552
|
close: () => {
|
|
@@ -51154,6 +51175,7 @@ var init_testClient = __esm({
|
|
|
51154
51175
|
"use strict";
|
|
51155
51176
|
init_router();
|
|
51156
51177
|
init_server();
|
|
51178
|
+
init_dotenv();
|
|
51157
51179
|
TestResponse = class {
|
|
51158
51180
|
status;
|
|
51159
51181
|
body;
|
|
@@ -51169,7 +51191,18 @@ var init_testClient = __esm({
|
|
|
51169
51191
|
for (const [name, values] of Object.entries(headerList)) {
|
|
51170
51192
|
if (values.length > 0) flat[name] = values[values.length - 1];
|
|
51171
51193
|
}
|
|
51172
|
-
this.headers = flat
|
|
51194
|
+
this.headers = new Proxy(flat, {
|
|
51195
|
+
get(target, prop, receiver) {
|
|
51196
|
+
if (typeof prop === "string" && !(prop in target) && prop.toLowerCase() in target) {
|
|
51197
|
+
return target[prop.toLowerCase()];
|
|
51198
|
+
}
|
|
51199
|
+
return Reflect.get(target, prop, receiver);
|
|
51200
|
+
},
|
|
51201
|
+
has(target, prop) {
|
|
51202
|
+
if (typeof prop === "string" && prop.toLowerCase() in target) return true;
|
|
51203
|
+
return Reflect.has(target, prop);
|
|
51204
|
+
}
|
|
51205
|
+
});
|
|
51173
51206
|
this.contentType = this.headers["content-type"] ?? "";
|
|
51174
51207
|
}
|
|
51175
51208
|
/**
|
|
@@ -51206,6 +51239,10 @@ var init_testClient = __esm({
|
|
|
51206
51239
|
ctxPromise = null;
|
|
51207
51240
|
constructor(router) {
|
|
51208
51241
|
this.explicitRouter = router;
|
|
51242
|
+
try {
|
|
51243
|
+
loadEnv();
|
|
51244
|
+
} catch {
|
|
51245
|
+
}
|
|
51209
51246
|
}
|
|
51210
51247
|
/**
|
|
51211
51248
|
* Resolve (and memoise) the DispatchContext this client dispatches
|
|
@@ -44354,7 +44354,6 @@ async function startServer(config) {
|
|
|
44354
44354
|
server.listen(port, host, async () => {
|
|
44355
44355
|
if (!cluster.isWorker) writePidfile(port);
|
|
44356
44356
|
const siblingServers = await startLoopbackSiblings(port, host, dispatch);
|
|
44357
|
-
await startAllTcpServices(host);
|
|
44358
44357
|
const displayHost = host === "0.0.0.0" ? "localhost" : host;
|
|
44359
44358
|
const isDebug = isTruthy(process.env.TINA4_DEBUG);
|
|
44360
44359
|
const logLevel = (process.env.TINA4_LOG_LEVEL ?? "DEBUG").toUpperCase();
|
|
@@ -44435,9 +44434,7 @@ ${reset2}
|
|
|
44435
44434
|
aiServer?.closeIdleConnections();
|
|
44436
44435
|
for (const sibling of siblingServers) sibling.closeIdleConnections();
|
|
44437
44436
|
});
|
|
44438
|
-
const
|
|
44439
|
-
if (shuttingDown) return;
|
|
44440
|
-
shuttingDown = true;
|
|
44437
|
+
const runTeardown = async (signal) => {
|
|
44441
44438
|
Log.info(`Received ${signal}, shutting down gracefully...`);
|
|
44442
44439
|
if (!cluster.isWorker) removePidfile(port);
|
|
44443
44440
|
stopAllBackgroundTasks();
|
|
@@ -44472,16 +44469,40 @@ ${reset2}
|
|
|
44472
44469
|
}
|
|
44473
44470
|
Log.info("Server stopped.");
|
|
44474
44471
|
Log.reset();
|
|
44472
|
+
};
|
|
44473
|
+
const degradeTeardownFailure = (signal, err) => {
|
|
44474
|
+
const detail = err instanceof Error ? err.message : String(err);
|
|
44475
|
+
try {
|
|
44476
|
+
Log.error(`Teardown step failed during ${signal} shutdown (exiting cleanly): ${detail}`);
|
|
44477
|
+
} catch {
|
|
44478
|
+
try {
|
|
44479
|
+
process.stderr.write(
|
|
44480
|
+
`tina4: teardown step failed during ${signal} shutdown (exiting cleanly): ${detail}
|
|
44481
|
+
`
|
|
44482
|
+
);
|
|
44483
|
+
} catch {
|
|
44484
|
+
}
|
|
44485
|
+
}
|
|
44486
|
+
};
|
|
44487
|
+
const gracefulShutdown = async (signal) => {
|
|
44488
|
+
if (shuttingDown) return;
|
|
44489
|
+
shuttingDown = true;
|
|
44490
|
+
try {
|
|
44491
|
+
await runTeardown(signal);
|
|
44492
|
+
} catch (err) {
|
|
44493
|
+
degradeTeardownFailure(signal, err);
|
|
44494
|
+
}
|
|
44475
44495
|
process.exit(0);
|
|
44476
44496
|
};
|
|
44477
44497
|
const onSigterm = () => {
|
|
44478
|
-
void gracefulShutdown("SIGTERM");
|
|
44498
|
+
void gracefulShutdown("SIGTERM").catch(() => process.exit(0));
|
|
44479
44499
|
};
|
|
44480
44500
|
const onSigint = () => {
|
|
44481
|
-
void gracefulShutdown("SIGINT");
|
|
44501
|
+
void gracefulShutdown("SIGINT").catch(() => process.exit(0));
|
|
44482
44502
|
};
|
|
44483
44503
|
process.on("SIGTERM", onSigterm);
|
|
44484
44504
|
process.on("SIGINT", onSigint);
|
|
44505
|
+
await startAllTcpServices(host);
|
|
44485
44506
|
const loopWatchdog = startLoopWatchdog();
|
|
44486
44507
|
resolvePromise({
|
|
44487
44508
|
close: () => {
|
|
@@ -51092,6 +51113,7 @@ var init_testClient = __esm({
|
|
|
51092
51113
|
"use strict";
|
|
51093
51114
|
init_router();
|
|
51094
51115
|
init_server();
|
|
51116
|
+
init_dotenv();
|
|
51095
51117
|
TestResponse = class {
|
|
51096
51118
|
status;
|
|
51097
51119
|
body;
|
|
@@ -51107,7 +51129,18 @@ var init_testClient = __esm({
|
|
|
51107
51129
|
for (const [name, values] of Object.entries(headerList)) {
|
|
51108
51130
|
if (values.length > 0) flat[name] = values[values.length - 1];
|
|
51109
51131
|
}
|
|
51110
|
-
this.headers = flat
|
|
51132
|
+
this.headers = new Proxy(flat, {
|
|
51133
|
+
get(target, prop, receiver) {
|
|
51134
|
+
if (typeof prop === "string" && !(prop in target) && prop.toLowerCase() in target) {
|
|
51135
|
+
return target[prop.toLowerCase()];
|
|
51136
|
+
}
|
|
51137
|
+
return Reflect.get(target, prop, receiver);
|
|
51138
|
+
},
|
|
51139
|
+
has(target, prop) {
|
|
51140
|
+
if (typeof prop === "string" && prop.toLowerCase() in target) return true;
|
|
51141
|
+
return Reflect.has(target, prop);
|
|
51142
|
+
}
|
|
51143
|
+
});
|
|
51111
51144
|
this.contentType = this.headers["content-type"] ?? "";
|
|
51112
51145
|
}
|
|
51113
51146
|
/**
|
|
@@ -51144,6 +51177,10 @@ var init_testClient = __esm({
|
|
|
51144
51177
|
ctxPromise = null;
|
|
51145
51178
|
constructor(router) {
|
|
51146
51179
|
this.explicitRouter = router;
|
|
51180
|
+
try {
|
|
51181
|
+
loadEnv();
|
|
51182
|
+
} catch {
|
|
51183
|
+
}
|
|
51147
51184
|
}
|
|
51148
51185
|
/**
|
|
51149
51186
|
* Resolve (and memoise) the DispatchContext this client dispatches
|
|
@@ -2388,11 +2388,11 @@ export async function startServer(config?: Tina4Config): Promise<{
|
|
|
2388
2388
|
// promise resolves (a client can then rely on both families being up).
|
|
2389
2389
|
const siblingServers = await startLoopbackSiblings(port, host, dispatch);
|
|
2390
2390
|
|
|
2391
|
-
// Raw TCP services
|
|
2392
|
-
//
|
|
2393
|
-
//
|
|
2394
|
-
//
|
|
2395
|
-
|
|
2391
|
+
// Raw TCP services start LATER, only after the SIGTERM/SIGINT handlers are
|
|
2392
|
+
// armed (see startAllTcpServices below). Binding a port that accepts work
|
|
2393
|
+
// BEFORE graceful shutdown is wired leaves a window in which a signal kills
|
|
2394
|
+
// the process ungracefully (exit 143) instead of draining to exit 0 — and
|
|
2395
|
+
// a client that connects the instant the port opens lands squarely in it.
|
|
2396
2396
|
|
|
2397
2397
|
const displayHost = host === "0.0.0.0" ? "localhost" : host;
|
|
2398
2398
|
const isDebug = isTruthy(process.env.TINA4_DEBUG);
|
|
@@ -2556,9 +2556,11 @@ ${reset}
|
|
|
2556
2556
|
for (const sibling of siblingServers) sibling.closeIdleConnections();
|
|
2557
2557
|
});
|
|
2558
2558
|
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2559
|
+
// The teardown steps a handled signal must run. Pulled out of
|
|
2560
|
+
// gracefulShutdown() so the handler itself stays a thin try/catch/exit
|
|
2561
|
+
// (low cyclomatic complexity) — the drain logic lives here, the
|
|
2562
|
+
// exit-safety contract lives in the caller.
|
|
2563
|
+
const runTeardown = async (signal: string): Promise<void> => {
|
|
2562
2564
|
Log.info(`Received ${signal}, shutting down gracefully...`);
|
|
2563
2565
|
|
|
2564
2566
|
// Drop our identity marker so a later takeover does not match a dead PID.
|
|
@@ -2623,23 +2625,77 @@ ${reset}
|
|
|
2623
2625
|
// without letting exit() actually kill the process (see
|
|
2624
2626
|
// test/gracefulShutdown.test.ts) must not inherit a stale snapshot.
|
|
2625
2627
|
Log.reset();
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2628
|
+
};
|
|
2629
|
+
|
|
2630
|
+
// Best-effort degrade when a teardown step throws: try the logger, and
|
|
2631
|
+
// when logging ITSELF is the failing step, fall back to a raw stderr
|
|
2632
|
+
// write (which never routes through the sink). Never throws.
|
|
2633
|
+
const degradeTeardownFailure = (signal: string, err: unknown): void => {
|
|
2634
|
+
const detail = err instanceof Error ? err.message : String(err);
|
|
2635
|
+
try {
|
|
2636
|
+
Log.error(`Teardown step failed during ${signal} shutdown (exiting cleanly): ${detail}`);
|
|
2637
|
+
} catch {
|
|
2638
|
+
try {
|
|
2639
|
+
process.stderr.write(
|
|
2640
|
+
`tina4: teardown step failed during ${signal} shutdown (exiting cleanly): ${detail}\n`,
|
|
2641
|
+
);
|
|
2642
|
+
} catch {
|
|
2643
|
+
/* nothing left to degrade to */
|
|
2644
|
+
}
|
|
2645
|
+
}
|
|
2646
|
+
};
|
|
2647
|
+
|
|
2648
|
+
const gracefulShutdown = async (signal: string): Promise<void> => {
|
|
2649
|
+
if (shuttingDown) return;
|
|
2650
|
+
shuttingDown = true;
|
|
2651
|
+
|
|
2652
|
+
// Exception-safe teardown (parity with PHP Server::cleanup()/
|
|
2653
|
+
// forceShutdown() and Ruby). A handled SIGTERM/SIGINT MUST drain and
|
|
2654
|
+
// exit 0, never fatal, so NO throw or rejection from any teardown step
|
|
2655
|
+
// may escape this function. The handlers below invoke it as
|
|
2656
|
+
// `void gracefulShutdown(...)`, which discards the promise - an escaping
|
|
2657
|
+
// rejection would surface as an unhandledRejection and Node's default
|
|
2658
|
+
// disposition would exit NON-ZERO, turning a handled signal into exit 1.
|
|
2659
|
+
// So the whole drain runs inside this guard: on any throw we degrade to
|
|
2660
|
+
// a best-effort line and STILL exit 0. `shuttingDown` keeps it idempotent.
|
|
2661
|
+
try {
|
|
2662
|
+
await runTeardown(signal);
|
|
2663
|
+
} catch (err) {
|
|
2664
|
+
degradeTeardownFailure(signal, err);
|
|
2665
|
+
}
|
|
2666
|
+
|
|
2667
|
+
// Exit 0: this process was ASKED to stop. Reached on the clean path AND
|
|
2668
|
+
// after a degraded teardown. 128+signum is what waitpid reports for a
|
|
2669
|
+
// process killed BY a signal, i.e. one that did NOT handle it - it is a
|
|
2670
|
+
// diagnosis, not a target. Gunicorn and Puma both halt 0 on a handled
|
|
2671
|
+
// TERM, and a container exiting 0 is a clean termination rather than a
|
|
2672
|
+
// signal-kill.
|
|
2631
2673
|
process.exit(0);
|
|
2632
2674
|
};
|
|
2633
2675
|
|
|
2634
2676
|
const onSigterm = (): void => {
|
|
2635
|
-
|
|
2677
|
+
// gracefulShutdown is internally exception-safe, so this cannot reject;
|
|
2678
|
+
// the `.catch` is belt-and-braces so the discarded (`void`) promise can
|
|
2679
|
+
// never become an unhandledRejection that exits non-zero on a handled
|
|
2680
|
+
// signal.
|
|
2681
|
+
void gracefulShutdown("SIGTERM").catch(() => process.exit(0));
|
|
2636
2682
|
};
|
|
2637
2683
|
const onSigint = (): void => {
|
|
2638
|
-
void gracefulShutdown("SIGINT");
|
|
2684
|
+
void gracefulShutdown("SIGINT").catch(() => process.exit(0));
|
|
2639
2685
|
};
|
|
2640
2686
|
process.on("SIGTERM", onSigterm);
|
|
2641
2687
|
process.on("SIGINT", onSigint);
|
|
2642
2688
|
|
|
2689
|
+
// Raw TCP services (feature 142, ADR-0102 D1) bind on THIS event loop,
|
|
2690
|
+
// beside the HTTP server — one process serves both the device gateway and
|
|
2691
|
+
// its dashboard. Started HERE, AFTER the shutdown handlers are armed and
|
|
2692
|
+
// still BEFORE resolvePromise (so a client can rely on both families being
|
|
2693
|
+
// up), so a device connecting the instant the port opens can never catch
|
|
2694
|
+
// the process in a state where SIGTERM kills it ungracefully instead of
|
|
2695
|
+
// draining (feature 142's SIGTERM-drain contract). Each binds its own port;
|
|
2696
|
+
// a worker that finds it already bound skips silently (single-owner).
|
|
2697
|
+
await startAllTcpServices(host);
|
|
2698
|
+
|
|
2643
2699
|
const loopWatchdog = startLoopWatchdog();
|
|
2644
2700
|
|
|
2645
2701
|
resolvePromise({
|
|
@@ -48,6 +48,7 @@ import { IncomingMessage, ServerResponse } from "node:http";
|
|
|
48
48
|
import { Socket } from "node:net";
|
|
49
49
|
import { defaultRouter, Router } from "./router.js";
|
|
50
50
|
import { runDispatch, buildDispatchContext, getLiveDispatchContext, type DispatchContext } from "./server.js";
|
|
51
|
+
import { loadEnv } from "./dotenv.js";
|
|
51
52
|
|
|
52
53
|
export class TestResponse {
|
|
53
54
|
public readonly status: number;
|
|
@@ -74,7 +75,25 @@ export class TestResponse {
|
|
|
74
75
|
for (const [name, values] of Object.entries(headerList)) {
|
|
75
76
|
if (values.length > 0) flat[name] = values[values.length - 1]!;
|
|
76
77
|
}
|
|
77
|
-
|
|
78
|
+
// #300: HTTP header names are case-insensitive (RFC 9110), and
|
|
79
|
+
// getHeaderList() already treats them that way. Keys are STORED lower case,
|
|
80
|
+
// so Object.keys / spread / JSON.stringify are all unchanged — every reader
|
|
81
|
+
// sees the same object. A Proxy lowercases only the LOOKUP, so
|
|
82
|
+
// headers["Location"] finds a header emitted as "location" instead of
|
|
83
|
+
// undefined, while a real own/inherited member (toString, hasOwnProperty…)
|
|
84
|
+
// is left untouched.
|
|
85
|
+
this.headers = new Proxy(flat, {
|
|
86
|
+
get(target, prop, receiver) {
|
|
87
|
+
if (typeof prop === "string" && !(prop in target) && prop.toLowerCase() in target) {
|
|
88
|
+
return target[prop.toLowerCase()];
|
|
89
|
+
}
|
|
90
|
+
return Reflect.get(target, prop, receiver);
|
|
91
|
+
},
|
|
92
|
+
has(target, prop) {
|
|
93
|
+
if (typeof prop === "string" && prop.toLowerCase() in target) return true;
|
|
94
|
+
return Reflect.has(target, prop);
|
|
95
|
+
},
|
|
96
|
+
}) as Record<string, string>;
|
|
78
97
|
this.contentType = this.headers["content-type"] ?? "";
|
|
79
98
|
}
|
|
80
99
|
|
|
@@ -123,6 +142,16 @@ export class TestClient {
|
|
|
123
142
|
|
|
124
143
|
constructor(router?: Router) {
|
|
125
144
|
this.explicitRouter = router;
|
|
145
|
+
|
|
146
|
+
// #296: load .env the way startServer does, so a TestClient test that never
|
|
147
|
+
// started a server still sees TINA4_SECRET etc. loadEnv is override=false
|
|
148
|
+
// (first-wins, .env.local then .env), so a value the test set in the real
|
|
149
|
+
// environment is never clobbered — the test still wins.
|
|
150
|
+
try {
|
|
151
|
+
loadEnv();
|
|
152
|
+
} catch {
|
|
153
|
+
// A missing or unreadable .env must never stop a test from running.
|
|
154
|
+
}
|
|
126
155
|
}
|
|
127
156
|
|
|
128
157
|
/**
|
|
@@ -31237,7 +31237,6 @@ async function startServer(config) {
|
|
|
31237
31237
|
server.listen(port, host, async () => {
|
|
31238
31238
|
if (!cluster.isWorker) writePidfile(port);
|
|
31239
31239
|
const siblingServers = await startLoopbackSiblings(port, host, dispatch);
|
|
31240
|
-
await startAllTcpServices(host);
|
|
31241
31240
|
const displayHost = host === "0.0.0.0" ? "localhost" : host;
|
|
31242
31241
|
const isDebug = isTruthy(process.env.TINA4_DEBUG);
|
|
31243
31242
|
const logLevel = (process.env.TINA4_LOG_LEVEL ?? "DEBUG").toUpperCase();
|
|
@@ -31318,9 +31317,7 @@ ${reset2}
|
|
|
31318
31317
|
aiServer?.closeIdleConnections();
|
|
31319
31318
|
for (const sibling of siblingServers) sibling.closeIdleConnections();
|
|
31320
31319
|
});
|
|
31321
|
-
const
|
|
31322
|
-
if (shuttingDown) return;
|
|
31323
|
-
shuttingDown = true;
|
|
31320
|
+
const runTeardown = async (signal) => {
|
|
31324
31321
|
Log.info(`Received ${signal}, shutting down gracefully...`);
|
|
31325
31322
|
if (!cluster.isWorker) removePidfile(port);
|
|
31326
31323
|
stopAllBackgroundTasks();
|
|
@@ -31355,16 +31352,40 @@ ${reset2}
|
|
|
31355
31352
|
}
|
|
31356
31353
|
Log.info("Server stopped.");
|
|
31357
31354
|
Log.reset();
|
|
31355
|
+
};
|
|
31356
|
+
const degradeTeardownFailure = (signal, err) => {
|
|
31357
|
+
const detail = err instanceof Error ? err.message : String(err);
|
|
31358
|
+
try {
|
|
31359
|
+
Log.error(`Teardown step failed during ${signal} shutdown (exiting cleanly): ${detail}`);
|
|
31360
|
+
} catch {
|
|
31361
|
+
try {
|
|
31362
|
+
process.stderr.write(
|
|
31363
|
+
`tina4: teardown step failed during ${signal} shutdown (exiting cleanly): ${detail}
|
|
31364
|
+
`
|
|
31365
|
+
);
|
|
31366
|
+
} catch {
|
|
31367
|
+
}
|
|
31368
|
+
}
|
|
31369
|
+
};
|
|
31370
|
+
const gracefulShutdown = async (signal) => {
|
|
31371
|
+
if (shuttingDown) return;
|
|
31372
|
+
shuttingDown = true;
|
|
31373
|
+
try {
|
|
31374
|
+
await runTeardown(signal);
|
|
31375
|
+
} catch (err) {
|
|
31376
|
+
degradeTeardownFailure(signal, err);
|
|
31377
|
+
}
|
|
31358
31378
|
process.exit(0);
|
|
31359
31379
|
};
|
|
31360
31380
|
const onSigterm = () => {
|
|
31361
|
-
void gracefulShutdown("SIGTERM");
|
|
31381
|
+
void gracefulShutdown("SIGTERM").catch(() => process.exit(0));
|
|
31362
31382
|
};
|
|
31363
31383
|
const onSigint = () => {
|
|
31364
|
-
void gracefulShutdown("SIGINT");
|
|
31384
|
+
void gracefulShutdown("SIGINT").catch(() => process.exit(0));
|
|
31365
31385
|
};
|
|
31366
31386
|
process.on("SIGTERM", onSigterm);
|
|
31367
31387
|
process.on("SIGINT", onSigint);
|
|
31388
|
+
await startAllTcpServices(host);
|
|
31368
31389
|
const loopWatchdog = startLoopWatchdog();
|
|
31369
31390
|
resolvePromise({
|
|
31370
31391
|
close: () => {
|
|
@@ -38506,6 +38527,7 @@ var init_testClient = __esm({
|
|
|
38506
38527
|
"use strict";
|
|
38507
38528
|
init_router();
|
|
38508
38529
|
init_server();
|
|
38530
|
+
init_dotenv();
|
|
38509
38531
|
TestResponse = class {
|
|
38510
38532
|
status;
|
|
38511
38533
|
body;
|
|
@@ -38521,7 +38543,18 @@ var init_testClient = __esm({
|
|
|
38521
38543
|
for (const [name, values] of Object.entries(headerList)) {
|
|
38522
38544
|
if (values.length > 0) flat[name] = values[values.length - 1];
|
|
38523
38545
|
}
|
|
38524
|
-
this.headers = flat
|
|
38546
|
+
this.headers = new Proxy(flat, {
|
|
38547
|
+
get(target, prop, receiver) {
|
|
38548
|
+
if (typeof prop === "string" && !(prop in target) && prop.toLowerCase() in target) {
|
|
38549
|
+
return target[prop.toLowerCase()];
|
|
38550
|
+
}
|
|
38551
|
+
return Reflect.get(target, prop, receiver);
|
|
38552
|
+
},
|
|
38553
|
+
has(target, prop) {
|
|
38554
|
+
if (typeof prop === "string" && prop.toLowerCase() in target) return true;
|
|
38555
|
+
return Reflect.has(target, prop);
|
|
38556
|
+
}
|
|
38557
|
+
});
|
|
38525
38558
|
this.contentType = this.headers["content-type"] ?? "";
|
|
38526
38559
|
}
|
|
38527
38560
|
/**
|
|
@@ -38558,6 +38591,10 @@ var init_testClient = __esm({
|
|
|
38558
38591
|
ctxPromise = null;
|
|
38559
38592
|
constructor(router) {
|
|
38560
38593
|
this.explicitRouter = router;
|
|
38594
|
+
try {
|
|
38595
|
+
loadEnv();
|
|
38596
|
+
} catch {
|
|
38597
|
+
}
|
|
38561
38598
|
}
|
|
38562
38599
|
/**
|
|
38563
38600
|
* Resolve (and memoise) the DispatchContext this client dispatches
|