@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 CHANGED
@@ -1550,7 +1550,7 @@ const traverseFactory = () => {
1550
1550
  }
1551
1551
  };
1552
1552
  const traverse = async (visitor2, options, data) => {
1553
- const { path = DEFAULT_PATH, schema, getModel } = options ?? {};
1553
+ const { path = DEFAULT_PATH, parent, schema, getModel } = options ?? {};
1554
1554
  for (const { predicate, handler } of state.interceptors) {
1555
1555
  if (predicate(data)) {
1556
1556
  return handler(visitor2, options, data, { recurse: traverse });
@@ -1577,7 +1577,8 @@ const traverseFactory = () => {
1577
1577
  schema,
1578
1578
  path: newPath,
1579
1579
  data: out,
1580
- getModel
1580
+ getModel,
1581
+ parent
1581
1582
  };
1582
1583
  const transformUtils = {
1583
1584
  remove(key2) {
@@ -1598,7 +1599,8 @@ const traverseFactory = () => {
1598
1599
  path: newPath,
1599
1600
  data: out,
1600
1601
  visitor: visitor2,
1601
- getModel
1602
+ getModel,
1603
+ parent
1602
1604
  });
1603
1605
  const ignoreCtx = createContext();
1604
1606
  const shouldIgnore = state.ignore.some((predicate) => predicate(ignoreCtx));
@@ -1687,26 +1689,46 @@ const filters = traverseFactory().intercept(
1687
1689
  }
1688
1690
  })).ignore(({ value }) => fp.isNil(value)).on(
1689
1691
  ({ attribute }) => fp.isNil(attribute),
1690
- async ({ key, visitor: visitor2, path, value, schema, getModel }, { set, recurse }) => {
1691
- set(key, await recurse(visitor2, { schema, path, getModel }, value));
1692
+ async ({ key, visitor: visitor2, path, value, schema, getModel, attribute }, { set, recurse }) => {
1693
+ const parent = { key, path, schema, attribute };
1694
+ set(key, await recurse(visitor2, { schema, path, getModel, parent }, value));
1695
+ }
1696
+ ).onRelation(
1697
+ async ({ key, attribute, visitor: visitor2, path, value, schema, getModel }, { set, recurse }) => {
1698
+ const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
1699
+ if (isMorphRelation) {
1700
+ return;
1701
+ }
1702
+ const parent = { key, path, schema, attribute };
1703
+ const targetSchemaUID = attribute.target;
1704
+ const targetSchema = getModel(targetSchemaUID);
1705
+ const newValue = await recurse(
1706
+ visitor2,
1707
+ { schema: targetSchema, path, getModel, parent },
1708
+ value
1709
+ );
1710
+ set(key, newValue);
1692
1711
  }
1693
- ).onRelation(async ({ key, attribute, visitor: visitor2, path, value, getModel }, { set, recurse }) => {
1694
- const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
1695
- if (isMorphRelation) {
1696
- return;
1712
+ ).onComponent(
1713
+ async ({ key, attribute, visitor: visitor2, path, schema, value, getModel }, { set, recurse }) => {
1714
+ const parent = { key, path, schema, attribute };
1715
+ const targetSchema = getModel(attribute.component);
1716
+ const newValue = await recurse(
1717
+ visitor2,
1718
+ { schema: targetSchema, path, getModel, parent },
1719
+ value
1720
+ );
1721
+ set(key, newValue);
1697
1722
  }
1698
- const targetSchemaUID = attribute.target;
1699
- const targetSchema = getModel(targetSchemaUID);
1700
- const newValue = await recurse(visitor2, { schema: targetSchema, path, getModel }, value);
1701
- set(key, newValue);
1702
- }).onComponent(async ({ key, attribute, visitor: visitor2, path, value, getModel }, { set, recurse }) => {
1703
- const targetSchema = getModel(attribute.component);
1704
- const newValue = await recurse(visitor2, { schema: targetSchema, path, getModel }, value);
1705
- set(key, newValue);
1706
- }).onMedia(async ({ key, visitor: visitor2, path, value, getModel }, { set, recurse }) => {
1723
+ ).onMedia(async ({ key, visitor: visitor2, path, schema, attribute, value, getModel }, { set, recurse }) => {
1724
+ const parent = { key, path, schema, attribute };
1707
1725
  const targetSchemaUID = "plugin::upload.file";
1708
1726
  const targetSchema = getModel(targetSchemaUID);
1709
- const newValue = await recurse(visitor2, { schema: targetSchema, path, getModel }, value);
1727
+ const newValue = await recurse(
1728
+ visitor2,
1729
+ { schema: targetSchema, path, getModel, parent },
1730
+ value
1731
+ );
1710
1732
  set(key, newValue);
1711
1733
  });
1712
1734
  const traverseQueryFilters = fp.curry(filters.traverse);
@@ -1794,66 +1816,91 @@ const sort = traverseFactory().intercept(
1794
1816
  get(key, data) {
1795
1817
  return data[key];
1796
1818
  }
1797
- })).onRelation(async ({ key, value, attribute, visitor: visitor2, path, getModel }, { set, recurse }) => {
1798
- const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
1799
- if (isMorphRelation) {
1800
- return;
1819
+ })).onRelation(
1820
+ async ({ key, value, attribute, visitor: visitor2, path, getModel, schema }, { set, recurse }) => {
1821
+ const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
1822
+ if (isMorphRelation) {
1823
+ return;
1824
+ }
1825
+ const parent = { key, path, schema, attribute };
1826
+ const targetSchemaUID = attribute.target;
1827
+ const targetSchema = getModel(targetSchemaUID);
1828
+ const newValue = await recurse(
1829
+ visitor2,
1830
+ { schema: targetSchema, path, getModel, parent },
1831
+ value
1832
+ );
1833
+ set(key, newValue);
1801
1834
  }
1802
- const targetSchemaUID = attribute.target;
1803
- const targetSchema = getModel(targetSchemaUID);
1804
- const newValue = await recurse(visitor2, { schema: targetSchema, path, getModel }, value);
1805
- set(key, newValue);
1806
- }).onMedia(async ({ key, path, visitor: visitor2, value, getModel }, { recurse, set }) => {
1835
+ ).onMedia(async ({ key, path, schema, attribute, visitor: visitor2, value, getModel }, { recurse, set }) => {
1836
+ const parent = { key, path, schema, attribute };
1807
1837
  const targetSchemaUID = "plugin::upload.file";
1808
1838
  const targetSchema = getModel(targetSchemaUID);
1809
- const newValue = await recurse(visitor2, { schema: targetSchema, path, getModel }, value);
1810
- set(key, newValue);
1811
- }).onComponent(async ({ key, value, visitor: visitor2, path, attribute, getModel }, { recurse, set }) => {
1812
- const targetSchema = getModel(attribute.component);
1813
- const newValue = await recurse(visitor2, { schema: targetSchema, path, getModel }, value);
1839
+ const newValue = await recurse(
1840
+ visitor2,
1841
+ { schema: targetSchema, path, getModel, parent },
1842
+ value
1843
+ );
1814
1844
  set(key, newValue);
1815
- });
1845
+ }).onComponent(
1846
+ async ({ key, value, visitor: visitor2, path, schema, attribute, getModel }, { recurse, set }) => {
1847
+ const parent = { key, path, schema, attribute };
1848
+ const targetSchema = getModel(attribute.component);
1849
+ const newValue = await recurse(
1850
+ visitor2,
1851
+ { schema: targetSchema, path, getModel, parent },
1852
+ value
1853
+ );
1854
+ set(key, newValue);
1855
+ }
1856
+ );
1816
1857
  const traverseQuerySort = fp.curry(sort.traverse);
1817
1858
  const isKeyword = (keyword) => {
1818
1859
  return ({ key, attribute }) => {
1819
1860
  return !attribute && keyword === key;
1820
1861
  };
1821
1862
  };
1863
+ const isWildcard = (value) => value === "*";
1864
+ const isPopulateString = (value) => {
1865
+ return fp.isString(value) && !isWildcard(value);
1866
+ };
1822
1867
  const isStringArray$1 = (value) => fp.isArray(value) && value.every(fp.isString);
1823
1868
  const isObj = (value) => fp.isObject(value);
1824
- const populate = traverseFactory().intercept(isStringArray$1, async (visitor2, options, populate2, { recurse }) => {
1825
- const visitedPopulate = await Promise.all(
1826
- populate2.map((nestedPopulate) => recurse(visitor2, options, nestedPopulate))
1869
+ const populate = traverseFactory().intercept(isPopulateString, async (visitor2, options, populate2, { recurse }) => {
1870
+ const populateObject = pathsToObjectPopulate([populate2]);
1871
+ const traversedPopulate = await recurse(visitor2, options, populateObject);
1872
+ const [result] = objectPopulateToPaths(traversedPopulate);
1873
+ return result;
1874
+ }).intercept(isStringArray$1, async (visitor2, options, populate2, { recurse }) => {
1875
+ const paths = await Promise.all(
1876
+ populate2.map((subClause) => recurse(visitor2, options, subClause))
1827
1877
  );
1828
- return visitedPopulate.filter((item) => !fp.isNil(item));
1829
- }).parse(
1830
- (value) => value === "*",
1831
- () => ({
1832
- /**
1833
- * Since value is '*', we don't need to transform it
1834
- */
1835
- transform: fp.identity,
1836
- /**
1837
- * '*' isn't a key/value structure, so regardless
1838
- * of the given key, it returns the data ('*')
1839
- */
1840
- get: (_key, data) => data,
1841
- /**
1842
- * '*' isn't a key/value structure, so regardless
1843
- * of the given `key`, use `value` as the new `data`
1844
- */
1845
- set: (_key, value) => value,
1846
- /**
1847
- * '*' isn't a key/value structure, but we need to simulate at least one to enable
1848
- * the data traversal. We're using '' since it represents a falsy string value
1849
- */
1850
- keys: fp.constant([""]),
1851
- /**
1852
- * Removing '*' means setting it to undefined, regardless of the given key
1853
- */
1854
- remove: fp.constant(void 0)
1855
- })
1856
- ).parse(fp.isString, () => {
1878
+ return paths.filter((item) => !fp.isNil(item));
1879
+ }).parse(isWildcard, () => ({
1880
+ /**
1881
+ * Since value is '*', we don't need to transform it
1882
+ */
1883
+ transform: fp.identity,
1884
+ /**
1885
+ * '*' isn't a key/value structure, so regardless
1886
+ * of the given key, it returns the data ('*')
1887
+ */
1888
+ get: (_key, data) => data,
1889
+ /**
1890
+ * '*' isn't a key/value structure, so regardless
1891
+ * of the given `key`, use `value` as the new `data`
1892
+ */
1893
+ set: (_key, value) => value,
1894
+ /**
1895
+ * '*' isn't a key/value structure, but we need to simulate at least one to enable
1896
+ * the data traversal. We're using '' since it represents a falsy string value
1897
+ */
1898
+ keys: fp.constant([""]),
1899
+ /**
1900
+ * Removing '*' means setting it to undefined, regardless of the given key
1901
+ */
1902
+ remove: fp.constant(void 0)
1903
+ })).parse(fp.isString, () => {
1857
1904
  const tokenize = fp.split(".");
1858
1905
  const recompose = fp.join(".");
1859
1906
  return {
@@ -1898,64 +1945,127 @@ const populate = traverseFactory().intercept(isStringArray$1, async (visitor2, o
1898
1945
  }).on(
1899
1946
  // Handle recursion on populate."populate"
1900
1947
  isKeyword("populate"),
1901
- async ({ key, visitor: visitor2, path, value, schema, getModel }, { set, recurse }) => {
1902
- const newValue = await recurse(visitor2, { schema, path, getModel }, value);
1948
+ async ({ key, visitor: visitor2, path, value, schema, getModel, attribute }, { set, recurse }) => {
1949
+ const parent = { key, path, schema, attribute };
1950
+ const newValue = await recurse(visitor2, { schema, path, getModel, parent }, value);
1903
1951
  set(key, newValue);
1904
1952
  }
1905
- ).on(isKeyword("on"), async ({ key, visitor: visitor2, path, value, getModel }, { set, recurse }) => {
1906
- const newOn = {};
1907
- if (!isObj(value)) {
1908
- return;
1909
- }
1910
- for (const [uid, subPopulate] of Object.entries(value)) {
1911
- const model = getModel(uid);
1912
- const newPath = { ...path, raw: `${path.raw}[${uid}]` };
1913
- newOn[uid] = await recurse(visitor2, { schema: model, path: newPath, getModel }, subPopulate);
1953
+ ).on(
1954
+ isKeyword("on"),
1955
+ async ({ key, visitor: visitor2, path, value, getModel, parent }, { set, recurse }) => {
1956
+ const newOn = {};
1957
+ if (!isObj(value)) {
1958
+ return;
1959
+ }
1960
+ for (const [uid, subPopulate] of Object.entries(value)) {
1961
+ const model = getModel(uid);
1962
+ const newPath = { ...path, raw: `${path.raw}[${uid}]` };
1963
+ newOn[uid] = await recurse(
1964
+ visitor2,
1965
+ { schema: model, path: newPath, getModel, parent },
1966
+ subPopulate
1967
+ );
1968
+ }
1969
+ set(key, newOn);
1914
1970
  }
1915
- set(key, newOn);
1916
- }).onRelation(
1971
+ ).onRelation(
1917
1972
  async ({ key, value, attribute, visitor: visitor2, path, schema, getModel }, { set, recurse }) => {
1918
1973
  if (fp.isNil(value)) {
1919
1974
  return;
1920
1975
  }
1976
+ const parent = { key, path, schema, attribute };
1921
1977
  if (isMorphToRelationalAttribute(attribute)) {
1922
1978
  if (!fp.isObject(value) || !("on" in value && fp.isObject(value?.on))) {
1923
1979
  return;
1924
1980
  }
1925
- const newValue2 = await recurse(visitor2, { schema, path, getModel }, { on: value?.on });
1981
+ const newValue2 = await recurse(
1982
+ visitor2,
1983
+ { schema, path, getModel, parent },
1984
+ { on: value?.on }
1985
+ );
1926
1986
  set(key, newValue2);
1927
1987
  return;
1928
1988
  }
1929
1989
  const targetSchemaUID = attribute.target;
1930
1990
  const targetSchema = getModel(targetSchemaUID);
1931
- const newValue = await recurse(visitor2, { schema: targetSchema, path, getModel }, value);
1991
+ const newValue = await recurse(
1992
+ visitor2,
1993
+ { schema: targetSchema, path, getModel, parent },
1994
+ value
1995
+ );
1932
1996
  set(key, newValue);
1933
1997
  }
1934
- ).onMedia(async ({ key, path, visitor: visitor2, value, getModel }, { recurse, set }) => {
1998
+ ).onMedia(async ({ key, path, schema, attribute, visitor: visitor2, value, getModel }, { recurse, set }) => {
1935
1999
  if (fp.isNil(value)) {
1936
2000
  return;
1937
2001
  }
2002
+ const parent = { key, path, schema, attribute };
1938
2003
  const targetSchemaUID = "plugin::upload.file";
1939
2004
  const targetSchema = getModel(targetSchemaUID);
1940
- const newValue = await recurse(visitor2, { schema: targetSchema, path, getModel }, value);
1941
- set(key, newValue);
1942
- }).onComponent(async ({ key, value, visitor: visitor2, path, attribute, getModel }, { recurse, set }) => {
1943
- if (fp.isNil(value)) {
1944
- return;
1945
- }
1946
- const targetSchema = getModel(attribute.component);
1947
- const newValue = await recurse(visitor2, { schema: targetSchema, path, getModel }, value);
2005
+ const newValue = await recurse(
2006
+ visitor2,
2007
+ { schema: targetSchema, path, getModel, parent },
2008
+ value
2009
+ );
1948
2010
  set(key, newValue);
1949
- }).onDynamicZone(async ({ key, value, schema, visitor: visitor2, path, getModel }, { set, recurse }) => {
1950
- if (fp.isNil(value) || !fp.isObject(value)) {
1951
- return;
2011
+ }).onComponent(
2012
+ async ({ key, value, schema, visitor: visitor2, path, attribute, getModel }, { recurse, set }) => {
2013
+ if (fp.isNil(value)) {
2014
+ return;
2015
+ }
2016
+ const parent = { key, path, schema, attribute };
2017
+ const targetSchema = getModel(attribute.component);
2018
+ const newValue = await recurse(
2019
+ visitor2,
2020
+ { schema: targetSchema, path, getModel, parent },
2021
+ value
2022
+ );
2023
+ set(key, newValue);
1952
2024
  }
1953
- if ("on" in value && value.on) {
1954
- const newOn = await recurse(visitor2, { schema, path, getModel }, { on: value.on });
1955
- set(key, newOn);
2025
+ ).onDynamicZone(
2026
+ async ({ key, value, schema, visitor: visitor2, path, attribute, getModel }, { set, recurse }) => {
2027
+ if (fp.isNil(value) || !fp.isObject(value)) {
2028
+ return;
2029
+ }
2030
+ const parent = { key, path, schema, attribute };
2031
+ if ("on" in value && value.on) {
2032
+ const newOn = await recurse(visitor2, { schema, path, getModel, parent }, { on: value.on });
2033
+ set(key, newOn);
2034
+ }
1956
2035
  }
1957
- });
2036
+ );
1958
2037
  const traverseQueryPopulate = fp.curry(populate.traverse);
2038
+ const objectPopulateToPaths = (input) => {
2039
+ const paths = [];
2040
+ function traverse(currentObj, parentPath) {
2041
+ for (const [key, value] of Object.entries(currentObj)) {
2042
+ const currentPath = parentPath ? `${parentPath}.${key}` : key;
2043
+ if (value === true) {
2044
+ paths.push(currentPath);
2045
+ } else {
2046
+ traverse(value.populate, currentPath);
2047
+ }
2048
+ }
2049
+ }
2050
+ traverse(input, "");
2051
+ return paths;
2052
+ };
2053
+ const pathsToObjectPopulate = (input) => {
2054
+ const result = {};
2055
+ function traverse(object, keys) {
2056
+ const [first2, ...rest] = keys;
2057
+ if (rest.length === 0) {
2058
+ object[first2] = true;
2059
+ } else {
2060
+ if (!object[first2] || typeof object[first2] === "boolean") {
2061
+ object[first2] = { populate: {} };
2062
+ }
2063
+ traverse(object[first2].populate, rest);
2064
+ }
2065
+ }
2066
+ input.forEach((clause) => traverse(result, clause.split(".")));
2067
+ return result;
2068
+ };
1959
2069
  const isStringArray = (value) => {
1960
2070
  return fp.isArray(value) && value.every(fp.isString);
1961
2071
  };
@@ -2101,21 +2211,22 @@ const defaultSanitizePopulate = fp.curry((ctx, populate2) => {
2101
2211
  }
2102
2212
  return pipe(
2103
2213
  traverseQueryPopulate(visitor$4, ctx),
2104
- traverseQueryPopulate(async ({ key, value, schema, attribute, getModel }, { set }) => {
2214
+ traverseQueryPopulate(async ({ key, value, schema, attribute, getModel, path }, { set }) => {
2105
2215
  if (attribute) {
2106
2216
  return;
2107
2217
  }
2218
+ const parent = { key, path, schema, attribute };
2108
2219
  if (key === "sort") {
2109
- set(key, await defaultSanitizeSort({ schema, getModel }, value));
2220
+ set(key, await defaultSanitizeSort({ schema, getModel, parent }, value));
2110
2221
  }
2111
2222
  if (key === "filters") {
2112
- set(key, await defaultSanitizeFilters({ schema, getModel }, value));
2223
+ set(key, await defaultSanitizeFilters({ schema, getModel, parent }, value));
2113
2224
  }
2114
2225
  if (key === "fields") {
2115
- set(key, await defaultSanitizeFields({ schema, getModel }, value));
2226
+ set(key, await defaultSanitizeFields({ schema, getModel, parent }, value));
2116
2227
  }
2117
2228
  if (key === "populate") {
2118
- set(key, await defaultSanitizePopulate({ schema, getModel }, value));
2229
+ set(key, await defaultSanitizePopulate({ schema, getModel, parent }, value));
2119
2230
  }
2120
2231
  }, ctx),
2121
2232
  // Remove private fields
@@ -2468,12 +2579,6 @@ const index$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
2468
2579
  throwUnrecognizedFields
2469
2580
  }, Symbol.toStringTag, { value: "Module" }));
2470
2581
  const { ID_ATTRIBUTE: ID_ATTRIBUTE$1, DOC_ID_ATTRIBUTE: DOC_ID_ATTRIBUTE$1 } = constants$1;
2471
- const throwPasswords = (ctx) => async (entity) => {
2472
- if (!ctx.schema) {
2473
- throw new Error("Missing schema in throwPasswords");
2474
- }
2475
- return traverseEntity$1(visitor$3, ctx, entity);
2476
- };
2477
2582
  const FILTER_TRAVERSALS = [
2478
2583
  "nonAttributesOperators",
2479
2584
  "dynamicZones",
@@ -2622,110 +2727,118 @@ const validatePopulate = asyncCurry(
2622
2727
  }
2623
2728
  const functionsToApply = [];
2624
2729
  functionsToApply.push(
2625
- traverseQueryPopulate(async ({ key, path, value, schema, attribute, getModel }, { set }) => {
2626
- if (attribute) {
2627
- const isPopulatableAttribute = ["relation", "dynamiczone", "component", "media"].includes(
2628
- attribute.type
2629
- );
2630
- if (!isPopulatableAttribute) {
2631
- throwInvalidKey({ key, path: path.raw });
2730
+ traverseQueryPopulate(
2731
+ async ({ key, path, value, schema, attribute, getModel, parent }, { set }) => {
2732
+ if (!parent?.attribute && attribute) {
2733
+ const isPopulatableAttribute = [
2734
+ "relation",
2735
+ "dynamiczone",
2736
+ "component",
2737
+ "media"
2738
+ ].includes(attribute.type);
2739
+ if (!isPopulatableAttribute) {
2740
+ throwInvalidKey({ key, path: path.raw });
2741
+ }
2742
+ return;
2632
2743
  }
2633
- return;
2634
- }
2635
- if (key === "on") {
2636
- if (!fp.isObject(value)) {
2637
- return throwInvalidKey({ key, path: path.raw });
2744
+ if (key === "on") {
2745
+ if (!fp.isObject(value)) {
2746
+ return throwInvalidKey({ key, path: path.raw });
2747
+ }
2748
+ const targets = Object.keys(value);
2749
+ for (const target of targets) {
2750
+ const model = getModel(target);
2751
+ if (!model) {
2752
+ throwInvalidKey({ key: target, path: `${path.raw}.${target}` });
2753
+ }
2754
+ }
2755
+ return;
2638
2756
  }
2639
- const targets = Object.keys(value);
2640
- for (const target of targets) {
2641
- const model = getModel(target);
2642
- if (!model) {
2643
- throwInvalidKey({ key: target, path: `${path.raw}.${target}` });
2757
+ if (key === "" && value === "*") {
2758
+ return;
2759
+ }
2760
+ if (key === "count") {
2761
+ try {
2762
+ parseType({ type: "boolean", value });
2763
+ return;
2764
+ } catch {
2765
+ throwInvalidKey({ key, path: path.attribute });
2644
2766
  }
2645
2767
  }
2646
- return;
2647
- }
2648
- if (key === "" && value === "*") {
2649
- return;
2650
- }
2651
- if (key === "count") {
2652
2768
  try {
2653
- parseType({ type: "boolean", value });
2769
+ parseType({ type: "boolean", value: key });
2654
2770
  return;
2655
2771
  } catch {
2772
+ }
2773
+ if (key === "sort") {
2774
+ set(
2775
+ key,
2776
+ await validateSort(
2777
+ {
2778
+ schema,
2779
+ getModel
2780
+ },
2781
+ value,
2782
+ // pass the sort value
2783
+ includes?.sort || SORT_TRAVERSALS
2784
+ )
2785
+ );
2786
+ return;
2787
+ }
2788
+ if (key === "filters") {
2789
+ set(
2790
+ key,
2791
+ await validateFilters(
2792
+ {
2793
+ schema,
2794
+ getModel
2795
+ },
2796
+ value,
2797
+ // pass the filters value
2798
+ includes?.filters || FILTER_TRAVERSALS
2799
+ )
2800
+ );
2801
+ return;
2802
+ }
2803
+ if (key === "fields") {
2804
+ set(
2805
+ key,
2806
+ await validateFields(
2807
+ {
2808
+ schema,
2809
+ getModel
2810
+ },
2811
+ value,
2812
+ // pass the fields value
2813
+ includes?.fields || FIELDS_TRAVERSALS
2814
+ )
2815
+ );
2816
+ return;
2817
+ }
2818
+ if (key === "populate") {
2819
+ set(
2820
+ key,
2821
+ await validatePopulate(
2822
+ {
2823
+ schema,
2824
+ getModel,
2825
+ parent: { key, path, schema, attribute },
2826
+ path
2827
+ },
2828
+ value,
2829
+ // pass the nested populate value
2830
+ includes
2831
+ // pass down the same includes object
2832
+ )
2833
+ );
2834
+ return;
2835
+ }
2836
+ if (includes?.populate?.includes("nonAttributesOperators")) {
2656
2837
  throwInvalidKey({ key, path: path.attribute });
2657
2838
  }
2658
- }
2659
- try {
2660
- parseType({ type: "boolean", value: key });
2661
- return;
2662
- } catch {
2663
- }
2664
- if (key === "sort") {
2665
- set(
2666
- key,
2667
- await validateSort(
2668
- {
2669
- schema,
2670
- getModel
2671
- },
2672
- value,
2673
- // pass the sort value
2674
- includes?.sort || SORT_TRAVERSALS
2675
- )
2676
- );
2677
- return;
2678
- }
2679
- if (key === "filters") {
2680
- set(
2681
- key,
2682
- await validateFilters(
2683
- {
2684
- schema,
2685
- getModel
2686
- },
2687
- value,
2688
- // pass the filters value
2689
- includes?.filters || FILTER_TRAVERSALS
2690
- )
2691
- );
2692
- return;
2693
- }
2694
- if (key === "fields") {
2695
- set(
2696
- key,
2697
- await validateFields(
2698
- {
2699
- schema,
2700
- getModel
2701
- },
2702
- value,
2703
- // pass the fields value
2704
- includes?.fields || FIELDS_TRAVERSALS
2705
- )
2706
- );
2707
- return;
2708
- }
2709
- if (key === "populate") {
2710
- set(
2711
- key,
2712
- await validatePopulate(
2713
- {
2714
- schema,
2715
- getModel
2716
- },
2717
- value,
2718
- // pass the nested populate value
2719
- includes
2720
- // pass down the same includes object
2721
- )
2722
- );
2723
- return;
2724
- }
2725
- if (includes?.populate?.includes("nonAttributesOperators")) {
2726
- throwInvalidKey({ key, path: path.attribute });
2727
- }
2728
- }, ctx)
2839
+ },
2840
+ ctx
2841
+ )
2729
2842
  );
2730
2843
  if (includes?.populate?.includes("private")) {
2731
2844
  functionsToApply.push(traverseQueryPopulate(visitor$2, ctx));
@@ -2757,7 +2870,6 @@ const validators = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePr
2757
2870
  defaultValidateFilters,
2758
2871
  defaultValidatePopulate,
2759
2872
  defaultValidateSort,
2760
- throwPasswords,
2761
2873
  validateFields,
2762
2874
  validateFilters,
2763
2875
  validatePopulate,