@dereekb/dbx-cli 13.11.14 → 13.11.16

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/index.cjs.js CHANGED
@@ -411,7 +411,13 @@ var _timeoutMs;
411
411
  fetchImpl = fetcher !== null && fetcher !== void 0 ? fetcher : fetch;
412
412
  timeoutMs = _timeoutMs;
413
413
  method = (_ref = init === null || init === void 0 ? void 0 : init.method) !== null && _ref !== void 0 ? _ref : 'GET';
414
- url = typeof input === 'string' ? input : _instanceof$6(input, URL) ? input.toString() : input.url;
414
+ if (typeof input === 'string') {
415
+ url = input;
416
+ } else if (_instanceof$6(input, URL)) {
417
+ url = input.toString();
418
+ } else {
419
+ url = input.url;
420
+ }
415
421
  verboseLog("".concat(method, " ").concat(url));
416
422
  finalInit = init;
417
423
  if (timeoutMs != null && (init === null || init === void 0 ? void 0 : init.signal) == null) {
@@ -420,7 +426,7 @@ var _timeoutMs;
420
426
  timeoutHandle = setTimeout(function() {
421
427
  return localController.abort();
422
428
  }, timeoutMs);
423
- finalInit = _object_spread_props$a(_object_spread$e({}, init !== null && init !== void 0 ? init : {}), {
429
+ finalInit = _object_spread_props$a(_object_spread$e({}, init), {
424
430
  signal: localController.signal
425
431
  });
426
432
  }
@@ -547,18 +553,21 @@ var _timeoutMs;
547
553
  * @__NO_SIDE_EFFECTS__
548
554
  */ function buildDumpFilePath(extension, suffix) {
549
555
  var dumpDir = _outputOptions.dumpDir, commandPath = _outputOptions.commandPath;
550
- if (!dumpDir) {
551
- return undefined;
552
- }
553
- if (!node_fs.existsSync(dumpDir)) {
554
- node_fs.mkdirSync(dumpDir, {
555
- recursive: true
556
- });
556
+ var result;
557
+ if (dumpDir) {
558
+ if (!node_fs.existsSync(dumpDir)) {
559
+ node_fs.mkdirSync(dumpDir, {
560
+ recursive: true
561
+ });
562
+ }
563
+ var prefix = (commandPath === null || commandPath === void 0 ? void 0 : commandPath.length) ? commandPath.join('_') : 'response';
564
+ var stamp = dumpTimestamp();
565
+ var base = suffix ? "".concat(prefix, "_").concat(stamp, "_").concat(suffix) : "".concat(prefix, "_").concat(stamp);
566
+ result = node_path.join(dumpDir, "".concat(base, ".").concat(extension));
567
+ } else {
568
+ result = undefined;
557
569
  }
558
- var prefix = (commandPath === null || commandPath === void 0 ? void 0 : commandPath.length) ? commandPath.join('_') : 'response';
559
- var stamp = dumpTimestamp();
560
- var base = suffix ? "".concat(prefix, "_").concat(stamp, "_").concat(suffix) : "".concat(prefix, "_").concat(stamp);
561
- return node_path.join(dumpDir, "".concat(base, ".").concat(extension));
570
+ return result;
562
571
  }
563
572
  function dumpResponse(data, meta) {
564
573
  var filePath = buildDumpFilePath('json');
@@ -583,42 +592,47 @@ function dumpResponse(data, meta) {
583
592
  var fields = pick.split(',').map(function(f) {
584
593
  return f.trim();
585
594
  });
595
+ var result;
586
596
  if (Array.isArray(data)) {
587
- return data.map(function(item) {
597
+ result = data.map(function(item) {
588
598
  return pickFromObject(item, fields);
589
599
  });
600
+ } else if (data != null && (typeof data === "undefined" ? "undefined" : _type_of$3(data)) === 'object') {
601
+ result = pickFromObject(data, fields);
602
+ } else {
603
+ result = data;
590
604
  }
591
- if (data != null && (typeof data === "undefined" ? "undefined" : _type_of$3(data)) === 'object') {
592
- return pickFromObject(data, fields);
593
- }
594
- return data;
605
+ return result;
595
606
  }
596
607
  function pickFromObject(obj, fields) {
608
+ var result;
597
609
  if (obj == null || (typeof obj === "undefined" ? "undefined" : _type_of$3(obj)) !== 'object') {
598
- return obj;
599
- }
600
- var result = {};
601
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
602
- try {
603
- for(var _iterator = fields[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
604
- var field = _step.value;
605
- if (field in obj) {
606
- result[field] = obj[field];
607
- }
608
- }
609
- } catch (err) {
610
- _didIteratorError = true;
611
- _iteratorError = err;
612
- } finally{
610
+ result = obj;
611
+ } else {
612
+ var picked = {};
613
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
613
614
  try {
614
- if (!_iteratorNormalCompletion && _iterator.return != null) {
615
- _iterator.return();
615
+ for(var _iterator = fields[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
616
+ var field = _step.value;
617
+ if (field in obj) {
618
+ picked[field] = obj[field];
619
+ }
616
620
  }
621
+ } catch (err) {
622
+ _didIteratorError = true;
623
+ _iteratorError = err;
617
624
  } finally{
618
- if (_didIteratorError) {
619
- throw _iteratorError;
625
+ try {
626
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
627
+ _iterator.return();
628
+ }
629
+ } finally{
630
+ if (_didIteratorError) {
631
+ throw _iteratorError;
632
+ }
620
633
  }
621
634
  }
635
+ result = picked;
622
636
  }
623
637
  return result;
624
638
  }
@@ -689,33 +703,32 @@ function stringifyEnvelope(value) {
689
703
  * @returns The structured {@link CliErrorOutput}.
690
704
  * @__NO_SIDE_EFFECTS__
691
705
  */ function buildErrorOutput(error) {
692
- if (_errorMapper) {
693
- var mapped = _errorMapper(error);
694
- if (mapped) {
695
- return mapped;
696
- }
697
- }
698
- if (_instanceof$6(error, CliError)) {
699
- return _object_spread$e({
706
+ var mapped = _errorMapper ? _errorMapper(error) : undefined;
707
+ var result;
708
+ if (mapped) {
709
+ result = mapped;
710
+ } else if (_instanceof$6(error, CliError)) {
711
+ result = _object_spread$e({
700
712
  ok: false,
701
713
  error: sanitizeString(error.message),
702
714
  code: error.code
703
715
  }, error.suggestion ? {
704
716
  suggestion: error.suggestion
705
717
  } : {});
706
- }
707
- if (_instanceof$6(error, Error)) {
708
- return {
718
+ } else if (_instanceof$6(error, Error)) {
719
+ result = {
709
720
  ok: false,
710
721
  error: sanitizeString(error.message),
711
722
  code: 'ERROR'
712
723
  };
724
+ } else {
725
+ result = {
726
+ ok: false,
727
+ error: sanitizeString(String(error)),
728
+ code: 'UNKNOWN_ERROR'
729
+ };
713
730
  }
714
- return {
715
- ok: false,
716
- error: sanitizeString(String(error)),
717
- code: 'UNKNOWN_ERROR'
718
- };
731
+ return result;
719
732
  }
720
733
 
721
734
  function _array_like_to_array$b(arr, len) {
@@ -1124,21 +1137,22 @@ var MAX_MODEL_ACCESS_MULTI_READ_KEYS = 50;
1124
1137
  }
1125
1138
  function requestJson(input) {
1126
1139
  return _async_to_generator$l(function() {
1127
- var init, res, _ref, ok, body, fallbackMessage;
1140
+ var hasJsonBody, init, res, _ref, ok, body, fallbackMessage;
1128
1141
  return _ts_generator$l(this, function(_state) {
1129
1142
  switch(_state.label){
1130
1143
  case 0:
1144
+ hasJsonBody = input.jsonBody !== undefined;
1131
1145
  init = _object_spread$d({
1132
1146
  method: input.method,
1133
1147
  headers: _object_spread$d({
1134
1148
  Accept: 'application/json',
1135
1149
  Authorization: "Bearer ".concat(input.accessToken)
1136
- }, input.jsonBody !== undefined ? {
1150
+ }, hasJsonBody ? {
1137
1151
  'Content-Type': 'application/json'
1138
- } : {})
1139
- }, input.jsonBody !== undefined ? {
1152
+ } : null)
1153
+ }, hasJsonBody ? {
1140
1154
  body: JSON.stringify(input.jsonBody)
1141
- } : {});
1155
+ } : null);
1142
1156
  return [
1143
1157
  4,
1144
1158
  tracedFetch(input.fetcher, input.url, init)
@@ -1203,13 +1217,23 @@ function extractMessage(body, fallback, res) {
1203
1217
  return messageString !== null && messageString !== void 0 ? messageString : fallback || "".concat(res.status, " ").concat(res.statusText);
1204
1218
  }
1205
1219
  function codeForStatus(status) {
1206
- if (status === 401) return 'AUTH_UNAUTHORIZED';
1207
- if (status === 403) return 'AUTH_FORBIDDEN';
1208
- if (status === 404) return 'NOT_FOUND';
1209
- if (status === 422) return 'VALIDATION_ERROR';
1210
- if (status === 429) return 'RATE_LIMITED';
1211
- if (status >= 500) return 'SERVER_ERROR';
1212
- return 'API_ERROR';
1220
+ var result;
1221
+ if (status === 401) {
1222
+ result = 'AUTH_UNAUTHORIZED';
1223
+ } else if (status === 403) {
1224
+ result = 'AUTH_FORBIDDEN';
1225
+ } else if (status === 404) {
1226
+ result = 'NOT_FOUND';
1227
+ } else if (status === 422) {
1228
+ result = 'VALIDATION_ERROR';
1229
+ } else if (status === 429) {
1230
+ result = 'RATE_LIMITED';
1231
+ } else if (status >= 500) {
1232
+ result = 'SERVER_ERROR';
1233
+ } else {
1234
+ result = 'API_ERROR';
1235
+ }
1236
+ return result;
1213
1237
  }
1214
1238
  function trimSlash$1(url) {
1215
1239
  return url.endsWith('/') ? url.slice(0, -1) : url;
@@ -2281,26 +2305,32 @@ function _processPage(input) {
2281
2305
  }
2282
2306
  function _computeEffectiveLimit(totalItemsLimit, limitPerPage, totalItems) {
2283
2307
  var remainingBudget = totalItemsLimit == null ? undefined : totalItemsLimit - totalItems;
2308
+ var result;
2284
2309
  if (limitPerPage != null && remainingBudget != null) {
2285
- return Math.min(limitPerPage, remainingBudget);
2310
+ result = Math.min(limitPerPage, remainingBudget);
2311
+ } else {
2312
+ result = limitPerPage !== null && limitPerPage !== void 0 ? limitPerPage : remainingBudget;
2286
2313
  }
2287
- return limitPerPage !== null && limitPerPage !== void 0 ? limitPerPage : remainingBudget;
2314
+ return result;
2288
2315
  }
2289
2316
  function _evaluateLoopExit(input) {
2290
2317
  var totalItemsLimit = input.totalItemsLimit, maxPages = input.maxPages, totalItems = input.totalItems, pageIndex = input.pageIndex, hasMore = input.hasMore, cursorDocumentKey = input.cursorDocumentKey;
2291
2318
  var reachedItemsLimit = totalItemsLimit != null && totalItems >= totalItemsLimit;
2292
2319
  var reachedPagesLimit = maxPages != null && pageIndex >= maxPages;
2320
+ var result;
2293
2321
  if (reachedItemsLimit || reachedPagesLimit) {
2294
- return {
2322
+ result = {
2295
2323
  stop: true,
2296
2324
  hitLimit: true
2297
2325
  };
2326
+ } else {
2327
+ var exhausted = hasMore === false || cursorDocumentKey == null;
2328
+ result = {
2329
+ stop: exhausted,
2330
+ hitLimit: false
2331
+ };
2298
2332
  }
2299
- var exhausted = hasMore === false || cursorDocumentKey == null;
2300
- return {
2301
- stop: exhausted,
2302
- hitLimit: false
2303
- };
2333
+ return result;
2304
2334
  }
2305
2335
  /**
2306
2336
  * Iterates a paginated `callModel` endpoint, exhausting (or stopping at the configured limit) all pages.
@@ -2313,6 +2343,9 @@ function _evaluateLoopExit(input) {
2313
2343
  * Concurrency: pages are fetched serially (cursor dependency); items within a page can run
2314
2344
  * in parallel via `maxParallelPerPage` (forwarded to `performAsyncTasks`).
2315
2345
  *
2346
+ * @param config - Iterator configuration.
2347
+ * @returns The aggregate result.
2348
+ *
2316
2349
  * @example
2317
2350
  * ```ts
2318
2351
  * // Exhaust every published Guestbook entry for a single Guestbook.
@@ -2322,7 +2355,6 @@ function _evaluateLoopExit(input) {
2322
2355
  * params: { guestbook: 'gb/abc', published: true }
2323
2356
  * });
2324
2357
  * ```
2325
- *
2326
2358
  * @example
2327
2359
  * ```ts
2328
2360
  * // Fan out to a child action per Guestbook, with 4-way parallelism per page.
@@ -2334,9 +2366,6 @@ function _evaluateLoopExit(input) {
2334
2366
  * iterateItem: ({ context, key }) => queryGuestbookEntriesForGuestbook({ context, guestbook: key, published: true })
2335
2367
  * });
2336
2368
  * ```
2337
- *
2338
- * @param config - Iterator configuration.
2339
- * @returns The aggregate result.
2340
2369
  */ function iterateDbxCliCallModel(config) {
2341
2370
  return _async_to_generator$i(function() {
2342
2371
  var context, modelType, call, specifier, params, _config_buildRequestData, buildRequestData, _config_responseAdapter, responseAdapter, limitPerPage, totalItemsLimit, maxPages, iterateItem, iteratePage, itemPerformTasksConfig, maxParallelPerPage, _config_collectItems, collectItems, _config_collectItemResults, collectItemResults, _config_collectPageResults, collectPageResults, allItems, allItemResults, allPageResults, pageIndex, totalItems, cursorDocumentKey, hitLimit, keepGoing, collectItemsForPage, collectItemResultsForPage, collectPageResultsForPage, effectiveLimit, data, raw, pageOutcome, _allItems, _allItemResults, exit, result;
@@ -3276,7 +3305,7 @@ function _ts_generator$f(thisArg, body) {
3276
3305
  *
3277
3306
  * Provides direct access to the demo-api's typed model dispatch without typed wrappers — useful
3278
3307
  * for ad-hoc admin tasks, scripting, and the MVP demo CLI before model-specific commands ship.
3279
- */ var callPassthroughCommand = {
3308
+ */ var CALL_PASSTHROUGH_COMMAND = {
3280
3309
  command: 'call <model> <verb> [specifier]',
3281
3310
  describe: 'POST a typed model call: { modelType, call, specifier?, data } — generic passthrough',
3282
3311
  builder: function builder(yargs) {
@@ -3412,9 +3441,10 @@ function _unsupported_iterable_to_array$8(o, minLen) {
3412
3441
  * `modelType` first, then falls back to `identityConst` and `collectionPrefix`
3413
3442
  * so callers can pass any of the three forms a user might type at the CLI.
3414
3443
  *
3415
- * @param modelType - identifier to look up.
3416
- * @param manifest - generated model manifest.
3417
- * @returns the matching entry, or `undefined` when none exists.
3444
+ * @param modelType - Identifier to look up.
3445
+ * @param manifest - Generated model manifest.
3446
+ * @returns The matching entry, or `undefined` when none exists.
3447
+ *
3418
3448
  * @__NO_SIDE_EFFECTS__
3419
3449
  */ function findCliModelManifestEntry(modelType, manifest) {
3420
3450
  var result;
@@ -3453,95 +3483,108 @@ function _unsupported_iterable_to_array$8(o, minLen) {
3453
3483
  * Unknown keys, primitives, `Date`, `null`, and `undefined` pass through
3454
3484
  * unchanged.
3455
3485
  *
3456
- * @param modelType - the model identifier (`modelType`, `identityConst`,
3486
+ * @param modelType - The model identifier (`modelType`, `identityConst`,
3457
3487
  * or `collectionPrefix`) used to look up the rewrite map.
3458
- * @param data - the value to rewrite (typically a `read`/`query` response
3488
+ * @param data - The value to rewrite (typically a `read`/`query` response
3459
3489
  * payload).
3460
- * @param manifest - generated model manifest.
3461
- * @returns the rewritten value, or `data` unchanged when no rewrite applies.
3490
+ * @param manifest - Generated model manifest.
3491
+ * @returns The rewritten value, or `data` unchanged when no rewrite applies.
3492
+ *
3462
3493
  * @__NO_SIDE_EFFECTS__
3463
3494
  */ function expandModelKeys(modelType, data, manifest) {
3464
3495
  var entry = findCliModelManifestEntry(modelType, manifest);
3465
- if (!entry) return data;
3466
- return rewriteWithFields(data, entry.fields);
3496
+ return entry ? rewriteWithFields(data, entry.fields) : data;
3467
3497
  }
3468
3498
  function rewriteWithFields(value, fields) {
3499
+ var result;
3469
3500
  if (Array.isArray(value)) {
3470
- return value.map(function(item) {
3501
+ result = value.map(function(item) {
3471
3502
  return rewriteWithFields(item, fields);
3472
3503
  });
3473
- }
3474
- if (!isPlainObject(value)) return value;
3475
- var fieldByName = new Map();
3476
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
3477
- try {
3478
- for(var _iterator = fields[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
3479
- var field = _step.value;
3480
- fieldByName.set(field.name, field);
3481
- }
3482
- } catch (err) {
3483
- _didIteratorError = true;
3484
- _iteratorError = err;
3485
- } finally{
3504
+ } else if (isPlainObject(value)) {
3505
+ var fieldByName = new Map();
3506
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
3486
3507
  try {
3487
- if (!_iteratorNormalCompletion && _iterator.return != null) {
3488
- _iterator.return();
3508
+ for(var _iterator = fields[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
3509
+ var field = _step.value;
3510
+ fieldByName.set(field.name, field);
3489
3511
  }
3512
+ } catch (err) {
3513
+ _didIteratorError = true;
3514
+ _iteratorError = err;
3490
3515
  } finally{
3491
- if (_didIteratorError) {
3492
- throw _iteratorError;
3493
- }
3494
- }
3495
- }
3496
- var out = {};
3497
- var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
3498
- try {
3499
- for(var _iterator1 = Object.entries(value)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
3500
- var _step_value = _sliced_to_array$4(_step1.value, 2), key = _step_value[0], raw = _step_value[1];
3501
- var field1 = fieldByName.get(key);
3502
- if (!field1) {
3503
- out[key] = raw;
3504
- continue;
3516
+ try {
3517
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
3518
+ _iterator.return();
3519
+ }
3520
+ } finally{
3521
+ if (_didIteratorError) {
3522
+ throw _iteratorError;
3523
+ }
3505
3524
  }
3506
- var longKey = field1.longName.length > 0 ? field1.longName : key;
3507
- out[longKey] = rewriteFieldValue(raw, field1);
3508
3525
  }
3509
- } catch (err) {
3510
- _didIteratorError1 = true;
3511
- _iteratorError1 = err;
3512
- } finally{
3526
+ var out = {};
3527
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
3513
3528
  try {
3514
- if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
3515
- _iterator1.return();
3529
+ for(var _iterator1 = Object.entries(value)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
3530
+ var _step_value = _sliced_to_array$4(_step1.value, 2), key = _step_value[0], raw = _step_value[1];
3531
+ var field1 = fieldByName.get(key);
3532
+ if (field1) {
3533
+ var longKey = field1.longName.length > 0 ? field1.longName : key;
3534
+ out[longKey] = rewriteFieldValue(raw, field1);
3535
+ } else {
3536
+ out[key] = raw;
3537
+ }
3516
3538
  }
3539
+ } catch (err) {
3540
+ _didIteratorError1 = true;
3541
+ _iteratorError1 = err;
3517
3542
  } finally{
3518
- if (_didIteratorError1) {
3519
- throw _iteratorError1;
3543
+ try {
3544
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
3545
+ _iterator1.return();
3546
+ }
3547
+ } finally{
3548
+ if (_didIteratorError1) {
3549
+ throw _iteratorError1;
3550
+ }
3520
3551
  }
3521
3552
  }
3553
+ result = out;
3554
+ } else {
3555
+ result = value;
3522
3556
  }
3523
- return out;
3557
+ return result;
3524
3558
  }
3525
3559
  function rewriteFieldValue(value, field) {
3526
3560
  var nested = field.nestedFields;
3527
- if (!nested || nested.length === 0) return value;
3528
- if (field.nestedIsArray) {
3529
- if (!Array.isArray(value)) return value;
3530
- return value.map(function(item) {
3561
+ var result;
3562
+ if (!nested || nested.length === 0) {
3563
+ result = value;
3564
+ } else if (field.nestedIsArray) {
3565
+ result = Array.isArray(value) ? value.map(function(item) {
3531
3566
  return rewriteWithFields(item, nested);
3532
- });
3567
+ }) : value;
3568
+ } else if (isPlainObject(value)) {
3569
+ result = rewriteWithFields(value, nested);
3570
+ } else {
3571
+ result = value;
3533
3572
  }
3534
- if (!isPlainObject(value)) return value;
3535
- return rewriteWithFields(value, nested);
3573
+ return result;
3536
3574
  }
3537
3575
  function isPlainObject(value) {
3538
- if (value === null || (typeof value === "undefined" ? "undefined" : _type_of$1(value)) !== 'object') return false;
3539
- if (Array.isArray(value)) return false;
3540
- if (_instanceof$4(value, Date)) return false;
3541
- // Objects from JSON.parse have Object.prototype as their proto. Anything
3542
- // exotic (Map, Set, Buffer, class instances) we leave untouched.
3543
- var proto = Object.getPrototypeOf(value);
3544
- return proto === Object.prototype || proto === null;
3576
+ var result;
3577
+ if (value === null || (typeof value === "undefined" ? "undefined" : _type_of$1(value)) !== 'object') {
3578
+ result = false;
3579
+ } else if (Array.isArray(value) || _instanceof$4(value, Date)) {
3580
+ result = false;
3581
+ } else {
3582
+ // Objects from JSON.parse have Object.prototype as their proto. Anything
3583
+ // exotic (Map, Set, Buffer, class instances) we leave untouched.
3584
+ var proto = Object.getPrototypeOf(value);
3585
+ result = proto === Object.prototype || proto === null;
3586
+ }
3587
+ return result;
3545
3588
  }
3546
3589
 
3547
3590
  function _array_like_to_array$7(arr, len) {
@@ -3626,6 +3669,8 @@ function runHandler$1(manifest, argv) {
3626
3669
  * @param rawKey - The Firestore key string.
3627
3670
  * @param manifest - The generated model manifest.
3628
3671
  * @returns The decoded key with leaf, ancestors, and any unresolved prefixes.
3672
+ * @throws {CliError} When `rawKey` is empty or does not parse into an even number of `prefix/id` segments.
3673
+ *
3629
3674
  * @__NO_SIDE_EFFECTS__
3630
3675
  */ function decodeFirestoreModelKey(rawKey, manifest) {
3631
3676
  var trimmed = rawKey.trim();
@@ -3666,13 +3711,7 @@ function runHandler$1(manifest, argv) {
3666
3711
  };
3667
3712
  }
3668
3713
  function toSegment(prefix, id, entry) {
3669
- if (!entry) {
3670
- return {
3671
- prefix: prefix,
3672
- id: id
3673
- };
3674
- }
3675
- return {
3714
+ var result = entry ? {
3676
3715
  prefix: prefix,
3677
3716
  id: id,
3678
3717
  modelName: entry.modelName,
@@ -3682,15 +3721,20 @@ function toSegment(prefix, id, entry) {
3682
3721
  parentIdentityConst: entry.parentIdentityConst,
3683
3722
  sourcePackage: entry.sourcePackage,
3684
3723
  sourceFile: entry.sourceFile
3724
+ } : {
3725
+ prefix: prefix,
3726
+ id: id
3685
3727
  };
3728
+ return result;
3686
3729
  }
3687
3730
  /**
3688
3731
  * Renders a {@link DecodedKey} as a human-readable text block. Mirrors the
3689
3732
  * MCP `dbx_model_decode` key-mode output for consistency between agent and
3690
3733
  * shell consumers.
3691
3734
  *
3692
- * @param decoded - the decoded key returned by {@link decodeFirestoreModelKey}.
3693
- * @returns the formatted block with a trailing newline.
3735
+ * @param decoded - The decoded key returned by {@link decodeFirestoreModelKey}.
3736
+ * @returns The formatted block with a trailing newline.
3737
+ *
3694
3738
  * @__NO_SIDE_EFFECTS__
3695
3739
  */ function renderDecodedKey(decoded) {
3696
3740
  var lines = _to_consumable_array$5(renderLeafLines(decoded.leaf));
@@ -3708,32 +3752,31 @@ function toSegment(prefix, id, entry) {
3708
3752
  return lines.join('\n') + '\n';
3709
3753
  }
3710
3754
  function renderLeafLines(leaf) {
3711
- if (!leaf.modelName) {
3712
- return [
3755
+ var lines;
3756
+ if (leaf.modelName) {
3757
+ lines = [
3758
+ "Model: ".concat(leaf.modelName)
3759
+ ];
3760
+ if (leaf.identityConst) lines.push("identityConst: ".concat(leaf.identityConst));
3761
+ if (leaf.modelType) lines.push("modelType: ".concat(leaf.modelType));
3762
+ lines.push("prefix: ".concat(leaf.prefix), "id: ".concat(leaf.id));
3763
+ if (leaf.modelGroup) lines.push("modelGroup: ".concat(leaf.modelGroup));
3764
+ if (leaf.parentIdentityConst) lines.push("parentIdentityConst: ".concat(leaf.parentIdentityConst));
3765
+ if (leaf.sourcePackage) {
3766
+ var sourceSuffix = leaf.sourceFile ? " (".concat(leaf.sourceFile, ")") : '';
3767
+ lines.push("source: ".concat(leaf.sourcePackage).concat(sourceSuffix));
3768
+ }
3769
+ } else {
3770
+ lines = [
3713
3771
  "Model: <unknown — prefix '".concat(leaf.prefix, "' not in manifest>"),
3714
3772
  "prefix: ".concat(leaf.prefix),
3715
3773
  "id: ".concat(leaf.id)
3716
3774
  ];
3717
3775
  }
3718
- var lines = [
3719
- "Model: ".concat(leaf.modelName)
3720
- ];
3721
- if (leaf.identityConst) lines.push("identityConst: ".concat(leaf.identityConst));
3722
- if (leaf.modelType) lines.push("modelType: ".concat(leaf.modelType));
3723
- lines.push("prefix: ".concat(leaf.prefix), "id: ".concat(leaf.id));
3724
- if (leaf.modelGroup) lines.push("modelGroup: ".concat(leaf.modelGroup));
3725
- if (leaf.parentIdentityConst) lines.push("parentIdentityConst: ".concat(leaf.parentIdentityConst));
3726
- if (leaf.sourcePackage) {
3727
- var sourceSuffix = leaf.sourceFile ? " (".concat(leaf.sourceFile, ")") : '';
3728
- lines.push("source: ".concat(leaf.sourcePackage).concat(sourceSuffix));
3729
- }
3730
3776
  return lines;
3731
3777
  }
3732
3778
  function renderAncestorLine(ancestor) {
3733
- if (ancestor.modelName) {
3734
- return "- ".concat(ancestor.modelName, " — prefix ").concat(ancestor.prefix, ", id ").concat(ancestor.id);
3735
- }
3736
- return "- <unknown> — prefix ".concat(ancestor.prefix, ", id ").concat(ancestor.id);
3779
+ return ancestor.modelName ? "- ".concat(ancestor.modelName, " — prefix ").concat(ancestor.prefix, ", id ").concat(ancestor.id) : "- <unknown> — prefix ".concat(ancestor.prefix, ", id ").concat(ancestor.id);
3737
3780
  }
3738
3781
 
3739
3782
  function _array_like_to_array$6(arr, len) {
@@ -3807,10 +3850,13 @@ function _unsupported_iterable_to_array$6(o, minLen) {
3807
3850
  * {@link CliError} if the manifest is missing, the prefix is unresolved, or the leaf
3808
3851
  * has no `modelType`.
3809
3852
  *
3853
+ * @param input - Positionals captured by yargs plus the optional model manifest.
3810
3854
  * @param input.modelOrKey - The first positional from yargs.
3811
3855
  * @param input.key - The optional second positional from yargs.
3812
3856
  * @param input.manifest - The generated model manifest (for prefix lookup).
3813
3857
  * @returns The parsed `{ modelType, key }` pair.
3858
+ * @throws {CliError} When `modelOrKey` is missing, when no manifest is wired but inference is required, when the bare positional is not a full key, or when the manifest cannot resolve the key's prefix.
3859
+ *
3814
3860
  * @__NO_SIDE_EFFECTS__
3815
3861
  */ function parseGetArgs(input) {
3816
3862
  var _input_modelOrKey;
@@ -3823,37 +3869,40 @@ function _unsupported_iterable_to_array$6(o, minLen) {
3823
3869
  });
3824
3870
  }
3825
3871
  var explicitKey = (_input_key = input.key) === null || _input_key === void 0 ? void 0 : _input_key.trim();
3872
+ var result;
3826
3873
  if (explicitKey != null && explicitKey.length > 0) {
3827
- return {
3874
+ result = {
3828
3875
  modelType: modelOrKey,
3829
3876
  key: explicitKey
3830
3877
  };
3878
+ } else {
3879
+ if (!modelOrKey.includes('/')) {
3880
+ throw new CliError({
3881
+ message: "get: '".concat(modelOrKey, "' looks like a bare doc id. Provide a full key (e.g. 'jws/abc123') or use 'get <model> <key>'."),
3882
+ code: 'INVALID_ARGUMENT'
3883
+ });
3884
+ }
3885
+ var manifest = input.manifest;
3886
+ if (!manifest || manifest.length === 0) {
3887
+ throw new CliError({
3888
+ message: 'get: cannot infer modelType — no model manifest is wired into the CLI. Pass `modelManifest` to `runCli`, or use `get <model> <key>` explicitly.',
3889
+ code: 'INVALID_ARGUMENT'
3890
+ });
3891
+ }
3892
+ var decoded = decodeFirestoreModelKey(modelOrKey, manifest);
3893
+ if (decoded.unresolvedPrefixes.length > 0 || !decoded.leaf.modelType) {
3894
+ throw new CliError({
3895
+ message: "get: unable to resolve modelType for key '".concat(modelOrKey, "'. Unknown prefix: ").concat(decoded.unresolvedPrefixes.join(', ') || decoded.leaf.prefix, ". Known prefixes: ").concat(manifestPrefixList(manifest), "."),
3896
+ code: 'INVALID_ARGUMENT',
3897
+ suggestion: "Run `<cli> model-decode '<key>'` to inspect a key, or use `get <model> <key>` explicitly."
3898
+ });
3899
+ }
3900
+ result = {
3901
+ modelType: decoded.leaf.modelType,
3902
+ key: modelOrKey
3903
+ };
3831
3904
  }
3832
- if (!modelOrKey.includes('/')) {
3833
- throw new CliError({
3834
- message: "get: '".concat(modelOrKey, "' looks like a bare doc id. Provide a full key (e.g. 'jws/abc123') or use 'get <model> <key>'."),
3835
- code: 'INVALID_ARGUMENT'
3836
- });
3837
- }
3838
- var manifest = input.manifest;
3839
- if (!manifest || manifest.length === 0) {
3840
- throw new CliError({
3841
- message: 'get: cannot infer modelType — no model manifest is wired into the CLI. Pass `modelManifest` to `runCli`, or use `get <model> <key>` explicitly.',
3842
- code: 'INVALID_ARGUMENT'
3843
- });
3844
- }
3845
- var decoded = decodeFirestoreModelKey(modelOrKey, manifest);
3846
- if (decoded.unresolvedPrefixes.length > 0 || !decoded.leaf.modelType) {
3847
- throw new CliError({
3848
- message: "get: unable to resolve modelType for key '".concat(modelOrKey, "'. Unknown prefix: ").concat(decoded.unresolvedPrefixes.join(', ') || decoded.leaf.prefix, ". Known prefixes: ").concat(manifestPrefixList(manifest), "."),
3849
- code: 'INVALID_ARGUMENT',
3850
- suggestion: "Run `<cli> model-decode '<key>'` to inspect a key, or use `get <model> <key>` explicitly."
3851
- });
3852
- }
3853
- return {
3854
- modelType: decoded.leaf.modelType,
3855
- key: modelOrKey
3856
- };
3905
+ return result;
3857
3906
  }
3858
3907
  /**
3859
3908
  * Parses the positionals for the top-level `get-many <firstArg> [rest..]` command.
@@ -3866,10 +3915,13 @@ function _unsupported_iterable_to_array$6(o, minLen) {
3866
3915
  *
3867
3916
  * Always rejects empty key lists and lists exceeding 50 keys.
3868
3917
  *
3918
+ * @param input - Positionals captured by yargs plus the optional model manifest.
3869
3919
  * @param input.firstArg - The first positional from yargs.
3870
3920
  * @param input.rest - The remaining positionals from yargs.
3871
3921
  * @param input.manifest - The generated model manifest (used only in the inferred-key branch).
3872
3922
  * @returns The parsed `{ modelType, keys }` pair.
3923
+ * @throws {CliError} When positionals are missing, when an inferred-key call lacks a manifest, when one or more keys cannot be resolved, or when the keys span multiple `modelType`s.
3924
+ *
3873
3925
  * @__NO_SIDE_EFFECTS__
3874
3926
  */ function parseGetManyArgs(input) {
3875
3927
  var _input_firstArg, _input_rest;
@@ -3885,22 +3937,25 @@ function _unsupported_iterable_to_array$6(o, minLen) {
3885
3937
  code: 'INVALID_ARGUMENT'
3886
3938
  });
3887
3939
  }
3940
+ var result;
3888
3941
  if (firstArg.includes('/')) {
3889
3942
  var keys = [
3890
3943
  firstArg
3891
3944
  ].concat(_to_consumable_array$4(rest));
3892
- return inferModelTypeFromKeys(keys, input.manifest);
3893
- }
3894
- if (rest.length === 0) {
3895
- throw new CliError({
3896
- message: "get-many: '".concat(firstArg, "' has no '/' so it was treated as a model name, but no keys were supplied. Usage: 'get-many <model> <key...>'."),
3897
- code: 'INVALID_ARGUMENT'
3898
- });
3945
+ result = inferModelTypeFromKeys(keys, input.manifest);
3946
+ } else {
3947
+ if (rest.length === 0) {
3948
+ throw new CliError({
3949
+ message: "get-many: '".concat(firstArg, "' has no '/' so it was treated as a model name, but no keys were supplied. Usage: 'get-many <model> <key...>'."),
3950
+ code: 'INVALID_ARGUMENT'
3951
+ });
3952
+ }
3953
+ result = {
3954
+ modelType: firstArg,
3955
+ keys: rest
3956
+ };
3899
3957
  }
3900
- return {
3901
- modelType: firstArg,
3902
- keys: rest
3903
- };
3958
+ return result;
3904
3959
  }
3905
3960
  function inferModelTypeFromKeys(keys, manifest) {
3906
3961
  if (!manifest || manifest.length === 0) {
@@ -4098,7 +4153,7 @@ function _ts_generator$e(thisArg, body) {
4098
4153
  * explicit `modelType` straight through.
4099
4154
  *
4100
4155
  * Backend: `GET <apiBaseUrl>/model/<modelType>/get?key=<key>` (ModelApiController.getOne).
4101
- */ var getCommand = {
4156
+ */ var GET_COMMAND = {
4102
4157
  command: 'get <modelOrKey> [key]',
4103
4158
  describe: 'Read a document by key. ModelType is inferred from the key prefix when only one positional is supplied.',
4104
4159
  builder: function builder(yargs) {
@@ -4278,7 +4333,7 @@ function _ts_generator$d(thisArg, body) {
4278
4333
  * (e.g. `cat keys.txt | <cli> get-many -`).
4279
4334
  *
4280
4335
  * Backend: `POST <apiBaseUrl>/model/<modelType>/get` with body `{ keys }` (ModelApiController.getMany).
4281
- */ var getManyCommand = {
4336
+ */ var GET_MANY_COMMAND = {
4282
4337
  command: 'get-many <firstArg> [rest..]',
4283
4338
  describe: 'Read documents by key (auto-chunks beyond 50). Pass `-` to read keys from stdin.',
4284
4339
  builder: function builder(yargs) {
@@ -4605,34 +4660,38 @@ function _ts_generator$c(thisArg, body) {
4605
4660
  };
4606
4661
  }
4607
4662
  function mergeOutputCommandsConfig(existing, updates) {
4608
- if (!('commands' in updates)) {
4609
- return existing;
4610
- }
4611
- if (!updates.commands) {
4612
- return undefined;
4613
- }
4614
- var merged = _object_spread$9({}, existing);
4615
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
4616
- try {
4617
- for(var _iterator = Object.keys(updates.commands)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
4618
- var key = _step.value;
4619
- merged[key] = _object_spread$9({}, existing === null || existing === void 0 ? void 0 : existing[key], updates.commands[key]);
4620
- }
4621
- } catch (err) {
4622
- _didIteratorError = true;
4623
- _iteratorError = err;
4624
- } finally{
4625
- try {
4626
- if (!_iteratorNormalCompletion && _iterator.return != null) {
4627
- _iterator.return();
4628
- }
4629
- } finally{
4630
- if (_didIteratorError) {
4631
- throw _iteratorError;
4663
+ var result;
4664
+ if ('commands' in updates) {
4665
+ if (updates.commands) {
4666
+ var merged = _object_spread$9({}, existing);
4667
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
4668
+ try {
4669
+ for(var _iterator = Object.keys(updates.commands)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
4670
+ var key = _step.value;
4671
+ merged[key] = _object_spread$9({}, existing === null || existing === void 0 ? void 0 : existing[key], updates.commands[key]);
4672
+ }
4673
+ } catch (err) {
4674
+ _didIteratorError = true;
4675
+ _iteratorError = err;
4676
+ } finally{
4677
+ try {
4678
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
4679
+ _iterator.return();
4680
+ }
4681
+ } finally{
4682
+ if (_didIteratorError) {
4683
+ throw _iteratorError;
4684
+ }
4685
+ }
4632
4686
  }
4687
+ result = merged;
4688
+ } else {
4689
+ result = undefined;
4633
4690
  }
4691
+ } else {
4692
+ result = existing;
4634
4693
  }
4635
- return merged;
4694
+ return result;
4636
4695
  }
4637
4696
  /**
4638
4697
  * Resolves output settings for a given command path.
@@ -4663,13 +4722,15 @@ function mergeOutputCommandsConfig(existing, updates) {
4663
4722
  * @param value - The string to mask. `null`/`undefined` are returned unchanged.
4664
4723
  * @returns The masked string (`***` when the input is 4 chars or shorter), or the input unchanged when nullish.
4665
4724
  */ function maskSecret(value) {
4725
+ var result;
4666
4726
  if (value == null) {
4667
- return value;
4668
- }
4669
- if (value.length <= 4) {
4670
- return '***';
4727
+ result = value;
4728
+ } else if (value.length <= 4) {
4729
+ result = '***';
4730
+ } else {
4731
+ result = value.substring(0, 4) + '***';
4671
4732
  }
4672
- return value.substring(0, 4) + '***';
4733
+ return result;
4673
4734
  }
4674
4735
 
4675
4736
  /**
@@ -4767,8 +4828,6 @@ function nonEmpty(value) {
4767
4828
  * @param input.env - The base {@link CliEnvConfig} to overlay env-var values on top of.
4768
4829
  * @returns The merged {@link CliEnvConfig}, or `undefined` when both the stored env and every override are empty.
4769
4830
  */ function applyEnvVarOverrides(input) {
4770
- var _ref, _ref1;
4771
- var _input_env, _input_env1, _input_env2, _input_env3, _input_env4, _input_env5, _input_env6;
4772
4831
  var prefix = input.cliName.replaceAll('-', '_').toUpperCase();
4773
4832
  var apiBaseUrl = process.env["".concat(prefix, "_API_BASE_URL")];
4774
4833
  var oidcIssuer = process.env["".concat(prefix, "_OIDC_ISSUER")];
@@ -4778,18 +4837,22 @@ function nonEmpty(value) {
4778
4837
  var redirectUri = process.env["".concat(prefix, "_REDIRECT_URI")];
4779
4838
  var scopes = process.env["".concat(prefix, "_SCOPES")];
4780
4839
  var hasOverrides = apiBaseUrl || oidcIssuer || appClientUrl || clientId || clientSecret || redirectUri || scopes;
4840
+ var result;
4781
4841
  if (!input.env && !hasOverrides) {
4782
- return undefined;
4783
- }
4784
- var result = {
4785
- apiBaseUrl: (_ref = apiBaseUrl !== null && apiBaseUrl !== void 0 ? apiBaseUrl : (_input_env = input.env) === null || _input_env === void 0 ? void 0 : _input_env.apiBaseUrl) !== null && _ref !== void 0 ? _ref : '',
4786
- oidcIssuer: (_ref1 = oidcIssuer !== null && oidcIssuer !== void 0 ? oidcIssuer : (_input_env1 = input.env) === null || _input_env1 === void 0 ? void 0 : _input_env1.oidcIssuer) !== null && _ref1 !== void 0 ? _ref1 : '',
4787
- appClientUrl: appClientUrl !== null && appClientUrl !== void 0 ? appClientUrl : (_input_env2 = input.env) === null || _input_env2 === void 0 ? void 0 : _input_env2.appClientUrl,
4788
- clientId: clientId !== null && clientId !== void 0 ? clientId : (_input_env3 = input.env) === null || _input_env3 === void 0 ? void 0 : _input_env3.clientId,
4789
- clientSecret: clientSecret !== null && clientSecret !== void 0 ? clientSecret : (_input_env4 = input.env) === null || _input_env4 === void 0 ? void 0 : _input_env4.clientSecret,
4790
- redirectUri: redirectUri !== null && redirectUri !== void 0 ? redirectUri : (_input_env5 = input.env) === null || _input_env5 === void 0 ? void 0 : _input_env5.redirectUri,
4791
- scopes: scopes !== null && scopes !== void 0 ? scopes : (_input_env6 = input.env) === null || _input_env6 === void 0 ? void 0 : _input_env6.scopes
4792
- };
4842
+ result = undefined;
4843
+ } else {
4844
+ var _ref, _ref1;
4845
+ var _input_env, _input_env1, _input_env2, _input_env3, _input_env4, _input_env5, _input_env6;
4846
+ result = {
4847
+ apiBaseUrl: (_ref = apiBaseUrl !== null && apiBaseUrl !== void 0 ? apiBaseUrl : (_input_env = input.env) === null || _input_env === void 0 ? void 0 : _input_env.apiBaseUrl) !== null && _ref !== void 0 ? _ref : '',
4848
+ oidcIssuer: (_ref1 = oidcIssuer !== null && oidcIssuer !== void 0 ? oidcIssuer : (_input_env1 = input.env) === null || _input_env1 === void 0 ? void 0 : _input_env1.oidcIssuer) !== null && _ref1 !== void 0 ? _ref1 : '',
4849
+ appClientUrl: appClientUrl !== null && appClientUrl !== void 0 ? appClientUrl : (_input_env2 = input.env) === null || _input_env2 === void 0 ? void 0 : _input_env2.appClientUrl,
4850
+ clientId: clientId !== null && clientId !== void 0 ? clientId : (_input_env3 = input.env) === null || _input_env3 === void 0 ? void 0 : _input_env3.clientId,
4851
+ clientSecret: clientSecret !== null && clientSecret !== void 0 ? clientSecret : (_input_env4 = input.env) === null || _input_env4 === void 0 ? void 0 : _input_env4.clientSecret,
4852
+ redirectUri: redirectUri !== null && redirectUri !== void 0 ? redirectUri : (_input_env5 = input.env) === null || _input_env5 === void 0 ? void 0 : _input_env5.redirectUri,
4853
+ scopes: scopes !== null && scopes !== void 0 ? scopes : (_input_env6 = input.env) === null || _input_env6 === void 0 ? void 0 : _input_env6.scopes
4854
+ };
4855
+ }
4793
4856
  return result;
4794
4857
  }
4795
4858
  /**
@@ -5825,6 +5888,8 @@ function _ts_generator$9(thisArg, body) {
5825
5888
  * @param input.state - The opaque OAuth state token used for CSRF protection.
5826
5889
  * @param input.codeChallenge - The PKCE code challenge derived from the verifier.
5827
5890
  * @returns The full authorization URL with all OAuth params merged in.
5891
+ * @throws {CliError} When `requestedSessionTtlSeconds` is provided but is not a positive integer.
5892
+ *
5828
5893
  * @__NO_SIDE_EFFECTS__
5829
5894
  */ function buildAuthorizationUrl(input) {
5830
5895
  var _input_scopes;
@@ -5895,6 +5960,9 @@ function _ts_generator$9(thisArg, body) {
5895
5960
  *
5896
5961
  * Returns `undefined` when none is set or every candidate fails to parse; the caller should then
5897
5962
  * use the discovered endpoint unchanged.
5963
+ *
5964
+ * @param input - The candidate URLs in priority order.
5965
+ * @returns The selected origin, or `undefined` when no candidate yields one.
5898
5966
  */ function resolveAuthorizationRebaseOrigin(input) {
5899
5967
  var result;
5900
5968
  if (input.appClientUrl) {
@@ -6031,6 +6099,7 @@ function parseUrlRedirect(trimmed, expectedState) {
6031
6099
  * @param input.pasted - The redirect URL or bare authorization code pasted by the user.
6032
6100
  * @param input.expectedState - Optional state value to assert against `state` when present in the URL.
6033
6101
  * @returns The {@link ParsedRedirect} containing `code` and (when present) `state`.
6102
+ * @throws {CliError} When `pasted` is empty, when the URL contains no `code` parameter, or when `expectedState` does not match the URL's `state`.
6034
6103
  */ function parsePastedRedirect(input) {
6035
6104
  var trimmed = input.pasted.trim();
6036
6105
  if (!trimmed) {
@@ -6039,10 +6108,8 @@ function parseUrlRedirect(trimmed, expectedState) {
6039
6108
  code: 'AUTH_NO_CODE'
6040
6109
  });
6041
6110
  }
6042
- if (trimmed.startsWith('http://') || trimmed.startsWith('https://') || trimmed.startsWith('urn:')) {
6043
- return parseUrlRedirect(trimmed, input.expectedState);
6044
- }
6045
- return {
6111
+ var isUrl = trimmed.startsWith('http://') || trimmed.startsWith('https://') || trimmed.startsWith('urn:');
6112
+ return isUrl ? parseUrlRedirect(trimmed, input.expectedState) : {
6046
6113
  code: trimmed
6047
6114
  };
6048
6115
  }
@@ -6071,80 +6138,83 @@ var KEY_DEL = ''; // DEL
6071
6138
  * @param input.mask - When `true`, characters are echoed as `*` and Ctrl-C cancels the prompt.
6072
6139
  * @returns The line entered by the user (without the trailing newline).
6073
6140
  */ function promptLine(input) {
6074
- if (!input.mask) {
6075
- var rl = node_readline.createInterface({
6076
- input: process.stdin,
6077
- output: process.stdout,
6078
- terminal: false
6079
- });
6080
- return new Promise(function(resolve) {
6081
- rl.question(input.question, function(answer) {
6082
- rl.close();
6083
- resolve(answer);
6084
- });
6085
- });
6086
- }
6087
- return new Promise(function(resolve, reject) {
6088
- var _process_stdin_setRawMode, _process_stdin;
6089
- var stdout = process.stdout;
6090
- stdout.write(input.question);
6091
- var buffer = '';
6092
- var onData = function onData1(chunk) {
6093
- var value = chunk.toString('utf8');
6094
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
6095
- try {
6096
- for(var _iterator = value[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
6097
- var char = _step.value;
6098
- if (char === '\n' || char === '\r' || char === KEY_EOT) {
6099
- var _process_stdin_setRawMode, _process_stdin;
6100
- stdout.write('\n');
6101
- process.stdin.removeListener('data', onData);
6102
- (_process_stdin_setRawMode = (_process_stdin = process.stdin).setRawMode) === null || _process_stdin_setRawMode === void 0 ? void 0 : _process_stdin_setRawMode.call(_process_stdin, false);
6103
- process.stdin.pause();
6104
- resolve(buffer);
6105
- return;
6106
- }
6107
- if (char === KEY_ETX) {
6108
- var _process_stdin_setRawMode1, _process_stdin1;
6109
- stdout.write('\n');
6110
- process.stdin.removeListener('data', onData);
6111
- (_process_stdin_setRawMode1 = (_process_stdin1 = process.stdin).setRawMode) === null || _process_stdin_setRawMode1 === void 0 ? void 0 : _process_stdin_setRawMode1.call(_process_stdin1, false);
6112
- process.stdin.pause();
6113
- reject(new CliError({
6114
- message: 'Prompt cancelled.',
6115
- code: PROMPT_CANCELLED_ERROR_CODE
6116
- }));
6117
- return;
6118
- }
6119
- if (char === KEY_BS || char === KEY_DEL) {
6120
- if (buffer.length > 0) {
6121
- buffer = buffer.slice(0, -1);
6122
- stdout.write('\b \b');
6123
- }
6124
- continue;
6125
- }
6126
- buffer += char;
6127
- stdout.write('*');
6128
- }
6129
- } catch (err) {
6130
- _didIteratorError = true;
6131
- _iteratorError = err;
6132
- } finally{
6141
+ var result;
6142
+ if (input.mask) {
6143
+ result = new Promise(function(resolve, reject) {
6144
+ var _process_stdin_setRawMode, _process_stdin;
6145
+ var stdout = process.stdout;
6146
+ stdout.write(input.question);
6147
+ var buffer = '';
6148
+ var onData = function onData1(chunk) {
6149
+ var value = chunk.toString('utf8');
6150
+ var done = false;
6151
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
6133
6152
  try {
6134
- if (!_iteratorNormalCompletion && _iterator.return != null) {
6135
- _iterator.return();
6153
+ for(var _iterator = value[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
6154
+ var char = _step.value;
6155
+ if (done) break;
6156
+ if (char === '\n' || char === '\r' || char === KEY_EOT) {
6157
+ var _process_stdin_setRawMode, _process_stdin;
6158
+ stdout.write('\n');
6159
+ process.stdin.removeListener('data', onData);
6160
+ (_process_stdin_setRawMode = (_process_stdin = process.stdin).setRawMode) === null || _process_stdin_setRawMode === void 0 ? void 0 : _process_stdin_setRawMode.call(_process_stdin, false);
6161
+ process.stdin.pause();
6162
+ resolve(buffer);
6163
+ done = true;
6164
+ } else if (char === KEY_ETX) {
6165
+ var _process_stdin_setRawMode1, _process_stdin1;
6166
+ stdout.write('\n');
6167
+ process.stdin.removeListener('data', onData);
6168
+ (_process_stdin_setRawMode1 = (_process_stdin1 = process.stdin).setRawMode) === null || _process_stdin_setRawMode1 === void 0 ? void 0 : _process_stdin_setRawMode1.call(_process_stdin1, false);
6169
+ process.stdin.pause();
6170
+ reject(new CliError({
6171
+ message: 'Prompt cancelled.',
6172
+ code: PROMPT_CANCELLED_ERROR_CODE
6173
+ }));
6174
+ done = true;
6175
+ } else if (char === KEY_BS || char === KEY_DEL) {
6176
+ if (buffer.length > 0) {
6177
+ buffer = buffer.slice(0, -1);
6178
+ stdout.write('\b \b');
6179
+ }
6180
+ } else {
6181
+ buffer += char;
6182
+ stdout.write('*');
6183
+ }
6136
6184
  }
6185
+ } catch (err) {
6186
+ _didIteratorError = true;
6187
+ _iteratorError = err;
6137
6188
  } finally{
6138
- if (_didIteratorError) {
6139
- throw _iteratorError;
6189
+ try {
6190
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
6191
+ _iterator.return();
6192
+ }
6193
+ } finally{
6194
+ if (_didIteratorError) {
6195
+ throw _iteratorError;
6196
+ }
6140
6197
  }
6141
6198
  }
6142
- }
6143
- };
6144
- (_process_stdin_setRawMode = (_process_stdin = process.stdin).setRawMode) === null || _process_stdin_setRawMode === void 0 ? void 0 : _process_stdin_setRawMode.call(_process_stdin, true);
6145
- process.stdin.resume();
6146
- process.stdin.on('data', onData);
6147
- });
6199
+ };
6200
+ (_process_stdin_setRawMode = (_process_stdin = process.stdin).setRawMode) === null || _process_stdin_setRawMode === void 0 ? void 0 : _process_stdin_setRawMode.call(_process_stdin, true);
6201
+ process.stdin.resume();
6202
+ process.stdin.on('data', onData);
6203
+ });
6204
+ } else {
6205
+ var rl = node_readline.createInterface({
6206
+ input: process.stdin,
6207
+ output: process.stdout,
6208
+ terminal: false
6209
+ });
6210
+ result = new Promise(function(resolve) {
6211
+ rl.question(input.question, function(answer) {
6212
+ rl.close();
6213
+ resolve(answer);
6214
+ });
6215
+ });
6216
+ }
6217
+ return result;
6148
6218
  }
6149
6219
 
6150
6220
  function asyncGeneratorStep$8(gen, resolve, reject, _next, _throw, key, arg) {
@@ -6322,6 +6392,53 @@ function _ts_generator$8(thisArg, body) {
6322
6392
  };
6323
6393
  }
6324
6394
  }
6395
+ function resolveAuthSetupPrompt(input) {
6396
+ return _async_to_generator$8(function() {
6397
+ var argvValue, existingValue, prompt, mask, result, answer;
6398
+ return _ts_generator$8(this, function(_state) {
6399
+ switch(_state.label){
6400
+ case 0:
6401
+ argvValue = input.argvValue, existingValue = input.existingValue, prompt = input.prompt, mask = input.mask;
6402
+ if (!argvValue) return [
6403
+ 3,
6404
+ 1
6405
+ ];
6406
+ result = argvValue;
6407
+ return [
6408
+ 3,
6409
+ 4
6410
+ ];
6411
+ case 1:
6412
+ if (!existingValue) return [
6413
+ 3,
6414
+ 2
6415
+ ];
6416
+ result = existingValue;
6417
+ return [
6418
+ 3,
6419
+ 4
6420
+ ];
6421
+ case 2:
6422
+ return [
6423
+ 4,
6424
+ promptLine({
6425
+ question: prompt,
6426
+ mask: mask
6427
+ })
6428
+ ];
6429
+ case 3:
6430
+ answer = _state.sent().trim();
6431
+ result = answer.length > 0 ? answer : existingValue;
6432
+ _state.label = 4;
6433
+ case 4:
6434
+ return [
6435
+ 2,
6436
+ result
6437
+ ];
6438
+ }
6439
+ });
6440
+ })();
6441
+ }
6325
6442
  /**
6326
6443
  * Factory for the built-in `auth` command tree.
6327
6444
  *
@@ -6380,38 +6497,6 @@ function _ts_generator$8(thisArg, body) {
6380
6497
  handler: wrapCommandHandler(function(argv) {
6381
6498
  return _async_to_generator$8(function() {
6382
6499
  var _ref, _ref1, _argv_env, _ref2, _ref3, _argv_appClientUrl, _ref4, _ref5, _argv_scopes, _config_envs, _findCliEnvDefault, config, envName, stored, defaultEnv, existing, apiBaseUrl, oidcIssuer, appClientUrl, clientId, clientSecret, redirectUri, scopes, nextEnv, merged;
6383
- function resolve(promptInput) {
6384
- return _async_to_generator$8(function() {
6385
- var argvValue, existingValue, prompt, mask, answer;
6386
- return _ts_generator$8(this, function(_state) {
6387
- switch(_state.label){
6388
- case 0:
6389
- argvValue = promptInput.argvValue, existingValue = promptInput.existingValue, prompt = promptInput.prompt, mask = promptInput.mask;
6390
- if (argvValue) return [
6391
- 2,
6392
- argvValue
6393
- ];
6394
- if (existingValue) return [
6395
- 2,
6396
- existingValue
6397
- ];
6398
- return [
6399
- 4,
6400
- promptLine({
6401
- question: prompt,
6402
- mask: mask
6403
- })
6404
- ];
6405
- case 1:
6406
- answer = _state.sent().trim();
6407
- return [
6408
- 2,
6409
- answer.length > 0 ? answer : existingValue
6410
- ];
6411
- }
6412
- });
6413
- })();
6414
- }
6415
6500
  return _ts_generator$8(this, function(_state) {
6416
6501
  switch(_state.label){
6417
6502
  case 0:
@@ -6441,7 +6526,7 @@ function _ts_generator$8(thisArg, body) {
6441
6526
  });
6442
6527
  return [
6443
6528
  4,
6444
- resolve({
6529
+ resolveAuthSetupPrompt({
6445
6530
  argvValue: argv.apiBaseUrl,
6446
6531
  existingValue: existing === null || existing === void 0 ? void 0 : existing.apiBaseUrl,
6447
6532
  prompt: "API base URL [".concat((_ref2 = existing === null || existing === void 0 ? void 0 : existing.apiBaseUrl) !== null && _ref2 !== void 0 ? _ref2 : '', "]: ")
@@ -6451,7 +6536,7 @@ function _ts_generator$8(thisArg, body) {
6451
6536
  apiBaseUrl = _state.sent();
6452
6537
  return [
6453
6538
  4,
6454
- resolve({
6539
+ resolveAuthSetupPrompt({
6455
6540
  argvValue: argv.oidcIssuer,
6456
6541
  existingValue: existing === null || existing === void 0 ? void 0 : existing.oidcIssuer,
6457
6542
  prompt: "OIDC issuer [".concat((_ref3 = existing === null || existing === void 0 ? void 0 : existing.oidcIssuer) !== null && _ref3 !== void 0 ? _ref3 : '', "]: ")
@@ -6462,7 +6547,7 @@ function _ts_generator$8(thisArg, body) {
6462
6547
  appClientUrl = (_argv_appClientUrl = argv.appClientUrl) !== null && _argv_appClientUrl !== void 0 ? _argv_appClientUrl : existing === null || existing === void 0 ? void 0 : existing.appClientUrl;
6463
6548
  return [
6464
6549
  4,
6465
- resolve({
6550
+ resolveAuthSetupPrompt({
6466
6551
  argvValue: argv.clientId,
6467
6552
  existingValue: existing === null || existing === void 0 ? void 0 : existing.clientId,
6468
6553
  prompt: 'Client ID: '
@@ -6472,7 +6557,7 @@ function _ts_generator$8(thisArg, body) {
6472
6557
  clientId = _state.sent();
6473
6558
  return [
6474
6559
  4,
6475
- resolve({
6560
+ resolveAuthSetupPrompt({
6476
6561
  argvValue: argv.clientSecret,
6477
6562
  existingValue: existing === null || existing === void 0 ? void 0 : existing.clientSecret,
6478
6563
  prompt: 'Client secret: ',
@@ -6483,7 +6568,7 @@ function _ts_generator$8(thisArg, body) {
6483
6568
  clientSecret = _state.sent();
6484
6569
  return [
6485
6570
  4,
6486
- resolve({
6571
+ resolveAuthSetupPrompt({
6487
6572
  argvValue: argv.redirectUri,
6488
6573
  existingValue: existing === null || existing === void 0 ? void 0 : existing.redirectUri,
6489
6574
  prompt: "Redirect URI [".concat((_ref5 = existing === null || existing === void 0 ? void 0 : existing.redirectUri) !== null && _ref5 !== void 0 ? _ref5 : DEFAULT_CLI_REDIRECT_URI, "]: ")
@@ -6823,16 +6908,10 @@ function _ts_generator$8(thisArg, body) {
6823
6908
  ];
6824
6909
  case 2:
6825
6910
  entry = _state.sent();
6826
- if (!entry) {
6827
- outputResult({
6828
- env: envName,
6829
- authenticated: false,
6830
- suggestion: "Run: ".concat(cliName, " auth login --env ").concat(envName)
6831
- });
6832
- return [
6833
- 2
6834
- ];
6835
- }
6911
+ if (!entry) return [
6912
+ 3,
6913
+ 7
6914
+ ];
6836
6915
  expired = isTokenExpired(entry);
6837
6916
  return [
6838
6917
  4,
@@ -6844,18 +6923,10 @@ function _ts_generator$8(thisArg, body) {
6844
6923
  case 3:
6845
6924
  meta = _state.sent();
6846
6925
  userinfoEndpoint = meta.userinfo_endpoint;
6847
- if (!userinfoEndpoint) {
6848
- outputResult({
6849
- env: envName,
6850
- authenticated: !expired,
6851
- expiresAt: entry.expiresAt,
6852
- expired: expired,
6853
- scope: entry.scope
6854
- });
6855
- return [
6856
- 2
6857
- ];
6858
- }
6926
+ if (!userinfoEndpoint) return [
6927
+ 3,
6928
+ 5
6929
+ ];
6859
6930
  return [
6860
6931
  4,
6861
6932
  fetchUserInfo({
@@ -6874,6 +6945,32 @@ function _ts_generator$8(thisArg, body) {
6874
6945
  sub: claims.sub,
6875
6946
  claims: claims
6876
6947
  });
6948
+ return [
6949
+ 3,
6950
+ 6
6951
+ ];
6952
+ case 5:
6953
+ outputResult({
6954
+ env: envName,
6955
+ authenticated: !expired,
6956
+ expiresAt: entry.expiresAt,
6957
+ expired: expired,
6958
+ scope: entry.scope
6959
+ });
6960
+ _state.label = 6;
6961
+ case 6:
6962
+ return [
6963
+ 3,
6964
+ 8
6965
+ ];
6966
+ case 7:
6967
+ outputResult({
6968
+ env: envName,
6969
+ authenticated: false,
6970
+ suggestion: "Run: ".concat(cliName, " auth login --env ").concat(envName)
6971
+ });
6972
+ _state.label = 8;
6973
+ case 8:
6877
6974
  return [
6878
6975
  2
6879
6976
  ];
@@ -7260,20 +7357,14 @@ function _ts_generator$7(thisArg, body) {
7260
7357
  function(param) {
7261
7358
  var env = param.env;
7262
7359
  return _async_to_generator$7(function() {
7263
- var candidates, meta, e;
7360
+ var result, candidates, meta, e;
7264
7361
  return _ts_generator$7(this, function(_state) {
7265
7362
  switch(_state.label){
7266
7363
  case 0:
7267
- if (!(env === null || env === void 0 ? void 0 : env.oidcIssuer)) {
7268
- return [
7269
- 2,
7270
- {
7271
- name: 'oidc-issuer-set',
7272
- ok: false,
7273
- suggestion: 'Set `oidcIssuer` via `<cli> auth setup`.'
7274
- }
7275
- ];
7276
- }
7364
+ if (!(env === null || env === void 0 ? void 0 : env.oidcIssuer)) return [
7365
+ 3,
7366
+ 5
7367
+ ];
7277
7368
  candidates = buildOidcDiscoveryCandidates({
7278
7369
  issuer: env.oidcIssuer,
7279
7370
  fallbackBaseUrl: env.apiBaseUrl
@@ -7295,35 +7386,50 @@ function _ts_generator$7(thisArg, body) {
7295
7386
  ];
7296
7387
  case 2:
7297
7388
  meta = _state.sent();
7298
- return [
7299
- 2,
7300
- {
7301
- name: 'oidc-discovery-reachable',
7302
- ok: true,
7303
- detail: {
7304
- candidates: candidates,
7305
- authorization_endpoint: meta.authorization_endpoint,
7306
- token_endpoint: meta.token_endpoint
7307
- }
7389
+ result = {
7390
+ name: 'oidc-discovery-reachable',
7391
+ ok: true,
7392
+ detail: {
7393
+ candidates: candidates,
7394
+ authorization_endpoint: meta.authorization_endpoint,
7395
+ token_endpoint: meta.token_endpoint
7308
7396
  }
7397
+ };
7398
+ return [
7399
+ 3,
7400
+ 4
7309
7401
  ];
7310
7402
  case 3:
7311
7403
  e = _state.sent();
7404
+ result = {
7405
+ name: 'oidc-discovery-reachable',
7406
+ ok: false,
7407
+ detail: {
7408
+ candidates: candidates,
7409
+ error: _instanceof$2(e, Error) ? e.message : String(e)
7410
+ },
7411
+ suggestion: 'Verify the env oidcIssuer URL and that the API is running.'
7412
+ };
7312
7413
  return [
7313
- 2,
7314
- {
7315
- name: 'oidc-discovery-reachable',
7316
- ok: false,
7317
- detail: {
7318
- candidates: candidates,
7319
- error: _instanceof$2(e, Error) ? e.message : String(e)
7320
- },
7321
- suggestion: 'Verify the env oidcIssuer URL and that the API is running.'
7322
- }
7414
+ 3,
7415
+ 4
7323
7416
  ];
7324
7417
  case 4:
7325
7418
  return [
7326
- 2
7419
+ 3,
7420
+ 6
7421
+ ];
7422
+ case 5:
7423
+ result = {
7424
+ name: 'oidc-issuer-set',
7425
+ ok: false,
7426
+ suggestion: 'Set `oidcIssuer` via `<cli> auth setup`.'
7427
+ };
7428
+ _state.label = 6;
7429
+ case 6:
7430
+ return [
7431
+ 2,
7432
+ result
7327
7433
  ];
7328
7434
  }
7329
7435
  });
@@ -7332,20 +7438,14 @@ function _ts_generator$7(thisArg, body) {
7332
7438
  function(param) {
7333
7439
  var cliName = param.cliName, envName = param.envName, env = param.env;
7334
7440
  return _async_to_generator$7(function() {
7335
- var paths, tokens, entry, expired;
7441
+ var result, paths, tokens, entry, expired;
7336
7442
  return _ts_generator$7(this, function(_state) {
7337
7443
  switch(_state.label){
7338
7444
  case 0:
7339
- if (!envName || !env) {
7340
- return [
7341
- 2,
7342
- {
7343
- name: 'token-cache-fresh',
7344
- ok: false,
7345
- suggestion: 'No env to check.'
7346
- }
7347
- ];
7348
- }
7445
+ if (!(envName && env)) return [
7446
+ 3,
7447
+ 2
7448
+ ];
7349
7449
  paths = buildCliPaths({
7350
7450
  cliName: cliName
7351
7451
  });
@@ -7358,20 +7458,9 @@ function _ts_generator$7(thisArg, body) {
7358
7458
  ];
7359
7459
  case 1:
7360
7460
  entry = _state.sent();
7361
- if (!entry) {
7362
- return [
7363
- 2,
7364
- {
7365
- name: 'token-cache-fresh',
7366
- ok: false,
7367
- suggestion: "Run `".concat(cliName, " auth login --env ").concat(envName, "`.")
7368
- }
7369
- ];
7370
- }
7371
- expired = isTokenExpired(entry);
7372
- return [
7373
- 2,
7374
- _object_spread$6({
7461
+ if (entry) {
7462
+ expired = isTokenExpired(entry);
7463
+ result = _object_spread$6({
7375
7464
  name: 'token-cache-fresh',
7376
7465
  ok: !expired,
7377
7466
  detail: {
@@ -7380,7 +7469,29 @@ function _ts_generator$7(thisArg, body) {
7380
7469
  }
7381
7470
  }, expired ? {
7382
7471
  suggestion: "Run `".concat(cliName, " auth check --env ").concat(envName, "` to refresh.")
7383
- } : {})
7472
+ } : {});
7473
+ } else {
7474
+ result = {
7475
+ name: 'token-cache-fresh',
7476
+ ok: false,
7477
+ suggestion: "Run `".concat(cliName, " auth login --env ").concat(envName, "`.")
7478
+ };
7479
+ }
7480
+ return [
7481
+ 3,
7482
+ 3
7483
+ ];
7484
+ case 2:
7485
+ result = {
7486
+ name: 'token-cache-fresh',
7487
+ ok: false,
7488
+ suggestion: 'No env to check.'
7489
+ };
7490
+ _state.label = 3;
7491
+ case 3:
7492
+ return [
7493
+ 2,
7494
+ result
7384
7495
  ];
7385
7496
  }
7386
7497
  });
@@ -7389,20 +7500,24 @@ function _ts_generator$7(thisArg, body) {
7389
7500
  function(param) {
7390
7501
  var cliName = param.cliName, envName = param.envName, env = param.env;
7391
7502
  return _async_to_generator$7(function() {
7392
- var paths, tokens, entry, meta, e;
7503
+ var result, paths, tokens, entry, meta, e;
7393
7504
  return _ts_generator$7(this, function(_state) {
7394
7505
  switch(_state.label){
7395
7506
  case 0:
7396
- if (!envName || !(env === null || env === void 0 ? void 0 : env.clientId) || !(env === null || env === void 0 ? void 0 : env.clientSecret)) {
7397
- return [
7398
- 2,
7399
- {
7400
- name: 'token-refresh-round-trip',
7401
- ok: false,
7402
- suggestion: 'Env credentials are incomplete.'
7403
- }
7404
- ];
7405
- }
7507
+ if (!(!envName || !(env === null || env === void 0 ? void 0 : env.clientId) || !(env === null || env === void 0 ? void 0 : env.clientSecret))) return [
7508
+ 3,
7509
+ 1
7510
+ ];
7511
+ result = {
7512
+ name: 'token-refresh-round-trip',
7513
+ ok: false,
7514
+ suggestion: 'Env credentials are incomplete.'
7515
+ };
7516
+ return [
7517
+ 3,
7518
+ 9
7519
+ ];
7520
+ case 1:
7406
7521
  paths = buildCliPaths({
7407
7522
  cliName: cliName
7408
7523
  });
@@ -7413,28 +7528,19 @@ function _ts_generator$7(thisArg, body) {
7413
7528
  4,
7414
7529
  tokens.get(envName)
7415
7530
  ];
7416
- case 1:
7417
- entry = _state.sent();
7418
- if (!(entry === null || entry === void 0 ? void 0 : entry.refreshToken)) {
7419
- return [
7420
- 2,
7421
- {
7422
- name: 'token-refresh-round-trip',
7423
- ok: false,
7424
- detail: {
7425
- reason: 'no-refresh-token'
7426
- },
7427
- suggestion: 'No refresh token cached for env "'.concat(envName, '". Run `').concat(cliName, " auth login --env ").concat(envName, "` — if the env's scopes omit `offline_access`, the OIDC provider may not issue one.")
7428
- }
7429
- ];
7430
- }
7431
- _state.label = 2;
7432
7531
  case 2:
7532
+ entry = _state.sent();
7533
+ if (!(entry === null || entry === void 0 ? void 0 : entry.refreshToken)) return [
7534
+ 3,
7535
+ 8
7536
+ ];
7537
+ _state.label = 3;
7538
+ case 3:
7433
7539
  _state.trys.push([
7434
- 2,
7435
- 5,
7540
+ 3,
7541
+ 6,
7436
7542
  ,
7437
- 6
7543
+ 7
7438
7544
  ]);
7439
7545
  return [
7440
7546
  4,
@@ -7443,7 +7549,7 @@ function _ts_generator$7(thisArg, body) {
7443
7549
  fallbackBaseUrl: env.apiBaseUrl
7444
7550
  })
7445
7551
  ];
7446
- case 3:
7552
+ case 4:
7447
7553
  meta = _state.sent();
7448
7554
  return [
7449
7555
  4,
@@ -7454,31 +7560,49 @@ function _ts_generator$7(thisArg, body) {
7454
7560
  refreshToken: entry.refreshToken
7455
7561
  })
7456
7562
  ];
7457
- case 4:
7563
+ case 5:
7458
7564
  _state.sent();
7565
+ result = {
7566
+ name: 'token-refresh-round-trip',
7567
+ ok: true
7568
+ };
7459
7569
  return [
7460
- 2,
7461
- {
7462
- name: 'token-refresh-round-trip',
7463
- ok: true
7464
- }
7570
+ 3,
7571
+ 7
7465
7572
  ];
7466
- case 5:
7573
+ case 6:
7467
7574
  e = _state.sent();
7575
+ result = {
7576
+ name: 'token-refresh-round-trip',
7577
+ ok: false,
7578
+ detail: {
7579
+ error: _instanceof$2(e, Error) ? e.message : String(e)
7580
+ },
7581
+ suggestion: "Run `".concat(cliName, " auth login --env ").concat(envName, "`.")
7582
+ };
7468
7583
  return [
7469
- 2,
7470
- {
7471
- name: 'token-refresh-round-trip',
7472
- ok: false,
7473
- detail: {
7474
- error: _instanceof$2(e, Error) ? e.message : String(e)
7475
- },
7476
- suggestion: "Run `".concat(cliName, " auth login --env ").concat(envName, "`.")
7477
- }
7584
+ 3,
7585
+ 7
7478
7586
  ];
7479
- case 6:
7587
+ case 7:
7480
7588
  return [
7481
- 2
7589
+ 3,
7590
+ 9
7591
+ ];
7592
+ case 8:
7593
+ result = {
7594
+ name: 'token-refresh-round-trip',
7595
+ ok: false,
7596
+ detail: {
7597
+ reason: 'no-refresh-token'
7598
+ },
7599
+ suggestion: 'No refresh token cached for env "'.concat(envName, '". Run `').concat(cliName, " auth login --env ").concat(envName, "` — if the env's scopes omit `offline_access`, the OIDC provider may not issue one.")
7600
+ };
7601
+ _state.label = 9;
7602
+ case 9:
7603
+ return [
7604
+ 2,
7605
+ result
7482
7606
  ];
7483
7607
  }
7484
7608
  });
@@ -7487,20 +7611,14 @@ function _ts_generator$7(thisArg, body) {
7487
7611
  function(param) {
7488
7612
  var env = param.env;
7489
7613
  return _async_to_generator$7(function() {
7490
- var url, res, e;
7614
+ var result, url, res, e;
7491
7615
  return _ts_generator$7(this, function(_state) {
7492
7616
  switch(_state.label){
7493
7617
  case 0:
7494
- if (!(env === null || env === void 0 ? void 0 : env.apiBaseUrl)) {
7495
- return [
7496
- 2,
7497
- {
7498
- name: 'api-base-url-reachable',
7499
- ok: false,
7500
- suggestion: 'Set `apiBaseUrl` via `<cli> auth setup`.'
7501
- }
7502
- ];
7503
- }
7618
+ if (!(env === null || env === void 0 ? void 0 : env.apiBaseUrl)) return [
7619
+ 3,
7620
+ 5
7621
+ ];
7504
7622
  url = "".concat(env.apiBaseUrl.replace(/\/+$/, '')).concat(CALL_MODEL_API_PATH);
7505
7623
  _state.label = 1;
7506
7624
  case 1:
@@ -7518,34 +7636,49 @@ function _ts_generator$7(thisArg, body) {
7518
7636
  ];
7519
7637
  case 2:
7520
7638
  res = _state.sent();
7521
- return [
7522
- 2,
7523
- {
7524
- name: 'api-base-url-reachable',
7525
- ok: res.status < 500,
7526
- detail: {
7527
- url: url,
7528
- status: res.status
7529
- }
7639
+ result = {
7640
+ name: 'api-base-url-reachable',
7641
+ ok: res.status < 500,
7642
+ detail: {
7643
+ url: url,
7644
+ status: res.status
7530
7645
  }
7646
+ };
7647
+ return [
7648
+ 3,
7649
+ 4
7531
7650
  ];
7532
7651
  case 3:
7533
7652
  e = _state.sent();
7653
+ result = {
7654
+ name: 'api-base-url-reachable',
7655
+ ok: false,
7656
+ detail: {
7657
+ url: url,
7658
+ error: _instanceof$2(e, Error) ? e.message : String(e)
7659
+ },
7660
+ suggestion: 'Verify the API is running at apiBaseUrl.'
7661
+ };
7534
7662
  return [
7535
- 2,
7536
- {
7537
- name: 'api-base-url-reachable',
7538
- ok: false,
7539
- detail: {
7540
- url: url,
7541
- error: _instanceof$2(e, Error) ? e.message : String(e)
7542
- },
7543
- suggestion: 'Verify the API is running at apiBaseUrl.'
7544
- }
7663
+ 3,
7664
+ 4
7545
7665
  ];
7546
7666
  case 4:
7547
7667
  return [
7548
- 2
7668
+ 3,
7669
+ 6
7670
+ ];
7671
+ case 5:
7672
+ result = {
7673
+ name: 'api-base-url-reachable',
7674
+ ok: false,
7675
+ suggestion: 'Set `apiBaseUrl` via `<cli> auth setup`.'
7676
+ };
7677
+ _state.label = 6;
7678
+ case 6:
7679
+ return [
7680
+ 2,
7681
+ result
7549
7682
  ];
7550
7683
  }
7551
7684
  });
@@ -8328,9 +8461,10 @@ function _unsupported_iterable_to_array$2(o, minLen) {
8328
8461
  * Re-exports {@link findCliModelManifestEntry} under a more descriptive name
8329
8462
  * for the model-info command.
8330
8463
  *
8331
- * @param manifest - the generated model manifest.
8332
- * @param query - identifier to look up.
8333
- * @returns the matching entry or `undefined`.
8464
+ * @param manifest - The generated model manifest.
8465
+ * @param query - Identifier to look up.
8466
+ * @returns The matching entry or `undefined`.
8467
+ *
8334
8468
  * @__NO_SIDE_EFFECTS__
8335
8469
  */ function resolveCliModel(manifest, query) {
8336
8470
  return findCliModelManifestEntry(query, manifest);
@@ -8338,41 +8472,46 @@ function _unsupported_iterable_to_array$2(o, minLen) {
8338
8472
  /**
8339
8473
  * Produces a column-aligned summary table of every model in the manifest.
8340
8474
  *
8341
- * @param manifest - the generated model manifest.
8342
- * @returns the formatted table as a single string with a trailing newline.
8475
+ * @param manifest - The generated model manifest.
8476
+ * @returns The formatted table as a single string with a trailing newline.
8477
+ *
8343
8478
  * @__NO_SIDE_EFFECTS__
8344
8479
  */ function renderModelManifestList(manifest) {
8480
+ var result;
8345
8481
  if (manifest.length === 0) {
8346
- return 'No models found in the generated manifest.\n';
8347
- }
8348
- var rows = [
8349
- [
8350
- 'MODEL',
8351
- 'PREFIX',
8352
- 'GROUP',
8353
- 'FIELDS',
8354
- 'PACKAGE',
8355
- 'IDENTITY'
8356
- ]
8357
- ].concat(_to_consumable_array$2(manifest.map(function(m) {
8358
- var _m_modelGroup;
8359
- return [
8360
- m.modelType,
8361
- m.collectionPrefix,
8362
- (_m_modelGroup = m.modelGroup) !== null && _m_modelGroup !== void 0 ? _m_modelGroup : '',
8363
- String(m.fields.length),
8364
- m.sourcePackage,
8365
- m.identityConst
8366
- ];
8367
- })));
8368
- return renderTable(rows);
8482
+ result = 'No models found in the generated manifest.\n';
8483
+ } else {
8484
+ var rows = [
8485
+ [
8486
+ 'MODEL',
8487
+ 'PREFIX',
8488
+ 'GROUP',
8489
+ 'FIELDS',
8490
+ 'PACKAGE',
8491
+ 'IDENTITY'
8492
+ ]
8493
+ ].concat(_to_consumable_array$2(manifest.map(function(m) {
8494
+ var _m_modelGroup;
8495
+ return [
8496
+ m.modelType,
8497
+ m.collectionPrefix,
8498
+ (_m_modelGroup = m.modelGroup) !== null && _m_modelGroup !== void 0 ? _m_modelGroup : '',
8499
+ String(m.fields.length),
8500
+ m.sourcePackage,
8501
+ m.identityConst
8502
+ ];
8503
+ })));
8504
+ result = renderTable(rows);
8505
+ }
8506
+ return result;
8369
8507
  }
8370
8508
  /**
8371
8509
  * Produces a human-readable summary of one model entry: header, description,
8372
8510
  * and an indented field tree (recursing into `nestedFields`).
8373
8511
  *
8374
- * @param entry - the manifest entry to render.
8375
- * @returns the formatted summary as a single string with a trailing newline.
8512
+ * @param entry - The manifest entry to render.
8513
+ * @returns The formatted summary as a single string with a trailing newline.
8514
+ *
8376
8515
  * @__NO_SIDE_EFFECTS__
8377
8516
  */ function renderModelManifestEntry(entry) {
8378
8517
  var groupSuffix = entry.modelGroup ? " \xb7 group ".concat(entry.modelGroup) : '';
@@ -8393,8 +8532,9 @@ function _unsupported_iterable_to_array$2(o, minLen) {
8393
8532
  * Produces the field-table portion of {@link renderModelManifestEntry} on its
8394
8533
  * own, used by the `--fields` flag of the `model-info` command.
8395
8534
  *
8396
- * @param entry - the manifest entry whose fields should be rendered.
8397
- * @returns the formatted field tree as a single string with a trailing newline.
8535
+ * @param entry - The manifest entry whose fields should be rendered.
8536
+ * @returns The formatted field tree as a single string with a trailing newline.
8537
+ *
8398
8538
  * @__NO_SIDE_EFFECTS__
8399
8539
  */ function renderModelManifestFields(entry) {
8400
8540
  return renderFieldsTree(entry.fields, 0) + '\n';
@@ -8445,58 +8585,72 @@ function buildFieldRow(field, includeConverter) {
8445
8585
  }
8446
8586
  function renderNestedFieldBlock(field, indent) {
8447
8587
  var nested = field.nestedFields;
8448
- if (!nested || nested.length === 0) return [];
8449
- var label = field.nestedIsArray ? 'array element' : 'sub-object';
8450
- var plural = nested.length === 1 ? '' : 's';
8451
- return [
8452
- indentLines$1("↳ ".concat(field.name, " (").concat(label, ", ").concat(nested.length, " field").concat(plural, ")"), indent + 2),
8453
- renderFieldsTree(nested, indent + 4)
8454
- ];
8588
+ var result;
8589
+ if (!nested || nested.length === 0) {
8590
+ result = [];
8591
+ } else {
8592
+ var label = field.nestedIsArray ? 'array element' : 'sub-object';
8593
+ var plural = nested.length === 1 ? '' : 's';
8594
+ result = [
8595
+ indentLines$1("↳ ".concat(field.name, " (").concat(label, ", ").concat(nested.length, " field").concat(plural, ")"), indent + 2),
8596
+ renderFieldsTree(nested, indent + 4)
8597
+ ];
8598
+ }
8599
+ return result;
8455
8600
  }
8456
8601
  function renderTable(rows) {
8457
- if (rows.length === 0) return '';
8458
- var widths = [];
8459
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
8460
- try {
8461
- for(var _iterator = rows[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
8462
- var row = _step.value;
8463
- row.forEach(function(cell, i) {
8464
- var _widths_i;
8465
- var cellWidth = cell.length;
8466
- widths[i] = Math.max((_widths_i = widths[i]) !== null && _widths_i !== void 0 ? _widths_i : 0, cellWidth);
8467
- });
8468
- }
8469
- } catch (err) {
8470
- _didIteratorError = true;
8471
- _iteratorError = err;
8472
- } finally{
8602
+ var result;
8603
+ if (rows.length === 0) {
8604
+ result = '';
8605
+ } else {
8606
+ var widths = [];
8607
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
8473
8608
  try {
8474
- if (!_iteratorNormalCompletion && _iterator.return != null) {
8475
- _iterator.return();
8609
+ for(var _iterator = rows[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
8610
+ var row = _step.value;
8611
+ row.forEach(function(cell, i) {
8612
+ var _widths_i;
8613
+ var cellWidth = cell.length;
8614
+ widths[i] = Math.max((_widths_i = widths[i]) !== null && _widths_i !== void 0 ? _widths_i : 0, cellWidth);
8615
+ });
8476
8616
  }
8617
+ } catch (err) {
8618
+ _didIteratorError = true;
8619
+ _iteratorError = err;
8477
8620
  } finally{
8478
- if (_didIteratorError) {
8479
- throw _iteratorError;
8621
+ try {
8622
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
8623
+ _iterator.return();
8624
+ }
8625
+ } finally{
8626
+ if (_didIteratorError) {
8627
+ throw _iteratorError;
8628
+ }
8480
8629
  }
8481
8630
  }
8631
+ result = rows.map(function(row) {
8632
+ return row.map(function(cell, i) {
8633
+ var _widths_i;
8634
+ return i === row.length - 1 ? cell : cell.padEnd((_widths_i = widths[i]) !== null && _widths_i !== void 0 ? _widths_i : 0);
8635
+ }).join(' ').replace(/\s+$/, '');
8636
+ }).join('\n');
8482
8637
  }
8483
- return rows.map(function(row) {
8484
- return row.map(function(cell, i) {
8485
- var _widths_i;
8486
- return i === row.length - 1 ? cell : cell.padEnd((_widths_i = widths[i]) !== null && _widths_i !== void 0 ? _widths_i : 0);
8487
- }).join(' ').replace(/\s+$/, '');
8488
- }).join('\n');
8638
+ return result;
8489
8639
  }
8490
8640
  function truncate(text, max) {
8491
- if (text.length <= max) return text;
8492
- return text.slice(0, max - 1) + '…';
8641
+ return text.length <= max ? text : text.slice(0, max - 1) + '…';
8493
8642
  }
8494
8643
  function indentLines$1(text, indent) {
8495
- if (indent <= 0) return text;
8496
- var pad = ' '.repeat(indent);
8497
- return text.split('\n').map(function(line) {
8498
- return line.length > 0 ? pad + line : line;
8499
- }).join('\n');
8644
+ var result;
8645
+ if (indent <= 0) {
8646
+ result = text;
8647
+ } else {
8648
+ var pad = ' '.repeat(indent);
8649
+ result = text.split('\n').map(function(line) {
8650
+ return line.length > 0 ? pad + line : line;
8651
+ }).join('\n');
8652
+ }
8653
+ return result;
8500
8654
  }
8501
8655
 
8502
8656
  /**
@@ -8548,30 +8702,26 @@ function indentLines$1(text, indent) {
8548
8702
  }
8549
8703
  function runHandler(manifest, argv) {
8550
8704
  var query = typeof argv.model === 'string' && argv.model.length > 0 ? argv.model : undefined;
8551
- if (!query) {
8705
+ if (query) {
8706
+ var entry = resolveCliModel(manifest, query);
8707
+ if (!entry) {
8708
+ throw new CliError({
8709
+ message: "No model matches '".concat(query, "'. Run `model-info` without an argument to list available models."),
8710
+ code: 'MODEL_INFO_NOT_FOUND'
8711
+ });
8712
+ }
8552
8713
  if (argv.json) {
8553
- outputResult(manifest);
8554
- return;
8714
+ outputResult(entry);
8715
+ } else if (argv.fields) {
8716
+ process.stdout.write(renderModelManifestFields(entry));
8717
+ } else {
8718
+ process.stdout.write(renderModelManifestEntry(entry));
8555
8719
  }
8720
+ } else if (argv.json) {
8721
+ outputResult(manifest);
8722
+ } else {
8556
8723
  process.stdout.write(renderModelManifestList(manifest));
8557
- return;
8558
- }
8559
- var entry = resolveCliModel(manifest, query);
8560
- if (!entry) {
8561
- throw new CliError({
8562
- message: "No model matches '".concat(query, "'. Run `model-info` without an argument to list available models."),
8563
- code: 'MODEL_INFO_NOT_FOUND'
8564
- });
8565
- }
8566
- if (argv.json) {
8567
- outputResult(entry);
8568
- return;
8569
- }
8570
- if (argv.fields) {
8571
- process.stdout.write(renderModelManifestFields(entry));
8572
- return;
8573
8724
  }
8574
- process.stdout.write(renderModelManifestEntry(entry));
8575
8725
  }
8576
8726
 
8577
8727
  function asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, key, arg) {
@@ -8895,11 +9045,12 @@ function _ts_generator$5(thisArg, body) {
8895
9045
  * Test-only middleware that skips OIDC discovery, disk token loading, and token refresh, attaching
8896
9046
  * a pre-built {@link CliContext} directly via {@link setCliContext}.
8897
9047
  *
8898
- * @internal Intended for use by `@dereekb/dbx-cli/test`. Not for production wiring.
8899
- *
8900
9048
  * @param input - The pre-built context to attach on every invocation.
8901
9049
  * @param input.cliContext - The {@link CliContext} that will be attached via {@link setCliContext}.
8902
9050
  * @returns A yargs middleware function that always sets the provided context.
9051
+ *
9052
+ * @internal Intended for use by `@dereekb/dbx-cli/test`. Not for production wiring.
9053
+ *
8903
9054
  * @__NO_SIDE_EFFECTS__
8904
9055
  */ function createPassthroughAuthMiddleware(input) {
8905
9056
  return function() {
@@ -9864,10 +10015,10 @@ function _ts_generator$2(thisArg, body) {
9864
10015
  }
9865
10016
  var allConfigCommands = _to_consumable_array$1(builtInConfigCommands).concat(_to_consumable_array$1((_input_configCommands = input.configCommands) !== null && _input_configCommands !== void 0 ? _input_configCommands : []));
9866
10017
  var builtInApiCommands = input.disableCallPassthrough ? [] : [
9867
- callPassthroughCommand
10018
+ CALL_PASSTHROUGH_COMMAND
9868
10019
  ];
9869
10020
  if (input.disableModelGet !== true) {
9870
- builtInApiCommands.push(getCommand, getManyCommand);
10021
+ builtInApiCommands.push(GET_COMMAND, GET_MANY_COMMAND);
9871
10022
  }
9872
10023
  var actionCommands = buildActionCommands((_input_actionCommands = input.actionCommands) !== null && _input_actionCommands !== void 0 ? _input_actionCommands : []);
9873
10024
  var allApiCommands = _to_consumable_array$1(builtInApiCommands).concat(_to_consumable_array$1((_input_apiCommands = input.apiCommands) !== null && _input_apiCommands !== void 0 ? _input_apiCommands : []), _to_consumable_array$1(actionCommands));
@@ -9941,10 +10092,10 @@ function _ts_generator$2(thisArg, body) {
9941
10092
  skipCommands: skipCommandNames
9942
10093
  })
9943
10094
  ], true).command(allConfigCommands).command(allApiCommands).demandCommand(1, 'Please specify a command. Use --help for available commands.').strict().fail(false).help().alias('help', 'h').wrap(Math.min(120, process.stdout.columns || 80));
9944
- if (input.version != null) {
9945
- parser = parser.version(input.version);
9946
- } else {
10095
+ if (input.version == null) {
9947
10096
  parser = parser.version(false);
10097
+ } else {
10098
+ parser = parser.version(input.version);
9948
10099
  }
9949
10100
  if (input.completionCommandName !== false) {
9950
10101
  var _input_completionCommandName;
@@ -9998,13 +10149,15 @@ function _ts_generator$2(thisArg, body) {
9998
10149
  }
9999
10150
  function commandName(cmd) {
10000
10151
  var raw = cmd.command;
10152
+ var result;
10001
10153
  if (typeof raw === 'string') {
10002
- return raw.split(' ')[0];
10003
- }
10004
- if (Array.isArray(raw) && raw.length > 0) {
10005
- return raw[0].split(' ')[0];
10154
+ result = raw.split(' ')[0];
10155
+ } else if (Array.isArray(raw) && raw.length > 0) {
10156
+ result = raw[0].split(' ')[0];
10157
+ } else {
10158
+ result = '';
10006
10159
  }
10007
- return '';
10160
+ return result;
10008
10161
  }
10009
10162
 
10010
10163
  function _array_like_to_array(arr, len) {
@@ -10298,7 +10451,6 @@ var DATA_HELP_FLAG = '--data-help';
10298
10451
  * when the manifest has no callable entries.
10299
10452
  * @__NO_SIDE_EFFECTS__
10300
10453
  */ function buildManifestCommands(manifest, options) {
10301
- var _ref, _ref1, _ref2, _ref3, _ref4, _ref5;
10302
10454
  var callable = manifest.filter(function(e) {
10303
10455
  return !SKIPPED_VERBS.has(e.verb);
10304
10456
  });
@@ -10330,64 +10482,68 @@ var DATA_HELP_FLAG = '--data-help';
10330
10482
  }
10331
10483
  }
10332
10484
  }
10485
+ var result;
10333
10486
  if (byModel.size === 0) {
10334
- return [];
10335
- }
10336
- var argv = (_ref = options === null || options === void 0 ? void 0 : options.argv) !== null && _ref !== void 0 ? _ref : process.argv;
10337
- var dataHelpFormat = (_ref1 = options === null || options === void 0 ? void 0 : options.dataHelpFormat) !== null && _ref1 !== void 0 ? _ref1 : detectDataHelpFormat(argv);
10338
- var helpMode = (_ref2 = options === null || options === void 0 ? void 0 : options.helpMode) !== null && _ref2 !== void 0 ? _ref2 : detectHelpMode(argv);
10339
- var focusHelp = ((_ref3 = options === null || options === void 0 ? void 0 : options.focusHelpOnDataHelp) !== null && _ref3 !== void 0 ? _ref3 : true) && hasDataHelpFlag(argv) && !hasAllHelpFlag(argv);
10340
- var hideOnFocus = focusHelp ? (_ref4 = options === null || options === void 0 ? void 0 : options.hiddenWhenFocused) !== null && _ref4 !== void 0 ? _ref4 : STANDARD_GLOBAL_OPTION_NAMES : [];
10341
- var modelCommandName = (_ref5 = options === null || options === void 0 ? void 0 : options.modelCommandName) !== null && _ref5 !== void 0 ? _ref5 : DEFAULT_MANIFEST_MODEL_COMMAND_NAME;
10342
- var sortedModels = _to_consumable_array(byModel.entries()).sort(function(param, param1) {
10343
- var _param = _sliced_to_array(param, 1), a = _param[0], _param1 = _sliced_to_array(param1, 1), b = _param1[0];
10344
- return a.localeCompare(b);
10345
- });
10346
- var context = {
10347
- dataHelpFormat: dataHelpFormat,
10348
- helpMode: helpMode,
10349
- hideOnFocus: hideOnFocus,
10350
- modelManifest: options === null || options === void 0 ? void 0 : options.modelManifest
10351
- };
10352
- return [
10353
- {
10354
- command: "".concat(modelCommandName, " <model>"),
10355
- describe: "Call typed model APIs (".concat(byModel.size, " model").concat(byModel.size === 1 ? '' : 's', "). Use `").concat(modelCommandName, " --help` to list them."),
10356
- builder: function builder(yargs) {
10357
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
10358
- try {
10359
- for(var _iterator = sortedModels[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
10360
- var _step_value = _sliced_to_array(_step.value, 2), model = _step_value[0], entries = _step_value[1];
10361
- yargs.command(buildModelCommand(model, entries, context));
10362
- }
10363
- } catch (err) {
10364
- _didIteratorError = true;
10365
- _iteratorError = err;
10366
- } finally{
10487
+ result = [];
10488
+ } else {
10489
+ var _ref, _ref1, _ref2, _ref3, _ref4, _ref5;
10490
+ var argv = (_ref = options === null || options === void 0 ? void 0 : options.argv) !== null && _ref !== void 0 ? _ref : process.argv;
10491
+ var dataHelpFormat = (_ref1 = options === null || options === void 0 ? void 0 : options.dataHelpFormat) !== null && _ref1 !== void 0 ? _ref1 : detectDataHelpFormat(argv);
10492
+ var helpMode = (_ref2 = options === null || options === void 0 ? void 0 : options.helpMode) !== null && _ref2 !== void 0 ? _ref2 : detectHelpMode(argv);
10493
+ var focusHelp = ((_ref3 = options === null || options === void 0 ? void 0 : options.focusHelpOnDataHelp) !== null && _ref3 !== void 0 ? _ref3 : true) && hasDataHelpFlag(argv) && !hasAllHelpFlag(argv);
10494
+ var hideOnFocus = focusHelp ? (_ref4 = options === null || options === void 0 ? void 0 : options.hiddenWhenFocused) !== null && _ref4 !== void 0 ? _ref4 : STANDARD_GLOBAL_OPTION_NAMES : [];
10495
+ var modelCommandName = (_ref5 = options === null || options === void 0 ? void 0 : options.modelCommandName) !== null && _ref5 !== void 0 ? _ref5 : DEFAULT_MANIFEST_MODEL_COMMAND_NAME;
10496
+ var sortedModels = _to_consumable_array(byModel.entries()).sort(function(param, param1) {
10497
+ var _param = _sliced_to_array(param, 1), a = _param[0], _param1 = _sliced_to_array(param1, 1), b = _param1[0];
10498
+ return a.localeCompare(b);
10499
+ });
10500
+ var context = {
10501
+ dataHelpFormat: dataHelpFormat,
10502
+ helpMode: helpMode,
10503
+ hideOnFocus: hideOnFocus,
10504
+ modelManifest: options === null || options === void 0 ? void 0 : options.modelManifest
10505
+ };
10506
+ result = [
10507
+ {
10508
+ command: "".concat(modelCommandName, " <model>"),
10509
+ describe: "Call typed model APIs (".concat(byModel.size, " model").concat(byModel.size === 1 ? '' : 's', "). Use `").concat(modelCommandName, " --help` to list them."),
10510
+ builder: function builder(yargs) {
10511
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
10367
10512
  try {
10368
- if (!_iteratorNormalCompletion && _iterator.return != null) {
10369
- _iterator.return();
10513
+ for(var _iterator = sortedModels[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
10514
+ var _step_value = _sliced_to_array(_step.value, 2), model = _step_value[0], entries = _step_value[1];
10515
+ yargs.command(buildModelCommand(model, entries, context));
10370
10516
  }
10517
+ } catch (err) {
10518
+ _didIteratorError = true;
10519
+ _iteratorError = err;
10371
10520
  } finally{
10372
- if (_didIteratorError) {
10373
- throw _iteratorError;
10521
+ try {
10522
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
10523
+ _iterator.return();
10524
+ }
10525
+ } finally{
10526
+ if (_didIteratorError) {
10527
+ throw _iteratorError;
10528
+ }
10374
10529
  }
10375
10530
  }
10531
+ hideGlobalOptions(yargs, hideOnFocus);
10532
+ return yargs.demandCommand(1, 'Please specify a model.');
10533
+ },
10534
+ handler: function handler() {
10535
+ return undefined;
10376
10536
  }
10377
- hideGlobalOptions(yargs, hideOnFocus);
10378
- return yargs.demandCommand(1, 'Please specify a model.');
10379
- },
10380
- handler: function handler() {
10381
- return undefined;
10382
10537
  }
10383
- }
10384
- ];
10538
+ ];
10539
+ }
10540
+ return result;
10385
10541
  }
10386
10542
  /**
10387
10543
  * Returns true if `--data-help` (with or without a value) appears anywhere in
10388
10544
  * the supplied argv. Used to opt into focused help mode.
10389
10545
  *
10390
- * @param argv - argv to scan (defaults to `process.argv`).
10546
+ * @param argv - Argv to scan (defaults to `process.argv`).
10391
10547
  * @returns Whether the user passed `--data-help`.
10392
10548
  */ function hasDataHelpFlag() {
10393
10549
  var argv = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : process.argv;
@@ -10400,7 +10556,7 @@ var DATA_HELP_FLAG = '--data-help';
10400
10556
  * as an explicit opt-out of focused help mode — `--data-help --all-help`
10401
10557
  * shows the schema sections AND the full options table.
10402
10558
  *
10403
- * @param argv - argv to scan (defaults to `process.argv`).
10559
+ * @param argv - Argv to scan (defaults to `process.argv`).
10404
10560
  * @returns Whether the user passed `--all-help`.
10405
10561
  */ function hasAllHelpFlag() {
10406
10562
  var argv = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : process.argv;
@@ -10416,7 +10572,7 @@ var DATA_HELP_FLAG = '--data-help';
10416
10572
  * value is needed when each command's builder runs — which is before yargs
10417
10573
  * parses argv. Unrecognized values fall back to the default.
10418
10574
  *
10419
- * @param argv - argv to inspect (defaults to `process.argv`).
10575
+ * @param argv - Argv to inspect (defaults to `process.argv`).
10420
10576
  * @returns The detected format, or {@link DEFAULT_MANIFEST_HELP_DATA_FORMAT}.
10421
10577
  */ function detectDataHelpFormat() {
10422
10578
  var argv = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : process.argv;
@@ -10448,7 +10604,7 @@ function parseDataHelpFormat(value) {
10448
10604
  * value is needed when each command's builder runs — which is before yargs
10449
10605
  * parses argv.
10450
10606
  *
10451
- * @param argv - argv to inspect (defaults to `process.argv`).
10607
+ * @param argv - Argv to inspect (defaults to `process.argv`).
10452
10608
  * @returns The detected mode, or {@link DEFAULT_MANIFEST_HELP_MODE}.
10453
10609
  */ function detectHelpMode() {
10454
10610
  var argv = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : process.argv;
@@ -10525,6 +10681,8 @@ function buildModelCommand(model, entries, context) {
10525
10681
  * @param manifest - The generated model manifest used to look up the model's `collectionPrefix`
10526
10682
  * and `parentIdentityConst`. When omitted, the key passes through unchanged.
10527
10683
  * @returns The resolved Firestore model key ready for `context.getModel(model, key)`.
10684
+ * @throws {CliError} When `model` resolves to a subcollection entry and only a bare doc id is supplied.
10685
+ *
10528
10686
  * @__NO_SIDE_EFFECTS__
10529
10687
  */ function resolvePerModelGetKey(model, key, manifest) {
10530
10688
  var result = key;
@@ -10643,7 +10801,7 @@ function buildEntryCommand(entry, context) {
10643
10801
  },
10644
10802
  handler: wrapCommandHandler(function(argv) {
10645
10803
  return _async_to_generator$1(function() {
10646
- var rawData, _tmp, _tmp1;
10804
+ var rawData, _tmp;
10647
10805
  return _ts_generator$1(this, function(_state) {
10648
10806
  switch(_state.label){
10649
10807
  case 0:
@@ -10660,25 +10818,18 @@ function buildEntryCommand(entry, context) {
10660
10818
  readAllStdin()
10661
10819
  ];
10662
10820
  case 1:
10663
- _tmp1 = _state.sent().trim();
10821
+ _tmp = _state.sent().trim();
10664
10822
  return [
10665
10823
  3,
10666
10824
  3
10667
10825
  ];
10668
10826
  case 2:
10669
- _tmp1 = argv.data;
10827
+ _tmp = argv.data;
10670
10828
  _state.label = 3;
10671
10829
  case 3:
10672
- _tmp = _tmp1;
10673
- return [
10674
- 3,
10675
- 5
10676
- ];
10677
- case 4:
10678
- _tmp = undefined;
10679
- _state.label = 5;
10680
- case 5:
10681
10830
  rawData = _tmp;
10831
+ _state.label = 4;
10832
+ case 4:
10682
10833
  return [
10683
10834
  4,
10684
10835
  callEntry(entry, rawData, {
@@ -10686,7 +10837,7 @@ function buildEntryCommand(entry, context) {
10686
10837
  modelManifest: context.modelManifest
10687
10838
  })
10688
10839
  ];
10689
- case 6:
10840
+ case 5:
10690
10841
  _state.sent();
10691
10842
  return [
10692
10843
  2
@@ -10698,10 +10849,15 @@ function buildEntryCommand(entry, context) {
10698
10849
  };
10699
10850
  }
10700
10851
  function oneLineDescription(description) {
10701
- var _description_split_;
10702
- if (!description) return undefined;
10703
- var firstLine = (_description_split_ = description.split('\n', 1)[0]) === null || _description_split_ === void 0 ? void 0 : _description_split_.trim();
10704
- return firstLine && firstLine.length > 0 ? firstLine : undefined;
10852
+ var result;
10853
+ if (description) {
10854
+ var _description_split_;
10855
+ var firstLine = (_description_split_ = description.split('\n', 1)[0]) === null || _description_split_ === void 0 ? void 0 : _description_split_.trim();
10856
+ if (firstLine && firstLine.length > 0) {
10857
+ result = firstLine;
10858
+ }
10859
+ }
10860
+ return result;
10705
10861
  }
10706
10862
  function hideGlobalOptions(yargs, names) {
10707
10863
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
@@ -10775,88 +10931,89 @@ function hideGlobalOptions(yargs, names) {
10775
10931
  return sections.length > 0 ? sections.join('\n\n') : undefined;
10776
10932
  }
10777
10933
  function buildActionSection(entry) {
10778
- if (!entry.description) return undefined;
10779
- return "About:\n".concat(indentLines(entry.description, ' '));
10934
+ return entry.description ? "About:\n".concat(indentLines(entry.description, ' ')) : undefined;
10780
10935
  }
10781
10936
  function buildParamsSection(entry) {
10782
- if (!entry.paramsTypeName && !entry.paramsTypeDescription && !(entry.paramsFields && entry.paramsFields.length > 0)) {
10783
- return undefined;
10784
- }
10785
- var lines = [];
10786
- if (entry.paramsTypeName) {
10787
- lines.push("Params: ".concat(entry.paramsTypeName));
10788
- }
10789
- if (entry.paramsTypeDescription) {
10790
- lines.push(indentLines(entry.paramsTypeDescription, ' '));
10791
- }
10792
- if (entry.paramsFields && entry.paramsFields.length > 0) {
10793
- lines.push('', 'Fields:');
10794
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
10795
- try {
10796
- for(var _iterator = entry.paramsFields[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
10797
- var field = _step.value;
10798
- var header = " - ".concat(field.name, ": ").concat(field.typeText);
10799
- lines.push(header);
10800
- if (field.description) {
10801
- lines.push(indentLines(field.description, ' '));
10802
- }
10803
- }
10804
- } catch (err) {
10805
- _didIteratorError = true;
10806
- _iteratorError = err;
10807
- } finally{
10937
+ var result;
10938
+ if (entry.paramsTypeName || entry.paramsTypeDescription || entry.paramsFields && entry.paramsFields.length > 0) {
10939
+ var lines = [];
10940
+ if (entry.paramsTypeName) {
10941
+ lines.push("Params: ".concat(entry.paramsTypeName));
10942
+ }
10943
+ if (entry.paramsTypeDescription) {
10944
+ lines.push(indentLines(entry.paramsTypeDescription, ' '));
10945
+ }
10946
+ if (entry.paramsFields && entry.paramsFields.length > 0) {
10947
+ lines.push('', 'Fields:');
10948
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
10808
10949
  try {
10809
- if (!_iteratorNormalCompletion && _iterator.return != null) {
10810
- _iterator.return();
10950
+ for(var _iterator = entry.paramsFields[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
10951
+ var field = _step.value;
10952
+ var header = " - ".concat(field.name, ": ").concat(field.typeText);
10953
+ lines.push(header);
10954
+ if (field.description) {
10955
+ lines.push(indentLines(field.description, ' '));
10956
+ }
10811
10957
  }
10958
+ } catch (err) {
10959
+ _didIteratorError = true;
10960
+ _iteratorError = err;
10812
10961
  } finally{
10813
- if (_didIteratorError) {
10814
- throw _iteratorError;
10962
+ try {
10963
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
10964
+ _iterator.return();
10965
+ }
10966
+ } finally{
10967
+ if (_didIteratorError) {
10968
+ throw _iteratorError;
10969
+ }
10815
10970
  }
10816
10971
  }
10817
10972
  }
10973
+ result = lines.join('\n');
10818
10974
  }
10819
- return lines.join('\n');
10975
+ return result;
10820
10976
  }
10821
10977
  function buildResultSection(entry) {
10822
- if (!entry.resultTypeDescription && !(entry.resultFields && entry.resultFields.length > 0)) {
10823
- return undefined;
10824
- }
10825
- var lines = [];
10826
- if (entry.resultTypeName) {
10827
- lines.push("Result: ".concat(entry.resultTypeName));
10828
- }
10829
- if (entry.resultTypeDescription) {
10830
- lines.push(indentLines(entry.resultTypeDescription, ' '));
10831
- }
10832
- if (entry.resultFields && entry.resultFields.length > 0) {
10833
- lines.push('', 'Fields:');
10834
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
10835
- try {
10836
- for(var _iterator = entry.resultFields[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
10837
- var field = _step.value;
10838
- var header = " - ".concat(field.name, ": ").concat(field.typeText);
10839
- lines.push(header);
10840
- if (field.description) {
10841
- lines.push(indentLines(field.description, ' '));
10842
- }
10843
- }
10844
- } catch (err) {
10845
- _didIteratorError = true;
10846
- _iteratorError = err;
10847
- } finally{
10978
+ var result;
10979
+ if (entry.resultTypeDescription || entry.resultFields && entry.resultFields.length > 0) {
10980
+ var lines = [];
10981
+ if (entry.resultTypeName) {
10982
+ lines.push("Result: ".concat(entry.resultTypeName));
10983
+ }
10984
+ if (entry.resultTypeDescription) {
10985
+ lines.push(indentLines(entry.resultTypeDescription, ' '));
10986
+ }
10987
+ if (entry.resultFields && entry.resultFields.length > 0) {
10988
+ lines.push('', 'Fields:');
10989
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
10848
10990
  try {
10849
- if (!_iteratorNormalCompletion && _iterator.return != null) {
10850
- _iterator.return();
10991
+ for(var _iterator = entry.resultFields[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
10992
+ var field = _step.value;
10993
+ var header = " - ".concat(field.name, ": ").concat(field.typeText);
10994
+ lines.push(header);
10995
+ if (field.description) {
10996
+ lines.push(indentLines(field.description, ' '));
10997
+ }
10851
10998
  }
10999
+ } catch (err) {
11000
+ _didIteratorError = true;
11001
+ _iteratorError = err;
10852
11002
  } finally{
10853
- if (_didIteratorError) {
10854
- throw _iteratorError;
11003
+ try {
11004
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
11005
+ _iterator.return();
11006
+ }
11007
+ } finally{
11008
+ if (_didIteratorError) {
11009
+ throw _iteratorError;
11010
+ }
10855
11011
  }
10856
11012
  }
10857
11013
  }
11014
+ result = lines.join('\n');
10858
11015
  }
10859
- return lines.join('\n');
11016
+ return result;
10860
11017
  }
10861
11018
  function indentLines(text, indent) {
10862
11019
  return text.split('\n').map(function(line) {
@@ -10865,75 +11022,73 @@ function indentLines(text, indent) {
10865
11022
  }
10866
11023
  function renderParamsSchemaSections(entry, dataHelpFormat) {
10867
11024
  var sections = [];
10868
- if (!entry.paramsValidator) {
10869
- return sections;
10870
- }
10871
- if (dataHelpFormat === 'jsonschema' || dataHelpFormat === 'both') {
10872
- var jsonSchemaSection = renderJsonSchemaSection(entry);
10873
- if (jsonSchemaSection) {
10874
- sections.push(jsonSchemaSection);
11025
+ if (entry.paramsValidator) {
11026
+ if (dataHelpFormat === 'jsonschema' || dataHelpFormat === 'both') {
11027
+ var jsonSchemaSection = renderJsonSchemaSection(entry);
11028
+ if (jsonSchemaSection) {
11029
+ sections.push(jsonSchemaSection);
11030
+ }
10875
11031
  }
10876
- }
10877
- if (dataHelpFormat === 'arktype' || dataHelpFormat === 'both') {
10878
- var arktypeSection = renderArktypeExpressionSection(entry);
10879
- if (arktypeSection) {
10880
- sections.push(arktypeSection);
11032
+ if (dataHelpFormat === 'arktype' || dataHelpFormat === 'both') {
11033
+ var arktypeSection = renderArktypeExpressionSection(entry);
11034
+ if (arktypeSection) {
11035
+ sections.push(arktypeSection);
11036
+ }
10881
11037
  }
10882
- }
10883
- if (sections.length === 0) {
10884
- // Last-ditch fallback when the requested format produced nothing usable
10885
- // (e.g. arktype was requested but the bound validator has no expression).
10886
- var expression = readArktypeExpression(entry);
10887
- if (expression) {
10888
- sections.push("Params Schema (arktype): ".concat(expression));
11038
+ if (sections.length === 0) {
11039
+ // Last-ditch fallback when the requested format produced nothing usable
11040
+ // (e.g. arktype was requested but the bound validator has no expression).
11041
+ var expression = readArktypeExpression(entry);
11042
+ if (expression) {
11043
+ sections.push("Params Schema (arktype): ".concat(expression));
11044
+ }
10889
11045
  }
10890
11046
  }
10891
11047
  return sections;
10892
11048
  }
10893
11049
  function renderJsonSchemaSection(entry) {
10894
- if (!entry.paramsValidator) {
10895
- return undefined;
10896
- }
10897
11050
  var result;
10898
- try {
10899
- // arktype's default `toJsonSchema` throws on any sub-schema that has no
10900
- // JSON Schema equivalent (custom predicates, morphs, `undefined`/symbol/
10901
- // bigint units or domains, etc.). Provide targeted fallbacks so help
10902
- // output stays useful:
10903
- // - `predicate` / `morph`: drop the lossy part, keep the JSON-shaped
10904
- // base e.g. `string > 0 & narrow(isFirestoreModelKey)` becomes
10905
- // `{ type: 'string', minLength: 1 }`.
10906
- // - everything else (e.g. the `undefined` unit in `clearable(T)`):
10907
- // return `false` (matches nothing). It's a no-op inside `anyOf`, and
10908
- // we strip it below so `T | null | undefined` reads as `T | null`.
10909
- var raw = entry.paramsValidator.toJsonSchema({
10910
- fallback: {
10911
- predicate: function predicate(ctx) {
10912
- return ctx.base;
10913
- },
10914
- morph: function morph(ctx) {
10915
- return ctx.base;
10916
- },
10917
- // `false` is a valid JSON Schema value ("matches nothing"), but
10918
- // arktype's TS types reject `false` for the fallback return — cast
10919
- // through `unknown` to keep the runtime behavior we want.
10920
- default: function _default() {
10921
- return false;
11051
+ if (entry.paramsValidator) {
11052
+ try {
11053
+ // arktype's default `toJsonSchema` throws on any sub-schema that has no
11054
+ // JSON Schema equivalent (custom predicates, morphs, `undefined`/symbol/
11055
+ // bigint units or domains, etc.). Provide targeted fallbacks so help
11056
+ // output stays useful:
11057
+ // - `predicate` / `morph`: drop the lossy part, keep the JSON-shaped
11058
+ // base e.g. `string > 0 & narrow(isFirestoreModelKey)` becomes
11059
+ // `{ type: 'string', minLength: 1 }`.
11060
+ // - everything else (e.g. the `undefined` unit in `clearable(T)`):
11061
+ // return `false` (matches nothing). It's a no-op inside `anyOf`, and
11062
+ // we strip it below so `T | null | undefined` reads as `T | null`.
11063
+ var raw = entry.paramsValidator.toJsonSchema({
11064
+ fallback: {
11065
+ predicate: function predicate(ctx) {
11066
+ return ctx.base;
11067
+ },
11068
+ morph: function morph(ctx) {
11069
+ return ctx.base;
11070
+ },
11071
+ // `false` is a valid JSON Schema value ("matches nothing"), but
11072
+ // arktype's TS types reject `false` for the fallback return cast
11073
+ // through `unknown` to keep the runtime behavior we want.
11074
+ default: function _default() {
11075
+ return false;
11076
+ }
10922
11077
  }
11078
+ });
11079
+ // arktype's fallback returns boxed schema nodes (objects with a `toJSON()`
11080
+ // method that emits the bare JSON Schema value, e.g. `false`). Round-trip
11081
+ // through JSON to invoke those `toJSON()` callbacks before pruning;
11082
+ // `structuredClone` would not call them.
11083
+ // NOSONAR (typescript:S7784): structuredClone bypasses toJSON()
11084
+ var normalized = JSON.parse(JSON.stringify(raw));
11085
+ var pruned = pruneFalseUnionBranches(normalized);
11086
+ result = "Params Schema (JSON Schema):\n".concat(JSON.stringify(pruned, null, 2));
11087
+ } catch (unused) {
11088
+ var expression = readArktypeExpression(entry);
11089
+ if (expression) {
11090
+ result = "Params Schema (arktype): ".concat(expression);
10923
11091
  }
10924
- });
10925
- // arktype's fallback returns boxed schema nodes (objects with a `toJSON()`
10926
- // method that emits the bare JSON Schema value, e.g. `false`). Round-trip
10927
- // through JSON to invoke those `toJSON()` callbacks before pruning;
10928
- // `structuredClone` would not call them.
10929
- // NOSONAR (typescript:S7784): structuredClone bypasses toJSON()
10930
- var normalized = JSON.parse(JSON.stringify(raw));
10931
- var pruned = pruneFalseUnionBranches(normalized);
10932
- result = "Params Schema (JSON Schema):\n".concat(JSON.stringify(pruned, null, 2));
10933
- } catch (unused) {
10934
- var expression = readArktypeExpression(entry);
10935
- if (expression) {
10936
- result = "Params Schema (arktype): ".concat(expression);
10937
11092
  }
10938
11093
  }
10939
11094
  return result;
@@ -11028,31 +11183,37 @@ function callEntry(entry, rawData, options) {
11028
11183
  }
11029
11184
  function parseAndValidate(entry, rawData) {
11030
11185
  var parsed = parseJsonData(rawData);
11031
- if (!entry.paramsValidator) {
11032
- return parsed;
11033
- }
11034
- var validated = entry.paramsValidator(parsed);
11035
- if (_instanceof(validated, Error)) {
11036
- var action = entry.specifier && entry.specifier !== '_' ? "".concat(entry.verb, "-").concat(entry.specifier) : entry.verb;
11037
- throw new CliError({
11038
- message: "Invalid --data for ".concat(entry.model, " ").concat(action, ": ").concat(validated.message),
11039
- code: 'VALIDATION_ERROR'
11040
- });
11186
+ var result;
11187
+ if (entry.paramsValidator) {
11188
+ var validated = entry.paramsValidator(parsed);
11189
+ if (_instanceof(validated, Error)) {
11190
+ var action = entry.specifier && entry.specifier !== '_' ? "".concat(entry.verb, "-").concat(entry.specifier) : entry.verb;
11191
+ throw new CliError({
11192
+ message: "Invalid --data for ".concat(entry.model, " ").concat(action, ": ").concat(validated.message),
11193
+ code: 'VALIDATION_ERROR'
11194
+ });
11195
+ }
11196
+ result = validated;
11197
+ } else {
11198
+ result = parsed;
11041
11199
  }
11042
- return validated;
11200
+ return result;
11043
11201
  }
11044
11202
  function parseJsonData(rawData) {
11203
+ var result;
11045
11204
  if (typeof rawData !== 'string' || rawData.length === 0) {
11046
- return {};
11047
- }
11048
- try {
11049
- return JSON.parse(rawData);
11050
- } catch (e) {
11051
- throw new CliError({
11052
- message: "--data must be valid JSON: ".concat(_instanceof(e, Error) ? e.message : String(e)),
11053
- code: 'INVALID_DATA_JSON'
11054
- });
11205
+ result = {};
11206
+ } else {
11207
+ try {
11208
+ result = JSON.parse(rawData);
11209
+ } catch (e) {
11210
+ throw new CliError({
11211
+ message: "--data must be valid JSON: ".concat(_instanceof(e, Error) ? e.message : String(e)),
11212
+ code: 'INVALID_DATA_JSON'
11213
+ });
11214
+ }
11055
11215
  }
11216
+ return result;
11056
11217
  }
11057
11218
 
11058
11219
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
@@ -11246,8 +11407,96 @@ function _ts_generator(thisArg, body) {
11246
11407
  var ext = dumpOutput === 'raw' ? 'json' : 'ndjson';
11247
11408
  var mainPath = buildDumpFilePath(ext);
11248
11409
  var pickPath = pick ? buildDumpFilePath(ext, 'pick') : undefined;
11249
- if (!mainPath) {
11250
- return {
11410
+ var dump;
11411
+ if (mainPath) {
11412
+ var pagesWritten = 0;
11413
+ var applyPickToPage = function applyPickToPage(result) {
11414
+ var mapped;
11415
+ if (pick) {
11416
+ var pickedData = pickFields(result.data, pick);
11417
+ mapped = _object_spread_props(_object_spread({}, result), {
11418
+ data: pickedData
11419
+ });
11420
+ } else {
11421
+ mapped = result;
11422
+ }
11423
+ return mapped;
11424
+ };
11425
+ var writeBoth = function writeBoth(input) {
11426
+ var flagFn = input.append ? node_fs.appendFileSync : node_fs.writeFileSync;
11427
+ flagFn(mainPath, input.mainContent);
11428
+ if (pickPath && input.pickContent !== undefined) {
11429
+ flagFn(pickPath, input.pickContent);
11430
+ }
11431
+ };
11432
+ var writeRawPage = function writeRawPage(result, append) {
11433
+ var mainContent = JSON.stringify(result, null, 2);
11434
+ var pickContent = pickPath ? JSON.stringify(applyPickToPage(result), null, 2) : undefined;
11435
+ writeBoth({
11436
+ mainContent: mainContent,
11437
+ pickContent: pickContent,
11438
+ append: append
11439
+ });
11440
+ };
11441
+ var writeLinePage = function writeLinePage(result, append) {
11442
+ var mainContent = JSON.stringify(result) + '\n';
11443
+ var pickContent = pickPath ? JSON.stringify(applyPickToPage(result)) + '\n' : undefined;
11444
+ writeBoth({
11445
+ mainContent: mainContent,
11446
+ pickContent: pickContent,
11447
+ append: append
11448
+ });
11449
+ };
11450
+ var writeDataByLinePage = function writeDataByLinePage(result, append) {
11451
+ var _result_data;
11452
+ // data_by_line — one record per line. For `replace` mode, truncate on first record then append the rest.
11453
+ var records = (_result_data = result.data) !== null && _result_data !== void 0 ? _result_data : [];
11454
+ var pickedRecords = pickPath ? pickFields(records, pick) : undefined;
11455
+ if (records.length === 0) {
11456
+ // Still ensure file is created/truncated on first iteration even when empty.
11457
+ if (!append) {
11458
+ writeBoth({
11459
+ mainContent: '',
11460
+ pickContent: pickPath ? '' : undefined,
11461
+ append: false
11462
+ });
11463
+ }
11464
+ } else {
11465
+ records.forEach(function(record, index) {
11466
+ var recordAppend = append || index > 0;
11467
+ var mainContent = JSON.stringify(record) + '\n';
11468
+ var pickContent = pickPath && pickedRecords ? JSON.stringify(pickedRecords[index]) + '\n' : undefined;
11469
+ writeBoth({
11470
+ mainContent: mainContent,
11471
+ pickContent: pickContent,
11472
+ append: recordAppend
11473
+ });
11474
+ });
11475
+ }
11476
+ };
11477
+ var writePage = function writePage(result) {
11478
+ var isFirst = pagesWritten === 0;
11479
+ // For `replace` mode every iteration truncates; for `concat` mode only the first page truncates.
11480
+ var append = dumpMerge === 'concat' && !isFirst;
11481
+ if (dumpOutput === 'raw') {
11482
+ writeRawPage(result, append);
11483
+ } else if (dumpOutput === 'page_by_line') {
11484
+ writeLinePage(result, append);
11485
+ } else {
11486
+ writeDataByLinePage(result, append);
11487
+ }
11488
+ pagesWritten += 1;
11489
+ };
11490
+ dump = {
11491
+ mainPath: mainPath,
11492
+ pickPath: pickPath,
11493
+ writePage: writePage,
11494
+ close: function close() {
11495
+ return undefined;
11496
+ }
11497
+ };
11498
+ } else {
11499
+ dump = {
11251
11500
  mainPath: undefined,
11252
11501
  pickPath: undefined,
11253
11502
  writePage: function writePage() {
@@ -11258,91 +11507,7 @@ function _ts_generator(thisArg, body) {
11258
11507
  }
11259
11508
  };
11260
11509
  }
11261
- var pagesWritten = 0;
11262
- function applyPickToPage(result) {
11263
- if (!pick) {
11264
- return result;
11265
- }
11266
- var pickedData = pickFields(result.data, pick);
11267
- return _object_spread_props(_object_spread({}, result), {
11268
- data: pickedData
11269
- });
11270
- }
11271
- function writeBoth(input) {
11272
- var flagFn = input.append ? node_fs.appendFileSync : node_fs.writeFileSync;
11273
- if (mainPath) {
11274
- flagFn(mainPath, input.mainContent);
11275
- }
11276
- if (pickPath && input.pickContent !== undefined) {
11277
- flagFn(pickPath, input.pickContent);
11278
- }
11279
- }
11280
- function writeRawPage(result, append) {
11281
- var mainContent = JSON.stringify(result, null, 2);
11282
- var pickContent = pickPath ? JSON.stringify(applyPickToPage(result), null, 2) : undefined;
11283
- writeBoth({
11284
- mainContent: mainContent,
11285
- pickContent: pickContent,
11286
- append: append
11287
- });
11288
- }
11289
- function writeLinePage(result, append) {
11290
- var mainContent = JSON.stringify(result) + '\n';
11291
- var pickContent = pickPath ? JSON.stringify(applyPickToPage(result)) + '\n' : undefined;
11292
- writeBoth({
11293
- mainContent: mainContent,
11294
- pickContent: pickContent,
11295
- append: append
11296
- });
11297
- }
11298
- function writeDataByLinePage(result, append) {
11299
- var _result_data;
11300
- // data_by_line — one record per line. For `replace` mode, truncate on first record then append the rest.
11301
- var records = (_result_data = result.data) !== null && _result_data !== void 0 ? _result_data : [];
11302
- var pickedRecords = pickPath ? pickFields(records, pick) : undefined;
11303
- if (records.length === 0) {
11304
- // Still ensure file is created/truncated on first iteration even when empty.
11305
- if (!append) {
11306
- writeBoth({
11307
- mainContent: '',
11308
- pickContent: pickPath ? '' : undefined,
11309
- append: false
11310
- });
11311
- }
11312
- } else {
11313
- records.forEach(function(record, index) {
11314
- var recordAppend = append || index > 0;
11315
- var mainContent = JSON.stringify(record) + '\n';
11316
- var pickContent = pickPath && pickedRecords ? JSON.stringify(pickedRecords[index]) + '\n' : undefined;
11317
- writeBoth({
11318
- mainContent: mainContent,
11319
- pickContent: pickContent,
11320
- append: recordAppend
11321
- });
11322
- });
11323
- }
11324
- }
11325
- function writePage(result) {
11326
- var isFirst = pagesWritten === 0;
11327
- // For `replace` mode every iteration truncates; for `concat` mode only the first page truncates.
11328
- var append = dumpMerge === 'concat' && !isFirst;
11329
- if (dumpOutput === 'raw') {
11330
- writeRawPage(result, append);
11331
- } else if (dumpOutput === 'page_by_line') {
11332
- writeLinePage(result, append);
11333
- } else {
11334
- writeDataByLinePage(result, append);
11335
- }
11336
- pagesWritten += 1;
11337
- }
11338
- return {
11339
- mainPath: mainPath,
11340
- pickPath: pickPath,
11341
- writePage: writePage,
11342
- close: function close() {
11343
- return undefined;
11344
- }
11345
- };
11510
+ return dump;
11346
11511
  }
11347
11512
  function runFetchLoop(input) {
11348
11513
  return _async_to_generator(function() {
@@ -11477,7 +11642,7 @@ function printPaginatedOutput(input) {
11477
11642
  * @returns `{ handled: false, result }` for single-page mode, otherwise `{ handled: true }` after the loop prints its own response.
11478
11643
  */ function runPaginatedList(params) {
11479
11644
  return _async_to_generator(function() {
11480
- var _stream_mainPath, initialInput, fetchPage, adapter, multiplePagesOutput, dumpOutput, dumpMerge, requestedPages, result, outputOptions, stream, state, summaryMeta;
11645
+ var initialInput, fetchPage, adapter, multiplePagesOutput, dumpOutput, dumpMerge, requestedPages, outcome, result, _stream_mainPath, outputOptions, stream, state, summaryMeta;
11481
11646
  return _ts_generator(this, function(_state) {
11482
11647
  switch(_state.label){
11483
11648
  case 0:
@@ -11493,12 +11658,13 @@ function printPaginatedOutput(input) {
11493
11658
  ];
11494
11659
  case 1:
11495
11660
  result = _state.sent();
11661
+ outcome = {
11662
+ handled: false,
11663
+ result: result
11664
+ };
11496
11665
  return [
11497
- 2,
11498
- {
11499
- handled: false,
11500
- result: result
11501
- }
11666
+ 3,
11667
+ 7
11502
11668
  ];
11503
11669
  case 2:
11504
11670
  outputOptions = getOutputOptions();
@@ -11557,11 +11723,14 @@ function printPaginatedOutput(input) {
11557
11723
  adapter: adapter,
11558
11724
  pickFilter: outputOptions.pick
11559
11725
  });
11726
+ outcome = {
11727
+ handled: true
11728
+ };
11729
+ _state.label = 7;
11730
+ case 7:
11560
11731
  return [
11561
11732
  2,
11562
- {
11563
- handled: true
11564
- }
11733
+ outcome
11565
11734
  ];
11566
11735
  }
11567
11736
  });
@@ -11573,6 +11742,7 @@ Object.defineProperty(exports, "CALL_MODEL_APP_FUNCTION_KEY", {
11573
11742
  get: function () { return firebase.CALL_MODEL_APP_FUNCTION_KEY; }
11574
11743
  });
11575
11744
  exports.CALL_MODEL_API_PATH = CALL_MODEL_API_PATH;
11745
+ exports.CALL_PASSTHROUGH_COMMAND = CALL_PASSTHROUGH_COMMAND;
11576
11746
  exports.CLI_EXIT_CODE_AUTH = CLI_EXIT_CODE_AUTH;
11577
11747
  exports.CLI_EXIT_CODE_HANDLER = CLI_EXIT_CODE_HANDLER;
11578
11748
  exports.CliError = CliError;
@@ -11587,6 +11757,8 @@ exports.DEFAULT_MODEL_DECODE_COMMAND_NAME = DEFAULT_MODEL_DECODE_COMMAND_NAME;
11587
11757
  exports.DEFAULT_MODEL_INFO_COMMAND_NAME = DEFAULT_MODEL_INFO_COMMAND_NAME;
11588
11758
  exports.DUMP_MERGE_MODES = DUMP_MERGE_MODES;
11589
11759
  exports.DUMP_OUTPUT_MODES = DUMP_OUTPUT_MODES;
11760
+ exports.GET_COMMAND = GET_COMMAND;
11761
+ exports.GET_MANY_COMMAND = GET_MANY_COMMAND;
11590
11762
  exports.MAX_MODEL_ACCESS_MULTI_READ_KEYS = MAX_MODEL_ACCESS_MULTI_READ_KEYS;
11591
11763
  exports.MODEL_WRITE_OIDC_SCOPES = MODEL_WRITE_OIDC_SCOPES;
11592
11764
  exports.MULTIPLE_PAGES_OUTPUT_MODES = MULTIPLE_PAGES_OUTPUT_MODES;
@@ -11603,7 +11775,6 @@ exports.buildModelDecodeCommand = buildModelDecodeCommand;
11603
11775
  exports.buildModelInfoCommand = buildModelInfoCommand;
11604
11776
  exports.buildOidcDiscoveryCandidates = buildOidcDiscoveryCandidates;
11605
11777
  exports.callModelOverHttp = callModelOverHttp;
11606
- exports.callPassthroughCommand = callPassthroughCommand;
11607
11778
  exports.configureCliErrorMapper = configureCliErrorMapper;
11608
11779
  exports.configureCliSecretPatterns = configureCliSecretPatterns;
11609
11780
  exports.configureOutputOptions = configureOutputOptions;
@@ -11637,8 +11808,6 @@ exports.generatePkceMaterial = generatePkceMaterial;
11637
11808
  exports.getCliContext = getCliContext;
11638
11809
  exports.getCliEnvVarName = getCliEnvVarName;
11639
11810
  exports.getCliTimeoutMs = getCliTimeoutMs;
11640
- exports.getCommand = getCommand;
11641
- exports.getManyCommand = getManyCommand;
11642
11811
  exports.getModelOverHttp = getModelOverHttp;
11643
11812
  exports.getMultipleModelsOverHttp = getMultipleModelsOverHttp;
11644
11813
  exports.getMultipleModelsOverHttpChunked = getMultipleModelsOverHttpChunked;