@spica-devkit/sync 0.20.8 → 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
@@ -194,7 +194,7 @@ const REMOVE$1 = Symbol('remove node');
194
194
  * and `Node` (alias, map, seq & scalar) targets. Of all these, only the most
195
195
  * specific defined one will be used for each node.
196
196
  */
197
- function visit$1(node, visitor) {
197
+ function visit$2(node, visitor) {
198
198
  const visitor_ = initVisitor(visitor);
199
199
  if (isDocument(node)) {
200
200
  const cd = visit_(null, node.contents, visitor_, Object.freeze([node]));
@@ -208,11 +208,11 @@ function visit$1(node, visitor) {
208
208
  // namespace using `var`, but then complains about that because
209
209
  // `unique symbol` must be `const`.
210
210
  /** Terminate visit traversal completely */
211
- visit$1.BREAK = BREAK$1;
211
+ visit$2.BREAK = BREAK$1;
212
212
  /** Do not visit the children of the current node */
213
- visit$1.SKIP = SKIP$1;
213
+ visit$2.SKIP = SKIP$1;
214
214
  /** Remove the current node */
215
- visit$1.REMOVE = REMOVE$1;
215
+ visit$2.REMOVE = REMOVE$1;
216
216
  function visit_(key, node, visitor, path) {
217
217
  const ctrl = callVisitor(key, node, visitor, path);
218
218
  if (isNode(ctrl) || isPair(ctrl)) {
@@ -543,7 +543,7 @@ class Directives {
543
543
  let tagNames;
544
544
  if (doc && tagEntries.length > 0 && isNode(doc.contents)) {
545
545
  const tags = {};
546
- visit$1(doc.contents, (_key, node) => {
546
+ visit$2(doc.contents, (_key, node) => {
547
547
  if (isNode(node) && node.tag)
548
548
  tags[node.tag] = true;
549
549
  });
@@ -578,7 +578,7 @@ function anchorIsValid(anchor) {
578
578
  }
579
579
  function anchorNames(root) {
580
580
  const anchors = new Set();
581
- visit$1(root, {
581
+ visit$2(root, {
582
582
  Value(_key, node) {
583
583
  if (node.anchor)
584
584
  anchors.add(node.anchor);
@@ -772,7 +772,7 @@ class Alias extends NodeBase {
772
772
  }
773
773
  else {
774
774
  nodes = [];
775
- visit$1(doc, {
775
+ visit$2(doc, {
776
776
  Node: (_key, node) => {
777
777
  if (isAlias(node) || hasAnchor(node))
778
778
  nodes.push(node);
@@ -5569,7 +5569,7 @@ const REMOVE = Symbol('remove item');
5569
5569
  * visitor is called on item entry, next visitors are called after handling
5570
5570
  * a non-empty `key` and when exiting the item.
5571
5571
  */
5572
- function visit(cst, visitor) {
5572
+ function visit$1(cst, visitor) {
5573
5573
  if ('type' in cst && cst.type === 'document')
5574
5574
  cst = { start: cst.start, value: cst.value };
5575
5575
  _visit(Object.freeze([]), cst, visitor);
@@ -5578,13 +5578,13 @@ function visit(cst, visitor) {
5578
5578
  // namespace using `var`, but then complains about that because
5579
5579
  // `unique symbol` must be `const`.
5580
5580
  /** Terminate visit traversal completely */
5581
- visit.BREAK = BREAK;
5581
+ visit$1.BREAK = BREAK;
5582
5582
  /** Do not visit the children of the current item */
5583
- visit.SKIP = SKIP;
5583
+ visit$1.SKIP = SKIP;
5584
5584
  /** Remove the current item */
5585
- visit.REMOVE = REMOVE;
5585
+ visit$1.REMOVE = REMOVE;
5586
5586
  /** Find the item at `path` from `cst` as the root */
5587
- visit.itemAtPath = (cst, path) => {
5587
+ visit$1.itemAtPath = (cst, path) => {
5588
5588
  let item = cst;
5589
5589
  for (const [field, index] of path) {
5590
5590
  const tok = item?.[field];
@@ -5601,8 +5601,8 @@ visit.itemAtPath = (cst, path) => {
5601
5601
  *
5602
5602
  * Throws an error if the collection is not found, which should never happen if the item itself exists.
5603
5603
  */
5604
- visit.parentCollection = (cst, path) => {
5605
- 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));
5606
5606
  const field = path[path.length - 1][0];
5607
5607
  const coll = parent?.[field];
5608
5608
  if (coll && 'items' in coll)
@@ -5741,7 +5741,7 @@ var cst = /*#__PURE__*/Object.freeze({
5741
5741
  setScalarValue: setScalarValue,
5742
5742
  stringify: stringify$1,
5743
5743
  tokenType: tokenType,
5744
- visit: visit
5744
+ visit: visit$1
5745
5745
  });
5746
5746
 
5747
5747
  /*
@@ -7581,7 +7581,7 @@ var YAML = /*#__PURE__*/Object.freeze({
7581
7581
  parseAllDocuments: parseAllDocuments,
7582
7582
  parseDocument: parseDocument,
7583
7583
  stringify: stringify,
7584
- visit: visit$1,
7584
+ visit: visit$2,
7585
7585
  visitAsync: visitAsync
7586
7586
  });
7587
7587
 
@@ -12814,6 +12814,126 @@ function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader
12814
12814
  return ret.join('\n') + '\n';
12815
12815
  }
12816
12816
 
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
+
12817
12937
  async function buildPlan(modules, unlimitedHttp, rootDir, options = {}) {
12818
12938
  const { detailed = false, detectRenames = true, reporter = silentReporter, concurrency = DEFAULT_CONCURRENCY, source } = options;
12819
12939
  const http = limitConcurrency(unlimitedHttp, concurrency);
@@ -12927,7 +13047,9 @@ async function applyPlan(plan, unlimitedHttp, opts = {}) {
12927
13047
  }
12928
13048
  return { errors };
12929
13049
  }
12930
- function diffObjectFields(local, remote, ignoredFields) {
13050
+ function diffObjectFields(rawLocal, rawRemote, ignoredFields, unorderedPaths = []) {
13051
+ const local = sortUnorderedArrays(rawLocal, unorderedPaths);
13052
+ const remote = sortUnorderedArrays(rawRemote, unorderedPaths);
12931
13053
  const allKeys = new Set([...Object.keys(local), ...Object.keys(remote)]);
12932
13054
  const changed = [];
12933
13055
  for (const key of allKeys) {
@@ -12939,15 +13061,18 @@ function diffObjectFields(local, remote, ignoredFields) {
12939
13061
  }
12940
13062
  return changed;
12941
13063
  }
12942
- function diffSchemaFields(local, remote, ignoredFields) {
12943
- 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 });
12944
13069
  }
12945
13070
  function buildUnifiedDiff(oldContent, newContent, filename) {
12946
13071
  return createTwoFilesPatch(`remote/${filename}`, `local/${filename}`, oldContent, newContent);
12947
13072
  }
12948
- function renderSchemaDetail(localData, remoteData, ignoredFields) {
12949
- const localYaml = YAML.stringify(omit(localData, ignoredFields));
12950
- 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));
12951
13076
  return { schema: buildUnifiedDiff(remoteYaml, localYaml, "schema.yaml") };
12952
13077
  }
12953
13078
  function runAllAtOnce(tasks, label, onError, reporter) {
@@ -12982,12 +13107,14 @@ function formatError(e) {
12982
13107
  return String(e);
12983
13108
  }
12984
13109
 
12985
- const IGNORED_FIELDS$3 = ["_id"];
13110
+ const IGNORED_FIELDS$3 = ["_id", "order"];
13111
+ const UNORDERED_PATHS$1 = ["required", "properties.**.required", "indexes"];
12986
13112
  const bucketModule = {
12987
13113
  name: "bucket",
12988
13114
  displayName: "Bucket",
12989
13115
  identityField: "title",
12990
13116
  ignoredFields: IGNORED_FIELDS$3,
13117
+ unorderedPaths: UNORDERED_PATHS$1,
12991
13118
  readLocal(rootDir, source) {
12992
13119
  return readLocalSchemas(rootDir, "bucket", source);
12993
13120
  },
@@ -13016,10 +13143,10 @@ const bucketModule = {
13016
13143
  deleteLocalSchema(rootDir, "bucket", slug);
13017
13144
  },
13018
13145
  diffFields(local, remote) {
13019
- return diffSchemaFields(local, remote, IGNORED_FIELDS$3);
13146
+ return diffSchemaFields(local, remote, IGNORED_FIELDS$3, UNORDERED_PATHS$1);
13020
13147
  },
13021
13148
  renderDetail(local, remote) {
13022
- return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS$3);
13149
+ return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS$3, UNORDERED_PATHS$1);
13023
13150
  },
13024
13151
  summaryLine(resource) {
13025
13152
  const propCount = Object.keys(resource.data.properties ?? {}).length;
@@ -15798,7 +15925,8 @@ function requireSemver () {
15798
15925
  var semverExports = requireSemver();
15799
15926
  var semver = /*@__PURE__*/getDefaultExportFromCjs(semverExports);
15800
15927
 
15801
- const SCHEMA_IGNORED = ["_id", "env_vars", "secrets"];
15928
+ const SCHEMA_IGNORED = ["_id", "env_vars", "secrets", "order"];
15929
+ const SCHEMA_UNORDERED = ["triggers.*.options.authenticate"];
15802
15930
  function indexFilename(language) {
15803
15931
  return language === "typescript" ? "index.ts" : "index.mjs";
15804
15932
  }
@@ -15855,6 +15983,7 @@ const functionModule = {
15855
15983
  displayName: "Function",
15856
15984
  identityField: "name",
15857
15985
  ignoredFields: SCHEMA_IGNORED,
15986
+ unorderedPaths: SCHEMA_UNORDERED,
15858
15987
  readSchema(rootDir, slug, source = diskSource) {
15859
15988
  return readSourceYaml(source, path.join(rootDir, "function", slug, "schema.yaml"));
15860
15989
  },
@@ -16006,7 +16135,7 @@ const functionModule = {
16006
16135
  },
16007
16136
  diffFields(local, remote) {
16008
16137
  const changed = [];
16009
- const schemaChanged = diffObjectFields(local.schema, remote.schema, SCHEMA_IGNORED);
16138
+ const schemaChanged = diffObjectFields(local.schema, remote.schema, SCHEMA_IGNORED, SCHEMA_UNORDERED);
16010
16139
  if (schemaChanged.length)
16011
16140
  changed.push("schema");
16012
16141
  if (local.index !== remote.index)
@@ -16025,8 +16154,8 @@ const functionModule = {
16025
16154
  },
16026
16155
  renderDetail(local, remote) {
16027
16156
  const result = {};
16028
- const localSchemaYaml = YAML.stringify(omit(local.data.schema, SCHEMA_IGNORED));
16029
- 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));
16030
16159
  if (localSchemaYaml !== remoteSchemaYaml) {
16031
16160
  result["schema"] = buildUnifiedDiff(remoteSchemaYaml, localSchemaYaml, "schema.yaml");
16032
16161
  }
@@ -16135,11 +16264,17 @@ const functionModule = {
16135
16264
  };
16136
16265
 
16137
16266
  const IGNORED_FIELDS$1 = ["_id", "system"];
16267
+ const UNORDERED_PATHS = [
16268
+ "statement",
16269
+ "statement.*.resource.include",
16270
+ "statement.*.resource.exclude"
16271
+ ];
16138
16272
  const policyModule = {
16139
16273
  name: "policy",
16140
16274
  displayName: "Policy",
16141
16275
  identityField: "name",
16142
16276
  ignoredFields: IGNORED_FIELDS$1,
16277
+ unorderedPaths: UNORDERED_PATHS,
16143
16278
  readLocal(rootDir, source) {
16144
16279
  return readLocalSchemas(rootDir, "policy", source);
16145
16280
  },
@@ -16172,10 +16307,10 @@ const policyModule = {
16172
16307
  deleteLocalSchema(rootDir, "policy", slug);
16173
16308
  },
16174
16309
  diffFields(local, remote) {
16175
- return diffSchemaFields(local, remote, IGNORED_FIELDS$1);
16310
+ return diffSchemaFields(local, remote, IGNORED_FIELDS$1, UNORDERED_PATHS);
16176
16311
  },
16177
16312
  renderDetail(local, remote) {
16178
- return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS$1);
16313
+ return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS$1, UNORDERED_PATHS);
16179
16314
  },
16180
16315
  summaryLine(resource) {
16181
16316
  const stmts = resource.data.statement?.length ?? 0;