pocketbase-zod-schema 0.3.1 → 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 +7 -0
- package/dist/cli/index.cjs +36 -32
- 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 +36 -32
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/migrate.cjs +36 -32
- package/dist/cli/migrate.cjs.map +1 -1
- package/dist/cli/migrate.js +36 -32
- 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-RVj26U-O.d.cts → fields-DBBm06VU.d.cts} +34 -7
- package/dist/{fields-RVj26U-O.d.ts → fields-DBBm06VU.d.ts} +34 -7
- package/dist/index.cjs +125 -66
- 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 +125 -66
- 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.d.cts +2 -2
- package/dist/migration/diff.d.ts +2 -2
- package/dist/migration/generator.cjs +70 -60
- 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 +70 -60
- package/dist/migration/generator.js.map +1 -1
- package/dist/migration/index.cjs +70 -60
- 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 +70 -60
- package/dist/migration/index.js.map +1 -1
- package/dist/migration/snapshot.d.cts +2 -2
- package/dist/migration/snapshot.d.ts +2 -2
- package/dist/migration/utils/index.cjs.map +1 -1
- package/dist/migration/utils/index.d.cts +2 -2
- package/dist/migration/utils/index.d.ts +2 -2
- 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-DaBe-1ph.d.cts → type-mapper-DsGgZwUo.d.cts} +1 -1
- package/dist/{type-mapper-CZzVeDj7.d.ts → type-mapper-Dvh4QTM-.d.ts} +1 -1
- package/dist/{types-D-Fsdn_O.d.cts → types-CVxPCgWX.d.cts} +1 -1
- package/dist/{types-CUVzgZ9k.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-CVxPCgWX.cjs';
|
|
2
|
+
import '../fields-DBBm06VU.cjs';
|
|
3
3
|
import 'zod';
|
|
4
4
|
import '../permissions-ZHafVSIx.cjs';
|
|
5
5
|
|
|
@@ -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);
|
|
@@ -567,11 +567,9 @@ function generateFieldModification(collectionName, modification, varName, isLast
|
|
|
567
567
|
function generateFieldDeletion(collectionName, fieldName, varName, isLast = false) {
|
|
568
568
|
const lines = [];
|
|
569
569
|
const collectionVar = varName || `collection_${collectionName}_${fieldName}`;
|
|
570
|
-
const fieldVar = `${collectionVar}_field`;
|
|
571
570
|
lines.push(` const ${collectionVar} = app.findCollectionByNameOrId("${collectionName}");`);
|
|
572
|
-
lines.push(` const ${fieldVar} = ${collectionVar}.fields.getByName("${fieldName}");`);
|
|
573
571
|
lines.push(``);
|
|
574
|
-
lines.push(` ${collectionVar}.fields.
|
|
572
|
+
lines.push(` ${collectionVar}.fields.removeByName("${fieldName}");`);
|
|
575
573
|
lines.push(``);
|
|
576
574
|
lines.push(isLast ? ` return app.save(${collectionVar});` : ` app.save(${collectionVar});`);
|
|
577
575
|
return lines.join("\n");
|
|
@@ -689,20 +687,23 @@ function generateOperationUpMigration(operation, collectionIdMap) {
|
|
|
689
687
|
lines.push(generateCollectionDeletion(collectionName, varName, true));
|
|
690
688
|
}
|
|
691
689
|
let code = lines.join("\n");
|
|
692
|
-
const
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
if (
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
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
|
+
}
|
|
706
707
|
}
|
|
707
708
|
}
|
|
708
709
|
return code;
|
|
@@ -791,20 +792,23 @@ function generateOperationDownMigration(operation, collectionIdMap) {
|
|
|
791
792
|
}
|
|
792
793
|
}
|
|
793
794
|
let code = lines.join("\n");
|
|
794
|
-
const
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
if (
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
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
|
+
}
|
|
808
812
|
}
|
|
809
813
|
}
|
|
810
814
|
return code;
|
|
@@ -905,20 +909,23 @@ function generateUpMigration(diff) {
|
|
|
905
909
|
lines.push(``);
|
|
906
910
|
}
|
|
907
911
|
let code = lines.join("\n");
|
|
908
|
-
const
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
if (
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
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
|
+
}
|
|
922
929
|
}
|
|
923
930
|
}
|
|
924
931
|
return code;
|
|
@@ -1035,20 +1042,23 @@ function generateDownMigration(diff) {
|
|
|
1035
1042
|
lines.push(``);
|
|
1036
1043
|
}
|
|
1037
1044
|
let code = lines.join("\n");
|
|
1038
|
-
const
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
if (
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
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
|
+
}
|
|
1052
1062
|
}
|
|
1053
1063
|
}
|
|
1054
1064
|
return code;
|