Skip to content

Commit 60babc7

Browse files
committed
Make sure that data.data does not exist in strapi
1 parent e12f7a1 commit 60babc7

File tree

5 files changed

+44
-38
lines changed

5 files changed

+44
-38
lines changed

dist/strapi.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/strapi.mjs

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
1-
const l = (t) => {
2-
if (typeof t != "object" || t === null)
3-
return t;
4-
const a = {};
5-
for (const r in t)
6-
a[r] = l(t[r]);
7-
return a;
8-
}, s = (t) => {
9-
const a = {};
10-
for (const r in t) {
11-
const e = t[r];
1+
const s = (a) => {
2+
if (typeof a != "object" || a === null)
3+
return a;
4+
const t = {};
5+
for (const r in a)
6+
t[r] = s(a[r]);
7+
return t;
8+
}, d = (a) => {
9+
const t = {};
10+
for (const r in a) {
11+
const e = a[r];
1212
if (typeof e == "object" && e !== null && "data" in e && e.data !== null && "id" in e.data && "attributes" in e.data) {
1313
const i = n(e);
14-
a[r] = { id: e.data.id, ...i };
14+
t[r] = { id: e.data.id, ...i };
1515
} else
16-
Array.isArray(e) ? a[r] = e.map((i) => s(i)) : a[r] = l(e);
16+
Array.isArray(e) ? t[r] = e.map((i) => d(i)) : t[r] = s(e);
1717
}
18-
return a;
19-
}, n = (t) => {
20-
if (t == null || typeof t == "object" && !Object.keys(t).length)
18+
return t;
19+
}, n = (a) => {
20+
if (a == null || typeof a == "object" && !Object.keys(a).length)
2121
return null;
22-
if (Array.isArray(t))
22+
if (Array.isArray(a))
2323
return {
24-
data: t.map(n)
24+
data: a.map(n)
2525
};
26-
let a = { ...t };
27-
return t.attributes && (a = {
28-
...a,
29-
...s(t.attributes)
30-
}, delete a.attributes), t.data && (a = n(t.data)), a;
31-
}, f = (t) => {
32-
const a = t?.meta?.pagination?.total, r = t?.meta?.pagination?.limit, e = t?.meta?.pagination?.start;
26+
let t = { ...a };
27+
return a.attributes && (t = {
28+
...t,
29+
...d(a.attributes)
30+
}, delete t.attributes), a.data && (t = n(a.data)), t;
31+
}, m = (a) => {
32+
const t = a?.meta?.pagination?.total, r = a?.meta?.pagination?.limit, e = a?.meta?.pagination?.start;
3333
let i = 0, o = 1;
34-
a && r && (i = Math.ceil(a / r)), e && r && (o = Math.floor(e / r) + 1);
35-
const d = o < i, c = o >= 2;
36-
return {
34+
t && r && (i = Math.ceil(t / r)), e && r && (o = Math.floor(e / r) + 1);
35+
const c = o < i, f = o >= 2, l = n(a.data);
36+
return Array.isArray(l?.data?.data) && (l.data = l.data.data), {
3737
meta: {
38-
...t?.meta,
38+
...a?.meta,
3939
pagination: {
40-
...t?.meta?.pagination,
40+
...a?.meta?.pagination,
4141
...i && { pages: i },
4242
...o && { page: o },
43-
hasNextPage: d,
44-
hasPrevPage: c
43+
hasNextPage: c,
44+
hasPrevPage: f
4545
}
4646
},
47-
data: n(t.data)
47+
data: n(a.data)
4848
};
4949
};
5050
export {
51-
f as normalize,
51+
m as normalize,
5252
n as normalizeContent,
53-
s as normalizeNestedAttributes
53+
d as normalizeNestedAttributes
5454
};

dist/strapi/index.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@teleporthq/cms-mappers",
3-
"version": "1.0.12",
3+
"version": "1.0.13",
44
"main": "dist/index.js",
55
"module": "dist/contentful.mjs",
66
"types": "dist/contentful/index.d.ts",

src/strapi/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ export const normalize = (content: any): NormalizedContent => {
109109
const hasNextPage = page < pages
110110
const hasPrevPage = page >= 2
111111

112+
const normalizedContent = normalizeContent(content.data)
113+
// We need to make sure that we do not have nested data.data
114+
if (Array.isArray(normalizedContent?.data?.data)) {
115+
normalizedContent.data = normalizedContent.data.data
116+
}
117+
112118
return {
113119
meta: {
114120
...content?.meta,

0 commit comments

Comments
 (0)