@nmakarov/cli-toolkit 0.43.0 → 0.44.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/index.js CHANGED
@@ -2283,23 +2283,18 @@ function defaultFileSynopsisFunction(fileEntry, data) {
2283
2283
  const timestamps = [];
2284
2284
  const statusCounts = {};
2285
2285
  for (const item of data) {
2286
- let ts = null;
2287
- let status = null;
2286
+ if (!item || typeof item !== "object") continue;
2288
2287
  for (const [key, value] of Object.entries(item)) {
2289
2288
  const k = key.toLowerCase();
2290
- if (k === "modificationtimestamp") {
2291
- ts = new Date(value).getTime();
2289
+ if (k.endsWith("modificationtimestamp") && value != null && value !== "") {
2290
+ const ts = new Date(value).getTime();
2291
+ if (!Number.isNaN(ts)) timestamps.push(ts);
2292
2292
  }
2293
- if (k === "standardstatus") {
2294
- status = value;
2293
+ if (k === "standardstatus" && value != null && value !== "") {
2294
+ const status = String(value);
2295
+ statusCounts[status] = (statusCounts[status] || 0) + 1;
2295
2296
  }
2296
2297
  }
2297
- if (ts && !isNaN(ts)) {
2298
- timestamps.push(ts);
2299
- }
2300
- if (status !== null && status !== void 0) {
2301
- statusCounts[status] = (statusCounts[status] || 0) + 1;
2302
- }
2303
2298
  }
2304
2299
  const result = { ...fileEntry };
2305
2300
  if (timestamps.length) {
@@ -2318,27 +2313,38 @@ function defaultVersionSynopsisFunction(metadata) {
2318
2313
  const timestamps = [];
2319
2314
  const statusCounts = {};
2320
2315
  for (const file of metadata.files) {
2321
- if (file.minModificationTimestamp) {
2316
+ if (file?.minModificationTimestamp) {
2322
2317
  const minTs = new Date(file.minModificationTimestamp).getTime();
2323
- if (!isNaN(minTs)) timestamps.push(minTs);
2318
+ if (!Number.isNaN(minTs)) timestamps.push(minTs);
2324
2319
  }
2325
- if (file.maxModificationTimestamp) {
2320
+ if (file?.maxModificationTimestamp) {
2326
2321
  const maxTs = new Date(file.maxModificationTimestamp).getTime();
2327
- if (!isNaN(maxTs)) timestamps.push(maxTs);
2322
+ if (!Number.isNaN(maxTs)) timestamps.push(maxTs);
2328
2323
  }
2329
- if (file.StandardStatuses && typeof file.StandardStatuses === "object") {
2324
+ if (file?.StandardStatuses && typeof file.StandardStatuses === "object") {
2330
2325
  for (const [status, count] of Object.entries(file.StandardStatuses)) {
2331
- statusCounts[status] = (statusCounts[status] || 0) + count;
2326
+ statusCounts[status] = (statusCounts[status] || 0) + Number(count || 0);
2332
2327
  }
2333
2328
  }
2334
2329
  }
2335
2330
  const result = { ...metadata };
2331
+ const synopsis = {
2332
+ ...metadata.synopsis && typeof metadata.synopsis === "object" ? metadata.synopsis : {}
2333
+ };
2336
2334
  if (timestamps.length) {
2337
- result.minModificationTimestamp = new Date(Math.min(...timestamps)).toISOString();
2338
- result.maxModificationTimestamp = new Date(Math.max(...timestamps)).toISOString();
2335
+ const minIso = new Date(Math.min(...timestamps)).toISOString();
2336
+ const maxIso = new Date(Math.max(...timestamps)).toISOString();
2337
+ result.minModificationTimestamp = minIso;
2338
+ result.maxModificationTimestamp = maxIso;
2339
+ synopsis.minModificationTimestamp = minIso;
2340
+ synopsis.maxModificationTimestamp = maxIso;
2339
2341
  }
2340
2342
  if (Object.keys(statusCounts).length > 0) {
2341
2343
  result.StandardStatuses = statusCounts;
2344
+ synopsis.StandardStatuses = statusCounts;
2345
+ }
2346
+ if (Object.keys(synopsis).length) {
2347
+ result.synopsis = synopsis;
2342
2348
  }
2343
2349
  return result;
2344
2350
  }
@@ -6321,22 +6327,46 @@ async function ensureTaskTables(context, options = {}) {
6321
6327
  }
6322
6328
  }
6323
6329
  const { actions } = await ensureSchema(db, spec, { dryRun, logger: context.logger });
6330
+ const legacyDrops = await dropLegacyTaskNameColumn(db, [tasksTable, historyTable], {
6331
+ dryRun,
6332
+ log,
6333
+ label
6334
+ });
6335
+ const allActions = [...actions, ...legacyDrops];
6324
6336
  if (dryRun) {
6325
- if (actions.length === 0) {
6337
+ if (allActions.length === 0) {
6326
6338
  log.info?.(`[tasks-schema] dryRun \u2014 ${label}: queue "${queueName}" already up to date; no DDL`);
6327
6339
  } else {
6328
6340
  log.info?.(
6329
- `[tasks-schema] dryRun \u2014 ${label}: would run ${actions.length} statement(s) for queue "${queueName}":`
6341
+ `[tasks-schema] dryRun \u2014 ${label}: would run ${allActions.length} statement(s) for queue "${queueName}":`
6330
6342
  );
6331
- for (const s of actions) log.info?.(` - ${s}`);
6343
+ for (const s of allActions) log.info?.(` - ${s}`);
6332
6344
  }
6333
- } else if (actions.length > 0) {
6345
+ } else if (allActions.length > 0) {
6334
6346
  log.info?.(
6335
- `[tasks-schema] ${label}: applied ${actions.length} DDL statement(s) for queue "${queueName}"`
6347
+ `[tasks-schema] ${label}: applied ${allActions.length} DDL statement(s) for queue "${queueName}"`
6336
6348
  );
6337
6349
  }
6338
6350
  }
6339
6351
  }
6352
+ async function dropLegacyTaskNameColumn(db, tableNames, { dryRun, log, label }) {
6353
+ const actions = [];
6354
+ for (const table of tableNames) {
6355
+ if (!await db.tableExists(table).catch(() => false)) continue;
6356
+ const hasTask = await db.schema.hasColumn(table, "task");
6357
+ const hasName = await db.schema.hasColumn(table, "name");
6358
+ if (!hasTask || !hasName) continue;
6359
+ const sql = `ALTER TABLE "${table}" DROP COLUMN IF EXISTS "task"`;
6360
+ actions.push(sql);
6361
+ if (dryRun) {
6362
+ log?.info?.(`[tasks-schema] dryRun \u2014 ${label}: ${sql}`);
6363
+ } else {
6364
+ await db.raw(sql);
6365
+ log?.info?.(`[tasks-schema] ${label}: dropped legacy column ${table}.task`);
6366
+ }
6367
+ }
6368
+ return actions;
6369
+ }
6340
6370
  async function enqueueTask(context, options) {
6341
6371
  const db = getDb(context);
6342
6372
  const queueName = options.queueName ?? "tasks";
@@ -6353,7 +6383,7 @@ async function enqueueTask(context, options) {
6353
6383
  } else if (schedule) {
6354
6384
  nextRunAt = nextTimeMatch(schedule, /* @__PURE__ */ new Date());
6355
6385
  }
6356
- await db(tasksTable).insert({
6386
+ const row = {
6357
6387
  id,
6358
6388
  name,
6359
6389
  params: toJsonColumn(options.params ?? null),
@@ -6367,9 +6397,21 @@ async function enqueueTask(context, options) {
6367
6397
  server_name: options.serverName ?? null,
6368
6398
  status: "idle",
6369
6399
  status_changed_at: db.fn.now()
6370
- });
6400
+ };
6401
+ if (await tableHasLegacyTaskColumn(db, tasksTable)) {
6402
+ row.task = name;
6403
+ }
6404
+ await db(tasksTable).insert(row);
6371
6405
  return id;
6372
6406
  }
6407
+ var legacyTaskColumnCache = /* @__PURE__ */ new Map();
6408
+ async function tableHasLegacyTaskColumn(db, tableName) {
6409
+ const key = `${db?.config?.name ?? "db"}:${tableName}`;
6410
+ if (!legacyTaskColumnCache.has(key)) {
6411
+ legacyTaskColumnCache.set(key, await db.schema.hasColumn(tableName, "task"));
6412
+ }
6413
+ return legacyTaskColumnCache.get(key);
6414
+ }
6373
6415
  async function updateTaskProgress(context, tasksTable, taskId, progress) {
6374
6416
  const db = getDb(context);
6375
6417
  await db(tasksTable).where({ id: taskId }).update({