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.
- package/CHANGELOG.md +8 -0
- package/dist/cli/index.cjs +167 -46
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.d.cts +2 -2
- package/dist/cli/index.d.ts +2 -2
- package/dist/cli/index.js +167 -46
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/migrate.cjs +167 -46
- package/dist/cli/migrate.cjs.map +1 -1
- package/dist/cli/migrate.js +167 -46
- package/dist/cli/migrate.js.map +1 -1
- package/dist/cli/utils/index.d.cts +2 -2
- package/dist/cli/utils/index.d.ts +2 -2
- package/dist/{fields-UcOPu1OQ.d.cts → fields-RVj26U-O.d.cts} +1 -0
- package/dist/{fields-UcOPu1OQ.d.ts → fields-RVj26U-O.d.ts} +1 -0
- package/dist/index.cjs +167 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +167 -46
- package/dist/index.js.map +1 -1
- package/dist/migration/analyzer.cjs.map +1 -1
- package/dist/migration/analyzer.d.cts +2 -2
- package/dist/migration/analyzer.d.ts +2 -2
- package/dist/migration/analyzer.js.map +1 -1
- package/dist/migration/diff.cjs +77 -26
- package/dist/migration/diff.cjs.map +1 -1
- package/dist/migration/diff.d.cts +4 -4
- package/dist/migration/diff.d.ts +4 -4
- package/dist/migration/diff.js +77 -26
- package/dist/migration/diff.js.map +1 -1
- package/dist/migration/generator.cjs +39 -2
- package/dist/migration/generator.cjs.map +1 -1
- package/dist/migration/generator.d.cts +2 -2
- package/dist/migration/generator.d.ts +2 -2
- package/dist/migration/generator.js +39 -2
- package/dist/migration/generator.js.map +1 -1
- package/dist/migration/index.cjs +167 -46
- package/dist/migration/index.cjs.map +1 -1
- package/dist/migration/index.d.cts +3 -3
- package/dist/migration/index.d.ts +3 -3
- package/dist/migration/index.js +167 -46
- package/dist/migration/index.js.map +1 -1
- package/dist/migration/snapshot.cjs +51 -18
- package/dist/migration/snapshot.cjs.map +1 -1
- package/dist/migration/snapshot.d.cts +2 -2
- package/dist/migration/snapshot.d.ts +2 -2
- package/dist/migration/snapshot.js +51 -18
- package/dist/migration/snapshot.js.map +1 -1
- package/dist/migration/utils/index.cjs +5 -3
- package/dist/migration/utils/index.cjs.map +1 -1
- package/dist/migration/utils/index.d.cts +4 -4
- package/dist/migration/utils/index.d.ts +4 -4
- package/dist/migration/utils/index.js +5 -3
- package/dist/migration/utils/index.js.map +1 -1
- package/dist/schema.cjs.map +1 -1
- package/dist/schema.d.cts +1 -1
- package/dist/schema.d.ts +1 -1
- package/dist/schema.js.map +1 -1
- package/dist/{type-mapper-n231Fspm.d.ts → type-mapper-CZzVeDj7.d.ts} +1 -1
- package/dist/{type-mapper-DrQmtznD.d.cts → type-mapper-DaBe-1ph.d.cts} +1 -1
- package/dist/{types-Ds3NQvny.d.ts → types-CUVzgZ9k.d.ts} +1 -1
- package/dist/{types-YoBjsa-A.d.cts → types-D-Fsdn_O.d.cts} +1 -1
- package/package.json +1 -1
package/dist/cli/migrate.js
CHANGED
|
@@ -1496,17 +1496,19 @@ var CollectionIdRegistry = class {
|
|
|
1496
1496
|
}
|
|
1497
1497
|
/**
|
|
1498
1498
|
* Generates a unique collection ID for a given collection name
|
|
1499
|
-
* Special case: Returns constant "_pb_users_auth_" for users collection
|
|
1500
1499
|
* Retries up to 10 times if collision occurs (extremely rare)
|
|
1500
|
+
* Special case: returns "_pb_users_auth_" for users collection
|
|
1501
1501
|
*
|
|
1502
|
-
* @param collectionName - The name of the collection
|
|
1502
|
+
* @param collectionName - The name of the collection (optional)
|
|
1503
1503
|
* @returns A unique collection ID
|
|
1504
1504
|
* @throws Error if unable to generate unique ID after max attempts
|
|
1505
1505
|
*/
|
|
1506
1506
|
generate(collectionName) {
|
|
1507
1507
|
if (collectionName && collectionName.toLowerCase() === "users") {
|
|
1508
1508
|
const usersId = "_pb_users_auth_";
|
|
1509
|
-
this.
|
|
1509
|
+
if (!this.has(usersId)) {
|
|
1510
|
+
this.register(usersId);
|
|
1511
|
+
}
|
|
1510
1512
|
return usersId;
|
|
1511
1513
|
}
|
|
1512
1514
|
const maxAttempts = 10;
|
|
@@ -1679,18 +1681,49 @@ function compareFieldConstraints(currentField, previousField) {
|
|
|
1679
1681
|
}
|
|
1680
1682
|
return changes;
|
|
1681
1683
|
}
|
|
1684
|
+
function normalizeOptionValue(key, value, fieldType) {
|
|
1685
|
+
if (key === "maxSelect" && value === 1 && (fieldType === "select" || fieldType === "file")) {
|
|
1686
|
+
return void 0;
|
|
1687
|
+
}
|
|
1688
|
+
if (key === "maxSize" && value === 0 && fieldType === "file") {
|
|
1689
|
+
return void 0;
|
|
1690
|
+
}
|
|
1691
|
+
if (fieldType === "file") {
|
|
1692
|
+
if (key === "mimeTypes" && Array.isArray(value) && value.length === 0) {
|
|
1693
|
+
return void 0;
|
|
1694
|
+
}
|
|
1695
|
+
if (key === "thumbs" && Array.isArray(value) && value.length === 0) {
|
|
1696
|
+
return void 0;
|
|
1697
|
+
}
|
|
1698
|
+
if (key === "protected" && value === false) {
|
|
1699
|
+
return void 0;
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
if (fieldType === "autodate") {
|
|
1703
|
+
if (key === "onCreate" && value === true) {
|
|
1704
|
+
return void 0;
|
|
1705
|
+
}
|
|
1706
|
+
if (key === "onUpdate" && value === false) {
|
|
1707
|
+
return void 0;
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
return value;
|
|
1711
|
+
}
|
|
1682
1712
|
function compareFieldOptions(currentField, previousField) {
|
|
1683
1713
|
const changes = [];
|
|
1684
1714
|
const currentOptions = currentField.options || {};
|
|
1685
1715
|
const previousOptions = previousField.options || {};
|
|
1686
1716
|
const allKeys = /* @__PURE__ */ new Set([...Object.keys(currentOptions), ...Object.keys(previousOptions)]);
|
|
1717
|
+
const fieldType = currentField.type;
|
|
1687
1718
|
for (const key of allKeys) {
|
|
1688
1719
|
const currentValue = currentOptions[key];
|
|
1689
1720
|
const previousValue = previousOptions[key];
|
|
1690
|
-
|
|
1721
|
+
const normalizedCurrent = normalizeOptionValue(key, currentValue, fieldType);
|
|
1722
|
+
const normalizedPrevious = normalizeOptionValue(key, previousValue, fieldType);
|
|
1723
|
+
if (normalizedCurrent === void 0 && normalizedPrevious === void 0) {
|
|
1691
1724
|
continue;
|
|
1692
1725
|
}
|
|
1693
|
-
if (!areValuesEqual(
|
|
1726
|
+
if (!areValuesEqual(normalizedCurrent, normalizedPrevious)) {
|
|
1694
1727
|
changes.push({
|
|
1695
1728
|
property: `options.${key}`,
|
|
1696
1729
|
oldValue: previousValue,
|
|
@@ -1700,7 +1733,7 @@ function compareFieldOptions(currentField, previousField) {
|
|
|
1700
1733
|
}
|
|
1701
1734
|
return changes;
|
|
1702
1735
|
}
|
|
1703
|
-
function compareRelationConfigurations(currentField, previousField) {
|
|
1736
|
+
function compareRelationConfigurations(currentField, previousField, collectionIdToName) {
|
|
1704
1737
|
const changes = [];
|
|
1705
1738
|
const currentRelation = currentField.relation;
|
|
1706
1739
|
const previousRelation = previousField.relation;
|
|
@@ -1712,8 +1745,8 @@ function compareRelationConfigurations(currentField, previousField) {
|
|
|
1712
1745
|
}
|
|
1713
1746
|
const normalizeCollection = (collection) => {
|
|
1714
1747
|
if (!collection) return collection;
|
|
1715
|
-
if (
|
|
1716
|
-
return
|
|
1748
|
+
if (collectionIdToName && collectionIdToName.has(collection)) {
|
|
1749
|
+
return collectionIdToName.get(collection);
|
|
1717
1750
|
}
|
|
1718
1751
|
const nameMatch = collection.match(/app\.findCollectionByNameOrId\s*\(\s*["']([^"']+)["']\s*\)/);
|
|
1719
1752
|
if (nameMatch) {
|
|
@@ -1723,13 +1756,11 @@ function compareRelationConfigurations(currentField, previousField) {
|
|
|
1723
1756
|
};
|
|
1724
1757
|
const normalizedCurrent = normalizeCollection(currentRelation.collection);
|
|
1725
1758
|
const normalizedPrevious = normalizeCollection(previousRelation.collection);
|
|
1726
|
-
if (normalizedCurrent !== normalizedPrevious) {
|
|
1759
|
+
if (normalizedCurrent.toLowerCase() !== normalizedPrevious.toLowerCase()) {
|
|
1727
1760
|
changes.push({
|
|
1728
1761
|
property: "relation.collection",
|
|
1729
|
-
oldValue:
|
|
1730
|
-
|
|
1731
|
-
newValue: normalizedCurrent
|
|
1732
|
-
// Use normalized value for clarity
|
|
1762
|
+
oldValue: previousRelation.collection,
|
|
1763
|
+
newValue: currentRelation.collection
|
|
1733
1764
|
});
|
|
1734
1765
|
}
|
|
1735
1766
|
if (currentRelation.cascadeDelete !== previousRelation.cascadeDelete) {
|
|
@@ -1739,14 +1770,20 @@ function compareRelationConfigurations(currentField, previousField) {
|
|
|
1739
1770
|
newValue: currentRelation.cascadeDelete
|
|
1740
1771
|
});
|
|
1741
1772
|
}
|
|
1742
|
-
|
|
1773
|
+
const normalizeMax = (val) => val === 1 ? null : val;
|
|
1774
|
+
const currentMax = normalizeMax(currentRelation.maxSelect);
|
|
1775
|
+
const previousMax = normalizeMax(previousRelation.maxSelect);
|
|
1776
|
+
if (currentMax != previousMax) {
|
|
1743
1777
|
changes.push({
|
|
1744
1778
|
property: "relation.maxSelect",
|
|
1745
1779
|
oldValue: previousRelation.maxSelect,
|
|
1746
1780
|
newValue: currentRelation.maxSelect
|
|
1747
1781
|
});
|
|
1748
1782
|
}
|
|
1749
|
-
|
|
1783
|
+
const normalizeMin = (val) => val === 0 ? null : val;
|
|
1784
|
+
const currentMin = normalizeMin(currentRelation.minSelect);
|
|
1785
|
+
const previousMin = normalizeMin(previousRelation.minSelect);
|
|
1786
|
+
if (currentMin != previousMin) {
|
|
1750
1787
|
changes.push({
|
|
1751
1788
|
property: "relation.minSelect",
|
|
1752
1789
|
oldValue: previousRelation.minSelect,
|
|
@@ -1755,7 +1792,7 @@ function compareRelationConfigurations(currentField, previousField) {
|
|
|
1755
1792
|
}
|
|
1756
1793
|
return changes;
|
|
1757
1794
|
}
|
|
1758
|
-
function detectFieldChanges(currentField, previousField) {
|
|
1795
|
+
function detectFieldChanges(currentField, previousField, collectionIdToName) {
|
|
1759
1796
|
const changes = [];
|
|
1760
1797
|
const typeChange = compareFieldTypes(currentField, previousField);
|
|
1761
1798
|
if (typeChange) {
|
|
@@ -1764,7 +1801,7 @@ function detectFieldChanges(currentField, previousField) {
|
|
|
1764
1801
|
changes.push(...compareFieldConstraints(currentField, previousField));
|
|
1765
1802
|
changes.push(...compareFieldOptions(currentField, previousField));
|
|
1766
1803
|
if (currentField.type === "relation" && previousField.type === "relation") {
|
|
1767
|
-
changes.push(...compareRelationConfigurations(currentField, previousField));
|
|
1804
|
+
changes.push(...compareRelationConfigurations(currentField, previousField, collectionIdToName));
|
|
1768
1805
|
}
|
|
1769
1806
|
return changes;
|
|
1770
1807
|
}
|
|
@@ -1775,7 +1812,7 @@ function compareIndexes(currentIndexes = [], previousIndexes = []) {
|
|
|
1775
1812
|
const indexesToRemove = previousIndexes.filter((idx) => !currentSet.has(idx));
|
|
1776
1813
|
return { indexesToAdd, indexesToRemove };
|
|
1777
1814
|
}
|
|
1778
|
-
function compareRules(currentRules, previousRules) {
|
|
1815
|
+
function compareRules(currentRules, previousRules, currentPermissions, previousPermissions) {
|
|
1779
1816
|
const updates = [];
|
|
1780
1817
|
const ruleTypes = [
|
|
1781
1818
|
"listRule",
|
|
@@ -1786,8 +1823,8 @@ function compareRules(currentRules, previousRules) {
|
|
|
1786
1823
|
"manageRule"
|
|
1787
1824
|
];
|
|
1788
1825
|
for (const ruleType of ruleTypes) {
|
|
1789
|
-
const currentValue = currentRules?.[ruleType] ?? null;
|
|
1790
|
-
const previousValue = previousRules?.[ruleType] ?? null;
|
|
1826
|
+
const currentValue = currentRules?.[ruleType] ?? currentPermissions?.[ruleType] ?? null;
|
|
1827
|
+
const previousValue = previousRules?.[ruleType] ?? previousPermissions?.[ruleType] ?? null;
|
|
1791
1828
|
if (currentValue !== previousValue) {
|
|
1792
1829
|
updates.push({
|
|
1793
1830
|
ruleType,
|
|
@@ -1814,7 +1851,7 @@ function comparePermissions(currentPermissions, previousPermissions) {
|
|
|
1814
1851
|
}
|
|
1815
1852
|
return changes;
|
|
1816
1853
|
}
|
|
1817
|
-
function compareCollectionFields(currentCollection, previousCollection, config) {
|
|
1854
|
+
function compareCollectionFields(currentCollection, previousCollection, config, collectionIdToName) {
|
|
1818
1855
|
let fieldsToAdd = findNewFields(currentCollection.fields, previousCollection.fields);
|
|
1819
1856
|
const fieldsToRemove = findRemovedFields(currentCollection.fields, previousCollection.fields);
|
|
1820
1857
|
const fieldsToModify = [];
|
|
@@ -1824,7 +1861,7 @@ function compareCollectionFields(currentCollection, previousCollection, config)
|
|
|
1824
1861
|
}
|
|
1825
1862
|
const matchedFields = matchFieldsByName(currentCollection.fields, previousCollection.fields);
|
|
1826
1863
|
for (const [currentField, previousField] of matchedFields) {
|
|
1827
|
-
const changes = detectFieldChanges(currentField, previousField);
|
|
1864
|
+
const changes = detectFieldChanges(currentField, previousField, collectionIdToName);
|
|
1828
1865
|
if (changes.length > 0) {
|
|
1829
1866
|
fieldsToModify.push({
|
|
1830
1867
|
fieldName: currentField.name,
|
|
@@ -1836,14 +1873,20 @@ function compareCollectionFields(currentCollection, previousCollection, config)
|
|
|
1836
1873
|
}
|
|
1837
1874
|
return { fieldsToAdd, fieldsToRemove, fieldsToModify };
|
|
1838
1875
|
}
|
|
1839
|
-
function buildCollectionModification(currentCollection, previousCollection, config) {
|
|
1876
|
+
function buildCollectionModification(currentCollection, previousCollection, config, collectionIdToName) {
|
|
1840
1877
|
const { fieldsToAdd, fieldsToRemove, fieldsToModify } = compareCollectionFields(
|
|
1841
1878
|
currentCollection,
|
|
1842
1879
|
previousCollection,
|
|
1843
|
-
config
|
|
1880
|
+
config,
|
|
1881
|
+
collectionIdToName
|
|
1844
1882
|
);
|
|
1845
1883
|
const { indexesToAdd, indexesToRemove } = compareIndexes(currentCollection.indexes, previousCollection.indexes);
|
|
1846
|
-
const rulesToUpdate = compareRules(
|
|
1884
|
+
const rulesToUpdate = compareRules(
|
|
1885
|
+
currentCollection.rules,
|
|
1886
|
+
previousCollection.rules,
|
|
1887
|
+
currentCollection.permissions,
|
|
1888
|
+
previousCollection.permissions
|
|
1889
|
+
);
|
|
1847
1890
|
const permissionsToUpdate = comparePermissions(currentCollection.permissions, previousCollection.permissions);
|
|
1848
1891
|
return {
|
|
1849
1892
|
collection: currentCollection.name,
|
|
@@ -1860,6 +1903,14 @@ function hasChanges(modification) {
|
|
|
1860
1903
|
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;
|
|
1861
1904
|
}
|
|
1862
1905
|
function aggregateChanges(currentSchema, previousSnapshot, config) {
|
|
1906
|
+
const collectionIdToName = /* @__PURE__ */ new Map();
|
|
1907
|
+
if (previousSnapshot) {
|
|
1908
|
+
for (const [name, collection] of previousSnapshot.collections) {
|
|
1909
|
+
if (collection.id) {
|
|
1910
|
+
collectionIdToName.set(collection.id, name);
|
|
1911
|
+
}
|
|
1912
|
+
}
|
|
1913
|
+
}
|
|
1863
1914
|
const collectionsToCreate = findNewCollections(currentSchema, previousSnapshot);
|
|
1864
1915
|
const collectionsToDelete = findRemovedCollections(currentSchema, previousSnapshot);
|
|
1865
1916
|
const filteredCollectionsToCreate = collectionsToCreate.filter(
|
|
@@ -1883,7 +1934,7 @@ function aggregateChanges(currentSchema, previousSnapshot, config) {
|
|
|
1883
1934
|
const collectionsToModify = [];
|
|
1884
1935
|
const matchedCollections = matchCollectionsByName(currentSchema, previousSnapshot);
|
|
1885
1936
|
for (const [currentCollection, previousCollection] of matchedCollections) {
|
|
1886
|
-
const modification = buildCollectionModification(currentCollection, previousCollection, config);
|
|
1937
|
+
const modification = buildCollectionModification(currentCollection, previousCollection, config, collectionIdToName);
|
|
1887
1938
|
if (hasChanges(modification)) {
|
|
1888
1939
|
collectionsToModify.push(modification);
|
|
1889
1940
|
}
|
|
@@ -2263,6 +2314,9 @@ function getSystemFields() {
|
|
|
2263
2314
|
function generateCollectionCreation(collection, varName = "collection", isLast = false, collectionIdMap) {
|
|
2264
2315
|
const lines = [];
|
|
2265
2316
|
lines.push(` const ${varName} = new Collection({`);
|
|
2317
|
+
if (collection.id) {
|
|
2318
|
+
lines.push(` id: ${formatValue(collection.id)},`);
|
|
2319
|
+
}
|
|
2266
2320
|
lines.push(` name: "${collection.name}",`);
|
|
2267
2321
|
lines.push(` type: "${collection.type}",`);
|
|
2268
2322
|
const permissionsCode = generateCollectionPermissions(collection.permissions);
|
|
@@ -2506,7 +2560,24 @@ function generateOperationUpMigration(operation, collectionIdMap) {
|
|
|
2506
2560
|
const varName = `collection_${collectionName}`;
|
|
2507
2561
|
lines.push(generateCollectionDeletion(collectionName, varName, true));
|
|
2508
2562
|
}
|
|
2509
|
-
|
|
2563
|
+
let code = lines.join("\n");
|
|
2564
|
+
const savePattern = /^(\s*)app\.save\((\w+)\);$/gm;
|
|
2565
|
+
const deletePattern = /^(\s*)app\.delete\((\w+)\);$/gm;
|
|
2566
|
+
const saveMatches = [...code.matchAll(savePattern)];
|
|
2567
|
+
const deleteMatches = [...code.matchAll(deletePattern)];
|
|
2568
|
+
const allMatches = [
|
|
2569
|
+
...saveMatches.map((m) => ({ match: m, type: "save", index: m.index })),
|
|
2570
|
+
...deleteMatches.map((m) => ({ match: m, type: "delete", index: m.index }))
|
|
2571
|
+
].sort((a, b) => b.index - a.index);
|
|
2572
|
+
if (allMatches.length > 0) {
|
|
2573
|
+
const lastMatch = allMatches[0];
|
|
2574
|
+
if (lastMatch.type === "save") {
|
|
2575
|
+
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);
|
|
2576
|
+
} else {
|
|
2577
|
+
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);
|
|
2578
|
+
}
|
|
2579
|
+
}
|
|
2580
|
+
return code;
|
|
2510
2581
|
}
|
|
2511
2582
|
function generateOperationDownMigration(operation, collectionIdMap) {
|
|
2512
2583
|
const lines = [];
|
|
@@ -2591,7 +2662,24 @@ function generateOperationDownMigration(operation, collectionIdMap) {
|
|
|
2591
2662
|
lines.push(generateCollectionCreation(collection, varName, true, collectionIdMap));
|
|
2592
2663
|
}
|
|
2593
2664
|
}
|
|
2594
|
-
|
|
2665
|
+
let code = lines.join("\n");
|
|
2666
|
+
const savePattern = /^(\s*)app\.save\((\w+)\);$/gm;
|
|
2667
|
+
const deletePattern = /^(\s*)app\.delete\((\w+)\);$/gm;
|
|
2668
|
+
const saveMatches = [...code.matchAll(savePattern)];
|
|
2669
|
+
const deleteMatches = [...code.matchAll(deletePattern)];
|
|
2670
|
+
const allMatches = [
|
|
2671
|
+
...saveMatches.map((m) => ({ match: m, type: "save", index: m.index })),
|
|
2672
|
+
...deleteMatches.map((m) => ({ match: m, type: "delete", index: m.index }))
|
|
2673
|
+
].sort((a, b) => b.index - a.index);
|
|
2674
|
+
if (allMatches.length > 0) {
|
|
2675
|
+
const lastMatch = allMatches[0];
|
|
2676
|
+
if (lastMatch.type === "save") {
|
|
2677
|
+
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);
|
|
2678
|
+
} else {
|
|
2679
|
+
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);
|
|
2680
|
+
}
|
|
2681
|
+
}
|
|
2682
|
+
return code;
|
|
2595
2683
|
}
|
|
2596
2684
|
function generate(diff, config) {
|
|
2597
2685
|
const normalizedConfig = typeof config === "string" ? { migrationDir: config } : config;
|
|
@@ -2640,7 +2728,7 @@ function generate(diff, config) {
|
|
|
2640
2728
|
var SNAPSHOT_VERSION = "1.0.0";
|
|
2641
2729
|
function resolveCollectionIdToName(collectionId) {
|
|
2642
2730
|
if (collectionId === "_pb_users_auth_") {
|
|
2643
|
-
return "
|
|
2731
|
+
return "users";
|
|
2644
2732
|
}
|
|
2645
2733
|
const nameMatch = collectionId.match(/app\.findCollectionByNameOrId\s*\(\s*["']([^"']+)["']\s*\)/);
|
|
2646
2734
|
if (nameMatch) {
|
|
@@ -2648,6 +2736,39 @@ function resolveCollectionIdToName(collectionId) {
|
|
|
2648
2736
|
}
|
|
2649
2737
|
return collectionId;
|
|
2650
2738
|
}
|
|
2739
|
+
function extractFieldOptions2(pbField) {
|
|
2740
|
+
const options = {};
|
|
2741
|
+
if (pbField.options && typeof pbField.options === "object") {
|
|
2742
|
+
Object.assign(options, pbField.options);
|
|
2743
|
+
}
|
|
2744
|
+
const directOptionKeys = [
|
|
2745
|
+
"min",
|
|
2746
|
+
"max",
|
|
2747
|
+
"pattern",
|
|
2748
|
+
"noDecimal",
|
|
2749
|
+
// text/number fields
|
|
2750
|
+
"values",
|
|
2751
|
+
"maxSelect",
|
|
2752
|
+
// select fields
|
|
2753
|
+
"mimeTypes",
|
|
2754
|
+
"maxSize",
|
|
2755
|
+
"thumbs",
|
|
2756
|
+
"protected",
|
|
2757
|
+
// file fields
|
|
2758
|
+
"onCreate",
|
|
2759
|
+
"onUpdate",
|
|
2760
|
+
// autodate fields
|
|
2761
|
+
"exceptDomains",
|
|
2762
|
+
"onlyDomains"
|
|
2763
|
+
// email/url fields
|
|
2764
|
+
];
|
|
2765
|
+
for (const key of directOptionKeys) {
|
|
2766
|
+
if (pbField[key] !== void 0) {
|
|
2767
|
+
options[key] = pbField[key];
|
|
2768
|
+
}
|
|
2769
|
+
}
|
|
2770
|
+
return options;
|
|
2771
|
+
}
|
|
2651
2772
|
function convertPocketBaseCollection(pbCollection) {
|
|
2652
2773
|
const fields = [];
|
|
2653
2774
|
const systemFieldNames = ["id", "created", "updated", "collectionId", "collectionName", "expand"];
|
|
@@ -2665,23 +2786,19 @@ function convertPocketBaseCollection(pbCollection) {
|
|
|
2665
2786
|
type: pbField.type,
|
|
2666
2787
|
required: pbField.required || false
|
|
2667
2788
|
};
|
|
2668
|
-
field.options = pbField
|
|
2669
|
-
if (pbField.type === "select") {
|
|
2670
|
-
if (pbField.values && Array.isArray(pbField.values)) {
|
|
2671
|
-
field.options.values = pbField.values;
|
|
2672
|
-
} else if (pbField.options?.values && Array.isArray(pbField.options.values)) {
|
|
2673
|
-
field.options.values = pbField.options.values;
|
|
2674
|
-
}
|
|
2675
|
-
}
|
|
2789
|
+
field.options = extractFieldOptions2(pbField);
|
|
2676
2790
|
if (pbField.type === "relation") {
|
|
2677
2791
|
const collectionId = pbField.collectionId || pbField.options?.collectionId || "";
|
|
2678
|
-
const collectionName = resolveCollectionIdToName(collectionId);
|
|
2792
|
+
const collectionName = resolveCollectionIdToName(collectionId || "");
|
|
2679
2793
|
field.relation = {
|
|
2680
2794
|
collection: collectionName,
|
|
2681
2795
|
cascadeDelete: pbField.cascadeDelete ?? pbField.options?.cascadeDelete ?? false,
|
|
2682
2796
|
maxSelect: pbField.maxSelect ?? pbField.options?.maxSelect,
|
|
2683
2797
|
minSelect: pbField.minSelect ?? pbField.options?.minSelect
|
|
2684
2798
|
};
|
|
2799
|
+
delete field.options.maxSelect;
|
|
2800
|
+
delete field.options.minSelect;
|
|
2801
|
+
delete field.options.cascadeDelete;
|
|
2685
2802
|
}
|
|
2686
2803
|
const hasOnlyValues = Object.keys(field.options).length === 1 && field.options.values !== void 0;
|
|
2687
2804
|
if (Object.keys(field.options).length === 0) {
|
|
@@ -2695,17 +2812,21 @@ function convertPocketBaseCollection(pbCollection) {
|
|
|
2695
2812
|
type: pbCollection.type || "base",
|
|
2696
2813
|
fields
|
|
2697
2814
|
};
|
|
2815
|
+
if (pbCollection.id) {
|
|
2816
|
+
schema.id = pbCollection.id;
|
|
2817
|
+
}
|
|
2698
2818
|
if (pbCollection.indexes && Array.isArray(pbCollection.indexes)) {
|
|
2699
2819
|
schema.indexes = pbCollection.indexes;
|
|
2700
2820
|
}
|
|
2701
|
-
const
|
|
2702
|
-
if (
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2821
|
+
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;
|
|
2822
|
+
if (hasAnyRule) {
|
|
2823
|
+
const rules = {};
|
|
2824
|
+
if (pbCollection.listRule !== void 0) rules.listRule = pbCollection.listRule;
|
|
2825
|
+
if (pbCollection.viewRule !== void 0) rules.viewRule = pbCollection.viewRule;
|
|
2826
|
+
if (pbCollection.createRule !== void 0) rules.createRule = pbCollection.createRule;
|
|
2827
|
+
if (pbCollection.updateRule !== void 0) rules.updateRule = pbCollection.updateRule;
|
|
2828
|
+
if (pbCollection.deleteRule !== void 0) rules.deleteRule = pbCollection.deleteRule;
|
|
2829
|
+
if (pbCollection.manageRule !== void 0) rules.manageRule = pbCollection.manageRule;
|
|
2709
2830
|
schema.rules = rules;
|
|
2710
2831
|
schema.permissions = { ...rules };
|
|
2711
2832
|
}
|