@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.mjs CHANGED
@@ -15,6 +15,85 @@ var ChangeKind;
15
15
  })(ChangeKind || (ChangeKind = {}));
16
16
  const DEFAULT_CONCURRENCY = 10;
17
17
 
18
+ const REQUEST_METHODS = ["get", "delete", "head", "post", "patch", "put"];
19
+ const limitedClients = new WeakMap();
20
+ function limitConcurrency(http, limit = DEFAULT_CONCURRENCY, signal) {
21
+ const existing = limitedClients.get(http);
22
+ if (existing && !signal)
23
+ return http;
24
+ const { semaphore, target } = existing ?? {
25
+ semaphore: new Semaphore(normalizeLimit(limit)),
26
+ target: http
27
+ };
28
+ const limited = { ...target };
29
+ for (const method of REQUEST_METHODS) {
30
+ limited[method] = (...args) => semaphore.run(() => {
31
+ if (signal?.aborted)
32
+ throw signal.reason;
33
+ return target[method](...args);
34
+ });
35
+ }
36
+ limitedClients.set(limited, { semaphore, target });
37
+ return limited;
38
+ }
39
+ async function mapWithConcurrency(items, limit, fn) {
40
+ const results = new Array(items.length);
41
+ let next = 0;
42
+ let failure;
43
+ const worker = async () => {
44
+ while (!failure && next < items.length) {
45
+ const index = next++;
46
+ try {
47
+ results[index] = await fn(items[index], index);
48
+ }
49
+ catch (error) {
50
+ if (!failure)
51
+ failure = { error };
52
+ }
53
+ }
54
+ };
55
+ const workerCount = Math.min(normalizeLimit(limit), items.length);
56
+ await Promise.all(Array.from({ length: workerCount }, worker));
57
+ if (failure)
58
+ throw failure.error;
59
+ return results;
60
+ }
61
+ function normalizeLimit(limit) {
62
+ return Number.isFinite(limit) ? Math.max(1, Math.floor(limit)) : DEFAULT_CONCURRENCY;
63
+ }
64
+ class Semaphore {
65
+ constructor(limit) {
66
+ this.limit = limit;
67
+ this.active = 0;
68
+ this.waiting = [];
69
+ }
70
+ async run(task) {
71
+ await this.acquire();
72
+ try {
73
+ return await task();
74
+ }
75
+ finally {
76
+ this.release();
77
+ }
78
+ }
79
+ acquire() {
80
+ if (this.active < this.limit) {
81
+ this.active++;
82
+ return Promise.resolve();
83
+ }
84
+ return new Promise(resolve => this.waiting.push(resolve));
85
+ }
86
+ release() {
87
+ const next = this.waiting.shift();
88
+ if (next) {
89
+ next();
90
+ }
91
+ else {
92
+ this.active--;
93
+ }
94
+ }
95
+ }
96
+
18
97
  const noopProgress = {
19
98
  update() { },
20
99
  succeed() { },
@@ -94,7 +173,7 @@ const REMOVE$1 = Symbol('remove node');
94
173
  * and `Node` (alias, map, seq & scalar) targets. Of all these, only the most
95
174
  * specific defined one will be used for each node.
96
175
  */
97
- function visit$1(node, visitor) {
176
+ function visit$2(node, visitor) {
98
177
  const visitor_ = initVisitor(visitor);
99
178
  if (isDocument(node)) {
100
179
  const cd = visit_(null, node.contents, visitor_, Object.freeze([node]));
@@ -108,11 +187,11 @@ function visit$1(node, visitor) {
108
187
  // namespace using `var`, but then complains about that because
109
188
  // `unique symbol` must be `const`.
110
189
  /** Terminate visit traversal completely */
111
- visit$1.BREAK = BREAK$1;
190
+ visit$2.BREAK = BREAK$1;
112
191
  /** Do not visit the children of the current node */
113
- visit$1.SKIP = SKIP$1;
192
+ visit$2.SKIP = SKIP$1;
114
193
  /** Remove the current node */
115
- visit$1.REMOVE = REMOVE$1;
194
+ visit$2.REMOVE = REMOVE$1;
116
195
  function visit_(key, node, visitor, path) {
117
196
  const ctrl = callVisitor(key, node, visitor, path);
118
197
  if (isNode(ctrl) || isPair(ctrl)) {
@@ -443,7 +522,7 @@ class Directives {
443
522
  let tagNames;
444
523
  if (doc && tagEntries.length > 0 && isNode(doc.contents)) {
445
524
  const tags = {};
446
- visit$1(doc.contents, (_key, node) => {
525
+ visit$2(doc.contents, (_key, node) => {
447
526
  if (isNode(node) && node.tag)
448
527
  tags[node.tag] = true;
449
528
  });
@@ -478,7 +557,7 @@ function anchorIsValid(anchor) {
478
557
  }
479
558
  function anchorNames(root) {
480
559
  const anchors = new Set();
481
- visit$1(root, {
560
+ visit$2(root, {
482
561
  Value(_key, node) {
483
562
  if (node.anchor)
484
563
  anchors.add(node.anchor);
@@ -672,7 +751,7 @@ class Alias extends NodeBase {
672
751
  }
673
752
  else {
674
753
  nodes = [];
675
- visit$1(doc, {
754
+ visit$2(doc, {
676
755
  Node: (_key, node) => {
677
756
  if (isAlias(node) || hasAnchor(node))
678
757
  nodes.push(node);
@@ -5469,7 +5548,7 @@ const REMOVE = Symbol('remove item');
5469
5548
  * visitor is called on item entry, next visitors are called after handling
5470
5549
  * a non-empty `key` and when exiting the item.
5471
5550
  */
5472
- function visit(cst, visitor) {
5551
+ function visit$1(cst, visitor) {
5473
5552
  if ('type' in cst && cst.type === 'document')
5474
5553
  cst = { start: cst.start, value: cst.value };
5475
5554
  _visit(Object.freeze([]), cst, visitor);
@@ -5478,13 +5557,13 @@ function visit(cst, visitor) {
5478
5557
  // namespace using `var`, but then complains about that because
5479
5558
  // `unique symbol` must be `const`.
5480
5559
  /** Terminate visit traversal completely */
5481
- visit.BREAK = BREAK;
5560
+ visit$1.BREAK = BREAK;
5482
5561
  /** Do not visit the children of the current item */
5483
- visit.SKIP = SKIP;
5562
+ visit$1.SKIP = SKIP;
5484
5563
  /** Remove the current item */
5485
- visit.REMOVE = REMOVE;
5564
+ visit$1.REMOVE = REMOVE;
5486
5565
  /** Find the item at `path` from `cst` as the root */
5487
- visit.itemAtPath = (cst, path) => {
5566
+ visit$1.itemAtPath = (cst, path) => {
5488
5567
  let item = cst;
5489
5568
  for (const [field, index] of path) {
5490
5569
  const tok = item?.[field];
@@ -5501,8 +5580,8 @@ visit.itemAtPath = (cst, path) => {
5501
5580
  *
5502
5581
  * Throws an error if the collection is not found, which should never happen if the item itself exists.
5503
5582
  */
5504
- visit.parentCollection = (cst, path) => {
5505
- const parent = visit.itemAtPath(cst, path.slice(0, -1));
5583
+ visit$1.parentCollection = (cst, path) => {
5584
+ const parent = visit$1.itemAtPath(cst, path.slice(0, -1));
5506
5585
  const field = path[path.length - 1][0];
5507
5586
  const coll = parent?.[field];
5508
5587
  if (coll && 'items' in coll)
@@ -5641,7 +5720,7 @@ var cst = /*#__PURE__*/Object.freeze({
5641
5720
  setScalarValue: setScalarValue,
5642
5721
  stringify: stringify$1,
5643
5722
  tokenType: tokenType,
5644
- visit: visit
5723
+ visit: visit$1
5645
5724
  });
5646
5725
 
5647
5726
  /*
@@ -7481,7 +7560,7 @@ var YAML = /*#__PURE__*/Object.freeze({
7481
7560
  parseAllDocuments: parseAllDocuments,
7482
7561
  parseDocument: parseDocument,
7483
7562
  stringify: stringify,
7484
- visit: visit$1,
7563
+ visit: visit$2,
7485
7564
  visitAsync: visitAsync
7486
7565
  });
7487
7566
 
@@ -12714,13 +12793,134 @@ function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader
12714
12793
  return ret.join('\n') + '\n';
12715
12794
  }
12716
12795
 
12717
- async function buildPlan(modules, http, rootDir, options = {}) {
12796
+ var isPlainObject_1;
12797
+ var hasRequiredIsPlainObject;
12798
+
12799
+ function requireIsPlainObject () {
12800
+ if (hasRequiredIsPlainObject) return isPlainObject_1;
12801
+ hasRequiredIsPlainObject = 1;
12802
+ var baseGetTag = require_baseGetTag(),
12803
+ getPrototype = require_getPrototype(),
12804
+ isObjectLike = requireIsObjectLike();
12805
+
12806
+ /** `Object#toString` result references. */
12807
+ var objectTag = '[object Object]';
12808
+
12809
+ /** Used for built-in method references. */
12810
+ var funcProto = Function.prototype,
12811
+ objectProto = Object.prototype;
12812
+
12813
+ /** Used to resolve the decompiled source of functions. */
12814
+ var funcToString = funcProto.toString;
12815
+
12816
+ /** Used to check objects for own properties. */
12817
+ var hasOwnProperty = objectProto.hasOwnProperty;
12818
+
12819
+ /** Used to infer the `Object` constructor. */
12820
+ var objectCtorString = funcToString.call(Object);
12821
+
12822
+ /**
12823
+ * Checks if `value` is a plain object, that is, an object created by the
12824
+ * `Object` constructor or one with a `[[Prototype]]` of `null`.
12825
+ *
12826
+ * @static
12827
+ * @memberOf _
12828
+ * @since 0.8.0
12829
+ * @category Lang
12830
+ * @param {*} value The value to check.
12831
+ * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
12832
+ * @example
12833
+ *
12834
+ * function Foo() {
12835
+ * this.a = 1;
12836
+ * }
12837
+ *
12838
+ * _.isPlainObject(new Foo);
12839
+ * // => false
12840
+ *
12841
+ * _.isPlainObject([1, 2, 3]);
12842
+ * // => false
12843
+ *
12844
+ * _.isPlainObject({ 'x': 0, 'y': 0 });
12845
+ * // => true
12846
+ *
12847
+ * _.isPlainObject(Object.create(null));
12848
+ * // => true
12849
+ */
12850
+ function isPlainObject(value) {
12851
+ if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
12852
+ return false;
12853
+ }
12854
+ var proto = getPrototype(value);
12855
+ if (proto === null) {
12856
+ return true;
12857
+ }
12858
+ var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
12859
+ return typeof Ctor == 'function' && Ctor instanceof Ctor &&
12860
+ funcToString.call(Ctor) == objectCtorString;
12861
+ }
12862
+
12863
+ isPlainObject_1 = isPlainObject;
12864
+ return isPlainObject_1;
12865
+ }
12866
+
12867
+ var isPlainObjectExports = requireIsPlainObject();
12868
+ var isPlainObject = /*@__PURE__*/getDefaultExportFromCjs(isPlainObjectExports);
12869
+
12870
+ function sortUnorderedArrays(data, paths = []) {
12871
+ if (!paths.length)
12872
+ return data;
12873
+ return visit(data, [], paths.map(p => p.split(".")));
12874
+ }
12875
+ function visit(node, path, patterns) {
12876
+ let visited = node;
12877
+ if (Array.isArray(node)) {
12878
+ visited = node.map((item, i) => visit(item, [...path, String(i)], patterns));
12879
+ }
12880
+ else if (isPlainObject(node)) {
12881
+ visited = Object.fromEntries(Object.entries(node).map(([k, v]) => [
12882
+ k,
12883
+ visit(v, [...path, k], patterns)
12884
+ ]));
12885
+ }
12886
+ if (Array.isArray(visited) && patterns.some(p => matches(p, path))) {
12887
+ return visited
12888
+ .map(item => ({ item, key: canonical(item) }))
12889
+ .sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0))
12890
+ .map(({ item }) => item);
12891
+ }
12892
+ return visited;
12893
+ }
12894
+ function matches(pattern, path) {
12895
+ if (!pattern.length)
12896
+ return !path.length;
12897
+ const [head, ...rest] = pattern;
12898
+ if (head === "**") {
12899
+ return matches(rest, path) || (path.length > 0 && matches(pattern, path.slice(1)));
12900
+ }
12901
+ return path.length > 0 && (head === "*" || head === path[0]) && matches(rest, path.slice(1));
12902
+ }
12903
+ function canonical(value) {
12904
+ if (Array.isArray(value))
12905
+ return `[${value.map(canonical).join(",")}]`;
12906
+ if (isPlainObject(value)) {
12907
+ const obj = value;
12908
+ const entries = Object.keys(obj)
12909
+ .sort()
12910
+ .map(k => `${JSON.stringify(k)}:${canonical(obj[k])}`);
12911
+ return `{${entries.join(",")}}`;
12912
+ }
12913
+ return JSON.stringify(value) ?? "undefined";
12914
+ }
12915
+
12916
+ async function buildPlan(modules, unlimitedHttp, rootDir, options = {}) {
12718
12917
  const { detailed = false, detectRenames = true, reporter = silentReporter, concurrency = DEFAULT_CONCURRENCY, source } = options;
12918
+ const http = limitConcurrency(unlimitedHttp, concurrency);
12719
12919
  const modulePlans = [];
12720
12920
  for (const mod of modules) {
12721
12921
  const [locals, remotes] = await Promise.all([
12722
12922
  reporter.task(`Reading local ${mod.displayName} files`, () => mod.readLocal(rootDir, source)),
12723
- reporter.task(`Fetching remote ${mod.displayName}`, () => mod.readRemote(http, { concurrency }))
12923
+ reporter.task(`Fetching remote ${mod.displayName}`, () => mod.readRemote(http))
12724
12924
  ]);
12725
12925
  const localBySlug = new Map(locals.map(l => [l.slug, l]));
12726
12926
  const remoteBySlug = new Map(remotes.map(r => [r.slug, r]));
@@ -12799,33 +12999,36 @@ async function buildPlan(modules, http, rootDir, options = {}) {
12799
12999
  }
12800
13000
  return { modules: modulePlans };
12801
13001
  }
12802
- async function applyPlan(plan, http, opts = {}) {
13002
+ async function applyPlan(plan, unlimitedHttp, opts = {}) {
12803
13003
  const concurrency = opts.concurrency ?? DEFAULT_CONCURRENCY;
12804
13004
  const reporter = opts.reporter ?? silentReporter;
12805
13005
  const errors = [];
13006
+ const abortController = new AbortController();
13007
+ const http = limitConcurrency(unlimitedHttp, concurrency, abortController.signal);
13008
+ let abortError;
12806
13009
  const handleErr = (label, e) => {
12807
- const msg = formatError(e);
12808
- const full = `${label}: ${msg}`;
12809
- if (opts.abortOnError)
12810
- throw new Error(full);
13010
+ if (abortError)
13011
+ throw abortError;
13012
+ const full = `${label}: ${formatError(e)}`;
13013
+ if (opts.abortOnError) {
13014
+ abortError = new Error(full);
13015
+ abortController.abort(abortError);
13016
+ throw abortError;
13017
+ }
12811
13018
  reporter.warn(full);
12812
13019
  errors.push(full);
12813
13020
  };
12814
13021
  for (const mp of plan.modules) {
12815
13022
  const { module: mod, creates, updates, deletes } = mp;
12816
- if (deletes.length) {
12817
- await runConcurrently(deletes.map(e => ({ slug: e.slug, run: () => mod.delete(http, e.remote.id) })), concurrency, `Deleting ${mod.displayName}`, handleErr, reporter);
12818
- }
12819
- if (updates.length) {
12820
- await runConcurrently(updates.map(e => ({ slug: e.slug, run: () => mod.update(http, e.local, e.remote.id) })), concurrency, `Updating ${mod.displayName}`, handleErr, reporter);
12821
- }
12822
- if (creates.length) {
12823
- await runConcurrently(creates.map(e => ({ slug: e.slug, run: () => mod.create(http, e.local) })), concurrency, `Creating ${mod.displayName}`, handleErr, reporter);
12824
- }
13023
+ await runAllAtOnce(deletes.map(e => ({ slug: e.slug, run: () => mod.delete(http, e.remote.id) })), `Deleting ${mod.displayName}`, handleErr, reporter);
13024
+ await runAllAtOnce(updates.map(e => ({ slug: e.slug, run: () => mod.update(http, e.local, e.remote.id) })), `Updating ${mod.displayName}`, handleErr, reporter);
13025
+ await runAllAtOnce(creates.map(e => ({ slug: e.slug, run: () => mod.create(http, e.local) })), `Creating ${mod.displayName}`, handleErr, reporter);
12825
13026
  }
12826
13027
  return { errors };
12827
13028
  }
12828
- function diffObjectFields(local, remote, ignoredFields) {
13029
+ function diffObjectFields(rawLocal, rawRemote, ignoredFields, unorderedPaths = []) {
13030
+ const local = sortUnorderedArrays(rawLocal, unorderedPaths);
13031
+ const remote = sortUnorderedArrays(rawRemote, unorderedPaths);
12829
13032
  const allKeys = new Set([...Object.keys(local), ...Object.keys(remote)]);
12830
13033
  const changed = [];
12831
13034
  for (const key of allKeys) {
@@ -12837,17 +13040,23 @@ function diffObjectFields(local, remote, ignoredFields) {
12837
13040
  }
12838
13041
  return changed;
12839
13042
  }
12840
- function diffSchemaFields(local, remote, ignoredFields) {
12841
- return diffObjectFields(local, remote, ignoredFields);
13043
+ function diffSchemaFields(local, remote, ignoredFields, unorderedPaths = []) {
13044
+ return diffObjectFields(local, remote, ignoredFields, unorderedPaths);
13045
+ }
13046
+ function stringifyForDiff(data) {
13047
+ return YAML.stringify(data, { sortMapEntries: true });
12842
13048
  }
12843
13049
  function buildUnifiedDiff(oldContent, newContent, filename) {
12844
13050
  return createTwoFilesPatch(`remote/${filename}`, `local/${filename}`, oldContent, newContent);
12845
13051
  }
12846
- function renderSchemaDetail(localData, remoteData, ignoredFields) {
12847
- const localYaml = YAML.stringify(omit(localData, ignoredFields));
12848
- const remoteYaml = YAML.stringify(omit(remoteData, ignoredFields));
13052
+ function renderSchemaDetail(localData, remoteData, ignoredFields, unorderedPaths = []) {
13053
+ const localYaml = stringifyForDiff(sortUnorderedArrays(omit(localData, ignoredFields), unorderedPaths));
13054
+ const remoteYaml = stringifyForDiff(sortUnorderedArrays(omit(remoteData, ignoredFields), unorderedPaths));
12849
13055
  return { schema: buildUnifiedDiff(remoteYaml, localYaml, "schema.yaml") };
12850
13056
  }
13057
+ function runAllAtOnce(tasks, label, onError, reporter) {
13058
+ return runConcurrently(tasks, tasks.length, label, onError, reporter);
13059
+ }
12851
13060
  async function runConcurrently(tasks, concurrency, label, onError, reporter) {
12852
13061
  if (!tasks.length)
12853
13062
  return;
@@ -12855,21 +13064,13 @@ async function runConcurrently(tasks, concurrency, label, onError, reporter) {
12855
13064
  let done = 0;
12856
13065
  const progress = reporter.progress(label, total);
12857
13066
  try {
12858
- const limit = Math.max(1, Math.min(total, concurrency));
12859
- let batch = [];
12860
- for (let i = 0; i < tasks.length; i++) {
12861
- batch.push(tasks[i]);
12862
- if (batch.length === limit || i === tasks.length - 1) {
12863
- await Promise.all(batch.map(task => task
12864
- .run()
12865
- .catch((e) => onError(`${label}: ${task.slug}`, e))
12866
- .finally(() => {
12867
- done++;
12868
- progress.update(task.slug, done, total);
12869
- })));
12870
- batch = [];
12871
- }
12872
- }
13067
+ await mapWithConcurrency(tasks, concurrency, task => task
13068
+ .run()
13069
+ .catch((e) => onError(`${label}: ${task.slug}`, e))
13070
+ .finally(() => {
13071
+ done++;
13072
+ progress.update(task.slug, done, total);
13073
+ }));
12873
13074
  progress.succeed();
12874
13075
  }
12875
13076
  catch (e) {
@@ -12885,12 +13086,14 @@ function formatError(e) {
12885
13086
  return String(e);
12886
13087
  }
12887
13088
 
12888
- const IGNORED_FIELDS$3 = ["_id"];
13089
+ const IGNORED_FIELDS$3 = ["_id", "order"];
13090
+ const UNORDERED_PATHS$1 = ["required", "properties.**.required", "indexes"];
12889
13091
  const bucketModule = {
12890
13092
  name: "bucket",
12891
13093
  displayName: "Bucket",
12892
13094
  identityField: "title",
12893
13095
  ignoredFields: IGNORED_FIELDS$3,
13096
+ unorderedPaths: UNORDERED_PATHS$1,
12894
13097
  readLocal(rootDir, source) {
12895
13098
  return readLocalSchemas(rootDir, "bucket", source);
12896
13099
  },
@@ -12919,10 +13122,10 @@ const bucketModule = {
12919
13122
  deleteLocalSchema(rootDir, "bucket", slug);
12920
13123
  },
12921
13124
  diffFields(local, remote) {
12922
- return diffSchemaFields(local, remote, IGNORED_FIELDS$3);
13125
+ return diffSchemaFields(local, remote, IGNORED_FIELDS$3, UNORDERED_PATHS$1);
12923
13126
  },
12924
13127
  renderDetail(local, remote) {
12925
- return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS$3);
13128
+ return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS$3, UNORDERED_PATHS$1);
12926
13129
  },
12927
13130
  summaryLine(resource) {
12928
13131
  const propCount = Object.keys(resource.data.properties ?? {}).length;
@@ -15701,7 +15904,8 @@ function requireSemver () {
15701
15904
  var semverExports = requireSemver();
15702
15905
  var semver = /*@__PURE__*/getDefaultExportFromCjs(semverExports);
15703
15906
 
15704
- const SCHEMA_IGNORED = ["_id", "env_vars", "secrets"];
15907
+ const SCHEMA_IGNORED = ["_id", "env_vars", "secrets", "order"];
15908
+ const SCHEMA_UNORDERED = ["triggers.*.options.authenticate"];
15705
15909
  function indexFilename(language) {
15706
15910
  return language === "typescript" ? "index.ts" : "index.mjs";
15707
15911
  }
@@ -15726,14 +15930,6 @@ function normalizeSchema(schema) {
15726
15930
  }
15727
15931
  return normalized;
15728
15932
  }
15729
- async function mapInBatches(items, size, fn) {
15730
- const limit = Math.max(1, size);
15731
- const results = [];
15732
- for (let i = 0; i < items.length; i += limit) {
15733
- results.push(...(await Promise.all(items.slice(i, i + limit).map(fn))));
15734
- }
15735
- return results;
15736
- }
15737
15933
  function isNotFoundError(error) {
15738
15934
  if (!error || typeof error !== "object")
15739
15935
  return false;
@@ -15766,6 +15962,7 @@ const functionModule = {
15766
15962
  displayName: "Function",
15767
15963
  identityField: "name",
15768
15964
  ignoredFields: SCHEMA_IGNORED,
15965
+ unorderedPaths: SCHEMA_UNORDERED,
15769
15966
  readSchema(rootDir, slug, source = diskSource) {
15770
15967
  return readSourceYaml(source, path.join(rootDir, "function", slug, "schema.yaml"));
15771
15968
  },
@@ -15797,10 +15994,10 @@ const functionModule = {
15797
15994
  }
15798
15995
  return results;
15799
15996
  },
15800
- async readRemote(http, options = {}) {
15997
+ async readRemote(http) {
15801
15998
  const res = await http.get("function");
15802
15999
  const fns = unwrapList(res);
15803
- return mapInBatches(fns, options.concurrency ?? DEFAULT_CONCURRENCY, async (fn) => {
16000
+ return Promise.all(fns.map(async (fn) => {
15804
16001
  const id = fn._id;
15805
16002
  const [indexRes, depsRes] = await Promise.all([
15806
16003
  http.get(`function/${id}/index`).catch(emptyIfMissing({ index: "" })),
@@ -15823,7 +16020,7 @@ const functionModule = {
15823
16020
  dependencies
15824
16021
  }
15825
16022
  };
15826
- });
16023
+ }));
15827
16024
  },
15828
16025
  async create(http, local) {
15829
16026
  const id = await this.createSchema(http, local.data.schema);
@@ -15917,7 +16114,7 @@ const functionModule = {
15917
16114
  },
15918
16115
  diffFields(local, remote) {
15919
16116
  const changed = [];
15920
- const schemaChanged = diffObjectFields(local.schema, remote.schema, SCHEMA_IGNORED);
16117
+ const schemaChanged = diffObjectFields(local.schema, remote.schema, SCHEMA_IGNORED, SCHEMA_UNORDERED);
15921
16118
  if (schemaChanged.length)
15922
16119
  changed.push("schema");
15923
16120
  if (local.index !== remote.index)
@@ -15936,8 +16133,8 @@ const functionModule = {
15936
16133
  },
15937
16134
  renderDetail(local, remote) {
15938
16135
  const result = {};
15939
- const localSchemaYaml = YAML.stringify(omit(local.data.schema, SCHEMA_IGNORED));
15940
- const remoteSchemaYaml = YAML.stringify(omit(remote.data.schema, SCHEMA_IGNORED));
16136
+ const localSchemaYaml = stringifyForDiff(sortUnorderedArrays(omit(local.data.schema, SCHEMA_IGNORED), SCHEMA_UNORDERED));
16137
+ const remoteSchemaYaml = stringifyForDiff(sortUnorderedArrays(omit(remote.data.schema, SCHEMA_IGNORED), SCHEMA_UNORDERED));
15941
16138
  if (localSchemaYaml !== remoteSchemaYaml) {
15942
16139
  result["schema"] = buildUnifiedDiff(remoteSchemaYaml, localSchemaYaml, "schema.yaml");
15943
16140
  }
@@ -16046,11 +16243,17 @@ const functionModule = {
16046
16243
  };
16047
16244
 
16048
16245
  const IGNORED_FIELDS$1 = ["_id", "system"];
16246
+ const UNORDERED_PATHS = [
16247
+ "statement",
16248
+ "statement.*.resource.include",
16249
+ "statement.*.resource.exclude"
16250
+ ];
16049
16251
  const policyModule = {
16050
16252
  name: "policy",
16051
16253
  displayName: "Policy",
16052
16254
  identityField: "name",
16053
16255
  ignoredFields: IGNORED_FIELDS$1,
16256
+ unorderedPaths: UNORDERED_PATHS,
16054
16257
  readLocal(rootDir, source) {
16055
16258
  return readLocalSchemas(rootDir, "policy", source);
16056
16259
  },
@@ -16083,10 +16286,10 @@ const policyModule = {
16083
16286
  deleteLocalSchema(rootDir, "policy", slug);
16084
16287
  },
16085
16288
  diffFields(local, remote) {
16086
- return diffSchemaFields(local, remote, IGNORED_FIELDS$1);
16289
+ return diffSchemaFields(local, remote, IGNORED_FIELDS$1, UNORDERED_PATHS);
16087
16290
  },
16088
16291
  renderDetail(local, remote) {
16089
- return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS$1);
16292
+ return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS$1, UNORDERED_PATHS);
16090
16293
  },
16091
16294
  summaryLine(resource) {
16092
16295
  const stmts = resource.data.statement?.length ?? 0;