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.
Files changed (64) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/cli/index.cjs +167 -46
  3. package/dist/cli/index.cjs.map +1 -1
  4. package/dist/cli/index.d.cts +2 -2
  5. package/dist/cli/index.d.ts +2 -2
  6. package/dist/cli/index.js +167 -46
  7. package/dist/cli/index.js.map +1 -1
  8. package/dist/cli/migrate.cjs +167 -46
  9. package/dist/cli/migrate.cjs.map +1 -1
  10. package/dist/cli/migrate.js +167 -46
  11. package/dist/cli/migrate.js.map +1 -1
  12. package/dist/cli/utils/index.d.cts +2 -2
  13. package/dist/cli/utils/index.d.ts +2 -2
  14. package/dist/{fields-UcOPu1OQ.d.cts → fields-RVj26U-O.d.cts} +1 -0
  15. package/dist/{fields-UcOPu1OQ.d.ts → fields-RVj26U-O.d.ts} +1 -0
  16. package/dist/index.cjs +167 -46
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +3 -3
  19. package/dist/index.d.ts +3 -3
  20. package/dist/index.js +167 -46
  21. package/dist/index.js.map +1 -1
  22. package/dist/migration/analyzer.cjs.map +1 -1
  23. package/dist/migration/analyzer.d.cts +2 -2
  24. package/dist/migration/analyzer.d.ts +2 -2
  25. package/dist/migration/analyzer.js.map +1 -1
  26. package/dist/migration/diff.cjs +77 -26
  27. package/dist/migration/diff.cjs.map +1 -1
  28. package/dist/migration/diff.d.cts +4 -4
  29. package/dist/migration/diff.d.ts +4 -4
  30. package/dist/migration/diff.js +77 -26
  31. package/dist/migration/diff.js.map +1 -1
  32. package/dist/migration/generator.cjs +39 -2
  33. package/dist/migration/generator.cjs.map +1 -1
  34. package/dist/migration/generator.d.cts +2 -2
  35. package/dist/migration/generator.d.ts +2 -2
  36. package/dist/migration/generator.js +39 -2
  37. package/dist/migration/generator.js.map +1 -1
  38. package/dist/migration/index.cjs +167 -46
  39. package/dist/migration/index.cjs.map +1 -1
  40. package/dist/migration/index.d.cts +3 -3
  41. package/dist/migration/index.d.ts +3 -3
  42. package/dist/migration/index.js +167 -46
  43. package/dist/migration/index.js.map +1 -1
  44. package/dist/migration/snapshot.cjs +51 -18
  45. package/dist/migration/snapshot.cjs.map +1 -1
  46. package/dist/migration/snapshot.d.cts +2 -2
  47. package/dist/migration/snapshot.d.ts +2 -2
  48. package/dist/migration/snapshot.js +51 -18
  49. package/dist/migration/snapshot.js.map +1 -1
  50. package/dist/migration/utils/index.cjs +5 -3
  51. package/dist/migration/utils/index.cjs.map +1 -1
  52. package/dist/migration/utils/index.d.cts +4 -4
  53. package/dist/migration/utils/index.d.ts +4 -4
  54. package/dist/migration/utils/index.js +5 -3
  55. package/dist/migration/utils/index.js.map +1 -1
  56. package/dist/schema.cjs.map +1 -1
  57. package/dist/schema.d.cts +1 -1
  58. package/dist/schema.d.ts +1 -1
  59. package/dist/schema.js.map +1 -1
  60. package/dist/{type-mapper-n231Fspm.d.ts → type-mapper-CZzVeDj7.d.ts} +1 -1
  61. package/dist/{type-mapper-DrQmtznD.d.cts → type-mapper-DaBe-1ph.d.cts} +1 -1
  62. package/dist/{types-Ds3NQvny.d.ts → types-CUVzgZ9k.d.ts} +1 -1
  63. package/dist/{types-YoBjsa-A.d.cts → types-D-Fsdn_O.d.cts} +1 -1
  64. 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-Ds3NQvny.js';
2
- import '../fields-UcOPu1OQ.js';
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
- return lines.join("\n");
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
- return lines.join("\n");
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 = [];