@nodaro/cli 1.26.2 → 1.27.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
@@ -29,7 +29,7 @@ var require_package = __commonJS({
29
29
  "package.json"(exports$1, module) {
30
30
  module.exports = {
31
31
  name: "@nodaro/cli",
32
- version: "1.26.2",
32
+ version: "1.27.0",
33
33
  description: "Command-line interface for Nodaro \u2014 list and run workflows, inspect jobs and executions, manage projects from the terminal.",
34
34
  type: "module",
35
35
  license: "Apache-2.0",
@@ -70,11 +70,11 @@ var require_package = __commonJS({
70
70
  "@inquirer/confirm": "^6.0.12",
71
71
  "@inquirer/input": "^5.0.12",
72
72
  "@inquirer/select": "^5.1.4",
73
- "@nodaro/sdk": "^2.21.1",
74
- "@nodaro/shared": "^3.26.0",
73
+ "@nodaro/sdk": "^2.22.0",
74
+ "@nodaro/shared": "^3.27.0",
75
75
  commander: "^12.1.0",
76
76
  picocolors: "^1.1.1",
77
- "@nodaro/prompts": "^1.35.0"
77
+ "@nodaro/prompts": "^1.36.0"
78
78
  },
79
79
  devDependencies: {
80
80
  tsup: "^8.5.0",
@@ -398,7 +398,7 @@ function saveWorkspace(profileName, workspaceId) {
398
398
  }
399
399
 
400
400
  // src/client.ts
401
- var CLI_VERSION = "1.26.2" ;
401
+ var CLI_VERSION = "1.27.0" ;
402
402
  function buildClient(profileName) {
403
403
  const { name, profile } = getProfile(profileName);
404
404
  if (!profile) {
@@ -3374,6 +3374,16 @@ function parseFormat(raw) {
3374
3374
  if (raw !== "csv" && raw !== "json") throw new Error("--format must be csv or json");
3375
3375
  return raw;
3376
3376
  }
3377
+ function parseCount2(flag, raw) {
3378
+ if (raw === void 0) return void 0;
3379
+ if (!/^\d+$/.test(raw)) throw new Error(`${flag} must be a whole number`);
3380
+ return Number(raw);
3381
+ }
3382
+ function parseUsage(raw) {
3383
+ if (raw === void 0 || raw === "all") return void 0;
3384
+ if (raw !== "unused" && raw !== "used") throw new Error("--usage must be all, unused or used");
3385
+ return raw;
3386
+ }
3377
3387
  function shorten2(text, max) {
3378
3388
  const flat = text.replace(/\s+/g, " ").trim();
3379
3389
  return flat.length > max ? `${flat.slice(0, max - 1)}\u2026` : flat;
@@ -3449,24 +3459,56 @@ function collectionsCommand() {
3449
3459
  handleError(err);
3450
3460
  }
3451
3461
  });
3452
- cmd.command("records <id>").description("a collection's records, newest first").option("--q <words>", "words in the title, text or link").option("--since <iso>", "only records saved at or after this time (ISO)").option("--limit <n>", "page size, 1-100 (default 50)").option("--cursor <cursor>", "the next cursor printed by the previous page").option("--profile <name>").option("--json").action(async (id, opts) => {
3462
+ cmd.command("records <id>").description("a collection's records, newest first").option("--q <words>", "words in the title, text or link").option("--since <iso>", "only records saved at or after this time (ISO)").option("--until <iso>", "only records saved before this time (ISO)").option("--usage <which>", "all (default), unused (not used yet) or used").option("--order <order>", "newest (default) or oldest first").option("--status <which>", "active (default: the live records) or trash").option("--limit <n>", "page size, 1-100 (default 50)").option("--offset <n>", "skip this many records first (a numbered page); not with --cursor").option("--cursor <cursor>", "the next cursor printed by the previous page").option("--profile <name>").option("--json").action(
3463
+ async (id, opts) => {
3464
+ try {
3465
+ const usage = parseUsage(opts.usage);
3466
+ const order = opts.order === "oldest" ? "oldest" : opts.order === void 0 || opts.order === "newest" ? void 0 : null;
3467
+ if (order === null) throw new Error("--order must be newest or oldest");
3468
+ const status = opts.status === "trash" ? "trash" : opts.status === void 0 || opts.status === "active" ? void 0 : null;
3469
+ if (status === null) throw new Error("--status must be active or trash");
3470
+ const client = buildClient(opts.profile);
3471
+ const page = await client.collections.records(id, {
3472
+ q: opts.q,
3473
+ since: opts.since,
3474
+ until: opts.until,
3475
+ usage,
3476
+ status,
3477
+ order,
3478
+ limit: parseCount2("--limit", opts.limit),
3479
+ offset: parseCount2("--offset", opts.offset),
3480
+ cursor: opts.cursor
3481
+ });
3482
+ if (opts.json) {
3483
+ emit(page, opts);
3484
+ return;
3485
+ }
3486
+ table(
3487
+ page.data.map((r) => ({
3488
+ id: r.id,
3489
+ saved: r.createdAt.slice(0, 10),
3490
+ used: r.usedAt ? r.usedAt.slice(0, 10) : "",
3491
+ headline: shorten2(collectionRecordHeadline(r), 56),
3492
+ from: r.source.workflowName ?? r.source.via ?? "",
3493
+ url: r.url ?? ""
3494
+ })),
3495
+ ["id", "saved", "used", "headline", "from", "url"]
3496
+ );
3497
+ if (page.nextCursor) success(`more: --cursor "${page.nextCursor}"`);
3498
+ } catch (err) {
3499
+ handleError(err);
3500
+ }
3501
+ }
3502
+ );
3503
+ cmd.command("mark-used <id> <recordId>").description("mark a record used (--not-used marks it not used again)").option("--not-used", "undo: the record is not used").option("--profile <name>").option("--json").action(async (id, recordId, opts) => {
3453
3504
  try {
3454
3505
  const client = buildClient(opts.profile);
3455
- const page = await client.collections.records(id, {
3456
- q: opts.q,
3457
- since: opts.since,
3458
- limit: opts.limit ? Number(opts.limit) : void 0,
3459
- cursor: opts.cursor
3460
- });
3506
+ const record = await client.collections.setUsed(id, recordId, !opts.notUsed);
3461
3507
  if (opts.json) {
3462
- emit(page, opts);
3508
+ emit(record, opts);
3463
3509
  return;
3464
3510
  }
3465
- table(
3466
- page.data.map((r) => ({ id: r.id, saved: r.createdAt.slice(0, 10), headline: shorten2(collectionRecordHeadline(r), 56), url: r.url ?? "" })),
3467
- ["id", "saved", "headline", "url"]
3468
- );
3469
- if (page.nextCursor) success(`more: --cursor "${page.nextCursor}"`);
3511
+ success(record.usedAt ? `used ${record.usedAt.slice(0, 16).replace("T", " ")}: ${collectionRecordHeadline(record)}` : `not used: ${collectionRecordHeadline(record)}`);
3470
3512
  } catch (err) {
3471
3513
  handleError(err);
3472
3514
  }
@@ -3502,20 +3544,39 @@ function collectionsCommand() {
3502
3544
  }
3503
3545
  }
3504
3546
  );
3505
- cmd.command("remove <id> <recordId>").description("remove one record").option("--profile <name>").action(async (id, recordId, opts) => {
3547
+ cmd.command("remove <id> <recordId>").description("move one record to the collection's Trash (restore brings it back); --forever deletes a record already in the Trash for good").option("--forever", "delete for good \u2014 the record must already be in the Trash").option("--profile <name>").action(async (id, recordId, opts) => {
3506
3548
  try {
3507
3549
  const client = buildClient(opts.profile);
3550
+ if (opts.forever) {
3551
+ await client.collections.deleteRecordForever(id, recordId);
3552
+ success(`deleted ${recordId} for good`);
3553
+ return;
3554
+ }
3508
3555
  await client.collections.deleteRecord(id, recordId);
3509
- success(`removed ${recordId}`);
3556
+ success(`moved ${recordId} to the Trash`);
3557
+ } catch (err) {
3558
+ handleError(err);
3559
+ }
3560
+ });
3561
+ cmd.command("restore <id> <recordId>").description("bring one record back from the collection's Trash").option("--profile <name>").option("--json").action(async (id, recordId, opts) => {
3562
+ try {
3563
+ const client = buildClient(opts.profile);
3564
+ const record = await client.collections.restoreRecord(id, recordId);
3565
+ if (opts.json) {
3566
+ emit(record, opts);
3567
+ return;
3568
+ }
3569
+ success(`restored: ${collectionRecordHeadline(record)}`);
3510
3570
  } catch (err) {
3511
3571
  handleError(err);
3512
3572
  }
3513
3573
  });
3514
- cmd.command("export <id>").description("the whole collection as CSV (default) or JSON, to stdout or a file").option("--format <format>", "csv or json (default csv)").option("--since <iso>", "only records saved at or after this time (ISO)").option("--q <words>", "words in the title, text or link").option("--out <path>", "write to this file instead of stdout").option("--profile <name>").action(async (id, opts) => {
3574
+ cmd.command("export <id>").description("the whole collection as CSV (default) or JSON, to stdout or a file").option("--format <format>", "csv or json (default csv)").option("--since <iso>", "only records saved at or after this time (ISO)").option("--until <iso>", "only records saved before this time (ISO)").option("--usage <which>", "all (default), unused (not used yet) or used").option("--q <words>", "words in the title, text or link").option("--out <path>", "write to this file instead of stdout").option("--profile <name>").action(async (id, opts) => {
3515
3575
  try {
3516
3576
  const format2 = parseFormat(opts.format);
3577
+ const usage = parseUsage(opts.usage);
3517
3578
  const client = buildClient(opts.profile);
3518
- const body = await client.collections.export(id, { format: format2, since: opts.since, q: opts.q });
3579
+ const body = await client.collections.export(id, { format: format2, since: opts.since, until: opts.until, usage, q: opts.q });
3519
3580
  if (opts.out) {
3520
3581
  writeFileSync(opts.out, body, "utf8");
3521
3582
  success(`wrote ${opts.out}`);