@spica-devkit/testing 0.20.7 → 0.21.0-beta.1

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.js CHANGED
@@ -281,6 +281,85 @@ var ChangeKind;
281
281
  })(ChangeKind || (ChangeKind = {}));
282
282
  const DEFAULT_CONCURRENCY = 10;
283
283
 
284
+ const REQUEST_METHODS = ["get", "delete", "head", "post", "patch", "put"];
285
+ const limitedClients = new WeakMap();
286
+ function limitConcurrency(http, limit = DEFAULT_CONCURRENCY, signal) {
287
+ const existing = limitedClients.get(http);
288
+ if (existing && !signal)
289
+ return http;
290
+ const { semaphore, target } = existing ?? {
291
+ semaphore: new Semaphore(normalizeLimit(limit)),
292
+ target: http
293
+ };
294
+ const limited = { ...target };
295
+ for (const method of REQUEST_METHODS) {
296
+ limited[method] = (...args) => semaphore.run(() => {
297
+ if (signal?.aborted)
298
+ throw signal.reason;
299
+ return target[method](...args);
300
+ });
301
+ }
302
+ limitedClients.set(limited, { semaphore, target });
303
+ return limited;
304
+ }
305
+ async function mapWithConcurrency(items, limit, fn) {
306
+ const results = new Array(items.length);
307
+ let next = 0;
308
+ let failure;
309
+ const worker = async () => {
310
+ while (!failure && next < items.length) {
311
+ const index = next++;
312
+ try {
313
+ results[index] = await fn(items[index], index);
314
+ }
315
+ catch (error) {
316
+ if (!failure)
317
+ failure = { error };
318
+ }
319
+ }
320
+ };
321
+ const workerCount = Math.min(normalizeLimit(limit), items.length);
322
+ await Promise.all(Array.from({ length: workerCount }, worker));
323
+ if (failure)
324
+ throw failure.error;
325
+ return results;
326
+ }
327
+ function normalizeLimit(limit) {
328
+ return Number.isFinite(limit) ? Math.max(1, Math.floor(limit)) : DEFAULT_CONCURRENCY;
329
+ }
330
+ class Semaphore {
331
+ constructor(limit) {
332
+ this.limit = limit;
333
+ this.active = 0;
334
+ this.waiting = [];
335
+ }
336
+ async run(task) {
337
+ await this.acquire();
338
+ try {
339
+ return await task();
340
+ }
341
+ finally {
342
+ this.release();
343
+ }
344
+ }
345
+ acquire() {
346
+ if (this.active < this.limit) {
347
+ this.active++;
348
+ return Promise.resolve();
349
+ }
350
+ return new Promise(resolve => this.waiting.push(resolve));
351
+ }
352
+ release() {
353
+ const next = this.waiting.shift();
354
+ if (next) {
355
+ next();
356
+ }
357
+ else {
358
+ this.active--;
359
+ }
360
+ }
361
+ }
362
+
284
363
  const noopProgress = {
285
364
  update() { },
286
365
  succeed() { },
@@ -360,7 +439,7 @@ const REMOVE$1 = Symbol('remove node');
360
439
  * and `Node` (alias, map, seq & scalar) targets. Of all these, only the most
361
440
  * specific defined one will be used for each node.
362
441
  */
363
- function visit$1(node, visitor) {
442
+ function visit$2(node, visitor) {
364
443
  const visitor_ = initVisitor(visitor);
365
444
  if (isDocument(node)) {
366
445
  const cd = visit_(null, node.contents, visitor_, Object.freeze([node]));
@@ -374,11 +453,11 @@ function visit$1(node, visitor) {
374
453
  // namespace using `var`, but then complains about that because
375
454
  // `unique symbol` must be `const`.
376
455
  /** Terminate visit traversal completely */
377
- visit$1.BREAK = BREAK$1;
456
+ visit$2.BREAK = BREAK$1;
378
457
  /** Do not visit the children of the current node */
379
- visit$1.SKIP = SKIP$1;
458
+ visit$2.SKIP = SKIP$1;
380
459
  /** Remove the current node */
381
- visit$1.REMOVE = REMOVE$1;
460
+ visit$2.REMOVE = REMOVE$1;
382
461
  function visit_(key, node, visitor, path) {
383
462
  const ctrl = callVisitor(key, node, visitor, path);
384
463
  if (isNode(ctrl) || isPair(ctrl)) {
@@ -709,7 +788,7 @@ class Directives {
709
788
  let tagNames;
710
789
  if (doc && tagEntries.length > 0 && isNode(doc.contents)) {
711
790
  const tags = {};
712
- visit$1(doc.contents, (_key, node) => {
791
+ visit$2(doc.contents, (_key, node) => {
713
792
  if (isNode(node) && node.tag)
714
793
  tags[node.tag] = true;
715
794
  });
@@ -744,7 +823,7 @@ function anchorIsValid(anchor) {
744
823
  }
745
824
  function anchorNames(root) {
746
825
  const anchors = new Set();
747
- visit$1(root, {
826
+ visit$2(root, {
748
827
  Value(_key, node) {
749
828
  if (node.anchor)
750
829
  anchors.add(node.anchor);
@@ -938,7 +1017,7 @@ class Alias extends NodeBase {
938
1017
  }
939
1018
  else {
940
1019
  nodes = [];
941
- visit$1(doc, {
1020
+ visit$2(doc, {
942
1021
  Node: (_key, node) => {
943
1022
  if (isAlias(node) || hasAnchor(node))
944
1023
  nodes.push(node);
@@ -5735,7 +5814,7 @@ const REMOVE = Symbol('remove item');
5735
5814
  * visitor is called on item entry, next visitors are called after handling
5736
5815
  * a non-empty `key` and when exiting the item.
5737
5816
  */
5738
- function visit(cst, visitor) {
5817
+ function visit$1(cst, visitor) {
5739
5818
  if ('type' in cst && cst.type === 'document')
5740
5819
  cst = { start: cst.start, value: cst.value };
5741
5820
  _visit(Object.freeze([]), cst, visitor);
@@ -5744,13 +5823,13 @@ function visit(cst, visitor) {
5744
5823
  // namespace using `var`, but then complains about that because
5745
5824
  // `unique symbol` must be `const`.
5746
5825
  /** Terminate visit traversal completely */
5747
- visit.BREAK = BREAK;
5826
+ visit$1.BREAK = BREAK;
5748
5827
  /** Do not visit the children of the current item */
5749
- visit.SKIP = SKIP;
5828
+ visit$1.SKIP = SKIP;
5750
5829
  /** Remove the current item */
5751
- visit.REMOVE = REMOVE;
5830
+ visit$1.REMOVE = REMOVE;
5752
5831
  /** Find the item at `path` from `cst` as the root */
5753
- visit.itemAtPath = (cst, path) => {
5832
+ visit$1.itemAtPath = (cst, path) => {
5754
5833
  let item = cst;
5755
5834
  for (const [field, index] of path) {
5756
5835
  const tok = item?.[field];
@@ -5767,8 +5846,8 @@ visit.itemAtPath = (cst, path) => {
5767
5846
  *
5768
5847
  * Throws an error if the collection is not found, which should never happen if the item itself exists.
5769
5848
  */
5770
- visit.parentCollection = (cst, path) => {
5771
- const parent = visit.itemAtPath(cst, path.slice(0, -1));
5849
+ visit$1.parentCollection = (cst, path) => {
5850
+ const parent = visit$1.itemAtPath(cst, path.slice(0, -1));
5772
5851
  const field = path[path.length - 1][0];
5773
5852
  const coll = parent?.[field];
5774
5853
  if (coll && 'items' in coll)
@@ -5907,7 +5986,7 @@ var cst = /*#__PURE__*/Object.freeze({
5907
5986
  setScalarValue: setScalarValue,
5908
5987
  stringify: stringify$1,
5909
5988
  tokenType: tokenType,
5910
- visit: visit
5989
+ visit: visit$1
5911
5990
  });
5912
5991
 
5913
5992
  /*
@@ -7747,7 +7826,7 @@ var YAML = /*#__PURE__*/Object.freeze({
7747
7826
  parseAllDocuments: parseAllDocuments,
7748
7827
  parseDocument: parseDocument,
7749
7828
  stringify: stringify,
7750
- visit: visit$1,
7829
+ visit: visit$2,
7751
7830
  visitAsync: visitAsync
7752
7831
  });
7753
7832
 
@@ -12948,13 +13027,134 @@ function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader
12948
13027
  return ret.join('\n') + '\n';
12949
13028
  }
12950
13029
 
12951
- async function buildPlan(modules, http, rootDir, options = {}) {
13030
+ var isPlainObject_1;
13031
+ var hasRequiredIsPlainObject;
13032
+
13033
+ function requireIsPlainObject () {
13034
+ if (hasRequiredIsPlainObject) return isPlainObject_1;
13035
+ hasRequiredIsPlainObject = 1;
13036
+ var baseGetTag = require_baseGetTag(),
13037
+ getPrototype = require_getPrototype(),
13038
+ isObjectLike = requireIsObjectLike();
13039
+
13040
+ /** `Object#toString` result references. */
13041
+ var objectTag = '[object Object]';
13042
+
13043
+ /** Used for built-in method references. */
13044
+ var funcProto = Function.prototype,
13045
+ objectProto = Object.prototype;
13046
+
13047
+ /** Used to resolve the decompiled source of functions. */
13048
+ var funcToString = funcProto.toString;
13049
+
13050
+ /** Used to check objects for own properties. */
13051
+ var hasOwnProperty = objectProto.hasOwnProperty;
13052
+
13053
+ /** Used to infer the `Object` constructor. */
13054
+ var objectCtorString = funcToString.call(Object);
13055
+
13056
+ /**
13057
+ * Checks if `value` is a plain object, that is, an object created by the
13058
+ * `Object` constructor or one with a `[[Prototype]]` of `null`.
13059
+ *
13060
+ * @static
13061
+ * @memberOf _
13062
+ * @since 0.8.0
13063
+ * @category Lang
13064
+ * @param {*} value The value to check.
13065
+ * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
13066
+ * @example
13067
+ *
13068
+ * function Foo() {
13069
+ * this.a = 1;
13070
+ * }
13071
+ *
13072
+ * _.isPlainObject(new Foo);
13073
+ * // => false
13074
+ *
13075
+ * _.isPlainObject([1, 2, 3]);
13076
+ * // => false
13077
+ *
13078
+ * _.isPlainObject({ 'x': 0, 'y': 0 });
13079
+ * // => true
13080
+ *
13081
+ * _.isPlainObject(Object.create(null));
13082
+ * // => true
13083
+ */
13084
+ function isPlainObject(value) {
13085
+ if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
13086
+ return false;
13087
+ }
13088
+ var proto = getPrototype(value);
13089
+ if (proto === null) {
13090
+ return true;
13091
+ }
13092
+ var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
13093
+ return typeof Ctor == 'function' && Ctor instanceof Ctor &&
13094
+ funcToString.call(Ctor) == objectCtorString;
13095
+ }
13096
+
13097
+ isPlainObject_1 = isPlainObject;
13098
+ return isPlainObject_1;
13099
+ }
13100
+
13101
+ var isPlainObjectExports = requireIsPlainObject();
13102
+ var isPlainObject = /*@__PURE__*/getDefaultExportFromCjs(isPlainObjectExports);
13103
+
13104
+ function sortUnorderedArrays(data, paths = []) {
13105
+ if (!paths.length)
13106
+ return data;
13107
+ return visit(data, [], paths.map(p => p.split(".")));
13108
+ }
13109
+ function visit(node, path, patterns) {
13110
+ let visited = node;
13111
+ if (Array.isArray(node)) {
13112
+ visited = node.map((item, i) => visit(item, [...path, String(i)], patterns));
13113
+ }
13114
+ else if (isPlainObject(node)) {
13115
+ visited = Object.fromEntries(Object.entries(node).map(([k, v]) => [
13116
+ k,
13117
+ visit(v, [...path, k], patterns)
13118
+ ]));
13119
+ }
13120
+ if (Array.isArray(visited) && patterns.some(p => matches(p, path))) {
13121
+ return visited
13122
+ .map(item => ({ item, key: canonical(item) }))
13123
+ .sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0))
13124
+ .map(({ item }) => item);
13125
+ }
13126
+ return visited;
13127
+ }
13128
+ function matches(pattern, path) {
13129
+ if (!pattern.length)
13130
+ return !path.length;
13131
+ const [head, ...rest] = pattern;
13132
+ if (head === "**") {
13133
+ return matches(rest, path) || (path.length > 0 && matches(pattern, path.slice(1)));
13134
+ }
13135
+ return path.length > 0 && (head === "*" || head === path[0]) && matches(rest, path.slice(1));
13136
+ }
13137
+ function canonical(value) {
13138
+ if (Array.isArray(value))
13139
+ return `[${value.map(canonical).join(",")}]`;
13140
+ if (isPlainObject(value)) {
13141
+ const obj = value;
13142
+ const entries = Object.keys(obj)
13143
+ .sort()
13144
+ .map(k => `${JSON.stringify(k)}:${canonical(obj[k])}`);
13145
+ return `{${entries.join(",")}}`;
13146
+ }
13147
+ return JSON.stringify(value) ?? "undefined";
13148
+ }
13149
+
13150
+ async function buildPlan(modules, unlimitedHttp, rootDir, options = {}) {
12952
13151
  const { detailed = false, detectRenames = true, reporter = silentReporter, concurrency = DEFAULT_CONCURRENCY, source } = options;
13152
+ const http = limitConcurrency(unlimitedHttp, concurrency);
12953
13153
  const modulePlans = [];
12954
13154
  for (const mod of modules) {
12955
13155
  const [locals, remotes] = await Promise.all([
12956
13156
  reporter.task(`Reading local ${mod.displayName} files`, () => mod.readLocal(rootDir, source)),
12957
- reporter.task(`Fetching remote ${mod.displayName}`, () => mod.readRemote(http, { concurrency }))
13157
+ reporter.task(`Fetching remote ${mod.displayName}`, () => mod.readRemote(http))
12958
13158
  ]);
12959
13159
  const localBySlug = new Map(locals.map(l => [l.slug, l]));
12960
13160
  const remoteBySlug = new Map(remotes.map(r => [r.slug, r]));
@@ -13033,33 +13233,36 @@ async function buildPlan(modules, http, rootDir, options = {}) {
13033
13233
  }
13034
13234
  return { modules: modulePlans };
13035
13235
  }
13036
- async function applyPlan(plan, http, opts = {}) {
13236
+ async function applyPlan(plan, unlimitedHttp, opts = {}) {
13037
13237
  const concurrency = opts.concurrency ?? DEFAULT_CONCURRENCY;
13038
13238
  const reporter = opts.reporter ?? silentReporter;
13039
13239
  const errors = [];
13240
+ const abortController = new AbortController();
13241
+ const http = limitConcurrency(unlimitedHttp, concurrency, abortController.signal);
13242
+ let abortError;
13040
13243
  const handleErr = (label, e) => {
13041
- const msg = formatError(e);
13042
- const full = `${label}: ${msg}`;
13043
- if (opts.abortOnError)
13044
- throw new Error(full);
13244
+ if (abortError)
13245
+ throw abortError;
13246
+ const full = `${label}: ${formatError(e)}`;
13247
+ if (opts.abortOnError) {
13248
+ abortError = new Error(full);
13249
+ abortController.abort(abortError);
13250
+ throw abortError;
13251
+ }
13045
13252
  reporter.warn(full);
13046
13253
  errors.push(full);
13047
13254
  };
13048
13255
  for (const mp of plan.modules) {
13049
13256
  const { module: mod, creates, updates, deletes } = mp;
13050
- if (deletes.length) {
13051
- await runConcurrently(deletes.map(e => ({ slug: e.slug, run: () => mod.delete(http, e.remote.id) })), concurrency, `Deleting ${mod.displayName}`, handleErr, reporter);
13052
- }
13053
- if (updates.length) {
13054
- await runConcurrently(updates.map(e => ({ slug: e.slug, run: () => mod.update(http, e.local, e.remote.id) })), concurrency, `Updating ${mod.displayName}`, handleErr, reporter);
13055
- }
13056
- if (creates.length) {
13057
- await runConcurrently(creates.map(e => ({ slug: e.slug, run: () => mod.create(http, e.local) })), concurrency, `Creating ${mod.displayName}`, handleErr, reporter);
13058
- }
13257
+ await runAllAtOnce(deletes.map(e => ({ slug: e.slug, run: () => mod.delete(http, e.remote.id) })), `Deleting ${mod.displayName}`, handleErr, reporter);
13258
+ await runAllAtOnce(updates.map(e => ({ slug: e.slug, run: () => mod.update(http, e.local, e.remote.id) })), `Updating ${mod.displayName}`, handleErr, reporter);
13259
+ await runAllAtOnce(creates.map(e => ({ slug: e.slug, run: () => mod.create(http, e.local) })), `Creating ${mod.displayName}`, handleErr, reporter);
13059
13260
  }
13060
13261
  return { errors };
13061
13262
  }
13062
- function diffObjectFields(local, remote, ignoredFields) {
13263
+ function diffObjectFields(rawLocal, rawRemote, ignoredFields, unorderedPaths = []) {
13264
+ const local = sortUnorderedArrays(rawLocal, unorderedPaths);
13265
+ const remote = sortUnorderedArrays(rawRemote, unorderedPaths);
13063
13266
  const allKeys = new Set([...Object.keys(local), ...Object.keys(remote)]);
13064
13267
  const changed = [];
13065
13268
  for (const key of allKeys) {
@@ -13071,17 +13274,23 @@ function diffObjectFields(local, remote, ignoredFields) {
13071
13274
  }
13072
13275
  return changed;
13073
13276
  }
13074
- function diffSchemaFields(local, remote, ignoredFields) {
13075
- return diffObjectFields(local, remote, ignoredFields);
13277
+ function diffSchemaFields(local, remote, ignoredFields, unorderedPaths = []) {
13278
+ return diffObjectFields(local, remote, ignoredFields, unorderedPaths);
13279
+ }
13280
+ function stringifyForDiff(data) {
13281
+ return YAML.stringify(data, { sortMapEntries: true });
13076
13282
  }
13077
13283
  function buildUnifiedDiff(oldContent, newContent, filename) {
13078
13284
  return createTwoFilesPatch(`remote/${filename}`, `local/${filename}`, oldContent, newContent);
13079
13285
  }
13080
- function renderSchemaDetail(localData, remoteData, ignoredFields) {
13081
- const localYaml = YAML.stringify(omit(localData, ignoredFields));
13082
- const remoteYaml = YAML.stringify(omit(remoteData, ignoredFields));
13286
+ function renderSchemaDetail(localData, remoteData, ignoredFields, unorderedPaths = []) {
13287
+ const localYaml = stringifyForDiff(sortUnorderedArrays(omit(localData, ignoredFields), unorderedPaths));
13288
+ const remoteYaml = stringifyForDiff(sortUnorderedArrays(omit(remoteData, ignoredFields), unorderedPaths));
13083
13289
  return { schema: buildUnifiedDiff(remoteYaml, localYaml, "schema.yaml") };
13084
13290
  }
13291
+ function runAllAtOnce(tasks, label, onError, reporter) {
13292
+ return runConcurrently(tasks, tasks.length, label, onError, reporter);
13293
+ }
13085
13294
  async function runConcurrently(tasks, concurrency, label, onError, reporter) {
13086
13295
  if (!tasks.length)
13087
13296
  return;
@@ -13089,21 +13298,13 @@ async function runConcurrently(tasks, concurrency, label, onError, reporter) {
13089
13298
  let done = 0;
13090
13299
  const progress = reporter.progress(label, total);
13091
13300
  try {
13092
- const limit = Math.max(1, Math.min(total, concurrency));
13093
- let batch = [];
13094
- for (let i = 0; i < tasks.length; i++) {
13095
- batch.push(tasks[i]);
13096
- if (batch.length === limit || i === tasks.length - 1) {
13097
- await Promise.all(batch.map(task => task
13098
- .run()
13099
- .catch((e) => onError(`${label}: ${task.slug}`, e))
13100
- .finally(() => {
13101
- done++;
13102
- progress.update(task.slug, done, total);
13103
- })));
13104
- batch = [];
13105
- }
13106
- }
13301
+ await mapWithConcurrency(tasks, concurrency, task => task
13302
+ .run()
13303
+ .catch((e) => onError(`${label}: ${task.slug}`, e))
13304
+ .finally(() => {
13305
+ done++;
13306
+ progress.update(task.slug, done, total);
13307
+ }));
13107
13308
  progress.succeed();
13108
13309
  }
13109
13310
  catch (e) {
@@ -13119,12 +13320,26 @@ function formatError(e) {
13119
13320
  return String(e);
13120
13321
  }
13121
13322
 
13122
- const IGNORED_FIELDS$3 = ["_id"];
13323
+ const KEY_FIELDS = ["_id", "id"];
13324
+ function recordKeyField(record) {
13325
+ if (record === null || typeof record != "object") {
13326
+ return undefined;
13327
+ }
13328
+ return KEY_FIELDS.find(field => field in record);
13329
+ }
13330
+ function recordKey(record) {
13331
+ const field = recordKeyField(record);
13332
+ return field ? record[field] : undefined;
13333
+ }
13334
+
13335
+ const IGNORED_FIELDS$3 = [...KEY_FIELDS, "order"];
13336
+ const UNORDERED_PATHS$1 = ["required", "properties.**.required", "indexes"];
13123
13337
  const bucketModule = {
13124
13338
  name: "bucket",
13125
13339
  displayName: "Bucket",
13126
13340
  identityField: "title",
13127
13341
  ignoredFields: IGNORED_FIELDS$3,
13342
+ unorderedPaths: UNORDERED_PATHS$1,
13128
13343
  readLocal(rootDir, source) {
13129
13344
  return readLocalSchemas(rootDir, "bucket", source);
13130
13345
  },
@@ -13133,7 +13348,7 @@ const bucketModule = {
13133
13348
  const buckets = unwrapList(res);
13134
13349
  return buckets.map(b => ({
13135
13350
  slug: sanitizeSlug(b.title),
13136
- id: b._id,
13351
+ id: recordKey(b),
13137
13352
  data: b
13138
13353
  }));
13139
13354
  },
@@ -13153,21 +13368,21 @@ const bucketModule = {
13153
13368
  deleteLocalSchema(rootDir, "bucket", slug);
13154
13369
  },
13155
13370
  diffFields(local, remote) {
13156
- return diffSchemaFields(local, remote, IGNORED_FIELDS$3);
13371
+ return diffSchemaFields(local, remote, IGNORED_FIELDS$3, UNORDERED_PATHS$1);
13157
13372
  },
13158
13373
  renderDetail(local, remote) {
13159
- return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS$3);
13374
+ return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS$3, UNORDERED_PATHS$1);
13160
13375
  },
13161
13376
  summaryLine(resource) {
13162
13377
  const propCount = Object.keys(resource.data.properties ?? {}).length;
13163
13378
  return `${propCount} properties`;
13164
13379
  },
13165
13380
  extractLocalId(data) {
13166
- return data._id;
13381
+ return recordKey(data);
13167
13382
  }
13168
13383
  };
13169
13384
 
13170
- const IGNORED_FIELDS$2 = ["_id", "updated_at"];
13385
+ const IGNORED_FIELDS$2 = [...KEY_FIELDS, "updated_at"];
13171
13386
  const envVarModule = {
13172
13387
  name: "env-var",
13173
13388
  displayName: "Environment Variable",
@@ -13181,7 +13396,7 @@ const envVarModule = {
13181
13396
  const items = unwrapList(res);
13182
13397
  return items.map(e => ({
13183
13398
  slug: sanitizeSlug(e.key),
13184
- id: e._id,
13399
+ id: recordKey(e),
13185
13400
  data: e
13186
13401
  }));
13187
13402
  },
@@ -13210,7 +13425,7 @@ const envVarModule = {
13210
13425
  return `key: ${resource.data.key}`;
13211
13426
  },
13212
13427
  extractLocalId(data) {
13213
- return data._id;
13428
+ return recordKey(data);
13214
13429
  }
13215
13430
  };
13216
13431
 
@@ -15935,15 +16150,14 @@ function requireSemver () {
15935
16150
  var semverExports = requireSemver();
15936
16151
  var semver = /*@__PURE__*/getDefaultExportFromCjs(semverExports);
15937
16152
 
15938
- const SCHEMA_IGNORED = ["_id", "env_vars", "secrets"];
16153
+ const SCHEMA_IGNORED = [...KEY_FIELDS, "env_vars", "secrets", "order"];
16154
+ const SCHEMA_UNORDERED = ["triggers.*.options.authenticate"];
15939
16155
  function indexFilename(language) {
15940
16156
  return language === "typescript" ? "index.ts" : "index.mjs";
15941
16157
  }
15942
16158
  function extractId(v) {
15943
- if (v && typeof v === "object" && "_id" in v) {
15944
- return String(v._id);
15945
- }
15946
- return String(v);
16159
+ const key = recordKey(v);
16160
+ return key === undefined ? String(v) : String(key);
15947
16161
  }
15948
16162
  function byCodeUnit(a, b) {
15949
16163
  if (a === b)
@@ -15960,14 +16174,6 @@ function normalizeSchema(schema) {
15960
16174
  }
15961
16175
  return normalized;
15962
16176
  }
15963
- async function mapInBatches(items, size, fn) {
15964
- const limit = Math.max(1, size);
15965
- const results = [];
15966
- for (let i = 0; i < items.length; i += limit) {
15967
- results.push(...(await Promise.all(items.slice(i, i + limit).map(fn))));
15968
- }
15969
- return results;
15970
- }
15971
16177
  function isNotFoundError(error) {
15972
16178
  if (!error || typeof error !== "object")
15973
16179
  return false;
@@ -16000,6 +16206,7 @@ const functionModule = {
16000
16206
  displayName: "Function",
16001
16207
  identityField: "name",
16002
16208
  ignoredFields: SCHEMA_IGNORED,
16209
+ unorderedPaths: SCHEMA_UNORDERED,
16003
16210
  readSchema(rootDir, slug, source = diskSource) {
16004
16211
  return readSourceYaml(source, path.join(rootDir, "function", slug, "schema.yaml"));
16005
16212
  },
@@ -16031,11 +16238,11 @@ const functionModule = {
16031
16238
  }
16032
16239
  return results;
16033
16240
  },
16034
- async readRemote(http, options = {}) {
16241
+ async readRemote(http) {
16035
16242
  const res = await http.get("function");
16036
16243
  const fns = unwrapList(res);
16037
- return mapInBatches(fns, options.concurrency ?? DEFAULT_CONCURRENCY, async (fn) => {
16038
- const id = fn._id;
16244
+ return Promise.all(fns.map(async (fn) => {
16245
+ const id = recordKey(fn);
16039
16246
  const [indexRes, depsRes] = await Promise.all([
16040
16247
  http.get(`function/${id}/index`).catch(emptyIfMissing({ index: "" })),
16041
16248
  http
@@ -16057,7 +16264,7 @@ const functionModule = {
16057
16264
  dependencies
16058
16265
  }
16059
16266
  };
16060
- });
16267
+ }));
16061
16268
  },
16062
16269
  async create(http, local) {
16063
16270
  const id = await this.createSchema(http, local.data.schema);
@@ -16068,7 +16275,7 @@ const functionModule = {
16068
16275
  },
16069
16276
  async createSchema(http, schema) {
16070
16277
  const created = await http.post("function", omit(schema, ["env_vars", "secrets"]));
16071
- const id = (created._id ?? schema._id);
16278
+ const id = recordKey(created) ?? recordKey(schema);
16072
16279
  if (!id)
16073
16280
  return undefined;
16074
16281
  const envVarIds = schema.env_vars ?? [];
@@ -16151,7 +16358,7 @@ const functionModule = {
16151
16358
  },
16152
16359
  diffFields(local, remote) {
16153
16360
  const changed = [];
16154
- const schemaChanged = diffObjectFields(local.schema, remote.schema, SCHEMA_IGNORED);
16361
+ const schemaChanged = diffObjectFields(local.schema, remote.schema, SCHEMA_IGNORED, SCHEMA_UNORDERED);
16155
16362
  if (schemaChanged.length)
16156
16363
  changed.push("schema");
16157
16364
  if (local.index !== remote.index)
@@ -16170,8 +16377,8 @@ const functionModule = {
16170
16377
  },
16171
16378
  renderDetail(local, remote) {
16172
16379
  const result = {};
16173
- const localSchemaYaml = YAML.stringify(omit(local.data.schema, SCHEMA_IGNORED));
16174
- const remoteSchemaYaml = YAML.stringify(omit(remote.data.schema, SCHEMA_IGNORED));
16380
+ const localSchemaYaml = stringifyForDiff(sortUnorderedArrays(omit(local.data.schema, SCHEMA_IGNORED), SCHEMA_UNORDERED));
16381
+ const remoteSchemaYaml = stringifyForDiff(sortUnorderedArrays(omit(remote.data.schema, SCHEMA_IGNORED), SCHEMA_UNORDERED));
16175
16382
  if (localSchemaYaml !== remoteSchemaYaml) {
16176
16383
  result["schema"] = buildUnifiedDiff(remoteSchemaYaml, localSchemaYaml, "schema.yaml");
16177
16384
  }
@@ -16191,7 +16398,7 @@ const functionModule = {
16191
16398
  return `${triggerCount} trigger${triggerCount !== 1 ? "s" : ""}`;
16192
16399
  },
16193
16400
  extractLocalId(data) {
16194
- return data.schema._id;
16401
+ return recordKey(data.schema);
16195
16402
  },
16196
16403
  watchedFiles: ["schema.yaml", "index.ts", "index.mjs", "index.js", "package.json"],
16197
16404
  async devHandleEvent(ctx) {
@@ -16218,7 +16425,7 @@ const functionModule = {
16218
16425
  const schema = self.readSchema(rootDir, slug);
16219
16426
  if (!schema)
16220
16427
  return;
16221
- const newLocalId = schema._id;
16428
+ const newLocalId = recordKey(schema);
16222
16429
  if (newLocalId) {
16223
16430
  const pending = consumePendingDeleteByRemoteId(newLocalId);
16224
16431
  if (pending) {
@@ -16279,12 +16486,18 @@ const functionModule = {
16279
16486
  }
16280
16487
  };
16281
16488
 
16282
- const IGNORED_FIELDS$1 = ["_id", "system"];
16489
+ const IGNORED_FIELDS$1 = [...KEY_FIELDS, "system"];
16490
+ const UNORDERED_PATHS = [
16491
+ "statement",
16492
+ "statement.*.resource.include",
16493
+ "statement.*.resource.exclude"
16494
+ ];
16283
16495
  const policyModule = {
16284
16496
  name: "policy",
16285
16497
  displayName: "Policy",
16286
16498
  identityField: "name",
16287
16499
  ignoredFields: IGNORED_FIELDS$1,
16500
+ unorderedPaths: UNORDERED_PATHS,
16288
16501
  readLocal(rootDir, source) {
16289
16502
  return readLocalSchemas(rootDir, "policy", source);
16290
16503
  },
@@ -16295,7 +16508,7 @@ const policyModule = {
16295
16508
  .filter(p => !p.system)
16296
16509
  .map(p => ({
16297
16510
  slug: sanitizeSlug(p.name),
16298
- id: p._id,
16511
+ id: recordKey(p),
16299
16512
  data: p
16300
16513
  }));
16301
16514
  },
@@ -16317,21 +16530,21 @@ const policyModule = {
16317
16530
  deleteLocalSchema(rootDir, "policy", slug);
16318
16531
  },
16319
16532
  diffFields(local, remote) {
16320
- return diffSchemaFields(local, remote, IGNORED_FIELDS$1);
16533
+ return diffSchemaFields(local, remote, IGNORED_FIELDS$1, UNORDERED_PATHS);
16321
16534
  },
16322
16535
  renderDetail(local, remote) {
16323
- return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS$1);
16536
+ return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS$1, UNORDERED_PATHS);
16324
16537
  },
16325
16538
  summaryLine(resource) {
16326
16539
  const stmts = resource.data.statement?.length ?? 0;
16327
16540
  return `${stmts} statement${stmts !== 1 ? "s" : ""}`;
16328
16541
  },
16329
16542
  extractLocalId(data) {
16330
- return data._id;
16543
+ return recordKey(data);
16331
16544
  }
16332
16545
  };
16333
16546
 
16334
- const IGNORED_FIELDS = ["_id", "value", "updated_at"];
16547
+ const IGNORED_FIELDS = [...KEY_FIELDS, "value", "updated_at"];
16335
16548
  const secretModule = {
16336
16549
  name: "secret",
16337
16550
  displayName: "Secret",
@@ -16345,7 +16558,7 @@ const secretModule = {
16345
16558
  const items = unwrapList(res);
16346
16559
  return items.map(s => ({
16347
16560
  slug: sanitizeSlug(s.key),
16348
- id: s._id,
16561
+ id: recordKey(s),
16349
16562
  data: s
16350
16563
  }));
16351
16564
  },
@@ -16374,7 +16587,7 @@ const secretModule = {
16374
16587
  return `key: ${resource.data.key}`;
16375
16588
  },
16376
16589
  extractLocalId(data) {
16377
- return data._id;
16590
+ return recordKey(data);
16378
16591
  }
16379
16592
  };
16380
16593