diff --git a/dist/strapi.js b/dist/strapi.js index 98a2b13..d94eff7 100644 --- a/dist/strapi.js +++ b/dist/strapi.js @@ -1 +1 @@ -"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=t=>{if(typeof t!="object"||t===null)return t;const a={};for(const r in t)a[r]=s(t[r]);return a},l=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=n(e);a[r]={id:e.data.id,...i}}else Array.isArray(e)?a[r]=e.map(i=>l(i)):a[r]=s(e)}return a},n=t=>{if(t==null||typeof t=="object"&&!Object.keys(t).length)return null;if(Array.isArray(t))return{data:t.map(d)};let a={...t};return t.attributes&&(a={...a,...l(t.attributes)},delete a.attributes),t.data&&(a=n(t.data)),a},d=t=>{const a=t?.meta?.pagination?.total,r=t?.meta?.pagination?.limit,e=t?.meta?.pagination?.start;let i=0,o=1;a&&r&&(i=Math.ceil(a/r)),e&&r&&(o=Math.floor(e/r)+1);const c=o=2;return{meta:{...t?.meta,pagination:{...t?.meta?.pagination,...i&&{pages:i},...o&&{page:o},hasNextPage:c,hasPrevPage:m}},data:n(t.data)}};exports.normalize=d;exports.normalizeContent=n;exports.normalizeNestedAttributes=l; +"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=t=>{if(typeof t!="object"||t===null)return t;const a={};for(const r in t)a[r]=s(t[r]);return a},l=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=n(e);a[r]={id:e.data.id,...i}}else Array.isArray(e)?a[r]=e.map(i=>l(i)):a[r]=s(e)}return a},n=t=>{if(t==null||typeof t=="object"&&!Object.keys(t).length)return null;if(Array.isArray(t))return{data:t.map(n)};let a={...t};return t.attributes&&(a={...a,...l(t.attributes)},delete a.attributes),t.data&&(a=n(t.data)),a},m=t=>{const a=t?.meta?.pagination?.total,r=t?.meta?.pagination?.limit,e=t?.meta?.pagination?.start;let i=0,o=1;a&&r&&(i=Math.ceil(a/r)),e&&r&&(o=Math.floor(e/r)+1);const d=o=2;return{meta:{...t?.meta,pagination:{...t?.meta?.pagination,...i&&{pages:i},...o&&{page:o},hasNextPage:d,hasPrevPage:c}},data:n(t.data)}};exports.normalize=m;exports.normalizeContent=n;exports.normalizeNestedAttributes=l; diff --git a/dist/strapi.mjs b/dist/strapi.mjs index 107270f..6ed5fb1 100644 --- a/dist/strapi.mjs +++ b/dist/strapi.mjs @@ -21,7 +21,7 @@ const l = (t) => { return null; if (Array.isArray(t)) return { - data: t.map(f) + data: t.map(n) }; let a = { ...t }; return t.attributes && (a = { diff --git a/dist/strapi/index.d.ts.map b/dist/strapi/index.d.ts.map index 7300e9b..50612ec 100644 --- a/dist/strapi/index.d.ts.map +++ b/dist/strapi/index.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/strapi/index.ts"],"names":[],"mappings":"AAAA,KAAK,UAAU,GAAG;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB,CAAA;AAaD,KAAK,iBAAiB,GAAG;IACvB,IAAI,EAAE;QACJ,UAAU,CAAC,EAAE,UAAU,CAAA;KACxB,CAAA;IACD,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAA;CAC1B,CAAA;AAgBD,eAAO,MAAM,yBAAyB,eACxB,OAAO,MAAM,EAAE,GAAG,CAAC,KAC9B,OAAO,MAAM,EAAE,OAAO,CA0BxB,CAAA;AAED,eAAO,MAAM,gBAAgB,UAAW,GAAG,KAAG,GA8B7C,CAAA;AAED,eAAO,MAAM,SAAS,YAAa,GAAG,KAAG,iBA+BxC,CAAA"} \ No newline at end of file +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/strapi/index.ts"],"names":[],"mappings":"AAAA,KAAK,UAAU,GAAG;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB,CAAA;AAED,KAAK,iBAAiB,GAAG;IACvB,IAAI,EAAE;QACJ,UAAU,CAAC,EAAE,UAAU,CAAA;KACxB,CAAA;IACD,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAA;CAC1B,CAAA;AAgBD,eAAO,MAAM,yBAAyB,eACxB,OAAO,MAAM,EAAE,GAAG,CAAC,KAC9B,OAAO,MAAM,EAAE,OAAO,CA0BxB,CAAA;AAED,eAAO,MAAM,gBAAgB,UAAW,GAAG,KAAG,GA8B7C,CAAA;AAED,eAAO,MAAM,SAAS,YAAa,GAAG,KAAG,iBA+BxC,CAAA"} \ No newline at end of file diff --git a/package.json b/package.json index b367bd6..e54e672 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@teleporthq/cms-mappers", - "version": "1.0.11", + "version": "1.0.12", "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 ce61a97..952b985 100644 --- a/src/strapi/index.ts +++ b/src/strapi/index.ts @@ -8,17 +8,6 @@ type Pagination = { hasPrevPage?: boolean } -type Meta = { - pagination?: Pagination -} - -type ContentData = { - id?: string - attributes?: Record - data?: ContentData | ContentData[] - meta?: Meta -} - type NormalizedContent = { meta: { pagination?: Pagination @@ -81,7 +70,7 @@ export const normalizeContent = (input: any): any => { if (Array.isArray(input)) { return { - data: input.map(normalize), + data: input.map(normalizeContent), } }