@strapi/utils 4.14.5 → 4.15.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 +32 -42
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +32 -42
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -577,7 +577,7 @@ yup__namespace.addMethod(
|
|
|
577
577
|
function uniqueProperty(propertyName, message) {
|
|
578
578
|
return this.test("unique", message, function unique(list) {
|
|
579
579
|
const errors2 = [];
|
|
580
|
-
list
|
|
580
|
+
list?.forEach((element, index2) => {
|
|
581
581
|
const sameElements = list.filter(
|
|
582
582
|
(e) => fp.get(propertyName, e) === fp.get(propertyName, element)
|
|
583
583
|
);
|
|
@@ -769,13 +769,10 @@ const isDraft = (data, model) => hasDraftAndPublish(model) && ___default.default
|
|
|
769
769
|
const isSingleType = ({ kind = COLLECTION_TYPE }) => kind === SINGLE_TYPE;
|
|
770
770
|
const isCollectionType = ({ kind = COLLECTION_TYPE }) => kind === COLLECTION_TYPE;
|
|
771
771
|
const isKind = (kind) => (model) => model.kind === kind;
|
|
772
|
-
const getStoredPrivateAttributes = (model) =>
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
fp.getOr([], "options.privateAttributes", model)
|
|
777
|
-
);
|
|
778
|
-
};
|
|
772
|
+
const getStoredPrivateAttributes = (model) => fp.union(
|
|
773
|
+
strapi?.config?.get("api.responses.privateAttributes", []) ?? [],
|
|
774
|
+
fp.getOr([], "options.privateAttributes", model)
|
|
775
|
+
);
|
|
779
776
|
const getPrivateAttributes = (model) => {
|
|
780
777
|
return ___default.default.union(
|
|
781
778
|
getStoredPrivateAttributes(model),
|
|
@@ -783,22 +780,20 @@ const getPrivateAttributes = (model) => {
|
|
|
783
780
|
);
|
|
784
781
|
};
|
|
785
782
|
const isPrivateAttribute = (model, attributeName) => {
|
|
786
|
-
|
|
787
|
-
if (((_b = (_a = model == null ? void 0 : model.attributes) == null ? void 0 : _a[attributeName]) == null ? void 0 : _b.private) === true) {
|
|
783
|
+
if (model?.attributes?.[attributeName]?.private === true) {
|
|
788
784
|
return true;
|
|
789
785
|
}
|
|
790
786
|
return getStoredPrivateAttributes(model).includes(attributeName);
|
|
791
787
|
};
|
|
792
788
|
const isScalarAttribute = (attribute) => {
|
|
793
|
-
return !["media", "component", "relation", "dynamiczone"].includes(attribute
|
|
789
|
+
return !["media", "component", "relation", "dynamiczone"].includes(attribute?.type);
|
|
794
790
|
};
|
|
795
|
-
const isMediaAttribute = (attribute) =>
|
|
796
|
-
const isRelationalAttribute = (attribute) =>
|
|
797
|
-
const isComponentAttribute = (attribute) => ["component", "dynamiczone"].includes(attribute
|
|
798
|
-
const isDynamicZoneAttribute = (attribute) =>
|
|
791
|
+
const isMediaAttribute = (attribute) => attribute?.type === "media";
|
|
792
|
+
const isRelationalAttribute = (attribute) => attribute?.type === "relation";
|
|
793
|
+
const isComponentAttribute = (attribute) => ["component", "dynamiczone"].includes(attribute?.type);
|
|
794
|
+
const isDynamicZoneAttribute = (attribute) => attribute?.type === "dynamiczone";
|
|
799
795
|
const isMorphToRelationalAttribute = (attribute) => {
|
|
800
|
-
|
|
801
|
-
return isRelationalAttribute(attribute) && ((_b = (_a = attribute == null ? void 0 : attribute.relation) == null ? void 0 : _a.startsWith) == null ? void 0 : _b.call(_a, "morphTo"));
|
|
796
|
+
return isRelationalAttribute(attribute) && attribute?.relation?.startsWith?.("morphTo");
|
|
802
797
|
};
|
|
803
798
|
const getComponentAttributes = (schema) => {
|
|
804
799
|
return ___default.default.reduce(
|
|
@@ -1195,7 +1190,7 @@ const forEachAsync = async (array, func, options) => {
|
|
|
1195
1190
|
await pMap__default.default(array, func, options);
|
|
1196
1191
|
};
|
|
1197
1192
|
const visitor$7 = ({ key: key2, attribute }, { remove }) => {
|
|
1198
|
-
if (
|
|
1193
|
+
if (attribute?.type === "password") {
|
|
1199
1194
|
remove(key2);
|
|
1200
1195
|
}
|
|
1201
1196
|
};
|
|
@@ -1211,7 +1206,6 @@ const visitor$6 = ({ schema, key: key2, attribute }, { remove }) => {
|
|
|
1211
1206
|
const ACTIONS_TO_VERIFY$1 = ["find"];
|
|
1212
1207
|
const { CREATED_BY_ATTRIBUTE: CREATED_BY_ATTRIBUTE$1, UPDATED_BY_ATTRIBUTE: UPDATED_BY_ATTRIBUTE$1 } = constants$1;
|
|
1213
1208
|
const removeRestrictedRelations = (auth) => async ({ data, key: key2, attribute, schema }, { remove, set }) => {
|
|
1214
|
-
var _a;
|
|
1215
1209
|
if (!attribute) {
|
|
1216
1210
|
return;
|
|
1217
1211
|
}
|
|
@@ -1246,7 +1240,7 @@ const removeRestrictedRelations = (auth) => async ({ data, key: key2, attribute,
|
|
|
1246
1240
|
await handleMorphRelation();
|
|
1247
1241
|
return;
|
|
1248
1242
|
}
|
|
1249
|
-
if (isCreatorRelation &&
|
|
1243
|
+
if (isCreatorRelation && schema.options?.populateCreatorFields) {
|
|
1250
1244
|
return;
|
|
1251
1245
|
}
|
|
1252
1246
|
await handleRegularRelation();
|
|
@@ -1314,7 +1308,7 @@ const removeRestrictedFields = (restrictedFields = null) => ({ key: key2, path:
|
|
|
1314
1308
|
return;
|
|
1315
1309
|
}
|
|
1316
1310
|
const isRestrictedNested = restrictedFields.some(
|
|
1317
|
-
(allowedPath) => path
|
|
1311
|
+
(allowedPath) => path?.toString().startsWith(`${allowedPath}.`)
|
|
1318
1312
|
);
|
|
1319
1313
|
if (isRestrictedNested) {
|
|
1320
1314
|
remove(key2);
|
|
@@ -1457,24 +1451,23 @@ const traverseFactory = () => {
|
|
|
1457
1451
|
}
|
|
1458
1452
|
};
|
|
1459
1453
|
const traverse = async (visitor2, options, data) => {
|
|
1460
|
-
var _a, _b, _c;
|
|
1461
1454
|
const { path = DEFAULT_PATH, schema } = options ?? {};
|
|
1462
1455
|
for (const { predicate, handler } of state.interceptors) {
|
|
1463
1456
|
if (predicate(data)) {
|
|
1464
1457
|
return handler(visitor2, options, data, { recurse: traverse });
|
|
1465
1458
|
}
|
|
1466
1459
|
}
|
|
1467
|
-
const parser =
|
|
1468
|
-
const utils2 = parser
|
|
1460
|
+
const parser = state.parsers.find((parser2) => parser2.predicate(data))?.parser;
|
|
1461
|
+
const utils2 = parser?.(data);
|
|
1469
1462
|
if (!utils2) {
|
|
1470
1463
|
return data;
|
|
1471
1464
|
}
|
|
1472
1465
|
let out = utils2.transform(data);
|
|
1473
1466
|
const keys = utils2.keys(out);
|
|
1474
1467
|
for (const key2 of keys) {
|
|
1475
|
-
const attribute =
|
|
1468
|
+
const attribute = schema?.attributes?.[key2] ?? // FIX: Needed to not break existing behavior on the API.
|
|
1476
1469
|
// It looks for the attribute in the DB metadata when the key is in snake_case
|
|
1477
|
-
|
|
1470
|
+
schema?.attributes?.[strapi.db.metadata.get(schema?.uid).columnToAttribute[key2]];
|
|
1478
1471
|
const newPath = { ...path };
|
|
1479
1472
|
newPath.raw = fp.isNil(path.raw) ? key2 : `${path.raw}.${key2}`;
|
|
1480
1473
|
if (!fp.isNil(attribute)) {
|
|
@@ -1547,16 +1540,16 @@ const traverseFactory = () => {
|
|
|
1547
1540
|
return this;
|
|
1548
1541
|
},
|
|
1549
1542
|
onRelation(handler) {
|
|
1550
|
-
return this.onAttribute(({ attribute }) =>
|
|
1543
|
+
return this.onAttribute(({ attribute }) => attribute?.type === "relation", handler);
|
|
1551
1544
|
},
|
|
1552
1545
|
onMedia(handler) {
|
|
1553
|
-
return this.onAttribute(({ attribute }) =>
|
|
1546
|
+
return this.onAttribute(({ attribute }) => attribute?.type === "media", handler);
|
|
1554
1547
|
},
|
|
1555
1548
|
onComponent(handler) {
|
|
1556
|
-
return this.onAttribute(({ attribute }) =>
|
|
1549
|
+
return this.onAttribute(({ attribute }) => attribute?.type === "component", handler);
|
|
1557
1550
|
},
|
|
1558
1551
|
onDynamicZone(handler) {
|
|
1559
|
-
return this.onAttribute(({ attribute }) =>
|
|
1552
|
+
return this.onAttribute(({ attribute }) => attribute?.type === "dynamiczone", handler);
|
|
1560
1553
|
}
|
|
1561
1554
|
};
|
|
1562
1555
|
};
|
|
@@ -1736,8 +1729,7 @@ const populate = traverseFactory().intercept(isStringArray$2, async (visitor2, o
|
|
|
1736
1729
|
);
|
|
1737
1730
|
return visitedPopulate.filter((item) => !fp.isNil(item));
|
|
1738
1731
|
}).intercept(isWildCardConstant, (visitor2, options, _data, { recurse }) => {
|
|
1739
|
-
|
|
1740
|
-
const attributes = (_a = options.schema) == null ? void 0 : _a.attributes;
|
|
1732
|
+
const attributes = options.schema?.attributes;
|
|
1741
1733
|
if (!attributes) {
|
|
1742
1734
|
return "*";
|
|
1743
1735
|
}
|
|
@@ -1808,10 +1800,10 @@ const populate = traverseFactory().intercept(isStringArray$2, async (visitor2, o
|
|
|
1808
1800
|
return;
|
|
1809
1801
|
}
|
|
1810
1802
|
if (isMorphToRelationalAttribute(attribute)) {
|
|
1811
|
-
if (!fp.isObject(value2) || !("on" in value2 && fp.isObject(value2
|
|
1803
|
+
if (!fp.isObject(value2) || !("on" in value2 && fp.isObject(value2?.on))) {
|
|
1812
1804
|
return;
|
|
1813
1805
|
}
|
|
1814
|
-
const newValue2 = await recurse(visitor2, { schema, path }, { on: value2
|
|
1806
|
+
const newValue2 = await recurse(visitor2, { schema, path }, { on: value2?.on });
|
|
1815
1807
|
set(key2, { on: newValue2 });
|
|
1816
1808
|
}
|
|
1817
1809
|
const targetSchemaUID = attribute.target;
|
|
@@ -1940,12 +1932,11 @@ const isObjKey = (key2, obj2) => {
|
|
|
1940
1932
|
return key2 in obj2;
|
|
1941
1933
|
};
|
|
1942
1934
|
const isOperatorOfType = (type, key2, ignoreCase = false) => {
|
|
1943
|
-
var _a, _b;
|
|
1944
1935
|
if (ignoreCase) {
|
|
1945
|
-
return
|
|
1936
|
+
return OPERATORS_LOWERCASE[type]?.includes(key2.toLowerCase()) ?? false;
|
|
1946
1937
|
}
|
|
1947
1938
|
if (isObjKey(type, OPERATORS)) {
|
|
1948
|
-
return
|
|
1939
|
+
return OPERATORS[type]?.includes(key2) ?? false;
|
|
1949
1940
|
}
|
|
1950
1941
|
return false;
|
|
1951
1942
|
};
|
|
@@ -2224,7 +2215,7 @@ const throwInvalidParam = ({ key: key2 }) => {
|
|
|
2224
2215
|
throw new ValidationError(`Invalid parameter ${key2}`);
|
|
2225
2216
|
};
|
|
2226
2217
|
const visitor$3 = ({ key: key2, attribute }) => {
|
|
2227
|
-
if (
|
|
2218
|
+
if (attribute?.type === "password") {
|
|
2228
2219
|
throwInvalidParam({ key: key2 });
|
|
2229
2220
|
}
|
|
2230
2221
|
};
|
|
@@ -2240,7 +2231,6 @@ const visitor$2 = ({ schema, key: key2, attribute }) => {
|
|
|
2240
2231
|
const ACTIONS_TO_VERIFY = ["find"];
|
|
2241
2232
|
const { CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE } = constants$1;
|
|
2242
2233
|
const throwRestrictedRelations = (auth) => async ({ data, key: key2, attribute, schema }) => {
|
|
2243
|
-
var _a;
|
|
2244
2234
|
if (!attribute) {
|
|
2245
2235
|
return;
|
|
2246
2236
|
}
|
|
@@ -2269,7 +2259,7 @@ const throwRestrictedRelations = (auth) => async ({ data, key: key2, attribute,
|
|
|
2269
2259
|
await handleMorphRelation();
|
|
2270
2260
|
return;
|
|
2271
2261
|
}
|
|
2272
|
-
if (isCreatorRelation &&
|
|
2262
|
+
if (isCreatorRelation && schema.options?.populateCreatorFields) {
|
|
2273
2263
|
return;
|
|
2274
2264
|
}
|
|
2275
2265
|
await handleRegularRelation();
|
|
@@ -2335,7 +2325,7 @@ const throwRestrictedFields = (restrictedFields = null) => ({ key: key2, path: {
|
|
|
2335
2325
|
throwInvalidParam({ key: key2 });
|
|
2336
2326
|
}
|
|
2337
2327
|
const isRestrictedNested = restrictedFields.some(
|
|
2338
|
-
(allowedPath) => path
|
|
2328
|
+
(allowedPath) => path?.toString().startsWith(`${allowedPath}.`)
|
|
2339
2329
|
);
|
|
2340
2330
|
if (isRestrictedNested) {
|
|
2341
2331
|
throwInvalidParam({ key: key2 });
|
|
@@ -2828,7 +2818,7 @@ const convertAndSanitizeFilters = (filters2, schema) => {
|
|
|
2828
2818
|
}
|
|
2829
2819
|
const removeOperator = (operator) => delete filters2[operator];
|
|
2830
2820
|
for (const [key2, value2] of Object.entries(filters2)) {
|
|
2831
|
-
const attribute = fp.get(key2, schema
|
|
2821
|
+
const attribute = fp.get(key2, schema?.attributes);
|
|
2832
2822
|
const validKey = isOperator(key2) || isValidSchemaAttribute(key2, schema);
|
|
2833
2823
|
if (!validKey) {
|
|
2834
2824
|
removeOperator(key2);
|