@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.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$
|
|
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$
|
|
190
|
+
visit$2.BREAK = BREAK$1;
|
|
112
191
|
/** Do not visit the children of the current node */
|
|
113
|
-
visit$
|
|
192
|
+
visit$2.SKIP = SKIP$1;
|
|
114
193
|
/** Remove the current node */
|
|
115
|
-
visit$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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
|
-
|
|
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
|
|
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,
|
|
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
|
-
|
|
12808
|
-
|
|
12809
|
-
|
|
12810
|
-
|
|
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
|
-
|
|
12817
|
-
|
|
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(
|
|
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 =
|
|
12848
|
-
const remoteYaml =
|
|
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
|
-
|
|
12859
|
-
|
|
12860
|
-
|
|
12861
|
-
|
|
12862
|
-
|
|
12863
|
-
|
|
12864
|
-
|
|
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,26 @@ function formatError(e) {
|
|
|
12885
13086
|
return String(e);
|
|
12886
13087
|
}
|
|
12887
13088
|
|
|
12888
|
-
const
|
|
13089
|
+
const KEY_FIELDS = ["_id", "id"];
|
|
13090
|
+
function recordKeyField(record) {
|
|
13091
|
+
if (record === null || typeof record != "object") {
|
|
13092
|
+
return undefined;
|
|
13093
|
+
}
|
|
13094
|
+
return KEY_FIELDS.find(field => field in record);
|
|
13095
|
+
}
|
|
13096
|
+
function recordKey(record) {
|
|
13097
|
+
const field = recordKeyField(record);
|
|
13098
|
+
return field ? record[field] : undefined;
|
|
13099
|
+
}
|
|
13100
|
+
|
|
13101
|
+
const IGNORED_FIELDS$3 = [...KEY_FIELDS, "order"];
|
|
13102
|
+
const UNORDERED_PATHS$1 = ["required", "properties.**.required", "indexes"];
|
|
12889
13103
|
const bucketModule = {
|
|
12890
13104
|
name: "bucket",
|
|
12891
13105
|
displayName: "Bucket",
|
|
12892
13106
|
identityField: "title",
|
|
12893
13107
|
ignoredFields: IGNORED_FIELDS$3,
|
|
13108
|
+
unorderedPaths: UNORDERED_PATHS$1,
|
|
12894
13109
|
readLocal(rootDir, source) {
|
|
12895
13110
|
return readLocalSchemas(rootDir, "bucket", source);
|
|
12896
13111
|
},
|
|
@@ -12899,7 +13114,7 @@ const bucketModule = {
|
|
|
12899
13114
|
const buckets = unwrapList(res);
|
|
12900
13115
|
return buckets.map(b => ({
|
|
12901
13116
|
slug: sanitizeSlug(b.title),
|
|
12902
|
-
id: b
|
|
13117
|
+
id: recordKey(b),
|
|
12903
13118
|
data: b
|
|
12904
13119
|
}));
|
|
12905
13120
|
},
|
|
@@ -12919,21 +13134,21 @@ const bucketModule = {
|
|
|
12919
13134
|
deleteLocalSchema(rootDir, "bucket", slug);
|
|
12920
13135
|
},
|
|
12921
13136
|
diffFields(local, remote) {
|
|
12922
|
-
return diffSchemaFields(local, remote, IGNORED_FIELDS$3);
|
|
13137
|
+
return diffSchemaFields(local, remote, IGNORED_FIELDS$3, UNORDERED_PATHS$1);
|
|
12923
13138
|
},
|
|
12924
13139
|
renderDetail(local, remote) {
|
|
12925
|
-
return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS$3);
|
|
13140
|
+
return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS$3, UNORDERED_PATHS$1);
|
|
12926
13141
|
},
|
|
12927
13142
|
summaryLine(resource) {
|
|
12928
13143
|
const propCount = Object.keys(resource.data.properties ?? {}).length;
|
|
12929
13144
|
return `${propCount} properties`;
|
|
12930
13145
|
},
|
|
12931
13146
|
extractLocalId(data) {
|
|
12932
|
-
return data
|
|
13147
|
+
return recordKey(data);
|
|
12933
13148
|
}
|
|
12934
13149
|
};
|
|
12935
13150
|
|
|
12936
|
-
const IGNORED_FIELDS$2 = [
|
|
13151
|
+
const IGNORED_FIELDS$2 = [...KEY_FIELDS, "updated_at"];
|
|
12937
13152
|
const envVarModule = {
|
|
12938
13153
|
name: "env-var",
|
|
12939
13154
|
displayName: "Environment Variable",
|
|
@@ -12947,7 +13162,7 @@ const envVarModule = {
|
|
|
12947
13162
|
const items = unwrapList(res);
|
|
12948
13163
|
return items.map(e => ({
|
|
12949
13164
|
slug: sanitizeSlug(e.key),
|
|
12950
|
-
id: e
|
|
13165
|
+
id: recordKey(e),
|
|
12951
13166
|
data: e
|
|
12952
13167
|
}));
|
|
12953
13168
|
},
|
|
@@ -12976,7 +13191,7 @@ const envVarModule = {
|
|
|
12976
13191
|
return `key: ${resource.data.key}`;
|
|
12977
13192
|
},
|
|
12978
13193
|
extractLocalId(data) {
|
|
12979
|
-
return data
|
|
13194
|
+
return recordKey(data);
|
|
12980
13195
|
}
|
|
12981
13196
|
};
|
|
12982
13197
|
|
|
@@ -15701,15 +15916,14 @@ function requireSemver () {
|
|
|
15701
15916
|
var semverExports = requireSemver();
|
|
15702
15917
|
var semver = /*@__PURE__*/getDefaultExportFromCjs(semverExports);
|
|
15703
15918
|
|
|
15704
|
-
const SCHEMA_IGNORED = [
|
|
15919
|
+
const SCHEMA_IGNORED = [...KEY_FIELDS, "env_vars", "secrets", "order"];
|
|
15920
|
+
const SCHEMA_UNORDERED = ["triggers.*.options.authenticate"];
|
|
15705
15921
|
function indexFilename(language) {
|
|
15706
15922
|
return language === "typescript" ? "index.ts" : "index.mjs";
|
|
15707
15923
|
}
|
|
15708
15924
|
function extractId(v) {
|
|
15709
|
-
|
|
15710
|
-
|
|
15711
|
-
}
|
|
15712
|
-
return String(v);
|
|
15925
|
+
const key = recordKey(v);
|
|
15926
|
+
return key === undefined ? String(v) : String(key);
|
|
15713
15927
|
}
|
|
15714
15928
|
function byCodeUnit$1(a, b) {
|
|
15715
15929
|
if (a === b)
|
|
@@ -15726,14 +15940,6 @@ function normalizeSchema(schema) {
|
|
|
15726
15940
|
}
|
|
15727
15941
|
return normalized;
|
|
15728
15942
|
}
|
|
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
15943
|
function isNotFoundError(error) {
|
|
15738
15944
|
if (!error || typeof error !== "object")
|
|
15739
15945
|
return false;
|
|
@@ -15766,6 +15972,7 @@ const functionModule = {
|
|
|
15766
15972
|
displayName: "Function",
|
|
15767
15973
|
identityField: "name",
|
|
15768
15974
|
ignoredFields: SCHEMA_IGNORED,
|
|
15975
|
+
unorderedPaths: SCHEMA_UNORDERED,
|
|
15769
15976
|
readSchema(rootDir, slug, source = diskSource) {
|
|
15770
15977
|
return readSourceYaml(source, path.join(rootDir, "function", slug, "schema.yaml"));
|
|
15771
15978
|
},
|
|
@@ -15797,11 +16004,11 @@ const functionModule = {
|
|
|
15797
16004
|
}
|
|
15798
16005
|
return results;
|
|
15799
16006
|
},
|
|
15800
|
-
async readRemote(http
|
|
16007
|
+
async readRemote(http) {
|
|
15801
16008
|
const res = await http.get("function");
|
|
15802
16009
|
const fns = unwrapList(res);
|
|
15803
|
-
return
|
|
15804
|
-
const id = fn
|
|
16010
|
+
return Promise.all(fns.map(async (fn) => {
|
|
16011
|
+
const id = recordKey(fn);
|
|
15805
16012
|
const [indexRes, depsRes] = await Promise.all([
|
|
15806
16013
|
http.get(`function/${id}/index`).catch(emptyIfMissing({ index: "" })),
|
|
15807
16014
|
http
|
|
@@ -15823,7 +16030,7 @@ const functionModule = {
|
|
|
15823
16030
|
dependencies
|
|
15824
16031
|
}
|
|
15825
16032
|
};
|
|
15826
|
-
});
|
|
16033
|
+
}));
|
|
15827
16034
|
},
|
|
15828
16035
|
async create(http, local) {
|
|
15829
16036
|
const id = await this.createSchema(http, local.data.schema);
|
|
@@ -15834,7 +16041,7 @@ const functionModule = {
|
|
|
15834
16041
|
},
|
|
15835
16042
|
async createSchema(http, schema) {
|
|
15836
16043
|
const created = await http.post("function", omit(schema, ["env_vars", "secrets"]));
|
|
15837
|
-
const id = (created
|
|
16044
|
+
const id = recordKey(created) ?? recordKey(schema);
|
|
15838
16045
|
if (!id)
|
|
15839
16046
|
return undefined;
|
|
15840
16047
|
const envVarIds = schema.env_vars ?? [];
|
|
@@ -15917,7 +16124,7 @@ const functionModule = {
|
|
|
15917
16124
|
},
|
|
15918
16125
|
diffFields(local, remote) {
|
|
15919
16126
|
const changed = [];
|
|
15920
|
-
const schemaChanged = diffObjectFields(local.schema, remote.schema, SCHEMA_IGNORED);
|
|
16127
|
+
const schemaChanged = diffObjectFields(local.schema, remote.schema, SCHEMA_IGNORED, SCHEMA_UNORDERED);
|
|
15921
16128
|
if (schemaChanged.length)
|
|
15922
16129
|
changed.push("schema");
|
|
15923
16130
|
if (local.index !== remote.index)
|
|
@@ -15936,8 +16143,8 @@ const functionModule = {
|
|
|
15936
16143
|
},
|
|
15937
16144
|
renderDetail(local, remote) {
|
|
15938
16145
|
const result = {};
|
|
15939
|
-
const localSchemaYaml =
|
|
15940
|
-
const remoteSchemaYaml =
|
|
16146
|
+
const localSchemaYaml = stringifyForDiff(sortUnorderedArrays(omit(local.data.schema, SCHEMA_IGNORED), SCHEMA_UNORDERED));
|
|
16147
|
+
const remoteSchemaYaml = stringifyForDiff(sortUnorderedArrays(omit(remote.data.schema, SCHEMA_IGNORED), SCHEMA_UNORDERED));
|
|
15941
16148
|
if (localSchemaYaml !== remoteSchemaYaml) {
|
|
15942
16149
|
result["schema"] = buildUnifiedDiff(remoteSchemaYaml, localSchemaYaml, "schema.yaml");
|
|
15943
16150
|
}
|
|
@@ -15957,7 +16164,7 @@ const functionModule = {
|
|
|
15957
16164
|
return `${triggerCount} trigger${triggerCount !== 1 ? "s" : ""}`;
|
|
15958
16165
|
},
|
|
15959
16166
|
extractLocalId(data) {
|
|
15960
|
-
return data.schema
|
|
16167
|
+
return recordKey(data.schema);
|
|
15961
16168
|
},
|
|
15962
16169
|
watchedFiles: ["schema.yaml", "index.ts", "index.mjs", "index.js", "package.json"],
|
|
15963
16170
|
async devHandleEvent(ctx) {
|
|
@@ -15984,7 +16191,7 @@ const functionModule = {
|
|
|
15984
16191
|
const schema = self.readSchema(rootDir, slug);
|
|
15985
16192
|
if (!schema)
|
|
15986
16193
|
return;
|
|
15987
|
-
const newLocalId = schema
|
|
16194
|
+
const newLocalId = recordKey(schema);
|
|
15988
16195
|
if (newLocalId) {
|
|
15989
16196
|
const pending = consumePendingDeleteByRemoteId(newLocalId);
|
|
15990
16197
|
if (pending) {
|
|
@@ -16045,12 +16252,18 @@ const functionModule = {
|
|
|
16045
16252
|
}
|
|
16046
16253
|
};
|
|
16047
16254
|
|
|
16048
|
-
const IGNORED_FIELDS$1 = [
|
|
16255
|
+
const IGNORED_FIELDS$1 = [...KEY_FIELDS, "system"];
|
|
16256
|
+
const UNORDERED_PATHS = [
|
|
16257
|
+
"statement",
|
|
16258
|
+
"statement.*.resource.include",
|
|
16259
|
+
"statement.*.resource.exclude"
|
|
16260
|
+
];
|
|
16049
16261
|
const policyModule = {
|
|
16050
16262
|
name: "policy",
|
|
16051
16263
|
displayName: "Policy",
|
|
16052
16264
|
identityField: "name",
|
|
16053
16265
|
ignoredFields: IGNORED_FIELDS$1,
|
|
16266
|
+
unorderedPaths: UNORDERED_PATHS,
|
|
16054
16267
|
readLocal(rootDir, source) {
|
|
16055
16268
|
return readLocalSchemas(rootDir, "policy", source);
|
|
16056
16269
|
},
|
|
@@ -16061,7 +16274,7 @@ const policyModule = {
|
|
|
16061
16274
|
.filter(p => !p.system)
|
|
16062
16275
|
.map(p => ({
|
|
16063
16276
|
slug: sanitizeSlug(p.name),
|
|
16064
|
-
id: p
|
|
16277
|
+
id: recordKey(p),
|
|
16065
16278
|
data: p
|
|
16066
16279
|
}));
|
|
16067
16280
|
},
|
|
@@ -16083,21 +16296,21 @@ const policyModule = {
|
|
|
16083
16296
|
deleteLocalSchema(rootDir, "policy", slug);
|
|
16084
16297
|
},
|
|
16085
16298
|
diffFields(local, remote) {
|
|
16086
|
-
return diffSchemaFields(local, remote, IGNORED_FIELDS$1);
|
|
16299
|
+
return diffSchemaFields(local, remote, IGNORED_FIELDS$1, UNORDERED_PATHS);
|
|
16087
16300
|
},
|
|
16088
16301
|
renderDetail(local, remote) {
|
|
16089
|
-
return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS$1);
|
|
16302
|
+
return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS$1, UNORDERED_PATHS);
|
|
16090
16303
|
},
|
|
16091
16304
|
summaryLine(resource) {
|
|
16092
16305
|
const stmts = resource.data.statement?.length ?? 0;
|
|
16093
16306
|
return `${stmts} statement${stmts !== 1 ? "s" : ""}`;
|
|
16094
16307
|
},
|
|
16095
16308
|
extractLocalId(data) {
|
|
16096
|
-
return data
|
|
16309
|
+
return recordKey(data);
|
|
16097
16310
|
}
|
|
16098
16311
|
};
|
|
16099
16312
|
|
|
16100
|
-
const IGNORED_FIELDS = [
|
|
16313
|
+
const IGNORED_FIELDS = [...KEY_FIELDS, "value", "updated_at"];
|
|
16101
16314
|
const secretModule = {
|
|
16102
16315
|
name: "secret",
|
|
16103
16316
|
displayName: "Secret",
|
|
@@ -16111,7 +16324,7 @@ const secretModule = {
|
|
|
16111
16324
|
const items = unwrapList(res);
|
|
16112
16325
|
return items.map(s => ({
|
|
16113
16326
|
slug: sanitizeSlug(s.key),
|
|
16114
|
-
id: s
|
|
16327
|
+
id: recordKey(s),
|
|
16115
16328
|
data: s
|
|
16116
16329
|
}));
|
|
16117
16330
|
},
|
|
@@ -16140,7 +16353,7 @@ const secretModule = {
|
|
|
16140
16353
|
return `key: ${resource.data.key}`;
|
|
16141
16354
|
},
|
|
16142
16355
|
extractLocalId(data) {
|
|
16143
|
-
return data
|
|
16356
|
+
return recordKey(data);
|
|
16144
16357
|
}
|
|
16145
16358
|
};
|
|
16146
16359
|
|