globalstorage
Version:
Global Storage is a Global Distributed Data Warehouse
132 lines (103 loc) • 4.18 kB
JavaScript
;
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
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('@metarhia/common'),
iter = _require.iter;
var _require2 = require('metaschema'),
extractDecorator = _require2.extractDecorator;
var CATEGORY_TYPES = {
Registry: 'Global',
Dictionary: 'Global',
System: 'Global',
History: 'Global',
Local: 'Local',
Log: 'Local',
View: 'Ignore',
Memory: 'Ignore'
};
var getCategoryType = function getCategoryType(schema) {
return CATEGORY_TYPES[extractDecorator(schema)] || 'Local';
};
var isGlobalCategory = function isGlobalCategory(category) {
return getCategoryType(category) === 'Global';
};
var isIgnoredCategory = function isIgnoredCategory(category) {
return getCategoryType(category) === 'Ignore';
};
var isLocalCategory = function isLocalCategory(category) {
return getCategoryType(category) === 'Local';
};
var decoratorToRealm = {
Registry: 'Global',
Dictionary: 'Global',
System: 'System',
Log: 'Local',
Local: 'Local',
Table: 'Local',
History: 'Global',
View: 'System',
Object: 'Local'
};
var getCategoryRealm = function getCategoryRealm(category) {
return decoratorToRealm[extractDecorator(category)];
};
var getCategoryFamily = function getCategoryFamily(category) {
var decorator = extractDecorator(category);
if (decorator === 'Object') {
return 'Local';
}
return decorator;
};
var constructActions = function constructActions(actions, pub, category) {
var common = {
Public: pub
};
if (!pub) common.Category = category;
return iter(actions).map(function (_ref) {
var _ref2 = _slicedToArray(_ref, 2),
key = _ref2[0],
value = _ref2[1];
return _objectSpread({}, common, {
Name: key,
Execute: value.definition.Execute
});
});
};
var extractIncludeCategoriesData = function extractIncludeCategoriesData(category, record) {
var result = [];
for (var key in category) {
var field = category[key];
if (extractDecorator(field) === 'Include') {
result.push({
category: field.category,
value: record[key]
});
}
}
return result;
};
var extractIncludeCategories = function extractIncludeCategories(category) {
var result = [];
for (var key in category) {
var field = category[key];
if (extractDecorator(field) === 'Include') {
result.push(field.category);
}
}
return result;
};
module.exports = {
getCategoryType: getCategoryType,
isGlobalCategory: isGlobalCategory,
isIgnoredCategory: isIgnoredCategory,
isLocalCategory: isLocalCategory,
getCategoryRealm: getCategoryRealm,
getCategoryFamily: getCategoryFamily,
constructActions: constructActions,
extractIncludeCategoriesData: extractIncludeCategoriesData,
extractIncludeCategories: extractIncludeCategories
};