pocketbase-zod-schema 0.3.0 → 0.3.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 +15 -0
- package/dist/cli/index.cjs +175 -50
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.d.cts +2 -2
- package/dist/cli/index.d.ts +2 -2
- package/dist/cli/index.js +175 -50
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/migrate.cjs +175 -50
- package/dist/cli/migrate.cjs.map +1 -1
- package/dist/cli/migrate.js +175 -50
- package/dist/cli/migrate.js.map +1 -1
- package/dist/cli/utils/index.d.cts +2 -2
- package/dist/cli/utils/index.d.ts +2 -2
- package/dist/{fields-UcOPu1OQ.d.cts → fields-DBBm06VU.d.cts} +35 -7
- package/dist/{fields-UcOPu1OQ.d.ts → fields-DBBm06VU.d.ts} +35 -7
- package/dist/index.cjs +264 -84
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +264 -84
- package/dist/index.js.map +1 -1
- package/dist/migration/analyzer.cjs.map +1 -1
- package/dist/migration/analyzer.d.cts +2 -2
- package/dist/migration/analyzer.d.ts +2 -2
- package/dist/migration/analyzer.js.map +1 -1
- package/dist/migration/diff.cjs +77 -26
- package/dist/migration/diff.cjs.map +1 -1
- package/dist/migration/diff.d.cts +4 -4
- package/dist/migration/diff.d.ts +4 -4
- package/dist/migration/diff.js +77 -26
- package/dist/migration/diff.js.map +1 -1
- package/dist/migration/generator.cjs +81 -34
- package/dist/migration/generator.cjs.map +1 -1
- package/dist/migration/generator.d.cts +2 -2
- package/dist/migration/generator.d.ts +2 -2
- package/dist/migration/generator.js +81 -34
- package/dist/migration/generator.js.map +1 -1
- package/dist/migration/index.cjs +209 -78
- package/dist/migration/index.cjs.map +1 -1
- package/dist/migration/index.d.cts +3 -3
- package/dist/migration/index.d.ts +3 -3
- package/dist/migration/index.js +209 -78
- package/dist/migration/index.js.map +1 -1
- package/dist/migration/snapshot.cjs +51 -18
- package/dist/migration/snapshot.cjs.map +1 -1
- package/dist/migration/snapshot.d.cts +2 -2
- package/dist/migration/snapshot.d.ts +2 -2
- package/dist/migration/snapshot.js +51 -18
- package/dist/migration/snapshot.js.map +1 -1
- package/dist/migration/utils/index.cjs +5 -3
- package/dist/migration/utils/index.cjs.map +1 -1
- package/dist/migration/utils/index.d.cts +4 -4
- package/dist/migration/utils/index.d.ts +4 -4
- package/dist/migration/utils/index.js +5 -3
- package/dist/migration/utils/index.js.map +1 -1
- package/dist/schema.cjs +55 -6
- package/dist/schema.cjs.map +1 -1
- package/dist/schema.d.cts +1 -1
- package/dist/schema.d.ts +1 -1
- package/dist/schema.js +55 -6
- package/dist/schema.js.map +1 -1
- package/dist/{type-mapper-DrQmtznD.d.cts → type-mapper-DsGgZwUo.d.cts} +1 -1
- package/dist/{type-mapper-n231Fspm.d.ts → type-mapper-Dvh4QTM-.d.ts} +1 -1
- package/dist/{types-YoBjsa-A.d.cts → types-CVxPCgWX.d.cts} +1 -1
- package/dist/{types-Ds3NQvny.d.ts → types-Dfp-NP2D.d.ts} +1 -1
- package/package.json +1 -1
|
@@ -296,7 +296,7 @@ function formatValue(value) {
|
|
|
296
296
|
return JSON.stringify(value).replace(/","/g, '", "');
|
|
297
297
|
}
|
|
298
298
|
if (typeof value === "object") {
|
|
299
|
-
const entries = Object.entries(value).map(([k, v]) => `${k}: ${formatValue(v)}`).join(", ");
|
|
299
|
+
const entries = Object.entries(value).filter(([_k, v]) => v !== void 0).map(([k, v]) => `${k}: ${formatValue(v)}`).join(", ");
|
|
300
300
|
return `{ ${entries} }`;
|
|
301
301
|
}
|
|
302
302
|
return String(value);
|
|
@@ -465,6 +465,9 @@ function getSystemFields() {
|
|
|
465
465
|
function generateCollectionCreation(collection, varName = "collection", isLast = false, collectionIdMap) {
|
|
466
466
|
const lines = [];
|
|
467
467
|
lines.push(` const ${varName} = new Collection({`);
|
|
468
|
+
if (collection.id) {
|
|
469
|
+
lines.push(` id: ${formatValue(collection.id)},`);
|
|
470
|
+
}
|
|
468
471
|
lines.push(` name: "${collection.name}",`);
|
|
469
472
|
lines.push(` type: "${collection.type}",`);
|
|
470
473
|
const permissionsCode = generateCollectionPermissions(collection.permissions);
|
|
@@ -587,11 +590,9 @@ function generateFieldModification(collectionName, modification, varName, isLast
|
|
|
587
590
|
function generateFieldDeletion(collectionName, fieldName, varName, isLast = false) {
|
|
588
591
|
const lines = [];
|
|
589
592
|
const collectionVar = varName || `collection_${collectionName}_${fieldName}`;
|
|
590
|
-
const fieldVar = `${collectionVar}_field`;
|
|
591
593
|
lines.push(` const ${collectionVar} = app.findCollectionByNameOrId("${collectionName}");`);
|
|
592
|
-
lines.push(` const ${fieldVar} = ${collectionVar}.fields.getByName("${fieldName}");`);
|
|
593
594
|
lines.push(``);
|
|
594
|
-
lines.push(` ${collectionVar}.fields.
|
|
595
|
+
lines.push(` ${collectionVar}.fields.removeByName("${fieldName}");`);
|
|
595
596
|
lines.push(``);
|
|
596
597
|
lines.push(isLast ? ` return app.save(${collectionVar});` : ` app.save(${collectionVar});`);
|
|
597
598
|
return lines.join("\n");
|
|
@@ -708,7 +709,27 @@ function generateOperationUpMigration(operation, collectionIdMap) {
|
|
|
708
709
|
const varName = `collection_${collectionName}`;
|
|
709
710
|
lines.push(generateCollectionDeletion(collectionName, varName, true));
|
|
710
711
|
}
|
|
711
|
-
|
|
712
|
+
let code = lines.join("\n");
|
|
713
|
+
const hasReturnStatement = /return\s+app\.(save|delete)\(/m.test(code);
|
|
714
|
+
if (!hasReturnStatement) {
|
|
715
|
+
const savePattern = /^(\s*)app\.save\((\w+)\);$/gm;
|
|
716
|
+
const deletePattern = /^(\s*)app\.delete\((\w+)\);$/gm;
|
|
717
|
+
const saveMatches = [...code.matchAll(savePattern)];
|
|
718
|
+
const deleteMatches = [...code.matchAll(deletePattern)];
|
|
719
|
+
const allMatches = [
|
|
720
|
+
...saveMatches.map((m) => ({ match: m, type: "save", index: m.index })),
|
|
721
|
+
...deleteMatches.map((m) => ({ match: m, type: "delete", index: m.index }))
|
|
722
|
+
].sort((a, b) => b.index - a.index);
|
|
723
|
+
if (allMatches.length > 0) {
|
|
724
|
+
const lastMatch = allMatches[0];
|
|
725
|
+
if (lastMatch.type === "save") {
|
|
726
|
+
code = code.substring(0, lastMatch.match.index) + lastMatch.match[1] + "return app.save(" + lastMatch.match[2] + ");" + code.substring(lastMatch.match.index + lastMatch.match[0].length);
|
|
727
|
+
} else {
|
|
728
|
+
code = code.substring(0, lastMatch.match.index) + lastMatch.match[1] + "return app.delete(" + lastMatch.match[2] + ");" + code.substring(lastMatch.match.index + lastMatch.match[0].length);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
return code;
|
|
712
733
|
}
|
|
713
734
|
function generateOperationDownMigration(operation, collectionIdMap) {
|
|
714
735
|
const lines = [];
|
|
@@ -793,7 +814,27 @@ function generateOperationDownMigration(operation, collectionIdMap) {
|
|
|
793
814
|
lines.push(generateCollectionCreation(collection, varName, true, collectionIdMap));
|
|
794
815
|
}
|
|
795
816
|
}
|
|
796
|
-
|
|
817
|
+
let code = lines.join("\n");
|
|
818
|
+
const hasReturnStatement = /return\s+app\.(save|delete)\(/m.test(code);
|
|
819
|
+
if (!hasReturnStatement) {
|
|
820
|
+
const savePattern = /^(\s*)app\.save\((\w+)\);$/gm;
|
|
821
|
+
const deletePattern = /^(\s*)app\.delete\((\w+)\);$/gm;
|
|
822
|
+
const saveMatches = [...code.matchAll(savePattern)];
|
|
823
|
+
const deleteMatches = [...code.matchAll(deletePattern)];
|
|
824
|
+
const allMatches = [
|
|
825
|
+
...saveMatches.map((m) => ({ match: m, type: "save", index: m.index })),
|
|
826
|
+
...deleteMatches.map((m) => ({ match: m, type: "delete", index: m.index }))
|
|
827
|
+
].sort((a, b) => b.index - a.index);
|
|
828
|
+
if (allMatches.length > 0) {
|
|
829
|
+
const lastMatch = allMatches[0];
|
|
830
|
+
if (lastMatch.type === "save") {
|
|
831
|
+
code = code.substring(0, lastMatch.match.index) + lastMatch.match[1] + "return app.save(" + lastMatch.match[2] + ");" + code.substring(lastMatch.match.index + lastMatch.match[0].length);
|
|
832
|
+
} else {
|
|
833
|
+
code = code.substring(0, lastMatch.match.index) + lastMatch.match[1] + "return app.delete(" + lastMatch.match[2] + ");" + code.substring(lastMatch.match.index + lastMatch.match[0].length);
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
return code;
|
|
797
838
|
}
|
|
798
839
|
function generateUpMigration(diff) {
|
|
799
840
|
const lines = [];
|
|
@@ -891,20 +932,23 @@ function generateUpMigration(diff) {
|
|
|
891
932
|
lines.push(``);
|
|
892
933
|
}
|
|
893
934
|
let code = lines.join("\n");
|
|
894
|
-
const
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
if (
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
935
|
+
const hasReturnStatement = /return\s+app\.(save|delete)\(/m.test(code);
|
|
936
|
+
if (!hasReturnStatement) {
|
|
937
|
+
const savePattern = /^(\s*)app\.save\((\w+)\);$/gm;
|
|
938
|
+
const deletePattern = /^(\s*)app\.delete\((\w+)\);$/gm;
|
|
939
|
+
const saveMatches = [...code.matchAll(savePattern)];
|
|
940
|
+
const deleteMatches = [...code.matchAll(deletePattern)];
|
|
941
|
+
const allMatches = [
|
|
942
|
+
...saveMatches.map((m) => ({ match: m, type: "save", index: m.index })),
|
|
943
|
+
...deleteMatches.map((m) => ({ match: m, type: "delete", index: m.index }))
|
|
944
|
+
].sort((a, b) => b.index - a.index);
|
|
945
|
+
if (allMatches.length > 0) {
|
|
946
|
+
const lastMatch = allMatches[0];
|
|
947
|
+
if (lastMatch.type === "save") {
|
|
948
|
+
code = code.substring(0, lastMatch.match.index) + lastMatch.match[1] + "return app.save(" + lastMatch.match[2] + ");" + code.substring(lastMatch.match.index + lastMatch.match[0].length);
|
|
949
|
+
} else {
|
|
950
|
+
code = code.substring(0, lastMatch.match.index) + lastMatch.match[1] + "return app.delete(" + lastMatch.match[2] + ");" + code.substring(lastMatch.match.index + lastMatch.match[0].length);
|
|
951
|
+
}
|
|
908
952
|
}
|
|
909
953
|
}
|
|
910
954
|
return code;
|
|
@@ -1021,20 +1065,23 @@ function generateDownMigration(diff) {
|
|
|
1021
1065
|
lines.push(``);
|
|
1022
1066
|
}
|
|
1023
1067
|
let code = lines.join("\n");
|
|
1024
|
-
const
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
if (
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1068
|
+
const hasReturnStatement = /return\s+app\.(save|delete)\(/m.test(code);
|
|
1069
|
+
if (!hasReturnStatement) {
|
|
1070
|
+
const savePattern = /^(\s*)app\.save\((\w+)\);$/gm;
|
|
1071
|
+
const deletePattern = /^(\s*)app\.delete\((\w+)\);$/gm;
|
|
1072
|
+
const saveMatches = [...code.matchAll(savePattern)];
|
|
1073
|
+
const deleteMatches = [...code.matchAll(deletePattern)];
|
|
1074
|
+
const allMatches = [
|
|
1075
|
+
...saveMatches.map((m) => ({ match: m, type: "save", index: m.index })),
|
|
1076
|
+
...deleteMatches.map((m) => ({ match: m, type: "delete", index: m.index }))
|
|
1077
|
+
].sort((a, b) => b.index - a.index);
|
|
1078
|
+
if (allMatches.length > 0) {
|
|
1079
|
+
const lastMatch = allMatches[0];
|
|
1080
|
+
if (lastMatch.type === "save") {
|
|
1081
|
+
code = code.substring(0, lastMatch.match.index) + lastMatch.match[1] + "return app.save(" + lastMatch.match[2] + ");" + code.substring(lastMatch.match.index + lastMatch.match[0].length);
|
|
1082
|
+
} else {
|
|
1083
|
+
code = code.substring(0, lastMatch.match.index) + lastMatch.match[1] + "return app.delete(" + lastMatch.match[2] + ");" + code.substring(lastMatch.match.index + lastMatch.match[0].length);
|
|
1084
|
+
}
|
|
1038
1085
|
}
|
|
1039
1086
|
}
|
|
1040
1087
|
return code;
|