UNPKG

@sakuli/commons

Version:

39 lines 1.58 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); var properties_decorator_1 = require("./properties.decorator"); /** * * @param propertyMap * @return a mapping function for Constructors of a decorated class which is bound to the propertyMap */ function createPropertyObjectFactory(propertyMap) { return function (cls) { if (cls.prototype.constructor.length) { throw Error("The constructor of " + cls.name + " must have 0 mandatory parameters but it has " + cls.prototype.constructor.length); } var propertyDefinitions = properties_decorator_1.getPropertyDecoratorDefinitions(cls); var dataObject = propertyDefinitions.reduce(function (agg, def) { var _a; if (propertyMap.has(def.path)) { return __assign({}, agg, (_a = {}, _a[def.property] = def.reader(propertyMap.get(def.path)), _a)); } else { return agg; } }, {}); return Object.assign(new cls(), dataObject); }; } exports.createPropertyObjectFactory = createPropertyObjectFactory; //# sourceMappingURL=create-property-object-factory.function.js.map