@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.
75 lines • 2.19 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.UModel = void 0;
class UModel {
constructor(name) {
this._fields = [];
this._attributes = [];
this._name = name;
}
$name() {
return this._name;
}
$field(field) {
var _a;
return ((_a = this._fields.find((f) => {
return typeof field == "string"
? f.$name() == field
: f.$name() == field.$name();
})) !== null && _a !== void 0 ? _a : null);
}
$fields() {
return [...this._fields];
}
$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);
return this;
}
name(name) {
this._name = name;
return this;
}
fields(fields) {
this.remove(fields);
this._fields = this._fields.concat(fields);
return this;
}
extends(model) {
return this.fields(model.$fields());
}
remove(fields) {
this._fields = this._fields.filter((field) => !fields.some((f) => {
if (typeof f == "string")
return f == field.$name();
else
return f.$name() == field.$name();
}));
return this;
}
pick(srcModel, fields) {
const picked = this._fields.filter((field) => fields.some((f) => {
if (typeof f == "string")
return f == field.$name();
else
return f.$name() == field.$name();
}));
srcModel.fields(picked);
return this;
}
removeAttributes(attributes) {
this._attributes = this._attributes.filter((attribute) => !attributes.some((a) => a.$name() == attribute.$name()));
return this;
}
}
exports.UModel = UModel;
//# sourceMappingURL=model.js.map