diff --git a/dist/strapi.js b/dist/strapi.js index 2bff4a1..da41faf 100644 --- a/dist/strapi.js +++ b/dist/strapi.js @@ -1 +1 @@ -"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=t=>{if(typeof t!="object"||t===null)return t;const a={};for(const r in t)a[r]=d(t[r]);return a},s=t=>{const a={};for(const r in t){const e=t[r];if(typeof e=="object"&&e!==null&&"data"in e&&e.data!==null&&"id"in e.data&&"attributes"in e.data){const i=o(e);a[r]={id:e.data.id,...i}}else Array.isArray(e)?a[r]=e.map(i=>s(i)):a[r]=d(e)}return a},o=t=>{if(t==null||typeof t=="object"&&!Object.keys(t).length)return null;if(Array.isArray(t))return{data:t.map(o)};let a={...t};return t.attributes&&(a={...a,...s(t.attributes)},delete a.attributes),t.data&&(a=o(t.data)),a},f=t=>{const a=t?.meta?.pagination?.total,r=t?.meta?.pagination?.limit,e=t?.meta?.pagination?.start;let i=0,n=1;a&&r&&(i=Math.ceil(a/r)),e&&r&&(n=Math.floor(e/r)+1);const m=n=2;let l=o(t.data);return l.data&&(l=l.data),{meta:{...t?.meta,pagination:{...t?.meta?.pagination,...i&&{pages:i},...n&&{page:n},hasNextPage:m,hasPrevPage:c}},data:l}};exports.normalize=f;exports.normalizeContent=o;exports.normalizeNestedAttributes=s; +"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=t=>{if(typeof t!="object"||t===null)return t;const a={};for(const r in t)a[r]=d(t[r]);return a},s=t=>{const a={};for(const r in t){const e=t[r];if(typeof e=="object"&&e!==null&&"data"in e&&e.data!==null&&"id"in e.data&&"attributes"in e.data){const i=o(e);a[r]={id:e.data.id,...i}}else Array.isArray(e)?a[r]=e.map(i=>s(i)):a[r]=d(e)}return a},o=t=>{if(Array.isArray(t))return{data:t.map(o)};if(t==null||typeof t=="object"&&!Object.keys(t).length)return null;let a={...t};return t.attributes&&(a={...a,...s(t.attributes)},delete a.attributes),t.data&&(a=o(t.data)),a},f=t=>{const a=t?.meta?.pagination?.total,r=t?.meta?.pagination?.limit,e=t?.meta?.pagination?.start;let i=0,n=1;a&&r&&(i=Math.ceil(a/r)),e&&r&&(n=Math.floor(e/r)+1);const m=n=2;let l=o(t.data);return l.data&&(l=l.data),{meta:{...t?.meta,pagination:{...t?.meta?.pagination,...i&&{pages:i},...n&&{page:n},hasNextPage:m,hasPrevPage:c}},data:l}};exports.normalize=f;exports.normalizeContent=o;exports.normalizeNestedAttributes=s; diff --git a/dist/strapi.mjs b/dist/strapi.mjs index 2ed42ca..d15e4bd 100644 --- a/dist/strapi.mjs +++ b/dist/strapi.mjs @@ -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, diff --git a/package.json b/package.json index e246e33..ca556a1 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/strapi/index.ts b/src/strapi/index.ts index 5bf55e8..abf5a43 100644 --- a/src/strapi/index.ts +++ b/src/strapi/index.ts @@ -60,6 +60,12 @@ export const normalizeNestedAttributes = ( } export const normalizeContent = (input: any): any => { + if (Array.isArray(input)) { + return { + data: input.map(normalizeContent), + } + } + if ( input === null || input === undefined || @@ -68,12 +74,6 @@ export const normalizeContent = (input: any): any => { return null } - if (Array.isArray(input)) { - return { - data: input.map(normalizeContent), - } - } - let output = { ...input } if (input.attributes) {