pocketbase-zod-schema 0.3.0 → 0.3.1
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 +8 -0
- package/dist/cli/index.cjs +167 -46
- 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 +167 -46
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/migrate.cjs +167 -46
- package/dist/cli/migrate.cjs.map +1 -1
- package/dist/cli/migrate.js +167 -46
- 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-RVj26U-O.d.cts} +1 -0
- package/dist/{fields-UcOPu1OQ.d.ts → fields-RVj26U-O.d.ts} +1 -0
- package/dist/index.cjs +167 -46
- 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 +167 -46
- 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 +39 -2
- 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 +39 -2
- package/dist/migration/generator.js.map +1 -1
- package/dist/migration/index.cjs +167 -46
- 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 +167 -46
- 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.map +1 -1
- package/dist/schema.d.cts +1 -1
- package/dist/schema.d.ts +1 -1
- package/dist/schema.js.map +1 -1
- package/dist/{type-mapper-n231Fspm.d.ts → type-mapper-CZzVeDj7.d.ts} +1 -1
- package/dist/{type-mapper-DrQmtznD.d.cts → type-mapper-DaBe-1ph.d.cts} +1 -1
- package/dist/{types-Ds3NQvny.d.ts → types-CUVzgZ9k.d.ts} +1 -1
- package/dist/{types-YoBjsa-A.d.cts → types-D-Fsdn_O.d.cts} +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-CUVzgZ9k.js';
|
|
2
|
+
import '../fields-RVj26U-O.js';
|
|
3
3
|
import 'zod';
|
|
4
4
|
import '../permissions-ZHafVSIx.js';
|
|
5
5
|
|
|
@@ -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);
|
|
@@ -685,7 +688,24 @@ function generateOperationUpMigration(operation, collectionIdMap) {
|
|
|
685
688
|
const varName = `collection_${collectionName}`;
|
|
686
689
|
lines.push(generateCollectionDeletion(collectionName, varName, true));
|
|
687
690
|
}
|
|
688
|
-
|
|
691
|
+
let code = lines.join("\n");
|
|
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
|
+
return code;
|
|
689
709
|
}
|
|
690
710
|
function generateOperationDownMigration(operation, collectionIdMap) {
|
|
691
711
|
const lines = [];
|
|
@@ -770,7 +790,24 @@ function generateOperationDownMigration(operation, collectionIdMap) {
|
|
|
770
790
|
lines.push(generateCollectionCreation(collection, varName, true, collectionIdMap));
|
|
771
791
|
}
|
|
772
792
|
}
|
|
773
|
-
|
|
793
|
+
let code = lines.join("\n");
|
|
794
|
+
const savePattern = /^(\s*)app\.save\((\w+)\);$/gm;
|
|
795
|
+
const deletePattern = /^(\s*)app\.delete\((\w+)\);$/gm;
|
|
796
|
+
const saveMatches = [...code.matchAll(savePattern)];
|
|
797
|
+
const deleteMatches = [...code.matchAll(deletePattern)];
|
|
798
|
+
const allMatches = [
|
|
799
|
+
...saveMatches.map((m) => ({ match: m, type: "save", index: m.index })),
|
|
800
|
+
...deleteMatches.map((m) => ({ match: m, type: "delete", index: m.index }))
|
|
801
|
+
].sort((a, b) => b.index - a.index);
|
|
802
|
+
if (allMatches.length > 0) {
|
|
803
|
+
const lastMatch = allMatches[0];
|
|
804
|
+
if (lastMatch.type === "save") {
|
|
805
|
+
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);
|
|
806
|
+
} else {
|
|
807
|
+
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);
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
return code;
|
|
774
811
|
}
|
|
775
812
|
function generateUpMigration(diff) {
|
|
776
813
|
const lines = [];
|