From c65c4c63838964cb7080a99139d61cc899faba12 Mon Sep 17 00:00:00 2001 From: Ionut Pasca Date: Mon, 29 Jul 2024 18:37:28 +0300 Subject: [PATCH] Increase version --- dist/strapi.js | 2 +- dist/strapi.mjs | 44 +++++++++++++++++++------------------- dist/strapi/index.d.ts | 28 +++++++++++++----------- dist/strapi/index.d.ts.map | 2 +- package.json | 2 +- 5 files changed, 41 insertions(+), 37 deletions(-) diff --git a/dist/strapi.js b/dist/strapi.js index ef65ef6..98a2b13 100644 --- a/dist/strapi.js +++ b/dist/strapi.js @@ -1 +1 @@ -"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function l(t){if(typeof t!="object"||t===null)return t;const a={};for(const i in t)a[i]=l(t[i]);return a}const m=t=>{const a={};for(const i in t){const e=t[i];if(typeof e=="object"&&e!==null&&"data"in e&&e.data!==null&&"id"in e.data&&"attributes"in e.data){const n=r(e);a[i]={id:e.data.id,...n}}else a[i]=l(e)}return a},r=t=>{if(t==null||typeof t=="object"&&!Object.keys(t).length)return null;if(Array.isArray(t))return{data:t.map(s)};let a={...t};return t.attributes&&(a={...a,...m(t.attributes)},delete a.attributes),t.data&&(a=r(t.data)),a},s=t=>{const a=t?.meta?.pagination?.total,i=t?.meta?.pagination?.limit,e=t?.meta?.pagination?.start;let n=0,o=1;a&&i&&(n=Math.ceil(a/i)),e&&i&&(o=e/i+1);const c=o=2;return{meta:{...t?.meta,pagination:{...t?.meta?.pagination,...!!n&&{pages:n},...!!o&&{page:o},hasNextPage:c,hasPrevPage:d}},...r(t)}};exports.normalize=s;exports.normalizeContent=r; +"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; diff --git a/dist/strapi.mjs b/dist/strapi.mjs index ca5eaf6..107270f 100644 --- a/dist/strapi.mjs +++ b/dist/strapi.mjs @@ -1,23 +1,22 @@ -function l(t) { +const l = (t) => { if (typeof t != "object" || t === null) return t; const a = {}; - for (const i in t) - a[i] = l(t[i]); + for (const r in t) + a[r] = l(t[r]); return a; -} -const d = (t) => { +}, s = (t) => { const a = {}; - for (const i in t) { - const e = t[i]; + 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 n = o(e); - a[i] = { id: e.data.id, ...n }; + const i = n(e); + a[r] = { id: e.data.id, ...i }; } else - a[i] = l(e); + Array.isArray(e) ? a[r] = e.map((i) => s(i)) : a[r] = l(e); } return a; -}, o = (t) => { +}, n = (t) => { if (t == null || typeof t == "object" && !Object.keys(t).length) return null; if (Array.isArray(t)) @@ -27,28 +26,29 @@ const d = (t) => { let a = { ...t }; return t.attributes && (a = { ...a, - ...d(t.attributes) - }, delete a.attributes), t.data && (a = o(t.data)), a; + ...s(t.attributes) + }, delete a.attributes), t.data && (a = n(t.data)), a; }, f = (t) => { - const a = t?.meta?.pagination?.total, i = t?.meta?.pagination?.limit, e = t?.meta?.pagination?.start; - let n = 0, r = 1; - a && i && (n = Math.ceil(a / i)), e && i && (r = e / i + 1); - const s = r < n, c = r >= 2; + 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 < i, c = o >= 2; return { meta: { ...t?.meta, pagination: { ...t?.meta?.pagination, - ...!!n && { pages: n }, - ...!!r && { page: r }, - hasNextPage: s, + ...i && { pages: i }, + ...o && { page: o }, + hasNextPage: d, hasPrevPage: c } }, - ...o(t) + data: n(t.data) }; }; export { f as normalize, - o as normalizeContent + n as normalizeContent, + s as normalizeNestedAttributes }; diff --git a/dist/strapi/index.d.ts b/dist/strapi/index.d.ts index 84bbab8..9273729 100644 --- a/dist/strapi/index.d.ts +++ b/dist/strapi/index.d.ts @@ -1,16 +1,20 @@ -export declare const normalizeContent: (input: any) => any; -export declare const normalize: (content: any) => { +type Pagination = { + total?: number; + limit?: number; + start?: number; + pages?: number; + page?: number; + hasNextPage?: boolean; + hasPrevPage?: boolean; +}; +type NormalizedContent = { meta: { - pagination?: { - total?: number; - limit?: number; - start?: number; - pages: number; - page: number; - hasNextPage: boolean; - hasPrevPage: boolean; - }; + pagination?: Pagination; }; - data: Array | unknown; + data: unknown[] | unknown; }; +export declare const normalizeNestedAttributes: (attributes: Record) => Record; +export declare const normalizeContent: (input: any) => any; +export declare const normalize: (content: any) => NormalizedContent; +export {}; //# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/strapi/index.d.ts.map b/dist/strapi/index.d.ts.map index 54a55bf..7300e9b 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":"AAsCA,eAAO,MAAM,gBAAgB,qBA8B5B,CAAA;AAED,eAAO,MAAM,SAAS;;;oBAKR,MAAM;oBACN,MAAM;oBACN,MAAM;mBACP,MAAM;kBACP,MAAM;yBACC,OAAO;yBACP,OAAO;;;UAGlB,MAAM,OAAO,CAAC,GAAG,OAAO;CA+B/B,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;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 diff --git a/package.json b/package.json index 5eae2db..b367bd6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@teleporthq/cms-mappers", - "version": "1.0.10", + "version": "1.0.11", "main": "dist/index.js", "module": "dist/contentful.mjs", "types": "dist/contentful/index.d.ts",