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