@mee4dy/crud
Version:
Create a backend and frontend in 5 minutes! With our powerful full stack crud system, customize it to suit you.
63 lines (62 loc) • 1.61 kB
JavaScript
import { ORMItem as g } from "./orm-item.js";
class u {
constructor(t = [], r = "id", n, h = [], e = null) {
this.includes = [], this.setPK(r), this.setLevel(e), this.setActions(n), this.setIncludes(h), this.setItems(t);
}
setItems(t = []) {
const r = this.getPK(), n = this.getActions(), h = this.getIncludes(), e = this.getLevel();
return this.items = t.map((c, o) => {
const a = e != null && e.path ? `${e.path}[${o}]` : e == null ? void 0 : e.path, i = { ...e, path: a }, l = new g(c, r, {
commit(s) {
return n.commit ? n.commit({ ...s, level: i }) : null;
},
update(s) {
return n.update ? n.update({ ...s, level: i }) : null;
},
delete(s) {
return n.delete ? n.delete({ ...s, level: i }) : null;
}
});
return h.forEach((s) => {
if (l.hasOwnProperty(s)) {
const p = {
parentPK: c.pk,
path: [i == null ? void 0 : i.path, s].filter((m) => m).join(".")
}, d = new u(l[s], r, n, h, p).getItems();
l[s] = d;
}
}), l;
}), this;
}
getItems() {
return this.items;
}
setLevel(t) {
return this.level = t, this;
}
getLevel() {
return this.level;
}
setPK(t) {
return this.pk = t, this;
}
getPK() {
return this.pk;
}
setActions(t) {
return this.actions = t, this;
}
getActions() {
return this.actions;
}
setIncludes(t) {
return this.includes = t, this;
}
getIncludes() {
return this.includes;
}
}
export {
u as ORM
};
//# sourceMappingURL=orm.js.map