UNPKG

@trapi/metadata

Version:

Generate REST-API metadata scheme from TypeScript Decorators.

59 lines 2.08 kB
"use strict"; /* * Copyright (c) 2022. * Author Peter Placzek (tada5hi) * For the full copyright and license information, * view the LICENSE file that was distributed with this source code. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.DecoratorPropertyManager = void 0; const utils_1 = require("../../utils"); const utils_2 = require("./utils"); class DecoratorPropertyManager { constructor(representation, decorators) { this.representation = representation; this.decorators = decorators; this.properties = {}; this.build(); } // ------------------------------------------- /** * Get one or more specific value(s) of the decorator arguments or typeArguments. * * @param type * @param decoratorOrIndex */ get(type, decoratorOrIndex) { if (!(0, utils_1.hasOwnProperty)(this.properties, type)) { return undefined; } const config = this.properties[type]; let decorator; if (typeof decoratorOrIndex === 'number' || typeof decoratorOrIndex === 'undefined') { decoratorOrIndex = decoratorOrIndex ?? 0; if (decoratorOrIndex < 0 || decoratorOrIndex >= this.decorators.length) { return undefined; } decorator = this.decorators[decoratorOrIndex]; } else { decorator = decoratorOrIndex; } return (0, utils_2.extractPropertyFromDecorator)(decorator, config); } // ------------------------------------------- build() { if (!this.representation.properties) { return; } const keys = Object.keys(this.representation.properties); const output = {}; for (let i = 0; i < keys.length; i++) { output[keys[i]] = (0, utils_2.buildDecoratorPropertyConfig)(this.representation.properties[keys[i]]); } this.properties = output; } } exports.DecoratorPropertyManager = DecoratorPropertyManager; //# sourceMappingURL=module.js.map