@spica/cli 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 +74 -15
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -3624,6 +3624,50 @@ import { bold as bold4, cyan, green as green4, red as red4, yellow as yellow2 }
|
|
|
3624
3624
|
import isEqual2 from "lodash/isEqual.js";
|
|
3625
3625
|
import { createTwoFilesPatch } from "diff";
|
|
3626
3626
|
import yaml2 from "yaml";
|
|
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
|
|
3627
3671
|
async function buildPlan(modules, unlimitedHttp, rootDir, options = {}) {
|
|
3628
3672
|
const { detailed = false, detectRenames = true, reporter = silentReporter, concurrency = DEFAULT_CONCURRENCY, source } = options;
|
|
3629
3673
|
const http2 = limitConcurrency(unlimitedHttp, concurrency);
|
|
@@ -3893,7 +3937,9 @@ async function fetchToDisk(plan2, http2, rootDir, opts = {}) {
|
|
|
3893
3937
|
}
|
|
3894
3938
|
return { written, deleted, errors };
|
|
3895
3939
|
}
|
|
3896
|
-
function diffObjectFields(
|
|
3940
|
+
function diffObjectFields(rawLocal, rawRemote, ignoredFields, unorderedPaths = []) {
|
|
3941
|
+
const local = sortUnorderedArrays(rawLocal, unorderedPaths);
|
|
3942
|
+
const remote = sortUnorderedArrays(rawRemote, unorderedPaths);
|
|
3897
3943
|
const allKeys = /* @__PURE__ */ new Set([...Object.keys(local), ...Object.keys(remote)]);
|
|
3898
3944
|
const changed = [];
|
|
3899
3945
|
for (const key of allKeys) {
|
|
@@ -3905,15 +3951,18 @@ function diffObjectFields(local, remote, ignoredFields) {
|
|
|
3905
3951
|
}
|
|
3906
3952
|
return changed;
|
|
3907
3953
|
}
|
|
3908
|
-
function diffSchemaFields(local, remote, ignoredFields) {
|
|
3909
|
-
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 });
|
|
3910
3959
|
}
|
|
3911
3960
|
function buildUnifiedDiff(oldContent, newContent, filename) {
|
|
3912
3961
|
return createTwoFilesPatch(`remote/${filename}`, `local/${filename}`, oldContent, newContent);
|
|
3913
3962
|
}
|
|
3914
|
-
function renderSchemaDetail(localData, remoteData, ignoredFields) {
|
|
3915
|
-
const localYaml =
|
|
3916
|
-
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));
|
|
3917
3966
|
return { schema: buildUnifiedDiff(remoteYaml, localYaml, "schema.yaml") };
|
|
3918
3967
|
}
|
|
3919
3968
|
function runAllAtOnce(tasks, label, onError, reporter) {
|
|
@@ -3945,12 +3994,14 @@ function formatError(e) {
|
|
|
3945
3994
|
}
|
|
3946
3995
|
|
|
3947
3996
|
// packages/sync/dist/src/modules/bucket.js
|
|
3948
|
-
var IGNORED_FIELDS = ["_id"];
|
|
3997
|
+
var IGNORED_FIELDS = ["_id", "order"];
|
|
3998
|
+
var UNORDERED_PATHS = ["required", "properties.**.required", "indexes"];
|
|
3949
3999
|
var bucketModule = {
|
|
3950
4000
|
name: "bucket",
|
|
3951
4001
|
displayName: "Bucket",
|
|
3952
4002
|
identityField: "title",
|
|
3953
4003
|
ignoredFields: IGNORED_FIELDS,
|
|
4004
|
+
unorderedPaths: UNORDERED_PATHS,
|
|
3954
4005
|
readLocal(rootDir, source) {
|
|
3955
4006
|
return readLocalSchemas(rootDir, "bucket", source);
|
|
3956
4007
|
},
|
|
@@ -3979,10 +4030,10 @@ var bucketModule = {
|
|
|
3979
4030
|
deleteLocalSchema(rootDir, "bucket", slug);
|
|
3980
4031
|
},
|
|
3981
4032
|
diffFields(local, remote) {
|
|
3982
|
-
return diffSchemaFields(local, remote, IGNORED_FIELDS);
|
|
4033
|
+
return diffSchemaFields(local, remote, IGNORED_FIELDS, UNORDERED_PATHS);
|
|
3983
4034
|
},
|
|
3984
4035
|
renderDetail(local, remote) {
|
|
3985
|
-
return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS);
|
|
4036
|
+
return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS, UNORDERED_PATHS);
|
|
3986
4037
|
},
|
|
3987
4038
|
summaryLine(resource) {
|
|
3988
4039
|
const propCount = Object.keys(resource.data.properties ?? {}).length;
|
|
@@ -4047,7 +4098,8 @@ import yaml3 from "yaml";
|
|
|
4047
4098
|
import isEqual3 from "lodash/isEqual.js";
|
|
4048
4099
|
import semver2 from "semver";
|
|
4049
4100
|
import { bold as bold5, cyan as cyan2, green as green5, yellow as yellow3 } from "colorette";
|
|
4050
|
-
var SCHEMA_IGNORED = ["_id", "env_vars", "secrets"];
|
|
4101
|
+
var SCHEMA_IGNORED = ["_id", "env_vars", "secrets", "order"];
|
|
4102
|
+
var SCHEMA_UNORDERED = ["triggers.*.options.authenticate"];
|
|
4051
4103
|
function indexFilename(language) {
|
|
4052
4104
|
return language === "typescript" ? "index.ts" : "index.mjs";
|
|
4053
4105
|
}
|
|
@@ -4101,6 +4153,7 @@ var functionModule = {
|
|
|
4101
4153
|
displayName: "Function",
|
|
4102
4154
|
identityField: "name",
|
|
4103
4155
|
ignoredFields: SCHEMA_IGNORED,
|
|
4156
|
+
unorderedPaths: SCHEMA_UNORDERED,
|
|
4104
4157
|
readSchema(rootDir, slug, source = diskSource) {
|
|
4105
4158
|
return readSourceYaml(source, path10.join(rootDir, "function", slug, "schema.yaml"));
|
|
4106
4159
|
},
|
|
@@ -4234,7 +4287,7 @@ var functionModule = {
|
|
|
4234
4287
|
},
|
|
4235
4288
|
diffFields(local, remote) {
|
|
4236
4289
|
const changed = [];
|
|
4237
|
-
const schemaChanged = diffObjectFields(local.schema, remote.schema, SCHEMA_IGNORED);
|
|
4290
|
+
const schemaChanged = diffObjectFields(local.schema, remote.schema, SCHEMA_IGNORED, SCHEMA_UNORDERED);
|
|
4238
4291
|
if (schemaChanged.length)
|
|
4239
4292
|
changed.push("schema");
|
|
4240
4293
|
if (local.index !== remote.index)
|
|
@@ -4253,8 +4306,8 @@ var functionModule = {
|
|
|
4253
4306
|
},
|
|
4254
4307
|
renderDetail(local, remote) {
|
|
4255
4308
|
const result = {};
|
|
4256
|
-
const localSchemaYaml =
|
|
4257
|
-
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));
|
|
4258
4311
|
if (localSchemaYaml !== remoteSchemaYaml) {
|
|
4259
4312
|
result["schema"] = buildUnifiedDiff(remoteSchemaYaml, localSchemaYaml, "schema.yaml");
|
|
4260
4313
|
}
|
|
@@ -4359,11 +4412,17 @@ var functionModule = {
|
|
|
4359
4412
|
|
|
4360
4413
|
// packages/sync/dist/src/modules/policy.js
|
|
4361
4414
|
var IGNORED_FIELDS3 = ["_id", "system"];
|
|
4415
|
+
var UNORDERED_PATHS2 = [
|
|
4416
|
+
"statement",
|
|
4417
|
+
"statement.*.resource.include",
|
|
4418
|
+
"statement.*.resource.exclude"
|
|
4419
|
+
];
|
|
4362
4420
|
var policyModule = {
|
|
4363
4421
|
name: "policy",
|
|
4364
4422
|
displayName: "Policy",
|
|
4365
4423
|
identityField: "name",
|
|
4366
4424
|
ignoredFields: IGNORED_FIELDS3,
|
|
4425
|
+
unorderedPaths: UNORDERED_PATHS2,
|
|
4367
4426
|
readLocal(rootDir, source) {
|
|
4368
4427
|
return readLocalSchemas(rootDir, "policy", source);
|
|
4369
4428
|
},
|
|
@@ -4394,10 +4453,10 @@ var policyModule = {
|
|
|
4394
4453
|
deleteLocalSchema(rootDir, "policy", slug);
|
|
4395
4454
|
},
|
|
4396
4455
|
diffFields(local, remote) {
|
|
4397
|
-
return diffSchemaFields(local, remote, IGNORED_FIELDS3);
|
|
4456
|
+
return diffSchemaFields(local, remote, IGNORED_FIELDS3, UNORDERED_PATHS2);
|
|
4398
4457
|
},
|
|
4399
4458
|
renderDetail(local, remote) {
|
|
4400
|
-
return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS3);
|
|
4459
|
+
return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS3, UNORDERED_PATHS2);
|
|
4401
4460
|
},
|
|
4402
4461
|
summaryLine(resource) {
|
|
4403
4462
|
const stmts = resource.data.statement?.length ?? 0;
|