Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Strapi normalizer when response.data is an empty array #29

Merged
merged 2 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/strapi.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/strapi.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ const s = (t) => {
}
return a;
}, l = (t) => {
if (t == null || typeof t == "object" && !Object.keys(t).length)
return null;
if (Array.isArray(t))
return {
data: t.map(l)
};
if (t == null || typeof t == "object" && !Object.keys(t).length)
return null;
let a = { ...t };
return t.attributes && (a = {
...a,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@teleporthq/cms-mappers",
"version": "1.0.14",
"version": "1.0.15",
"main": "dist/index.js",
"module": "dist/contentful.mjs",
"types": "dist/contentful/index.d.ts",
Expand Down
12 changes: 6 additions & 6 deletions src/strapi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
data: unknown[] | unknown
}

const toPlainObject = (obj: any): any => {

Check warning on line 18 in src/strapi/index.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type

Check warning on line 18 in src/strapi/index.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
if (typeof obj !== 'object' || obj === null) {
return obj
}
Expand All @@ -30,7 +30,7 @@
}

export const normalizeNestedAttributes = (
attributes: Record<string, any>

Check warning on line 33 in src/strapi/index.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
): Record<string, unknown> => {
const output: Record<string, unknown> = {}

Expand All @@ -48,7 +48,7 @@
const normalizedValue = normalizeContent(value)
output[key] = { id: value.data.id, ...normalizedValue }
} else if (Array.isArray(value)) {
output[key] = value.map((el: any) => {

Check warning on line 51 in src/strapi/index.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
return normalizeNestedAttributes(el)
})
} else {
Expand All @@ -59,7 +59,13 @@
return output
}

export const normalizeContent = (input: any): any => {

Check warning on line 62 in src/strapi/index.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type

Check warning on line 62 in src/strapi/index.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
if (Array.isArray(input)) {
return {
data: input.map(normalizeContent),
}
}

if (
input === null ||
input === undefined ||
Expand All @@ -68,12 +74,6 @@
return null
}

if (Array.isArray(input)) {
return {
data: input.map(normalizeContent),
}
}

let output = { ...input }

if (input.attributes) {
Expand All @@ -91,7 +91,7 @@
return output
}

export const normalize = (content: any): NormalizedContent => {

Check warning on line 94 in src/strapi/index.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
const total = content?.meta?.pagination?.total
const limit = content?.meta?.pagination?.limit
const start = content?.meta?.pagination?.start
Expand Down
Loading