@amplience/dc-cli
Version:
Dynamic Content CLI Tool
80 lines (79 loc) • 2.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.dependsOn = dependsOn;
exports.hierarchyParent = hierarchyParent;
exports.dependantType = dependantType;
function dependancy(id, type = 'http://bigcontent.io/cms/schema/v1/core#/definitions/content-link') {
return {
_meta: {
schema: type,
name: 'content-link'
},
contentType: 'https://dev-solutions.s3.amazonaws.com/DynamicContentTypes/Accelerators/blog.json',
id: id
};
}
function dependProps(itemProps) {
const result = {};
itemProps.forEach(element => {
result[element[0]] = dependancy(element[1]);
});
return result;
}
function dependsOn(itemIds, type, itemProps) {
itemProps = itemProps || [];
return {
links: itemIds.map(id => dependancy(id, type)),
...dependProps(itemProps)
};
}
function hierarchyParent(parentId, itemProps) {
itemProps = itemProps || [];
const item = {
...dependProps(itemProps)
};
if (!item._meta) {
item._meta = {};
}
if (!item._meta.hierarchy) {
item._meta.hierarchy = {};
}
item._meta.hierarchy.parentId = parentId;
return item;
}
function dependantType(items) {
return {
$schema: 'http://json-schema.org/draft-07/schema#',
$id: 'http://superbasic.com',
title: 'Title',
description: 'Description',
allOf: [
{
$ref: 'http://bigcontent.io/cms/schema/v1/core#/definitions/content'
}
],
required: ['valid'],
type: 'object',
properties: {
links: {
title: 'title',
type: 'array',
minItems: items,
maxItems: items,
items: {
allOf: [
{ $ref: 'http://bigcontent.io/cms/schema/v1/core#/definitions/content-link' },
{
properties: {
contentType: {
enum: ['*']
}
}
}
]
}
}
},
propertyOrder: []
};
}