@strapi/utils
Advanced tools
Comparing version 4.3.6 to 4.3.7
@@ -109,3 +109,17 @@ 'use strict'; | ||
}; | ||
const isMediaAttribute = (attribute) => attribute.type === 'media'; | ||
const isRelationalAttribute = (attribute) => attribute.type === 'relation'; | ||
const isComponentAttribute = (attribute) => ['component', 'dynamiczone'].includes(attribute.type); | ||
const getComponentAttributes = (schema) => { | ||
return _.reduce( | ||
schema.attributes, | ||
(acc, attr, attrName) => { | ||
if (isComponentAttribute(attr)) acc.push(attrName); | ||
return acc; | ||
}, | ||
[] | ||
); | ||
}; | ||
const getScalarAttributes = (schema) => { | ||
@@ -122,6 +136,2 @@ return _.reduce( | ||
const isMediaAttribute = (attribute) => attribute.type === 'media'; | ||
const isRelationalAttribute = (attribute) => attribute.type === 'relation'; | ||
const isComponentAttribute = (attribute) => ['component', 'dynamiczone'].includes(attribute.type); | ||
/** | ||
@@ -157,2 +167,3 @@ * Checks if an attribute is of type `type` | ||
getNonWritableAttributes, | ||
getComponentAttributes, | ||
getScalarAttributes, | ||
@@ -159,0 +170,0 @@ getWritableAttributes, |
@@ -177,4 +177,10 @@ /* eslint-disable max-classes-per-file */ | ||
.map((uid) => strapi.getModel(uid)) | ||
.map((schema) => convertNestedPopulate(subPopulate, schema)); | ||
.map((schema) => convertNestedPopulate(subPopulate, schema)) | ||
.map((populate) => (populate === true ? {} : populate)) // cast boolean to empty object to avoid merging issues | ||
.filter((populate) => populate !== false); | ||
if (isEmpty(populates)) { | ||
return acc; | ||
} | ||
return { | ||
@@ -207,5 +213,11 @@ ...acc, | ||
const populateObject = convertNestedPopulate(subPopulate, targetSchema); | ||
if (!populateObject) { | ||
return acc; | ||
} | ||
return { | ||
...acc, | ||
[key]: convertNestedPopulate(subPopulate, targetSchema), | ||
[key]: populateObject, | ||
}; | ||
@@ -216,4 +228,4 @@ }, {}); | ||
const convertNestedPopulate = (subPopulate, schema) => { | ||
if (subPopulate === '*') { | ||
return true; | ||
if (_.isString(subPopulate)) { | ||
return parseType({ type: 'boolean', value: subPopulate, forceCast: true }); | ||
} | ||
@@ -220,0 +232,0 @@ |
{ | ||
"name": "@strapi/utils", | ||
"version": "4.3.6", | ||
"version": "4.3.7", | ||
"description": "Shared utilities for the Strapi packages", | ||
@@ -48,3 +48,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "4c6e67c4934580ed051a2afb83e6fc8f64f3a5b5" | ||
"gitHead": "73f523b98322cea8992c72977b94a73a624d2e79" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
69600
2086