@spica-devkit/sync 0.20.7 → 0.20.9

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
@@ -36,6 +36,85 @@ var ChangeKind;
36
36
  })(ChangeKind || (ChangeKind = {}));
37
37
  const DEFAULT_CONCURRENCY = 10;
38
38
 
39
+ const REQUEST_METHODS = ["get", "delete", "head", "post", "patch", "put"];
40
+ const limitedClients = new WeakMap();
41
+ function limitConcurrency(http, limit = DEFAULT_CONCURRENCY, signal) {
42
+ const existing = limitedClients.get(http);
43
+ if (existing && !signal)
44
+ return http;
45
+ const { semaphore, target } = existing ?? {
46
+ semaphore: new Semaphore(normalizeLimit(limit)),
47
+ target: http
48
+ };
49
+ const limited = { ...target };
50
+ for (const method of REQUEST_METHODS) {
51
+ limited[method] = (...args) => semaphore.run(() => {
52
+ if (signal?.aborted)
53
+ throw signal.reason;
54
+ return target[method](...args);
55
+ });
56
+ }
57
+ limitedClients.set(limited, { semaphore, target });
58
+ return limited;
59
+ }
60
+ async function mapWithConcurrency(items, limit, fn) {
61
+ const results = new Array(items.length);
62
+ let next = 0;
63
+ let failure;
64
+ const worker = async () => {
65
+ while (!failure && next < items.length) {
66
+ const index = next++;
67
+ try {
68
+ results[index] = await fn(items[index], index);
69
+ }
70
+ catch (error) {
71
+ if (!failure)
72
+ failure = { error };
73
+ }
74
+ }
75
+ };
76
+ const workerCount = Math.min(normalizeLimit(limit), items.length);
77
+ await Promise.all(Array.from({ length: workerCount }, worker));
78
+ if (failure)
79
+ throw failure.error;
80
+ return results;
81
+ }
82
+ function normalizeLimit(limit) {
83
+ return Number.isFinite(limit) ? Math.max(1, Math.floor(limit)) : DEFAULT_CONCURRENCY;
84
+ }
85
+ class Semaphore {
86
+ constructor(limit) {
87
+ this.limit = limit;
88
+ this.active = 0;
89
+ this.waiting = [];
90
+ }
91
+ async run(task) {
92
+ await this.acquire();
93
+ try {
94
+ return await task();
95
+ }
96
+ finally {
97
+ this.release();
98
+ }
99
+ }
100
+ acquire() {
101
+ if (this.active < this.limit) {
102
+ this.active++;
103
+ return Promise.resolve();
104
+ }
105
+ return new Promise(resolve => this.waiting.push(resolve));
106
+ }
107
+ release() {
108
+ const next = this.waiting.shift();
109
+ if (next) {
110
+ next();
111
+ }
112
+ else {
113
+ this.active--;
114
+ }
115
+ }
116
+ }
117
+
39
118
  const noopProgress = {
40
119
  update() { },
41
120
  succeed() { },
@@ -115,7 +194,7 @@ const REMOVE$1 = Symbol('remove node');
115
194
  * and `Node` (alias, map, seq & scalar) targets. Of all these, only the most
116
195
  * specific defined one will be used for each node.
117
196
  */
118
- function visit$1(node, visitor) {
197
+ function visit$2(node, visitor) {
119
198
  const visitor_ = initVisitor(visitor);
120
199
  if (isDocument(node)) {
121
200
  const cd = visit_(null, node.contents, visitor_, Object.freeze([node]));
@@ -129,11 +208,11 @@ function visit$1(node, visitor) {
129
208
  // namespace using `var`, but then complains about that because
130
209
  // `unique symbol` must be `const`.
131
210
  /** Terminate visit traversal completely */
132
- visit$1.BREAK = BREAK$1;
211
+ visit$2.BREAK = BREAK$1;
133
212
  /** Do not visit the children of the current node */
134
- visit$1.SKIP = SKIP$1;
213
+ visit$2.SKIP = SKIP$1;
135
214
  /** Remove the current node */
136
- visit$1.REMOVE = REMOVE$1;
215
+ visit$2.REMOVE = REMOVE$1;
137
216
  function visit_(key, node, visitor, path) {
138
217
  const ctrl = callVisitor(key, node, visitor, path);
139
218
  if (isNode(ctrl) || isPair(ctrl)) {
@@ -464,7 +543,7 @@ class Directives {
464
543
  let tagNames;
465
544
  if (doc && tagEntries.length > 0 && isNode(doc.contents)) {
466
545
  const tags = {};
467
- visit$1(doc.contents, (_key, node) => {
546
+ visit$2(doc.contents, (_key, node) => {
468
547
  if (isNode(node) && node.tag)
469
548
  tags[node.tag] = true;
470
549
  });
@@ -499,7 +578,7 @@ function anchorIsValid(anchor) {
499
578
  }
500
579
  function anchorNames(root) {
501
580
  const anchors = new Set();
502
- visit$1(root, {
581
+ visit$2(root, {
503
582
  Value(_key, node) {
504
583
  if (node.anchor)
505
584
  anchors.add(node.anchor);
@@ -693,7 +772,7 @@ class Alias extends NodeBase {
693
772
  }
694
773
  else {
695
774
  nodes = [];
696
- visit$1(doc, {
775
+ visit$2(doc, {
697
776
  Node: (_key, node) => {
698
777
  if (isAlias(node) || hasAnchor(node))
699
778
  nodes.push(node);
@@ -5490,7 +5569,7 @@ const REMOVE = Symbol('remove item');
5490
5569
  * visitor is called on item entry, next visitors are called after handling
5491
5570
  * a non-empty `key` and when exiting the item.
5492
5571
  */
5493
- function visit(cst, visitor) {
5572
+ function visit$1(cst, visitor) {
5494
5573
  if ('type' in cst && cst.type === 'document')
5495
5574
  cst = { start: cst.start, value: cst.value };
5496
5575
  _visit(Object.freeze([]), cst, visitor);
@@ -5499,13 +5578,13 @@ function visit(cst, visitor) {
5499
5578
  // namespace using `var`, but then complains about that because
5500
5579
  // `unique symbol` must be `const`.
5501
5580
  /** Terminate visit traversal completely */
5502
- visit.BREAK = BREAK;
5581
+ visit$1.BREAK = BREAK;
5503
5582
  /** Do not visit the children of the current item */
5504
- visit.SKIP = SKIP;
5583
+ visit$1.SKIP = SKIP;
5505
5584
  /** Remove the current item */
5506
- visit.REMOVE = REMOVE;
5585
+ visit$1.REMOVE = REMOVE;
5507
5586
  /** Find the item at `path` from `cst` as the root */
5508
- visit.itemAtPath = (cst, path) => {
5587
+ visit$1.itemAtPath = (cst, path) => {
5509
5588
  let item = cst;
5510
5589
  for (const [field, index] of path) {
5511
5590
  const tok = item?.[field];
@@ -5522,8 +5601,8 @@ visit.itemAtPath = (cst, path) => {
5522
5601
  *
5523
5602
  * Throws an error if the collection is not found, which should never happen if the item itself exists.
5524
5603
  */
5525
- visit.parentCollection = (cst, path) => {
5526
- const parent = visit.itemAtPath(cst, path.slice(0, -1));
5604
+ visit$1.parentCollection = (cst, path) => {
5605
+ const parent = visit$1.itemAtPath(cst, path.slice(0, -1));
5527
5606
  const field = path[path.length - 1][0];
5528
5607
  const coll = parent?.[field];
5529
5608
  if (coll && 'items' in coll)
@@ -5662,7 +5741,7 @@ var cst = /*#__PURE__*/Object.freeze({
5662
5741
  setScalarValue: setScalarValue,
5663
5742
  stringify: stringify$1,
5664
5743
  tokenType: tokenType,
5665
- visit: visit
5744
+ visit: visit$1
5666
5745
  });
5667
5746
 
5668
5747
  /*
@@ -7502,7 +7581,7 @@ var YAML = /*#__PURE__*/Object.freeze({
7502
7581
  parseAllDocuments: parseAllDocuments,
7503
7582
  parseDocument: parseDocument,
7504
7583
  stringify: stringify,
7505
- visit: visit$1,
7584
+ visit: visit$2,
7506
7585
  visitAsync: visitAsync
7507
7586
  });
7508
7587
 
@@ -12735,13 +12814,134 @@ function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader
12735
12814
  return ret.join('\n') + '\n';
12736
12815
  }
12737
12816
 
12738
- async function buildPlan(modules, http, rootDir, options = {}) {
12817
+ var isPlainObject_1;
12818
+ var hasRequiredIsPlainObject;
12819
+
12820
+ function requireIsPlainObject () {
12821
+ if (hasRequiredIsPlainObject) return isPlainObject_1;
12822
+ hasRequiredIsPlainObject = 1;
12823
+ var baseGetTag = require_baseGetTag(),
12824
+ getPrototype = require_getPrototype(),
12825
+ isObjectLike = requireIsObjectLike();
12826
+
12827
+ /** `Object#toString` result references. */
12828
+ var objectTag = '[object Object]';
12829
+
12830
+ /** Used for built-in method references. */
12831
+ var funcProto = Function.prototype,
12832
+ objectProto = Object.prototype;
12833
+
12834
+ /** Used to resolve the decompiled source of functions. */
12835
+ var funcToString = funcProto.toString;
12836
+
12837
+ /** Used to check objects for own properties. */
12838
+ var hasOwnProperty = objectProto.hasOwnProperty;
12839
+
12840
+ /** Used to infer the `Object` constructor. */
12841
+ var objectCtorString = funcToString.call(Object);
12842
+
12843
+ /**
12844
+ * Checks if `value` is a plain object, that is, an object created by the
12845
+ * `Object` constructor or one with a `[[Prototype]]` of `null`.
12846
+ *
12847
+ * @static
12848
+ * @memberOf _
12849
+ * @since 0.8.0
12850
+ * @category Lang
12851
+ * @param {*} value The value to check.
12852
+ * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
12853
+ * @example
12854
+ *
12855
+ * function Foo() {
12856
+ * this.a = 1;
12857
+ * }
12858
+ *
12859
+ * _.isPlainObject(new Foo);
12860
+ * // => false
12861
+ *
12862
+ * _.isPlainObject([1, 2, 3]);
12863
+ * // => false
12864
+ *
12865
+ * _.isPlainObject({ 'x': 0, 'y': 0 });
12866
+ * // => true
12867
+ *
12868
+ * _.isPlainObject(Object.create(null));
12869
+ * // => true
12870
+ */
12871
+ function isPlainObject(value) {
12872
+ if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
12873
+ return false;
12874
+ }
12875
+ var proto = getPrototype(value);
12876
+ if (proto === null) {
12877
+ return true;
12878
+ }
12879
+ var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
12880
+ return typeof Ctor == 'function' && Ctor instanceof Ctor &&
12881
+ funcToString.call(Ctor) == objectCtorString;
12882
+ }
12883
+
12884
+ isPlainObject_1 = isPlainObject;
12885
+ return isPlainObject_1;
12886
+ }
12887
+
12888
+ var isPlainObjectExports = requireIsPlainObject();
12889
+ var isPlainObject = /*@__PURE__*/getDefaultExportFromCjs(isPlainObjectExports);
12890
+
12891
+ function sortUnorderedArrays(data, paths = []) {
12892
+ if (!paths.length)
12893
+ return data;
12894
+ return visit(data, [], paths.map(p => p.split(".")));
12895
+ }
12896
+ function visit(node, path, patterns) {
12897
+ let visited = node;
12898
+ if (Array.isArray(node)) {
12899
+ visited = node.map((item, i) => visit(item, [...path, String(i)], patterns));
12900
+ }
12901
+ else if (isPlainObject(node)) {
12902
+ visited = Object.fromEntries(Object.entries(node).map(([k, v]) => [
12903
+ k,
12904
+ visit(v, [...path, k], patterns)
12905
+ ]));
12906
+ }
12907
+ if (Array.isArray(visited) && patterns.some(p => matches(p, path))) {
12908
+ return visited
12909
+ .map(item => ({ item, key: canonical(item) }))
12910
+ .sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0))
12911
+ .map(({ item }) => item);
12912
+ }
12913
+ return visited;
12914
+ }
12915
+ function matches(pattern, path) {
12916
+ if (!pattern.length)
12917
+ return !path.length;
12918
+ const [head, ...rest] = pattern;
12919
+ if (head === "**") {
12920
+ return matches(rest, path) || (path.length > 0 && matches(pattern, path.slice(1)));
12921
+ }
12922
+ return path.length > 0 && (head === "*" || head === path[0]) && matches(rest, path.slice(1));
12923
+ }
12924
+ function canonical(value) {
12925
+ if (Array.isArray(value))
12926
+ return `[${value.map(canonical).join(",")}]`;
12927
+ if (isPlainObject(value)) {
12928
+ const obj = value;
12929
+ const entries = Object.keys(obj)
12930
+ .sort()
12931
+ .map(k => `${JSON.stringify(k)}:${canonical(obj[k])}`);
12932
+ return `{${entries.join(",")}}`;
12933
+ }
12934
+ return JSON.stringify(value) ?? "undefined";
12935
+ }
12936
+
12937
+ async function buildPlan(modules, unlimitedHttp, rootDir, options = {}) {
12739
12938
  const { detailed = false, detectRenames = true, reporter = silentReporter, concurrency = DEFAULT_CONCURRENCY, source } = options;
12939
+ const http = limitConcurrency(unlimitedHttp, concurrency);
12740
12940
  const modulePlans = [];
12741
12941
  for (const mod of modules) {
12742
12942
  const [locals, remotes] = await Promise.all([
12743
12943
  reporter.task(`Reading local ${mod.displayName} files`, () => mod.readLocal(rootDir, source)),
12744
- reporter.task(`Fetching remote ${mod.displayName}`, () => mod.readRemote(http, { concurrency }))
12944
+ reporter.task(`Fetching remote ${mod.displayName}`, () => mod.readRemote(http))
12745
12945
  ]);
12746
12946
  const localBySlug = new Map(locals.map(l => [l.slug, l]));
12747
12947
  const remoteBySlug = new Map(remotes.map(r => [r.slug, r]));
@@ -12820,33 +13020,36 @@ async function buildPlan(modules, http, rootDir, options = {}) {
12820
13020
  }
12821
13021
  return { modules: modulePlans };
12822
13022
  }
12823
- async function applyPlan(plan, http, opts = {}) {
13023
+ async function applyPlan(plan, unlimitedHttp, opts = {}) {
12824
13024
  const concurrency = opts.concurrency ?? DEFAULT_CONCURRENCY;
12825
13025
  const reporter = opts.reporter ?? silentReporter;
12826
13026
  const errors = [];
13027
+ const abortController = new AbortController();
13028
+ const http = limitConcurrency(unlimitedHttp, concurrency, abortController.signal);
13029
+ let abortError;
12827
13030
  const handleErr = (label, e) => {
12828
- const msg = formatError(e);
12829
- const full = `${label}: ${msg}`;
12830
- if (opts.abortOnError)
12831
- throw new Error(full);
13031
+ if (abortError)
13032
+ throw abortError;
13033
+ const full = `${label}: ${formatError(e)}`;
13034
+ if (opts.abortOnError) {
13035
+ abortError = new Error(full);
13036
+ abortController.abort(abortError);
13037
+ throw abortError;
13038
+ }
12832
13039
  reporter.warn(full);
12833
13040
  errors.push(full);
12834
13041
  };
12835
13042
  for (const mp of plan.modules) {
12836
13043
  const { module: mod, creates, updates, deletes } = mp;
12837
- if (deletes.length) {
12838
- await runConcurrently(deletes.map(e => ({ slug: e.slug, run: () => mod.delete(http, e.remote.id) })), concurrency, `Deleting ${mod.displayName}`, handleErr, reporter);
12839
- }
12840
- if (updates.length) {
12841
- await runConcurrently(updates.map(e => ({ slug: e.slug, run: () => mod.update(http, e.local, e.remote.id) })), concurrency, `Updating ${mod.displayName}`, handleErr, reporter);
12842
- }
12843
- if (creates.length) {
12844
- await runConcurrently(creates.map(e => ({ slug: e.slug, run: () => mod.create(http, e.local) })), concurrency, `Creating ${mod.displayName}`, handleErr, reporter);
12845
- }
13044
+ await runAllAtOnce(deletes.map(e => ({ slug: e.slug, run: () => mod.delete(http, e.remote.id) })), `Deleting ${mod.displayName}`, handleErr, reporter);
13045
+ await runAllAtOnce(updates.map(e => ({ slug: e.slug, run: () => mod.update(http, e.local, e.remote.id) })), `Updating ${mod.displayName}`, handleErr, reporter);
13046
+ await runAllAtOnce(creates.map(e => ({ slug: e.slug, run: () => mod.create(http, e.local) })), `Creating ${mod.displayName}`, handleErr, reporter);
12846
13047
  }
12847
13048
  return { errors };
12848
13049
  }
12849
- function diffObjectFields(local, remote, ignoredFields) {
13050
+ function diffObjectFields(rawLocal, rawRemote, ignoredFields, unorderedPaths = []) {
13051
+ const local = sortUnorderedArrays(rawLocal, unorderedPaths);
13052
+ const remote = sortUnorderedArrays(rawRemote, unorderedPaths);
12850
13053
  const allKeys = new Set([...Object.keys(local), ...Object.keys(remote)]);
12851
13054
  const changed = [];
12852
13055
  for (const key of allKeys) {
@@ -12858,17 +13061,23 @@ function diffObjectFields(local, remote, ignoredFields) {
12858
13061
  }
12859
13062
  return changed;
12860
13063
  }
12861
- function diffSchemaFields(local, remote, ignoredFields) {
12862
- return diffObjectFields(local, remote, ignoredFields);
13064
+ function diffSchemaFields(local, remote, ignoredFields, unorderedPaths = []) {
13065
+ return diffObjectFields(local, remote, ignoredFields, unorderedPaths);
13066
+ }
13067
+ function stringifyForDiff(data) {
13068
+ return YAML.stringify(data, { sortMapEntries: true });
12863
13069
  }
12864
13070
  function buildUnifiedDiff(oldContent, newContent, filename) {
12865
13071
  return createTwoFilesPatch(`remote/${filename}`, `local/${filename}`, oldContent, newContent);
12866
13072
  }
12867
- function renderSchemaDetail(localData, remoteData, ignoredFields) {
12868
- const localYaml = YAML.stringify(omit(localData, ignoredFields));
12869
- const remoteYaml = YAML.stringify(omit(remoteData, ignoredFields));
13073
+ function renderSchemaDetail(localData, remoteData, ignoredFields, unorderedPaths = []) {
13074
+ const localYaml = stringifyForDiff(sortUnorderedArrays(omit(localData, ignoredFields), unorderedPaths));
13075
+ const remoteYaml = stringifyForDiff(sortUnorderedArrays(omit(remoteData, ignoredFields), unorderedPaths));
12870
13076
  return { schema: buildUnifiedDiff(remoteYaml, localYaml, "schema.yaml") };
12871
13077
  }
13078
+ function runAllAtOnce(tasks, label, onError, reporter) {
13079
+ return runConcurrently(tasks, tasks.length, label, onError, reporter);
13080
+ }
12872
13081
  async function runConcurrently(tasks, concurrency, label, onError, reporter) {
12873
13082
  if (!tasks.length)
12874
13083
  return;
@@ -12876,21 +13085,13 @@ async function runConcurrently(tasks, concurrency, label, onError, reporter) {
12876
13085
  let done = 0;
12877
13086
  const progress = reporter.progress(label, total);
12878
13087
  try {
12879
- const limit = Math.max(1, Math.min(total, concurrency));
12880
- let batch = [];
12881
- for (let i = 0; i < tasks.length; i++) {
12882
- batch.push(tasks[i]);
12883
- if (batch.length === limit || i === tasks.length - 1) {
12884
- await Promise.all(batch.map(task => task
12885
- .run()
12886
- .catch((e) => onError(`${label}: ${task.slug}`, e))
12887
- .finally(() => {
12888
- done++;
12889
- progress.update(task.slug, done, total);
12890
- })));
12891
- batch = [];
12892
- }
12893
- }
13088
+ await mapWithConcurrency(tasks, concurrency, task => task
13089
+ .run()
13090
+ .catch((e) => onError(`${label}: ${task.slug}`, e))
13091
+ .finally(() => {
13092
+ done++;
13093
+ progress.update(task.slug, done, total);
13094
+ }));
12894
13095
  progress.succeed();
12895
13096
  }
12896
13097
  catch (e) {
@@ -12906,12 +13107,14 @@ function formatError(e) {
12906
13107
  return String(e);
12907
13108
  }
12908
13109
 
12909
- const IGNORED_FIELDS$3 = ["_id"];
13110
+ const IGNORED_FIELDS$3 = ["_id", "order"];
13111
+ const UNORDERED_PATHS$1 = ["required", "properties.**.required", "indexes"];
12910
13112
  const bucketModule = {
12911
13113
  name: "bucket",
12912
13114
  displayName: "Bucket",
12913
13115
  identityField: "title",
12914
13116
  ignoredFields: IGNORED_FIELDS$3,
13117
+ unorderedPaths: UNORDERED_PATHS$1,
12915
13118
  readLocal(rootDir, source) {
12916
13119
  return readLocalSchemas(rootDir, "bucket", source);
12917
13120
  },
@@ -12940,10 +13143,10 @@ const bucketModule = {
12940
13143
  deleteLocalSchema(rootDir, "bucket", slug);
12941
13144
  },
12942
13145
  diffFields(local, remote) {
12943
- return diffSchemaFields(local, remote, IGNORED_FIELDS$3);
13146
+ return diffSchemaFields(local, remote, IGNORED_FIELDS$3, UNORDERED_PATHS$1);
12944
13147
  },
12945
13148
  renderDetail(local, remote) {
12946
- return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS$3);
13149
+ return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS$3, UNORDERED_PATHS$1);
12947
13150
  },
12948
13151
  summaryLine(resource) {
12949
13152
  const propCount = Object.keys(resource.data.properties ?? {}).length;
@@ -15722,7 +15925,8 @@ function requireSemver () {
15722
15925
  var semverExports = requireSemver();
15723
15926
  var semver = /*@__PURE__*/getDefaultExportFromCjs(semverExports);
15724
15927
 
15725
- const SCHEMA_IGNORED = ["_id", "env_vars", "secrets"];
15928
+ const SCHEMA_IGNORED = ["_id", "env_vars", "secrets", "order"];
15929
+ const SCHEMA_UNORDERED = ["triggers.*.options.authenticate"];
15726
15930
  function indexFilename(language) {
15727
15931
  return language === "typescript" ? "index.ts" : "index.mjs";
15728
15932
  }
@@ -15747,14 +15951,6 @@ function normalizeSchema(schema) {
15747
15951
  }
15748
15952
  return normalized;
15749
15953
  }
15750
- async function mapInBatches(items, size, fn) {
15751
- const limit = Math.max(1, size);
15752
- const results = [];
15753
- for (let i = 0; i < items.length; i += limit) {
15754
- results.push(...(await Promise.all(items.slice(i, i + limit).map(fn))));
15755
- }
15756
- return results;
15757
- }
15758
15954
  function isNotFoundError(error) {
15759
15955
  if (!error || typeof error !== "object")
15760
15956
  return false;
@@ -15787,6 +15983,7 @@ const functionModule = {
15787
15983
  displayName: "Function",
15788
15984
  identityField: "name",
15789
15985
  ignoredFields: SCHEMA_IGNORED,
15986
+ unorderedPaths: SCHEMA_UNORDERED,
15790
15987
  readSchema(rootDir, slug, source = diskSource) {
15791
15988
  return readSourceYaml(source, path.join(rootDir, "function", slug, "schema.yaml"));
15792
15989
  },
@@ -15818,10 +16015,10 @@ const functionModule = {
15818
16015
  }
15819
16016
  return results;
15820
16017
  },
15821
- async readRemote(http, options = {}) {
16018
+ async readRemote(http) {
15822
16019
  const res = await http.get("function");
15823
16020
  const fns = unwrapList(res);
15824
- return mapInBatches(fns, options.concurrency ?? DEFAULT_CONCURRENCY, async (fn) => {
16021
+ return Promise.all(fns.map(async (fn) => {
15825
16022
  const id = fn._id;
15826
16023
  const [indexRes, depsRes] = await Promise.all([
15827
16024
  http.get(`function/${id}/index`).catch(emptyIfMissing({ index: "" })),
@@ -15844,7 +16041,7 @@ const functionModule = {
15844
16041
  dependencies
15845
16042
  }
15846
16043
  };
15847
- });
16044
+ }));
15848
16045
  },
15849
16046
  async create(http, local) {
15850
16047
  const id = await this.createSchema(http, local.data.schema);
@@ -15938,7 +16135,7 @@ const functionModule = {
15938
16135
  },
15939
16136
  diffFields(local, remote) {
15940
16137
  const changed = [];
15941
- const schemaChanged = diffObjectFields(local.schema, remote.schema, SCHEMA_IGNORED);
16138
+ const schemaChanged = diffObjectFields(local.schema, remote.schema, SCHEMA_IGNORED, SCHEMA_UNORDERED);
15942
16139
  if (schemaChanged.length)
15943
16140
  changed.push("schema");
15944
16141
  if (local.index !== remote.index)
@@ -15957,8 +16154,8 @@ const functionModule = {
15957
16154
  },
15958
16155
  renderDetail(local, remote) {
15959
16156
  const result = {};
15960
- const localSchemaYaml = YAML.stringify(omit(local.data.schema, SCHEMA_IGNORED));
15961
- const remoteSchemaYaml = YAML.stringify(omit(remote.data.schema, SCHEMA_IGNORED));
16157
+ const localSchemaYaml = stringifyForDiff(sortUnorderedArrays(omit(local.data.schema, SCHEMA_IGNORED), SCHEMA_UNORDERED));
16158
+ const remoteSchemaYaml = stringifyForDiff(sortUnorderedArrays(omit(remote.data.schema, SCHEMA_IGNORED), SCHEMA_UNORDERED));
15962
16159
  if (localSchemaYaml !== remoteSchemaYaml) {
15963
16160
  result["schema"] = buildUnifiedDiff(remoteSchemaYaml, localSchemaYaml, "schema.yaml");
15964
16161
  }
@@ -16067,11 +16264,17 @@ const functionModule = {
16067
16264
  };
16068
16265
 
16069
16266
  const IGNORED_FIELDS$1 = ["_id", "system"];
16267
+ const UNORDERED_PATHS = [
16268
+ "statement",
16269
+ "statement.*.resource.include",
16270
+ "statement.*.resource.exclude"
16271
+ ];
16070
16272
  const policyModule = {
16071
16273
  name: "policy",
16072
16274
  displayName: "Policy",
16073
16275
  identityField: "name",
16074
16276
  ignoredFields: IGNORED_FIELDS$1,
16277
+ unorderedPaths: UNORDERED_PATHS,
16075
16278
  readLocal(rootDir, source) {
16076
16279
  return readLocalSchemas(rootDir, "policy", source);
16077
16280
  },
@@ -16104,10 +16307,10 @@ const policyModule = {
16104
16307
  deleteLocalSchema(rootDir, "policy", slug);
16105
16308
  },
16106
16309
  diffFields(local, remote) {
16107
- return diffSchemaFields(local, remote, IGNORED_FIELDS$1);
16310
+ return diffSchemaFields(local, remote, IGNORED_FIELDS$1, UNORDERED_PATHS);
16108
16311
  },
16109
16312
  renderDetail(local, remote) {
16110
- return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS$1);
16313
+ return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS$1, UNORDERED_PATHS);
16111
16314
  },
16112
16315
  summaryLine(resource) {
16113
16316
  const stmts = resource.data.statement?.length ?? 0;