roarcli
Version:
Overview:
144 lines (115 loc) • 5.85 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
exports.default = function (obj, file) {
console.log('[DEBUG]', obj, file);
Object.keys(obj, function (k) {
if (keys.indexOf(k) === -1) {
console.error('Unrecognized field ' + k + ' found in the view file: ' + file);
process.exit(1);
}
});
if (!obj.NodeType || obj.NodeType.length === 0) {
console.error('A valid `NodeType` must be supplied in the view file: ', file);
process.exit(1);
}
if (!obj.Views || obj.Views.length === 0) {
console.error('One or more `Views` must be supplied in the view file: ', file);
process.exit(1);
}
obj.Views.forEach(function (view, index) {
if (!view || (typeof view === 'undefined' ? 'undefined' : _typeof(view)) !== 'object') {
console.error('Invalid `view` was specified in ' + file + '. ' + view ? 'The `view` ' + view.toString() + ' is not a valid object.' : 'The `view` appears to be null or undefined.');
process.exit(1);
}
Object.keys(view).forEach(function (k) {
if (viewKeys.indexOf(k) === -1) {
console.error('Invalid `view` was specified in ' + file + '. The `view` contains an unrecognized field: ' + k);
process.exit(1);
}
});
if (!view.Title || view.Title.length === 0) {
console.error('A valid `Title` must be supplied in view #' + index + ' the view file: ', file);
process.exit(1);
}
if (!view.Items || view.Items.length === 0) {
console.error('`Items` must be supplied in the view file: ', file);
process.exit(1);
}
view.Items.forEach(function (item, subindex) {
if (!item || (typeof item === 'undefined' ? 'undefined' : _typeof(item)) !== 'object') {
console.error('Invalid `item` was specified in ' + file + '. ' + item ? 'The `item` ' + item.toString() + ' is not a valid object.' : 'The `item` appears to be null or undefined.');
process.exit(1);
}
if (!item.Type || item.Type.length === 0) {
console.error('A valid `Type` must be supplied in view #' + index + ' @ item #' + subindex + ' in the view file: ', file);
process.exit(1);
} else if (itemTypes.indexOf(item.Type) === -1) {
console.error('An invalid `Type` was supplied in view #' + index + ' @ item #' + subindex + ' in the view file: ', file, 'Must be ' + itemTypes.join(', '));
process.exit(1);
}
var fullItemKeySet = itemKeys.concat(keysets[item.Type]);
Object.keys(item).forEach(function (k) {
if (fullItemKeySet.indexOf(k) === -1) {
console.error('Invalid `item` was specified in ' + file + '. The `item` contains an unrecognized field: ' + k);
process.exit(1);
}
});
if (item.Type === 'table') {
if (item.Header && (item.Header !== true || item.Header !== false)) {
console.error('`Header` must be either true or false in view #' + index + ' @ item #' + subindex + ' in the view file: ', file);
process.exit(1);
}
if (item.Columns) {
item.Columns.forEach(function (c, cindex) {
Object.keys(c, function (k) {
if (columnKeys.indexOf(k) === -1) {
console.error('Unrecognized field in view #' + index + ' @ item #' + subindex + ' @ column #' + cindex + ' in the view file: ', file);
process.exit(1);
}
});
if (!c.Name || c.Name.length === 0) {
console.error('A valid `Name` must be supplied in view #' + index + ' @ item #' + subindex + ' @ column #' + cindex + ' in the view file: ', file);
process.exit(1);
}
if (c.Sortable && c.Sortable !== true && c.Sortable !== false) {
console.error('`Sortable` must be either true or false in view #' + index + ' @ item #' + subindex + ' @ column #' + cindex + ' in the view file: ', file);
process.exit(1);
}
if (c.Filterable && c.Filterable !== true && c.Filterable !== false) {
console.error('`Filterable` must be either true or false in view #' + index + ' @ item #' + subindex + ' @ column #' + cindex + ' in the view file: ', file);
process.exit(1);
}
if (!c.JsonPath || c.JsonPath.length === 0) {
console.error('A valid `JsonPath` must be supplied in view #' + index + ' @ item #' + subindex + ' @ column #' + cindex + ' in the view file: ', file);
process.exit(1);
}
});
}
} else if (item.Type === 'json') {
if (!item.JsonPath || item.JsonPath.length === 0) {
console.error('A valid `JsonPath` must be supplied in view #' + index + ' @ item #' + subindex + ' in the view file: ', file);
process.exit(1);
}
}
});
});
};
var _taskCategories = require('./task-categories');
var _taskCategories2 = _interopRequireDefault(_taskCategories);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var keys = ['NodeType', 'Keys', 'Views'];
var viewKeys = ['Title', 'Items'];
var itemKeys = ['Type', 'Label'];
var keysets = {
'json': ['JsonPath'],
'table': ['Header', 'Columns', 'Subtable', 'Rows']
};
var columnKeys = ['Name', 'Type', 'Sortable', 'Filterable', 'JsonPath'];
var itemTypes = ['table', 'json'];
var columnTypes = ['string', 'number', 'boolean', 'array', 'object'];
;
module.exports = exports['default'];
//# sourceMappingURL=validate-view.js.map