@dereekb/dbx-cli 13.11.9 → 13.11.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs.js CHANGED
@@ -11,13 +11,13 @@ var node_readline = require('node:readline');
11
11
  var yargs = require('yargs');
12
12
  var helpers = require('yargs/helpers');
13
13
 
14
- function _array_like_to_array$8(arr, len) {
14
+ function _array_like_to_array$b(arr, len) {
15
15
  if (len == null || len > arr.length) len = arr.length;
16
16
  for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
17
17
  return arr2;
18
18
  }
19
- function _array_without_holes$5(arr) {
20
- if (Array.isArray(arr)) return _array_like_to_array$8(arr);
19
+ function _array_without_holes$8(arr) {
20
+ if (Array.isArray(arr)) return _array_like_to_array$b(arr);
21
21
  }
22
22
  function _assert_this_initialized(self) {
23
23
  if (self === void 0) {
@@ -51,7 +51,7 @@ function _construct(Parent, args, Class) {
51
51
  }
52
52
  return _construct.apply(null, arguments);
53
53
  }
54
- function _define_property$c(obj, key, value) {
54
+ function _define_property$d(obj, key, value) {
55
55
  if (key in obj) {
56
56
  Object.defineProperty(obj, key, {
57
57
  value: value,
@@ -94,13 +94,13 @@ function _instanceof$6(left, right) {
94
94
  function _is_native_function(fn) {
95
95
  return Function.toString.call(fn).indexOf("[native code]") !== -1;
96
96
  }
97
- function _iterable_to_array$5(iter) {
97
+ function _iterable_to_array$8(iter) {
98
98
  if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
99
99
  }
100
- function _non_iterable_spread$5() {
100
+ function _non_iterable_spread$8() {
101
101
  throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
102
102
  }
103
- function _object_spread$c(target) {
103
+ function _object_spread$d(target) {
104
104
  for(var i = 1; i < arguments.length; i++){
105
105
  var source = arguments[i] != null ? arguments[i] : {};
106
106
  var ownKeys = Object.keys(source);
@@ -110,7 +110,7 @@ function _object_spread$c(target) {
110
110
  }));
111
111
  }
112
112
  ownKeys.forEach(function(key) {
113
- _define_property$c(target, key, source[key]);
113
+ _define_property$d(target, key, source[key]);
114
114
  });
115
115
  }
116
116
  return target;
@@ -128,20 +128,20 @@ function _set_prototype_of(o, p) {
128
128
  };
129
129
  return _set_prototype_of(o, p);
130
130
  }
131
- function _to_consumable_array$5(arr) {
132
- return _array_without_holes$5(arr) || _iterable_to_array$5(arr) || _unsupported_iterable_to_array$8(arr) || _non_iterable_spread$5();
131
+ function _to_consumable_array$8(arr) {
132
+ return _array_without_holes$8(arr) || _iterable_to_array$8(arr) || _unsupported_iterable_to_array$b(arr) || _non_iterable_spread$8();
133
133
  }
134
134
  function _type_of$3(obj) {
135
135
  "@swc/helpers - typeof";
136
136
  return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
137
137
  }
138
- function _unsupported_iterable_to_array$8(o, minLen) {
138
+ function _unsupported_iterable_to_array$b(o, minLen) {
139
139
  if (!o) return;
140
- if (typeof o === "string") return _array_like_to_array$8(o, minLen);
140
+ if (typeof o === "string") return _array_like_to_array$b(o, minLen);
141
141
  var n = Object.prototype.toString.call(o).slice(8, -1);
142
142
  if (n === "Object" && o.constructor) n = o.constructor.name;
143
143
  if (n === "Map" || n === "Set") return Array.from(n);
144
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$8(o, minLen);
144
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$b(o, minLen);
145
145
  }
146
146
  function _wrap_native_super(Class) {
147
147
  var _cache = typeof Map === "function" ? new Map() : undefined;
@@ -190,7 +190,7 @@ function _is_native_reflect_construct() {
190
190
  /id_token[=:]\s*\S+/gi
191
191
  ];
192
192
  var _outputOptions = {};
193
- var _secretPatterns = _to_consumable_array$5(DEFAULT_CLI_SECRET_PATTERNS);
193
+ var _secretPatterns = _to_consumable_array$8(DEFAULT_CLI_SECRET_PATTERNS);
194
194
  var _errorMapper;
195
195
  /**
196
196
  * Configures output options from parsed CLI arguments.
@@ -296,7 +296,7 @@ function dumpResponse(data, meta) {
296
296
  if (!filePath) {
297
297
  return;
298
298
  }
299
- var content = _object_spread$c({
299
+ var content = _object_spread$d({
300
300
  ok: true,
301
301
  data: data
302
302
  }, meta ? {
@@ -364,7 +364,7 @@ function pickFromObject(obj, fields) {
364
364
  */ function outputResult(data, meta) {
365
365
  dumpResponse(data, meta);
366
366
  var outputData = _outputOptions.pick ? pickFields(data, _outputOptions.pick) : data;
367
- var output = _object_spread$c({
367
+ var output = _object_spread$d({
368
368
  ok: true,
369
369
  data: outputData
370
370
  }, meta ? {
@@ -391,7 +391,7 @@ function pickFromObject(obj, fields) {
391
391
  var _this;
392
392
  _this = _call_super(this, CliError, [
393
393
  input.message
394
- ]), _define_property$c(_this, "code", void 0), _define_property$c(_this, "suggestion", void 0);
394
+ ]), _define_property$d(_this, "code", void 0), _define_property$d(_this, "suggestion", void 0);
395
395
  _this.name = 'CliError';
396
396
  _this.code = input.code;
397
397
  _this.suggestion = input.suggestion;
@@ -421,7 +421,7 @@ function pickFromObject(obj, fields) {
421
421
  }
422
422
  }
423
423
  if (_instanceof$6(error, CliError)) {
424
- return _object_spread$c({
424
+ return _object_spread$d({
425
425
  ok: false,
426
426
  error: sanitizeString(error.message),
427
427
  code: error.code
@@ -443,7 +443,7 @@ function pickFromObject(obj, fields) {
443
443
  };
444
444
  }
445
445
 
446
- function asyncGeneratorStep$h(gen, resolve, reject, _next, _throw, key, arg) {
446
+ function asyncGeneratorStep$j(gen, resolve, reject, _next, _throw, key, arg) {
447
447
  try {
448
448
  var info = gen[key](arg);
449
449
  var value = info.value;
@@ -457,16 +457,16 @@ function asyncGeneratorStep$h(gen, resolve, reject, _next, _throw, key, arg) {
457
457
  Promise.resolve(value).then(_next, _throw);
458
458
  }
459
459
  }
460
- function _async_to_generator$h(fn) {
460
+ function _async_to_generator$j(fn) {
461
461
  return function() {
462
462
  var self = this, args = arguments;
463
463
  return new Promise(function(resolve, reject) {
464
464
  var gen = fn.apply(self, args);
465
465
  function _next(value) {
466
- asyncGeneratorStep$h(gen, resolve, reject, _next, _throw, "next", value);
466
+ asyncGeneratorStep$j(gen, resolve, reject, _next, _throw, "next", value);
467
467
  }
468
468
  function _throw(err) {
469
- asyncGeneratorStep$h(gen, resolve, reject, _next, _throw, "throw", err);
469
+ asyncGeneratorStep$j(gen, resolve, reject, _next, _throw, "throw", err);
470
470
  }
471
471
  _next(undefined);
472
472
  });
@@ -476,7 +476,7 @@ function _type_of$2(obj) {
476
476
  "@swc/helpers - typeof";
477
477
  return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
478
478
  }
479
- function _ts_generator$h(thisArg, body) {
479
+ function _ts_generator$j(thisArg, body) {
480
480
  var f, y, t, _ = {
481
481
  label: 0,
482
482
  sent: function() {
@@ -592,9 +592,9 @@ var MAX_MODEL_ACCESS_MULTI_READ_KEYS = 50;
592
592
  * @param input.fetcher - Optional fetch implementation override (used by tests).
593
593
  * @returns The parsed JSON response body cast to `R`.
594
594
  */ function callModelOverHttp(input) {
595
- return _async_to_generator$h(function() {
595
+ return _async_to_generator$j(function() {
596
596
  var _input_fetcher, fetcher, url, res, text, body, _input_params_call, bodyMessage, messageString, message;
597
- return _ts_generator$h(this, function(_state) {
597
+ return _ts_generator$j(this, function(_state) {
598
598
  switch(_state.label){
599
599
  case 0:
600
600
  fetcher = (_input_fetcher = input.fetcher) !== null && _input_fetcher !== void 0 ? _input_fetcher : fetch;
@@ -657,9 +657,9 @@ var MAX_MODEL_ACCESS_MULTI_READ_KEYS = 50;
657
657
  * @param input - The request envelope describing the API target, access token, model + key, and optional fetch override.
658
658
  * @returns The parsed `{ key, data }` envelope.
659
659
  */ function getModelOverHttp(input) {
660
- return _async_to_generator$h(function() {
660
+ return _async_to_generator$j(function() {
661
661
  var _input_fetcher, fetcher, url, res, _ref, ok, body, fallbackMessage;
662
- return _ts_generator$h(this, function(_state) {
662
+ return _ts_generator$j(this, function(_state) {
663
663
  switch(_state.label){
664
664
  case 0:
665
665
  fetcher = (_input_fetcher = input.fetcher) !== null && _input_fetcher !== void 0 ? _input_fetcher : fetch;
@@ -709,9 +709,9 @@ var MAX_MODEL_ACCESS_MULTI_READ_KEYS = 50;
709
709
  * @param input - The request envelope describing the API target, access token, model, keys, and optional fetch override.
710
710
  * @returns The parsed `{ results, errors }` envelope.
711
711
  */ function getMultipleModelsOverHttp(input) {
712
- return _async_to_generator$h(function() {
712
+ return _async_to_generator$j(function() {
713
713
  var _input_fetcher, fetcher, url, res, _ref, ok, body, fallbackMessage;
714
- return _ts_generator$h(this, function(_state) {
714
+ return _ts_generator$j(this, function(_state) {
715
715
  switch(_state.label){
716
716
  case 0:
717
717
  if (input.keys.length === 0) {
@@ -766,9 +766,9 @@ var MAX_MODEL_ACCESS_MULTI_READ_KEYS = 50;
766
766
  })();
767
767
  }
768
768
  function readJsonResponse(res) {
769
- return _async_to_generator$h(function() {
769
+ return _async_to_generator$j(function() {
770
770
  var text, body;
771
- return _ts_generator$h(this, function(_state) {
771
+ return _ts_generator$j(this, function(_state) {
772
772
  switch(_state.label){
773
773
  case 0:
774
774
  return [
@@ -848,70 +848,1010 @@ function trimSlash$1(url) {
848
848
  if (_value == null) {
849
849
  throw new Error(notInitializedMessage);
850
850
  }
851
- return _value;
852
- }
851
+ return _value;
852
+ }
853
+ };
854
+ }
855
+
856
+ /**
857
+ * Module-level slot holding the {@link CliContext} for the current invocation.
858
+ *
859
+ * Stored here instead of on argv so that yargs strict-mode does not flag it as an unknown argument.
860
+ */ var _cliContextSlot = createContextSlot({
861
+ notInitializedMessage: 'CLI context not initialized — auth middleware must run before this command.'
862
+ });
863
+ var setCliContext = _cliContextSlot.set;
864
+ var getCliContext = _cliContextSlot.get;
865
+ /**
866
+ * Returns the current {@link CliContext} or throws — for use in command handlers that require auth.
867
+ */ var requireCliContext = _cliContextSlot.require;
868
+ /**
869
+ * Builds a {@link CliContext} for the current invocation.
870
+ *
871
+ * Bundles the env config and access token alongside helpers that POST/GET against
872
+ * `<env.apiBaseUrl>/model/*` with the cached Bearer token.
873
+ *
874
+ * @param input - The context inputs.
875
+ * @param input.cliName - The CLI's binary name.
876
+ * @param input.envName - The active env name.
877
+ * @param input.env - The resolved {@link CliEnvConfig} for the active env.
878
+ * @param input.accessToken - The Bearer access token to include on outgoing API calls.
879
+ * @param input.modelManifest - Optional generated {@link CliModelManifest} for key→modelType resolution.
880
+ * @returns The constructed {@link CliContext}.
881
+ * @__NO_SIDE_EFFECTS__
882
+ */ function createCliContext(input) {
883
+ var apiBaseUrl = input.env.apiBaseUrl;
884
+ var accessToken = input.accessToken;
885
+ return {
886
+ cliName: input.cliName,
887
+ envName: input.envName,
888
+ env: input.env,
889
+ accessToken: accessToken,
890
+ modelManifest: input.modelManifest,
891
+ callModel: function callModel(params) {
892
+ return callModelOverHttp({
893
+ apiBaseUrl: apiBaseUrl,
894
+ accessToken: accessToken,
895
+ params: params
896
+ });
897
+ },
898
+ getModel: function getModel(modelType, key) {
899
+ return getModelOverHttp({
900
+ apiBaseUrl: apiBaseUrl,
901
+ accessToken: accessToken,
902
+ modelType: modelType,
903
+ key: key
904
+ });
905
+ },
906
+ getMultipleModels: function getMultipleModels(modelType, keys) {
907
+ return getMultipleModelsOverHttp({
908
+ apiBaseUrl: apiBaseUrl,
909
+ accessToken: accessToken,
910
+ modelType: modelType,
911
+ keys: keys
912
+ });
913
+ }
914
+ };
915
+ }
916
+
917
+ function asyncGeneratorStep$i(gen, resolve, reject, _next, _throw, key, arg) {
918
+ try {
919
+ var info = gen[key](arg);
920
+ var value = info.value;
921
+ } catch (error) {
922
+ reject(error);
923
+ return;
924
+ }
925
+ if (info.done) {
926
+ resolve(value);
927
+ } else {
928
+ Promise.resolve(value).then(_next, _throw);
929
+ }
930
+ }
931
+ function _async_to_generator$i(fn) {
932
+ return function() {
933
+ var self = this, args = arguments;
934
+ return new Promise(function(resolve, reject) {
935
+ var gen = fn.apply(self, args);
936
+ function _next(value) {
937
+ asyncGeneratorStep$i(gen, resolve, reject, _next, _throw, "next", value);
938
+ }
939
+ function _throw(err) {
940
+ asyncGeneratorStep$i(gen, resolve, reject, _next, _throw, "throw", err);
941
+ }
942
+ _next(undefined);
943
+ });
944
+ };
945
+ }
946
+ function _ts_generator$i(thisArg, body) {
947
+ var f, y, t, _ = {
948
+ label: 0,
949
+ sent: function() {
950
+ if (t[0] & 1) throw t[1];
951
+ return t[1];
952
+ },
953
+ trys: [],
954
+ ops: []
955
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
956
+ return d(g, "next", {
957
+ value: verb(0)
958
+ }), d(g, "throw", {
959
+ value: verb(1)
960
+ }), d(g, "return", {
961
+ value: verb(2)
962
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
963
+ value: function() {
964
+ return this;
965
+ }
966
+ }), g;
967
+ function verb(n) {
968
+ return function(v) {
969
+ return step([
970
+ n,
971
+ v
972
+ ]);
973
+ };
974
+ }
975
+ function step(op) {
976
+ if (f) throw new TypeError("Generator is already executing.");
977
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
978
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
979
+ if (y = 0, t) op = [
980
+ op[0] & 2,
981
+ t.value
982
+ ];
983
+ switch(op[0]){
984
+ case 0:
985
+ case 1:
986
+ t = op;
987
+ break;
988
+ case 4:
989
+ _.label++;
990
+ return {
991
+ value: op[1],
992
+ done: false
993
+ };
994
+ case 5:
995
+ _.label++;
996
+ y = op[1];
997
+ op = [
998
+ 0
999
+ ];
1000
+ continue;
1001
+ case 7:
1002
+ op = _.ops.pop();
1003
+ _.trys.pop();
1004
+ continue;
1005
+ default:
1006
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
1007
+ _ = 0;
1008
+ continue;
1009
+ }
1010
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
1011
+ _.label = op[1];
1012
+ break;
1013
+ }
1014
+ if (op[0] === 6 && _.label < t[1]) {
1015
+ _.label = t[1];
1016
+ t = op;
1017
+ break;
1018
+ }
1019
+ if (t && _.label < t[2]) {
1020
+ _.label = t[2];
1021
+ _.ops.push(op);
1022
+ break;
1023
+ }
1024
+ if (t[2]) _.ops.pop();
1025
+ _.trys.pop();
1026
+ continue;
1027
+ }
1028
+ op = body.call(thisArg, _);
1029
+ } catch (e) {
1030
+ op = [
1031
+ 6,
1032
+ e
1033
+ ];
1034
+ y = 0;
1035
+ } finally{
1036
+ f = t = 0;
1037
+ }
1038
+ if (op[0] & 5) throw op[1];
1039
+ return {
1040
+ value: op[0] ? op[1] : void 0,
1041
+ done: true
1042
+ };
1043
+ }
1044
+ }
1045
+ /**
1046
+ * Wraps an {@link ActionCommandSpec} as a yargs `CommandModule`.
1047
+ *
1048
+ * The returned command:
1049
+ * - Calls {@link requireCliContext} so it fails loudly when auth middleware did not run.
1050
+ * - Invokes `spec.handler({ context, argv })`.
1051
+ * - Pipes the result through `spec.mapResult` when provided.
1052
+ * - Emits the value via {@link outputResult}; emits {@link outputError} + `process.exit(1)` on failure.
1053
+ *
1054
+ * @param spec - The action specification.
1055
+ * @returns The yargs command module ready to be registered under the `action` parent.
1056
+ * @__NO_SIDE_EFFECTS__
1057
+ */ function createActionCommand(spec) {
1058
+ return {
1059
+ command: spec.command,
1060
+ describe: spec.describe,
1061
+ builder: function builder(yargs) {
1062
+ var built = spec.builder ? spec.builder(yargs) : yargs;
1063
+ return spec.helpEpilogue ? built.epilogue(spec.helpEpilogue) : built;
1064
+ },
1065
+ handler: function handler(argv) {
1066
+ return _async_to_generator$i(function() {
1067
+ var context, result, e;
1068
+ return _ts_generator$i(this, function(_state) {
1069
+ switch(_state.label){
1070
+ case 0:
1071
+ _state.trys.push([
1072
+ 0,
1073
+ 2,
1074
+ ,
1075
+ 3
1076
+ ]);
1077
+ context = requireCliContext();
1078
+ return [
1079
+ 4,
1080
+ spec.handler({
1081
+ context: context,
1082
+ argv: argv
1083
+ })
1084
+ ];
1085
+ case 1:
1086
+ result = _state.sent();
1087
+ outputResult(spec.mapResult ? spec.mapResult(result) : result);
1088
+ return [
1089
+ 3,
1090
+ 3
1091
+ ];
1092
+ case 2:
1093
+ e = _state.sent();
1094
+ outputError(e);
1095
+ process.exit(1);
1096
+ return [
1097
+ 3,
1098
+ 3
1099
+ ];
1100
+ case 3:
1101
+ return [
1102
+ 2
1103
+ ];
1104
+ }
1105
+ });
1106
+ })();
1107
+ }
1108
+ };
1109
+ }
1110
+
1111
+ function _array_like_to_array$a(arr, len) {
1112
+ if (len == null || len > arr.length) len = arr.length;
1113
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
1114
+ return arr2;
1115
+ }
1116
+ function _array_with_holes$6(arr) {
1117
+ if (Array.isArray(arr)) return arr;
1118
+ }
1119
+ function _array_without_holes$7(arr) {
1120
+ if (Array.isArray(arr)) return _array_like_to_array$a(arr);
1121
+ }
1122
+ function _iterable_to_array$7(iter) {
1123
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
1124
+ }
1125
+ function _iterable_to_array_limit$6(arr, i) {
1126
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
1127
+ if (_i == null) return;
1128
+ var _arr = [];
1129
+ var _n = true;
1130
+ var _d = false;
1131
+ var _s, _e;
1132
+ try {
1133
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
1134
+ _arr.push(_s.value);
1135
+ if (i && _arr.length === i) break;
1136
+ }
1137
+ } catch (err) {
1138
+ _d = true;
1139
+ _e = err;
1140
+ } finally{
1141
+ try {
1142
+ if (!_n && _i["return"] != null) _i["return"]();
1143
+ } finally{
1144
+ if (_d) throw _e;
1145
+ }
1146
+ }
1147
+ return _arr;
1148
+ }
1149
+ function _non_iterable_rest$6() {
1150
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1151
+ }
1152
+ function _non_iterable_spread$7() {
1153
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1154
+ }
1155
+ function _sliced_to_array$6(arr, i) {
1156
+ return _array_with_holes$6(arr) || _iterable_to_array_limit$6(arr, i) || _unsupported_iterable_to_array$a(arr, i) || _non_iterable_rest$6();
1157
+ }
1158
+ function _to_consumable_array$7(arr) {
1159
+ return _array_without_holes$7(arr) || _iterable_to_array$7(arr) || _unsupported_iterable_to_array$a(arr) || _non_iterable_spread$7();
1160
+ }
1161
+ function _unsupported_iterable_to_array$a(o, minLen) {
1162
+ if (!o) return;
1163
+ if (typeof o === "string") return _array_like_to_array$a(o, minLen);
1164
+ var n = Object.prototype.toString.call(o).slice(8, -1);
1165
+ if (n === "Object" && o.constructor) n = o.constructor.name;
1166
+ if (n === "Map" || n === "Set") return Array.from(n);
1167
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$a(o, minLen);
1168
+ }
1169
+ /**
1170
+ * Default name of the parent command that groups all registered action specs.
1171
+ * Surfaces as `<cli> action <action>` (root) and `<cli> action <model> <action>` (model-scoped).
1172
+ */ var DEFAULT_ACTION_COMMAND_NAME = 'action';
1173
+ /**
1174
+ * Assembles the parent `action` command tree from a list of {@link ActionCommandSpec}s.
1175
+ *
1176
+ * Specs without a `model` are appended as direct subcommands of `action`. Specs with a
1177
+ * `model` are grouped under `action <model> <action>` (mirroring `buildManifestCommands`'
1178
+ * `model <model> <action>` shape) so the model-scoped surface stays browseable.
1179
+ *
1180
+ * @param specs - The action specs registered by the app.
1181
+ * @param options - Optional overrides (e.g. parent command name).
1182
+ * @returns An array containing a single parent `action` command, or empty when no specs were provided.
1183
+ * @__NO_SIDE_EFFECTS__
1184
+ */ function buildActionCommands(specs, options) {
1185
+ var result = [];
1186
+ if (specs.length > 0) {
1187
+ var _ref;
1188
+ var actionCommandName = (_ref = options === null || options === void 0 ? void 0 : options.actionCommandName) !== null && _ref !== void 0 ? _ref : DEFAULT_ACTION_COMMAND_NAME;
1189
+ var rootSpecs = specs.filter(function(s) {
1190
+ return !s.model;
1191
+ });
1192
+ var byModel = new Map();
1193
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1194
+ try {
1195
+ for(var _iterator = specs[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1196
+ var spec = _step.value;
1197
+ if (spec.model) {
1198
+ var list = byModel.get(spec.model);
1199
+ if (list) {
1200
+ list.push(spec);
1201
+ } else {
1202
+ byModel.set(spec.model, [
1203
+ spec
1204
+ ]);
1205
+ }
1206
+ }
1207
+ }
1208
+ } catch (err) {
1209
+ _didIteratorError = true;
1210
+ _iteratorError = err;
1211
+ } finally{
1212
+ try {
1213
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1214
+ _iterator.return();
1215
+ }
1216
+ } finally{
1217
+ if (_didIteratorError) {
1218
+ throw _iteratorError;
1219
+ }
1220
+ }
1221
+ }
1222
+ var sortedModels = _to_consumable_array$7(byModel.entries()).sort(function(param, param1) {
1223
+ var _param = _sliced_to_array$6(param, 1), a = _param[0], _param1 = _sliced_to_array$6(param1, 1), b = _param1[0];
1224
+ return a.localeCompare(b);
1225
+ });
1226
+ result = [
1227
+ {
1228
+ command: "".concat(actionCommandName, " <action>"),
1229
+ describe: "Run a composite action (".concat(specs.length, "). Use `").concat(actionCommandName, " --help` to list them."),
1230
+ builder: function builder(yargs) {
1231
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1232
+ try {
1233
+ for(var _iterator = rootSpecs[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1234
+ var spec = _step.value;
1235
+ yargs.command(createActionCommand(spec));
1236
+ }
1237
+ } catch (err) {
1238
+ _didIteratorError = true;
1239
+ _iteratorError = err;
1240
+ } finally{
1241
+ try {
1242
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1243
+ _iterator.return();
1244
+ }
1245
+ } finally{
1246
+ if (_didIteratorError) {
1247
+ throw _iteratorError;
1248
+ }
1249
+ }
1250
+ }
1251
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
1252
+ try {
1253
+ var _loop = function() {
1254
+ var _step_value = _sliced_to_array$6(_step1.value, 2), model = _step_value[0], modelSpecs = _step_value[1];
1255
+ yargs.command({
1256
+ command: "".concat(model, " <action>"),
1257
+ describe: "Composite actions scoped to model '".concat(model, "' (").concat(modelSpecs.length, ")."),
1258
+ builder: function builder(yy) {
1259
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1260
+ try {
1261
+ for(var _iterator = modelSpecs[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1262
+ var spec = _step.value;
1263
+ yy.command(createActionCommand(spec));
1264
+ }
1265
+ } catch (err) {
1266
+ _didIteratorError = true;
1267
+ _iteratorError = err;
1268
+ } finally{
1269
+ try {
1270
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1271
+ _iterator.return();
1272
+ }
1273
+ } finally{
1274
+ if (_didIteratorError) {
1275
+ throw _iteratorError;
1276
+ }
1277
+ }
1278
+ }
1279
+ return yy.demandCommand(1, 'Please specify an action.');
1280
+ },
1281
+ handler: function handler() {
1282
+ return undefined;
1283
+ }
1284
+ });
1285
+ };
1286
+ for(var _iterator1 = sortedModels[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true)_loop();
1287
+ } catch (err) {
1288
+ _didIteratorError1 = true;
1289
+ _iteratorError1 = err;
1290
+ } finally{
1291
+ try {
1292
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
1293
+ _iterator1.return();
1294
+ }
1295
+ } finally{
1296
+ if (_didIteratorError1) {
1297
+ throw _iteratorError1;
1298
+ }
1299
+ }
1300
+ }
1301
+ return yargs.demandCommand(1, 'Please specify an action.');
1302
+ },
1303
+ handler: function handler() {
1304
+ return undefined;
1305
+ }
1306
+ }
1307
+ ];
1308
+ }
1309
+ return result;
1310
+ }
1311
+
1312
+ function _array_like_to_array$9(arr, len) {
1313
+ if (len == null || len > arr.length) len = arr.length;
1314
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
1315
+ return arr2;
1316
+ }
1317
+ function _array_with_holes$5(arr) {
1318
+ if (Array.isArray(arr)) return arr;
1319
+ }
1320
+ function _array_without_holes$6(arr) {
1321
+ if (Array.isArray(arr)) return _array_like_to_array$9(arr);
1322
+ }
1323
+ function asyncGeneratorStep$h(gen, resolve, reject, _next, _throw, key, arg) {
1324
+ try {
1325
+ var info = gen[key](arg);
1326
+ var value = info.value;
1327
+ } catch (error) {
1328
+ reject(error);
1329
+ return;
1330
+ }
1331
+ if (info.done) {
1332
+ resolve(value);
1333
+ } else {
1334
+ Promise.resolve(value).then(_next, _throw);
1335
+ }
1336
+ }
1337
+ function _async_to_generator$h(fn) {
1338
+ return function() {
1339
+ var self = this, args = arguments;
1340
+ return new Promise(function(resolve, reject) {
1341
+ var gen = fn.apply(self, args);
1342
+ function _next(value) {
1343
+ asyncGeneratorStep$h(gen, resolve, reject, _next, _throw, "next", value);
1344
+ }
1345
+ function _throw(err) {
1346
+ asyncGeneratorStep$h(gen, resolve, reject, _next, _throw, "throw", err);
1347
+ }
1348
+ _next(undefined);
1349
+ });
1350
+ };
1351
+ }
1352
+ function _define_property$c(obj, key, value) {
1353
+ if (key in obj) {
1354
+ Object.defineProperty(obj, key, {
1355
+ value: value,
1356
+ enumerable: true,
1357
+ configurable: true,
1358
+ writable: true
1359
+ });
1360
+ } else {
1361
+ obj[key] = value;
1362
+ }
1363
+ return obj;
1364
+ }
1365
+ function _iterable_to_array$6(iter) {
1366
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
1367
+ }
1368
+ function _iterable_to_array_limit$5(arr, i) {
1369
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
1370
+ if (_i == null) return;
1371
+ var _arr = [];
1372
+ var _n = true;
1373
+ var _d = false;
1374
+ var _s, _e;
1375
+ try {
1376
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
1377
+ _arr.push(_s.value);
1378
+ if (i && _arr.length === i) break;
1379
+ }
1380
+ } catch (err) {
1381
+ _d = true;
1382
+ _e = err;
1383
+ } finally{
1384
+ try {
1385
+ if (!_n && _i["return"] != null) _i["return"]();
1386
+ } finally{
1387
+ if (_d) throw _e;
1388
+ }
1389
+ }
1390
+ return _arr;
1391
+ }
1392
+ function _non_iterable_rest$5() {
1393
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1394
+ }
1395
+ function _non_iterable_spread$6() {
1396
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1397
+ }
1398
+ function _object_spread$c(target) {
1399
+ for(var i = 1; i < arguments.length; i++){
1400
+ var source = arguments[i] != null ? arguments[i] : {};
1401
+ var ownKeys = Object.keys(source);
1402
+ if (typeof Object.getOwnPropertySymbols === "function") {
1403
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
1404
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
1405
+ }));
1406
+ }
1407
+ ownKeys.forEach(function(key) {
1408
+ _define_property$c(target, key, source[key]);
1409
+ });
1410
+ }
1411
+ return target;
1412
+ }
1413
+ function ownKeys$8(object, enumerableOnly) {
1414
+ var keys = Object.keys(object);
1415
+ if (Object.getOwnPropertySymbols) {
1416
+ var symbols = Object.getOwnPropertySymbols(object);
1417
+ keys.push.apply(keys, symbols);
1418
+ }
1419
+ return keys;
1420
+ }
1421
+ function _object_spread_props$8(target, source) {
1422
+ source = source != null ? source : {};
1423
+ if (Object.getOwnPropertyDescriptors) {
1424
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
1425
+ } else {
1426
+ ownKeys$8(Object(source)).forEach(function(key) {
1427
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
1428
+ });
1429
+ }
1430
+ return target;
1431
+ }
1432
+ function _sliced_to_array$5(arr, i) {
1433
+ return _array_with_holes$5(arr) || _iterable_to_array_limit$5(arr, i) || _unsupported_iterable_to_array$9(arr, i) || _non_iterable_rest$5();
1434
+ }
1435
+ function _to_consumable_array$6(arr) {
1436
+ return _array_without_holes$6(arr) || _iterable_to_array$6(arr) || _unsupported_iterable_to_array$9(arr) || _non_iterable_spread$6();
1437
+ }
1438
+ function _unsupported_iterable_to_array$9(o, minLen) {
1439
+ if (!o) return;
1440
+ if (typeof o === "string") return _array_like_to_array$9(o, minLen);
1441
+ var n = Object.prototype.toString.call(o).slice(8, -1);
1442
+ if (n === "Object" && o.constructor) n = o.constructor.name;
1443
+ if (n === "Map" || n === "Set") return Array.from(n);
1444
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$9(o, minLen);
1445
+ }
1446
+ function _ts_generator$h(thisArg, body) {
1447
+ var f, y, t, _ = {
1448
+ label: 0,
1449
+ sent: function() {
1450
+ if (t[0] & 1) throw t[1];
1451
+ return t[1];
1452
+ },
1453
+ trys: [],
1454
+ ops: []
1455
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
1456
+ return d(g, "next", {
1457
+ value: verb(0)
1458
+ }), d(g, "throw", {
1459
+ value: verb(1)
1460
+ }), d(g, "return", {
1461
+ value: verb(2)
1462
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
1463
+ value: function() {
1464
+ return this;
1465
+ }
1466
+ }), g;
1467
+ function verb(n) {
1468
+ return function(v) {
1469
+ return step([
1470
+ n,
1471
+ v
1472
+ ]);
1473
+ };
1474
+ }
1475
+ function step(op) {
1476
+ if (f) throw new TypeError("Generator is already executing.");
1477
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
1478
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
1479
+ if (y = 0, t) op = [
1480
+ op[0] & 2,
1481
+ t.value
1482
+ ];
1483
+ switch(op[0]){
1484
+ case 0:
1485
+ case 1:
1486
+ t = op;
1487
+ break;
1488
+ case 4:
1489
+ _.label++;
1490
+ return {
1491
+ value: op[1],
1492
+ done: false
1493
+ };
1494
+ case 5:
1495
+ _.label++;
1496
+ y = op[1];
1497
+ op = [
1498
+ 0
1499
+ ];
1500
+ continue;
1501
+ case 7:
1502
+ op = _.ops.pop();
1503
+ _.trys.pop();
1504
+ continue;
1505
+ default:
1506
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
1507
+ _ = 0;
1508
+ continue;
1509
+ }
1510
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
1511
+ _.label = op[1];
1512
+ break;
1513
+ }
1514
+ if (op[0] === 6 && _.label < t[1]) {
1515
+ _.label = t[1];
1516
+ t = op;
1517
+ break;
1518
+ }
1519
+ if (t && _.label < t[2]) {
1520
+ _.label = t[2];
1521
+ _.ops.push(op);
1522
+ break;
1523
+ }
1524
+ if (t[2]) _.ops.pop();
1525
+ _.trys.pop();
1526
+ continue;
1527
+ }
1528
+ op = body.call(thisArg, _);
1529
+ } catch (e) {
1530
+ op = [
1531
+ 6,
1532
+ e
1533
+ ];
1534
+ y = 0;
1535
+ } finally{
1536
+ f = t = 0;
1537
+ }
1538
+ if (op[0] & 5) throw op[1];
1539
+ return {
1540
+ value: op[0] ? op[1] : void 0,
1541
+ done: true
1542
+ };
1543
+ }
1544
+ }
1545
+ var _defaultResponseAdapter = {
1546
+ items: function items(raw) {
1547
+ return raw.results;
1548
+ },
1549
+ keys: function keys(raw) {
1550
+ return raw.keys;
1551
+ },
1552
+ cursorDocumentKey: function cursorDocumentKey(raw) {
1553
+ return raw.cursorDocumentKey;
1554
+ },
1555
+ hasMore: function hasMore(raw) {
1556
+ return raw.hasMore;
1557
+ }
1558
+ };
1559
+ function _defaultBuildRequestData(params, state, limit) {
1560
+ var base = _object_spread$c({}, params);
1561
+ if (state.cursorDocumentKey != null) {
1562
+ base.cursorDocumentKey = state.cursorDocumentKey;
1563
+ }
1564
+ if (limit != null) {
1565
+ base.limit = limit;
1566
+ }
1567
+ return base;
1568
+ }
1569
+ function _runItemTasks(input) {
1570
+ return _async_to_generator$h(function() {
1571
+ var context, items, keys, pageIndex, iterateItem, itemPerformTasksConfig, maxParallelPerPage, indexed, taskConfig, performResult;
1572
+ return _ts_generator$h(this, function(_state) {
1573
+ switch(_state.label){
1574
+ case 0:
1575
+ context = input.context, items = input.items, keys = input.keys, pageIndex = input.pageIndex, iterateItem = input.iterateItem, itemPerformTasksConfig = input.itemPerformTasksConfig, maxParallelPerPage = input.maxParallelPerPage;
1576
+ indexed = items.map(function(item, itemIndex) {
1577
+ var _keys_itemIndex;
1578
+ return {
1579
+ item: item,
1580
+ key: (_keys_itemIndex = keys[itemIndex]) !== null && _keys_itemIndex !== void 0 ? _keys_itemIndex : '',
1581
+ itemIndex: itemIndex
1582
+ };
1583
+ });
1584
+ taskConfig = _object_spread_props$8(_object_spread$c({
1585
+ sequential: true,
1586
+ throwError: true
1587
+ }, itemPerformTasksConfig), {
1588
+ maxParallelTasks: maxParallelPerPage !== null && maxParallelPerPage !== void 0 ? maxParallelPerPage : itemPerformTasksConfig === null || itemPerformTasksConfig === void 0 ? void 0 : itemPerformTasksConfig.maxParallelTasks
1589
+ });
1590
+ return [
1591
+ 4,
1592
+ util.performAsyncTasks(indexed, function(param) {
1593
+ var item = param.item, key = param.key, itemIndex = param.itemIndex;
1594
+ return iterateItem({
1595
+ context: context,
1596
+ item: item,
1597
+ key: key,
1598
+ pageIndex: pageIndex,
1599
+ itemIndex: itemIndex
1600
+ });
1601
+ }, taskConfig)
1602
+ ];
1603
+ case 1:
1604
+ performResult = _state.sent();
1605
+ return [
1606
+ 2,
1607
+ performResult.results.map(function(param) {
1608
+ var _param = _sliced_to_array$5(param, 2), output = _param[1];
1609
+ return output;
1610
+ })
1611
+ ];
1612
+ }
1613
+ });
1614
+ })();
1615
+ }
1616
+ function _processPage(input) {
1617
+ return _async_to_generator$h(function() {
1618
+ var context, raw, pageIndex, responseAdapter, iterateItem, iteratePage, itemPerformTasksConfig, maxParallelPerPage, items, keys, nextCursorDocumentKey, hasMore, itemResults, _tmp, pageResult, _tmp1, output;
1619
+ return _ts_generator$h(this, function(_state) {
1620
+ switch(_state.label){
1621
+ case 0:
1622
+ context = input.context, raw = input.raw, pageIndex = input.pageIndex, responseAdapter = input.responseAdapter, iterateItem = input.iterateItem, iteratePage = input.iteratePage, itemPerformTasksConfig = input.itemPerformTasksConfig, maxParallelPerPage = input.maxParallelPerPage;
1623
+ items = responseAdapter.items(raw);
1624
+ keys = responseAdapter.keys ? responseAdapter.keys(raw) : [];
1625
+ nextCursorDocumentKey = responseAdapter.cursorDocumentKey ? responseAdapter.cursorDocumentKey(raw) : undefined;
1626
+ hasMore = responseAdapter.hasMore ? responseAdapter.hasMore(raw) : nextCursorDocumentKey != null;
1627
+ if (!iterateItem) return [
1628
+ 3,
1629
+ 2
1630
+ ];
1631
+ return [
1632
+ 4,
1633
+ _runItemTasks({
1634
+ context: context,
1635
+ items: items,
1636
+ keys: keys,
1637
+ pageIndex: pageIndex,
1638
+ iterateItem: iterateItem,
1639
+ itemPerformTasksConfig: itemPerformTasksConfig,
1640
+ maxParallelPerPage: maxParallelPerPage
1641
+ })
1642
+ ];
1643
+ case 1:
1644
+ _tmp = _state.sent();
1645
+ return [
1646
+ 3,
1647
+ 3
1648
+ ];
1649
+ case 2:
1650
+ _tmp = undefined;
1651
+ _state.label = 3;
1652
+ case 3:
1653
+ itemResults = _tmp;
1654
+ if (!iteratePage) return [
1655
+ 3,
1656
+ 5
1657
+ ];
1658
+ return [
1659
+ 4,
1660
+ iteratePage({
1661
+ context: context,
1662
+ page: raw,
1663
+ items: items,
1664
+ keys: keys,
1665
+ pageIndex: pageIndex,
1666
+ pageItemResults: itemResults
1667
+ })
1668
+ ];
1669
+ case 4:
1670
+ _tmp1 = _state.sent();
1671
+ return [
1672
+ 3,
1673
+ 6
1674
+ ];
1675
+ case 5:
1676
+ _tmp1 = undefined;
1677
+ _state.label = 6;
1678
+ case 6:
1679
+ pageResult = _tmp1;
1680
+ output = {
1681
+ items: items,
1682
+ itemResults: itemResults,
1683
+ pageResult: pageResult,
1684
+ nextCursorDocumentKey: nextCursorDocumentKey,
1685
+ hasMore: hasMore
1686
+ };
1687
+ return [
1688
+ 2,
1689
+ output
1690
+ ];
1691
+ }
1692
+ });
1693
+ })();
1694
+ }
1695
+ function _computeEffectiveLimit(totalItemsLimit, limitPerPage, totalItems) {
1696
+ var remainingBudget = totalItemsLimit == null ? undefined : totalItemsLimit - totalItems;
1697
+ if (limitPerPage != null && remainingBudget != null) {
1698
+ return Math.min(limitPerPage, remainingBudget);
1699
+ }
1700
+ return limitPerPage !== null && limitPerPage !== void 0 ? limitPerPage : remainingBudget;
1701
+ }
1702
+ function _evaluateLoopExit(input) {
1703
+ var totalItemsLimit = input.totalItemsLimit, maxPages = input.maxPages, totalItems = input.totalItems, pageIndex = input.pageIndex, hasMore = input.hasMore, cursorDocumentKey = input.cursorDocumentKey;
1704
+ var reachedItemsLimit = totalItemsLimit != null && totalItems >= totalItemsLimit;
1705
+ var reachedPagesLimit = maxPages != null && pageIndex >= maxPages;
1706
+ if (reachedItemsLimit || reachedPagesLimit) {
1707
+ return {
1708
+ stop: true,
1709
+ hitLimit: true
1710
+ };
1711
+ }
1712
+ var exhausted = hasMore === false || cursorDocumentKey == null;
1713
+ return {
1714
+ stop: exhausted,
1715
+ hitLimit: false
853
1716
  };
854
1717
  }
855
-
856
1718
  /**
857
- * Module-level slot holding the {@link CliContext} for the current invocation.
1719
+ * Iterates a paginated `callModel` endpoint, exhausting (or stopping at the configured limit) all pages.
858
1720
  *
859
- * Stored here instead of on argv so that yargs strict-mode does not flag it as an unknown argument.
860
- */ var _cliContextSlot = createContextSlot({
861
- notInitializedMessage: 'CLI context not initializedauth middleware must run before this command.'
862
- });
863
- var setCliContext = _cliContextSlot.set;
864
- var getCliContext = _cliContextSlot.get;
865
- /**
866
- * Returns the current {@link CliContext} or throws — for use in command handlers that require auth.
867
- */ var requireCliContext = _cliContextSlot.require;
868
- /**
869
- * Builds a {@link CliContext} for the current invocation.
1721
+ * Cursor-paginated analog of {@link iterateFirestoreDocumentSnapshots}, but speaking HTTP/`callModel`
1722
+ * rather than direct Firestore. The default response adapter reads the canonical
1723
+ * {@link OnCallQueryModelResult} shapesupply a custom adapter to iterate other array-returning
1724
+ * call types (e.g. a `getMultiple`-style standalone call).
870
1725
  *
871
- * Bundles the env config and access token alongside helpers that POST/GET against
872
- * `<env.apiBaseUrl>/model/*` with the cached Bearer token.
1726
+ * Concurrency: pages are fetched serially (cursor dependency); items within a page can run
1727
+ * in parallel via `maxParallelPerPage` (forwarded to `performAsyncTasks`).
873
1728
  *
874
- * @param input - The context inputs.
875
- * @param input.cliName - The CLI's binary name.
876
- * @param input.envName - The active env name.
877
- * @param input.env - The resolved {@link CliEnvConfig} for the active env.
878
- * @param input.accessToken - The Bearer access token to include on outgoing API calls.
879
- * @param input.modelManifest - Optional generated {@link CliModelManifest} for key→modelType resolution.
880
- * @returns The constructed {@link CliContext}.
881
- * @__NO_SIDE_EFFECTS__
882
- */ function createCliContext(input) {
883
- var apiBaseUrl = input.env.apiBaseUrl;
884
- var accessToken = input.accessToken;
885
- return {
886
- cliName: input.cliName,
887
- envName: input.envName,
888
- env: input.env,
889
- accessToken: accessToken,
890
- modelManifest: input.modelManifest,
891
- callModel: function callModel(params) {
892
- return callModelOverHttp({
893
- apiBaseUrl: apiBaseUrl,
894
- accessToken: accessToken,
895
- params: params
896
- });
897
- },
898
- getModel: function getModel(modelType, key) {
899
- return getModelOverHttp({
900
- apiBaseUrl: apiBaseUrl,
901
- accessToken: accessToken,
902
- modelType: modelType,
903
- key: key
904
- });
905
- },
906
- getMultipleModels: function getMultipleModels(modelType, keys) {
907
- return getMultipleModelsOverHttp({
908
- apiBaseUrl: apiBaseUrl,
909
- accessToken: accessToken,
910
- modelType: modelType,
911
- keys: keys
912
- });
913
- }
914
- };
1729
+ * @example
1730
+ * ```ts
1731
+ * // Exhaust every published Guestbook entry for a single Guestbook.
1732
+ * const { totalItems, items } = await iterateDbxCliCallModel<QueryGuestbookEntriesParams, GuestbookEntry>({
1733
+ * context,
1734
+ * modelType: 'guestbookEntry',
1735
+ * params: { guestbook: 'gb/abc', published: true }
1736
+ * });
1737
+ * ```
1738
+ *
1739
+ * @example
1740
+ * ```ts
1741
+ * // Fan out to a child action per Guestbook, with 4-way parallelism per page.
1742
+ * const { itemResults } = await iterateDbxCliCallModel<QueryGuestbooksParams, Guestbook, OnCallQueryModelResult<Guestbook>, EntriesForGuestbook>({
1743
+ * context,
1744
+ * modelType: 'guestbook',
1745
+ * params: { published: true },
1746
+ * maxParallelPerPage: 4,
1747
+ * iterateItem: ({ context, key }) => queryGuestbookEntriesForGuestbook({ context, guestbook: key, published: true })
1748
+ * });
1749
+ * ```
1750
+ *
1751
+ * @param config - Iterator configuration.
1752
+ * @returns The aggregate result.
1753
+ */ function iterateDbxCliCallModel(config) {
1754
+ return _async_to_generator$h(function() {
1755
+ 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;
1756
+ return _ts_generator$h(this, function(_state) {
1757
+ switch(_state.label){
1758
+ case 0:
1759
+ context = config.context, modelType = config.modelType, call = config.call, specifier = config.specifier, params = config.params, _config_buildRequestData = config.buildRequestData, buildRequestData = _config_buildRequestData === void 0 ? _defaultBuildRequestData : _config_buildRequestData, _config_responseAdapter = config.responseAdapter, responseAdapter = _config_responseAdapter === void 0 ? _defaultResponseAdapter : _config_responseAdapter, limitPerPage = config.limitPerPage, totalItemsLimit = config.totalItemsLimit, maxPages = config.maxPages, iterateItem = config.iterateItem, iteratePage = config.iteratePage, itemPerformTasksConfig = config.itemPerformTasksConfig, maxParallelPerPage = config.maxParallelPerPage, _config_collectItems = config.collectItems, collectItems = _config_collectItems === void 0 ? true : _config_collectItems, _config_collectItemResults = config.collectItemResults, collectItemResults = _config_collectItemResults === void 0 ? iterateItem != null : _config_collectItemResults, _config_collectPageResults = config.collectPageResults, collectPageResults = _config_collectPageResults === void 0 ? iteratePage != null : _config_collectPageResults;
1760
+ allItems = [];
1761
+ allItemResults = [];
1762
+ allPageResults = [];
1763
+ pageIndex = 0;
1764
+ totalItems = 0;
1765
+ cursorDocumentKey = undefined;
1766
+ hitLimit = false;
1767
+ keepGoing = true;
1768
+ collectItemsForPage = collectItems;
1769
+ collectItemResultsForPage = iterateItem != null && collectItemResults;
1770
+ collectPageResultsForPage = iteratePage != null && collectPageResults;
1771
+ _state.label = 1;
1772
+ case 1:
1773
+ if (!keepGoing) return [
1774
+ 3,
1775
+ 4
1776
+ ];
1777
+ effectiveLimit = _computeEffectiveLimit(totalItemsLimit, limitPerPage, totalItems);
1778
+ data = buildRequestData(params, {
1779
+ pageIndex: pageIndex,
1780
+ cursorDocumentKey: cursorDocumentKey,
1781
+ visitedItems: totalItems
1782
+ }, effectiveLimit);
1783
+ return [
1784
+ 4,
1785
+ context.callModel({
1786
+ modelType: modelType,
1787
+ call: call,
1788
+ specifier: specifier,
1789
+ data: data
1790
+ })
1791
+ ];
1792
+ case 2:
1793
+ raw = _state.sent();
1794
+ return [
1795
+ 4,
1796
+ _processPage({
1797
+ context: context,
1798
+ raw: raw,
1799
+ pageIndex: pageIndex,
1800
+ responseAdapter: responseAdapter,
1801
+ iterateItem: iterateItem,
1802
+ iteratePage: iteratePage,
1803
+ itemPerformTasksConfig: itemPerformTasksConfig,
1804
+ maxParallelPerPage: maxParallelPerPage
1805
+ })
1806
+ ];
1807
+ case 3:
1808
+ pageOutcome = _state.sent();
1809
+ if (collectItemsForPage) {
1810
+ (_allItems = allItems).push.apply(_allItems, _to_consumable_array$6(pageOutcome.items));
1811
+ }
1812
+ if (collectItemResultsForPage && pageOutcome.itemResults) {
1813
+ (_allItemResults = allItemResults).push.apply(_allItemResults, _to_consumable_array$6(pageOutcome.itemResults));
1814
+ }
1815
+ if (collectPageResultsForPage && pageOutcome.pageResult !== undefined) {
1816
+ allPageResults.push(pageOutcome.pageResult);
1817
+ }
1818
+ totalItems += pageOutcome.items.length;
1819
+ cursorDocumentKey = pageOutcome.nextCursorDocumentKey;
1820
+ pageIndex += 1;
1821
+ exit = _evaluateLoopExit({
1822
+ totalItemsLimit: totalItemsLimit,
1823
+ maxPages: maxPages,
1824
+ totalItems: totalItems,
1825
+ pageIndex: pageIndex,
1826
+ hasMore: pageOutcome.hasMore,
1827
+ cursorDocumentKey: cursorDocumentKey
1828
+ });
1829
+ hitLimit = exit.hitLimit;
1830
+ keepGoing = !exit.stop;
1831
+ return [
1832
+ 3,
1833
+ 1
1834
+ ];
1835
+ case 4:
1836
+ result = _object_spread$c({
1837
+ totalPages: pageIndex,
1838
+ totalItems: totalItems,
1839
+ hitLimit: hitLimit,
1840
+ lastCursorDocumentKey: cursorDocumentKey
1841
+ }, collectItemsForPage ? {
1842
+ items: allItems
1843
+ } : {}, collectItemResultsForPage ? {
1844
+ itemResults: allItemResults
1845
+ } : {}, collectPageResultsForPage ? {
1846
+ pageResults: allPageResults
1847
+ } : {});
1848
+ return [
1849
+ 2,
1850
+ result
1851
+ ];
1852
+ }
1853
+ });
1854
+ })();
915
1855
  }
916
1856
 
917
1857
  function asyncGeneratorStep$g(gen, resolve, reject, _next, _throw, key, arg) {
@@ -1524,7 +2464,7 @@ function _ts_generator$f(thisArg, body) {
1524
2464
  }
1525
2465
  };
1526
2466
 
1527
- function _array_like_to_array$7(arr, len) {
2467
+ function _array_like_to_array$8(arr, len) {
1528
2468
  if (len == null || len > arr.length) len = arr.length;
1529
2469
  for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
1530
2470
  return arr2;
@@ -1568,19 +2508,19 @@ function _non_iterable_rest$4() {
1568
2508
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1569
2509
  }
1570
2510
  function _sliced_to_array$4(arr, i) {
1571
- return _array_with_holes$4(arr) || _iterable_to_array_limit$4(arr, i) || _unsupported_iterable_to_array$7(arr, i) || _non_iterable_rest$4();
2511
+ return _array_with_holes$4(arr) || _iterable_to_array_limit$4(arr, i) || _unsupported_iterable_to_array$8(arr, i) || _non_iterable_rest$4();
1572
2512
  }
1573
2513
  function _type_of$1(obj) {
1574
2514
  "@swc/helpers - typeof";
1575
2515
  return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
1576
2516
  }
1577
- function _unsupported_iterable_to_array$7(o, minLen) {
2517
+ function _unsupported_iterable_to_array$8(o, minLen) {
1578
2518
  if (!o) return;
1579
- if (typeof o === "string") return _array_like_to_array$7(o, minLen);
2519
+ if (typeof o === "string") return _array_like_to_array$8(o, minLen);
1580
2520
  var n = Object.prototype.toString.call(o).slice(8, -1);
1581
2521
  if (n === "Object" && o.constructor) n = o.constructor.name;
1582
2522
  if (n === "Map" || n === "Set") return Array.from(n);
1583
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$7(o, minLen);
2523
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$8(o, minLen);
1584
2524
  }
1585
2525
  /**
1586
2526
  * Resolves the manifest entry for `modelType`. Lookup tries
@@ -1719,6 +2659,31 @@ function isPlainObject(value) {
1719
2659
  return proto === Object.prototype || proto === null;
1720
2660
  }
1721
2661
 
2662
+ function _array_like_to_array$7(arr, len) {
2663
+ if (len == null || len > arr.length) len = arr.length;
2664
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
2665
+ return arr2;
2666
+ }
2667
+ function _array_without_holes$5(arr) {
2668
+ if (Array.isArray(arr)) return _array_like_to_array$7(arr);
2669
+ }
2670
+ function _iterable_to_array$5(iter) {
2671
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
2672
+ }
2673
+ function _non_iterable_spread$5() {
2674
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
2675
+ }
2676
+ function _to_consumable_array$5(arr) {
2677
+ return _array_without_holes$5(arr) || _iterable_to_array$5(arr) || _unsupported_iterable_to_array$7(arr) || _non_iterable_spread$5();
2678
+ }
2679
+ function _unsupported_iterable_to_array$7(o, minLen) {
2680
+ if (!o) return;
2681
+ if (typeof o === "string") return _array_like_to_array$7(o, minLen);
2682
+ var n = Object.prototype.toString.call(o).slice(8, -1);
2683
+ if (n === "Object" && o.constructor) n = o.constructor.name;
2684
+ if (n === "Map" || n === "Set") return Array.from(n);
2685
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$7(o, minLen);
2686
+ }
1722
2687
  /**
1723
2688
  * Default command name for the model-decode command. Top-level so it stays
1724
2689
  * out of the API-call namespace owned by `model <model> <action>`.
@@ -1811,7 +2776,7 @@ function runHandler$1(manifest, argv) {
1811
2776
  }
1812
2777
  decoded.push(toSegment(prefix, id, entry));
1813
2778
  }
1814
- var leaf = decoded[decoded.length - 1];
2779
+ var leaf = decoded.at(-1);
1815
2780
  var ancestors = decoded.slice(0, -1);
1816
2781
  return {
1817
2782
  key: trimmed,
@@ -1848,59 +2813,48 @@ function toSegment(prefix, id, entry) {
1848
2813
  * @returns the formatted block with a trailing newline.
1849
2814
  * @__NO_SIDE_EFFECTS__
1850
2815
  */ function renderDecodedKey(decoded) {
1851
- var lines = [];
1852
- var leaf = decoded.leaf;
1853
- if (leaf.modelName) {
1854
- lines.push("Model: ".concat(leaf.modelName));
1855
- if (leaf.identityConst) lines.push("identityConst: ".concat(leaf.identityConst));
1856
- if (leaf.modelType) lines.push("modelType: ".concat(leaf.modelType));
1857
- lines.push("prefix: ".concat(leaf.prefix));
1858
- lines.push("id: ".concat(leaf.id));
1859
- if (leaf.modelGroup) lines.push("modelGroup: ".concat(leaf.modelGroup));
1860
- if (leaf.parentIdentityConst) lines.push("parentIdentityConst: ".concat(leaf.parentIdentityConst));
1861
- if (leaf.sourcePackage) {
1862
- var sourceSuffix = leaf.sourceFile ? " (".concat(leaf.sourceFile, ")") : '';
1863
- lines.push("source: ".concat(leaf.sourcePackage).concat(sourceSuffix));
1864
- }
1865
- } else {
1866
- lines.push("Model: <unknown — prefix '".concat(leaf.prefix, "' not in manifest>"));
1867
- lines.push("prefix: ".concat(leaf.prefix));
1868
- lines.push("id: ".concat(leaf.id));
1869
- }
2816
+ var lines = _to_consumable_array$5(renderLeafLines(decoded.leaf));
1870
2817
  if (decoded.ancestors.length > 0) {
1871
- lines.push('');
1872
- lines.push('Parent chain:');
1873
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1874
- try {
1875
- for(var _iterator = decoded.ancestors[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1876
- var ancestor = _step.value;
1877
- if (ancestor.modelName) {
1878
- lines.push("- ".concat(ancestor.modelName, " — prefix ").concat(ancestor.prefix, ", id ").concat(ancestor.id));
1879
- } else {
1880
- lines.push("- <unknown> — prefix ".concat(ancestor.prefix, ", id ").concat(ancestor.id));
1881
- }
1882
- }
1883
- } catch (err) {
1884
- _didIteratorError = true;
1885
- _iteratorError = err;
1886
- } finally{
1887
- try {
1888
- if (!_iteratorNormalCompletion && _iterator.return != null) {
1889
- _iterator.return();
1890
- }
1891
- } finally{
1892
- if (_didIteratorError) {
1893
- throw _iteratorError;
1894
- }
1895
- }
1896
- }
2818
+ var _lines;
2819
+ (_lines = lines).push.apply(_lines, [
2820
+ '',
2821
+ 'Parent chain:'
2822
+ ].concat(_to_consumable_array$5(decoded.ancestors.map(renderAncestorLine))));
1897
2823
  }
1898
2824
  if (decoded.unresolvedPrefixes.length > 0) {
1899
- lines.push('');
1900
- lines.push("Unresolved prefix".concat(decoded.unresolvedPrefixes.length === 1 ? '' : 'es', ": ").concat(decoded.unresolvedPrefixes.join(', '), ". Run `model-info` to list known models."));
2825
+ var suffix = decoded.unresolvedPrefixes.length === 1 ? '' : 'es';
2826
+ lines.push('', "Unresolved prefix".concat(suffix, ": ").concat(decoded.unresolvedPrefixes.join(', '), ". Run `model-info` to list known models."));
1901
2827
  }
1902
2828
  return lines.join('\n') + '\n';
1903
2829
  }
2830
+ function renderLeafLines(leaf) {
2831
+ if (!leaf.modelName) {
2832
+ return [
2833
+ "Model: <unknown — prefix '".concat(leaf.prefix, "' not in manifest>"),
2834
+ "prefix: ".concat(leaf.prefix),
2835
+ "id: ".concat(leaf.id)
2836
+ ];
2837
+ }
2838
+ var lines = [
2839
+ "Model: ".concat(leaf.modelName)
2840
+ ];
2841
+ if (leaf.identityConst) lines.push("identityConst: ".concat(leaf.identityConst));
2842
+ if (leaf.modelType) lines.push("modelType: ".concat(leaf.modelType));
2843
+ lines.push("prefix: ".concat(leaf.prefix), "id: ".concat(leaf.id));
2844
+ if (leaf.modelGroup) lines.push("modelGroup: ".concat(leaf.modelGroup));
2845
+ if (leaf.parentIdentityConst) lines.push("parentIdentityConst: ".concat(leaf.parentIdentityConst));
2846
+ if (leaf.sourcePackage) {
2847
+ var sourceSuffix = leaf.sourceFile ? " (".concat(leaf.sourceFile, ")") : '';
2848
+ lines.push("source: ".concat(leaf.sourcePackage).concat(sourceSuffix));
2849
+ }
2850
+ return lines;
2851
+ }
2852
+ function renderAncestorLine(ancestor) {
2853
+ if (ancestor.modelName) {
2854
+ return "- ".concat(ancestor.modelName, " — prefix ").concat(ancestor.prefix, ", id ").concat(ancestor.id);
2855
+ }
2856
+ return "- <unknown> — prefix ".concat(ancestor.prefix, ", id ").concat(ancestor.id);
2857
+ }
1904
2858
 
1905
2859
  function _array_like_to_array$6(arr, len) {
1906
2860
  if (len == null || len > arr.length) len = arr.length;
@@ -2123,7 +3077,7 @@ function inferModelTypeFromKeys(keys, manifest) {
2123
3077
  function manifestPrefixList(manifest) {
2124
3078
  var prefixes = manifest.map(function(e) {
2125
3079
  return e.collectionPrefix;
2126
- }).sort();
3080
+ }).sort(util.compareStrings);
2127
3081
  return prefixes.join(', ');
2128
3082
  }
2129
3083
 
@@ -6640,20 +7594,18 @@ function _unsupported_iterable_to_array$2(o, minLen) {
6640
7594
  * @returns the formatted summary as a single string with a trailing newline.
6641
7595
  * @__NO_SIDE_EFFECTS__
6642
7596
  */ function renderModelManifestEntry(entry) {
6643
- var lines = [];
6644
- lines.push("# ".concat(entry.modelType) + (entry.modelGroup ? " \xb7 group ".concat(entry.modelGroup) : ''));
6645
- lines.push("Identity: ".concat(entry.identityConst));
6646
- lines.push("Collection prefix: ".concat(entry.collectionPrefix));
7597
+ var groupSuffix = entry.modelGroup ? " \xb7 group ".concat(entry.modelGroup) : '';
7598
+ var lines = [
7599
+ "# ".concat(entry.modelType).concat(groupSuffix),
7600
+ "Identity: ".concat(entry.identityConst),
7601
+ "Collection prefix: ".concat(entry.collectionPrefix)
7602
+ ];
6647
7603
  if (entry.parentIdentityConst) lines.push("Parent identity: ".concat(entry.parentIdentityConst));
6648
- lines.push("Source package: ".concat(entry.sourcePackage));
6649
- lines.push("Source file: ".concat(entry.sourceFile));
7604
+ lines.push("Source package: ".concat(entry.sourcePackage), "Source file: ".concat(entry.sourceFile));
6650
7605
  if (entry.description) {
6651
- lines.push('');
6652
- lines.push(entry.description);
7606
+ lines.push('', entry.description);
6653
7607
  }
6654
- lines.push('');
6655
- lines.push("Fields (".concat(entry.fields.length, "):"));
6656
- lines.push(renderFieldsTree(entry.fields, 0));
7608
+ lines.push('', "Fields (".concat(entry.fields.length, "):"), renderFieldsTree(entry.fields, 0));
6657
7609
  return lines.join('\n') + '\n';
6658
7610
  }
6659
7611
  /**
@@ -6667,10 +7619,18 @@ function _unsupported_iterable_to_array$2(o, minLen) {
6667
7619
  return renderFieldsTree(entry.fields, 0) + '\n';
6668
7620
  }
6669
7621
  function renderFieldsTree(fields, indent) {
6670
- var out = [];
6671
7622
  var includeConverter = fields.some(function(f) {
6672
7623
  return f.converter !== undefined;
6673
7624
  });
7625
+ var tableBlock = indentLines$1(renderTable(buildFieldsTableRows(fields, includeConverter)), indent);
7626
+ var nestedBlocks = fields.flatMap(function(field) {
7627
+ return renderNestedFieldBlock(field, indent);
7628
+ });
7629
+ return [
7630
+ tableBlock
7631
+ ].concat(_to_consumable_array$2(nestedBlocks)).join('\n');
7632
+ }
7633
+ function buildFieldsTableRows(fields, includeConverter) {
6674
7634
  var header = includeConverter ? [
6675
7635
  'NAME',
6676
7636
  'LONG NAME',
@@ -6683,63 +7643,34 @@ function renderFieldsTree(fields, indent) {
6683
7643
  'TYPE',
6684
7644
  'OPTIONAL'
6685
7645
  ];
6686
- var rows = [
7646
+ return [
6687
7647
  header
7648
+ ].concat(_to_consumable_array$2(fields.map(function(field) {
7649
+ return buildFieldRow(field, includeConverter);
7650
+ })));
7651
+ }
7652
+ function buildFieldRow(field, includeConverter) {
7653
+ var _field_tsType;
7654
+ var row = [
7655
+ field.name,
7656
+ field.longName,
7657
+ (_field_tsType = field.tsType) !== null && _field_tsType !== void 0 ? _field_tsType : '',
7658
+ field.optional ? 'yes' : 'no'
6688
7659
  ];
6689
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
6690
- try {
6691
- for(var _iterator = fields[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
6692
- var field = _step.value;
6693
- var _field_tsType;
6694
- var row = [
6695
- field.name,
6696
- field.longName,
6697
- (_field_tsType = field.tsType) !== null && _field_tsType !== void 0 ? _field_tsType : '',
6698
- field.optional ? 'yes' : 'no'
6699
- ];
6700
- if (includeConverter) row.push(field.converter ? truncate(field.converter, 60) : '');
6701
- rows.push(row);
6702
- }
6703
- } catch (err) {
6704
- _didIteratorError = true;
6705
- _iteratorError = err;
6706
- } finally{
6707
- try {
6708
- if (!_iteratorNormalCompletion && _iterator.return != null) {
6709
- _iterator.return();
6710
- }
6711
- } finally{
6712
- if (_didIteratorError) {
6713
- throw _iteratorError;
6714
- }
6715
- }
6716
- }
6717
- out.push(indentLines$1(renderTable(rows), indent));
6718
- var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
6719
- try {
6720
- for(var _iterator1 = fields[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
6721
- var field1 = _step1.value;
6722
- if (field1.nestedFields && field1.nestedFields.length > 0) {
6723
- var label = field1.nestedIsArray ? 'array element' : 'sub-object';
6724
- out.push(indentLines$1("↳ ".concat(field1.name, " (").concat(label, ", ").concat(field1.nestedFields.length, " field").concat(field1.nestedFields.length === 1 ? '' : 's', ")"), indent + 2));
6725
- out.push(renderFieldsTree(field1.nestedFields, indent + 4));
6726
- }
6727
- }
6728
- } catch (err) {
6729
- _didIteratorError1 = true;
6730
- _iteratorError1 = err;
6731
- } finally{
6732
- try {
6733
- if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
6734
- _iterator1.return();
6735
- }
6736
- } finally{
6737
- if (_didIteratorError1) {
6738
- throw _iteratorError1;
6739
- }
6740
- }
7660
+ if (includeConverter) {
7661
+ row.push(field.converter ? truncate(field.converter, 60) : '');
6741
7662
  }
6742
- return out.join('\n');
7663
+ return row;
7664
+ }
7665
+ function renderNestedFieldBlock(field, indent) {
7666
+ var nested = field.nestedFields;
7667
+ if (!nested || nested.length === 0) return [];
7668
+ var label = field.nestedIsArray ? 'array element' : 'sub-object';
7669
+ var plural = nested.length === 1 ? '' : 's';
7670
+ return [
7671
+ indentLines$1("↳ ".concat(field.name, " (").concat(label, ", ").concat(nested.length, " field").concat(plural, ")"), indent + 2),
7672
+ renderFieldsTree(nested, indent + 4)
7673
+ ];
6743
7674
  }
6744
7675
  function renderTable(rows) {
6745
7676
  if (rows.length === 0) return '';
@@ -7202,6 +8133,21 @@ function _ts_generator$6(thisArg, body) {
7202
8133
  })();
7203
8134
  };
7204
8135
  }
8136
+ /**
8137
+ * Test-only middleware that skips OIDC discovery, disk token loading, and token refresh, attaching
8138
+ * a pre-built {@link CliContext} directly via {@link setCliContext}.
8139
+ *
8140
+ * @internal Intended for use by `@dereekb/dbx-cli/test`. Not for production wiring.
8141
+ *
8142
+ * @param input - The pre-built context to attach on every invocation.
8143
+ * @param input.cliContext - The {@link CliContext} that will be attached via {@link setCliContext}.
8144
+ * @returns A yargs middleware function that always sets the provided context.
8145
+ * @__NO_SIDE_EFFECTS__
8146
+ */ function createPassthroughAuthMiddleware(input) {
8147
+ return function() {
8148
+ setCliContext(input.cliContext);
8149
+ };
8150
+ }
7205
8151
 
7206
8152
  function asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, key, arg) {
7207
8153
  try {
@@ -8302,7 +9248,7 @@ function _ts_generator$2(thisArg, body) {
8302
9248
  * @returns The configured yargs `Argv` ready to be `.parse()`-d.
8303
9249
  * @__NO_SIDE_EFFECTS__
8304
9250
  */ function createCli(input) {
8305
- var _input_configCommands, _input_apiCommands, _input_argv;
9251
+ var _input_configCommands, _input_actionCommands, _input_apiCommands, _input_argv;
8306
9252
  var cliName = input.cliName;
8307
9253
  var defaultEnvs = input.defaultEnvs;
8308
9254
  var builtInConfigCommands = [
@@ -8336,10 +9282,19 @@ function _ts_generator$2(thisArg, body) {
8336
9282
  if (input.disableModelGet !== true) {
8337
9283
  builtInApiCommands.push(getCommand, getManyCommand);
8338
9284
  }
8339
- var allApiCommands = _to_consumable_array$1(builtInApiCommands).concat(_to_consumable_array$1((_input_apiCommands = input.apiCommands) !== null && _input_apiCommands !== void 0 ? _input_apiCommands : []));
9285
+ var actionCommands = buildActionCommands((_input_actionCommands = input.actionCommands) !== null && _input_actionCommands !== void 0 ? _input_actionCommands : []);
9286
+ 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));
8340
9287
  var skipCommandNames = new Set(allConfigCommands.map(function(c) {
8341
9288
  return commandName(c);
8342
9289
  }));
9290
+ var authMiddleware = input.testCliContext ? createPassthroughAuthMiddleware({
9291
+ cliContext: input.testCliContext
9292
+ }) : createAuthMiddleware({
9293
+ cliName: cliName,
9294
+ skipCommands: skipCommandNames,
9295
+ defaultEnvs: defaultEnvs,
9296
+ modelManifest: input.modelManifest
9297
+ });
8343
9298
  return yargs((_input_argv = input.argv) !== null && _input_argv !== void 0 ? _input_argv : helpers.hideBin(process.argv)).scriptName(cliName).usage('$0 <command> [options]').option('verbose', {
8344
9299
  alias: 'v',
8345
9300
  type: 'boolean',
@@ -8384,12 +9339,7 @@ function _ts_generator$2(thisArg, body) {
8384
9339
  global: true,
8385
9340
  describe: 'Show the full options table in --help even when --data-help is in focus mode'
8386
9341
  }).middleware([
8387
- createAuthMiddleware({
8388
- cliName: cliName,
8389
- skipCommands: skipCommandNames,
8390
- defaultEnvs: defaultEnvs,
8391
- modelManifest: input.modelManifest
8392
- }),
9342
+ authMiddleware,
8393
9343
  createOutputMiddleware({
8394
9344
  cliName: cliName,
8395
9345
  skipCommands: skipCommandNames
@@ -8940,7 +9890,7 @@ function buildModelCommand(model, entries, context) {
8940
9890
  }
8941
9891
  }
8942
9892
  }
8943
- yargs.command(buildPerModelGetCommand(model));
9893
+ yargs.command(buildPerModelGetCommand(model, context.modelManifest));
8944
9894
  hideGlobalOptions(yargs, context.hideOnFocus);
8945
9895
  return yargs.demandCommand(1, 'Please specify an action.');
8946
9896
  },
@@ -8950,24 +9900,86 @@ function buildModelCommand(model, entries, context) {
8950
9900
  };
8951
9901
  }
8952
9902
  /**
8953
- * Synthetic per-model `get <key>` sub-command appended to every model's command tree.
9903
+ * Resolves a per-model `get` positional into the full Firestore key the backend expects.
9904
+ *
9905
+ * The backend's `ModelApiController.getOne` only accepts full `prefix/id` keys, so a bare doc id
9906
+ * has to be expanded before the HTTP call. The expansion is only safe for top-level (root) models
9907
+ * whose `collectionPrefix` is enough to address the document — subcollection models also need the
9908
+ * parent prefix/id and cannot be reconstructed from a bare id alone.
8954
9909
  *
8955
- * The parent `model <name>` already fixes the `modelType`, so this command just passes the bare
8956
- * `key` positional through to `context.getModel(modelType, key)`. Supports both the full
8957
- * `<prefix>/<id>` form and a bare doc id (when the user knows the modelType from the parent).
8958
- */ function buildPerModelGetCommand(model) {
9910
+ * Rules:
9911
+ * 1. Keys containing `/` are treated as full keys and passed through verbatim.
9912
+ * 2. Bare ids on a top-level model resolve to `<collectionPrefix>/<id>` via the manifest.
9913
+ * 3. Bare ids on a subcollection model throw — the parent path is required.
9914
+ * 4. When the manifest is not wired, bare ids pass through unchanged (preserves the old behavior
9915
+ * so the CLI still works without `modelManifest` even though the backend will reject the call).
9916
+ *
9917
+ * @param model - The persisted model type (e.g. `profile`).
9918
+ * @param key - The trimmed `<key>` positional from yargs — full `prefix/id` or bare doc id.
9919
+ * @param manifest - The generated model manifest used to look up the model's `collectionPrefix`
9920
+ * and `parentIdentityConst`. When omitted, the key passes through unchanged.
9921
+ * @returns The resolved Firestore model key ready for `context.getModel(model, key)`.
9922
+ * @__NO_SIDE_EFFECTS__
9923
+ */ function resolvePerModelGetKey(model, key, manifest) {
9924
+ var result = key;
9925
+ if (!key.includes('/')) {
9926
+ var entry = manifest === null || manifest === void 0 ? void 0 : manifest.find(function(e) {
9927
+ return e.modelType === model;
9928
+ });
9929
+ if (entry) {
9930
+ if (entry.parentIdentityConst) {
9931
+ throw new CliError({
9932
+ message: "get: model '".concat(model, "' is a subcollection — bare doc id '").concat(key, "' is ambiguous without the parent path. Provide a full key (e.g. '<parentPrefix>/<parentId>/").concat(entry.collectionPrefix, "/").concat(key, "')."),
9933
+ code: 'INVALID_ARGUMENT'
9934
+ });
9935
+ }
9936
+ result = "".concat(entry.collectionPrefix, "/").concat(key);
9937
+ }
9938
+ }
9939
+ return result;
9940
+ }
9941
+ /**
9942
+ * Synthetic per-model `get` sub-command appended to every model's command tree.
9943
+ *
9944
+ * The parent `model <name>` already fixes the `modelType`. The command shape varies by whether
9945
+ * the model is root-level (no parent) or a subcollection — only root models can address documents
9946
+ * by bare doc id, so subcollection models keep the `<key>` positional (full `prefix/id` required):
9947
+ *
9948
+ * - **Root model with a wired manifest entry** — `get <id-or-key>` accepts either a bare doc id
9949
+ * (expanded to `<collectionPrefix>/<id>` via {@link resolvePerModelGetKey}) or a full
9950
+ * `<prefix>/<id>` key.
9951
+ * - **Subcollection model with a wired manifest entry** — `get <key>` requires the full
9952
+ * `<parentPrefix>/<parentId>/<childPrefix>/<childId>` path. Bare doc ids are rejected with a
9953
+ * clear error because the parent path cannot be reconstructed from the id alone.
9954
+ * - **No wired model manifest** — falls back to `get <key>`; the key is forwarded verbatim and
9955
+ * the backend will reject anything that is not a full `prefix/id` key.
9956
+ *
9957
+ * @param model - The persisted model type owning this `get` subcommand.
9958
+ * @param manifest - The generated model manifest used by {@link resolvePerModelGetKey} to expand
9959
+ * bare doc ids into full keys for top-level models and to pick the command shape.
9960
+ * @returns The yargs `CommandModule` registered under the model's command tree.
9961
+ */ function buildPerModelGetCommand(model, manifest) {
9962
+ var entry = manifest === null || manifest === void 0 ? void 0 : manifest.find(function(e) {
9963
+ return e.modelType === model;
9964
+ });
9965
+ var isRootModel = entry != null && !entry.parentIdentityConst;
9966
+ var positionalName = isRootModel ? 'idOrKey' : 'key';
9967
+ var placeholder = isRootModel ? '<id-or-key>' : '<key>';
9968
+ var subcollectionNote = entry ? ' for this subcollection model' : '';
9969
+ var positionalDescribe = isRootModel ? "Firestore key for the ".concat(model, " document — bare doc id (resolved to `").concat(entry.collectionPrefix, "/<id>`) or full `prefix/id`.") : "Firestore key for the ".concat(model, " document (full `prefix/id` — bare doc id is not supported").concat(subcollectionNote, ").");
9970
+ var commandDescribe = isRootModel ? "Read a single ".concat(model, " document by id or key.") : "Read a single ".concat(model, " document by key.");
8959
9971
  return {
8960
- command: 'get <key>',
8961
- describe: "Read a single ".concat(model, " document by key."),
9972
+ command: "get ".concat(placeholder),
9973
+ describe: commandDescribe,
8962
9974
  builder: function builder(yargs) {
8963
- return yargs.positional('key', {
9975
+ return yargs.positional(positionalName, {
8964
9976
  type: 'string',
8965
- describe: "Firestore key for the ".concat(model, " document (full `prefix/id` or bare id).")
9977
+ describe: positionalDescribe
8966
9978
  });
8967
9979
  },
8968
9980
  handler: function handler(argv) {
8969
9981
  return _async_to_generator$1(function() {
8970
- var ctx, key, result, e;
9982
+ var ctx, raw, key, resolvedKey, result, e;
8971
9983
  return _ts_generator$1(this, function(_state) {
8972
9984
  switch(_state.label){
8973
9985
  case 0:
@@ -8978,16 +9990,18 @@ function buildModelCommand(model, entries, context) {
8978
9990
  3
8979
9991
  ]);
8980
9992
  ctx = requireCliContext();
8981
- key = typeof argv.key === 'string' ? argv.key.trim() : '';
9993
+ raw = argv[positionalName];
9994
+ key = typeof raw === 'string' ? raw.trim() : '';
8982
9995
  if (key.length === 0) {
8983
9996
  throw new CliError({
8984
- message: "get: missing required <key> positional for model '".concat(model, "'."),
9997
+ message: "get: missing required ".concat(placeholder, " positional for model '").concat(model, "'."),
8985
9998
  code: 'INVALID_ARGUMENT'
8986
9999
  });
8987
10000
  }
10001
+ resolvedKey = resolvePerModelGetKey(model, key, manifest);
8988
10002
  return [
8989
10003
  4,
8990
- ctx.getModel(model, key)
10004
+ ctx.getModel(model, resolvedKey)
8991
10005
  ];
8992
10006
  case 1:
8993
10007
  result = _state.sent();
@@ -9176,8 +10190,7 @@ function buildParamsSection(entry) {
9176
10190
  lines.push(indentLines(entry.paramsTypeDescription, ' '));
9177
10191
  }
9178
10192
  if (entry.paramsFields && entry.paramsFields.length > 0) {
9179
- lines.push('');
9180
- lines.push('Fields:');
10193
+ lines.push('', 'Fields:');
9181
10194
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
9182
10195
  try {
9183
10196
  for(var _iterator = entry.paramsFields[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
@@ -9217,8 +10230,7 @@ function buildResultSection(entry) {
9217
10230
  lines.push(indentLines(entry.resultTypeDescription, ' '));
9218
10231
  }
9219
10232
  if (entry.resultFields && entry.resultFields.length > 0) {
9220
- lines.push('');
9221
- lines.push('Fields:');
10233
+ lines.push('', 'Fields:');
9222
10234
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
9223
10235
  try {
9224
10236
  for(var _iterator = entry.resultFields[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
@@ -9314,6 +10326,7 @@ function renderJsonSchemaSection(entry) {
9314
10326
  // method that emits the bare JSON Schema value, e.g. `false`). Round-trip
9315
10327
  // through JSON to invoke those `toJSON()` callbacks before pruning;
9316
10328
  // `structuredClone` would not call them.
10329
+ // NOSONAR (typescript:S7784): structuredClone bypasses toJSON()
9317
10330
  var normalized = JSON.parse(JSON.stringify(raw));
9318
10331
  var pruned = pruneFalseUnionBranches(normalized);
9319
10332
  result = "Params Schema (JSON Schema):\n".concat(JSON.stringify(pruned, null, 2));
@@ -9961,6 +10974,7 @@ Object.defineProperty(exports, "CALL_MODEL_APP_FUNCTION_KEY", {
9961
10974
  });
9962
10975
  exports.CALL_MODEL_API_PATH = CALL_MODEL_API_PATH;
9963
10976
  exports.CliError = CliError;
10977
+ exports.DEFAULT_ACTION_COMMAND_NAME = DEFAULT_ACTION_COMMAND_NAME;
9964
10978
  exports.DEFAULT_CLI_OIDC_SCOPES = DEFAULT_CLI_OIDC_SCOPES;
9965
10979
  exports.DEFAULT_CLI_REDIRECT_URI = DEFAULT_CLI_REDIRECT_URI;
9966
10980
  exports.DEFAULT_CLI_SECRET_PATTERNS = DEFAULT_CLI_SECRET_PATTERNS;
@@ -9977,6 +10991,7 @@ exports.MULTIPLE_PAGES_OUTPUT_MODES = MULTIPLE_PAGES_OUTPUT_MODES;
9977
10991
  exports.PROMPT_CANCELLED_ERROR_CODE = PROMPT_CANCELLED_ERROR_CODE;
9978
10992
  exports.STANDARD_GLOBAL_OPTION_NAMES = STANDARD_GLOBAL_OPTION_NAMES;
9979
10993
  exports.applyEnvVarOverrides = applyEnvVarOverrides;
10994
+ exports.buildActionCommands = buildActionCommands;
9980
10995
  exports.buildAuthorizationUrl = buildAuthorizationUrl;
9981
10996
  exports.buildCliPaths = buildCliPaths;
9982
10997
  exports.buildDumpFilePath = buildDumpFilePath;
@@ -9990,6 +11005,7 @@ exports.callPassthroughCommand = callPassthroughCommand;
9990
11005
  exports.configureCliErrorMapper = configureCliErrorMapper;
9991
11006
  exports.configureCliSecretPatterns = configureCliSecretPatterns;
9992
11007
  exports.configureOutputOptions = configureOutputOptions;
11008
+ exports.createActionCommand = createActionCommand;
9993
11009
  exports.createAuthCommand = createAuthCommand;
9994
11010
  exports.createAuthMiddleware = createAuthMiddleware;
9995
11011
  exports.createCallModelCommand = createCallModelCommand;
@@ -10001,6 +11017,7 @@ exports.createDoctorCommand = createDoctorCommand;
10001
11017
  exports.createEnvCommand = createEnvCommand;
10002
11018
  exports.createOutputCommand = createOutputCommand;
10003
11019
  exports.createOutputMiddleware = createOutputMiddleware;
11020
+ exports.createPassthroughAuthMiddleware = createPassthroughAuthMiddleware;
10004
11021
  exports.decodeFirestoreModelKey = decodeFirestoreModelKey;
10005
11022
  exports.defaultDoctorChecks = defaultDoctorChecks;
10006
11023
  exports.detectDataHelpFormat = detectDataHelpFormat;
@@ -10023,6 +11040,7 @@ exports.getMultipleModelsOverHttp = getMultipleModelsOverHttp;
10023
11040
  exports.getOutputOptions = getOutputOptions;
10024
11041
  exports.isCliEnvConfigComplete = isCliEnvConfigComplete;
10025
11042
  exports.isTokenExpired = isTokenExpired;
11043
+ exports.iterateDbxCliCallModel = iterateDbxCliCallModel;
10026
11044
  exports.loadCliConfig = loadCliConfig;
10027
11045
  exports.maskSecret = maskSecret;
10028
11046
  exports.mergeCliConfig = mergeCliConfig;
@@ -10045,6 +11063,7 @@ exports.requireCliContext = requireCliContext;
10045
11063
  exports.resolveActiveEnvName = resolveActiveEnvName;
10046
11064
  exports.resolveCliModel = resolveCliModel;
10047
11065
  exports.resolveOutputConfig = resolveOutputConfig;
11066
+ exports.resolvePerModelGetKey = resolvePerModelGetKey;
10048
11067
  exports.revokeToken = revokeToken;
10049
11068
  exports.runCli = runCli;
10050
11069
  exports.runPaginatedList = runPaginatedList;