@qodalis/cli-server-jobs 2.4.2 → 2.5.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.
@@ -2053,6 +2053,7 @@ var jobs = (() => {
2053
2053
  }
2054
2054
  return resolveHeaders(configHeaders);
2055
2055
  }
2056
+ var ICliSecretStore_TOKEN = createCliToken("cli-secret-store");
2056
2057
  var ICliCommandGuard_TOKEN = createCliToken("cli-command-guard");
2057
2058
  var ICliEventBus_TOKEN = createCliToken("cli-event-bus");
2058
2059
  var DefaultLibraryAuthor = {
@@ -2943,11 +2944,11 @@ var jobs = (() => {
2943
2944
  context,
2944
2945
  rows,
2945
2946
  (cmd) => cmd,
2946
- (comment) => writer.wrapInColor(
2947
+ (comment) => comment ? writer.wrapInColor(
2947
2948
  `# ${comment}`,
2948
2949
  "\x1B[32m"
2949
2950
  /* Green */
2950
- )
2951
+ ) : ""
2951
2952
  );
2952
2953
  }
2953
2954
  function writeWrapped(context, text, indent = 0) {
@@ -3157,6 +3158,14 @@ var jobs = (() => {
3157
3158
  };
3158
3159
 
3159
3160
  // src/lib/services/cli-jobs-service.ts
3161
+ function jobHasTags(job, tags) {
3162
+ const own = new Set((job.tags ?? []).map((t) => t.toLowerCase()));
3163
+ return tags.every((t) => own.has(t.toLowerCase()));
3164
+ }
3165
+ function parseTagArgs(value) {
3166
+ const values = Array.isArray(value) ? value : value === void 0 || value === null || value === true ? [] : [value];
3167
+ return values.flatMap((v) => String(v).split(",")).map((t) => t.trim()).filter(Boolean);
3168
+ }
3160
3169
  var CliJobsService = class {
3161
3170
  constructor(baseUrl, headers = {}) {
3162
3171
  this.baseUrl = baseUrl;
@@ -3189,8 +3198,15 @@ var jobs = (() => {
3189
3198
  }
3190
3199
  return JSON.parse(text);
3191
3200
  }
3192
- async listJobs() {
3193
- return this.request("");
3201
+ /**
3202
+ * The jobs; with `tags`, only those that have every tag (ignoring case). The server filters
3203
+ * (`?tag=`), and the list is filtered here too, so a server without job tags lists nothing
3204
+ * for a tag filter instead of every job.
3205
+ */
3206
+ async listJobs(tags = []) {
3207
+ const query = tags.map((t) => `tag=${encodeURIComponent(t)}`).join("&");
3208
+ const jobs = await this.request(query ? `?${query}` : "");
3209
+ return tags.length ? jobs.filter((j) => jobHasTags(j, tags)) : jobs;
3194
3210
  }
3195
3211
  async getJob(id) {
3196
3212
  return this.request(`/${encodeURIComponent(id)}`);
@@ -3338,6 +3354,9 @@ var jobs = (() => {
3338
3354
  if (job.queued) parts.push("1 queued");
3339
3355
  return parts.join(", ");
3340
3356
  }
3357
+ function formatTags(tags) {
3358
+ return tags && tags.length > 0 ? tags.join(", ") : "-";
3359
+ }
3341
3360
  function formatDuration(ms) {
3342
3361
  if (ms == null) return "-";
3343
3362
  if (ms < 1e3) return `${ms}ms`;
@@ -3435,12 +3454,14 @@ var jobs = (() => {
3435
3454
  context.writer.writeln();
3436
3455
  writeUsage(context, [
3437
3456
  ["server jobs list", t.t("cli.server.jobs.list.help.jobs_all_connected_servers", "Jobs on all connected servers")],
3438
- ["server jobs ls --group <name>", t.t("cli.server.jobs.list.help.only_one_group", "Only one group")]
3457
+ ["server jobs ls --group <name>", t.t("cli.server.jobs.list.help.only_one_group", "Only one group")],
3458
+ ["server jobs ls --tag <tag> [--tag <tag>]", t.t("cli.server.jobs.list.help.only_tagged", "Only the jobs that have every tag given")]
3439
3459
  ]);
3440
3460
  context.writer.writeln();
3441
3461
  writeExamples(context, [
3442
3462
  ["server jobs ls --server node", t.t("cli.server.jobs.list.help.jobs_node_server", "Jobs on the node server")],
3443
- ["server jobs list --group reports", t.t("cli.server.jobs.list.help.jobs_reports_group", "Jobs in the reports group")]
3463
+ ["server jobs list --group reports", t.t("cli.server.jobs.list.help.jobs_reports_group", "Jobs in the reports group")],
3464
+ ["server jobs list --tag country:ro --tag bank", t.t("cli.server.jobs.list.help.jobs_tagged", "Jobs tagged both country:ro and bank")]
3444
3465
  ]);
3445
3466
  },
3446
3467
  aliases: ["ls"],
@@ -3451,6 +3472,12 @@ var jobs = (() => {
3451
3472
  description: "Filter jobs by group",
3452
3473
  required: false,
3453
3474
  type: "string"
3475
+ },
3476
+ {
3477
+ name: "tag",
3478
+ description: "Only jobs that have this tag (repeatable or comma-separated; every tag must match)",
3479
+ required: false,
3480
+ type: "array"
3454
3481
  }
3455
3482
  ],
3456
3483
  processCommand: async (cmd, context) => {
@@ -3765,10 +3792,11 @@ var jobs = (() => {
3765
3792
  return;
3766
3793
  }
3767
3794
  const groupFilter = cmd.args["group"];
3795
+ const tagFilter = parseTagArgs(cmd.args["tag"]);
3768
3796
  const multiServer = services.length > 1;
3769
3797
  for (const { name, service } of services) {
3770
3798
  try {
3771
- let jobs = await service.listJobs();
3799
+ let jobs = await service.listJobs(tagFilter);
3772
3800
  if (groupFilter) {
3773
3801
  jobs = jobs.filter(
3774
3802
  (j) => j.group?.toLowerCase() === groupFilter.toLowerCase()
@@ -3786,9 +3814,11 @@ var jobs = (() => {
3786
3814
  context.writer.writeInfo(" No jobs found.");
3787
3815
  continue;
3788
3816
  }
3817
+ const showTags = jobs.some((j) => (j.tags?.length ?? 0) > 0);
3789
3818
  const headers = [
3790
3819
  "Name",
3791
3820
  "Group",
3821
+ ...showTags ? ["Tags"] : [],
3792
3822
  "Status",
3793
3823
  "Schedule",
3794
3824
  "Last Run",
@@ -3798,6 +3828,7 @@ var jobs = (() => {
3798
3828
  const rows = jobs.map((j) => [
3799
3829
  j.name,
3800
3830
  j.group ?? "-",
3831
+ ...showTags ? [formatTags(j.tags)] : [],
3801
3832
  statusColor(j.status, context.writer),
3802
3833
  j.schedule ?? (formatSpan(j.interval) ? `every ${formatSpan(j.interval)}` : "-"),
3803
3834
  formatRelativeTime(j.lastRunAt),
@@ -3834,6 +3865,7 @@ var jobs = (() => {
3834
3865
  ["Name", job.name],
3835
3866
  ["Description", job.description],
3836
3867
  ["Group", job.group ?? "-"],
3868
+ ["Tags", formatTags(job.tags)],
3837
3869
  ["Status", statusColor(job.status, context.writer)],
3838
3870
  [
3839
3871
  "Schedule",
@@ -4090,6 +4122,10 @@ var jobs = (() => {
4090
4122
  const newGroup = await ask(`Group [${job.group ?? "none"}]: `);
4091
4123
  if (newGroup == null) return cancelled();
4092
4124
  if (newGroup) update.group = newGroup;
4125
+ const newTags = await ask(`Tags, comma-separated, - for none [${formatTags(job.tags)}]: `);
4126
+ if (newTags == null) return cancelled();
4127
+ if (newTags.trim() === "-") update.tags = null;
4128
+ else if (newTags.trim()) update.tags = parseTagArgs(newTags);
4093
4129
  const currentSchedule = job.schedule ?? (formatSpan(job.interval) ? `interval: ${formatSpan(job.interval)}` : "none");
4094
4130
  const newSchedule = await ask(
4095
4131
  `Cron schedule [${currentSchedule}]: `