[FIX] strapi-v4 - data provider - deep data normalization
See original GitHub issueIs your feature request related to a problem? Please describe. Populated data from strapi-v4 data provider are not normalized, which makes hard to work with them via ts interfaces.
Describe the solution you’d like Use deep traversal like the one proposed here : https://forum.strapi.io/t/discussion-regarding-the-complex-response-structure-for-rest-graphql-developer-experience/13400/9
const normalize = (data) => {
const isObject = (data) =>
Object.prototype.toString.call(data) === '[object Object]'
const isArray = (data) =>
Object.prototype.toString.call(data) === '[object Array]'
const flatten = (data) => {
if (!data.attributes) return data
return {
id: data.id,
...data.attributes
}
}
if (isArray(data)) {
return data.map((item) => normalize(item))
}
if (isObject(data)) {
if (isArray(data.data)) {
data = [...data.data]
} else if (isObject(data.data)) {
data = flatten({ ...data.data })
} else if (data.data === null) {
data = null
} else {
data = flatten(data)
}
for (const key in data) {
data[key] = normalize(data[key])
}
return data
}
return data
}
Describe alternatives you’ve considered Alternative would be to normalize data after you get query data. This might be too late if you load it as useTable which expect slightly modified data already.
Additional context Read more at : https://forum.strapi.io/t/discussion-regarding-the-complex-response-structure-for-rest-graphql-developer-experience/13400
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (13 by maintainers)
Top Results From Across the Web
How to Improve Data Normalization in Healthcare
Healthcare data normalization begins when patient records are collected from various sources, including EHRs, lab systems, billing systems, ...
Read more >Data Normalization: Converting Raw Numbers Into Revenue
Data normalization is a rock-solid way to turn raw data into actionable insights. We explain why normalization is essential and how to ...
Read more >Normalization | Machine Learning - Google Developers
The goal of normalization is to transform features to be on a similar scale. This improves the performance and training stability of the ......
Read more >How, When, and Why Should You Normalize / Standardize ...
Normalization (Min-Max Scalar) : In this approach, the data is scaled to a fixed range — usually 0 to 1. In contrast to...
Read more >4 Levels of Data Normalization
Data normalization is a process in the development of clean data. Diving deeper, however, the meaning or goal of data normalization is twofold:....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey @lukassos 👋 ,
Thanks for your contribution. After this point, we will make a new release by making additions to what you have done. When finished, we would appreciate it if you could review the changes and make sure they are correct.
Hey @lukassos , I forgot we already normalized data. Thanks a lot for your warning. Now everything is clearer to me. Thanks so much for your passion!
What we have to do now is
You can create a new section for the document. I’ll also try to set the “plugin::users-permissions.user” plugin today as you suggested. Is there anything I missed?