@nmakarov/cli-toolkit 0.27.0 → 0.29.0
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/dist/cli-runner.cjs +43 -11
- package/dist/cli-runner.cjs.map +1 -1
- package/dist/cli-runner.js +43 -11
- package/dist/cli-runner.js.map +1 -1
- package/dist/index.cjs +45 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +45 -13
- package/dist/index.js.map +1 -1
- package/dist/init.cjs +19 -6
- package/dist/init.cjs.map +1 -1
- package/dist/init.js +19 -6
- package/dist/init.js.map +1 -1
- package/dist/params.cjs +8 -4
- package/dist/params.cjs.map +1 -1
- package/dist/params.js +8 -4
- package/dist/params.js.map +1 -1
- package/dist/s3.cjs +1 -0
- package/dist/s3.cjs.map +1 -1
- package/dist/s3.js +1 -0
- package/dist/s3.js.map +1 -1
- package/dist/tasks.cjs +25 -7
- package/dist/tasks.cjs.map +1 -1
- package/dist/tasks.js +25 -7
- package/dist/tasks.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1692,7 +1692,8 @@ var Params = class _Params {
|
|
|
1692
1692
|
/**
|
|
1693
1693
|
* Resolved early in constructor so cleanup does not read params lazily.
|
|
1694
1694
|
* One of: false (off) | "end" (print at exit) | "top" (print after init,
|
|
1695
|
-
* via context.showUsedParamsIfNeeded())
|
|
1695
|
+
* via context.showUsedParamsIfNeeded()) | "stop" (print after init, then
|
|
1696
|
+
* exit the process — also via context.showUsedParamsIfNeeded()).
|
|
1696
1697
|
*/
|
|
1697
1698
|
_showUsedParamsMode = false;
|
|
1698
1699
|
/** Guard so the dump prints at most once (top OR end, never both). */
|
|
@@ -1716,8 +1717,9 @@ var Params = class _Params {
|
|
|
1716
1717
|
* (absent) / --no-showUsedParams / =false -> false (off)
|
|
1717
1718
|
* --showUsedParams / =true -> "end" (print at exit)
|
|
1718
1719
|
* --showUsedParams=top -> "top" (print after init)
|
|
1719
|
-
*
|
|
1720
|
-
*
|
|
1720
|
+
* --showUsedParams=stop -> "stop" (print after init, then exit)
|
|
1721
|
+
* Read raw (uncoerced) from args so the string "top"/"stop" isn't forced to
|
|
1722
|
+
* a boolean, then track it under the "script" module for the dump itself.
|
|
1721
1723
|
*/
|
|
1722
1724
|
_resolveShowUsedParams() {
|
|
1723
1725
|
const raw = this.args.get("showUsedParams");
|
|
@@ -1727,6 +1729,8 @@ var Params = class _Params {
|
|
|
1727
1729
|
mode = false;
|
|
1728
1730
|
} else if (typeof raw === "string" && raw.trim().toLowerCase() === "top") {
|
|
1729
1731
|
mode = "top";
|
|
1732
|
+
} else if (typeof raw === "string" && raw.trim().toLowerCase() === "stop") {
|
|
1733
|
+
mode = "stop";
|
|
1730
1734
|
} else {
|
|
1731
1735
|
const s = typeof raw === "string" ? raw.trim().toLowerCase() : raw;
|
|
1732
1736
|
const falsey = s === false || s === "false" || s === "0" || s === "no" || s === "off";
|
|
@@ -1740,7 +1744,7 @@ var Params = class _Params {
|
|
|
1740
1744
|
getShowUsedParams() {
|
|
1741
1745
|
return this._showUsedParamsMode !== false;
|
|
1742
1746
|
}
|
|
1743
|
-
/** Resolved mode: false | "end" | "top". */
|
|
1747
|
+
/** Resolved mode: false | "end" | "top" | "stop". */
|
|
1744
1748
|
getShowUsedParamsMode() {
|
|
1745
1749
|
return this._showUsedParamsMode;
|
|
1746
1750
|
}
|
|
@@ -3786,6 +3790,7 @@ var S3 = class _S3 {
|
|
|
3786
3790
|
secretAccessKey: config2.secretAccessKey
|
|
3787
3791
|
};
|
|
3788
3792
|
}
|
|
3793
|
+
process.env.AWS_SDK_JS_NODE_VERSION_SUPPORT_WARNING_DISABLED ??= "true";
|
|
3789
3794
|
this.client = new S3Client(clientConfig);
|
|
3790
3795
|
}
|
|
3791
3796
|
// ── info ────────────────────────────────────────────────────────────────
|
|
@@ -4317,9 +4322,18 @@ function setup(opts = {}) {
|
|
|
4317
4322
|
// the used-params list now (after the script has initialized all its
|
|
4318
4323
|
// own components), instead of at exit. No-op for the default mode,
|
|
4319
4324
|
// which prints at exit via the cleanup registered by Params.
|
|
4325
|
+
//
|
|
4326
|
+
// --showUsedParams=stop behaves like "top" but then exits immediately —
|
|
4327
|
+
// a quick "show me the figured params and quit" that skips the flow's
|
|
4328
|
+
// actual work. Like --stopAfter=init, this is a hard exit(0) (registered
|
|
4329
|
+
// cleanups are skipped); call it once components/params are resolved.
|
|
4320
4330
|
showUsedParamsIfNeeded: () => {
|
|
4321
|
-
|
|
4322
|
-
|
|
4331
|
+
const mode = params.getShowUsedParamsMode?.();
|
|
4332
|
+
if (mode !== "top" && mode !== "stop") return;
|
|
4333
|
+
params.printUsedParams(logger);
|
|
4334
|
+
if (mode === "stop") {
|
|
4335
|
+
logger.debug?.("[showUsedParams=stop] params printed \u2014 exiting");
|
|
4336
|
+
process.exit(0);
|
|
4323
4337
|
}
|
|
4324
4338
|
}
|
|
4325
4339
|
};
|
|
@@ -4443,7 +4457,7 @@ function defineTasksTable(t, db, tableNameForIndex) {
|
|
|
4443
4457
|
t.timestamp("past_due").defaultTo(null);
|
|
4444
4458
|
t.text("name").notNullable();
|
|
4445
4459
|
t.text("opid");
|
|
4446
|
-
t.
|
|
4460
|
+
t.jsonb("params");
|
|
4447
4461
|
t.text("service_group");
|
|
4448
4462
|
t.integer("instance_number");
|
|
4449
4463
|
t.text("service_name");
|
|
@@ -4452,7 +4466,7 @@ function defineTasksTable(t, db, tableNameForIndex) {
|
|
|
4452
4466
|
t.timestamp("status_changed_at").defaultTo(null);
|
|
4453
4467
|
t.text("progress");
|
|
4454
4468
|
t.boolean("success");
|
|
4455
|
-
t.
|
|
4469
|
+
t.jsonb("results");
|
|
4456
4470
|
t.index(["service_group", "status", "priority", "created_at"], `${tableNameForIndex}_claim_idx`);
|
|
4457
4471
|
t.index(["service_group", "name"], `${tableNameForIndex}_group_name_idx`);
|
|
4458
4472
|
}
|
|
@@ -4467,11 +4481,29 @@ function taskHistoryInsertFromQueueRow(row, overrides) {
|
|
|
4467
4481
|
async function ensureTaskTables(context, options = {}) {
|
|
4468
4482
|
const queueName = options.queueName ?? "tasks";
|
|
4469
4483
|
const recreate = options.recreate ?? false;
|
|
4484
|
+
const dryRun = options.dryRun ?? false;
|
|
4470
4485
|
const db = getDb(context);
|
|
4486
|
+
const log = context.logger ?? console;
|
|
4471
4487
|
const { tasksTable, historyTable, registryTable } = queueToTableNames(queueName);
|
|
4472
4488
|
const needsTasks = recreate ? true : !await db.tableExists(tasksTable);
|
|
4473
4489
|
const needsHistory = recreate ? true : !await db.tableExists(historyTable);
|
|
4474
4490
|
const needsRegistry = recreate ? true : !await db.tableExists(registryTable);
|
|
4491
|
+
if (dryRun) {
|
|
4492
|
+
const plan = [];
|
|
4493
|
+
if (recreate) {
|
|
4494
|
+
plan.push(`DROP TABLE IF EXISTS ${historyTable}, ${tasksTable}, ${registryTable}`);
|
|
4495
|
+
}
|
|
4496
|
+
if (needsTasks) plan.push(`CREATE TABLE ${tasksTable} (tasks queue)`);
|
|
4497
|
+
if (needsHistory) plan.push(`CREATE TABLE ${historyTable} (history mirror)`);
|
|
4498
|
+
if (needsRegistry) plan.push(`CREATE TABLE ${registryTable} (services registry)`);
|
|
4499
|
+
if (plan.length === 0) {
|
|
4500
|
+
log.info?.(`[tasks-schema] dryRun \u2014 queue "${queueName}" already up to date; no DDL`);
|
|
4501
|
+
} else {
|
|
4502
|
+
log.info?.(`[tasks-schema] dryRun \u2014 would run ${plan.length} statement(s) for queue "${queueName}":`);
|
|
4503
|
+
for (const s of plan) log.info?.(` - ${s}`);
|
|
4504
|
+
}
|
|
4505
|
+
return;
|
|
4506
|
+
}
|
|
4475
4507
|
if (recreate) {
|
|
4476
4508
|
await db.schema.dropTableIfExists(historyTable);
|
|
4477
4509
|
await db.schema.dropTableIfExists(tasksTable);
|
|
@@ -5914,8 +5946,7 @@ function forwardChildLogToParent(context, prefix, message) {
|
|
|
5914
5946
|
}
|
|
5915
5947
|
function buildNodeArgs(scriptPath, cliArgs) {
|
|
5916
5948
|
const inheritedExecArgs = Array.isArray(process.execArgv) ? [...process.execArgv] : [];
|
|
5917
|
-
|
|
5918
|
-
return hasTsRuntimeInParent ? [...inheritedExecArgs, scriptPath, ...cliArgs] : ["--import", "tsx", scriptPath, ...cliArgs];
|
|
5949
|
+
return [...inheritedExecArgs, scriptPath, ...cliArgs];
|
|
5919
5950
|
}
|
|
5920
5951
|
function resolveTasksTableName(context) {
|
|
5921
5952
|
return context.tasksQueueName || context.params?.get?.("table") || "tasks";
|
|
@@ -6155,9 +6186,8 @@ async function executeClaimedTask(context, tasksTable, historyTable, row, regist
|
|
|
6155
6186
|
const dbName = String(context?.params?.get?.("dbName") || "local");
|
|
6156
6187
|
const tableName = String(context?.params?.get?.("table") || "tasks");
|
|
6157
6188
|
const fallbackRecoverCommand = [
|
|
6158
|
-
"
|
|
6159
|
-
"
|
|
6160
|
-
"examples/tasks/recover-task.ts",
|
|
6189
|
+
"node",
|
|
6190
|
+
"examples/tasks/recover-task.js",
|
|
6161
6191
|
`--dbName='${dbName.replace(/'/g, `'\\''`)}'`,
|
|
6162
6192
|
`--table='${tableName.replace(/'/g, `'\\''`)}'`,
|
|
6163
6193
|
`--id='${String(row.id).replace(/'/g, `'\\''`)}'`
|
|
@@ -6223,6 +6253,8 @@ async function claimNextRunnableTask(context, tasksTable, serviceGroup, registry
|
|
|
6223
6253
|
const db = getDb3(context);
|
|
6224
6254
|
let query = db(tasksTable).where({ status: "idle" }).where(function() {
|
|
6225
6255
|
this.whereNull("service_group").orWhere({ service_group: serviceGroup });
|
|
6256
|
+
}).where(function() {
|
|
6257
|
+
this.whereNull("next_run_at").orWhere("next_run_at", "<=", db.fn.now());
|
|
6226
6258
|
}).orderByRaw("CASE WHEN past_due IS NULL THEN 1 ELSE 0 END ASC").orderBy([{ column: "priority", order: "asc" }]).orderByRaw("CASE WHEN completed_at IS NULL THEN 0 ELSE 1 END ASC").orderBy([{ column: "completed_at", order: "asc" }, { column: "created_at", order: "asc" }]).limit(scanLimit);
|
|
6227
6259
|
if (taskNames && taskNames.length > 0) {
|
|
6228
6260
|
query = query.whereIn("name", taskNames);
|