import{b as h}from"./router-W58Zb32N.js";import"./jwt-decode.esm-CzNJpMna.js";(function(){try{var f=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},s=new Error().stack;s&&(f._sentryDebugIds=f._sentryDebugIds||{},f._sentryDebugIds[s]="896a34a1-6283-4eeb-96c1-644f85618d32",f._sentryDebugIdIdentifier="sentry-dbid-896a34a1-6283-4eeb-96c1-644f85618d32")}catch{}})();class I{async list(s){return h.get(`projects/${s}/builds`)}async get(s){return h.get(`builds/${s}`)}async download(s){return h.get(`builds/${s}/download`)}}const w=new I;class b{constructor(s){this.dto=s}static async list(s){return(await w.list(s)).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 s=await w.download(this.id);if(!s)throw new Error("Download failed");window.open(s.url,"_blank")}}class m{constructor(s,o,a,r){this.projectId=s,this.buildId=o,this.abstraVersion=a,this.project=r}static fromV0(s,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:[]};return new m(s,o,a,d)}static fromDTO(s,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}))};return new m(s,o,a,d)}static async get(s){const o=await w.get(s);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,s,d,t):this.fromDTO(a,s,d,t)}get runtimes(){return[...this.project.forms.map(s=>({...s,type:"form"})),...this.project.hooks.map(s=>({...s,type:"hook"})),...this.project.jobs.map(s=>({...s,type:"job"})),...this.project.scripts.map(s=>({...s,type:"script"})),...this.project.components.map(s=>({...s,type:"component"}))]}get runtimesSorted(){const s=this.runtimes,o=new Map(s.map(e=>[e.id,e])),a=new Map,r=new Map;for(const e of s)a.set(e.id,[]),r.set(e.id,[]);for(const e of s)if(e.transitions)for(const n of e.transitions)o.has(n.target_id)&&(a.get(e.id)?.push(n.target_id),r.get(e.id)?.push(n.target_id),r.get(n.target_id)?.push(e.id));const d=new Set,t=[];for(const e of s)if(!d.has(e.id)){const n=[],l=[e.id];for(d.add(e.id);l.length>0;){const g=l.shift();n.push(g);const u=r.get(g)||[];for(const i of u)d.has(i)||(d.add(i),l.push(i))}t.push(n)}t.sort((e,n)=>n.length-e.length);const y=[];for(const e of t){const n=new Map,l=new Set(e);for(const i of e)n.set(i,0);for(const i of e){const p=a.get(i)||[];for(const c of p)l.has(c)&&n.set(c,(n.get(c)||0)+1)}const g=[];for(const i of e)n.get(i)===0&&g.push(i);const u=[];for(;g.length>0;){const i=g.shift();u.push(i);const p=a.get(i)||[];for(const c of p)l.has(c)&&(n.set(c,n.get(c)-1),n.get(c)===0&&g.push(c))}for(const i of e)u.includes(i)||u.push(i);y.push(...u)}return y.map(e=>o.get(e))}}export{b as B,m as a,I as b};
//# sourceMappingURL=build-DOCjIYzy.js.map
