// @bun
import{Pj as C,Qj as B,Rj as Q,Sj as R}from"../../../chunk-evqhsx3y.js";import{Vj as O,_j as z}from"../../../chunk-wted43pt.js";import{ak as P}from"../../../chunk-h5dgqn1t.js";import{mk as x}from"../../../chunk-06zcccwx.js";import"../../../chunk-2642sss7.js";import"../../../chunk-qysx0asq.js";import"../../../chunk-ejs63yby.js";import"../../../chunk-13vg3e02.js";import"../../../chunk-tkx569sk.js";import{ul as N}from"../../../chunk-c5jsd4mw.js";import"../../../chunk-k519zv4b.js";import"../../../chunk-wdapmeyv.js";import"../../../chunk-kfn0pv7b.js";import"../../../chunk-9k6sqsj1.js";import"../../../chunk-2150ew87.js";import"../../../chunk-hvdk0fxe.js";import"../../../chunk-jxkt647q.js";import"../../../chunk-6mn8xp1g.js";import"../../../chunk-2szzt9yn.js";import{$p as J,Fq as L,Zp as k,jq as K,vs as M}from"../../../chunk-vcm8340w.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};
