UNPKG

sws-frontend

Version:

sws frontend project

48 lines 1.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var helpers_1 = require("../commons/helpers"); var action_config; var init = function (config) { return action_config = config; }; var any = "*"; var notype = "app"; var unknown = { type: notype, resource: any, labels: ["unknown"], description: "This is action hasn't been mapped yet.", name: "Unknown Action" }; var config = function () { return action_config; }; var list = function () { return config().actions; }; var isSame = function (a, b) { return isLike(a, b) && a.resource == b.resource; }; var isLike = function (a, b) { // must have same length if (a.labels.length < b.labels.length) return false; // exit as soon as one pair of labels don't match a.labels.forEach(function (lbl, i) { if (b.labels[i] && (b.labels[i] != lbl && b.labels[i] != '*')) return false; }); return true; }; var isImpliedBy = function (a, b) { return isLike(a, b) && (a.resource == b.resource || b.resource == any); }; var map = function (array) { return (array || []) .filter(function (e) { return list().find(function (a) { return isLike(e, a); }) != undefined; }) .map(function (e) { return specialise(list().find(function (a) { return isLike(e, a); }), e.resource); }); }; var isTemplate = function (a) { return a.type != notype; }; var asPermission = function (a) { return ({ labels: a.labels, resource: a.resource, type: a.type }); }; var specialise = function (a, id) { var clone = helpers_1.deepCopy(a); clone.resource = id; return clone; }; exports.api = { init: init, config: config, any: any, notype: notype, unknown: unknown, list: list, asPermission: asPermission, isLike: isLike, isImpliedBy: isImpliedBy, isSame: isSame, isTemplate: isTemplate, map: map, specialise: specialise }; exports.default = exports.api; //# sourceMappingURL=action.js.map