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
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.3.1](https://github.com/dastron/pocketbase-zod-schema/compare/pocketbase-zod-schema-v0.3.0...pocketbase-zod-schema-v0.3.1) (2026-01-05)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * add collection id ([2ee0808](https://github.com/dastron/pocketbase-zod-schema/commit/2ee08082f5a27b76a277e37427ba16011046a1cc))
9
+ * Add Collection Id on Create ([c911b94](https://github.com/dastron/pocketbase-zod-schema/commit/c911b946b34317387bce06a70ad14f3718658a11))
10
+
3
11
  ## [0.3.0](https://github.com/dastron/pocketbase-zod-schema/compare/pocketbase-zod-schema-v0.2.5...pocketbase-zod-schema-v0.3.0) (2026-01-04)
4
12
 
5
13
 
@@ -1519,17 +1519,19 @@ var CollectionIdRegistry = class {
1519
1519
  }
1520
1520
  /**
1521
1521
  * Generates a unique collection ID for a given collection name
1522
- * Special case: Returns constant "_pb_users_auth_" for users collection
1523
1522
  * Retries up to 10 times if collision occurs (extremely rare)
1523
+ * Special case: returns "_pb_users_auth_" for users collection
1524
1524
  *
1525
- * @param collectionName - The name of the collection
1525
+ * @param collectionName - The name of the collection (optional)
1526
1526
  * @returns A unique collection ID
1527
1527
  * @throws Error if unable to generate unique ID after max attempts
1528
1528
  */
1529
1529
  generate(collectionName) {
1530
1530
  if (collectionName && collectionName.toLowerCase() === "users") {
1531
1531
  const usersId = "_pb_users_auth_";
1532
- this.register(usersId);
1532
+ if (!this.has(usersId)) {
1533
+ this.register(usersId);
1534
+ }
1533
1535
  return usersId;
1534
1536
  }
1535
1537
  const maxAttempts = 10;
@@ -1702,18 +1704,49 @@ function compareFieldConstraints(currentField, previousField) {
1702
1704
  }
1703
1705
  return changes;
1704
1706
  }
1707
+ function normalizeOptionValue(key, value, fieldType) {
1708
+ if (key === "maxSelect" && value === 1 && (fieldType === "select" || fieldType === "file")) {
1709
+ return void 0;
1710
+ }
1711
+ if (key === "maxSize" && value === 0 && fieldType === "file") {
1712
+ return void 0;
1713
+ }
1714
+ if (fieldType === "file") {
1715
+ if (key === "mimeTypes" && Array.isArray(value) && value.length === 0) {
1716
+ return void 0;
1717
+ }
1718
+ if (key === "thumbs" && Array.isArray(value) && value.length === 0) {
1719
+ return void 0;
1720
+ }
1721
+ if (key === "protected" && value === false) {
1722
+ return void 0;
1723
+ }
1724
+ }
1725
+ if (fieldType === "autodate") {
1726
+ if (key === "onCreate" && value === true) {
1727
+ return void 0;
1728
+ }
1729
+ if (key === "onUpdate" && value === false) {
1730
+ return void 0;
1731
+ }
1732
+ }
1733
+ return value;
1734
+ }
1705
1735
  function compareFieldOptions(currentField, previousField) {
1706
1736
  const changes = [];
1707
1737
  const currentOptions = currentField.options || {};
1708
1738
  const previousOptions = previousField.options || {};
1709
1739
  const allKeys = /* @__PURE__ */ new Set([...Object.keys(currentOptions), ...Object.keys(previousOptions)]);
1740
+ const fieldType = currentField.type;
1710
1741
  for (const key of allKeys) {
1711
1742
  const currentValue = currentOptions[key];
1712
1743
  const previousValue = previousOptions[key];
1713
- if (currentValue === void 0 && previousValue === void 0) {
1744
+ const normalizedCurrent = normalizeOptionValue(key, currentValue, fieldType);
1745
+ const normalizedPrevious = normalizeOptionValue(key, previousValue, fieldType);
1746
+ if (normalizedCurrent === void 0 && normalizedPrevious === void 0) {
1714
1747
  continue;
1715
1748
  }
1716
- if (!areValuesEqual(currentValue, previousValue)) {
1749
+ if (!areValuesEqual(normalizedCurrent, normalizedPrevious)) {
1717
1750
  changes.push({
1718
1751
  property: `options.${key}`,
1719
1752
  oldValue: previousValue,
@@ -1723,7 +1756,7 @@ function compareFieldOptions(currentField, previousField) {
1723
1756
  }
1724
1757
  return changes;
1725
1758
  }
1726
- function compareRelationConfigurations(currentField, previousField) {
1759
+ function compareRelationConfigurations(currentField, previousField, collectionIdToName) {
1727
1760
  const changes = [];
1728
1761
  const currentRelation = currentField.relation;
1729
1762
  const previousRelation = previousField.relation;
@@ -1735,8 +1768,8 @@ function compareRelationConfigurations(currentField, previousField) {
1735
1768
  }
1736
1769
  const normalizeCollection = (collection) => {
1737
1770
  if (!collection) return collection;
1738
- if (collection === "_pb_users_auth_") {
1739
- return "Users";
1771
+ if (collectionIdToName && collectionIdToName.has(collection)) {
1772
+ return collectionIdToName.get(collection);
1740
1773
  }
1741
1774
  const nameMatch = collection.match(/app\.findCollectionByNameOrId\s*\(\s*["']([^"']+)["']\s*\)/);
1742
1775
  if (nameMatch) {
@@ -1746,13 +1779,11 @@ function compareRelationConfigurations(currentField, previousField) {
1746
1779
  };
1747
1780
  const normalizedCurrent = normalizeCollection(currentRelation.collection);
1748
1781
  const normalizedPrevious = normalizeCollection(previousRelation.collection);
1749
- if (normalizedCurrent !== normalizedPrevious) {
1782
+ if (normalizedCurrent.toLowerCase() !== normalizedPrevious.toLowerCase()) {
1750
1783
  changes.push({
1751
1784
  property: "relation.collection",
1752
- oldValue: normalizedPrevious,
1753
- // Use normalized value for clarity
1754
- newValue: normalizedCurrent
1755
- // Use normalized value for clarity
1785
+ oldValue: previousRelation.collection,
1786
+ newValue: currentRelation.collection
1756
1787
  });
1757
1788
  }
1758
1789
  if (currentRelation.cascadeDelete !== previousRelation.cascadeDelete) {
@@ -1762,14 +1793,20 @@ function compareRelationConfigurations(currentField, previousField) {
1762
1793
  newValue: currentRelation.cascadeDelete
1763
1794
  });
1764
1795
  }
1765
- if (currentRelation.maxSelect !== previousRelation.maxSelect) {
1796
+ const normalizeMax = (val) => val === 1 ? null : val;
1797
+ const currentMax = normalizeMax(currentRelation.maxSelect);
1798
+ const previousMax = normalizeMax(previousRelation.maxSelect);
1799
+ if (currentMax != previousMax) {
1766
1800
  changes.push({
1767
1801
  property: "relation.maxSelect",
1768
1802
  oldValue: previousRelation.maxSelect,
1769
1803
  newValue: currentRelation.maxSelect
1770
1804
  });
1771
1805
  }
1772
- if (currentRelation.minSelect !== previousRelation.minSelect) {
1806
+ const normalizeMin = (val) => val === 0 ? null : val;
1807
+ const currentMin = normalizeMin(currentRelation.minSelect);
1808
+ const previousMin = normalizeMin(previousRelation.minSelect);
1809
+ if (currentMin != previousMin) {
1773
1810
  changes.push({
1774
1811
  property: "relation.minSelect",
1775
1812
  oldValue: previousRelation.minSelect,
@@ -1778,7 +1815,7 @@ function compareRelationConfigurations(currentField, previousField) {
1778
1815
  }
1779
1816
  return changes;
1780
1817
  }
1781
- function detectFieldChanges(currentField, previousField) {
1818
+ function detectFieldChanges(currentField, previousField, collectionIdToName) {
1782
1819
  const changes = [];
1783
1820
  const typeChange = compareFieldTypes(currentField, previousField);
1784
1821
  if (typeChange) {
@@ -1787,7 +1824,7 @@ function detectFieldChanges(currentField, previousField) {
1787
1824
  changes.push(...compareFieldConstraints(currentField, previousField));
1788
1825
  changes.push(...compareFieldOptions(currentField, previousField));
1789
1826
  if (currentField.type === "relation" && previousField.type === "relation") {
1790
- changes.push(...compareRelationConfigurations(currentField, previousField));
1827
+ changes.push(...compareRelationConfigurations(currentField, previousField, collectionIdToName));
1791
1828
  }
1792
1829
  return changes;
1793
1830
  }
@@ -1798,7 +1835,7 @@ function compareIndexes(currentIndexes = [], previousIndexes = []) {
1798
1835
  const indexesToRemove = previousIndexes.filter((idx) => !currentSet.has(idx));
1799
1836
  return { indexesToAdd, indexesToRemove };
1800
1837
  }
1801
- function compareRules(currentRules, previousRules) {
1838
+ function compareRules(currentRules, previousRules, currentPermissions, previousPermissions) {
1802
1839
  const updates = [];
1803
1840
  const ruleTypes = [
1804
1841
  "listRule",
@@ -1809,8 +1846,8 @@ function compareRules(currentRules, previousRules) {
1809
1846
  "manageRule"
1810
1847
  ];
1811
1848
  for (const ruleType of ruleTypes) {
1812
- const currentValue = currentRules?.[ruleType] ?? null;
1813
- const previousValue = previousRules?.[ruleType] ?? null;
1849
+ const currentValue = currentRules?.[ruleType] ?? currentPermissions?.[ruleType] ?? null;
1850
+ const previousValue = previousRules?.[ruleType] ?? previousPermissions?.[ruleType] ?? null;
1814
1851
  if (currentValue !== previousValue) {
1815
1852
  updates.push({
1816
1853
  ruleType,
@@ -1837,7 +1874,7 @@ function comparePermissions(currentPermissions, previousPermissions) {
1837
1874
  }
1838
1875
  return changes;
1839
1876
  }
1840
- function compareCollectionFields(currentCollection, previousCollection, config) {
1877
+ function compareCollectionFields(currentCollection, previousCollection, config, collectionIdToName) {
1841
1878
  let fieldsToAdd = findNewFields(currentCollection.fields, previousCollection.fields);
1842
1879
  const fieldsToRemove = findRemovedFields(currentCollection.fields, previousCollection.fields);
1843
1880
  const fieldsToModify = [];
@@ -1847,7 +1884,7 @@ function compareCollectionFields(currentCollection, previousCollection, config)
1847
1884
  }
1848
1885
  const matchedFields = matchFieldsByName(currentCollection.fields, previousCollection.fields);
1849
1886
  for (const [currentField, previousField] of matchedFields) {
1850
- const changes = detectFieldChanges(currentField, previousField);
1887
+ const changes = detectFieldChanges(currentField, previousField, collectionIdToName);
1851
1888
  if (changes.length > 0) {
1852
1889
  fieldsToModify.push({
1853
1890
  fieldName: currentField.name,
@@ -1859,14 +1896,20 @@ function compareCollectionFields(currentCollection, previousCollection, config)
1859
1896
  }
1860
1897
  return { fieldsToAdd, fieldsToRemove, fieldsToModify };
1861
1898
  }
1862
- function buildCollectionModification(currentCollection, previousCollection, config) {
1899
+ function buildCollectionModification(currentCollection, previousCollection, config, collectionIdToName) {
1863
1900
  const { fieldsToAdd, fieldsToRemove, fieldsToModify } = compareCollectionFields(
1864
1901
  currentCollection,
1865
1902
  previousCollection,
1866
- config
1903
+ config,
1904
+ collectionIdToName
1867
1905
  );
1868
1906
  const { indexesToAdd, indexesToRemove } = compareIndexes(currentCollection.indexes, previousCollection.indexes);
1869
- const rulesToUpdate = compareRules(currentCollection.rules, previousCollection.rules);
1907
+ const rulesToUpdate = compareRules(
1908
+ currentCollection.rules,
1909
+ previousCollection.rules,
1910
+ currentCollection.permissions,
1911
+ previousCollection.permissions
1912
+ );
1870
1913
  const permissionsToUpdate = comparePermissions(currentCollection.permissions, previousCollection.permissions);
1871
1914
  return {
1872
1915
  collection: currentCollection.name,
@@ -1883,6 +1926,14 @@ function hasChanges(modification) {
1883
1926
  return modification.fieldsToAdd.length > 0 || modification.fieldsToRemove.length > 0 || modification.fieldsToModify.length > 0 || modification.indexesToAdd.length > 0 || modification.indexesToRemove.length > 0 || modification.rulesToUpdate.length > 0 || modification.permissionsToUpdate.length > 0;
1884
1927
  }
1885
1928
  function aggregateChanges(currentSchema, previousSnapshot, config) {
1929
+ const collectionIdToName = /* @__PURE__ */ new Map();
1930
+ if (previousSnapshot) {
1931
+ for (const [name, collection] of previousSnapshot.collections) {
1932
+ if (collection.id) {
1933
+ collectionIdToName.set(collection.id, name);
1934
+ }
1935
+ }
1936
+ }
1886
1937
  const collectionsToCreate = findNewCollections(currentSchema, previousSnapshot);
1887
1938
  const collectionsToDelete = findRemovedCollections(currentSchema, previousSnapshot);
1888
1939
  const filteredCollectionsToCreate = collectionsToCreate.filter(
@@ -1906,7 +1957,7 @@ function aggregateChanges(currentSchema, previousSnapshot, config) {
1906
1957
  const collectionsToModify = [];
1907
1958
  const matchedCollections = matchCollectionsByName(currentSchema, previousSnapshot);
1908
1959
  for (const [currentCollection, previousCollection] of matchedCollections) {
1909
- const modification = buildCollectionModification(currentCollection, previousCollection, config);
1960
+ const modification = buildCollectionModification(currentCollection, previousCollection, config, collectionIdToName);
1910
1961
  if (hasChanges(modification)) {
1911
1962
  collectionsToModify.push(modification);
1912
1963
  }
@@ -2286,6 +2337,9 @@ function getSystemFields() {
2286
2337
  function generateCollectionCreation(collection, varName = "collection", isLast = false, collectionIdMap) {
2287
2338
  const lines = [];
2288
2339
  lines.push(` const ${varName} = new Collection({`);
2340
+ if (collection.id) {
2341
+ lines.push(` id: ${formatValue(collection.id)},`);
2342
+ }
2289
2343
  lines.push(` name: "${collection.name}",`);
2290
2344
  lines.push(` type: "${collection.type}",`);
2291
2345
  const permissionsCode = generateCollectionPermissions(collection.permissions);
@@ -2529,7 +2583,24 @@ function generateOperationUpMigration(operation, collectionIdMap) {
2529
2583
  const varName = `collection_${collectionName}`;
2530
2584
  lines.push(generateCollectionDeletion(collectionName, varName, true));
2531
2585
  }
2532
- return lines.join("\n");
2586
+ let code = lines.join("\n");
2587
+ const savePattern = /^(\s*)app\.save\((\w+)\);$/gm;
2588
+ const deletePattern = /^(\s*)app\.delete\((\w+)\);$/gm;
2589
+ const saveMatches = [...code.matchAll(savePattern)];
2590
+ const deleteMatches = [...code.matchAll(deletePattern)];
2591
+ const allMatches = [
2592
+ ...saveMatches.map((m) => ({ match: m, type: "save", index: m.index })),
2593
+ ...deleteMatches.map((m) => ({ match: m, type: "delete", index: m.index }))
2594
+ ].sort((a, b) => b.index - a.index);
2595
+ if (allMatches.length > 0) {
2596
+ const lastMatch = allMatches[0];
2597
+ if (lastMatch.type === "save") {
2598
+ 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);
2599
+ } else {
2600
+ 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);
2601
+ }
2602
+ }
2603
+ return code;
2533
2604
  }
2534
2605
  function generateOperationDownMigration(operation, collectionIdMap) {
2535
2606
  const lines = [];
@@ -2614,7 +2685,24 @@ function generateOperationDownMigration(operation, collectionIdMap) {
2614
2685
  lines.push(generateCollectionCreation(collection, varName, true, collectionIdMap));
2615
2686
  }
2616
2687
  }
2617
- return lines.join("\n");
2688
+ let code = lines.join("\n");
2689
+ const savePattern = /^(\s*)app\.save\((\w+)\);$/gm;
2690
+ const deletePattern = /^(\s*)app\.delete\((\w+)\);$/gm;
2691
+ const saveMatches = [...code.matchAll(savePattern)];
2692
+ const deleteMatches = [...code.matchAll(deletePattern)];
2693
+ const allMatches = [
2694
+ ...saveMatches.map((m) => ({ match: m, type: "save", index: m.index })),
2695
+ ...deleteMatches.map((m) => ({ match: m, type: "delete", index: m.index }))
2696
+ ].sort((a, b) => b.index - a.index);
2697
+ if (allMatches.length > 0) {
2698
+ const lastMatch = allMatches[0];
2699
+ if (lastMatch.type === "save") {
2700
+ 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);
2701
+ } else {
2702
+ 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);
2703
+ }
2704
+ }
2705
+ return code;
2618
2706
  }
2619
2707
  function generate(diff, config) {
2620
2708
  const normalizedConfig = typeof config === "string" ? { migrationDir: config } : config;
@@ -2663,7 +2751,7 @@ function generate(diff, config) {
2663
2751
  var SNAPSHOT_VERSION = "1.0.0";
2664
2752
  function resolveCollectionIdToName(collectionId) {
2665
2753
  if (collectionId === "_pb_users_auth_") {
2666
- return "Users";
2754
+ return "users";
2667
2755
  }
2668
2756
  const nameMatch = collectionId.match(/app\.findCollectionByNameOrId\s*\(\s*["']([^"']+)["']\s*\)/);
2669
2757
  if (nameMatch) {
@@ -2671,6 +2759,39 @@ function resolveCollectionIdToName(collectionId) {
2671
2759
  }
2672
2760
  return collectionId;
2673
2761
  }
2762
+ function extractFieldOptions2(pbField) {
2763
+ const options = {};
2764
+ if (pbField.options && typeof pbField.options === "object") {
2765
+ Object.assign(options, pbField.options);
2766
+ }
2767
+ const directOptionKeys = [
2768
+ "min",
2769
+ "max",
2770
+ "pattern",
2771
+ "noDecimal",
2772
+ // text/number fields
2773
+ "values",
2774
+ "maxSelect",
2775
+ // select fields
2776
+ "mimeTypes",
2777
+ "maxSize",
2778
+ "thumbs",
2779
+ "protected",
2780
+ // file fields
2781
+ "onCreate",
2782
+ "onUpdate",
2783
+ // autodate fields
2784
+ "exceptDomains",
2785
+ "onlyDomains"
2786
+ // email/url fields
2787
+ ];
2788
+ for (const key of directOptionKeys) {
2789
+ if (pbField[key] !== void 0) {
2790
+ options[key] = pbField[key];
2791
+ }
2792
+ }
2793
+ return options;
2794
+ }
2674
2795
  function convertPocketBaseCollection(pbCollection) {
2675
2796
  const fields = [];
2676
2797
  const systemFieldNames = ["id", "created", "updated", "collectionId", "collectionName", "expand"];
@@ -2688,23 +2809,19 @@ function convertPocketBaseCollection(pbCollection) {
2688
2809
  type: pbField.type,
2689
2810
  required: pbField.required || false
2690
2811
  };
2691
- field.options = pbField.options ? { ...pbField.options } : {};
2692
- if (pbField.type === "select") {
2693
- if (pbField.values && Array.isArray(pbField.values)) {
2694
- field.options.values = pbField.values;
2695
- } else if (pbField.options?.values && Array.isArray(pbField.options.values)) {
2696
- field.options.values = pbField.options.values;
2697
- }
2698
- }
2812
+ field.options = extractFieldOptions2(pbField);
2699
2813
  if (pbField.type === "relation") {
2700
2814
  const collectionId = pbField.collectionId || pbField.options?.collectionId || "";
2701
- const collectionName = resolveCollectionIdToName(collectionId);
2815
+ const collectionName = resolveCollectionIdToName(collectionId || "");
2702
2816
  field.relation = {
2703
2817
  collection: collectionName,
2704
2818
  cascadeDelete: pbField.cascadeDelete ?? pbField.options?.cascadeDelete ?? false,
2705
2819
  maxSelect: pbField.maxSelect ?? pbField.options?.maxSelect,
2706
2820
  minSelect: pbField.minSelect ?? pbField.options?.minSelect
2707
2821
  };
2822
+ delete field.options.maxSelect;
2823
+ delete field.options.minSelect;
2824
+ delete field.options.cascadeDelete;
2708
2825
  }
2709
2826
  const hasOnlyValues = Object.keys(field.options).length === 1 && field.options.values !== void 0;
2710
2827
  if (Object.keys(field.options).length === 0) {
@@ -2718,17 +2835,21 @@ function convertPocketBaseCollection(pbCollection) {
2718
2835
  type: pbCollection.type || "base",
2719
2836
  fields
2720
2837
  };
2838
+ if (pbCollection.id) {
2839
+ schema.id = pbCollection.id;
2840
+ }
2721
2841
  if (pbCollection.indexes && Array.isArray(pbCollection.indexes)) {
2722
2842
  schema.indexes = pbCollection.indexes;
2723
2843
  }
2724
- const rules = {};
2725
- if (pbCollection.listRule !== void 0) rules.listRule = pbCollection.listRule;
2726
- if (pbCollection.viewRule !== void 0) rules.viewRule = pbCollection.viewRule;
2727
- if (pbCollection.createRule !== void 0) rules.createRule = pbCollection.createRule;
2728
- if (pbCollection.updateRule !== void 0) rules.updateRule = pbCollection.updateRule;
2729
- if (pbCollection.deleteRule !== void 0) rules.deleteRule = pbCollection.deleteRule;
2730
- if (pbCollection.manageRule !== void 0) rules.manageRule = pbCollection.manageRule;
2731
- if (Object.keys(rules).length > 0) {
2844
+ const hasAnyRule = pbCollection.listRule !== void 0 || pbCollection.viewRule !== void 0 || pbCollection.createRule !== void 0 || pbCollection.updateRule !== void 0 || pbCollection.deleteRule !== void 0 || pbCollection.manageRule !== void 0;
2845
+ if (hasAnyRule) {
2846
+ const rules = {};
2847
+ if (pbCollection.listRule !== void 0) rules.listRule = pbCollection.listRule;
2848
+ if (pbCollection.viewRule !== void 0) rules.viewRule = pbCollection.viewRule;
2849
+ if (pbCollection.createRule !== void 0) rules.createRule = pbCollection.createRule;
2850
+ if (pbCollection.updateRule !== void 0) rules.updateRule = pbCollection.updateRule;
2851
+ if (pbCollection.deleteRule !== void 0) rules.deleteRule = pbCollection.deleteRule;
2852
+ if (pbCollection.manageRule !== void 0) rules.manageRule = pbCollection.manageRule;
2732
2853
  schema.rules = rules;
2733
2854
  schema.permissions = { ...rules };
2734
2855
  }