@spica-devkit/sync 0.20.7 → 0.21.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +305 -92
- package/index.js.map +1 -1
- package/index.mjs +305 -92
- package/index.mjs.map +1 -1
- package/package.json +1 -1
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$
|
|
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$
|
|
211
|
+
visit$2.BREAK = BREAK$1;
|
|
133
212
|
/** Do not visit the children of the current node */
|
|
134
|
-
visit$
|
|
213
|
+
visit$2.SKIP = SKIP$1;
|
|
135
214
|
/** Remove the current node */
|
|
136
|
-
visit$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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
|
-
|
|
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
|
|
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,
|
|
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
|
-
|
|
12829
|
-
|
|
12830
|
-
|
|
12831
|
-
|
|
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
|
-
|
|
12838
|
-
|
|
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(
|
|
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 =
|
|
12869
|
-
const remoteYaml =
|
|
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
|
-
|
|
12880
|
-
|
|
12881
|
-
|
|
12882
|
-
|
|
12883
|
-
|
|
12884
|
-
|
|
12885
|
-
|
|
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,26 @@ function formatError(e) {
|
|
|
12906
13107
|
return String(e);
|
|
12907
13108
|
}
|
|
12908
13109
|
|
|
12909
|
-
const
|
|
13110
|
+
const KEY_FIELDS = ["_id", "id"];
|
|
13111
|
+
function recordKeyField(record) {
|
|
13112
|
+
if (record === null || typeof record != "object") {
|
|
13113
|
+
return undefined;
|
|
13114
|
+
}
|
|
13115
|
+
return KEY_FIELDS.find(field => field in record);
|
|
13116
|
+
}
|
|
13117
|
+
function recordKey(record) {
|
|
13118
|
+
const field = recordKeyField(record);
|
|
13119
|
+
return field ? record[field] : undefined;
|
|
13120
|
+
}
|
|
13121
|
+
|
|
13122
|
+
const IGNORED_FIELDS$3 = [...KEY_FIELDS, "order"];
|
|
13123
|
+
const UNORDERED_PATHS$1 = ["required", "properties.**.required", "indexes"];
|
|
12910
13124
|
const bucketModule = {
|
|
12911
13125
|
name: "bucket",
|
|
12912
13126
|
displayName: "Bucket",
|
|
12913
13127
|
identityField: "title",
|
|
12914
13128
|
ignoredFields: IGNORED_FIELDS$3,
|
|
13129
|
+
unorderedPaths: UNORDERED_PATHS$1,
|
|
12915
13130
|
readLocal(rootDir, source) {
|
|
12916
13131
|
return readLocalSchemas(rootDir, "bucket", source);
|
|
12917
13132
|
},
|
|
@@ -12920,7 +13135,7 @@ const bucketModule = {
|
|
|
12920
13135
|
const buckets = unwrapList(res);
|
|
12921
13136
|
return buckets.map(b => ({
|
|
12922
13137
|
slug: sanitizeSlug(b.title),
|
|
12923
|
-
id: b
|
|
13138
|
+
id: recordKey(b),
|
|
12924
13139
|
data: b
|
|
12925
13140
|
}));
|
|
12926
13141
|
},
|
|
@@ -12940,21 +13155,21 @@ const bucketModule = {
|
|
|
12940
13155
|
deleteLocalSchema(rootDir, "bucket", slug);
|
|
12941
13156
|
},
|
|
12942
13157
|
diffFields(local, remote) {
|
|
12943
|
-
return diffSchemaFields(local, remote, IGNORED_FIELDS$3);
|
|
13158
|
+
return diffSchemaFields(local, remote, IGNORED_FIELDS$3, UNORDERED_PATHS$1);
|
|
12944
13159
|
},
|
|
12945
13160
|
renderDetail(local, remote) {
|
|
12946
|
-
return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS$3);
|
|
13161
|
+
return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS$3, UNORDERED_PATHS$1);
|
|
12947
13162
|
},
|
|
12948
13163
|
summaryLine(resource) {
|
|
12949
13164
|
const propCount = Object.keys(resource.data.properties ?? {}).length;
|
|
12950
13165
|
return `${propCount} properties`;
|
|
12951
13166
|
},
|
|
12952
13167
|
extractLocalId(data) {
|
|
12953
|
-
return data
|
|
13168
|
+
return recordKey(data);
|
|
12954
13169
|
}
|
|
12955
13170
|
};
|
|
12956
13171
|
|
|
12957
|
-
const IGNORED_FIELDS$2 = [
|
|
13172
|
+
const IGNORED_FIELDS$2 = [...KEY_FIELDS, "updated_at"];
|
|
12958
13173
|
const envVarModule = {
|
|
12959
13174
|
name: "env-var",
|
|
12960
13175
|
displayName: "Environment Variable",
|
|
@@ -12968,7 +13183,7 @@ const envVarModule = {
|
|
|
12968
13183
|
const items = unwrapList(res);
|
|
12969
13184
|
return items.map(e => ({
|
|
12970
13185
|
slug: sanitizeSlug(e.key),
|
|
12971
|
-
id: e
|
|
13186
|
+
id: recordKey(e),
|
|
12972
13187
|
data: e
|
|
12973
13188
|
}));
|
|
12974
13189
|
},
|
|
@@ -12997,7 +13212,7 @@ const envVarModule = {
|
|
|
12997
13212
|
return `key: ${resource.data.key}`;
|
|
12998
13213
|
},
|
|
12999
13214
|
extractLocalId(data) {
|
|
13000
|
-
return data
|
|
13215
|
+
return recordKey(data);
|
|
13001
13216
|
}
|
|
13002
13217
|
};
|
|
13003
13218
|
|
|
@@ -15722,15 +15937,14 @@ function requireSemver () {
|
|
|
15722
15937
|
var semverExports = requireSemver();
|
|
15723
15938
|
var semver = /*@__PURE__*/getDefaultExportFromCjs(semverExports);
|
|
15724
15939
|
|
|
15725
|
-
const SCHEMA_IGNORED = [
|
|
15940
|
+
const SCHEMA_IGNORED = [...KEY_FIELDS, "env_vars", "secrets", "order"];
|
|
15941
|
+
const SCHEMA_UNORDERED = ["triggers.*.options.authenticate"];
|
|
15726
15942
|
function indexFilename(language) {
|
|
15727
15943
|
return language === "typescript" ? "index.ts" : "index.mjs";
|
|
15728
15944
|
}
|
|
15729
15945
|
function extractId(v) {
|
|
15730
|
-
|
|
15731
|
-
|
|
15732
|
-
}
|
|
15733
|
-
return String(v);
|
|
15946
|
+
const key = recordKey(v);
|
|
15947
|
+
return key === undefined ? String(v) : String(key);
|
|
15734
15948
|
}
|
|
15735
15949
|
function byCodeUnit$1(a, b) {
|
|
15736
15950
|
if (a === b)
|
|
@@ -15747,14 +15961,6 @@ function normalizeSchema(schema) {
|
|
|
15747
15961
|
}
|
|
15748
15962
|
return normalized;
|
|
15749
15963
|
}
|
|
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
15964
|
function isNotFoundError(error) {
|
|
15759
15965
|
if (!error || typeof error !== "object")
|
|
15760
15966
|
return false;
|
|
@@ -15787,6 +15993,7 @@ const functionModule = {
|
|
|
15787
15993
|
displayName: "Function",
|
|
15788
15994
|
identityField: "name",
|
|
15789
15995
|
ignoredFields: SCHEMA_IGNORED,
|
|
15996
|
+
unorderedPaths: SCHEMA_UNORDERED,
|
|
15790
15997
|
readSchema(rootDir, slug, source = diskSource) {
|
|
15791
15998
|
return readSourceYaml(source, path.join(rootDir, "function", slug, "schema.yaml"));
|
|
15792
15999
|
},
|
|
@@ -15818,11 +16025,11 @@ const functionModule = {
|
|
|
15818
16025
|
}
|
|
15819
16026
|
return results;
|
|
15820
16027
|
},
|
|
15821
|
-
async readRemote(http
|
|
16028
|
+
async readRemote(http) {
|
|
15822
16029
|
const res = await http.get("function");
|
|
15823
16030
|
const fns = unwrapList(res);
|
|
15824
|
-
return
|
|
15825
|
-
const id = fn
|
|
16031
|
+
return Promise.all(fns.map(async (fn) => {
|
|
16032
|
+
const id = recordKey(fn);
|
|
15826
16033
|
const [indexRes, depsRes] = await Promise.all([
|
|
15827
16034
|
http.get(`function/${id}/index`).catch(emptyIfMissing({ index: "" })),
|
|
15828
16035
|
http
|
|
@@ -15844,7 +16051,7 @@ const functionModule = {
|
|
|
15844
16051
|
dependencies
|
|
15845
16052
|
}
|
|
15846
16053
|
};
|
|
15847
|
-
});
|
|
16054
|
+
}));
|
|
15848
16055
|
},
|
|
15849
16056
|
async create(http, local) {
|
|
15850
16057
|
const id = await this.createSchema(http, local.data.schema);
|
|
@@ -15855,7 +16062,7 @@ const functionModule = {
|
|
|
15855
16062
|
},
|
|
15856
16063
|
async createSchema(http, schema) {
|
|
15857
16064
|
const created = await http.post("function", omit(schema, ["env_vars", "secrets"]));
|
|
15858
|
-
const id = (created
|
|
16065
|
+
const id = recordKey(created) ?? recordKey(schema);
|
|
15859
16066
|
if (!id)
|
|
15860
16067
|
return undefined;
|
|
15861
16068
|
const envVarIds = schema.env_vars ?? [];
|
|
@@ -15938,7 +16145,7 @@ const functionModule = {
|
|
|
15938
16145
|
},
|
|
15939
16146
|
diffFields(local, remote) {
|
|
15940
16147
|
const changed = [];
|
|
15941
|
-
const schemaChanged = diffObjectFields(local.schema, remote.schema, SCHEMA_IGNORED);
|
|
16148
|
+
const schemaChanged = diffObjectFields(local.schema, remote.schema, SCHEMA_IGNORED, SCHEMA_UNORDERED);
|
|
15942
16149
|
if (schemaChanged.length)
|
|
15943
16150
|
changed.push("schema");
|
|
15944
16151
|
if (local.index !== remote.index)
|
|
@@ -15957,8 +16164,8 @@ const functionModule = {
|
|
|
15957
16164
|
},
|
|
15958
16165
|
renderDetail(local, remote) {
|
|
15959
16166
|
const result = {};
|
|
15960
|
-
const localSchemaYaml =
|
|
15961
|
-
const remoteSchemaYaml =
|
|
16167
|
+
const localSchemaYaml = stringifyForDiff(sortUnorderedArrays(omit(local.data.schema, SCHEMA_IGNORED), SCHEMA_UNORDERED));
|
|
16168
|
+
const remoteSchemaYaml = stringifyForDiff(sortUnorderedArrays(omit(remote.data.schema, SCHEMA_IGNORED), SCHEMA_UNORDERED));
|
|
15962
16169
|
if (localSchemaYaml !== remoteSchemaYaml) {
|
|
15963
16170
|
result["schema"] = buildUnifiedDiff(remoteSchemaYaml, localSchemaYaml, "schema.yaml");
|
|
15964
16171
|
}
|
|
@@ -15978,7 +16185,7 @@ const functionModule = {
|
|
|
15978
16185
|
return `${triggerCount} trigger${triggerCount !== 1 ? "s" : ""}`;
|
|
15979
16186
|
},
|
|
15980
16187
|
extractLocalId(data) {
|
|
15981
|
-
return data.schema
|
|
16188
|
+
return recordKey(data.schema);
|
|
15982
16189
|
},
|
|
15983
16190
|
watchedFiles: ["schema.yaml", "index.ts", "index.mjs", "index.js", "package.json"],
|
|
15984
16191
|
async devHandleEvent(ctx) {
|
|
@@ -16005,7 +16212,7 @@ const functionModule = {
|
|
|
16005
16212
|
const schema = self.readSchema(rootDir, slug);
|
|
16006
16213
|
if (!schema)
|
|
16007
16214
|
return;
|
|
16008
|
-
const newLocalId = schema
|
|
16215
|
+
const newLocalId = recordKey(schema);
|
|
16009
16216
|
if (newLocalId) {
|
|
16010
16217
|
const pending = consumePendingDeleteByRemoteId(newLocalId);
|
|
16011
16218
|
if (pending) {
|
|
@@ -16066,12 +16273,18 @@ const functionModule = {
|
|
|
16066
16273
|
}
|
|
16067
16274
|
};
|
|
16068
16275
|
|
|
16069
|
-
const IGNORED_FIELDS$1 = [
|
|
16276
|
+
const IGNORED_FIELDS$1 = [...KEY_FIELDS, "system"];
|
|
16277
|
+
const UNORDERED_PATHS = [
|
|
16278
|
+
"statement",
|
|
16279
|
+
"statement.*.resource.include",
|
|
16280
|
+
"statement.*.resource.exclude"
|
|
16281
|
+
];
|
|
16070
16282
|
const policyModule = {
|
|
16071
16283
|
name: "policy",
|
|
16072
16284
|
displayName: "Policy",
|
|
16073
16285
|
identityField: "name",
|
|
16074
16286
|
ignoredFields: IGNORED_FIELDS$1,
|
|
16287
|
+
unorderedPaths: UNORDERED_PATHS,
|
|
16075
16288
|
readLocal(rootDir, source) {
|
|
16076
16289
|
return readLocalSchemas(rootDir, "policy", source);
|
|
16077
16290
|
},
|
|
@@ -16082,7 +16295,7 @@ const policyModule = {
|
|
|
16082
16295
|
.filter(p => !p.system)
|
|
16083
16296
|
.map(p => ({
|
|
16084
16297
|
slug: sanitizeSlug(p.name),
|
|
16085
|
-
id: p
|
|
16298
|
+
id: recordKey(p),
|
|
16086
16299
|
data: p
|
|
16087
16300
|
}));
|
|
16088
16301
|
},
|
|
@@ -16104,21 +16317,21 @@ const policyModule = {
|
|
|
16104
16317
|
deleteLocalSchema(rootDir, "policy", slug);
|
|
16105
16318
|
},
|
|
16106
16319
|
diffFields(local, remote) {
|
|
16107
|
-
return diffSchemaFields(local, remote, IGNORED_FIELDS$1);
|
|
16320
|
+
return diffSchemaFields(local, remote, IGNORED_FIELDS$1, UNORDERED_PATHS);
|
|
16108
16321
|
},
|
|
16109
16322
|
renderDetail(local, remote) {
|
|
16110
|
-
return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS$1);
|
|
16323
|
+
return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS$1, UNORDERED_PATHS);
|
|
16111
16324
|
},
|
|
16112
16325
|
summaryLine(resource) {
|
|
16113
16326
|
const stmts = resource.data.statement?.length ?? 0;
|
|
16114
16327
|
return `${stmts} statement${stmts !== 1 ? "s" : ""}`;
|
|
16115
16328
|
},
|
|
16116
16329
|
extractLocalId(data) {
|
|
16117
|
-
return data
|
|
16330
|
+
return recordKey(data);
|
|
16118
16331
|
}
|
|
16119
16332
|
};
|
|
16120
16333
|
|
|
16121
|
-
const IGNORED_FIELDS = [
|
|
16334
|
+
const IGNORED_FIELDS = [...KEY_FIELDS, "value", "updated_at"];
|
|
16122
16335
|
const secretModule = {
|
|
16123
16336
|
name: "secret",
|
|
16124
16337
|
displayName: "Secret",
|
|
@@ -16132,7 +16345,7 @@ const secretModule = {
|
|
|
16132
16345
|
const items = unwrapList(res);
|
|
16133
16346
|
return items.map(s => ({
|
|
16134
16347
|
slug: sanitizeSlug(s.key),
|
|
16135
|
-
id: s
|
|
16348
|
+
id: recordKey(s),
|
|
16136
16349
|
data: s
|
|
16137
16350
|
}));
|
|
16138
16351
|
},
|
|
@@ -16161,7 +16374,7 @@ const secretModule = {
|
|
|
16161
16374
|
return `key: ${resource.data.key}`;
|
|
16162
16375
|
},
|
|
16163
16376
|
extractLocalId(data) {
|
|
16164
|
-
return data
|
|
16377
|
+
return recordKey(data);
|
|
16165
16378
|
}
|
|
16166
16379
|
};
|
|
16167
16380
|
|