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 { S as SchemaDefinition, a as SchemaSnapshot, e as SchemaDiff, F as FieldDefinition, b as FieldChange, C as CollectionSchema, P as PermissionChange } from '../types-
|
|
2
|
-
import '../fields-
|
|
1
|
+
import { S as SchemaDefinition, a as SchemaSnapshot, e as SchemaDiff, F as FieldDefinition, b as FieldChange, C as CollectionSchema, P as PermissionChange } from '../types-CVxPCgWX.cjs';
|
|
2
|
+
import '../fields-DBBm06VU.cjs';
|
|
3
3
|
import 'zod';
|
|
4
4
|
import '../permissions-ZHafVSIx.cjs';
|
|
5
5
|
|
package/dist/migration/diff.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as SchemaDefinition, a as SchemaSnapshot, e as SchemaDiff, F as FieldDefinition, b as FieldChange, C as CollectionSchema, P as PermissionChange } from '../types-
|
|
2
|
-
import '../fields-
|
|
1
|
+
import { S as SchemaDefinition, a as SchemaSnapshot, e as SchemaDiff, F as FieldDefinition, b as FieldChange, C as CollectionSchema, P as PermissionChange } from '../types-Dfp-NP2D.js';
|
|
2
|
+
import '../fields-DBBm06VU.js';
|
|
3
3
|
import 'zod';
|
|
4
4
|
import '../permissions-ZHafVSIx.js';
|
|
5
5
|
|
|
@@ -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);
|
|
@@ -590,11 +590,9 @@ function generateFieldModification(collectionName, modification, varName, isLast
|
|
|
590
590
|
function generateFieldDeletion(collectionName, fieldName, varName, isLast = false) {
|
|
591
591
|
const lines = [];
|
|
592
592
|
const collectionVar = varName || `collection_${collectionName}_${fieldName}`;
|
|
593
|
-
const fieldVar = `${collectionVar}_field`;
|
|
594
593
|
lines.push(` const ${collectionVar} = app.findCollectionByNameOrId("${collectionName}");`);
|
|
595
|
-
lines.push(` const ${fieldVar} = ${collectionVar}.fields.getByName("${fieldName}");`);
|
|
596
594
|
lines.push(``);
|
|
597
|
-
lines.push(` ${collectionVar}.fields.
|
|
595
|
+
lines.push(` ${collectionVar}.fields.removeByName("${fieldName}");`);
|
|
598
596
|
lines.push(``);
|
|
599
597
|
lines.push(isLast ? ` return app.save(${collectionVar});` : ` app.save(${collectionVar});`);
|
|
600
598
|
return lines.join("\n");
|
|
@@ -712,20 +710,23 @@ function generateOperationUpMigration(operation, collectionIdMap) {
|
|
|
712
710
|
lines.push(generateCollectionDeletion(collectionName, varName, true));
|
|
713
711
|
}
|
|
714
712
|
let code = lines.join("\n");
|
|
715
|
-
const
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
if (
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
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
|
+
}
|
|
729
730
|
}
|
|
730
731
|
}
|
|
731
732
|
return code;
|
|
@@ -814,20 +815,23 @@ function generateOperationDownMigration(operation, collectionIdMap) {
|
|
|
814
815
|
}
|
|
815
816
|
}
|
|
816
817
|
let code = lines.join("\n");
|
|
817
|
-
const
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
if (
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
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
|
+
}
|
|
831
835
|
}
|
|
832
836
|
}
|
|
833
837
|
return code;
|
|
@@ -928,20 +932,23 @@ function generateUpMigration(diff) {
|
|
|
928
932
|
lines.push(``);
|
|
929
933
|
}
|
|
930
934
|
let code = lines.join("\n");
|
|
931
|
-
const
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
if (
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
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
|
+
}
|
|
945
952
|
}
|
|
946
953
|
}
|
|
947
954
|
return code;
|
|
@@ -1058,20 +1065,23 @@ function generateDownMigration(diff) {
|
|
|
1058
1065
|
lines.push(``);
|
|
1059
1066
|
}
|
|
1060
1067
|
let code = lines.join("\n");
|
|
1061
|
-
const
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
if (
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
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
|
+
}
|
|
1075
1085
|
}
|
|
1076
1086
|
}
|
|
1077
1087
|
return code;
|