@koda-sl/baker-cli 0.371.0 → 0.372.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/README.md +16 -0
- package/dist/{chunk-L4QXAYIC.js → chunk-4ACU7GBN.js} +4 -4
- package/dist/{chunk-3NIBJ3GL.js → chunk-FGHMWBUD.js} +3 -3
- package/dist/{chunk-2OKSJNLA.js → chunk-HJEMOSPH.js} +439 -2
- package/dist/chunk-HJEMOSPH.js.map +1 -0
- package/dist/{chunk-MZQC4LII.js → chunk-MF7YA62W.js} +3 -3
- package/dist/{chunk-XWHHYHKQ.js → chunk-VZEDAFAR.js} +2 -2
- package/dist/{chunk-FXVELNAS.js → chunk-ZI7TPBXB.js} +3 -3
- package/dist/cli.js +28 -293
- package/dist/cli.js.map +1 -1
- package/dist/{client-3DGBQ2H3.js → client-GR6YL3YX.js} +4 -4
- package/dist/engine/index.js +3 -3
- package/dist/{env-BSG7TY5Y.js → env-4P5HOGNA.js} +2 -2
- package/dist/{output-AT5SRVH7.js → output-KMEPFOFT.js} +5 -5
- package/dist/{shared-HZ44PY2F.js → shared-26NWGQ5G.js} +6 -6
- package/package.json +1 -1
- package/dist/chunk-2OKSJNLA.js.map +0 -1
- /package/dist/{chunk-L4QXAYIC.js.map → chunk-4ACU7GBN.js.map} +0 -0
- /package/dist/{chunk-3NIBJ3GL.js.map → chunk-FGHMWBUD.js.map} +0 -0
- /package/dist/{chunk-MZQC4LII.js.map → chunk-MF7YA62W.js.map} +0 -0
- /package/dist/{chunk-XWHHYHKQ.js.map → chunk-VZEDAFAR.js.map} +0 -0
- /package/dist/{chunk-FXVELNAS.js.map → chunk-ZI7TPBXB.js.map} +0 -0
- /package/dist/{client-3DGBQ2H3.js.map → client-GR6YL3YX.js.map} +0 -0
- /package/dist/{env-BSG7TY5Y.js.map → env-4P5HOGNA.js.map} +0 -0
- /package/dist/{output-AT5SRVH7.js.map → output-KMEPFOFT.js.map} +0 -0
- /package/dist/{shared-HZ44PY2F.js.map → shared-26NWGQ5G.js.map} +0 -0
package/README.md
CHANGED
|
@@ -110,6 +110,22 @@ question — and nothing in the output said so. Both spellings of an option work
|
|
|
110
110
|
that lists every option: `baker schema <command>` (`check_schema`) when the command
|
|
111
111
|
registers a schema, `baker <command> --help` (`check_help`) when it does not.
|
|
112
112
|
|
|
113
|
+
### Narrowing a result: `--fields`
|
|
114
|
+
|
|
115
|
+
`--fields a,b,c` works on every command that prints the JSON envelope. It keeps only
|
|
116
|
+
those keys of each record in `data` — the rows when `data` is a list or wraps one
|
|
117
|
+
(`baker chats list --fields id,title`), `data` itself when it is a single record
|
|
118
|
+
(`baker experiment plan ... --fields traffic,warning`). Naming a key of the wrapper beside
|
|
119
|
+
keys of its rows narrows both. `meta`, `hints` and warnings are
|
|
120
|
+
kept, and a name no record carries is reported in `hints` alongside the keys that do
|
|
121
|
+
exist. Commands that declare `--fields` themselves keep their own meaning
|
|
122
|
+
(`ads meta insights` chooses which metrics to request; `ads linkedin creatives` takes dotted
|
|
123
|
+
paths; `actions draft` picks the columns of `--output md|files` and leaves its JSON
|
|
124
|
+
whole). A command whose default output is text needs `--output json` for there to be an
|
|
125
|
+
envelope to narrow; without it a note on stderr says the flag changed nothing. A success
|
|
126
|
+
that prints its result beside `ok` rather than under `data` (`canvas validate`,
|
|
127
|
+
`canvas critique`) comes back whole, with a hint saying `--fields` was not applied.
|
|
128
|
+
|
|
113
129
|
### Fresh reads: `--no-cache`
|
|
114
130
|
|
|
115
131
|
Every command that caches takes `--no-cache`, and it skips **both** cache layers — the
|
|
@@ -2,13 +2,13 @@ import {
|
|
|
2
2
|
handleConnectionError,
|
|
3
3
|
needsConnectionFix,
|
|
4
4
|
writeAdsJson
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-ZI7TPBXB.js";
|
|
6
6
|
import {
|
|
7
7
|
ApiError
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-MF7YA62W.js";
|
|
9
9
|
import {
|
|
10
10
|
getEnv
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-HJEMOSPH.js";
|
|
12
12
|
|
|
13
13
|
// src/commands/ads/meta/shared.ts
|
|
14
14
|
var DAY_MS = 864e5;
|
|
@@ -120,4 +120,4 @@ export {
|
|
|
120
120
|
resolveEffectiveStatus,
|
|
121
121
|
statusFilterHints
|
|
122
122
|
};
|
|
123
|
-
//# sourceMappingURL=chunk-
|
|
123
|
+
//# sourceMappingURL=chunk-4ACU7GBN.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
debugLogHttp,
|
|
3
3
|
readBodyForLog
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-VZEDAFAR.js";
|
|
5
5
|
import {
|
|
6
6
|
API_KEY_FORMAT_MESSAGE,
|
|
7
7
|
DIRECT_ROUTE,
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
refuseNonPublicUrl,
|
|
19
19
|
requireConnection,
|
|
20
20
|
shouldEscalate
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-HJEMOSPH.js";
|
|
22
22
|
|
|
23
23
|
// ../../node_modules/.pnpm/safe-stable-stringify@2.5.0/node_modules/safe-stable-stringify/index.js
|
|
24
24
|
var require_safe_stable_stringify = __commonJS({
|
|
@@ -9986,4 +9986,4 @@ export {
|
|
|
9986
9986
|
defaultRegistry,
|
|
9987
9987
|
createEngineFromEnv
|
|
9988
9988
|
};
|
|
9989
|
-
//# sourceMappingURL=chunk-
|
|
9989
|
+
//# sourceMappingURL=chunk-FGHMWBUD.js.map
|
|
@@ -282,6 +282,434 @@ 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
|
+
|
|
285
713
|
// src/output.ts
|
|
286
714
|
var ASPECT_RATIO_MAP = {
|
|
287
715
|
"1:1": 1,
|
|
@@ -671,7 +1099,8 @@ function writeOutput(envelope, format, fields, full, normalizer) {
|
|
|
671
1099
|
return;
|
|
672
1100
|
}
|
|
673
1101
|
if (format === "json") {
|
|
674
|
-
|
|
1102
|
+
write(`${JSON.stringify(fields ? maskEnvelope(envelope, fields) : envelope, null, 2)}
|
|
1103
|
+
`);
|
|
675
1104
|
return;
|
|
676
1105
|
}
|
|
677
1106
|
if (format !== "files" && format !== "md") {
|
|
@@ -829,6 +1258,14 @@ export {
|
|
|
829
1258
|
plannedRoutes,
|
|
830
1259
|
API_KEY_FORMAT_MESSAGE,
|
|
831
1260
|
isBakerApiKey,
|
|
1261
|
+
registerSchema,
|
|
1262
|
+
listSchemas,
|
|
1263
|
+
findSchema,
|
|
1264
|
+
commandPathOf,
|
|
1265
|
+
refuseUnknownFlags,
|
|
1266
|
+
outputFlagForCommand,
|
|
1267
|
+
takeFieldsFlag,
|
|
1268
|
+
installFieldMask,
|
|
832
1269
|
compactImage,
|
|
833
1270
|
compactVideo,
|
|
834
1271
|
videoNormalizer,
|
|
@@ -852,4 +1289,4 @@ export {
|
|
|
852
1289
|
captureVimeoCookie,
|
|
853
1290
|
childEnvWith
|
|
854
1291
|
};
|
|
855
|
-
//# sourceMappingURL=chunk-
|
|
1292
|
+
//# sourceMappingURL=chunk-HJEMOSPH.js.map
|