var j=Object.defineProperty;var y=(s,t,e)=>t in s?j(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var i=(s,t,e)=>(y(s,typeof t!="symbol"?t+"":t,e),e);import{C as c}from"./gateway.1c0effff.js";import{A as b}from"./activeRecord.eb203c6f.js";import"./registerWidgets.6f5be576.js";(function(){try{var s=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},t=new Error().stack;t&&(s._sentryDebugIds=s._sentryDebugIds||{},s._sentryDebugIds[t]="3260c3ad-3ac5-42e0-a49d-e3fa082c07f5",s._sentryDebugIdIdentifier="sentry-dbid-3260c3ad-3ac5-42e0-a49d-e3fa082c07f5")}catch{}})();class w{async create(t){return c.post(`projects/${t.projectId}/tables/${t.tableId}/columns`,t)}async delete(t){return c.delete(`projects/${t.projectId}/tables/${t.tableId}/columns/${t.id}`)}async update(t,e){return c.patch(`projects/${t.projectId}/tables/${t.tableId}/columns/${t.id}`,e)}}const p=new w,l=class{constructor(t){i(this,"record");this.record=b.create(p,t,"id")}static async create(t,e,r,d,a,I){const h=await p.create({name:t,type:e,nullable:r,unique:d,tableId:a,projectId:I});return"error"in h?h:new l(h)}async update(t){if(Object.keys(t).length===0||!this.id)return{success:!0,error:""};const e=await p.update({id:this.id,tableId:this.tableId,projectId:this.projectId},t);return e.error?{success:!1,error:e.error}:{success:!0,error:""}}toDTO(){return this.record.state}get id(){return this.record.get("id")}get tableId(){return this.record.get("tableId")}get projectId(){return this.record.get("projectId")}get protected(){return this.record.get("protected")}async delete(){this.id&&p.delete({id:this.id,tableId:this.tableId,projectId:this.projectId})}};let n=l;i(n,"fromDTO",t=>new l(t));class m{async list(t){return c.get(`projects/${t}/tables`)}async create(t,e){return await c.post(`projects/${t.projectId}/tables`,e)}async get(t){return c.get(`projects/${t.projectId}/tables/${t.tableId}`)}async delete(t){return c.delete(`projects/${t.projectId}/tables/${t.tableId}`)}async selectRow(t){return c.get(`projects/${t.projectId}/tables/${t.tableId}/rows`)}async update(t,e){return c.patch(`projects/${t.projectId}/tables/${t.tableId}`,e)}async insertRow(t,e){return c.post(`projects/${t.projectId}/tables/${t.tableId}/rows`,e)}async updateRow(t,e){return c.patch(`projects/${t.projectId}/tables/${t.tableId}/rows/${t.rowId}`,e)}async deleteRow(t){return c.delete(`projects/${t.projectId}/tables/${t.tableId}/rows/${t.rowId}`)}}const o=new m;class u{constructor(t,e=null){i(this,"record");i(this,"columns");this.record=b.create(o,t,"id"),this.columns=e}static async list(t){return(await o.list(t)).map(r=>new u(r))}static async create(t,e){const r=await o.create({projectId:t},{name:e});return new u(r.table,r.columns.map(a=>n.fromDTO(a)))}static async get(t,e){const r=await o.get({projectId:t,tableId:e}),d=r.table,a=r.columns.map(I=>n.fromDTO({...I,projectId:d.projectId}));return new u(d,a)}async delete(t,e){return o.delete({projectId:t,tableId:e})}async save(){const t=this.record.changes;if(Object.keys(t).length!==0)try{await o.update({id:this.id,tableId:this.id,projectId:this.projectId},t)}finally{this.record.resetChanges()}}onUpdate(t){this.record.pubsub.subscribe("update",t)}hasChanges(){return this.record.hasChanges()}getColumns(){var t,e;return(e=(t=this.columns)==null?void 0:t.map(r=>r.toDTO()))!=null?e:[]}getUnprotectedColumns(){var t,e;return(e=(t=this.columns)==null?void 0:t.filter(r=>!r.protected).map(r=>r.toDTO()))!=null?e:[]}get id(){return this.record.get("id")}get name(){return this.record.get("name")}set name(t){this.record.set("name",t)}get projectId(){return this.record.get("projectId")}async addColumn(t){const e=await n.create(t.name,t.type,t.nullable,t.unique,this.id,this.projectId);return"error"in e?{success:!1,error:e.error}:this.columns?(this.columns.push(e),{success:!0,error:""}):(this.columns=[e],{success:!0,error:""})}getColumn(t){var e;return(e=this.columns)==null?void 0:e.find(r=>r.id&&r.id===t)}async select(t={}){const e=Object.keys(t).map(r=>`${r} = :${r}`).join(" AND ");return o.selectRow({name:this.name,where:e,params:t,tableId:this.id,projectId:this.projectId})}async insertRow(t){return o.insertRow({tableId:this.id,projectId:this.projectId},t)}async updateRow(t,e){return o.updateRow({tableId:this.id,projectId:this.projectId,rowId:t},e)}async deleteRow(t){return o.deleteRow({tableId:this.id,projectId:this.projectId,rowId:t})}}export{u as T};
//# sourceMappingURL=tables.407696de.js.map
