@strapi/utils 5.0.0-beta.8 → 5.0.0-rc.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/LICENSE +18 -3
- 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
package/LICENSE
CHANGED
|
@@ -2,7 +2,21 @@ Copyright (c) 2015-present Strapi Solutions SAS
|
|
|
2
2
|
|
|
3
3
|
Portions of the Strapi software are licensed as follows:
|
|
4
4
|
|
|
5
|
-
* All software that resides under an "ee/" directory (the “EE Software”), if that directory exists, is licensed under the license defined
|
|
5
|
+
* All software that resides under an "ee/" directory (the “EE Software”), if that directory exists, is licensed under the license defined below.
|
|
6
|
+
|
|
7
|
+
Enterprise License
|
|
8
|
+
|
|
9
|
+
If you or the company you represent has entered into a written agreement referencing the Enterprise Edition of the Strapi source code available at
|
|
10
|
+
https://github.com/strapi/strapi, then such agreement applies to your use of the Enterprise Edition of the Strapi Software. If you or the company you
|
|
11
|
+
represent is using the Enterprise Edition of the Strapi Software in connection with a subscription to our cloud offering, then the agreement you have
|
|
12
|
+
agreed to with respect to our cloud offering and the licenses included in such agreement apply to your use of the Enterprise Edition of the Strapi Software.
|
|
13
|
+
Otherwise, the Strapi Enterprise Software License Agreement (found here https://strapi.io/enterprise-terms) applies to your use of the Enterprise Edition of the Strapi Software.
|
|
14
|
+
|
|
15
|
+
BY ACCESSING OR USING THE ENTERPRISE EDITION OF THE STRAPI SOFTWARE, YOU ARE AGREEING TO BE BOUND BY THE RELEVANT REFERENCED AGREEMENT.
|
|
16
|
+
IF YOU ARE NOT AUTHORIZED TO ACCEPT THESE TERMS ON BEHALF OF THE COMPANY YOU REPRESENT OR IF YOU DO NOT AGREE TO ALL OF THE RELEVANT TERMS AND CONDITIONS REFERENCED AND YOU
|
|
17
|
+
HAVE NOT OTHERWISE EXECUTED A WRITTEN AGREEMENT WITH STRAPI, YOU ARE NOT AUTHORIZED TO ACCESS OR USE OR ALLOW ANY USER TO ACCESS OR USE ANY PART OF
|
|
18
|
+
THE ENTERPRISE EDITION OF THE STRAPI SOFTWARE. YOUR ACCESS RIGHTS ARE CONDITIONAL ON YOUR CONSENT TO THE RELEVANT REFERENCED TERMS TO THE EXCLUSION OF ALL OTHER TERMS;
|
|
19
|
+
IF THE RELEVANT REFERENCED TERMS ARE CONSIDERED AN OFFER BY YOU, ACCEPTANCE IS EXPRESSLY LIMITED TO THE RELEVANT REFERENCED TERMS.
|
|
6
20
|
|
|
7
21
|
* All software outside of the above-mentioned directories or restrictions above is available under the "MIT Expat" license as set forth below.
|
|
8
22
|
|
|
@@ -18,5 +32,6 @@ furnished to do so, subject to the following conditions:
|
|
|
18
32
|
The above copyright notice and this permission notice shall be included in all
|
|
19
33
|
copies or substantial portions of the Software.
|
|
20
34
|
|
|
21
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
-
|
|
35
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
36
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
37
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -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,CAAC;IACxD,EAAE,CAAC,EAAE,wBAAwB,CAAC;IAC9B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,GAAG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B,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 }) => {
|