@nmakarov/cli-toolkit 0.61.0 → 0.63.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.
@@ -2389,6 +2389,9 @@ var Logger = class _Logger {
2389
2389
  const message = this.inspectChunks([operation, ...chunks]);
2390
2390
  this.out({ level: "response", message });
2391
2391
  }
2392
+ /**
2393
+ * @returns {boolean} true when the progress line was emitted (not throttled)
2394
+ */
2392
2395
  progress(message, opts) {
2393
2396
  const { prefix, count, total } = opts;
2394
2397
  const paddedTotal = String(total).length;
@@ -2422,7 +2425,9 @@ var Logger = class _Logger {
2422
2425
  if (this.options.progressThrottle && prefix) {
2423
2426
  this.lastProgressTimes[prefix] = Date.now();
2424
2427
  }
2428
+ return true;
2425
2429
  }
2430
+ return false;
2426
2431
  }
2427
2432
  shouldOutputProgress(prefix, count, total) {
2428
2433
  if (!this.options.progressThrottle) {
@@ -2825,13 +2830,15 @@ var CONNECTION_ERROR_CODES = /* @__PURE__ */ new Set([
2825
2830
  "57P02",
2826
2831
  "57P03"
2827
2832
  ]);
2828
- var CONNECTION_ERROR_MESSAGE_RE = /connection (terminated|ended|closed|destroyed|reset|refused|not open)|Connection terminated unexpectedly|Client has encountered a connection error|server closed the connection|Cannot use a pool after calling end|This socket has been ended|connect ECONNRESET|Timeout acquiring a connection/i;
2833
+ var CONNECTION_ERROR_MESSAGE_RE = /connection (terminated|ended|closed|destroyed|reset|refused|not open)|Connection terminated unexpectedly|Client has encountered a connection error|server closed the connection|Cannot use a pool after calling end|This socket has been ended|connect ECONNRESET/i;
2829
2834
  var Db = class _Db {
2830
2835
  static async init(context, options = {}) {
2831
2836
  const buildConfig = async () => {
2832
2837
  const defs2 = {
2833
2838
  dbName: "string",
2834
- dbProfile: "boolean default false"
2839
+ dbProfile: "boolean default false",
2840
+ /** Cap knex pool size (default 10). Size ≈ expected concurrency + headroom. */
2841
+ dbPoolMax: "number"
2835
2842
  };
2836
2843
  const discovered = context?.params?.getAllForModule?.("db", defs2) ?? {};
2837
2844
  const merged = { ...discovered, ...options };
@@ -2890,12 +2897,23 @@ var Db = class _Db {
2890
2897
  context?.args?.env,
2891
2898
  merged.name
2892
2899
  );
2900
+ const poolMaxRaw = merged.dbPoolMax ?? merged.pool?.max;
2901
+ const poolMax = Number(poolMaxRaw);
2902
+ const pool = {
2903
+ ...KNEX_DEFAULTS.pool,
2904
+ ...merged.pool && typeof merged.pool === "object" ? merged.pool : {}
2905
+ };
2906
+ if (Number.isFinite(poolMax) && poolMax >= 1) {
2907
+ pool.max = Math.floor(poolMax);
2908
+ }
2893
2909
  return {
2894
2910
  ...KNEX_DEFAULTS,
2895
2911
  connectionString: dbConnectionString,
2896
2912
  name: displayName,
2897
2913
  profile: !!dbProfile,
2898
- logger: context.logger
2914
+ logger: context.logger,
2915
+ pool,
2916
+ ...merged.acquireConnectionTimeout != null ? { acquireConnectionTimeout: merged.acquireConnectionTimeout } : {}
2899
2917
  };
2900
2918
  };
2901
2919
  const config2 = context?.params?.runWithModuleAsync ? await context.params.runWithModuleAsync("db", buildConfig) : await buildConfig();
@@ -4039,6 +4057,34 @@ async function updateTaskProgress(context, tasksTable, taskId, progress) {
4039
4057
  progress: typeof progress === "string" ? progress : JSON.stringify(progress)
4040
4058
  });
4041
4059
  }
4060
+ function createTaskProgressReporter(context, tasksTable, taskId) {
4061
+ let pump = null;
4062
+ let pending = void 0;
4063
+ let hasPending = false;
4064
+ return (progress) => {
4065
+ pending = progress;
4066
+ hasPending = true;
4067
+ if (pump) return pump;
4068
+ pump = (async () => {
4069
+ try {
4070
+ while (hasPending) {
4071
+ hasPending = false;
4072
+ const value = pending;
4073
+ try {
4074
+ await updateTaskProgress(context, tasksTable, taskId, value);
4075
+ } catch (err) {
4076
+ context.logger?.warn?.(
4077
+ `[tasks] progress update failed for ${taskId}: ${err?.message ?? err}`
4078
+ );
4079
+ }
4080
+ }
4081
+ } finally {
4082
+ pump = null;
4083
+ }
4084
+ })();
4085
+ return pump;
4086
+ };
4087
+ }
4042
4088
 
4043
4089
  // src/tasks/servicesRegistry.js
4044
4090
  function getDb2(context) {
@@ -6707,7 +6753,8 @@ async function executeClaimedTask(context, tasksTable, historyTable, row, regist
6707
6753
  try {
6708
6754
  taskInstance = new TaskClass(context, row);
6709
6755
  runningTaskInstances.set(row.id, taskInstance);
6710
- const runResult = await taskInstance.run((progress) => updateTaskProgress(context, tasksTable, row.id, progress));
6756
+ const reportProgress = createTaskProgressReporter(context, tasksTable, row.id);
6757
+ const runResult = await taskInstance.run(reportProgress);
6711
6758
  success = !!runResult?.success;
6712
6759
  results = runResult?.results ?? null;
6713
6760
  } catch (error) {