@strapi/utils 5.1.1 → 5.2.0
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/dist/index.js +316 -204
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +316 -204
- package/dist/index.mjs.map +1 -1
- package/dist/sanitize/sanitizers.d.ts +2 -0
- package/dist/sanitize/sanitizers.d.ts.map +1 -1
- package/dist/traverse/factory.d.ts +10 -1
- package/dist/traverse/factory.d.ts.map +1 -1
- package/dist/traverse/query-filters.d.ts.map +1 -1
- package/dist/traverse/query-populate.d.ts.map +1 -1
- package/dist/traverse/query-sort.d.ts.map +1 -1
- package/dist/traverse-entity.d.ts +4 -4
- package/dist/traverse-entity.d.ts.map +1 -1
- package/dist/validate/validators.d.ts +7 -3
- package/dist/validate/validators.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -1523,7 +1523,7 @@ const traverseFactory = () => {
|
|
|
1523
1523
|
}
|
|
1524
1524
|
};
|
|
1525
1525
|
const traverse = async (visitor2, options, data) => {
|
|
1526
|
-
const { path = DEFAULT_PATH, schema, getModel } = options ?? {};
|
|
1526
|
+
const { path = DEFAULT_PATH, parent, schema, getModel } = options ?? {};
|
|
1527
1527
|
for (const { predicate, handler } of state.interceptors) {
|
|
1528
1528
|
if (predicate(data)) {
|
|
1529
1529
|
return handler(visitor2, options, data, { recurse: traverse });
|
|
@@ -1550,7 +1550,8 @@ const traverseFactory = () => {
|
|
|
1550
1550
|
schema,
|
|
1551
1551
|
path: newPath,
|
|
1552
1552
|
data: out,
|
|
1553
|
-
getModel
|
|
1553
|
+
getModel,
|
|
1554
|
+
parent
|
|
1554
1555
|
};
|
|
1555
1556
|
const transformUtils = {
|
|
1556
1557
|
remove(key2) {
|
|
@@ -1571,7 +1572,8 @@ const traverseFactory = () => {
|
|
|
1571
1572
|
path: newPath,
|
|
1572
1573
|
data: out,
|
|
1573
1574
|
visitor: visitor2,
|
|
1574
|
-
getModel
|
|
1575
|
+
getModel,
|
|
1576
|
+
parent
|
|
1575
1577
|
});
|
|
1576
1578
|
const ignoreCtx = createContext();
|
|
1577
1579
|
const shouldIgnore = state.ignore.some((predicate) => predicate(ignoreCtx));
|
|
@@ -1660,26 +1662,46 @@ const filters = traverseFactory().intercept(
|
|
|
1660
1662
|
}
|
|
1661
1663
|
})).ignore(({ value }) => isNil(value)).on(
|
|
1662
1664
|
({ attribute }) => isNil(attribute),
|
|
1663
|
-
async ({ key, visitor: visitor2, path, value, schema, getModel }, { set, recurse }) => {
|
|
1664
|
-
|
|
1665
|
+
async ({ key, visitor: visitor2, path, value, schema, getModel, attribute }, { set, recurse }) => {
|
|
1666
|
+
const parent = { key, path, schema, attribute };
|
|
1667
|
+
set(key, await recurse(visitor2, { schema, path, getModel, parent }, value));
|
|
1668
|
+
}
|
|
1669
|
+
).onRelation(
|
|
1670
|
+
async ({ key, attribute, visitor: visitor2, path, value, schema, getModel }, { set, recurse }) => {
|
|
1671
|
+
const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
|
|
1672
|
+
if (isMorphRelation) {
|
|
1673
|
+
return;
|
|
1674
|
+
}
|
|
1675
|
+
const parent = { key, path, schema, attribute };
|
|
1676
|
+
const targetSchemaUID = attribute.target;
|
|
1677
|
+
const targetSchema = getModel(targetSchemaUID);
|
|
1678
|
+
const newValue = await recurse(
|
|
1679
|
+
visitor2,
|
|
1680
|
+
{ schema: targetSchema, path, getModel, parent },
|
|
1681
|
+
value
|
|
1682
|
+
);
|
|
1683
|
+
set(key, newValue);
|
|
1665
1684
|
}
|
|
1666
|
-
).
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1685
|
+
).onComponent(
|
|
1686
|
+
async ({ key, attribute, visitor: visitor2, path, schema, value, getModel }, { set, recurse }) => {
|
|
1687
|
+
const parent = { key, path, schema, attribute };
|
|
1688
|
+
const targetSchema = getModel(attribute.component);
|
|
1689
|
+
const newValue = await recurse(
|
|
1690
|
+
visitor2,
|
|
1691
|
+
{ schema: targetSchema, path, getModel, parent },
|
|
1692
|
+
value
|
|
1693
|
+
);
|
|
1694
|
+
set(key, newValue);
|
|
1670
1695
|
}
|
|
1671
|
-
|
|
1672
|
-
const
|
|
1673
|
-
const newValue = await recurse(visitor2, { schema: targetSchema, path, getModel }, value);
|
|
1674
|
-
set(key, newValue);
|
|
1675
|
-
}).onComponent(async ({ key, attribute, visitor: visitor2, path, value, getModel }, { set, recurse }) => {
|
|
1676
|
-
const targetSchema = getModel(attribute.component);
|
|
1677
|
-
const newValue = await recurse(visitor2, { schema: targetSchema, path, getModel }, value);
|
|
1678
|
-
set(key, newValue);
|
|
1679
|
-
}).onMedia(async ({ key, visitor: visitor2, path, value, getModel }, { set, recurse }) => {
|
|
1696
|
+
).onMedia(async ({ key, visitor: visitor2, path, schema, attribute, value, getModel }, { set, recurse }) => {
|
|
1697
|
+
const parent = { key, path, schema, attribute };
|
|
1680
1698
|
const targetSchemaUID = "plugin::upload.file";
|
|
1681
1699
|
const targetSchema = getModel(targetSchemaUID);
|
|
1682
|
-
const newValue = await recurse(
|
|
1700
|
+
const newValue = await recurse(
|
|
1701
|
+
visitor2,
|
|
1702
|
+
{ schema: targetSchema, path, getModel, parent },
|
|
1703
|
+
value
|
|
1704
|
+
);
|
|
1683
1705
|
set(key, newValue);
|
|
1684
1706
|
});
|
|
1685
1707
|
const traverseQueryFilters = curry(filters.traverse);
|
|
@@ -1767,66 +1789,91 @@ const sort = traverseFactory().intercept(
|
|
|
1767
1789
|
get(key, data) {
|
|
1768
1790
|
return data[key];
|
|
1769
1791
|
}
|
|
1770
|
-
})).onRelation(
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1792
|
+
})).onRelation(
|
|
1793
|
+
async ({ key, value, attribute, visitor: visitor2, path, getModel, schema }, { set, recurse }) => {
|
|
1794
|
+
const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
|
|
1795
|
+
if (isMorphRelation) {
|
|
1796
|
+
return;
|
|
1797
|
+
}
|
|
1798
|
+
const parent = { key, path, schema, attribute };
|
|
1799
|
+
const targetSchemaUID = attribute.target;
|
|
1800
|
+
const targetSchema = getModel(targetSchemaUID);
|
|
1801
|
+
const newValue = await recurse(
|
|
1802
|
+
visitor2,
|
|
1803
|
+
{ schema: targetSchema, path, getModel, parent },
|
|
1804
|
+
value
|
|
1805
|
+
);
|
|
1806
|
+
set(key, newValue);
|
|
1774
1807
|
}
|
|
1775
|
-
|
|
1776
|
-
const
|
|
1777
|
-
const newValue = await recurse(visitor2, { schema: targetSchema, path, getModel }, value);
|
|
1778
|
-
set(key, newValue);
|
|
1779
|
-
}).onMedia(async ({ key, path, visitor: visitor2, value, getModel }, { recurse, set }) => {
|
|
1808
|
+
).onMedia(async ({ key, path, schema, attribute, visitor: visitor2, value, getModel }, { recurse, set }) => {
|
|
1809
|
+
const parent = { key, path, schema, attribute };
|
|
1780
1810
|
const targetSchemaUID = "plugin::upload.file";
|
|
1781
1811
|
const targetSchema = getModel(targetSchemaUID);
|
|
1782
|
-
const newValue = await recurse(
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1812
|
+
const newValue = await recurse(
|
|
1813
|
+
visitor2,
|
|
1814
|
+
{ schema: targetSchema, path, getModel, parent },
|
|
1815
|
+
value
|
|
1816
|
+
);
|
|
1787
1817
|
set(key, newValue);
|
|
1788
|
-
})
|
|
1818
|
+
}).onComponent(
|
|
1819
|
+
async ({ key, value, visitor: visitor2, path, schema, attribute, getModel }, { recurse, set }) => {
|
|
1820
|
+
const parent = { key, path, schema, attribute };
|
|
1821
|
+
const targetSchema = getModel(attribute.component);
|
|
1822
|
+
const newValue = await recurse(
|
|
1823
|
+
visitor2,
|
|
1824
|
+
{ schema: targetSchema, path, getModel, parent },
|
|
1825
|
+
value
|
|
1826
|
+
);
|
|
1827
|
+
set(key, newValue);
|
|
1828
|
+
}
|
|
1829
|
+
);
|
|
1789
1830
|
const traverseQuerySort = curry(sort.traverse);
|
|
1790
1831
|
const isKeyword = (keyword) => {
|
|
1791
1832
|
return ({ key, attribute }) => {
|
|
1792
1833
|
return !attribute && keyword === key;
|
|
1793
1834
|
};
|
|
1794
1835
|
};
|
|
1836
|
+
const isWildcard = (value) => value === "*";
|
|
1837
|
+
const isPopulateString = (value) => {
|
|
1838
|
+
return isString(value) && !isWildcard(value);
|
|
1839
|
+
};
|
|
1795
1840
|
const isStringArray$1 = (value) => isArray(value) && value.every(isString);
|
|
1796
1841
|
const isObj = (value) => isObject(value);
|
|
1797
|
-
const populate = traverseFactory().intercept(
|
|
1798
|
-
const
|
|
1799
|
-
|
|
1842
|
+
const populate = traverseFactory().intercept(isPopulateString, async (visitor2, options, populate2, { recurse }) => {
|
|
1843
|
+
const populateObject = pathsToObjectPopulate([populate2]);
|
|
1844
|
+
const traversedPopulate = await recurse(visitor2, options, populateObject);
|
|
1845
|
+
const [result] = objectPopulateToPaths(traversedPopulate);
|
|
1846
|
+
return result;
|
|
1847
|
+
}).intercept(isStringArray$1, async (visitor2, options, populate2, { recurse }) => {
|
|
1848
|
+
const paths = await Promise.all(
|
|
1849
|
+
populate2.map((subClause) => recurse(visitor2, options, subClause))
|
|
1800
1850
|
);
|
|
1801
|
-
return
|
|
1802
|
-
}).parse(
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
remove: constant(void 0)
|
|
1828
|
-
})
|
|
1829
|
-
).parse(isString, () => {
|
|
1851
|
+
return paths.filter((item) => !isNil(item));
|
|
1852
|
+
}).parse(isWildcard, () => ({
|
|
1853
|
+
/**
|
|
1854
|
+
* Since value is '*', we don't need to transform it
|
|
1855
|
+
*/
|
|
1856
|
+
transform: identity,
|
|
1857
|
+
/**
|
|
1858
|
+
* '*' isn't a key/value structure, so regardless
|
|
1859
|
+
* of the given key, it returns the data ('*')
|
|
1860
|
+
*/
|
|
1861
|
+
get: (_key, data) => data,
|
|
1862
|
+
/**
|
|
1863
|
+
* '*' isn't a key/value structure, so regardless
|
|
1864
|
+
* of the given `key`, use `value` as the new `data`
|
|
1865
|
+
*/
|
|
1866
|
+
set: (_key, value) => value,
|
|
1867
|
+
/**
|
|
1868
|
+
* '*' isn't a key/value structure, but we need to simulate at least one to enable
|
|
1869
|
+
* the data traversal. We're using '' since it represents a falsy string value
|
|
1870
|
+
*/
|
|
1871
|
+
keys: constant([""]),
|
|
1872
|
+
/**
|
|
1873
|
+
* Removing '*' means setting it to undefined, regardless of the given key
|
|
1874
|
+
*/
|
|
1875
|
+
remove: constant(void 0)
|
|
1876
|
+
})).parse(isString, () => {
|
|
1830
1877
|
const tokenize = split(".");
|
|
1831
1878
|
const recompose = join(".");
|
|
1832
1879
|
return {
|
|
@@ -1871,64 +1918,127 @@ const populate = traverseFactory().intercept(isStringArray$1, async (visitor2, o
|
|
|
1871
1918
|
}).on(
|
|
1872
1919
|
// Handle recursion on populate."populate"
|
|
1873
1920
|
isKeyword("populate"),
|
|
1874
|
-
async ({ key, visitor: visitor2, path, value, schema, getModel }, { set, recurse }) => {
|
|
1875
|
-
const
|
|
1921
|
+
async ({ key, visitor: visitor2, path, value, schema, getModel, attribute }, { set, recurse }) => {
|
|
1922
|
+
const parent = { key, path, schema, attribute };
|
|
1923
|
+
const newValue = await recurse(visitor2, { schema, path, getModel, parent }, value);
|
|
1876
1924
|
set(key, newValue);
|
|
1877
1925
|
}
|
|
1878
|
-
).on(
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
const
|
|
1886
|
-
|
|
1926
|
+
).on(
|
|
1927
|
+
isKeyword("on"),
|
|
1928
|
+
async ({ key, visitor: visitor2, path, value, getModel, parent }, { set, recurse }) => {
|
|
1929
|
+
const newOn = {};
|
|
1930
|
+
if (!isObj(value)) {
|
|
1931
|
+
return;
|
|
1932
|
+
}
|
|
1933
|
+
for (const [uid, subPopulate] of Object.entries(value)) {
|
|
1934
|
+
const model = getModel(uid);
|
|
1935
|
+
const newPath = { ...path, raw: `${path.raw}[${uid}]` };
|
|
1936
|
+
newOn[uid] = await recurse(
|
|
1937
|
+
visitor2,
|
|
1938
|
+
{ schema: model, path: newPath, getModel, parent },
|
|
1939
|
+
subPopulate
|
|
1940
|
+
);
|
|
1941
|
+
}
|
|
1942
|
+
set(key, newOn);
|
|
1887
1943
|
}
|
|
1888
|
-
|
|
1889
|
-
}).onRelation(
|
|
1944
|
+
).onRelation(
|
|
1890
1945
|
async ({ key, value, attribute, visitor: visitor2, path, schema, getModel }, { set, recurse }) => {
|
|
1891
1946
|
if (isNil(value)) {
|
|
1892
1947
|
return;
|
|
1893
1948
|
}
|
|
1949
|
+
const parent = { key, path, schema, attribute };
|
|
1894
1950
|
if (isMorphToRelationalAttribute(attribute)) {
|
|
1895
1951
|
if (!isObject(value) || !("on" in value && isObject(value?.on))) {
|
|
1896
1952
|
return;
|
|
1897
1953
|
}
|
|
1898
|
-
const newValue2 = await recurse(
|
|
1954
|
+
const newValue2 = await recurse(
|
|
1955
|
+
visitor2,
|
|
1956
|
+
{ schema, path, getModel, parent },
|
|
1957
|
+
{ on: value?.on }
|
|
1958
|
+
);
|
|
1899
1959
|
set(key, newValue2);
|
|
1900
1960
|
return;
|
|
1901
1961
|
}
|
|
1902
1962
|
const targetSchemaUID = attribute.target;
|
|
1903
1963
|
const targetSchema = getModel(targetSchemaUID);
|
|
1904
|
-
const newValue = await recurse(
|
|
1964
|
+
const newValue = await recurse(
|
|
1965
|
+
visitor2,
|
|
1966
|
+
{ schema: targetSchema, path, getModel, parent },
|
|
1967
|
+
value
|
|
1968
|
+
);
|
|
1905
1969
|
set(key, newValue);
|
|
1906
1970
|
}
|
|
1907
|
-
).onMedia(async ({ key, path, visitor: visitor2, value, getModel }, { recurse, set }) => {
|
|
1971
|
+
).onMedia(async ({ key, path, schema, attribute, visitor: visitor2, value, getModel }, { recurse, set }) => {
|
|
1908
1972
|
if (isNil(value)) {
|
|
1909
1973
|
return;
|
|
1910
1974
|
}
|
|
1975
|
+
const parent = { key, path, schema, attribute };
|
|
1911
1976
|
const targetSchemaUID = "plugin::upload.file";
|
|
1912
1977
|
const targetSchema = getModel(targetSchemaUID);
|
|
1913
|
-
const newValue = await recurse(
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
}
|
|
1919
|
-
const targetSchema = getModel(attribute.component);
|
|
1920
|
-
const newValue = await recurse(visitor2, { schema: targetSchema, path, getModel }, value);
|
|
1978
|
+
const newValue = await recurse(
|
|
1979
|
+
visitor2,
|
|
1980
|
+
{ schema: targetSchema, path, getModel, parent },
|
|
1981
|
+
value
|
|
1982
|
+
);
|
|
1921
1983
|
set(key, newValue);
|
|
1922
|
-
}).
|
|
1923
|
-
|
|
1924
|
-
|
|
1984
|
+
}).onComponent(
|
|
1985
|
+
async ({ key, value, schema, visitor: visitor2, path, attribute, getModel }, { recurse, set }) => {
|
|
1986
|
+
if (isNil(value)) {
|
|
1987
|
+
return;
|
|
1988
|
+
}
|
|
1989
|
+
const parent = { key, path, schema, attribute };
|
|
1990
|
+
const targetSchema = getModel(attribute.component);
|
|
1991
|
+
const newValue = await recurse(
|
|
1992
|
+
visitor2,
|
|
1993
|
+
{ schema: targetSchema, path, getModel, parent },
|
|
1994
|
+
value
|
|
1995
|
+
);
|
|
1996
|
+
set(key, newValue);
|
|
1925
1997
|
}
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1998
|
+
).onDynamicZone(
|
|
1999
|
+
async ({ key, value, schema, visitor: visitor2, path, attribute, getModel }, { set, recurse }) => {
|
|
2000
|
+
if (isNil(value) || !isObject(value)) {
|
|
2001
|
+
return;
|
|
2002
|
+
}
|
|
2003
|
+
const parent = { key, path, schema, attribute };
|
|
2004
|
+
if ("on" in value && value.on) {
|
|
2005
|
+
const newOn = await recurse(visitor2, { schema, path, getModel, parent }, { on: value.on });
|
|
2006
|
+
set(key, newOn);
|
|
2007
|
+
}
|
|
1929
2008
|
}
|
|
1930
|
-
|
|
2009
|
+
);
|
|
1931
2010
|
const traverseQueryPopulate = curry(populate.traverse);
|
|
2011
|
+
const objectPopulateToPaths = (input) => {
|
|
2012
|
+
const paths = [];
|
|
2013
|
+
function traverse(currentObj, parentPath) {
|
|
2014
|
+
for (const [key, value] of Object.entries(currentObj)) {
|
|
2015
|
+
const currentPath = parentPath ? `${parentPath}.${key}` : key;
|
|
2016
|
+
if (value === true) {
|
|
2017
|
+
paths.push(currentPath);
|
|
2018
|
+
} else {
|
|
2019
|
+
traverse(value.populate, currentPath);
|
|
2020
|
+
}
|
|
2021
|
+
}
|
|
2022
|
+
}
|
|
2023
|
+
traverse(input, "");
|
|
2024
|
+
return paths;
|
|
2025
|
+
};
|
|
2026
|
+
const pathsToObjectPopulate = (input) => {
|
|
2027
|
+
const result = {};
|
|
2028
|
+
function traverse(object, keys) {
|
|
2029
|
+
const [first2, ...rest] = keys;
|
|
2030
|
+
if (rest.length === 0) {
|
|
2031
|
+
object[first2] = true;
|
|
2032
|
+
} else {
|
|
2033
|
+
if (!object[first2] || typeof object[first2] === "boolean") {
|
|
2034
|
+
object[first2] = { populate: {} };
|
|
2035
|
+
}
|
|
2036
|
+
traverse(object[first2].populate, rest);
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
input.forEach((clause) => traverse(result, clause.split(".")));
|
|
2040
|
+
return result;
|
|
2041
|
+
};
|
|
1932
2042
|
const isStringArray = (value) => {
|
|
1933
2043
|
return isArray(value) && value.every(isString);
|
|
1934
2044
|
};
|
|
@@ -2074,21 +2184,22 @@ const defaultSanitizePopulate = curry((ctx, populate2) => {
|
|
|
2074
2184
|
}
|
|
2075
2185
|
return pipe(
|
|
2076
2186
|
traverseQueryPopulate(visitor$4, ctx),
|
|
2077
|
-
traverseQueryPopulate(async ({ key, value, schema, attribute, getModel }, { set }) => {
|
|
2187
|
+
traverseQueryPopulate(async ({ key, value, schema, attribute, getModel, path }, { set }) => {
|
|
2078
2188
|
if (attribute) {
|
|
2079
2189
|
return;
|
|
2080
2190
|
}
|
|
2191
|
+
const parent = { key, path, schema, attribute };
|
|
2081
2192
|
if (key === "sort") {
|
|
2082
|
-
set(key, await defaultSanitizeSort({ schema, getModel }, value));
|
|
2193
|
+
set(key, await defaultSanitizeSort({ schema, getModel, parent }, value));
|
|
2083
2194
|
}
|
|
2084
2195
|
if (key === "filters") {
|
|
2085
|
-
set(key, await defaultSanitizeFilters({ schema, getModel }, value));
|
|
2196
|
+
set(key, await defaultSanitizeFilters({ schema, getModel, parent }, value));
|
|
2086
2197
|
}
|
|
2087
2198
|
if (key === "fields") {
|
|
2088
|
-
set(key, await defaultSanitizeFields({ schema, getModel }, value));
|
|
2199
|
+
set(key, await defaultSanitizeFields({ schema, getModel, parent }, value));
|
|
2089
2200
|
}
|
|
2090
2201
|
if (key === "populate") {
|
|
2091
|
-
set(key, await defaultSanitizePopulate({ schema, getModel }, value));
|
|
2202
|
+
set(key, await defaultSanitizePopulate({ schema, getModel, parent }, value));
|
|
2092
2203
|
}
|
|
2093
2204
|
}, ctx),
|
|
2094
2205
|
// Remove private fields
|
|
@@ -2441,12 +2552,6 @@ const index$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
|
|
|
2441
2552
|
throwUnrecognizedFields
|
|
2442
2553
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
2443
2554
|
const { ID_ATTRIBUTE: ID_ATTRIBUTE$1, DOC_ID_ATTRIBUTE: DOC_ID_ATTRIBUTE$1 } = constants$1;
|
|
2444
|
-
const throwPasswords = (ctx) => async (entity) => {
|
|
2445
|
-
if (!ctx.schema) {
|
|
2446
|
-
throw new Error("Missing schema in throwPasswords");
|
|
2447
|
-
}
|
|
2448
|
-
return traverseEntity$1(visitor$3, ctx, entity);
|
|
2449
|
-
};
|
|
2450
2555
|
const FILTER_TRAVERSALS = [
|
|
2451
2556
|
"nonAttributesOperators",
|
|
2452
2557
|
"dynamicZones",
|
|
@@ -2595,110 +2700,118 @@ const validatePopulate = asyncCurry(
|
|
|
2595
2700
|
}
|
|
2596
2701
|
const functionsToApply = [];
|
|
2597
2702
|
functionsToApply.push(
|
|
2598
|
-
traverseQueryPopulate(
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2703
|
+
traverseQueryPopulate(
|
|
2704
|
+
async ({ key, path, value, schema, attribute, getModel, parent }, { set }) => {
|
|
2705
|
+
if (!parent?.attribute && attribute) {
|
|
2706
|
+
const isPopulatableAttribute = [
|
|
2707
|
+
"relation",
|
|
2708
|
+
"dynamiczone",
|
|
2709
|
+
"component",
|
|
2710
|
+
"media"
|
|
2711
|
+
].includes(attribute.type);
|
|
2712
|
+
if (!isPopulatableAttribute) {
|
|
2713
|
+
throwInvalidKey({ key, path: path.raw });
|
|
2714
|
+
}
|
|
2715
|
+
return;
|
|
2605
2716
|
}
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2717
|
+
if (key === "on") {
|
|
2718
|
+
if (!isObject(value)) {
|
|
2719
|
+
return throwInvalidKey({ key, path: path.raw });
|
|
2720
|
+
}
|
|
2721
|
+
const targets = Object.keys(value);
|
|
2722
|
+
for (const target of targets) {
|
|
2723
|
+
const model = getModel(target);
|
|
2724
|
+
if (!model) {
|
|
2725
|
+
throwInvalidKey({ key: target, path: `${path.raw}.${target}` });
|
|
2726
|
+
}
|
|
2727
|
+
}
|
|
2728
|
+
return;
|
|
2611
2729
|
}
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2730
|
+
if (key === "" && value === "*") {
|
|
2731
|
+
return;
|
|
2732
|
+
}
|
|
2733
|
+
if (key === "count") {
|
|
2734
|
+
try {
|
|
2735
|
+
parseType({ type: "boolean", value });
|
|
2736
|
+
return;
|
|
2737
|
+
} catch {
|
|
2738
|
+
throwInvalidKey({ key, path: path.attribute });
|
|
2617
2739
|
}
|
|
2618
2740
|
}
|
|
2619
|
-
return;
|
|
2620
|
-
}
|
|
2621
|
-
if (key === "" && value === "*") {
|
|
2622
|
-
return;
|
|
2623
|
-
}
|
|
2624
|
-
if (key === "count") {
|
|
2625
2741
|
try {
|
|
2626
|
-
parseType({ type: "boolean", value });
|
|
2742
|
+
parseType({ type: "boolean", value: key });
|
|
2627
2743
|
return;
|
|
2628
2744
|
} catch {
|
|
2745
|
+
}
|
|
2746
|
+
if (key === "sort") {
|
|
2747
|
+
set(
|
|
2748
|
+
key,
|
|
2749
|
+
await validateSort(
|
|
2750
|
+
{
|
|
2751
|
+
schema,
|
|
2752
|
+
getModel
|
|
2753
|
+
},
|
|
2754
|
+
value,
|
|
2755
|
+
// pass the sort value
|
|
2756
|
+
includes?.sort || SORT_TRAVERSALS
|
|
2757
|
+
)
|
|
2758
|
+
);
|
|
2759
|
+
return;
|
|
2760
|
+
}
|
|
2761
|
+
if (key === "filters") {
|
|
2762
|
+
set(
|
|
2763
|
+
key,
|
|
2764
|
+
await validateFilters(
|
|
2765
|
+
{
|
|
2766
|
+
schema,
|
|
2767
|
+
getModel
|
|
2768
|
+
},
|
|
2769
|
+
value,
|
|
2770
|
+
// pass the filters value
|
|
2771
|
+
includes?.filters || FILTER_TRAVERSALS
|
|
2772
|
+
)
|
|
2773
|
+
);
|
|
2774
|
+
return;
|
|
2775
|
+
}
|
|
2776
|
+
if (key === "fields") {
|
|
2777
|
+
set(
|
|
2778
|
+
key,
|
|
2779
|
+
await validateFields(
|
|
2780
|
+
{
|
|
2781
|
+
schema,
|
|
2782
|
+
getModel
|
|
2783
|
+
},
|
|
2784
|
+
value,
|
|
2785
|
+
// pass the fields value
|
|
2786
|
+
includes?.fields || FIELDS_TRAVERSALS
|
|
2787
|
+
)
|
|
2788
|
+
);
|
|
2789
|
+
return;
|
|
2790
|
+
}
|
|
2791
|
+
if (key === "populate") {
|
|
2792
|
+
set(
|
|
2793
|
+
key,
|
|
2794
|
+
await validatePopulate(
|
|
2795
|
+
{
|
|
2796
|
+
schema,
|
|
2797
|
+
getModel,
|
|
2798
|
+
parent: { key, path, schema, attribute },
|
|
2799
|
+
path
|
|
2800
|
+
},
|
|
2801
|
+
value,
|
|
2802
|
+
// pass the nested populate value
|
|
2803
|
+
includes
|
|
2804
|
+
// pass down the same includes object
|
|
2805
|
+
)
|
|
2806
|
+
);
|
|
2807
|
+
return;
|
|
2808
|
+
}
|
|
2809
|
+
if (includes?.populate?.includes("nonAttributesOperators")) {
|
|
2629
2810
|
throwInvalidKey({ key, path: path.attribute });
|
|
2630
2811
|
}
|
|
2631
|
-
}
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
return;
|
|
2635
|
-
} catch {
|
|
2636
|
-
}
|
|
2637
|
-
if (key === "sort") {
|
|
2638
|
-
set(
|
|
2639
|
-
key,
|
|
2640
|
-
await validateSort(
|
|
2641
|
-
{
|
|
2642
|
-
schema,
|
|
2643
|
-
getModel
|
|
2644
|
-
},
|
|
2645
|
-
value,
|
|
2646
|
-
// pass the sort value
|
|
2647
|
-
includes?.sort || SORT_TRAVERSALS
|
|
2648
|
-
)
|
|
2649
|
-
);
|
|
2650
|
-
return;
|
|
2651
|
-
}
|
|
2652
|
-
if (key === "filters") {
|
|
2653
|
-
set(
|
|
2654
|
-
key,
|
|
2655
|
-
await validateFilters(
|
|
2656
|
-
{
|
|
2657
|
-
schema,
|
|
2658
|
-
getModel
|
|
2659
|
-
},
|
|
2660
|
-
value,
|
|
2661
|
-
// pass the filters value
|
|
2662
|
-
includes?.filters || FILTER_TRAVERSALS
|
|
2663
|
-
)
|
|
2664
|
-
);
|
|
2665
|
-
return;
|
|
2666
|
-
}
|
|
2667
|
-
if (key === "fields") {
|
|
2668
|
-
set(
|
|
2669
|
-
key,
|
|
2670
|
-
await validateFields(
|
|
2671
|
-
{
|
|
2672
|
-
schema,
|
|
2673
|
-
getModel
|
|
2674
|
-
},
|
|
2675
|
-
value,
|
|
2676
|
-
// pass the fields value
|
|
2677
|
-
includes?.fields || FIELDS_TRAVERSALS
|
|
2678
|
-
)
|
|
2679
|
-
);
|
|
2680
|
-
return;
|
|
2681
|
-
}
|
|
2682
|
-
if (key === "populate") {
|
|
2683
|
-
set(
|
|
2684
|
-
key,
|
|
2685
|
-
await validatePopulate(
|
|
2686
|
-
{
|
|
2687
|
-
schema,
|
|
2688
|
-
getModel
|
|
2689
|
-
},
|
|
2690
|
-
value,
|
|
2691
|
-
// pass the nested populate value
|
|
2692
|
-
includes
|
|
2693
|
-
// pass down the same includes object
|
|
2694
|
-
)
|
|
2695
|
-
);
|
|
2696
|
-
return;
|
|
2697
|
-
}
|
|
2698
|
-
if (includes?.populate?.includes("nonAttributesOperators")) {
|
|
2699
|
-
throwInvalidKey({ key, path: path.attribute });
|
|
2700
|
-
}
|
|
2701
|
-
}, ctx)
|
|
2812
|
+
},
|
|
2813
|
+
ctx
|
|
2814
|
+
)
|
|
2702
2815
|
);
|
|
2703
2816
|
if (includes?.populate?.includes("private")) {
|
|
2704
2817
|
functionsToApply.push(traverseQueryPopulate(visitor$2, ctx));
|
|
@@ -2730,7 +2843,6 @@ const validators = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePr
|
|
|
2730
2843
|
defaultValidateFilters,
|
|
2731
2844
|
defaultValidatePopulate,
|
|
2732
2845
|
defaultValidateSort,
|
|
2733
|
-
throwPasswords,
|
|
2734
2846
|
validateFields,
|
|
2735
2847
|
validateFilters,
|
|
2736
2848
|
validatePopulate,
|