@zuplo/core 6.60.8 → 6.60.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -649,7 +649,7 @@ export default {
649
649
  `:10,l=typeof a=="string"?"\r":13;return a[a.length-1]===s&&(a=a.slice(0,-1)),a[a.length-1]===l&&(a=a.slice(0,-1)),a}t(NLe,"stripFinalNewline");import hde from"node:process";import NY from"node:path";import{fileURLToPath as RTt}from"node:url";function mde(a={}){let{env:s=process.env,platform:l=process.platform}=a;return l!=="win32"?"PATH":Object.keys(s).reverse().find(_=>_.toUpperCase()==="PATH")||"Path"}t(mde,"pathKey");var oNr=t(({cwd:a=hde.cwd(),path:s=hde.env[mde()],preferLocal:l=!0,execPath:_=hde.execPath,addExecPath:h=!0}={})=>{let b=a instanceof URL?RTt(a):a,w=NY.resolve(b),N=[];return l&&cNr(N,w),h&&lNr(N,_,w),[...N,s].join(NY.delimiter)},"npmRunPath"),cNr=t((a,s)=>{let l;for(;l!==s;)a.push(NY.join(s,"node_modules/.bin")),l=s,s=NY.resolve(s,"..")},"applyPreferLocal"),lNr=t((a,s,l)=>{let _=s instanceof URL?RTt(s):s;a.push(NY.resolve(l,_,".."))},"applyExecPath"),MTt=t(({env:a=hde.env,...s}={})=>{a={...a};let l=mde({env:a});return s.path=a[l],a[l]=oNr(s),a},"npmRunPathEnv");var uNr=t((a,s,l,_)=>{if(l==="length"||l==="prototype"||l==="arguments"||l==="caller")return;let h=Object.getOwnPropertyDescriptor(a,l),b=Object.getOwnPropertyDescriptor(s,l);!fNr(h,b)&&_||Object.defineProperty(a,l,b)},"copyProperty"),fNr=t(function(a,s){return a===void 0||a.configurable||a.writable===s.writable&&a.enumerable===s.enumerable&&a.configurable===s.configurable&&(a.writable||a.value===s.value)},"canCopyProperty"),_Nr=t((a,s)=>{let l=Object.getPrototypeOf(s);l!==Object.getPrototypeOf(a)&&Object.setPrototypeOf(a,l)},"changePrototype"),pNr=t((a,s)=>`/* Wrapped ${a}*/
650
650
  ${s}`,"wrappedToString"),dNr=Object.getOwnPropertyDescriptor(Function.prototype,"toString"),mNr=Object.getOwnPropertyDescriptor(Function.prototype.toString,"name"),hNr=t((a,s,l)=>{let _=l===""?"":`with ${l.trim()}() `,h=pNr.bind(null,_,s.toString());Object.defineProperty(h,"name",mNr),Object.defineProperty(a,"toString",{...dNr,value:h})},"changeToString");function ILe(a,s,{ignoreNonConfigurable:l=!1}={}){let{name:_}=a;for(let h of Reflect.ownKeys(s))uNr(a,s,h,l);return _Nr(a,s),hNr(a,s,_),a}t(ILe,"mimicFunction");var gde=new WeakMap,jTt=t((a,s={})=>{if(typeof a!="function")throw new TypeError("Expected a function");let l,_=0,h=a.displayName||a.name||"<anonymous>",b=t(function(...w){if(gde.set(b,++_),_===1)l=a.apply(this,w),a=null;else if(s.throw===!0)throw new Error(`Function \`${h}\` can only be called once`);return l},"onetime");return ILe(b,a),gde.set(b,_),b},"onetime");jTt.callCount=a=>{if(!gde.has(a))throw new Error(`The given function \`${a.name}\` is not wrapped by the \`onetime\` package`);return gde.get(a)};var BTt=jTt;import{constants as bNr}from"os";var $Tt=t(function(){let a=OLe-UTt+1;return Array.from({length:a},gNr)},"getRealtimeSignals"),gNr=t(function(a,s){return{name:`SIGRT${s+1}`,number:UTt+s,action:"terminate",description:"Application-specific signal (realtime)",standard:"posix"}},"getRealtimeSignal"),UTt=34,OLe=64;import{constants as yNr}from"os";var zTt=[{name:"SIGHUP",number:1,action:"terminate",description:"Terminal closed",standard:"posix"},{name:"SIGINT",number:2,action:"terminate",description:"User interruption with CTRL-C",standard:"ansi"},{name:"SIGQUIT",number:3,action:"core",description:"User interruption with CTRL-\\",standard:"posix"},{name:"SIGILL",number:4,action:"core",description:"Invalid machine instruction",standard:"ansi"},{name:"SIGTRAP",number:5,action:"core",description:"Debugger breakpoint",standard:"posix"},{name:"SIGABRT",number:6,action:"core",description:"Aborted",standard:"ansi"},{name:"SIGIOT",number:6,action:"core",description:"Aborted",standard:"bsd"},{name:"SIGBUS",number:7,action:"core",description:"Bus error due to misaligned, non-existing address or paging error",standard:"bsd"},{name:"SIGEMT",number:7,action:"terminate",description:"Command should be emulated but is not implemented",standard:"other"},{name:"SIGFPE",number:8,action:"core",description:"Floating point arithmetic error",standard:"ansi"},{name:"SIGKILL",number:9,action:"terminate",description:"Forced termination",standard:"posix",forced:!0},{name:"SIGUSR1",number:10,action:"terminate",description:"Application-specific signal",standard:"posix"},{name:"SIGSEGV",number:11,action:"core",description:"Segmentation fault",standard:"ansi"},{name:"SIGUSR2",number:12,action:"terminate",description:"Application-specific signal",standard:"posix"},{name:"SIGPIPE",number:13,action:"terminate",description:"Broken pipe or socket",standard:"posix"},{name:"SIGALRM",number:14,action:"terminate",description:"Timeout or timer",standard:"posix"},{name:"SIGTERM",number:15,action:"terminate",description:"Termination",standard:"ansi"},{name:"SIGSTKFLT",number:16,action:"terminate",description:"Stack is empty or overflowed",standard:"other"},{name:"SIGCHLD",number:17,action:"ignore",description:"Child process terminated, paused or unpaused",standard:"posix"},{name:"SIGCLD",number:17,action:"ignore",description:"Child process terminated, paused or unpaused",standard:"other"},{name:"SIGCONT",number:18,action:"unpause",description:"Unpaused",standard:"posix",forced:!0},{name:"SIGSTOP",number:19,action:"pause",description:"Paused",standard:"posix",forced:!0},{name:"SIGTSTP",number:20,action:"pause",description:'Paused using CTRL-Z or "suspend"',standard:"posix"},{name:"SIGTTIN",number:21,action:"pause",description:"Background process cannot read terminal input",standard:"posix"},{name:"SIGBREAK",number:21,action:"terminate",description:"User interruption with CTRL-BREAK",standard:"other"},{name:"SIGTTOU",number:22,action:"pause",description:"Background process cannot write to terminal output",standard:"posix"},{name:"SIGURG",number:23,action:"ignore",description:"Socket received out-of-band data",standard:"bsd"},{name:"SIGXCPU",number:24,action:"core",description:"Process timed out",standard:"bsd"},{name:"SIGXFSZ",number:25,action:"core",description:"File too big",standard:"bsd"},{name:"SIGVTALRM",number:26,action:"terminate",description:"Timeout or timer",standard:"bsd"},{name:"SIGPROF",number:27,action:"terminate",description:"Timeout or timer",standard:"bsd"},{name:"SIGWINCH",number:28,action:"ignore",description:"Terminal window size changed",standard:"bsd"},{name:"SIGIO",number:29,action:"terminate",description:"I/O is available",standard:"other"},{name:"SIGPOLL",number:29,action:"terminate",description:"Watched event",standard:"other"},{name:"SIGINFO",number:29,action:"ignore",description:"Request for process information",standard:"other"},{name:"SIGPWR",number:30,action:"terminate",description:"Device running out of power",standard:"systemv"},{name:"SIGSYS",number:31,action:"core",description:"Invalid system call",standard:"other"},{name:"SIGUNUSED",number:31,action:"terminate",description:"Invalid system call",standard:"other"}];var FLe=t(function(){let a=$Tt();return[...zTt,...a].map(vNr)},"getSignals"),vNr=t(function({name:a,number:s,description:l,action:_,forced:h=!1,standard:b}){let{signals:{[a]:w}}=yNr,N=w!==void 0;return{name:a,number:N?w:s,description:l,supported:N,action:_,forced:h,standard:b}},"normalizeSignal");var SNr=t(function(){return FLe().reduce(TNr,{})},"getSignalsByName"),TNr=t(function(a,{name:s,number:l,description:_,supported:h,action:b,forced:w,standard:N}){return{...a,[s]:{name:s,number:l,description:_,supported:h,action:b,forced:w,standard:N}}},"getSignalByName"),JTt=SNr(),xNr=t(function(){let a=FLe(),s=OLe+1,l=Array.from({length:s},(_,h)=>ENr(h,a));return Object.assign({},...l)},"getSignalsByNumber"),ENr=t(function(a,s){let l=CNr(a,s);if(l===void 0)return{};let{name:_,description:h,supported:b,action:w,forced:N,standard:B}=l;return{[a]:{name:_,number:a,description:h,supported:b,action:w,forced:N,standard:B}}},"getSignalByNumber"),CNr=t(function(a,s){let l=s.find(({name:_})=>bNr.signals[_]===a);return l!==void 0?l:s.find(_=>_.number===a)},"findSignalByNumber"),jZr=xNr();var wNr=t(({timedOut:a,timeout:s,errorCode:l,signal:_,signalDescription:h,exitCode:b,isCanceled:w})=>a?`timed out after ${s} milliseconds`:w?"was canceled":l!==void 0?`failed with ${l}`:_!==void 0?`was killed with ${_} (${h})`:b!==void 0?`failed with exit code ${b}`:"failed","getErrorPrefix"),LLe=t(({stdout:a,stderr:s,all:l,error:_,signal:h,exitCode:b,command:w,escapedCommand:N,timedOut:B,isCanceled:q,killed:le,parsed:{options:{timeout:se}}})=>{b=b===null?void 0:b,h=h===null?void 0:h;let te=h===void 0?void 0:JTt[h].description,ze=_&&_.code,De=`Command ${wNr({timedOut:B,timeout:se,errorCode:ze,signal:h,signalDescription:te,exitCode:b,isCanceled:q})}: ${w}`,xt=Object.prototype.toString.call(_)==="[object Error]",gt=xt?`${De}
651
651
  ${_.message}`:De,yr=[gt,s,a].filter(Boolean).join(`
652
- `);return xt?(_.originalMessage=_.message,_.message=yr):_=new Error(yr),_.shortMessage=gt,_.command=w,_.escapedCommand=N,_.exitCode=b,_.signal=h,_.signalDescription=te,_.stdout=a,_.stderr=s,l!==void 0&&(_.all=l),"bufferedData"in _&&delete _.bufferedData,_.failed=!0,_.timedOut=!!B,_.isCanceled=q,_.killed=le&&!B,_},"makeError");var yde=["stdin","stdout","stderr"],kNr=t(a=>yde.some(s=>a[s]!==void 0),"hasAlias"),qTt=t(a=>{if(!a)return;let{stdio:s}=a;if(s===void 0)return yde.map(_=>a[_]);if(kNr(a))throw new Error(`It's not possible to provide \`stdio\` in combination with one of ${yde.map(_=>`\`${_}\``).join(", ")}`);if(typeof s=="string")return s;if(!Array.isArray(s))throw new TypeError(`Expected \`stdio\` to be of type \`string\` or \`Array\`, got \`${typeof s}\``);let l=Math.max(s.length,yde.length);return Array.from({length:l},(_,h)=>s[h])},"normalizeStdio");var XTt=Rd(YTt(),1);import DNr from"node:os";var PNr=1e3*5,ZTt=t((a,s="SIGTERM",l={})=>{let _=a(s);return ANr(a,s,l,_),_},"spawnedKill"),ANr=t((a,s,l,_)=>{if(!NNr(s,l,_))return;let h=ONr(l),b=setTimeout(()=>{a("SIGKILL")},h);b.unref&&b.unref()},"setKillTimeout"),NNr=t((a,{forceKillAfterTimeout:s},l)=>INr(a)&&s!==!1&&l,"shouldForceKill"),INr=t(a=>a===DNr.constants.signals.SIGTERM||typeof a=="string"&&a.toUpperCase()==="SIGTERM","isSigterm"),ONr=t(({forceKillAfterTimeout:a=!0})=>{if(a===!0)return PNr;if(!Number.isFinite(a)||a<0)throw new TypeError(`Expected the \`forceKillAfterTimeout\` option to be a non-negative integer, got \`${a}\` (${typeof a})`);return a},"getForceKillAfterTimeout"),QTt=t((a,s)=>{a.kill()&&(s.isCanceled=!0)},"spawnedCancel"),FNr=t((a,s,l)=>{a.kill(s),l(Object.assign(new Error("Timed out"),{timedOut:!0,signal:s}))},"timeoutKill"),ext=t((a,{timeout:s,killSignal:l="SIGTERM"},_)=>{if(s===0||s===void 0)return _;let h,b=new Promise((N,B)=>{h=setTimeout(()=>{FNr(a,l,B)},s)}),w=_.finally(()=>{clearTimeout(h)});return Promise.race([b,w])},"setupTimeout"),txt=t(({timeout:a})=>{if(a!==void 0&&(!Number.isFinite(a)||a<0))throw new TypeError(`Expected the \`timeout\` option to be a non-negative integer, got \`${a}\` (${typeof a})`)},"validateTimeout"),rxt=t(async(a,{cleanup:s,detached:l},_)=>{if(!s||l)return _;let h=(0,XTt.default)(()=>{a.kill()});return _.finally(()=>{h()})},"setExitHandler");function nxt(a){return a!==null&&typeof a=="object"&&typeof a.pipe=="function"}t(nxt,"isStream");var ULe=Rd(axt(),1),lxt=Rd(cxt(),1);var uxt=t((a,s)=>{s===void 0||a.stdin===void 0||(nxt(s)?s.pipe(a.stdin):a.stdin.end(s))},"handleInput"),fxt=t((a,{all:s})=>{if(!s||!a.stdout&&!a.stderr)return;let l=(0,lxt.default)();return a.stdout&&l.add(a.stdout),a.stderr&&l.add(a.stderr),l},"makeAllStream"),BLe=t(async(a,s)=>{if(a){a.destroy();try{return await s}catch(l){return l.bufferedData}}},"getBufferedData"),$Le=t((a,{encoding:s,buffer:l,maxBuffer:_})=>{if(!(!a||!l))return s?(0,ULe.default)(a,{encoding:s,maxBuffer:_}):ULe.default.buffer(a,{maxBuffer:_})},"getStreamPromise"),_xt=t(async({stdout:a,stderr:s,all:l},{encoding:_,buffer:h,maxBuffer:b},w)=>{let N=$Le(a,{encoding:_,buffer:h,maxBuffer:b}),B=$Le(s,{encoding:_,buffer:h,maxBuffer:b}),q=$Le(l,{encoding:_,buffer:h,maxBuffer:b*2});try{return await Promise.all([w,N,B,q])}catch(le){return Promise.all([{error:le,signal:le.signal,timedOut:le.timedOut},BLe(a,N),BLe(s,B),BLe(l,q)])}},"getSpawnedResult");var zNr=(async()=>{})().constructor.prototype,JNr=["then","catch","finally"].map(a=>[a,Reflect.getOwnPropertyDescriptor(zNr,a)]),zLe=t((a,s)=>{for(let[l,_]of JNr){let h=typeof s=="function"?(...b)=>Reflect.apply(_.value,s(),b):_.value.bind(s);Reflect.defineProperty(a,l,{..._,value:h})}return a},"mergePromise"),pxt=t(a=>new Promise((s,l)=>{a.on("exit",(_,h)=>{s({exitCode:_,signal:h})}),a.on("error",_=>{l(_)}),a.stdin&&a.stdin.on("error",_=>{l(_)})}),"getSpawnedPromise");var dxt=t((a,s=[])=>Array.isArray(s)?[a,...s]:[a],"normalizeArgs"),qNr=/^[\w.-]+$/,VNr=/"/g,WNr=t(a=>typeof a!="string"||qNr.test(a)?a:`"${a.replace(VNr,'\\"')}"`,"escapeArg"),mxt=t((a,s)=>dxt(a,s).join(" "),"joinCommand"),hxt=t((a,s)=>dxt(a,s).map(l=>WNr(l)).join(" "),"getEscapedCommand");var KNr=1e3*1e3*100,YNr=t(({env:a,extendEnv:s,preferLocal:l,localDir:_,execPath:h})=>{let b=s?{...Ede.env,...a}:a;return l?MTt({env:b,cwd:_,execPath:h}):b},"getEnv"),XNr=t((a,s,l={})=>{let _=yxt.default._parse(a,s,l);return a=_.command,s=_.args,l=_.options,l={maxBuffer:KNr,buffer:!0,stripFinalNewline:!0,extendEnv:!0,preferLocal:!1,localDir:l.cwd||Ede.cwd(),execPath:Ede.execPath,encoding:"utf8",reject:!0,cleanup:!0,all:!1,windowsHide:!0,...l},l.env=YNr(l),l.stdio=qTt(l),Ede.platform==="win32"&&GNr.basename(a,".exe")==="cmd"&&s.unshift("/q"),{file:a,args:s,options:l,parsed:_}},"handleArguments"),JLe=t((a,s,l)=>typeof s!="string"&&!HNr.isBuffer(s)?l===void 0?void 0:"":a.stripFinalNewline?NLe(s):s,"handleOutput");function vxt(a,s,l){let _=XNr(a,s,l),h=mxt(a,s),b=hxt(a,s);txt(_.options);let w;try{w=gxt.spawn(_.file,_.args,_.options)}catch(ze){let Ie=new gxt.ChildProcess,De=Promise.reject(LLe({error:ze,stdout:"",stderr:"",all:"",command:h,escapedCommand:b,parsed:_,timedOut:!1,isCanceled:!1,killed:!1}));return zLe(Ie,De)}let N=pxt(w),B=ext(w,_.options,N),q=rxt(w,_.options,B),le={isCanceled:!1};w.kill=ZTt.bind(null,w.kill.bind(w)),w.cancel=QTt.bind(null,w,le);let te=BTt(t(async()=>{let[{error:ze,exitCode:Ie,signal:De,timedOut:xt},gt,yr,sn]=await _xt(w,_.options,q),jr=JLe(_.options,gt),Qr=JLe(_.options,yr),br=JLe(_.options,sn);if(ze||Ie!==0||De!==null){let gr=LLe({error:ze,exitCode:Ie,signal:De,stdout:jr,stderr:Qr,all:br,command:h,escapedCommand:b,parsed:_,timedOut:xt,isCanceled:le.isCanceled||(_.options.signal?_.options.signal.aborted:!1),killed:w.killed});if(!_.options.reject)return gr;throw gr}return{command:h,escapedCommand:b,exitCode:0,stdout:jr,stderr:Qr,all:br,failed:!1,timedOut:!1,isCanceled:!1,killed:!1}},"handlePromise"));return uxt(w,_.options.input),w.all=fxt(w,_.options),zLe(w,te)}t(vxt,"execa");async function wde(a,s){if(a.__ZUPLO_LOG_LEVEL=process.env.__ZUPLO_LOG_LEVEL??process.env.LOG_LEVEL,a.__ZUPLO_LOG_FORMAT=process.env.__ZUPLO_LOG_FORMAT??process.env.LOG_FORMAT,a.LOG_LEVEL=process.env.LOG_LEVEL??process.env.LOG_LEVEL,a.LOG_FORMAT=process.env.LOG_FORMAT??process.env.LOG_FORMAT,a.GIT_SHA=process.env.GIT_SHA??await ZNr(s),process.env.__ZUPLO_CONFIG&&(a.__ZUPLO_CONFIG=process.env.__ZUPLO_CONFIG),bxt(Cde.join(s,".env.zuplo"))){let l=Sxt(Cde.join(s,".env.zuplo"),"utf8"),_=qLe.default.parse(l);for(let h of Object.keys(_))if(a[h]=_[h],h==="ZUPLO_SYSTEM_CONFIGURATIONS"){let b=Buffer.from(xue.decode(_[h])).toString(),w=JSON.parse(b);for(let N of Object.keys(w))a[N]=w[N]}}if(bxt(Cde.join(s,".env"))){let l=Sxt(Cde.join(s,".env"),"utf8"),_=qLe.default.parse(l);for(let h of Object.keys(_))a[h]=_[h]}for(let l of Object.keys(a))a[l]===void 0&&delete a[l];return a}t(wde,"setEnvironment");async function ZNr(a){let s="unknown";try{let{stdout:l}=await vxt("git",["rev-parse","HEAD"],{cwd:a});l.trim().length===40&&(s=l.trim())}catch{}return s}t(ZNr,"getGitSha");async function rIr({buildId:a,output:s,sourceDirectory:l,bundledDir:_,port:h,binaryName:b,publicZuploEnvironmentVariables:w,logger:N,handleRuntimeStdio:B}){if(_){let le=FY.join(l,_,"modules.json");if(!QNr(le))throw new Error("The bundled-dir does not contain a modules.json file.");let se=await tIr(le,"utf-8").then(JSON.parse),te=await bB(l);return te.status===SA?new Promise((ze,Ie)=>{q(te.config.compatibilityDate,FY.join(l,_),se,ze,B)().catch(De=>{N.error(De),Ie(De)})}):(N.warn("Failed to get Zuplo config. Using default compatibility date."),new Promise((ze,Ie)=>{q(void 0,l,se,ze,B)().catch(De=>{N.error(De),Ie(De)})}))}else{let le=new O4({buildId:a,output:s,sourceDirectory:l,command:"dev",logger:N,publicZuploEnvironmentVariables:w??{ZUPLO_ENVIRONMENT_TYPE:"LOCAL_DEVELOPMENT"},urls:void 0});try{await le.start()}catch{N.info("Ran into irrecoverable error while building. Fix the error and rerun the command."),process.exit(1)}return new Promise((se,te)=>{le.onReload((ze,Ie)=>{(Ie||ze&&ze.errors&&ze.errors.length>0)&&te(Ie??ze?.errors),q(ze?.config?.compatibilityDate,FY.join(l,"dist"),vB(l,ze?.metafile),se,B)().catch(De=>{N.error(De),te(De)})})})}function q(le,se,te,ze,Ie){return async()=>{let De={};await wde(De,l);let xt=new Txt.ZuploWorkerd({compatibilityDate:le,scriptDirectory:se,modules:te,port:h??lh.DEV_SERVER_PORT,bindings:De,handleRuntimeStdio:Ie}),gt=b??"compiled-zup",yr=FY.join(l,"dist");await eIr(yr,{recursive:!0}),await xt.compileBinary({binaryPath:FY.join(l,"dist",gt)}),await xt.dispose(),ze(void 0)}}t(q,"compile")}t(rIr,"compileWorkerdServer");var xxt=Rd(yLe(),1);import iIr from"node:path";import nIr from"node:net";function LY(a,s){return new Promise(l=>{let _=new nIr.Socket;_.connect(s,a),_.on("connect",()=>{_.destroy(),l(!1)}),_.on("error",()=>{_.destroy(),l(!0)})})}t(LY,"isPortAvailable");var kde=class{static{t(this,"WorkerdServer")}sourceDirectory;port;debugPort;buildWatcher;workerd;logger;output;handleRuntimeStdio;onReload;constructor(s){if(this.sourceDirectory=s.sourceDirectory,this.port=s.port??lh.DEV_SERVER_PORT,this.debugPort=s.debugPort,this.logger=s.logger,this.output=s.output,this.handleRuntimeStdio=s.handleRuntimeStdio,this.onReload=s.onReload,!s.zupTestMode){let l="http://localhost:3000",_=`http://localhost:${this.port}`;this.buildWatcher=new O4({...s,logger:this.logger,publicZuploEnvironmentVariables:{...s.publicZuploEnvironmentVariables,ZUPLO_ENVIRONMENT_TYPE:"LOCAL_DEVELOPMENT"},urls:{devPortal:{defaultUrl:l,urls:[l]},api:{defaultUrl:_,urls:[_]}}}),this.buildWatcher.watchEnvFiles()}}async start(){if(!await LY("localhost",this.port))throw new Error(`Port ${this.port} is currently in use. Please use a different port.`);if(this.buildWatcher)try{await this.buildWatcher.start()}catch(l){this.output.child("api").error(l.toString());let _="Ran into irrecoverable error while starting watcher. Fix the error and restart the server.";this.output.child("api").error(_),this.logger?.info(_),process.exit(1)}this.buildWatcher?.onReload((l,_)=>{_||l&&l.errors&&l.errors.length>0||(this.onReload(l,_),this.startOrReload(l).catch(h=>{this.output.child("api").error(h.toString()),this.logger?.error(h)}))})}async startOrReload(s){try{let l={};await wde(l,this.sourceDirectory),await this.workerd?.dispose(),this.workerd=new xxt.ZuploWorkerd({compatibilityDate:s?.config?.compatibilityDate,scriptDirectory:iIr.join(this.sourceDirectory,"dist"),modules:vB(this.sourceDirectory,s?.metafile),port:this.port,inspectorPort:this.debugPort??void 0,bindings:l,handleRuntimeStdio:this.handleRuntimeStdio}),await this.workerd.serve()}catch(l){this.logger?.debug(l)}}async stop(){await this.buildWatcher?.close(),await this.workerd?.dispose()}};import{fileURLToPath as Dxt}from"node:url";import{Readable as Ext}from"node:stream";import Cxt from"node:assert";import sIr from"node:child_process";import aIr from"node:fs";import Dde from"node:os";import oIr from"node:path";function wxt(a,s){let l=import.meta.resolve(a),_=new URL(".",l),h=new URL(s,_);if(aIr.existsSync(h))return Dxt(h)}t(wxt,"getValidExecutablePath");function cIr(){let a=Dde.platform()==="win32"?"deno.exe":"deno",s=wxt("deno/package.json",a);if(s)return s;let l=lIr(),_=wxt(`@deno/${l}/package.json`,a);if(_)return _;throw new Error("Failed to locate the managed-dedicated server executable.")}t(cIr,"locateDenoExecutable");function lIr(){let a=Dde.platform();return a==="linux"?a+"-"+kxt()+"-glibc":a+"-"+kxt()}t(lIr,"getTarget");function kxt(){let a=Dde.arch();if(a!=="arm64"&&a!=="x64")throw new Error("Unsupported architecture "+Dde.arch()+". Only x64 and aarch64 binaries are available.");return a}t(kxt,"getArch");var Pde=class{static{t(this,"ZenoServer")}serverProcess;sourceDirectory;debugPort;processExitPromise;logger;output;buildWatcher;onReload;handleRuntimeStdio;denoExecutablePath;unsafelyIgnoreCertificateErrors;port=9e3;constructor(s){if(this.debugPort=s.debugPort,this.logger=s.logger,this.output=s.output,this.onReload=s.onReload,this.handleRuntimeStdio=s.handleRuntimeStdio,this.sourceDirectory=s.sourceDirectory,this.unsafelyIgnoreCertificateErrors=!!s.unsafelyIgnoreCertificateErrors,!s.zupTestMode){let l="http://localhost:3000",_=`http://localhost:${this.port}`;this.buildWatcher=new O4({sourceDirectory:s.sourceDirectory,command:"dev",logger:s.logger,publicZuploEnvironmentVariables:{...s.publicZuploEnvironmentVariables,ZUPLO_ENVIRONMENT_TYPE:"LOCAL_DEVELOPMENT"},buildId:"dev",output:s.output,urls:{devPortal:{defaultUrl:l,urls:[l]},api:{defaultUrl:_,urls:[_]}}}),this.buildWatcher.watchEnvFiles()}this.denoExecutablePath=cIr()}getServeArgs(){let s=`${oIr.dirname(Dxt(import.meta.url))}/zeno.js`,l=["run","--allow-read","--allow-net","--allow-env","--allow-write",...this.unsafelyIgnoreCertificateErrors?["--unsafely-ignore-certificate-errors"]:[]];return this.debugPort&&l.push(`--inspect=127.0.0.1:${this.debugPort}`),l.push(s),l.push("--dir",this.sourceDirectory),l}async getUnavailablePorts(){let s=[];return this.debugPort&&!await LY("127.0.0.1",this.debugPort)&&s.push(this.debugPort),await LY("127.0.0.1",this.port)||s.push(this.port),s}async start(){let s=await this.getUnavailablePorts();if(s.length>0)throw new Error("The following ports are not available: "+s.join(", "));if(this.buildWatcher)try{await this.buildWatcher.start()}catch(l){this.output.child("api").error(l.toString());let _="Ran into irrecoverable error while starting watcher. Fix the error and restart the server.";this.output.child("api").error(_),this.logger?.info(_),process.exit(1)}await this.startOrReload(),this.buildWatcher?.onReload((l,_)=>{_||l&&l.errors&&l.errors.length>0||(this.onReload(l,_),this.startOrReload().catch(h=>{this.output.child("api").error(h.toString()),this.logger?.error(h)}))})}async startOrReload(){try{await this.dispose(),this.logger?.info("Starting managed-dedicated local server");let s=this.getServeArgs();this.serverProcess=sIr.spawn(this.denoExecutablePath,s,{stdio:["pipe","pipe","pipe"],env:{...process.env,FORCE_COLOR:"1"}}),Cxt(this.serverProcess.stdout instanceof Ext),Cxt(this.serverProcess.stderr instanceof Ext),this.processExitPromise=this.waitForExit(),this.handleRuntimeStdio(this.serverProcess.stdout,this.serverProcess.stderr)}catch(s){this.logger?.debug(s)}}waitForExit(){return new Promise(s=>{this.serverProcess?.once("exit",s)})}dispose(){return this.serverProcess?.kill("SIGKILL"),this.processExitPromise}async stop(){await this.dispose(),await this.buildWatcher?.close()}};async function uIr(a){let s=await bB(a),l=!1;return s.status===SA&&(l=s.config.projectType!=="managed-edge"||(s.config.flags?.managedDedicatedFlags?.useZeno??!1)),l||process.env.ZUPLO_DEV_RUNTIME==="zeno"}t(uIr,"useZeno");async function fIr({sourceDirectory:a,port:s,debugPort:l,publicZuploEnvironmentVariables:_,unsafelyIgnoreCertificateErrors:h,logger:b,output:w,buildId:N,onReload:B,handleRuntimeStdio:q}){process.env.ZUPLO_IS_LOCAL_DEVELOPMENT="true";let le;await uIr(a)?(b.debug("Starting managed-dedicated local dev server."),le=new Pde({sourceDirectory:a,debugPort:l,logger:b,output:w,publicZuploEnvironmentVariables:_,onReload:B,handleRuntimeStdio:q,unsafelyIgnoreCertificateErrors:h})):(b.debug("Starting edge local dev server."),le=new kde({sourceDirectory:a,command:"dev",port:s,debugPort:l,publicZuploEnvironmentVariables:_,logger:b,output:w,buildId:N,onReload:B,handleRuntimeStdio:q})),await le.start();async function se(){await le.stop()}t(se,"handle"),process.on("SIGTERM",se),process.on("SIGINT",se)}t(fIr,"startDevServer");var Qy=new URL("./public/",import.meta.url);import{readFile as Ade}from"fs/promises";var _v=class{static{t(this,"BaseComponent")}#e;#n;#t;scriptFile;cssFile;constructor(a){this.#t=a}async getStyles(){return this.cssFile?this.#t?await Ade(this.cssFile,"utf-8"):(this.#e=this.#e??await Ade(this.cssFile,"utf-8"),this.#e):null}async getScript(){return this.scriptFile?this.#t?await Ade(this.scriptFile,"utf-8"):(this.#n=this.#n??await Ade(this.scriptFile,"utf-8"),this.#n):null}};var Pxt=class extends _v{static{t(this,"Layout")}cssFile=new URL("./layout/style.css",Qy);scriptFile=new URL("./layout/script.js",Qy);async toHTML(a){return`<!DOCTYPE html>
652
+ `);return xt?(_.originalMessage=_.message,_.message=yr):_=new Error(yr),_.shortMessage=gt,_.command=w,_.escapedCommand=N,_.exitCode=b,_.signal=h,_.signalDescription=te,_.stdout=a,_.stderr=s,l!==void 0&&(_.all=l),"bufferedData"in _&&delete _.bufferedData,_.failed=!0,_.timedOut=!!B,_.isCanceled=q,_.killed=le&&!B,_},"makeError");var yde=["stdin","stdout","stderr"],kNr=t(a=>yde.some(s=>a[s]!==void 0),"hasAlias"),qTt=t(a=>{if(!a)return;let{stdio:s}=a;if(s===void 0)return yde.map(_=>a[_]);if(kNr(a))throw new Error(`It's not possible to provide \`stdio\` in combination with one of ${yde.map(_=>`\`${_}\``).join(", ")}`);if(typeof s=="string")return s;if(!Array.isArray(s))throw new TypeError(`Expected \`stdio\` to be of type \`string\` or \`Array\`, got \`${typeof s}\``);let l=Math.max(s.length,yde.length);return Array.from({length:l},(_,h)=>s[h])},"normalizeStdio");var XTt=Rd(YTt(),1);import DNr from"node:os";var PNr=1e3*5,ZTt=t((a,s="SIGTERM",l={})=>{let _=a(s);return ANr(a,s,l,_),_},"spawnedKill"),ANr=t((a,s,l,_)=>{if(!NNr(s,l,_))return;let h=ONr(l),b=setTimeout(()=>{a("SIGKILL")},h);b.unref&&b.unref()},"setKillTimeout"),NNr=t((a,{forceKillAfterTimeout:s},l)=>INr(a)&&s!==!1&&l,"shouldForceKill"),INr=t(a=>a===DNr.constants.signals.SIGTERM||typeof a=="string"&&a.toUpperCase()==="SIGTERM","isSigterm"),ONr=t(({forceKillAfterTimeout:a=!0})=>{if(a===!0)return PNr;if(!Number.isFinite(a)||a<0)throw new TypeError(`Expected the \`forceKillAfterTimeout\` option to be a non-negative integer, got \`${a}\` (${typeof a})`);return a},"getForceKillAfterTimeout"),QTt=t((a,s)=>{a.kill()&&(s.isCanceled=!0)},"spawnedCancel"),FNr=t((a,s,l)=>{a.kill(s),l(Object.assign(new Error("Timed out"),{timedOut:!0,signal:s}))},"timeoutKill"),ext=t((a,{timeout:s,killSignal:l="SIGTERM"},_)=>{if(s===0||s===void 0)return _;let h,b=new Promise((N,B)=>{h=setTimeout(()=>{FNr(a,l,B)},s)}),w=_.finally(()=>{clearTimeout(h)});return Promise.race([b,w])},"setupTimeout"),txt=t(({timeout:a})=>{if(a!==void 0&&(!Number.isFinite(a)||a<0))throw new TypeError(`Expected the \`timeout\` option to be a non-negative integer, got \`${a}\` (${typeof a})`)},"validateTimeout"),rxt=t(async(a,{cleanup:s,detached:l},_)=>{if(!s||l)return _;let h=(0,XTt.default)(()=>{a.kill()});return _.finally(()=>{h()})},"setExitHandler");function nxt(a){return a!==null&&typeof a=="object"&&typeof a.pipe=="function"}t(nxt,"isStream");var ULe=Rd(axt(),1),lxt=Rd(cxt(),1);var uxt=t((a,s)=>{s===void 0||a.stdin===void 0||(nxt(s)?s.pipe(a.stdin):a.stdin.end(s))},"handleInput"),fxt=t((a,{all:s})=>{if(!s||!a.stdout&&!a.stderr)return;let l=(0,lxt.default)();return a.stdout&&l.add(a.stdout),a.stderr&&l.add(a.stderr),l},"makeAllStream"),BLe=t(async(a,s)=>{if(a){a.destroy();try{return await s}catch(l){return l.bufferedData}}},"getBufferedData"),$Le=t((a,{encoding:s,buffer:l,maxBuffer:_})=>{if(!(!a||!l))return s?(0,ULe.default)(a,{encoding:s,maxBuffer:_}):ULe.default.buffer(a,{maxBuffer:_})},"getStreamPromise"),_xt=t(async({stdout:a,stderr:s,all:l},{encoding:_,buffer:h,maxBuffer:b},w)=>{let N=$Le(a,{encoding:_,buffer:h,maxBuffer:b}),B=$Le(s,{encoding:_,buffer:h,maxBuffer:b}),q=$Le(l,{encoding:_,buffer:h,maxBuffer:b*2});try{return await Promise.all([w,N,B,q])}catch(le){return Promise.all([{error:le,signal:le.signal,timedOut:le.timedOut},BLe(a,N),BLe(s,B),BLe(l,q)])}},"getSpawnedResult");var zNr=(async()=>{})().constructor.prototype,JNr=["then","catch","finally"].map(a=>[a,Reflect.getOwnPropertyDescriptor(zNr,a)]),zLe=t((a,s)=>{for(let[l,_]of JNr){let h=typeof s=="function"?(...b)=>Reflect.apply(_.value,s(),b):_.value.bind(s);Reflect.defineProperty(a,l,{..._,value:h})}return a},"mergePromise"),pxt=t(a=>new Promise((s,l)=>{a.on("exit",(_,h)=>{s({exitCode:_,signal:h})}),a.on("error",_=>{l(_)}),a.stdin&&a.stdin.on("error",_=>{l(_)})}),"getSpawnedPromise");var dxt=t((a,s=[])=>Array.isArray(s)?[a,...s]:[a],"normalizeArgs"),qNr=/^[\w.-]+$/,VNr=/"/g,WNr=t(a=>typeof a!="string"||qNr.test(a)?a:`"${a.replace(VNr,'\\"')}"`,"escapeArg"),mxt=t((a,s)=>dxt(a,s).join(" "),"joinCommand"),hxt=t((a,s)=>dxt(a,s).map(l=>WNr(l)).join(" "),"getEscapedCommand");var KNr=1e3*1e3*100,YNr=t(({env:a,extendEnv:s,preferLocal:l,localDir:_,execPath:h})=>{let b=s?{...Ede.env,...a}:a;return l?MTt({env:b,cwd:_,execPath:h}):b},"getEnv"),XNr=t((a,s,l={})=>{let _=yxt.default._parse(a,s,l);return a=_.command,s=_.args,l=_.options,l={maxBuffer:KNr,buffer:!0,stripFinalNewline:!0,extendEnv:!0,preferLocal:!1,localDir:l.cwd||Ede.cwd(),execPath:Ede.execPath,encoding:"utf8",reject:!0,cleanup:!0,all:!1,windowsHide:!0,...l},l.env=YNr(l),l.stdio=qTt(l),Ede.platform==="win32"&&GNr.basename(a,".exe")==="cmd"&&s.unshift("/q"),{file:a,args:s,options:l,parsed:_}},"handleArguments"),JLe=t((a,s,l)=>typeof s!="string"&&!HNr.isBuffer(s)?l===void 0?void 0:"":a.stripFinalNewline?NLe(s):s,"handleOutput");function vxt(a,s,l){let _=XNr(a,s,l),h=mxt(a,s),b=hxt(a,s);txt(_.options);let w;try{w=gxt.spawn(_.file,_.args,_.options)}catch(ze){let Ie=new gxt.ChildProcess,De=Promise.reject(LLe({error:ze,stdout:"",stderr:"",all:"",command:h,escapedCommand:b,parsed:_,timedOut:!1,isCanceled:!1,killed:!1}));return zLe(Ie,De)}let N=pxt(w),B=ext(w,_.options,N),q=rxt(w,_.options,B),le={isCanceled:!1};w.kill=ZTt.bind(null,w.kill.bind(w)),w.cancel=QTt.bind(null,w,le);let te=BTt(t(async()=>{let[{error:ze,exitCode:Ie,signal:De,timedOut:xt},gt,yr,sn]=await _xt(w,_.options,q),jr=JLe(_.options,gt),Qr=JLe(_.options,yr),br=JLe(_.options,sn);if(ze||Ie!==0||De!==null){let gr=LLe({error:ze,exitCode:Ie,signal:De,stdout:jr,stderr:Qr,all:br,command:h,escapedCommand:b,parsed:_,timedOut:xt,isCanceled:le.isCanceled||(_.options.signal?_.options.signal.aborted:!1),killed:w.killed});if(!_.options.reject)return gr;throw gr}return{command:h,escapedCommand:b,exitCode:0,stdout:jr,stderr:Qr,all:br,failed:!1,timedOut:!1,isCanceled:!1,killed:!1}},"handlePromise"));return uxt(w,_.options.input),w.all=fxt(w,_.options),zLe(w,te)}t(vxt,"execa");async function wde(a,s){if(a.__ZUPLO_LOG_LEVEL=process.env.__ZUPLO_LOG_LEVEL??process.env.LOG_LEVEL,a.__ZUPLO_LOG_FORMAT=process.env.__ZUPLO_LOG_FORMAT??process.env.LOG_FORMAT,a.LOG_LEVEL=process.env.LOG_LEVEL??process.env.LOG_LEVEL,a.LOG_FORMAT=process.env.LOG_FORMAT??process.env.LOG_FORMAT,a.GIT_SHA=process.env.GIT_SHA??await ZNr(s),process.env.__ZUPLO_CONFIG&&(a.__ZUPLO_CONFIG=process.env.__ZUPLO_CONFIG),bxt(Cde.join(s,".env.zuplo"))){let l=Sxt(Cde.join(s,".env.zuplo"),"utf8"),_=qLe.default.parse(l);for(let h of Object.keys(_))if(a[h]=_[h],h==="ZUPLO_SYSTEM_CONFIGURATIONS"){let b=Buffer.from(xue.decode(_[h])).toString(),w=JSON.parse(b);for(let N of Object.keys(w))a[N]=w[N]}}if(bxt(Cde.join(s,".env"))){let l=Sxt(Cde.join(s,".env"),"utf8"),_=qLe.default.parse(l);for(let h of Object.keys(_))a[h]=_[h]}for(let l of Object.keys(a))a[l]===void 0&&delete a[l];return a}t(wde,"setEnvironment");async function ZNr(a){let s="unknown";try{let{stdout:l}=await vxt("git",["rev-parse","HEAD"],{cwd:a});l.trim().length===40&&(s=l.trim())}catch{}return s}t(ZNr,"getGitSha");async function rIr({buildId:a,output:s,sourceDirectory:l,bundledDir:_,port:h,binaryName:b,publicZuploEnvironmentVariables:w,logger:N,handleRuntimeStdio:B}){if(_){let le=FY.join(l,_,"modules.json");if(!QNr(le))throw new Error("The bundled-dir does not contain a modules.json file.");let se=await tIr(le,"utf-8").then(JSON.parse),te=await bB(l);return te.status===SA?new Promise((ze,Ie)=>{q(te.config.compatibilityDate,FY.join(l,_),se,ze,B)().catch(De=>{N.error(De),Ie(De)})}):(N.warn("Failed to get Zuplo config. Using default compatibility date."),new Promise((ze,Ie)=>{q(void 0,l,se,ze,B)().catch(De=>{N.error(De),Ie(De)})}))}else{let le=new O4({buildId:a,output:s,sourceDirectory:l,command:"dev",logger:N,publicZuploEnvironmentVariables:w??{ZUPLO_ENVIRONMENT_TYPE:"LOCAL_DEVELOPMENT"},urls:void 0});try{await le.start()}catch{N.info("Ran into irrecoverable error while building. Fix the error and rerun the command."),process.exit(1)}return new Promise((se,te)=>{le.onReload((ze,Ie)=>{(Ie||ze&&ze.errors&&ze.errors.length>0)&&te(Ie??ze?.errors),q(ze?.config?.compatibilityDate,FY.join(l,"dist"),vB(l,ze?.metafile),se,B)().catch(De=>{N.error(De),te(De)})})})}function q(le,se,te,ze,Ie){return async()=>{let De={};await wde(De,l);let xt=new Txt.ZuploWorkerd({compatibilityDate:le,scriptDirectory:se,modules:te,port:h??lh.DEV_SERVER_PORT,bindings:De,handleRuntimeStdio:Ie}),gt=b??"compiled-zup",yr=FY.join(l,"dist");await eIr(yr,{recursive:!0}),await xt.compileBinary({binaryPath:FY.join(l,"dist",gt)}),await xt.dispose(),ze(void 0)}}t(q,"compile")}t(rIr,"compileWorkerdServer");var xxt=Rd(yLe(),1);import iIr from"node:path";import nIr from"node:net";function LY(a,s){return new Promise(l=>{let _=new nIr.Socket;_.connect(s,a),_.on("connect",()=>{_.destroy(),l(!1)}),_.on("error",()=>{_.destroy(),l(!0)})})}t(LY,"isPortAvailable");var kde=class{static{t(this,"WorkerdServer")}sourceDirectory;port;debugPort;buildWatcher;workerd;logger;output;handleRuntimeStdio;onReload;constructor(s){if(this.sourceDirectory=s.sourceDirectory,this.port=s.port??lh.DEV_SERVER_PORT,this.debugPort=s.debugPort,this.logger=s.logger,this.output=s.output,this.handleRuntimeStdio=s.handleRuntimeStdio,this.onReload=s.onReload,!s.zupTestMode){let l="http://localhost:3000",_=`http://localhost:${this.port}`;this.buildWatcher=new O4({...s,logger:this.logger,publicZuploEnvironmentVariables:{...s.publicZuploEnvironmentVariables,ZUPLO_ENVIRONMENT_TYPE:"LOCAL_DEVELOPMENT"},urls:{devPortal:{defaultUrl:l,urls:[l]},api:{defaultUrl:_,urls:[_]}}}),this.buildWatcher.watchEnvFiles()}}async start(){if(!await LY("localhost",this.port))throw new Error(`Port ${this.port} is currently in use. Please use a different port.`);if(this.buildWatcher)try{await this.buildWatcher.start()}catch(l){this.output.child("api").error(l.toString());let _="Ran into irrecoverable error while starting watcher. Fix the error and restart the server.";this.output.child("api").error(_),this.logger?.info(_),process.exit(1)}this.buildWatcher?.onReload((l,_)=>{_||l&&l.errors&&l.errors.length>0||(this.onReload(l,_),this.startOrReload(l).catch(h=>{this.output.child("api").error(h.toString()),this.logger?.error(h)}))})}async startOrReload(s){try{let l={};await wde(l,this.sourceDirectory),await this.workerd?.dispose(),this.workerd=new xxt.ZuploWorkerd({compatibilityDate:s?.config?.compatibilityDate,scriptDirectory:iIr.join(this.sourceDirectory,"dist"),modules:vB(this.sourceDirectory,s?.metafile),port:this.port,inspectorPort:this.debugPort??void 0,bindings:l,handleRuntimeStdio:this.handleRuntimeStdio}),await this.workerd.serve()}catch(l){this.logger?.debug(l)}}async stop(){await this.buildWatcher?.close(),await this.workerd?.dispose()}};import{fileURLToPath as Dxt}from"node:url";import{Readable as Ext}from"node:stream";import Cxt from"node:assert";import sIr from"node:child_process";import aIr from"node:fs";import Dde from"node:os";import oIr from"node:path";function wxt(a,s){let l=import.meta.resolve(a),_=new URL(".",l),h=new URL(s,_);if(aIr.existsSync(h))return Dxt(h)}t(wxt,"getValidExecutablePath");function cIr(){let a=Dde.platform()==="win32"?"deno.exe":"deno",s=wxt("deno/package.json",a);if(s)return s;let l=lIr(),_=wxt(`@deno/${l}/package.json`,a);if(_)return _;throw new Error("Failed to locate the managed-dedicated server executable.")}t(cIr,"locateDenoExecutable");function lIr(){let a=Dde.platform();return a==="linux"?a+"-"+kxt()+"-glibc":a+"-"+kxt()}t(lIr,"getTarget");function kxt(){let a=Dde.arch();if(a!=="arm64"&&a!=="x64")throw new Error("Unsupported architecture "+Dde.arch()+". Only x64 and aarch64 binaries are available.");return a}t(kxt,"getArch");var Pde=class{static{t(this,"ZenoServer")}serverProcess;sourceDirectory;port;debugPort;processExitPromise;logger;output;buildWatcher;onReload;handleRuntimeStdio;denoExecutablePath;unsafelyIgnoreCertificateErrors;constructor(s){if(this.port=s.port??9e3,this.debugPort=s.debugPort,this.logger=s.logger,this.output=s.output,this.onReload=s.onReload,this.handleRuntimeStdio=s.handleRuntimeStdio,this.sourceDirectory=s.sourceDirectory,this.unsafelyIgnoreCertificateErrors=!!s.unsafelyIgnoreCertificateErrors,!s.zupTestMode){let l="http://localhost:3000",_=`http://localhost:${this.port}`;this.buildWatcher=new O4({sourceDirectory:s.sourceDirectory,command:"dev",logger:s.logger,publicZuploEnvironmentVariables:{...s.publicZuploEnvironmentVariables,ZUPLO_ENVIRONMENT_TYPE:"LOCAL_DEVELOPMENT"},buildId:"dev",output:s.output,urls:{devPortal:{defaultUrl:l,urls:[l]},api:{defaultUrl:_,urls:[_]}}}),this.buildWatcher.watchEnvFiles()}this.denoExecutablePath=cIr()}getServeArgs(){let s=`${oIr.dirname(Dxt(import.meta.url))}/zeno.js`,l=["run","--allow-read","--allow-net","--allow-env","--allow-write",...this.unsafelyIgnoreCertificateErrors?["--unsafely-ignore-certificate-errors"]:[]];return this.debugPort&&l.push(`--inspect=127.0.0.1:${this.debugPort}`),l.push(s),l.push("--dir",this.sourceDirectory),l.push("--port",this.port.toString()),l}async getUnavailablePorts(){let s=[];return this.debugPort&&!await LY("127.0.0.1",this.debugPort)&&s.push(this.debugPort),await LY("127.0.0.1",this.port)||s.push(this.port),s}async start(){let s=await this.getUnavailablePorts();if(s.length>0)throw new Error("The following ports are not available: "+s.join(", "));if(this.buildWatcher)try{await this.buildWatcher.start()}catch(l){this.output.child("api").error(l.toString());let _="Ran into irrecoverable error while starting watcher. Fix the error and restart the server.";this.output.child("api").error(_),this.logger?.info(_),process.exit(1)}await this.startOrReload(),this.buildWatcher?.onReload((l,_)=>{_||l&&l.errors&&l.errors.length>0||(this.onReload(l,_),this.startOrReload().catch(h=>{this.output.child("api").error(h.toString()),this.logger?.error(h)}))})}async startOrReload(){try{await this.dispose(),this.logger?.info("Starting managed-dedicated local server");let s=this.getServeArgs();this.serverProcess=sIr.spawn(this.denoExecutablePath,s,{stdio:["pipe","pipe","pipe"],env:{...process.env,FORCE_COLOR:"1"}}),Cxt(this.serverProcess.stdout instanceof Ext),Cxt(this.serverProcess.stderr instanceof Ext),this.processExitPromise=this.waitForExit(),this.handleRuntimeStdio(this.serverProcess.stdout,this.serverProcess.stderr)}catch(s){this.logger?.debug(s)}}waitForExit(){return new Promise(s=>{this.serverProcess?.once("exit",s)})}dispose(){return this.serverProcess?.kill("SIGKILL"),this.processExitPromise}async stop(){await this.dispose(),await this.buildWatcher?.close()}};async function uIr(a){let s=await bB(a),l=!1;return s.status===SA&&(l=s.config.projectType!=="managed-edge"||(s.config.flags?.managedDedicatedFlags?.useZeno??!1)),l||process.env.ZUPLO_DEV_RUNTIME==="zeno"}t(uIr,"useZeno");async function fIr({sourceDirectory:a,port:s,debugPort:l,publicZuploEnvironmentVariables:_,unsafelyIgnoreCertificateErrors:h,logger:b,output:w,buildId:N,onReload:B,handleRuntimeStdio:q}){process.env.ZUPLO_IS_LOCAL_DEVELOPMENT="true";let le;await uIr(a)?(b.debug("Starting managed-dedicated local dev server."),le=new Pde({sourceDirectory:a,port:s,debugPort:l,logger:b,output:w,publicZuploEnvironmentVariables:_,onReload:B,handleRuntimeStdio:q,unsafelyIgnoreCertificateErrors:h})):(b.debug("Starting edge local dev server."),le=new kde({sourceDirectory:a,command:"dev",port:s,debugPort:l,publicZuploEnvironmentVariables:_,logger:b,output:w,buildId:N,onReload:B,handleRuntimeStdio:q})),await le.start();async function se(){await le.stop()}t(se,"handle"),process.on("SIGTERM",se),process.on("SIGINT",se)}t(fIr,"startDevServer");var Qy=new URL("./public/",import.meta.url);import{readFile as Ade}from"fs/promises";var _v=class{static{t(this,"BaseComponent")}#e;#n;#t;scriptFile;cssFile;constructor(a){this.#t=a}async getStyles(){return this.cssFile?this.#t?await Ade(this.cssFile,"utf-8"):(this.#e=this.#e??await Ade(this.cssFile,"utf-8"),this.#e):null}async getScript(){return this.scriptFile?this.#t?await Ade(this.scriptFile,"utf-8"):(this.#n=this.#n??await Ade(this.scriptFile,"utf-8"),this.#n):null}};var Pxt=class extends _v{static{t(this,"Layout")}cssFile=new URL("./layout/style.css",Qy);scriptFile=new URL("./layout/script.js",Qy);async toHTML(a){return`<!DOCTYPE html>
653
653
  <html lang="en">
654
654
  <head>
655
655
  <meta charset="UTF-8" />
package/index.minified.js CHANGED
@@ -654,7 +654,7 @@ export default {
654
654
  `:10,l=typeof a=="string"?"\r":13;return a[a.length-1]===s&&(a=a.slice(0,-1)),a[a.length-1]===l&&(a=a.slice(0,-1)),a}t(LLe,"stripFinalNewline");import hde from"node:process";import NY from"node:path";import{fileURLToPath as MTt}from"node:url";function mde(a={}){let{env:s=process.env,platform:l=process.platform}=a;return l!=="win32"?"PATH":Object.keys(s).reverse().find(_=>_.toUpperCase()==="PATH")||"Path"}t(mde,"pathKey");var gNr=t(({cwd:a=hde.cwd(),path:s=hde.env[mde()],preferLocal:l=!0,execPath:_=hde.execPath,addExecPath:h=!0}={})=>{let b=a instanceof URL?MTt(a):a,w=NY.resolve(b),N=[];return l&&yNr(N,w),h&&vNr(N,_,w),[...N,s].join(NY.delimiter)},"npmRunPath"),yNr=t((a,s)=>{let l;for(;l!==s;)a.push(NY.join(s,"node_modules/.bin")),l=s,s=NY.resolve(s,"..")},"applyPreferLocal"),vNr=t((a,s,l)=>{let _=s instanceof URL?MTt(s):s;a.push(NY.resolve(l,_,".."))},"applyExecPath"),jTt=t(({env:a=hde.env,...s}={})=>{a={...a};let l=mde({env:a});return s.path=a[l],a[l]=gNr(s),a},"npmRunPathEnv");var bNr=t((a,s,l,_)=>{if(l==="length"||l==="prototype"||l==="arguments"||l==="caller")return;let h=Object.getOwnPropertyDescriptor(a,l),b=Object.getOwnPropertyDescriptor(s,l);!SNr(h,b)&&_||Object.defineProperty(a,l,b)},"copyProperty"),SNr=t(function(a,s){return a===void 0||a.configurable||a.writable===s.writable&&a.enumerable===s.enumerable&&a.configurable===s.configurable&&(a.writable||a.value===s.value)},"canCopyProperty"),TNr=t((a,s)=>{let l=Object.getPrototypeOf(s);l!==Object.getPrototypeOf(a)&&Object.setPrototypeOf(a,l)},"changePrototype"),xNr=t((a,s)=>`/* Wrapped ${a}*/
655
655
  ${s}`,"wrappedToString"),ENr=Object.getOwnPropertyDescriptor(Function.prototype,"toString"),CNr=Object.getOwnPropertyDescriptor(Function.prototype.toString,"name"),wNr=t((a,s,l)=>{let _=l===""?"":`with ${l.trim()}() `,h=xNr.bind(null,_,s.toString());Object.defineProperty(h,"name",CNr),Object.defineProperty(a,"toString",{...ENr,value:h})},"changeToString");function RLe(a,s,{ignoreNonConfigurable:l=!1}={}){let{name:_}=a;for(let h of Reflect.ownKeys(s))bNr(a,s,h,l);return TNr(a,s),wNr(a,s,_),a}t(RLe,"mimicFunction");var gde=new WeakMap,BTt=t((a,s={})=>{if(typeof a!="function")throw new TypeError("Expected a function");let l,_=0,h=a.displayName||a.name||"<anonymous>",b=t(function(...w){if(gde.set(b,++_),_===1)l=a.apply(this,w),a=null;else if(s.throw===!0)throw new Error(`Function \`${h}\` can only be called once`);return l},"onetime");return RLe(b,a),gde.set(b,_),b},"onetime");BTt.callCount=a=>{if(!gde.has(a))throw new Error(`The given function \`${a.name}\` is not wrapped by the \`onetime\` package`);return gde.get(a)};var $Tt=BTt;import{constants as ANr}from"os";var UTt=t(function(){let a=MLe-zTt+1;return Array.from({length:a},kNr)},"getRealtimeSignals"),kNr=t(function(a,s){return{name:`SIGRT${s+1}`,number:zTt+s,action:"terminate",description:"Application-specific signal (realtime)",standard:"posix"}},"getRealtimeSignal"),zTt=34,MLe=64;import{constants as DNr}from"os";var JTt=[{name:"SIGHUP",number:1,action:"terminate",description:"Terminal closed",standard:"posix"},{name:"SIGINT",number:2,action:"terminate",description:"User interruption with CTRL-C",standard:"ansi"},{name:"SIGQUIT",number:3,action:"core",description:"User interruption with CTRL-\\",standard:"posix"},{name:"SIGILL",number:4,action:"core",description:"Invalid machine instruction",standard:"ansi"},{name:"SIGTRAP",number:5,action:"core",description:"Debugger breakpoint",standard:"posix"},{name:"SIGABRT",number:6,action:"core",description:"Aborted",standard:"ansi"},{name:"SIGIOT",number:6,action:"core",description:"Aborted",standard:"bsd"},{name:"SIGBUS",number:7,action:"core",description:"Bus error due to misaligned, non-existing address or paging error",standard:"bsd"},{name:"SIGEMT",number:7,action:"terminate",description:"Command should be emulated but is not implemented",standard:"other"},{name:"SIGFPE",number:8,action:"core",description:"Floating point arithmetic error",standard:"ansi"},{name:"SIGKILL",number:9,action:"terminate",description:"Forced termination",standard:"posix",forced:!0},{name:"SIGUSR1",number:10,action:"terminate",description:"Application-specific signal",standard:"posix"},{name:"SIGSEGV",number:11,action:"core",description:"Segmentation fault",standard:"ansi"},{name:"SIGUSR2",number:12,action:"terminate",description:"Application-specific signal",standard:"posix"},{name:"SIGPIPE",number:13,action:"terminate",description:"Broken pipe or socket",standard:"posix"},{name:"SIGALRM",number:14,action:"terminate",description:"Timeout or timer",standard:"posix"},{name:"SIGTERM",number:15,action:"terminate",description:"Termination",standard:"ansi"},{name:"SIGSTKFLT",number:16,action:"terminate",description:"Stack is empty or overflowed",standard:"other"},{name:"SIGCHLD",number:17,action:"ignore",description:"Child process terminated, paused or unpaused",standard:"posix"},{name:"SIGCLD",number:17,action:"ignore",description:"Child process terminated, paused or unpaused",standard:"other"},{name:"SIGCONT",number:18,action:"unpause",description:"Unpaused",standard:"posix",forced:!0},{name:"SIGSTOP",number:19,action:"pause",description:"Paused",standard:"posix",forced:!0},{name:"SIGTSTP",number:20,action:"pause",description:'Paused using CTRL-Z or "suspend"',standard:"posix"},{name:"SIGTTIN",number:21,action:"pause",description:"Background process cannot read terminal input",standard:"posix"},{name:"SIGBREAK",number:21,action:"terminate",description:"User interruption with CTRL-BREAK",standard:"other"},{name:"SIGTTOU",number:22,action:"pause",description:"Background process cannot write to terminal output",standard:"posix"},{name:"SIGURG",number:23,action:"ignore",description:"Socket received out-of-band data",standard:"bsd"},{name:"SIGXCPU",number:24,action:"core",description:"Process timed out",standard:"bsd"},{name:"SIGXFSZ",number:25,action:"core",description:"File too big",standard:"bsd"},{name:"SIGVTALRM",number:26,action:"terminate",description:"Timeout or timer",standard:"bsd"},{name:"SIGPROF",number:27,action:"terminate",description:"Timeout or timer",standard:"bsd"},{name:"SIGWINCH",number:28,action:"ignore",description:"Terminal window size changed",standard:"bsd"},{name:"SIGIO",number:29,action:"terminate",description:"I/O is available",standard:"other"},{name:"SIGPOLL",number:29,action:"terminate",description:"Watched event",standard:"other"},{name:"SIGINFO",number:29,action:"ignore",description:"Request for process information",standard:"other"},{name:"SIGPWR",number:30,action:"terminate",description:"Device running out of power",standard:"systemv"},{name:"SIGSYS",number:31,action:"core",description:"Invalid system call",standard:"other"},{name:"SIGUNUSED",number:31,action:"terminate",description:"Invalid system call",standard:"other"}];var jLe=t(function(){let a=UTt();return[...JTt,...a].map(PNr)},"getSignals"),PNr=t(function({name:a,number:s,description:l,action:_,forced:h=!1,standard:b}){let{signals:{[a]:w}}=DNr,N=w!==void 0;return{name:a,number:N?w:s,description:l,supported:N,action:_,forced:h,standard:b}},"normalizeSignal");var NNr=t(function(){return jLe().reduce(INr,{})},"getSignalsByName"),INr=t(function(a,{name:s,number:l,description:_,supported:h,action:b,forced:w,standard:N}){return{...a,[s]:{name:s,number:l,description:_,supported:h,action:b,forced:w,standard:N}}},"getSignalByName"),qTt=NNr(),ONr=t(function(){let a=jLe(),s=MLe+1,l=Array.from({length:s},(_,h)=>FNr(h,a));return Object.assign({},...l)},"getSignalsByNumber"),FNr=t(function(a,s){let l=LNr(a,s);if(l===void 0)return{};let{name:_,description:h,supported:b,action:w,forced:N,standard:M}=l;return{[a]:{name:_,number:a,description:h,supported:b,action:w,forced:N,standard:M}}},"getSignalByNumber"),LNr=t(function(a,s){let l=s.find(({name:_})=>ANr.signals[_]===a);return l!==void 0?l:s.find(_=>_.number===a)},"findSignalByNumber"),uQr=ONr();var RNr=t(({timedOut:a,timeout:s,errorCode:l,signal:_,signalDescription:h,exitCode:b,isCanceled:w})=>a?`timed out after ${s} milliseconds`:w?"was canceled":l!==void 0?`failed with ${l}`:_!==void 0?`was killed with ${_} (${h})`:b!==void 0?`failed with exit code ${b}`:"failed","getErrorPrefix"),BLe=t(({stdout:a,stderr:s,all:l,error:_,signal:h,exitCode:b,command:w,escapedCommand:N,timedOut:M,isCanceled:J,killed:le,parsed:{options:{timeout:se}}})=>{b=b===null?void 0:b,h=h===null?void 0:h;let te=h===void 0?void 0:qTt[h].description,ze=_&&_.code,De=`Command ${RNr({timedOut:M,timeout:se,errorCode:ze,signal:h,signalDescription:te,exitCode:b,isCanceled:J})}: ${w}`,Et=Object.prototype.toString.call(_)==="[object Error]",gt=Et?`${De}
656
656
  ${_.message}`:De,yr=[gt,s,a].filter(Boolean).join(`
657
- `);return Et?(_.originalMessage=_.message,_.message=yr):_=new Error(yr),_.shortMessage=gt,_.command=w,_.escapedCommand=N,_.exitCode=b,_.signal=h,_.signalDescription=te,_.stdout=a,_.stderr=s,l!==void 0&&(_.all=l),"bufferedData"in _&&delete _.bufferedData,_.failed=!0,_.timedOut=!!M,_.isCanceled=J,_.killed=le&&!M,_},"makeError");var yde=["stdin","stdout","stderr"],MNr=t(a=>yde.some(s=>a[s]!==void 0),"hasAlias"),VTt=t(a=>{if(!a)return;let{stdio:s}=a;if(s===void 0)return yde.map(_=>a[_]);if(MNr(a))throw new Error(`It's not possible to provide \`stdio\` in combination with one of ${yde.map(_=>`\`${_}\``).join(", ")}`);if(typeof s=="string")return s;if(!Array.isArray(s))throw new TypeError(`Expected \`stdio\` to be of type \`string\` or \`Array\`, got \`${typeof s}\``);let l=Math.max(s.length,yde.length);return Array.from({length:l},(_,h)=>s[h])},"normalizeStdio");var ZTt=$p(XTt(),1);import jNr from"node:os";var BNr=1e3*5,QTt=t((a,s="SIGTERM",l={})=>{let _=a(s);return $Nr(a,s,l,_),_},"spawnedKill"),$Nr=t((a,s,l,_)=>{if(!UNr(s,l,_))return;let h=JNr(l),b=setTimeout(()=>{a("SIGKILL")},h);b.unref&&b.unref()},"setKillTimeout"),UNr=t((a,{forceKillAfterTimeout:s},l)=>zNr(a)&&s!==!1&&l,"shouldForceKill"),zNr=t(a=>a===jNr.constants.signals.SIGTERM||typeof a=="string"&&a.toUpperCase()==="SIGTERM","isSigterm"),JNr=t(({forceKillAfterTimeout:a=!0})=>{if(a===!0)return BNr;if(!Number.isFinite(a)||a<0)throw new TypeError(`Expected the \`forceKillAfterTimeout\` option to be a non-negative integer, got \`${a}\` (${typeof a})`);return a},"getForceKillAfterTimeout"),ext=t((a,s)=>{a.kill()&&(s.isCanceled=!0)},"spawnedCancel"),qNr=t((a,s,l)=>{a.kill(s),l(Object.assign(new Error("Timed out"),{timedOut:!0,signal:s}))},"timeoutKill"),txt=t((a,{timeout:s,killSignal:l="SIGTERM"},_)=>{if(s===0||s===void 0)return _;let h,b=new Promise((N,M)=>{h=setTimeout(()=>{qNr(a,l,M)},s)}),w=_.finally(()=>{clearTimeout(h)});return Promise.race([b,w])},"setupTimeout"),rxt=t(({timeout:a})=>{if(a!==void 0&&(!Number.isFinite(a)||a<0))throw new TypeError(`Expected the \`timeout\` option to be a non-negative integer, got \`${a}\` (${typeof a})`)},"validateTimeout"),nxt=t(async(a,{cleanup:s,detached:l},_)=>{if(!s||l)return _;let h=(0,ZTt.default)(()=>{a.kill()});return _.finally(()=>{h()})},"setExitHandler");function ixt(a){return a!==null&&typeof a=="object"&&typeof a.pipe=="function"}t(ixt,"isStream");var VLe=$p(oxt(),1),uxt=$p(lxt(),1);var fxt=t((a,s)=>{s===void 0||a.stdin===void 0||(ixt(s)?s.pipe(a.stdin):a.stdin.end(s))},"handleInput"),_xt=t((a,{all:s})=>{if(!s||!a.stdout&&!a.stderr)return;let l=(0,uxt.default)();return a.stdout&&l.add(a.stdout),a.stderr&&l.add(a.stderr),l},"makeAllStream"),JLe=t(async(a,s)=>{if(a){a.destroy();try{return await s}catch(l){return l.bufferedData}}},"getBufferedData"),qLe=t((a,{encoding:s,buffer:l,maxBuffer:_})=>{if(!(!a||!l))return s?(0,VLe.default)(a,{encoding:s,maxBuffer:_}):VLe.default.buffer(a,{maxBuffer:_})},"getStreamPromise"),pxt=t(async({stdout:a,stderr:s,all:l},{encoding:_,buffer:h,maxBuffer:b},w)=>{let N=qLe(a,{encoding:_,buffer:h,maxBuffer:b}),M=qLe(s,{encoding:_,buffer:h,maxBuffer:b}),J=qLe(l,{encoding:_,buffer:h,maxBuffer:b*2});try{return await Promise.all([w,N,M,J])}catch(le){return Promise.all([{error:le,signal:le.signal,timedOut:le.timedOut},JLe(a,N),JLe(s,M),JLe(l,J)])}},"getSpawnedResult");var ZNr=(async()=>{})().constructor.prototype,QNr=["then","catch","finally"].map(a=>[a,Reflect.getOwnPropertyDescriptor(ZNr,a)]),WLe=t((a,s)=>{for(let[l,_]of QNr){let h=typeof s=="function"?(...b)=>Reflect.apply(_.value,s(),b):_.value.bind(s);Reflect.defineProperty(a,l,{..._,value:h})}return a},"mergePromise"),dxt=t(a=>new Promise((s,l)=>{a.on("exit",(_,h)=>{s({exitCode:_,signal:h})}),a.on("error",_=>{l(_)}),a.stdin&&a.stdin.on("error",_=>{l(_)})}),"getSpawnedPromise");var mxt=t((a,s=[])=>Array.isArray(s)?[a,...s]:[a],"normalizeArgs"),eIr=/^[\w.-]+$/,tIr=/"/g,rIr=t(a=>typeof a!="string"||eIr.test(a)?a:`"${a.replace(tIr,'\\"')}"`,"escapeArg"),hxt=t((a,s)=>mxt(a,s).join(" "),"joinCommand"),gxt=t((a,s)=>mxt(a,s).map(l=>rIr(l)).join(" "),"getEscapedCommand");var sIr=1e3*1e3*100,aIr=t(({env:a,extendEnv:s,preferLocal:l,localDir:_,execPath:h})=>{let b=s?{...Ede.env,...a}:a;return l?jTt({env:b,cwd:_,execPath:h}):b},"getEnv"),oIr=t((a,s,l={})=>{let _=vxt.default._parse(a,s,l);return a=_.command,s=_.args,l=_.options,l={maxBuffer:sIr,buffer:!0,stripFinalNewline:!0,extendEnv:!0,preferLocal:!1,localDir:l.cwd||Ede.cwd(),execPath:Ede.execPath,encoding:"utf8",reject:!0,cleanup:!0,all:!1,windowsHide:!0,...l},l.env=aIr(l),l.stdio=VTt(l),Ede.platform==="win32"&&iIr.basename(a,".exe")==="cmd"&&s.unshift("/q"),{file:a,args:s,options:l,parsed:_}},"handleArguments"),HLe=t((a,s,l)=>typeof s!="string"&&!nIr.isBuffer(s)?l===void 0?void 0:"":a.stripFinalNewline?LLe(s):s,"handleOutput");function bxt(a,s,l){let _=oIr(a,s,l),h=hxt(a,s),b=gxt(a,s);rxt(_.options);let w;try{w=yxt.spawn(_.file,_.args,_.options)}catch(ze){let Ie=new yxt.ChildProcess,De=Promise.reject(BLe({error:ze,stdout:"",stderr:"",all:"",command:h,escapedCommand:b,parsed:_,timedOut:!1,isCanceled:!1,killed:!1}));return WLe(Ie,De)}let N=dxt(w),M=txt(w,_.options,N),J=nxt(w,_.options,M),le={isCanceled:!1};w.kill=QTt.bind(null,w.kill.bind(w)),w.cancel=ext.bind(null,w,le);let te=$Tt(t(async()=>{let[{error:ze,exitCode:Ie,signal:De,timedOut:Et},gt,yr,sn]=await pxt(w,_.options,J),jr=HLe(_.options,gt),Qr=HLe(_.options,yr),br=HLe(_.options,sn);if(ze||Ie!==0||De!==null){let gr=BLe({error:ze,exitCode:Ie,signal:De,stdout:jr,stderr:Qr,all:br,command:h,escapedCommand:b,parsed:_,timedOut:Et,isCanceled:le.isCanceled||(_.options.signal?_.options.signal.aborted:!1),killed:w.killed});if(!_.options.reject)return gr;throw gr}return{command:h,escapedCommand:b,exitCode:0,stdout:jr,stderr:Qr,all:br,failed:!1,timedOut:!1,isCanceled:!1,killed:!1}},"handlePromise"));return fxt(w,_.options.input),w.all=_xt(w,_.options),WLe(w,te)}t(bxt,"execa");async function wde(a,s){if(a.__ZUPLO_LOG_LEVEL=process.env.__ZUPLO_LOG_LEVEL??process.env.LOG_LEVEL,a.__ZUPLO_LOG_FORMAT=process.env.__ZUPLO_LOG_FORMAT??process.env.LOG_FORMAT,a.LOG_LEVEL=process.env.LOG_LEVEL??process.env.LOG_LEVEL,a.LOG_FORMAT=process.env.LOG_FORMAT??process.env.LOG_FORMAT,a.GIT_SHA=process.env.GIT_SHA??await cIr(s),process.env.__ZUPLO_CONFIG&&(a.__ZUPLO_CONFIG=process.env.__ZUPLO_CONFIG),Sxt(Cde.join(s,".env.zuplo"))){let l=Txt(Cde.join(s,".env.zuplo"),"utf8"),_=GLe.default.parse(l);for(let h of Object.keys(_))if(a[h]=_[h],h==="ZUPLO_SYSTEM_CONFIGURATIONS"){let b=Buffer.from(xue.decode(_[h])).toString(),w=JSON.parse(b);for(let N of Object.keys(w))a[N]=w[N]}}if(Sxt(Cde.join(s,".env"))){let l=Txt(Cde.join(s,".env"),"utf8"),_=GLe.default.parse(l);for(let h of Object.keys(_))a[h]=_[h]}for(let l of Object.keys(a))a[l]===void 0&&delete a[l];return a}t(wde,"setEnvironment");async function cIr(a){let s="unknown";try{let{stdout:l}=await bxt("git",["rev-parse","HEAD"],{cwd:a});l.trim().length===40&&(s=l.trim())}catch{}return s}t(cIr,"getGitSha");async function _Ir({buildId:a,output:s,sourceDirectory:l,bundledDir:_,port:h,binaryName:b,publicZuploEnvironmentVariables:w,logger:N,handleRuntimeStdio:M}){if(_){let le=FY.join(l,_,"modules.json");if(!lIr(le))throw new Error("The bundled-dir does not contain a modules.json file.");let se=await fIr(le,"utf-8").then(JSON.parse),te=await bB(l);return te.status===EA?new Promise((ze,Ie)=>{J(te.config.compatibilityDate,FY.join(l,_),se,ze,M)().catch(De=>{N.error(De),Ie(De)})}):(N.warn("Failed to get Zuplo config. Using default compatibility date."),new Promise((ze,Ie)=>{J(void 0,l,se,ze,M)().catch(De=>{N.error(De),Ie(De)})}))}else{let le=new KA({buildId:a,output:s,sourceDirectory:l,command:"dev",logger:N,publicZuploEnvironmentVariables:w??{ZUPLO_ENVIRONMENT_TYPE:"LOCAL_DEVELOPMENT"},urls:void 0});try{await le.start()}catch{N.info("Ran into irrecoverable error while building. Fix the error and rerun the command."),process.exit(1)}return new Promise((se,te)=>{le.onReload((ze,Ie)=>{(Ie||ze&&ze.errors&&ze.errors.length>0)&&te(Ie??ze?.errors),J(ze?.config?.compatibilityDate,FY.join(l,"dist"),vB(l,ze?.metafile),se,M)().catch(De=>{N.error(De),te(De)})})})}function J(le,se,te,ze,Ie){return async()=>{let De={};await wde(De,l);let Et=new xxt.ZuploWorkerd({compatibilityDate:le,scriptDirectory:se,modules:te,port:h??$m.DEV_SERVER_PORT,bindings:De,handleRuntimeStdio:Ie}),gt=b??"compiled-zup",yr=FY.join(l,"dist");await uIr(yr,{recursive:!0}),await Et.compileBinary({binaryPath:FY.join(l,"dist",gt)}),await Et.dispose(),ze(void 0)}}t(J,"compile")}t(_Ir,"compileWorkerdServer");var Ext=$p(CLe(),1);import dIr from"node:path";import pIr from"node:net";function LY(a,s){return new Promise(l=>{let _=new pIr.Socket;_.connect(s,a),_.on("connect",()=>{_.destroy(),l(!1)}),_.on("error",()=>{_.destroy(),l(!0)})})}t(LY,"isPortAvailable");var kde=class{static{t(this,"WorkerdServer")}sourceDirectory;port;debugPort;buildWatcher;workerd;logger;output;handleRuntimeStdio;onReload;constructor(s){if(this.sourceDirectory=s.sourceDirectory,this.port=s.port??$m.DEV_SERVER_PORT,this.debugPort=s.debugPort,this.logger=s.logger,this.output=s.output,this.handleRuntimeStdio=s.handleRuntimeStdio,this.onReload=s.onReload,!s.zupTestMode){let l="http://localhost:3000",_=`http://localhost:${this.port}`;this.buildWatcher=new KA({...s,logger:this.logger,publicZuploEnvironmentVariables:{...s.publicZuploEnvironmentVariables,ZUPLO_ENVIRONMENT_TYPE:"LOCAL_DEVELOPMENT"},urls:{devPortal:{defaultUrl:l,urls:[l]},api:{defaultUrl:_,urls:[_]}}}),this.buildWatcher.watchEnvFiles()}}async start(){if(!await LY("localhost",this.port))throw new Error(`Port ${this.port} is currently in use. Please use a different port.`);if(this.buildWatcher)try{await this.buildWatcher.start()}catch(l){this.output.child("api").error(l.toString());let _="Ran into irrecoverable error while starting watcher. Fix the error and restart the server.";this.output.child("api").error(_),this.logger?.info(_),process.exit(1)}this.buildWatcher?.onReload((l,_)=>{_||l&&l.errors&&l.errors.length>0||(this.onReload(l,_),this.startOrReload(l).catch(h=>{this.output.child("api").error(h.toString()),this.logger?.error(h)}))})}async startOrReload(s){try{let l={};await wde(l,this.sourceDirectory),await this.workerd?.dispose(),this.workerd=new Ext.ZuploWorkerd({compatibilityDate:s?.config?.compatibilityDate,scriptDirectory:dIr.join(this.sourceDirectory,"dist"),modules:vB(this.sourceDirectory,s?.metafile),port:this.port,inspectorPort:this.debugPort??void 0,bindings:l,handleRuntimeStdio:this.handleRuntimeStdio}),await this.workerd.serve()}catch(l){this.logger?.debug(l)}}async stop(){await this.buildWatcher?.close(),await this.workerd?.dispose()}};import{fileURLToPath as Pxt}from"node:url";import{Readable as Cxt}from"node:stream";import wxt from"node:assert";import mIr from"node:child_process";import hIr from"node:fs";import Dde from"node:os";import gIr from"node:path";function kxt(a,s){let l=import.meta.resolve(a),_=new URL(".",l),h=new URL(s,_);if(hIr.existsSync(h))return Pxt(h)}t(kxt,"getValidExecutablePath");function yIr(){let a=Dde.platform()==="win32"?"deno.exe":"deno",s=kxt("deno/package.json",a);if(s)return s;let l=vIr(),_=kxt(`@deno/${l}/package.json`,a);if(_)return _;throw new Error("Failed to locate the managed-dedicated server executable.")}t(yIr,"locateDenoExecutable");function vIr(){let a=Dde.platform();return a==="linux"?a+"-"+Dxt()+"-glibc":a+"-"+Dxt()}t(vIr,"getTarget");function Dxt(){let a=Dde.arch();if(a!=="arm64"&&a!=="x64")throw new Error("Unsupported architecture "+Dde.arch()+". Only x64 and aarch64 binaries are available.");return a}t(Dxt,"getArch");var Pde=class{static{t(this,"ZenoServer")}serverProcess;sourceDirectory;debugPort;processExitPromise;logger;output;buildWatcher;onReload;handleRuntimeStdio;denoExecutablePath;unsafelyIgnoreCertificateErrors;port=9e3;constructor(s){if(this.debugPort=s.debugPort,this.logger=s.logger,this.output=s.output,this.onReload=s.onReload,this.handleRuntimeStdio=s.handleRuntimeStdio,this.sourceDirectory=s.sourceDirectory,this.unsafelyIgnoreCertificateErrors=!!s.unsafelyIgnoreCertificateErrors,!s.zupTestMode){let l="http://localhost:3000",_=`http://localhost:${this.port}`;this.buildWatcher=new KA({sourceDirectory:s.sourceDirectory,command:"dev",logger:s.logger,publicZuploEnvironmentVariables:{...s.publicZuploEnvironmentVariables,ZUPLO_ENVIRONMENT_TYPE:"LOCAL_DEVELOPMENT"},buildId:"dev",output:s.output,urls:{devPortal:{defaultUrl:l,urls:[l]},api:{defaultUrl:_,urls:[_]}}}),this.buildWatcher.watchEnvFiles()}this.denoExecutablePath=yIr()}getServeArgs(){let s=`${gIr.dirname(Pxt(import.meta.url))}/zeno.js`,l=["run","--allow-read","--allow-net","--allow-env","--allow-write",...this.unsafelyIgnoreCertificateErrors?["--unsafely-ignore-certificate-errors"]:[]];return this.debugPort&&l.push(`--inspect=127.0.0.1:${this.debugPort}`),l.push(s),l.push("--dir",this.sourceDirectory),l}async getUnavailablePorts(){let s=[];return this.debugPort&&!await LY("127.0.0.1",this.debugPort)&&s.push(this.debugPort),await LY("127.0.0.1",this.port)||s.push(this.port),s}async start(){let s=await this.getUnavailablePorts();if(s.length>0)throw new Error("The following ports are not available: "+s.join(", "));if(this.buildWatcher)try{await this.buildWatcher.start()}catch(l){this.output.child("api").error(l.toString());let _="Ran into irrecoverable error while starting watcher. Fix the error and restart the server.";this.output.child("api").error(_),this.logger?.info(_),process.exit(1)}await this.startOrReload(),this.buildWatcher?.onReload((l,_)=>{_||l&&l.errors&&l.errors.length>0||(this.onReload(l,_),this.startOrReload().catch(h=>{this.output.child("api").error(h.toString()),this.logger?.error(h)}))})}async startOrReload(){try{await this.dispose(),this.logger?.info("Starting managed-dedicated local server");let s=this.getServeArgs();this.serverProcess=mIr.spawn(this.denoExecutablePath,s,{stdio:["pipe","pipe","pipe"],env:{...process.env,FORCE_COLOR:"1"}}),wxt(this.serverProcess.stdout instanceof Cxt),wxt(this.serverProcess.stderr instanceof Cxt),this.processExitPromise=this.waitForExit(),this.handleRuntimeStdio(this.serverProcess.stdout,this.serverProcess.stderr)}catch(s){this.logger?.debug(s)}}waitForExit(){return new Promise(s=>{this.serverProcess?.once("exit",s)})}dispose(){return this.serverProcess?.kill("SIGKILL"),this.processExitPromise}async stop(){await this.dispose(),await this.buildWatcher?.close()}};async function bIr(a){let s=await bB(a),l=!1;return s.status===EA&&(l=s.config.projectType!=="managed-edge"||(s.config.flags?.managedDedicatedFlags?.useZeno??!1)),l||process.env.ZUPLO_DEV_RUNTIME==="zeno"}t(bIr,"useZeno");async function SIr({sourceDirectory:a,port:s,debugPort:l,publicZuploEnvironmentVariables:_,unsafelyIgnoreCertificateErrors:h,logger:b,output:w,buildId:N,onReload:M,handleRuntimeStdio:J}){process.env.ZUPLO_IS_LOCAL_DEVELOPMENT="true";let le;await bIr(a)?(b.debug("Starting managed-dedicated local dev server."),le=new Pde({sourceDirectory:a,debugPort:l,logger:b,output:w,publicZuploEnvironmentVariables:_,onReload:M,handleRuntimeStdio:J,unsafelyIgnoreCertificateErrors:h})):(b.debug("Starting edge local dev server."),le=new kde({sourceDirectory:a,command:"dev",port:s,debugPort:l,publicZuploEnvironmentVariables:_,logger:b,output:w,buildId:N,onReload:M,handleRuntimeStdio:J})),await le.start();async function se(){await le.stop()}t(se,"handle"),process.on("SIGTERM",se),process.on("SIGINT",se)}t(SIr,"startDevServer");var e1=new URL("./public/",import.meta.url);import{readFile as Ade}from"fs/promises";var _v=class{static{t(this,"BaseComponent")}#e;#n;#t;scriptFile;cssFile;constructor(a){this.#t=a}async getStyles(){return this.cssFile?this.#t?await Ade(this.cssFile,"utf-8"):(this.#e=this.#e??await Ade(this.cssFile,"utf-8"),this.#e):null}async getScript(){return this.scriptFile?this.#t?await Ade(this.scriptFile,"utf-8"):(this.#n=this.#n??await Ade(this.scriptFile,"utf-8"),this.#n):null}};var Axt=class extends _v{static{t(this,"Layout")}cssFile=new URL("./layout/style.css",e1);scriptFile=new URL("./layout/script.js",e1);async toHTML(a){return`<!DOCTYPE html>
657
+ `);return Et?(_.originalMessage=_.message,_.message=yr):_=new Error(yr),_.shortMessage=gt,_.command=w,_.escapedCommand=N,_.exitCode=b,_.signal=h,_.signalDescription=te,_.stdout=a,_.stderr=s,l!==void 0&&(_.all=l),"bufferedData"in _&&delete _.bufferedData,_.failed=!0,_.timedOut=!!M,_.isCanceled=J,_.killed=le&&!M,_},"makeError");var yde=["stdin","stdout","stderr"],MNr=t(a=>yde.some(s=>a[s]!==void 0),"hasAlias"),VTt=t(a=>{if(!a)return;let{stdio:s}=a;if(s===void 0)return yde.map(_=>a[_]);if(MNr(a))throw new Error(`It's not possible to provide \`stdio\` in combination with one of ${yde.map(_=>`\`${_}\``).join(", ")}`);if(typeof s=="string")return s;if(!Array.isArray(s))throw new TypeError(`Expected \`stdio\` to be of type \`string\` or \`Array\`, got \`${typeof s}\``);let l=Math.max(s.length,yde.length);return Array.from({length:l},(_,h)=>s[h])},"normalizeStdio");var ZTt=$p(XTt(),1);import jNr from"node:os";var BNr=1e3*5,QTt=t((a,s="SIGTERM",l={})=>{let _=a(s);return $Nr(a,s,l,_),_},"spawnedKill"),$Nr=t((a,s,l,_)=>{if(!UNr(s,l,_))return;let h=JNr(l),b=setTimeout(()=>{a("SIGKILL")},h);b.unref&&b.unref()},"setKillTimeout"),UNr=t((a,{forceKillAfterTimeout:s},l)=>zNr(a)&&s!==!1&&l,"shouldForceKill"),zNr=t(a=>a===jNr.constants.signals.SIGTERM||typeof a=="string"&&a.toUpperCase()==="SIGTERM","isSigterm"),JNr=t(({forceKillAfterTimeout:a=!0})=>{if(a===!0)return BNr;if(!Number.isFinite(a)||a<0)throw new TypeError(`Expected the \`forceKillAfterTimeout\` option to be a non-negative integer, got \`${a}\` (${typeof a})`);return a},"getForceKillAfterTimeout"),ext=t((a,s)=>{a.kill()&&(s.isCanceled=!0)},"spawnedCancel"),qNr=t((a,s,l)=>{a.kill(s),l(Object.assign(new Error("Timed out"),{timedOut:!0,signal:s}))},"timeoutKill"),txt=t((a,{timeout:s,killSignal:l="SIGTERM"},_)=>{if(s===0||s===void 0)return _;let h,b=new Promise((N,M)=>{h=setTimeout(()=>{qNr(a,l,M)},s)}),w=_.finally(()=>{clearTimeout(h)});return Promise.race([b,w])},"setupTimeout"),rxt=t(({timeout:a})=>{if(a!==void 0&&(!Number.isFinite(a)||a<0))throw new TypeError(`Expected the \`timeout\` option to be a non-negative integer, got \`${a}\` (${typeof a})`)},"validateTimeout"),nxt=t(async(a,{cleanup:s,detached:l},_)=>{if(!s||l)return _;let h=(0,ZTt.default)(()=>{a.kill()});return _.finally(()=>{h()})},"setExitHandler");function ixt(a){return a!==null&&typeof a=="object"&&typeof a.pipe=="function"}t(ixt,"isStream");var VLe=$p(oxt(),1),uxt=$p(lxt(),1);var fxt=t((a,s)=>{s===void 0||a.stdin===void 0||(ixt(s)?s.pipe(a.stdin):a.stdin.end(s))},"handleInput"),_xt=t((a,{all:s})=>{if(!s||!a.stdout&&!a.stderr)return;let l=(0,uxt.default)();return a.stdout&&l.add(a.stdout),a.stderr&&l.add(a.stderr),l},"makeAllStream"),JLe=t(async(a,s)=>{if(a){a.destroy();try{return await s}catch(l){return l.bufferedData}}},"getBufferedData"),qLe=t((a,{encoding:s,buffer:l,maxBuffer:_})=>{if(!(!a||!l))return s?(0,VLe.default)(a,{encoding:s,maxBuffer:_}):VLe.default.buffer(a,{maxBuffer:_})},"getStreamPromise"),pxt=t(async({stdout:a,stderr:s,all:l},{encoding:_,buffer:h,maxBuffer:b},w)=>{let N=qLe(a,{encoding:_,buffer:h,maxBuffer:b}),M=qLe(s,{encoding:_,buffer:h,maxBuffer:b}),J=qLe(l,{encoding:_,buffer:h,maxBuffer:b*2});try{return await Promise.all([w,N,M,J])}catch(le){return Promise.all([{error:le,signal:le.signal,timedOut:le.timedOut},JLe(a,N),JLe(s,M),JLe(l,J)])}},"getSpawnedResult");var ZNr=(async()=>{})().constructor.prototype,QNr=["then","catch","finally"].map(a=>[a,Reflect.getOwnPropertyDescriptor(ZNr,a)]),WLe=t((a,s)=>{for(let[l,_]of QNr){let h=typeof s=="function"?(...b)=>Reflect.apply(_.value,s(),b):_.value.bind(s);Reflect.defineProperty(a,l,{..._,value:h})}return a},"mergePromise"),dxt=t(a=>new Promise((s,l)=>{a.on("exit",(_,h)=>{s({exitCode:_,signal:h})}),a.on("error",_=>{l(_)}),a.stdin&&a.stdin.on("error",_=>{l(_)})}),"getSpawnedPromise");var mxt=t((a,s=[])=>Array.isArray(s)?[a,...s]:[a],"normalizeArgs"),eIr=/^[\w.-]+$/,tIr=/"/g,rIr=t(a=>typeof a!="string"||eIr.test(a)?a:`"${a.replace(tIr,'\\"')}"`,"escapeArg"),hxt=t((a,s)=>mxt(a,s).join(" "),"joinCommand"),gxt=t((a,s)=>mxt(a,s).map(l=>rIr(l)).join(" "),"getEscapedCommand");var sIr=1e3*1e3*100,aIr=t(({env:a,extendEnv:s,preferLocal:l,localDir:_,execPath:h})=>{let b=s?{...Ede.env,...a}:a;return l?jTt({env:b,cwd:_,execPath:h}):b},"getEnv"),oIr=t((a,s,l={})=>{let _=vxt.default._parse(a,s,l);return a=_.command,s=_.args,l=_.options,l={maxBuffer:sIr,buffer:!0,stripFinalNewline:!0,extendEnv:!0,preferLocal:!1,localDir:l.cwd||Ede.cwd(),execPath:Ede.execPath,encoding:"utf8",reject:!0,cleanup:!0,all:!1,windowsHide:!0,...l},l.env=aIr(l),l.stdio=VTt(l),Ede.platform==="win32"&&iIr.basename(a,".exe")==="cmd"&&s.unshift("/q"),{file:a,args:s,options:l,parsed:_}},"handleArguments"),HLe=t((a,s,l)=>typeof s!="string"&&!nIr.isBuffer(s)?l===void 0?void 0:"":a.stripFinalNewline?LLe(s):s,"handleOutput");function bxt(a,s,l){let _=oIr(a,s,l),h=hxt(a,s),b=gxt(a,s);rxt(_.options);let w;try{w=yxt.spawn(_.file,_.args,_.options)}catch(ze){let Ie=new yxt.ChildProcess,De=Promise.reject(BLe({error:ze,stdout:"",stderr:"",all:"",command:h,escapedCommand:b,parsed:_,timedOut:!1,isCanceled:!1,killed:!1}));return WLe(Ie,De)}let N=dxt(w),M=txt(w,_.options,N),J=nxt(w,_.options,M),le={isCanceled:!1};w.kill=QTt.bind(null,w.kill.bind(w)),w.cancel=ext.bind(null,w,le);let te=$Tt(t(async()=>{let[{error:ze,exitCode:Ie,signal:De,timedOut:Et},gt,yr,sn]=await pxt(w,_.options,J),jr=HLe(_.options,gt),Qr=HLe(_.options,yr),br=HLe(_.options,sn);if(ze||Ie!==0||De!==null){let gr=BLe({error:ze,exitCode:Ie,signal:De,stdout:jr,stderr:Qr,all:br,command:h,escapedCommand:b,parsed:_,timedOut:Et,isCanceled:le.isCanceled||(_.options.signal?_.options.signal.aborted:!1),killed:w.killed});if(!_.options.reject)return gr;throw gr}return{command:h,escapedCommand:b,exitCode:0,stdout:jr,stderr:Qr,all:br,failed:!1,timedOut:!1,isCanceled:!1,killed:!1}},"handlePromise"));return fxt(w,_.options.input),w.all=_xt(w,_.options),WLe(w,te)}t(bxt,"execa");async function wde(a,s){if(a.__ZUPLO_LOG_LEVEL=process.env.__ZUPLO_LOG_LEVEL??process.env.LOG_LEVEL,a.__ZUPLO_LOG_FORMAT=process.env.__ZUPLO_LOG_FORMAT??process.env.LOG_FORMAT,a.LOG_LEVEL=process.env.LOG_LEVEL??process.env.LOG_LEVEL,a.LOG_FORMAT=process.env.LOG_FORMAT??process.env.LOG_FORMAT,a.GIT_SHA=process.env.GIT_SHA??await cIr(s),process.env.__ZUPLO_CONFIG&&(a.__ZUPLO_CONFIG=process.env.__ZUPLO_CONFIG),Sxt(Cde.join(s,".env.zuplo"))){let l=Txt(Cde.join(s,".env.zuplo"),"utf8"),_=GLe.default.parse(l);for(let h of Object.keys(_))if(a[h]=_[h],h==="ZUPLO_SYSTEM_CONFIGURATIONS"){let b=Buffer.from(xue.decode(_[h])).toString(),w=JSON.parse(b);for(let N of Object.keys(w))a[N]=w[N]}}if(Sxt(Cde.join(s,".env"))){let l=Txt(Cde.join(s,".env"),"utf8"),_=GLe.default.parse(l);for(let h of Object.keys(_))a[h]=_[h]}for(let l of Object.keys(a))a[l]===void 0&&delete a[l];return a}t(wde,"setEnvironment");async function cIr(a){let s="unknown";try{let{stdout:l}=await bxt("git",["rev-parse","HEAD"],{cwd:a});l.trim().length===40&&(s=l.trim())}catch{}return s}t(cIr,"getGitSha");async function _Ir({buildId:a,output:s,sourceDirectory:l,bundledDir:_,port:h,binaryName:b,publicZuploEnvironmentVariables:w,logger:N,handleRuntimeStdio:M}){if(_){let le=FY.join(l,_,"modules.json");if(!lIr(le))throw new Error("The bundled-dir does not contain a modules.json file.");let se=await fIr(le,"utf-8").then(JSON.parse),te=await bB(l);return te.status===EA?new Promise((ze,Ie)=>{J(te.config.compatibilityDate,FY.join(l,_),se,ze,M)().catch(De=>{N.error(De),Ie(De)})}):(N.warn("Failed to get Zuplo config. Using default compatibility date."),new Promise((ze,Ie)=>{J(void 0,l,se,ze,M)().catch(De=>{N.error(De),Ie(De)})}))}else{let le=new KA({buildId:a,output:s,sourceDirectory:l,command:"dev",logger:N,publicZuploEnvironmentVariables:w??{ZUPLO_ENVIRONMENT_TYPE:"LOCAL_DEVELOPMENT"},urls:void 0});try{await le.start()}catch{N.info("Ran into irrecoverable error while building. Fix the error and rerun the command."),process.exit(1)}return new Promise((se,te)=>{le.onReload((ze,Ie)=>{(Ie||ze&&ze.errors&&ze.errors.length>0)&&te(Ie??ze?.errors),J(ze?.config?.compatibilityDate,FY.join(l,"dist"),vB(l,ze?.metafile),se,M)().catch(De=>{N.error(De),te(De)})})})}function J(le,se,te,ze,Ie){return async()=>{let De={};await wde(De,l);let Et=new xxt.ZuploWorkerd({compatibilityDate:le,scriptDirectory:se,modules:te,port:h??$m.DEV_SERVER_PORT,bindings:De,handleRuntimeStdio:Ie}),gt=b??"compiled-zup",yr=FY.join(l,"dist");await uIr(yr,{recursive:!0}),await Et.compileBinary({binaryPath:FY.join(l,"dist",gt)}),await Et.dispose(),ze(void 0)}}t(J,"compile")}t(_Ir,"compileWorkerdServer");var Ext=$p(CLe(),1);import dIr from"node:path";import pIr from"node:net";function LY(a,s){return new Promise(l=>{let _=new pIr.Socket;_.connect(s,a),_.on("connect",()=>{_.destroy(),l(!1)}),_.on("error",()=>{_.destroy(),l(!0)})})}t(LY,"isPortAvailable");var kde=class{static{t(this,"WorkerdServer")}sourceDirectory;port;debugPort;buildWatcher;workerd;logger;output;handleRuntimeStdio;onReload;constructor(s){if(this.sourceDirectory=s.sourceDirectory,this.port=s.port??$m.DEV_SERVER_PORT,this.debugPort=s.debugPort,this.logger=s.logger,this.output=s.output,this.handleRuntimeStdio=s.handleRuntimeStdio,this.onReload=s.onReload,!s.zupTestMode){let l="http://localhost:3000",_=`http://localhost:${this.port}`;this.buildWatcher=new KA({...s,logger:this.logger,publicZuploEnvironmentVariables:{...s.publicZuploEnvironmentVariables,ZUPLO_ENVIRONMENT_TYPE:"LOCAL_DEVELOPMENT"},urls:{devPortal:{defaultUrl:l,urls:[l]},api:{defaultUrl:_,urls:[_]}}}),this.buildWatcher.watchEnvFiles()}}async start(){if(!await LY("localhost",this.port))throw new Error(`Port ${this.port} is currently in use. Please use a different port.`);if(this.buildWatcher)try{await this.buildWatcher.start()}catch(l){this.output.child("api").error(l.toString());let _="Ran into irrecoverable error while starting watcher. Fix the error and restart the server.";this.output.child("api").error(_),this.logger?.info(_),process.exit(1)}this.buildWatcher?.onReload((l,_)=>{_||l&&l.errors&&l.errors.length>0||(this.onReload(l,_),this.startOrReload(l).catch(h=>{this.output.child("api").error(h.toString()),this.logger?.error(h)}))})}async startOrReload(s){try{let l={};await wde(l,this.sourceDirectory),await this.workerd?.dispose(),this.workerd=new Ext.ZuploWorkerd({compatibilityDate:s?.config?.compatibilityDate,scriptDirectory:dIr.join(this.sourceDirectory,"dist"),modules:vB(this.sourceDirectory,s?.metafile),port:this.port,inspectorPort:this.debugPort??void 0,bindings:l,handleRuntimeStdio:this.handleRuntimeStdio}),await this.workerd.serve()}catch(l){this.logger?.debug(l)}}async stop(){await this.buildWatcher?.close(),await this.workerd?.dispose()}};import{fileURLToPath as Pxt}from"node:url";import{Readable as Cxt}from"node:stream";import wxt from"node:assert";import mIr from"node:child_process";import hIr from"node:fs";import Dde from"node:os";import gIr from"node:path";function kxt(a,s){let l=import.meta.resolve(a),_=new URL(".",l),h=new URL(s,_);if(hIr.existsSync(h))return Pxt(h)}t(kxt,"getValidExecutablePath");function yIr(){let a=Dde.platform()==="win32"?"deno.exe":"deno",s=kxt("deno/package.json",a);if(s)return s;let l=vIr(),_=kxt(`@deno/${l}/package.json`,a);if(_)return _;throw new Error("Failed to locate the managed-dedicated server executable.")}t(yIr,"locateDenoExecutable");function vIr(){let a=Dde.platform();return a==="linux"?a+"-"+Dxt()+"-glibc":a+"-"+Dxt()}t(vIr,"getTarget");function Dxt(){let a=Dde.arch();if(a!=="arm64"&&a!=="x64")throw new Error("Unsupported architecture "+Dde.arch()+". Only x64 and aarch64 binaries are available.");return a}t(Dxt,"getArch");var Pde=class{static{t(this,"ZenoServer")}serverProcess;sourceDirectory;port;debugPort;processExitPromise;logger;output;buildWatcher;onReload;handleRuntimeStdio;denoExecutablePath;unsafelyIgnoreCertificateErrors;constructor(s){if(this.port=s.port??9e3,this.debugPort=s.debugPort,this.logger=s.logger,this.output=s.output,this.onReload=s.onReload,this.handleRuntimeStdio=s.handleRuntimeStdio,this.sourceDirectory=s.sourceDirectory,this.unsafelyIgnoreCertificateErrors=!!s.unsafelyIgnoreCertificateErrors,!s.zupTestMode){let l="http://localhost:3000",_=`http://localhost:${this.port}`;this.buildWatcher=new KA({sourceDirectory:s.sourceDirectory,command:"dev",logger:s.logger,publicZuploEnvironmentVariables:{...s.publicZuploEnvironmentVariables,ZUPLO_ENVIRONMENT_TYPE:"LOCAL_DEVELOPMENT"},buildId:"dev",output:s.output,urls:{devPortal:{defaultUrl:l,urls:[l]},api:{defaultUrl:_,urls:[_]}}}),this.buildWatcher.watchEnvFiles()}this.denoExecutablePath=yIr()}getServeArgs(){let s=`${gIr.dirname(Pxt(import.meta.url))}/zeno.js`,l=["run","--allow-read","--allow-net","--allow-env","--allow-write",...this.unsafelyIgnoreCertificateErrors?["--unsafely-ignore-certificate-errors"]:[]];return this.debugPort&&l.push(`--inspect=127.0.0.1:${this.debugPort}`),l.push(s),l.push("--dir",this.sourceDirectory),l.push("--port",this.port.toString()),l}async getUnavailablePorts(){let s=[];return this.debugPort&&!await LY("127.0.0.1",this.debugPort)&&s.push(this.debugPort),await LY("127.0.0.1",this.port)||s.push(this.port),s}async start(){let s=await this.getUnavailablePorts();if(s.length>0)throw new Error("The following ports are not available: "+s.join(", "));if(this.buildWatcher)try{await this.buildWatcher.start()}catch(l){this.output.child("api").error(l.toString());let _="Ran into irrecoverable error while starting watcher. Fix the error and restart the server.";this.output.child("api").error(_),this.logger?.info(_),process.exit(1)}await this.startOrReload(),this.buildWatcher?.onReload((l,_)=>{_||l&&l.errors&&l.errors.length>0||(this.onReload(l,_),this.startOrReload().catch(h=>{this.output.child("api").error(h.toString()),this.logger?.error(h)}))})}async startOrReload(){try{await this.dispose(),this.logger?.info("Starting managed-dedicated local server");let s=this.getServeArgs();this.serverProcess=mIr.spawn(this.denoExecutablePath,s,{stdio:["pipe","pipe","pipe"],env:{...process.env,FORCE_COLOR:"1"}}),wxt(this.serverProcess.stdout instanceof Cxt),wxt(this.serverProcess.stderr instanceof Cxt),this.processExitPromise=this.waitForExit(),this.handleRuntimeStdio(this.serverProcess.stdout,this.serverProcess.stderr)}catch(s){this.logger?.debug(s)}}waitForExit(){return new Promise(s=>{this.serverProcess?.once("exit",s)})}dispose(){return this.serverProcess?.kill("SIGKILL"),this.processExitPromise}async stop(){await this.dispose(),await this.buildWatcher?.close()}};async function bIr(a){let s=await bB(a),l=!1;return s.status===EA&&(l=s.config.projectType!=="managed-edge"||(s.config.flags?.managedDedicatedFlags?.useZeno??!1)),l||process.env.ZUPLO_DEV_RUNTIME==="zeno"}t(bIr,"useZeno");async function SIr({sourceDirectory:a,port:s,debugPort:l,publicZuploEnvironmentVariables:_,unsafelyIgnoreCertificateErrors:h,logger:b,output:w,buildId:N,onReload:M,handleRuntimeStdio:J}){process.env.ZUPLO_IS_LOCAL_DEVELOPMENT="true";let le;await bIr(a)?(b.debug("Starting managed-dedicated local dev server."),le=new Pde({sourceDirectory:a,port:s,debugPort:l,logger:b,output:w,publicZuploEnvironmentVariables:_,onReload:M,handleRuntimeStdio:J,unsafelyIgnoreCertificateErrors:h})):(b.debug("Starting edge local dev server."),le=new kde({sourceDirectory:a,command:"dev",port:s,debugPort:l,publicZuploEnvironmentVariables:_,logger:b,output:w,buildId:N,onReload:M,handleRuntimeStdio:J})),await le.start();async function se(){await le.stop()}t(se,"handle"),process.on("SIGTERM",se),process.on("SIGINT",se)}t(SIr,"startDevServer");var e1=new URL("./public/",import.meta.url);import{readFile as Ade}from"fs/promises";var _v=class{static{t(this,"BaseComponent")}#e;#n;#t;scriptFile;cssFile;constructor(a){this.#t=a}async getStyles(){return this.cssFile?this.#t?await Ade(this.cssFile,"utf-8"):(this.#e=this.#e??await Ade(this.cssFile,"utf-8"),this.#e):null}async getScript(){return this.scriptFile?this.#t?await Ade(this.scriptFile,"utf-8"):(this.#n=this.#n??await Ade(this.scriptFile,"utf-8"),this.#n):null}};var Axt=class extends _v{static{t(this,"Layout")}cssFile=new URL("./layout/style.css",e1);scriptFile=new URL("./layout/script.js",e1);async toHTML(a){return`<!DOCTYPE html>
658
658
  <html lang="en">
659
659
  <head>
660
660
  <meta charset="UTF-8" />
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zuplo/core",
3
- "version": "6.60.8",
3
+ "version": "6.60.10",
4
4
  "repository": "https://github.com/zuplo/zuplo",
5
5
  "author": "Zuplo, Inc.",
6
6
  "type": "module",
@@ -42,9 +42,9 @@
42
42
  "source-map": "^0.7.4"
43
43
  },
44
44
  "peerDependencies": {
45
- "@zuplo/graphql": "6.60.8",
46
- "@zuplo/otel": "6.60.8",
47
- "@zuplo/runtime": "6.60.8",
45
+ "@zuplo/graphql": "6.60.10",
46
+ "@zuplo/otel": "6.60.10",
47
+ "@zuplo/runtime": "6.60.10",
48
48
  "deno": "2.3.1"
49
49
  }
50
50
  }
package/zeno.js CHANGED
@@ -23,6 +23,6 @@
23
23
  *--------------------------------------------------------------------------------------------*/
24
24
 
25
25
  var He=Object.defineProperty;var n=(t,e)=>He(t,"name",{value:e,configurable:!0});import{scheduler as Ue}from"node:timers/promises";Object.defineProperty(globalThis,"scheduler",{value:Ue,writable:!1,enumerable:!0,configurable:!1});function q(t){let e=0;for(let s of t)e+=s.length;let r=new Uint8Array(e),o=0;for(let s of t)r.set(s,o),o+=s.length;return r}n(q,"concat");var M=new TextEncoder,se=new TextDecoder,Ie=42,Fe=124,Be=40,Ge=33,$e=35,Me=36,We=44,je=45,ze=58,Ve=37,Ke=95,Je=62,Xe=126,Ze=43,qe=61,J=M.encode(`\r
26
- `),Ye=M.encode("*"),Qe=M.encode("$");function oe(t){let e=[Ye,M.encode(t.length.toString()),J];for(let r of t){let o=r instanceof Uint8Array?r:M.encode(r.toString());e.push(Qe,M.encode(o.byteLength.toString()),J,o,J)}return q(e)}n(oe,"createRequest");async function*et(t){let e=new Uint8Array;for await(let r of t){e=q([e,r]);let o;for(;(o=e.indexOf(J[0]))!==-1&&e[o+1]===J[1];)yield e.subarray(0,o),e=e.subarray(o+2)}}n(et,"readLines");function K(t,e,r=!1){return Array.fromAsync({length:e},()=>X(t,r))}n(K,"readNReplies");function D(t){return se.decode(t.slice(1))}n(D,"parseLine");function tt(t){let e=[];for(let r=0;r<t.length;r+=2)e.push(t.slice(r,r+2));return e}n(tt,"chunk");async function X(t,e=!1){let{value:r}=await t.next();switch(r[0]){case Ie:case Je:{let o=Number(D(r));return o===-1?null:await K(t,o)}case Fe:{let o=Number(D(r))*2;return await K(t,o),X(t,e)}case Be:return BigInt(D(r));case Ge:{let{value:o}=await t.next();return Promise.reject(se.decode(o))}case $e:return D(r)==="t";case Me:case qe:return D(r)==="-1"?null:X(t,e);case We:case ze:switch(D(r)){case"inf":return 1/0;case"-inf":return-1/0;default:return Number(D(r))}case je:return Promise.reject(D(r));case Ve:{let o=Number(D(r))*2,s=await K(t,o);return Object.fromEntries(tt(s))}case Ke:return null;case Xe:return new Set(await K(t,Number(D(r)),e));case Ze:return D(r);default:return e?r:se.decode(r)}}n(X,"readReply");var Y=class{static{n(this,"RedisClient")}#t;#r;#e=Promise.resolve();constructor(e){this.#t=e.writable.getWriter(),this.#r=et(e.readable)}#n(e){return this.#e=this.#e.then(e),this.#e}sendCommand(e,r=!1){return this.#n(()=>(this.#t.write(oe(e)),X(this.#r,r)))}writeCommand(e){return this.#n(()=>this.#t.write(oe(e)))}async*readReplies(e=!1){for(;;)yield X(this.#r,e)}pipelineCommands(e,r=!1){return this.#n(()=>{let o=q(e.map(oe));return this.#t.write(o),K(this.#r,e.length,r)})}};var R=globalThis.Deno?.build.os==="windows"||globalThis.navigator?.platform?.startsWith("Win")||globalThis.process?.platform?.startsWith("win")||!1;function C(t){if(typeof t!="string")throw new TypeError(`Path must be a string, received "${JSON.stringify(t)}"`)}n(C,"assertPath");function v(t){return t===47}n(v,"isPosixPathSeparator");function y(t){return t===47||t===92}n(y,"isPathSeparator");function H(t){return t>=97&&t<=122||t>=65&&t<=90}n(H,"isWindowsDeviceRoot");function ee(t){if(C(t),t.length===0)return"."}n(ee,"assertArg");function W(t,e,r,o){let s="",c=0,d=-1,l=0,u;for(let i=0;i<=t.length;++i){if(i<t.length)u=t.charCodeAt(i);else{if(o(u))break;u=47}if(o(u)){if(!(d===i-1||l===1))if(d!==i-1&&l===2){if(s.length<2||c!==2||s.charCodeAt(s.length-1)!==46||s.charCodeAt(s.length-2)!==46){if(s.length>2){let g=s.lastIndexOf(r);g===-1?(s="",c=0):(s=s.slice(0,g),c=s.length-1-s.lastIndexOf(r)),d=i,l=0;continue}else if(s.length===2||s.length===1){s="",c=0,d=i,l=0;continue}}e&&(s.length>0?s+=`${r}..`:s="..",c=2)}else s.length>0?s+=r+t.slice(d+1,i):s=t.slice(d+1,i),c=i-d-1;d=i,l=0}else u===46&&l!==-1?++l:l=-1}return s}n(W,"normalizeString");function te(t){ee(t);let e=v(t.charCodeAt(0)),r=v(t.charCodeAt(t.length-1));return t=W(t,!e,"/",v),t.length===0&&!e&&(t="."),t.length>0&&r&&(t+="/"),e?`/${t}`:t}n(te,"normalize");function ae(...t){if(t.length===0)return".";t.forEach(r=>C(r));let e=t.filter(r=>r.length>0).join("/");return e===""?".":te(e)}n(ae,"join");function re(t){ee(t);let e=t.length,r=0,o,s=!1,c=t.charCodeAt(0);if(e>1)if(y(c))if(s=!0,y(t.charCodeAt(1))){let l=2,u=l;for(;l<e&&!y(t.charCodeAt(l));++l);if(l<e&&l!==u){let i=t.slice(u,l);for(u=l;l<e&&y(t.charCodeAt(l));++l);if(l<e&&l!==u){for(u=l;l<e&&!y(t.charCodeAt(l));++l);if(l===e)return`\\\\${i}\\${t.slice(u)}\\`;l!==u&&(o=`\\\\${i}\\${t.slice(u,l)}`,r=l)}}}else r=1;else H(c)&&t.charCodeAt(1)===58&&(o=t.slice(0,2),r=2,e>2&&y(t.charCodeAt(2))&&(s=!0,r=3));else if(y(c))return"\\";let d;return r<e?d=W(t.slice(r),!s,"\\",y):d="",d.length===0&&!s&&(d="."),d.length>0&&y(t.charCodeAt(e-1))&&(d+="\\"),o===void 0?s?d.length>0?`\\${d}`:"\\":d:s?d.length>0?`${o}\\${d}`:`${o}\\`:o+d}n(re,"normalize");function le(...t){if(t.forEach(c=>C(c)),t=t.filter(c=>c.length>0),t.length===0)return".";let e=!0,r=0,o=t[0];if(y(o.charCodeAt(0))){++r;let c=o.length;c>1&&y(o.charCodeAt(1))&&(++r,c>2&&(y(o.charCodeAt(2))?++r:e=!1))}let s=t.join("\\");if(e){for(;r<s.length&&y(s.charCodeAt(r));++r);r>=2&&(s=`\\${s.slice(r)}`)}return re(s)}n(le,"join");function k(...t){return R?le(...t):ae(...t)}n(k,"join");function bt(t){if(t.length>=255)throw new TypeError("Alphabet too long");let e=new Uint8Array(256);for(let i=0;i<e.length;i++)e[i]=255;for(let i=0;i<t.length;i++){let g=t.charAt(i),p=g.charCodeAt(0);if(e[p]!==255)throw new TypeError(g+" is ambiguous");e[p]=i}let r=t.length,o=t.charAt(0),s=Math.log(r)/Math.log(256),c=Math.log(256)/Math.log(r);function d(i){if(i instanceof Uint8Array||(ArrayBuffer.isView(i)?i=new Uint8Array(i.buffer,i.byteOffset,i.byteLength):Array.isArray(i)&&(i=Uint8Array.from(i))),!(i instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(i.length===0)return"";let g=0,p=0,A=0,x=i.length;for(;A!==x&&i[A]===0;)A++,g++;let E=(x-A)*c+1>>>0,S=new Uint8Array(E);for(;A!==x;){let T=i[A],P=0;for(let N=E-1;(T!==0||P<p)&&N!==-1;N--,P++)T+=256*S[N]>>>0,S[N]=T%r>>>0,T=T/r>>>0;if(T!==0)throw new Error("Non-zero carry");p=P,A++}let _=E-p;for(;_!==E&&S[_]===0;)_++;let b=o.repeat(g);for(;_<E;++_)b+=t.charAt(S[_]);return b}n(d,"encode");function l(i){if(typeof i!="string")throw new TypeError("Expected String");if(i.length===0)return new Uint8Array;let g=0,p=0,A=0;for(;i[g]===o;)p++,g++;let x=(i.length-g)*s+1>>>0,E=new Uint8Array(x);for(;g<i.length;){let T=i.charCodeAt(g);if(T>255)return;let P=e[T];if(P===255)return;let N=0;for(let f=x-1;(P!==0||N<A)&&f!==-1;f--,N++)P+=r*E[f]>>>0,E[f]=P%256>>>0,P=P/256>>>0;if(P!==0)throw new Error("Non-zero carry");A=N,g++}let S=x-A;for(;S!==x&&E[S]===0;)S++;let _=new Uint8Array(p+(x-S)),b=p;for(;S!==x;)_[b++]=E[S++];return _}n(l,"decodeUnsafe");function u(i){let g=l(i);if(g)return g;throw new Error("Non-base"+r+" character")}return n(u,"decode"),{encode:d,decodeUnsafe:l,decode:u}}n(bt,"base");var ye=bt;var Rt="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",xe=ye(Rt);import{pathToFileURL as be}from"node:url";import Re from"dotenv";var ce=class{static{n(this,"ZenoLogger")}prefix="[ZENO]:";logLevel;originalConsole={debug:console.debug,info:console.info,warn:console.warn,error:console.error};constructor(e="info"){this.logLevel=e}debug(...e){(this.shouldLog("debug")||Deno.env.get("ZENO_DEBUG"))&&this.originalConsole.debug(this.prefix,"[DEBUG]",...e)}info(...e){this.shouldLog("info")&&this.originalConsole.info(this.prefix,"[INFO]",...e)}warn(...e){this.shouldLog("warn")&&this.originalConsole.warn(this.prefix,"[WARN]",...e)}error(...e){this.shouldLog("error")&&this.originalConsole.error(this.prefix,"[ERROR]",...e)}shouldLog(e){let r=["debug","info","warn","error"],o=r.indexOf(this.logLevel);return r.indexOf(e)>=o}setLogLevel(e){this.logLevel=e}},w=new ce;async function Ce(t){let e={};for(let[r,o]of Object.entries(Deno.env.toObject()))o!==void 0&&(e[r]=o);try{let r=k(t,".env.zuplo"),o=new TextDecoder("utf-8"),s=await Deno.readFile(be(r)),c=o.decode(s),d=Re.parse(c);for(let[l,u]of Object.entries(d))if(e[l]=u,l==="ZUPLO_SYSTEM_CONFIGURATIONS")try{let i=new TextDecoder().decode(xe.decode(u)),g=JSON.parse(i);for(let[p,A]of Object.entries(g))e[p]=String(A)}catch(i){Deno.build.standalone||w.error("Failed to parse ZUPLO_SYSTEM_CONFIGURATIONS from .env.zuplo:",i)}}catch(r){Deno.build.standalone||w.error("Error loading .env.zuplo:",r)}try{let r=k(t,".env"),o=new TextDecoder("utf-8"),s=await Deno.readFile(be(r)),c=o.decode(s),d=Re.parse(c);for(let[l,u]of Object.entries(d))e[l]=u}catch(r){Deno.build.standalone||w.error("Error loading .env:",r)}for(let[r,o]of Object.entries(e))o===void 0&&delete e[r];return e.__ZUPLO_IS_MANAGED_DEDICATED="true",e}n(Ce,"loadEnvironment");function Ee(t){return t?["true","1","yes","y"].includes(t.toLowerCase()):!1}n(Ee,"parseEnvBool");var fe=class{static{n(this,"CacheStorage")}#t;constructor(){this.#t=new Map}async open(e){let r=this.#t.get(e);return r||(r=new de,this.#t.set(e,r)),r}async has(e){return this.#t.has(e)}async delete(e){throw new Error("caches.delete is not supported")}};async function Ct(){let t=Deno.env.get("ZUPLO_CACHE_REDIS_HOSTNAME");if(t===void 0)throw new Error("ZUPLO_CACHE_REDIS_HOSTNAME is not set");let e=parseInt(Deno.env.get("ZUPLO_CACHE_REDIS_PORT")||"6379"),r=await Deno.connect({hostname:t,port:e});return new Y(r)}n(Ct,"getRedisClient");function Et(t){let e={};return t&&t.split(",").forEach(o=>{let[s,c]=o.trim().split("=");e[s.toLowerCase()]=c?c.trim():!0}),e}n(Et,"parseHeaderValue");function wt(t){let e={};for(let[r,o]of t.entries())e[r]=o;return e}n(wt,"objectifyHeaders");async function St(t){let e=await t.arrayBuffer(),r=new Uint8Array(e),o="";for(let s=0;s<r.length;s++)o+=String.fromCharCode(r[s]);return btoa(o)}n(St,"serializeResponseBody");function Pt(t){let e=atob(t),r=e.length,o=new Uint8Array(r);for(let s=0;s<r;s++)o[s]=e.charCodeAt(s);return o}n(Pt,"deserializeResponseBody");var de=class{static{n(this,"Cache")}#t;#r;#e;constructor(e="default",r={}){this.#t=e;let o=Deno.env.get("ZUPLO_CACHE_REDIS_HOSTNAME")&&Deno.env.get("ZUPLO_CACHE_REDIS_PORT");this.#r=!o||!Ee(Deno.env.get("USE_ZENO_ZONE_CACHE")),this.#e=r.getRedisClient||Ct}#n(e){return`${this.#t}:${e.url}`}async match(e,r){if(this.#r)return;let o=this.#n(e),s=await this.#e();await s.sendCommand(["HELLO",3]);let c=await s.sendCommand(["TTL",o]);if(c!==-2){if(c<2)return;{let d=await s.sendCommand(["HGETALL",o]),l=d.status,u=d.status,i=new Headers(JSON.parse(d.headers));return new Response(Pt(d.body),{status:l,statusText:u,headers:i})}}}async put(e,r){if(this.#r)return;let o=1*60*60,s=Et(r.headers.get("cache-control")),c=parseInt(s["s-maxage"]),d=parseInt(s["max-age"]),l=s["no-store"],u=s["no-cache"],i=c||d||0;if(i===0&&!l&&!u&&(i=o,r.headers.append("cache-control",`s-maxage=${o}`)),i>0){let g=this.#n(e),p=await this.#e();await p.sendCommand(["HELLO",3]),await p.sendCommand(["HSET",g,"maxage",i,"status",r.status,"statusText",r.statusText,"headers",JSON.stringify(wt(r.headers)),"body",await St(r)]),await p.sendCommand(["EXPIRE",g,i])}}async delete(e){if(this.#r)return;let r=this.#n(e);if(await(await this.#e()).sendCommand(["DEL",r])!==1)throw new Error("Failed to delete cache entry")}},_t=new fe;Object.defineProperty(globalThis,"caches",{value:_t,writable:!1,enumerable:!0,configurable:!1});var ne=class{static{n(this,"WorkerServer")}#t;#r;#e=n(()=>({waitUntil:n(e=>{e.catch(r=>{console.error("Error in waitUntil:",r)})},"waitUntil")}),"#createContext");constructor(e){this.#r=e}async start(){let{port:e,workerModule:r,env:o}=this.#r;this.#t=Deno.serve({port:e,onListen:n(()=>{w.debug(`Server running at http://localhost:${e}`)},"onListen")},async s=>{try{return await r.default.fetch(s,o,this.#e())}catch(c){return w.error("Error handling request:",c),new Response("Internal Server Error",{status:500})}}),await this.#t.finished}async stop(){await this.#t?.shutdown()}};import{pathToFileURL as Nt}from"node:url";var we=k("dist","worker.js");function Se(){if(Deno.build.standalone)return k("..",we);let t=Deno.cwd();return k(t,we)}n(Se,"getDefaultWorkerPath");function Ot(t){return typeof t=="object"&&t!==null&&"default"in t&&typeof t.default=="object"&&"fetch"in t.default&&typeof t.default.fetch=="function"}n(Ot,"isWorkerModule");async function ue(t){let e;if(Deno.build.standalone?(w.debug("Loading worker module from: ",t),e=await import(t)):(w.debug("Loading dev worker module from: ",t),e=await import(Nt(t).href)),!Ot(e))throw new Error("Invalid worker module");return e}n(ue,"importWorkerModule");function Pe(){console.log("Enabling fetch host override.");let t=globalThis.fetch,e=Deno.createHttpClient({allowHost:!0,http2:!1});return globalThis.fetch=async(r,o={})=>await t(r,{...o,client:e}),e}n(Pe,"setFetchHostOverride");function _e(t){if(new.target)throw new TypeError("Cannot create an instance: parse is not a constructor");return new pe(t).parse()}n(_e,"parse");var pe=class{static{n(this,"JsoncParser")}#t=new Set(` \r
26
+ `),Ye=M.encode("*"),Qe=M.encode("$");function oe(t){let e=[Ye,M.encode(t.length.toString()),J];for(let r of t){let o=r instanceof Uint8Array?r:M.encode(r.toString());e.push(Qe,M.encode(o.byteLength.toString()),J,o,J)}return q(e)}n(oe,"createRequest");async function*et(t){let e=new Uint8Array;for await(let r of t){e=q([e,r]);let o;for(;(o=e.indexOf(J[0]))!==-1&&e[o+1]===J[1];)yield e.subarray(0,o),e=e.subarray(o+2)}}n(et,"readLines");function K(t,e,r=!1){return Array.fromAsync({length:e},()=>X(t,r))}n(K,"readNReplies");function D(t){return se.decode(t.slice(1))}n(D,"parseLine");function tt(t){let e=[];for(let r=0;r<t.length;r+=2)e.push(t.slice(r,r+2));return e}n(tt,"chunk");async function X(t,e=!1){let{value:r}=await t.next();switch(r[0]){case Ie:case Je:{let o=Number(D(r));return o===-1?null:await K(t,o)}case Fe:{let o=Number(D(r))*2;return await K(t,o),X(t,e)}case Be:return BigInt(D(r));case Ge:{let{value:o}=await t.next();return Promise.reject(se.decode(o))}case $e:return D(r)==="t";case Me:case qe:return D(r)==="-1"?null:X(t,e);case We:case ze:switch(D(r)){case"inf":return 1/0;case"-inf":return-1/0;default:return Number(D(r))}case je:return Promise.reject(D(r));case Ve:{let o=Number(D(r))*2,s=await K(t,o);return Object.fromEntries(tt(s))}case Ke:return null;case Xe:return new Set(await K(t,Number(D(r)),e));case Ze:return D(r);default:return e?r:se.decode(r)}}n(X,"readReply");var Y=class{static{n(this,"RedisClient")}#t;#r;#e=Promise.resolve();constructor(e){this.#t=e.writable.getWriter(),this.#r=et(e.readable)}#n(e){return this.#e=this.#e.then(e),this.#e}sendCommand(e,r=!1){return this.#n(()=>(this.#t.write(oe(e)),X(this.#r,r)))}writeCommand(e){return this.#n(()=>this.#t.write(oe(e)))}async*readReplies(e=!1){for(;;)yield X(this.#r,e)}pipelineCommands(e,r=!1){return this.#n(()=>{let o=q(e.map(oe));return this.#t.write(o),K(this.#r,e.length,r)})}};var R=globalThis.Deno?.build.os==="windows"||globalThis.navigator?.platform?.startsWith("Win")||globalThis.process?.platform?.startsWith("win")||!1;function C(t){if(typeof t!="string")throw new TypeError(`Path must be a string, received "${JSON.stringify(t)}"`)}n(C,"assertPath");function v(t){return t===47}n(v,"isPosixPathSeparator");function y(t){return t===47||t===92}n(y,"isPathSeparator");function H(t){return t>=97&&t<=122||t>=65&&t<=90}n(H,"isWindowsDeviceRoot");function ee(t){if(C(t),t.length===0)return"."}n(ee,"assertArg");function W(t,e,r,o){let s="",c=0,d=-1,l=0,u;for(let i=0;i<=t.length;++i){if(i<t.length)u=t.charCodeAt(i);else{if(o(u))break;u=47}if(o(u)){if(!(d===i-1||l===1))if(d!==i-1&&l===2){if(s.length<2||c!==2||s.charCodeAt(s.length-1)!==46||s.charCodeAt(s.length-2)!==46){if(s.length>2){let g=s.lastIndexOf(r);g===-1?(s="",c=0):(s=s.slice(0,g),c=s.length-1-s.lastIndexOf(r)),d=i,l=0;continue}else if(s.length===2||s.length===1){s="",c=0,d=i,l=0;continue}}e&&(s.length>0?s+=`${r}..`:s="..",c=2)}else s.length>0?s+=r+t.slice(d+1,i):s=t.slice(d+1,i),c=i-d-1;d=i,l=0}else u===46&&l!==-1?++l:l=-1}return s}n(W,"normalizeString");function te(t){ee(t);let e=v(t.charCodeAt(0)),r=v(t.charCodeAt(t.length-1));return t=W(t,!e,"/",v),t.length===0&&!e&&(t="."),t.length>0&&r&&(t+="/"),e?`/${t}`:t}n(te,"normalize");function ae(...t){if(t.length===0)return".";t.forEach(r=>C(r));let e=t.filter(r=>r.length>0).join("/");return e===""?".":te(e)}n(ae,"join");function re(t){ee(t);let e=t.length,r=0,o,s=!1,c=t.charCodeAt(0);if(e>1)if(y(c))if(s=!0,y(t.charCodeAt(1))){let l=2,u=l;for(;l<e&&!y(t.charCodeAt(l));++l);if(l<e&&l!==u){let i=t.slice(u,l);for(u=l;l<e&&y(t.charCodeAt(l));++l);if(l<e&&l!==u){for(u=l;l<e&&!y(t.charCodeAt(l));++l);if(l===e)return`\\\\${i}\\${t.slice(u)}\\`;l!==u&&(o=`\\\\${i}\\${t.slice(u,l)}`,r=l)}}}else r=1;else H(c)&&t.charCodeAt(1)===58&&(o=t.slice(0,2),r=2,e>2&&y(t.charCodeAt(2))&&(s=!0,r=3));else if(y(c))return"\\";let d;return r<e?d=W(t.slice(r),!s,"\\",y):d="",d.length===0&&!s&&(d="."),d.length>0&&y(t.charCodeAt(e-1))&&(d+="\\"),o===void 0?s?d.length>0?`\\${d}`:"\\":d:s?d.length>0?`${o}\\${d}`:`${o}\\`:o+d}n(re,"normalize");function le(...t){if(t.forEach(c=>C(c)),t=t.filter(c=>c.length>0),t.length===0)return".";let e=!0,r=0,o=t[0];if(y(o.charCodeAt(0))){++r;let c=o.length;c>1&&y(o.charCodeAt(1))&&(++r,c>2&&(y(o.charCodeAt(2))?++r:e=!1))}let s=t.join("\\");if(e){for(;r<s.length&&y(s.charCodeAt(r));++r);r>=2&&(s=`\\${s.slice(r)}`)}return re(s)}n(le,"join");function k(...t){return R?le(...t):ae(...t)}n(k,"join");function bt(t){if(t.length>=255)throw new TypeError("Alphabet too long");let e=new Uint8Array(256);for(let i=0;i<e.length;i++)e[i]=255;for(let i=0;i<t.length;i++){let g=t.charAt(i),p=g.charCodeAt(0);if(e[p]!==255)throw new TypeError(g+" is ambiguous");e[p]=i}let r=t.length,o=t.charAt(0),s=Math.log(r)/Math.log(256),c=Math.log(256)/Math.log(r);function d(i){if(i instanceof Uint8Array||(ArrayBuffer.isView(i)?i=new Uint8Array(i.buffer,i.byteOffset,i.byteLength):Array.isArray(i)&&(i=Uint8Array.from(i))),!(i instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(i.length===0)return"";let g=0,p=0,A=0,x=i.length;for(;A!==x&&i[A]===0;)A++,g++;let E=(x-A)*c+1>>>0,S=new Uint8Array(E);for(;A!==x;){let T=i[A],P=0;for(let N=E-1;(T!==0||P<p)&&N!==-1;N--,P++)T+=256*S[N]>>>0,S[N]=T%r>>>0,T=T/r>>>0;if(T!==0)throw new Error("Non-zero carry");p=P,A++}let _=E-p;for(;_!==E&&S[_]===0;)_++;let b=o.repeat(g);for(;_<E;++_)b+=t.charAt(S[_]);return b}n(d,"encode");function l(i){if(typeof i!="string")throw new TypeError("Expected String");if(i.length===0)return new Uint8Array;let g=0,p=0,A=0;for(;i[g]===o;)p++,g++;let x=(i.length-g)*s+1>>>0,E=new Uint8Array(x);for(;g<i.length;){let T=i.charCodeAt(g);if(T>255)return;let P=e[T];if(P===255)return;let N=0;for(let f=x-1;(P!==0||N<A)&&f!==-1;f--,N++)P+=r*E[f]>>>0,E[f]=P%256>>>0,P=P/256>>>0;if(P!==0)throw new Error("Non-zero carry");A=N,g++}let S=x-A;for(;S!==x&&E[S]===0;)S++;let _=new Uint8Array(p+(x-S)),b=p;for(;S!==x;)_[b++]=E[S++];return _}n(l,"decodeUnsafe");function u(i){let g=l(i);if(g)return g;throw new Error("Non-base"+r+" character")}return n(u,"decode"),{encode:d,decodeUnsafe:l,decode:u}}n(bt,"base");var ye=bt;var Rt="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",xe=ye(Rt);import{pathToFileURL as be}from"node:url";import Re from"dotenv";var ce=class{static{n(this,"ZenoLogger")}prefix="[ZENO]:";logLevel;originalConsole={debug:console.debug,info:console.info,warn:console.warn,error:console.error};constructor(e="info"){this.logLevel=e}debug(...e){(this.shouldLog("debug")||Deno.env.get("ZENO_DEBUG"))&&this.originalConsole.debug(this.prefix,"[DEBUG]",...e)}info(...e){this.shouldLog("info")&&this.originalConsole.info(this.prefix,"[INFO]",...e)}warn(...e){this.shouldLog("warn")&&this.originalConsole.warn(this.prefix,"[WARN]",...e)}error(...e){this.shouldLog("error")&&this.originalConsole.error(this.prefix,"[ERROR]",...e)}shouldLog(e){let r=["debug","info","warn","error"],o=r.indexOf(this.logLevel);return r.indexOf(e)>=o}setLogLevel(e){this.logLevel=e}},w=new ce;async function Ce(t){let e={};for(let[r,o]of Object.entries(Deno.env.toObject()))o!==void 0&&(e[r]=o);try{let r=k(t,".env.zuplo"),o=new TextDecoder("utf-8"),s=await Deno.readFile(be(r)),c=o.decode(s),d=Re.parse(c);for(let[l,u]of Object.entries(d))if(e[l]=u,l==="ZUPLO_SYSTEM_CONFIGURATIONS")try{let i=new TextDecoder().decode(xe.decode(u)),g=JSON.parse(i);for(let[p,A]of Object.entries(g))e[p]=String(A)}catch(i){Deno.build.standalone||w.error("Failed to parse ZUPLO_SYSTEM_CONFIGURATIONS from .env.zuplo:",i)}}catch(r){r instanceof Deno.errors.NotFound||w.error("Failed to load .env.zuplo file:",r)}try{let r=k(t,".env"),o=new TextDecoder("utf-8"),s=await Deno.readFile(be(r)),c=o.decode(s),d=Re.parse(c);for(let[l,u]of Object.entries(d))e[l]=u}catch(r){r instanceof Deno.errors.NotFound||w.error("Failed to load .env.zuplo file:",r)}for(let[r,o]of Object.entries(e))o===void 0&&delete e[r];return e.__ZUPLO_IS_MANAGED_DEDICATED="true",e}n(Ce,"loadEnvironment");function Ee(t){return t?["true","1","yes","y"].includes(t.toLowerCase()):!1}n(Ee,"parseEnvBool");var fe=class{static{n(this,"CacheStorage")}#t;constructor(){this.#t=new Map}async open(e){let r=this.#t.get(e);return r||(r=new de,this.#t.set(e,r)),r}async has(e){return this.#t.has(e)}async delete(e){throw new Error("caches.delete is not supported")}};async function Ct(){let t=Deno.env.get("ZUPLO_CACHE_REDIS_HOSTNAME");if(t===void 0)throw new Error("ZUPLO_CACHE_REDIS_HOSTNAME is not set");let e=parseInt(Deno.env.get("ZUPLO_CACHE_REDIS_PORT")||"6379"),r=await Deno.connect({hostname:t,port:e});return new Y(r)}n(Ct,"getRedisClient");function Et(t){let e={};return t&&t.split(",").forEach(o=>{let[s,c]=o.trim().split("=");e[s.toLowerCase()]=c?c.trim():!0}),e}n(Et,"parseHeaderValue");function wt(t){let e={};for(let[r,o]of t.entries())e[r]=o;return e}n(wt,"objectifyHeaders");async function St(t){let e=await t.arrayBuffer(),r=new Uint8Array(e),o="";for(let s=0;s<r.length;s++)o+=String.fromCharCode(r[s]);return btoa(o)}n(St,"serializeResponseBody");function Pt(t){let e=atob(t),r=e.length,o=new Uint8Array(r);for(let s=0;s<r;s++)o[s]=e.charCodeAt(s);return o}n(Pt,"deserializeResponseBody");var de=class{static{n(this,"Cache")}#t;#r;#e;constructor(e="default",r={}){this.#t=e;let o=Deno.env.get("ZUPLO_CACHE_REDIS_HOSTNAME")&&Deno.env.get("ZUPLO_CACHE_REDIS_PORT");this.#r=!o||!Ee(Deno.env.get("USE_ZENO_ZONE_CACHE")),this.#e=r.getRedisClient||Ct}#n(e){return`${this.#t}:${e.url}`}async match(e,r){if(this.#r)return;let o=this.#n(e),s=await this.#e();await s.sendCommand(["HELLO",3]);let c=await s.sendCommand(["TTL",o]);if(c!==-2){if(c<2)return;{let d=await s.sendCommand(["HGETALL",o]),l=d.status,u=d.status,i=new Headers(JSON.parse(d.headers));return new Response(Pt(d.body),{status:l,statusText:u,headers:i})}}}async put(e,r){if(this.#r)return;let o=1*60*60,s=Et(r.headers.get("cache-control")),c=parseInt(s["s-maxage"]),d=parseInt(s["max-age"]),l=s["no-store"],u=s["no-cache"],i=c||d||0;if(i===0&&!l&&!u&&(i=o,r.headers.append("cache-control",`s-maxage=${o}`)),i>0){let g=this.#n(e),p=await this.#e();await p.sendCommand(["HELLO",3]),await p.sendCommand(["HSET",g,"maxage",i,"status",r.status,"statusText",r.statusText,"headers",JSON.stringify(wt(r.headers)),"body",await St(r)]),await p.sendCommand(["EXPIRE",g,i])}}async delete(e){if(this.#r)return;let r=this.#n(e);if(await(await this.#e()).sendCommand(["DEL",r])!==1)throw new Error("Failed to delete cache entry")}},_t=new fe;Object.defineProperty(globalThis,"caches",{value:_t,writable:!1,enumerable:!0,configurable:!1});var ne=class{static{n(this,"WorkerServer")}#t;#r;#e=n(()=>({waitUntil:n(e=>{e.catch(r=>{console.error("Error in waitUntil:",r)})},"waitUntil")}),"#createContext");constructor(e){this.#r=e}async start(){let{port:e,workerModule:r,env:o}=this.#r;this.#t=Deno.serve({port:e,onListen:n(()=>{w.debug(`Server running at http://localhost:${e}`)},"onListen")},async s=>{try{return await r.default.fetch(s,o,this.#e())}catch(c){return w.error("Error handling request:",c),new Response("Internal Server Error",{status:500})}}),await this.#t.finished}async stop(){await this.#t?.shutdown()}};import{pathToFileURL as Nt}from"node:url";var we=k("dist","worker.js");function Se(){if(Deno.build.standalone)return k("..",we);let t=Deno.cwd();return k(t,we)}n(Se,"getDefaultWorkerPath");function Ot(t){return typeof t=="object"&&t!==null&&"default"in t&&typeof t.default=="object"&&"fetch"in t.default&&typeof t.default.fetch=="function"}n(Ot,"isWorkerModule");async function ue(t){let e;if(Deno.build.standalone?(w.debug("Loading worker module from: ",t),e=await import(t)):(w.debug("Loading dev worker module from: ",t),e=await import(Nt(t).href)),!Ot(e))throw new Error("Invalid worker module");return e}n(ue,"importWorkerModule");function Pe(){console.log("Enabling fetch host override.");let t=globalThis.fetch,e=Deno.createHttpClient({allowHost:!0,http2:!1});return globalThis.fetch=async(r,o={})=>await t(r,{...o,client:e}),e}n(Pe,"setFetchHostOverride");function _e(t){if(new.target)throw new TypeError("Cannot create an instance: parse is not a constructor");return new pe(t).parse()}n(_e,"parse");var pe=class{static{n(this,"JsoncParser")}#t=new Set(` \r
27
27
  `);#r=new Set([..."[]{}:,/",...this.#t]);#e;#n;#s;constructor(e){this.#e=`${e}`,this.#n=this.#e.length,this.#s=this.#l()}parse(){let e=this.#o(),r=this.#i(e),{done:o,value:s}=this.#s.next();if(!o)throw new SyntaxError(B(s));return r}#o(){let{done:e,value:r}=this.#s.next();if(e)throw new SyntaxError("Cannot parse JSONC: unexpected end of JSONC input");return r}*#l(){for(let e=0;e<this.#n;e++)if(!this.#t.has(this.#e[e])){if(this.#e[e]==="/"&&this.#e[e+1]==="*"){e+=2;let r=!1;for(;e<this.#n;e++)if(this.#e[e]==="*"&&this.#e[e+1]==="/"){r=!0;break}if(!r)throw new SyntaxError("Cannot parse JSONC: unexpected end of JSONC input");e++;continue}if(this.#e[e]==="/"&&this.#e[e+1]==="/"){for(e+=2;e<this.#n&&!(this.#e[e]===`
28
28
  `||this.#e[e]==="\r");e++);continue}switch(this.#e[e]){case"{":yield{type:"BeginObject",position:e};break;case"}":yield{type:"EndObject",position:e};break;case"[":yield{type:"BeginArray",position:e};break;case"]":yield{type:"EndArray",position:e};break;case":":yield{type:"NameSeparator",position:e};break;case",":yield{type:"ValueSeparator",position:e};break;case'"':{let r=e,o=!1;for(e++;e<this.#n&&!(this.#e[e]==='"'&&!o);e++)o=this.#e[e]==="\\"&&!o;yield{type:"String",sourceText:this.#e.substring(r,e+1),position:r};break}default:{let r=e;for(;e<this.#n&&!this.#r.has(this.#e[e]);e++);e--,yield{type:"NullOrTrueOrFalseOrNumber",sourceText:this.#e.substring(r,e+1),position:r}}}}}#i(e){switch(e.type){case"BeginObject":return this.#c();case"BeginArray":return this.#f();case"NullOrTrueOrFalseOrNumber":return this.#d(e);case"String":return this.#a(e);default:throw new SyntaxError(B(e))}}#c(){let e={};for(;;){let r=this.#o();if(r.type==="EndObject")return e;if(r.type!=="String")throw new SyntaxError(B(r));let o=this.#a(r),s=this.#o();if(s.type!=="NameSeparator")throw new SyntaxError(B(s));let c=this.#o();Object.defineProperty(e,o,{value:this.#i(c),writable:!0,enumerable:!0,configurable:!0});let d=this.#o();if(d.type==="EndObject")return e;if(d.type!=="ValueSeparator")throw new SyntaxError(B(d))}}#f(){let e=[];for(;;){let r=this.#o();if(r.type==="EndArray")return e;e.push(this.#i(r));let o=this.#o();if(o.type==="EndArray")return e;if(o.type!=="ValueSeparator")throw new SyntaxError(B(o))}}#a(e){let r;try{r=JSON.parse(e.sourceText)}catch{throw new SyntaxError(B(e))}if(typeof r!="string")throw new TypeError(`Parsed value is not a string: ${r}`);return r}#d(e){if(e.sourceText==="null")return null;if(e.sourceText==="true")return!0;if(e.sourceText==="false")return!1;let r;try{r=JSON.parse(e.sourceText)}catch{throw new SyntaxError(B(e))}if(typeof r!="number")throw new TypeError(`Parsed value is not a number: ${r}`);return r}};function B({type:t,sourceText:e,position:r}){let o="";switch(t){case"BeginObject":o="{";break;case"EndObject":o="}";break;case"BeginArray":o="[";break;case"EndArray":o="]";break;case"NameSeparator":o=":";break;case"ValueSeparator":o=",";break;case"NullOrTrueOrFalseOrNumber":case"String":o=30<e.length?`${e.slice(0,30)}...`:e;break}return`Cannot parse JSONC: unexpected token "${o}" in JSONC at position ${r}`}n(B,"buildErrorMessage");var Ne="zuplo.jsonc";function Oe(t){let e=k(t,Ne),r;try{r=Deno.readTextFileSync(e)}catch(c){w.warn(c,`Failed to read ${Ne}`);return}let o=_e(r);if(o===null)return;let s;return typeof o=="object"&&"managedDedicatedFlags"in o?s=o.managedDedicatedFlags:typeof o=="object"&&"flags"in o&&typeof o.flags=="object"&&o.flags!==null&&"managedDedicatedFlags"in o.flags?s=o.flags.managedDedicatedFlags:typeof o=="object"&&("projectType"in o||"allowHostHeaderOverride"in o)&&(s={useZeno:"projectType"in o&&o.projectType!=="managed-edge",allowFetchHostHeaderOverride:"allowHostHeaderOverride"in o&&o.allowHostHeaderOverride===!0}),s}n(Oe,"getManagedDedicatedSettings");var Dt=/^(?:-(?:(?<doubleDash>-)(?<negated>no-)?)?)(?<key>.+?)(?:=(?<value>.+?))?$/s,vt=/[A-Za-z]/,kt=/-?\d+(\.\d*)?(e-?\d+)?$/,Lt=/^(-|--)[^-]/,Ht=/=(?<value>.+)/,Ut=/^--[^=]+$/,It=/\W/,Ft=/\S/;function De(t){return Ft.test(t)&&Number.isFinite(Number(t))}n(De,"isNumber");function j(t,e,r,o=!1){e=[...e];let s=e.pop();if(e.forEach(c=>t=t[c]??={}),o){let c=t[s];if(Array.isArray(c)){c.push(r);return}r=c?[c,r]:[r]}t[s]=r}n(j,"setNested");function ge(t,e){for(let r of e){let o=t[r];if(!Object.hasOwn(t,r))return!1;t=o}return!0}n(ge,"hasNested");function ve(t,e,r){let o=t.get(r);if(o===void 0)return!1;for(let s of o)if(e.has(s))return!0;return!1}n(ve,"aliasIsBoolean");function ke(t){return t==="true"||t==="false"}n(ke,"isBooleanString");function me(t){return t!=="false"}n(me,"parseBooleanString");function Le(t,e){let{"--":r=!1,alias:o={},boolean:s=!1,default:c={},stopEarly:d=!1,string:l=[],collect:u=[],negatable:i=[],unknown:g=n(f=>f,"unknownFn")}=e??{},p=new Map,A=new Set,x=new Set,E=new Set,S=new Set,_=!1;if(o)for(let[f,a]of Object.entries(o)){if(a===void 0)throw new TypeError("Alias value must be defined");let m=Array.isArray(a)?a:[a];p.set(f,new Set(m)),m.forEach(U=>p.set(U,new Set([f,...m.filter($=>$!==U)])))}if(s)if(typeof s=="boolean")_=s;else{let f=Array.isArray(s)?s:[s];for(let a of f.filter(Boolean))A.add(a),p.get(a)?.forEach(m=>{A.add(m)})}if(l){let f=Array.isArray(l)?l:[l];for(let a of f.filter(Boolean))x.add(a),p.get(a)?.forEach(m=>x.add(m))}if(u){let f=Array.isArray(u)?u:[u];for(let a of f.filter(Boolean))E.add(a),p.get(a)?.forEach(m=>E.add(m))}if(i){let f=Array.isArray(i)?i:[i];for(let a of f.filter(Boolean))S.add(a),p.get(a)?.forEach(m=>S.add(m))}let b={_:[]};function T(f,a,m,U){if(!A.has(f)&&!x.has(f)&&!p.has(f)&&!(_&&Ut.test(m))&&g?.(m,f,a)===!1)return;typeof a=="string"&&!x.has(f)&&(a=De(a)?Number(a):a);let $=U&&E.has(f);j(b,f.split("."),a,$),p.get(f)?.forEach(h=>{j(b,h.split("."),a,$)})}n(T,"setArgument");let P=[],N=t.indexOf("--");N!==-1&&(P=t.slice(N+1),t=t.slice(0,N));e:for(let f=0;f<t.length;f++){let a=t[f],m=a.match(Dt)?.groups;if(m){let{doubleDash:U,negated:$}=m,h=m.key,L=m.value;if(U){if(L){A.has(h)&&(L=me(L)),T(h,L,a,!0);continue}if($){if(S.has(h)){T(h,!1,a,!1);continue}h=`no-${h}`}let O=t[f+1];if(O){if(!A.has(h)&&!_&&!O.startsWith("-")&&(!p.has(h)||!ve(p,A,h))){L=O,f++,T(h,L,a,!0);continue}if(ke(O)){L=me(O),f++,T(h,L,a,!0);continue}}L=x.has(h)?"":!0,T(h,L,a,!0);continue}let he=a.slice(1,-1).split("");for(let[O,G]of he.entries()){let V=a.slice(O+2);if(V==="-"){T(G,V,a,!0);continue}if(vt.test(G)){let Ae=Ht.exec(V)?.groups;if(Ae){T(G,Ae.value,a,!0);continue e}if(kt.test(V)){T(G,V,a,!0);continue e}}if(he[O+1]?.match(It)){T(G,a.slice(O+2),a,!0);continue e}T(G,x.has(G)?"":!0,a,!0)}if(h=a.slice(-1),h==="-")continue;let z=t[f+1];if(z){if(!Lt.test(z)&&!A.has(h)&&(!p.has(h)||!ve(p,A,h))){T(h,z,a,!0),f++;continue}if(ke(z)){let O=me(z);T(h,O,a,!0),f++;continue}}T(h,x.has(h)?"":!0,a,!0);continue}if(g?.(a)!==!1&&b._.push(x.has("_")||!De(a)?a:Number(a)),d){b._.push(...t.slice(f+1));break}}for(let[f,a]of Object.entries(c)){let m=f.split(".");ge(b,m)||(j(b,m,a),p.get(f)?.forEach(U=>j(b,U.split("."),a)))}for(let f of A.keys()){let a=f.split(".");if(!ge(b,a)){let m=E.has(f)?[]:!1;j(b,a,m)}}for(let f of x.keys()){let a=f.split(".");!ge(b,a)&&E.has(f)&&j(b,a,[])}return r?b["--"]=P:b._.push(...P),b}n(Le,"parseArgs");async function Bt(){let t;w.debug("Starting Zeno server...");let e=Le(Deno.args,{boolean:["help"],string:["port","dir"],default:{port:9e3}}),r=Number(e.port);(isNaN(r)||r<1||r>65535)&&(w.error(`Invalid port: ${e.port}. Port must be a number between 1 and 65535.`),Deno.exit(1));let o=r;try{let s=e.dir?e.dir:Deno.cwd(),c=k(s,"dist","worker.js"),d;Deno.build.standalone?d=await ue(Se()):d=await ue(c);let l=await Ce(s);Oe(s)?.allowFetchHostHeaderOverride&&(t=Pe()),await new ne({port:o,workerModule:d,env:l}).start()}catch(s){w.error("Failed to start server:",s)}finally{t&&t.close()}}n(Bt,"main");import.meta.main&&await Bt();export{Bt as main};