// @bun
import{Pj as C,Qj as B,Rj as Q,Sj as R}from"../../../chunk-p4psw4vh.js";import{Vj as O,_j as z}from"../../../chunk-faxajjtr.js";import{ak as P}from"../../../chunk-ss1ckkfc.js";import{mk as x}from"../../../chunk-y5859m2g.js";import"../../../chunk-2642sss7.js";import"../../../chunk-e6x35j27.js";import"../../../chunk-ejs63yby.js";import"../../../chunk-rtfqg1mk.js";import"../../../chunk-k8jh056g.js";import{ul as N}from"../../../chunk-q532xbtw.js";import"../../../chunk-cvshp0d0.js";import"../../../chunk-6bavhfhy.js";import"../../../chunk-vrd7ga60.js";import"../../../chunk-n70kwbk5.js";import"../../../chunk-2150ew87.js";import"../../../chunk-hvdk0fxe.js";import"../../../chunk-jxkt647q.js";import"../../../chunk-6mn8xp1g.js";import"../../../chunk-6wq8tkg7.js";import{$p as J,Fq as L,Zp as k,jq as K,vs as M}from"../../../chunk-9fn5qenm.js";import"../../../chunk-5sm3bawt.js";import"../../../chunk-439fnydv.js";import"../../../chunk-h4nqzdt7.js";import"../../../chunk-g2rmdpb3.js";import"../../../chunk-fjf6txcy.js";import"../../../chunk-wsajxhdd.js";import"../../../chunk-t0zv8n0w.js";import"../../../chunk-ggmp8g5c.js";import"../../../chunk-m9a3r7rv.js";import"../../../chunk-qze335a6.js";import"../../../chunk-0dcnzv90.js";import"../../../chunk-ecs98jj1.js";import"../../../chunk-kmd1ghec.js";import"../../../chunk-hzdm0yt0.js";import"../../../chunk-ajc5mn2j.js";import"../../../chunk-fgfsckqx.js";import"../../../chunk-6vd03edf.js";import{bD as H}from"../../../chunk-bt9y3st3.js";import"../../../chunk-x3d5kerf.js";import"../../../chunk-vk8psqqh.js";import"../../../chunk-xyhgvt88.js";import{writeHeapSnapshot as U}from"v8";K("worker");await J({print:process.argv.includes("--print-logs"),dev:x.isLocal(),level:(()=>{if(x.isLocal())return"DEBUG";return"INFO"})()});Q.start();process.on("unhandledRejection",(f)=>{k.error("rejection",{e:f instanceof Error?f.message:f})});process.on("uncaughtException",(f)=>{k.error("exception",{e:f instanceof Error?f.message:f})});L.on("event",(f)=>{C.emit("global.event",f)});var g,V={async fetch(f){let j={...f.headers},F=N.header();if(F&&!j.authorization&&!j.Authorization)j.Authorization=F;let S=new Request(f.url,{method:f.method,headers:j,body:f.body}),w=await z.Default().app.fetch(S),T=await w.text();return{status:w.status,headers:Object.fromEntries(w.headers.entries()),body:T}},snapshot(){return U("server.heapsnapshot")},async server(f){if(g)await g.stop(!0);return g=await z.listen(f),{url:g.url.toString()}},async checkUpgrade(f){await B.load({directory:f.directory}).catch(()=>{}),await R().catch(()=>{})},async reload(){await P.runPromise(H.gen(function*(){yield*(yield*M.Service).invalidate(),yield*O({swallowErrors:!0})}))},async shutdown(){if(k.info("worker shutting down"),await B.disposeAllInstances(),g)await g.stop(!0)}};C.listen(V);export{V as rpc};
