UNPKG

@mee4dy/crud

Version:

Create a backend and frontend in 5 minutes! With our powerful full stack crud system, customize it to suit you.

3 lines (2 loc) 1.19 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("./orm-item.cjs");class c{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((u,o)=>{const a=e!=null&&e.path?`${e.path}[${o}]`:e==null?void 0:e.path,i={...e,path:a},l=new g.ORMItem(u,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:u.pk,path:[i==null?void 0:i.path,s].filter(m=>m).join(".")},d=new c(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}}exports.ORM=c; //# sourceMappingURL=orm.cjs.map