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.cjs
CHANGED
|
@@ -1524,17 +1524,19 @@ var CollectionIdRegistry = class {
|
|
|
1524
1524
|
}
|
|
1525
1525
|
/**
|
|
1526
1526
|
* Generates a unique collection ID for a given collection name
|
|
1527
|
-
* Special case: Returns constant "_pb_users_auth_" for users collection
|
|
1528
1527
|
* Retries up to 10 times if collision occurs (extremely rare)
|
|
1528
|
+
* Special case: returns "_pb_users_auth_" for users collection
|
|
1529
1529
|
*
|
|
1530
|
-
* @param collectionName - The name of the collection
|
|
1530
|
+
* @param collectionName - The name of the collection (optional)
|
|
1531
1531
|
* @returns A unique collection ID
|
|
1532
1532
|
* @throws Error if unable to generate unique ID after max attempts
|
|
1533
1533
|
*/
|
|
1534
1534
|
generate(collectionName) {
|
|
1535
1535
|
if (collectionName && collectionName.toLowerCase() === "users") {
|
|
1536
1536
|
const usersId = "_pb_users_auth_";
|
|
1537
|
-
this.
|
|
1537
|
+
if (!this.has(usersId)) {
|
|
1538
|
+
this.register(usersId);
|
|
1539
|
+
}
|
|
1538
1540
|
return usersId;
|
|
1539
1541
|
}
|
|
1540
1542
|
const maxAttempts = 10;
|
|
@@ -1707,18 +1709,49 @@ function compareFieldConstraints(currentField, previousField) {
|
|
|
1707
1709
|
}
|
|
1708
1710
|
return changes;
|
|
1709
1711
|
}
|
|
1712
|
+
function normalizeOptionValue(key, value, fieldType) {
|
|
1713
|
+
if (key === "maxSelect" && value === 1 && (fieldType === "select" || fieldType === "file")) {
|
|
1714
|
+
return void 0;
|
|
1715
|
+
}
|
|
1716
|
+
if (key === "maxSize" && value === 0 && fieldType === "file") {
|
|
1717
|
+
return void 0;
|
|
1718
|
+
}
|
|
1719
|
+
if (fieldType === "file") {
|
|
1720
|
+
if (key === "mimeTypes" && Array.isArray(value) && value.length === 0) {
|
|
1721
|
+
return void 0;
|
|
1722
|
+
}
|
|
1723
|
+
if (key === "thumbs" && Array.isArray(value) && value.length === 0) {
|
|
1724
|
+
return void 0;
|
|
1725
|
+
}
|
|
1726
|
+
if (key === "protected" && value === false) {
|
|
1727
|
+
return void 0;
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
if (fieldType === "autodate") {
|
|
1731
|
+
if (key === "onCreate" && value === true) {
|
|
1732
|
+
return void 0;
|
|
1733
|
+
}
|
|
1734
|
+
if (key === "onUpdate" && value === false) {
|
|
1735
|
+
return void 0;
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
return value;
|
|
1739
|
+
}
|
|
1710
1740
|
function compareFieldOptions(currentField, previousField) {
|
|
1711
1741
|
const changes = [];
|
|
1712
1742
|
const currentOptions = currentField.options || {};
|
|
1713
1743
|
const previousOptions = previousField.options || {};
|
|
1714
1744
|
const allKeys = /* @__PURE__ */ new Set([...Object.keys(currentOptions), ...Object.keys(previousOptions)]);
|
|
1745
|
+
const fieldType = currentField.type;
|
|
1715
1746
|
for (const key of allKeys) {
|
|
1716
1747
|
const currentValue = currentOptions[key];
|
|
1717
1748
|
const previousValue = previousOptions[key];
|
|
1718
|
-
|
|
1749
|
+
const normalizedCurrent = normalizeOptionValue(key, currentValue, fieldType);
|
|
1750
|
+
const normalizedPrevious = normalizeOptionValue(key, previousValue, fieldType);
|
|
1751
|
+
if (normalizedCurrent === void 0 && normalizedPrevious === void 0) {
|
|
1719
1752
|
continue;
|
|
1720
1753
|
}
|
|
1721
|
-
if (!areValuesEqual(
|
|
1754
|
+
if (!areValuesEqual(normalizedCurrent, normalizedPrevious)) {
|
|
1722
1755
|
changes.push({
|
|
1723
1756
|
property: `options.${key}`,
|
|
1724
1757
|
oldValue: previousValue,
|
|
@@ -1728,7 +1761,7 @@ function compareFieldOptions(currentField, previousField) {
|
|
|
1728
1761
|
}
|
|
1729
1762
|
return changes;
|
|
1730
1763
|
}
|
|
1731
|
-
function compareRelationConfigurations(currentField, previousField) {
|
|
1764
|
+
function compareRelationConfigurations(currentField, previousField, collectionIdToName) {
|
|
1732
1765
|
const changes = [];
|
|
1733
1766
|
const currentRelation = currentField.relation;
|
|
1734
1767
|
const previousRelation = previousField.relation;
|
|
@@ -1740,8 +1773,8 @@ function compareRelationConfigurations(currentField, previousField) {
|
|
|
1740
1773
|
}
|
|
1741
1774
|
const normalizeCollection = (collection) => {
|
|
1742
1775
|
if (!collection) return collection;
|
|
1743
|
-
if (
|
|
1744
|
-
return
|
|
1776
|
+
if (collectionIdToName && collectionIdToName.has(collection)) {
|
|
1777
|
+
return collectionIdToName.get(collection);
|
|
1745
1778
|
}
|
|
1746
1779
|
const nameMatch = collection.match(/app\.findCollectionByNameOrId\s*\(\s*["']([^"']+)["']\s*\)/);
|
|
1747
1780
|
if (nameMatch) {
|
|
@@ -1751,13 +1784,11 @@ function compareRelationConfigurations(currentField, previousField) {
|
|
|
1751
1784
|
};
|
|
1752
1785
|
const normalizedCurrent = normalizeCollection(currentRelation.collection);
|
|
1753
1786
|
const normalizedPrevious = normalizeCollection(previousRelation.collection);
|
|
1754
|
-
if (normalizedCurrent !== normalizedPrevious) {
|
|
1787
|
+
if (normalizedCurrent.toLowerCase() !== normalizedPrevious.toLowerCase()) {
|
|
1755
1788
|
changes.push({
|
|
1756
1789
|
property: "relation.collection",
|
|
1757
|
-
oldValue:
|
|
1758
|
-
|
|
1759
|
-
newValue: normalizedCurrent
|
|
1760
|
-
// Use normalized value for clarity
|
|
1790
|
+
oldValue: previousRelation.collection,
|
|
1791
|
+
newValue: currentRelation.collection
|
|
1761
1792
|
});
|
|
1762
1793
|
}
|
|
1763
1794
|
if (currentRelation.cascadeDelete !== previousRelation.cascadeDelete) {
|
|
@@ -1767,14 +1798,20 @@ function compareRelationConfigurations(currentField, previousField) {
|
|
|
1767
1798
|
newValue: currentRelation.cascadeDelete
|
|
1768
1799
|
});
|
|
1769
1800
|
}
|
|
1770
|
-
|
|
1801
|
+
const normalizeMax = (val) => val === 1 ? null : val;
|
|
1802
|
+
const currentMax = normalizeMax(currentRelation.maxSelect);
|
|
1803
|
+
const previousMax = normalizeMax(previousRelation.maxSelect);
|
|
1804
|
+
if (currentMax != previousMax) {
|
|
1771
1805
|
changes.push({
|
|
1772
1806
|
property: "relation.maxSelect",
|
|
1773
1807
|
oldValue: previousRelation.maxSelect,
|
|
1774
1808
|
newValue: currentRelation.maxSelect
|
|
1775
1809
|
});
|
|
1776
1810
|
}
|
|
1777
|
-
|
|
1811
|
+
const normalizeMin = (val) => val === 0 ? null : val;
|
|
1812
|
+
const currentMin = normalizeMin(currentRelation.minSelect);
|
|
1813
|
+
const previousMin = normalizeMin(previousRelation.minSelect);
|
|
1814
|
+
if (currentMin != previousMin) {
|
|
1778
1815
|
changes.push({
|
|
1779
1816
|
property: "relation.minSelect",
|
|
1780
1817
|
oldValue: previousRelation.minSelect,
|
|
@@ -1783,7 +1820,7 @@ function compareRelationConfigurations(currentField, previousField) {
|
|
|
1783
1820
|
}
|
|
1784
1821
|
return changes;
|
|
1785
1822
|
}
|
|
1786
|
-
function detectFieldChanges(currentField, previousField) {
|
|
1823
|
+
function detectFieldChanges(currentField, previousField, collectionIdToName) {
|
|
1787
1824
|
const changes = [];
|
|
1788
1825
|
const typeChange = compareFieldTypes(currentField, previousField);
|
|
1789
1826
|
if (typeChange) {
|
|
@@ -1792,7 +1829,7 @@ function detectFieldChanges(currentField, previousField) {
|
|
|
1792
1829
|
changes.push(...compareFieldConstraints(currentField, previousField));
|
|
1793
1830
|
changes.push(...compareFieldOptions(currentField, previousField));
|
|
1794
1831
|
if (currentField.type === "relation" && previousField.type === "relation") {
|
|
1795
|
-
changes.push(...compareRelationConfigurations(currentField, previousField));
|
|
1832
|
+
changes.push(...compareRelationConfigurations(currentField, previousField, collectionIdToName));
|
|
1796
1833
|
}
|
|
1797
1834
|
return changes;
|
|
1798
1835
|
}
|
|
@@ -1803,7 +1840,7 @@ function compareIndexes(currentIndexes = [], previousIndexes = []) {
|
|
|
1803
1840
|
const indexesToRemove = previousIndexes.filter((idx) => !currentSet.has(idx));
|
|
1804
1841
|
return { indexesToAdd, indexesToRemove };
|
|
1805
1842
|
}
|
|
1806
|
-
function compareRules(currentRules, previousRules) {
|
|
1843
|
+
function compareRules(currentRules, previousRules, currentPermissions, previousPermissions) {
|
|
1807
1844
|
const updates = [];
|
|
1808
1845
|
const ruleTypes = [
|
|
1809
1846
|
"listRule",
|
|
@@ -1814,8 +1851,8 @@ function compareRules(currentRules, previousRules) {
|
|
|
1814
1851
|
"manageRule"
|
|
1815
1852
|
];
|
|
1816
1853
|
for (const ruleType of ruleTypes) {
|
|
1817
|
-
const currentValue = currentRules?.[ruleType] ?? null;
|
|
1818
|
-
const previousValue = previousRules?.[ruleType] ?? null;
|
|
1854
|
+
const currentValue = currentRules?.[ruleType] ?? currentPermissions?.[ruleType] ?? null;
|
|
1855
|
+
const previousValue = previousRules?.[ruleType] ?? previousPermissions?.[ruleType] ?? null;
|
|
1819
1856
|
if (currentValue !== previousValue) {
|
|
1820
1857
|
updates.push({
|
|
1821
1858
|
ruleType,
|
|
@@ -1842,7 +1879,7 @@ function comparePermissions(currentPermissions, previousPermissions) {
|
|
|
1842
1879
|
}
|
|
1843
1880
|
return changes;
|
|
1844
1881
|
}
|
|
1845
|
-
function compareCollectionFields(currentCollection, previousCollection, config) {
|
|
1882
|
+
function compareCollectionFields(currentCollection, previousCollection, config, collectionIdToName) {
|
|
1846
1883
|
let fieldsToAdd = findNewFields(currentCollection.fields, previousCollection.fields);
|
|
1847
1884
|
const fieldsToRemove = findRemovedFields(currentCollection.fields, previousCollection.fields);
|
|
1848
1885
|
const fieldsToModify = [];
|
|
@@ -1852,7 +1889,7 @@ function compareCollectionFields(currentCollection, previousCollection, config)
|
|
|
1852
1889
|
}
|
|
1853
1890
|
const matchedFields = matchFieldsByName(currentCollection.fields, previousCollection.fields);
|
|
1854
1891
|
for (const [currentField, previousField] of matchedFields) {
|
|
1855
|
-
const changes = detectFieldChanges(currentField, previousField);
|
|
1892
|
+
const changes = detectFieldChanges(currentField, previousField, collectionIdToName);
|
|
1856
1893
|
if (changes.length > 0) {
|
|
1857
1894
|
fieldsToModify.push({
|
|
1858
1895
|
fieldName: currentField.name,
|
|
@@ -1864,14 +1901,20 @@ function compareCollectionFields(currentCollection, previousCollection, config)
|
|
|
1864
1901
|
}
|
|
1865
1902
|
return { fieldsToAdd, fieldsToRemove, fieldsToModify };
|
|
1866
1903
|
}
|
|
1867
|
-
function buildCollectionModification(currentCollection, previousCollection, config) {
|
|
1904
|
+
function buildCollectionModification(currentCollection, previousCollection, config, collectionIdToName) {
|
|
1868
1905
|
const { fieldsToAdd, fieldsToRemove, fieldsToModify } = compareCollectionFields(
|
|
1869
1906
|
currentCollection,
|
|
1870
1907
|
previousCollection,
|
|
1871
|
-
config
|
|
1908
|
+
config,
|
|
1909
|
+
collectionIdToName
|
|
1872
1910
|
);
|
|
1873
1911
|
const { indexesToAdd, indexesToRemove } = compareIndexes(currentCollection.indexes, previousCollection.indexes);
|
|
1874
|
-
const rulesToUpdate = compareRules(
|
|
1912
|
+
const rulesToUpdate = compareRules(
|
|
1913
|
+
currentCollection.rules,
|
|
1914
|
+
previousCollection.rules,
|
|
1915
|
+
currentCollection.permissions,
|
|
1916
|
+
previousCollection.permissions
|
|
1917
|
+
);
|
|
1875
1918
|
const permissionsToUpdate = comparePermissions(currentCollection.permissions, previousCollection.permissions);
|
|
1876
1919
|
return {
|
|
1877
1920
|
collection: currentCollection.name,
|
|
@@ -1888,6 +1931,14 @@ function hasChanges(modification) {
|
|
|
1888
1931
|
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;
|
|
1889
1932
|
}
|
|
1890
1933
|
function aggregateChanges(currentSchema, previousSnapshot, config) {
|
|
1934
|
+
const collectionIdToName = /* @__PURE__ */ new Map();
|
|
1935
|
+
if (previousSnapshot) {
|
|
1936
|
+
for (const [name, collection] of previousSnapshot.collections) {
|
|
1937
|
+
if (collection.id) {
|
|
1938
|
+
collectionIdToName.set(collection.id, name);
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1891
1942
|
const collectionsToCreate = findNewCollections(currentSchema, previousSnapshot);
|
|
1892
1943
|
const collectionsToDelete = findRemovedCollections(currentSchema, previousSnapshot);
|
|
1893
1944
|
const filteredCollectionsToCreate = collectionsToCreate.filter(
|
|
@@ -1911,7 +1962,7 @@ function aggregateChanges(currentSchema, previousSnapshot, config) {
|
|
|
1911
1962
|
const collectionsToModify = [];
|
|
1912
1963
|
const matchedCollections = matchCollectionsByName(currentSchema, previousSnapshot);
|
|
1913
1964
|
for (const [currentCollection, previousCollection] of matchedCollections) {
|
|
1914
|
-
const modification = buildCollectionModification(currentCollection, previousCollection, config);
|
|
1965
|
+
const modification = buildCollectionModification(currentCollection, previousCollection, config, collectionIdToName);
|
|
1915
1966
|
if (hasChanges(modification)) {
|
|
1916
1967
|
collectionsToModify.push(modification);
|
|
1917
1968
|
}
|
|
@@ -2291,6 +2342,9 @@ function getSystemFields() {
|
|
|
2291
2342
|
function generateCollectionCreation(collection, varName = "collection", isLast = false, collectionIdMap) {
|
|
2292
2343
|
const lines = [];
|
|
2293
2344
|
lines.push(` const ${varName} = new Collection({`);
|
|
2345
|
+
if (collection.id) {
|
|
2346
|
+
lines.push(` id: ${formatValue(collection.id)},`);
|
|
2347
|
+
}
|
|
2294
2348
|
lines.push(` name: "${collection.name}",`);
|
|
2295
2349
|
lines.push(` type: "${collection.type}",`);
|
|
2296
2350
|
const permissionsCode = generateCollectionPermissions(collection.permissions);
|
|
@@ -2534,7 +2588,24 @@ function generateOperationUpMigration(operation, collectionIdMap) {
|
|
|
2534
2588
|
const varName = `collection_${collectionName}`;
|
|
2535
2589
|
lines.push(generateCollectionDeletion(collectionName, varName, true));
|
|
2536
2590
|
}
|
|
2537
|
-
|
|
2591
|
+
let code = lines.join("\n");
|
|
2592
|
+
const savePattern = /^(\s*)app\.save\((\w+)\);$/gm;
|
|
2593
|
+
const deletePattern = /^(\s*)app\.delete\((\w+)\);$/gm;
|
|
2594
|
+
const saveMatches = [...code.matchAll(savePattern)];
|
|
2595
|
+
const deleteMatches = [...code.matchAll(deletePattern)];
|
|
2596
|
+
const allMatches = [
|
|
2597
|
+
...saveMatches.map((m) => ({ match: m, type: "save", index: m.index })),
|
|
2598
|
+
...deleteMatches.map((m) => ({ match: m, type: "delete", index: m.index }))
|
|
2599
|
+
].sort((a, b) => b.index - a.index);
|
|
2600
|
+
if (allMatches.length > 0) {
|
|
2601
|
+
const lastMatch = allMatches[0];
|
|
2602
|
+
if (lastMatch.type === "save") {
|
|
2603
|
+
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);
|
|
2604
|
+
} else {
|
|
2605
|
+
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);
|
|
2606
|
+
}
|
|
2607
|
+
}
|
|
2608
|
+
return code;
|
|
2538
2609
|
}
|
|
2539
2610
|
function generateOperationDownMigration(operation, collectionIdMap) {
|
|
2540
2611
|
const lines = [];
|
|
@@ -2619,7 +2690,24 @@ function generateOperationDownMigration(operation, collectionIdMap) {
|
|
|
2619
2690
|
lines.push(generateCollectionCreation(collection, varName, true, collectionIdMap));
|
|
2620
2691
|
}
|
|
2621
2692
|
}
|
|
2622
|
-
|
|
2693
|
+
let code = lines.join("\n");
|
|
2694
|
+
const savePattern = /^(\s*)app\.save\((\w+)\);$/gm;
|
|
2695
|
+
const deletePattern = /^(\s*)app\.delete\((\w+)\);$/gm;
|
|
2696
|
+
const saveMatches = [...code.matchAll(savePattern)];
|
|
2697
|
+
const deleteMatches = [...code.matchAll(deletePattern)];
|
|
2698
|
+
const allMatches = [
|
|
2699
|
+
...saveMatches.map((m) => ({ match: m, type: "save", index: m.index })),
|
|
2700
|
+
...deleteMatches.map((m) => ({ match: m, type: "delete", index: m.index }))
|
|
2701
|
+
].sort((a, b) => b.index - a.index);
|
|
2702
|
+
if (allMatches.length > 0) {
|
|
2703
|
+
const lastMatch = allMatches[0];
|
|
2704
|
+
if (lastMatch.type === "save") {
|
|
2705
|
+
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);
|
|
2706
|
+
} else {
|
|
2707
|
+
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);
|
|
2708
|
+
}
|
|
2709
|
+
}
|
|
2710
|
+
return code;
|
|
2623
2711
|
}
|
|
2624
2712
|
function generate(diff, config) {
|
|
2625
2713
|
const normalizedConfig = typeof config === "string" ? { migrationDir: config } : config;
|
|
@@ -2668,7 +2756,7 @@ function generate(diff, config) {
|
|
|
2668
2756
|
var SNAPSHOT_VERSION = "1.0.0";
|
|
2669
2757
|
function resolveCollectionIdToName(collectionId) {
|
|
2670
2758
|
if (collectionId === "_pb_users_auth_") {
|
|
2671
|
-
return "
|
|
2759
|
+
return "users";
|
|
2672
2760
|
}
|
|
2673
2761
|
const nameMatch = collectionId.match(/app\.findCollectionByNameOrId\s*\(\s*["']([^"']+)["']\s*\)/);
|
|
2674
2762
|
if (nameMatch) {
|
|
@@ -2676,6 +2764,39 @@ function resolveCollectionIdToName(collectionId) {
|
|
|
2676
2764
|
}
|
|
2677
2765
|
return collectionId;
|
|
2678
2766
|
}
|
|
2767
|
+
function extractFieldOptions2(pbField) {
|
|
2768
|
+
const options = {};
|
|
2769
|
+
if (pbField.options && typeof pbField.options === "object") {
|
|
2770
|
+
Object.assign(options, pbField.options);
|
|
2771
|
+
}
|
|
2772
|
+
const directOptionKeys = [
|
|
2773
|
+
"min",
|
|
2774
|
+
"max",
|
|
2775
|
+
"pattern",
|
|
2776
|
+
"noDecimal",
|
|
2777
|
+
// text/number fields
|
|
2778
|
+
"values",
|
|
2779
|
+
"maxSelect",
|
|
2780
|
+
// select fields
|
|
2781
|
+
"mimeTypes",
|
|
2782
|
+
"maxSize",
|
|
2783
|
+
"thumbs",
|
|
2784
|
+
"protected",
|
|
2785
|
+
// file fields
|
|
2786
|
+
"onCreate",
|
|
2787
|
+
"onUpdate",
|
|
2788
|
+
// autodate fields
|
|
2789
|
+
"exceptDomains",
|
|
2790
|
+
"onlyDomains"
|
|
2791
|
+
// email/url fields
|
|
2792
|
+
];
|
|
2793
|
+
for (const key of directOptionKeys) {
|
|
2794
|
+
if (pbField[key] !== void 0) {
|
|
2795
|
+
options[key] = pbField[key];
|
|
2796
|
+
}
|
|
2797
|
+
}
|
|
2798
|
+
return options;
|
|
2799
|
+
}
|
|
2679
2800
|
function convertPocketBaseCollection(pbCollection) {
|
|
2680
2801
|
const fields = [];
|
|
2681
2802
|
const systemFieldNames = ["id", "created", "updated", "collectionId", "collectionName", "expand"];
|
|
@@ -2693,23 +2814,19 @@ function convertPocketBaseCollection(pbCollection) {
|
|
|
2693
2814
|
type: pbField.type,
|
|
2694
2815
|
required: pbField.required || false
|
|
2695
2816
|
};
|
|
2696
|
-
field.options = pbField
|
|
2697
|
-
if (pbField.type === "select") {
|
|
2698
|
-
if (pbField.values && Array.isArray(pbField.values)) {
|
|
2699
|
-
field.options.values = pbField.values;
|
|
2700
|
-
} else if (pbField.options?.values && Array.isArray(pbField.options.values)) {
|
|
2701
|
-
field.options.values = pbField.options.values;
|
|
2702
|
-
}
|
|
2703
|
-
}
|
|
2817
|
+
field.options = extractFieldOptions2(pbField);
|
|
2704
2818
|
if (pbField.type === "relation") {
|
|
2705
2819
|
const collectionId = pbField.collectionId || pbField.options?.collectionId || "";
|
|
2706
|
-
const collectionName = resolveCollectionIdToName(collectionId);
|
|
2820
|
+
const collectionName = resolveCollectionIdToName(collectionId || "");
|
|
2707
2821
|
field.relation = {
|
|
2708
2822
|
collection: collectionName,
|
|
2709
2823
|
cascadeDelete: pbField.cascadeDelete ?? pbField.options?.cascadeDelete ?? false,
|
|
2710
2824
|
maxSelect: pbField.maxSelect ?? pbField.options?.maxSelect,
|
|
2711
2825
|
minSelect: pbField.minSelect ?? pbField.options?.minSelect
|
|
2712
2826
|
};
|
|
2827
|
+
delete field.options.maxSelect;
|
|
2828
|
+
delete field.options.minSelect;
|
|
2829
|
+
delete field.options.cascadeDelete;
|
|
2713
2830
|
}
|
|
2714
2831
|
const hasOnlyValues = Object.keys(field.options).length === 1 && field.options.values !== void 0;
|
|
2715
2832
|
if (Object.keys(field.options).length === 0) {
|
|
@@ -2723,17 +2840,21 @@ function convertPocketBaseCollection(pbCollection) {
|
|
|
2723
2840
|
type: pbCollection.type || "base",
|
|
2724
2841
|
fields
|
|
2725
2842
|
};
|
|
2843
|
+
if (pbCollection.id) {
|
|
2844
|
+
schema.id = pbCollection.id;
|
|
2845
|
+
}
|
|
2726
2846
|
if (pbCollection.indexes && Array.isArray(pbCollection.indexes)) {
|
|
2727
2847
|
schema.indexes = pbCollection.indexes;
|
|
2728
2848
|
}
|
|
2729
|
-
const
|
|
2730
|
-
if (
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2849
|
+
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;
|
|
2850
|
+
if (hasAnyRule) {
|
|
2851
|
+
const rules = {};
|
|
2852
|
+
if (pbCollection.listRule !== void 0) rules.listRule = pbCollection.listRule;
|
|
2853
|
+
if (pbCollection.viewRule !== void 0) rules.viewRule = pbCollection.viewRule;
|
|
2854
|
+
if (pbCollection.createRule !== void 0) rules.createRule = pbCollection.createRule;
|
|
2855
|
+
if (pbCollection.updateRule !== void 0) rules.updateRule = pbCollection.updateRule;
|
|
2856
|
+
if (pbCollection.deleteRule !== void 0) rules.deleteRule = pbCollection.deleteRule;
|
|
2857
|
+
if (pbCollection.manageRule !== void 0) rules.manageRule = pbCollection.manageRule;
|
|
2737
2858
|
schema.rules = rules;
|
|
2738
2859
|
schema.permissions = { ...rules };
|
|
2739
2860
|
}
|