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.
Files changed (56) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/cli/index.cjs +36 -32
  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 +36 -32
  7. package/dist/cli/index.js.map +1 -1
  8. package/dist/cli/migrate.cjs +36 -32
  9. package/dist/cli/migrate.cjs.map +1 -1
  10. package/dist/cli/migrate.js +36 -32
  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-RVj26U-O.d.cts → fields-DBBm06VU.d.cts} +34 -7
  15. package/dist/{fields-RVj26U-O.d.ts → fields-DBBm06VU.d.ts} +34 -7
  16. package/dist/index.cjs +125 -66
  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 +125 -66
  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.d.cts +2 -2
  27. package/dist/migration/diff.d.ts +2 -2
  28. package/dist/migration/generator.cjs +70 -60
  29. package/dist/migration/generator.cjs.map +1 -1
  30. package/dist/migration/generator.d.cts +2 -2
  31. package/dist/migration/generator.d.ts +2 -2
  32. package/dist/migration/generator.js +70 -60
  33. package/dist/migration/generator.js.map +1 -1
  34. package/dist/migration/index.cjs +70 -60
  35. package/dist/migration/index.cjs.map +1 -1
  36. package/dist/migration/index.d.cts +3 -3
  37. package/dist/migration/index.d.ts +3 -3
  38. package/dist/migration/index.js +70 -60
  39. package/dist/migration/index.js.map +1 -1
  40. package/dist/migration/snapshot.d.cts +2 -2
  41. package/dist/migration/snapshot.d.ts +2 -2
  42. package/dist/migration/utils/index.cjs.map +1 -1
  43. package/dist/migration/utils/index.d.cts +2 -2
  44. package/dist/migration/utils/index.d.ts +2 -2
  45. package/dist/migration/utils/index.js.map +1 -1
  46. package/dist/schema.cjs +55 -6
  47. package/dist/schema.cjs.map +1 -1
  48. package/dist/schema.d.cts +1 -1
  49. package/dist/schema.d.ts +1 -1
  50. package/dist/schema.js +55 -6
  51. package/dist/schema.js.map +1 -1
  52. package/dist/{type-mapper-DaBe-1ph.d.cts → type-mapper-DsGgZwUo.d.cts} +1 -1
  53. package/dist/{type-mapper-CZzVeDj7.d.ts → type-mapper-Dvh4QTM-.d.ts} +1 -1
  54. package/dist/{types-D-Fsdn_O.d.cts → types-CVxPCgWX.d.cts} +1 -1
  55. package/dist/{types-CUVzgZ9k.d.ts → types-Dfp-NP2D.d.ts} +1 -1
  56. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  export { MigrationConfig, StatusOutput, VerbosityLevel, createProgressBar, createSpinner, formatChangeSummary, formatDuration, formatStatusJson, getMigrationsDirectory, getSchemaDirectory, getVerbosity, loadConfig, logBox, logDebug, logError, logInfo, logKeyValue, logList, logSection, logStep, logSuccess, logTable, logTimed, logTimestamp, logWarning, setVerbosity, withProgress } from './utils/index.cjs';
2
2
  import 'ora';
3
- import '../types-D-Fsdn_O.cjs';
4
- import '../fields-RVj26U-O.cjs';
3
+ import '../types-CVxPCgWX.cjs';
4
+ import '../fields-DBBm06VU.cjs';
5
5
  import 'zod';
6
6
  import '../permissions-ZHafVSIx.cjs';
7
7
 
@@ -1,7 +1,7 @@
1
1
  export { MigrationConfig, StatusOutput, VerbosityLevel, createProgressBar, createSpinner, formatChangeSummary, formatDuration, formatStatusJson, getMigrationsDirectory, getSchemaDirectory, getVerbosity, loadConfig, logBox, logDebug, logError, logInfo, logKeyValue, logList, logSection, logStep, logSuccess, logTable, logTimed, logTimestamp, logWarning, setVerbosity, withProgress } from './utils/index.js';
2
2
  import 'ora';
3
- import '../types-CUVzgZ9k.js';
4
- import '../fields-RVj26U-O.js';
3
+ import '../types-Dfp-NP2D.js';
4
+ import '../fields-DBBm06VU.js';
5
5
  import 'zod';
6
6
  import '../permissions-ZHafVSIx.js';
7
7
 
package/dist/cli/index.js CHANGED
@@ -2141,7 +2141,7 @@ function formatValue(value) {
2141
2141
  return JSON.stringify(value).replace(/","/g, '", "');
2142
2142
  }
2143
2143
  if (typeof value === "object") {
2144
- const entries = Object.entries(value).map(([k, v]) => `${k}: ${formatValue(v)}`).join(", ");
2144
+ const entries = Object.entries(value).filter(([_k, v]) => v !== void 0).map(([k, v]) => `${k}: ${formatValue(v)}`).join(", ");
2145
2145
  return `{ ${entries} }`;
2146
2146
  }
2147
2147
  return String(value);
@@ -2435,11 +2435,9 @@ function generateFieldModification(collectionName, modification, varName, isLast
2435
2435
  function generateFieldDeletion(collectionName, fieldName, varName, isLast = false) {
2436
2436
  const lines = [];
2437
2437
  const collectionVar = varName || `collection_${collectionName}_${fieldName}`;
2438
- const fieldVar = `${collectionVar}_field`;
2439
2438
  lines.push(` const ${collectionVar} = app.findCollectionByNameOrId("${collectionName}");`);
2440
- lines.push(` const ${fieldVar} = ${collectionVar}.fields.getByName("${fieldName}");`);
2441
2439
  lines.push(``);
2442
- lines.push(` ${collectionVar}.fields.remove(${fieldVar}.id);`);
2440
+ lines.push(` ${collectionVar}.fields.removeByName("${fieldName}");`);
2443
2441
  lines.push(``);
2444
2442
  lines.push(isLast ? ` return app.save(${collectionVar});` : ` app.save(${collectionVar});`);
2445
2443
  return lines.join("\n");
@@ -2557,20 +2555,23 @@ function generateOperationUpMigration(operation, collectionIdMap) {
2557
2555
  lines.push(generateCollectionDeletion(collectionName, varName, true));
2558
2556
  }
2559
2557
  let code = lines.join("\n");
2560
- const savePattern = /^(\s*)app\.save\((\w+)\);$/gm;
2561
- const deletePattern = /^(\s*)app\.delete\((\w+)\);$/gm;
2562
- const saveMatches = [...code.matchAll(savePattern)];
2563
- const deleteMatches = [...code.matchAll(deletePattern)];
2564
- const allMatches = [
2565
- ...saveMatches.map((m) => ({ match: m, type: "save", index: m.index })),
2566
- ...deleteMatches.map((m) => ({ match: m, type: "delete", index: m.index }))
2567
- ].sort((a, b) => b.index - a.index);
2568
- if (allMatches.length > 0) {
2569
- const lastMatch = allMatches[0];
2570
- if (lastMatch.type === "save") {
2571
- 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);
2572
- } else {
2573
- 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);
2558
+ const hasReturnStatement = /return\s+app\.(save|delete)\(/m.test(code);
2559
+ if (!hasReturnStatement) {
2560
+ const savePattern = /^(\s*)app\.save\((\w+)\);$/gm;
2561
+ const deletePattern = /^(\s*)app\.delete\((\w+)\);$/gm;
2562
+ const saveMatches = [...code.matchAll(savePattern)];
2563
+ const deleteMatches = [...code.matchAll(deletePattern)];
2564
+ const allMatches = [
2565
+ ...saveMatches.map((m) => ({ match: m, type: "save", index: m.index })),
2566
+ ...deleteMatches.map((m) => ({ match: m, type: "delete", index: m.index }))
2567
+ ].sort((a, b) => b.index - a.index);
2568
+ if (allMatches.length > 0) {
2569
+ const lastMatch = allMatches[0];
2570
+ if (lastMatch.type === "save") {
2571
+ 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);
2572
+ } else {
2573
+ 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);
2574
+ }
2574
2575
  }
2575
2576
  }
2576
2577
  return code;
@@ -2659,20 +2660,23 @@ function generateOperationDownMigration(operation, collectionIdMap) {
2659
2660
  }
2660
2661
  }
2661
2662
  let code = lines.join("\n");
2662
- const savePattern = /^(\s*)app\.save\((\w+)\);$/gm;
2663
- const deletePattern = /^(\s*)app\.delete\((\w+)\);$/gm;
2664
- const saveMatches = [...code.matchAll(savePattern)];
2665
- const deleteMatches = [...code.matchAll(deletePattern)];
2666
- const allMatches = [
2667
- ...saveMatches.map((m) => ({ match: m, type: "save", index: m.index })),
2668
- ...deleteMatches.map((m) => ({ match: m, type: "delete", index: m.index }))
2669
- ].sort((a, b) => b.index - a.index);
2670
- if (allMatches.length > 0) {
2671
- const lastMatch = allMatches[0];
2672
- if (lastMatch.type === "save") {
2673
- 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);
2674
- } else {
2675
- 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);
2663
+ const hasReturnStatement = /return\s+app\.(save|delete)\(/m.test(code);
2664
+ if (!hasReturnStatement) {
2665
+ const savePattern = /^(\s*)app\.save\((\w+)\);$/gm;
2666
+ const deletePattern = /^(\s*)app\.delete\((\w+)\);$/gm;
2667
+ const saveMatches = [...code.matchAll(savePattern)];
2668
+ const deleteMatches = [...code.matchAll(deletePattern)];
2669
+ const allMatches = [
2670
+ ...saveMatches.map((m) => ({ match: m, type: "save", index: m.index })),
2671
+ ...deleteMatches.map((m) => ({ match: m, type: "delete", index: m.index }))
2672
+ ].sort((a, b) => b.index - a.index);
2673
+ if (allMatches.length > 0) {
2674
+ const lastMatch = allMatches[0];
2675
+ if (lastMatch.type === "save") {
2676
+ 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);
2677
+ } else {
2678
+ 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);
2679
+ }
2676
2680
  }
2677
2681
  }
2678
2682
  return code;