@zintrust/core 1.5.5 → 1.6.1
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/bin/launcher.d.ts +6 -0
- package/bin/launcher.d.ts.map +1 -0
- package/bin/launcher.js +167 -0
- package/bin/z.js +2 -102
- package/bin/zin.js +2 -192
- package/bin/zintrust.d.ts +1 -1
- package/bin/zintrust.d.ts.map +1 -1
- package/bin/zintrust.js +3 -103
- package/bin/zt.d.ts +1 -1
- package/bin/zt.js +3 -100
- package/package.json +5 -5
- package/src/boot/registry/runtime.d.ts +4 -2
- package/src/boot/registry/runtime.d.ts.map +1 -1
- package/src/boot/registry/runtime.js +45 -30
- package/src/cli/cloudflare/CloudflareWranglerDevEnv.d.ts.map +1 -1
- package/src/cli/cloudflare/CloudflareWranglerDevEnv.js +21 -0
- package/src/cli/scaffolding/env.d.ts.map +1 -1
- package/src/cli/scaffolding/env.js +2 -0
- package/src/helper/ShutdownTrace.d.ts.map +1 -1
- package/src/helper/ShutdownTrace.js +2 -19
- package/src/index.js +3 -3
- package/src/templates/project/basic/config/database.ts.tpl +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"launcher.d.ts","sourceRoot":"","sources":["../../bin/launcher.ts"],"names":[],"mappings":"AAMA,KAAK,kBAAkB,GAAG;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AA6LF,eAAO,MAAM,aAAa,GAAU,QAAO,kBAAuB,KAAG,OAAO,CAAC,IAAI,CAoBhF,CAAC"}
|
package/bin/launcher.js
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
const CLI_SPAWN_TRACE_ENV_KEYS = ['CLI_SPAWN_TRACE', 'ZIN_SPAWN_TRACE'];
|
|
7
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
const require = createRequire(import.meta.url);
|
|
9
|
+
const isCliSpawnTraceEnabled = () => {
|
|
10
|
+
return CLI_SPAWN_TRACE_ENV_KEYS.some((key) => {
|
|
11
|
+
const raw = process.env[key];
|
|
12
|
+
if (typeof raw !== 'string')
|
|
13
|
+
return false;
|
|
14
|
+
const normalized = raw.trim().toLowerCase();
|
|
15
|
+
return (normalized === '1' || normalized === 'true' || normalized === 'yes' || normalized === 'on');
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
const writeCliSpawnTrace = (input, label, details = {}) => {
|
|
19
|
+
if (input.traceName === undefined || !isCliSpawnTraceEnabled())
|
|
20
|
+
return;
|
|
21
|
+
process.stderr.write(`${JSON.stringify({ trace: input.traceName, label, pid: process.pid, details })}\n`);
|
|
22
|
+
};
|
|
23
|
+
const resolveNodeArgs = () => {
|
|
24
|
+
const tsTarget = path.join(here, 'zintrust-main.ts');
|
|
25
|
+
const jsTarget = path.join(here, 'zintrust-main.js');
|
|
26
|
+
const target = existsSync(tsTarget) ? tsTarget : jsTarget;
|
|
27
|
+
if (!target.endsWith('.ts')) {
|
|
28
|
+
return [target, ...process.argv.slice(2)];
|
|
29
|
+
}
|
|
30
|
+
return ['--import', require.resolve('tsx'), target, ...process.argv.slice(2)];
|
|
31
|
+
};
|
|
32
|
+
const getExitCode = (exitCode, signal) => {
|
|
33
|
+
if (typeof exitCode === 'number')
|
|
34
|
+
return exitCode;
|
|
35
|
+
if (signal === 'SIGINT' || signal === 'SIGTERM')
|
|
36
|
+
return 0;
|
|
37
|
+
return 1;
|
|
38
|
+
};
|
|
39
|
+
const attachOutputRelay = (input, child, stream) => {
|
|
40
|
+
const childStream = child[stream];
|
|
41
|
+
const targetStream = stream === 'stdout' ? process.stdout : process.stderr;
|
|
42
|
+
childStream?.on('data', (chunk) => {
|
|
43
|
+
writeCliSpawnTrace(input, `wrapper.child.${stream}.data`, {
|
|
44
|
+
childPid: child.pid,
|
|
45
|
+
bytes: typeof chunk === 'string' ? Buffer.byteLength(chunk) : chunk.length,
|
|
46
|
+
});
|
|
47
|
+
targetStream.write(chunk);
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
const waitForChildClose = async (input, child, onBeforeResolve) => {
|
|
51
|
+
return new Promise((resolve, reject) => {
|
|
52
|
+
let settled = false;
|
|
53
|
+
let childResult = {
|
|
54
|
+
exitCode: null,
|
|
55
|
+
signal: null,
|
|
56
|
+
};
|
|
57
|
+
const finalize = () => {
|
|
58
|
+
if (settled)
|
|
59
|
+
return;
|
|
60
|
+
settled = true;
|
|
61
|
+
onBeforeResolve();
|
|
62
|
+
child.off?.('error', reject);
|
|
63
|
+
child.off?.('exit', handleExit);
|
|
64
|
+
child.off?.('close', handleClose);
|
|
65
|
+
writeCliSpawnTrace(input, 'wrapper.child.finalize', {
|
|
66
|
+
childPid: child.pid,
|
|
67
|
+
exitCode: childResult.exitCode,
|
|
68
|
+
signal: childResult.signal,
|
|
69
|
+
});
|
|
70
|
+
resolve(childResult);
|
|
71
|
+
};
|
|
72
|
+
const handleExit = (exitCode, signal) => {
|
|
73
|
+
childResult = { exitCode, signal };
|
|
74
|
+
};
|
|
75
|
+
const handleClose = (exitCode, signal) => {
|
|
76
|
+
childResult = {
|
|
77
|
+
exitCode: childResult.exitCode ?? exitCode,
|
|
78
|
+
signal: childResult.signal ?? signal,
|
|
79
|
+
};
|
|
80
|
+
finalize();
|
|
81
|
+
};
|
|
82
|
+
child.once('error', reject);
|
|
83
|
+
child.once('exit', handleExit);
|
|
84
|
+
child.once('close', handleClose);
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
const registerSignalHandlers = (input, child) => {
|
|
88
|
+
let childClosed = false;
|
|
89
|
+
let delayedSignalTimer;
|
|
90
|
+
const clearDelayedSignal = () => {
|
|
91
|
+
if (delayedSignalTimer === undefined)
|
|
92
|
+
return;
|
|
93
|
+
clearTimeout(delayedSignalTimer);
|
|
94
|
+
delayedSignalTimer = undefined;
|
|
95
|
+
};
|
|
96
|
+
const forwardSignal = (signal) => {
|
|
97
|
+
if (childClosed)
|
|
98
|
+
return;
|
|
99
|
+
try {
|
|
100
|
+
writeCliSpawnTrace(input, 'wrapper.signal.forward', {
|
|
101
|
+
childPid: child.pid,
|
|
102
|
+
signal,
|
|
103
|
+
});
|
|
104
|
+
child.kill(signal);
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
// best-effort
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
const scheduleSignalForward = (signal) => {
|
|
111
|
+
if (childClosed || delayedSignalTimer !== undefined)
|
|
112
|
+
return;
|
|
113
|
+
delayedSignalTimer = globalThis.setTimeout(() => {
|
|
114
|
+
delayedSignalTimer = undefined;
|
|
115
|
+
writeCliSpawnTrace(input, 'wrapper.signal.delay.fire', {
|
|
116
|
+
childPid: child.pid,
|
|
117
|
+
signal,
|
|
118
|
+
});
|
|
119
|
+
forwardSignal(signal);
|
|
120
|
+
}, 1500);
|
|
121
|
+
writeCliSpawnTrace(input, 'wrapper.signal.delay.schedule', {
|
|
122
|
+
childPid: child.pid,
|
|
123
|
+
signal,
|
|
124
|
+
delayMs: 1500,
|
|
125
|
+
});
|
|
126
|
+
delayedSignalTimer.unref?.();
|
|
127
|
+
};
|
|
128
|
+
const onSigint = () => {
|
|
129
|
+
if (process.stdin.isTTY === true) {
|
|
130
|
+
scheduleSignalForward('SIGINT');
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
forwardSignal('SIGINT');
|
|
134
|
+
};
|
|
135
|
+
const onSigterm = () => {
|
|
136
|
+
if (process.stdin.isTTY === true) {
|
|
137
|
+
scheduleSignalForward('SIGTERM');
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
forwardSignal('SIGTERM');
|
|
141
|
+
};
|
|
142
|
+
process.on('SIGINT', onSigint);
|
|
143
|
+
process.on('SIGTERM', onSigterm);
|
|
144
|
+
return () => {
|
|
145
|
+
childClosed = true;
|
|
146
|
+
clearDelayedSignal();
|
|
147
|
+
process.off('SIGINT', onSigint);
|
|
148
|
+
process.off('SIGTERM', onSigterm);
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
export const runCliWrapper = async (input = {}) => {
|
|
152
|
+
const nodeArgs = resolveNodeArgs();
|
|
153
|
+
const child = spawn(process.execPath, nodeArgs, {
|
|
154
|
+
stdio: ['inherit', 'pipe', 'pipe'],
|
|
155
|
+
env: process.env,
|
|
156
|
+
});
|
|
157
|
+
writeCliSpawnTrace(input, 'wrapper.child.started', {
|
|
158
|
+
childPid: child.pid,
|
|
159
|
+
command: process.execPath,
|
|
160
|
+
args: nodeArgs,
|
|
161
|
+
});
|
|
162
|
+
attachOutputRelay(input, child, 'stdout');
|
|
163
|
+
attachOutputRelay(input, child, 'stderr');
|
|
164
|
+
const unregisterSignalHandlers = registerSignalHandlers(input, child);
|
|
165
|
+
const result = await waitForChildClose(input, child, unregisterSignalHandlers);
|
|
166
|
+
process.exit(getExitCode(result.exitCode, result.signal));
|
|
167
|
+
};
|
package/bin/z.js
CHANGED
|
@@ -3,105 +3,5 @@
|
|
|
3
3
|
* ZinTrust CLI Shortcut - 'z'
|
|
4
4
|
* Mirrors bin/zintrust.ts for convenience
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import { createRequire } from 'node:module';
|
|
9
|
-
import path from 'node:path';
|
|
10
|
-
import { fileURLToPath } from 'node:url';
|
|
11
|
-
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
12
|
-
const require = createRequire(import.meta.url);
|
|
13
|
-
const tsTarget = path.join(here, 'zintrust-main.ts');
|
|
14
|
-
const jsTarget = path.join(here, 'zintrust-main.js');
|
|
15
|
-
const target = existsSync(tsTarget) ? tsTarget : jsTarget;
|
|
16
|
-
const tsxImportPath = require.resolve('tsx');
|
|
17
|
-
const nodeArgs = target.endsWith('.ts')
|
|
18
|
-
? ['--import', tsxImportPath, target, ...process.argv.slice(2)]
|
|
19
|
-
: [target, ...process.argv.slice(2)];
|
|
20
|
-
const child = spawn(process.execPath, nodeArgs, {
|
|
21
|
-
stdio: ['inherit', 'pipe', 'pipe'],
|
|
22
|
-
env: process.env,
|
|
23
|
-
});
|
|
24
|
-
child.stdout?.on('data', (chunk) => {
|
|
25
|
-
process.stdout.write(chunk);
|
|
26
|
-
});
|
|
27
|
-
child.stderr?.on('data', (chunk) => {
|
|
28
|
-
process.stderr.write(chunk);
|
|
29
|
-
});
|
|
30
|
-
let childClosed = false;
|
|
31
|
-
let delayedSignalTimer;
|
|
32
|
-
const clearDelayedSignal = () => {
|
|
33
|
-
if (delayedSignalTimer === undefined)
|
|
34
|
-
return;
|
|
35
|
-
clearTimeout(delayedSignalTimer);
|
|
36
|
-
delayedSignalTimer = undefined;
|
|
37
|
-
};
|
|
38
|
-
const forwardSignal = (signal) => {
|
|
39
|
-
if (childClosed)
|
|
40
|
-
return;
|
|
41
|
-
try {
|
|
42
|
-
child.kill(signal);
|
|
43
|
-
}
|
|
44
|
-
catch {
|
|
45
|
-
// best-effort
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
const scheduleSignalForward = (signal) => {
|
|
49
|
-
if (childClosed || delayedSignalTimer !== undefined)
|
|
50
|
-
return;
|
|
51
|
-
delayedSignalTimer = globalThis.setTimeout(() => {
|
|
52
|
-
delayedSignalTimer = undefined;
|
|
53
|
-
forwardSignal(signal);
|
|
54
|
-
}, 1500);
|
|
55
|
-
delayedSignalTimer.unref?.();
|
|
56
|
-
};
|
|
57
|
-
const onSigint = () => {
|
|
58
|
-
if (process.stdin.isTTY === true) {
|
|
59
|
-
scheduleSignalForward('SIGINT');
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
forwardSignal('SIGINT');
|
|
63
|
-
};
|
|
64
|
-
const onSigterm = () => {
|
|
65
|
-
if (process.stdin.isTTY === true) {
|
|
66
|
-
scheduleSignalForward('SIGTERM');
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
forwardSignal('SIGTERM');
|
|
70
|
-
};
|
|
71
|
-
process.on('SIGINT', onSigint);
|
|
72
|
-
process.on('SIGTERM', onSigterm);
|
|
73
|
-
const result = await new Promise((resolve, reject) => {
|
|
74
|
-
let settled = false;
|
|
75
|
-
let childResult = {
|
|
76
|
-
exitCode: null,
|
|
77
|
-
signal: null,
|
|
78
|
-
};
|
|
79
|
-
const finalize = () => {
|
|
80
|
-
if (settled) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
settled = true;
|
|
84
|
-
childClosed = true;
|
|
85
|
-
clearDelayedSignal();
|
|
86
|
-
process.off('SIGINT', onSigint);
|
|
87
|
-
process.off('SIGTERM', onSigterm);
|
|
88
|
-
child.off?.('error', reject);
|
|
89
|
-
child.off?.('exit', handleExit);
|
|
90
|
-
child.off?.('close', handleClose);
|
|
91
|
-
resolve(childResult);
|
|
92
|
-
};
|
|
93
|
-
const handleExit = (exitCode, signal) => {
|
|
94
|
-
childResult = { exitCode, signal };
|
|
95
|
-
};
|
|
96
|
-
const handleClose = (exitCode, signal) => {
|
|
97
|
-
childResult = {
|
|
98
|
-
exitCode: childResult.exitCode ?? exitCode,
|
|
99
|
-
signal: childResult.signal ?? signal,
|
|
100
|
-
};
|
|
101
|
-
finalize();
|
|
102
|
-
};
|
|
103
|
-
child.once('error', reject);
|
|
104
|
-
child.once('exit', handleExit);
|
|
105
|
-
child.once('close', handleClose);
|
|
106
|
-
});
|
|
107
|
-
process.exit(result.exitCode ?? (result.signal === 'SIGINT' || result.signal === 'SIGTERM' ? 0 : 1));
|
|
6
|
+
import { runCliWrapper } from './launcher.js';
|
|
7
|
+
await runCliWrapper();
|
package/bin/zin.js
CHANGED
|
@@ -3,195 +3,5 @@
|
|
|
3
3
|
* ZinTrust CLI Shortcut - 'zin'
|
|
4
4
|
* Mirrors bin/zintrust.ts for convenience
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import { createRequire } from 'node:module';
|
|
9
|
-
import path from 'node:path';
|
|
10
|
-
import { fileURLToPath } from 'node:url';
|
|
11
|
-
const CLI_SPAWN_TRACE_ENV_KEYS = ['CLI_SPAWN_TRACE', 'ZIN_SPAWN_TRACE'];
|
|
12
|
-
const isCliSpawnTraceEnabled = () => {
|
|
13
|
-
return CLI_SPAWN_TRACE_ENV_KEYS.some((key) => {
|
|
14
|
-
const raw = process.env[key];
|
|
15
|
-
if (typeof raw !== 'string')
|
|
16
|
-
return false;
|
|
17
|
-
const normalized = raw.trim().toLowerCase();
|
|
18
|
-
return (normalized === '1' || normalized === 'true' || normalized === 'yes' || normalized === 'on');
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
const writeCliSpawnTrace = (label, details = {}) => {
|
|
22
|
-
if (!isCliSpawnTraceEnabled())
|
|
23
|
-
return;
|
|
24
|
-
process.stderr.write(`${JSON.stringify({ trace: 'cli-wrapper', label, pid: process.pid, details })}\n`);
|
|
25
|
-
};
|
|
26
|
-
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
27
|
-
const require = createRequire(import.meta.url);
|
|
28
|
-
const tsTarget = path.join(here, 'zintrust-main.ts');
|
|
29
|
-
const jsTarget = path.join(here, 'zintrust-main.js');
|
|
30
|
-
const target = existsSync(tsTarget) ? tsTarget : jsTarget;
|
|
31
|
-
const tsxImportPath = require.resolve('tsx');
|
|
32
|
-
const nodeArgs = target.endsWith('.ts')
|
|
33
|
-
? ['--import', tsxImportPath, target, ...process.argv.slice(2)]
|
|
34
|
-
: [target, ...process.argv.slice(2)];
|
|
35
|
-
const child = spawn(process.execPath, nodeArgs, {
|
|
36
|
-
stdio: ['inherit', 'pipe', 'pipe'],
|
|
37
|
-
env: process.env,
|
|
38
|
-
});
|
|
39
|
-
writeCliSpawnTrace('wrapper.child.started', {
|
|
40
|
-
childPid: child.pid,
|
|
41
|
-
command: process.execPath,
|
|
42
|
-
args: nodeArgs,
|
|
43
|
-
});
|
|
44
|
-
child.stdout?.on('data', (chunk) => {
|
|
45
|
-
writeCliSpawnTrace('wrapper.child.stdout.data', {
|
|
46
|
-
childPid: child.pid,
|
|
47
|
-
bytes: typeof chunk === 'string' ? Buffer.byteLength(chunk) : chunk.length,
|
|
48
|
-
});
|
|
49
|
-
process.stdout.write(chunk);
|
|
50
|
-
});
|
|
51
|
-
child.stdout?.on('end', () => {
|
|
52
|
-
writeCliSpawnTrace('wrapper.child.stdout.end', {
|
|
53
|
-
childPid: child.pid,
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
child.stdout?.on('close', () => {
|
|
57
|
-
writeCliSpawnTrace('wrapper.child.stdout.close', {
|
|
58
|
-
childPid: child.pid,
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
child.stderr?.on('data', (chunk) => {
|
|
62
|
-
writeCliSpawnTrace('wrapper.child.stderr.data', {
|
|
63
|
-
childPid: child.pid,
|
|
64
|
-
bytes: typeof chunk === 'string' ? Buffer.byteLength(chunk) : chunk.length,
|
|
65
|
-
});
|
|
66
|
-
process.stderr.write(chunk);
|
|
67
|
-
});
|
|
68
|
-
child.stderr?.on('end', () => {
|
|
69
|
-
writeCliSpawnTrace('wrapper.child.stderr.end', {
|
|
70
|
-
childPid: child.pid,
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
child.stderr?.on('close', () => {
|
|
74
|
-
writeCliSpawnTrace('wrapper.child.stderr.close', {
|
|
75
|
-
childPid: child.pid,
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
let childClosed = false;
|
|
79
|
-
let delayedSignalTimer;
|
|
80
|
-
const clearDelayedSignal = () => {
|
|
81
|
-
if (delayedSignalTimer === undefined)
|
|
82
|
-
return;
|
|
83
|
-
clearTimeout(delayedSignalTimer);
|
|
84
|
-
delayedSignalTimer = undefined;
|
|
85
|
-
};
|
|
86
|
-
const forwardSignal = (signal) => {
|
|
87
|
-
if (childClosed)
|
|
88
|
-
return;
|
|
89
|
-
try {
|
|
90
|
-
writeCliSpawnTrace('wrapper.signal.forward.attempt', {
|
|
91
|
-
childPid: child.pid,
|
|
92
|
-
signal,
|
|
93
|
-
});
|
|
94
|
-
child.kill(signal);
|
|
95
|
-
writeCliSpawnTrace('wrapper.signal.forward.complete', {
|
|
96
|
-
childPid: child.pid,
|
|
97
|
-
signal,
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
catch {
|
|
101
|
-
// best-effort
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
const scheduleSignalForward = (signal) => {
|
|
105
|
-
if (childClosed || delayedSignalTimer !== undefined)
|
|
106
|
-
return;
|
|
107
|
-
delayedSignalTimer = globalThis.setTimeout(() => {
|
|
108
|
-
delayedSignalTimer = undefined;
|
|
109
|
-
writeCliSpawnTrace('wrapper.signal.delay.fire', {
|
|
110
|
-
childPid: child.pid,
|
|
111
|
-
signal,
|
|
112
|
-
});
|
|
113
|
-
forwardSignal(signal);
|
|
114
|
-
}, 1500);
|
|
115
|
-
writeCliSpawnTrace('wrapper.signal.delay.schedule', {
|
|
116
|
-
childPid: child.pid,
|
|
117
|
-
signal,
|
|
118
|
-
delayMs: 1500,
|
|
119
|
-
});
|
|
120
|
-
delayedSignalTimer.unref?.();
|
|
121
|
-
};
|
|
122
|
-
const onSigint = () => {
|
|
123
|
-
writeCliSpawnTrace('wrapper.signal.received', {
|
|
124
|
-
childPid: child.pid,
|
|
125
|
-
signal: 'SIGINT',
|
|
126
|
-
tty: process.stdin.isTTY === true,
|
|
127
|
-
});
|
|
128
|
-
if (process.stdin.isTTY === true) {
|
|
129
|
-
scheduleSignalForward('SIGINT');
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
forwardSignal('SIGINT');
|
|
133
|
-
};
|
|
134
|
-
const onSigterm = () => {
|
|
135
|
-
writeCliSpawnTrace('wrapper.signal.received', {
|
|
136
|
-
childPid: child.pid,
|
|
137
|
-
signal: 'SIGTERM',
|
|
138
|
-
tty: process.stdin.isTTY === true,
|
|
139
|
-
});
|
|
140
|
-
if (process.stdin.isTTY === true) {
|
|
141
|
-
scheduleSignalForward('SIGTERM');
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
forwardSignal('SIGTERM');
|
|
145
|
-
};
|
|
146
|
-
process.on('SIGINT', onSigint);
|
|
147
|
-
process.on('SIGTERM', onSigterm);
|
|
148
|
-
const result = await new Promise((resolve, reject) => {
|
|
149
|
-
let settled = false;
|
|
150
|
-
let childResult = {
|
|
151
|
-
exitCode: null,
|
|
152
|
-
signal: null,
|
|
153
|
-
};
|
|
154
|
-
const finalize = () => {
|
|
155
|
-
if (settled) {
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
settled = true;
|
|
159
|
-
writeCliSpawnTrace('wrapper.child.finalize', {
|
|
160
|
-
childPid: child.pid,
|
|
161
|
-
exitCode: childResult.exitCode,
|
|
162
|
-
signal: childResult.signal,
|
|
163
|
-
});
|
|
164
|
-
childClosed = true;
|
|
165
|
-
clearDelayedSignal();
|
|
166
|
-
process.off('SIGINT', onSigint);
|
|
167
|
-
process.off('SIGTERM', onSigterm);
|
|
168
|
-
child.off?.('error', reject);
|
|
169
|
-
child.off?.('exit', handleExit);
|
|
170
|
-
child.off?.('close', handleClose);
|
|
171
|
-
resolve(childResult);
|
|
172
|
-
};
|
|
173
|
-
const handleExit = (exitCode, signal) => {
|
|
174
|
-
writeCliSpawnTrace('wrapper.child.exit', {
|
|
175
|
-
childPid: child.pid,
|
|
176
|
-
exitCode,
|
|
177
|
-
signal,
|
|
178
|
-
});
|
|
179
|
-
childResult = { exitCode, signal };
|
|
180
|
-
};
|
|
181
|
-
const handleClose = (exitCode, signal) => {
|
|
182
|
-
writeCliSpawnTrace('wrapper.child.close', {
|
|
183
|
-
childPid: child.pid,
|
|
184
|
-
exitCode,
|
|
185
|
-
signal,
|
|
186
|
-
});
|
|
187
|
-
childResult = {
|
|
188
|
-
exitCode: childResult.exitCode ?? exitCode,
|
|
189
|
-
signal: childResult.signal ?? signal,
|
|
190
|
-
};
|
|
191
|
-
finalize();
|
|
192
|
-
};
|
|
193
|
-
child.once('error', reject);
|
|
194
|
-
child.once('exit', handleExit);
|
|
195
|
-
child.once('close', handleClose);
|
|
196
|
-
});
|
|
197
|
-
process.exit(result.exitCode ?? (result.signal === 'SIGINT' || result.signal === 'SIGTERM' ? 0 : 1));
|
|
6
|
+
import { runCliWrapper } from './launcher.js';
|
|
7
|
+
await runCliWrapper({ traceName: 'cli-wrapper' });
|
package/bin/zintrust.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* This bin script is a thin wrapper around the hashbang-free implementation in
|
|
6
6
|
* bin/zintrust-main.ts. Keeping the implementation hashbang-free allows other
|
|
7
|
-
* shortcuts (zin/z/zt) to
|
|
7
|
+
* shortcuts (zin/z/zt) to reuse the same launcher behavior.
|
|
8
8
|
*/
|
|
9
9
|
export {};
|
|
10
10
|
//# sourceMappingURL=zintrust.d.ts.map
|
package/bin/zintrust.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zintrust.d.ts","sourceRoot":"","sources":["../../bin/zintrust.ts"],"names":[],"mappings":";AAEA;;;;;;GAMG
|
|
1
|
+
{"version":3,"file":"zintrust.d.ts","sourceRoot":"","sources":["../../bin/zintrust.ts"],"names":[],"mappings":";AAEA;;;;;;GAMG"}
|
package/bin/zintrust.js
CHANGED
|
@@ -4,107 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* This bin script is a thin wrapper around the hashbang-free implementation in
|
|
6
6
|
* bin/zintrust-main.ts. Keeping the implementation hashbang-free allows other
|
|
7
|
-
* shortcuts (zin/z/zt) to
|
|
7
|
+
* shortcuts (zin/z/zt) to reuse the same launcher behavior.
|
|
8
8
|
*/
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
import { createRequire } from 'node:module';
|
|
12
|
-
import path from 'node:path';
|
|
13
|
-
import { fileURLToPath } from 'node:url';
|
|
14
|
-
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
15
|
-
const require = createRequire(import.meta.url);
|
|
16
|
-
const tsTarget = path.join(here, 'zintrust-main.ts');
|
|
17
|
-
const jsTarget = path.join(here, 'zintrust-main.js');
|
|
18
|
-
const target = existsSync(tsTarget) ? tsTarget : jsTarget;
|
|
19
|
-
const tsxImportPath = require.resolve('tsx');
|
|
20
|
-
const nodeArgs = target.endsWith('.ts')
|
|
21
|
-
? ['--import', tsxImportPath, target, ...process.argv.slice(2)]
|
|
22
|
-
: [target, ...process.argv.slice(2)];
|
|
23
|
-
const child = spawn(process.execPath, nodeArgs, {
|
|
24
|
-
stdio: ['inherit', 'pipe', 'pipe'],
|
|
25
|
-
env: process.env,
|
|
26
|
-
});
|
|
27
|
-
child.stdout?.on('data', (chunk) => {
|
|
28
|
-
process.stdout.write(chunk);
|
|
29
|
-
});
|
|
30
|
-
child.stderr?.on('data', (chunk) => {
|
|
31
|
-
process.stderr.write(chunk);
|
|
32
|
-
});
|
|
33
|
-
let childClosed = false;
|
|
34
|
-
let delayedSignalTimer;
|
|
35
|
-
const clearDelayedSignal = () => {
|
|
36
|
-
if (delayedSignalTimer === undefined)
|
|
37
|
-
return;
|
|
38
|
-
clearTimeout(delayedSignalTimer);
|
|
39
|
-
delayedSignalTimer = undefined;
|
|
40
|
-
};
|
|
41
|
-
const forwardSignal = (signal) => {
|
|
42
|
-
if (childClosed)
|
|
43
|
-
return;
|
|
44
|
-
try {
|
|
45
|
-
child.kill(signal);
|
|
46
|
-
}
|
|
47
|
-
catch {
|
|
48
|
-
// best-effort
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
const scheduleSignalForward = (signal) => {
|
|
52
|
-
if (childClosed || delayedSignalTimer !== undefined)
|
|
53
|
-
return;
|
|
54
|
-
delayedSignalTimer = globalThis.setTimeout(() => {
|
|
55
|
-
delayedSignalTimer = undefined;
|
|
56
|
-
forwardSignal(signal);
|
|
57
|
-
}, 1500);
|
|
58
|
-
delayedSignalTimer.unref?.();
|
|
59
|
-
};
|
|
60
|
-
const onSigint = () => {
|
|
61
|
-
if (process.stdin.isTTY === true) {
|
|
62
|
-
scheduleSignalForward('SIGINT');
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
forwardSignal('SIGINT');
|
|
66
|
-
};
|
|
67
|
-
const onSigterm = () => {
|
|
68
|
-
if (process.stdin.isTTY === true) {
|
|
69
|
-
scheduleSignalForward('SIGTERM');
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
forwardSignal('SIGTERM');
|
|
73
|
-
};
|
|
74
|
-
process.on('SIGINT', onSigint);
|
|
75
|
-
process.on('SIGTERM', onSigterm);
|
|
76
|
-
const result = await new Promise((resolve, reject) => {
|
|
77
|
-
let settled = false;
|
|
78
|
-
let childResult = {
|
|
79
|
-
exitCode: null,
|
|
80
|
-
signal: null,
|
|
81
|
-
};
|
|
82
|
-
const finalize = () => {
|
|
83
|
-
if (settled) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
settled = true;
|
|
87
|
-
childClosed = true;
|
|
88
|
-
clearDelayedSignal();
|
|
89
|
-
process.off('SIGINT', onSigint);
|
|
90
|
-
process.off('SIGTERM', onSigterm);
|
|
91
|
-
child.off?.('error', reject);
|
|
92
|
-
child.off?.('exit', handleExit);
|
|
93
|
-
child.off?.('close', handleClose);
|
|
94
|
-
resolve(childResult);
|
|
95
|
-
};
|
|
96
|
-
const handleExit = (exitCode, signal) => {
|
|
97
|
-
childResult = { exitCode, signal };
|
|
98
|
-
};
|
|
99
|
-
const handleClose = (exitCode, signal) => {
|
|
100
|
-
childResult = {
|
|
101
|
-
exitCode: childResult.exitCode ?? exitCode,
|
|
102
|
-
signal: childResult.signal ?? signal,
|
|
103
|
-
};
|
|
104
|
-
finalize();
|
|
105
|
-
};
|
|
106
|
-
child.once('error', reject);
|
|
107
|
-
child.once('exit', handleExit);
|
|
108
|
-
child.once('close', handleClose);
|
|
109
|
-
});
|
|
110
|
-
process.exit(result.exitCode ?? (result.signal === 'SIGINT' || result.signal === 'SIGTERM' ? 0 : 1));
|
|
9
|
+
import { runCliWrapper } from './launcher.js';
|
|
10
|
+
await runCliWrapper();
|
package/bin/zt.d.ts
CHANGED
package/bin/zt.js
CHANGED
|
@@ -1,104 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* ZinTrust CLI Shortcut - '
|
|
3
|
+
* ZinTrust CLI Shortcut - 'zt'
|
|
4
4
|
* Mirrors bin/zintrust.ts for convenience
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import path from 'node:path';
|
|
9
|
-
import { fileURLToPath } from 'node:url';
|
|
10
|
-
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
11
|
-
const tsTarget = path.join(here, 'zintrust-main.ts');
|
|
12
|
-
const jsTarget = path.join(here, 'zintrust-main.js');
|
|
13
|
-
const target = existsSync(tsTarget) ? tsTarget : jsTarget;
|
|
14
|
-
const nodeArgs = target.endsWith('.ts')
|
|
15
|
-
? ['--import', 'tsx', target, ...process.argv.slice(2)]
|
|
16
|
-
: [target, ...process.argv.slice(2)];
|
|
17
|
-
const child = spawn(process.execPath, nodeArgs, {
|
|
18
|
-
stdio: ['inherit', 'pipe', 'pipe'],
|
|
19
|
-
env: process.env,
|
|
20
|
-
});
|
|
21
|
-
child.stdout?.on('data', (chunk) => {
|
|
22
|
-
process.stdout.write(chunk);
|
|
23
|
-
});
|
|
24
|
-
child.stderr?.on('data', (chunk) => {
|
|
25
|
-
process.stderr.write(chunk);
|
|
26
|
-
});
|
|
27
|
-
let childClosed = false;
|
|
28
|
-
let delayedSignalTimer;
|
|
29
|
-
const clearDelayedSignal = () => {
|
|
30
|
-
if (delayedSignalTimer === undefined)
|
|
31
|
-
return;
|
|
32
|
-
clearTimeout(delayedSignalTimer);
|
|
33
|
-
delayedSignalTimer = undefined;
|
|
34
|
-
};
|
|
35
|
-
const forwardSignal = (signal) => {
|
|
36
|
-
if (childClosed)
|
|
37
|
-
return;
|
|
38
|
-
try {
|
|
39
|
-
child.kill(signal);
|
|
40
|
-
}
|
|
41
|
-
catch {
|
|
42
|
-
// best-effort
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
const scheduleSignalForward = (signal) => {
|
|
46
|
-
if (childClosed || delayedSignalTimer !== undefined)
|
|
47
|
-
return;
|
|
48
|
-
delayedSignalTimer = globalThis.setTimeout(() => {
|
|
49
|
-
delayedSignalTimer = undefined;
|
|
50
|
-
forwardSignal(signal);
|
|
51
|
-
}, 1500);
|
|
52
|
-
delayedSignalTimer.unref?.();
|
|
53
|
-
};
|
|
54
|
-
const onSigint = () => {
|
|
55
|
-
if (process.stdin.isTTY === true) {
|
|
56
|
-
scheduleSignalForward('SIGINT');
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
forwardSignal('SIGINT');
|
|
60
|
-
};
|
|
61
|
-
const onSigterm = () => {
|
|
62
|
-
if (process.stdin.isTTY === true) {
|
|
63
|
-
scheduleSignalForward('SIGTERM');
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
forwardSignal('SIGTERM');
|
|
67
|
-
};
|
|
68
|
-
process.on('SIGINT', onSigint);
|
|
69
|
-
process.on('SIGTERM', onSigterm);
|
|
70
|
-
const result = await new Promise((resolve, reject) => {
|
|
71
|
-
let settled = false;
|
|
72
|
-
let childResult = {
|
|
73
|
-
exitCode: null,
|
|
74
|
-
signal: null,
|
|
75
|
-
};
|
|
76
|
-
const finalize = () => {
|
|
77
|
-
if (settled) {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
settled = true;
|
|
81
|
-
childClosed = true;
|
|
82
|
-
clearDelayedSignal();
|
|
83
|
-
process.off('SIGINT', onSigint);
|
|
84
|
-
process.off('SIGTERM', onSigterm);
|
|
85
|
-
child.off?.('error', reject);
|
|
86
|
-
child.off?.('exit', handleExit);
|
|
87
|
-
child.off?.('close', handleClose);
|
|
88
|
-
resolve(childResult);
|
|
89
|
-
};
|
|
90
|
-
const handleExit = (exitCode, signal) => {
|
|
91
|
-
childResult = { exitCode, signal };
|
|
92
|
-
};
|
|
93
|
-
const handleClose = (exitCode, signal) => {
|
|
94
|
-
childResult = {
|
|
95
|
-
exitCode: childResult.exitCode ?? exitCode,
|
|
96
|
-
signal: childResult.signal ?? signal,
|
|
97
|
-
};
|
|
98
|
-
finalize();
|
|
99
|
-
};
|
|
100
|
-
child.once('error', reject);
|
|
101
|
-
child.once('exit', handleExit);
|
|
102
|
-
child.once('close', handleClose);
|
|
103
|
-
});
|
|
104
|
-
process.exit(result.exitCode ?? (result.signal === 'SIGINT' || result.signal === 'SIGTERM' ? 0 : 1));
|
|
6
|
+
import { runCliWrapper } from './launcher.js';
|
|
7
|
+
await runCliWrapper();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zintrust/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "Production-grade TypeScript backend framework for JavaScript",
|
|
5
5
|
"homepage": "https://zintrust.com",
|
|
6
6
|
"repository": {
|
|
@@ -57,14 +57,14 @@
|
|
|
57
57
|
"./package.json": "./package.json"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@cloudflare/containers": "^0.3.
|
|
60
|
+
"@cloudflare/containers": "^0.3.3",
|
|
61
61
|
"bcryptjs": "^3.0.3",
|
|
62
|
-
"bullmq": "^5.76.
|
|
62
|
+
"bullmq": "^5.76.4",
|
|
63
63
|
"chalk": "^5.6.2",
|
|
64
64
|
"commander": "^14.0.3",
|
|
65
|
-
"inquirer": "^13.4.
|
|
65
|
+
"inquirer": "^13.4.2",
|
|
66
66
|
"jsonwebtoken": "^9.0.3",
|
|
67
|
-
"mysql2": "^3.22.
|
|
67
|
+
"mysql2": "^3.22.3",
|
|
68
68
|
"pg": "^8.20.0",
|
|
69
69
|
"tsx": "^4.21.0"
|
|
70
70
|
},
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import type { IShutdownManager } from './type';
|
|
2
2
|
import type { IRouter } from '../../index.js';
|
|
3
3
|
export declare const registerFrameworkShutdownHooks: (shutdownManager: IShutdownManager) => void;
|
|
4
|
-
|
|
4
|
+
type LifecycleParams = {
|
|
5
5
|
environment: string;
|
|
6
6
|
resolvedBasePath: string;
|
|
7
7
|
router: IRouter;
|
|
8
8
|
shutdownManager: IShutdownManager;
|
|
9
9
|
getBooted: () => boolean;
|
|
10
10
|
setBooted: (value: boolean) => void;
|
|
11
|
-
}
|
|
11
|
+
};
|
|
12
|
+
export declare const createLifecycle: (params: LifecycleParams) => {
|
|
12
13
|
boot: () => Promise<void>;
|
|
13
14
|
shutdown: () => Promise<void>;
|
|
14
15
|
};
|
|
16
|
+
export {};
|
|
15
17
|
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../../src/boot/registry/runtime.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAUvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAkQ9C,eAAO,MAAM,8BAA8B,GAAI,iBAAiB,gBAAgB,KAAG,IA6BlF,CAAC;
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../../src/boot/registry/runtime.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAUvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAkQ9C,eAAO,MAAM,8BAA8B,GAAI,iBAAiB,gBAAgB,KAAG,IA6BlF,CAAC;AAyVF,KAAK,eAAe,GAAG;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;IACzB,MAAM,EAAE,OAAO,CAAC;IAChB,eAAe,EAAE,gBAAgB,CAAC;IAClC,SAAS,EAAE,MAAM,OAAO,CAAC;IACzB,SAAS,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CACrC,CAAC;AA4HF,eAAO,MAAM,eAAe,GAC1B,QAAQ,eAAe,KACtB;IAAE,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAAC,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAK5D,CAAC"}
|
|
@@ -411,6 +411,12 @@ const isTraceDashboardAutoMountEnabled = () => {
|
|
|
411
411
|
const raw = readEnvString('TRACE_AUTO_MOUNT').trim().toLowerCase();
|
|
412
412
|
return raw === '1' || raw === 'true';
|
|
413
413
|
};
|
|
414
|
+
const isTraceProxySenderEnabled = () => {
|
|
415
|
+
const proxyEnabled = readEnvString('TRACE_PROXY').trim().toLowerCase();
|
|
416
|
+
if (proxyEnabled !== '1' && proxyEnabled !== 'true')
|
|
417
|
+
return false;
|
|
418
|
+
return readEnvString('TRACE_PROXY_URL').trim() !== '';
|
|
419
|
+
};
|
|
414
420
|
const resolveTraceDashboardBasePath = () => {
|
|
415
421
|
const raw = readEnvString('TRACE_BASE_PATH').trim();
|
|
416
422
|
if (raw === '')
|
|
@@ -447,6 +453,9 @@ const initializeSystemTrace = async (router) => {
|
|
|
447
453
|
return;
|
|
448
454
|
}
|
|
449
455
|
if (!isTraceDashboardAutoMountEnabled()) {
|
|
456
|
+
if (isTraceProxySenderEnabled()) {
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
450
459
|
Logger.info('System Trace runtime activated. Set TRACE_AUTO_MOUNT=true or register dashboard routes manually if needed.');
|
|
451
460
|
return;
|
|
452
461
|
}
|
|
@@ -495,8 +504,34 @@ const initializeSockets = (router) => {
|
|
|
495
504
|
Logger.info(`Transport: ${diagnostics.transport}`);
|
|
496
505
|
Logger.info(`Path: ${diagnostics.path}`);
|
|
497
506
|
};
|
|
498
|
-
|
|
499
|
-
|
|
507
|
+
const initializeRuntimeRoutes = async (params) => {
|
|
508
|
+
await initializeArtifactDirectories(params.resolvedBasePath);
|
|
509
|
+
await registerMasterRoutes(params.resolvedBasePath, params.router);
|
|
510
|
+
initializeSockets(params.router);
|
|
511
|
+
await initializeSystemTrace(params.router);
|
|
512
|
+
if (Cloudflare.getWorkersEnv() === null && appConfig.dockerWorker === false) {
|
|
513
|
+
if (appConfig.worker === true) {
|
|
514
|
+
await initializeWorkers(params.router);
|
|
515
|
+
}
|
|
516
|
+
else {
|
|
517
|
+
Logger.info('Skipping worker route registration (WORKER_ENABLED=false).');
|
|
518
|
+
}
|
|
519
|
+
await initializeQueueMonitor(params.router);
|
|
520
|
+
if (appConfig.worker === true) {
|
|
521
|
+
await initializeQueueHttpGateway(params.router);
|
|
522
|
+
await initializeScheduleHttpGateway(params.router);
|
|
523
|
+
}
|
|
524
|
+
else {
|
|
525
|
+
Logger.info('Skipping worker execution/gateway initialization (WORKER_ENABLED=false).');
|
|
526
|
+
}
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
if (!appConfig.dockerWorker) {
|
|
530
|
+
Logger.info('Skipping local worker dashboards in Cloudflare Workers runtime.');
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
const createBootLifecycle = (params) => {
|
|
534
|
+
return async () => {
|
|
500
535
|
if (params.getBooted())
|
|
501
536
|
return;
|
|
502
537
|
Logger.info(`🚀 Booting ZinTrust Application in ${params.environment} mode...`);
|
|
@@ -515,7 +550,6 @@ export const createLifecycle = (params) => {
|
|
|
515
550
|
warnings: startupConfigValidation.warnings,
|
|
516
551
|
});
|
|
517
552
|
}
|
|
518
|
-
// Preload project-owned config overrides that must be available synchronously.
|
|
519
553
|
await StartupConfigFileRegistry.preload([
|
|
520
554
|
StartupConfigFile.Middleware,
|
|
521
555
|
StartupConfigFile.Cache,
|
|
@@ -529,35 +563,13 @@ export const createLifecycle = (params) => {
|
|
|
529
563
|
FeatureFlags.initialize();
|
|
530
564
|
await StartupHealthChecks.assertHealthy();
|
|
531
565
|
await registerFromRuntimeConfig();
|
|
532
|
-
await
|
|
533
|
-
await registerMasterRoutes(params.resolvedBasePath, params.router);
|
|
534
|
-
initializeSockets(params.router);
|
|
535
|
-
await initializeSystemTrace(params.router);
|
|
536
|
-
if (Cloudflare.getWorkersEnv() === null && appConfig.dockerWorker === false) {
|
|
537
|
-
if (appConfig.worker === true) {
|
|
538
|
-
await initializeWorkers(params.router);
|
|
539
|
-
}
|
|
540
|
-
else {
|
|
541
|
-
Logger.info('Skipping worker route registration (WORKER_ENABLED=false).');
|
|
542
|
-
}
|
|
543
|
-
await initializeQueueMonitor(params.router);
|
|
544
|
-
if (appConfig.worker === true) {
|
|
545
|
-
await initializeQueueHttpGateway(params.router);
|
|
546
|
-
await initializeScheduleHttpGateway(params.router);
|
|
547
|
-
}
|
|
548
|
-
else {
|
|
549
|
-
Logger.info('Skipping worker execution/gateway initialization (WORKER_ENABLED=false).');
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
else if (!appConfig.dockerWorker) {
|
|
553
|
-
Logger.info('Skipping local worker dashboards in Cloudflare Workers runtime.');
|
|
554
|
-
}
|
|
555
|
-
// Register service providers
|
|
556
|
-
// Bootstrap services
|
|
566
|
+
await initializeRuntimeRoutes(params);
|
|
557
567
|
Logger.info('✅ Application booted successfully');
|
|
558
568
|
params.setBooted(true);
|
|
559
569
|
};
|
|
560
|
-
|
|
570
|
+
};
|
|
571
|
+
const createShutdownLifecycle = (params) => {
|
|
572
|
+
return async () => {
|
|
561
573
|
Logger.info('🛑 Shutting down application...');
|
|
562
574
|
ShutdownTrace.logHandles('runtime.lifecycle.shutdown.start');
|
|
563
575
|
QueueReliabilityOrchestrator.stop();
|
|
@@ -588,7 +600,6 @@ export const createLifecycle = (params) => {
|
|
|
588
600
|
error: error instanceof Error ? error.message : String(error),
|
|
589
601
|
});
|
|
590
602
|
}
|
|
591
|
-
// Ensure FileLogWriter.flush is attempted even if dynamic registration failed.
|
|
592
603
|
try {
|
|
593
604
|
const fileLogWriter = await tryImportOptional('@config/FileLogWriter');
|
|
594
605
|
fileLogWriter?.FileLogWriter?.flush?.();
|
|
@@ -599,5 +610,9 @@ export const createLifecycle = (params) => {
|
|
|
599
610
|
params.setBooted(false);
|
|
600
611
|
ShutdownTrace.logHandles('runtime.lifecycle.shutdown.complete');
|
|
601
612
|
};
|
|
613
|
+
};
|
|
614
|
+
export const createLifecycle = (params) => {
|
|
615
|
+
const boot = createBootLifecycle(params);
|
|
616
|
+
const shutdown = createShutdownLifecycle(params);
|
|
602
617
|
return { boot, shutdown };
|
|
603
618
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CloudflareWranglerDevEnv.d.ts","sourceRoot":"","sources":["../../../../src/cli/cloudflare/CloudflareWranglerDevEnv.ts"],"names":[],"mappings":"AAUA,KAAK,kBAAkB,GAAG;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IAC/B,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,mCAAmC,GAAG;IAChD,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChC,CAAC;
|
|
1
|
+
{"version":3,"file":"CloudflareWranglerDevEnv.d.ts","sourceRoot":"","sources":["../../../../src/cli/cloudflare/CloudflareWranglerDevEnv.ts"],"names":[],"mappings":"AAUA,KAAK,kBAAkB,GAAG;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IAC/B,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,mCAAmC,GAAG;IAChD,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChC,CAAC;AA+KF,eAAO,MAAM,0BAA0B,GACrC,MAAM,kBAAkB,KACvB,OAAO,CAAC,mCAAmC,CAmB7C,CAAC;AAEF,eAAO,MAAM,2BAA2B,GAAU,CAAC,EACjD,MAAM,kBAAkB,EACxB,IAAI,MAAM,OAAO,CAAC,CAAC,CAAC,KACnB,OAAO,CAAC,CAAC,CAkCX,CAAC;;uCA3DM,kBAAkB,KACvB,OAAO,CAAC,mCAAmC,CAAC;kCAqBG,CAAC,QAC3C,kBAAkB,MACpB,MAAM,OAAO,CAAC,CAAC,CAAC,KACnB,OAAO,CAAC,CAAC,CAAC;;AAoCb,wBAGG"}
|
|
@@ -70,6 +70,24 @@ const resolveRuntimeEnvMap = (runtimeEnv) => {
|
|
|
70
70
|
return typeof entry[1] === 'string';
|
|
71
71
|
}));
|
|
72
72
|
};
|
|
73
|
+
const isTruthyEnvValue = (value) => {
|
|
74
|
+
if (!isNonEmptyString(value))
|
|
75
|
+
return false;
|
|
76
|
+
const normalized = value.trim().toLowerCase();
|
|
77
|
+
return normalized === '1' || normalized === 'true' || normalized === 'yes' || normalized === 'on';
|
|
78
|
+
};
|
|
79
|
+
const shouldUseEnvFileDirectly = async (args) => {
|
|
80
|
+
const runtimeEnv = resolveRuntimeEnvMap(args.runtimeEnv ?? process.env);
|
|
81
|
+
if (isTruthyEnvValue(runtimeEnv['USE_ENV'])) {
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
const envPath = isNonEmptyString(args.envPath) ? args.envPath.trim() : '.env';
|
|
85
|
+
const envFileValues = await EnvFile.read({
|
|
86
|
+
cwd: args.projectRoot,
|
|
87
|
+
path: envPath,
|
|
88
|
+
});
|
|
89
|
+
return isTruthyEnvValue(envFileValues['USE_ENV']);
|
|
90
|
+
};
|
|
73
91
|
const resolveSelectedKeys = (args) => {
|
|
74
92
|
const zintrustConfigPath = path.join(args.projectRoot, '.zintrust.json');
|
|
75
93
|
if (!existsSync(zintrustConfigPath)) {
|
|
@@ -136,6 +154,9 @@ export const materializeWranglerDevVars = async (args) => {
|
|
|
136
154
|
};
|
|
137
155
|
};
|
|
138
156
|
export const withWranglerDevVarsSnapshot = async (args, fn) => {
|
|
157
|
+
if (await shouldUseEnvFileDirectly(args)) {
|
|
158
|
+
return fn();
|
|
159
|
+
}
|
|
139
160
|
const targetPath = path.join(args.cwd, getWranglerDevVarsFileName(args.envName));
|
|
140
161
|
const backupPath = getWranglerDevVarsBackupPath(targetPath);
|
|
141
162
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../../../src/cli/scaffolding/env.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../../../src/cli/scaffolding/env.ts"],"names":[],"mappings":"AAqiBA,eAAO,MAAM,OAAO,GAClB,MAAM,MAAM,EACZ,MAAM,MAAM,EACZ,SAAS,MAAM,EACf,QAAQ,MAAM,EACd,oBAAoB,MAAM,EAC1B,SAAS,MAAM,EAAE,EACjB,cAAc,MAAM,KACnB,MAAM,EAWR,CAAC"}
|
|
@@ -26,6 +26,8 @@ const HeaderAndApp = (name, port, baseUrl, appKey) => [
|
|
|
26
26
|
'',
|
|
27
27
|
'# Cloudflare Workers (TCP sockets) — set true if using TCP adapters on Workers.',
|
|
28
28
|
'ENABLE_CLOUDFLARE_SOCKETS=false',
|
|
29
|
+
'# When true, Wrangler reads .env directly and ZinTrust will not materialize .dev.vars files.',
|
|
30
|
+
'USE_ENV=false',
|
|
29
31
|
'',
|
|
30
32
|
'# CLI / tooling',
|
|
31
33
|
'ZINTRUST_RUN_FROM_SOURCE=0',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ShutdownTrace.d.ts","sourceRoot":"","sources":["../../../src/helper/ShutdownTrace.ts"],"names":[],"mappings":"AAKA,KAAK,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"ShutdownTrace.d.ts","sourceRoot":"","sources":["../../../src/helper/ShutdownTrace.ts"],"names":[],"mappings":"AAKA,KAAK,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAoLpD,eAAO,MAAM,aAAa;qBAnKJ,OAAO;iBAwFT,MAAM,YAAW,oBAAoB,KAAQ,IAAI;wBAY1C,MAAM,YAAW,oBAAoB,KAAQ,IAAI;6BA8BnE,MAAM,UACL,OAAO,YACN,oBAAoB,KAC5B,IAAI;EAmCL,CAAC"}
|
|
@@ -4,16 +4,12 @@ const writeLine = (line) => {
|
|
|
4
4
|
const nodeProcess = getNodeProcess();
|
|
5
5
|
if (nodeProcess?.stderr && typeof nodeProcess.stderr.write === 'function') {
|
|
6
6
|
nodeProcess.stderr.write(`${line}\n`);
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
if (typeof console !== 'undefined' && typeof console.info === 'function') {
|
|
10
|
-
console.info(line);
|
|
11
7
|
}
|
|
12
8
|
};
|
|
13
9
|
const getNodeProcess = () => {
|
|
14
10
|
if (typeof process === 'undefined')
|
|
15
11
|
return null;
|
|
16
|
-
return process;
|
|
12
|
+
return process; // NOSONAR
|
|
17
13
|
};
|
|
18
14
|
const isEnabled = () => {
|
|
19
15
|
const nodeProcess = getNodeProcess();
|
|
@@ -99,20 +95,7 @@ const log = (label, details = {}) => {
|
|
|
99
95
|
const logHandles = (label, details = {}) => {
|
|
100
96
|
if (!isEnabled())
|
|
101
97
|
return;
|
|
102
|
-
const nodeProcess = getNodeProcess();
|
|
103
|
-
if (nodeProcess === null) {
|
|
104
|
-
writeLine(JSON.stringify({
|
|
105
|
-
level: 'info',
|
|
106
|
-
trace: 'shutdown',
|
|
107
|
-
label,
|
|
108
|
-
details: {
|
|
109
|
-
...details,
|
|
110
|
-
available: false,
|
|
111
|
-
reason: 'process unavailable',
|
|
112
|
-
},
|
|
113
|
-
}));
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
98
|
+
const nodeProcess = getNodeProcess(); //NOSONAR
|
|
116
99
|
const handles = typeof nodeProcess._getActiveHandles === 'function' ? nodeProcess._getActiveHandles() : [];
|
|
117
100
|
const requests = typeof nodeProcess._getActiveRequests === 'function' ? nodeProcess._getActiveRequests() : [];
|
|
118
101
|
writeLine(JSON.stringify({
|
package/src/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @zintrust/core v1.
|
|
2
|
+
* @zintrust/core v1.6.1
|
|
3
3
|
*
|
|
4
4
|
* ZinTrust Framework - Production-Grade TypeScript Backend
|
|
5
5
|
* Built for performance, type safety, and exceptional developer experience
|
|
6
6
|
*
|
|
7
7
|
* Build Information:
|
|
8
|
-
* Built: 2026-04-
|
|
8
|
+
* Built: 2026-04-30T12:31:49.571Z
|
|
9
9
|
* Node: >=20.0.0
|
|
10
10
|
* License: MIT
|
|
11
11
|
*
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* Available at runtime for debugging and health checks
|
|
22
22
|
*/
|
|
23
23
|
export const ZINTRUST_VERSION = '0.1.41';
|
|
24
|
-
export const ZINTRUST_BUILD_DATE = '2026-04-
|
|
24
|
+
export const ZINTRUST_BUILD_DATE = '2026-04-30T12:31:49.535Z'; // Replaced during build
|
|
25
25
|
export { Application } from './boot/Application.js';
|
|
26
26
|
export { AwsSigV4 } from './common/index.js';
|
|
27
27
|
export { SignedRequest } from './security/SignedRequest.js';
|
|
@@ -17,7 +17,7 @@ const parseReadHosts = (raw: string): string[] | undefined => {
|
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
export default {
|
|
20
|
-
default: Env.get('DB_CONNECTION', '
|
|
20
|
+
default: Env.get('DB_CONNECTION', Env.getBool('CLOUDFLARE_WORKER', false) ? 'd1' : 'sqlite'),
|
|
21
21
|
connections: {
|
|
22
22
|
sqlite: {
|
|
23
23
|
driver: 'sqlite' as const,
|