@zintrust/core 0.4.75 → 0.4.77
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 +60 -25
- package/src/cache/Cache.d.ts.map +1 -1
- package/src/cache/Cache.js +11 -11
- package/src/cli/BaseCommand.js +3 -3
- package/src/cli/OptionalCliExtensions.js +8 -8
- package/src/cli/commands/MigrateCommand.js +1 -1
- package/src/cli/commands/TraceCommand.d.ts +18 -0
- package/src/cli/commands/TraceCommand.d.ts.map +1 -0
- package/src/cli/commands/TraceCommand.js +6 -0
- package/src/cli/commands/TraceCommands.d.ts +25 -0
- package/src/cli/commands/TraceCommands.d.ts.map +1 -0
- package/src/cli/commands/{DebuggerCommands.js → TraceCommands.js} +112 -120
- package/src/cli/commands/index.d.ts +1 -1
- package/src/cli/commands/index.d.ts.map +1 -1
- package/src/cli/commands/index.js +1 -1
- package/src/cli/index.d.ts +2 -2
- package/src/cli/index.d.ts.map +1 -1
- package/src/cli/index.js +2 -2
- package/src/cli.d.ts +1 -1
- package/src/cli.d.ts.map +1 -1
- package/src/cli.js +1 -1
- package/src/config/logging/KvLogger.d.ts.map +1 -1
- package/src/config/logging/KvLogger.js +18 -6
- package/src/events/EventDispatcher.js +3 -3
- 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 +2 -1
- package/src/index.d.ts.map +1 -1
- package/src/index.js +5 -4
- package/src/middleware/ErrorHandlerMiddleware.d.ts.map +1 -1
- package/src/middleware/ErrorHandlerMiddleware.js +2 -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 +352 -16
- 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 +24 -0
- package/src/runtime/plugins/trace-runtime.d.ts.map +1 -0
- package/src/runtime/plugins/trace-runtime.js +63 -0
- package/src/runtime/plugins/trace.d.ts +2 -0
- package/src/runtime/plugins/trace.d.ts.map +1 -0
- package/src/runtime/plugins/{system-debugger.js → trace.js} +2 -2
- package/src/security/JwtManager.js +4 -4
- package/src/templates/project/basic/tsconfig.json.tpl +11 -12
- package/src/tools/http/Http.js +2 -2
- package/src/tools/mail/index.js +2 -2
- package/src/tools/notification/Service.js +6 -6
- 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 +3 -4
- package/src/{debugger/SystemDebuggerBridge.d.ts → trace/SystemTraceBridge.d.ts} +3 -3
- package/src/trace/SystemTraceBridge.d.ts.map +1 -0
- package/src/{debugger/SystemDebuggerBridge.js → trace/SystemTraceBridge.js} +20 -20
- package/src/zintrust.comon.d.ts +11 -0
- package/src/zintrust.comon.d.ts.map +1 -0
- package/src/zintrust.comon.js +17 -0
- package/src/zintrust.plugins.d.ts +7 -3
- package/src/zintrust.plugins.d.ts.map +1 -1
- package/src/zintrust.plugins.js +9 -3
- package/src/zintrust.plugins.wg.d.ts +1 -0
- package/src/zintrust.plugins.wg.d.ts.map +1 -1
- package/src/zintrust.plugins.wg.js +3 -0
- package/src/cli/commands/DebuggerCommand.d.ts +0 -18
- package/src/cli/commands/DebuggerCommand.d.ts.map +0 -1
- package/src/cli/commands/DebuggerCommand.js +0 -6
- package/src/cli/commands/DebuggerCommands.d.ts +0 -25
- package/src/cli/commands/DebuggerCommands.d.ts.map +0 -1
- package/src/debugger/SystemDebuggerBridge.d.ts.map +0 -1
- package/src/runtime/plugins/system-debugger-runtime.d.ts +0 -19
- package/src/runtime/plugins/system-debugger-runtime.d.ts.map +0 -1
- package/src/runtime/plugins/system-debugger-runtime.js +0 -19
- package/src/runtime/plugins/system-debugger.d.ts +0 -2
- package/src/runtime/plugins/system-debugger.d.ts.map +0 -1
|
@@ -14,22 +14,42 @@ import { createRequire } from '../../node-singletons/module.js';
|
|
|
14
14
|
import * as path from '../../node-singletons/path.js';
|
|
15
15
|
import { Database } from '../../orm/Database.js';
|
|
16
16
|
import { DatabaseAdapterRegistry } from '../../orm/DatabaseAdapterRegistry.js';
|
|
17
|
-
const
|
|
17
|
+
const loadTraceModule = async () => {
|
|
18
18
|
try {
|
|
19
|
-
return (await import('@zintrust/
|
|
19
|
+
return (await import('@zintrust/trace'));
|
|
20
20
|
}
|
|
21
21
|
catch (error) {
|
|
22
|
-
Logger.error('Failed to load optional package "@zintrust/
|
|
23
|
-
throw ErrorFactory.createCliError('Package "@zintrust/
|
|
22
|
+
Logger.error('Failed to load optional package "@zintrust/trace"', error);
|
|
23
|
+
throw ErrorFactory.createCliError('Package "@zintrust/trace" is not installed. Add it to your project first.');
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
|
-
const
|
|
26
|
+
const addD1DatabaseOptions = (command) => {
|
|
27
27
|
command
|
|
28
|
-
.option('--hours <number>', 'Remove entries older than N hours (default: from config)', '')
|
|
29
28
|
.option('--local', 'D1 only: run against local D1 database')
|
|
30
29
|
.option('--remote', 'D1 only: run against remote D1 database')
|
|
31
|
-
.option('--database <name>', 'D1 only: Wrangler D1 database binding name')
|
|
30
|
+
.option('--database <name>', 'D1 only: Wrangler D1 database binding name');
|
|
31
|
+
};
|
|
32
|
+
const createTraceCommand = (config) => {
|
|
33
|
+
const command = BaseCommand.create({
|
|
34
|
+
name: config.name,
|
|
35
|
+
description: config.description,
|
|
36
|
+
addOptions: config.addOptions,
|
|
37
|
+
execute: async (options) => config.execute(options, command),
|
|
38
|
+
});
|
|
39
|
+
return command;
|
|
40
|
+
};
|
|
41
|
+
const resolveNamedTraceConnection = (name) => {
|
|
42
|
+
const connections = databaseConfig.connections;
|
|
43
|
+
return {
|
|
44
|
+
name,
|
|
45
|
+
config: connections[name] ?? databaseConfig.getConnection(),
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
const addPruneOptions = (command) => {
|
|
49
|
+
command
|
|
50
|
+
.option('--hours <number>', 'Remove entries older than N hours (default: from config)', '')
|
|
32
51
|
.option('--keep-exceptions', 'Keep exception entries regardless of age', false);
|
|
52
|
+
addD1DatabaseOptions(command);
|
|
33
53
|
};
|
|
34
54
|
const addMigrateOptions = (command) => {
|
|
35
55
|
command
|
|
@@ -40,16 +60,14 @@ const addMigrateOptions = (command) => {
|
|
|
40
60
|
.option('--step <number>', 'Number of batches to rollback (use with --rollback)', '1')
|
|
41
61
|
.option('--force', 'Skip production confirmation (allow unsafe operations in production)')
|
|
42
62
|
.option('--all', 'Run migrations for all configured database connections')
|
|
43
|
-
.option('--connection <name>', 'Use a specific database connection for
|
|
44
|
-
.option('--local', 'D1 only: run against local D1 database')
|
|
45
|
-
.option('--remote', 'D1 only: run against remote D1 database')
|
|
46
|
-
.option('--database <name>', 'D1 only: Wrangler D1 database binding name')
|
|
63
|
+
.option('--connection <name>', 'Use a specific database connection for trace migrations')
|
|
47
64
|
.option('--no-interactive', 'Disable interactive prompts (useful for CI/CD)');
|
|
65
|
+
addD1DatabaseOptions(command);
|
|
48
66
|
};
|
|
49
67
|
const resolveDashboardBasePath = () => {
|
|
50
|
-
const raw = readEnvString('
|
|
68
|
+
const raw = readEnvString('TRACE_BASE_PATH').trim();
|
|
51
69
|
if (raw === '')
|
|
52
|
-
return '/
|
|
70
|
+
return '/trace';
|
|
53
71
|
return raw.startsWith('/') ? raw : `/${raw}`;
|
|
54
72
|
};
|
|
55
73
|
const resolveDashboardUrl = () => {
|
|
@@ -57,7 +75,7 @@ const resolveDashboardUrl = () => {
|
|
|
57
75
|
const port = readEnvString('PORT').trim() || readEnvString('APP_PORT').trim() || '7777';
|
|
58
76
|
return `http://${host}:${port}${resolveDashboardBasePath()}`;
|
|
59
77
|
};
|
|
60
|
-
const
|
|
78
|
+
const resolveTraceMigrationTargetFromResolvedPath = (resolvedPath) => {
|
|
61
79
|
const extension = path.extname(resolvedPath).toLowerCase();
|
|
62
80
|
const dir = path.dirname(resolvedPath);
|
|
63
81
|
if (extension === '.js' || extension === '.mjs' || extension === '.cjs') {
|
|
@@ -77,25 +95,25 @@ const resolveDebuggerMigrationTargetFromResolvedPath = (resolvedPath) => {
|
|
|
77
95
|
extension: candidateExt.slice(1),
|
|
78
96
|
};
|
|
79
97
|
}
|
|
80
|
-
throw ErrorFactory.createCliError('Installed package "@zintrust/
|
|
98
|
+
throw ErrorFactory.createCliError('Installed package "@zintrust/trace" exposes TypeScript-only migrations. Upgrade to a version that publishes runnable JavaScript migrations.');
|
|
81
99
|
}
|
|
82
100
|
return {
|
|
83
101
|
dir,
|
|
84
102
|
extension: databaseConfig.migrations.extension,
|
|
85
103
|
};
|
|
86
104
|
};
|
|
87
|
-
const
|
|
105
|
+
const resolveTraceMigrationTarget = () => {
|
|
88
106
|
const requireFromProject = createRequire(path.join(process.cwd(), 'package.json'));
|
|
89
107
|
try {
|
|
90
|
-
const resolved = requireFromProject.resolve('@zintrust/
|
|
91
|
-
return
|
|
108
|
+
const resolved = requireFromProject.resolve('@zintrust/trace/migrations');
|
|
109
|
+
return resolveTraceMigrationTargetFromResolvedPath(resolved);
|
|
92
110
|
}
|
|
93
111
|
catch (error) {
|
|
94
112
|
if (error instanceof Error && error.message.includes('TypeScript-only migrations')) {
|
|
95
113
|
throw error;
|
|
96
114
|
}
|
|
97
115
|
return {
|
|
98
|
-
dir: path.join(process.cwd(), 'packages', '
|
|
116
|
+
dir: path.join(process.cwd(), 'packages', 'trace', 'migrations'),
|
|
99
117
|
extension: 'ts',
|
|
100
118
|
};
|
|
101
119
|
}
|
|
@@ -127,17 +145,17 @@ const normalizeConnectionName = (value) => {
|
|
|
127
145
|
}
|
|
128
146
|
return normalized;
|
|
129
147
|
};
|
|
130
|
-
const
|
|
148
|
+
const resolveTraceConnectionName = (options) => {
|
|
131
149
|
if (isNonEmptyString(options['connection'])) {
|
|
132
150
|
return normalizeConnectionName(String(options['connection']));
|
|
133
151
|
}
|
|
134
|
-
return normalizeConnectionName(readEnvString('
|
|
152
|
+
return normalizeConnectionName(readEnvString('TRACE_DB_CONNECTION').trim());
|
|
135
153
|
};
|
|
136
|
-
const
|
|
154
|
+
const withConfiguredTraceConnection = (options, configuredConnection) => {
|
|
137
155
|
if (isNonEmptyString(options['connection'])) {
|
|
138
156
|
return {
|
|
139
157
|
...options,
|
|
140
|
-
connection:
|
|
158
|
+
connection: resolveTraceConnectionName(options),
|
|
141
159
|
};
|
|
142
160
|
}
|
|
143
161
|
if (isNonEmptyString(configuredConnection)) {
|
|
@@ -148,11 +166,11 @@ const withConfiguredDebuggerConnection = (options, configuredConnection) => {
|
|
|
148
166
|
}
|
|
149
167
|
return {
|
|
150
168
|
...options,
|
|
151
|
-
connection:
|
|
169
|
+
connection: resolveTraceConnectionName(options),
|
|
152
170
|
};
|
|
153
171
|
};
|
|
154
|
-
const
|
|
155
|
-
const selected =
|
|
172
|
+
const resolveTraceConnectionConfig = (options) => {
|
|
173
|
+
const selected = resolveTraceConnectionName(options);
|
|
156
174
|
const connections = databaseConfig.connections;
|
|
157
175
|
return connections[selected] ?? databaseConfig.getConnection();
|
|
158
176
|
};
|
|
@@ -229,13 +247,13 @@ const buildStatsFromTableRows = (rows) => {
|
|
|
229
247
|
}
|
|
230
248
|
return stats;
|
|
231
249
|
};
|
|
232
|
-
const
|
|
233
|
-
const {
|
|
234
|
-
const conn =
|
|
250
|
+
const withSqlTraceStorage = async (options, callback) => {
|
|
251
|
+
const { TraceStorage } = await loadTraceModule();
|
|
252
|
+
const conn = resolveTraceConnectionConfig(options);
|
|
235
253
|
const db = Database.create(mapConnectionToOrmConfig(conn));
|
|
236
254
|
await db.connect();
|
|
237
255
|
try {
|
|
238
|
-
const storage =
|
|
256
|
+
const storage = TraceStorage.resolveStorage(db);
|
|
239
257
|
return await callback(storage);
|
|
240
258
|
}
|
|
241
259
|
finally {
|
|
@@ -246,7 +264,7 @@ const executeD1Stats = (options) => {
|
|
|
246
264
|
const output = WranglerD1.executeSql({
|
|
247
265
|
dbName: getD1DatabaseName(options),
|
|
248
266
|
isLocal: resolveD1ExecutionMode(options),
|
|
249
|
-
sql: 'SELECT type, COUNT(*) as cnt FROM
|
|
267
|
+
sql: 'SELECT type, COUNT(*) as cnt FROM zin_trace_entries GROUP BY type ORDER BY type',
|
|
250
268
|
});
|
|
251
269
|
const payload = extractWranglerJson(output);
|
|
252
270
|
if (payload !== null) {
|
|
@@ -277,49 +295,49 @@ const isBuiltInDriver = (driver) => driver === 'sqlite' ||
|
|
|
277
295
|
driver === 'd1-remote';
|
|
278
296
|
const isDestructiveAction = (options) => options['fresh'] === true || options['reset'] === true || options['rollback'] === true;
|
|
279
297
|
const executePrune = async (options) => {
|
|
280
|
-
const {
|
|
281
|
-
const config =
|
|
282
|
-
const resolvedOptions =
|
|
298
|
+
const { TraceConfig } = await loadTraceModule();
|
|
299
|
+
const config = TraceConfig.merge();
|
|
300
|
+
const resolvedOptions = withConfiguredTraceConnection(options, config.connection);
|
|
283
301
|
const hours = typeof options['hours'] === 'string' && options['hours'] !== ''
|
|
284
302
|
? Number.parseInt(options['hours'], 10)
|
|
285
303
|
: config.pruneAfterHours;
|
|
286
304
|
const olderThanMs = hours * 60 * 60 * 1000;
|
|
287
305
|
const keepExceptions = options['keepExceptions'] === true;
|
|
288
|
-
const conn =
|
|
306
|
+
const conn = resolveTraceConnectionConfig(resolvedOptions);
|
|
289
307
|
const threshold = Date.now() - olderThanMs;
|
|
290
308
|
const pruneSql = keepExceptions
|
|
291
|
-
? `DELETE FROM
|
|
292
|
-
: `DELETE FROM
|
|
293
|
-
Logger.info(`Pruning
|
|
309
|
+
? `DELETE FROM zin_trace_entries WHERE created_at < ${String(threshold)} AND type != 'exception'`
|
|
310
|
+
: `DELETE FROM zin_trace_entries WHERE created_at < ${String(threshold)}`;
|
|
311
|
+
Logger.info(`Pruning trace entries older than ${hours}h...`);
|
|
294
312
|
const deleted = isD1ConnectionDriver(conn.driver)
|
|
295
313
|
? executeD1Delete(options, pruneSql)
|
|
296
|
-
: await
|
|
314
|
+
: await withSqlTraceStorage(resolvedOptions, async (storage) => storage.prune(olderThanMs, keepExceptions));
|
|
297
315
|
Logger.info(`Done - removed ${deleted} entries.`);
|
|
298
316
|
};
|
|
299
317
|
const executeClear = async (options) => {
|
|
300
|
-
const {
|
|
301
|
-
const config =
|
|
302
|
-
const resolvedOptions =
|
|
303
|
-
const conn =
|
|
304
|
-
Logger.info('Clearing all
|
|
318
|
+
const { TraceConfig } = await loadTraceModule();
|
|
319
|
+
const config = TraceConfig.merge();
|
|
320
|
+
const resolvedOptions = withConfiguredTraceConnection(options, config.connection);
|
|
321
|
+
const conn = resolveTraceConnectionConfig(resolvedOptions);
|
|
322
|
+
Logger.info('Clearing all trace entries...');
|
|
305
323
|
if (isD1ConnectionDriver(conn.driver)) {
|
|
306
|
-
executeD1Delete(options, 'DELETE FROM
|
|
324
|
+
executeD1Delete(options, 'DELETE FROM zin_trace_entries');
|
|
307
325
|
}
|
|
308
326
|
else {
|
|
309
|
-
await
|
|
327
|
+
await withSqlTraceStorage(resolvedOptions, async (storage) => storage.clear());
|
|
310
328
|
}
|
|
311
329
|
Logger.info('Done - all entries cleared.');
|
|
312
330
|
};
|
|
313
331
|
const executeStatus = async (options, cmd) => {
|
|
314
|
-
const {
|
|
315
|
-
const config =
|
|
316
|
-
const resolvedOptions =
|
|
317
|
-
const connection =
|
|
318
|
-
const conn =
|
|
332
|
+
const { TraceConfig } = await loadTraceModule();
|
|
333
|
+
const config = TraceConfig.merge();
|
|
334
|
+
const resolvedOptions = withConfiguredTraceConnection(options, config.connection);
|
|
335
|
+
const connection = resolveTraceConnectionName(resolvedOptions);
|
|
336
|
+
const conn = resolveTraceConnectionConfig(resolvedOptions);
|
|
319
337
|
const stats = isD1ConnectionDriver(conn.driver)
|
|
320
338
|
? executeD1Stats(options)
|
|
321
|
-
: await
|
|
322
|
-
cmd.info(`
|
|
339
|
+
: await withSqlTraceStorage(resolvedOptions, async (storage) => storage.stats());
|
|
340
|
+
cmd.info(`Trace enabled via env: ${readEnvString('TRACE_ENABLED').trim() || 'false'}`);
|
|
323
341
|
cmd.info(`Connection: ${connection}`);
|
|
324
342
|
cmd.info(`Prune after hours: ${String(config.pruneAfterHours)}`);
|
|
325
343
|
cmd.info(`Expected dashboard URL (if mounted): ${resolveDashboardUrl()}`);
|
|
@@ -335,7 +353,7 @@ const executeStatus = async (options, cmd) => {
|
|
|
335
353
|
const printMigrationStatus = async (migrator, cmd) => {
|
|
336
354
|
const rows = await migrator.status();
|
|
337
355
|
if (rows.length === 0) {
|
|
338
|
-
cmd.info('No
|
|
356
|
+
cmd.info('No trace migrations found.');
|
|
339
357
|
return;
|
|
340
358
|
}
|
|
341
359
|
for (const row of rows) {
|
|
@@ -344,13 +362,13 @@ const printMigrationStatus = async (migrator, cmd) => {
|
|
|
344
362
|
cmd.info(`${tag}: ${row.name}${extra}`);
|
|
345
363
|
}
|
|
346
364
|
};
|
|
347
|
-
const
|
|
365
|
+
const applyTraceMigrations = async (migrator, cmd) => {
|
|
348
366
|
const result = await migrator.migrate();
|
|
349
367
|
if (result.appliedNames.length === 0) {
|
|
350
|
-
cmd.info('No pending
|
|
368
|
+
cmd.info('No pending trace migrations.');
|
|
351
369
|
return;
|
|
352
370
|
}
|
|
353
|
-
cmd.success('
|
|
371
|
+
cmd.success('Trace migrations applied.');
|
|
354
372
|
for (const name of result.appliedNames) {
|
|
355
373
|
cmd.info(`\u2713 ${name}`);
|
|
356
374
|
}
|
|
@@ -363,21 +381,21 @@ const runMigrationActions = async (migrator, options, cmd, driver) => {
|
|
|
363
381
|
}
|
|
364
382
|
if (options['fresh'] === true) {
|
|
365
383
|
await migrator.fresh();
|
|
366
|
-
cmd.success('
|
|
384
|
+
cmd.success('Trace migrations applied (fresh).');
|
|
367
385
|
return;
|
|
368
386
|
}
|
|
369
387
|
if (options['reset'] === true) {
|
|
370
388
|
await migrator.resetAll();
|
|
371
|
-
cmd.success('
|
|
389
|
+
cmd.success('Trace migrations reset.');
|
|
372
390
|
return;
|
|
373
391
|
}
|
|
374
392
|
if (options['rollback'] === true) {
|
|
375
393
|
const steps = parseRollbackSteps(options);
|
|
376
394
|
const result = await migrator.rollbackLastBatch(steps);
|
|
377
|
-
cmd.success(`
|
|
395
|
+
cmd.success(`Trace migrations rolled back (${result.rolledBack}).`);
|
|
378
396
|
return;
|
|
379
397
|
}
|
|
380
|
-
await
|
|
398
|
+
await applyTraceMigrations(migrator, cmd);
|
|
381
399
|
};
|
|
382
400
|
const runMigrationsForConnection = async (conn, options, cmd, interactive) => {
|
|
383
401
|
const destructive = isDestructiveAction(options);
|
|
@@ -386,7 +404,7 @@ const runMigrationsForConnection = async (conn, options, cmd, interactive) => {
|
|
|
386
404
|
interactive,
|
|
387
405
|
destructive,
|
|
388
406
|
force: options['force'] === true,
|
|
389
|
-
message: 'NODE_ENV=production. Continue running
|
|
407
|
+
message: 'NODE_ENV=production. Continue running trace migrations?',
|
|
390
408
|
});
|
|
391
409
|
if (!proceed)
|
|
392
410
|
return;
|
|
@@ -400,9 +418,9 @@ const runMigrationsForConnection = async (conn, options, cmd, interactive) => {
|
|
|
400
418
|
options['fresh'] === true ||
|
|
401
419
|
options['reset'] === true ||
|
|
402
420
|
options['rollback'] === true) {
|
|
403
|
-
throw ErrorFactory.createCliError('D1-backed
|
|
421
|
+
throw ErrorFactory.createCliError('D1-backed trace migrations currently support apply only. Run `zin migrate:trace --local|--remote` without status or rollback flags.');
|
|
404
422
|
}
|
|
405
|
-
const migrationTarget =
|
|
423
|
+
const migrationTarget = resolveTraceMigrationTarget();
|
|
406
424
|
const projectRoot = process.cwd();
|
|
407
425
|
const dbName = getD1DatabaseName(options);
|
|
408
426
|
const isLocal = options['local'] === true || options['remote'] !== true;
|
|
@@ -418,14 +436,14 @@ const runMigrationsForConnection = async (conn, options, cmd, interactive) => {
|
|
|
418
436
|
if (output !== '') {
|
|
419
437
|
cmd.info(output);
|
|
420
438
|
}
|
|
421
|
-
cmd.success('
|
|
439
|
+
cmd.success('Trace D1 migrations applied.');
|
|
422
440
|
return;
|
|
423
441
|
}
|
|
424
442
|
const ormConfig = mapConnectionToOrmConfig(conn);
|
|
425
443
|
const db = Database.create(ormConfig);
|
|
426
444
|
await db.connect();
|
|
427
445
|
try {
|
|
428
|
-
const migrationTarget =
|
|
446
|
+
const migrationTarget = resolveTraceMigrationTarget();
|
|
429
447
|
const migrator = Migrator.create({
|
|
430
448
|
db,
|
|
431
449
|
projectRoot: process.cwd(),
|
|
@@ -447,7 +465,7 @@ const runMigrationsForConnection = async (conn, options, cmd, interactive) => {
|
|
|
447
465
|
await db.disconnect();
|
|
448
466
|
}
|
|
449
467
|
};
|
|
450
|
-
const
|
|
468
|
+
const executeMigrateTrace = async (options, cmd) => {
|
|
451
469
|
const interactive = getInteractive(options);
|
|
452
470
|
const targets = [];
|
|
453
471
|
if (options['all'] === true) {
|
|
@@ -456,20 +474,10 @@ const executeMigrateDebugger = async (options, cmd) => {
|
|
|
456
474
|
}
|
|
457
475
|
}
|
|
458
476
|
else if (isNonEmptyString(options['connection'])) {
|
|
459
|
-
|
|
460
|
-
const connections = databaseConfig.connections;
|
|
461
|
-
targets.push({
|
|
462
|
-
name: selected,
|
|
463
|
-
config: connections[selected] ?? databaseConfig.getConnection(),
|
|
464
|
-
});
|
|
477
|
+
targets.push(resolveNamedTraceConnection(String(options['connection']).trim()));
|
|
465
478
|
}
|
|
466
479
|
else {
|
|
467
|
-
|
|
468
|
-
const connections = databaseConfig.connections;
|
|
469
|
-
targets.push({
|
|
470
|
-
name: selected,
|
|
471
|
-
config: connections[selected] ?? databaseConfig.getConnection(),
|
|
472
|
-
});
|
|
480
|
+
targets.push(resolveNamedTraceConnection(readEnvString('TRACE_DB_CONNECTION').trim() || 'default'));
|
|
473
481
|
}
|
|
474
482
|
let sequence = Promise.resolve();
|
|
475
483
|
for (const { name, config } of targets) {
|
|
@@ -488,49 +496,33 @@ const createProvider = (name, getCommand) => {
|
|
|
488
496
|
getCommand: () => getCommand().getCommand(),
|
|
489
497
|
});
|
|
490
498
|
};
|
|
491
|
-
export const
|
|
492
|
-
|
|
493
|
-
name: '
|
|
494
|
-
description: 'Prune old entries from the
|
|
499
|
+
export const TraceCommands = Object.freeze({
|
|
500
|
+
createTracePruneCommand: () => createTraceCommand({
|
|
501
|
+
name: 'trace:prune',
|
|
502
|
+
description: 'Prune old entries from the trace storage',
|
|
495
503
|
addOptions: addPruneOptions,
|
|
496
|
-
execute: executePrune,
|
|
504
|
+
execute: async (options) => executePrune(options),
|
|
497
505
|
}),
|
|
498
|
-
|
|
499
|
-
name: '
|
|
500
|
-
description: 'Clear all entries from the
|
|
501
|
-
addOptions:
|
|
502
|
-
command
|
|
503
|
-
.option('--local', 'D1 only: run against local D1 database')
|
|
504
|
-
.option('--remote', 'D1 only: run against remote D1 database')
|
|
505
|
-
.option('--database <name>', 'D1 only: Wrangler D1 database binding name');
|
|
506
|
-
},
|
|
506
|
+
createTraceClearCommand: () => createTraceCommand({
|
|
507
|
+
name: 'trace:clear',
|
|
508
|
+
description: 'Clear all entries from the trace storage',
|
|
509
|
+
addOptions: addD1DatabaseOptions,
|
|
507
510
|
execute: async (options) => executeClear(options),
|
|
508
511
|
}),
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
name: 'migrate:debugger',
|
|
526
|
-
description: 'Run debugger package migrations',
|
|
527
|
-
addOptions: addMigrateOptions,
|
|
528
|
-
execute: async (options) => executeMigrateDebugger(options, cmd),
|
|
529
|
-
});
|
|
530
|
-
return cmd;
|
|
531
|
-
},
|
|
532
|
-
createDebuggerPruneProvider: () => createProvider('debugger:prune', DebuggerCommands.createDebuggerPruneCommand),
|
|
533
|
-
createDebuggerClearProvider: () => createProvider('debugger:clear', DebuggerCommands.createDebuggerClearCommand),
|
|
534
|
-
createDebuggerStatusProvider: () => createProvider('debugger:status', DebuggerCommands.createDebuggerStatusCommand),
|
|
535
|
-
createDebuggerMigrateProvider: () => createProvider('migrate:debugger', DebuggerCommands.createDebuggerMigrateCommand),
|
|
512
|
+
createTraceStatusCommand: () => createTraceCommand({
|
|
513
|
+
name: 'trace:status',
|
|
514
|
+
description: 'Show trace storage stats and dashboard location',
|
|
515
|
+
addOptions: addD1DatabaseOptions,
|
|
516
|
+
execute: executeStatus,
|
|
517
|
+
}),
|
|
518
|
+
createTraceMigrateCommand: () => createTraceCommand({
|
|
519
|
+
name: 'migrate:trace',
|
|
520
|
+
description: 'Run trace package migrations',
|
|
521
|
+
addOptions: addMigrateOptions,
|
|
522
|
+
execute: executeMigrateTrace,
|
|
523
|
+
}),
|
|
524
|
+
createTracePruneProvider: () => createProvider('trace:prune', TraceCommands.createTracePruneCommand),
|
|
525
|
+
createTraceClearProvider: () => createProvider('trace:clear', TraceCommands.createTraceClearCommand),
|
|
526
|
+
createTraceStatusProvider: () => createProvider('trace:status', TraceCommands.createTraceStatusCommand),
|
|
527
|
+
createTraceMigrateProvider: () => createProvider('migrate:trace', TraceCommands.createTraceMigrateCommand),
|
|
536
528
|
});
|
|
@@ -8,7 +8,6 @@ export { ContainerWorkersCommand } from '../commands/ContainerWorkersCommand';
|
|
|
8
8
|
export { AddMigrationCommand, CreateCommand, CreateMigrationCommand, } from '../commands/CreateCommand';
|
|
9
9
|
export { D1ProxyCommand } from '../commands/D1ProxyCommand';
|
|
10
10
|
export { DebugCommand } from '../commands/DebugCommand';
|
|
11
|
-
export { DebuggerCommands } from '../commands/DebuggerCommands';
|
|
12
11
|
export { JwtDevCommand } from '../commands/JwtDevCommand';
|
|
13
12
|
export { KvProxyCommand } from '../commands/KvProxyCommand';
|
|
14
13
|
export { LogsCleanupCommand } from '../commands/LogsCleanupCommand';
|
|
@@ -26,5 +25,6 @@ export { RoutesCommand } from '../commands/RoutesCommand';
|
|
|
26
25
|
export { SecretsCommand } from '../commands/SecretsCommand';
|
|
27
26
|
export { StartCommand } from '../commands/StartCommand';
|
|
28
27
|
export { TemplatesCommand } from '../commands/TemplatesCommand';
|
|
28
|
+
export { TraceCommands } from '../commands/TraceCommands';
|
|
29
29
|
export { WranglerDevVarsCommand } from '../commands/WranglerDevVarsCommand';
|
|
30
30
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAChF,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAChF,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAChF,OAAO,EAAE,+BAA+B,EAAE,MAAM,+CAA+C,CAAC;AAChG,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC"}
|
|
@@ -8,7 +8,6 @@ export { ContainerWorkersCommand } from '../commands/ContainerWorkersCommand.js'
|
|
|
8
8
|
export { AddMigrationCommand, CreateCommand, CreateMigrationCommand, } from '../commands/CreateCommand.js';
|
|
9
9
|
export { D1ProxyCommand } from '../commands/D1ProxyCommand.js';
|
|
10
10
|
export { DebugCommand } from '../commands/DebugCommand.js';
|
|
11
|
-
export { DebuggerCommands } from '../commands/DebuggerCommands.js';
|
|
12
11
|
export { JwtDevCommand } from '../commands/JwtDevCommand.js';
|
|
13
12
|
export { KvProxyCommand } from '../commands/KvProxyCommand.js';
|
|
14
13
|
export { LogsCleanupCommand } from '../commands/LogsCleanupCommand.js';
|
|
@@ -26,4 +25,5 @@ export { RoutesCommand } from '../commands/RoutesCommand.js';
|
|
|
26
25
|
export { SecretsCommand } from '../commands/SecretsCommand.js';
|
|
27
26
|
export { StartCommand } from '../commands/StartCommand.js';
|
|
28
27
|
export { TemplatesCommand } from '../commands/TemplatesCommand.js';
|
|
28
|
+
export { TraceCommands } from '../commands/TraceCommands.js';
|
|
29
29
|
export { WranglerDevVarsCommand } from '../commands/WranglerDevVarsCommand.js';
|
package/src/cli/index.d.ts
CHANGED
|
@@ -4,13 +4,12 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export { BaseCommand, type CommandOptions } from './BaseCommand';
|
|
6
6
|
export { CLI } from './CLI';
|
|
7
|
-
export {
|
|
7
|
+
export { ErrorHandler, EXIT_CODES } from './ErrorHandler';
|
|
8
8
|
export { PromptHelper, type PromptOptions } from './PromptHelper';
|
|
9
9
|
export { AddCommand } from './commands/AddCommand';
|
|
10
10
|
export { ConfigCommand } from './commands/ConfigCommand';
|
|
11
11
|
export { D1ProxyCommand } from './commands/D1ProxyCommand';
|
|
12
12
|
export { DebugCommand } from './commands/DebugCommand';
|
|
13
|
-
export { DebuggerCommands } from './commands/DebuggerCommands';
|
|
14
13
|
export { KvProxyCommand } from './commands/KvProxyCommand';
|
|
15
14
|
export { MigrateCommand } from './commands/MigrateCommand';
|
|
16
15
|
export { MySqlProxyCommand } from './commands/MySqlProxyCommand';
|
|
@@ -19,5 +18,6 @@ export { PostgresProxyCommand } from './commands/PostgresProxyCommand';
|
|
|
19
18
|
export { ProxyCommand } from './commands/ProxyCommand';
|
|
20
19
|
export { RedisProxyCommand } from './commands/RedisProxyCommand';
|
|
21
20
|
export { SecretsCommand } from './commands/SecretsCommand';
|
|
21
|
+
export { TraceCommands } from './commands/TraceCommands';
|
|
22
22
|
export { WorkerCommands } from './commands/WorkerCommands';
|
|
23
23
|
//# sourceMappingURL=index.d.ts.map
|
package/src/cli/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cli/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cli/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,KAAK,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGrE,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC"}
|
package/src/cli/index.js
CHANGED
|
@@ -4,14 +4,13 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export { BaseCommand } from './BaseCommand.js';
|
|
6
6
|
export { CLI } from './CLI.js';
|
|
7
|
-
export {
|
|
7
|
+
export { ErrorHandler, EXIT_CODES } from './ErrorHandler.js';
|
|
8
8
|
export { PromptHelper } from './PromptHelper.js';
|
|
9
9
|
// Export commands
|
|
10
10
|
export { AddCommand } from './commands/AddCommand.js';
|
|
11
11
|
export { ConfigCommand } from './commands/ConfigCommand.js';
|
|
12
12
|
export { D1ProxyCommand } from './commands/D1ProxyCommand.js';
|
|
13
13
|
export { DebugCommand } from './commands/DebugCommand.js';
|
|
14
|
-
export { DebuggerCommands } from './commands/DebuggerCommands.js';
|
|
15
14
|
export { KvProxyCommand } from './commands/KvProxyCommand.js';
|
|
16
15
|
export { MigrateCommand } from './commands/MigrateCommand.js';
|
|
17
16
|
export { MySqlProxyCommand } from './commands/MySqlProxyCommand.js';
|
|
@@ -20,4 +19,5 @@ export { PostgresProxyCommand } from './commands/PostgresProxyCommand.js';
|
|
|
20
19
|
export { ProxyCommand } from './commands/ProxyCommand.js';
|
|
21
20
|
export { RedisProxyCommand } from './commands/RedisProxyCommand.js';
|
|
22
21
|
export { SecretsCommand } from './commands/SecretsCommand.js';
|
|
22
|
+
export { TraceCommands } from './commands/TraceCommands.js';
|
|
23
23
|
export { WorkerCommands } from './commands/WorkerCommands.js';
|
package/src/cli.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { BaseCommand } from './cli/BaseCommand';
|
|
|
2
2
|
export type { CommandOptions } from './cli/BaseCommand';
|
|
3
3
|
export { CLI } from './cli/CLI';
|
|
4
4
|
export { ErrorHandler, EXIT_CODES } from './cli/ErrorHandler';
|
|
5
|
-
export {
|
|
5
|
+
export { TraceCommands } from './cli/commands/TraceCommands';
|
|
6
6
|
export { WorkerCommands } from './cli/commands/WorkerCommands';
|
|
7
7
|
export { OptionalCliCommandRegistry } from './cli/OptionalCliCommandRegistry';
|
|
8
8
|
export type { CliCommandProvider } from './cli/OptionalCliCommandRegistry';
|
package/src/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,YAAY,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE7D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,YAAY,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE7D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAC7E,YAAY,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC"}
|
package/src/cli.js
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
export { BaseCommand } from './cli/BaseCommand.js';
|
|
3
3
|
export { CLI } from './cli/CLI.js';
|
|
4
4
|
export { ErrorHandler, EXIT_CODES } from './cli/ErrorHandler.js';
|
|
5
|
-
export {
|
|
5
|
+
export { TraceCommands } from './cli/commands/TraceCommands.js';
|
|
6
6
|
export { WorkerCommands } from './cli/commands/WorkerCommands.js';
|
|
7
7
|
export { OptionalCliCommandRegistry } from './cli/OptionalCliCommandRegistry.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KvLogger.d.ts","sourceRoot":"","sources":["../../../../src/config/logging/KvLogger.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,MAAM,MAAM,UAAU,GAAG;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;IACrD,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;
|
|
1
|
+
{"version":3,"file":"KvLogger.d.ts","sourceRoot":"","sources":["../../../../src/config/logging/KvLogger.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,MAAM,MAAM,UAAU,GAAG;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;IACrD,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAiKF,eAAO,MAAM,QAAQ;mBACE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;EAa/C,CAAC;AAEH,eAAe,QAAQ,CAAC"}
|
|
@@ -46,6 +46,7 @@ const buildKey = (timestampIso) => {
|
|
|
46
46
|
let buffer = [];
|
|
47
47
|
let flushTimer;
|
|
48
48
|
let flushPromise;
|
|
49
|
+
let resolveScheduledFlush;
|
|
49
50
|
const scheduleFlush = async () => {
|
|
50
51
|
if (flushPromise !== undefined)
|
|
51
52
|
return flushPromise;
|
|
@@ -57,6 +58,7 @@ const scheduleFlush = async () => {
|
|
|
57
58
|
await flushNow();
|
|
58
59
|
}
|
|
59
60
|
finally {
|
|
61
|
+
resolveScheduledFlush = undefined;
|
|
60
62
|
resolve(undefined);
|
|
61
63
|
}
|
|
62
64
|
};
|
|
@@ -65,6 +67,7 @@ const scheduleFlush = async () => {
|
|
|
65
67
|
void run();
|
|
66
68
|
return;
|
|
67
69
|
}
|
|
70
|
+
resolveScheduledFlush = resolve;
|
|
68
71
|
flushTimer = globalThis.setTimeout(() => {
|
|
69
72
|
flushTimer = undefined;
|
|
70
73
|
void run();
|
|
@@ -122,6 +125,20 @@ const flushSoon = async () => {
|
|
|
122
125
|
});
|
|
123
126
|
return flushPromise;
|
|
124
127
|
};
|
|
128
|
+
const flushImmediately = async () => {
|
|
129
|
+
const pendingResolve = resolveScheduledFlush;
|
|
130
|
+
if (flushTimer !== undefined) {
|
|
131
|
+
globalThis.clearTimeout(flushTimer);
|
|
132
|
+
flushTimer = undefined;
|
|
133
|
+
resolveScheduledFlush = undefined;
|
|
134
|
+
flushPromise = undefined;
|
|
135
|
+
}
|
|
136
|
+
const immediatePromise = flushSoon();
|
|
137
|
+
if (pendingResolve !== undefined) {
|
|
138
|
+
void immediatePromise.finally(() => pendingResolve());
|
|
139
|
+
}
|
|
140
|
+
return immediatePromise;
|
|
141
|
+
};
|
|
125
142
|
export const KvLogger = Object.freeze({
|
|
126
143
|
async enqueue(event) {
|
|
127
144
|
if (!isEnabled())
|
|
@@ -130,12 +147,7 @@ export const KvLogger = Object.freeze({
|
|
|
130
147
|
// Basic size guard: flush if it gets too large
|
|
131
148
|
const maxBatch = 100;
|
|
132
149
|
if (buffer.length >= maxBatch) {
|
|
133
|
-
|
|
134
|
-
if (flushTimer !== undefined) {
|
|
135
|
-
globalThis.clearTimeout(flushTimer);
|
|
136
|
-
flushTimer = undefined;
|
|
137
|
-
}
|
|
138
|
-
return flushSoon();
|
|
150
|
+
return flushImmediately();
|
|
139
151
|
}
|
|
140
152
|
return scheduleFlush();
|
|
141
153
|
},
|