globalstorage
Version:
Global Storage is a Global Distributed Data Warehouse
110 lines (89 loc) • 3.58 kB
JavaScript
;
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
var _require = require('metaschema'),
SchemaValidationError = _require.errors.SchemaValidationError,
extractByPath = _require.extractByPath,
extractDecorator = _require.extractDecorator;
var processFields = function processFields(ms, category, fields, source) {
var errors = [];
var _arr = Object.entries(fields);
for (var _i = 0; _i < _arr.length; _i++) {
var _arr$_i = _slicedToArray(_arr[_i], 2),
key = _arr$_i[0],
field = _arr$_i[1];
if (field.domain) {
var def = ms.domains.get(field.domain);
if (!def) {
errors.push(new SchemaValidationError('unresolved', "".concat(source, ".").concat(key), {
type: 'domain',
value: field.domain
}));
} else {
Object.assign(field, {
domain: field.domain,
definition: def
});
}
} else if (field.category) {
var cat = ms.categories.get(field.category);
if (!cat) {
errors.push(new SchemaValidationError('unresolved', "".concat(source, ".").concat(key), {
type: 'category',
value: field.category
}));
} else {
field.definition = cat.definition;
}
} else if (typeof field === 'string') {
var src = "".concat(source, ".").concat(key);
if (!category) {
errors.push(new SchemaValidationError('illegalParamsResolving', src, {
type: 'publicAction'
}));
continue;
}
try {
var _def = extractByPath(category, field.field, ms, src);
Object.assign(field, _def);
} catch (error) {
errors.push(error);
}
}
}
return errors;
};
var REFERENCE_TYPES = new Set(['Include', 'Many', 'Master', 'Other']); // Determines type of a reference by its decorator
// decorator - <string>
// Returns: <string>
var getReferenceType = function getReferenceType(decorator) {
return REFERENCE_TYPES.has(decorator) ? decorator : 'Other';
};
var getEntityPath = function getEntityPath(entity) {
return "".concat(entity.category, ".").concat(entity.name);
};
var _typeToPlural = {
form: 'forms',
action: 'actions'
};
var HIERARCHICAL_RELATIONS = ['Catalog', 'Subsystem', 'Hierarchy', 'Master']; // Extracts category decorator type, any undecorated category
// will be treated as Local.
// category - <Object>
// Returns: <string>
var getCategoryType = function getCategoryType(category) {
var type = extractDecorator(category);
return type === 'Object' ? 'Local' : type;
};
module.exports = {
processFields: processFields,
getReferenceType: getReferenceType,
getEntityPath: getEntityPath,
getCategoryType: getCategoryType,
typeToPlural: function typeToPlural(type) {
return _typeToPlural[type];
},
REFERENCE_TYPES: REFERENCE_TYPES,
HIERARCHICAL_RELATIONS: HIERARCHICAL_RELATIONS
};