@specset/cli 0.5.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -118,17 +118,17 @@ var require_visit = __commonJS({
118
118
  visit.BREAK = BREAK;
119
119
  visit.SKIP = SKIP;
120
120
  visit.REMOVE = REMOVE;
121
- function visit_(key, node, visitor, path10) {
122
- const ctrl = callVisitor(key, node, visitor, path10);
121
+ function visit_(key, node, visitor, path12) {
122
+ const ctrl = callVisitor(key, node, visitor, path12);
123
123
  if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
124
- replaceNode(key, path10, ctrl);
125
- return visit_(key, ctrl, visitor, path10);
124
+ replaceNode(key, path12, ctrl);
125
+ return visit_(key, ctrl, visitor, path12);
126
126
  }
127
127
  if (typeof ctrl !== "symbol") {
128
128
  if (identity.isCollection(node)) {
129
- path10 = Object.freeze(path10.concat(node));
129
+ path12 = Object.freeze(path12.concat(node));
130
130
  for (let i2 = 0; i2 < node.items.length; ++i2) {
131
- const ci = visit_(i2, node.items[i2], visitor, path10);
131
+ const ci = visit_(i2, node.items[i2], visitor, path12);
132
132
  if (typeof ci === "number")
133
133
  i2 = ci - 1;
134
134
  else if (ci === BREAK)
@@ -139,13 +139,13 @@ var require_visit = __commonJS({
139
139
  }
140
140
  }
141
141
  } else if (identity.isPair(node)) {
142
- path10 = Object.freeze(path10.concat(node));
143
- const ck = visit_("key", node.key, visitor, path10);
142
+ path12 = Object.freeze(path12.concat(node));
143
+ const ck = visit_("key", node.key, visitor, path12);
144
144
  if (ck === BREAK)
145
145
  return BREAK;
146
146
  else if (ck === REMOVE)
147
147
  node.key = null;
148
- const cv = visit_("value", node.value, visitor, path10);
148
+ const cv = visit_("value", node.value, visitor, path12);
149
149
  if (cv === BREAK)
150
150
  return BREAK;
151
151
  else if (cv === REMOVE)
@@ -166,17 +166,17 @@ var require_visit = __commonJS({
166
166
  visitAsync.BREAK = BREAK;
167
167
  visitAsync.SKIP = SKIP;
168
168
  visitAsync.REMOVE = REMOVE;
169
- async function visitAsync_(key, node, visitor, path10) {
170
- const ctrl = await callVisitor(key, node, visitor, path10);
169
+ async function visitAsync_(key, node, visitor, path12) {
170
+ const ctrl = await callVisitor(key, node, visitor, path12);
171
171
  if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
172
- replaceNode(key, path10, ctrl);
173
- return visitAsync_(key, ctrl, visitor, path10);
172
+ replaceNode(key, path12, ctrl);
173
+ return visitAsync_(key, ctrl, visitor, path12);
174
174
  }
175
175
  if (typeof ctrl !== "symbol") {
176
176
  if (identity.isCollection(node)) {
177
- path10 = Object.freeze(path10.concat(node));
177
+ path12 = Object.freeze(path12.concat(node));
178
178
  for (let i2 = 0; i2 < node.items.length; ++i2) {
179
- const ci = await visitAsync_(i2, node.items[i2], visitor, path10);
179
+ const ci = await visitAsync_(i2, node.items[i2], visitor, path12);
180
180
  if (typeof ci === "number")
181
181
  i2 = ci - 1;
182
182
  else if (ci === BREAK)
@@ -187,13 +187,13 @@ var require_visit = __commonJS({
187
187
  }
188
188
  }
189
189
  } else if (identity.isPair(node)) {
190
- path10 = Object.freeze(path10.concat(node));
191
- const ck = await visitAsync_("key", node.key, visitor, path10);
190
+ path12 = Object.freeze(path12.concat(node));
191
+ const ck = await visitAsync_("key", node.key, visitor, path12);
192
192
  if (ck === BREAK)
193
193
  return BREAK;
194
194
  else if (ck === REMOVE)
195
195
  node.key = null;
196
- const cv = await visitAsync_("value", node.value, visitor, path10);
196
+ const cv = await visitAsync_("value", node.value, visitor, path12);
197
197
  if (cv === BREAK)
198
198
  return BREAK;
199
199
  else if (cv === REMOVE)
@@ -220,23 +220,23 @@ var require_visit = __commonJS({
220
220
  }
221
221
  return visitor;
222
222
  }
223
- function callVisitor(key, node, visitor, path10) {
223
+ function callVisitor(key, node, visitor, path12) {
224
224
  if (typeof visitor === "function")
225
- return visitor(key, node, path10);
225
+ return visitor(key, node, path12);
226
226
  if (identity.isMap(node))
227
- return visitor.Map?.(key, node, path10);
227
+ return visitor.Map?.(key, node, path12);
228
228
  if (identity.isSeq(node))
229
- return visitor.Seq?.(key, node, path10);
229
+ return visitor.Seq?.(key, node, path12);
230
230
  if (identity.isPair(node))
231
- return visitor.Pair?.(key, node, path10);
231
+ return visitor.Pair?.(key, node, path12);
232
232
  if (identity.isScalar(node))
233
- return visitor.Scalar?.(key, node, path10);
233
+ return visitor.Scalar?.(key, node, path12);
234
234
  if (identity.isAlias(node))
235
- return visitor.Alias?.(key, node, path10);
235
+ return visitor.Alias?.(key, node, path12);
236
236
  return void 0;
237
237
  }
238
- function replaceNode(key, path10, node) {
239
- const parent = path10[path10.length - 1];
238
+ function replaceNode(key, path12, node) {
239
+ const parent = path12[path12.length - 1];
240
240
  if (identity.isCollection(parent)) {
241
241
  parent.items[key] = node;
242
242
  } else if (identity.isPair(parent)) {
@@ -844,10 +844,10 @@ var require_Collection = __commonJS({
844
844
  var createNode = require_createNode();
845
845
  var identity = require_identity();
846
846
  var Node = require_Node();
847
- function collectionFromPath(schema, path10, value2) {
847
+ function collectionFromPath(schema, path12, value2) {
848
848
  let v = value2;
849
- for (let i2 = path10.length - 1; i2 >= 0; --i2) {
850
- const k = path10[i2];
849
+ for (let i2 = path12.length - 1; i2 >= 0; --i2) {
850
+ const k = path12[i2];
851
851
  if (typeof k === "number" && Number.isInteger(k) && k >= 0) {
852
852
  const a3 = [];
853
853
  a3[k] = v;
@@ -866,7 +866,7 @@ var require_Collection = __commonJS({
866
866
  sourceObjects: /* @__PURE__ */ new Map()
867
867
  });
868
868
  }
869
- var isEmptyPath = (path10) => path10 == null || typeof path10 === "object" && !!path10[Symbol.iterator]().next().done;
869
+ var isEmptyPath = (path12) => path12 == null || typeof path12 === "object" && !!path12[Symbol.iterator]().next().done;
870
870
  var Collection = class extends Node.NodeBase {
871
871
  constructor(type2, schema) {
872
872
  super(type2);
@@ -896,11 +896,11 @@ var require_Collection = __commonJS({
896
896
  * be a Pair instance or a `{ key, value }` object, which may not have a key
897
897
  * that already exists in the map.
898
898
  */
899
- addIn(path10, value2) {
900
- if (isEmptyPath(path10))
899
+ addIn(path12, value2) {
900
+ if (isEmptyPath(path12))
901
901
  this.add(value2);
902
902
  else {
903
- const [key, ...rest] = path10;
903
+ const [key, ...rest] = path12;
904
904
  const node = this.get(key, true);
905
905
  if (identity.isCollection(node))
906
906
  node.addIn(rest, value2);
@@ -914,8 +914,8 @@ var require_Collection = __commonJS({
914
914
  * Removes a value from the collection.
915
915
  * @returns `true` if the item was found and removed.
916
916
  */
917
- deleteIn(path10) {
918
- const [key, ...rest] = path10;
917
+ deleteIn(path12) {
918
+ const [key, ...rest] = path12;
919
919
  if (rest.length === 0)
920
920
  return this.delete(key);
921
921
  const node = this.get(key, true);
@@ -929,8 +929,8 @@ var require_Collection = __commonJS({
929
929
  * scalar values from their surrounding node; to disable set `keepScalar` to
930
930
  * `true` (collections are always returned intact).
931
931
  */
932
- getIn(path10, keepScalar) {
933
- const [key, ...rest] = path10;
932
+ getIn(path12, keepScalar) {
933
+ const [key, ...rest] = path12;
934
934
  const node = this.get(key, true);
935
935
  if (rest.length === 0)
936
936
  return !keepScalar && identity.isScalar(node) ? node.value : node;
@@ -948,8 +948,8 @@ var require_Collection = __commonJS({
948
948
  /**
949
949
  * Checks if the collection includes a value with the key `key`.
950
950
  */
951
- hasIn(path10) {
952
- const [key, ...rest] = path10;
951
+ hasIn(path12) {
952
+ const [key, ...rest] = path12;
953
953
  if (rest.length === 0)
954
954
  return this.has(key);
955
955
  const node = this.get(key, true);
@@ -959,8 +959,8 @@ var require_Collection = __commonJS({
959
959
  * Sets a value in this collection. For `!!set`, `value` needs to be a
960
960
  * boolean to add/remove the item from the set.
961
961
  */
962
- setIn(path10, value2) {
963
- const [key, ...rest] = path10;
962
+ setIn(path12, value2) {
963
+ const [key, ...rest] = path12;
964
964
  if (rest.length === 0) {
965
965
  this.set(key, value2);
966
966
  } else {
@@ -3472,9 +3472,9 @@ var require_Document = __commonJS({
3472
3472
  this.contents.add(value2);
3473
3473
  }
3474
3474
  /** Adds a value to the document. */
3475
- addIn(path10, value2) {
3475
+ addIn(path12, value2) {
3476
3476
  if (assertCollection(this.contents))
3477
- this.contents.addIn(path10, value2);
3477
+ this.contents.addIn(path12, value2);
3478
3478
  }
3479
3479
  /**
3480
3480
  * Create a new `Alias` node, ensuring that the target `node` has the required anchor.
@@ -3549,14 +3549,14 @@ var require_Document = __commonJS({
3549
3549
  * Removes a value from the document.
3550
3550
  * @returns `true` if the item was found and removed.
3551
3551
  */
3552
- deleteIn(path10) {
3553
- if (Collection.isEmptyPath(path10)) {
3552
+ deleteIn(path12) {
3553
+ if (Collection.isEmptyPath(path12)) {
3554
3554
  if (this.contents == null)
3555
3555
  return false;
3556
3556
  this.contents = null;
3557
3557
  return true;
3558
3558
  }
3559
- return assertCollection(this.contents) ? this.contents.deleteIn(path10) : false;
3559
+ return assertCollection(this.contents) ? this.contents.deleteIn(path12) : false;
3560
3560
  }
3561
3561
  /**
3562
3562
  * Returns item at `key`, or `undefined` if not found. By default unwraps
@@ -3571,10 +3571,10 @@ var require_Document = __commonJS({
3571
3571
  * scalar values from their surrounding node; to disable set `keepScalar` to
3572
3572
  * `true` (collections are always returned intact).
3573
3573
  */
3574
- getIn(path10, keepScalar) {
3575
- if (Collection.isEmptyPath(path10))
3574
+ getIn(path12, keepScalar) {
3575
+ if (Collection.isEmptyPath(path12))
3576
3576
  return !keepScalar && identity.isScalar(this.contents) ? this.contents.value : this.contents;
3577
- return identity.isCollection(this.contents) ? this.contents.getIn(path10, keepScalar) : void 0;
3577
+ return identity.isCollection(this.contents) ? this.contents.getIn(path12, keepScalar) : void 0;
3578
3578
  }
3579
3579
  /**
3580
3580
  * Checks if the document includes a value with the key `key`.
@@ -3585,10 +3585,10 @@ var require_Document = __commonJS({
3585
3585
  /**
3586
3586
  * Checks if the document includes a value at `path`.
3587
3587
  */
3588
- hasIn(path10) {
3589
- if (Collection.isEmptyPath(path10))
3588
+ hasIn(path12) {
3589
+ if (Collection.isEmptyPath(path12))
3590
3590
  return this.contents !== void 0;
3591
- return identity.isCollection(this.contents) ? this.contents.hasIn(path10) : false;
3591
+ return identity.isCollection(this.contents) ? this.contents.hasIn(path12) : false;
3592
3592
  }
3593
3593
  /**
3594
3594
  * Sets a value in this document. For `!!set`, `value` needs to be a
@@ -3605,13 +3605,13 @@ var require_Document = __commonJS({
3605
3605
  * Sets a value in this document. For `!!set`, `value` needs to be a
3606
3606
  * boolean to add/remove the item from the set.
3607
3607
  */
3608
- setIn(path10, value2) {
3609
- if (Collection.isEmptyPath(path10)) {
3608
+ setIn(path12, value2) {
3609
+ if (Collection.isEmptyPath(path12)) {
3610
3610
  this.contents = value2;
3611
3611
  } else if (this.contents == null) {
3612
- this.contents = Collection.collectionFromPath(this.schema, Array.from(path10), value2);
3612
+ this.contents = Collection.collectionFromPath(this.schema, Array.from(path12), value2);
3613
3613
  } else if (assertCollection(this.contents)) {
3614
- this.contents.setIn(path10, value2);
3614
+ this.contents.setIn(path12, value2);
3615
3615
  }
3616
3616
  }
3617
3617
  /**
@@ -5568,9 +5568,9 @@ var require_cst_visit = __commonJS({
5568
5568
  visit.BREAK = BREAK;
5569
5569
  visit.SKIP = SKIP;
5570
5570
  visit.REMOVE = REMOVE;
5571
- visit.itemAtPath = (cst, path10) => {
5571
+ visit.itemAtPath = (cst, path12) => {
5572
5572
  let item = cst;
5573
- for (const [field, index] of path10) {
5573
+ for (const [field, index] of path12) {
5574
5574
  const tok = item?.[field];
5575
5575
  if (tok && "items" in tok) {
5576
5576
  item = tok.items[index];
@@ -5579,23 +5579,23 @@ var require_cst_visit = __commonJS({
5579
5579
  }
5580
5580
  return item;
5581
5581
  };
5582
- visit.parentCollection = (cst, path10) => {
5583
- const parent = visit.itemAtPath(cst, path10.slice(0, -1));
5584
- const field = path10[path10.length - 1][0];
5582
+ visit.parentCollection = (cst, path12) => {
5583
+ const parent = visit.itemAtPath(cst, path12.slice(0, -1));
5584
+ const field = path12[path12.length - 1][0];
5585
5585
  const coll = parent?.[field];
5586
5586
  if (coll && "items" in coll)
5587
5587
  return coll;
5588
5588
  throw new Error("Parent collection not found");
5589
5589
  };
5590
- function _visit(path10, item, visitor) {
5591
- let ctrl = visitor(item, path10);
5590
+ function _visit(path12, item, visitor) {
5591
+ let ctrl = visitor(item, path12);
5592
5592
  if (typeof ctrl === "symbol")
5593
5593
  return ctrl;
5594
5594
  for (const field of ["key", "value"]) {
5595
5595
  const token = item[field];
5596
5596
  if (token && "items" in token) {
5597
5597
  for (let i2 = 0; i2 < token.items.length; ++i2) {
5598
- const ci = _visit(Object.freeze(path10.concat([[field, i2]])), token.items[i2], visitor);
5598
+ const ci = _visit(Object.freeze(path12.concat([[field, i2]])), token.items[i2], visitor);
5599
5599
  if (typeof ci === "number")
5600
5600
  i2 = ci - 1;
5601
5601
  else if (ci === BREAK)
@@ -5606,10 +5606,10 @@ var require_cst_visit = __commonJS({
5606
5606
  }
5607
5607
  }
5608
5608
  if (typeof ctrl === "function" && field === "key")
5609
- ctrl = ctrl(item, path10);
5609
+ ctrl = ctrl(item, path12);
5610
5610
  }
5611
5611
  }
5612
- return typeof ctrl === "function" ? ctrl(item, path10) : ctrl;
5612
+ return typeof ctrl === "function" ? ctrl(item, path12) : ctrl;
5613
5613
  }
5614
5614
  exports.visit = visit;
5615
5615
  }
@@ -7582,10 +7582,10 @@ var require_GraphQLError = __commonJS({
7582
7582
  */
7583
7583
  constructor(message, ...rawArgs) {
7584
7584
  var _this$nodes, _nodeLocations$, _ref;
7585
- const { nodes, source, positions, path: path10, originalError, extensions } = toNormalizedOptions(rawArgs);
7585
+ const { nodes, source, positions, path: path12, originalError, extensions } = toNormalizedOptions(rawArgs);
7586
7586
  super(message);
7587
7587
  this.name = "GraphQLError";
7588
- this.path = path10 !== null && path10 !== void 0 ? path10 : void 0;
7588
+ this.path = path12 !== null && path12 !== void 0 ? path12 : void 0;
7589
7589
  this.originalError = originalError !== null && originalError !== void 0 ? originalError : void 0;
7590
7590
  this.nodes = undefinedIfEmpty(
7591
7591
  Array.isArray(nodes) ? nodes : nodes ? [nodes] : void 0
@@ -10805,14 +10805,14 @@ var require_visitor = __commonJS({
10805
10805
  let node = root2;
10806
10806
  let key = void 0;
10807
10807
  let parent = void 0;
10808
- const path10 = [];
10808
+ const path12 = [];
10809
10809
  const ancestors = [];
10810
10810
  do {
10811
10811
  index++;
10812
10812
  const isLeaving = index === keys.length;
10813
10813
  const isEdited = isLeaving && edits.length !== 0;
10814
10814
  if (isLeaving) {
10815
- key = ancestors.length === 0 ? void 0 : path10[path10.length - 1];
10815
+ key = ancestors.length === 0 ? void 0 : path12[path12.length - 1];
10816
10816
  node = parent;
10817
10817
  parent = ancestors.pop();
10818
10818
  if (isEdited) {
@@ -10846,7 +10846,7 @@ var require_visitor = __commonJS({
10846
10846
  if (node === null || node === void 0) {
10847
10847
  continue;
10848
10848
  }
10849
- path10.push(key);
10849
+ path12.push(key);
10850
10850
  }
10851
10851
  let result;
10852
10852
  if (!Array.isArray(node)) {
@@ -10856,13 +10856,13 @@ var require_visitor = __commonJS({
10856
10856
  `Invalid AST Node: ${(0, _inspect.inspect)(node)}.`
10857
10857
  );
10858
10858
  const visitFn = isLeaving ? (_enterLeaveMap$get = enterLeaveMap.get(node.kind)) === null || _enterLeaveMap$get === void 0 ? void 0 : _enterLeaveMap$get.leave : (_enterLeaveMap$get2 = enterLeaveMap.get(node.kind)) === null || _enterLeaveMap$get2 === void 0 ? void 0 : _enterLeaveMap$get2.enter;
10859
- result = visitFn === null || visitFn === void 0 ? void 0 : visitFn.call(visitor, node, key, parent, path10, ancestors);
10859
+ result = visitFn === null || visitFn === void 0 ? void 0 : visitFn.call(visitor, node, key, parent, path12, ancestors);
10860
10860
  if (result === BREAK) {
10861
10861
  break;
10862
10862
  }
10863
10863
  if (result === false) {
10864
10864
  if (!isLeaving) {
10865
- path10.pop();
10865
+ path12.pop();
10866
10866
  continue;
10867
10867
  }
10868
10868
  } else if (result !== void 0) {
@@ -10871,7 +10871,7 @@ var require_visitor = __commonJS({
10871
10871
  if ((0, _ast.isNode)(result)) {
10872
10872
  node = result;
10873
10873
  } else {
10874
- path10.pop();
10874
+ path12.pop();
10875
10875
  continue;
10876
10876
  }
10877
10877
  }
@@ -10881,7 +10881,7 @@ var require_visitor = __commonJS({
10881
10881
  edits.push([key, node]);
10882
10882
  }
10883
10883
  if (isLeaving) {
10884
- path10.pop();
10884
+ path12.pop();
10885
10885
  } else {
10886
10886
  var _node$kind;
10887
10887
  stack = {
@@ -16152,8 +16152,8 @@ var require_printPathArray = __commonJS({
16152
16152
  value: true
16153
16153
  });
16154
16154
  exports.printPathArray = printPathArray;
16155
- function printPathArray(path10) {
16156
- return path10.map(
16155
+ function printPathArray(path12) {
16156
+ return path12.map(
16157
16157
  (key) => typeof key === "number" ? "[" + key.toString() + "]" : "." + key
16158
16158
  ).join("");
16159
16159
  }
@@ -16176,9 +16176,9 @@ var require_Path = __commonJS({
16176
16176
  typename
16177
16177
  };
16178
16178
  }
16179
- function pathToArray(path10) {
16179
+ function pathToArray(path12) {
16180
16180
  const flattened = [];
16181
- let curr = path10;
16181
+ let curr = path12;
16182
16182
  while (curr) {
16183
16183
  flattened.push(curr.key);
16184
16184
  curr = curr.prev;
@@ -16209,21 +16209,21 @@ var require_coerceInputValue = __commonJS({
16209
16209
  function coerceInputValue(inputValue, type2, onError = defaultOnError) {
16210
16210
  return coerceInputValueImpl(inputValue, type2, onError, void 0);
16211
16211
  }
16212
- function defaultOnError(path10, invalidValue, error3) {
16212
+ function defaultOnError(path12, invalidValue, error3) {
16213
16213
  let errorPrefix = "Invalid value " + (0, _inspect.inspect)(invalidValue);
16214
- if (path10.length > 0) {
16215
- errorPrefix += ` at "value${(0, _printPathArray.printPathArray)(path10)}"`;
16214
+ if (path12.length > 0) {
16215
+ errorPrefix += ` at "value${(0, _printPathArray.printPathArray)(path12)}"`;
16216
16216
  }
16217
16217
  error3.message = errorPrefix + ": " + error3.message;
16218
16218
  throw error3;
16219
16219
  }
16220
- function coerceInputValueImpl(inputValue, type2, onError, path10) {
16220
+ function coerceInputValueImpl(inputValue, type2, onError, path12) {
16221
16221
  if ((0, _definition.isNonNullType)(type2)) {
16222
16222
  if (inputValue != null) {
16223
- return coerceInputValueImpl(inputValue, type2.ofType, onError, path10);
16223
+ return coerceInputValueImpl(inputValue, type2.ofType, onError, path12);
16224
16224
  }
16225
16225
  onError(
16226
- (0, _Path.pathToArray)(path10),
16226
+ (0, _Path.pathToArray)(path12),
16227
16227
  inputValue,
16228
16228
  new _GraphQLError.GraphQLError(
16229
16229
  `Expected non-nullable type "${(0, _inspect.inspect)(
@@ -16240,16 +16240,16 @@ var require_coerceInputValue = __commonJS({
16240
16240
  const itemType = type2.ofType;
16241
16241
  if ((0, _isIterableObject.isIterableObject)(inputValue)) {
16242
16242
  return Array.from(inputValue, (itemValue, index) => {
16243
- const itemPath = (0, _Path.addPath)(path10, index, void 0);
16243
+ const itemPath = (0, _Path.addPath)(path12, index, void 0);
16244
16244
  return coerceInputValueImpl(itemValue, itemType, onError, itemPath);
16245
16245
  });
16246
16246
  }
16247
- return [coerceInputValueImpl(inputValue, itemType, onError, path10)];
16247
+ return [coerceInputValueImpl(inputValue, itemType, onError, path12)];
16248
16248
  }
16249
16249
  if ((0, _definition.isInputObjectType)(type2)) {
16250
16250
  if (!(0, _isObjectLike.isObjectLike)(inputValue) || Array.isArray(inputValue)) {
16251
16251
  onError(
16252
- (0, _Path.pathToArray)(path10),
16252
+ (0, _Path.pathToArray)(path12),
16253
16253
  inputValue,
16254
16254
  new _GraphQLError.GraphQLError(
16255
16255
  `Expected type "${type2.name}" to be an object.`
@@ -16267,7 +16267,7 @@ var require_coerceInputValue = __commonJS({
16267
16267
  } else if ((0, _definition.isNonNullType)(field.type)) {
16268
16268
  const typeStr = (0, _inspect.inspect)(field.type);
16269
16269
  onError(
16270
- (0, _Path.pathToArray)(path10),
16270
+ (0, _Path.pathToArray)(path12),
16271
16271
  inputValue,
16272
16272
  new _GraphQLError.GraphQLError(
16273
16273
  `Field "${field.name}" of required type "${typeStr}" was not provided.`
@@ -16280,7 +16280,7 @@ var require_coerceInputValue = __commonJS({
16280
16280
  fieldValue,
16281
16281
  field.type,
16282
16282
  onError,
16283
- (0, _Path.addPath)(path10, field.name, type2.name)
16283
+ (0, _Path.addPath)(path12, field.name, type2.name)
16284
16284
  );
16285
16285
  }
16286
16286
  for (const fieldName of Object.keys(inputValue)) {
@@ -16290,7 +16290,7 @@ var require_coerceInputValue = __commonJS({
16290
16290
  Object.keys(type2.getFields())
16291
16291
  );
16292
16292
  onError(
16293
- (0, _Path.pathToArray)(path10),
16293
+ (0, _Path.pathToArray)(path12),
16294
16294
  inputValue,
16295
16295
  new _GraphQLError.GraphQLError(
16296
16296
  `Field "${fieldName}" is not defined by type "${type2.name}".` + (0, _didYouMean.didYouMean)(suggestions)
@@ -16302,7 +16302,7 @@ var require_coerceInputValue = __commonJS({
16302
16302
  const keys = Object.keys(coercedValue);
16303
16303
  if (keys.length !== 1) {
16304
16304
  onError(
16305
- (0, _Path.pathToArray)(path10),
16305
+ (0, _Path.pathToArray)(path12),
16306
16306
  inputValue,
16307
16307
  new _GraphQLError.GraphQLError(
16308
16308
  `Exactly one key must be specified for OneOf type "${type2.name}".`
@@ -16313,7 +16313,7 @@ var require_coerceInputValue = __commonJS({
16313
16313
  const value2 = coercedValue[key];
16314
16314
  if (value2 === null) {
16315
16315
  onError(
16316
- (0, _Path.pathToArray)(path10).concat(key),
16316
+ (0, _Path.pathToArray)(path12).concat(key),
16317
16317
  value2,
16318
16318
  new _GraphQLError.GraphQLError(`Field "${key}" must be non-null.`)
16319
16319
  );
@@ -16327,10 +16327,10 @@ var require_coerceInputValue = __commonJS({
16327
16327
  parseResult = type2.parseValue(inputValue);
16328
16328
  } catch (error3) {
16329
16329
  if (error3 instanceof _GraphQLError.GraphQLError) {
16330
- onError((0, _Path.pathToArray)(path10), inputValue, error3);
16330
+ onError((0, _Path.pathToArray)(path12), inputValue, error3);
16331
16331
  } else {
16332
16332
  onError(
16333
- (0, _Path.pathToArray)(path10),
16333
+ (0, _Path.pathToArray)(path12),
16334
16334
  inputValue,
16335
16335
  new _GraphQLError.GraphQLError(
16336
16336
  `Expected type "${type2.name}". ` + error3.message,
@@ -16344,7 +16344,7 @@ var require_coerceInputValue = __commonJS({
16344
16344
  }
16345
16345
  if (parseResult === void 0) {
16346
16346
  onError(
16347
- (0, _Path.pathToArray)(path10),
16347
+ (0, _Path.pathToArray)(path12),
16348
16348
  inputValue,
16349
16349
  new _GraphQLError.GraphQLError(`Expected type "${type2.name}".`)
16350
16350
  );
@@ -16582,11 +16582,11 @@ var require_values = __commonJS({
16582
16582
  coercedValues[varName] = (0, _coerceInputValue.coerceInputValue)(
16583
16583
  value2,
16584
16584
  varType,
16585
- (path10, invalidValue, error3) => {
16585
+ (path12, invalidValue, error3) => {
16586
16586
  let prefix = `Variable "$${varName}" got invalid value ` + (0, _inspect.inspect)(invalidValue);
16587
- if (path10.length > 0) {
16587
+ if (path12.length > 0) {
16588
16588
  prefix += ` at "${varName}${(0, _printPathArray.printPathArray)(
16589
- path10
16589
+ path12
16590
16590
  )}"`;
16591
16591
  }
16592
16592
  onError(
@@ -18329,7 +18329,7 @@ var require_locatedError = __commonJS({
18329
18329
  exports.locatedError = locatedError;
18330
18330
  var _toError = require_toError();
18331
18331
  var _GraphQLError = require_GraphQLError();
18332
- function locatedError(rawOriginalError, nodes, path10) {
18332
+ function locatedError(rawOriginalError, nodes, path12) {
18333
18333
  var _nodes;
18334
18334
  const originalError = (0, _toError.toError)(rawOriginalError);
18335
18335
  if (isLocatedGraphQLError(originalError)) {
@@ -18339,7 +18339,7 @@ var require_locatedError = __commonJS({
18339
18339
  nodes: (_nodes = originalError.nodes) !== null && _nodes !== void 0 ? _nodes : nodes,
18340
18340
  source: originalError.source,
18341
18341
  positions: originalError.positions,
18342
- path: path10,
18342
+ path: path12,
18343
18343
  originalError
18344
18344
  });
18345
18345
  }
@@ -18535,27 +18535,27 @@ var require_execute = __commonJS({
18535
18535
  rootType,
18536
18536
  operation.selectionSet
18537
18537
  );
18538
- const path10 = void 0;
18538
+ const path12 = void 0;
18539
18539
  switch (operation.operation) {
18540
18540
  case _ast.OperationTypeNode.QUERY:
18541
- return executeFields(exeContext, rootType, rootValue, path10, rootFields);
18541
+ return executeFields(exeContext, rootType, rootValue, path12, rootFields);
18542
18542
  case _ast.OperationTypeNode.MUTATION:
18543
18543
  return executeFieldsSerially(
18544
18544
  exeContext,
18545
18545
  rootType,
18546
18546
  rootValue,
18547
- path10,
18547
+ path12,
18548
18548
  rootFields
18549
18549
  );
18550
18550
  case _ast.OperationTypeNode.SUBSCRIPTION:
18551
- return executeFields(exeContext, rootType, rootValue, path10, rootFields);
18551
+ return executeFields(exeContext, rootType, rootValue, path12, rootFields);
18552
18552
  }
18553
18553
  }
18554
- function executeFieldsSerially(exeContext, parentType, sourceValue, path10, fields) {
18554
+ function executeFieldsSerially(exeContext, parentType, sourceValue, path12, fields) {
18555
18555
  return (0, _promiseReduce.promiseReduce)(
18556
18556
  fields.entries(),
18557
18557
  (results, [responseName, fieldNodes]) => {
18558
- const fieldPath = (0, _Path.addPath)(path10, responseName, parentType.name);
18558
+ const fieldPath = (0, _Path.addPath)(path12, responseName, parentType.name);
18559
18559
  const result = executeField(
18560
18560
  exeContext,
18561
18561
  parentType,
@@ -18578,12 +18578,12 @@ var require_execute = __commonJS({
18578
18578
  /* @__PURE__ */ Object.create(null)
18579
18579
  );
18580
18580
  }
18581
- function executeFields(exeContext, parentType, sourceValue, path10, fields) {
18581
+ function executeFields(exeContext, parentType, sourceValue, path12, fields) {
18582
18582
  const results = /* @__PURE__ */ Object.create(null);
18583
18583
  let containsPromise = false;
18584
18584
  try {
18585
18585
  for (const [responseName, fieldNodes] of fields.entries()) {
18586
- const fieldPath = (0, _Path.addPath)(path10, responseName, parentType.name);
18586
+ const fieldPath = (0, _Path.addPath)(path12, responseName, parentType.name);
18587
18587
  const result = executeField(
18588
18588
  exeContext,
18589
18589
  parentType,
@@ -18611,7 +18611,7 @@ var require_execute = __commonJS({
18611
18611
  }
18612
18612
  return (0, _promiseForObject.promiseForObject)(results);
18613
18613
  }
18614
- function executeField(exeContext, parentType, source, fieldNodes, path10) {
18614
+ function executeField(exeContext, parentType, source, fieldNodes, path12) {
18615
18615
  var _fieldDef$resolve;
18616
18616
  const fieldDef = getFieldDef(exeContext.schema, parentType, fieldNodes[0]);
18617
18617
  if (!fieldDef) {
@@ -18624,7 +18624,7 @@ var require_execute = __commonJS({
18624
18624
  fieldDef,
18625
18625
  fieldNodes,
18626
18626
  parentType,
18627
- path10
18627
+ path12
18628
18628
  );
18629
18629
  try {
18630
18630
  const args = (0, _values.getArgumentValues)(
@@ -18637,7 +18637,7 @@ var require_execute = __commonJS({
18637
18637
  let completed;
18638
18638
  if ((0, _isPromise.isPromise)(result)) {
18639
18639
  completed = result.then(
18640
- (resolved) => completeValue(exeContext, returnType, fieldNodes, info, path10, resolved)
18640
+ (resolved) => completeValue(exeContext, returnType, fieldNodes, info, path12, resolved)
18641
18641
  );
18642
18642
  } else {
18643
18643
  completed = completeValue(
@@ -18645,7 +18645,7 @@ var require_execute = __commonJS({
18645
18645
  returnType,
18646
18646
  fieldNodes,
18647
18647
  info,
18648
- path10,
18648
+ path12,
18649
18649
  result
18650
18650
  );
18651
18651
  }
@@ -18654,7 +18654,7 @@ var require_execute = __commonJS({
18654
18654
  const error3 = (0, _locatedError.locatedError)(
18655
18655
  rawError,
18656
18656
  fieldNodes,
18657
- (0, _Path.pathToArray)(path10)
18657
+ (0, _Path.pathToArray)(path12)
18658
18658
  );
18659
18659
  return handleFieldError(error3, returnType, exeContext);
18660
18660
  });
@@ -18664,18 +18664,18 @@ var require_execute = __commonJS({
18664
18664
  const error3 = (0, _locatedError.locatedError)(
18665
18665
  rawError,
18666
18666
  fieldNodes,
18667
- (0, _Path.pathToArray)(path10)
18667
+ (0, _Path.pathToArray)(path12)
18668
18668
  );
18669
18669
  return handleFieldError(error3, returnType, exeContext);
18670
18670
  }
18671
18671
  }
18672
- function buildResolveInfo(exeContext, fieldDef, fieldNodes, parentType, path10) {
18672
+ function buildResolveInfo(exeContext, fieldDef, fieldNodes, parentType, path12) {
18673
18673
  return {
18674
18674
  fieldName: fieldDef.name,
18675
18675
  fieldNodes,
18676
18676
  returnType: fieldDef.type,
18677
18677
  parentType,
18678
- path: path10,
18678
+ path: path12,
18679
18679
  schema: exeContext.schema,
18680
18680
  fragments: exeContext.fragments,
18681
18681
  rootValue: exeContext.rootValue,
@@ -18690,7 +18690,7 @@ var require_execute = __commonJS({
18690
18690
  exeContext.errors.push(error3);
18691
18691
  return null;
18692
18692
  }
18693
- function completeValue(exeContext, returnType, fieldNodes, info, path10, result) {
18693
+ function completeValue(exeContext, returnType, fieldNodes, info, path12, result) {
18694
18694
  if (result instanceof Error) {
18695
18695
  throw result;
18696
18696
  }
@@ -18700,7 +18700,7 @@ var require_execute = __commonJS({
18700
18700
  returnType.ofType,
18701
18701
  fieldNodes,
18702
18702
  info,
18703
- path10,
18703
+ path12,
18704
18704
  result
18705
18705
  );
18706
18706
  if (completed === null) {
@@ -18719,7 +18719,7 @@ var require_execute = __commonJS({
18719
18719
  returnType,
18720
18720
  fieldNodes,
18721
18721
  info,
18722
- path10,
18722
+ path12,
18723
18723
  result
18724
18724
  );
18725
18725
  }
@@ -18732,7 +18732,7 @@ var require_execute = __commonJS({
18732
18732
  returnType,
18733
18733
  fieldNodes,
18734
18734
  info,
18735
- path10,
18735
+ path12,
18736
18736
  result
18737
18737
  );
18738
18738
  }
@@ -18742,7 +18742,7 @@ var require_execute = __commonJS({
18742
18742
  returnType,
18743
18743
  fieldNodes,
18744
18744
  info,
18745
- path10,
18745
+ path12,
18746
18746
  result
18747
18747
  );
18748
18748
  }
@@ -18751,7 +18751,7 @@ var require_execute = __commonJS({
18751
18751
  "Cannot complete value of unexpected output type: " + (0, _inspect.inspect)(returnType)
18752
18752
  );
18753
18753
  }
18754
- function completeListValue(exeContext, returnType, fieldNodes, info, path10, result) {
18754
+ function completeListValue(exeContext, returnType, fieldNodes, info, path12, result) {
18755
18755
  if (!(0, _isIterableObject.isIterableObject)(result)) {
18756
18756
  throw new _GraphQLError.GraphQLError(
18757
18757
  `Expected Iterable, but did not find one for field "${info.parentType.name}.${info.fieldName}".`
@@ -18760,7 +18760,7 @@ var require_execute = __commonJS({
18760
18760
  const itemType = returnType.ofType;
18761
18761
  let containsPromise = false;
18762
18762
  const completedResults = Array.from(result, (item, index) => {
18763
- const itemPath = (0, _Path.addPath)(path10, index, void 0);
18763
+ const itemPath = (0, _Path.addPath)(path12, index, void 0);
18764
18764
  try {
18765
18765
  let completedItem;
18766
18766
  if ((0, _isPromise.isPromise)(item)) {
@@ -18818,7 +18818,7 @@ var require_execute = __commonJS({
18818
18818
  }
18819
18819
  return serializedResult;
18820
18820
  }
18821
- function completeAbstractValue(exeContext, returnType, fieldNodes, info, path10, result) {
18821
+ function completeAbstractValue(exeContext, returnType, fieldNodes, info, path12, result) {
18822
18822
  var _returnType$resolveTy;
18823
18823
  const resolveTypeFn = (_returnType$resolveTy = returnType.resolveType) !== null && _returnType$resolveTy !== void 0 ? _returnType$resolveTy : exeContext.typeResolver;
18824
18824
  const contextValue = exeContext.contextValue;
@@ -18837,7 +18837,7 @@ var require_execute = __commonJS({
18837
18837
  ),
18838
18838
  fieldNodes,
18839
18839
  info,
18840
- path10,
18840
+ path12,
18841
18841
  result
18842
18842
  )
18843
18843
  );
@@ -18854,7 +18854,7 @@ var require_execute = __commonJS({
18854
18854
  ),
18855
18855
  fieldNodes,
18856
18856
  info,
18857
- path10,
18857
+ path12,
18858
18858
  result
18859
18859
  );
18860
18860
  }
@@ -18902,7 +18902,7 @@ var require_execute = __commonJS({
18902
18902
  }
18903
18903
  return runtimeType;
18904
18904
  }
18905
- function completeObjectValue(exeContext, returnType, fieldNodes, info, path10, result) {
18905
+ function completeObjectValue(exeContext, returnType, fieldNodes, info, path12, result) {
18906
18906
  const subFieldNodes = collectSubfields(exeContext, returnType, fieldNodes);
18907
18907
  if (returnType.isTypeOf) {
18908
18908
  const isTypeOf = returnType.isTypeOf(result, exeContext.contextValue, info);
@@ -18915,7 +18915,7 @@ var require_execute = __commonJS({
18915
18915
  exeContext,
18916
18916
  returnType,
18917
18917
  result,
18918
- path10,
18918
+ path12,
18919
18919
  subFieldNodes
18920
18920
  );
18921
18921
  });
@@ -18924,7 +18924,7 @@ var require_execute = __commonJS({
18924
18924
  throw invalidReturnTypeError(returnType, result, fieldNodes);
18925
18925
  }
18926
18926
  }
18927
- return executeFields(exeContext, returnType, result, path10, subFieldNodes);
18927
+ return executeFields(exeContext, returnType, result, path12, subFieldNodes);
18928
18928
  }
18929
18929
  function invalidReturnTypeError(returnType, result, fieldNodes) {
18930
18930
  return new _GraphQLError.GraphQLError(
@@ -19992,13 +19992,13 @@ var require_subscribe = __commonJS({
19992
19992
  }
19993
19993
  );
19994
19994
  }
19995
- const path10 = (0, _Path.addPath)(void 0, responseName, rootType.name);
19995
+ const path12 = (0, _Path.addPath)(void 0, responseName, rootType.name);
19996
19996
  const info = (0, _execute.buildResolveInfo)(
19997
19997
  exeContext,
19998
19998
  fieldDef,
19999
19999
  fieldNodes,
20000
20000
  rootType,
20001
- path10
20001
+ path12
20002
20002
  );
20003
20003
  try {
20004
20004
  var _fieldDef$subscribe;
@@ -20018,7 +20018,7 @@ var require_subscribe = __commonJS({
20018
20018
  throw (0, _locatedError.locatedError)(
20019
20019
  error3,
20020
20020
  fieldNodes,
20021
- (0, _Path.pathToArray)(path10)
20021
+ (0, _Path.pathToArray)(path12)
20022
20022
  );
20023
20023
  }
20024
20024
  }
@@ -27487,8 +27487,8 @@ var require_schemes = __commonJS({
27487
27487
  wsComponents.secure = void 0;
27488
27488
  }
27489
27489
  if (wsComponents.resourceName) {
27490
- const [path10, query] = wsComponents.resourceName.split("?");
27491
- wsComponents.path = path10 && path10 !== "/" ? path10 : void 0;
27490
+ const [path12, query] = wsComponents.resourceName.split("?");
27491
+ wsComponents.path = path12 && path12 !== "/" ? path12 : void 0;
27492
27492
  wsComponents.query = query;
27493
27493
  wsComponents.resourceName = void 0;
27494
27494
  }
@@ -37004,10 +37004,10 @@ async function downloadToFile(opts) {
37004
37004
  Readable.fromWeb(response.body),
37005
37005
  createWriteStream(opts.destPath)
37006
37006
  );
37007
- const stat = await fs2.stat(opts.destPath);
37007
+ const stat2 = await fs2.stat(opts.destPath);
37008
37008
  return {
37009
37009
  path: opts.destPath,
37010
- bytes: stat.size,
37010
+ bytes: stat2.size,
37011
37011
  contentType: response.headers.get("content-type")
37012
37012
  };
37013
37013
  }
@@ -37023,8 +37023,8 @@ async function resolveDestPath(opts) {
37023
37023
  if (opts.out.endsWith("/") || opts.out.endsWith(path6.sep)) {
37024
37024
  return path6.join(resolved, opts.defaultFilename);
37025
37025
  }
37026
- const stat = await fs2.stat(resolved).catch(() => null);
37027
- if (stat?.isDirectory()) {
37026
+ const stat2 = await fs2.stat(resolved).catch(() => null);
37027
+ if (stat2?.isDirectory()) {
37028
37028
  return path6.join(resolved, opts.defaultFilename);
37029
37029
  }
37030
37030
  return resolved;
@@ -37810,6 +37810,316 @@ var filesDownload = buildCommand({
37810
37810
  }
37811
37811
  });
37812
37812
 
37813
+ // apps/cli/src/commands/files/upload.ts
37814
+ import path10 from "node:path";
37815
+
37816
+ // apps/cli/src/util/fileUpload.ts
37817
+ import { createHash, randomUUID as randomUUID2 } from "node:crypto";
37818
+ import { createReadStream } from "node:fs";
37819
+ import { stat } from "node:fs/promises";
37820
+ import { request as httpRequest } from "node:http";
37821
+ import { request as httpsRequest } from "node:https";
37822
+ import path9 from "node:path";
37823
+
37824
+ // apps/cli/src/graphql/uploads.ts
37825
+ var generateFileUploadUrlDocument = graphql(`
37826
+ mutation Cli_generateFileUploadUrl($orgId: ID!, $metadata: [KeyValueInput!]) {
37827
+ generateFileUploadUrl(orgId: $orgId, metadata: $metadata) {
37828
+ id
37829
+ url
37830
+ maxFilesize
37831
+ fields {
37832
+ key
37833
+ value
37834
+ }
37835
+ }
37836
+ }
37837
+ `);
37838
+ var completeFileUploadDocument = graphql(`
37839
+ mutation Cli_completeFileUpload($orgId: ID!, $id: ID!, $filename: String!) {
37840
+ completeUpload(orgId: $orgId, id: $id, filename: $filename) {
37841
+ id
37842
+ filename
37843
+ filesize
37844
+ mimeType
37845
+ downloadUrl
37846
+ }
37847
+ }
37848
+ `);
37849
+
37850
+ // apps/cli/src/util/fileUpload.ts
37851
+ var MAX_ERROR_RESPONSE_BYTES = 8 * 1024;
37852
+ async function uploadCloudFile(ctx, options) {
37853
+ const absolutePath = path9.resolve(options.filePath);
37854
+ const filename = sanitizeUploadFilename(path9.basename(absolutePath));
37855
+ let fileStat;
37856
+ try {
37857
+ fileStat = await stat(absolutePath);
37858
+ } catch (err) {
37859
+ return new Error(
37860
+ `Cannot read "${absolutePath}": ${err instanceof Error ? err.message : String(err)}`
37861
+ );
37862
+ }
37863
+ if (!fileStat.isFile()) {
37864
+ return new Error(`"${absolutePath}" is not a file.`);
37865
+ }
37866
+ if (fileStat.size === 0) {
37867
+ return new Error("Cannot upload an empty file.");
37868
+ }
37869
+ const contentType = normalizeContentType(options.contentType);
37870
+ if (contentType instanceof Error) {
37871
+ return contentType;
37872
+ }
37873
+ const checksum = await computeFileChecksum(absolutePath);
37874
+ let uploadData;
37875
+ try {
37876
+ const result = await ctx.client.request(generateFileUploadUrlDocument, {
37877
+ orgId: ctx.orgId,
37878
+ metadata: [
37879
+ { key: "content-type", value: contentType },
37880
+ { key: "sha256", value: checksum }
37881
+ ]
37882
+ });
37883
+ uploadData = result.generateFileUploadUrl;
37884
+ } catch (err) {
37885
+ return new Error(formatGraphQLError(err));
37886
+ }
37887
+ const maxFilesize = Number(uploadData.maxFilesize);
37888
+ if (!Number.isSafeInteger(maxFilesize) || maxFilesize <= 0) {
37889
+ return new Error("The server returned an invalid upload size limit.");
37890
+ }
37891
+ if (fileStat.size > maxFilesize) {
37892
+ return new Error(
37893
+ `File is ${fileStat.size} bytes; the server limit is ${maxFilesize} bytes.`
37894
+ );
37895
+ }
37896
+ try {
37897
+ await postMultipartFile({
37898
+ url: uploadData.url,
37899
+ fields: Object.fromEntries(
37900
+ uploadData.fields.map(({ key, value: value2 }) => [key, value2])
37901
+ ),
37902
+ filePath: absolutePath,
37903
+ filename,
37904
+ contentType,
37905
+ filesize: fileStat.size
37906
+ });
37907
+ } catch (err) {
37908
+ return err instanceof Error ? err : new Error(String(err));
37909
+ }
37910
+ try {
37911
+ const result = await ctx.client.request(completeFileUploadDocument, {
37912
+ orgId: ctx.orgId,
37913
+ id: uploadData.id,
37914
+ filename
37915
+ });
37916
+ return {
37917
+ ...result.completeUpload,
37918
+ filesize: Number(result.completeUpload.filesize)
37919
+ };
37920
+ } catch (err) {
37921
+ return new Error(formatGraphQLError(err));
37922
+ }
37923
+ }
37924
+ async function computeFileChecksum(filePath) {
37925
+ const hash = createHash("sha256");
37926
+ for await (const chunk of createReadStream(filePath)) {
37927
+ if (Buffer.isBuffer(chunk)) {
37928
+ hash.update(chunk);
37929
+ }
37930
+ }
37931
+ return hash.digest("base64");
37932
+ }
37933
+ async function postMultipartFile(options) {
37934
+ const boundary = `specset-${randomUUID2()}`;
37935
+ const fieldParts = Object.entries(options.fields).map(
37936
+ ([name2, value2]) => formField(boundary, name2, value2)
37937
+ );
37938
+ const fileHeader = Buffer.from(
37939
+ `--${boundary}\r
37940
+ Content-Disposition: form-data; name="file"; filename="${escapeHeaderValue(options.filename)}"\r
37941
+ Content-Type: ${options.contentType}\r
37942
+ \r
37943
+ `
37944
+ );
37945
+ const closing = Buffer.from(`\r
37946
+ --${boundary}--\r
37947
+ `);
37948
+ const contentLength = fieldParts.reduce((total, part) => total + part.length, 0) + fileHeader.length + options.filesize + closing.length;
37949
+ const target = new URL(options.url);
37950
+ if (target.protocol !== "https:" && target.protocol !== "http:") {
37951
+ throw new Error(`Unsupported upload URL protocol "${target.protocol}".`);
37952
+ }
37953
+ const responsePromise = new Promise((resolve, reject) => {
37954
+ const send = target.protocol === "https:" ? httpsRequest : httpRequest;
37955
+ const request2 = send(
37956
+ target,
37957
+ {
37958
+ method: "POST",
37959
+ headers: {
37960
+ "content-type": `multipart/form-data; boundary=${boundary}`,
37961
+ "content-length": String(contentLength)
37962
+ }
37963
+ },
37964
+ (response2) => {
37965
+ void readResponse(response2).then(resolve, reject);
37966
+ }
37967
+ );
37968
+ request2.once("error", reject);
37969
+ void writeMultipartRequest(
37970
+ request2,
37971
+ fieldParts,
37972
+ fileHeader,
37973
+ options.filePath,
37974
+ closing
37975
+ ).catch((error3) => {
37976
+ request2.destroy(
37977
+ error3 instanceof Error ? error3 : new Error(String(error3))
37978
+ );
37979
+ });
37980
+ });
37981
+ const response = await responsePromise;
37982
+ if (response.statusCode < 200 || response.statusCode >= 300) {
37983
+ const detail = response.body ? `: ${response.body}` : "";
37984
+ throw new Error(
37985
+ `Storage upload failed (${response.statusCode} ${response.statusMessage})${detail}`
37986
+ );
37987
+ }
37988
+ }
37989
+ async function writeMultipartRequest(request2, fieldParts, fileHeader, filePath, closing) {
37990
+ for (const part of fieldParts) {
37991
+ await writeChunk(request2, part);
37992
+ }
37993
+ await writeChunk(request2, fileHeader);
37994
+ for await (const chunk of createReadStream(filePath)) {
37995
+ if (Buffer.isBuffer(chunk)) {
37996
+ await writeChunk(request2, chunk);
37997
+ }
37998
+ }
37999
+ request2.end(closing);
38000
+ }
38001
+ async function writeChunk(request2, chunk) {
38002
+ if (request2.write(chunk)) {
38003
+ return;
38004
+ }
38005
+ await new Promise((resolve, reject) => {
38006
+ const cleanup = () => {
38007
+ request2.off("drain", handleDrain);
38008
+ request2.off("error", handleError);
38009
+ };
38010
+ const handleDrain = () => {
38011
+ cleanup();
38012
+ resolve();
38013
+ };
38014
+ const handleError = (error3) => {
38015
+ cleanup();
38016
+ reject(error3);
38017
+ };
38018
+ request2.once("drain", handleDrain);
38019
+ request2.once("error", handleError);
38020
+ });
38021
+ }
38022
+ async function readResponse(response) {
38023
+ const chunks = [];
38024
+ let received = 0;
38025
+ for await (const chunk of response) {
38026
+ if (!Buffer.isBuffer(chunk) || received >= MAX_ERROR_RESPONSE_BYTES) {
38027
+ continue;
38028
+ }
38029
+ const remaining = MAX_ERROR_RESPONSE_BYTES - received;
38030
+ const selected = chunk.subarray(0, remaining);
38031
+ chunks.push(selected);
38032
+ received += selected.length;
38033
+ }
38034
+ return {
38035
+ statusCode: response.statusCode ?? 0,
38036
+ statusMessage: response.statusMessage ?? "Unknown status",
38037
+ body: Buffer.concat(chunks).toString("utf8").trim()
38038
+ };
38039
+ }
38040
+ function formField(boundary, name2, value2) {
38041
+ return Buffer.from(
38042
+ `--${boundary}\r
38043
+ Content-Disposition: form-data; name="${escapeHeaderValue(name2)}"\r
38044
+ \r
38045
+ ${value2}\r
38046
+ `
38047
+ );
38048
+ }
38049
+ function escapeHeaderValue(value2) {
38050
+ return value2.replace(/["\r\n]/g, "_");
38051
+ }
38052
+ function normalizeContentType(value2) {
38053
+ const contentType = value2?.trim().toLowerCase() || "application/octet-stream";
38054
+ if (!/^[a-z0-9][a-z0-9!#$&^_.+-]*\/[a-z0-9][a-z0-9!#$&^_.+-]*$/.test(
38055
+ contentType
38056
+ )) {
38057
+ return new Error(`Invalid MIME type "${value2}".`);
38058
+ }
38059
+ return contentType;
38060
+ }
38061
+ function sanitizeUploadFilename(value2) {
38062
+ return value2.replace(/[\u0000-\u001f\u007f/\\:*?"<>|]/g, "_").slice(0, 255);
38063
+ }
38064
+
38065
+ // apps/cli/src/commands/files/upload.ts
38066
+ async function filesUploadCommand(flags, file) {
38067
+ const cli = await resolveDownloadCli(this.config, flags.host);
38068
+ if (cli instanceof Error) {
38069
+ return cli;
38070
+ }
38071
+ const uploaded = await uploadCloudFile(
38072
+ { client: cli.client, orgId: cli.orgId },
38073
+ { filePath: file, contentType: flags.type }
38074
+ );
38075
+ if (uploaded instanceof Error) {
38076
+ return uploaded;
38077
+ }
38078
+ printResult(
38079
+ this.process,
38080
+ flags.json ?? false,
38081
+ uploaded,
38082
+ `Uploaded ${path10.basename(file)} as cloud file ${uploaded.id}`
38083
+ );
38084
+ }
38085
+ var filesUpload = buildCommand({
38086
+ func: filesUploadCommand,
38087
+ parameters: {
38088
+ positional: {
38089
+ kind: "tuple",
38090
+ parameters: [
38091
+ {
38092
+ brief: "Local file to upload",
38093
+ parse: String,
38094
+ placeholder: "file"
38095
+ }
38096
+ ]
38097
+ },
38098
+ flags: {
38099
+ type: {
38100
+ kind: "parsed",
38101
+ parse: String,
38102
+ brief: "MIME type (defaults to application/octet-stream)",
38103
+ optional: true
38104
+ },
38105
+ host: {
38106
+ kind: "parsed",
38107
+ parse: String,
38108
+ brief: "Host to call (defaults to the active host)",
38109
+ optional: true
38110
+ },
38111
+ json: {
38112
+ kind: "boolean",
38113
+ brief: "Emit uploaded cloud-file metadata as JSON",
38114
+ optional: true
38115
+ }
38116
+ }
38117
+ },
38118
+ docs: {
38119
+ brief: "Upload a local file and return its cloud file id for an attachment mutation"
38120
+ }
38121
+ });
38122
+
37813
38123
  // apps/cli/src/commands/host/list.ts
37814
38124
  async function hostListCommand(flags) {
37815
38125
  const hosts = Object.keys(this.config.hosts).sort();
@@ -38613,8 +38923,8 @@ function getErrorMap() {
38613
38923
 
38614
38924
  // node_modules/zod/v3/helpers/parseUtil.js
38615
38925
  var makeIssue = (params) => {
38616
- const { data, path: path10, errorMaps, issueData } = params;
38617
- const fullPath = [...path10, ...issueData.path || []];
38926
+ const { data, path: path12, errorMaps, issueData } = params;
38927
+ const fullPath = [...path12, ...issueData.path || []];
38618
38928
  const fullIssue = {
38619
38929
  ...issueData,
38620
38930
  path: fullPath
@@ -38729,11 +39039,11 @@ var errorUtil;
38729
39039
 
38730
39040
  // node_modules/zod/v3/types.js
38731
39041
  var ParseInputLazyPath = class {
38732
- constructor(parent, value2, path10, key) {
39042
+ constructor(parent, value2, path12, key) {
38733
39043
  this._cachedPath = [];
38734
39044
  this.parent = parent;
38735
39045
  this.data = value2;
38736
- this._path = path10;
39046
+ this._path = path12;
38737
39047
  this._key = key;
38738
39048
  }
38739
39049
  get path() {
@@ -42366,10 +42676,10 @@ function mergeDefs(...defs) {
42366
42676
  function cloneDef(schema) {
42367
42677
  return mergeDefs(schema._zod.def);
42368
42678
  }
42369
- function getElementAtPath(obj, path10) {
42370
- if (!path10)
42679
+ function getElementAtPath(obj, path12) {
42680
+ if (!path12)
42371
42681
  return obj;
42372
- return path10.reduce((acc, key) => acc?.[key], obj);
42682
+ return path12.reduce((acc, key) => acc?.[key], obj);
42373
42683
  }
42374
42684
  function promiseAllObject(promisesObj) {
42375
42685
  const keys = Object.keys(promisesObj);
@@ -42730,11 +43040,11 @@ function aborted(x, startIndex = 0) {
42730
43040
  }
42731
43041
  return false;
42732
43042
  }
42733
- function prefixIssues(path10, issues) {
43043
+ function prefixIssues(path12, issues) {
42734
43044
  return issues.map((iss) => {
42735
43045
  var _a;
42736
43046
  (_a = iss).path ?? (_a.path = []);
42737
- iss.path.unshift(path10);
43047
+ iss.path.unshift(path12);
42738
43048
  return iss;
42739
43049
  });
42740
43050
  }
@@ -50027,7 +50337,7 @@ var submittalsDownload = buildCommand({
50027
50337
  // apps/cli/src/commands/skill/install.ts
50028
50338
  import fs3 from "node:fs/promises";
50029
50339
  import os2 from "node:os";
50030
- import path9 from "node:path";
50340
+ import path11 from "node:path";
50031
50341
 
50032
50342
  // apps/cli/src/skillAsset.ts
50033
50343
  import { existsSync as existsSync2, readdirSync, readFileSync as readFileSync2 } from "node:fs";
@@ -50064,7 +50374,7 @@ function isSkillInstallTarget(value2) {
50064
50374
  return Object.hasOwn(SKILL_TARGET_PATHS, value2);
50065
50375
  }
50066
50376
  function defaultSkillsDir(target, homeDir = os2.homedir()) {
50067
- return path9.join(homeDir, ...SKILL_TARGET_PATHS[target]);
50377
+ return path11.join(homeDir, ...SKILL_TARGET_PATHS[target]);
50068
50378
  }
50069
50379
  async function readOptionalText(file) {
50070
50380
  try {
@@ -50077,9 +50387,9 @@ async function readOptionalText(file) {
50077
50387
  }
50078
50388
  }
50079
50389
  async function installOne(skillsDir, name2, version2) {
50080
- const destDir = path9.join(skillsDir, name2);
50081
- const destFile = path9.join(destDir, "SKILL.md");
50082
- const versionFile = path9.join(destDir, SKILL_VERSION_FILENAME);
50390
+ const destDir = path11.join(skillsDir, name2);
50391
+ const destFile = path11.join(destDir, "SKILL.md");
50392
+ const versionFile = path11.join(destDir, SKILL_VERSION_FILENAME);
50083
50393
  const desired = readPackagedSkill(name2);
50084
50394
  const [existing, recordedVersion] = await Promise.all([
50085
50395
  readOptionalText(destFile),
@@ -50120,18 +50430,18 @@ async function findOrphanedSkills(skillsDir, packagedNames) {
50120
50430
  }
50121
50431
  try {
50122
50432
  const recordedVersion = await readOptionalText(
50123
- path9.join(skillsDir, entry.name, SKILL_VERSION_FILENAME)
50433
+ path11.join(skillsDir, entry.name, SKILL_VERSION_FILENAME)
50124
50434
  );
50125
50435
  if (recordedVersion?.trim()) {
50126
- orphans.push(path9.join(skillsDir, entry.name));
50436
+ orphans.push(path11.join(skillsDir, entry.name));
50127
50437
  continue;
50128
50438
  }
50129
50439
  const content = await fs3.readFile(
50130
- path9.join(skillsDir, entry.name, "SKILL.md"),
50440
+ path11.join(skillsDir, entry.name, "SKILL.md"),
50131
50441
  "utf8"
50132
50442
  );
50133
50443
  if (extractSkillVersion(content) !== null) {
50134
- orphans.push(path9.join(skillsDir, entry.name));
50444
+ orphans.push(path11.join(skillsDir, entry.name));
50135
50445
  }
50136
50446
  } catch {
50137
50447
  }
@@ -50604,10 +50914,11 @@ var rfisRoutes = buildRouteMap({
50604
50914
  });
50605
50915
  var filesRoutes = buildRouteMap({
50606
50916
  routes: {
50607
- download: filesDownload
50917
+ download: filesDownload,
50918
+ upload: filesUpload
50608
50919
  },
50609
50920
  docs: {
50610
- brief: "Fetch raw file resources by id"
50921
+ brief: "Upload local files or fetch raw file resources by id"
50611
50922
  }
50612
50923
  });
50613
50924
  var root = buildRouteMap({