@strapi/utils 4.1.2 → 4.1.4-alpha.1
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.
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Converts the standard Strapi REST query params to a more usable format for querying
|
|
5
5
|
* You can read more here: https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/rest-api.html#filters
|
|
6
6
|
*/
|
|
7
|
-
const { has, isEmpty, isObject, cloneDeep, get } = require('lodash/fp');
|
|
7
|
+
const { has, isEmpty, isObject, isPlainObject, cloneDeep, get } = require('lodash/fp');
|
|
8
8
|
const _ = require('lodash');
|
|
9
9
|
const parseType = require('./parse-type');
|
|
10
10
|
const contentTypesUtils = require('./content-types');
|
|
@@ -286,7 +286,7 @@ const convertFiltersQueryParams = (filters, schema) => {
|
|
|
286
286
|
};
|
|
287
287
|
|
|
288
288
|
const convertAndSanitizeFilters = (filters, schema) => {
|
|
289
|
-
if (!
|
|
289
|
+
if (!isPlainObject(filters)) {
|
|
290
290
|
return filters;
|
|
291
291
|
}
|
|
292
292
|
|
|
@@ -349,7 +349,7 @@ const convertAndSanitizeFilters = (filters, schema) => {
|
|
|
349
349
|
}
|
|
350
350
|
|
|
351
351
|
// Remove empty objects & arrays
|
|
352
|
-
if (
|
|
352
|
+
if (isPlainObject(filters[key]) && isEmpty(filters[key])) {
|
|
353
353
|
removeOperator(key);
|
|
354
354
|
}
|
|
355
355
|
}
|
package/lib/index.js
CHANGED
|
@@ -19,6 +19,8 @@ const {
|
|
|
19
19
|
stringEquals,
|
|
20
20
|
isKebabCase,
|
|
21
21
|
isCamelCase,
|
|
22
|
+
toRegressedEnumValue,
|
|
23
|
+
startsWithANumber,
|
|
22
24
|
} = require('./string-formatting');
|
|
23
25
|
const { removeUndefined } = require('./object-formatting');
|
|
24
26
|
const { getConfigUrls, getAbsoluteAdminUrl, getAbsoluteServerUrl } = require('./config');
|
|
@@ -47,6 +49,8 @@ module.exports = {
|
|
|
47
49
|
traverseEntity,
|
|
48
50
|
parseType,
|
|
49
51
|
nameToSlug,
|
|
52
|
+
toRegressedEnumValue,
|
|
53
|
+
startsWithANumber,
|
|
50
54
|
nameToCollectionName,
|
|
51
55
|
getCommonBeginning,
|
|
52
56
|
getConfigUrls,
|
package/lib/string-formatting.js
CHANGED
|
@@ -6,6 +6,13 @@ const nameToSlug = (name, options = { separator: '-' }) => slugify(name, options
|
|
|
6
6
|
|
|
7
7
|
const nameToCollectionName = name => slugify(name, { separator: '_' });
|
|
8
8
|
|
|
9
|
+
const toRegressedEnumValue = value =>
|
|
10
|
+
slugify(value, {
|
|
11
|
+
decamelize: false,
|
|
12
|
+
lowercase: false,
|
|
13
|
+
separator: '_',
|
|
14
|
+
});
|
|
15
|
+
|
|
9
16
|
const getCommonBeginning = (...strings) =>
|
|
10
17
|
_.takeWhile(strings[0], (char, index) => strings.every(string => string[index] === char)).join(
|
|
11
18
|
''
|
|
@@ -35,6 +42,7 @@ const stringIncludes = (arr, val) => arr.map(String).includes(String(val));
|
|
|
35
42
|
const stringEquals = (a, b) => String(a) === String(b);
|
|
36
43
|
const isCamelCase = value => /^[a-z][a-zA-Z0-9]+$/.test(value);
|
|
37
44
|
const isKebabCase = value => /^([a-z][a-z0-9]*)(-[a-z0-9]+)*$/.test(value);
|
|
45
|
+
const startsWithANumber = value => /^[0-9]/.test(value);
|
|
38
46
|
|
|
39
47
|
module.exports = {
|
|
40
48
|
nameToSlug,
|
|
@@ -46,4 +54,6 @@ module.exports = {
|
|
|
46
54
|
stringEquals,
|
|
47
55
|
isCamelCase,
|
|
48
56
|
isKebabCase,
|
|
57
|
+
toRegressedEnumValue,
|
|
58
|
+
startsWithANumber,
|
|
49
59
|
};
|
package/lib/traverse-entity.js
CHANGED
|
@@ -41,6 +41,7 @@ const traverseEntity = async (visitor, options, entity) => {
|
|
|
41
41
|
const isRelation = attribute.type === 'relation';
|
|
42
42
|
const isComponent = attribute.type === 'component';
|
|
43
43
|
const isDynamicZone = attribute.type === 'dynamiczone';
|
|
44
|
+
const isMedia = attribute.type === 'media';
|
|
44
45
|
|
|
45
46
|
if (isRelation) {
|
|
46
47
|
const isMorphRelation = attribute.relation.toLowerCase().startsWith('morph');
|
|
@@ -61,6 +62,22 @@ const traverseEntity = async (visitor, options, entity) => {
|
|
|
61
62
|
: await traverseTarget(value);
|
|
62
63
|
}
|
|
63
64
|
|
|
65
|
+
if (isMedia) {
|
|
66
|
+
const traverseTarget = entry => {
|
|
67
|
+
const targetSchemaUID = 'plugin::upload.file';
|
|
68
|
+
const targetSchema = strapi.getModel(targetSchemaUID);
|
|
69
|
+
|
|
70
|
+
const traverseOptions = { schema: targetSchema, path: newPath };
|
|
71
|
+
|
|
72
|
+
return traverseEntity(visitor, traverseOptions, entry);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// need to update copy
|
|
76
|
+
copy[key] = isArray(value)
|
|
77
|
+
? await Promise.all(value.map(traverseTarget))
|
|
78
|
+
: await traverseTarget(value);
|
|
79
|
+
}
|
|
80
|
+
|
|
64
81
|
if (isComponent) {
|
|
65
82
|
const targetSchema = strapi.getModel(attribute.component);
|
|
66
83
|
const traverseOptions = { schema: targetSchema, path: newPath };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/utils",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.4-alpha.1",
|
|
4
4
|
"description": "Shared utilities for the Strapi packages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"strapi",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"node": ">=12.22.0 <=16.x.x",
|
|
46
46
|
"npm": ">=6.0.0"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "28155df2bef16f415127fd6e65bd5f223f816d47"
|
|
49
49
|
}
|