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
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { e as SchemaDiff, C as CollectionSchema, F as FieldDefinition, c as FieldModification, f as CollectionOperation } from '../types-
|
|
2
|
-
import '../fields-
|
|
1
|
+
import { e as SchemaDiff, C as CollectionSchema, F as FieldDefinition, c as FieldModification, f as CollectionOperation } from '../types-Dfp-NP2D.js';
|
|
2
|
+
import '../fields-DBBm06VU.js';
|
|
3
3
|
import 'zod';
|
|
4
4
|
import '../permissions-ZHafVSIx.js';
|
|
5
5
|
|
|
@@ -273,7 +273,7 @@ function formatValue(value) {
|
|
|
273
273
|
return JSON.stringify(value).replace(/","/g, '", "');
|
|
274
274
|
}
|
|
275
275
|
if (typeof value === "object") {
|
|
276
|
-
const entries = Object.entries(value).map(([k, v]) => `${k}: ${formatValue(v)}`).join(", ");
|
|
276
|
+
const entries = Object.entries(value).filter(([_k, v]) => v !== void 0).map(([k, v]) => `${k}: ${formatValue(v)}`).join(", ");
|
|
277
277
|
return `{ ${entries} }`;
|
|
278
278
|
}
|
|
279
279
|
return String(value);
|
|
@@ -442,6 +442,9 @@ function getSystemFields() {
|
|
|
442
442
|
function generateCollectionCreation(collection, varName = "collection", isLast = false, collectionIdMap) {
|
|
443
443
|
const lines = [];
|
|
444
444
|
lines.push(` const ${varName} = new Collection({`);
|
|
445
|
+
if (collection.id) {
|
|
446
|
+
lines.push(` id: ${formatValue(collection.id)},`);
|
|
447
|
+
}
|
|
445
448
|
lines.push(` name: "${collection.name}",`);
|
|
446
449
|
lines.push(` type: "${collection.type}",`);
|
|
447
450
|
const permissionsCode = generateCollectionPermissions(collection.permissions);
|
|
@@ -564,11 +567,9 @@ function generateFieldModification(collectionName, modification, varName, isLast
|
|
|
564
567
|
function generateFieldDeletion(collectionName, fieldName, varName, isLast = false) {
|
|
565
568
|
const lines = [];
|
|
566
569
|
const collectionVar = varName || `collection_${collectionName}_${fieldName}`;
|
|
567
|
-
const fieldVar = `${collectionVar}_field`;
|
|
568
570
|
lines.push(` const ${collectionVar} = app.findCollectionByNameOrId("${collectionName}");`);
|
|
569
|
-
lines.push(` const ${fieldVar} = ${collectionVar}.fields.getByName("${fieldName}");`);
|
|
570
571
|
lines.push(``);
|
|
571
|
-
lines.push(` ${collectionVar}.fields.
|
|
572
|
+
lines.push(` ${collectionVar}.fields.removeByName("${fieldName}");`);
|
|
572
573
|
lines.push(``);
|
|
573
574
|
lines.push(isLast ? ` return app.save(${collectionVar});` : ` app.save(${collectionVar});`);
|
|
574
575
|
return lines.join("\n");
|
|
@@ -685,7 +686,27 @@ function generateOperationUpMigration(operation, collectionIdMap) {
|
|
|
685
686
|
const varName = `collection_${collectionName}`;
|
|
686
687
|
lines.push(generateCollectionDeletion(collectionName, varName, true));
|
|
687
688
|
}
|
|
688
|
-
|
|
689
|
+
let code = lines.join("\n");
|
|
690
|
+
const hasReturnStatement = /return\s+app\.(save|delete)\(/m.test(code);
|
|
691
|
+
if (!hasReturnStatement) {
|
|
692
|
+
const savePattern = /^(\s*)app\.save\((\w+)\);$/gm;
|
|
693
|
+
const deletePattern = /^(\s*)app\.delete\((\w+)\);$/gm;
|
|
694
|
+
const saveMatches = [...code.matchAll(savePattern)];
|
|
695
|
+
const deleteMatches = [...code.matchAll(deletePattern)];
|
|
696
|
+
const allMatches = [
|
|
697
|
+
...saveMatches.map((m) => ({ match: m, type: "save", index: m.index })),
|
|
698
|
+
...deleteMatches.map((m) => ({ match: m, type: "delete", index: m.index }))
|
|
699
|
+
].sort((a, b) => b.index - a.index);
|
|
700
|
+
if (allMatches.length > 0) {
|
|
701
|
+
const lastMatch = allMatches[0];
|
|
702
|
+
if (lastMatch.type === "save") {
|
|
703
|
+
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);
|
|
704
|
+
} else {
|
|
705
|
+
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);
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
return code;
|
|
689
710
|
}
|
|
690
711
|
function generateOperationDownMigration(operation, collectionIdMap) {
|
|
691
712
|
const lines = [];
|
|
@@ -770,7 +791,27 @@ function generateOperationDownMigration(operation, collectionIdMap) {
|
|
|
770
791
|
lines.push(generateCollectionCreation(collection, varName, true, collectionIdMap));
|
|
771
792
|
}
|
|
772
793
|
}
|
|
773
|
-
|
|
794
|
+
let code = lines.join("\n");
|
|
795
|
+
const hasReturnStatement = /return\s+app\.(save|delete)\(/m.test(code);
|
|
796
|
+
if (!hasReturnStatement) {
|
|
797
|
+
const savePattern = /^(\s*)app\.save\((\w+)\);$/gm;
|
|
798
|
+
const deletePattern = /^(\s*)app\.delete\((\w+)\);$/gm;
|
|
799
|
+
const saveMatches = [...code.matchAll(savePattern)];
|
|
800
|
+
const deleteMatches = [...code.matchAll(deletePattern)];
|
|
801
|
+
const allMatches = [
|
|
802
|
+
...saveMatches.map((m) => ({ match: m, type: "save", index: m.index })),
|
|
803
|
+
...deleteMatches.map((m) => ({ match: m, type: "delete", index: m.index }))
|
|
804
|
+
].sort((a, b) => b.index - a.index);
|
|
805
|
+
if (allMatches.length > 0) {
|
|
806
|
+
const lastMatch = allMatches[0];
|
|
807
|
+
if (lastMatch.type === "save") {
|
|
808
|
+
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);
|
|
809
|
+
} else {
|
|
810
|
+
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);
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
return code;
|
|
774
815
|
}
|
|
775
816
|
function generateUpMigration(diff) {
|
|
776
817
|
const lines = [];
|
|
@@ -868,20 +909,23 @@ function generateUpMigration(diff) {
|
|
|
868
909
|
lines.push(``);
|
|
869
910
|
}
|
|
870
911
|
let code = lines.join("\n");
|
|
871
|
-
const
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
if (
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
912
|
+
const hasReturnStatement = /return\s+app\.(save|delete)\(/m.test(code);
|
|
913
|
+
if (!hasReturnStatement) {
|
|
914
|
+
const savePattern = /^(\s*)app\.save\((\w+)\);$/gm;
|
|
915
|
+
const deletePattern = /^(\s*)app\.delete\((\w+)\);$/gm;
|
|
916
|
+
const saveMatches = [...code.matchAll(savePattern)];
|
|
917
|
+
const deleteMatches = [...code.matchAll(deletePattern)];
|
|
918
|
+
const allMatches = [
|
|
919
|
+
...saveMatches.map((m) => ({ match: m, type: "save", index: m.index })),
|
|
920
|
+
...deleteMatches.map((m) => ({ match: m, type: "delete", index: m.index }))
|
|
921
|
+
].sort((a, b) => b.index - a.index);
|
|
922
|
+
if (allMatches.length > 0) {
|
|
923
|
+
const lastMatch = allMatches[0];
|
|
924
|
+
if (lastMatch.type === "save") {
|
|
925
|
+
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);
|
|
926
|
+
} else {
|
|
927
|
+
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);
|
|
928
|
+
}
|
|
885
929
|
}
|
|
886
930
|
}
|
|
887
931
|
return code;
|
|
@@ -998,20 +1042,23 @@ function generateDownMigration(diff) {
|
|
|
998
1042
|
lines.push(``);
|
|
999
1043
|
}
|
|
1000
1044
|
let code = lines.join("\n");
|
|
1001
|
-
const
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
if (
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1045
|
+
const hasReturnStatement = /return\s+app\.(save|delete)\(/m.test(code);
|
|
1046
|
+
if (!hasReturnStatement) {
|
|
1047
|
+
const savePattern = /^(\s*)app\.save\((\w+)\);$/gm;
|
|
1048
|
+
const deletePattern = /^(\s*)app\.delete\((\w+)\);$/gm;
|
|
1049
|
+
const saveMatches = [...code.matchAll(savePattern)];
|
|
1050
|
+
const deleteMatches = [...code.matchAll(deletePattern)];
|
|
1051
|
+
const allMatches = [
|
|
1052
|
+
...saveMatches.map((m) => ({ match: m, type: "save", index: m.index })),
|
|
1053
|
+
...deleteMatches.map((m) => ({ match: m, type: "delete", index: m.index }))
|
|
1054
|
+
].sort((a, b) => b.index - a.index);
|
|
1055
|
+
if (allMatches.length > 0) {
|
|
1056
|
+
const lastMatch = allMatches[0];
|
|
1057
|
+
if (lastMatch.type === "save") {
|
|
1058
|
+
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);
|
|
1059
|
+
} else {
|
|
1060
|
+
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);
|
|
1061
|
+
}
|
|
1015
1062
|
}
|
|
1016
1063
|
}
|
|
1017
1064
|
return code;
|