@zuplo/core 6.64.21 → 6.64.24

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.
Files changed (2) hide show
  1. package/package.json +4 -4
  2. package/zeno.js +3 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zuplo/core",
3
- "version": "6.64.21",
3
+ "version": "6.64.24",
4
4
  "repository": "https://github.com/zuplo/zuplo",
5
5
  "author": "Zuplo, Inc.",
6
6
  "type": "module",
@@ -40,9 +40,9 @@
40
40
  "source-map": "^0.7.4"
41
41
  },
42
42
  "peerDependencies": {
43
- "@zuplo/graphql": "6.64.21",
44
- "@zuplo/otel": "6.64.21",
45
- "@zuplo/runtime": "6.64.21",
43
+ "@zuplo/graphql": "6.64.24",
44
+ "@zuplo/otel": "6.64.24",
45
+ "@zuplo/runtime": "6.64.24",
46
46
  "deno": "2.3.1"
47
47
  }
48
48
  }
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){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
- `);#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
- `||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};
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;#n;#e=Promise.resolve();constructor(e){this.#t=e.writable.getWriter(),this.#n=et(e.readable)}#r(e){return this.#e=this.#e.then(e),this.#e}sendCommand(e,r=!1){return this.#r(()=>(this.#t.write(oe(e)),X(this.#n,r)))}writeCommand(e){return this.#r(()=>this.#t.write(oe(e)))}async*readReplies(e=!1){for(;;)yield X(this.#n,e)}pipelineCommands(e,r=!1){return this.#r(()=>{let o=q(e.map(oe));return this.#t.write(o),K(this.#n,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="",l=0,f=-1,c=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(!(f===i-1||c===1))if(f!==i-1&&c===2){if(s.length<2||l!==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="",l=0):(s=s.slice(0,g),l=s.length-1-s.lastIndexOf(r)),f=i,c=0;continue}else if(s.length===2||s.length===1){s="",l=0,f=i,c=0;continue}}e&&(s.length>0?s+=`${r}..`:s="..",l=2)}else s.length>0?s+=r+t.slice(f+1,i):s=t.slice(f+1,i),l=i-f-1;f=i,c=0}else u===46&&c!==-1?++c:c=-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,l=t.charCodeAt(0);if(e>1)if(y(l))if(s=!0,y(t.charCodeAt(1))){let c=2,u=c;for(;c<e&&!y(t.charCodeAt(c));++c);if(c<e&&c!==u){let i=t.slice(u,c);for(u=c;c<e&&y(t.charCodeAt(c));++c);if(c<e&&c!==u){for(u=c;c<e&&!y(t.charCodeAt(c));++c);if(c===e)return`\\\\${i}\\${t.slice(u)}\\`;c!==u&&(o=`\\\\${i}\\${t.slice(u,c)}`,r=c)}}}else r=1;else H(l)&&t.charCodeAt(1)===58&&(o=t.slice(0,2),r=2,e>2&&y(t.charCodeAt(2))&&(s=!0,r=3));else if(y(l))return"\\";let f;return r<e?f=W(t.slice(r),!s,"\\",y):f="",f.length===0&&!s&&(f="."),f.length>0&&y(t.charCodeAt(e-1))&&(f+="\\"),o===void 0?s?f.length>0?`\\${f}`:"\\":f:s?f.length>0?`${o}\\${f}`:`${o}\\`:o+f}n(re,"normalize");function le(...t){if(t.forEach(l=>C(l)),t=t.filter(l=>l.length>0),t.length===0)return".";let e=!0,r=0,o=t[0];if(y(o.charCodeAt(0))){++r;let l=o.length;l>1&&y(o.charCodeAt(1))&&(++r,l>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),l=Math.log(256)/Math.log(r);function f(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 w=(x-A)*l+1>>>0,S=new Uint8Array(w);for(;A!==x;){let T=i[A],P=0;for(let N=w-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 _=w-p;for(;_!==w&&S[_]===0;)_++;let b=o.repeat(g);for(;_<w;++_)b+=t.charAt(S[_]);return b}n(f,"encode");function c(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,w=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 d=x-1;(P!==0||N<A)&&d!==-1;d--,N++)P+=r*w[d]>>>0,w[d]=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&&w[S]===0;)S++;let _=new Uint8Array(p+(x-S)),b=p;for(;S!==x;)_[b++]=w[S++];return _}n(c,"decodeUnsafe");function u(i){let g=c(i);if(g)return g;throw new Error("Non-base"+r+" character")}return n(u,"decode"),{encode:f,decodeUnsafe:c,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}},E=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)),l=o.decode(s),f=Re.parse(l);for(let[c,u]of Object.entries(f))if(e[c]=u,c==="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||E.error("Failed to parse ZUPLO_SYSTEM_CONFIGURATIONS from .env.zuplo:",i)}}catch(r){r instanceof Deno.errors.NotFound||E.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)),l=o.decode(s),f=Re.parse(l);for(let[c,u]of Object.entries(f))e[c]=u}catch(r){r instanceof Deno.errors.NotFound||E.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,l]=o.trim().split("=");e[s.toLowerCase()]=l?l.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;#n;#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.#n=!o||!Ee(Deno.env.get("USE_ZENO_ZONE_CACHE")),this.#e=r.getRedisClient||Ct}#r(e){return`${this.#t}:${e.url}`}async match(e,r){if(this.#n)return;let o=this.#r(e),s=await this.#e();await s.sendCommand(["HELLO",3]);let l=await s.sendCommand(["TTL",o]);if(l!==-2){if(l<2)return;{let f=await s.sendCommand(["HGETALL",o]),c=f.status,u=f.status,i=new Headers(JSON.parse(f.headers));return new Response(Pt(f.body),{status:c,statusText:u,headers:i})}}}async put(e,r){if(this.#n)return;let o=1*60*60,s=Et(r.headers.get("cache-control")),l=parseInt(s["s-maxage"]),f=parseInt(s["max-age"]),c=s["no-store"],u=s["no-cache"],i=l||f||0;if(i===0&&!c&&!u&&(i=o,r.headers.append("cache-control",`s-maxage=${o}`)),i>0){let g=this.#r(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.#n)return;let r=this.#r(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;#n;#e;#r=n(()=>({waitUntil:n(e=>{e.catch(r=>{console.error("Error in waitUntil:",r)})},"waitUntil")}),"#createContext");constructor(e){this.#e=e}async start(){let{port:e,workerModule:r,env:o}=this.#e,s=e+1;this.#n=Deno.serve({port:s,onListen:n(()=>{E.debug(`Stats server running at http://localhost:${s}`)},"onListen")},l=>l.url.endsWith("/__zuplo/internal_memory_metrics")?new Response(JSON.stringify(Deno.memoryUsage()),{headers:{"content-type":"application/json"}}):new Response("Not Found",{status:404})),this.#t=Deno.serve({port:e,onListen:n(()=>{E.debug(`Server running at http://localhost:${e}`)},"onListen")},async l=>{try{return await r.default.fetch(l,o,this.#r())}catch(f){return E.error("Error handling request:",f),new Response("Internal Server Error",{status:500})}}),await this.#t.finished,await this.#n.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?(E.debug("Loading worker module from: ",t),e=await import(t)):(E.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
+ `);#n=new Set([..."[]{}:,/",...this.#t]);#e;#r;#s;constructor(e){this.#e=`${e}`,this.#r=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.#r;e++)if(!this.#t.has(this.#e[e])){if(this.#e[e]==="/"&&this.#e[e+1]==="*"){e+=2;let r=!1;for(;e<this.#r;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.#r&&!(this.#e[e]===`
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.#r&&!(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.#r&&!this.#n.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 l=this.#o();Object.defineProperty(e,o,{value:this.#i(l),writable:!0,enumerable:!0,configurable:!0});let f=this.#o();if(f.type==="EndObject")return e;if(f.type!=="ValueSeparator")throw new SyntaxError(B(f))}}#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(l){E.warn(l,`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(l=>t=t[l]??={}),o){let l=t[s];if(Array.isArray(l)){l.push(r);return}r=l?[l,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:l={},stopEarly:f=!1,string:c=[],collect:u=[],negatable:i=[],unknown:g=n(d=>d,"unknownFn")}=e??{},p=new Map,A=new Set,x=new Set,w=new Set,S=new Set,_=!1;if(o)for(let[d,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(d,new Set(m)),m.forEach(U=>p.set(U,new Set([d,...m.filter($=>$!==U)])))}if(s)if(typeof s=="boolean")_=s;else{let d=Array.isArray(s)?s:[s];for(let a of d.filter(Boolean))A.add(a),p.get(a)?.forEach(m=>{A.add(m)})}if(c){let d=Array.isArray(c)?c:[c];for(let a of d.filter(Boolean))x.add(a),p.get(a)?.forEach(m=>x.add(m))}if(u){let d=Array.isArray(u)?u:[u];for(let a of d.filter(Boolean))w.add(a),p.get(a)?.forEach(m=>w.add(m))}if(i){let d=Array.isArray(i)?i:[i];for(let a of d.filter(Boolean))S.add(a),p.get(a)?.forEach(m=>S.add(m))}let b={_:[]};function T(d,a,m,U){if(!A.has(d)&&!x.has(d)&&!p.has(d)&&!(_&&Ut.test(m))&&g?.(m,d,a)===!1)return;typeof a=="string"&&!x.has(d)&&(a=De(a)?Number(a):a);let $=U&&w.has(d);j(b,d.split("."),a,$),p.get(d)?.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 d=0;d<t.length;d++){let a=t[d],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[d+1];if(O){if(!A.has(h)&&!_&&!O.startsWith("-")&&(!p.has(h)||!ve(p,A,h))){L=O,d++,T(h,L,a,!0);continue}if(ke(O)){L=me(O),d++,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[d+1];if(z){if(!Lt.test(z)&&!A.has(h)&&(!p.has(h)||!ve(p,A,h))){T(h,z,a,!0),d++;continue}if(ke(z)){let O=me(z);T(h,O,a,!0),d++;continue}}T(h,x.has(h)?"":!0,a,!0);continue}if(g?.(a)!==!1&&b._.push(x.has("_")||!De(a)?a:Number(a)),f){b._.push(...t.slice(d+1));break}}for(let[d,a]of Object.entries(l)){let m=d.split(".");ge(b,m)||(j(b,m,a),p.get(d)?.forEach(U=>j(b,U.split("."),a)))}for(let d of A.keys()){let a=d.split(".");if(!ge(b,a)){let m=w.has(d)?[]:!1;j(b,a,m)}}for(let d of x.keys()){let a=d.split(".");!ge(b,a)&&w.has(d)&&j(b,a,[])}return r?b["--"]=P:b._.push(...P),b}n(Le,"parseArgs");async function Bt(){let t;E.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)&&(E.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(),l=k(s,"dist","worker.js"),f;Deno.build.standalone?f=await ue(Se()):f=await ue(l);let c=await Ce(s);Oe(s)?.allowFetchHostHeaderOverride&&(t=Pe()),await new ne({port:o,workerModule:f,env:c}).start()}catch(s){E.error("Failed to start server:",s)}finally{t&&t.close()}}n(Bt,"main");import.meta.main&&await Bt();export{Bt as main};