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.
Files changed (66) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/cli/index.cjs +175 -50
  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 +175 -50
  7. package/dist/cli/index.js.map +1 -1
  8. package/dist/cli/migrate.cjs +175 -50
  9. package/dist/cli/migrate.cjs.map +1 -1
  10. package/dist/cli/migrate.js +175 -50
  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-DBBm06VU.d.cts} +35 -7
  15. package/dist/{fields-UcOPu1OQ.d.ts → fields-DBBm06VU.d.ts} +35 -7
  16. package/dist/index.cjs +264 -84
  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 +264 -84
  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 +81 -34
  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 +81 -34
  37. package/dist/migration/generator.js.map +1 -1
  38. package/dist/migration/index.cjs +209 -78
  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 +209 -78
  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 +55 -6
  57. package/dist/schema.cjs.map +1 -1
  58. package/dist/schema.d.cts +1 -1
  59. package/dist/schema.d.ts +1 -1
  60. package/dist/schema.js +55 -6
  61. package/dist/schema.js.map +1 -1
  62. package/dist/{type-mapper-DrQmtznD.d.cts → type-mapper-DsGgZwUo.d.cts} +1 -1
  63. package/dist/{type-mapper-n231Fspm.d.ts → type-mapper-Dvh4QTM-.d.ts} +1 -1
  64. package/dist/{types-YoBjsa-A.d.cts → types-CVxPCgWX.d.cts} +1 -1
  65. package/dist/{types-Ds3NQvny.d.ts → types-Dfp-NP2D.d.ts} +1 -1
  66. 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-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.remove(${fieldVar}.id);`);
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
- return lines.join("\n");
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
- return lines.join("\n");
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 savePattern = /^(\s*)app\.save\((\w+)\);$/gm;
872
- const deletePattern = /^(\s*)app\.delete\((\w+)\);$/gm;
873
- const saveMatches = [...code.matchAll(savePattern)];
874
- const deleteMatches = [...code.matchAll(deletePattern)];
875
- const allMatches = [
876
- ...saveMatches.map((m) => ({ match: m, type: "save", index: m.index })),
877
- ...deleteMatches.map((m) => ({ match: m, type: "delete", index: m.index }))
878
- ].sort((a, b) => b.index - a.index);
879
- if (allMatches.length > 0) {
880
- const lastMatch = allMatches[0];
881
- if (lastMatch.type === "save") {
882
- 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);
883
- } else {
884
- 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);
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 savePattern = /^(\s*)app\.save\((\w+)\);$/gm;
1002
- const deletePattern = /^(\s*)app\.delete\((\w+)\);$/gm;
1003
- const saveMatches = [...code.matchAll(savePattern)];
1004
- const deleteMatches = [...code.matchAll(deletePattern)];
1005
- const allMatches = [
1006
- ...saveMatches.map((m) => ({ match: m, type: "save", index: m.index })),
1007
- ...deleteMatches.map((m) => ({ match: m, type: "delete", index: m.index }))
1008
- ].sort((a, b) => b.index - a.index);
1009
- if (allMatches.length > 0) {
1010
- const lastMatch = allMatches[0];
1011
- if (lastMatch.type === "save") {
1012
- 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);
1013
- } else {
1014
- 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);
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;