@craftercms/content
Advanced tools
Comparing version 2.0.7 to 4.0.3
@@ -228,6 +228,6 @@ /* | ||
lastModifiedDate_dt: 'dateModified', | ||
disabled: 'disabled' | ||
disabled: 'disabled', | ||
orderDefault_f: 'orderInNav' | ||
}; | ||
var ignoreProps = [ | ||
'orderDefault_f', | ||
var ignoredProps = [ | ||
'merge-strategy', | ||
@@ -242,3 +242,13 @@ 'display-template', | ||
var systemProps = Object.keys(systemPropMap).concat(Object.values(systemPropMap)); | ||
function mixParseDescriptorOptions(options) { | ||
if (options === void 0) { options = {}; } | ||
return Object.assign({ | ||
systemPropMap: systemPropMap, | ||
ignoredProps: ignoredProps, | ||
systemProps: systemProps, | ||
parseFieldValueTypes: false | ||
}, options); | ||
} | ||
function parseDescriptor(data, options) { | ||
options = mixParseDescriptorOptions(options); | ||
if (data == null) { | ||
@@ -270,2 +280,3 @@ return null; | ||
dateModified: null, | ||
disabled: false, | ||
sourceMap: {} | ||
@@ -278,7 +289,8 @@ } | ||
if (parsed === void 0) { parsed = {}; } | ||
if (options === void 0) { options = { parseFieldValueTypes: false }; } | ||
options = mixParseDescriptorOptions(options); | ||
var systemPropMap = options.systemPropMap, ignoredProps = options.ignoredProps, systemProps = options.systemProps; | ||
Object.entries(props).forEach(function (_a) { | ||
var _b, _c; | ||
var prop = _a[0], value = _a[1]; | ||
if (ignoreProps.includes(prop)) { | ||
if (ignoredProps.includes(prop)) { | ||
return; // continue, skip prop. | ||
@@ -298,4 +310,17 @@ } | ||
if (systemProps.includes(prop)) { | ||
var propName = (_b = systemPropMap[prop]) !== null && _b !== void 0 ? _b : prop; | ||
var parsedValue = value; | ||
switch (propName) { | ||
case 'disabled': | ||
parsedValue = value === 'true'; | ||
break; | ||
case 'orderInNav': | ||
parsedValue = parseFloat(value); | ||
// Should never happen but just in case the value is not numeric, rollback to original string | ||
if (isNaN(parsedValue)) | ||
parsedValue = value; | ||
break; | ||
} | ||
// @ts-ignore | ||
parsed.craftercms[(_b = systemPropMap[prop]) !== null && _b !== void 0 ? _b : prop] = value; | ||
parsed.craftercms[propName] = parsedValue; | ||
// Is there a risk prop name that matches what's considered a system prop? | ||
@@ -339,4 +364,4 @@ // In that case, here, parsed.craftercms might not be in the target object | ||
function parseFieldValue(propName, propValue) { | ||
var postFix = propName.substr(propName.lastIndexOf('_')); | ||
switch (postFix) { | ||
var suffix = propName.substr(propName.lastIndexOf('_')); | ||
switch (suffix) { | ||
/* | ||
@@ -362,11 +387,12 @@ _i For integer number. | ||
function fetchModelByPath(path, options) { | ||
var _a; | ||
return getDescriptor(path, { flatten: (_a = options === null || options === void 0 ? void 0 : options.flatten) !== null && _a !== void 0 ? _a : true }).pipe(operators.map(function (descriptor) { var _a; return parseDescriptor(descriptor, { parseFieldValueTypes: (_a = options === null || options === void 0 ? void 0 : options.parseFieldValueTypes) !== null && _a !== void 0 ? _a : true }); })); | ||
var pdo = mixParseDescriptorOptions(__assign({ parseFieldValueTypes: true }, options)); | ||
return getDescriptor(path, __assign({ flatten: true }, options)).pipe(operators.map(function (descriptor) { return parseDescriptor(descriptor, pdo); })); | ||
} | ||
function fetchModelByUrl(webUrl, options) { | ||
return urlTransform('renderUrlToStoreUrl', webUrl).pipe(operators.switchMap(function (path) { var _a; return getDescriptor(path, { flatten: (_a = options === null || options === void 0 ? void 0 : options.flatten) !== null && _a !== void 0 ? _a : true }); }), operators.map(function (descriptor) { var _a; return parseDescriptor(descriptor, { parseFieldValueTypes: (_a = options === null || options === void 0 ? void 0 : options.parseFieldValueTypes) !== null && _a !== void 0 ? _a : true }); })); | ||
var pdo = mixParseDescriptorOptions(__assign({ parseFieldValueTypes: true }, options)); | ||
return urlTransform('renderUrlToStoreUrl', webUrl).pipe(operators.switchMap(function (path) { return getDescriptor(path, __assign({ flatten: true }, options)); }), operators.map(function (descriptor) { return parseDescriptor(descriptor, pdo); })); | ||
} | ||
/** | ||
* Inspects the data for getItem or getDescriptor responses and returns the inner content object | ||
* */ | ||
*/ | ||
function extractContent(data) { | ||
@@ -387,3 +413,3 @@ var output = data; | ||
* Flattens a getChildren response into a flat list of content items | ||
* */ | ||
*/ | ||
function extractChildren(children) { | ||
@@ -426,2 +452,4 @@ return children.flatMap(function (child) { | ||
exports.UrlTransformationService = UrlTransformationService; | ||
exports.extractChildren = extractChildren; | ||
exports.extractContent = extractContent; | ||
exports.fetchModelByPath = fetchModelByPath; | ||
@@ -435,2 +463,3 @@ exports.fetchModelByUrl = fetchModelByUrl; | ||
exports.getTree = getTree; | ||
exports.ignoredProps = ignoredProps; | ||
exports.parseDescriptor = parseDescriptor; | ||
@@ -440,2 +469,4 @@ exports.parseFieldValue = parseFieldValue; | ||
exports.preParseSearchResults = preParseSearchResults; | ||
exports.systemPropMap = systemPropMap; | ||
exports.systemProps = systemProps; | ||
exports.urlTransform = urlTransform; | ||
@@ -442,0 +473,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(global,factory){"object"==typeof exports&&"undefined"!=typeof module?factory(exports,require("@craftercms/classes"),require("@craftercms/utils"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("@craftercms/content",["exports","@craftercms/classes","@craftercms/utils","rxjs/operators"],factory):factory(((global=global||self).craftercms=global.craftercms||{},global.craftercms.content={}),global.craftercms.classes,global.craftercms.utils,global.rxjs.operators)}(this,function(exports,classes,utils,operators){"use strict";var __assign=function(){return(__assign=Object.assign||function(t){for(var s,i=1,n=arguments.length;i<n;i++)for(var p in s=arguments[i])Object.prototype.hasOwnProperty.call(s,p)&&(t[p]=s[p]);return t}).apply(this,arguments)};function getItem(path,config){config=classes.crafterConf.mix(config);var requestURL=utils.composeUrl(config,config.endpoints.GET_ITEM_URL);return classes.SDKService.httpGet(requestURL,{url:path,crafterSite:config.site},config.headers)}function getDescriptor(path,config){var cfg=classes.crafterConf.mix(config);return classes.SDKService.httpGet(utils.composeUrl(cfg,cfg.endpoints.GET_DESCRIPTOR),{url:path,crafterSite:cfg.site,flatten:Boolean(null===config||void 0===config?void 0:config.flatten)},cfg.headers).pipe(operators.map(function(descriptor){var _a,prop=void 0===descriptor.page?"component":"page";return(_a={})[prop]=__assign(__assign({},descriptor[prop]),{localId:path}),_a}))}function getChildren(path,config){config=classes.crafterConf.mix(config);var requestURL=utils.composeUrl(config,config.endpoints.GET_CHILDREN);return classes.SDKService.httpGet(requestURL,{url:path,crafterSite:config.site},config.headers)}function getTree(path,depth,config){void 0===depth&&(depth=1),"object"==typeof depth&&(config=depth,depth=1),config=classes.crafterConf.mix(config);var requestURL=utils.composeUrl(config,config.endpoints.GET_TREE);return classes.SDKService.httpGet(requestURL,{url:path,depth:depth,crafterSite:config.site},config.headers)}var ContentStoreService={getItem:getItem,getDescriptor:getDescriptor,getChildren:getChildren,getTree:getTree};function getNavTree(path,depth,currentPageUrl,config){void 0===depth&&(depth=1),void 0===currentPageUrl&&(currentPageUrl=""),config=classes.crafterConf.mix(config);var requestURL=utils.composeUrl(config,config.endpoints.GET_NAV_TREE);return classes.SDKService.httpGet(requestURL,{crafterSite:config.site,currentPageUrl:currentPageUrl,url:path,depth:depth},config.headers)}function getNavBreadcrumb(path,root,config){void 0===root&&(root=""),config=classes.crafterConf.mix(config);var requestURL=utils.composeUrl(config,config.endpoints.GET_BREADCRUMB);return classes.SDKService.httpGet(requestURL,{crafterSite:config.site,url:path,root:root},config.headers)}var NavigationService={getNavTree:getNavTree,getNavBreadcrumb:getNavBreadcrumb};function urlTransform(transformerName,url,config){config=classes.crafterConf.mix(config);var requestURL=utils.composeUrl(config,config.endpoints.TRANSFORM_URL);return classes.SDKService.httpGet(requestURL,{crafterSite:config.site,transformerName:transformerName,url:url},config.headers)}var UrlTransformationService={transform:urlTransform,urlTransform:urlTransform},systemPropMap={guid:"id",cmsId:"id",objectId:"id",localId:"path","file-name":"fileName",file__name:"fileName",placeInNav:"placeInNav","internal-name":"label",internal__name:"label","content-type":"contentTypeId",content__type:"contentTypeId",createdDate_dt:"dateCreated",lastModifiedDate_dt:"dateModified",disabled:"disabled"},ignoreProps=["orderDefault_f","merge-strategy","display-template","objectGroupId","folder-name","createdDate","lastModifiedDate","no-template-required"],systemProps=Object.keys(systemPropMap).concat(Object.values(systemPropMap));function parseDescriptor(data,options){if(null==data)return null;if(Array.isArray(data))return data.map(function(item){return parseDescriptor(item,options)});if(data.children)return parseDescriptor(function extractChildren(children){return children.flatMap(function(child){return child.children?extractChildren(child.children):child})}(data.children),options);if(null===data.descriptorDom&&data.descriptorUrl)throw new Error("[parseDescriptor] Invalid descriptor supplied. Did you call parseDescriptor with a `getChildren` API response? The `getChildren` API response may contain certain items that are not parsable into ContentInstances. Try a different API (getItem, getDescriptor or getTree) or filter out the metadata items which descriptorDom property has a `page` or `component` property with the content item.");return parseProps(function(data){var output=data;if(data.descriptorDom)return __assign(__assign({},data.descriptorDom.page||data.descriptorDom.component),{path:data.url});if(data.page)return data.page;if(data.component)return data.component;return output}(data),{craftercms:{id:null,path:null,label:null,contentTypeId:null,dateCreated:null,dateModified:null,sourceMap:{}}},options)}function parseProps(props,parsed,options){return void 0===parsed&&(parsed={}),void 0===options&&(options={parseFieldValueTypes:!1}),Object.entries(props).forEach(function(_a){var _b,_c,prop=_a[0],value=_a[1];ignoreProps.includes(prop)||((null===value||void 0===value?void 0:value["crafter-source-content-type-id"])&&(parsed.craftercms.sourceMap[prop]=value["crafter-source-content-type-id"],"string"==typeof value.text?value=value.text:2===Object.keys(value).length&&(value=null)),systemProps.includes(prop)?parsed.craftercms[null!==(_b=systemPropMap[prop])&&void 0!==_b?_b:prop]=value:prop.endsWith("_o")?(parsed[prop]=null!==(_c=null===value||void 0===value?void 0:value.item)&&void 0!==_c?_c:[],Array.isArray(parsed[prop])||(parsed[prop]=[parsed[prop]]),parsed[prop]=parsed[prop].map(function(item){var key=item.key,value=item.value,component=item.component,include=item.include;return item.component||item.key&&item.include?parseDescriptor(__assign(__assign({label:value},component),{path:(null===key||void 0===key?void 0:key.startsWith("/"))?key:(null===include||void 0===include?void 0:include.startsWith("/"))?include:(null===component||void 0===component?void 0:component.path)?component.path:null}),options):parseProps(item,void 0,options)})):parsed[prop]=null!=value?options.parseFieldValueTypes?parseFieldValue(prop,value):value:null)}),parsed}function parseFieldValue(propName,propValue){switch(propName.substr(propName.lastIndexOf("_"))){case"_b":return"true"===propValue.toLowerCase().trim();case"_i":case"_l":case"_f":case"_d":return parseFloat(propValue);default:return propValue}}var propsToRemove=["rootId","crafterSite","crafterPublishedDate","crafterPublishedDate_dt","inheritsFrom_smv"];exports.ContentStoreService=ContentStoreService,exports.NavigationService=NavigationService,exports.UrlTransformationService=UrlTransformationService,exports.fetchModelByPath=function(path,options){var _a;return getDescriptor(path,{flatten:null===(_a=null===options||void 0===options?void 0:options.flatten)||void 0===_a||_a}).pipe(operators.map(function(descriptor){var _a;return parseDescriptor(descriptor,{parseFieldValueTypes:null===(_a=null===options||void 0===options?void 0:options.parseFieldValueTypes)||void 0===_a||_a})}))},exports.fetchModelByUrl=function(webUrl,options){return urlTransform("renderUrlToStoreUrl",webUrl).pipe(operators.switchMap(function(path){var _a;return getDescriptor(path,{flatten:null===(_a=null===options||void 0===options?void 0:options.flatten)||void 0===_a||_a})}),operators.map(function(descriptor){var _a;return parseDescriptor(descriptor,{parseFieldValueTypes:null===(_a=null===options||void 0===options?void 0:options.parseFieldValueTypes)||void 0===_a||_a})}))},exports.getChildren=getChildren,exports.getDescriptor=getDescriptor,exports.getItem=getItem,exports.getNavBreadcrumb=getNavBreadcrumb,exports.getNavTree=getNavTree,exports.getTree=getTree,exports.parseDescriptor=parseDescriptor,exports.parseFieldValue=parseFieldValue,exports.parseProps=parseProps,exports.preParseSearchResults=function preParseSearchResults(source){return Object.entries(source).forEach(function(_a){var prop=_a[0],value=_a[1];if(propsToRemove.includes(prop))delete source[prop];else if(prop.endsWith("_o")){var collection=value;Array.isArray(collection.item)||(source[prop]={item:[collection.item]}),source[prop].item.forEach(function(item,i){source[prop].item[i]=preParseSearchResults(item),item.component&&(source[prop].item[i].component=preParseSearchResults(item.component))})}}),source},exports.urlTransform=urlTransform,Object.defineProperty(exports,"__esModule",{value:!0})}); | ||
!function(global,factory){"object"==typeof exports&&"undefined"!=typeof module?factory(exports,require("@craftercms/classes"),require("@craftercms/utils"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("@craftercms/content",["exports","@craftercms/classes","@craftercms/utils","rxjs/operators"],factory):factory(((global=global||self).craftercms=global.craftercms||{},global.craftercms.content={}),global.craftercms.classes,global.craftercms.utils,global.rxjs.operators)}(this,function(exports,classes,utils,operators){"use strict";var __assign=function(){return(__assign=Object.assign||function(t){for(var s,i=1,n=arguments.length;i<n;i++)for(var p in s=arguments[i])Object.prototype.hasOwnProperty.call(s,p)&&(t[p]=s[p]);return t}).apply(this,arguments)};function getItem(path,config){config=classes.crafterConf.mix(config);var requestURL=utils.composeUrl(config,config.endpoints.GET_ITEM_URL);return classes.SDKService.httpGet(requestURL,{url:path,crafterSite:config.site},config.headers)}function getDescriptor(path,config){var cfg=classes.crafterConf.mix(config);return classes.SDKService.httpGet(utils.composeUrl(cfg,cfg.endpoints.GET_DESCRIPTOR),{url:path,crafterSite:cfg.site,flatten:Boolean(null===config||void 0===config?void 0:config.flatten)},cfg.headers).pipe(operators.map(function(descriptor){var _a,prop=void 0===descriptor.page?"component":"page";return(_a={})[prop]=__assign(__assign({},descriptor[prop]),{localId:path}),_a}))}function getChildren(path,config){config=classes.crafterConf.mix(config);var requestURL=utils.composeUrl(config,config.endpoints.GET_CHILDREN);return classes.SDKService.httpGet(requestURL,{url:path,crafterSite:config.site},config.headers)}function getTree(path,depth,config){void 0===depth&&(depth=1),"object"==typeof depth&&(config=depth,depth=1),config=classes.crafterConf.mix(config);var requestURL=utils.composeUrl(config,config.endpoints.GET_TREE);return classes.SDKService.httpGet(requestURL,{url:path,depth:depth,crafterSite:config.site},config.headers)}var ContentStoreService={getItem:getItem,getDescriptor:getDescriptor,getChildren:getChildren,getTree:getTree};function getNavTree(path,depth,currentPageUrl,config){void 0===depth&&(depth=1),void 0===currentPageUrl&&(currentPageUrl=""),config=classes.crafterConf.mix(config);var requestURL=utils.composeUrl(config,config.endpoints.GET_NAV_TREE);return classes.SDKService.httpGet(requestURL,{crafterSite:config.site,currentPageUrl:currentPageUrl,url:path,depth:depth},config.headers)}function getNavBreadcrumb(path,root,config){void 0===root&&(root=""),config=classes.crafterConf.mix(config);var requestURL=utils.composeUrl(config,config.endpoints.GET_BREADCRUMB);return classes.SDKService.httpGet(requestURL,{crafterSite:config.site,url:path,root:root},config.headers)}var NavigationService={getNavTree:getNavTree,getNavBreadcrumb:getNavBreadcrumb};function urlTransform(transformerName,url,config){config=classes.crafterConf.mix(config);var requestURL=utils.composeUrl(config,config.endpoints.TRANSFORM_URL);return classes.SDKService.httpGet(requestURL,{crafterSite:config.site,transformerName:transformerName,url:url},config.headers)}var UrlTransformationService={transform:urlTransform,urlTransform:urlTransform},systemPropMap={guid:"id",cmsId:"id",objectId:"id",localId:"path","file-name":"fileName",file__name:"fileName",placeInNav:"placeInNav","internal-name":"label",internal__name:"label","content-type":"contentTypeId",content__type:"contentTypeId",createdDate_dt:"dateCreated",lastModifiedDate_dt:"dateModified",disabled:"disabled",orderDefault_f:"orderInNav"},ignoredProps=["merge-strategy","display-template","objectGroupId","folder-name","createdDate","lastModifiedDate","no-template-required"],systemProps=Object.keys(systemPropMap).concat(Object.values(systemPropMap));function mixParseDescriptorOptions(options){return void 0===options&&(options={}),Object.assign({systemPropMap:systemPropMap,ignoredProps:ignoredProps,systemProps:systemProps,parseFieldValueTypes:!1},options)}function parseDescriptor(data,options){if(options=mixParseDescriptorOptions(options),null==data)return null;if(Array.isArray(data))return data.map(function(item){return parseDescriptor(item,options)});if(data.children)return parseDescriptor(extractChildren(data.children),options);if(null===data.descriptorDom&&data.descriptorUrl)throw new Error("[parseDescriptor] Invalid descriptor supplied. Did you call parseDescriptor with a `getChildren` API response? The `getChildren` API response may contain certain items that are not parsable into ContentInstances. Try a different API (getItem, getDescriptor or getTree) or filter out the metadata items which descriptorDom property has a `page` or `component` property with the content item.");return parseProps(extractContent(data),{craftercms:{id:null,path:null,label:null,contentTypeId:null,dateCreated:null,dateModified:null,disabled:!1,sourceMap:{}}},options)}function parseProps(props,parsed,options){void 0===parsed&&(parsed={});var systemPropMap=(options=mixParseDescriptorOptions(options)).systemPropMap,ignoredProps=options.ignoredProps,systemProps=options.systemProps;return Object.entries(props).forEach(function(_a){var _b,_c,prop=_a[0],value=_a[1];if(!ignoredProps.includes(prop))if((null===value||void 0===value?void 0:value["crafter-source-content-type-id"])&&(parsed.craftercms.sourceMap[prop]=value["crafter-source-content-type-id"],"string"==typeof value.text?value=value.text:2===Object.keys(value).length&&(value=null)),systemProps.includes(prop)){var propName=null!==(_b=systemPropMap[prop])&&void 0!==_b?_b:prop,parsedValue=value;switch(propName){case"disabled":parsedValue="true"===value;break;case"orderInNav":parsedValue=parseFloat(value),isNaN(parsedValue)&&(parsedValue=value)}parsed.craftercms[propName]=parsedValue}else prop.endsWith("_o")?(parsed[prop]=null!==(_c=null===value||void 0===value?void 0:value.item)&&void 0!==_c?_c:[],Array.isArray(parsed[prop])||(parsed[prop]=[parsed[prop]]),parsed[prop]=parsed[prop].map(function(item){var key=item.key,value=item.value,component=item.component,include=item.include;return item.component||item.key&&item.include?parseDescriptor(__assign(__assign({label:value},component),{path:(null===key||void 0===key?void 0:key.startsWith("/"))?key:(null===include||void 0===include?void 0:include.startsWith("/"))?include:(null===component||void 0===component?void 0:component.path)?component.path:null}),options):parseProps(item,void 0,options)})):parsed[prop]=null!=value?options.parseFieldValueTypes?parseFieldValue(prop,value):value:null}),parsed}function parseFieldValue(propName,propValue){switch(propName.substr(propName.lastIndexOf("_"))){case"_b":return"true"===propValue.toLowerCase().trim();case"_i":case"_l":case"_f":case"_d":return parseFloat(propValue);default:return propValue}}function extractContent(data){var output=data;return data.descriptorDom?__assign(__assign({},data.descriptorDom.page||data.descriptorDom.component),{path:data.url}):data.page?data.page:data.component?data.component:output}function extractChildren(children){return children.flatMap(function(child){return child.children?extractChildren(child.children):child})}var propsToRemove=["rootId","crafterSite","crafterPublishedDate","crafterPublishedDate_dt","inheritsFrom_smv"];exports.ContentStoreService=ContentStoreService,exports.NavigationService=NavigationService,exports.UrlTransformationService=UrlTransformationService,exports.extractChildren=extractChildren,exports.extractContent=extractContent,exports.fetchModelByPath=function(path,options){var pdo=mixParseDescriptorOptions(__assign({parseFieldValueTypes:!0},options));return getDescriptor(path,__assign({flatten:!0},options)).pipe(operators.map(function(descriptor){return parseDescriptor(descriptor,pdo)}))},exports.fetchModelByUrl=function(webUrl,options){var pdo=mixParseDescriptorOptions(__assign({parseFieldValueTypes:!0},options));return urlTransform("renderUrlToStoreUrl",webUrl).pipe(operators.switchMap(function(path){return getDescriptor(path,__assign({flatten:!0},options))}),operators.map(function(descriptor){return parseDescriptor(descriptor,pdo)}))},exports.getChildren=getChildren,exports.getDescriptor=getDescriptor,exports.getItem=getItem,exports.getNavBreadcrumb=getNavBreadcrumb,exports.getNavTree=getNavTree,exports.getTree=getTree,exports.ignoredProps=ignoredProps,exports.parseDescriptor=parseDescriptor,exports.parseFieldValue=parseFieldValue,exports.parseProps=parseProps,exports.preParseSearchResults=function preParseSearchResults(source){return Object.entries(source).forEach(function(_a){var prop=_a[0],value=_a[1];if(propsToRemove.includes(prop))delete source[prop];else if(prop.endsWith("_o")){var collection=value;Array.isArray(collection.item)||(source[prop]={item:[collection.item]}),source[prop].item.forEach(function(item,i){source[prop].item[i]=preParseSearchResults(item),item.component&&(source[prop].item[i].component=preParseSearchResults(item.component))})}}),source},exports.systemPropMap=systemPropMap,exports.systemProps=systemProps,exports.urlTransform=urlTransform,Object.defineProperty(exports,"__esModule",{value:!0})}); |
@@ -19,3 +19,3 @@ /* | ||
import { map, switchMap } from 'rxjs/operators'; | ||
const systemPropMap = { | ||
export const systemPropMap = { | ||
guid: 'id', | ||
@@ -34,6 +34,6 @@ cmsId: 'id', | ||
lastModifiedDate_dt: 'dateModified', | ||
disabled: 'disabled' | ||
disabled: 'disabled', | ||
orderDefault_f: 'orderInNav' | ||
}; | ||
const ignoreProps = [ | ||
'orderDefault_f', | ||
export const ignoredProps = [ | ||
'merge-strategy', | ||
@@ -47,4 +47,13 @@ 'display-template', | ||
]; | ||
const systemProps = Object.keys(systemPropMap).concat(Object.values(systemPropMap)); | ||
export const systemProps = Object.keys(systemPropMap).concat(Object.values(systemPropMap)); | ||
function mixParseDescriptorOptions(options = {}) { | ||
return Object.assign({ | ||
systemPropMap, | ||
ignoredProps, | ||
systemProps, | ||
parseFieldValueTypes: false | ||
}, options); | ||
} | ||
export function parseDescriptor(data, options) { | ||
options = mixParseDescriptorOptions(options); | ||
if (data == null) { | ||
@@ -76,2 +85,3 @@ return null; | ||
dateModified: null, | ||
disabled: false, | ||
sourceMap: {} | ||
@@ -82,6 +92,8 @@ } | ||
} | ||
export function parseProps(props, parsed = {}, options = { parseFieldValueTypes: false }) { | ||
export function parseProps(props, parsed = {}, options) { | ||
options = mixParseDescriptorOptions(options); | ||
let { systemPropMap, ignoredProps, systemProps } = options; | ||
Object.entries(props).forEach(([prop, value]) => { | ||
var _a, _b; | ||
if (ignoreProps.includes(prop)) { | ||
if (ignoredProps.includes(prop)) { | ||
return; // continue, skip prop. | ||
@@ -101,4 +113,17 @@ } | ||
if (systemProps.includes(prop)) { | ||
let propName = (_a = systemPropMap[prop]) !== null && _a !== void 0 ? _a : prop; | ||
let parsedValue = value; | ||
switch (propName) { | ||
case 'disabled': | ||
parsedValue = value === 'true'; | ||
break; | ||
case 'orderInNav': | ||
parsedValue = parseFloat(value); | ||
// Should never happen but just in case the value is not numeric, rollback to original string | ||
if (isNaN(parsedValue)) | ||
parsedValue = value; | ||
break; | ||
} | ||
// @ts-ignore | ||
parsed.craftercms[(_a = systemPropMap[prop]) !== null && _a !== void 0 ? _a : prop] = value; | ||
parsed.craftercms[propName] = parsedValue; | ||
// Is there a risk prop name that matches what's considered a system prop? | ||
@@ -142,4 +167,4 @@ // In that case, here, parsed.craftercms might not be in the target object | ||
export function parseFieldValue(propName, propValue) { | ||
let postFix = propName.substr(propName.lastIndexOf('_')); | ||
switch (postFix) { | ||
let suffix = propName.substr(propName.lastIndexOf('_')); | ||
switch (suffix) { | ||
/* | ||
@@ -165,12 +190,13 @@ _i For integer number. | ||
export function fetchModelByPath(path, options) { | ||
var _a; | ||
return getDescriptor(path, { flatten: (_a = options === null || options === void 0 ? void 0 : options.flatten) !== null && _a !== void 0 ? _a : true }).pipe(map((descriptor) => { var _a; return parseDescriptor(descriptor, { parseFieldValueTypes: (_a = options === null || options === void 0 ? void 0 : options.parseFieldValueTypes) !== null && _a !== void 0 ? _a : true }); })); | ||
let pdo = mixParseDescriptorOptions(Object.assign({ parseFieldValueTypes: true }, options)); | ||
return getDescriptor(path, Object.assign({ flatten: true }, options)).pipe(map((descriptor) => parseDescriptor(descriptor, pdo))); | ||
} | ||
export function fetchModelByUrl(webUrl, options) { | ||
return urlTransform('renderUrlToStoreUrl', webUrl).pipe(switchMap((path) => { var _a; return getDescriptor(path, { flatten: (_a = options === null || options === void 0 ? void 0 : options.flatten) !== null && _a !== void 0 ? _a : true }); }), map((descriptor) => { var _a; return parseDescriptor(descriptor, { parseFieldValueTypes: (_a = options === null || options === void 0 ? void 0 : options.parseFieldValueTypes) !== null && _a !== void 0 ? _a : true }); })); | ||
let pdo = mixParseDescriptorOptions(Object.assign({ parseFieldValueTypes: true }, options)); | ||
return urlTransform('renderUrlToStoreUrl', webUrl).pipe(switchMap((path) => getDescriptor(path, Object.assign({ flatten: true }, options))), map((descriptor) => parseDescriptor(descriptor, pdo))); | ||
} | ||
/** | ||
* Inspects the data for getItem or getDescriptor responses and returns the inner content object | ||
* */ | ||
function extractContent(data) { | ||
*/ | ||
export function extractContent(data) { | ||
let output = data; | ||
@@ -190,4 +216,4 @@ if (data.descriptorDom) { | ||
* Flattens a getChildren response into a flat list of content items | ||
* */ | ||
function extractChildren(children) { | ||
*/ | ||
export function extractChildren(children) { | ||
return children.flatMap((child) => { | ||
@@ -194,0 +220,0 @@ return child.children ? extractChildren(child.children) : child; |
@@ -20,3 +20,3 @@ /* | ||
import { map, switchMap } from 'rxjs/operators'; | ||
var systemPropMap = { | ||
export var systemPropMap = { | ||
guid: 'id', | ||
@@ -35,6 +35,6 @@ cmsId: 'id', | ||
lastModifiedDate_dt: 'dateModified', | ||
disabled: 'disabled' | ||
disabled: 'disabled', | ||
orderDefault_f: 'orderInNav' | ||
}; | ||
var ignoreProps = [ | ||
'orderDefault_f', | ||
export var ignoredProps = [ | ||
'merge-strategy', | ||
@@ -48,4 +48,14 @@ 'display-template', | ||
]; | ||
var systemProps = Object.keys(systemPropMap).concat(Object.values(systemPropMap)); | ||
export var systemProps = Object.keys(systemPropMap).concat(Object.values(systemPropMap)); | ||
function mixParseDescriptorOptions(options) { | ||
if (options === void 0) { options = {}; } | ||
return Object.assign({ | ||
systemPropMap: systemPropMap, | ||
ignoredProps: ignoredProps, | ||
systemProps: systemProps, | ||
parseFieldValueTypes: false | ||
}, options); | ||
} | ||
export function parseDescriptor(data, options) { | ||
options = mixParseDescriptorOptions(options); | ||
if (data == null) { | ||
@@ -77,2 +87,3 @@ return null; | ||
dateModified: null, | ||
disabled: false, | ||
sourceMap: {} | ||
@@ -85,7 +96,8 @@ } | ||
if (parsed === void 0) { parsed = {}; } | ||
if (options === void 0) { options = { parseFieldValueTypes: false }; } | ||
options = mixParseDescriptorOptions(options); | ||
var systemPropMap = options.systemPropMap, ignoredProps = options.ignoredProps, systemProps = options.systemProps; | ||
Object.entries(props).forEach(function (_a) { | ||
var _b, _c; | ||
var prop = _a[0], value = _a[1]; | ||
if (ignoreProps.includes(prop)) { | ||
if (ignoredProps.includes(prop)) { | ||
return; // continue, skip prop. | ||
@@ -105,4 +117,17 @@ } | ||
if (systemProps.includes(prop)) { | ||
var propName = (_b = systemPropMap[prop]) !== null && _b !== void 0 ? _b : prop; | ||
var parsedValue = value; | ||
switch (propName) { | ||
case 'disabled': | ||
parsedValue = value === 'true'; | ||
break; | ||
case 'orderInNav': | ||
parsedValue = parseFloat(value); | ||
// Should never happen but just in case the value is not numeric, rollback to original string | ||
if (isNaN(parsedValue)) | ||
parsedValue = value; | ||
break; | ||
} | ||
// @ts-ignore | ||
parsed.craftercms[(_b = systemPropMap[prop]) !== null && _b !== void 0 ? _b : prop] = value; | ||
parsed.craftercms[propName] = parsedValue; | ||
// Is there a risk prop name that matches what's considered a system prop? | ||
@@ -146,4 +171,4 @@ // In that case, here, parsed.craftercms might not be in the target object | ||
export function parseFieldValue(propName, propValue) { | ||
var postFix = propName.substr(propName.lastIndexOf('_')); | ||
switch (postFix) { | ||
var suffix = propName.substr(propName.lastIndexOf('_')); | ||
switch (suffix) { | ||
/* | ||
@@ -169,12 +194,13 @@ _i For integer number. | ||
export function fetchModelByPath(path, options) { | ||
var _a; | ||
return getDescriptor(path, { flatten: (_a = options === null || options === void 0 ? void 0 : options.flatten) !== null && _a !== void 0 ? _a : true }).pipe(map(function (descriptor) { var _a; return parseDescriptor(descriptor, { parseFieldValueTypes: (_a = options === null || options === void 0 ? void 0 : options.parseFieldValueTypes) !== null && _a !== void 0 ? _a : true }); })); | ||
var pdo = mixParseDescriptorOptions(__assign({ parseFieldValueTypes: true }, options)); | ||
return getDescriptor(path, __assign({ flatten: true }, options)).pipe(map(function (descriptor) { return parseDescriptor(descriptor, pdo); })); | ||
} | ||
export function fetchModelByUrl(webUrl, options) { | ||
return urlTransform('renderUrlToStoreUrl', webUrl).pipe(switchMap(function (path) { var _a; return getDescriptor(path, { flatten: (_a = options === null || options === void 0 ? void 0 : options.flatten) !== null && _a !== void 0 ? _a : true }); }), map(function (descriptor) { var _a; return parseDescriptor(descriptor, { parseFieldValueTypes: (_a = options === null || options === void 0 ? void 0 : options.parseFieldValueTypes) !== null && _a !== void 0 ? _a : true }); })); | ||
var pdo = mixParseDescriptorOptions(__assign({ parseFieldValueTypes: true }, options)); | ||
return urlTransform('renderUrlToStoreUrl', webUrl).pipe(switchMap(function (path) { return getDescriptor(path, __assign({ flatten: true }, options)); }), map(function (descriptor) { return parseDescriptor(descriptor, pdo); })); | ||
} | ||
/** | ||
* Inspects the data for getItem or getDescriptor responses and returns the inner content object | ||
* */ | ||
function extractContent(data) { | ||
*/ | ||
export function extractContent(data) { | ||
var output = data; | ||
@@ -194,4 +220,4 @@ if (data.descriptorDom) { | ||
* Flattens a getChildren response into a flat list of content items | ||
* */ | ||
function extractChildren(children) { | ||
*/ | ||
export function extractChildren(children) { | ||
return children.flatMap(function (child) { | ||
@@ -198,0 +224,0 @@ return child.children ? extractChildren(child.children) : child; |
@@ -179,6 +179,6 @@ /* | ||
lastModifiedDate_dt: 'dateModified', | ||
disabled: 'disabled' | ||
disabled: 'disabled', | ||
orderDefault_f: 'orderInNav' | ||
}; | ||
const ignoreProps = [ | ||
'orderDefault_f', | ||
const ignoredProps = [ | ||
'merge-strategy', | ||
@@ -193,3 +193,12 @@ 'display-template', | ||
const systemProps = Object.keys(systemPropMap).concat(Object.values(systemPropMap)); | ||
function mixParseDescriptorOptions(options = {}) { | ||
return Object.assign({ | ||
systemPropMap, | ||
ignoredProps, | ||
systemProps, | ||
parseFieldValueTypes: false | ||
}, options); | ||
} | ||
function parseDescriptor(data, options) { | ||
options = mixParseDescriptorOptions(options); | ||
if (data == null) { | ||
@@ -221,2 +230,3 @@ return null; | ||
dateModified: null, | ||
disabled: false, | ||
sourceMap: {} | ||
@@ -227,6 +237,8 @@ } | ||
} | ||
function parseProps(props, parsed = {}, options = { parseFieldValueTypes: false }) { | ||
function parseProps(props, parsed = {}, options) { | ||
options = mixParseDescriptorOptions(options); | ||
let { systemPropMap, ignoredProps, systemProps } = options; | ||
Object.entries(props).forEach(([prop, value]) => { | ||
var _a, _b; | ||
if (ignoreProps.includes(prop)) { | ||
if (ignoredProps.includes(prop)) { | ||
return; // continue, skip prop. | ||
@@ -246,4 +258,17 @@ } | ||
if (systemProps.includes(prop)) { | ||
let propName = (_a = systemPropMap[prop]) !== null && _a !== void 0 ? _a : prop; | ||
let parsedValue = value; | ||
switch (propName) { | ||
case 'disabled': | ||
parsedValue = value === 'true'; | ||
break; | ||
case 'orderInNav': | ||
parsedValue = parseFloat(value); | ||
// Should never happen but just in case the value is not numeric, rollback to original string | ||
if (isNaN(parsedValue)) | ||
parsedValue = value; | ||
break; | ||
} | ||
// @ts-ignore | ||
parsed.craftercms[(_a = systemPropMap[prop]) !== null && _a !== void 0 ? _a : prop] = value; | ||
parsed.craftercms[propName] = parsedValue; | ||
// Is there a risk prop name that matches what's considered a system prop? | ||
@@ -287,4 +312,4 @@ // In that case, here, parsed.craftercms might not be in the target object | ||
function parseFieldValue(propName, propValue) { | ||
let postFix = propName.substr(propName.lastIndexOf('_')); | ||
switch (postFix) { | ||
let suffix = propName.substr(propName.lastIndexOf('_')); | ||
switch (suffix) { | ||
/* | ||
@@ -310,11 +335,12 @@ _i For integer number. | ||
function fetchModelByPath(path, options) { | ||
var _a; | ||
return getDescriptor(path, { flatten: (_a = options === null || options === void 0 ? void 0 : options.flatten) !== null && _a !== void 0 ? _a : true }).pipe(map((descriptor) => { var _a; return parseDescriptor(descriptor, { parseFieldValueTypes: (_a = options === null || options === void 0 ? void 0 : options.parseFieldValueTypes) !== null && _a !== void 0 ? _a : true }); })); | ||
let pdo = mixParseDescriptorOptions(Object.assign({ parseFieldValueTypes: true }, options)); | ||
return getDescriptor(path, Object.assign({ flatten: true }, options)).pipe(map((descriptor) => parseDescriptor(descriptor, pdo))); | ||
} | ||
function fetchModelByUrl(webUrl, options) { | ||
return urlTransform('renderUrlToStoreUrl', webUrl).pipe(switchMap((path) => { var _a; return getDescriptor(path, { flatten: (_a = options === null || options === void 0 ? void 0 : options.flatten) !== null && _a !== void 0 ? _a : true }); }), map((descriptor) => { var _a; return parseDescriptor(descriptor, { parseFieldValueTypes: (_a = options === null || options === void 0 ? void 0 : options.parseFieldValueTypes) !== null && _a !== void 0 ? _a : true }); })); | ||
let pdo = mixParseDescriptorOptions(Object.assign({ parseFieldValueTypes: true }, options)); | ||
return urlTransform('renderUrlToStoreUrl', webUrl).pipe(switchMap((path) => getDescriptor(path, Object.assign({ flatten: true }, options))), map((descriptor) => parseDescriptor(descriptor, pdo))); | ||
} | ||
/** | ||
* Inspects the data for getItem or getDescriptor responses and returns the inner content object | ||
* */ | ||
*/ | ||
function extractContent(data) { | ||
@@ -335,3 +361,3 @@ let output = data; | ||
* Flattens a getChildren response into a flat list of content items | ||
* */ | ||
*/ | ||
function extractChildren(children) { | ||
@@ -370,3 +396,3 @@ return children.flatMap((child) => { | ||
export { ContentStoreService, NavigationService, UrlTransformationService, fetchModelByPath, fetchModelByUrl, getChildren, getDescriptor, getItem, getNavBreadcrumb, getNavTree, getTree, parseDescriptor, parseFieldValue, parseProps, preParseSearchResults, urlTransform }; | ||
export { ContentStoreService, NavigationService, UrlTransformationService, extractChildren, extractContent, fetchModelByPath, fetchModelByUrl, getChildren, getDescriptor, getItem, getNavBreadcrumb, getNavTree, getTree, ignoredProps, parseDescriptor, parseFieldValue, parseProps, preParseSearchResults, systemPropMap, systemProps, urlTransform }; | ||
//# sourceMappingURL=content.js.map |
@@ -179,6 +179,6 @@ /* | ||
lastModifiedDate_dt: 'dateModified', | ||
disabled: 'disabled' | ||
disabled: 'disabled', | ||
orderDefault_f: 'orderInNav' | ||
}; | ||
const ignoreProps = [ | ||
'orderDefault_f', | ||
const ignoredProps = [ | ||
'merge-strategy', | ||
@@ -193,3 +193,12 @@ 'display-template', | ||
const systemProps = Object.keys(systemPropMap).concat(Object.values(systemPropMap)); | ||
function mixParseDescriptorOptions(options = {}) { | ||
return Object.assign({ | ||
systemPropMap, | ||
ignoredProps, | ||
systemProps, | ||
parseFieldValueTypes: false | ||
}, options); | ||
} | ||
function parseDescriptor(data, options) { | ||
options = mixParseDescriptorOptions(options); | ||
if (data == null) { | ||
@@ -221,2 +230,3 @@ return null; | ||
dateModified: null, | ||
disabled: false, | ||
sourceMap: {} | ||
@@ -227,6 +237,8 @@ } | ||
} | ||
function parseProps(props, parsed = {}, options = { parseFieldValueTypes: false }) { | ||
function parseProps(props, parsed = {}, options) { | ||
options = mixParseDescriptorOptions(options); | ||
let { systemPropMap, ignoredProps, systemProps } = options; | ||
Object.entries(props).forEach(([prop, value]) => { | ||
var _a, _b; | ||
if (ignoreProps.includes(prop)) { | ||
if (ignoredProps.includes(prop)) { | ||
return; // continue, skip prop. | ||
@@ -246,4 +258,17 @@ } | ||
if (systemProps.includes(prop)) { | ||
let propName = (_a = systemPropMap[prop]) !== null && _a !== void 0 ? _a : prop; | ||
let parsedValue = value; | ||
switch (propName) { | ||
case 'disabled': | ||
parsedValue = value === 'true'; | ||
break; | ||
case 'orderInNav': | ||
parsedValue = parseFloat(value); | ||
// Should never happen but just in case the value is not numeric, rollback to original string | ||
if (isNaN(parsedValue)) | ||
parsedValue = value; | ||
break; | ||
} | ||
// @ts-ignore | ||
parsed.craftercms[(_a = systemPropMap[prop]) !== null && _a !== void 0 ? _a : prop] = value; | ||
parsed.craftercms[propName] = parsedValue; | ||
// Is there a risk prop name that matches what's considered a system prop? | ||
@@ -287,4 +312,4 @@ // In that case, here, parsed.craftercms might not be in the target object | ||
function parseFieldValue(propName, propValue) { | ||
let postFix = propName.substr(propName.lastIndexOf('_')); | ||
switch (postFix) { | ||
let suffix = propName.substr(propName.lastIndexOf('_')); | ||
switch (suffix) { | ||
/* | ||
@@ -310,11 +335,12 @@ _i For integer number. | ||
function fetchModelByPath(path, options) { | ||
var _a; | ||
return getDescriptor(path, { flatten: (_a = options === null || options === void 0 ? void 0 : options.flatten) !== null && _a !== void 0 ? _a : true }).pipe(map((descriptor) => { var _a; return parseDescriptor(descriptor, { parseFieldValueTypes: (_a = options === null || options === void 0 ? void 0 : options.parseFieldValueTypes) !== null && _a !== void 0 ? _a : true }); })); | ||
let pdo = mixParseDescriptorOptions(Object.assign({ parseFieldValueTypes: true }, options)); | ||
return getDescriptor(path, Object.assign({ flatten: true }, options)).pipe(map((descriptor) => parseDescriptor(descriptor, pdo))); | ||
} | ||
function fetchModelByUrl(webUrl, options) { | ||
return urlTransform('renderUrlToStoreUrl', webUrl).pipe(switchMap((path) => { var _a; return getDescriptor(path, { flatten: (_a = options === null || options === void 0 ? void 0 : options.flatten) !== null && _a !== void 0 ? _a : true }); }), map((descriptor) => { var _a; return parseDescriptor(descriptor, { parseFieldValueTypes: (_a = options === null || options === void 0 ? void 0 : options.parseFieldValueTypes) !== null && _a !== void 0 ? _a : true }); })); | ||
let pdo = mixParseDescriptorOptions(Object.assign({ parseFieldValueTypes: true }, options)); | ||
return urlTransform('renderUrlToStoreUrl', webUrl).pipe(switchMap((path) => getDescriptor(path, Object.assign({ flatten: true }, options))), map((descriptor) => parseDescriptor(descriptor, pdo))); | ||
} | ||
/** | ||
* Inspects the data for getItem or getDescriptor responses and returns the inner content object | ||
* */ | ||
*/ | ||
function extractContent(data) { | ||
@@ -335,3 +361,3 @@ let output = data; | ||
* Flattens a getChildren response into a flat list of content items | ||
* */ | ||
*/ | ||
function extractChildren(children) { | ||
@@ -370,3 +396,3 @@ return children.flatMap((child) => { | ||
export { ContentStoreService, NavigationService, UrlTransformationService, fetchModelByPath, fetchModelByUrl, getChildren, getDescriptor, getItem, getNavBreadcrumb, getNavTree, getTree, parseDescriptor, parseFieldValue, parseProps, preParseSearchResults, urlTransform }; | ||
export { ContentStoreService, NavigationService, UrlTransformationService, extractChildren, extractContent, fetchModelByPath, fetchModelByUrl, getChildren, getDescriptor, getItem, getNavBreadcrumb, getNavTree, getTree, ignoredProps, parseDescriptor, parseFieldValue, parseProps, preParseSearchResults, systemPropMap, systemProps, urlTransform }; | ||
//# sourceMappingURL=content.js.map |
@@ -210,6 +210,6 @@ /* | ||
lastModifiedDate_dt: 'dateModified', | ||
disabled: 'disabled' | ||
disabled: 'disabled', | ||
orderDefault_f: 'orderInNav' | ||
}; | ||
var ignoreProps = [ | ||
'orderDefault_f', | ||
var ignoredProps = [ | ||
'merge-strategy', | ||
@@ -224,3 +224,13 @@ 'display-template', | ||
var systemProps = Object.keys(systemPropMap).concat(Object.values(systemPropMap)); | ||
function mixParseDescriptorOptions(options) { | ||
if (options === void 0) { options = {}; } | ||
return Object.assign({ | ||
systemPropMap: systemPropMap, | ||
ignoredProps: ignoredProps, | ||
systemProps: systemProps, | ||
parseFieldValueTypes: false | ||
}, options); | ||
} | ||
function parseDescriptor(data, options) { | ||
options = mixParseDescriptorOptions(options); | ||
if (data == null) { | ||
@@ -252,2 +262,3 @@ return null; | ||
dateModified: null, | ||
disabled: false, | ||
sourceMap: {} | ||
@@ -260,7 +271,8 @@ } | ||
if (parsed === void 0) { parsed = {}; } | ||
if (options === void 0) { options = { parseFieldValueTypes: false }; } | ||
options = mixParseDescriptorOptions(options); | ||
var systemPropMap = options.systemPropMap, ignoredProps = options.ignoredProps, systemProps = options.systemProps; | ||
Object.entries(props).forEach(function (_a) { | ||
var _b, _c; | ||
var prop = _a[0], value = _a[1]; | ||
if (ignoreProps.includes(prop)) { | ||
if (ignoredProps.includes(prop)) { | ||
return; // continue, skip prop. | ||
@@ -280,4 +292,17 @@ } | ||
if (systemProps.includes(prop)) { | ||
var propName = (_b = systemPropMap[prop]) !== null && _b !== void 0 ? _b : prop; | ||
var parsedValue = value; | ||
switch (propName) { | ||
case 'disabled': | ||
parsedValue = value === 'true'; | ||
break; | ||
case 'orderInNav': | ||
parsedValue = parseFloat(value); | ||
// Should never happen but just in case the value is not numeric, rollback to original string | ||
if (isNaN(parsedValue)) | ||
parsedValue = value; | ||
break; | ||
} | ||
// @ts-ignore | ||
parsed.craftercms[(_b = systemPropMap[prop]) !== null && _b !== void 0 ? _b : prop] = value; | ||
parsed.craftercms[propName] = parsedValue; | ||
// Is there a risk prop name that matches what's considered a system prop? | ||
@@ -321,4 +346,4 @@ // In that case, here, parsed.craftercms might not be in the target object | ||
function parseFieldValue(propName, propValue) { | ||
var postFix = propName.substr(propName.lastIndexOf('_')); | ||
switch (postFix) { | ||
var suffix = propName.substr(propName.lastIndexOf('_')); | ||
switch (suffix) { | ||
/* | ||
@@ -344,11 +369,12 @@ _i For integer number. | ||
function fetchModelByPath(path, options) { | ||
var _a; | ||
return getDescriptor(path, { flatten: (_a = options === null || options === void 0 ? void 0 : options.flatten) !== null && _a !== void 0 ? _a : true }).pipe(map(function (descriptor) { var _a; return parseDescriptor(descriptor, { parseFieldValueTypes: (_a = options === null || options === void 0 ? void 0 : options.parseFieldValueTypes) !== null && _a !== void 0 ? _a : true }); })); | ||
var pdo = mixParseDescriptorOptions(__assign({ parseFieldValueTypes: true }, options)); | ||
return getDescriptor(path, __assign({ flatten: true }, options)).pipe(map(function (descriptor) { return parseDescriptor(descriptor, pdo); })); | ||
} | ||
function fetchModelByUrl(webUrl, options) { | ||
return urlTransform('renderUrlToStoreUrl', webUrl).pipe(switchMap(function (path) { var _a; return getDescriptor(path, { flatten: (_a = options === null || options === void 0 ? void 0 : options.flatten) !== null && _a !== void 0 ? _a : true }); }), map(function (descriptor) { var _a; return parseDescriptor(descriptor, { parseFieldValueTypes: (_a = options === null || options === void 0 ? void 0 : options.parseFieldValueTypes) !== null && _a !== void 0 ? _a : true }); })); | ||
var pdo = mixParseDescriptorOptions(__assign({ parseFieldValueTypes: true }, options)); | ||
return urlTransform('renderUrlToStoreUrl', webUrl).pipe(switchMap(function (path) { return getDescriptor(path, __assign({ flatten: true }, options)); }), map(function (descriptor) { return parseDescriptor(descriptor, pdo); })); | ||
} | ||
/** | ||
* Inspects the data for getItem or getDescriptor responses and returns the inner content object | ||
* */ | ||
*/ | ||
function extractContent(data) { | ||
@@ -369,3 +395,3 @@ var output = data; | ||
* Flattens a getChildren response into a flat list of content items | ||
* */ | ||
*/ | ||
function extractChildren(children) { | ||
@@ -405,3 +431,3 @@ return children.flatMap(function (child) { | ||
export { ContentStoreService, NavigationService, UrlTransformationService, fetchModelByPath, fetchModelByUrl, getChildren, getDescriptor, getItem, getNavBreadcrumb, getNavTree, getTree, parseDescriptor, parseFieldValue, parseProps, preParseSearchResults, urlTransform }; | ||
export { ContentStoreService, NavigationService, UrlTransformationService, extractChildren, extractContent, fetchModelByPath, fetchModelByUrl, getChildren, getDescriptor, getItem, getNavBreadcrumb, getNavTree, getTree, ignoredProps, parseDescriptor, parseFieldValue, parseProps, preParseSearchResults, systemPropMap, systemProps, urlTransform }; | ||
//# sourceMappingURL=content.js.map |
@@ -210,6 +210,6 @@ /* | ||
lastModifiedDate_dt: 'dateModified', | ||
disabled: 'disabled' | ||
disabled: 'disabled', | ||
orderDefault_f: 'orderInNav' | ||
}; | ||
var ignoreProps = [ | ||
'orderDefault_f', | ||
var ignoredProps = [ | ||
'merge-strategy', | ||
@@ -224,3 +224,13 @@ 'display-template', | ||
var systemProps = Object.keys(systemPropMap).concat(Object.values(systemPropMap)); | ||
function mixParseDescriptorOptions(options) { | ||
if (options === void 0) { options = {}; } | ||
return Object.assign({ | ||
systemPropMap: systemPropMap, | ||
ignoredProps: ignoredProps, | ||
systemProps: systemProps, | ||
parseFieldValueTypes: false | ||
}, options); | ||
} | ||
function parseDescriptor(data, options) { | ||
options = mixParseDescriptorOptions(options); | ||
if (data == null) { | ||
@@ -252,2 +262,3 @@ return null; | ||
dateModified: null, | ||
disabled: false, | ||
sourceMap: {} | ||
@@ -260,7 +271,8 @@ } | ||
if (parsed === void 0) { parsed = {}; } | ||
if (options === void 0) { options = { parseFieldValueTypes: false }; } | ||
options = mixParseDescriptorOptions(options); | ||
var systemPropMap = options.systemPropMap, ignoredProps = options.ignoredProps, systemProps = options.systemProps; | ||
Object.entries(props).forEach(function (_a) { | ||
var _b, _c; | ||
var prop = _a[0], value = _a[1]; | ||
if (ignoreProps.includes(prop)) { | ||
if (ignoredProps.includes(prop)) { | ||
return; // continue, skip prop. | ||
@@ -280,4 +292,17 @@ } | ||
if (systemProps.includes(prop)) { | ||
var propName = (_b = systemPropMap[prop]) !== null && _b !== void 0 ? _b : prop; | ||
var parsedValue = value; | ||
switch (propName) { | ||
case 'disabled': | ||
parsedValue = value === 'true'; | ||
break; | ||
case 'orderInNav': | ||
parsedValue = parseFloat(value); | ||
// Should never happen but just in case the value is not numeric, rollback to original string | ||
if (isNaN(parsedValue)) | ||
parsedValue = value; | ||
break; | ||
} | ||
// @ts-ignore | ||
parsed.craftercms[(_b = systemPropMap[prop]) !== null && _b !== void 0 ? _b : prop] = value; | ||
parsed.craftercms[propName] = parsedValue; | ||
// Is there a risk prop name that matches what's considered a system prop? | ||
@@ -321,4 +346,4 @@ // In that case, here, parsed.craftercms might not be in the target object | ||
function parseFieldValue(propName, propValue) { | ||
var postFix = propName.substr(propName.lastIndexOf('_')); | ||
switch (postFix) { | ||
var suffix = propName.substr(propName.lastIndexOf('_')); | ||
switch (suffix) { | ||
/* | ||
@@ -344,11 +369,12 @@ _i For integer number. | ||
function fetchModelByPath(path, options) { | ||
var _a; | ||
return getDescriptor(path, { flatten: (_a = options === null || options === void 0 ? void 0 : options.flatten) !== null && _a !== void 0 ? _a : true }).pipe(map(function (descriptor) { var _a; return parseDescriptor(descriptor, { parseFieldValueTypes: (_a = options === null || options === void 0 ? void 0 : options.parseFieldValueTypes) !== null && _a !== void 0 ? _a : true }); })); | ||
var pdo = mixParseDescriptorOptions(__assign({ parseFieldValueTypes: true }, options)); | ||
return getDescriptor(path, __assign({ flatten: true }, options)).pipe(map(function (descriptor) { return parseDescriptor(descriptor, pdo); })); | ||
} | ||
function fetchModelByUrl(webUrl, options) { | ||
return urlTransform('renderUrlToStoreUrl', webUrl).pipe(switchMap(function (path) { var _a; return getDescriptor(path, { flatten: (_a = options === null || options === void 0 ? void 0 : options.flatten) !== null && _a !== void 0 ? _a : true }); }), map(function (descriptor) { var _a; return parseDescriptor(descriptor, { parseFieldValueTypes: (_a = options === null || options === void 0 ? void 0 : options.parseFieldValueTypes) !== null && _a !== void 0 ? _a : true }); })); | ||
var pdo = mixParseDescriptorOptions(__assign({ parseFieldValueTypes: true }, options)); | ||
return urlTransform('renderUrlToStoreUrl', webUrl).pipe(switchMap(function (path) { return getDescriptor(path, __assign({ flatten: true }, options)); }), map(function (descriptor) { return parseDescriptor(descriptor, pdo); })); | ||
} | ||
/** | ||
* Inspects the data for getItem or getDescriptor responses and returns the inner content object | ||
* */ | ||
*/ | ||
function extractContent(data) { | ||
@@ -369,3 +395,3 @@ var output = data; | ||
* Flattens a getChildren response into a flat list of content items | ||
* */ | ||
*/ | ||
function extractChildren(children) { | ||
@@ -405,3 +431,3 @@ return children.flatMap(function (child) { | ||
export { ContentStoreService, NavigationService, UrlTransformationService, fetchModelByPath, fetchModelByUrl, getChildren, getDescriptor, getItem, getNavBreadcrumb, getNavTree, getTree, parseDescriptor, parseFieldValue, parseProps, preParseSearchResults, urlTransform }; | ||
export { ContentStoreService, NavigationService, UrlTransformationService, extractChildren, extractContent, fetchModelByPath, fetchModelByUrl, getChildren, getDescriptor, getItem, getNavBreadcrumb, getNavTree, getTree, ignoredProps, parseDescriptor, parseFieldValue, parseProps, preParseSearchResults, systemPropMap, systemProps, urlTransform }; | ||
//# sourceMappingURL=content.js.map |
{ | ||
"name": "@craftercms/content", | ||
"version": "2.0.7", | ||
"version": "4.0.3", | ||
"description": "Crafter CMS services for content and navigation retrieval", | ||
@@ -29,5 +29,5 @@ "main": "./bundles/content.umd.js", | ||
"dependencies": { | ||
"@craftercms/classes": "2.0.7", | ||
"@craftercms/models": "2.0.7", | ||
"@craftercms/utils": "2.0.7", | ||
"@craftercms/classes": "4.0.3", | ||
"@craftercms/models": "4.0.3", | ||
"@craftercms/utils": "4.0.3", | ||
"rxjs": "^7.0.0" | ||
@@ -34,0 +34,0 @@ }, |
@@ -1,16 +0,54 @@ | ||
import { ContentInstance, DescriptorResponse } from '@craftercms/models'; | ||
import { ContentInstance, Descriptor, DescriptorResponse, Item } from '@craftercms/models'; | ||
import { GetDescriptorConfig } from './ContentStoreService'; | ||
import { Observable } from 'rxjs'; | ||
export interface ParseDescriptorOptions { | ||
export declare const systemPropMap: { | ||
guid: string; | ||
cmsId: string; | ||
objectId: string; | ||
localId: string; | ||
'file-name': string; | ||
file__name: string; | ||
placeInNav: string; | ||
'internal-name': string; | ||
internal__name: string; | ||
'content-type': string; | ||
content__type: string; | ||
createdDate_dt: string; | ||
lastModifiedDate_dt: string; | ||
disabled: string; | ||
orderDefault_f: string; | ||
}; | ||
export declare const ignoredProps: string[]; | ||
export declare const systemProps: string[]; | ||
export declare type ParseDescriptorOptions = Partial<{ | ||
/** Whether to parse the field values to their respective data type based on postfix (e.g. _i number, _b boolean, etc) */ | ||
parseFieldValueTypes: boolean; | ||
} | ||
export declare function parseDescriptor(data: DescriptorResponse, options?: ParseDescriptorOptions): ContentInstance; | ||
export declare function parseDescriptor(data: DescriptorResponse[], options?: ParseDescriptorOptions): ContentInstance[]; | ||
/** Defines the parsed names that go inside the `.craftercms` property of the ContentInstance */ | ||
systemPropMap: Record<string, string>; | ||
/** Defines the list of properties that aren't included in the parsed ContentInstance */ | ||
ignoredProps: string[]; | ||
/** List of all props considered "system" that will be routed to the `.craftercms` prop of the parsed ContentInstances */ | ||
systemProps: string[]; | ||
}>; | ||
export declare function parseDescriptor(data: DescriptorResponse): ContentInstance; | ||
export declare function parseDescriptor(data: DescriptorResponse, options: ParseDescriptorOptions): ContentInstance; | ||
export declare function parseDescriptor(data: DescriptorResponse[]): ContentInstance[]; | ||
export declare function parseDescriptor(data: DescriptorResponse[], options: ParseDescriptorOptions): ContentInstance[]; | ||
export declare function parseProps<Props = object, Target = object>(props: Props, parsed?: Target, options?: ParseDescriptorOptions): Target; | ||
export declare function parseFieldValue(propName: string, propValue: any): number | string | boolean; | ||
export declare function fetchModelByPath(path: string): Observable<ContentInstance>; | ||
export declare function fetchModelByPath(path: string, options?: GetDescriptorConfig & ParseDescriptorOptions): Observable<ContentInstance>; | ||
export declare function fetchModelByPath(path: string, options: Partial<GetDescriptorConfig & ParseDescriptorOptions>): Observable<ContentInstance>; | ||
export declare function fetchModelByUrl(webUrl: string): Observable<ContentInstance>; | ||
export declare function fetchModelByUrl(webUrl: string, options?: GetDescriptorConfig & ParseDescriptorOptions): Observable<ContentInstance>; | ||
export declare function fetchModelByUrl(webUrl: string, options: Partial<GetDescriptorConfig & ParseDescriptorOptions>): Observable<ContentInstance>; | ||
/** | ||
* Inspects the data for getItem or getDescriptor responses and returns the inner content object | ||
*/ | ||
export declare function extractContent(data: Descriptor | Item): any; | ||
export interface ItemWithChildren extends Record<string, any> { | ||
children?: Array<ItemWithChildren>; | ||
} | ||
/** | ||
* Flattens a getChildren response into a flat list of content items | ||
*/ | ||
export declare function extractChildren(children: Array<ItemWithChildren>): any; | ||
export declare function preParseSearchResults<T extends object = {}>(source: T): ContentInstance; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
433446
3039
+ Added@craftercms/classes@4.0.3(transitive)
+ Added@craftercms/models@4.0.3(transitive)
+ Added@craftercms/utils@4.0.3(transitive)
- Removed@craftercms/classes@2.0.7(transitive)
- Removed@craftercms/models@2.0.7(transitive)
- Removed@craftercms/utils@2.0.7(transitive)
Updated@craftercms/classes@4.0.3
Updated@craftercms/models@4.0.3
Updated@craftercms/utils@4.0.3