pocketbase-zod-schema 0.7.0 → 0.7.2
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/CHANGELOG.md +14 -0
- package/dist/cli/index.cjs +449 -50
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.d.cts +1 -1
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +449 -50
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/migrate.cjs +455 -53
- package/dist/cli/migrate.cjs.map +1 -1
- package/dist/cli/migrate.js +455 -53
- package/dist/cli/migrate.js.map +1 -1
- package/dist/cli/utils/index.cjs +8 -1
- package/dist/cli/utils/index.cjs.map +1 -1
- package/dist/cli/utils/index.d.cts +1 -1
- package/dist/cli/utils/index.d.ts +1 -1
- package/dist/cli/utils/index.js +8 -1
- package/dist/cli/utils/index.js.map +1 -1
- package/dist/index.cjs +90 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +87 -2
- package/dist/index.js.map +1 -1
- package/dist/migration/analyzer.cjs +87 -14
- package/dist/migration/analyzer.cjs.map +1 -1
- package/dist/migration/analyzer.d.cts +12 -4
- package/dist/migration/analyzer.d.ts +12 -4
- package/dist/migration/analyzer.js +87 -15
- package/dist/migration/analyzer.js.map +1 -1
- package/dist/migration/diff.cjs +64 -9
- package/dist/migration/diff.cjs.map +1 -1
- package/dist/migration/diff.d.cts +12 -2
- package/dist/migration/diff.d.ts +12 -2
- package/dist/migration/diff.js +64 -10
- package/dist/migration/diff.js.map +1 -1
- package/dist/migration/generator.cjs +206 -39
- package/dist/migration/generator.cjs.map +1 -1
- package/dist/migration/generator.d.cts +54 -2
- package/dist/migration/generator.d.ts +54 -2
- package/dist/migration/generator.js +203 -40
- package/dist/migration/generator.js.map +1 -1
- package/dist/migration/index.cjs +501 -63
- package/dist/migration/index.cjs.map +1 -1
- package/dist/migration/index.d.cts +2 -2
- package/dist/migration/index.d.ts +2 -2
- package/dist/migration/index.js +501 -63
- package/dist/migration/index.js.map +1 -1
- package/dist/migration/snapshot.cjs +147 -1
- package/dist/migration/snapshot.cjs.map +1 -1
- package/dist/migration/snapshot.d.cts +3 -1
- package/dist/migration/snapshot.d.ts +3 -1
- package/dist/migration/snapshot.js +147 -1
- package/dist/migration/snapshot.js.map +1 -1
- package/dist/migration/utils/index.d.cts +1 -1
- package/dist/migration/utils/index.d.ts +1 -1
- package/dist/schema.cjs +90 -1
- package/dist/schema.cjs.map +1 -1
- package/dist/schema.d.cts +128 -2
- package/dist/schema.d.ts +128 -2
- package/dist/schema.js +87 -2
- package/dist/schema.js.map +1 -1
- package/dist/server.cjs +545 -65
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.js +542 -66
- package/dist/server.js.map +1 -1
- package/dist/{types-CWHV6ATd.d.cts → types-CnzfX6JH.d.cts} +20 -2
- package/dist/{types-C2nGWHLV.d.ts → types-Do3jyFBm.d.ts} +20 -2
- package/package.json +1 -1
|
@@ -224,6 +224,13 @@ function formatValue(value) {
|
|
|
224
224
|
}
|
|
225
225
|
return String(value);
|
|
226
226
|
}
|
|
227
|
+
function formatSqlTemplate(query, indent = " ") {
|
|
228
|
+
const escaped = query.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${");
|
|
229
|
+
const body = escaped.split("\n").map((line) => line.trim() === "" ? "" : `${indent}${line}`).join("\n");
|
|
230
|
+
return `\`
|
|
231
|
+
${body}
|
|
232
|
+
${indent.slice(0, -2)}\``;
|
|
233
|
+
}
|
|
227
234
|
function getFieldConstructorName(fieldType) {
|
|
228
235
|
const constructorMap = {
|
|
229
236
|
text: "TextField",
|
|
@@ -262,6 +269,36 @@ function getSystemFields() {
|
|
|
262
269
|
}
|
|
263
270
|
];
|
|
264
271
|
}
|
|
272
|
+
function getSystemTimestampFields() {
|
|
273
|
+
return [
|
|
274
|
+
{
|
|
275
|
+
name: "created",
|
|
276
|
+
id: "autodate2990389176",
|
|
277
|
+
type: "autodate",
|
|
278
|
+
required: false,
|
|
279
|
+
options: {
|
|
280
|
+
hidden: false,
|
|
281
|
+
onCreate: true,
|
|
282
|
+
onUpdate: false,
|
|
283
|
+
presentable: false,
|
|
284
|
+
system: true
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
name: "updated",
|
|
289
|
+
id: "autodate3332085495",
|
|
290
|
+
type: "autodate",
|
|
291
|
+
required: false,
|
|
292
|
+
options: {
|
|
293
|
+
hidden: false,
|
|
294
|
+
onCreate: true,
|
|
295
|
+
onUpdate: true,
|
|
296
|
+
presentable: false,
|
|
297
|
+
system: true
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
];
|
|
301
|
+
}
|
|
265
302
|
function getAuthSystemFields() {
|
|
266
303
|
return [
|
|
267
304
|
{
|
|
@@ -554,6 +591,15 @@ function generateCollectionRules(rules, collectionType = "base") {
|
|
|
554
591
|
if (!rules) {
|
|
555
592
|
return "";
|
|
556
593
|
}
|
|
594
|
+
if (collectionType === "view") {
|
|
595
|
+
return [
|
|
596
|
+
`"listRule": ${formatValue(rules.listRule ?? null)}`,
|
|
597
|
+
`"viewRule": ${formatValue(rules.viewRule ?? null)}`,
|
|
598
|
+
`"createRule": null`,
|
|
599
|
+
`"updateRule": null`,
|
|
600
|
+
`"deleteRule": null`
|
|
601
|
+
].join(",\n ");
|
|
602
|
+
}
|
|
557
603
|
const parts = [];
|
|
558
604
|
if (rules.listRule !== void 0) {
|
|
559
605
|
parts.push(`"listRule": ${formatValue(rules.listRule)}`);
|
|
@@ -579,6 +625,15 @@ function generateCollectionPermissions(permissions, collectionType = "base") {
|
|
|
579
625
|
if (!permissions) {
|
|
580
626
|
return "";
|
|
581
627
|
}
|
|
628
|
+
if (collectionType === "view") {
|
|
629
|
+
return [
|
|
630
|
+
`"listRule": ${formatValue(permissions.listRule ?? null)}`,
|
|
631
|
+
`"viewRule": ${formatValue(permissions.viewRule ?? null)}`,
|
|
632
|
+
`"createRule": null`,
|
|
633
|
+
`"updateRule": null`,
|
|
634
|
+
`"deleteRule": null`
|
|
635
|
+
].join(",\n ");
|
|
636
|
+
}
|
|
582
637
|
const parts = [];
|
|
583
638
|
if (permissions.listRule !== void 0) {
|
|
584
639
|
parts.push(`"listRule": ${formatValue(permissions.listRule)}`);
|
|
@@ -616,6 +671,28 @@ function generatePermissionUpdate(collectionName, ruleType, newValue, varName, i
|
|
|
616
671
|
lines.push(isLast ? ` return app.save(${collectionVar});` : ` app.save(${collectionVar});`);
|
|
617
672
|
return lines.join("\n");
|
|
618
673
|
}
|
|
674
|
+
function generateViewQueryUpdate(collectionName, viewQuery, varName, isLast = false, collectionIdMap) {
|
|
675
|
+
const lines = [];
|
|
676
|
+
const collectionVar = varName || `collection_${collectionName}_viewQuery`;
|
|
677
|
+
lines.push(` const ${collectionVar} = ${generateFindCollectionCode(collectionName, collectionIdMap)};`);
|
|
678
|
+
lines.push(` unmarshal({`);
|
|
679
|
+
lines.push(` "viewQuery": ${formatSqlTemplate(viewQuery, " ")},`);
|
|
680
|
+
lines.push(` }, ${collectionVar})`);
|
|
681
|
+
lines.push(isLast ? ` return app.save(${collectionVar});` : ` app.save(${collectionVar});`);
|
|
682
|
+
return lines.join("\n");
|
|
683
|
+
}
|
|
684
|
+
function generateGroupedRuleUpdates(collectionName, entries, varSuffix, isLast = false, collectionIdMap) {
|
|
685
|
+
const collectionVar = `collection_${collectionName}_${varSuffix}`;
|
|
686
|
+
const lines = [];
|
|
687
|
+
lines.push(` const ${collectionVar} = ${generateFindCollectionCode(collectionName, collectionIdMap)};`);
|
|
688
|
+
lines.push(` unmarshal({`);
|
|
689
|
+
for (const entry of entries) {
|
|
690
|
+
lines.push(` "${entry.ruleType}": ${formatValue(entry.value)},`);
|
|
691
|
+
}
|
|
692
|
+
lines.push(` }, ${collectionVar})`);
|
|
693
|
+
lines.push(isLast ? ` return app.save(${collectionVar});` : ` app.save(${collectionVar});`);
|
|
694
|
+
return lines.join("\n");
|
|
695
|
+
}
|
|
619
696
|
|
|
620
697
|
// src/migration/generator/collections.ts
|
|
621
698
|
function generateCollectionCreation(collection, varName = "collection", isLast = false, collectionIdMap) {
|
|
@@ -634,16 +711,24 @@ function generateCollectionCreation(collection, varName = "collection", isLast =
|
|
|
634
711
|
} else if (rulesCode) {
|
|
635
712
|
lines.push(` ${rulesCode},`);
|
|
636
713
|
}
|
|
714
|
+
if (collection.type === "view") {
|
|
715
|
+
lines.push(` "viewQuery": ${formatSqlTemplate(collection.viewQuery ?? "")},`);
|
|
716
|
+
lines.push(` });`);
|
|
717
|
+
lines.push(``);
|
|
718
|
+
lines.push(isLast ? ` return app.save(${varName});` : ` app.save(${varName});`);
|
|
719
|
+
return lines.join("\n");
|
|
720
|
+
}
|
|
637
721
|
const systemFieldNames = ["created", "updated", "id"];
|
|
638
722
|
if (collection.type === "auth") {
|
|
639
723
|
systemFieldNames.push(...getAuthSystemFields().map((f) => f.name));
|
|
640
724
|
}
|
|
641
725
|
const userFields = collection.fields.filter((f) => !systemFieldNames.includes(f.name));
|
|
642
|
-
const allFields = [...getSystemFields()
|
|
726
|
+
const allFields = [...getSystemFields()];
|
|
643
727
|
if (collection.type === "auth") {
|
|
644
728
|
allFields.push(...getAuthSystemFields());
|
|
645
729
|
}
|
|
646
730
|
allFields.push(...userFields);
|
|
731
|
+
allFields.push(...getSystemTimestampFields());
|
|
647
732
|
lines.push(` "fields": ${generateFieldsArray(allFields, collectionIdMap)},`);
|
|
648
733
|
let allIndexes = [...collection.indexes || []];
|
|
649
734
|
if (collection.type === "auth") {
|
|
@@ -673,7 +758,21 @@ function generateOperationUpMigration(operation, collectionIdMap) {
|
|
|
673
758
|
const modification = operation.modifications;
|
|
674
759
|
const collectionName = typeof operation.collection === "string" ? operation.collection : operation.collection?.name ?? modification.collection;
|
|
675
760
|
let operationCount = 0;
|
|
676
|
-
const totalOperations = modification.fieldsToAdd.length + modification.fieldsToModify.length + modification.fieldsToRemove.length + modification.indexesToAdd.length + modification.indexesToRemove.length + modification.
|
|
761
|
+
const totalOperations = modification.fieldsToAdd.length + modification.fieldsToModify.length + modification.fieldsToRemove.length + modification.indexesToAdd.length + modification.indexesToRemove.length + (modification.viewQueryUpdate ? 1 : 0) + (modification.permissionsToUpdate.length > 0 ? 1 : modification.rulesToUpdate.length > 0 ? 1 : 0);
|
|
762
|
+
if (modification.viewQueryUpdate) {
|
|
763
|
+
operationCount++;
|
|
764
|
+
const isLast = operationCount === totalOperations;
|
|
765
|
+
lines.push(
|
|
766
|
+
generateViewQueryUpdate(
|
|
767
|
+
collectionName,
|
|
768
|
+
modification.viewQueryUpdate.newValue,
|
|
769
|
+
void 0,
|
|
770
|
+
isLast,
|
|
771
|
+
collectionIdMap
|
|
772
|
+
)
|
|
773
|
+
);
|
|
774
|
+
if (!isLast) lines.push("");
|
|
775
|
+
}
|
|
677
776
|
for (let i = 0; i < modification.fieldsToAdd.length; i++) {
|
|
678
777
|
const field = modification.fieldsToAdd[i];
|
|
679
778
|
operationCount++;
|
|
@@ -713,23 +812,29 @@ function generateOperationUpMigration(operation, collectionIdMap) {
|
|
|
713
812
|
if (!isLast) lines.push("");
|
|
714
813
|
}
|
|
715
814
|
if (modification.permissionsToUpdate && modification.permissionsToUpdate.length > 0) {
|
|
716
|
-
|
|
717
|
-
|
|
815
|
+
operationCount++;
|
|
816
|
+
const isLast = operationCount === totalOperations;
|
|
817
|
+
if (modification.permissionsToUpdate.length >= 2) {
|
|
818
|
+
const entries = modification.permissionsToUpdate.map((p) => ({ ruleType: p.ruleType, value: p.newValue }));
|
|
819
|
+
lines.push(generateGroupedRuleUpdates(collectionName, entries, "rules", isLast, collectionIdMap));
|
|
820
|
+
} else {
|
|
821
|
+
const permission = modification.permissionsToUpdate[0];
|
|
718
822
|
const varName = `collection_${collectionName}_perm_${permission.ruleType}`;
|
|
719
|
-
|
|
720
|
-
lines.push(
|
|
721
|
-
generatePermissionUpdate(collectionName, permission.ruleType, permission.newValue, varName, isLast, collectionIdMap)
|
|
722
|
-
);
|
|
723
|
-
if (!isLast) lines.push("");
|
|
823
|
+
lines.push(generatePermissionUpdate(collectionName, permission.ruleType, permission.newValue, varName, isLast, collectionIdMap));
|
|
724
824
|
}
|
|
825
|
+
if (!isLast) lines.push("");
|
|
725
826
|
} else if (modification.rulesToUpdate.length > 0) {
|
|
726
|
-
|
|
727
|
-
|
|
827
|
+
operationCount++;
|
|
828
|
+
const isLast = operationCount === totalOperations;
|
|
829
|
+
if (modification.rulesToUpdate.length >= 2) {
|
|
830
|
+
const entries = modification.rulesToUpdate.map((r) => ({ ruleType: r.ruleType, value: r.newValue }));
|
|
831
|
+
lines.push(generateGroupedRuleUpdates(collectionName, entries, "rules", isLast, collectionIdMap));
|
|
832
|
+
} else {
|
|
833
|
+
const rule = modification.rulesToUpdate[0];
|
|
728
834
|
const varName = `collection_${collectionName}_rule_${rule.ruleType}`;
|
|
729
|
-
const isLast = operationCount === totalOperations;
|
|
730
835
|
lines.push(generateRuleUpdate(collectionName, rule.ruleType, rule.newValue, varName, isLast, collectionIdMap));
|
|
731
|
-
if (!isLast) lines.push("");
|
|
732
836
|
}
|
|
837
|
+
if (!isLast) lines.push("");
|
|
733
838
|
}
|
|
734
839
|
} else if (operation.type === "delete") {
|
|
735
840
|
const collectionName = typeof operation.collection === "string" ? operation.collection : operation.collection.name;
|
|
@@ -768,25 +873,45 @@ function generateOperationDownMigration(operation, collectionIdMap) {
|
|
|
768
873
|
const modification = operation.modifications;
|
|
769
874
|
const collectionName = typeof operation.collection === "string" ? operation.collection : operation.collection?.name ?? modification.collection;
|
|
770
875
|
let operationCount = 0;
|
|
771
|
-
const totalOperations = modification.fieldsToAdd.length + modification.fieldsToModify.length + modification.fieldsToRemove.length + modification.indexesToAdd.length + modification.indexesToRemove.length + modification.
|
|
876
|
+
const totalOperations = modification.fieldsToAdd.length + modification.fieldsToModify.length + modification.fieldsToRemove.length + modification.indexesToAdd.length + modification.indexesToRemove.length + (modification.viewQueryUpdate ? 1 : 0) + (modification.permissionsToUpdate.length > 0 ? 1 : modification.rulesToUpdate.length > 0 ? 1 : 0);
|
|
877
|
+
if (modification.viewQueryUpdate) {
|
|
878
|
+
operationCount++;
|
|
879
|
+
const isLast = operationCount === totalOperations;
|
|
880
|
+
lines.push(
|
|
881
|
+
generateViewQueryUpdate(
|
|
882
|
+
collectionName,
|
|
883
|
+
modification.viewQueryUpdate.oldValue ?? "",
|
|
884
|
+
`collection_${collectionName}_revert_viewQuery`,
|
|
885
|
+
isLast,
|
|
886
|
+
collectionIdMap
|
|
887
|
+
)
|
|
888
|
+
);
|
|
889
|
+
if (!isLast) lines.push("");
|
|
890
|
+
}
|
|
772
891
|
if (modification.permissionsToUpdate && modification.permissionsToUpdate.length > 0) {
|
|
773
|
-
|
|
774
|
-
|
|
892
|
+
operationCount++;
|
|
893
|
+
const isLast = operationCount === totalOperations;
|
|
894
|
+
if (modification.permissionsToUpdate.length >= 2) {
|
|
895
|
+
const entries = modification.permissionsToUpdate.map((p) => ({ ruleType: p.ruleType, value: p.oldValue }));
|
|
896
|
+
lines.push(generateGroupedRuleUpdates(collectionName, entries, "revert_rules", isLast, collectionIdMap));
|
|
897
|
+
} else {
|
|
898
|
+
const permission = modification.permissionsToUpdate[0];
|
|
775
899
|
const varName = `collection_${collectionName}_revert_perm_${permission.ruleType}`;
|
|
776
|
-
|
|
777
|
-
lines.push(
|
|
778
|
-
generatePermissionUpdate(collectionName, permission.ruleType, permission.oldValue, varName, isLast, collectionIdMap)
|
|
779
|
-
);
|
|
780
|
-
if (!isLast) lines.push("");
|
|
900
|
+
lines.push(generatePermissionUpdate(collectionName, permission.ruleType, permission.oldValue, varName, isLast, collectionIdMap));
|
|
781
901
|
}
|
|
902
|
+
if (!isLast) lines.push("");
|
|
782
903
|
} else if (modification.rulesToUpdate.length > 0) {
|
|
783
|
-
|
|
784
|
-
|
|
904
|
+
operationCount++;
|
|
905
|
+
const isLast = operationCount === totalOperations;
|
|
906
|
+
if (modification.rulesToUpdate.length >= 2) {
|
|
907
|
+
const entries = modification.rulesToUpdate.map((r) => ({ ruleType: r.ruleType, value: r.oldValue }));
|
|
908
|
+
lines.push(generateGroupedRuleUpdates(collectionName, entries, "revert_rules", isLast, collectionIdMap));
|
|
909
|
+
} else {
|
|
910
|
+
const rule = modification.rulesToUpdate[0];
|
|
785
911
|
const varName = `collection_${collectionName}_revert_rule_${rule.ruleType}`;
|
|
786
|
-
const isLast = operationCount === totalOperations;
|
|
787
912
|
lines.push(generateRuleUpdate(collectionName, rule.ruleType, rule.oldValue, varName, isLast, collectionIdMap));
|
|
788
|
-
if (!isLast) lines.push("");
|
|
789
913
|
}
|
|
914
|
+
if (!isLast) lines.push("");
|
|
790
915
|
}
|
|
791
916
|
for (let i = 0; i < modification.indexesToRemove.length; i++) {
|
|
792
917
|
operationCount++;
|
|
@@ -893,6 +1018,19 @@ function generateUpMigration(diff) {
|
|
|
893
1018
|
lines.push(` // Modify existing collections`);
|
|
894
1019
|
for (const modification of diff.collectionsToModify) {
|
|
895
1020
|
const collectionName = modification.collection;
|
|
1021
|
+
if (modification.viewQueryUpdate) {
|
|
1022
|
+
lines.push(` // Update the view query of ${collectionName}`);
|
|
1023
|
+
lines.push(
|
|
1024
|
+
generateViewQueryUpdate(
|
|
1025
|
+
collectionName,
|
|
1026
|
+
modification.viewQueryUpdate.newValue,
|
|
1027
|
+
void 0,
|
|
1028
|
+
false,
|
|
1029
|
+
collectionIdMap
|
|
1030
|
+
)
|
|
1031
|
+
);
|
|
1032
|
+
lines.push(``);
|
|
1033
|
+
}
|
|
896
1034
|
if (modification.fieldsToAdd.length > 0) {
|
|
897
1035
|
lines.push(` // Add fields to ${collectionName}`);
|
|
898
1036
|
for (let i = 0; i < modification.fieldsToAdd.length; i++) {
|
|
@@ -938,20 +1076,26 @@ function generateUpMigration(diff) {
|
|
|
938
1076
|
}
|
|
939
1077
|
if (modification.permissionsToUpdate && modification.permissionsToUpdate.length > 0) {
|
|
940
1078
|
lines.push(` // Update permissions for ${collectionName}`);
|
|
941
|
-
|
|
1079
|
+
if (modification.permissionsToUpdate.length >= 2) {
|
|
1080
|
+
const entries = modification.permissionsToUpdate.map((p) => ({ ruleType: p.ruleType, value: p.newValue }));
|
|
1081
|
+
lines.push(generateGroupedRuleUpdates(collectionName, entries, "rules", false, collectionIdMap));
|
|
1082
|
+
} else {
|
|
1083
|
+
const permission = modification.permissionsToUpdate[0];
|
|
942
1084
|
const varName = `collection_${collectionName}_perm_${permission.ruleType}`;
|
|
943
|
-
lines.push(
|
|
944
|
-
generatePermissionUpdate(collectionName, permission.ruleType, permission.newValue, varName, false, collectionIdMap)
|
|
945
|
-
);
|
|
946
|
-
lines.push(``);
|
|
1085
|
+
lines.push(generatePermissionUpdate(collectionName, permission.ruleType, permission.newValue, varName, false, collectionIdMap));
|
|
947
1086
|
}
|
|
1087
|
+
lines.push(``);
|
|
948
1088
|
} else if (modification.rulesToUpdate.length > 0) {
|
|
949
1089
|
lines.push(` // Update rules for ${collectionName}`);
|
|
950
|
-
|
|
1090
|
+
if (modification.rulesToUpdate.length >= 2) {
|
|
1091
|
+
const entries = modification.rulesToUpdate.map((r) => ({ ruleType: r.ruleType, value: r.newValue }));
|
|
1092
|
+
lines.push(generateGroupedRuleUpdates(collectionName, entries, "rules", false, collectionIdMap));
|
|
1093
|
+
} else {
|
|
1094
|
+
const rule = modification.rulesToUpdate[0];
|
|
951
1095
|
const varName = `collection_${collectionName}_rule_${rule.ruleType}`;
|
|
952
1096
|
lines.push(generateRuleUpdate(collectionName, rule.ruleType, rule.newValue, varName, false, collectionIdMap));
|
|
953
|
-
lines.push(``);
|
|
954
1097
|
}
|
|
1098
|
+
lines.push(``);
|
|
955
1099
|
}
|
|
956
1100
|
}
|
|
957
1101
|
}
|
|
@@ -1023,22 +1167,41 @@ function generateDownMigration(diff) {
|
|
|
1023
1167
|
lines.push(` // Revert modifications`);
|
|
1024
1168
|
for (const modification of diff.collectionsToModify) {
|
|
1025
1169
|
const collectionName = modification.collection;
|
|
1170
|
+
if (modification.viewQueryUpdate) {
|
|
1171
|
+
lines.push(` // Restore the view query of ${collectionName}`);
|
|
1172
|
+
lines.push(
|
|
1173
|
+
generateViewQueryUpdate(
|
|
1174
|
+
collectionName,
|
|
1175
|
+
modification.viewQueryUpdate.oldValue ?? "",
|
|
1176
|
+
`collection_${collectionName}_revert_viewQuery`,
|
|
1177
|
+
false,
|
|
1178
|
+
collectionIdMap
|
|
1179
|
+
)
|
|
1180
|
+
);
|
|
1181
|
+
lines.push(``);
|
|
1182
|
+
}
|
|
1026
1183
|
if (modification.permissionsToUpdate && modification.permissionsToUpdate.length > 0) {
|
|
1027
1184
|
lines.push(` // Revert permissions for ${collectionName}`);
|
|
1028
|
-
|
|
1185
|
+
if (modification.permissionsToUpdate.length >= 2) {
|
|
1186
|
+
const entries = modification.permissionsToUpdate.map((p) => ({ ruleType: p.ruleType, value: p.oldValue }));
|
|
1187
|
+
lines.push(generateGroupedRuleUpdates(collectionName, entries, "revert_rules", false, collectionIdMap));
|
|
1188
|
+
} else {
|
|
1189
|
+
const permission = modification.permissionsToUpdate[0];
|
|
1029
1190
|
const varName = `collection_${collectionName}_revert_perm_${permission.ruleType}`;
|
|
1030
|
-
lines.push(
|
|
1031
|
-
generatePermissionUpdate(collectionName, permission.ruleType, permission.oldValue, varName, false, collectionIdMap)
|
|
1032
|
-
);
|
|
1033
|
-
lines.push(``);
|
|
1191
|
+
lines.push(generatePermissionUpdate(collectionName, permission.ruleType, permission.oldValue, varName, false, collectionIdMap));
|
|
1034
1192
|
}
|
|
1193
|
+
lines.push(``);
|
|
1035
1194
|
} else if (modification.rulesToUpdate.length > 0) {
|
|
1036
1195
|
lines.push(` // Revert rules for ${collectionName}`);
|
|
1037
|
-
|
|
1196
|
+
if (modification.rulesToUpdate.length >= 2) {
|
|
1197
|
+
const entries = modification.rulesToUpdate.map((r) => ({ ruleType: r.ruleType, value: r.oldValue }));
|
|
1198
|
+
lines.push(generateGroupedRuleUpdates(collectionName, entries, "revert_rules", false, collectionIdMap));
|
|
1199
|
+
} else {
|
|
1200
|
+
const rule = modification.rulesToUpdate[0];
|
|
1038
1201
|
const varName = `collection_${collectionName}_revert_rule_${rule.ruleType}`;
|
|
1039
1202
|
lines.push(generateRuleUpdate(collectionName, rule.ruleType, rule.oldValue, varName, false, collectionIdMap));
|
|
1040
|
-
lines.push(``);
|
|
1041
1203
|
}
|
|
1204
|
+
lines.push(``);
|
|
1042
1205
|
}
|
|
1043
1206
|
if (modification.indexesToRemove.length > 0) {
|
|
1044
1207
|
lines.push(` // Restore indexes to ${collectionName}`);
|
|
@@ -1368,6 +1531,7 @@ exports.DEFAULT_CONFIG = DEFAULT_CONFIG;
|
|
|
1368
1531
|
exports.DEFAULT_TEMPLATE = DEFAULT_TEMPLATE;
|
|
1369
1532
|
exports.MigrationGenerator = MigrationGenerator;
|
|
1370
1533
|
exports.createMigrationFileStructure = createMigrationFileStructure;
|
|
1534
|
+
exports.formatSqlTemplate = formatSqlTemplate;
|
|
1371
1535
|
exports.formatValue = formatValue;
|
|
1372
1536
|
exports.generate = generate;
|
|
1373
1537
|
exports.generateCollectionCreation = generateCollectionCreation;
|
|
@@ -1383,6 +1547,7 @@ exports.generateFieldDeletion = generateFieldDeletion;
|
|
|
1383
1547
|
exports.generateFieldModification = generateFieldModification;
|
|
1384
1548
|
exports.generateFieldsArray = generateFieldsArray;
|
|
1385
1549
|
exports.generateFindCollectionCode = generateFindCollectionCode;
|
|
1550
|
+
exports.generateGroupedRuleUpdates = generateGroupedRuleUpdates;
|
|
1386
1551
|
exports.generateIndexAddition = generateIndexAddition;
|
|
1387
1552
|
exports.generateIndexRemoval = generateIndexRemoval;
|
|
1388
1553
|
exports.generateIndexesArray = generateIndexesArray;
|
|
@@ -1394,10 +1559,12 @@ exports.generatePermissionUpdate = generatePermissionUpdate;
|
|
|
1394
1559
|
exports.generateRuleUpdate = generateRuleUpdate;
|
|
1395
1560
|
exports.generateTimestamp = generateTimestamp;
|
|
1396
1561
|
exports.generateUpMigration = generateUpMigration;
|
|
1562
|
+
exports.generateViewQueryUpdate = generateViewQueryUpdate;
|
|
1397
1563
|
exports.getAuthSystemFields = getAuthSystemFields;
|
|
1398
1564
|
exports.getAuthSystemIndexes = getAuthSystemIndexes;
|
|
1399
1565
|
exports.getFieldConstructorName = getFieldConstructorName;
|
|
1400
1566
|
exports.getSystemFields = getSystemFields;
|
|
1567
|
+
exports.getSystemTimestampFields = getSystemTimestampFields;
|
|
1401
1568
|
exports.incrementTimestamp = incrementTimestamp;
|
|
1402
1569
|
exports.mergeConfig = mergeConfig;
|
|
1403
1570
|
exports.resolveMigrationDir = resolveMigrationDir;
|