tina4-nodejs 3.13.161 → 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 +27 -6
- package/packages/core/dist/index.js +27 -6
- package/packages/core/src/server.ts +71 -15
- package/packages/orm/dist/index.js +27 -6
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: () => {
|
|
@@ -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: () => {
|
|
@@ -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({
|
|
@@ -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: () => {
|