import{C as h}from"./router-BkUH5xox.js";import"./jwt-decode.esm-hjaWXwux.js";(function(){try{var u=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},e=new Error().stack;e&&(u._sentryDebugIds=u._sentryDebugIds||{},u._sentryDebugIds[e]="e2c66cab-2793-4e56-9c76-f4355cebee6b",u._sentryDebugIdIdentifier="sentry-dbid-e2c66cab-2793-4e56-9c76-f4355cebee6b")}catch{}})();class T{async list(e){return h.get(`projects/${e}/builds`)}async get(e){return h.get(`builds/${e}`)}async download(e){return h.get(`builds/${e}/download`)}}const w=new T;class b{constructor(e){this.dto=e}static async list(e){return(await w.list(e)).map(a=>new b(a))}get id(){return this.dto.id}get projectId(){return this.dto.projectId}get createdAt(){return new Date(this.dto.createdAt)}get status(){return this.dto.status}get log(){return this.dto.log}get latest(){return this.dto.latest}get abstraVersion(){return this.dto.abstraVersion}async download(){const e=await w.download(this.id);if(!e)throw new Error("Download failed");window.open(e.url,"_blank")}}class m{constructor(e,o,a,r){this.projectId=e,this.buildId=o,this.abstraVersion=a,this.project=r}static fromV0(e,o,a,r){const c={hooks:r.hooks.map(t=>({id:t.path,logQuery:{buildId:o,stageId:t.path,stageTitle:t.title},...t})),forms:r.forms.map(t=>({id:t.path,logQuery:{buildId:o,stageId:t.path,stageTitle:t.title},...t})),jobs:r.jobs.map(t=>({id:t.identifier,logQuery:{buildId:o,stageId:t.identifier,stageTitle:t.title},...t})),scripts:[],components:[],pages:[]};return new m(e,o,a,c)}static fromDTO(e,o,a,r){const c={hooks:r.hooks.map(t=>({logQuery:{buildId:o,stageId:t.id,stageTitle:t.title},...t})),forms:r.forms.map(t=>({logQuery:{buildId:o,stageId:t.id,stageTitle:t.title},...t})),jobs:r.jobs.map(t=>({logQuery:{buildId:o,stageId:t.id,stageTitle:t.title},...t})),scripts:r.scripts.map(t=>({logQuery:{buildId:o,stageId:t.id,stageTitle:t.title},...t})),components:(r.components??[]).map(t=>({logQuery:{buildId:o,stageId:t.id,stageTitle:t.title},...t})),pages:(r.pages??[]).map(t=>({logQuery:{buildId:o,stageId:t.id,stageTitle:t.title},...t}))};return new m(e,o,a,c)}static async get(e){const o=await w.get(e);if(!o)throw new Error("Build not found");const{projectId:a,abstraJson:r,abstraVersion:c}=o;if(!r||!c)return null;const t=JSON.parse(r);if(!t.version)throw new Error("Version is invalid");return t.version==="0.1"?this.fromV0(a,e,c,t):this.fromDTO(a,e,c,t)}get runtimes(){return[...this.project.forms.map(e=>({...e,type:"form"})),...this.project.hooks.map(e=>({...e,type:"hook"})),...this.project.jobs.map(e=>({...e,type:"job"})),...this.project.scripts.map(e=>({...e,type:"script"})),...this.project.components.map(e=>({...e,type:"component"})),...this.project.pages.map(e=>({...e,type:"page"}))]}get runtimesSorted(){const e=this.runtimes,o=new Map(e.map(s=>[s.id,s])),a=new Map,r=new Map;for(const s of e)a.set(s.id,[]),r.set(s.id,[]);for(const s of e)if(s.transitions)for(const n of s.transitions)o.has(n.target_id)&&(a.get(s.id)?.push(n.target_id),r.get(s.id)?.push(n.target_id),r.get(n.target_id)?.push(s.id));const c=new Set,t=[];for(const s of e)if(!c.has(s.id)){const n=[],p=[s.id];for(c.add(s.id);p.length>0;){const g=p.shift();n.push(g);const l=r.get(g)||[];for(const i of l)c.has(i)||(c.add(i),p.push(i))}t.push(n)}t.sort((s,n)=>n.length-s.length);const y=[];for(const s of t){const n=new Map,p=new Set(s);for(const i of s)n.set(i,0);for(const i of s){const f=a.get(i)||[];for(const d of f)p.has(d)&&n.set(d,(n.get(d)||0)+1)}const g=[];for(const i of s)n.get(i)===0&&g.push(i);const l=[];for(;g.length>0;){const i=g.shift();l.push(i);const f=a.get(i)||[];for(const d of f)p.has(d)&&(n.set(d,n.get(d)-1),n.get(d)===0&&g.push(d))}for(const i of s)l.includes(i)||l.push(i);y.push(...l)}return y.map(s=>o.get(s))}}export{b as B,m as a,T as b};
//# sourceMappingURL=build-DJsnjxpF.js.map
