@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.mjs CHANGED
@@ -260,6 +260,85 @@ var ChangeKind;
260
260
  })(ChangeKind || (ChangeKind = {}));
261
261
  const DEFAULT_CONCURRENCY = 10;
262
262
 
263
+ const REQUEST_METHODS = ["get", "delete", "head", "post", "patch", "put"];
264
+ const limitedClients = new WeakMap();
265
+ function limitConcurrency(http, limit = DEFAULT_CONCURRENCY, signal) {
266
+ const existing = limitedClients.get(http);
267
+ if (existing && !signal)
268
+ return http;
269
+ const { semaphore, target } = existing ?? {
270
+ semaphore: new Semaphore(normalizeLimit(limit)),
271
+ target: http
272
+ };
273
+ const limited = { ...target };
274
+ for (const method of REQUEST_METHODS) {
275
+ limited[method] = (...args) => semaphore.run(() => {
276
+ if (signal?.aborted)
277
+ throw signal.reason;
278
+ return target[method](...args);
279
+ });
280
+ }
281
+ limitedClients.set(limited, { semaphore, target });
282
+ return limited;
283
+ }
284
+ async function mapWithConcurrency(items, limit, fn) {
285
+ const results = new Array(items.length);
286
+ let next = 0;
287
+ let failure;
288
+ const worker = async () => {
289
+ while (!failure && next < items.length) {
290
+ const index = next++;
291
+ try {
292
+ results[index] = await fn(items[index], index);
293
+ }
294
+ catch (error) {
295
+ if (!failure)
296
+ failure = { error };
297
+ }
298
+ }
299
+ };
300
+ const workerCount = Math.min(normalizeLimit(limit), items.length);
301
+ await Promise.all(Array.from({ length: workerCount }, worker));
302
+ if (failure)
303
+ throw failure.error;
304
+ return results;
305
+ }
306
+ function normalizeLimit(limit) {
307
+ return Number.isFinite(limit) ? Math.max(1, Math.floor(limit)) : DEFAULT_CONCURRENCY;
308
+ }
309
+ class Semaphore {
310
+ constructor(limit) {
311
+ this.limit = limit;
312
+ this.active = 0;
313
+ this.waiting = [];
314
+ }
315
+ async run(task) {
316
+ await this.acquire();
317
+ try {
318
+ return await task();
319
+ }
320
+ finally {
321
+ this.release();
322
+ }
323
+ }
324
+ acquire() {
325
+ if (this.active < this.limit) {
326
+ this.active++;
327
+ return Promise.resolve();
328
+ }
329
+ return new Promise(resolve => this.waiting.push(resolve));
330
+ }
331
+ release() {
332
+ const next = this.waiting.shift();
333
+ if (next) {
334
+ next();
335
+ }
336
+ else {
337
+ this.active--;
338
+ }
339
+ }
340
+ }
341
+
263
342
  const noopProgress = {
264
343
  update() { },
265
344
  succeed() { },
@@ -339,7 +418,7 @@ const REMOVE$1 = Symbol('remove node');
339
418
  * and `Node` (alias, map, seq & scalar) targets. Of all these, only the most
340
419
  * specific defined one will be used for each node.
341
420
  */
342
- function visit$1(node, visitor) {
421
+ function visit$2(node, visitor) {
343
422
  const visitor_ = initVisitor(visitor);
344
423
  if (isDocument(node)) {
345
424
  const cd = visit_(null, node.contents, visitor_, Object.freeze([node]));
@@ -353,11 +432,11 @@ function visit$1(node, visitor) {
353
432
  // namespace using `var`, but then complains about that because
354
433
  // `unique symbol` must be `const`.
355
434
  /** Terminate visit traversal completely */
356
- visit$1.BREAK = BREAK$1;
435
+ visit$2.BREAK = BREAK$1;
357
436
  /** Do not visit the children of the current node */
358
- visit$1.SKIP = SKIP$1;
437
+ visit$2.SKIP = SKIP$1;
359
438
  /** Remove the current node */
360
- visit$1.REMOVE = REMOVE$1;
439
+ visit$2.REMOVE = REMOVE$1;
361
440
  function visit_(key, node, visitor, path) {
362
441
  const ctrl = callVisitor(key, node, visitor, path);
363
442
  if (isNode(ctrl) || isPair(ctrl)) {
@@ -688,7 +767,7 @@ class Directives {
688
767
  let tagNames;
689
768
  if (doc && tagEntries.length > 0 && isNode(doc.contents)) {
690
769
  const tags = {};
691
- visit$1(doc.contents, (_key, node) => {
770
+ visit$2(doc.contents, (_key, node) => {
692
771
  if (isNode(node) && node.tag)
693
772
  tags[node.tag] = true;
694
773
  });
@@ -723,7 +802,7 @@ function anchorIsValid(anchor) {
723
802
  }
724
803
  function anchorNames(root) {
725
804
  const anchors = new Set();
726
- visit$1(root, {
805
+ visit$2(root, {
727
806
  Value(_key, node) {
728
807
  if (node.anchor)
729
808
  anchors.add(node.anchor);
@@ -917,7 +996,7 @@ class Alias extends NodeBase {
917
996
  }
918
997
  else {
919
998
  nodes = [];
920
- visit$1(doc, {
999
+ visit$2(doc, {
921
1000
  Node: (_key, node) => {
922
1001
  if (isAlias(node) || hasAnchor(node))
923
1002
  nodes.push(node);
@@ -5714,7 +5793,7 @@ const REMOVE = Symbol('remove item');
5714
5793
  * visitor is called on item entry, next visitors are called after handling
5715
5794
  * a non-empty `key` and when exiting the item.
5716
5795
  */
5717
- function visit(cst, visitor) {
5796
+ function visit$1(cst, visitor) {
5718
5797
  if ('type' in cst && cst.type === 'document')
5719
5798
  cst = { start: cst.start, value: cst.value };
5720
5799
  _visit(Object.freeze([]), cst, visitor);
@@ -5723,13 +5802,13 @@ function visit(cst, visitor) {
5723
5802
  // namespace using `var`, but then complains about that because
5724
5803
  // `unique symbol` must be `const`.
5725
5804
  /** Terminate visit traversal completely */
5726
- visit.BREAK = BREAK;
5805
+ visit$1.BREAK = BREAK;
5727
5806
  /** Do not visit the children of the current item */
5728
- visit.SKIP = SKIP;
5807
+ visit$1.SKIP = SKIP;
5729
5808
  /** Remove the current item */
5730
- visit.REMOVE = REMOVE;
5809
+ visit$1.REMOVE = REMOVE;
5731
5810
  /** Find the item at `path` from `cst` as the root */
5732
- visit.itemAtPath = (cst, path) => {
5811
+ visit$1.itemAtPath = (cst, path) => {
5733
5812
  let item = cst;
5734
5813
  for (const [field, index] of path) {
5735
5814
  const tok = item?.[field];
@@ -5746,8 +5825,8 @@ visit.itemAtPath = (cst, path) => {
5746
5825
  *
5747
5826
  * Throws an error if the collection is not found, which should never happen if the item itself exists.
5748
5827
  */
5749
- visit.parentCollection = (cst, path) => {
5750
- const parent = visit.itemAtPath(cst, path.slice(0, -1));
5828
+ visit$1.parentCollection = (cst, path) => {
5829
+ const parent = visit$1.itemAtPath(cst, path.slice(0, -1));
5751
5830
  const field = path[path.length - 1][0];
5752
5831
  const coll = parent?.[field];
5753
5832
  if (coll && 'items' in coll)
@@ -5886,7 +5965,7 @@ var cst = /*#__PURE__*/Object.freeze({
5886
5965
  setScalarValue: setScalarValue,
5887
5966
  stringify: stringify$1,
5888
5967
  tokenType: tokenType,
5889
- visit: visit
5968
+ visit: visit$1
5890
5969
  });
5891
5970
 
5892
5971
  /*
@@ -7726,7 +7805,7 @@ var YAML = /*#__PURE__*/Object.freeze({
7726
7805
  parseAllDocuments: parseAllDocuments,
7727
7806
  parseDocument: parseDocument,
7728
7807
  stringify: stringify,
7729
- visit: visit$1,
7808
+ visit: visit$2,
7730
7809
  visitAsync: visitAsync
7731
7810
  });
7732
7811
 
@@ -12927,13 +13006,134 @@ function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader
12927
13006
  return ret.join('\n') + '\n';
12928
13007
  }
12929
13008
 
12930
- async function buildPlan(modules, http, rootDir, options = {}) {
13009
+ var isPlainObject_1;
13010
+ var hasRequiredIsPlainObject;
13011
+
13012
+ function requireIsPlainObject () {
13013
+ if (hasRequiredIsPlainObject) return isPlainObject_1;
13014
+ hasRequiredIsPlainObject = 1;
13015
+ var baseGetTag = require_baseGetTag(),
13016
+ getPrototype = require_getPrototype(),
13017
+ isObjectLike = requireIsObjectLike();
13018
+
13019
+ /** `Object#toString` result references. */
13020
+ var objectTag = '[object Object]';
13021
+
13022
+ /** Used for built-in method references. */
13023
+ var funcProto = Function.prototype,
13024
+ objectProto = Object.prototype;
13025
+
13026
+ /** Used to resolve the decompiled source of functions. */
13027
+ var funcToString = funcProto.toString;
13028
+
13029
+ /** Used to check objects for own properties. */
13030
+ var hasOwnProperty = objectProto.hasOwnProperty;
13031
+
13032
+ /** Used to infer the `Object` constructor. */
13033
+ var objectCtorString = funcToString.call(Object);
13034
+
13035
+ /**
13036
+ * Checks if `value` is a plain object, that is, an object created by the
13037
+ * `Object` constructor or one with a `[[Prototype]]` of `null`.
13038
+ *
13039
+ * @static
13040
+ * @memberOf _
13041
+ * @since 0.8.0
13042
+ * @category Lang
13043
+ * @param {*} value The value to check.
13044
+ * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
13045
+ * @example
13046
+ *
13047
+ * function Foo() {
13048
+ * this.a = 1;
13049
+ * }
13050
+ *
13051
+ * _.isPlainObject(new Foo);
13052
+ * // => false
13053
+ *
13054
+ * _.isPlainObject([1, 2, 3]);
13055
+ * // => false
13056
+ *
13057
+ * _.isPlainObject({ 'x': 0, 'y': 0 });
13058
+ * // => true
13059
+ *
13060
+ * _.isPlainObject(Object.create(null));
13061
+ * // => true
13062
+ */
13063
+ function isPlainObject(value) {
13064
+ if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
13065
+ return false;
13066
+ }
13067
+ var proto = getPrototype(value);
13068
+ if (proto === null) {
13069
+ return true;
13070
+ }
13071
+ var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
13072
+ return typeof Ctor == 'function' && Ctor instanceof Ctor &&
13073
+ funcToString.call(Ctor) == objectCtorString;
13074
+ }
13075
+
13076
+ isPlainObject_1 = isPlainObject;
13077
+ return isPlainObject_1;
13078
+ }
13079
+
13080
+ var isPlainObjectExports = requireIsPlainObject();
13081
+ var isPlainObject = /*@__PURE__*/getDefaultExportFromCjs(isPlainObjectExports);
13082
+
13083
+ function sortUnorderedArrays(data, paths = []) {
13084
+ if (!paths.length)
13085
+ return data;
13086
+ return visit(data, [], paths.map(p => p.split(".")));
13087
+ }
13088
+ function visit(node, path, patterns) {
13089
+ let visited = node;
13090
+ if (Array.isArray(node)) {
13091
+ visited = node.map((item, i) => visit(item, [...path, String(i)], patterns));
13092
+ }
13093
+ else if (isPlainObject(node)) {
13094
+ visited = Object.fromEntries(Object.entries(node).map(([k, v]) => [
13095
+ k,
13096
+ visit(v, [...path, k], patterns)
13097
+ ]));
13098
+ }
13099
+ if (Array.isArray(visited) && patterns.some(p => matches(p, path))) {
13100
+ return visited
13101
+ .map(item => ({ item, key: canonical(item) }))
13102
+ .sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0))
13103
+ .map(({ item }) => item);
13104
+ }
13105
+ return visited;
13106
+ }
13107
+ function matches(pattern, path) {
13108
+ if (!pattern.length)
13109
+ return !path.length;
13110
+ const [head, ...rest] = pattern;
13111
+ if (head === "**") {
13112
+ return matches(rest, path) || (path.length > 0 && matches(pattern, path.slice(1)));
13113
+ }
13114
+ return path.length > 0 && (head === "*" || head === path[0]) && matches(rest, path.slice(1));
13115
+ }
13116
+ function canonical(value) {
13117
+ if (Array.isArray(value))
13118
+ return `[${value.map(canonical).join(",")}]`;
13119
+ if (isPlainObject(value)) {
13120
+ const obj = value;
13121
+ const entries = Object.keys(obj)
13122
+ .sort()
13123
+ .map(k => `${JSON.stringify(k)}:${canonical(obj[k])}`);
13124
+ return `{${entries.join(",")}}`;
13125
+ }
13126
+ return JSON.stringify(value) ?? "undefined";
13127
+ }
13128
+
13129
+ async function buildPlan(modules, unlimitedHttp, rootDir, options = {}) {
12931
13130
  const { detailed = false, detectRenames = true, reporter = silentReporter, concurrency = DEFAULT_CONCURRENCY, source } = options;
13131
+ const http = limitConcurrency(unlimitedHttp, concurrency);
12932
13132
  const modulePlans = [];
12933
13133
  for (const mod of modules) {
12934
13134
  const [locals, remotes] = await Promise.all([
12935
13135
  reporter.task(`Reading local ${mod.displayName} files`, () => mod.readLocal(rootDir, source)),
12936
- reporter.task(`Fetching remote ${mod.displayName}`, () => mod.readRemote(http, { concurrency }))
13136
+ reporter.task(`Fetching remote ${mod.displayName}`, () => mod.readRemote(http))
12937
13137
  ]);
12938
13138
  const localBySlug = new Map(locals.map(l => [l.slug, l]));
12939
13139
  const remoteBySlug = new Map(remotes.map(r => [r.slug, r]));
@@ -13012,33 +13212,36 @@ async function buildPlan(modules, http, rootDir, options = {}) {
13012
13212
  }
13013
13213
  return { modules: modulePlans };
13014
13214
  }
13015
- async function applyPlan(plan, http, opts = {}) {
13215
+ async function applyPlan(plan, unlimitedHttp, opts = {}) {
13016
13216
  const concurrency = opts.concurrency ?? DEFAULT_CONCURRENCY;
13017
13217
  const reporter = opts.reporter ?? silentReporter;
13018
13218
  const errors = [];
13219
+ const abortController = new AbortController();
13220
+ const http = limitConcurrency(unlimitedHttp, concurrency, abortController.signal);
13221
+ let abortError;
13019
13222
  const handleErr = (label, e) => {
13020
- const msg = formatError(e);
13021
- const full = `${label}: ${msg}`;
13022
- if (opts.abortOnError)
13023
- throw new Error(full);
13223
+ if (abortError)
13224
+ throw abortError;
13225
+ const full = `${label}: ${formatError(e)}`;
13226
+ if (opts.abortOnError) {
13227
+ abortError = new Error(full);
13228
+ abortController.abort(abortError);
13229
+ throw abortError;
13230
+ }
13024
13231
  reporter.warn(full);
13025
13232
  errors.push(full);
13026
13233
  };
13027
13234
  for (const mp of plan.modules) {
13028
13235
  const { module: mod, creates, updates, deletes } = mp;
13029
- if (deletes.length) {
13030
- await runConcurrently(deletes.map(e => ({ slug: e.slug, run: () => mod.delete(http, e.remote.id) })), concurrency, `Deleting ${mod.displayName}`, handleErr, reporter);
13031
- }
13032
- if (updates.length) {
13033
- await runConcurrently(updates.map(e => ({ slug: e.slug, run: () => mod.update(http, e.local, e.remote.id) })), concurrency, `Updating ${mod.displayName}`, handleErr, reporter);
13034
- }
13035
- if (creates.length) {
13036
- await runConcurrently(creates.map(e => ({ slug: e.slug, run: () => mod.create(http, e.local) })), concurrency, `Creating ${mod.displayName}`, handleErr, reporter);
13037
- }
13236
+ await runAllAtOnce(deletes.map(e => ({ slug: e.slug, run: () => mod.delete(http, e.remote.id) })), `Deleting ${mod.displayName}`, handleErr, reporter);
13237
+ await runAllAtOnce(updates.map(e => ({ slug: e.slug, run: () => mod.update(http, e.local, e.remote.id) })), `Updating ${mod.displayName}`, handleErr, reporter);
13238
+ await runAllAtOnce(creates.map(e => ({ slug: e.slug, run: () => mod.create(http, e.local) })), `Creating ${mod.displayName}`, handleErr, reporter);
13038
13239
  }
13039
13240
  return { errors };
13040
13241
  }
13041
- function diffObjectFields(local, remote, ignoredFields) {
13242
+ function diffObjectFields(rawLocal, rawRemote, ignoredFields, unorderedPaths = []) {
13243
+ const local = sortUnorderedArrays(rawLocal, unorderedPaths);
13244
+ const remote = sortUnorderedArrays(rawRemote, unorderedPaths);
13042
13245
  const allKeys = new Set([...Object.keys(local), ...Object.keys(remote)]);
13043
13246
  const changed = [];
13044
13247
  for (const key of allKeys) {
@@ -13050,17 +13253,23 @@ function diffObjectFields(local, remote, ignoredFields) {
13050
13253
  }
13051
13254
  return changed;
13052
13255
  }
13053
- function diffSchemaFields(local, remote, ignoredFields) {
13054
- return diffObjectFields(local, remote, ignoredFields);
13256
+ function diffSchemaFields(local, remote, ignoredFields, unorderedPaths = []) {
13257
+ return diffObjectFields(local, remote, ignoredFields, unorderedPaths);
13258
+ }
13259
+ function stringifyForDiff(data) {
13260
+ return YAML.stringify(data, { sortMapEntries: true });
13055
13261
  }
13056
13262
  function buildUnifiedDiff(oldContent, newContent, filename) {
13057
13263
  return createTwoFilesPatch(`remote/${filename}`, `local/${filename}`, oldContent, newContent);
13058
13264
  }
13059
- function renderSchemaDetail(localData, remoteData, ignoredFields) {
13060
- const localYaml = YAML.stringify(omit(localData, ignoredFields));
13061
- const remoteYaml = YAML.stringify(omit(remoteData, ignoredFields));
13265
+ function renderSchemaDetail(localData, remoteData, ignoredFields, unorderedPaths = []) {
13266
+ const localYaml = stringifyForDiff(sortUnorderedArrays(omit(localData, ignoredFields), unorderedPaths));
13267
+ const remoteYaml = stringifyForDiff(sortUnorderedArrays(omit(remoteData, ignoredFields), unorderedPaths));
13062
13268
  return { schema: buildUnifiedDiff(remoteYaml, localYaml, "schema.yaml") };
13063
13269
  }
13270
+ function runAllAtOnce(tasks, label, onError, reporter) {
13271
+ return runConcurrently(tasks, tasks.length, label, onError, reporter);
13272
+ }
13064
13273
  async function runConcurrently(tasks, concurrency, label, onError, reporter) {
13065
13274
  if (!tasks.length)
13066
13275
  return;
@@ -13068,21 +13277,13 @@ async function runConcurrently(tasks, concurrency, label, onError, reporter) {
13068
13277
  let done = 0;
13069
13278
  const progress = reporter.progress(label, total);
13070
13279
  try {
13071
- const limit = Math.max(1, Math.min(total, concurrency));
13072
- let batch = [];
13073
- for (let i = 0; i < tasks.length; i++) {
13074
- batch.push(tasks[i]);
13075
- if (batch.length === limit || i === tasks.length - 1) {
13076
- await Promise.all(batch.map(task => task
13077
- .run()
13078
- .catch((e) => onError(`${label}: ${task.slug}`, e))
13079
- .finally(() => {
13080
- done++;
13081
- progress.update(task.slug, done, total);
13082
- })));
13083
- batch = [];
13084
- }
13085
- }
13280
+ await mapWithConcurrency(tasks, concurrency, task => task
13281
+ .run()
13282
+ .catch((e) => onError(`${label}: ${task.slug}`, e))
13283
+ .finally(() => {
13284
+ done++;
13285
+ progress.update(task.slug, done, total);
13286
+ }));
13086
13287
  progress.succeed();
13087
13288
  }
13088
13289
  catch (e) {
@@ -13098,12 +13299,26 @@ function formatError(e) {
13098
13299
  return String(e);
13099
13300
  }
13100
13301
 
13101
- const IGNORED_FIELDS$3 = ["_id"];
13302
+ const KEY_FIELDS = ["_id", "id"];
13303
+ function recordKeyField(record) {
13304
+ if (record === null || typeof record != "object") {
13305
+ return undefined;
13306
+ }
13307
+ return KEY_FIELDS.find(field => field in record);
13308
+ }
13309
+ function recordKey(record) {
13310
+ const field = recordKeyField(record);
13311
+ return field ? record[field] : undefined;
13312
+ }
13313
+
13314
+ const IGNORED_FIELDS$3 = [...KEY_FIELDS, "order"];
13315
+ const UNORDERED_PATHS$1 = ["required", "properties.**.required", "indexes"];
13102
13316
  const bucketModule = {
13103
13317
  name: "bucket",
13104
13318
  displayName: "Bucket",
13105
13319
  identityField: "title",
13106
13320
  ignoredFields: IGNORED_FIELDS$3,
13321
+ unorderedPaths: UNORDERED_PATHS$1,
13107
13322
  readLocal(rootDir, source) {
13108
13323
  return readLocalSchemas(rootDir, "bucket", source);
13109
13324
  },
@@ -13112,7 +13327,7 @@ const bucketModule = {
13112
13327
  const buckets = unwrapList(res);
13113
13328
  return buckets.map(b => ({
13114
13329
  slug: sanitizeSlug(b.title),
13115
- id: b._id,
13330
+ id: recordKey(b),
13116
13331
  data: b
13117
13332
  }));
13118
13333
  },
@@ -13132,21 +13347,21 @@ const bucketModule = {
13132
13347
  deleteLocalSchema(rootDir, "bucket", slug);
13133
13348
  },
13134
13349
  diffFields(local, remote) {
13135
- return diffSchemaFields(local, remote, IGNORED_FIELDS$3);
13350
+ return diffSchemaFields(local, remote, IGNORED_FIELDS$3, UNORDERED_PATHS$1);
13136
13351
  },
13137
13352
  renderDetail(local, remote) {
13138
- return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS$3);
13353
+ return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS$3, UNORDERED_PATHS$1);
13139
13354
  },
13140
13355
  summaryLine(resource) {
13141
13356
  const propCount = Object.keys(resource.data.properties ?? {}).length;
13142
13357
  return `${propCount} properties`;
13143
13358
  },
13144
13359
  extractLocalId(data) {
13145
- return data._id;
13360
+ return recordKey(data);
13146
13361
  }
13147
13362
  };
13148
13363
 
13149
- const IGNORED_FIELDS$2 = ["_id", "updated_at"];
13364
+ const IGNORED_FIELDS$2 = [...KEY_FIELDS, "updated_at"];
13150
13365
  const envVarModule = {
13151
13366
  name: "env-var",
13152
13367
  displayName: "Environment Variable",
@@ -13160,7 +13375,7 @@ const envVarModule = {
13160
13375
  const items = unwrapList(res);
13161
13376
  return items.map(e => ({
13162
13377
  slug: sanitizeSlug(e.key),
13163
- id: e._id,
13378
+ id: recordKey(e),
13164
13379
  data: e
13165
13380
  }));
13166
13381
  },
@@ -13189,7 +13404,7 @@ const envVarModule = {
13189
13404
  return `key: ${resource.data.key}`;
13190
13405
  },
13191
13406
  extractLocalId(data) {
13192
- return data._id;
13407
+ return recordKey(data);
13193
13408
  }
13194
13409
  };
13195
13410
 
@@ -15914,15 +16129,14 @@ function requireSemver () {
15914
16129
  var semverExports = requireSemver();
15915
16130
  var semver = /*@__PURE__*/getDefaultExportFromCjs(semverExports);
15916
16131
 
15917
- const SCHEMA_IGNORED = ["_id", "env_vars", "secrets"];
16132
+ const SCHEMA_IGNORED = [...KEY_FIELDS, "env_vars", "secrets", "order"];
16133
+ const SCHEMA_UNORDERED = ["triggers.*.options.authenticate"];
15918
16134
  function indexFilename(language) {
15919
16135
  return language === "typescript" ? "index.ts" : "index.mjs";
15920
16136
  }
15921
16137
  function extractId(v) {
15922
- if (v && typeof v === "object" && "_id" in v) {
15923
- return String(v._id);
15924
- }
15925
- return String(v);
16138
+ const key = recordKey(v);
16139
+ return key === undefined ? String(v) : String(key);
15926
16140
  }
15927
16141
  function byCodeUnit(a, b) {
15928
16142
  if (a === b)
@@ -15939,14 +16153,6 @@ function normalizeSchema(schema) {
15939
16153
  }
15940
16154
  return normalized;
15941
16155
  }
15942
- async function mapInBatches(items, size, fn) {
15943
- const limit = Math.max(1, size);
15944
- const results = [];
15945
- for (let i = 0; i < items.length; i += limit) {
15946
- results.push(...(await Promise.all(items.slice(i, i + limit).map(fn))));
15947
- }
15948
- return results;
15949
- }
15950
16156
  function isNotFoundError(error) {
15951
16157
  if (!error || typeof error !== "object")
15952
16158
  return false;
@@ -15979,6 +16185,7 @@ const functionModule = {
15979
16185
  displayName: "Function",
15980
16186
  identityField: "name",
15981
16187
  ignoredFields: SCHEMA_IGNORED,
16188
+ unorderedPaths: SCHEMA_UNORDERED,
15982
16189
  readSchema(rootDir, slug, source = diskSource) {
15983
16190
  return readSourceYaml(source, path.join(rootDir, "function", slug, "schema.yaml"));
15984
16191
  },
@@ -16010,11 +16217,11 @@ const functionModule = {
16010
16217
  }
16011
16218
  return results;
16012
16219
  },
16013
- async readRemote(http, options = {}) {
16220
+ async readRemote(http) {
16014
16221
  const res = await http.get("function");
16015
16222
  const fns = unwrapList(res);
16016
- return mapInBatches(fns, options.concurrency ?? DEFAULT_CONCURRENCY, async (fn) => {
16017
- const id = fn._id;
16223
+ return Promise.all(fns.map(async (fn) => {
16224
+ const id = recordKey(fn);
16018
16225
  const [indexRes, depsRes] = await Promise.all([
16019
16226
  http.get(`function/${id}/index`).catch(emptyIfMissing({ index: "" })),
16020
16227
  http
@@ -16036,7 +16243,7 @@ const functionModule = {
16036
16243
  dependencies
16037
16244
  }
16038
16245
  };
16039
- });
16246
+ }));
16040
16247
  },
16041
16248
  async create(http, local) {
16042
16249
  const id = await this.createSchema(http, local.data.schema);
@@ -16047,7 +16254,7 @@ const functionModule = {
16047
16254
  },
16048
16255
  async createSchema(http, schema) {
16049
16256
  const created = await http.post("function", omit(schema, ["env_vars", "secrets"]));
16050
- const id = (created._id ?? schema._id);
16257
+ const id = recordKey(created) ?? recordKey(schema);
16051
16258
  if (!id)
16052
16259
  return undefined;
16053
16260
  const envVarIds = schema.env_vars ?? [];
@@ -16130,7 +16337,7 @@ const functionModule = {
16130
16337
  },
16131
16338
  diffFields(local, remote) {
16132
16339
  const changed = [];
16133
- const schemaChanged = diffObjectFields(local.schema, remote.schema, SCHEMA_IGNORED);
16340
+ const schemaChanged = diffObjectFields(local.schema, remote.schema, SCHEMA_IGNORED, SCHEMA_UNORDERED);
16134
16341
  if (schemaChanged.length)
16135
16342
  changed.push("schema");
16136
16343
  if (local.index !== remote.index)
@@ -16149,8 +16356,8 @@ const functionModule = {
16149
16356
  },
16150
16357
  renderDetail(local, remote) {
16151
16358
  const result = {};
16152
- const localSchemaYaml = YAML.stringify(omit(local.data.schema, SCHEMA_IGNORED));
16153
- const remoteSchemaYaml = YAML.stringify(omit(remote.data.schema, SCHEMA_IGNORED));
16359
+ const localSchemaYaml = stringifyForDiff(sortUnorderedArrays(omit(local.data.schema, SCHEMA_IGNORED), SCHEMA_UNORDERED));
16360
+ const remoteSchemaYaml = stringifyForDiff(sortUnorderedArrays(omit(remote.data.schema, SCHEMA_IGNORED), SCHEMA_UNORDERED));
16154
16361
  if (localSchemaYaml !== remoteSchemaYaml) {
16155
16362
  result["schema"] = buildUnifiedDiff(remoteSchemaYaml, localSchemaYaml, "schema.yaml");
16156
16363
  }
@@ -16170,7 +16377,7 @@ const functionModule = {
16170
16377
  return `${triggerCount} trigger${triggerCount !== 1 ? "s" : ""}`;
16171
16378
  },
16172
16379
  extractLocalId(data) {
16173
- return data.schema._id;
16380
+ return recordKey(data.schema);
16174
16381
  },
16175
16382
  watchedFiles: ["schema.yaml", "index.ts", "index.mjs", "index.js", "package.json"],
16176
16383
  async devHandleEvent(ctx) {
@@ -16197,7 +16404,7 @@ const functionModule = {
16197
16404
  const schema = self.readSchema(rootDir, slug);
16198
16405
  if (!schema)
16199
16406
  return;
16200
- const newLocalId = schema._id;
16407
+ const newLocalId = recordKey(schema);
16201
16408
  if (newLocalId) {
16202
16409
  const pending = consumePendingDeleteByRemoteId(newLocalId);
16203
16410
  if (pending) {
@@ -16258,12 +16465,18 @@ const functionModule = {
16258
16465
  }
16259
16466
  };
16260
16467
 
16261
- const IGNORED_FIELDS$1 = ["_id", "system"];
16468
+ const IGNORED_FIELDS$1 = [...KEY_FIELDS, "system"];
16469
+ const UNORDERED_PATHS = [
16470
+ "statement",
16471
+ "statement.*.resource.include",
16472
+ "statement.*.resource.exclude"
16473
+ ];
16262
16474
  const policyModule = {
16263
16475
  name: "policy",
16264
16476
  displayName: "Policy",
16265
16477
  identityField: "name",
16266
16478
  ignoredFields: IGNORED_FIELDS$1,
16479
+ unorderedPaths: UNORDERED_PATHS,
16267
16480
  readLocal(rootDir, source) {
16268
16481
  return readLocalSchemas(rootDir, "policy", source);
16269
16482
  },
@@ -16274,7 +16487,7 @@ const policyModule = {
16274
16487
  .filter(p => !p.system)
16275
16488
  .map(p => ({
16276
16489
  slug: sanitizeSlug(p.name),
16277
- id: p._id,
16490
+ id: recordKey(p),
16278
16491
  data: p
16279
16492
  }));
16280
16493
  },
@@ -16296,21 +16509,21 @@ const policyModule = {
16296
16509
  deleteLocalSchema(rootDir, "policy", slug);
16297
16510
  },
16298
16511
  diffFields(local, remote) {
16299
- return diffSchemaFields(local, remote, IGNORED_FIELDS$1);
16512
+ return diffSchemaFields(local, remote, IGNORED_FIELDS$1, UNORDERED_PATHS);
16300
16513
  },
16301
16514
  renderDetail(local, remote) {
16302
- return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS$1);
16515
+ return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS$1, UNORDERED_PATHS);
16303
16516
  },
16304
16517
  summaryLine(resource) {
16305
16518
  const stmts = resource.data.statement?.length ?? 0;
16306
16519
  return `${stmts} statement${stmts !== 1 ? "s" : ""}`;
16307
16520
  },
16308
16521
  extractLocalId(data) {
16309
- return data._id;
16522
+ return recordKey(data);
16310
16523
  }
16311
16524
  };
16312
16525
 
16313
- const IGNORED_FIELDS = ["_id", "value", "updated_at"];
16526
+ const IGNORED_FIELDS = [...KEY_FIELDS, "value", "updated_at"];
16314
16527
  const secretModule = {
16315
16528
  name: "secret",
16316
16529
  displayName: "Secret",
@@ -16324,7 +16537,7 @@ const secretModule = {
16324
16537
  const items = unwrapList(res);
16325
16538
  return items.map(s => ({
16326
16539
  slug: sanitizeSlug(s.key),
16327
- id: s._id,
16540
+ id: recordKey(s),
16328
16541
  data: s
16329
16542
  }));
16330
16543
  },
@@ -16353,7 +16566,7 @@ const secretModule = {
16353
16566
  return `key: ${resource.data.key}`;
16354
16567
  },
16355
16568
  extractLocalId(data) {
16356
- return data._id;
16569
+ return recordKey(data);
16357
16570
  }
16358
16571
  };
16359
16572