pocketbase-zod-schema 0.3.2 → 0.3.3

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 (44) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/cli/index.cjs +28 -6
  3. package/dist/cli/index.cjs.map +1 -1
  4. package/dist/cli/index.d.cts +1 -1
  5. package/dist/cli/index.d.ts +1 -1
  6. package/dist/cli/index.js +28 -6
  7. package/dist/cli/index.js.map +1 -1
  8. package/dist/cli/migrate.cjs +28 -6
  9. package/dist/cli/migrate.cjs.map +1 -1
  10. package/dist/cli/migrate.js +28 -6
  11. package/dist/cli/migrate.js.map +1 -1
  12. package/dist/cli/utils/index.d.cts +1 -1
  13. package/dist/cli/utils/index.d.ts +1 -1
  14. package/dist/index.cjs +42 -9
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +1 -1
  17. package/dist/index.d.ts +1 -1
  18. package/dist/index.js +42 -9
  19. package/dist/index.js.map +1 -1
  20. package/dist/migration/analyzer.d.cts +1 -1
  21. package/dist/migration/analyzer.d.ts +1 -1
  22. package/dist/migration/diff.cjs +10 -1
  23. package/dist/migration/diff.cjs.map +1 -1
  24. package/dist/migration/diff.d.cts +1 -1
  25. package/dist/migration/diff.d.ts +1 -1
  26. package/dist/migration/diff.js +10 -1
  27. package/dist/migration/diff.js.map +1 -1
  28. package/dist/migration/generator.cjs +32 -8
  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 +32 -8
  33. package/dist/migration/generator.js.map +1 -1
  34. package/dist/migration/index.cjs +42 -9
  35. package/dist/migration/index.cjs.map +1 -1
  36. package/dist/migration/index.d.cts +1 -1
  37. package/dist/migration/index.d.ts +1 -1
  38. package/dist/migration/index.js +42 -9
  39. package/dist/migration/index.js.map +1 -1
  40. package/dist/migration/snapshot.d.cts +1 -1
  41. package/dist/migration/snapshot.d.ts +1 -1
  42. package/dist/{types-Dfp-NP2D.d.ts → types-BWhwQxG-.d.ts} +5 -0
  43. package/dist/{types-CVxPCgWX.d.cts → types-d0yBwHoN.d.cts} +5 -0
  44. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.3.3](https://github.com/dastron/pocketbase-zod-schema/compare/pocketbase-zod-schema-v0.3.2...pocketbase-zod-schema-v0.3.3) (2026-01-06)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * looping migrations ([faf75ca](https://github.com/dastron/pocketbase-zod-schema/commit/faf75cada22149b262065f078fdffa8f5a9fdacd))
9
+
3
10
  ## [0.3.2](https://github.com/dastron/pocketbase-zod-schema/compare/pocketbase-zod-schema-v0.3.1...pocketbase-zod-schema-v0.3.2) (2026-01-06)
4
11
 
5
12
 
@@ -1962,10 +1962,19 @@ function aggregateChanges(currentSchema, previousSnapshot, config) {
1962
1962
  collectionsToModify.push(modification);
1963
1963
  }
1964
1964
  }
1965
+ const existingCollectionIds = /* @__PURE__ */ new Map();
1966
+ if (previousSnapshot) {
1967
+ for (const [name, collection] of previousSnapshot.collections) {
1968
+ if (collection.id) {
1969
+ existingCollectionIds.set(name, collection.id);
1970
+ }
1971
+ }
1972
+ }
1965
1973
  return {
1966
1974
  collectionsToCreate: collectionsWithIds,
1967
1975
  collectionsToDelete: filteredCollectionsToDelete,
1968
- collectionsToModify
1976
+ collectionsToModify,
1977
+ existingCollectionIds
1969
1978
  };
1970
1979
  }
1971
1980
  function categorizeChangesBySeverity(diff, _config) {
@@ -2431,7 +2440,7 @@ function generateFieldAddition(collectionName, field, varName, isLast = false, c
2431
2440
  lines.push(isLast ? ` return app.save(${collectionVar});` : ` app.save(${collectionVar});`);
2432
2441
  return lines.join("\n");
2433
2442
  }
2434
- function generateFieldModification(collectionName, modification, varName, isLast = false) {
2443
+ function generateFieldModification(collectionName, modification, varName, isLast = false, collectionIdMap) {
2435
2444
  const lines = [];
2436
2445
  const collectionVar = varName || `collection_${collectionName}_${modification.fieldName}`;
2437
2446
  const fieldVar = `${collectionVar}_field`;
@@ -2446,7 +2455,14 @@ function generateFieldModification(collectionName, modification, varName, isLast
2446
2455
  const relationKey = change.property.replace("relation.", "");
2447
2456
  if (relationKey === "collection") {
2448
2457
  const isUsersCollection = String(change.newValue).toLowerCase() === "users";
2449
- const collectionIdValue = isUsersCollection ? '"_pb_users_auth_"' : `app.findCollectionByNameOrId("${change.newValue}").id`;
2458
+ let collectionIdValue;
2459
+ if (isUsersCollection) {
2460
+ collectionIdValue = '"_pb_users_auth_"';
2461
+ } else if (collectionIdMap && collectionIdMap.has(String(change.newValue))) {
2462
+ collectionIdValue = `"${collectionIdMap.get(String(change.newValue))}"`;
2463
+ } else {
2464
+ collectionIdValue = `app.findCollectionByNameOrId("${change.newValue}").id`;
2465
+ }
2450
2466
  lines.push(` ${fieldVar}.collectionId = ${collectionIdValue};`);
2451
2467
  } else {
2452
2468
  lines.push(` ${fieldVar}.${relationKey} = ${formatValue(change.newValue)};`);
@@ -2522,9 +2538,10 @@ function generateOperationUpMigration(operation, collectionIdMap) {
2522
2538
  const collectionName = typeof operation.collection === "string" ? operation.collection : operation.collection?.name ?? modification.collection;
2523
2539
  let operationCount = 0;
2524
2540
  const totalOperations = modification.fieldsToAdd.length + modification.fieldsToModify.length + modification.fieldsToRemove.length + modification.indexesToAdd.length + modification.indexesToRemove.length + modification.rulesToUpdate.length + modification.permissionsToUpdate.length;
2525
- for (const field of modification.fieldsToAdd) {
2541
+ for (let i = 0; i < modification.fieldsToAdd.length; i++) {
2542
+ const field = modification.fieldsToAdd[i];
2526
2543
  operationCount++;
2527
- const varName = `collection_${collectionName}_add_${field.name}`;
2544
+ const varName = `collection_${collectionName}_add_${field.name}_${i}`;
2528
2545
  const isLast = operationCount === totalOperations;
2529
2546
  lines.push(generateFieldAddition(collectionName, field, varName, isLast, collectionIdMap));
2530
2547
  if (!isLast) lines.push("");
@@ -2533,7 +2550,7 @@ function generateOperationUpMigration(operation, collectionIdMap) {
2533
2550
  operationCount++;
2534
2551
  const varName = `collection_${collectionName}_modify_${fieldMod.fieldName}`;
2535
2552
  const isLast = operationCount === totalOperations;
2536
- lines.push(generateFieldModification(collectionName, fieldMod, varName, isLast));
2553
+ lines.push(generateFieldModification(collectionName, fieldMod, varName, isLast, collectionIdMap));
2537
2554
  if (!isLast) lines.push("");
2538
2555
  }
2539
2556
  for (const field of modification.fieldsToRemove) {
@@ -2727,6 +2744,11 @@ function generate(diff, config) {
2727
2744
  collectionIdMap.set(collection.name, collection.id);
2728
2745
  }
2729
2746
  }
2747
+ if (diff.existingCollectionIds) {
2748
+ for (const [name, id] of diff.existingCollectionIds) {
2749
+ collectionIdMap.set(name, id);
2750
+ }
2751
+ }
2730
2752
  const baseTimestamp = generateTimestamp(normalizedConfig);
2731
2753
  const operations = splitDiffByCollection(diff, baseTimestamp);
2732
2754
  const filePaths = [];