contentful-parsers
Advanced tools
Comparing version 1.2.17 to 1.2.18
@@ -222,2 +222,6 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
objectClone[key] = parseEntry(field, typename, definitionMap === null || definitionMap === void 0 ? void 0 : definitionMap[key], depth + 1); | ||
} else if (field && field.nodeType && field.nodeType === 'document') { | ||
objectClone[key] = { | ||
json: field | ||
}; | ||
} else { | ||
@@ -224,0 +228,0 @@ objectClone[key] = field; |
{ | ||
"name": "contentful-parsers", | ||
"version": "1.2.17", | ||
"version": "1.2.18", | ||
"description": "Library of useful parsers to use when working with Contentful API responses.", | ||
@@ -5,0 +5,0 @@ "repository": "ryanhefner/contentful-parsers.git", |
@@ -233,2 +233,6 @@ "use strict"; | ||
objectClone[key] = parseEntry(field, typename, definitionMap === null || definitionMap === void 0 ? void 0 : definitionMap[key], depth + 1); | ||
} else if (field && field.nodeType && field.nodeType === 'document') { | ||
objectClone[key] = { | ||
json: field | ||
}; | ||
} else { | ||
@@ -235,0 +239,0 @@ objectClone[key] = field; |
@@ -15,3 +15,3 @@ import { fieldsParser } from './fieldsParser' | ||
return rootValue && rootValue.hasOwnProperty(fieldName) ? rootValue[fieldName] : null | ||
}; | ||
} | ||
@@ -170,3 +170,3 @@ /** | ||
: object | ||
); | ||
) | ||
@@ -199,6 +199,6 @@ // Parse all references and reference collections | ||
depth + 1 | ||
); | ||
) | ||
// Delete old flat array field | ||
delete objectClone[key]; | ||
delete objectClone[key] | ||
} else { | ||
@@ -218,2 +218,6 @@ objectClone[key] = field | ||
objectClone[key] = parseEntry(field, typename, definitionMap?.[key], depth + 1) | ||
} else if (field && field.nodeType && field.nodeType === 'document') { | ||
objectClone[key] = { | ||
json: field, | ||
} | ||
} else { | ||
@@ -235,3 +239,3 @@ objectClone[key] = field | ||
// Return GraphQL-ready object | ||
return definedClone; | ||
return definedClone | ||
} | ||
@@ -257,3 +261,3 @@ | ||
.filter(item => !!item), | ||
}; | ||
} | ||
} | ||
@@ -260,0 +264,0 @@ |
@@ -1,2 +0,2 @@ | ||
/*! contentful-parsers v1.2.17 | (c) 2020 Ryan Hefner | MIT License | https://github.com/ryanhefner/contentful-parsers.git !*/ | ||
/*! contentful-parsers v1.2.18 | (c) 2021 Ryan Hefner | MIT License | https://github.com/ryanhefner/contentful-parsers.git !*/ | ||
(function (global, factory) { | ||
@@ -364,2 +364,6 @@ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
objectClone[key] = parseEntry(field, typename, definitionMap === null || definitionMap === void 0 ? void 0 : definitionMap[key], depth + 1); | ||
} else if (field && field.nodeType && field.nodeType === 'document') { | ||
objectClone[key] = { | ||
json: field | ||
}; | ||
} else { | ||
@@ -366,0 +370,0 @@ objectClone[key] = field; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["contentful-parsers"]={})}(this,function(e){"use strict";function R(e,s,l){function o(e){return e&&"object"==typeof e&&e.hasOwnProperty("sys")&&1===Object.keys(e).length}function u(t,e,n,r){if(void 0===n&&(n={}),void 0===r&&(r=0),!t||"object"!=typeof t)return n;if(r>=s.include)return n;var i=Object.assign({},n);return Object.keys(t).forEach(function(e){i[e]=t[e]&&t[e].fields&&l.parseRefs?u(t[e].fields,t[e].sys,i[e],r+1):function t(e,n){return void 0===n&&(n=0),o(e)?null:Array.isArray(e)&&l.parseArrays?e.filter(function(e){return!o(e)}).map(function(e){return e&&"object"==typeof e&&e.fields?u(e.fields,e.sys,{},n+1):t(e,n+1)}):e}(t[e],r+1)}),e&&e.contentType&&e.contentType.sys&&e.contentType.sys.id&&(i.id=e.id,i.__typename=e.contentType.sys.id),e&&e.updatedAt&&(i.updatedAt=e.updatedAt),e&&e.createdAt&&(i.createdAt=e.createdAt),i}void 0===s&&(s={include:10}),void 0===l&&(l={parseArrays:!0,parseRefs:!0});var t=Object.assign({},e);return u(t.fields,t.sys)}var r=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e};function i(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,r)}return n}function s(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?i(Object(n),!0).forEach(function(e){r(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function S(e){return e.substring(0,1).toUpperCase()+e.substring(1)}e.contentfulResolver=function(e,t){return t&&t.hasOwnProperty(e)?t[e]:null},e.fieldsParser=R,e.graphqlParser=function(e,t,n,E){var r,i;function k(e,t){var n,r;return e&&(e.hasOwnProperty("__typename")&&e.__typename&&(e.__typename=S(e.__typename)),t&&t.sys?e.sys=s(s({},t.sys),{},{__typename:"Sys"}):t.id&&(e.sys={id:t.id,__typename:"Sys"}),null!=e&&null!==(n=e.sys)&&void 0!==n&&n.createdAt&&(e.sys.firstPublishedAt=e.sys.createdAt,delete e.sys.createdAt),null!=e&&null!==(r=e.sys)&&void 0!==r&&r.updatedAt&&(e.sys.publishedAt=e.sys.updatedAt,delete e.sys.updatedAt),e.id&&delete e.id,e.createdAt&&(e.sys.firstPublishedAt||(e.sys.firstPublishedAt=e.createdAt),delete e.createdAt),e.updatedAt&&(e.sys.publishedAt||(e.sys.publishedAt=e.updatedAt),delete e.updatedAt)),e}function C(i,s,l,o){var e;if(void 0===o&&(o=0),!i)return null;if(o>=E.include)return i;var u=Object.assign({},i.hasOwnProperty("sys")&&i.hasOwnProperty("fields")?R(i,E,{parseArrays:!1,parseRefs:!1}):i);Object.keys(u).forEach(function(n){var e=u[n];if(Array.isArray(e)){var t=!1;if(e.filter(function(e){return!!e}).forEach(function(e){(e.hasOwnProperty("sys")&&e.hasOwnProperty("fields")||e.hasOwnProperty("__typename"))&&(t=!0)}),t){var r=n+"Collection";u[r]=D(e,""+s+S(r),null==l?void 0:l[r],o+1),delete u[n]}else u[n]=e.map(function(e,t){return k(e,i&&i.fields&&i.fields[n][t])}).filter(function(e){return!!e})}else e&&"object"==typeof e&&(e.hasOwnProperty("__typename")||e.hasOwnProperty("sys")&&e.hasOwnProperty("fields"))?u[n]=C(e,s,null==l?void 0:l[n],o+1):u[n]=e});var t,n,r,d,a,f,y,c,p,v,h,b,O,A,m,_,j,P,g,w=k(u,i),T="Asset"===(null==w||null===(e=w.sys)||void 0===e?void 0:e.type)?(t=w,(g=Object.assign({},t)).__typename="Asset",g.url=null==g||null===(n=g.file)||void 0===n?void 0:n.url,g.contentType=null==g||null===(r=g.file)||void 0===r?void 0:r.contentType,g.size=null==g||null===(d=g.file)||void 0===d||null===(a=d.details)||void 0===a?void 0:a.size,g.width=(null==g||null===(f=g.file)||void 0===f||null===(y=f.details)||void 0===y||null===(c=y.image)||void 0===c?void 0:c.width)||(null==g||null===(p=g.file)||void 0===p||null===(v=p.details)||void 0===v||null===(h=v.video)||void 0===h?void 0:h.width),g.height=(null==g||null===(b=g.file)||void 0===b||null===(O=b.details)||void 0===O||null===(A=O.image)||void 0===A?void 0:A.height)||(null==g||null===(m=g.file)||void 0===m||null===(_=m.details)||void 0===_||null===(j=_.video)||void 0===j?void 0:j.height),g.fileName=null==g||null===(P=g.file)||void 0===P?void 0:P.fileName,g.url.startsWith("https:")||(g.url="https:"+g.url),delete g.file,g):w;return function r(e,i,s){if(!e||!s)return e;var l=Object.assign({},e||{});return Object.keys(s).forEach(function(e){if(!l.hasOwnProperty(e))if(e.endsWith("Collection")){var t=e.replace("Collection",""),n=l.hasOwnProperty(t)&&l[t];n?(l[e]=D(n,""+i+S(e),s[e]),delete l[t]):l[e]=D([],""+i+S(e),s[e])}else e.startsWith("...")&&l.__typename&&l.__typename===e.replace("...","")?Object.assign(l,r(l,i,s[e])):l[e]=null}),l}(T,T.__typename||s,l)}function D(e,t,n,r){return void 0===e&&(e=[]),void 0===r&&(r=0),{__typename:t,total:(e&&Array.isArray(e)?e:[]).length,items:(e&&Array.isArray(e)?e:[]).map(function(e){return C(e,t,null==n?void 0:n.items,r)}).filter(function(e){return!!e})}}return void 0===E&&(E={include:10}),null!=t&&t.items?((i={})[e]=D(t.items,S(e),null==n?void 0:n[e]),i):((r={})[e]=s({__typename:S(e)},C(t,S(e),null==n?void 0:n[e])),r)},Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["contentful-parsers"]={})}(this,function(e){"use strict";function R(e,s,l){function o(e){return e&&"object"==typeof e&&e.hasOwnProperty("sys")&&1===Object.keys(e).length}function u(t,e,n,r){if(void 0===n&&(n={}),void 0===r&&(r=0),!t||"object"!=typeof t)return n;if(r>=s.include)return n;var i=Object.assign({},n);return Object.keys(t).forEach(function(e){i[e]=t[e]&&t[e].fields&&l.parseRefs?u(t[e].fields,t[e].sys,i[e],r+1):function t(e,n){return void 0===n&&(n=0),o(e)?null:Array.isArray(e)&&l.parseArrays?e.filter(function(e){return!o(e)}).map(function(e){return e&&"object"==typeof e&&e.fields?u(e.fields,e.sys,{},n+1):t(e,n+1)}):e}(t[e],r+1)}),e&&e.contentType&&e.contentType.sys&&e.contentType.sys.id&&(i.id=e.id,i.__typename=e.contentType.sys.id),e&&e.updatedAt&&(i.updatedAt=e.updatedAt),e&&e.createdAt&&(i.createdAt=e.createdAt),i}void 0===s&&(s={include:10}),void 0===l&&(l={parseArrays:!0,parseRefs:!0});var t=Object.assign({},e);return u(t.fields,t.sys)}var r=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e};function i(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,r)}return n}function s(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?i(Object(n),!0).forEach(function(e){r(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function S(e){return e.substring(0,1).toUpperCase()+e.substring(1)}e.contentfulResolver=function(e,t){return t&&t.hasOwnProperty(e)?t[e]:null},e.fieldsParser=R,e.graphqlParser=function(e,t,n,E){var r,i;function k(e,t){var n,r;return e&&(e.hasOwnProperty("__typename")&&e.__typename&&(e.__typename=S(e.__typename)),t&&t.sys?e.sys=s(s({},t.sys),{},{__typename:"Sys"}):t.id&&(e.sys={id:t.id,__typename:"Sys"}),null!=e&&null!==(n=e.sys)&&void 0!==n&&n.createdAt&&(e.sys.firstPublishedAt=e.sys.createdAt,delete e.sys.createdAt),null!=e&&null!==(r=e.sys)&&void 0!==r&&r.updatedAt&&(e.sys.publishedAt=e.sys.updatedAt,delete e.sys.updatedAt),e.id&&delete e.id,e.createdAt&&(e.sys.firstPublishedAt||(e.sys.firstPublishedAt=e.createdAt),delete e.createdAt),e.updatedAt&&(e.sys.publishedAt||(e.sys.publishedAt=e.updatedAt),delete e.updatedAt)),e}function C(i,s,l,o){var e;if(void 0===o&&(o=0),!i)return null;if(o>=E.include)return i;var u=Object.assign({},i.hasOwnProperty("sys")&&i.hasOwnProperty("fields")?R(i,E,{parseArrays:!1,parseRefs:!1}):i);Object.keys(u).forEach(function(n){var e=u[n];if(Array.isArray(e)){var t=!1;if(e.filter(function(e){return!!e}).forEach(function(e){(e.hasOwnProperty("sys")&&e.hasOwnProperty("fields")||e.hasOwnProperty("__typename"))&&(t=!0)}),t){var r=n+"Collection";u[r]=D(e,""+s+S(r),null==l?void 0:l[r],o+1),delete u[n]}else u[n]=e.map(function(e,t){return k(e,i&&i.fields&&i.fields[n][t])}).filter(function(e){return!!e})}else e&&"object"==typeof e&&(e.hasOwnProperty("__typename")||e.hasOwnProperty("sys")&&e.hasOwnProperty("fields"))?u[n]=C(e,s,null==l?void 0:l[n],o+1):e&&e.nodeType&&"document"===e.nodeType?u[n]={json:e}:u[n]=e});var t,n,r,d,a,f,y,c,p,v,h,b,O,A,m,_,j,P,g,w=k(u,i),T="Asset"===(null==w||null===(e=w.sys)||void 0===e?void 0:e.type)?(t=w,(g=Object.assign({},t)).__typename="Asset",g.url=null==g||null===(n=g.file)||void 0===n?void 0:n.url,g.contentType=null==g||null===(r=g.file)||void 0===r?void 0:r.contentType,g.size=null==g||null===(d=g.file)||void 0===d||null===(a=d.details)||void 0===a?void 0:a.size,g.width=(null==g||null===(f=g.file)||void 0===f||null===(y=f.details)||void 0===y||null===(c=y.image)||void 0===c?void 0:c.width)||(null==g||null===(p=g.file)||void 0===p||null===(v=p.details)||void 0===v||null===(h=v.video)||void 0===h?void 0:h.width),g.height=(null==g||null===(b=g.file)||void 0===b||null===(O=b.details)||void 0===O||null===(A=O.image)||void 0===A?void 0:A.height)||(null==g||null===(m=g.file)||void 0===m||null===(_=m.details)||void 0===_||null===(j=_.video)||void 0===j?void 0:j.height),g.fileName=null==g||null===(P=g.file)||void 0===P?void 0:P.fileName,g.url.startsWith("https:")||(g.url="https:"+g.url),delete g.file,g):w;return function r(e,i,s){if(!e||!s)return e;var l=Object.assign({},e||{});return Object.keys(s).forEach(function(e){if(!l.hasOwnProperty(e))if(e.endsWith("Collection")){var t=e.replace("Collection",""),n=l.hasOwnProperty(t)&&l[t];n?(l[e]=D(n,""+i+S(e),s[e]),delete l[t]):l[e]=D([],""+i+S(e),s[e])}else e.startsWith("...")&&l.__typename&&l.__typename===e.replace("...","")?Object.assign(l,r(l,i,s[e])):l[e]=null}),l}(T,T.__typename||s,l)}function D(e,t,n,r){return void 0===e&&(e=[]),void 0===r&&(r=0),{__typename:t,total:(e&&Array.isArray(e)?e:[]).length,items:(e&&Array.isArray(e)?e:[]).map(function(e){return C(e,t,null==n?void 0:n.items,r)}).filter(function(e){return!!e})}}return void 0===E&&(E={include:10}),null!=t&&t.items?((i={})[e]=D(t.items,S(e),null==n?void 0:n[e]),i):((r={})[e]=s({__typename:S(e)},C(t,S(e),null==n?void 0:n[e])),r)},Object.defineProperty(e,"__esModule",{value:!0})}); |
84391
1838