@zintrust/core 0.4.76 → 0.4.79
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/zintrust-main.d.ts +12 -0
- package/bin/zintrust-main.d.ts.map +1 -1
- package/bin/zintrust-main.js +149 -54
- package/package.json +1 -1
- package/src/boot/registry/runtime.d.ts.map +1 -1
- package/src/boot/registry/runtime.js +38 -4
- package/src/cli/commands/ProxyScaffoldUtils.d.ts +2 -0
- package/src/cli/commands/ProxyScaffoldUtils.d.ts.map +1 -1
- package/src/cli/commands/ProxyScaffoldUtils.js +147 -4
- package/src/cli/commands/TraceCommands.d.ts.map +1 -1
- package/src/cli/commands/TraceCommands.js +43 -51
- package/src/cli/commands/WranglerProxyCommandUtils.d.ts.map +1 -1
- package/src/cli/commands/WranglerProxyCommandUtils.js +14 -2
- package/src/config/logging/KvLogger.d.ts.map +1 -1
- package/src/config/logging/KvLogger.js +18 -6
- package/src/config/workers.d.ts.map +1 -1
- package/src/config/workers.js +52 -12
- package/src/functions/cloudflare.d.ts.map +1 -1
- package/src/functions/cloudflare.js +8 -0
- package/src/http/RequestContext.d.ts.map +1 -1
- package/src/http/RequestContext.js +5 -6
- package/src/index.d.ts +1 -0
- package/src/index.d.ts.map +1 -1
- package/src/index.js +4 -3
- package/src/middleware/ErrorHandlerMiddleware.d.ts.map +1 -1
- package/src/middleware/ErrorHandlerMiddleware.js +14 -0
- package/src/orm/adapters/SQLiteAdapter.d.ts.map +1 -1
- package/src/orm/adapters/SQLiteAdapter.js +2 -1
- package/src/orm/migrations/MigrationStore.d.ts.map +1 -1
- package/src/orm/migrations/MigrationStore.js +383 -16
- package/src/proxy/d1/ZintrustD1Proxy.d.ts.map +1 -1
- package/src/proxy/d1/ZintrustD1Proxy.js +16 -9
- package/src/runtime/StartupConfigFileRegistry.d.ts +2 -1
- package/src/runtime/StartupConfigFileRegistry.d.ts.map +1 -1
- package/src/runtime/StartupConfigFileRegistry.js +1 -0
- package/src/runtime/plugins/trace-runtime.d.ts +10 -0
- package/src/runtime/plugins/trace-runtime.d.ts.map +1 -1
- package/src/runtime/plugins/trace-runtime.js +51 -7
- package/src/templates/project/basic/tsconfig.json.tpl +11 -12
- package/src/tools/queue/Queue.d.ts +1 -2
- package/src/tools/queue/Queue.d.ts.map +1 -1
- package/src/tools/queue/Queue.js +1 -2
- package/src/trace/SystemTraceBridge.js +1 -1
- package/src/zintrust.plugins.js +2 -2
- package/src/zintrust.plugins.wg.js +2 -2
package/bin/zintrust-main.d.ts
CHANGED
|
@@ -4,6 +4,18 @@
|
|
|
4
4
|
* This module contains the CLI implementation without a hashbang so that it can
|
|
5
5
|
* be imported by other bin shortcuts (zin/z/zt) without parse errors.
|
|
6
6
|
*/
|
|
7
|
+
type ProjectLocalCliTarget = {
|
|
8
|
+
binPath: string;
|
|
9
|
+
packageRoot: string;
|
|
10
|
+
};
|
|
7
11
|
export declare function run(): Promise<void>;
|
|
12
|
+
export declare const CliLauncherInternal: Readonly<{
|
|
13
|
+
CLI_HANDOFF_ENV_KEY: "ZINTRUST_CLI_HANDOFF";
|
|
14
|
+
findProjectLocalCliTarget: (cwd: string) => ProjectLocalCliTarget | undefined;
|
|
15
|
+
getCurrentPackageRoot: () => string;
|
|
16
|
+
getRealPath: (targetPath: string) => string;
|
|
17
|
+
isWithinDirectory: (targetPath: string, possibleParentPath: string) => boolean;
|
|
18
|
+
resolveProjectLocalCliHandoff: (cwd: string, currentPackageRoot: string, env?: NodeJS.ProcessEnv) => ProjectLocalCliTarget | undefined;
|
|
19
|
+
}>;
|
|
8
20
|
export {};
|
|
9
21
|
//# sourceMappingURL=zintrust-main.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zintrust-main.d.ts","sourceRoot":"","sources":["../../bin/zintrust-main.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"zintrust-main.d.ts","sourceRoot":"","sources":["../../bin/zintrust-main.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,KAAK,qBAAqB,GAAG;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAmTF,wBAAsB,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,CAMzC;AAED,eAAO,MAAM,mBAAmB;;qCAjSQ,MAAM,KAAG,qBAAqB,GAAG,SAAS;iCAtBhD,MAAM;8BAIP,MAAM,KAAG,MAAM;oCAQT,MAAM,sBAAsB,MAAM,KAAG,OAAO;yCAqC5E,MAAM,sBACS,MAAM,QACrB,MAAM,CAAC,UAAU,KACrB,qBAAqB,GAAG,SAAS;EA0QlC,CAAC;AAEH,OAAO,EAAE,CAAC"}
|
package/bin/zintrust-main.js
CHANGED
|
@@ -5,9 +5,86 @@
|
|
|
5
5
|
* be imported by other bin shortcuts (zin/z/zt) without parse errors.
|
|
6
6
|
*/
|
|
7
7
|
import { Logger } from '../src/config/logger.js';
|
|
8
|
+
import { spawnSync } from 'node:child_process';
|
|
8
9
|
import fs from 'node:fs';
|
|
9
10
|
import path from 'node:path';
|
|
10
11
|
import { fileURLToPath } from 'node:url';
|
|
12
|
+
const CLI_HANDOFF_ENV_KEY = 'ZINTRUST_CLI_HANDOFF';
|
|
13
|
+
const getCurrentPackageRoot = () => {
|
|
14
|
+
return path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
15
|
+
};
|
|
16
|
+
const getRealPath = (targetPath) => {
|
|
17
|
+
try {
|
|
18
|
+
return fs.realpathSync(targetPath);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return path.resolve(targetPath);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const isWithinDirectory = (targetPath, possibleParentPath) => {
|
|
25
|
+
const normalizedTarget = getRealPath(targetPath);
|
|
26
|
+
const normalizedParent = getRealPath(possibleParentPath);
|
|
27
|
+
if (normalizedTarget === normalizedParent)
|
|
28
|
+
return true;
|
|
29
|
+
const relativePath = path.relative(normalizedParent, normalizedTarget);
|
|
30
|
+
return relativePath !== '' && !relativePath.startsWith('..') && !path.isAbsolute(relativePath);
|
|
31
|
+
};
|
|
32
|
+
const findProjectLocalCliTarget = (cwd) => {
|
|
33
|
+
let currentDir = path.resolve(cwd);
|
|
34
|
+
while (true) {
|
|
35
|
+
const packageRoot = path.join(currentDir, 'node_modules', '@zintrust', 'core');
|
|
36
|
+
const packageJsonPath = path.join(packageRoot, 'package.json');
|
|
37
|
+
const binCandidates = [
|
|
38
|
+
path.join(packageRoot, 'bin', 'zin.js'),
|
|
39
|
+
path.join(packageRoot, 'bin', 'zin.mjs'),
|
|
40
|
+
path.join(packageRoot, 'bin', 'zin.cjs'),
|
|
41
|
+
path.join(packageRoot, 'bin', 'zin.ts'),
|
|
42
|
+
];
|
|
43
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
44
|
+
const binPath = binCandidates.find((candidate) => fs.existsSync(candidate));
|
|
45
|
+
if (binPath !== undefined) {
|
|
46
|
+
return { binPath, packageRoot };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const parentDir = path.dirname(currentDir);
|
|
50
|
+
if (parentDir === currentDir)
|
|
51
|
+
return undefined;
|
|
52
|
+
currentDir = parentDir;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const resolveProjectLocalCliHandoff = (cwd, currentPackageRoot, env = process.env) => {
|
|
56
|
+
if (env[CLI_HANDOFF_ENV_KEY] === '1')
|
|
57
|
+
return undefined;
|
|
58
|
+
if (isWithinDirectory(cwd, currentPackageRoot))
|
|
59
|
+
return undefined;
|
|
60
|
+
const target = findProjectLocalCliTarget(cwd);
|
|
61
|
+
if (target === undefined)
|
|
62
|
+
return undefined;
|
|
63
|
+
if (getRealPath(target.packageRoot) === getRealPath(currentPackageRoot)) {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
return target;
|
|
67
|
+
};
|
|
68
|
+
const handoffToProjectLocalCli = (target, rawArgs) => {
|
|
69
|
+
const result = spawnSync(process.execPath, [target.binPath, ...rawArgs], {
|
|
70
|
+
stdio: 'inherit',
|
|
71
|
+
env: {
|
|
72
|
+
...process.env,
|
|
73
|
+
[CLI_HANDOFF_ENV_KEY]: '1',
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
if (result.error !== undefined) {
|
|
77
|
+
throw result.error;
|
|
78
|
+
}
|
|
79
|
+
process.exit(typeof result.status === 'number' ? result.status : 1);
|
|
80
|
+
};
|
|
81
|
+
const maybeHandoffToProjectLocalCli = (rawArgs) => {
|
|
82
|
+
const localCliTarget = resolveProjectLocalCliHandoff(process.cwd(), getCurrentPackageRoot());
|
|
83
|
+
if (localCliTarget === undefined)
|
|
84
|
+
return false;
|
|
85
|
+
handoffToProjectLocalCli(localCliTarget, rawArgs);
|
|
86
|
+
return true;
|
|
87
|
+
};
|
|
11
88
|
const loadPackageVersionFast = () => {
|
|
12
89
|
try {
|
|
13
90
|
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
@@ -33,6 +110,12 @@ const getArgsFromProcess = () => {
|
|
|
33
110
|
const isVersionRequest = (args) => {
|
|
34
111
|
return args.includes('-v') || args.includes('--version');
|
|
35
112
|
};
|
|
113
|
+
const maybePrintVersionAndExit = (args) => {
|
|
114
|
+
if (!isVersionRequest(args))
|
|
115
|
+
return false;
|
|
116
|
+
printFancyVersion(loadPackageVersionFast());
|
|
117
|
+
return true;
|
|
118
|
+
};
|
|
36
119
|
const printFancyVersion = (version) => {
|
|
37
120
|
const framework = 'ZinTrust Framework';
|
|
38
121
|
const bannerWidth = 46;
|
|
@@ -110,69 +193,81 @@ const handleCliFatal = async (error, context) => {
|
|
|
110
193
|
}
|
|
111
194
|
process.exit(1);
|
|
112
195
|
};
|
|
113
|
-
|
|
196
|
+
const runCliInternal = async () => {
|
|
197
|
+
const { rawArgs: rawArgs0, args: args0 } = getArgsFromProcess();
|
|
198
|
+
if (maybeHandoffToProjectLocalCli(rawArgs0)) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
// Fast path: print version and exit without bootstrapping the CLI.
|
|
202
|
+
// This keeps `zin -v` / `zin --version` snappy and avoids any debug output.
|
|
203
|
+
if (maybePrintVersionAndExit(args0)) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const { EnvFileLoader } = await import('../src/cli/utils/EnvFileLoader.js');
|
|
207
|
+
EnvFileLoader.ensureLoaded();
|
|
208
|
+
// Auto-load install-only CLI extension packages that self-register commands.
|
|
209
|
+
let optionalCliExtensions;
|
|
210
|
+
let optionalCliStatuses = [];
|
|
114
211
|
try {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
212
|
+
({ OptionalCliExtensions: optionalCliExtensions } = await import('../src/cli/OptionalCliExtensions.js'));
|
|
213
|
+
optionalCliStatuses = await optionalCliExtensions.loadForArgs(args0);
|
|
214
|
+
}
|
|
215
|
+
catch {
|
|
216
|
+
// best-effort; missing optional extensions must not block the CLI
|
|
217
|
+
}
|
|
218
|
+
const missingOptionalExtension = optionalCliExtensions?.findMissingExtensionForArgs(args0, optionalCliStatuses);
|
|
219
|
+
if (missingOptionalExtension !== undefined) {
|
|
220
|
+
const { ErrorFactory } = await import('../src/exceptions/ZintrustError.js');
|
|
221
|
+
throw ErrorFactory.createCliError(optionalCliExtensions?.getMissingExtensionMessage(missingOptionalExtension) ??
|
|
222
|
+
`Missing optional CLI package: ${missingOptionalExtension.packageName}`);
|
|
223
|
+
}
|
|
224
|
+
// Ensure project-installed adapters/drivers are registered for CLI commands.
|
|
225
|
+
// (This is driven by src/zintrust.plugins.ts generated by `zin plugin install`.)
|
|
226
|
+
try {
|
|
227
|
+
const { PluginAutoImports } = await import('../src/runtime/PluginAutoImports.js');
|
|
228
|
+
const runtimeImportMode = process.env['DOCKER_WORKER'] === 'true' ? 'worker' : 'base';
|
|
229
|
+
const officialImports = await PluginAutoImports.tryImportRuntimeAutoImports(runtimeImportMode);
|
|
230
|
+
if (!officialImports.ok) {
|
|
231
|
+
logPluginAutoImportFailure(args0, 'Official', officialImports.errorMessage);
|
|
134
232
|
}
|
|
135
|
-
const
|
|
136
|
-
if (
|
|
137
|
-
|
|
138
|
-
throw ErrorFactory.createCliError(optionalCliExtensions?.getMissingExtensionMessage(missingOptionalExtension) ??
|
|
139
|
-
`Missing optional CLI package: ${missingOptionalExtension.packageName}`);
|
|
233
|
+
const projectImports = await PluginAutoImports.tryImportProjectAutoImports();
|
|
234
|
+
if (!projectImports.ok && projectImports.reason !== 'not-found') {
|
|
235
|
+
logPluginAutoImportFailure(args0, 'Project', projectImports.errorMessage);
|
|
140
236
|
}
|
|
141
|
-
|
|
142
|
-
|
|
237
|
+
}
|
|
238
|
+
catch {
|
|
239
|
+
// best-effort; CLI should still run even if plugins file is missing
|
|
240
|
+
}
|
|
241
|
+
const { CLI } = await import('../src/cli/CLI.js');
|
|
242
|
+
const cli = CLI.create();
|
|
243
|
+
// When executing via tsx (e.g. `npx tsx bin/zin.ts ...`), the script path can
|
|
244
|
+
// appear as the first element of `process.argv.slice(2)`. Commander expects
|
|
245
|
+
// args to start at the command name, so we strip a leading script path if present.
|
|
246
|
+
const { rawArgs, args } = getArgsFromProcess();
|
|
247
|
+
if (shouldDebugArgs(rawArgs)) {
|
|
143
248
|
try {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
const officialImports = await PluginAutoImports.tryImportRuntimeAutoImports(runtimeImportMode);
|
|
147
|
-
if (!officialImports.ok) {
|
|
148
|
-
logPluginAutoImportFailure(args0, 'Official', officialImports.errorMessage);
|
|
149
|
-
}
|
|
150
|
-
const projectImports = await PluginAutoImports.tryImportProjectAutoImports();
|
|
151
|
-
if (!projectImports.ok && projectImports.reason !== 'not-found') {
|
|
152
|
-
logPluginAutoImportFailure(args0, 'Project', projectImports.errorMessage);
|
|
153
|
-
}
|
|
249
|
+
process.stderr.write(`[zintrust-cli] process.argv=${JSON.stringify(process.argv)}\n`);
|
|
250
|
+
process.stderr.write(`[zintrust-cli] rawArgs=${JSON.stringify(rawArgs)}\n`);
|
|
154
251
|
}
|
|
155
252
|
catch {
|
|
156
|
-
//
|
|
157
|
-
}
|
|
158
|
-
const { CLI } = await import('../src/cli/CLI.js');
|
|
159
|
-
const cli = CLI.create();
|
|
160
|
-
// When executing via tsx (e.g. `npx tsx bin/zin.ts ...`), the script path can
|
|
161
|
-
// appear as the first element of `process.argv.slice(2)`. Commander expects
|
|
162
|
-
// args to start at the command name, so we strip a leading script path if present.
|
|
163
|
-
const { rawArgs, args } = getArgsFromProcess();
|
|
164
|
-
if (shouldDebugArgs(rawArgs)) {
|
|
165
|
-
try {
|
|
166
|
-
process.stderr.write(`[zintrust-cli] process.argv=${JSON.stringify(process.argv)}\n`);
|
|
167
|
-
process.stderr.write(`[zintrust-cli] rawArgs=${JSON.stringify(rawArgs)}\n`);
|
|
168
|
-
}
|
|
169
|
-
catch {
|
|
170
|
-
// ignore
|
|
171
|
-
}
|
|
253
|
+
// ignore
|
|
172
254
|
}
|
|
173
|
-
|
|
255
|
+
}
|
|
256
|
+
await cli.run(normalizeProxyTargetArgs(args));
|
|
257
|
+
};
|
|
258
|
+
export async function run() {
|
|
259
|
+
try {
|
|
260
|
+
await runCliInternal();
|
|
174
261
|
}
|
|
175
262
|
catch (error) {
|
|
176
263
|
await handleCliFatal(error, 'CLI execution failed');
|
|
177
264
|
}
|
|
178
265
|
}
|
|
266
|
+
export const CliLauncherInternal = Object.freeze({
|
|
267
|
+
CLI_HANDOFF_ENV_KEY,
|
|
268
|
+
findProjectLocalCliTarget,
|
|
269
|
+
getCurrentPackageRoot,
|
|
270
|
+
getRealPath,
|
|
271
|
+
isWithinDirectory,
|
|
272
|
+
resolveProjectLocalCliHandoff,
|
|
273
|
+
});
|
package/package.json
CHANGED
|
@@ -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;AASvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,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;AASvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AA2O9C,eAAO,MAAM,8BAA8B,GAAI,iBAAiB,gBAAgB,KAAG,IA6BlF,CAAC;AAqUF,eAAO,MAAM,eAAe,GAAI,QAAQ;IACtC,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,KAAG;IAAE,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAAC,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CA0F7D,CAAC"}
|
|
@@ -384,11 +384,27 @@ const isTraceEnabled = () => {
|
|
|
384
384
|
const raw = readEnvString('TRACE_ENABLED').trim().toLowerCase();
|
|
385
385
|
return raw === '1' || raw === 'true';
|
|
386
386
|
};
|
|
387
|
+
const isTraceDashboardAutoMountEnabled = () => {
|
|
388
|
+
const raw = readEnvString('TRACE_AUTO_MOUNT').trim().toLowerCase();
|
|
389
|
+
return raw === '1' || raw === 'true';
|
|
390
|
+
};
|
|
391
|
+
const resolveTraceDashboardBasePath = () => {
|
|
392
|
+
const raw = readEnvString('TRACE_BASE_PATH').trim();
|
|
393
|
+
if (raw === '')
|
|
394
|
+
return '/trace';
|
|
395
|
+
return raw.startsWith('/') ? raw : `/${raw}`;
|
|
396
|
+
};
|
|
397
|
+
const resolveTraceDashboardMiddleware = () => {
|
|
398
|
+
return readEnvString('TRACE_MIDDLEWARE')
|
|
399
|
+
.split(',')
|
|
400
|
+
.map((value) => value.trim())
|
|
401
|
+
.filter(isNonEmptyString);
|
|
402
|
+
};
|
|
387
403
|
const isSystemTracePluginRequested = () => {
|
|
388
404
|
const globalTracePluginState = globalThis;
|
|
389
405
|
return globalTracePluginState.__zintrust_system_trace_plugin_requested__ === true;
|
|
390
406
|
};
|
|
391
|
-
const initializeSystemTrace = async () => {
|
|
407
|
+
const initializeSystemTrace = async (router) => {
|
|
392
408
|
if (!isSystemTracePluginRequested()) {
|
|
393
409
|
Logger.debug('System Trace plugin is not enabled in zintrust.plugins.*. Skipping init.');
|
|
394
410
|
return;
|
|
@@ -397,13 +413,31 @@ const initializeSystemTrace = async () => {
|
|
|
397
413
|
return;
|
|
398
414
|
const traceModule = (await tryImportOptional('@runtime/plugins/trace-runtime')) ??
|
|
399
415
|
(await loadLocalSystemTraceModule());
|
|
400
|
-
if (traceModule === undefined
|
|
416
|
+
if (traceModule === undefined) {
|
|
401
417
|
Logger.debug('System Trace is enabled but the optional package is unavailable.');
|
|
402
418
|
return;
|
|
403
419
|
}
|
|
404
420
|
try {
|
|
405
421
|
await traceModule.ensureSystemTraceRegistered();
|
|
406
|
-
|
|
422
|
+
if (traceModule.isAvailable?.() === false) {
|
|
423
|
+
Logger.debug('System Trace is enabled but the optional package is unavailable.');
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
if (!isTraceDashboardAutoMountEnabled()) {
|
|
427
|
+
Logger.info('System Trace runtime activated. Set TRACE_AUTO_MOUNT=true or register dashboard routes manually if needed.');
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
if (typeof traceModule.registerTraceDashboard !== 'function') {
|
|
431
|
+
Logger.warn('System Trace auto-mount requested but the optional package does not expose registerTraceDashboard.');
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
const basePath = resolveTraceDashboardBasePath();
|
|
435
|
+
const middleware = resolveTraceDashboardMiddleware();
|
|
436
|
+
traceModule.registerTraceDashboard(router, {
|
|
437
|
+
basePath,
|
|
438
|
+
...(middleware.length > 0 ? { middleware } : {}),
|
|
439
|
+
});
|
|
440
|
+
Logger.info(`System Trace dashboard auto-mounted at ${basePath}.`);
|
|
407
441
|
}
|
|
408
442
|
catch (error) {
|
|
409
443
|
Logger.warn('Failed to initialize System Trace runtime', error);
|
|
@@ -474,7 +508,7 @@ export const createLifecycle = (params) => {
|
|
|
474
508
|
await initializeArtifactDirectories(params.resolvedBasePath);
|
|
475
509
|
await registerMasterRoutes(params.resolvedBasePath, params.router);
|
|
476
510
|
initializeSockets(params.router);
|
|
477
|
-
await initializeSystemTrace();
|
|
511
|
+
await initializeSystemTrace(params.router);
|
|
478
512
|
if (Cloudflare.getWorkersEnv() === null && appConfig.dockerWorker === false) {
|
|
479
513
|
await initializeWorkers(params.router);
|
|
480
514
|
await initializeQueueMonitor(params.router);
|
|
@@ -15,11 +15,13 @@ type EnsureWranglerConfigOptions<TValues, TOptions> = {
|
|
|
15
15
|
type EnsureWranglerConfigResult<TValues> = {
|
|
16
16
|
createdFile: boolean;
|
|
17
17
|
insertedEnv: boolean;
|
|
18
|
+
content: string;
|
|
18
19
|
values: TValues;
|
|
19
20
|
};
|
|
20
21
|
export declare const trimNonEmptyOption: (value: string | undefined) => string | undefined;
|
|
21
22
|
export declare const resolveConfigPath: (raw: string | undefined, fallback?: string) => string;
|
|
22
23
|
export declare const findQuotedValue: (content: string, key: string) => string | undefined;
|
|
24
|
+
export declare const renderProxyWranglerDevConfig: (content: string, envName: string) => string | undefined;
|
|
23
25
|
export declare const injectEnvBlock: (content: string, envName: string, block: string) => string;
|
|
24
26
|
export declare const renderDefaultWranglerConfig: (envBlock: string, compatibilityDate: string) => string;
|
|
25
27
|
export declare const ensureProxyEntrypoint: (options: EnsureProxyEntrypointOptions) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProxyScaffoldUtils.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/ProxyScaffoldUtils.ts"],"names":[],"mappings":"AAKA,KAAK,4BAA4B,GAAG;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,KAAK,2BAA2B,CAAC,OAAO,EAAE,QAAQ,IAAI;IACpD,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,QAAQ,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,EAAE,QAAQ,KAAK,OAAO,CAAC;IAC3E,cAAc,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,MAAM,CAAC;IAC5C,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,KAAK,0BAA0B,CAAC,OAAO,IAAI;IACzC,WAAW,EAAE,OAAO,CAAC;IACrB,WAAW,EAAE,OAAO,CAAC;IACrB,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,OAAO,MAAM,GAAG,SAAS,KAAG,MAAM,GAAG,SAIvE,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,KAAK,MAAM,GAAG,SAAS,EAAE,iBAA2B,KAAG,MAExF,CAAC;AAmBF,eAAO,MAAM,eAAe,GAAI,SAAS,MAAM,EAAE,KAAK,MAAM,KAAG,MAAM,GAAG,SAQvE,CAAC;
|
|
1
|
+
{"version":3,"file":"ProxyScaffoldUtils.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/ProxyScaffoldUtils.ts"],"names":[],"mappings":"AAKA,KAAK,4BAA4B,GAAG;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,KAAK,2BAA2B,CAAC,OAAO,EAAE,QAAQ,IAAI;IACpD,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,QAAQ,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,EAAE,QAAQ,KAAK,OAAO,CAAC;IAC3E,cAAc,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,MAAM,CAAC;IAC5C,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,KAAK,0BAA0B,CAAC,OAAO,IAAI;IACzC,WAAW,EAAE,OAAO,CAAC;IACrB,WAAW,EAAE,OAAO,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,OAAO,MAAM,GAAG,SAAS,KAAG,MAAM,GAAG,SAIvE,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,KAAK,MAAM,GAAG,SAAS,EAAE,iBAA2B,KAAG,MAExF,CAAC;AAmBF,eAAO,MAAM,eAAe,GAAI,SAAS,MAAM,EAAE,KAAK,MAAM,KAAG,MAAM,GAAG,SAQvE,CAAC;AAwKF,eAAO,MAAM,4BAA4B,GACvC,SAAS,MAAM,EACf,SAAS,MAAM,KACd,MAAM,GAAG,SAgBX,CAAC;AAQF,eAAO,MAAM,cAAc,GAAI,SAAS,MAAM,EAAE,SAAS,MAAM,EAAE,OAAO,MAAM,KAAG,MAuBhF,CAAC;AAEF,eAAO,MAAM,2BAA2B,GACtC,UAAU,MAAM,EAChB,mBAAmB,MAAM,KACxB,MAaF,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAChC,SAAS,4BAA4B,KACpC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAmB3C,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAAI,OAAO,EAAE,QAAQ,EACpD,SAAS,2BAA2B,CAAC,OAAO,EAAE,QAAQ,CAAC,KACtD,0BAA0B,CAAC,OAAO,CAqBpC,CAAC"}
|
|
@@ -47,6 +47,148 @@ const findEnvObjectStart = (content) => {
|
|
|
47
47
|
return -1;
|
|
48
48
|
return valueStart;
|
|
49
49
|
};
|
|
50
|
+
const createJsonScanState = () => ({
|
|
51
|
+
inString: false,
|
|
52
|
+
isEscaped: false,
|
|
53
|
+
inLineComment: false,
|
|
54
|
+
inBlockComment: false,
|
|
55
|
+
});
|
|
56
|
+
const advanceWithinLineComment = (state, current) => {
|
|
57
|
+
if (!state.inLineComment)
|
|
58
|
+
return 0;
|
|
59
|
+
if (current === '\n')
|
|
60
|
+
state.inLineComment = false;
|
|
61
|
+
return 1;
|
|
62
|
+
};
|
|
63
|
+
const advanceWithinBlockComment = (state, current, next) => {
|
|
64
|
+
if (!state.inBlockComment)
|
|
65
|
+
return 0;
|
|
66
|
+
if (current === '*' && next === '/') {
|
|
67
|
+
state.inBlockComment = false;
|
|
68
|
+
return 2;
|
|
69
|
+
}
|
|
70
|
+
return 1;
|
|
71
|
+
};
|
|
72
|
+
const advanceWithinString = (state, current) => {
|
|
73
|
+
if (!state.inString)
|
|
74
|
+
return 0;
|
|
75
|
+
if (state.isEscaped) {
|
|
76
|
+
state.isEscaped = false;
|
|
77
|
+
}
|
|
78
|
+
else if (current === '\\') {
|
|
79
|
+
state.isEscaped = true;
|
|
80
|
+
}
|
|
81
|
+
else if (current === '"') {
|
|
82
|
+
state.inString = false;
|
|
83
|
+
}
|
|
84
|
+
return 1;
|
|
85
|
+
};
|
|
86
|
+
const startJsonScanContext = (state, current, next) => {
|
|
87
|
+
if (current === '/' && next === '/') {
|
|
88
|
+
state.inLineComment = true;
|
|
89
|
+
return 2;
|
|
90
|
+
}
|
|
91
|
+
if (current === '/' && next === '*') {
|
|
92
|
+
state.inBlockComment = true;
|
|
93
|
+
return 2;
|
|
94
|
+
}
|
|
95
|
+
if (current === '"') {
|
|
96
|
+
state.inString = true;
|
|
97
|
+
return 1;
|
|
98
|
+
}
|
|
99
|
+
return 0;
|
|
100
|
+
};
|
|
101
|
+
const advanceJsonScanState = (state, current, next) => {
|
|
102
|
+
return (advanceWithinLineComment(state, current) ||
|
|
103
|
+
advanceWithinBlockComment(state, current, next) ||
|
|
104
|
+
advanceWithinString(state, current) ||
|
|
105
|
+
startJsonScanContext(state, current, next));
|
|
106
|
+
};
|
|
107
|
+
const rewriteRelativeWranglerPaths = (content) => {
|
|
108
|
+
return content.replaceAll('": "./', '": "../../');
|
|
109
|
+
};
|
|
110
|
+
const findQuotedKeyFrom = (content, key, startIndex) => {
|
|
111
|
+
let cursor = Math.max(0, startIndex);
|
|
112
|
+
const state = createJsonScanState();
|
|
113
|
+
const candidate = `"${key}"`;
|
|
114
|
+
while (cursor < content.length) {
|
|
115
|
+
const current = content[cursor];
|
|
116
|
+
const next = content[cursor + 1];
|
|
117
|
+
if (!state.inString && !state.inLineComment && !state.inBlockComment) {
|
|
118
|
+
if (content.startsWith(candidate, cursor))
|
|
119
|
+
return cursor;
|
|
120
|
+
}
|
|
121
|
+
const advanced = advanceJsonScanState(state, current, next);
|
|
122
|
+
cursor += advanced > 0 ? advanced : 1;
|
|
123
|
+
}
|
|
124
|
+
return -1;
|
|
125
|
+
};
|
|
126
|
+
const findJsonKeyValueStartFrom = (content, key, startIndex) => {
|
|
127
|
+
const keyPosition = findQuotedKeyFrom(content, key, startIndex);
|
|
128
|
+
if (keyPosition < 0)
|
|
129
|
+
return -1;
|
|
130
|
+
let cursor = keyPosition + key.length + 2;
|
|
131
|
+
while (isJsonWhitespace(content[cursor]))
|
|
132
|
+
cursor += 1;
|
|
133
|
+
if (content[cursor] !== ':')
|
|
134
|
+
return -1;
|
|
135
|
+
cursor += 1;
|
|
136
|
+
while (isJsonWhitespace(content[cursor]))
|
|
137
|
+
cursor += 1;
|
|
138
|
+
return cursor;
|
|
139
|
+
};
|
|
140
|
+
const findMatchingObjectBrace = (content, objectStart) => {
|
|
141
|
+
let depth = 0;
|
|
142
|
+
const state = createJsonScanState();
|
|
143
|
+
for (let index = objectStart; index < content.length; index += 1) {
|
|
144
|
+
const current = content[index];
|
|
145
|
+
const next = content[index + 1];
|
|
146
|
+
if (!state.inString && !state.inLineComment && !state.inBlockComment) {
|
|
147
|
+
if (current === '{') {
|
|
148
|
+
depth += 1;
|
|
149
|
+
}
|
|
150
|
+
else if (current === '}') {
|
|
151
|
+
depth -= 1;
|
|
152
|
+
if (depth === 0)
|
|
153
|
+
return index;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const advanced = advanceJsonScanState(state, current, next);
|
|
157
|
+
if (advanced > 1)
|
|
158
|
+
index += advanced - 1;
|
|
159
|
+
}
|
|
160
|
+
return -1;
|
|
161
|
+
};
|
|
162
|
+
const extractObjectBlock = (content, key, startIndex = 0) => {
|
|
163
|
+
const valueStart = findJsonKeyValueStartFrom(content, key, startIndex);
|
|
164
|
+
if (valueStart < 0 || content[valueStart] !== '{')
|
|
165
|
+
return undefined;
|
|
166
|
+
const valueEnd = findMatchingObjectBrace(content, valueStart);
|
|
167
|
+
if (valueEnd < 0)
|
|
168
|
+
return undefined;
|
|
169
|
+
return content.slice(valueStart, valueEnd + 1);
|
|
170
|
+
};
|
|
171
|
+
const indentBlock = (content, spaces) => {
|
|
172
|
+
const prefix = ' '.repeat(spaces);
|
|
173
|
+
return content
|
|
174
|
+
.split('\n')
|
|
175
|
+
.map((line) => (line.trim().length === 0 ? line : `${prefix}${line}`))
|
|
176
|
+
.join('\n');
|
|
177
|
+
};
|
|
178
|
+
export const renderProxyWranglerDevConfig = (content, envName) => {
|
|
179
|
+
const envObjectStart = findEnvObjectStart(content);
|
|
180
|
+
if (envObjectStart < 0)
|
|
181
|
+
return undefined;
|
|
182
|
+
const envBlock = extractObjectBlock(content, envName, envObjectStart);
|
|
183
|
+
if (envBlock === undefined)
|
|
184
|
+
return undefined;
|
|
185
|
+
const aliasBlock = extractObjectBlock(content, 'alias');
|
|
186
|
+
const envBody = envBlock.slice(1, -1).trim();
|
|
187
|
+
if (envBody.length === 0)
|
|
188
|
+
return undefined;
|
|
189
|
+
const aliasLine = aliasBlock === undefined ? [] : [` "alias": ${aliasBlock},`];
|
|
190
|
+
return rewriteRelativeWranglerPaths(['{', ...aliasLine, indentBlock(envBody, 2), '}', ''].join('\n'));
|
|
191
|
+
};
|
|
50
192
|
const isObjectEffectivelyEmpty = (content, objectStart) => {
|
|
51
193
|
let cursor = objectStart + 1;
|
|
52
194
|
while (isJsonWhitespace(content[cursor]))
|
|
@@ -105,15 +247,16 @@ export const ensureProxyEntrypoint = (options) => {
|
|
|
105
247
|
export const ensureWranglerConfig = (options) => {
|
|
106
248
|
if (!existsSync(options.configPath)) {
|
|
107
249
|
const values = options.resolveValues(undefined, options.options);
|
|
108
|
-
|
|
109
|
-
|
|
250
|
+
const content = renderDefaultWranglerConfig(options.renderEnvBlock(values), options.compatibilityDate);
|
|
251
|
+
writeFileSync(options.configPath, content, 'utf-8');
|
|
252
|
+
return { createdFile: true, insertedEnv: true, content, values };
|
|
110
253
|
}
|
|
111
254
|
const content = readFileSync(options.configPath, 'utf-8');
|
|
112
255
|
const values = options.resolveValues(content, options.options);
|
|
113
256
|
const next = injectEnvBlock(content, options.envName, options.renderEnvBlock(values));
|
|
114
257
|
if (next !== content) {
|
|
115
258
|
writeFileSync(options.configPath, next, 'utf-8');
|
|
116
|
-
return { createdFile: false, insertedEnv: true, values };
|
|
259
|
+
return { createdFile: false, insertedEnv: true, content: next, values };
|
|
117
260
|
}
|
|
118
|
-
return { createdFile: false, insertedEnv: false, values };
|
|
261
|
+
return { createdFile: false, insertedEnv: false, content, values };
|
|
119
262
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TraceCommands.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/TraceCommands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAsBrE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"TraceCommands.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/TraceCommands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAsBrE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAgqBzC,eAAO,MAAM,aAAa;mCACK,YAAY;mCAQZ,YAAY;oCAQX,YAAY;qCAQX,YAAY;;cAhCzB,MAAM;oBAAc,MAAM,OAAO;;;cAAjC,MAAM;oBAAc,MAAM,OAAO;;;cAAjC,MAAM;oBAAc,MAAM,OAAO;;;cAAjC,MAAM;oBAAc,MAAM,OAAO;;EAmDnD,CAAC"}
|