UNPKG

@udraft/core

Version:

uDraft is a language and stack agnostic code-generation tool that simplifies full-stack development by converting a single YAML file into code for rapid development.

62 lines 1.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UFeature = void 0; const attributes_1 = require("../shortcuts/attributes"); const queries_1 = require("../shortcuts/queries"); class UFeature { constructor(name) { this._attributes = []; this._name = name; } $name() { return this._name; } $attribute(attribute) { const a = this._attributes.find((attr) => typeof attribute == "string" ? attr.$name() == attribute : attr.$name() == attribute.$name()); return a ? a : null; } $attributes() { return [...this._attributes]; } attributes(attributes) { this.removeAttributes(attributes); this._attributes = this._attributes.concat(attributes); this._updateRootModule(); return this; } $input() { return this._input; } $output() { return this._output; } input(model) { this._input = model; this._updateRootModule(); return this; } output(model) { this._output = model; this._updateRootModule(); return this; } _updateRootModule() { const rootModule = (0, queries_1.$attr)(this, (0, attributes_1._rootModule)()); if (!rootModule) return; const input = this.$input(); const output = this.$output(); if (input && !(0, queries_1.$attr)(input, (0, attributes_1._rootModule)())) input.attributes([(0, attributes_1._rootModule)(rootModule)]); if (output && !(0, queries_1.$attr)(output, (0, attributes_1._rootModule)())) output.attributes([(0, attributes_1._rootModule)(rootModule)]); } removeAttributes(attributes) { this._attributes = this._attributes.filter((attribute) => !attributes.some((a) => a.$name() == attribute.$name())); return this; } } exports.UFeature = UFeature; //# sourceMappingURL=feature.js.map