@strapi/utils 4.3.5 → 4.3.8
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/lib/content-types.js +15 -4
- package/lib/convert-query-params.js +16 -4
- package/package.json +2 -2
package/lib/content-types.js
CHANGED
|
@@ -106,6 +106,20 @@ const isPrivateAttribute = (model = {}, attributeName) => {
|
|
|
106
106
|
const isScalarAttribute = (attribute) => {
|
|
107
107
|
return !['media', 'component', 'relation', 'dynamiczone'].includes(attribute.type);
|
|
108
108
|
};
|
|
109
|
+
const isMediaAttribute = (attribute) => attribute.type === 'media';
|
|
110
|
+
const isRelationalAttribute = (attribute) => attribute.type === 'relation';
|
|
111
|
+
const isComponentAttribute = (attribute) => ['component', 'dynamiczone'].includes(attribute.type);
|
|
112
|
+
|
|
113
|
+
const getComponentAttributes = (schema) => {
|
|
114
|
+
return _.reduce(
|
|
115
|
+
schema.attributes,
|
|
116
|
+
(acc, attr, attrName) => {
|
|
117
|
+
if (isComponentAttribute(attr)) acc.push(attrName);
|
|
118
|
+
return acc;
|
|
119
|
+
},
|
|
120
|
+
[]
|
|
121
|
+
);
|
|
122
|
+
};
|
|
109
123
|
|
|
110
124
|
const getScalarAttributes = (schema) => {
|
|
111
125
|
return _.reduce(
|
|
@@ -118,10 +132,6 @@ const getScalarAttributes = (schema) => {
|
|
|
118
132
|
);
|
|
119
133
|
};
|
|
120
134
|
|
|
121
|
-
const isMediaAttribute = (attribute) => attribute.type === 'media';
|
|
122
|
-
const isRelationalAttribute = (attribute) => attribute.type === 'relation';
|
|
123
|
-
const isComponentAttribute = (attribute) => ['component', 'dynamiczone'].includes(attribute.type);
|
|
124
|
-
|
|
125
135
|
/**
|
|
126
136
|
* Checks if an attribute is of type `type`
|
|
127
137
|
* @param {object} attribute
|
|
@@ -152,6 +162,7 @@ module.exports = {
|
|
|
152
162
|
isPrivateAttribute,
|
|
153
163
|
constants,
|
|
154
164
|
getNonWritableAttributes,
|
|
165
|
+
getComponentAttributes,
|
|
155
166
|
getScalarAttributes,
|
|
156
167
|
getWritableAttributes,
|
|
157
168
|
isWritableAttribute,
|
|
@@ -174,7 +174,13 @@ const convertPopulateObject = (populate, schema) => {
|
|
|
174
174
|
if (attribute.type === 'dynamiczone') {
|
|
175
175
|
const populates = attribute.components
|
|
176
176
|
.map((uid) => strapi.getModel(uid))
|
|
177
|
-
.map((schema) => convertNestedPopulate(subPopulate, schema))
|
|
177
|
+
.map((schema) => convertNestedPopulate(subPopulate, schema))
|
|
178
|
+
.map((populate) => (populate === true ? {} : populate)) // cast boolean to empty object to avoid merging issues
|
|
179
|
+
.filter((populate) => populate !== false);
|
|
180
|
+
|
|
181
|
+
if (isEmpty(populates)) {
|
|
182
|
+
return acc;
|
|
183
|
+
}
|
|
178
184
|
|
|
179
185
|
return {
|
|
180
186
|
...acc,
|
|
@@ -203,16 +209,22 @@ const convertPopulateObject = (populate, schema) => {
|
|
|
203
209
|
return acc;
|
|
204
210
|
}
|
|
205
211
|
|
|
212
|
+
const populateObject = convertNestedPopulate(subPopulate, targetSchema);
|
|
213
|
+
|
|
214
|
+
if (!populateObject) {
|
|
215
|
+
return acc;
|
|
216
|
+
}
|
|
217
|
+
|
|
206
218
|
return {
|
|
207
219
|
...acc,
|
|
208
|
-
[key]:
|
|
220
|
+
[key]: populateObject,
|
|
209
221
|
};
|
|
210
222
|
}, {});
|
|
211
223
|
};
|
|
212
224
|
|
|
213
225
|
const convertNestedPopulate = (subPopulate, schema) => {
|
|
214
|
-
if (subPopulate
|
|
215
|
-
return true;
|
|
226
|
+
if (_.isString(subPopulate)) {
|
|
227
|
+
return parseType({ type: 'boolean', value: subPopulate, forceCast: true });
|
|
216
228
|
}
|
|
217
229
|
|
|
218
230
|
if (_.isBoolean(subPopulate)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/utils",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.8",
|
|
4
4
|
"description": "Shared utilities for the Strapi packages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"strapi",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"node": ">=14.19.1 <=16.x.x",
|
|
46
46
|
"npm": ">=6.0.0"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "c44f21d5ba95d3f2fbba239cf241081dddd54dd7"
|
|
49
49
|
}
|