@qodalis/cli-server-jobs 2.4.2 → 2.5.1

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/public-api.mjs CHANGED
@@ -3,6 +3,14 @@ import { DefaultLibraryAuthor, CliIcon, writeWrapped, writeUsage, writeExamples,
3
3
  // src/lib/processors/cli-jobs-command-processor.ts
4
4
 
5
5
  // src/lib/services/cli-jobs-service.ts
6
+ function jobHasTags(job, tags) {
7
+ const own = new Set((job.tags ?? []).map((t) => t.toLowerCase()));
8
+ return tags.every((t) => own.has(t.toLowerCase()));
9
+ }
10
+ function parseTagArgs(value) {
11
+ const values = Array.isArray(value) ? value : value === void 0 || value === null || value === true ? [] : [value];
12
+ return values.flatMap((v) => String(v).split(",")).map((t) => t.trim()).filter(Boolean);
13
+ }
6
14
  var CliJobsService = class {
7
15
  constructor(baseUrl, headers = {}) {
8
16
  this.baseUrl = baseUrl;
@@ -35,8 +43,15 @@ var CliJobsService = class {
35
43
  }
36
44
  return JSON.parse(text);
37
45
  }
38
- async listJobs() {
39
- return this.request("");
46
+ /**
47
+ * The jobs; with `tags`, only those that have every tag (ignoring case). The server filters
48
+ * (`?tag=`), and the list is filtered here too, so a server without job tags lists nothing
49
+ * for a tag filter instead of every job.
50
+ */
51
+ async listJobs(tags = []) {
52
+ const query = tags.map((t) => `tag=${encodeURIComponent(t)}`).join("&");
53
+ const jobs = await this.request(query ? `?${query}` : "");
54
+ return tags.length ? jobs.filter((j) => jobHasTags(j, tags)) : jobs;
40
55
  }
41
56
  async getJob(id) {
42
57
  return this.request(`/${encodeURIComponent(id)}`);
@@ -184,6 +199,9 @@ function formatRunning(job) {
184
199
  if (job.queued) parts.push("1 queued");
185
200
  return parts.join(", ");
186
201
  }
202
+ function formatTags(tags) {
203
+ return tags && tags.length > 0 ? tags.join(", ") : "-";
204
+ }
187
205
  function formatDuration(ms) {
188
206
  if (ms == null) return "-";
189
207
  if (ms < 1e3) return `${ms}ms`;
@@ -281,12 +299,14 @@ var CliJobsCommandProcessor = class {
281
299
  context.writer.writeln();
282
300
  writeUsage(context, [
283
301
  ["server jobs list", t.t("cli.server.jobs.list.help.jobs_all_connected_servers", "Jobs on all connected servers")],
284
- ["server jobs ls --group <name>", t.t("cli.server.jobs.list.help.only_one_group", "Only one group")]
302
+ ["server jobs ls --group <name>", t.t("cli.server.jobs.list.help.only_one_group", "Only one group")],
303
+ ["server jobs ls --tag <tag> [--tag <tag>]", t.t("cli.server.jobs.list.help.only_tagged", "Only the jobs that have every tag given")]
285
304
  ]);
286
305
  context.writer.writeln();
287
306
  writeExamples(context, [
288
307
  ["server jobs ls --server node", t.t("cli.server.jobs.list.help.jobs_node_server", "Jobs on the node server")],
289
- ["server jobs list --group reports", t.t("cli.server.jobs.list.help.jobs_reports_group", "Jobs in the reports group")]
308
+ ["server jobs list --group reports", t.t("cli.server.jobs.list.help.jobs_reports_group", "Jobs in the reports group")],
309
+ ["server jobs list --tag country:ro --tag bank", t.t("cli.server.jobs.list.help.jobs_tagged", "Jobs tagged both country:ro and bank")]
290
310
  ]);
291
311
  },
292
312
  aliases: ["ls"],
@@ -297,6 +317,12 @@ var CliJobsCommandProcessor = class {
297
317
  description: "Filter jobs by group",
298
318
  required: false,
299
319
  type: "string"
320
+ },
321
+ {
322
+ name: "tag",
323
+ description: "Only jobs that have this tag (repeatable or comma-separated; every tag must match)",
324
+ required: false,
325
+ type: "array"
300
326
  }
301
327
  ],
302
328
  processCommand: async (cmd, context) => {
@@ -611,10 +637,11 @@ var CliJobsCommandProcessor = class {
611
637
  return;
612
638
  }
613
639
  const groupFilter = cmd.args["group"];
640
+ const tagFilter = parseTagArgs(cmd.args["tag"]);
614
641
  const multiServer = services.length > 1;
615
642
  for (const { name, service } of services) {
616
643
  try {
617
- let jobs = await service.listJobs();
644
+ let jobs = await service.listJobs(tagFilter);
618
645
  if (groupFilter) {
619
646
  jobs = jobs.filter(
620
647
  (j) => j.group?.toLowerCase() === groupFilter.toLowerCase()
@@ -632,9 +659,11 @@ var CliJobsCommandProcessor = class {
632
659
  context.writer.writeInfo(" No jobs found.");
633
660
  continue;
634
661
  }
662
+ const showTags = jobs.some((j) => (j.tags?.length ?? 0) > 0);
635
663
  const headers = [
636
664
  "Name",
637
665
  "Group",
666
+ ...showTags ? ["Tags"] : [],
638
667
  "Status",
639
668
  "Schedule",
640
669
  "Last Run",
@@ -644,6 +673,7 @@ var CliJobsCommandProcessor = class {
644
673
  const rows = jobs.map((j) => [
645
674
  j.name,
646
675
  j.group ?? "-",
676
+ ...showTags ? [formatTags(j.tags)] : [],
647
677
  statusColor(j.status, context.writer),
648
678
  j.schedule ?? (formatSpan(j.interval) ? `every ${formatSpan(j.interval)}` : "-"),
649
679
  formatRelativeTime(j.lastRunAt),
@@ -680,6 +710,7 @@ var CliJobsCommandProcessor = class {
680
710
  ["Name", job.name],
681
711
  ["Description", job.description],
682
712
  ["Group", job.group ?? "-"],
713
+ ["Tags", formatTags(job.tags)],
683
714
  ["Status", statusColor(job.status, context.writer)],
684
715
  [
685
716
  "Schedule",
@@ -936,6 +967,10 @@ var CliJobsCommandProcessor = class {
936
967
  const newGroup = await ask(`Group [${job.group ?? "none"}]: `);
937
968
  if (newGroup == null) return cancelled();
938
969
  if (newGroup) update.group = newGroup;
970
+ const newTags = await ask(`Tags, comma-separated, - for none [${formatTags(job.tags)}]: `);
971
+ if (newTags == null) return cancelled();
972
+ if (newTags.trim() === "-") update.tags = null;
973
+ else if (newTags.trim()) update.tags = parseTagArgs(newTags);
939
974
  const currentSchedule = job.schedule ?? (formatSpan(job.interval) ? `interval: ${formatSpan(job.interval)}` : "none");
940
975
  const newSchedule = await ask(
941
976
  `Cron schedule [${currentSchedule}]: `
@@ -1216,7 +1251,7 @@ var CliJobNameCompletionProvider = class {
1216
1251
  };
1217
1252
 
1218
1253
  // src/lib/version.ts
1219
- var LIBRARY_VERSION = "2.4.2";
1254
+ var LIBRARY_VERSION = "2.5.1";
1220
1255
  var API_VERSION = 2;
1221
1256
  var completionProvider = new CliJobNameCompletionProvider();
1222
1257
  var jobsModule = {
@@ -1235,6 +1270,6 @@ var jobsModule = {
1235
1270
  }
1236
1271
  };
1237
1272
 
1238
- export { API_VERSION, CliJobNameCompletionProvider, CliJobsCommandProcessor, CliJobsService, LIBRARY_VERSION, formatRunning, formatSpan, jobsModule };
1273
+ export { API_VERSION, CliJobNameCompletionProvider, CliJobsCommandProcessor, CliJobsService, LIBRARY_VERSION, formatRunning, formatSpan, jobHasTags, jobsModule, parseTagArgs };
1239
1274
  //# sourceMappingURL=public-api.mjs.map
1240
1275
  //# sourceMappingURL=public-api.mjs.map