import{b as h}from"./router-C8CCuUKN.js";import"./jwt-decode.esm-CZajAnkk.js";(function(){try{var l=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},e=new Error().stack;e&&(l._sentryDebugIds=l._sentryDebugIds||{},l._sentryDebugIds[e]="fdef85f1-e7fe-4190-9b72-97b967e6be07",l._sentryDebugIdIdentifier="sentry-dbid-fdef85f1-e7fe-4190-9b72-97b967e6be07")}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 d={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,d)}static fromDTO(e,o,a,r){const d={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,d)}static async get(e){const o=await w.get(e);if(!o)throw new Error("Build not found");const{projectId:a,abstraJson:r,abstraVersion:d}=o;if(!r||!d)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,d,t):this.fromDTO(a,e,d,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 d=new Set,t=[];for(const s of e)if(!d.has(s.id)){const n=[],f=[s.id];for(d.add(s.id);f.length>0;){const g=f.shift();n.push(g);const p=r.get(g)||[];for(const i of p)d.has(i)||(d.add(i),f.push(i))}t.push(n)}t.sort((s,n)=>n.length-s.length);const y=[];for(const s of t){const n=new Map,f=new Set(s);for(const i of s)n.set(i,0);for(const i of s){const u=a.get(i)||[];for(const c of u)f.has(c)&&n.set(c,(n.get(c)||0)+1)}const g=[];for(const i of s)n.get(i)===0&&g.push(i);const p=[];for(;g.length>0;){const i=g.shift();p.push(i);const u=a.get(i)||[];for(const c of u)f.has(c)&&(n.set(c,n.get(c)-1),n.get(c)===0&&g.push(c))}for(const i of s)p.includes(i)||p.push(i);y.push(...p)}return y.map(s=>o.get(s))}}export{b as B,m as a,T as b};
//# sourceMappingURL=build-bJimrXLT.js.map
