@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.
80 lines • 2.71 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.UModule = void 0;
const attributes_1 = require("../shortcuts/attributes");
class UModule {
constructor(name) {
this._features = [];
this._models = [];
this._attributes = [];
this._name = name;
}
$name() {
return this._name;
}
$features(features) {
if (features) {
const featureNames = features.map((f) => typeof f === "string" ? f : f.$name());
return this._features.filter((f) => featureNames.includes(f.$name()));
}
return [...this._features];
}
$models(models) {
if (models) {
const modelNames = models.map((model) => typeof model === "string" ? model : model.$name());
return this._models.filter((f) => modelNames.includes(f.$name()));
}
return [...this._models];
}
$attributes() {
return [...this._attributes];
}
$attribute(attribute) {
const a = this._attributes.find((attr) => typeof attribute == "string"
? attr.$name() == attribute
: attr.$name() == attribute.$name());
return a ? a : null;
}
$attributeValue(name) {
const a = this._attributes.find((attr) => attr.$name() == name);
return a ? a.$value() : undefined;
}
$where(clause) {
return this._features.filter(clause);
}
attributes(attributes) {
this.removeAttributes(attributes);
this._attributes = this._attributes.concat(attributes);
return this;
}
models(models) {
this.removeModels(models);
this._models = this._models.concat(models);
this._models.forEach((model) => {
model.attributes([(0, attributes_1._rootModule)(this)]);
});
return this;
}
features(features) {
this.remove(features);
this._features = this._features.concat(features);
this._features.forEach((feature) => {
feature.attributes([(0, attributes_1._rootModule)(this)]);
});
return this;
}
remove(features) {
this._features = this._features.filter((feature) => !features.some((m) => m.$name() === feature.$name()));
return this;
}
removeAttributes(attributes) {
this._attributes = this._attributes.filter((attribute) => !attributes.some((a) => a.$name() == attribute.$name()));
return this;
}
removeModels(models) {
this._models = this._models.filter((model) => !models.some((m) => m.$name() == model.$name()));
return this;
}
}
exports.UModule = UModule;
//# sourceMappingURL=module.js.map