@koda-sl/baker-cli 0.378.0 → 0.379.0-dev.5cbcc1f8e

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.
Files changed (28) hide show
  1. package/README.md +115 -46
  2. package/dist/{chunk-XHC4LMK4.js → chunk-2QXMPTHG.js} +18 -19
  3. package/dist/chunk-2QXMPTHG.js.map +1 -0
  4. package/dist/{chunk-HJEMOSPH.js → chunk-7YNOGIWQ.js} +2 -439
  5. package/dist/chunk-7YNOGIWQ.js.map +1 -0
  6. package/dist/{chunk-VZEDAFAR.js → chunk-IZOAYU2G.js} +2 -2
  7. package/dist/{chunk-VLUGGVJL.js → chunk-PGYWZEAW.js} +4 -9
  8. package/dist/{chunk-VLUGGVJL.js.map → chunk-PGYWZEAW.js.map} +1 -1
  9. package/dist/{chunk-FGHMWBUD.js → chunk-RK44ZR7L.js} +114 -196
  10. package/dist/chunk-RK44ZR7L.js.map +1 -0
  11. package/dist/{chunk-MF7YA62W.js → chunk-UMIALY2G.js} +3 -3
  12. package/dist/cli.js +7999 -4499
  13. package/dist/cli.js.map +1 -1
  14. package/dist/{client-GR6YL3YX.js → client-OTWPBCHC.js} +4 -4
  15. package/dist/engine/index.js +3 -3
  16. package/dist/{env-4P5HOGNA.js → env-P7YVNPZ6.js} +2 -2
  17. package/dist/{output-NMQXZF3Z.js → output-WCDFLOHZ.js} +5 -5
  18. package/dist/{shared-J7DQZ2ED.js → shared-JZJ6PVJ7.js} +6 -8
  19. package/package.json +2 -2
  20. package/dist/chunk-FGHMWBUD.js.map +0 -1
  21. package/dist/chunk-HJEMOSPH.js.map +0 -1
  22. package/dist/chunk-XHC4LMK4.js.map +0 -1
  23. /package/dist/{chunk-VZEDAFAR.js.map → chunk-IZOAYU2G.js.map} +0 -0
  24. /package/dist/{chunk-MF7YA62W.js.map → chunk-UMIALY2G.js.map} +0 -0
  25. /package/dist/{client-GR6YL3YX.js.map → client-OTWPBCHC.js.map} +0 -0
  26. /package/dist/{env-4P5HOGNA.js.map → env-P7YVNPZ6.js.map} +0 -0
  27. /package/dist/{output-NMQXZF3Z.js.map → output-WCDFLOHZ.js.map} +0 -0
  28. /package/dist/{shared-J7DQZ2ED.js.map → shared-JZJ6PVJ7.js.map} +0 -0
@@ -282,434 +282,6 @@ function isBakerApiKey(value) {
282
282
  return KEY_PREFIXES.some((prefix) => value.startsWith(prefix));
283
283
  }
284
284
 
285
- // src/schemas.ts
286
- var registry = /* @__PURE__ */ new Map();
287
- function registerSchema(schema) {
288
- registry.set(schema.command, schema);
289
- }
290
- function listSchemas() {
291
- return [...registry.keys()];
292
- }
293
- function spellingKey(name) {
294
- return name.toLowerCase().replaceAll("-", "");
295
- }
296
- function resolveSchemaName(words, names) {
297
- const joined = words.join(".");
298
- if (names.includes(joined)) {
299
- return joined;
300
- }
301
- const matches = names.filter((name) => spellingKey(name) === spellingKey(joined));
302
- return matches.length === 1 ? matches[0] : void 0;
303
- }
304
- function findSchema(words) {
305
- const name = resolveSchemaName(words, listSchemas());
306
- return name === void 0 ? void 0 : registry.get(name);
307
- }
308
-
309
- // src/unknown-flags.ts
310
- var ALWAYS_ACCEPTED = /* @__PURE__ */ new Set(["help", "h", "version"]);
311
- function subCommandsOf(command) {
312
- const sub = command.subCommands;
313
- return sub && typeof sub === "object" ? sub : null;
314
- }
315
- function argsOf(command) {
316
- const args = command.args;
317
- return args && typeof args === "object" ? args : null;
318
- }
319
- function resolveCommand(root, argv) {
320
- let command = root;
321
- for (const token of argv) {
322
- if (token === "--" || token.startsWith("-")) {
323
- break;
324
- }
325
- const subCommands = subCommandsOf(command);
326
- if (!subCommands) {
327
- break;
328
- }
329
- const next = subCommands[token];
330
- if (next === void 0) {
331
- break;
332
- }
333
- if (typeof next !== "object") {
334
- return { command, resolved: false };
335
- }
336
- command = next;
337
- }
338
- return { command, resolved: true };
339
- }
340
- function typeOf(def) {
341
- return def && typeof def === "object" ? def.type : void 0;
342
- }
343
- function acceptedNames(command) {
344
- const args = argsOf(command);
345
- if (!args) {
346
- return null;
347
- }
348
- const names = new Set(ALWAYS_ACCEPTED);
349
- for (const [name, def] of Object.entries(args)) {
350
- if (typeOf(def) === "positional") {
351
- continue;
352
- }
353
- for (const spelling of [name, kebab(name), camel(name)]) {
354
- names.add(spelling);
355
- if (typeOf(def) === "boolean") {
356
- names.add(`no-${spelling}`);
357
- }
358
- }
359
- }
360
- return names;
361
- }
362
- function kebab(name) {
363
- return name.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
364
- }
365
- function camel(name) {
366
- return name.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
367
- }
368
- function findUnknownFlags(root, argv) {
369
- const { command, resolved } = resolveCommand(root, argv);
370
- if (!resolved) {
371
- return [];
372
- }
373
- const accepted = acceptedNames(command);
374
- if (!accepted) {
375
- return [];
376
- }
377
- const unknown = [];
378
- for (const token of argv) {
379
- if (token === "--") {
380
- break;
381
- }
382
- if (!token.startsWith("--")) {
383
- continue;
384
- }
385
- const name = token.slice(2).split("=")[0] ?? "";
386
- if (name.length > 0 && !accepted.has(name) && !unknown.includes(token)) {
387
- unknown.push(token);
388
- }
389
- }
390
- return unknown;
391
- }
392
- var SYNONYMS = {
393
- from: ["start-date", "start", "since"],
394
- since: ["start-date", "start"],
395
- start: ["start-date", "since"],
396
- to: ["end-date", "end", "until"],
397
- until: ["end-date", "end"],
398
- end: ["end-date", "until"],
399
- path: ["landing"],
400
- url: ["landing"]
401
- };
402
- function closestFlag(unknown, command) {
403
- const accepted = acceptedNames(command);
404
- if (!accepted) {
405
- return null;
406
- }
407
- const name = unknown.replace(/^--/, "").split("=")[0] ?? "";
408
- const synonym = SYNONYMS[name]?.find((candidate) => accepted.has(candidate));
409
- if (synonym) {
410
- return `--${synonym}`;
411
- }
412
- const scored = [...accepted].filter((candidate) => !ALWAYS_ACCEPTED.has(candidate)).map((candidate) => ({
413
- candidate,
414
- prefix: sharedPrefix(name, candidate),
415
- distance: editDistance(name, candidate)
416
- })).filter(({ prefix, distance }) => prefix >= 4 || distance <= typoBudget(name)).sort((a, b) => b.prefix - a.prefix || a.distance - b.distance);
417
- return scored[0] ? `--${scored[0].candidate}` : null;
418
- }
419
- function typoBudget(name) {
420
- return Math.max(1, Math.floor(name.length / 3));
421
- }
422
- function sharedPrefix(a, b) {
423
- let i = 0;
424
- while (i < a.length && i < b.length && a[i] === b[i]) {
425
- i++;
426
- }
427
- return i;
428
- }
429
- function editDistance(a, b) {
430
- let previous = Array.from({ length: b.length + 1 }, (_, j) => j);
431
- for (let i = 1; i <= a.length; i++) {
432
- const current = [i];
433
- for (let j = 1; j <= b.length; j++) {
434
- const substitution = (previous[j - 1] ?? 0) + (a[i - 1] === b[j - 1] ? 0 : 1);
435
- current.push(Math.min((previous[j] ?? 0) + 1, (current[j - 1] ?? 0) + 1, substitution));
436
- }
437
- previous = current;
438
- }
439
- return previous[b.length] ?? 0;
440
- }
441
- function commandFor(root, argv) {
442
- const { command, resolved } = resolveCommand(root, argv);
443
- return resolved ? command : null;
444
- }
445
- function suggestFlag(unknown, command) {
446
- const flag = closestFlag(unknown, command);
447
- if (!flag) {
448
- return null;
449
- }
450
- const args = argsOf(command) ?? {};
451
- const name = flag.slice(2);
452
- const def = args[name] ?? args[camel(name)];
453
- const described = def && typeof def === "object" ? def.description : void 0;
454
- const description = typeof described === "string" ? described.split(/(?<!\b(?:e\.g|i\.e|vs))\.\s/)[0]?.trim().replace(/\.$/, "") : "";
455
- return description ? { flag, description } : { flag };
456
- }
457
- function suggestionText(suggestion) {
458
- if (!suggestion) {
459
- return "";
460
- }
461
- return suggestion.description ? `Did you mean ${suggestion.flag}? It is described as: ${suggestion.description}. ` : `Did you mean ${suggestion.flag}? `;
462
- }
463
- var OUTPUT_EXPLANATION = "This command has no --output option: `--output json` is accepted by every command that prints the JSON envelope, and md or files only where `baker schema` lists `output`. Drop the option and read the default output. ";
464
- function unknownFlagEnvelope(unknown, commandPath, suggestion, hasSchema) {
465
- const list = unknown.join(", ");
466
- return {
467
- ok: false,
468
- error: {
469
- code: "UNKNOWN_ARGUMENT",
470
- message: `${list} ${unknown.length > 1 ? "are not options" : "is not an option"} of \`baker ${commandPath}\`.`,
471
- fix: {
472
- action: hasSchema ? "check_schema" : "check_help",
473
- explanation: (unknown.some((flag) => flag === "--output" || flag.startsWith("--output=")) ? OUTPUT_EXPLANATION : "") + suggestionText(suggestion) + `Run \`${hasSchema ? `baker schema ${commandPath}` : `baker ${commandPath} --help`}\` to see every option this command takes. Do not re-run the same call: until this version an unrecognised option was accepted and ignored, so a command that looked like it had filtered or narrowed the result was in fact answering the unfiltered question.`
474
- },
475
- retryable: false
476
- }
477
- };
478
- }
479
- function commandPathOf(root, argv) {
480
- const path = [];
481
- let command = root;
482
- for (const token of argv) {
483
- if (token === "--" || token.startsWith("-")) {
484
- break;
485
- }
486
- const subCommands = subCommandsOf(command);
487
- const next = subCommands?.[token];
488
- if (next === void 0 || typeof next !== "object") {
489
- break;
490
- }
491
- path.push(token);
492
- command = next;
493
- }
494
- return path.join(" ");
495
- }
496
- function refuseUnknownFlags(root, argv) {
497
- const unknown = findUnknownFlags(root, argv);
498
- if (unknown.length === 0) {
499
- return;
500
- }
501
- const command = commandFor(root, argv);
502
- const first = unknown[0];
503
- const suggestion = command && first ? suggestFlag(first, command) : null;
504
- const path = commandPathOf(root, argv);
505
- process.stdout.write(
506
- `${JSON.stringify(unknownFlagEnvelope(unknown, path, suggestion, findSchema(path.split(" ")) !== void 0), null, 2)}
507
- `
508
- );
509
- process.exit(1);
510
- }
511
-
512
- // src/output-flag.ts
513
- var FLAG = "--output";
514
- var ENVELOPE = "json";
515
- var PRINTS_NO_ENVELOPE = /* @__PURE__ */ new Set([
516
- "analytics sending-events",
517
- "canvas run",
518
- "canvas rerun",
519
- "canvas sync-definition"
520
- ]);
521
- function declaredArg(command, name) {
522
- const args = command.args;
523
- if (!args || typeof args !== "object" || !(name in args)) {
524
- return null;
525
- }
526
- const def = args[name];
527
- return def && typeof def === "object" ? def : {};
528
- }
529
- function envelopeRequests(argv) {
530
- const end = argv.indexOf("--");
531
- const limit = end === -1 ? argv.length : end;
532
- const found = [];
533
- for (let index = 0; index < limit; index++) {
534
- const token = argv[index];
535
- if (token === `${FLAG}=${ENVELOPE}`) {
536
- found.push({ index, length: 1 });
537
- } else if (token === FLAG && argv[index + 1] === ENVELOPE && index + 1 < limit) {
538
- found.push({ index, length: 2 });
539
- index++;
540
- }
541
- }
542
- return found;
543
- }
544
- function outputFlagForCommand(root, argv) {
545
- const requests = envelopeRequests(argv);
546
- if (requests.length === 0) {
547
- return argv;
548
- }
549
- const command = commandFor(root, argv);
550
- if (!command || declaredArg(command, "output") || PRINTS_NO_ENVELOPE.has(commandPathOf(root, argv))) {
551
- return argv;
552
- }
553
- const jsonSwitch = declaredArg(command, "json")?.type === "boolean";
554
- const dropped = new Set(requests.flatMap(({ index, length }) => length === 2 ? [index, index + 1] : [index]));
555
- const first = requests[0]?.index;
556
- return argv.flatMap((token, index) => {
557
- if (!dropped.has(index)) {
558
- return [token];
559
- }
560
- return jsonSwitch && index === first ? ["--json"] : [];
561
- });
562
- }
563
-
564
- // src/field-mask.ts
565
- var FLAG2 = "--fields";
566
- function parseFields(value) {
567
- return value.split(",").map((field) => field.trim()).filter((field) => field.length > 0);
568
- }
569
- function takeFieldsFlag(root, argv) {
570
- const end = argv.indexOf("--");
571
- const limit = end === -1 ? argv.length : end;
572
- const taken = /* @__PURE__ */ new Set();
573
- const fields = [];
574
- for (let index = 0; index < limit; index++) {
575
- const token = argv[index] ?? "";
576
- if (token.startsWith(`${FLAG2}=`)) {
577
- taken.add(index);
578
- fields.push(...parseFields(token.slice(FLAG2.length + 1)));
579
- } else if (token === FLAG2) {
580
- const value = argv[index + 1];
581
- if (value === void 0 || index + 1 >= limit || value.startsWith("-")) {
582
- return { argv, fields: null };
583
- }
584
- taken.add(index).add(index + 1);
585
- fields.push(...parseFields(value));
586
- index++;
587
- }
588
- }
589
- if (taken.size === 0 || fields.length === 0) {
590
- return { argv, fields: null };
591
- }
592
- const command = commandFor(root, argv);
593
- if (!command || declaredArg(command, "fields") || PRINTS_NO_ENVELOPE.has(commandPathOf(root, argv))) {
594
- return { argv, fields: null };
595
- }
596
- return { argv: argv.filter((_, index) => !taken.has(index)), fields };
597
- }
598
- function isRecord(value) {
599
- return typeof value === "object" && value !== null && !Array.isArray(value);
600
- }
601
- function pick(record, fields) {
602
- return Object.fromEntries(fields.filter((field) => field in record).map((field) => [field, record[field]]));
603
- }
604
- function soleList(data) {
605
- const lists = Object.entries(data).filter(
606
- (entry) => Array.isArray(entry[1]) && entry[1].length > 0 && entry[1].every((item) => isRecord(item))
607
- );
608
- return lists.length === 1 ? lists[0] ?? null : null;
609
- }
610
- function wrappedList(data, fields) {
611
- const rowFields = fields.filter((field) => !(field in data));
612
- const list = soleList(data);
613
- if (list === null || !list[1].some((row) => rowFields.some((field) => field in row))) {
614
- return null;
615
- }
616
- return list[0];
617
- }
618
- function recordsOf(data, fields) {
619
- if (Array.isArray(data)) {
620
- return data;
621
- }
622
- if (!isRecord(data)) {
623
- return [];
624
- }
625
- const list = wrappedList(data, fields);
626
- return list === null ? [data] : data[list];
627
- }
628
- function maskData(data, fields) {
629
- const maskWith = (keep) => (item) => isRecord(item) ? pick(item, keep) : item;
630
- if (Array.isArray(data)) {
631
- return data.map(maskWith(fields));
632
- }
633
- if (!isRecord(data)) {
634
- return data;
635
- }
636
- const list = wrappedList(data, fields);
637
- if (list === null) {
638
- return pick(data, fields);
639
- }
640
- const wrapperFields = fields.filter((field) => field in data);
641
- const rows = recordsOf(data, fields).map(maskWith(fields.filter((field) => !(field in data))));
642
- return { ...wrapperFields.length > 0 ? pick(data, wrapperFields) : data, [list]: rows };
643
- }
644
- function unmatchedHint(data, fields) {
645
- const records = recordsOf(data, fields).filter(isRecord);
646
- if (records.length === 0) {
647
- return null;
648
- }
649
- const keys = isRecord(data) ? [data, ...soleList(data)?.[1] ?? []] : records;
650
- const carried = new Set(keys.flatMap((record) => Object.keys(record)));
651
- const unmatched = fields.filter((field) => !carried.has(field));
652
- if (unmatched.length === 0) {
653
- return null;
654
- }
655
- return `--fields matched nothing for: ${unmatched.join(", ")}. The keys data carries are: ${[...carried].join(", ")}.`;
656
- }
657
- function reprint(text, envelope) {
658
- const indent = text.trimStart().startsWith("{\n") ? 2 : void 0;
659
- return `${JSON.stringify(envelope, null, indent)}${text.endsWith("\n") ? "\n" : ""}`;
660
- }
661
- function withHint(envelope, hint) {
662
- return { ...envelope, hints: [...Array.isArray(envelope.hints) ? envelope.hints : [], hint] };
663
- }
664
- var NO_DATA_HINT = "--fields was not applied: this result carries no data to narrow, so it is printed whole. Drop --fields on this command.";
665
- function maskPrintedEnvelope(text, fields) {
666
- let parsed;
667
- try {
668
- parsed = JSON.parse(text);
669
- } catch {
670
- return null;
671
- }
672
- if (!isRecord(parsed) || typeof parsed.ok !== "boolean") {
673
- return null;
674
- }
675
- if (parsed.ok !== true || "dryRun" in parsed) {
676
- return text;
677
- }
678
- return reprint(text, maskEnvelope(parsed, fields));
679
- }
680
- function maskEnvelope(envelope, fields) {
681
- if (!("data" in envelope)) {
682
- return withHint(envelope, NO_DATA_HINT);
683
- }
684
- const masked = { ...envelope, data: maskData(envelope.data, fields) };
685
- const miss = unmatchedHint(envelope.data, fields);
686
- return miss ? withHint(masked, miss) : masked;
687
- }
688
- function maskWrites(stream, fields) {
689
- let applied = false;
690
- const write2 = stream.write.bind(stream);
691
- stream.write = (chunk, ...rest) => {
692
- const masked = typeof chunk === "string" ? maskPrintedEnvelope(chunk, fields) : null;
693
- if (masked === null) {
694
- return write2(chunk, ...rest);
695
- }
696
- applied = true;
697
- return write2(masked, ...rest);
698
- };
699
- return { sawEnvelope: () => applied };
700
- }
701
- function installFieldMask(fields, commandPath) {
702
- const mask = maskWrites(process.stdout, fields);
703
- process.on("exit", () => {
704
- if (!mask.sawEnvelope()) {
705
- process.stderr.write(
706
- `--fields was not applied: \`baker ${commandPath}\` printed no JSON envelope to narrow. Add --output json to get the envelope, or drop --fields.
707
- `
708
- );
709
- }
710
- });
711
- }
712
-
713
285
  // src/output.ts
714
286
  var ASPECT_RATIO_MAP = {
715
287
  "1:1": 1,
@@ -1099,8 +671,7 @@ function writeOutput(envelope, format, fields, full, normalizer) {
1099
671
  return;
1100
672
  }
1101
673
  if (format === "json") {
1102
- write(`${JSON.stringify(fields ? maskEnvelope(envelope, fields) : envelope, null, 2)}
1103
- `);
674
+ writeJson(envelope);
1104
675
  return;
1105
676
  }
1106
677
  if (format !== "files" && format !== "md") {
@@ -1258,14 +829,6 @@ export {
1258
829
  plannedRoutes,
1259
830
  API_KEY_FORMAT_MESSAGE,
1260
831
  isBakerApiKey,
1261
- registerSchema,
1262
- listSchemas,
1263
- findSchema,
1264
- commandPathOf,
1265
- refuseUnknownFlags,
1266
- outputFlagForCommand,
1267
- takeFieldsFlag,
1268
- installFieldMask,
1269
832
  compactImage,
1270
833
  compactVideo,
1271
834
  videoNormalizer,
@@ -1289,4 +852,4 @@ export {
1289
852
  captureVimeoCookie,
1290
853
  childEnvWith
1291
854
  };
1292
- //# sourceMappingURL=chunk-HJEMOSPH.js.map
855
+ //# sourceMappingURL=chunk-7YNOGIWQ.js.map