@strapi/utils 5.0.0-beta.8 → 5.0.0-beta.9
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/convert-query-params.d.ts.map +1 -1
- package/dist/index.js +42 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -51
- package/dist/index.mjs.map +1 -1
- package/dist/traverse/query-populate.d.ts.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert-query-params.d.ts","sourceRoot":"","sources":["../src/convert-query-params.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"convert-query-params.d.ts","sourceRoot":"","sources":["../src/convert-query-params.ts"],"names":[],"mappings":"AA4BA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAKhC,KAAK,SAAS,GAAG,KAAK,GAAG,MAAM,CAAC;AAEhC,MAAM,WAAW,OAAO;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC;CACpC;AAED,MAAM,WAAW,gBAAgB;IAC/B,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,gBAAgB,CAAC;CAC7C;AACD,KAAK,UAAU,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,gBAAgB,GAAG,gBAAgB,EAAE,CAAC;AAC5E,KAAK,YAAY,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC;AAEtC,KAAK,aAAa,GAAG,OAAO,CAAC;AAE7B,MAAM,WAAW,wBAAwB;IACvC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,GAAG,oBAAoB,CAAC;CAC/C;AACD,MAAM,WAAW,oBAAoB;IACnC,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,wBAAwB,C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G,CAAC;CACpB;AAED,KAAK,aAAa,GACd,OAAO,GACP,MAAM,EAAE,GACR;IACE,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAAC;CAC9B,CAAC;AAEN,MAAM,WAAW,KAAK;IACpB,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,KAAK,CAAC,EAAE,UAAU,CAAC;IAEnB,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAkCD,UAAU,kBAAkB;IAC1B,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,KAAK,GAAG,SAAS,CAAC;CAC9C;AAED,QAAA,MAAM,iBAAiB,iBAAkB,kBAAkB;gDAId,UAAU,KAAG,YAAY;kDAqEvB,OAAO,KAAG,MAAM;kDAahB,OAAO,KAAG,MAAM,GAAG,SAAS;mDAgE7D,cAAc,WACf,KAAK,qBAEb,aAAa;iDAyP4B,aAAa,WAAW,KAAK,KAAG,UAAU;+CAlC5C,YAAY,qBAAc,WAAW,GAAG,SAAS;gCAwIxD,MAAM,UAAU,MAAM,KAAG,KAAK;CAkElE,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1051,27 +1051,45 @@ const createTransformer = ({ getModel }) => {
|
|
|
1051
1051
|
}
|
|
1052
1052
|
throw new InvalidPopulateError();
|
|
1053
1053
|
};
|
|
1054
|
-
const
|
|
1054
|
+
const hasPopulateFragmentDefined = (populate2) => {
|
|
1055
1055
|
return typeof populate2 === "object" && "on" in populate2 && !fp.isNil(populate2.on);
|
|
1056
1056
|
};
|
|
1057
|
+
const hasCountDefined = (populate2) => {
|
|
1058
|
+
return typeof populate2 === "object" && "count" in populate2 && typeof populate2.count === "boolean";
|
|
1059
|
+
};
|
|
1057
1060
|
const convertPopulateObject = (populate2, schema) => {
|
|
1058
1061
|
if (!schema) {
|
|
1059
1062
|
return {};
|
|
1060
1063
|
}
|
|
1061
1064
|
const { attributes } = schema;
|
|
1062
1065
|
return Object.entries(populate2).reduce((acc, [key, subPopulate]) => {
|
|
1066
|
+
if (___namespace.default.isString(subPopulate)) {
|
|
1067
|
+
try {
|
|
1068
|
+
const subPopulateAsBoolean = parseType({ type: "boolean", value: subPopulate });
|
|
1069
|
+
return subPopulateAsBoolean === true ? { ...acc, [key]: true } : acc;
|
|
1070
|
+
} catch {
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1063
1073
|
if (___namespace.default.isBoolean(subPopulate)) {
|
|
1064
|
-
return { ...acc, [key]:
|
|
1074
|
+
return subPopulate === true ? { ...acc, [key]: true } : acc;
|
|
1065
1075
|
}
|
|
1066
1076
|
const attribute = attributes[key];
|
|
1067
1077
|
if (!attribute) {
|
|
1068
1078
|
return acc;
|
|
1069
1079
|
}
|
|
1070
|
-
const
|
|
1071
|
-
if (
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1080
|
+
const isMorphLikeRelationalAttribute = isDynamicZoneAttribute(attribute) || isMorphToRelationalAttribute(attribute);
|
|
1081
|
+
if (isMorphLikeRelationalAttribute) {
|
|
1082
|
+
const hasInvalidProperties = Object.keys(subPopulate).some(
|
|
1083
|
+
(key2) => !["on", "count"].includes(key2)
|
|
1084
|
+
);
|
|
1085
|
+
if (hasInvalidProperties) {
|
|
1086
|
+
throw new Error(
|
|
1087
|
+
`Invalid nested populate for ${schema.info?.singularName}.${key} (${schema.uid}). Expected a fragment ("on") or "count" but found ${JSON.stringify(subPopulate)}`
|
|
1088
|
+
);
|
|
1089
|
+
}
|
|
1090
|
+
const newSubPopulate = {};
|
|
1091
|
+
if (hasPopulateFragmentDefined(subPopulate)) {
|
|
1092
|
+
Object.assign(newSubPopulate, {
|
|
1075
1093
|
on: Object.entries(subPopulate.on).reduce(
|
|
1076
1094
|
(acc2, [type, typeSubPopulate]) => ({
|
|
1077
1095
|
...acc2,
|
|
@@ -1079,21 +1097,15 @@ const createTransformer = ({ getModel }) => {
|
|
|
1079
1097
|
}),
|
|
1080
1098
|
{}
|
|
1081
1099
|
)
|
|
1082
|
-
}
|
|
1083
|
-
}
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
const populates = attribute.components.map((uid) => getModel(uid)).map((schema2) => convertNestedPopulate(subPopulate, schema2)).map((populate22) => populate22 === true ? {} : populate22).filter((populate22) => populate22 !== false);
|
|
1087
|
-
if (fp.isEmpty(populates)) {
|
|
1088
|
-
return acc;
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1102
|
+
if (hasCountDefined(subPopulate)) {
|
|
1103
|
+
Object.assign(newSubPopulate, { count: subPopulate.count });
|
|
1089
1104
|
}
|
|
1090
|
-
return {
|
|
1091
|
-
...acc,
|
|
1092
|
-
[key]: fp.mergeAll(populates)
|
|
1093
|
-
};
|
|
1105
|
+
return { ...acc, [key]: newSubPopulate };
|
|
1094
1106
|
}
|
|
1095
|
-
if (
|
|
1096
|
-
|
|
1107
|
+
if (!isMorphLikeRelationalAttribute && hasPopulateFragmentDefined(subPopulate)) {
|
|
1108
|
+
throw new Error(`Using fragments is not permitted to populate "${key}" in "${schema.uid}"`);
|
|
1097
1109
|
}
|
|
1098
1110
|
let targetSchemaUID;
|
|
1099
1111
|
if (attribute.type === "relation") {
|
|
@@ -1849,7 +1861,8 @@ const populate = traverseFactory().intercept(isStringArray$1, async (visitor2, o
|
|
|
1849
1861
|
return;
|
|
1850
1862
|
}
|
|
1851
1863
|
const newValue2 = await recurse(visitor2, { schema, path, getModel }, { on: value?.on });
|
|
1852
|
-
set(key,
|
|
1864
|
+
set(key, newValue2);
|
|
1865
|
+
return;
|
|
1853
1866
|
}
|
|
1854
1867
|
const targetSchemaUID = attribute.target;
|
|
1855
1868
|
const targetSchema = getModel(targetSchemaUID);
|
|
@@ -1871,36 +1884,15 @@ const populate = traverseFactory().intercept(isStringArray$1, async (visitor2, o
|
|
|
1871
1884
|
const targetSchema = getModel(attribute.component);
|
|
1872
1885
|
const newValue = await recurse(visitor2, { schema: targetSchema, path, getModel }, value);
|
|
1873
1886
|
set(key, newValue);
|
|
1874
|
-
}).onDynamicZone(
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
return;
|
|
1878
|
-
}
|
|
1879
|
-
if (fp.isObject(value)) {
|
|
1880
|
-
const { components } = attribute;
|
|
1881
|
-
const newValue = {};
|
|
1882
|
-
let newProperties = fp.omit("on", value);
|
|
1883
|
-
for (const componentUID of components) {
|
|
1884
|
-
const componentSchema = getModel(componentUID);
|
|
1885
|
-
const properties = await recurse(
|
|
1886
|
-
visitor2,
|
|
1887
|
-
{ schema: componentSchema, path, getModel },
|
|
1888
|
-
value
|
|
1889
|
-
);
|
|
1890
|
-
newProperties = fp.merge(newProperties, properties);
|
|
1891
|
-
}
|
|
1892
|
-
Object.assign(newValue, newProperties);
|
|
1893
|
-
if ("on" in value && value.on) {
|
|
1894
|
-
const newOn = await recurse(visitor2, { schema, path, getModel }, { on: value.on });
|
|
1895
|
-
Object.assign(newValue, newOn);
|
|
1896
|
-
}
|
|
1897
|
-
set(key, newValue);
|
|
1898
|
-
} else {
|
|
1899
|
-
const newValue = await recurse(visitor2, { schema, path, getModel }, value);
|
|
1900
|
-
set(key, newValue);
|
|
1901
|
-
}
|
|
1887
|
+
}).onDynamicZone(async ({ key, value, schema, visitor: visitor2, path, getModel }, { set, recurse }) => {
|
|
1888
|
+
if (fp.isNil(value) || !fp.isObject(value)) {
|
|
1889
|
+
return;
|
|
1902
1890
|
}
|
|
1903
|
-
)
|
|
1891
|
+
if ("on" in value && value.on) {
|
|
1892
|
+
const newOn = await recurse(visitor2, { schema, path, getModel }, { on: value.on });
|
|
1893
|
+
set(key, newOn);
|
|
1894
|
+
}
|
|
1895
|
+
});
|
|
1904
1896
|
const traverseQueryPopulate = fp.curry(populate.traverse);
|
|
1905
1897
|
const isStringArray = (value) => fp.isArray(value) && value.every(fp.isString);
|
|
1906
1898
|
const fields = traverseFactory().intercept(isStringArray, async (visitor2, options, fields2, { recurse }) => {
|