@spica/cli 0.20.7 → 0.20.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +200 -62
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// apps/cli/index.ts
|
|
2
|
-
import
|
|
2
|
+
import caporalCore8 from "@caporal/core";
|
|
3
3
|
|
|
4
4
|
// apps/cli/src/console.ts
|
|
5
5
|
import { blue, bold, red, yellow } from "colorette";
|
|
@@ -3443,6 +3443,83 @@ var ChangeKind;
|
|
|
3443
3443
|
})(ChangeKind || (ChangeKind = {}));
|
|
3444
3444
|
var DEFAULT_CONCURRENCY = 10;
|
|
3445
3445
|
|
|
3446
|
+
// packages/sync/dist/src/concurrency.js
|
|
3447
|
+
var REQUEST_METHODS = ["get", "delete", "head", "post", "patch", "put"];
|
|
3448
|
+
var limitedClients = /* @__PURE__ */ new WeakMap();
|
|
3449
|
+
function limitConcurrency(http2, limit = DEFAULT_CONCURRENCY, signal) {
|
|
3450
|
+
const existing = limitedClients.get(http2);
|
|
3451
|
+
if (existing && !signal)
|
|
3452
|
+
return http2;
|
|
3453
|
+
const { semaphore, target } = existing ?? {
|
|
3454
|
+
semaphore: new Semaphore(normalizeLimit(limit)),
|
|
3455
|
+
target: http2
|
|
3456
|
+
};
|
|
3457
|
+
const limited = { ...target };
|
|
3458
|
+
for (const method of REQUEST_METHODS) {
|
|
3459
|
+
limited[method] = (...args) => semaphore.run(() => {
|
|
3460
|
+
if (signal?.aborted)
|
|
3461
|
+
throw signal.reason;
|
|
3462
|
+
return target[method](...args);
|
|
3463
|
+
});
|
|
3464
|
+
}
|
|
3465
|
+
limitedClients.set(limited, { semaphore, target });
|
|
3466
|
+
return limited;
|
|
3467
|
+
}
|
|
3468
|
+
async function mapWithConcurrency(items, limit, fn) {
|
|
3469
|
+
const results = new Array(items.length);
|
|
3470
|
+
let next = 0;
|
|
3471
|
+
let failure;
|
|
3472
|
+
const worker = async () => {
|
|
3473
|
+
while (!failure && next < items.length) {
|
|
3474
|
+
const index = next++;
|
|
3475
|
+
try {
|
|
3476
|
+
results[index] = await fn(items[index], index);
|
|
3477
|
+
} catch (error) {
|
|
3478
|
+
if (!failure)
|
|
3479
|
+
failure = { error };
|
|
3480
|
+
}
|
|
3481
|
+
}
|
|
3482
|
+
};
|
|
3483
|
+
const workerCount = Math.min(normalizeLimit(limit), items.length);
|
|
3484
|
+
await Promise.all(Array.from({ length: workerCount }, worker));
|
|
3485
|
+
if (failure)
|
|
3486
|
+
throw failure.error;
|
|
3487
|
+
return results;
|
|
3488
|
+
}
|
|
3489
|
+
function normalizeLimit(limit) {
|
|
3490
|
+
return Number.isFinite(limit) ? Math.max(1, Math.floor(limit)) : DEFAULT_CONCURRENCY;
|
|
3491
|
+
}
|
|
3492
|
+
var Semaphore = class {
|
|
3493
|
+
constructor(limit) {
|
|
3494
|
+
this.limit = limit;
|
|
3495
|
+
this.active = 0;
|
|
3496
|
+
this.waiting = [];
|
|
3497
|
+
}
|
|
3498
|
+
async run(task) {
|
|
3499
|
+
await this.acquire();
|
|
3500
|
+
try {
|
|
3501
|
+
return await task();
|
|
3502
|
+
} finally {
|
|
3503
|
+
this.release();
|
|
3504
|
+
}
|
|
3505
|
+
}
|
|
3506
|
+
acquire() {
|
|
3507
|
+
if (this.active < this.limit) {
|
|
3508
|
+
this.active++;
|
|
3509
|
+
return Promise.resolve();
|
|
3510
|
+
}
|
|
3511
|
+
return new Promise((resolve) => this.waiting.push(resolve));
|
|
3512
|
+
}
|
|
3513
|
+
release() {
|
|
3514
|
+
const next = this.waiting.shift();
|
|
3515
|
+
if (next) {
|
|
3516
|
+
next();
|
|
3517
|
+
} else {
|
|
3518
|
+
this.active--;
|
|
3519
|
+
}
|
|
3520
|
+
}
|
|
3521
|
+
};
|
|
3522
|
+
|
|
3446
3523
|
// packages/sync/dist/src/reporter.js
|
|
3447
3524
|
var noopProgress = {
|
|
3448
3525
|
update() {
|
|
@@ -3547,13 +3624,58 @@ import { bold as bold4, cyan, green as green4, red as red4, yellow as yellow2 }
|
|
|
3547
3624
|
import isEqual2 from "lodash/isEqual.js";
|
|
3548
3625
|
import { createTwoFilesPatch } from "diff";
|
|
3549
3626
|
import yaml2 from "yaml";
|
|
3550
|
-
|
|
3627
|
+
|
|
3628
|
+
// packages/sync/dist/src/unordered.js
|
|
3629
|
+
import isPlainObject from "lodash/isPlainObject.js";
|
|
3630
|
+
function sortUnorderedArrays(data, paths = []) {
|
|
3631
|
+
if (!paths.length)
|
|
3632
|
+
return data;
|
|
3633
|
+
return visit(data, [], paths.map((p) => p.split(".")));
|
|
3634
|
+
}
|
|
3635
|
+
function visit(node, path15, patterns) {
|
|
3636
|
+
let visited = node;
|
|
3637
|
+
if (Array.isArray(node)) {
|
|
3638
|
+
visited = node.map((item, i) => visit(item, [...path15, String(i)], patterns));
|
|
3639
|
+
} else if (isPlainObject(node)) {
|
|
3640
|
+
visited = Object.fromEntries(Object.entries(node).map(([k, v]) => [
|
|
3641
|
+
k,
|
|
3642
|
+
visit(v, [...path15, k], patterns)
|
|
3643
|
+
]));
|
|
3644
|
+
}
|
|
3645
|
+
if (Array.isArray(visited) && patterns.some((p) => matches(p, path15))) {
|
|
3646
|
+
return visited.map((item) => ({ item, key: canonical(item) })).sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0).map(({ item }) => item);
|
|
3647
|
+
}
|
|
3648
|
+
return visited;
|
|
3649
|
+
}
|
|
3650
|
+
function matches(pattern, path15) {
|
|
3651
|
+
if (!pattern.length)
|
|
3652
|
+
return !path15.length;
|
|
3653
|
+
const [head, ...rest] = pattern;
|
|
3654
|
+
if (head === "**") {
|
|
3655
|
+
return matches(rest, path15) || path15.length > 0 && matches(pattern, path15.slice(1));
|
|
3656
|
+
}
|
|
3657
|
+
return path15.length > 0 && (head === "*" || head === path15[0]) && matches(rest, path15.slice(1));
|
|
3658
|
+
}
|
|
3659
|
+
function canonical(value) {
|
|
3660
|
+
if (Array.isArray(value))
|
|
3661
|
+
return `[${value.map(canonical).join(",")}]`;
|
|
3662
|
+
if (isPlainObject(value)) {
|
|
3663
|
+
const obj = value;
|
|
3664
|
+
const entries = Object.keys(obj).sort().map((k) => `${JSON.stringify(k)}:${canonical(obj[k])}`);
|
|
3665
|
+
return `{${entries.join(",")}}`;
|
|
3666
|
+
}
|
|
3667
|
+
return JSON.stringify(value) ?? "undefined";
|
|
3668
|
+
}
|
|
3669
|
+
|
|
3670
|
+
// packages/sync/dist/src/planner.js
|
|
3671
|
+
async function buildPlan(modules, unlimitedHttp, rootDir, options = {}) {
|
|
3551
3672
|
const { detailed = false, detectRenames = true, reporter = silentReporter, concurrency = DEFAULT_CONCURRENCY, source } = options;
|
|
3673
|
+
const http2 = limitConcurrency(unlimitedHttp, concurrency);
|
|
3552
3674
|
const modulePlans = [];
|
|
3553
3675
|
for (const mod of modules) {
|
|
3554
3676
|
const [locals, remotes] = await Promise.all([
|
|
3555
3677
|
reporter.task(`Reading local ${mod.displayName} files`, () => mod.readLocal(rootDir, source)),
|
|
3556
|
-
reporter.task(`Fetching remote ${mod.displayName}`, () => mod.readRemote(http2
|
|
3678
|
+
reporter.task(`Fetching remote ${mod.displayName}`, () => mod.readRemote(http2))
|
|
3557
3679
|
]);
|
|
3558
3680
|
const localBySlug = new Map(locals.map((l) => [l.slug, l]));
|
|
3559
3681
|
const remoteBySlug = new Map(remotes.map((r) => [r.slug, r]));
|
|
@@ -3750,29 +3872,30 @@ function renderUnifiedDiff(diff, reversed = false) {
|
|
|
3750
3872
|
}
|
|
3751
3873
|
}
|
|
3752
3874
|
}
|
|
3753
|
-
async function applyPlan(plan2,
|
|
3875
|
+
async function applyPlan(plan2, unlimitedHttp, opts = {}) {
|
|
3754
3876
|
const concurrency = opts.concurrency ?? DEFAULT_CONCURRENCY;
|
|
3755
3877
|
const reporter = opts.reporter ?? silentReporter;
|
|
3756
3878
|
const errors = [];
|
|
3879
|
+
const abortController = new AbortController();
|
|
3880
|
+
const http2 = limitConcurrency(unlimitedHttp, concurrency, abortController.signal);
|
|
3881
|
+
let abortError;
|
|
3757
3882
|
const handleErr = (label, e) => {
|
|
3758
|
-
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
|
|
3883
|
+
if (abortError)
|
|
3884
|
+
throw abortError;
|
|
3885
|
+
const full = `${label}: ${formatError(e)}`;
|
|
3886
|
+
if (opts.abortOnError) {
|
|
3887
|
+
abortError = new Error(full);
|
|
3888
|
+
abortController.abort(abortError);
|
|
3889
|
+
throw abortError;
|
|
3890
|
+
}
|
|
3762
3891
|
reporter.warn(full);
|
|
3763
3892
|
errors.push(full);
|
|
3764
3893
|
};
|
|
3765
3894
|
for (const mp of plan2.modules) {
|
|
3766
3895
|
const { module: mod, creates, updates, deletes } = mp;
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
}
|
|
3770
|
-
if (updates.length) {
|
|
3771
|
-
await runConcurrently(updates.map((e) => ({ slug: e.slug, run: () => mod.update(http2, e.local, e.remote.id) })), concurrency, `Updating ${mod.displayName}`, handleErr, reporter);
|
|
3772
|
-
}
|
|
3773
|
-
if (creates.length) {
|
|
3774
|
-
await runConcurrently(creates.map((e) => ({ slug: e.slug, run: () => mod.create(http2, e.local) })), concurrency, `Creating ${mod.displayName}`, handleErr, reporter);
|
|
3775
|
-
}
|
|
3896
|
+
await runAllAtOnce(deletes.map((e) => ({ slug: e.slug, run: () => mod.delete(http2, e.remote.id) })), `Deleting ${mod.displayName}`, handleErr, reporter);
|
|
3897
|
+
await runAllAtOnce(updates.map((e) => ({ slug: e.slug, run: () => mod.update(http2, e.local, e.remote.id) })), `Updating ${mod.displayName}`, handleErr, reporter);
|
|
3898
|
+
await runAllAtOnce(creates.map((e) => ({ slug: e.slug, run: () => mod.create(http2, e.local) })), `Creating ${mod.displayName}`, handleErr, reporter);
|
|
3776
3899
|
}
|
|
3777
3900
|
return { errors };
|
|
3778
3901
|
}
|
|
@@ -3814,7 +3937,9 @@ async function fetchToDisk(plan2, http2, rootDir, opts = {}) {
|
|
|
3814
3937
|
}
|
|
3815
3938
|
return { written, deleted, errors };
|
|
3816
3939
|
}
|
|
3817
|
-
function diffObjectFields(
|
|
3940
|
+
function diffObjectFields(rawLocal, rawRemote, ignoredFields, unorderedPaths = []) {
|
|
3941
|
+
const local = sortUnorderedArrays(rawLocal, unorderedPaths);
|
|
3942
|
+
const remote = sortUnorderedArrays(rawRemote, unorderedPaths);
|
|
3818
3943
|
const allKeys = /* @__PURE__ */ new Set([...Object.keys(local), ...Object.keys(remote)]);
|
|
3819
3944
|
const changed = [];
|
|
3820
3945
|
for (const key of allKeys) {
|
|
@@ -3826,17 +3951,23 @@ function diffObjectFields(local, remote, ignoredFields) {
|
|
|
3826
3951
|
}
|
|
3827
3952
|
return changed;
|
|
3828
3953
|
}
|
|
3829
|
-
function diffSchemaFields(local, remote, ignoredFields) {
|
|
3830
|
-
return diffObjectFields(local, remote, ignoredFields);
|
|
3954
|
+
function diffSchemaFields(local, remote, ignoredFields, unorderedPaths = []) {
|
|
3955
|
+
return diffObjectFields(local, remote, ignoredFields, unorderedPaths);
|
|
3956
|
+
}
|
|
3957
|
+
function stringifyForDiff(data) {
|
|
3958
|
+
return yaml2.stringify(data, { sortMapEntries: true });
|
|
3831
3959
|
}
|
|
3832
3960
|
function buildUnifiedDiff(oldContent, newContent, filename) {
|
|
3833
3961
|
return createTwoFilesPatch(`remote/${filename}`, `local/${filename}`, oldContent, newContent);
|
|
3834
3962
|
}
|
|
3835
|
-
function renderSchemaDetail(localData, remoteData, ignoredFields) {
|
|
3836
|
-
const localYaml =
|
|
3837
|
-
const remoteYaml =
|
|
3963
|
+
function renderSchemaDetail(localData, remoteData, ignoredFields, unorderedPaths = []) {
|
|
3964
|
+
const localYaml = stringifyForDiff(sortUnorderedArrays(omit(localData, ignoredFields), unorderedPaths));
|
|
3965
|
+
const remoteYaml = stringifyForDiff(sortUnorderedArrays(omit(remoteData, ignoredFields), unorderedPaths));
|
|
3838
3966
|
return { schema: buildUnifiedDiff(remoteYaml, localYaml, "schema.yaml") };
|
|
3839
3967
|
}
|
|
3968
|
+
function runAllAtOnce(tasks, label, onError, reporter) {
|
|
3969
|
+
return runConcurrently(tasks, tasks.length, label, onError, reporter);
|
|
3970
|
+
}
|
|
3840
3971
|
async function runConcurrently(tasks, concurrency, label, onError, reporter) {
|
|
3841
3972
|
if (!tasks.length)
|
|
3842
3973
|
return;
|
|
@@ -3844,18 +3975,10 @@ async function runConcurrently(tasks, concurrency, label, onError, reporter) {
|
|
|
3844
3975
|
let done = 0;
|
|
3845
3976
|
const progress = reporter.progress(label, total);
|
|
3846
3977
|
try {
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
if (batch.length === limit || i === tasks.length - 1) {
|
|
3852
|
-
await Promise.all(batch.map((task) => task.run().catch((e) => onError(`${label}: ${task.slug}`, e)).finally(() => {
|
|
3853
|
-
done++;
|
|
3854
|
-
progress.update(task.slug, done, total);
|
|
3855
|
-
})));
|
|
3856
|
-
batch = [];
|
|
3857
|
-
}
|
|
3858
|
-
}
|
|
3978
|
+
await mapWithConcurrency(tasks, concurrency, (task) => task.run().catch((e) => onError(`${label}: ${task.slug}`, e)).finally(() => {
|
|
3979
|
+
done++;
|
|
3980
|
+
progress.update(task.slug, done, total);
|
|
3981
|
+
}));
|
|
3859
3982
|
progress.succeed();
|
|
3860
3983
|
} catch (e) {
|
|
3861
3984
|
progress.fail();
|
|
@@ -3871,12 +3994,14 @@ function formatError(e) {
|
|
|
3871
3994
|
}
|
|
3872
3995
|
|
|
3873
3996
|
// packages/sync/dist/src/modules/bucket.js
|
|
3874
|
-
var IGNORED_FIELDS = ["_id"];
|
|
3997
|
+
var IGNORED_FIELDS = ["_id", "order"];
|
|
3998
|
+
var UNORDERED_PATHS = ["required", "properties.**.required", "indexes"];
|
|
3875
3999
|
var bucketModule = {
|
|
3876
4000
|
name: "bucket",
|
|
3877
4001
|
displayName: "Bucket",
|
|
3878
4002
|
identityField: "title",
|
|
3879
4003
|
ignoredFields: IGNORED_FIELDS,
|
|
4004
|
+
unorderedPaths: UNORDERED_PATHS,
|
|
3880
4005
|
readLocal(rootDir, source) {
|
|
3881
4006
|
return readLocalSchemas(rootDir, "bucket", source);
|
|
3882
4007
|
},
|
|
@@ -3905,10 +4030,10 @@ var bucketModule = {
|
|
|
3905
4030
|
deleteLocalSchema(rootDir, "bucket", slug);
|
|
3906
4031
|
},
|
|
3907
4032
|
diffFields(local, remote) {
|
|
3908
|
-
return diffSchemaFields(local, remote, IGNORED_FIELDS);
|
|
4033
|
+
return diffSchemaFields(local, remote, IGNORED_FIELDS, UNORDERED_PATHS);
|
|
3909
4034
|
},
|
|
3910
4035
|
renderDetail(local, remote) {
|
|
3911
|
-
return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS);
|
|
4036
|
+
return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS, UNORDERED_PATHS);
|
|
3912
4037
|
},
|
|
3913
4038
|
summaryLine(resource) {
|
|
3914
4039
|
const propCount = Object.keys(resource.data.properties ?? {}).length;
|
|
@@ -3973,7 +4098,8 @@ import yaml3 from "yaml";
|
|
|
3973
4098
|
import isEqual3 from "lodash/isEqual.js";
|
|
3974
4099
|
import semver2 from "semver";
|
|
3975
4100
|
import { bold as bold5, cyan as cyan2, green as green5, yellow as yellow3 } from "colorette";
|
|
3976
|
-
var SCHEMA_IGNORED = ["_id", "env_vars", "secrets"];
|
|
4101
|
+
var SCHEMA_IGNORED = ["_id", "env_vars", "secrets", "order"];
|
|
4102
|
+
var SCHEMA_UNORDERED = ["triggers.*.options.authenticate"];
|
|
3977
4103
|
function indexFilename(language) {
|
|
3978
4104
|
return language === "typescript" ? "index.ts" : "index.mjs";
|
|
3979
4105
|
}
|
|
@@ -3998,14 +4124,6 @@ function normalizeSchema(schema) {
|
|
|
3998
4124
|
}
|
|
3999
4125
|
return normalized;
|
|
4000
4126
|
}
|
|
4001
|
-
async function mapInBatches(items, size, fn) {
|
|
4002
|
-
const limit = Math.max(1, size);
|
|
4003
|
-
const results = [];
|
|
4004
|
-
for (let i = 0; i < items.length; i += limit) {
|
|
4005
|
-
results.push(...await Promise.all(items.slice(i, i + limit).map(fn)));
|
|
4006
|
-
}
|
|
4007
|
-
return results;
|
|
4008
|
-
}
|
|
4009
4127
|
function isNotFoundError(error) {
|
|
4010
4128
|
if (!error || typeof error !== "object")
|
|
4011
4129
|
return false;
|
|
@@ -4035,6 +4153,7 @@ var functionModule = {
|
|
|
4035
4153
|
displayName: "Function",
|
|
4036
4154
|
identityField: "name",
|
|
4037
4155
|
ignoredFields: SCHEMA_IGNORED,
|
|
4156
|
+
unorderedPaths: SCHEMA_UNORDERED,
|
|
4038
4157
|
readSchema(rootDir, slug, source = diskSource) {
|
|
4039
4158
|
return readSourceYaml(source, path10.join(rootDir, "function", slug, "schema.yaml"));
|
|
4040
4159
|
},
|
|
@@ -4065,10 +4184,10 @@ var functionModule = {
|
|
|
4065
4184
|
}
|
|
4066
4185
|
return results;
|
|
4067
4186
|
},
|
|
4068
|
-
async readRemote(http2
|
|
4187
|
+
async readRemote(http2) {
|
|
4069
4188
|
const res = await http2.get("function");
|
|
4070
4189
|
const fns = unwrapList(res);
|
|
4071
|
-
return
|
|
4190
|
+
return Promise.all(fns.map(async (fn) => {
|
|
4072
4191
|
const id = fn._id;
|
|
4073
4192
|
const [indexRes, depsRes] = await Promise.all([
|
|
4074
4193
|
http2.get(`function/${id}/index`).catch(emptyIfMissing({ index: "" })),
|
|
@@ -4089,7 +4208,7 @@ var functionModule = {
|
|
|
4089
4208
|
dependencies
|
|
4090
4209
|
}
|
|
4091
4210
|
};
|
|
4092
|
-
});
|
|
4211
|
+
}));
|
|
4093
4212
|
},
|
|
4094
4213
|
async create(http2, local) {
|
|
4095
4214
|
const id = await this.createSchema(http2, local.data.schema);
|
|
@@ -4168,7 +4287,7 @@ var functionModule = {
|
|
|
4168
4287
|
},
|
|
4169
4288
|
diffFields(local, remote) {
|
|
4170
4289
|
const changed = [];
|
|
4171
|
-
const schemaChanged = diffObjectFields(local.schema, remote.schema, SCHEMA_IGNORED);
|
|
4290
|
+
const schemaChanged = diffObjectFields(local.schema, remote.schema, SCHEMA_IGNORED, SCHEMA_UNORDERED);
|
|
4172
4291
|
if (schemaChanged.length)
|
|
4173
4292
|
changed.push("schema");
|
|
4174
4293
|
if (local.index !== remote.index)
|
|
@@ -4187,8 +4306,8 @@ var functionModule = {
|
|
|
4187
4306
|
},
|
|
4188
4307
|
renderDetail(local, remote) {
|
|
4189
4308
|
const result = {};
|
|
4190
|
-
const localSchemaYaml =
|
|
4191
|
-
const remoteSchemaYaml =
|
|
4309
|
+
const localSchemaYaml = stringifyForDiff(sortUnorderedArrays(omit(local.data.schema, SCHEMA_IGNORED), SCHEMA_UNORDERED));
|
|
4310
|
+
const remoteSchemaYaml = stringifyForDiff(sortUnorderedArrays(omit(remote.data.schema, SCHEMA_IGNORED), SCHEMA_UNORDERED));
|
|
4192
4311
|
if (localSchemaYaml !== remoteSchemaYaml) {
|
|
4193
4312
|
result["schema"] = buildUnifiedDiff(remoteSchemaYaml, localSchemaYaml, "schema.yaml");
|
|
4194
4313
|
}
|
|
@@ -4293,11 +4412,17 @@ var functionModule = {
|
|
|
4293
4412
|
|
|
4294
4413
|
// packages/sync/dist/src/modules/policy.js
|
|
4295
4414
|
var IGNORED_FIELDS3 = ["_id", "system"];
|
|
4415
|
+
var UNORDERED_PATHS2 = [
|
|
4416
|
+
"statement",
|
|
4417
|
+
"statement.*.resource.include",
|
|
4418
|
+
"statement.*.resource.exclude"
|
|
4419
|
+
];
|
|
4296
4420
|
var policyModule = {
|
|
4297
4421
|
name: "policy",
|
|
4298
4422
|
displayName: "Policy",
|
|
4299
4423
|
identityField: "name",
|
|
4300
4424
|
ignoredFields: IGNORED_FIELDS3,
|
|
4425
|
+
unorderedPaths: UNORDERED_PATHS2,
|
|
4301
4426
|
readLocal(rootDir, source) {
|
|
4302
4427
|
return readLocalSchemas(rootDir, "policy", source);
|
|
4303
4428
|
},
|
|
@@ -4328,10 +4453,10 @@ var policyModule = {
|
|
|
4328
4453
|
deleteLocalSchema(rootDir, "policy", slug);
|
|
4329
4454
|
},
|
|
4330
4455
|
diffFields(local, remote) {
|
|
4331
|
-
return diffSchemaFields(local, remote, IGNORED_FIELDS3);
|
|
4456
|
+
return diffSchemaFields(local, remote, IGNORED_FIELDS3, UNORDERED_PATHS2);
|
|
4332
4457
|
},
|
|
4333
4458
|
renderDetail(local, remote) {
|
|
4334
|
-
return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS3);
|
|
4459
|
+
return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS3, UNORDERED_PATHS2);
|
|
4335
4460
|
},
|
|
4336
4461
|
summaryLine(resource) {
|
|
4337
4462
|
const stmts = resource.data.statement?.length ?? 0;
|
|
@@ -4651,8 +4776,10 @@ function fetch_default(program2) {
|
|
|
4651
4776
|
// apps/cli/src/commands/sync/dev.ts
|
|
4652
4777
|
import path14 from "path";
|
|
4653
4778
|
import chokidar from "chokidar";
|
|
4779
|
+
import caporalCore7 from "@caporal/core";
|
|
4654
4780
|
import { bold as bold9, cyan as cyan3, green as green8, red as red7, yellow as yellow7 } from "colorette";
|
|
4655
4781
|
import ora3 from "ora";
|
|
4782
|
+
var { CaporalValidator: CaporalValidator7 } = caporalCore7;
|
|
4656
4783
|
function createEmptyState() {
|
|
4657
4784
|
return { remoteIds: /* @__PURE__ */ new Map() };
|
|
4658
4785
|
}
|
|
@@ -4886,6 +5013,7 @@ function formatError2(e) {
|
|
|
4886
5013
|
async function dev({ args, options }) {
|
|
4887
5014
|
const rootDir = path14.resolve(args.dir ?? process.cwd());
|
|
4888
5015
|
const moduleFilter = options.module ? (Array.isArray(options.module) ? options.module : [options.module]).map(String) : void 0;
|
|
5016
|
+
const concurrency = options.concurrency;
|
|
4889
5017
|
const modules = resolveModules(moduleFilter);
|
|
4890
5018
|
let ctx;
|
|
4891
5019
|
try {
|
|
@@ -4902,14 +5030,17 @@ ${bold9(red7(`\u2717 ${formatError2(err)}`))}`);
|
|
|
4902
5030
|
Tip: Start a local instance with ${bold9("spica project start")} and switch to it with ${bold9("spica context switch <name>")} before running ${bold9("sync dev")}.`
|
|
4903
5031
|
);
|
|
4904
5032
|
}
|
|
4905
|
-
const http2 =
|
|
4906
|
-
|
|
4907
|
-
|
|
4908
|
-
|
|
5033
|
+
const http2 = limitConcurrency(
|
|
5034
|
+
httpService.create({
|
|
5035
|
+
baseUrl: ctx.url,
|
|
5036
|
+
authorization: ctx.authorization
|
|
5037
|
+
}),
|
|
5038
|
+
concurrency
|
|
5039
|
+
);
|
|
4909
5040
|
console.log(bold9("\nBuilding plan\u2026"));
|
|
4910
5041
|
let plan2;
|
|
4911
5042
|
try {
|
|
4912
|
-
plan2 = await buildPlan(modules, http2, rootDir, { reporter: cliReporter });
|
|
5043
|
+
plan2 = await buildPlan(modules, http2, rootDir, { reporter: cliReporter, concurrency });
|
|
4913
5044
|
} catch (err) {
|
|
4914
5045
|
console.log(`
|
|
4915
5046
|
${bold9(red7(`\u2717 Failed to build plan: ${formatError2(err)}`))}`);
|
|
@@ -4931,7 +5062,7 @@ ${bold9(red7(`\u2717 Failed to build plan: ${formatError2(err)}`))}`);
|
|
|
4931
5062
|
console.log(bold9("\nApplying changes\u2026"));
|
|
4932
5063
|
try {
|
|
4933
5064
|
const { errors } = await applyPlan(plan2, http2, {
|
|
4934
|
-
concurrency
|
|
5065
|
+
concurrency,
|
|
4935
5066
|
abortOnError: true,
|
|
4936
5067
|
reporter: cliReporter
|
|
4937
5068
|
});
|
|
@@ -5001,6 +5132,13 @@ function dev_default(program2) {
|
|
|
5001
5132
|
"dev",
|
|
5002
5133
|
"Watch local project files and automatically sync changes to the connected Spica instance."
|
|
5003
5134
|
).argument("[dir]", "Project directory (default: current working directory)").option(
|
|
5135
|
+
"--concurrency <n>",
|
|
5136
|
+
"Maximum parallel API requests.",
|
|
5137
|
+
{
|
|
5138
|
+
default: DEFAULT_CONCURRENCY,
|
|
5139
|
+
validator: CaporalValidator7.NUMBER
|
|
5140
|
+
}
|
|
5141
|
+
).option(
|
|
5004
5142
|
"--module <name>",
|
|
5005
5143
|
`Filter to specific module(s). Available: ${MODULE_NAMES.join(", ")}.`,
|
|
5006
5144
|
{
|
|
@@ -5021,7 +5159,7 @@ function readPackageVersion(baseUrl) {
|
|
|
5021
5159
|
}
|
|
5022
5160
|
|
|
5023
5161
|
// apps/cli/index.ts
|
|
5024
|
-
var { program } =
|
|
5162
|
+
var { program } = caporalCore8;
|
|
5025
5163
|
function run(argv) {
|
|
5026
5164
|
program.version(readPackageVersion(import.meta.url)).name("spica").bin("spica").description("Command line interface for spica.");
|
|
5027
5165
|
apply_default(program);
|