UNPKG

globalstorage

Version:

Global Storage is a Global Distributed Data Warehouse

239 lines (203 loc) 7.85 kB
'use strict'; 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; } function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); } function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); } function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } } var _require = require('metaschema'), config = _require.default.config, SchemaValidationError = _require.errors.SchemaValidationError, extractDecorator = _require.extractDecorator; var _require2 = require('./decorators'), decorators = _require2.decorators, localDecorators = _require2.localDecorators; var _require3 = require('./category'), preprocessCategoryData = _require3.preprocessCategoryData, addCategory = _require3.addCategory, processRelations = _require3.processRelations, validateCategory = _require3.validateCategory, categoryCreator = _require3.categoryCreator; var _require4 = require('./form'), preprocessForm = _require4.preprocessForm, processForm = _require4.processForm, addForm = _require4.addForm, validateForm = _require4.validateForm; var _require5 = require('./action'), addAction = _require5.addAction, processAction = _require5.processAction, validateAction = _require5.validateAction, actionCreator = _require5.actionCreator; var _require6 = require('./resource'), preprocessResources = _require6.preprocessResources, addResources = _require6.addResources; var _require7 = require('./application'), addApplication = _require7.addApplication, processApplication = _require7.processApplication; var _require8 = require('./utils'), typeToPlural = _require8.typeToPlural; SchemaValidationError.serializers.unlinked = function (_ref) { var source = _ref.source, type = _ref.info.type; return "Unlinked ".concat(type, " '").concat(source, "'"); }; SchemaValidationError.serializers.illegalLink = function (_ref2) { var source = _ref2.source, _ref2$info = _ref2.info, sourceType = _ref2$info.sourceType, destination = _ref2$info.destination, destinationType = _ref2$info.destinationType; return "Illegal link from ".concat(sourceType, " '").concat(source, "' ") + "to ".concat(destinationType, " '").concat(destination); }; SchemaValidationError.serializers.detailHierarchy = function (_ref3) { var source = _ref3.source, _ref3$info = _ref3.info, type = _ref3$info.type, master = _ref3$info.master; return "Category '".concat(source, "' can not be divided by ").concat(type, " ") + "while being a detail of '".concat(master, "'"); }; SchemaValidationError.serializers.illegalParamsResolving = function (_ref4) { var source = _ref4.source, type = _ref4.info.type; return "Params resolving is forbidden for ".concat(type, ": '").concat(source, "'"); }; var preprocessor = function preprocessor(schemas) { var arr = _toConsumableArray(schemas); var _iteratorNormalCompletion = true; var _didIteratorError = false; var _iteratorError = undefined; try { var _loop = function _loop() { var schema = _step.value; if (schema.type !== 'category') { return "continue"; } Object.entries(schema.definition).forEach(function (_ref5) { var _ref6 = _slicedToArray(_ref5, 2), key = _ref6[0], value = _ref6[1]; var decorator = extractDecorator(value); if (decorator === 'Action') { delete schema.definition[key]; arr.push({ type: 'action', name: "".concat(schema.name, ".").concat(key), module: schema.module, definition: value }); } }); }; for (var _iterator = schemas[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var _ret = _loop(); if (_ret === "continue") continue; } } catch (err) { _didIteratorError = true; _iteratorError = err; } finally { try { if (!_iteratorNormalCompletion && _iterator.return != null) { _iterator.return(); } } finally { if (_didIteratorError) { throw _iteratorError; } } } return arr; }; module.exports = { options: { decorators: decorators, localDecorators: localDecorators, pathToType: { domains: 'domains', category: 'category', action: 'action', form: 'form', json: 'resource', application: 'application' }, preprocessor: preprocessor }, config: { prepare: function prepare(ms) { ms.categories = new Map(); ms.domains = new Map(); ms.actions = new Map(); ms.resources = { common: new Map(), domains: new Map() }; ms.applications = new Map(); ms.createAndValidate = function (type, schema, instance, options) { var value; try { value = ms.create(type, schema, instance, options); } catch (err) { return [err]; } var err = ms.validate(type, schema, value, options); return [err, value]; }; }, resolve: function resolve(ms, type, name) { if (type === 'domains') { return ms.domains.get(name); } else if (type === 'category') { return ms.categories.get(name); } else { var _name$split = name.split('.'), _name$split2 = _slicedToArray(_name$split, 2), category = _name$split2[0], entity = _name$split2[1]; if (type === 'action' && !entity) { return ms.actions.get(name); } return ms.categories.get(category)[typeToPlural(type)].get(entity); } }, processors: { domains: config.processors.domains, category: { add: [].concat(_toConsumableArray(config.processors.category.add), [addCategory]), postprocess: [].concat(_toConsumableArray(config.processors.category.postprocess), [processRelations]), validateInstance: validateCategory, creator: categoryCreator }, action: { preprocess: [preprocessCategoryData], add: [addAction], postprocess: [processAction], validateInstance: validateAction, creator: actionCreator }, form: { preprocess: [preprocessCategoryData, preprocessForm], add: [addForm], postprocess: [processForm], validateInstance: validateForm }, resource: { preprocess: [preprocessResources], add: [addResources] }, application: { add: [addApplication], postprocess: [processApplication] } }, processOrder: { domains: 0, category: 1, form: 2, action: 3, resource: 4, application: 5 } } };