web-listener 1.2.1 → 1.3.0

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.
package/index.js CHANGED
@@ -1,2 +1,3 @@
1
- import{isIPv4 as t,isIPv6 as e}from"node:net";import n from"node:events";import{constants as r,open as o,readFile as i,stat as s,writeFile as a,utimes as c,rm as f,readdir as u,realpath as l,mkdtemp as h}from"node:fs/promises";import{TransformStream as d,TextDecoderStream as w,DecompressionStream as p,ReadableStream as m}from"node:stream/web";import{STATUS_CODES as y,createServer as g,Agent as b,request as v,ServerResponse as E}from"node:http";import{createReadStream as _,createWriteStream as S,openAsBlob as $}from"node:fs";import{createHash as x,randomUUID as T}from"node:crypto";import{pipeline as k}from"node:stream/promises";import{extname as N,join as R,dirname as O,basename as A,sep as P,resolve as F}from"node:path";import C,{createInflateRaw as M}from"node:zlib";import{promisify as U}from"node:util";import{tmpdir as D,platform as B}from"node:os";import{Readable as I,Duplex as H}from"node:stream";import{Agent as j,request as z}from"node:https";function q(n){if(!n||"unknown"===n)return;const r=/^((?:\d{1,3}\.){3}\d{1,3})(?::(\d+))?$/.exec(n);if(r?.[1]&&t(r[1]))return{family:"IPv4",address:r[1],port:r[2]?Number.parseInt(r[2]):void 0};const o=/^\[([\da-fA-F:]+)\](?::(\d+))?$|^([\da-fA-F:]+)$/.exec(n);if(o?.[1]&&e(o[1]))return{family:"IPv6",address:o[1].toLowerCase(),port:o[2]?Number.parseInt(o[2]):void 0};if(o?.[3]&&e(o[3]))return{family:"IPv6",address:o[3].toLowerCase(),port:void 0};const i=/^(.*?):(\d+)$/i.exec(n);return i?.[2]?{family:"alias",address:i[1],port:Number.parseInt(i[2])}:{family:"alias",address:n,port:void 0}}function J(t){const e=new Set,n=[],r=[];for(const o of t){const t=/^((?:\d{1,3}\.){3}\d{1,3})(?:\/(\d+))?$/.exec(o);if(t?.[1]){const e=t[2]?Number.parseInt(t[2]):32,r=e<32?4294967295>>>e:0;n.push([W(t[1])|r,r]);continue}const i=/^\[?([\da-fA-F:]+)\]?(?:\/(\d+))?$/.exec(o);if(i?.[1]){const t=G(i[1]),e=i[2]?L>>BigInt(Number.parseInt(i[2])):0n;r.push([t|e,e]);continue}e.add(o)}return t=>{switch(t?.family){case"alias":return e.has(t.address);case"IPv4":const o=W(t.address);return n.some(([t,e])=>(o|e)===t);case"IPv6":const i=G(t.address);return r.some(([t,e])=>(i|e)===t);default:return!1}}}const L=/*@__PURE__*/BigInt("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");function W(t){const e=t.split(".").map(Number);return(e[0]<<24|e[1]<<16|e[2]<<8|e[3])>>>0}function G(t){const e=t.split(":").map(t=>t?Number.parseInt(t,16):-1);let n=0n;for(const t of e)t<0?n<<=16n*BigInt(9-e.length):n=n<<16n|BigInt(t);return n}function V(t,e,n){if(t>=2147483648||Number.isNaN(t)||!n&&t<0)throw new RangeError(`${e} must fit in a 31 bit integer - got ${t}`)}class X{constructor(t){const e={t:null,o:null};this.i=e,this.u=e,void 0!==t&&this.push(t)}isEmpty(){return!this.i.o}clear(){this.i.o=null,this.i.t=null,this.u=this.i}push(t){const e={t,o:null};this.u.o=e,this.u=e}shift(){if(!this.i.o)return null;this.i=this.i.o;const t=this.i.t;return this.i.t=null,t}remove(t){for(let e=this.i;e.o;e=e.o)if(e.o.t===t){e.o=e.o.o;break}}[Symbol.iterator](){return{next:()=>{if(!this.i.o)return{value:null,done:!0};this.i=this.i.o;const t=this.i.t;return this.i.t=null,{value:t,done:!1}}}}}class Z{constructor(){this.l=new X,this.h=new X,this.m=0}push(t){if(this.m)return;const e=this.h.shift();e?(e.v&&clearTimeout(e.v),e._(t)):this.l.push(t)}shift(t){return V(t??0,"timeout"),this.l.isEmpty()?this.m?Promise.reject(this.S):new Promise((e,n)=>{const r={_:e,$:n,v:null};this.h.push(r),void 0!==t&&(r.v=setTimeout(()=>{this.h.remove(r),n(new Error(`timeout after ${t}ms`))},t))}):Promise.resolve(this.l.shift())}T(t){this.S=t;for(const e of this.h)e.$(t),e.v&&clearTimeout(e.v)}close(t){this.m||(this.m=1,this.T(t))}fail(t){this.m||(this.m=2,this.T(t))}[Symbol.asyncIterator](){return{next:()=>this.shift().then(t=>({value:t,done:!1}),t=>{if(2===this.m)throw t;return{value:null,done:!0}})}}}function Y(t,e){if(!(t instanceof n))return t.createReadStream(e);const r=t.close&&!1===e.autoClose?new Proxy(t,{get:(t,e,...n)=>"close"===e?()=>Promise.resolve():Reflect.get(t,e,...n)}):t,o=t.listeners("close").length,i=r.createReadStream(e),s=t.listeners("close"),a=s.length>o?s[s.length-1]:void 0,c=()=>{a&&t.off("close",a),i.destroy(),i.off("end",c),i.off("error",f)},f=()=>{t.close?.(),c()};return i.once("end",c),i.once("error",f),i}function K(t,e){if(t instanceof e)return t;if(t&&"object"==typeof t){if("cause"in t)return K(t.cause,e);if("error"in t)return K(t.error,e)}}function Q(t,e="http"){if(!t)throw new TypeError("no address");if("string"==typeof t)return t;const n=void 0===t.port?"":`:${t.port}`;if("IPv4"===t.family||"alias"===t.family)return`${e}://${t.address}${n}`;if("IPv6"===t.family)return`${e}://[${t.address}]${n}`;throw new TypeError(`unknown address family: ${t.family}`)}const tt=(t,e)=>new RegExp(t,(t.unicodeSets?"v":t.unicode?"u":"")+(t.ignoreCase||e?"i":"")),et=(t,e)=>{if(void 0===t)return()=>!0;if(Array.isArray(t)||(t=[t]),!t.length)return()=>!1;if(1===t.length){const n=t[0];if("string"==typeof n){if(e){const t=n.toLowerCase();return e=>e.toLowerCase()===t}return t=>t===n}const r=tt(n,e);return t=>r.test(t)}const n=new Set,r=[];for(const o of t)"string"==typeof o?e?n.add(o.toLowerCase()):n.add(o):r.push(tt(o,e));return t=>n.has(e?t.toLowerCase():t)||r.some(e=>e.test(t))};class nt{constructor(t,e=r.O_RDONLY,n=438,o=1e3){this.k=t,this.N=e,this.R=n,this.O=0,this.A=o}get path(){return this.k}countActive(){return this.O}async open(){++this.O,clearTimeout(this.P),this.P=void 0,this.F||(this.F=o(this.k,this.N,this.R).then(t=>(t.setMaxListeners(0),this.F=t,t)));const t=t=>{let e=!1;const n=()=>(e||(e=!0,this.T()),Promise.resolve());return new Proxy(t,{get:(t,e,...r)=>"close"===e?n:Reflect.get(t,e,...r)})};return"then"in this.F?this.F.then(t):t(this.F)}T(){--this.O||(clearTimeout(this.P),this.P=setTimeout(()=>{this.P=void 0,Promise.resolve(this.F).then(t=>{t&&!this.O&&(this.F=void 0,t.close().catch(()=>{}))})},this.A).unref())}}const rt=/*@__PURE__*/Buffer.alloc(0);function ot(t,e){const n=t.indexOf(e);return-1===n?[t]:[t.substring(0,n),t.substring(n+e.length)]}function it(t,e,n=it){throw t.code=e,Error.captureStackTrace(t,n),t}class st{constructor(t,{fatal:e=!1}={}){this.C=t,this.M=e,this.U=new Uint8Array(4),this.D=new DataView(this.U.buffer),this.B=0}decode(t,{stream:e=!1}={}){const n=t.byteLength,r=[];let o=0;if(this.B>0){if(o=4-this.B,n<o)return this.U.set(t,this.B),this.B+=n,"";this.U.set(t.subarray(0,o),this.B),r.push(this.D.getUint32(0,this.C)),this.B=0}const i=new DataView(t.buffer,t.byteOffset,t.byteLength);let s=o;for(const t=n-3;s<t;s+=4)r.push(i.getUint32(s,this.C));if(e?(s<n&&this.U.set(t.subarray(s)),this.B=n-s):(this.B=0,s<n&&(this.M?it(new TypeError("The encoded data was not valid for encoding utf-32"),"ERR_ENCODING_INVALID_ENCODED_DATA"):r.push(65533))),r.length>0){try{return String.fromCodePoint(...r)}catch{this.M&&it(new TypeError("The encoded data was not valid for encoding utf-32"),"ERR_ENCODING_INVALID_ENCODED_DATA")}for(let t=0;t<r.length;++t)r[t]>1114111&&(r[t]=65533);return String.fromCodePoint(...r)}return""}}class at{constructor(t){this.I=t,this.H=Object.create(null),this.j=!1}get headersSent(){return this.j}writeHead(t,e=y[t]??"-"){return this.j&&it(new Error("Cannot write headers after they are sent to the client"),"ERR_HTTP_HEADERS_SENT"),this.I.write([`HTTP/1.1 ${t} ${ut(e)}`,...ct(this.H),"",""].join("\r\n"),"ascii"),this.j=!0,this}write(t,e="utf-8",n){return this.I.write(t,e,n)}end(t,e="utf-8",n){return this.I.end(t,e,n),this}setHeader(t,e){const n=t.toLowerCase();return this.H[n]="string"==typeof e||"number"==typeof e?e:[...e],this}setHeaders(t){for(const[e,n]of t)this.setHeader(e,n);return this}}function ct(t){const e=[];for(const[n,r]of Object.entries(t)){const t=ft(r);t&&e.push(`${ut(n)}: ${ut(t)}`)}return e}const ft=t=>"string"==typeof t?t:"number"==typeof t?String(t):t?t.join(", "):"",ut=t=>t.replaceAll(/[^ \t!-~]/g,"");function lt(t){if(!t||t instanceof Headers||Array.isArray(t))return new Headers(t);const e=t instanceof Map?[...t.entries()]:Object.entries(t);return new Headers(e.map(([t,e])=>[t,ft(e)]).filter(([t,e])=>e))}class ht extends Error{constructor(t,{message:e,statusMessage:n,headers:r,body:o,...i}={}){super(e??o,i),this.statusCode=0|t,this.statusMessage=n??y[this.statusCode]??"-",this.headers=lt(r),this.body=o??"",this.name=`HTTPError(${this.statusCode} ${this.statusMessage})`}}class dt extends d{constructor(t){super({transform(e,n){try{const r=t.decode(e,{stream:!0});r&&n.enqueue(r)}catch(t){n.error(t)}},flush(e){try{const n=t.decode(rt);n&&e.enqueue(n)}catch(t){e.error(t)}}})}}const wt=new Map;function pt(t,e){wt.set(t.toLowerCase(),e)}function mt(){pt("utf-32be",{decoder:t=>new st(!1,t)}),pt("utf-32le",{decoder:t=>new st(!0,t)})}function yt(t,e={}){const n=wt.get(t.toLowerCase());if(n)return n.decoder(e);try{return new TextDecoder(t,e)}catch{throw new ht(415,{body:`unsupported charset: ${t}`})}}function gt(t,e={}){const n=wt.get(t.toLowerCase());if(n)return n.decoderStream?n.decoderStream(e):new dt(n.decoder(e));try{return new w(t,e)}catch{throw new ht(415,{body:`unsupported charset: ${t}`})}}const bt=[null,"utf-32be",null,null,null,"utf-16be","utf-16be","utf-16be","utf-32le","utf-16le","utf-16le","utf-16le",null,null,null,"utf-8"];function vt(t){if(!t)return null;const[e,n]=ot(t,";"),r=new Map;if(n){const t=/\s*([!#-'*+\-.0-:>-Z^-z|~]+)=(?:([!#-'*+\-.0-:>-Z^-z|~]+)|"((?:[^\x00-\x08\x0a-\x1f"\\\x7f]|\\.)*)")\s*(;|$)/gy;for(;t.lastIndex!==n.length;){const e=t.exec(n);if(!e)return null;const o=e[1].toLowerCase(),i=e[2]??e[3]?.replaceAll(/\\(.)/g,"$1")??"";r.has(o)||r.set(o,i)}}return{mime:e.trim().toLowerCase(),params:r}}function Et(t,e,n,r){const o=t.byteLength;for(;e<o;){for(;e<o;++e){const n=t[e];if(32!==n&&9!==n)break}if(e===o)break;if(59!==t[e++])return!1;for(;e<o;++e){const n=t[e];if(32!==n&&9!==n)break}if(e===o)return!1;const i=e;for(;e<o;++e){const n=t[e];if(!_t[n]){if(61===n)break;return!1}}if(e===o)return!1;const s=t.latin1Slice(i,e).toLowerCase();if("*"===s[s.length-1]){const r=++e;for(;e<o;++e){const n=t[e];if(!$t[n]){if(39!==n)return!1;break}}if(e===o)return!1;const i=yt(t.latin1Slice(r,e));for(++e;e<o&&39!==t[e];++e);if(e===o)return!1;if(++e===o)return!1;let a=e;const c=[];for(;e<o;++e){const n=t[e];if(1!==St[n]){if(37===n){let n,r;if(e+2<o&&16!==(n=Tt[t[e+1]])&&16!==(r=Tt[t[e+2]])){const o=(n<<4)+r;e>a&&c.push(i.decode(t.subarray(a,e),{stream:!0})),c.push(i.decode(Buffer.from([o]),{stream:!0})),a=(e+=2)+1;continue}return!1}break}}c.push(i.decode(t.subarray(a,e)));const f=c.join("");n.has(s)||n.set(s,f);continue}if(++e===o)return!1;if(34===t[e]){let i=++e,a=!1;const c=[];for(;e<o;++e){const n=t[e];if(92!==n){if(34===n){if(a){i=e,a=!1;continue}c.push(r.decode(t.subarray(i,e)));break}if(a&&(i=e-1,a=!1),!xt[n])return!1}else a?(i=e,a=!1):(c.push(r.decode(t.subarray(i,e),{stream:!0})),a=!0)}if(e===o)return!1;++e,n.has(s)||n.set(s,c.join(""));continue}let a=e;for(;e<o;++e){const n=t[e];if(!_t[n]){if(e===a)return!1;break}}n.has(s)||n.set(s,r.decode(t.subarray(a,e)))}return!0}const _t=/*@__PURE__*/(()=>{const t=new Uint8Array(256);return t.set([1,0,1,1,1,1,1,0,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1],33),t})(),St=/*@__PURE__*/(()=>{const t=new Uint8Array(_t);return t.set([0,1,0,0,0,0],37),t})(),$t=/*@__PURE__*/(()=>{const t=new Uint8Array(_t);return t.set([0,0,0,0,1,0,1,0],39),t.set([1,0,1,1],123),t})(),xt=/*@__PURE__*/(()=>{const t=new Uint8Array(256);return t.fill(1,32,256),t[9]=1,t[34]=0,t[92]=0,t[127]=0,t})(),Tt=/*@__PURE__*/(()=>{const t=new Uint8Array(256).fill(16);for(let e=0;e<10;++e)t[48+e]=e;for(let e=0;e<6;++e)t[65+e]=e+10,t[97+e]=e+10;return t})(),kt=t=>new URL("http://localhost"+(t.url??"/")),Nt=/%(25|2f)/gi,Rt=t=>t.replaceAll(/%2f/gi,"/").replaceAll(/%25/g,"%"),Ot=[6,6,9,12];class At extends Error{constructor(t,e,n){super(n??""),this.error=t,this.suppressed=e}}const Pt=globalThis.SuppressedError??At;class Ft{constructor(){this.J=!1}L(t){this.J?t!==this.W&&(this.W=new Pt(t,this.W)):(this.W=t,this.J=!0)}G(){this.J=!1,this.W=void 0}}const Ct=new WeakMap;function Mt(t,e,n){const r=Ct.get(t);if(r)return r;const o=kt(t),i={V:t,X:o,Z:(s=o.pathname,decodeURIComponent(s.replaceAll(Nt,"%25$1"))),Y:new AbortController,K:e,tt:[],et:[],nt:n?Bt(t):null};var s;return o.pathname.includes("%")&&(i.rt=o.pathname),Ct.set(t,i),i}function Ut(t,e,n){e||(t.nt=null),t.ot=n;const r=async()=>{t.Y.abort(n.it.writableEnded?"complete":"client abort");const e=new Ft;await Dt(t.tt,e,t),await Dt(t.et,e,t,()=>{t.st=async e=>{try{await e()}catch(e){t.K(e,"tearing down",t.V)}}}),e.J&&t.K(e.W,"tearing down",t.V)};return n.it.closed?r():n.it.once("close",r),t}async function Dt(t,e,n,r){for(;n.ct;)await n.ct;const o=(async()=>{for(;;){const n=t.pop();if(!n)return void r?.();try{await n()}catch(t){e.L(t)}}})().then(()=>{n.ct===o&&(n.ct=void 0)});n.ct=o,await o}function Bt(t){return new Set(t.headers.upgrade?.split(",").map(t=>t.trim().toLowerCase())??[])}const It=t=>Ct.get(t),Ht=t=>Ct.delete(t);function jt(t){const e=It(t);if(!e)throw new RangeError("unknown request");return e}function zt(t,e){const n=It(t);n&&qt(n,e)}function qt(t,e){t.ft=e;const n=t.ut;n&&queueMicrotask(()=>Xt(e,n,t))}const Jt=t=>Boolean(It(t)?.ut);function Lt(t,e,n,r=0,o){const i=jt(t),s=n-Math.max(r,0),a=i.lt??Number.POSITIVE_INFINITY,c=i.dt?.ht??a;s>=c&&n>=a||(n<a&&(i.lt=n),s<c&&(i.dt={ht:s,wt:e,K:o??i.K}),Vt(i))}function Wt(t,e,n){if(!t.ut){if(t.ot&&!t.nt){const e=t.ot.it;e.headersSent||e.hasHeader("connection")||e.setHeader("connection","close")}t.ot?.it.once("close",()=>t.V.socket.destroy()),t.ut={wt:e,K:n},Xt(t.ft,t.ut,t),Vt(t)}}function Gt(t){if(t.ot){if(t.nt){if(!t.yt&&t.ot.it.writable){const e=new at(t.ot.it);e.setHeader("connection","close"),e.writeHead(503)}}else{const e=t.ot.it;e.headersSent||(e.hasHeader("connection")||e.setHeader("connection","close"),e.writeHead(503))}t.ot.it.end(()=>t.V.socket.destroy())}else t.V.socket.destroy()}function Vt(t){if(clearTimeout(t.gt),!t.lt||t.st)return;const e=Date.now();if(e>=t.lt)return void Gt(t);let n=t.lt;t.dt&&!t.ut&&(e<t.dt.ht?n=t.dt.ht:(t.ut=t.dt,Xt(t.ft,t.ut,t))),void 0===t.gt&&t.et.push(()=>clearTimeout(t.gt)),t.gt=setTimeout(()=>Vt(t),Math.min(n-e,6048e5))}async function Xt(t,e,n){try{await(t?.(e.wt))}catch(t){e.K(t,"soft closing",n.V),Gt(n)}}const Zt=(t,e)=>{const n=jt(t);n.st?n.st(e):n.tt.push(e)},Yt=(t,e)=>{const n=jt(t);n.st?n.st(e):n.et.push(e)},Kt=t=>jt(t).Y.signal;class Qt extends Error{}const te=/*@__PURE__*/new Qt("STOP"),ee=/*@__PURE__*/new Qt("CONTINUE"),ne=/*@__PURE__*/new Qt("NEXT_ROUTE"),re=/*@__PURE__*/new Qt("NEXT_ROUTER");async function oe(t,e){const n=jt(t);if(!n.ot)throw new TypeError("cannot call acceptUpgrade from shouldUpgrade");if(!n.nt)throw new TypeError("not an upgrade request");if(3===n.yt)throw new TypeError("upgrade already delegated");if(2===n.yt)return n.bt;const r=n.ot.it;if(!r.readable||!r.writable)throw te;n.yt=1;const o=await e(t,r,n.ot.i);return n.ot.i=rt,n.vt=o.onError,o.softCloseHandler&&qt(n,o.softCloseHandler),n.yt=2,n.bt=o.return,o.return}function ie(t){const e=jt(t);if(!e.ot)throw new TypeError("cannot call delegateUpgrade from shouldUpgrade");if(!e.nt)throw new TypeError("not an upgrade request");if(e.yt)throw new TypeError("upgrade already handled");e.yt=3}const se=RegExp.escape??(t=>t.replaceAll(/[^a-zA-Z0-9_ ]/g,t=>"\\u"+t.charCodeAt(0).toString(16).padStart(4,"0"))),ae=t=>t&&Rt(t),ce=t=>void 0===t?void 0:""===t?[]:t.split("/").map(Rt),fe=t=>ce(t)?.filter(t=>t),ue=/*@__PURE__*/(t=>e=>{const n=[];let r=0;for(;r<e.length;++r){const o=t.get(e[r]);if(!o)break;n.push([o,!0])}return[Object.fromEntries(n),e.substring(r)]})(
2
- /*@__PURE__*/new Map([["i","Et"],["!","_t"],["%","St"]])),le=(t,e)=>{Object.prototype.hasOwnProperty.call(t,e)&&delete t[e]},he=Object.freeze({});function de(t,e,n){const r=t.V.url,o=t.Z,i=t.rt,s=t.$t??he;if(t.rt){const n=((t,e)=>{let n=0;for(;e>0;){const r=t.indexOf("%",n),o=r-n;if(-1===r||o>=e){n+=e;break}const i=Tt[t.charCodeAt(r+1)];n=r+(Ot[i-12]||3),e-=o+(2===i&&"5fF".includes(t[r+2])?3:15===i?2:1)}if(e<0||n>t.length)throw new RangeError;return n})(t.rt,t.Z.length-e.length),r=t.rt.substring(n);t.V.url=r+t.X.search,t.rt=r.includes("%")?r:void 0}else t.V.url=e+t.X.search;return t.Z=e,n.length>0&&(t.$t=Object.freeze(Object.fromEntries([...Object.entries(s),...n]))),()=>{t.V.url=r,t.Z=o,i&&(t.rt=i),t.$t=s}}function we(t){return It(t)?.$t??he}function pe(t,e){return n=we(t),r=e,Object.prototype.hasOwnProperty.call(n,r)?n[r]:void 0;var n,r}function me(t){const e=It(t);return e?e.X.pathname+e.X.search:t.url??"/"}function ye(t){const e=It(t);e&&(t.url=e.X.pathname+e.X.search)}const ge=t=>"function"==typeof t?{handleRequest:t}:t,be=(t,e)=>"function"==typeof t?{handleUpgrade:t,shouldUpgrade:e}:{shouldUpgrade:e,...t},ve=(t,e=Te)=>({handleRequest:t,handleUpgrade:t,shouldUpgrade:e}),Ee=t=>"function"==typeof t?{handleError:t}:t,_e=(t,e)=>Se(e=>e instanceof t,e),Se=(t,e)=>({handleError:(n,r,o)=>{if(o.response&&t(n))return e(n,r,o.response);throw n},shouldHandleError:(e,n,r)=>Boolean(r.response)&&t(e)}),$e=t=>"function"==typeof t?{handleRequest:t}:t,xe=t=>"function"==typeof t?{handleUpgrade:t}:t,Te=()=>!1,ke=Symbol("http");class Ne{constructor(){this.xt=[],this.Tt=[]}L(t,e,n,r,o){const i=n?((t,e)=>{const n=["^"],r=[],o=/[{}]|\/+|%|\\(.)|[:*]([a-zA-Z0-9_]*)/g,[{Et:i,_t:s,St:a},c]=ue(t);if("/"!==c[0])throw new TypeError("path must begin with '/' or flags");let f=0,u={kt:null,Nt:!1};const l=[u],h=t=>{null!==u.kt&&(u.kt+=t,u.Nt=!1),n.push(t)};let d=!1;const w=a?"/":"(?:/|%2[fF])",p=a?"[^/]":"(?:[^/%]|%25)";for(const t of c.matchAll(o)){t.index>f&&h(se(c.substring(f,t.index)));const e=t[0];if("{"===e)n.push("(?:"),u={...u},l.push(u);else if("}"===e){if(l.pop(),!l.length)throw new TypeError(`unbalanced optional braces in path at ${t.index}`);const e=u;if(u=l[l.length-1],null===u.kt?(u.kt=e.kt,u.Nt=e.Nt):null!==e.kt&&(u.kt=`(?:${u.kt}|${e.kt})`,u.Nt||=e.Nt),"(?:"===n[n.length-1])throw new Error(`empty optional section in path at ${t.index}`);n.push(")?")}else if("/"===e[0])u.kt=null,n.push(w),e.length>1?n.push(`{${e.length}${s?"":","}}`):s||n.push("+");else if("%"===e[0])h("%25");else if("\\"===e[0])h("%"===t[1]?"%25":se(t[1]));else{const o=e[0],i=t[2];if(!i)throw new TypeError(`unnamed parameter or unescaped '${o}' at ${t.index}`);if(null!==u.kt&&u.Nt)throw new TypeError(`path parameters must be separated by at least one character at ${t.index}`);if("*"===o){if(d)throw new TypeError("paths must not contain more than one multi-component path parameter");d=!0,null!==u.kt?n.push(`((?:(?!${u.kt})${p})*?(?:${w}.*?)?)`):n.push("(.*?)"),r.push({Rt:i,Ot:s?ce:fe})}else null!==u.kt?n.push(`((?:(?!${u.kt})${p})+?)`):n.push(`(${p}+?)`),r.push({Rt:i,Ot:ae});u.kt="",u.Nt=!0}f=t.index+e.length}if(f<c.length&&n.push(se(c.substring(f))),l.length>1)throw new TypeError("unbalanced optional braces in path");return e&&(n.push("(?:"),s?n.push(`(?:(?<=${w})|${w})`):n.push(`(?:${w}+|(?<=${w}))`),n.push("(?<rest>.*))?")),n.push("$"),{At:new RegExp(n.join(""),i?"i":""),Pt:r}})(n,r):{At:null,Pt:[]};if(o.some(t=>t instanceof Promise))throw new TypeError("expected handler, got Promise (did you forget to await?)");return this.xt.push({Ft:t,Ct:"string"==typeof e?e.toLowerCase():e,Mt:i.At,Ut:i.Pt,Dt:o}),this}use(...t){return this.L(null,null,null,!0,t.map($e))}mount(t,...e){return this.L(null,null,t,!0,e.map($e))}within(t){const e=new Ne;return this.mount(t,e),e}at(t,...e){return this.L(null,null,t,!1,e.map($e))}onRequest(t,e,...n){return this.L(Oe(t),ke,e,!1,n.map($e))}onUpgrade(t,e,n,...r){return this.L(Oe(t),e,n,!1,r.map(xe))}onError(...t){return this.L(null,null,null,!0,t.map(Ee))}onReturn(...t){return this.Tt.push(...t),this}get=(t,...e)=>this.L(Re,ke,t,!1,e.map($e));delete=(...t)=>this.onRequest("DELETE",...t);getOnly=(...t)=>this.onRequest("GET",...t);head=(...t)=>this.onRequest("HEAD",...t);options=(...t)=>this.onRequest("OPTIONS",...t);patch=(...t)=>this.onRequest("PATCH",...t);post=(...t)=>this.onRequest("POST",...t);put=(...t)=>this.onRequest("PUT",...t);ws=(...t)=>this.onUpgrade("GET","websocket",...t);async handleRequest(t){return this.Bt(t,new Ft)}async handleUpgrade(t){return this.Bt(t,new Ft)}async handleError(t,e){const n=new Ft;return n.L(t),this.Bt(e,n)}shouldUpgrade(t){return this.It(jt(t))}It(t){for(const e of this.xt){const n=Ae(t,e);if(!n)continue;let r=()=>{};if(!0!==n)try{r=de(t,n.Ht,[])}catch{continue}try{for(const n of e.Dt)if(Ce(n,t))return!0}finally{r()}}return!1}async Bt(t,e){const n=jt(t),r=await this.jt(n,e);if(e.J)throw e.W;return r}async jt(t,e){for(const n of this.xt){const r=Ae(t,n);if(!r)continue;let o=()=>{};if(!0!==r)try{const e=r.zt();o=de(t,r.Ht,e)}catch(t){e.L(t);continue}try{const r=await Pe(t,n.Dt,this.Tt,e);if(r===re)break;if(r===ne)continue;return r}finally{o()}}return ee}}const Re=new Set(["HEAD","GET"]),Oe=t=>t?"string"==typeof t?t:new Set(t):null;function Ae(t,e){if("string"==typeof e.Ft){if(e.Ft!==t.V.method)return!1}else if(null!==e.Ft&&!e.Ft.has(t.V.method??""))return!1;if(e.Ct===ke){if(t.nt)return!1}else if(null!==e.Ct&&!t.nt?.has(e.Ct))return!1;if(null===e.Mt)return!0;const n=e.Mt.exec(t.Z);return!!n&&{Ht:"/"+(n.groups?.rest??""),zt:()=>e.Ut.map((t,e)=>[t.Rt,t.Ot(n[e+1])])}}async function Pe(t,e,n,r){for(const o of e){let e=await Fe(o,t,r);if(e!==ee){if(!t.nt&&!(e instanceof Qt)&&n.length)try{const r="object"==typeof e?e:void 0,o=t.V,i=t.ot.it;for(const t of n)await t(r,o,i)}catch(t){r.L(t);continue}return e}}return ne}async function Fe(t,e,n){if(t instanceof Ne)return t.jt(e,n);let r=ee;try{if(n.J){if(t.handleError){const o=n.W,i=e.nt?{socket:e.ot.it,head:e.ot.i,hasUpgraded:Boolean(e.yt)}:{response:e.ot.it};t.shouldHandleError&&!t.shouldHandleError(o,e.V,i)||(n.G(),r=await t.handleError(o,e.V,i))}}else if(e.nt){if(t.handleUpgrade){const n=e.ot;r=await t.handleUpgrade(e.V,n.it,n.i)}}else t.handleRequest&&(r=await t.handleRequest(e.V,e.ot.it))}catch(t){t instanceof Qt?r=t:n.L(t)}finally{e.tt.length&&await((t,e)=>Dt(t.tt,e,t))(e,n)}return r===te?void 0:r}function Ce(t,e){if(t instanceof Ne)return t.It(e);if(!t.shouldUpgrade)return Boolean(t.handleUpgrade);try{return t.shouldUpgrade(e.V)}catch(t){return e.K(t,"checking should upgrade",e.V),!1}}const Me=(t,e,n)=>{const r=Ue(n);if(!r)return;const o=K(t,ht)??new ht(500);r.setHeader("content-type","text/plain; charset=utf-8"),r.setHeader("x-content-type-options","nosniff"),r.setHeaders(o.headers),r.setHeader("content-length",String(Buffer.byteLength(o.body,"utf-8"))),n.response||r.setHeader("connection","close"),r.writeHead(o.statusCode,o.statusMessage),r.end(o.body,"utf-8")};function Ue(t){if(t.response){const e=t.response;return e.headersSent?void e.end():e}const e=t.socket;if(!t.hasUpgraded&&e.writable)return e.addListener("finish",()=>e.destroy()),new at(e);e.destroy()}function De(t,{onError:e=Be,socketCloseTimeout:n=500}={}){V(n,"socketCloseTimeout");let r=0,o="",i=e;const s=[],a=new Set,c=()=>{const t=[...s];s.length=0;for(const e of t)e()},f=t=>{t&&(a.size?s.push(t):setImmediate(t))},u=t=>{a.add(t),t.et.push(()=>{a.delete(t),!a.size&&s.length&&setImmediate(c)})},l=async(n,s,a)=>{let c;try{c=Mt(n,e,!1)}catch(t){return e(t,"parsing request",n),void Me(new ht(400),0,{response:s})}if(Ut(c,!1,{it:s}),a&&(c.qt=!0),u(c),1===r)Wt(c,o,i);else if(2===r)return Gt(c),void Ht(n);const f=new Ft,l=await Fe(t,c,f);f.J||l!==ee&&l!==ne&&l!==re||f.L(new ht(404)),f.J&&(e(f.W,"handling request",n),Me(f.W,0,{response:s}),Ht(n))};return{request:(t,e)=>l(t,e,!1),checkContinue:(t,e)=>l(t,e,!0),upgrade:async(s,a,c)=>{let f;a.once("finish",()=>{const t=setTimeout(()=>a.destroy(),n);a.once("close",()=>clearTimeout(t))});try{f=Mt(s,e,!0)}catch(t){return e(t,"parsing upgrade",s),void Me(new ht(400),0,{socket:a,hasUpgraded:!1})}if(Ut(f,!0,{it:a,i:c}),c=rt,u(f),1===r)Wt(f,o,i);else if(2===r)return Gt(f),void Ht(s);const l=new Ft,h=await Fe(t,f,l);l.J||h!==ee&&h!==ne&&h!==re||(console.warn(`Upgrade ${s.headers.upgrade} request for ${s.url} fell-through. This probably means you need to add shouldUpgrade to one of your upgrade handlers, or if this is intentional, explicitly reject the request (throw new HTTPError(404)) instead of using CONTINUE.`),l.L(new ht(404))),l.J&&(e(l.W,"handling upgrade",s),f.vt?f.vt(l.W):Me(l.W,0,{socket:a,head:f.ot?.i??rt,hasUpgraded:Boolean(f.yt)}),Ht(s))},shouldUpgrade:n=>{try{const r=Mt(n,e,!0);return Ce(t,r)}catch{return!1}},clientError:(t,n)=>{const r=n.Jt,o=t.code;n.writable&&!r?.headersSent&&n.end(He.get(o)??je),n.destroy(t),("EPIPE"!==o||n.writable)&&("ECONNRESET"!==o||n.writable)&&"HPE_INVALID_EOF_STATE"!==o&&e(t,"initialising request",void 0)},softClose(t,e,n){if(r<1){r=1,o=t,i=e;for(const n of a)Wt(n,t,e)}f(n)},hardClose(t){if(r<2){r=2;for(const t of a)Gt(t)}f(t)},countConnections:()=>a.size}}const Be=(t,e,n)=>{(K(t,ht)?.statusCode??500)>=500&&console.error("%s",`unhandled error while ${e} ${n?.url??"(no request information)"}:`,t)},Ie=t=>Buffer.from(`HTTP/1.1 ${t} ${y[t]}\r\nConnection: close\r\n\r\n`),He=/*@__PURE__*/new Map([["HPE_HEADER_OVERFLOW",/*@__PURE__*/Ie(431)],["HPE_CHUNK_EXTENSIONS_OVERFLOW",/*@__PURE__*/Ie(413)],["ERR_HTTP_REQUEST_TIMEOUT",/*@__PURE__*/Ie(408)]]),je=/*@__PURE__*/Ie(400);class ze extends EventTarget{constructor(t){super(),this.Lt=t}attach(t,e={}){const n=(e,n,r)=>{const o={server:t,error:e,context:n,request:r};this.dispatchEvent(new CustomEvent("error",{detail:o,cancelable:!0}))&&Be(e,n,r)},r=De(this.Lt,{...e,onError:n});!1===e.autoContinue&&t.addListener("checkContinue",r.checkContinue),!1===e.rejectNonStandardExpect&&t.addListener("checkExpectation",r.request),t.addListener("request",r.request),t.addListener("upgrade",r.upgrade);const o=t.shouldUpgradeCallback??(()=>!1);!1!==e.overrideShouldUpgradeCallback&&(t.shouldUpgradeCallback=r.shouldUpgrade),t.addListener("clientError",r.clientError);let i=()=>{i=void 0,t.removeListener("checkContinue",r.checkContinue),t.removeListener("checkExpectation",r.request),t.removeListener("request",r.request),t.removeListener("upgrade",r.upgrade),t.shouldUpgradeCallback===r.shouldUpgrade&&(t.shouldUpgradeCallback=o),t.removeListener("clientError",r.clientError)};return(t="",e=-1,o=!1,s)=>{if(V(e,"existingConnectionTimeout",!0),o||i?.(),e>0){const o=setTimeout(()=>{i?.(),r.hardClose()},e);r.softClose(t,n,()=>{i?.(),clearTimeout(o),s?.()})}else 0===e?(i?.(),r.hardClose(s)):(i?.(),s&&setImmediate(s));return r}}createServer(t={}){t.shouldUpgradeCallback&&(t={overrideShouldUpgradeCallback:!1,...t});const e=g(t),n=this.attach(e,t),r=Object.assign(e,{closeWithTimeout:(t,r)=>new Promise(o=>n(t,r,!0,()=>{e.close(()=>o()),e.closeAllConnections()}))});return r}listen(t,e,n={}){const r=this.createServer(n);return n.socketTimeout&&r.setTimeout(n.socketTimeout),new Promise((o,i)=>{r.once("error",i),r.listen(t,e,n.backlog??511,()=>{r.off("error",i),o(r)})})}}const qe=t=>It(t)?.X??kt(t),Je=t=>qe(t).search,Le=t=>new URLSearchParams(qe(t).searchParams),We=(t,e)=>qe(t).searchParams.get(e);function Ge(t){const e=t.headers.authorization;if(!e)return;const[n,r]=ot(e," ");return void 0!==r?[n.trim().toLowerCase(),r.trim()]:void 0}function Ve(t){const e=/^text\/.*;\s*charset=([^;]+)/i.exec(t.headers["content-type"]??"");return e?.[1]?.trim().toLowerCase()??void 0}function Xe(t){const e=t.headers["if-range"];return e&&"string"==typeof e?/^("|W\/")/.test(e)?{etag:[e]}:{modifiedSeconds:en(e)}:{}}function Ze(t,e,{maxRanges:n=10,maxNonSequential:r=2,maxWithOverlap:o=2}={}){const i=t.headers.range;if(!i||0===e)return;const[s,a]=ot(i,"=");if("bytes"!==s||!a)return;const c=new ht(416,{headers:{"content-range":`bytes */${e}`}}),f=t=>{const e=Ke(t);if(void 0===e)throw c;return e},u=[];for(const t of a.split(",")){const[r,o]=ot(t.trim(),"-");if(void 0===o)throw c;let i;if(r)i={start:f(r),end:o?Math.min(f(o),e-1):e-1};else{if(!o)throw c;i={start:Math.max(e-f(o),0),end:e-1}}if(!(i.start>=e)){if(i.end<i.start||u.length>=n)throw c;u.push(i)}}if(!u.length)throw c;if(u.length>r)for(let t=0;t<u.length-1;++t)if(u[t].start>u[t+1].start)throw c;if(u.length>o)for(let t=1;t<u.length;++t){const e=u[t];for(let n=0;n<t;++n){const t=u[n];if(e.end>=t.start&&t.end>=e.start)throw c}}return{ranges:u,totalSize:e}}function Ye(t){if(void 0!==t)return"number"==typeof t?[String(t)]:t.length?"string"==typeof t?t.split(",").map(t=>t.trim()):t.flatMap(t=>t.split(",").map(t=>t.trim())):[]}function Ke(t){if(t&&/^\s*-?\d+\s*$/.test(t))return Number.parseInt(t,10)}const Qe=t=>Ye(t)?.map(t=>{const[e,...n]=t.split(";"),r=new Map(n.map(t=>{const[e,n]=ot(t,"=");return[e.trim(),n?.trim()??""]})),o=e.trim(),i="*/*"===o||"*"===o?0:o.endsWith("/*")?1:2,s=Math.max(0,Math.min(1,Number.parseFloat(r.get("q")??"1")));return{name:o,specifiers:r,specificity:i,q:s}});function tn(t){const e=new Map,n=/\s*([^=]+)=(?:([^";]*)|"((?:[^\\"]|\\.)*)"\s*)(?:;|$)/y;for(;n.lastIndex<t.length;){const r=n.exec(t);if(!r)throw new ht(400,{body:"invalid HTTP key values"});const o=r[1].toLowerCase();void 0!==r[3]?e.set(o,r[3].replaceAll(/\\(.)/g,"$1")):e.set(o,r[2].trim())}return e}function en(t){if("string"!=typeof t)return;const e=Date.parse(t);return Number.isNaN(e)?void 0:e/1e3|0}const nn=t=>"function"==typeof t?t:()=>t;class rn{constructor(t=cn){this.Wt=nn(t)}set(t,e){sn(jt(t)).set(this,e)}get(t){return an(t,this,this.Wt)}clear(t){const e=It(t);e?.Gt?.delete(this)}withValue(t){return ve(e=>(this.set(e,t),ee))}}const on=(t,...e)=>{const n=n=>t(n,...e);return t=>an(t,n,n)};function sn(t){return t.Gt||(t.Gt=new Map),t.Gt}function an(t,e,n){const r=It(t);if(!r)return n(t);const o=sn(r);if(o.has(e))return o.get(e);const i=n(t);return o.set(e,i),i}const cn=()=>{throw new Error("property has not been set")};function fn({realm:t,extractAndValidateToken:e,fallbackTokenFetcher:n,closeOnExpiry:r=!0,softCloseBufferTime:o=0,onSoftCloseError:i}){const s=nn(t);return{...ve(async t=>{const a=Date.now(),c=await s(t),f={"www-authenticate":`Bearer realm="${c}"`},u=Ge(t),l="bearer"===u?.[0]?u[1]:await(n?.(t));if(!l)throw new ht(401,{headers:f,body:"no token provided"});let h;try{h=await e(l,c,t)}catch(t){throw new ht(401,{headers:f,body:"invalid token",cause:t})}if(!h)throw new ht(401,{headers:f,body:"invalid token"});if("object"==typeof h){if("nbf"in h&&"number"==typeof h.nbf&&a<1e3*h.nbf)throw new ht(401,{headers:f,body:"token not valid yet"});if("exp"in h&&"number"==typeof h.exp){const e=1e3*h.exp;if(a>=e-o)throw new ht(401,{headers:f,body:"token expired"});r&&Lt(t,"token expired",e,o,i)}}return dn.set(t,{Vt:c,Xt:!0,Zt:h,Yt:wn(h)}),ee}),getTokenData:t=>{const e=dn.get(t);if(!e.Xt)throw new TypeError("cannot use getTokenData in an unauthenticated endpoint");return e.Zt}}}const un=(t,e)=>dn.get(t).Yt.has(e),ln=t=>new Set(dn.get(t).Yt),hn=t=>ve(e=>{const n=dn.get(e);if(!n.Yt.has(t))throw new ht(403,{headers:{"www-authenticate":`Bearer realm="${n.Vt}", scope="${t}"`},body:`scope required: ${t}`});return ee}),dn=/*@__PURE__*/new rn({Vt:"",Xt:!1,Zt:null,Yt:new Set});function wn(t){if(!t||"object"!=typeof t||!("scopes"in t))return new Set;const{scopes:e}=t;return Array.isArray(e)?new Set(e):"string"==typeof e?new Set([e]):e&&"object"==typeof e?new Set(Object.entries(e).filter(([t,e])=>e).map(([t])=>t)):new Set}function pn(t,e){const n=`${0|e.mtimeMs} ${e.size} ${t??""}`;return`W/"${x("sha256").update(n).digest("base64").substring(0,12)}"`}async function mn(t){const e=x("sha256");return"string"==typeof t?await k(_(t),e):await k(Y(t,{start:0,autoClose:!1}),e),`"sha256-${e.digest("base64")}"`}const yn=t=>{const e=x("sha256");return e.write(t),`"sha256-${e.digest("base64")}"`},gn={type:{Kt:"accept",Qt:"content-type"},language:{Kt:"accept-language",Qt:"content-language"},encoding:{Kt:"accept-encoding",Qt:"content-encoding"}},bn=/*@__PURE__*/new Map([["zstd","{file}.zst"],["br","{file}.br"],["gzip","{file}.gz"],["deflate","{file}.deflate"],["identity","{file}"]]),vn=t=>{return{feature:"encoding",options:(e=t,n=bn,Array.isArray(e)?e.map(t=>({value:t,file:n.get(t)})):Object.entries(e).map(([t,e])=>({value:t,file:e})))};var e,n};class En{constructor(t,{maxFailedAttempts:e=10}={}){this.te=t.map(t=>{if(!Object.prototype.hasOwnProperty.call(gn,t.feature))throw new RangeError(`unknown negotiation feature: ${t.feature}`);return{ee:t.feature,ne:et(t.match,!0),re:t.options.map(t=>({oe:t.file,ie:t.value,ne:et(t.for??t.value,!0)}))}}).filter(t=>t.re.length>0),this.se=e}*options(t,e){const n=this.te,r=new Set,o=this.se,i={},s=new Set;let a=!1;o>0&&(yield*function*c(f,u){const l=n[u];if(!l)return void(r.has(f)||(r.add(f),a&&(i.vary=[...s].join(", "),a=!1),yield{filename:f,headers:i}));if(!l.ne(t))return void(yield*c(f,u+1));const h=gn[l.ee];s.add(gn[l.ee].Kt),a=!0;const d=Qe(e[h.Kt])?.sort(_n);if(!d?.length)return void(yield*c(f,u+1));const w=new Set,p=[];for(const t of l.re){const e=d.find(e=>t.ne(e.name));e&&p.push({...e,ae:t})}for(const t of p.sort(_n)){const e=Sn(f,t.ae.oe);if(!w.has(e)&&(w.add(e),i[h.Qt]=t.ae.ie,yield*c(e,u+1),r.size>=o))return}delete i[h.Qt],!w.has(f)&&r.size<o&&(yield*c(f,u+1))}(t,0)),r.has(t)||(a&&(i.vary=[...s].join(", ")),yield{filename:t,headers:i})}}const _n=(t,e)=>e.q-t.q||e.specificity-t.specificity;function Sn(t,e){return e.replaceAll(/\{(?:file|base|ext)\}/g,e=>"{file}"===e?t:"{base}"===e?t.replace(/\.[^.]*$/,""):N(t))}const $n=/*@__PURE__*/Nn("bin=application/octet-stream;gz(ip),json,ogg,pdf,wasm,xml,y(a)ml,zip,zst(d)=application/{ext};webmanifest=application/manifest+json;aac,flac,mid(i),wav(e)=audio/{ext};mp3=audio/mpeg;oga,opus=audio/ogg;otf,ttf,woff,woff2=font/{ext};apng,avif,bmp,gif,heic,heif,jp(e)g,png,tif(f),webp=image/{ext};ico,cur=image/x-icon;svg=image/svg+xml;3mf,obj,stl,u3d=model/{ext};wrl=model/vrml;x3d=model/x3d+xml;x3db=model/x3d+binary;x3dv=model/x3d+vrml;css,csv,htm(l),rtf,vcard=text/{ext};(m)js=text/javascript;md=text/markdown;txt=text/plain;3gp(p),3g(pp)2,mp4,mp(e)g,h264=video/{ext};mov=video/quicktime;ogv=video/ogg");let xn=/*@__PURE__*/new Map($n);function Tn(){xn=new Map($n)}function kn(t){const e=new Map;for(const n of t.split("\n")){const[t,...r]=n.replaceAll(/\s+/g," ").trim().split(" ");if(!t.startsWith("#"))for(const n of r)e.set(n.toLowerCase(),t)}return e}function Nn(t){const e=new Map;for(const n of t.split(/[\n;]/g)){const[t,r,o]=/^ *([^ =]+)=(.*)$/.exec(n)??[null,null,""];for(const t of r?.split(",")??[]){const[n,r,i="",s=""]=/^([^(]*)(?:\(([^)]*)\)(.*))?$/.exec(t),a=r+i+s,c=o.replace("{ext}",a);e.set(a.toLowerCase(),c),i&&e.set((r+s).toLowerCase(),c)}}return e}function Rn(t){for(const[e,n]of t)xn.set(e.toLowerCase(),n)}function On(t,e="utf-8"){"."===t[0]&&(t=t.substring(1));const n=xn.get(t)??"application/octet-stream";return n.startsWith("text/")&&!n.includes("charset=")?`${n}; charset=${e}`:n}const An=/*@__PURE__*/new Map([["zstd",t=>U(C.zstdCompress)(t)],["br",t=>U(C.brotliCompress)(t,{params:{[C.constants.BROTLI_PARAM_QUALITY]:C.constants.BROTLI_MAX_QUALITY,[C.constants.BROTLI_PARAM_SIZE_HINT]:t.length}})],["gzip",t=>U(C.gzip)(t,{level:C.constants.Z_BEST_COMPRESSION})],["deflate",t=>U(C.deflate)(t)]]);async function Pn(t,e,n){const r=t.byteLength-n;if(r<=0)return;const o=An.get(e);if(!o)return;const i=await o(t);return i.byteLength<=r?i:void 0}const Fn=(t,e)=>!["image","video","audio","font"].includes(e.split("/")[0]);async function Cn(t,e,{minCompression:n=0,deleteObsolete:r=!1,matchModifiedTime:o=!0,filter:u=Fn}={}){const l=await i(t),h={file:t,mime:On(N(t)),rawSize:l.byteLength,bestSize:l.byteLength,created:0};if(!u(t,h.mime))return h;const d=await s(t);for(const i of e){const e=R(O(t),Sn(A(t),i.file));if(e===i.file)continue;const s=await Pn(l,i.value,n);s?(await a(e,s),o&&await c(e,d.atime,d.mtime),h.bestSize=Math.min(h.bestSize,s.byteLength),++h.created):r&&await f(e).catch(()=>{})}return h}async function Mn(t,e,n={}){const r=new Set,o=new X(t);for(const t of o)for(const e of await u(t,{withFileTypes:!0,encoding:"utf-8"}))e.isDirectory()?o.push(R(t,e.name)):e.isFile()&&r.add(R(t,e.name));for(const t of r)for(const n of e){const e=R(O(t),Sn(A(t),n.file));e!==t&&r.delete(e)}return Promise.all([...r].map(t=>Cn(t,e,n)))}const Un=(t,e,n)=>{const r=jt(t);r.K(e,n??(r.nt?"handling upgrade":"handling request"),t)},Dn=(t,{onlyIfRequested:e=!0,emitError:n=!0,forceStatus:r,contentType:o="application/json"}={})=>({handleError:(i,s,a)=>{if(a.hasUpgraded||e&&!Bn(s,o))throw i;n&&Un(s,i);const c=Ue(a);if(!c)return;const f=K(i,ht)??new ht(500),u=JSON.stringify(t(f));c.setHeaders(f.headers),c.setHeader("content-type",o),c.setHeader("x-content-type-options","nosniff"),c.setHeader("content-length",String(Buffer.byteLength(u,"utf-8"))),a.response||c.setHeader("connection","close"),r?c.writeHead(r):c.writeHead(f.statusCode,f.statusMessage),c.end(u,"utf-8")},shouldHandleError:(t,n,r)=>!r.hasUpgraded&&(!e||Bn(n,o))}),Bn=(t,e)=>Qe(t.headers.accept)?.some(t=>t.name===e||"application/json"===t.name)??!1;class In{constructor({subDirectories:t=!0,caseSensitive:e="exact",allowAllDotfiles:n=!1,allowAllTildefiles:r=!1,allowDirectIndexAccess:o=!1,allow:i=[".well-known"],hide:s=[],indexFiles:a=["index.htm","index.html"],implicitSuffixes:c=[],negotiator:f}){this.ce=!0===t?Number.POSITIVE_INFINITY:t||0,this.fe=e,this.ue=n,this.le=r,this.he=o,this.de=a,this.we=["",...c],this.pe=new Set(i.map(t=>this.me(t))),this.ye=et(s,!e),this.ge=new Set(a.map(t=>this.me(t))),this.be=f}me(t){return"exact"===this.fe?t:t.toLowerCase()}ve(t){const e=this.me(t);if(this.pe.has(e))return!0;const n=e.trim();return!(!("~"!==n[0]&&"~"!==n[n.length-1]||this.le)||"."===n[0]&&!this.ue||this.ye(n))}Ee(t){const e=t[t.length-1];return e&&this.ge.has(this.me(e))?t.slice(0,t.length-1):t}}const Hn=async(t,e={})=>new jn(await zn(t),new In(e));class jn{constructor(t,e){this._e=t,this.Se=e}get isStaticListing(){return!1}toNormalisedPath(t){return this.Se.Ee(t)}async find(t,e={},n){let r=t.join(P);if("force-lowercase"===this.Se.fe&&(r=r.toLowerCase()),/(^|[\\\/])\.\.($|[\\\/])|^[\\\/]/.test(r))return n?.push(`${JSON.stringify(r)} is not permitted`),null;let o=F(this._e,r);if(!o.startsWith(this._e)&&o+P!==this._e)return n?.push(`${JSON.stringify(o)} is not inside root ${JSON.stringify(this._e)}`),null;let i=null,a=null;for(const t of this.Se.we){const e=o+t;if(i=e.substring(this._e.length).split(P).filter(t=>t),i.length-1>this.Se.ce)return n?.push(`${JSON.stringify(o)} is nested too deeply (${i.length-1} > ${this.Se.ce})`),null;if(i.some(t=>!this.Se.ve(t)))return n?.push(`${JSON.stringify(o)} is not permitted`),null;const r=i[i.length-1]??"";if(!this.Se.he&&this.Se.ge.has(this.Se.me(r))&&!this.Se.pe.has(this.Se.me(r)))return n?.push(`${JSON.stringify(o)} is a hidden index file`),null;if(a=await l(e,{encoding:"utf-8"}).catch(()=>null),a){o=e;break}}if(!a||!i)return n?.push(`file ${JSON.stringify(o)} does not exist`),null;if(this.Se.me(a)!==this.Se.me(o))return n?.push(`realpath ${JSON.stringify(a)} does not match request ${JSON.stringify(o)}`),null;let c=a,f=await s(a).catch(()=>null);if(!f)return n?.push(`file ${JSON.stringify(a)} does not exist`),null;if(f.isDirectory()){if(i.length>this.Se.ce)return n?.push(`${JSON.stringify(a)} index file is nested too deeply (${i.length} > ${this.Se.ce})`),null;for(const t of this.Se.de){const e=R(a,t);if(f=await s(e).catch(()=>null),f?.isFile()){c=e;break}}}if(!f?.isFile())return n?.push(`${JSON.stringify(a)} exists but is not a file`),null;const u=A(c);if(!this.Se.be)return qn(c,{canonicalFilename:u,headers:{}},n);const h=O(c);for(const t of this.Se.be.options(u,e)){if(!t.filename||t.filename.includes(P))continue;const e=await qn(R(h,t.filename),{canonicalFilename:u,headers:t.headers},n);if(e)return e}return null}}const zn=async t=>await l(F(process.cwd(),t),{encoding:"utf-8"})+P;async function qn(t,e,n){const i=await o(t,r.O_RDONLY).catch(()=>null);if(!i)return n?.push(`failed to open ${JSON.stringify(t)}`),null;const s=()=>(i.close().catch(()=>{}),null),a=await i.stat().catch(s);return a?.isFile()?{handle:i,stats:a,filesystemPath:t,...e}:(n?.push(`${JSON.stringify(t)} exists but is not a file`),s())}async function Jn(t,e={}){const n=await zn(t),r=new In(e),o=new Ln(r,qn),i=new X([]);for(const t of i){const e=await u(R(n,...t),{withFileTypes:!0,encoding:"utf-8"}),s=new Map(e.map(e=>[r.me(e.name),R(n,...t,e.name)]));for(const a of e)if(r.ve(a.name))if(a.isDirectory()){const e=[...t,a.name];o.$e(e),t.length<r.ce&&i.push(e)}else a.isFile()&&o.xe(t,a.name,R(n,...t,a.name),s)}return o}class Ln{get isStaticListing(){return!0}constructor(t,e){this.Te=new Map,this.Se=t,this.ke=e}Ne(t,e){const n=this.Te.get(t);(!n||e.p>n.p)&&this.Te.set(t,e)}xe(t,e,n,r){const o=this.Se.me(e),i={data:n,basename:o,siblings:r},s=this.Se.de.indexOf(o);if(-1!==s&&(this.Ne(this.Se.me(t.join("/")),{...i,p:this.Se.de.length+1-s}),!this.Se.he&&!this.Se.pe.has(o)))return;const a=this.Se.me([...t,e].join("/"));for(let t=0;t<this.Se.we.length;++t){const n=this.Se.we[t];e.endsWith(n)&&this.Ne(a.substring(0,a.length-n.length),{...i,p:-t})}}$e(t){this.Ne(this.Se.me(t.join("/")),Wn)}toNormalisedPath(t){return this.Se.Ee(t)}async find(t,e={},n){const r=this.Te.get(this.Se.me(t.join("/")));if(!r||void 0===r.data)return n?.push(`${JSON.stringify(t.join("/"))} not found in static file paths`),null;if(!this.Se.be)return this.ke(r.data,{canonicalFilename:r.basename,headers:{}},n);for(const t of this.Se.be.options(r.basename,e)){const e=r.siblings.get(this.Se.me(t.filename));if(void 0===e)continue;const o=await this.ke(e,{canonicalFilename:r.basename,headers:t.headers},n);if(o)return o}return null}staticPaths(){return new Set([...this.Te].filter(([t,e])=>e.basename).map(([t])=>t))}}const Wn={data:void 0,basename:"",siblings:new Map,p:1};function Gn(t,e={}){const n=new In(e),r=new Ln(n,async(t,e)=>({handle:await t.open(),stats:t.stat(),filesystemPath:t.filesystemPath,...e})),o=new X({dir:t,path:[]});for(const{dir:t,path:e}of o){const i=new Map([...t.children.entries()].filter(([t,e])=>!e.isDirectory).map(([t,e])=>[n.me(t),e]));for(const[s,a]of t.children)if(!a.virtual&&n.ve(s))if(a.isDirectory){const t=[...e,s];r.$e(t),e.length<n.ce&&o.push({dir:a,path:t})}else r.xe(e,s,a,i)}return r}const Vn=/*@__PURE__*/on(async t=>{const e=Kt(t);if(e.aborted)throw te;e.throwIfAborted();const n=await h(R(D(),"upload"));Yt(t,()=>f(n,{recursive:!0}));let r=0;const o=()=>{if(e.aborted)throw te;return R(n,(++r).toString(10).padStart(6,"0"))};return{dir:n,nextFile:o,save:async(t,{mode:n=384}={})=>{const r=o(),i=S(r,{mode:n});try{return await k(t,i,{signal:e}),{path:r,size:i.bytesWritten}}finally{i.close()}}}});class Xn extends Error{constructor(t,e){super(`${t} is not a valid zip archive: ${e}`)}}async function Zn(t){const e=new nt(t,r.O_RDONLY),n=await e.open();try{const r=(await n.stat()).size,o=Math.max(r-65535-22-20,0);let i;const s=async(e,s)=>{if(e<0||e>r||e+s>r)throw new Xn(t,`byte range ${e}-${e+s} is not within 0-${r}`);if(e>=o&&i)return new Uint8Array(i.buffer,i.byteOffset+e-o,s);const a=new Uint8Array(s),{bytesRead:c}=await n.read(a,0,s,e);if(c!==s)throw new Xn(t,"modified while reading");return a};i=await s(o,r-o);const a=i.byteLength,c=Math.min(65535,a-22);let f=-1;for(let t=0;t<c;++t)if(er(i,a-t-2)===t&&1347093766===sr(i,a-t-22)){f=t;break}if(-1===f)throw new Xn(t,"no EOCD found");const u=r-f-22,l=or(i,u-o,22);let h=er(l,10),d=nr(l,12),w=nr(l,16);if((65535===h||4294967295===d||4294967295===w)&&u>=o+20){const e=or(i,u-o-20,20);if(1347094023!==sr(e,0))throw new Xn(t,"missing EOCDL in 64-bit zip");const n=rr(e,8),r=await s(n,56);if(1347094022!==sr(r,0))throw new Xn(t,"EOCD64 is invalid");h=rr(r,32),d=rr(r,40),w=rr(r,48)}const p=new Yn(t,[]),m=await s(w,d);let y=0;for(let n=0;n<h;++n){if(1347092738!==sr(m,y))throw new Xn(t,`missing CDFH for record #${n+1} at 0x${y.toString(16)}`);const o=er(m,y+8),i=Boolean(1024&o),a=er(m,y+10);if(0!==a&&8!==a)throw new Xn(t,`unsupported compression type: ${a}`);let c=tr(er(m,y+12),er(m,y+14));const f=nr(m,y+16);let u=nr(m,y+20),l=nr(m,y+24);const h=er(m,y+28),d=er(m,y+30),w=er(m,y+32);let g=nr(m,y+42);const b=or(m,y+46,h);let v=i?ir(b):[...b].map(t=>Qn[t]).join("");const E=or(m,y+46+h,d);y+=46+h+d+w;for(let t=0;t<d;){const e=er(E,t+2),n=or(E,t+4,e);switch(er(E,t)){case 1:{let t=0;4294967295===l&&(l=rr(n,t),t+=8),4294967295===u&&(u=rr(n,t),t+=8),4294967295===g&&(g=rr(n,t),t+=8);break}case 21589:1&n[0]&&(c=1e3*nr(n,1));break;case 28789:v=ir(or(n,5,n.byteLength-5))}t+=e+4}if(v.startsWith("__MACOSX/"))continue;const _=v.split("/");if(!_[_.length-1]){p.Re(new Yn(t,_.slice(0,_.length-1)));continue}const S=await s(g,30);if(1347093252!==sr(S,0))throw new Xn(t,`invalid local header for ${v}`);const $=30+er(S,26)+er(S,28);if(g<0||g+$+u>r)throw new Xn(t,`invalid location for ${v}`);const x={Oe:g+$,Ae:u,Pe:l,Fe:c,Ce:f};if(8===a){p.Re(new Kn(e,_,x,!0,!1));const t=[..._];t[t.length-1]+=".deflate",p.Re(new Kn(e,t,x,!1,!0))}else p.Re(new Kn(e,_,x,!1,!1))}return p}finally{await n.close()}}class Yn{constructor(t,e){this.zipFilePath=t,this.k=e,this.children=new Map}get isDirectory(){return!0}get virtual(){return!1}get filesystemPath(){return R(this.zipFilePath,...this.k)}Re(t){const e=t.k;let n=this;for(let r=0;r<e.length-1;++r){const o=e[r];let i=n.children.get(o);if(!i||i.virtual)i=new Yn(this.zipFilePath,e.slice(0,r+1)),n.children.set(o,i);else if(!i.isDirectory){if(t.virtual)return;throw new Xn(this.zipFilePath,`mix of file and directory at ${e.join("/")}`)}n=i}const r=e[e.length-1],o=n.children.get(r);if(o&&!o.virtual){if(t.virtual)return;throw o.isDirectory!==t.isDirectory?new Xn(this.zipFilePath,`mix of file and directory at ${e.join("/")}`):new Xn(this.zipFilePath,`duplicate file/directory at ${e.join("/")}`)}n.children.set(r,t)}*allFiles(t=[]){for(const[e,n]of this.children)n.isDirectory?yield*n.allFiles([...t,e]):yield{path:[...t,e],node:n}}find(t){let e=this;for(const n of t){if(!e.isDirectory)return;const t=e.children.get(n);if(!t)return;e=t}return e}}class Kn{constructor(t,e,n,r,o){this.k=e,this.Me=t,this.Ue=n,this.De=r,this.virtual=o}get isDirectory(){return!1}get zipFilePath(){return this.Me.path}meta(){return{p:this.Ue.Oe,z:this.De,s:this.Ue.Ae}}get filesystemPath(){return R(this.Me.path,...this.k)}get crc32(){return this.Ue.Ce}stat({bigint:t=!1}={}){const e=e=>t?BigInt(e):e,n={isFile:()=>!0,mode:e(33060),size:e(this.De?this.Ue.Pe:this.Ue.Ae),mtimeMs:e(this.Ue.Fe),mtime:new Date(this.Ue.Fe)};return new Proxy({},{get:(t,r)=>n[r]??("string"!=typeof r?void 0:r.startsWith("is")?()=>!1:r.endsWith("time")?new Date(0):r.endsWith("Instant")?void 0:e(0))})}async open(){const t=this.Ue.Ae,e=t=>Promise.resolve(this.stat(t));if(!t)return{noRandomAccess:this.De,createReadStream:({encoding:t,start:e=0,end:n,...r}={})=>{if(0!==e)throw new RangeError(`invalid byte range ${e}-${n}`);return Object.assign(I.from([],{...r,encoding:t??void 0,objectMode:!1}),{close:()=>{}})},stat:e,close:()=>Promise.resolve(),[Symbol.asyncDispose]:()=>Promise.resolve()};const n=await this.Me.open();return{noRandomAccess:this.De,createReadStream:({encoding:e,start:r=0,end:o=t-1,highWaterMark:i,...s}={})=>{if(this.De){if(0!==r)throw new RangeError("start offset must be 0 for compressed files");o=t-1}else if(r<0||o<r||o>=t)throw new RangeError(`invalid byte range ${r}-${o}`);let a=Y(n,{start:this.Ue.Oe+r,end:this.Ue.Oe+o,highWaterMark:this.De?void 0:i,...s});return this.De&&(a=a.pipe(M({chunkSize:i}))),e&&a.setEncoding(e),a},stat:e,close:n.close,[Symbol.asyncDispose]:n.close}}}const Qn="\0\u263a\u263b\u2665\u2666\u2663\u2660\u2022\u25d8\u25cb\u25d9\u2642\u2640\u266a\u266b\u263c\u25ba\u25c4\u2195\u203c\xb6\xa7\u25ac\u21a8\u2191\u2193\u2192\u2190\u221f\u2194\u25b2\u25bc !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u2302\xc7\xfc\xe9\xe2\xe4\xe0\xe5\xe7\xea\xeb\xe8\xef\xee\xec\xc4\xc5\xc9\xe6\xc6\xf4\xf6\xf2\xfb\xf9\xff\xd6\xdc\xa2\xa3\xa5\u20a7\u0192\xe1\xed\xf3\xfa\xf1\xd1\xaa\xba\xbf\u2310\xac\xbd\xbc\xa1\xab\xbb\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255d\u255c\u255b\u2510\u2514\u2534\u252c\u251c\u2500\u253c\u255e\u255f\u255a\u2554\u2569\u2566\u2560\u2550\u256c\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256b\u256a\u2518\u250c\u2588\u2584\u258c\u2590\u2580\u03b1\xdf\u0393\u03c0\u03a3\u03c3\xb5\u03c4\u03a6\u0398\u03a9\u03b4\u221e\u03c6\u03b5\u2229\u2261\xb1\u2265\u2264\u2320\u2321\xf7\u2248\xb0\u2219\xb7\u221a\u207f\xb2\u25a0\xa0",tr=(t,e)=>Date.UTC(1980+(e>>>9&127),(e>>>5&15)-1,e>>>0&31,t>>>11&31,t>>>5&63,(t>>>0&31)<<1,0),er=(t,e)=>t[e+1]<<8|t[e],nr=(t,e)=>(t[e+3]<<24|t[e+2]<<16|t[e+1]<<8|t[e])>>>0,rr=(t,e)=>(t=>{if(t>Number.MAX_SAFE_INTEGER||t<Number.MIN_SAFE_INTEGER)throw new RangeError(`unsupported size (limited to ${Number.MAX_SAFE_INTEGER})`);return Number(t)})(BigInt(nr(t,e+4))<<32n|BigInt(nr(t,e))),or=(t,e,n)=>new Uint8Array(t.buffer,t.byteOffset+e,n),ir=t=>new TextDecoder("utf-8").decode(t),sr=(t,e)=>(t[e]<<24|t[e+1]<<16|t[e+2]<<8|t[e+3])>>>0,ar=(t,e)=>e instanceof Error&&"ERR_STREAM_PREMATURE_CLOSE"===e.code&&t.closed;function cr(t){const e=jt(t);if(!e.ot)throw new TypeError("cannot call acceptBody from shouldUpgrade");if(e.Y.signal.aborted)throw te;e.qt&&(e.qt=!1,e.ot.it.writeContinue())}function fr(t){const e=jt(t);return!e.Y.signal.aborted&&!e.qt}function ur(t,{blockRequestHeaders:e=[],requestHeaders:n=[],blockResponseHeaders:r=[],responseHeaders:o=[],agent:i,...s}={}){const a=new URL(t);let c;"https:"===a.protocol?(i??=new j({keepAlive:!0,...s}),c=v):(i??=new b({keepAlive:!0,...s}),c=z);const f=a.pathname,u=f+(f.endsWith("/")?"":"/"),l="a://a"+u;return ge((t,s)=>new Promise((h,d)=>{if(s.closed||!s.writable)return d(te);const w=Kt(t),p=t=>d(w.aborted?te:new ht(502,{cause:t})),m=new URL(l+t.url?.substring(1));if(!m.pathname.startsWith(u)&&m.pathname!==f)return d(new ht(400,{message:"directory traversal blocked"}));cr(t);let y={...t.headers};lr(y,e),delete y.host,y.expect&&hr.test(y.expect)&&delete y.expect;for(const e of n)y=e(t,y);const g=c(a,{agent:i,path:m.pathname+m.search,method:t.method,headers:y,signal:w});g.once("error",p),g.once("response",e=>{if(s.closed||!s.writable)return d(te);if(!s.headersSent){let n={...e.headers};lr(n,r);for(const r of o)n=r(t,e,n);s.writeHead(e.statusCode??200,e.statusMessage,n)}k(e,s).then(h,t=>d(ar(s,t)?te:t))}),k(t,g).catch(p)}))}function lr(t,e){for(const e of Ye(t.connection)??[])le(t,e.toLowerCase());for(const e of dr)le(t,e);for(const n of e)le(t,n)}const hr=/(?:^|\W)100-continue(?:$|\W)/i,dr=["connection","keep-alive","proxy-authenticate","proxy-authorization","te","trailer","transfer-encoding","upgrade"];function wr({trustedProxyCount:t,trustedProxyAddresses:e,trustedHeaders:n}){const r=e?J(e):()=>!0,o=t??(e?Number.POSITIVE_INFINITY:0),i=new Set(n);return on(t=>{const e=e=>{if(i.has(e))return Ye(t.headers[e])?.reverse()},n=e("forwarded"),s=e("x-forwarded-for"),a=e("x-forwarded-host"),c=e("x-forwarded-proto"),f=e("x-forwarded-protocol"),u=e("x-url-scheme"),l=e("via")?.map(t=>{const e=/^([^/ ]+\/)?([^/ ]+) (.+)$/.exec(t);return e?.[3]?q(e[3]):void 0}),h=[pr(t)];if(n)for(const t of n)try{const e=tn(t);h.push({client:q(e.get("for")),server:q(e.get("by")),host:e.get("host"),proto:e.get("proto")})}catch{h.push({client:void 0,server:void 0,host:void 0,proto:void 0})}else if(s){const t=s.map(q),e=a??[],n=c??f??u??[];let r=h[0].client;for(let o=0;o<t.length;++o){const i=t[o];h.push({client:i,server:l?.[o]??(r?{...r,port:void 0}:void 0),host:e[o],proto:n[o]}),r=i}}else if(l)for(const t of l)h.push({client:void 0,server:t,host:void 0,proto:void 0});let d=Math.min(1+o,h.length);for(let t=0;t<d-1;++t)r(h[t].client)||(d=t+1);return Object.freeze({trusted:h.slice(0,d),untrusted:h.slice(d),outwardChain:h,edge:h[d-1]})})}const pr=t=>({client:{...q(t.socket.remoteAddress)??mr,port:t.socket.remotePort},server:{...q(t.socket.localAddress)??mr,port:t.socket.localPort},host:t.headers.host,proto:t.socket.encrypted?"https":"http"}),mr={family:"alias",address:"_disconnected",port:void 0};function yr(t,e){return delete e.forwarded,delete e["x-forwarded-for"],delete e["x-forwarded-host"],delete e["x-forwarded-proto"],delete e["x-forwarded-protocol"],delete e["x-url-scheme"],delete e.via,e}function gr(t,e){const n=yr(0,e);return n.forwarded=Er([pr(t)]),n}const br=(t,{onlyTrusted:e=!1}={})=>(n,r)=>{const o=yr(0,r),i=t(n);return o.forwarded=Er([...e?i.trusted:i.outwardChain].reverse()),o};function vr(t,e){let n=t.headers.forwarded;const r=Er([pr(t)]);n?n+=", "+r:n=r;const o=yr(0,e);return o.forwarded=n,o}function Er(t){return t.filter(t=>t.server||t.client).map(t=>Object.entries({for:t.client?.address,by:t.server?.address,host:t.host,proto:t.proto}).filter(([t,e])=>e).map(([t,e])=>e&&/[^a-zA-Z0-9._]/.test(e)?`${t}="${e.replaceAll("\\","\\\\").replaceAll('"','\\"').replaceAll(",","-")}"`:`${t}=${e}`).join("; ")).join(", ")}function _r(t,e,n){const r=en(t.headers["if-modified-since"]),o=Ye(t.headers["if-none-match"]);if(o){if($r(e,n,o))return!1}else if(n&&r&&(n.mtimeMs/1e3|0)<=r)return!1;return!0}function Sr(t,e,n){let r=!0;const o=Xe(t);return o.etag&&(r&&=$r(e,n,o.etag)),o.modifiedSeconds&&(r&&=(n.mtimeMs/1e3|0)===o.modifiedSeconds),r}function $r(t,e,n){if(n.includes("*"))return!0;const r=t.getHeader("etag");if("string"==typeof r){if(n.includes(r))return!0;if(r.startsWith('W/"'))return!1}return!(!e||!n.some(t=>t.startsWith('W/"')))&&n.includes(pn(t.getHeader("content-encoding"),e))}class xr extends d{constructor(t,e){super({transform(r,o){n+=r.byteLength,n>t?o.error(e):o.enqueue(r)}});let n=0}}function Tr(t,{maxContentBytes:e=Number.POSITIVE_INFINITY,maxNetworkBytes:n=e,maxEncodingSteps:r=1}={}){const o=Ke(t.headers["content-length"]);if(void 0!==o&&o>n)throw new ht(413);const i=Ye(t.headers["content-encoding"])??[];if(i.length>r)throw new ht(415,{body:"too many content-encoding stages"});cr(t);let s=I.toWeb(t);void 0===o&&Number.isFinite(n)&&(s=s.pipeThrough(new xr(n,new ht(413))));for(const t of i.reverse())s=s.pipeThrough(Or(t));return Number.isFinite(e)&&(s=s.pipeThrough(new xr(e,new ht(413,{body:"decoded content too large"})))),s}function kr(t,e={}){const n=Tr(t,e),r=Ve(t)??e.defaultCharset??"utf-8";return n.pipeThrough(gt(r,e))}async function Nr(t,e={}){let n="";for await(const r of kr(t,e))n+=r;return n}async function Rr(t,e={}){const n=await(async(t,e)=>{const n=t.getReader(),r=new Uint8Array(4);r[0]=1;let o=0,i=null;for(;;){const t=await n.read(),e=4-o;if(t.done){o<3&&(o<2&&(r[1]=r[0]),r[2]=r[0]),r[3]=r[1],i=null;break}if(i=t.value,i.byteLength>=e){r.set(i.subarray(0,e),o);break}r.set(i,o),o+=i.byteLength}const s=bt[(r[0]?8:0)|(r[1]?4:0)|(r[2]?2:0)|(r[3]?1:0)];if(!s)throw n.cancel(),new ht(415,{body:"invalid JSON encoding"});const a=gt(s,e),c=a.writable.getWriter();return o&&c.write(r.subarray(0,o)),i&&c.write(i),n.releaseLock(),c.releaseLock(),t.pipeThrough(a)})(Tr(t,e),e);let r="";for await(const t of n)r+=t;try{return JSON.parse(r,e.reviver)}catch(t){throw new ht(400,{body:"invalid JSON",cause:t})}}function Or(t){switch(t.toLowerCase()){case"gzip":case"x-gzip":return new p("gzip");case"deflate":return new p("deflate");case"br":try{return new p("brotli")}catch{return H.toWeb(C.createBrotliDecompress())}case"zstd":try{return H.toWeb(C.createZstdDecompress())}catch{throw new ht(415,{body:"unsupported content encoding"})}default:throw new ht(415,{body:"unknown content encoding"})}}class Ar{constructor(t,e,n){const r=t.byteLength;if(!r||r>65535)throw new RangeError("invalid needle");this.Be=t,this.Ie=e,this.He=n,this.je=null,this.ze=0,this.qe=null}push(t){let e=0;const n=t.byteLength,r=this.Be,o=r.byteLength-1,i=n-o;let s=-this.ze;if(this.ze){const a=this.qe,c=this.je,f=r[o];if(s<i){const n=t[s+o];n!==f||t.compare(r,-s,o,0,s+o)?s+=a[n]:(this.He(),this.ze=0,e=s+=o+1)}const u=i<0?i:0;for(;s<u;){const n=t[s+o];if(n===f&&!c.compare(r,0,-s,this.ze+s,this.ze)&&!t.compare(r,-s,o,0,s+o)){this.Ie(c,0,this.ze+s,!1),this.He(),this.ze=0,e=s+=o+1;break}s+=a[n]}const l=this.ze;if(l>0){const e=r[0];for(;s<0;){const o=c.subarray(0,l).indexOf(e,l+s);if(-1===o){s=0;break}const i=l-o;if(!c.compare(r,1,i,o+1,l)&&!t.compare(r,i,i+n))return o&&(this.Ie(c,0,o,!1),c.copy(c,0,o,i)),c.set(t,i),void(this.ze+=n-o);s=o+1-l}this.Ie(c,0,l,!1),this.ze=0}}for(;s<i;){const n=t.indexOf(r,s);if(-1!==n){if(n>e&&this.Ie(t,e,n,!0),this.He(),n===i+1)return;e=s=n+o+1}else s=i}const a=r[0];for(;s<n;){const i=t.indexOf(a,s);if(-1===i)return void this.Ie(t,e,n,!0);if(!t.compare(r,1,n-i,i+1)){if(!this.je){this.je=Buffer.allocUnsafe(o),this.qe=new Uint16Array(256).fill(o+1);for(let t=0;t<o;++t)this.qe[r[t]]=o-t}return t.copy(this.je,0,i),this.ze=n-i,void(i>e&&this.Ie(t,e,i,!0))}s=i+1}n>e&&this.Ie(t,e,n,!0)}destroy(){const t=this.ze;t&&this.je&&this.Ie(this.je,0,t,!1),this.ze=0}}class Pr{constructor(t){this.Ie=t,this.reset()}reset(){this.H=[],this.Je=16384,this.m=0,this.Le="",this.We=void 0}push(t,e,n){let r=e,o=e;const i=Math.min(n,e+this.Je);for(;o<i;)switch(this.m){case 0:for(;o<i&&_t[t[o]];++o);if(o>r&&(this.Le+=t.latin1Slice(r,o)),o<i){if(58!==t[o])return-1;if(!this.Le)return-1;++o,this.We=Ur.get(this.Le.toLowerCase()),this.Le="",this.m=1}break;case 1:for(;o<i;++o){const e=t[o];if(32!==e&&9!==e){r=o,this.m=2;break}}break;case 2:for(;o<i;++o){const e=t[o];if(e<32||127===e){if(13!==e)return-1;this.m=3;break}}this.We&&(this.Le+=t.latin1Slice(r,o)),++o;break;case 3:if(10!==t[o++])return-1;this.m=4;break;case 4:{const e=t[o];if(32===e||9===e)r=o,this.m=2;else{if(this.We){const t=this.We.Ge;void 0===this.H[t]?this.H[t]=this.Le:this.We.Ve&&(this.H[t]+=","+this.Le)}13===e?(this.m=5,++o):(r=o,this.m=0,this.Le="",this.We=void 0)}break}case 5:{if(10!==t[o++])return-1;const e=this.H;return this.reset(),this.Ie(e),o}}return i<n?-1:(this.Je-=i-e,i)}}const Fr=0,Cr=1,Mr=2,Ur=new Map([["content-type",{Ge:Fr,Ve:!1}],["content-disposition",{Ge:Cr,Ve:!1}],["content-transfer-encoding",{Ge:Mr,Ve:!0}]]);function Dr(t){const e=this.Xe;e&&(this.Xe=void 0,e())}const Br=/*@__PURE__*/Buffer.from("\r\n"),Ir=()=>{},Hr=37,jr=43,zr=/*@__PURE__*/new Uint8Array(256);function qr(t,e={}){const n=t["content-type"];if(!n)throw new ht(400,{body:"missing content-type"});const r=vt(n);if(!r)throw new ht(400,{body:"malformed content-type"});const o=Ke(t["content-length"]);if(void 0!==o&&void 0!==e.maxNetworkBytes&&o>e.maxNetworkBytes)throw new ht(413,{body:"content too large"});if("application/x-www-form-urlencoded"===r.mime)return(({defCharset:t="utf-8",maxNetworkBytes:e=Number.POSITIVE_INFINITY,maxContentBytes:n=e,maxFieldSize:r=1048576,maxFieldNameSize:o=100,maxFields:i=Number.POSITIVE_INFINITY},s)=>{const a=s.get("charset")??t,c=/^utf-?8$/i.test(a)?1:/^(latin-?1|iso[\-_]?8859-?1|(us-)?ascii)$/i.test(a)?2:0,f=yt(a);return(t,s)=>new Promise((u,l)=>{let h=e,d=n,w=i,p=!0,m="",y=Math.min(o,d),g=0,b="",v=-2;const E=()=>{const t=!c||1===c&&8&g?f.decode(Buffer.from(m,"latin1")):m;if(p){if(y<0)return $(new ht(413,{body:`field name ${JSON.stringify(t)}... too long`})),!1;t&&s({name:t,type:"string",value:"",encoding:a,mimeType:"text/plain"})}else{if(y<0)return $(new ht(413,{body:`value for ${JSON.stringify(b)} too long`})),!1;s({name:b,type:"string",value:t,encoding:a,mimeType:"text/plain"})}return!0},_=t=>{if(!t.byteLength)return;if((h-=t.byteLength)<0)return $(new ht(413,{body:"content too large"}));if(!w)return $(new ht(413,{body:"too many fields"}));const e=t.byteLength;let n=0,i=v;if(-2!==i){if(-1===i){if(16===(i=Tt[t[n++]]))return $(new ht(400,{body:"malformed urlencoded form"}));if(g|=i,n===e)return void(v=i)}const r=Tt[t[n++]];if(16===r)return $(new ht(400,{body:"malformed urlencoded form"}));if(m+=String.fromCharCode((i<<4)+r),v=-2,n===e)return}for(zr[37]=1,zr[38]=1,zr[43]=1,zr[61]=p?1:0;;){const i=n;for(;n<e&&!zr[t[n]];++n);if(n>i&&y>=0&&((y-=n-i)<0?m+=t.latin1Slice(i,n+y):(d-=n-i,m+=t.latin1Slice(i,n))),n===e)return;switch(t[n++]){case Hr:for(;;){if(--y<0){zr[37]=0,zr[43]=0;break}if(--d,n===e){v=-1;break}const r=Tt[t[n++]];if(16===r)return $(new ht(400,{body:"malformed urlencoded form"}));if(g|=r,n===e)return void(v=r);const o=Tt[t[n++]];if(16===o)return $(new ht(400,{body:"malformed urlencoded form"}));if(m+=String.fromCharCode((r<<4)+o),n===e)return;if(t[n]!==Hr)break;n++}break;case 38:if(!E())return;if(b="",p=!0,zr[61]=1,zr[37]=1,zr[43]=1,m="",y=Math.min(o,d),g=0,! --w)return $(new ht(413,{body:"too many fields"}));break;case jr:--y<0?(zr[37]=0,zr[43]=0):(--d,m+=" ");break;case 61:if(b=!c||1===c&&8&g?f.decode(Buffer.from(m,"latin1")):m,y<0)return $(new ht(413,{body:`field name ${JSON.stringify(b)}... too long`}));p=!1,zr[61]=0,zr[37]=1,zr[43]=1,m="",g=0,y=Math.min(r,d)}if(n===e)return}},S=()=>{if(-2!==v)return $(new ht(400,{body:"malformed urlencoded form"}));E()&&(t.off("data",_),t.off("end",S),t.off("error",$),u())},$=e=>{t.off("data",_),t.off("end",S),t.off("error",$),l(e)};t.on("data",_),t.once("end",S),t.once("error",$)})})(e,r.params);if("multipart/form-data"===r.mime&&!e.blockMultipart)return function({preservePath:t,fileHwm:e,defParamCharset:n="utf-8",defCharset:r="utf-8",maxNetworkBytes:o=Number.POSITIVE_INFINITY,maxContentBytes:i=o,maxFieldSize:s=1048576,maxFileSize:a=Number.POSITIVE_INFINITY,maxTotalFileSize:c=Number.POSITIVE_INFINITY,maxFieldNameSize:f=100,maxParts:u=Number.POSITIVE_INFINITY,maxFields:l=Number.POSITIVE_INFINITY,maxFiles:h=Number.POSITIVE_INFINITY},d){const w=d.get("boundary");if(!w)throw new ht(400,{body:"multipart boundary not found"});if(w.length>70)throw new ht(400,{body:"multipart boundary too long"});const p=yt(n),m={autoDestroy:!0,emitClose:!0,highWaterMark:e,read:Dr};return(e,n)=>new Promise((d,y)=>{let g,b,v,E,_,S,$,x=5,T=o,k=i,N=c,R=u,O=l,A=h,P=0,F=!1,C=0,M="";const U=new Pr(e=>{const o=e[Cr];if(!o)return void(x=5);const i=((t,e)=>{if(!t.byteLength)return null;const n=new Map;let r=0;for(;r<t.byteLength;++r)if(!_t[t[r]]){if(!Et(t,r,n,e))return null;break}return{type:t.latin1Slice(0,r).toLowerCase(),params:n}})(Buffer.from(o,"latin1"),p);if("form-data"!==i?.type)return void(x=5);if(v=i.params.get("name"),void 0===v)return z(new ht(400,{body:"missing field name"}));const c=Buffer.byteLength(v,"utf-8"),u=Math.min(f,k);if(c>u)return z(new ht(413,{body:`field name ${JSON.stringify(v.substring(0,u))}... too long`}));k-=c,E=i.params.get("filename*")??i.params.get("filename");const l=vt(e[Fr]);if(_=l?.mime??"text/plain",S=e[Mr]?.toLowerCase()??"7bit","application/octet-stream"===_||void 0!==E){if(!A--)return z(new ht(413,{body:"too many files"}));if(!E)return void(x=5);t||(E=(t=>{for(let e=t.length;e-- >0;)if("/"===t[e]||"\\"===t[e]){t=t.slice(e+1);break}return".."===t||"."===t?"":t})(E));const e=new I(m);e.once("error",Ir),e.once("close",()=>{e.Xe?.(),e.off("error",Ir),! --C&&b&&process.nextTick(b)}),g=e,++C,P=Math.min(a,N,k,T),n({name:v,type:"file",value:e,filename:E,encoding:S,mimeType:_,sizeLimit:P}),x=4}else{if(!O--)return z(new ht(413,{body:"too many fields"}));x=4,P=Math.min(s,k,T);const t=l?.params.get("charset")?.toLowerCase()??r;$=yt(t)}}),D=Buffer.from(`\r\n--${w}`,"latin1"),B=new Ar(D,(t,n,r,o)=>{if(x<=2){if(0===x){if(13===t[n])x=1;else{if(45!==t[n])return void(x=5);x=2}if(++n===r)return}if(1!==x)return 45!==t[n]?void(x=5):(x=6,e.off("data",H),void e.resume());if(10!==t[n++])return void(x=5);if(!R--)return z(new ht(413,{body:"too many parts"}));if(x=3,n===r)return}if(3===x){if(-1===(n=U.push(t,n,r)))return z(new ht(400,{body:"malformed part header"}));if(n===r)return}if(4===x){const e=Math.min(r,n+P);if(P-=r-n,k-=r-n,g){if(N-=r-n,e>n){let r;r=o?t.subarray(n,e):Buffer.copyBytesFrom(t,n,e-n),g.push(r)||(F=!0)}if(P<0)return z(new ht(413,{body:`uploaded file for ${JSON.stringify(v)}: ${JSON.stringify(E)} too large`}))}else{if(P<0)return z(new ht(413,{body:`value for ${JSON.stringify(v)} too long`}));M+=t.latin1Slice(n,e)}}},()=>{if(3===x)return z(new ht(400,{body:"unexpected end of headers"}));if(4===x)if(g)g.push(null),g=void 0,F=!1;else{const t=Buffer.from(M,"latin1");M="",n({name:v,type:"string",value:$.decode(t),encoding:S,mimeType:_})}x<6&&(x=0)});B.push(Br);const H=t=>{if((T-=t.byteLength)<0)return z(new ht(413,{body:"content too large"}));F=!1,B.push(t),g&&F&&(e.pause(),g.Xe=()=>e.resume())},j=()=>{if(7!==x){if(6!==x&&(B.destroy(),6!==x))return z(new ht(400,{body:"unexpected end of form"}));e.off("data",H),e.off("end",j),b=()=>{e.off("error",z),d()},C||b()}},z=t=>{7!==x&&(x=7,e.off("data",H),e.off("end",j),e.off("error",z),g?.destroy(t),g=void 0,y(t))};e.on("data",H),e.once("end",j),e.once("error",z)})}(e,r.params);throw new ht(415)}function Jr(t,{closeAfterErrorDelay:e=500,...n}={}){V(e,"closeAfterErrorDelay",!0);const r=()=>{if(e>=0&&t.readable){const n=setTimeout(()=>t.socket.destroy(),e);t.once("end",()=>clearTimeout(n))}};try{const e=qr(t.headers,n);cr(t);const o=new Z;return e(t,t=>o.push(t)).then(()=>o.close("complete"),e=>{o.fail(t.readableAborted?te:e),t.resume(),r()}),o}catch(e){throw fr(t)&&(t.resume(),r()),e}}async function Lr(t,e={}){const n=new FormData,r=new Map;for await(const o of Jr(t,e))if("file"===o.type){const i=o.value;let s=await(e.preCheckFile?.({fieldName:o.name,filename:o.filename,encoding:o.encoding,mimeType:o.mimeType,maxBytes:o.sizeLimit}));const a=t=>{if("function"==typeof s){const e=s;return s=void 0,e({actualBytes:t})}};Yt(t,()=>a(0));const c=await Vn(t),f=await c.save(i,{mode:384});await a(f.size);const u=new File([await $(f.path)],o.filename,{type:o.mimeType});r.set(u,f.path),n.append(o.name,u)}else{let t=o.value;e.trimAllValues&&(t=t.trim()),n.append(o.name,t)}return Object.assign(n,{getTempFilePath(t){const e=r.get(t);if(!e)throw new RangeError("unknown file");return e},getBoolean(t){const e=n.get(t);return null===e?null:"true"===e||"on"===e},getString(t){const e=n.get(t);return"string"==typeof e?e:null},getAllStrings:t=>n.getAll(t).filter(t=>"string"==typeof t),getFile(t){const e=n.get(t);return"string"==typeof e?null:e},getAllFiles:t=>n.getAll(t).filter(t=>"string"!=typeof t)})}const Wr="win32"===/*@__PURE__*/B();function Gr(t,{rejectPotentiallyUnsafe:e=!0}={}){let n=[];const r=It(t);if(r&&!r.rt){if("/"===r.Z)return[];n=r.Z.split("/")}else{const e=r?.rt??kt(t).pathname;if("/"===e)return[];n=e.split("/").map(decodeURIComponent)}if(""!==n[0])throw new ht(400,{body:"invalid path"});if(n.shift(),e){const t=Wr?Xr:Vr;if(n.some(e=>t.test(e)||e.includes(P)))throw new ht(400,{body:"invalid path"});if(n.slice(0,n.length-1).includes(""))throw new ht(400,{body:"invalid path"})}return n}const Vr=/[\x00-\x1F\x7F/]|^(\.\.?|~)$/,Xr=/[\x00-\x1F"*/:<>?\\|\x7F]|^[\s.]*$|^(CON|PRN|AUX|NUL|(COM|LPT)[\d\xB9\xB2\xB3])(\.|$)/i;class Zr{constructor(t){this.load=t}}const Yr=t=>new Zr(t);function Kr(t){if(t&&("object"==typeof t||"function"==typeof t)){if(t instanceof I)return void t.destroy();if(t instanceof m)return t.cancel();if(Symbol.dispose&&"function"==typeof t[Symbol.dispose])return void t[Symbol.dispose]();if(Symbol.asyncDispose&&"function"==typeof t[Symbol.asyncDispose])return t[Symbol.asyncDispose]();if("function"==typeof t.return){const e=t.return();return e instanceof Promise?e:void 0}}}const Qr=/*@__PURE__*/to("accelerometer,attribution-reporting,autoplay,bluetooth,browsing-topics,camera,cross-origin-isolated,deferred-fetch-minimal,deferred-fetch,display-capture,encrypted-media,fullscreen,gamepad,geolocation,gyroscope,identity-credentials-get,idle-detection,language-detector,microphone,midi,otp-credentials,payment,picture-in-picture,private-state-token-issuance,private-state-token-redemption,publickey-credentials-create,publickey-credentials-get,screen-wake-lock,serial,storage-access,translator,usb,web-share,window-management,xr-spatial-tracking");function to(...t){const e=new Map;for(const n of t){const t=/ *([^,= ]+) *(?:= *((?:[^,"]|"(?:[^\\"]|\\.)*")*))?(,|$)/gy;for(;t.lastIndex<n.length;){const r=t.exec(n);if(!r)throw new Error(`invalid policy syntax: ${n}`);const o=r[1],i=r[2]??"",s=e.get(o)??new Set,a=/([^" ]+|"(?:[^"\\]|\\.)*")(?: +|$)/gy;for(;a.lastIndex<i.length;){const t=a.exec(i);if(!t)throw new Error(`invalid policy syntax: ${o}=${i}`);s.add(t[1])}e.set(o,s)}}const n=[];for(const[t,r]of e)r.delete("()"),n.push(`${t}=${r.has("*")?"*":[...r].join(" ")||"()"}`);return n.join(",")}const eo=t=>new Promise(e=>{if(!t.writable)return e();const n=()=>{t.off("close",n),t.off("drain",n),t.cork(),e()};t.once("close",n),t instanceof E?t.write(rt,n):t.once("drain",n),t.uncork()});async function no(t,e,{delimiter:n=",",newline:r="\n",quote:o='"',encoding:i="utf-8",headerRow:s,end:a=!0}={}){if(!t.writable)return;"string"==typeof n&&(n=Buffer.from(n,i)),"string"==typeof r&&(r=Buffer.from(r,i));const c="string"==typeof o?Buffer.from(o,i):o,f=o+o,u=e=>{if(!e||!t.writable)return!0;if("string"==typeof e){const n=e.includes(o);return!n&&ro.test(e)?t.write(e,i)||eo(t):(t.write(c),n?t.write(e.replaceAll(o,f),i):t.write(e,i),t.write(c)||eo(t))}return(async()=>{t.write(c);for await(const n of e){if("string"!=typeof n)throw new TypeError("Readables must have an encoding");if(!t.writable)break;t.write(n.replaceAll(o,f),i)||await eo(t)}t.write(c)})()};t instanceof E&&!t.headersSent&&!t.hasHeader("content-type")&&t.setHeader("content-type","text/csv; charset="+i+(s?"; header=present":!1===s?"; header=absent":"")),t.cork(),e instanceof Zr&&(e=await e.load());try{t.write(rt);for await(let o of e){if(!t.writable)break;o instanceof Zr&&(o=await o.load());try{let e=0;if(Symbol.iterator in o)for(let r of o){if(!t.writable)break;e&&t.write(n),r instanceof Zr&&(r=await r.load());try{const t=u(r);t&&await t}finally{const t=Kr(r);t&&await t}++e}else for await(let r of o){if(!t.writable)break;e&&t.write(n),r instanceof Zr&&(r=await r.load());try{const t=u(r);t&&await t}finally{const t=Kr(r);t&&await t}++e}}finally{const t=Kr(o);t&&await t}t.write(r)||await eo(t)}}finally{t.uncork();const n=Kr(e);n&&await n}a&&t.end()}const ro=/^[^"':;,\\\r\n\t ]*$/i;class oo{constructor(t){(t=>"Ze"in t&&"function"==typeof t.pipe)(t)&&(t=I.toWeb(t)),this.Ot=t.getReader(),this.Ye=null,this.Ke=0,this.m=0}getRange(t,e){if(e<t)throw new RangeError("invalid range");if(t<this.Ke)throw new RangeError("non-sequential range");if(this.m)throw new TypeError("previous range still active");let n=e-t+1,r=t-this.Ke;this.Ke=e+1,this.m=1;const o=this,i=(t,e)=>{const o=t.byteLength;o<=r?r-=o:o>r+n?(this.Ye=t.subarray(r+n),e.enqueue(t.subarray(r,r+n)),n=0):r>0?(e.enqueue(t.subarray(r)),n-=o-r,r=0):(e.enqueue(t),n-=o)};return new m({start(t){if(o.Ye){const e=o.Ye;o.Ye=null,i(e,t)}},async pull(t){if(n<=0)return o.m=0,void t.close();const e=await o.Ot.read();e.done?t.error(new RangeError("range exceeds content")):"string"==typeof e.value?i(Buffer.from(e.value,"utf-8"),t):e.value instanceof Uint8Array?i(e.value,t):t.error(new TypeError("invalid stream type: must contain bytes or UTF-8 text"))}})}async close(){await this.Ot.cancel(),this.Ot.releaseLock()}}function io(t,{forceSequential:e=!1,mergeOverlapDistance:n=100}={}){const r=[];if(n>=0)for(const e of t.ranges){let t=null,o=0;for(let i=0;i<r.length;++i){const s=r[i];e.end>=s.start-n-1&&s.end>=e.start-n-1?t?(++o,t.start=Math.min(t.start,s.start),t.end=Math.max(t.end,s.end)):(t=s,t.start=Math.min(t.start,e.start),t.end=Math.max(t.end,e.end)):o>0&&(r[i-o]=s)}t?r.length-=o:r.push({...e})}else r.push(...t.ranges);if(e)for(let t=0;t<r.length-1;++t)if(r[t].start>r[t+1].start){r.sort((t,e)=>t.start-e.start);break}return{ranges:r,totalSize:t.totalSize}}async function so(t,e,n,r){if(e.closed||!e.writable)throw te;if("string"==typeof n||"createReadStream"in n&&!n.noRandomAccess||(r=io(r,{mergeOverlapDistance:0,forceSequential:!0})),1===r.ranges.length){const o=r.ranges[0];if(e.setHeader("content-length",o.end-o.start+1),e.setHeader("content-range",`bytes ${o.start}-${o.end}/${r.totalSize??"*"}`),e.writeHead(206),"HEAD"===t.method)return void e.end();const i=await ao(n);try{if(e.closed||!e.writable)throw te;await k(i.Qe(o.start,o.end),e)}catch(t){throw ar(e,t)?te:t}finally{i.tn&&await i.tn()}return}const o=e.getHeader("content-type"),i=T()+T()+"ABCDEFGHIJKLMNOPQRSTUVWXYZ";e.setHeader("content-type",`multipart/byteranges; boundary=${i}`);const s=r.ranges.map(t=>({i:[`--${i}`,...ct({"content-type":o,"content-range":`bytes ${t.start}-${t.end}/${r.totalSize??"*"}`}),"",""].join("\r\n"),en:t})),a=`--${i}--`;let c=a.length;for(const{i:t,en:e}of s)c+=t.length+e.end-e.start+1+2;if(e.setHeader("content-length",c),"HEAD"===t.method)return void e.end();let f="";const u=await ao(n);try{for(const{i:t,en:n}of s){if(e.closed||!e.writable)throw te;e.write(f+t,"ascii"),await k(u.Qe(n.start,n.end),e,{end:!1}),f="\r\n"}e.end(f+a)}catch(t){throw ar(e,t)?te:t}finally{u.tn&&await u.tn()}}async function ao(t){if("string"==typeof t){const e=await o(t,"r");return{Qe:(t,n)=>Y(e,{start:t,end:n,autoClose:!1}),tn:()=>e.close()}}if("createReadStream"in t){if(t.noRandomAccess){const e=Y(t,{start:0,autoClose:!1}),n=new oo(e);return{Qe:(t,e)=>n.getRange(t,e),tn:async()=>{await n.close(),e.close()}}}return{Qe:(e,n)=>Y(t,{start:e,end:n,autoClose:!1})}}{const e=new oo(t);return{Qe:(t,n)=>e.getRange(t,n),tn:()=>e.close()}}}async function co(t,e,n,r=null,o){if(e.closed||!e.writable)throw te;if(!r&&("string"==typeof n?r=await s(n):"stat"in n&&(r=await n.stat()),e.closed||!e.writable))throw te;if(r){if("GET"===t.method||"HEAD"===t.method){if(!_r(t,e,r))return void e.writeHead(304).end();e.setHeader("accept-ranges","bytes");const i=Ze(t,r.size,o);if(i&&Sr(t,e,r))return so(t,e,n,io(i,o))}e.setHeader("content-length",r.size)}if(e.writeHead(e.statusCode,e.statusMessage),"HEAD"!==t.method){"string"==typeof n?n=_(n):"createReadStream"in n&&(n=Y(n,{start:0,autoClose:!1}));try{await k(n,e)}catch(t){throw ar(e,t)?te:t}}else e.end()}function fo(t,e,{replacer:n,space:r,undefinedAsNull:o=!1,encoding:i="utf-8",end:s=!0}={}){const a=JSON.stringify(e,n,r??void 0)??(o?"null":void 0);t instanceof E&&!t.headersSent&&(t.hasHeader("content-type")||t.setHeader("content-type","application/json"),s&&t.setHeader("content-length",Buffer.byteLength(a,i))),s?t.end(a,i):a&&t.write(a,i)}async function uo(t,e,{replacer:n=null,space:r=null,undefinedAsNull:o=!1,encoding:i="utf-8",end:s=!0}={}){if(Array.isArray(n)){const t=new Set(n.map(t=>String(t)));n=function(e,n){return null===this||Array.isArray(this)||t.has(e)?n:void 0}}"number"==typeof r&&(r=" ".substring(0,r));try{if(!t.writable)return;const s={it:t,nn:e=>t.write(e,i),rn:n,sn:r??""};t instanceof E&&!t.headersSent&&!t.hasHeader("content-type")&&t.setHeader("content-type","application/json"),e instanceof Zr&&(e=await e.load());const a=ho(null,"",e,s);if(wo(a))o&&s.nn("null");else{t.cork(),t.write(rt);try{await lo(s,a,r?"\n":"")}finally{t.uncork()}}}finally{const t=Kr(e);t&&await t}s&&t.end()}async function lo(t,e,n){const r=(r,o,i)=>{t.nn(r);const s=n+t.sn,a=t.sn?": ":":";let c=!0;return{o:async(n,r)=>{if(t.it.writable){r instanceof Zr&&(r=await r.load());try{const o=ho(e,n,r,t);i&&wo(o)||(c?c=!1:t.nn(","),t.nn(s),i&&(t.nn(JSON.stringify(n))||await eo(t.it),t.nn(a)),await lo(t,o,s))}finally{const t=Kr(r);t&&await t}}},tn:()=>{c||t.nn(n),t.nn(o)}}};if(t.it.writable)if(null===e||"object"!=typeof e||e instanceof String||e instanceof Number||e instanceof Boolean||e instanceof Function||e instanceof Symbol||e instanceof BigInt||JSON.isRawJSON(e))t.nn(JSON.stringify(e)??"null")||await eo(t.it);else if(e instanceof I||e instanceof m){t.nn('"');for await(const n of e){if("string"!=typeof n)throw new TypeError("Readables must have an encoding");if(!t.it.writable)break;const e=JSON.stringify(n);t.nn(e.substring(1,e.length-1))||await eo(t.it)}t.nn('"')}else if(e instanceof Map){const t=r("{","}",!0);for(const[n,r]of e)await t.o(n,r);t.tn()}else if(po(e)){let n=0;const o=r("[","]",!1);for(const r of e){if(!t.it.writable)break;await o.o(String(n++),r)}o.tn()}else if(mo(e)){let n=0;const o=r("[","]",!1);for await(const r of e){if(!t.it.writable)break;await o.o(String(n++),r)}o.tn()}else{const t=r("{","}",!0);for(const[n,r]of Object.entries(e))await t.o(n,r);t.tn()}}function ho(t,e,n,r){return r.rn&&(n=r.rn.call(t,e,n)),n&&"object"==typeof n&&"function"==typeof n.toJSON&&(n=n.toJSON(e)),n}const wo=t=>void 0===t||"function"==typeof t||"symbol"==typeof t||t instanceof Function||t instanceof Symbol,po=t=>Symbol.iterator in t,mo=t=>Symbol.asyncIterator in t;class yo{constructor(t,e,{keepaliveInterval:n=15e3,softCloseReconnectDelay:r=500,softCloseReconnectStagger:o=2e3}={}){V(n,"keepaliveInterval",!0),this.an=e,this.cn=n,this.Y=new AbortController,e.setHeader("content-type","text/event-stream"),e.setHeader("x-accel-buffering","no"),e.setHeader("cache-control","no-store"),e.writeHead(200),e.flushHeaders(),this.ping=this.ping.bind(this),this.fn(),t.once("close",()=>this.close()),zt(t,()=>this.close(r,o))}get signal(){return this.Y.signal}get open(){return!this.Y.signal.aborted}fn(){this.cn>0&&(this.un=setTimeout(this.ping,this.cn))}ping(){!this.Y.signal.aborted&&this.an.writable&&(clearTimeout(this.un),this.an.write(":\n\n",()=>this.fn()))}send({event:t,id:e,data:n,reconnectDelay:r=-1}){return this.sendFields([["event",t],["id",e],["data",n],["retry",r>=0?String(0|r):void 0]])}async sendFields(t){let e;this.Y.signal.throwIfAborted(),this.an.cork();try{let n=!1;for(const[e,r]of t){if(void 0===r)continue;const t=r.split(/(?<=\n)|(?<=\r)(?!\n)/g);for(let n of t)this.an.write(e)," "===n[0]?this.an.write(": "):this.an.write(":"),this.an.write(n);/[\r\n]$/.test(r)?(this.an.write(e),this.an.write(":\n")):this.an.write("\n"),n=!0}if(!n)return;clearTimeout(this.un),this.an.write("\n",()=>e())}finally{this.an.uncork()}await new Promise(t=>{e=t}),this.fn()}async close(t=0,e=0){if(this.Y.signal.aborted){if(this.an.closed)return;return new Promise(t=>this.an.once("close",t))}this.cn=0,clearTimeout(this.un),this.Y.abort(new Error("ServerSentEvents closed")),await new Promise(n=>{if(this.an.writable&&(t>0||e>0)){const r=t+Math.random()*e;this.an.end(`retry:${0|r}\n\n`,n)}else this.an.end(n)})}}const go=(t,e)=>{e&&"identity"!==e&&t.setHeader("content-encoding",e)},bo=(t,e)=>{if(e){const n=t.getHeader("vary")??"";t.setHeader("vary",(n?n+", ":"")+e)}},vo=(t,{fallback:e,verbose:n,headers:r,dynamicHeaders:o=["etag","last-modified"],callback:i}={})=>{let s=null;const a=e?.statusCode??200;if(e){let n=e.filePath;n.startsWith("/")&&(n=n.substring(1)),s=t.toNormalisedPath(n.split("/"))}const c={rejectPotentiallyUnsafe:!t.isStaticListing},f=lt(r),u=new Set((o||[]).map(t=>t.toLowerCase()));for(const t of f.keys())u.delete(t);return{handleRequest:async(e,r)=>{if("GET"!==e.method&&"HEAD"!==e.method)return ee;let o=!1;const l=Gr(e,c),h=[];let d=await t.find(l,e.headers,n?h:void 0);if(!d){if(!s)return n&&Un(e,new Error(h.join(", ")),"serving static content"),ee;if(o=!0,d=await t.find(s,e.headers,h),!d)throw new ht(500,{message:`failed to find fallback file: ${h.join(", ")}`})}try{o&&(r.statusCode=a);const t=d.headers["content-type"]??On(N(d.canonicalFilename));r.setHeader("content-type",t);const n=d.headers["content-language"];n&&r.setHeader("content-language",n),go(r,d.headers["content-encoding"]),bo(r,d.headers.vary),r.setHeaders(f),u.has("etag")&&r.setHeader("etag",pn(r.getHeader("content-encoding"),d.stats)),u.has("last-modified")&&r.setHeader("last-modified",d.stats.mtime.toUTCString()),await(i?.(e,r,d,o)),await co(e,r,d.handle,d.stats)}finally{d.handle.close().catch(()=>{})}}}},Eo=async(t,e={})=>vo("static-paths"===e.mode?await Jn(t,e):await Hn(t,e),e),_o=(t,e,{headers:n,encodings:r=[],minCompression:o=0}={})=>{const i=(async()=>{const e=new Map;e.set("",{Zt:t,ln:yn(t)});const n=[];for(const i of r){const r=await Pn(t,i,o);r&&(e.set(i,{Zt:r,ln:yn(r)}),n.push({value:i,file:i}))}const i=new En([{feature:"encoding",options:n}]);return t=>{for(const n of i.options("",t)){const t=e.get(n.filename);if(t)return{H:n.headers,...t}}throw new Error("failed to serve static content")}})();return{handleRequest:async(t,r)=>{if("GET"!==t.method&&"HEAD"!==t.method)return ee;const{H:o,ln:s,Zt:a}=(await i)(t.headers);!r.closed&&r.writable&&(n&&r.setHeaders(lt(n)),go(r,o["content-encoding"]),bo(r,o.vary),r.setHeader("content-type",e),r.setHeader("etag",s),_r(t,r,null)?(r.setHeader("content-length",a.byteLength),r.end(a)):r.writeHead(304).end())}}},So=(t,e)=>_o(Buffer.from(JSON.stringify(t),"utf-8"),"application/json",e);class $o extends Error{constructor(t,{message:e,closeReason:n,...r}={}){super(e,r),this.closeCode=0|t,this.closeReason=n??"",this.name=`WebSocketError(${this.closeCode} ${this.closeReason})`}static NORMAL_CLOSURE=1e3;static GOING_AWAY=1001;static UNSUPPORTED_DATA=1003;static POLICY_VIOLATION=1008;static MESSAGE_TOO_BIG=1009;static INTERNAL_SERVER_ERROR=1011;static SERVICE_RESTART=1012;static TRY_AGAIN_LATER=1013;static BAD_GATEWAY=1014}function xo(t,{softCloseStatusCode:e=$o.GOING_AWAY,...n}={}){const r=(r,o,i)=>new Promise((s,a)=>{const c=new t({...n,noServer:!0,clientTracking:!1});c.once("wsClientError",a),c.handleUpgrade(r,o,i,t=>{c.off("wsClientError",a),i=rt,s({return:t,onError:e=>{const n=K(e,$o);if(n)return void t.close(n.closeCode,n.closeReason);const r=K(e,ht)??new ht(500),o=r.statusCode>=500?$o.INTERNAL_SERVER_ERROR:4e3+r.statusCode;t.close(o,r.statusMessage)},softCloseHandler:n=>t.close(e,n)})})});return t=>oe(t,r)}class To{constructor(t,e){this.data=t,this.isBinary=e}get text(){if(this.isBinary)throw new $o($o.UNSUPPORTED_DATA,{closeReason:"expected text"});return this.data.toString("utf-8")}get binary(){if(!this.isBinary)throw new $o($o.UNSUPPORTED_DATA,{closeReason:"expected binary"});return this.data}}class ko{constructor(t,{limit:e=-1,signal:n}={}){this.hn=new Z;const r=e=>{t.off("message",i),t.off("close",o),this.hn.close(new Error(e))},o=()=>r("connection closed"),i=(t,n)=>{void 0!==n?this.hn.push(new To(t,n)):"string"==typeof t?this.hn.push(new To(Buffer.from(t,"utf-8"),!1)):this.hn.push(new To(t,!0)),e>0&&0===--e&&this.detach()};this.detach=()=>{},n?.aborted?this.hn.close(n.reason):2===t.readyState||3===t.readyState?this.hn.close(new Error("connection closed")):(t.on("message",i),t.on("close",o),n?.addEventListener("abort",()=>r("signal aborted")),this.detach=()=>r("WebSocket listener detached"))}next(t){return this.hn.shift(t)}[Symbol.asyncIterator](){return this.hn[Symbol.asyncIterator]()}}function No(t,{timeout:e,signal:n}={}){const r=new ko(t,{limit:1,signal:n});return r.next(e).finally(()=>r.detach())}function Ro(t){const e=jt(t);return"GET"===t.method&&(e.nt?.has("websocket")??!1)}const Oo=t=>t.headers.origin??ft(t.headers["sec-websocket-origin"]),Ao=(t,e=5e3)=>async n=>{if(!Ro(n))return;const r=await t(n);let o;try{o=await No(r,{timeout:e})}catch(t){if((r.readyState??0)>=2)throw te;throw new $o($o.POLICY_VIOLATION,{closeReason:"timeout waiting for authentication token",cause:t})}if(o.isBinary)throw new $o($o.UNSUPPORTED_DATA,{closeReason:"authentication token must be sent as text"});return o.data.toString("utf-8")};export{Z as BlockingQueue,ee as CONTINUE,ht as HTTPError,ne as NEXT_ROUTE,re as NEXT_ROUTER,En as Negotiator,Qr as PP_BASE_DENY_2026,rn as Property,X as Queue,Ne as Router,te as STOP,yo as ServerSentEvents,nt as SharedFileHandle,ze as WebListener,$o as WebSocketError,To as WebSocketMessage,ko as WebSocketMessages,cr as acceptBody,oe as acceptUpgrade,Yt as addTeardown,ve as anyHandler,vo as assetServer,_r as checkIfModified,Sr as checkIfRange,$r as compareETag,Cn as compressFileOffline,Mn as compressFilesInDir,Se as conditionalErrorHandler,Y as createSafeReadStream,Nn as decompressMime,Zt as defer,ie as delegateUpgrade,Hn as dynamicFileFinder,Un as emitError,Ee as errorHandler,Eo as fileServer,K as findCause,mn as generateStrongETag,pn as generateWeakETag,Kt as getAbortSignal,me as getAbsolutePath,Q as getAddressURL,ln as getAuthScopes,Ge as getAuthorization,Rr as getBodyJSON,Tr as getBodyStream,Nr as getBodyText,kr as getBodyTextStream,Ve as getCharset,Lr as getFormData,Jr as getFormFields,Xe as getIfRange,On as getMime,pe as getPathParameter,we as getPathParameters,We as getQuery,Ze as getRange,Gr as getRemainingPathComponents,Je as getSearch,Le as getSearchParams,yt as getTextDecoder,gt as getTextDecoderStream,Oo as getWebSocketOrigin,un as hasAuthScope,Jt as isSoftClosed,Ro as isWebSocketRequest,Dn as jsonErrorHandler,Yr as loadOnDemand,xo as makeAcceptWebSocket,J as makeAddressTester,wr as makeGetClient,on as makeMemo,Vn as makeTempFileStorage,Ao as makeWebSocketFallbackTokenFetcher,to as mergePermissionsPolicy,vn as negotiateEncoding,No as nextWebSocketMessage,q as parseAddress,ur as proxy,en as readHTTPDateSeconds,Ke as readHTTPInteger,tn as readHTTPKeyValues,Qe as readHTTPQualityValues,Ye as readHTTPUnquotedCommaSeparated,kn as readMimeTypes,Zn as readZip,pt as registerCharset,Rn as registerMime,mt as registerUTF32,yr as removeForwarded,gr as replaceForwarded,ge as requestHandler,hn as requireAuthScope,fn as requireBearerAuth,Tn as resetMime,ye as restoreAbsolutePath,br as sanitiseAndAppendForwarded,Lt as scheduleClose,no as sendCSVStream,co as sendFile,fo as sendJSON,uo as sendJSONStream,so as sendRanges,zt as setSoftCloseHandler,vr as simpleAppendForwarded,io as simplifyRange,_o as staticContent,Jn as staticFileFinder,So as staticJSON,et as stringPredicate,De as toListeners,_e as typedErrorHandler,be as upgradeHandler,fr as willSendBody,Gn as zipFileFinder};
1
+ import{isIPv4 as t,isIPv6 as e}from"node:net";import n from"node:events";import{constants as r,open as o,realpath as i,stat as s,readdir as a,readFile as c,writeFile as f,utimes as u,rm as l,mkdtemp as h}from"node:fs/promises";import{TransformStream as d,TextDecoderStream as w,DecompressionStream as p,ReadableStream as m}from"node:stream/web";import{STATUS_CODES as y,createServer as g,Agent as b,request as v,ServerResponse as _}from"node:http";import{createReadStream as E,createWriteStream as S,openAsBlob as $}from"node:fs";import{createHash as x,randomUUID as T}from"node:crypto";import{pipeline as k}from"node:stream/promises";import{extname as N,sep as R,resolve as O,join as A,basename as P,dirname as F}from"node:path";import M,{constants as C,createZstdCompress as U,createBrotliCompress as B,createGzip as D,createDeflate as z,createInflateRaw as I}from"node:zlib";import{Readable as H,PassThrough as j,Duplex as q}from"node:stream";import{buffer as J}from"node:stream/consumers";import{tmpdir as L,platform as W}from"node:os";import{Agent as G,request as V}from"node:https";function X(n){if(!n||"unknown"===n)return;const r=/^((?:\d{1,3}\.){3}\d{1,3})(?::(\d+))?$/.exec(n);if(r?.[1]&&t(r[1]))return{family:"IPv4",address:r[1],port:r[2]?Number.parseInt(r[2]):void 0};const o=/^\[([\da-fA-F:]+)\](?::(\d+))?$|^([\da-fA-F:]+)$/.exec(n);if(o?.[1]&&e(o[1]))return{family:"IPv6",address:o[1].toLowerCase(),port:o[2]?Number.parseInt(o[2]):void 0};if(o?.[3]&&e(o[3]))return{family:"IPv6",address:o[3].toLowerCase(),port:void 0};const i=/^(.*?):(\d+)$/i.exec(n);return i?.[2]?{family:"alias",address:i[1],port:Number.parseInt(i[2])}:{family:"alias",address:n,port:void 0}}function Z(t){const e=new Set,n=[],r=[];for(const o of t){const t=/^((?:\d{1,3}\.){3}\d{1,3})(?:\/(\d+))?$/.exec(o);if(t?.[1]){const e=t[2]?Number.parseInt(t[2]):32,r=e<32?4294967295>>>e:0;n.push([K(t[1])|r,r]);continue}const i=/^\[?([\da-fA-F:]+)\]?(?:\/(\d+))?$/.exec(o);if(i?.[1]){const t=Q(i[1]),e=i[2]?Y>>BigInt(Number.parseInt(i[2])):0n;r.push([t|e,e]);continue}e.add(o)}return t=>{switch(t?.family){case"alias":return e.has(t.address);case"IPv4":const o=K(t.address);return n.some(([t,e])=>(o|e)===t);case"IPv6":const i=Q(t.address);return r.some(([t,e])=>(i|e)===t);default:return!1}}}const Y=/*@__PURE__*/BigInt("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");function K(t){const e=t.split(".").map(Number);return(e[0]<<24|e[1]<<16|e[2]<<8|e[3])>>>0}function Q(t){const e=t.split(":").map(t=>t?Number.parseInt(t,16):-1);let n=0n;for(const t of e)t<0?n<<=16n*BigInt(9-e.length):n=n<<16n|BigInt(t);return n}function tt(t,e,n){if(t>=2147483648||Number.isNaN(t)||!n&&t<0)throw new RangeError(`${e} must fit in a 31 bit integer - got ${t}`)}class et{constructor(t){const e={t:null,o:null};this.i=e,this.u=e,void 0!==t&&this.push(t)}isEmpty(){return!this.i.o}clear(){this.i.o=null,this.i.t=null,this.u=this.i}push(t){const e={t,o:null};this.u.o=e,this.u=e}shift(){if(!this.i.o)return null;this.i=this.i.o;const t=this.i.t;return this.i.t=null,t}remove(t){for(let e=this.i;e.o;e=e.o)if(e.o.t===t){e.o=e.o.o;break}}[Symbol.iterator](){return{next:()=>{if(!this.i.o)return{value:null,done:!0};this.i=this.i.o;const t=this.i.t;return this.i.t=null,{value:t,done:!1}}}}}class nt{constructor(){this.l=new et,this.h=new et,this.m=0}push(t){if(this.m)return;const e=this.h.shift();e?(e.v&&clearTimeout(e.v),e._(t)):this.l.push(t)}shift(t){return tt(t??0,"timeout"),this.l.isEmpty()?this.m?Promise.reject(this.S):new Promise((e,n)=>{const r={_:e,$:n,v:null};this.h.push(r),void 0!==t&&(r.v=setTimeout(()=>{this.h.remove(r),n(new Error(`timeout after ${t}ms`))},t))}):Promise.resolve(this.l.shift())}T(t){this.S=t;for(const e of this.h)e.$(t),e.v&&clearTimeout(e.v)}close(t){this.m||(this.m=1,this.T(t))}fail(t){this.m||(this.m=2,this.T(t))}[Symbol.asyncIterator](){return{next:()=>this.shift().then(t=>({value:t,done:!1}),t=>{if(2===this.m)throw t;return{value:null,done:!0}})}}}function rt(t,e){if(!(t instanceof n))return t.createReadStream(e);const r=t.close&&!1===e.autoClose?new Proxy(t,{get:(t,e,...n)=>"close"===e?()=>Promise.resolve():Reflect.get(t,e,...n)}):t,o=t.listeners("close").length,i=r.createReadStream(e),s=t.listeners("close"),a=s.length>o?s[s.length-1]:void 0,c=()=>{a&&t.off("close",a),i.destroy(),i.off("end",c),i.off("error",f)},f=()=>{t.close?.(),c()};return i.once("end",c),i.once("error",f),i}function ot(t,e){if(t instanceof e)return t;if(t&&"object"==typeof t){if("cause"in t)return ot(t.cause,e);if("error"in t)return ot(t.error,e)}}function it(t,e="http"){if(!t)throw new TypeError("no address");if("string"==typeof t)return t;const n=void 0===t.port?"":`:${t.port}`;if("IPv4"===t.family||"alias"===t.family)return`${e}://${t.address}${n}`;if("IPv6"===t.family)return`${e}://[${t.address}]${n}`;throw new TypeError(`unknown address family: ${t.family}`)}const st=Array.isArray,at=(t,e)=>new RegExp(t,(t.unicodeSets?"v":t.unicode?"u":"")+(t.ignoreCase||e?"i":"")),ct=(t,e)=>{if(void 0===t)return()=>!0;if(st(t)||(t=[t]),!t.length)return()=>!1;if(1===t.length){const n=t[0];if("string"==typeof n){if(e){const t=n.toLowerCase();return e=>e.toLowerCase()===t}return t=>t===n}const r=at(n,e);return t=>r.test(t)}const n=new Set,r=[];for(const o of t)"string"==typeof o?e?n.add(o.toLowerCase()):n.add(o):r.push(at(o,e));return t=>n.has(e?t.toLowerCase():t)||r.some(e=>e.test(t))};class ft{constructor(t,e=r.O_RDONLY,n=438,o=1e3){this.k=t,this.N=e,this.R=n,this.O=0,this.A=o}get path(){return this.k}countActive(){return this.O}async open(){++this.O,clearTimeout(this.P),this.P=void 0,this.F||(this.F=o(this.k,this.N,this.R).then(t=>(t.setMaxListeners(0),this.F=t,t)));const t=t=>{let e=!1;const n=()=>(e||(e=!0,this.T()),Promise.resolve());return new Proxy(t,{get:(t,e,...r)=>"close"===e?n:Reflect.get(t,e,...r)})};return"then"in this.F?this.F.then(t):t(this.F)}T(){--this.O||(clearTimeout(this.P),this.P=setTimeout(()=>{this.P=void 0,Promise.resolve(this.F).then(t=>{t&&!this.O&&(this.F=void 0,t.close().catch(()=>{}))})},this.A).unref())}}const ut=/*@__PURE__*/Buffer.alloc(0);function lt(t,e){const n=t.indexOf(e);return-1===n?[t]:[t.substring(0,n),t.substring(n+e.length)]}function ht(t,e,n=ht){throw t.code=e,Error.captureStackTrace(t,n),t}class dt{constructor(t,{fatal:e=!1}={}){this.M=t,this.C=e,this.U=new Uint8Array(4),this.B=new DataView(this.U.buffer),this.D=0}decode(t,{stream:e=!1}={}){const n=t.byteLength,r=[];let o=0;if(this.D>0){if(o=4-this.D,n<o)return this.U.set(t,this.D),this.D+=n,"";this.U.set(t.subarray(0,o),this.D),r.push(this.B.getUint32(0,this.M)),this.D=0}const i=new DataView(t.buffer,t.byteOffset,t.byteLength);let s=o;for(const t=n-3;s<t;s+=4)r.push(i.getUint32(s,this.M));if(e?(s<n&&this.U.set(t.subarray(s)),this.D=n-s):(this.D=0,s<n&&(this.C?ht(new TypeError("The encoded data was not valid for encoding utf-32"),"ERR_ENCODING_INVALID_ENCODED_DATA"):r.push(65533))),r.length>0){try{return String.fromCodePoint(...r)}catch{this.C&&ht(new TypeError("The encoded data was not valid for encoding utf-32"),"ERR_ENCODING_INVALID_ENCODED_DATA")}for(let t=0;t<r.length;++t)r[t]>1114111&&(r[t]=65533);return String.fromCodePoint(...r)}return""}}class wt{constructor(t){this.I=t,this.H=Object.create(null),this.j=!1}get headersSent(){return this.j}writeHead(t,e=y[t]??"-"){return this.j&&ht(new Error("Cannot write headers after they are sent to the client"),"ERR_HTTP_HEADERS_SENT"),this.I.write([`HTTP/1.1 ${t} ${yt(e)}`,...pt(this.H),"",""].join("\r\n"),"ascii"),this.j=!0,this}write(t,e="utf-8",n){return this.I.write(t,e,n)}end(t,e="utf-8",n){return this.I.end(t,e,n),this}setHeader(t,e){const n=t.toLowerCase();return this.H[n]="string"==typeof e||"number"==typeof e?e:[...e],this}setHeaders(t){for(const[e,n]of t)this.setHeader(e,n);return this}}function pt(t){const e=[];for(const[n,r]of Object.entries(t)){const t=mt(r);t&&e.push(`${yt(n)}: ${yt(t)}`)}return e}const mt=t=>"string"==typeof t?t:"number"==typeof t?String(t):t?t.join(", "):"",yt=t=>t.replaceAll(/[^ \t!-~]/g,"");function gt(t){if(!t||t instanceof Headers||Array.isArray(t))return new Headers(t);const e=t instanceof Map?[...t.entries()]:Object.entries(t);return new Headers(e.map(([t,e])=>[t,mt(e)]).filter(([t,e])=>e))}class bt extends Error{constructor(t,{message:e,statusMessage:n,headers:r,body:o,...i}={}){super(e??o,i),this.statusCode=0|t,this.statusMessage=n??y[this.statusCode]??"-",this.headers=gt(r),this.body=o??"",this.name=`HTTPError(${this.statusCode} ${this.statusMessage})`}}class vt extends d{constructor(t){super({transform(e,n){try{const r=t.decode(e,{stream:!0});r&&n.enqueue(r)}catch(t){n.error(t)}},flush(e){try{const n=t.decode(ut);n&&e.enqueue(n)}catch(t){e.error(t)}}})}}const _t=new Map;function Et(t,e){_t.set(t.toLowerCase(),e)}function St(){Et("utf-32be",{decoder:t=>new dt(!1,t)}),Et("utf-32le",{decoder:t=>new dt(!0,t)})}function $t(t,e={}){const n=_t.get(t.toLowerCase());if(n)return n.decoder(e);try{return new TextDecoder(t,e)}catch{throw new bt(415,{body:`unsupported charset: ${t}`})}}function xt(t,e={}){const n=_t.get(t.toLowerCase());if(n)return n.decoderStream?n.decoderStream(e):new vt(n.decoder(e));try{return new w(t,e)}catch{throw new bt(415,{body:`unsupported charset: ${t}`})}}const Tt=[null,"utf-32be",null,null,null,"utf-16be","utf-16be","utf-16be","utf-32le","utf-16le","utf-16le","utf-16le",null,null,null,"utf-8"];function kt(t){if(!t)return null;const[e,n]=lt(t,";"),r=new Map;if(n){const t=/\s*([!#-'*+\-.0-:>-Z^-z|~]+)=(?:([!#-'*+\-.0-:>-Z^-z|~]+)|"((?:[^\x00-\x08\x0a-\x1f"\\\x7f]|\\.)*)")\s*(;|$)/gy;for(;t.lastIndex!==n.length;){const e=t.exec(n);if(!e)return null;const o=e[1].toLowerCase(),i=e[2]??e[3]?.replaceAll(/\\(.)/g,"$1")??"";r.has(o)||r.set(o,i)}}return{mime:e.trim().toLowerCase(),params:r}}function Nt(t,e,n,r){const o=t.byteLength;for(;e<o;){for(;e<o;++e){const n=t[e];if(32!==n&&9!==n)break}if(e===o)break;if(59!==t[e++])return!1;for(;e<o;++e){const n=t[e];if(32!==n&&9!==n)break}if(e===o)return!1;const i=e;for(;e<o;++e){const n=t[e];if(!Rt[n]){if(61===n)break;return!1}}if(e===o)return!1;const s=t.latin1Slice(i,e).toLowerCase();if("*"===s[s.length-1]){const r=++e;for(;e<o;++e){const n=t[e];if(!At[n]){if(39!==n)return!1;break}}if(e===o)return!1;const i=$t(t.latin1Slice(r,e));for(++e;e<o&&39!==t[e];++e);if(e===o)return!1;if(++e===o)return!1;let a=e;const c=[];for(;e<o;++e){const n=t[e];if(1!==Ot[n]){if(37===n){let n,r;if(e+2<o&&16!==(n=Ft[t[e+1]])&&16!==(r=Ft[t[e+2]])){const o=(n<<4)+r;e>a&&c.push(i.decode(t.subarray(a,e),{stream:!0})),c.push(i.decode(Buffer.from([o]),{stream:!0})),a=(e+=2)+1;continue}return!1}break}}c.push(i.decode(t.subarray(a,e)));const f=c.join("");n.has(s)||n.set(s,f);continue}if(++e===o)return!1;if(34===t[e]){let i=++e,a=!1;const c=[];for(;e<o;++e){const n=t[e];if(92!==n){if(34===n){if(a){i=e,a=!1;continue}c.push(r.decode(t.subarray(i,e)));break}if(a&&(i=e-1,a=!1),!Pt[n])return!1}else a?(i=e,a=!1):(c.push(r.decode(t.subarray(i,e),{stream:!0})),a=!0)}if(e===o)return!1;++e,n.has(s)||n.set(s,c.join(""));continue}let a=e;for(;e<o;++e){const n=t[e];if(!Rt[n]){if(e===a)return!1;break}}n.has(s)||n.set(s,r.decode(t.subarray(a,e)))}return!0}const Rt=/*@__PURE__*/(()=>{const t=new Uint8Array(256);return t.set([1,0,1,1,1,1,1,0,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1],33),t})(),Ot=/*@__PURE__*/(()=>{const t=new Uint8Array(Rt);return t.set([0,1,0,0,0,0],37),t})(),At=/*@__PURE__*/(()=>{const t=new Uint8Array(Rt);return t.set([0,0,0,0,1,0,1,0],39),t.set([1,0,1,1],123),t})(),Pt=/*@__PURE__*/(()=>{const t=new Uint8Array(256);return t.fill(1,32,256),t[9]=1,t[34]=0,t[92]=0,t[127]=0,t})(),Ft=/*@__PURE__*/(()=>{const t=new Uint8Array(256).fill(16);for(let e=0;e<10;++e)t[48+e]=e;for(let e=0;e<6;++e)t[65+e]=e+10,t[97+e]=e+10;return t})(),Mt=t=>new URL("http://localhost"+(t.url??"/")),Ct=/%(25|2f)/gi,Ut=t=>t.replaceAll(/%2f/gi,"/").replaceAll(/%25/g,"%"),Bt=[6,6,9,12];class Dt extends Error{constructor(t,e,n){super(n??""),this.error=t,this.suppressed=e}}const zt=globalThis.SuppressedError??Dt,It=/*@__PURE__*/new WeakSet;class Ht{constructor(){this.J=!1}L(t){t instanceof Error&&It.add(t),this.J?t!==this.W&&(this.W=new zt(t,this.W)):(this.W=t,this.J=!0)}G(){this.J=!1,this.W=void 0}}const jt=new WeakMap;function qt(t,e,n){const r=jt.get(t);if(r)return r;const o=Mt(t),i={V:t,X:o,Z:(s=o.pathname,decodeURIComponent(s.replaceAll(Ct,"%25$1"))),Y:new AbortController,K:e,tt:[],et:[],nt:n?Wt(t):null};var s;return o.pathname.includes("%")&&(i.rt=o.pathname),jt.set(t,i),i}function Jt(t,e,n){e||(t.nt=null),t.ot=n;const r=async()=>{t.Y.abort(n.it.writableEnded?"complete":"client abort");const e=new Ht;await Lt(t.tt,e,t),await Lt(t.et,e,t,()=>{t.st=async e=>{try{await e()}catch(e){t.K(e,"tearing down",t.V)}}}),e.J&&t.K(e.W,"tearing down",t.V)};return n.it.closed?r():n.it.once("close",r),t}async function Lt(t,e,n,r){for(;n.ct;)await n.ct;const o=(async()=>{for(;;){const n=t.pop();if(!n)return void r?.();try{await n()}catch(t){e.L(t)}}})().then(()=>{n.ct===o&&(n.ct=void 0)});n.ct=o,await o}function Wt(t){return new Set(t.headers.upgrade?.split(",").map(t=>t.trim().toLowerCase())??[])}const Gt=t=>jt.get(t),Vt=t=>jt.delete(t);function Xt(t){const e=Gt(t);if(!e)throw new RangeError("unknown request");return e}function Zt(t,e){const n=Gt(t);n&&Yt(n,e)}function Yt(t,e){t.ft=e;const n=t.ut;n&&queueMicrotask(()=>re(e,n,t))}const Kt=t=>Boolean(Gt(t)?.ut);function Qt(t,e,n,r=0,o){const i=Xt(t),s=n-Math.max(r,0),a=i.lt??Number.POSITIVE_INFINITY,c=i.dt?.ht??a;s>=c&&n>=a||(n<a&&(i.lt=n),s<c&&(i.dt={ht:s,wt:e,K:o??i.K}),ne(i))}function te(t,e,n){if(!t.ut){if(t.ot&&!t.nt){const e=t.ot.it;e.headersSent||e.hasHeader("connection")||e.setHeader("connection","close")}t.ot?.it.once("close",()=>t.V.socket.destroy()),t.ut={wt:e,K:n},re(t.ft,t.ut,t),ne(t)}}function ee(t){if(t.ot){if(t.nt){if(!t.yt&&t.ot.it.writable){const e=new wt(t.ot.it);e.setHeader("connection","close"),e.writeHead(503)}}else{const e=t.ot.it;e.headersSent||(e.hasHeader("connection")||e.setHeader("connection","close"),e.writeHead(503))}t.ot.it.end(()=>t.V.socket.destroy())}else t.V.socket.destroy()}function ne(t){if(clearTimeout(t.gt),!t.lt||t.st)return;const e=Date.now();if(e>=t.lt)return void ee(t);let n=t.lt;t.dt&&!t.ut&&(e<t.dt.ht?n=t.dt.ht:(t.ut=t.dt,re(t.ft,t.ut,t))),void 0===t.gt&&t.et.push(()=>clearTimeout(t.gt)),t.gt=setTimeout(()=>ne(t),Math.min(n-e,6048e5))}async function re(t,e,n){try{await(t?.(e.wt))}catch(t){e.K(t,"soft closing",n.V),ee(n)}}const oe=(t,e)=>{const n=Xt(t);n.st?n.st(e):n.tt.push(e)},ie=(t,e)=>{const n=Xt(t);n.st?n.st(e):n.et.push(e)},se=t=>Xt(t).Y.signal;class ae extends Error{}const ce=/*@__PURE__*/new ae("STOP"),fe=/*@__PURE__*/new ae("CONTINUE"),ue=/*@__PURE__*/new ae("NEXT_ROUTE"),le=/*@__PURE__*/new ae("NEXT_ROUTER");async function he(t,e){const n=Xt(t);if(!n.ot)throw new TypeError("cannot call acceptUpgrade from shouldUpgrade");if(!n.nt)throw new TypeError("not an upgrade request");if(3===n.yt)throw new TypeError("upgrade already delegated");if(2===n.yt)return n.bt;const r=n.ot.it;if(!r.readable||!r.writable)throw ce;n.yt=1;const o=await e(t,r,n.ot.i);return n.ot.i=ut,n.vt=o.onError,o.softCloseHandler&&Yt(n,o.softCloseHandler),n.yt=2,n.bt=o.return,o.return}function de(t){const e=Xt(t);if(!e.ot)throw new TypeError("cannot call delegateUpgrade from shouldUpgrade");if(!e.nt)throw new TypeError("not an upgrade request");if(e.yt)throw new TypeError("upgrade already handled");e.yt=3}const we=RegExp.escape??(t=>t.replaceAll(/[^a-zA-Z0-9_ ]/g,t=>"\\u"+t.charCodeAt(0).toString(16).padStart(4,"0"))),pe=t=>t&&Ut(t),me=t=>void 0===t?void 0:""===t?[]:t.split("/").map(Ut),ye=t=>me(t)?.filter(t=>t),ge=/*@__PURE__*/(t=>e=>{const n=[];let r=0;for(;r<e.length;++r){const o=t.get(e[r]);if(!o)break;n.push([o,!0])}return[Object.fromEntries(n),e.substring(r)]})(
2
+ /*@__PURE__*/new Map([["i","_t"],["!","Et"],["%","St"]])),be=(t,e)=>{Object.prototype.hasOwnProperty.call(t,e)&&delete t[e]},ve=Object.freeze({});function _e(t,e,n){const r=t.V.url,o=t.Z,i=t.rt,s=t.$t??ve;if(t.rt){const n=((t,e)=>{let n=0;for(;e>0;){const r=t.indexOf("%",n),o=r-n;if(-1===r||o>=e){n+=e;break}const i=Ft[t.charCodeAt(r+1)];n=r+(Bt[i-12]||3),e-=o+(2===i&&"5fF".includes(t[r+2])?3:15===i?2:1)}if(e<0||n>t.length)throw new RangeError;return n})(t.rt,t.Z.length-e.length),r=t.rt.substring(n);t.V.url=r+t.X.search,t.rt=r.includes("%")?r:void 0}else t.V.url=e+t.X.search;return t.Z=e,n.length>0&&(t.$t=Object.freeze(Object.fromEntries([...Object.entries(s),...n]))),()=>{t.V.url=r,t.Z=o,i&&(t.rt=i),t.$t=s}}function Ee(t){return Gt(t)?.$t??ve}function Se(t,e){return n=Ee(t),r=e,Object.prototype.hasOwnProperty.call(n,r)?n[r]:void 0;var n,r}function $e(t){const e=Gt(t);return e?e.X.pathname+e.X.search:t.url??"/"}function xe(t){const e=Gt(t);e&&(t.url=e.X.pathname+e.X.search)}const Te=t=>"function"==typeof t?{handleRequest:t}:t,ke=(t,e)=>"function"==typeof t?{handleUpgrade:t,shouldUpgrade:e}:{shouldUpgrade:e,...t},Ne=(t,e=Fe)=>({handleRequest:t,handleUpgrade:t,shouldUpgrade:e}),Re=t=>"function"==typeof t?{handleError:t}:t,Oe=(t,e)=>Ae(e=>e instanceof t,e),Ae=(t,e)=>({handleError:(n,r,o)=>{if(o.response&&t(n))return e(n,r,o.response);throw n},shouldHandleError:(e,n,r)=>Boolean(r.response)&&t(e)}),Pe=t=>t.filter(t=>t).map(t=>"function"==typeof t?{handleRequest:t}:t),Fe=()=>!1,Me=Symbol("http");class Ce{constructor(){this.xt=[],this.Tt=[]}L(t,e,n,r,o){if(o.length){const i=n?((t,e)=>{const n=["^"],r=[],o=/[{}]|\/+|%|\\(.)|[:*]([a-zA-Z0-9_]*)/g,[{_t:i,Et:s,St:a},c]=ge(t);if("/"!==c[0])throw new TypeError("path must begin with '/' or flags");let f=0,u={kt:null,Nt:!1};const l=[u],h=t=>{null!==u.kt&&(u.kt+=t,u.Nt=!1),n.push(t)};let d=!1;const w=a?"/":"(?:/|%2[fF])",p=a?"[^/]":"(?:[^/%]|%25)";for(const t of c.matchAll(o)){t.index>f&&h(we(c.substring(f,t.index)));const e=t[0];if("{"===e)n.push("(?:"),u={...u},l.push(u);else if("}"===e){if(l.pop(),!l.length)throw new TypeError(`unbalanced optional braces in path at ${t.index}`);const e=u;if(u=l[l.length-1],null===u.kt?(u.kt=e.kt,u.Nt=e.Nt):null!==e.kt&&(u.kt=`(?:${u.kt}|${e.kt})`,u.Nt||=e.Nt),"(?:"===n[n.length-1])throw new Error(`empty optional section in path at ${t.index}`);n.push(")?")}else if("/"===e[0])u.kt=null,n.push(w),e.length>1?n.push(`{${e.length}${s?"":","}}`):s||n.push("+");else if("%"===e[0])h("%25");else if("\\"===e[0])h("%"===t[1]?"%25":we(t[1]));else{const o=e[0],i=t[2];if(!i)throw new TypeError(`unnamed parameter or unescaped '${o}' at ${t.index}`);if(null!==u.kt&&u.Nt)throw new TypeError(`path parameters must be separated by at least one character at ${t.index}`);if("*"===o){if(d)throw new TypeError("paths must not contain more than one multi-component path parameter");d=!0,null!==u.kt?n.push(`((?:(?!${u.kt})${p})*?(?:${w}.*?)?)`):n.push("(.*?)"),r.push({Rt:i,Ot:s?me:ye})}else null!==u.kt?n.push(`((?:(?!${u.kt})${p})+?)`):n.push(`(${p}+?)`),r.push({Rt:i,Ot:pe});u.kt="",u.Nt=!0}f=t.index+e.length}if(f<c.length&&n.push(we(c.substring(f))),l.length>1)throw new TypeError("unbalanced optional braces in path");return e&&(n.push("(?:"),s?n.push(`(?:(?<=${w})|${w})`):n.push(`(?:${w}+|(?<=${w}))`),n.push("(?<rest>.*))?")),n.push("$"),{At:new RegExp(n.join(""),i?"i":""),Pt:r}})(n,r):{At:null,Pt:[]};if(o.some(t=>t instanceof Promise))throw new TypeError("expected handler, got Promise (did you forget to await?)");this.xt.push({Ft:t,Mt:"string"==typeof e?e.toLowerCase():e,Ct:i.At,Ut:i.Pt,Bt:o})}return this}use(...t){return this.L(null,null,null,!0,Pe(t))}mount(t,...e){return this.L(null,null,t,!0,Pe(e))}within(t){const e=new Ce;return this.mount(t,e),e}at(t,...e){return this.L(null,null,t,!1,Pe(e))}onRequest(t,e,...n){return this.L(Be(t),Me,e,!1,Pe(n))}onUpgrade(t,e,n,...r){return this.L(Be(t),e,n,!1,(t=>t.filter(t=>t).map(t=>"function"==typeof t?{handleUpgrade:t}:t))(r))}onError(...t){return this.L(null,null,null,!0,t.map(Re))}onReturn(...t){return this.Tt.push(...t),this}get=(t,...e)=>this.L(Ue,Me,t,!1,Pe(e));delete=(...t)=>this.onRequest("DELETE",...t);getOnly=(...t)=>this.onRequest("GET",...t);head=(...t)=>this.onRequest("HEAD",...t);options=(...t)=>this.onRequest("OPTIONS",...t);patch=(...t)=>this.onRequest("PATCH",...t);post=(...t)=>this.onRequest("POST",...t);put=(...t)=>this.onRequest("PUT",...t);ws=(...t)=>this.onUpgrade("GET","websocket",...t);async handleRequest(t){return this.Dt(t,new Ht)}async handleUpgrade(t){return this.Dt(t,new Ht)}async handleError(t,e){const n=new Ht;return n.L(t),this.Dt(e,n)}shouldUpgrade(t){return this.zt(Xt(t))}zt(t){for(const e of this.xt){const n=De(t,e);if(!n)continue;let r=()=>{};if(!0!==n)try{r=_e(t,n.It,[])}catch{continue}try{for(const n of e.Bt)if(He(n,t))return!0}finally{r()}}return!1}async Dt(t,e){const n=Xt(t),r=await this.Ht(n,e);if(e.J)throw e.W;return r}async Ht(t,e){for(const n of this.xt){const r=De(t,n);if(!r)continue;let o=()=>{};if(!0!==r)try{const e=r.jt();o=_e(t,r.It,e)}catch(t){e.L(t);continue}try{const r=await ze(t,n.Bt,this.Tt,e);if(r===le)break;if(r===ue)continue;return r}finally{o()}}return fe}}const Ue=new Set(["HEAD","GET"]),Be=t=>t?"string"==typeof t?t:new Set(t):null;function De(t,e){if("string"==typeof e.Ft){if(e.Ft!==t.V.method)return!1}else if(null!==e.Ft&&!e.Ft.has(t.V.method??""))return!1;if(e.Mt===Me){if(t.nt)return!1}else if(null!==e.Mt&&!t.nt?.has(e.Mt))return!1;if(null===e.Ct)return!0;const n=e.Ct.exec(t.Z);return!!n&&{It:"/"+(n.groups?.rest??""),jt:()=>e.Ut.map((t,e)=>[t.Rt,t.Ot(n[e+1])])}}async function ze(t,e,n,r){for(const o of e){let e=await Ie(o,t,r);if(e!==fe){if(!t.nt&&!(e instanceof ae)&&n.length)try{const r="object"==typeof e?e:void 0,o=t.V,i=t.ot.it;for(const t of n)await t(r,o,i)}catch(t){r.L(t);continue}return e}}return ue}async function Ie(t,e,n){if(t instanceof Ce)return t.Ht(e,n);let r=fe;try{if(n.J){if(t.handleError){const o=n.W,i=e.nt?{socket:e.ot.it,head:e.ot.i,hasUpgraded:Boolean(e.yt)}:{response:e.ot.it};t.shouldHandleError&&!t.shouldHandleError(o,e.V,i)||(n.G(),r=await t.handleError(o,e.V,i))}}else if(e.nt){if(t.handleUpgrade){const n=e.ot;r=await t.handleUpgrade(e.V,n.it,n.i)}}else t.handleRequest&&(r=await t.handleRequest(e.V,e.ot.it))}catch(t){t instanceof ae?r=t:n.L(t)}finally{e.tt.length&&await((t,e)=>Lt(t.tt,e,t))(e,n)}return r===ce?void 0:r}function He(t,e){if(t instanceof Ce)return t.zt(e);if(!t.shouldUpgrade)return Boolean(t.handleUpgrade);try{return t.shouldUpgrade(e.V)}catch(t){return e.K(t,"checking should upgrade",e.V),!1}}const je=(t,e,n)=>{const r=qe(n);if(!r)return;const o=ot(t,bt)??new bt(500);r.setHeader("content-type","text/plain; charset=utf-8"),r.setHeader("x-content-type-options","nosniff"),r.setHeaders(o.headers),r.setHeader("content-length",String(Buffer.byteLength(o.body,"utf-8"))),n.response||r.setHeader("connection","close"),r.writeHead(o.statusCode,o.statusMessage),r.end(o.body,"utf-8")};function qe(t){if(t.response){const e=t.response;return e.headersSent?void e.end():e}const e=t.socket;if(!t.hasUpgraded&&e.writable)return e.addListener("finish",()=>e.destroy()),new wt(e);e.destroy()}function Je(t,{onError:e=Le,socketCloseTimeout:n=500}={}){tt(n,"socketCloseTimeout");let r=0,o="",i=e;const s=[],a=new Set,c=()=>{const t=[...s];s.length=0;for(const e of t)e()},f=t=>{t&&(a.size?s.push(t):setImmediate(t))},u=t=>{a.add(t),t.et.push(()=>{a.delete(t),!a.size&&s.length&&setImmediate(c)})},l=async(n,s,a)=>{let c;try{c=qt(n,e,!1)}catch(t){return e(t,"parsing request",n),void je(new bt(400),0,{response:s})}if(Jt(c,!1,{it:s}),a&&(c.qt=!0),u(c),1===r)te(c,o,i);else if(2===r)return ee(c),void Vt(n);const f=new Ht,l=await Ie(t,c,f);f.J||l!==fe&&l!==ue&&l!==le||f.L(new bt(404)),f.J&&(e(f.W,"handling request",n),je(f.W,0,{response:s}),Vt(n))};return{request:(t,e)=>l(t,e,!1),checkContinue:(t,e)=>l(t,e,!0),upgrade:async(s,a,c)=>{let f;a.once("finish",()=>{const t=setTimeout(()=>a.destroy(),n);a.once("close",()=>clearTimeout(t))});try{f=qt(s,e,!0)}catch(t){return e(t,"parsing upgrade",s),void je(new bt(400),0,{socket:a,hasUpgraded:!1})}if(Jt(f,!0,{it:a,i:c}),c=ut,u(f),1===r)te(f,o,i);else if(2===r)return ee(f),void Vt(s);const l=new Ht,h=await Ie(t,f,l);l.J||h!==fe&&h!==ue&&h!==le||(console.warn(`${s.url}: ${s.headers.upgrade} upgrade request fell-through. See https://github.com/davidje13/web-listener/blob/main/docs/API.md#upgrade-request-fell-through`),l.L(new bt(404))),l.J&&(e(l.W,"handling upgrade",s),f.vt?f.vt(l.W):je(l.W,0,{socket:a,head:f.ot?.i??ut,hasUpgraded:Boolean(f.yt)}),Vt(s))},shouldUpgrade:n=>{try{const r=qt(n,e,!0);return He(t,r)}catch{return!1}},clientError:(t,n)=>{const r=n.Jt,o=t.code;n.writable&&!r?.headersSent&&n.end(Ge.get(o)??Ve),n.destroy(t),("EPIPE"!==o||n.writable)&&("ECONNRESET"!==o||n.writable)&&"HPE_INVALID_EOF_STATE"!==o&&setTimeout(()=>{It.has(t)||e(t,"initialising request",void 0)},0)},softClose(t,e,n){if(r<1){r=1,o=t,i=e;for(const n of a)te(n,t,e)}f(n)},hardClose(t){if(r<2){r=2;for(const t of a)ee(t)}f(t)},countConnections:()=>a.size}}const Le=(t,e,n)=>{(ot(t,bt)?.statusCode??500)>=500&&console.error("%s",`unhandled error while ${e} ${n?.url??"(no request information)"}:`,t)},We=t=>Buffer.from(`HTTP/1.1 ${t} ${y[t]}\r\nConnection: close\r\n\r\n`),Ge=/*@__PURE__*/new Map([["HPE_HEADER_OVERFLOW",/*@__PURE__*/We(431)],["HPE_CHUNK_EXTENSIONS_OVERFLOW",/*@__PURE__*/We(413)],["ERR_HTTP_REQUEST_TIMEOUT",/*@__PURE__*/We(408)]]),Ve=/*@__PURE__*/We(400);class Xe extends EventTarget{constructor(t){super(),this.Lt=t}attach(t,e={}){const n=(e,n,r)=>{const o={server:t,error:e,context:n,request:r};this.dispatchEvent(new CustomEvent("error",{detail:o,cancelable:!0}))&&Le(e,n,r)},r=Je(this.Lt,{...e,onError:n});!1===e.autoContinue&&t.addListener("checkContinue",r.checkContinue),!1===e.rejectNonStandardExpect&&t.addListener("checkExpectation",r.request),t.addListener("request",r.request),t.addListener("upgrade",r.upgrade);const o=t.shouldUpgradeCallback??(()=>!1);!1!==e.overrideShouldUpgradeCallback&&(t.shouldUpgradeCallback=r.shouldUpgrade),t.addListener("clientError",r.clientError);let i=()=>{i=void 0,t.removeListener("checkContinue",r.checkContinue),t.removeListener("checkExpectation",r.request),t.removeListener("request",r.request),t.removeListener("upgrade",r.upgrade),t.shouldUpgradeCallback===r.shouldUpgrade&&(t.shouldUpgradeCallback=o),t.removeListener("clientError",r.clientError)};return(t="",e=-1,o=!1,s)=>{if(tt(e,"existingConnectionTimeout",!0),o||i?.(),e>0){const o=setTimeout(()=>{i?.(),r.hardClose()},e);r.softClose(t,n,()=>{i?.(),clearTimeout(o),s?.()})}else 0===e?(i?.(),r.hardClose(s)):(i?.(),s&&setImmediate(s));return r}}createServer(t={}){t.shouldUpgradeCallback&&(t={overrideShouldUpgradeCallback:!1,...t});const e=g(t),n=this.attach(e,t),r=Object.assign(e,{closeWithTimeout:(t,r)=>new Promise(o=>n(t,r,!0,()=>{e.close(()=>o()),e.closeAllConnections()}))});return r}listen(t,e,n={}){const r=this.createServer(n);return n.socketTimeout&&r.setTimeout(n.socketTimeout),new Promise((o,i)=>{r.once("error",i),r.listen(t,e,n.backlog??511,()=>{r.off("error",i),o(r)})})}}const Ze=t=>Gt(t)?.X??Mt(t),Ye=t=>Ze(t).search,Ke=t=>new URLSearchParams(Ze(t).searchParams),Qe=(t,e)=>Ze(t).searchParams.get(e);function tn(t){const e=t.headers.authorization;if(!e)return;const[n,r]=lt(e," ");return void 0!==r?[n.trim().toLowerCase(),r.trim()]:void 0}function en(t){const e=/^text\/.*;\s*charset=([^;]+)/i.exec(t.headers["content-type"]??"");return e?.[1]?.trim().toLowerCase()??void 0}function nn(t){const e=t.headers["if-range"];return e&&"string"==typeof e?/^("|W\/")/.test(e)?{etag:[e]}:{modifiedSeconds:fn(e)}:{}}function rn(t,e,{maxRanges:n=10,maxNonSequential:r=2,maxWithOverlap:o=2}={}){const i=t.headers.range;if(!i||0===e)return;const[s,a]=lt(i,"=");if("bytes"!==s||!a)return;const c=new bt(416,{headers:{"content-range":`bytes */${e}`}}),f=t=>{const e=sn(t);if(void 0===e)throw c;return e},u=[];for(const t of a.split(",")){const[r,o]=lt(t.trim(),"-");if(void 0===o)throw c;let i;if(r)i={start:f(r),end:o?Math.min(f(o),e-1):e-1};else{if(!o)throw c;i={start:Math.max(e-f(o),0),end:e-1}}if(!(i.start>=e)){if(i.end<i.start||u.length>=n)throw c;u.push(i)}}if(!u.length)throw c;if(u.length>r)for(let t=0;t<u.length-1;++t)if(u[t].start>u[t+1].start)throw c;if(u.length>o)for(let t=1;t<u.length;++t){const e=u[t];for(let n=0;n<t;++n){const t=u[n];if(e.end>=t.start&&t.end>=e.start)throw c}}return{ranges:u,totalSize:e}}function on(t){if(void 0!==t)return"number"==typeof t?[String(t)]:t.length?"string"==typeof t?t.split(",").map(t=>t.trim()):t.flatMap(t=>t.split(",").map(t=>t.trim())):[]}function sn(t){if(t&&/^\s*-?\d+\s*$/.test(t))return Number.parseInt(t,10)}const an=t=>on(t)?.map(t=>{const[e,...n]=t.split(";"),r=new Map(n.map(t=>{const[e,n]=lt(t,"=");return[e.trim(),n?.trim()??""]})),o=e.trim(),i="*/*"===o||"*"===o?0:o.endsWith("/*")?1:2,s=Math.max(0,Math.min(1,Number.parseFloat(r.get("q")??"1")));return{name:o,specifiers:r,specificity:i,q:s}});function cn(t){const e=new Map,n=/\s*([^=]+)=(?:([^";]*)|"((?:[^\\"]|\\.)*)"\s*)(?:;|$)/y;for(;n.lastIndex<t.length;){const r=n.exec(t);if(!r)throw new bt(400,{body:"invalid HTTP key values"});const o=r[1].toLowerCase();void 0!==r[3]?e.set(o,r[3].replaceAll(/\\(.)/g,"$1")):e.set(o,r[2].trim())}return e}function fn(t){if("string"!=typeof t)return;const e=Date.parse(t);return Number.isNaN(e)?void 0:e/1e3|0}const un=t=>"function"==typeof t?t:()=>t;class ln{constructor(t=pn){this.Wt=un(t)}set(t,e){dn(Xt(t)).set(this,e)}get(t){return wn(t,this,this.Wt)}clear(t){const e=Gt(t);e?.Gt?.delete(this)}withValue(t){return Ne(e=>(this.set(e,t),fe))}}const hn=(t,...e)=>{const n=n=>t(n,...e);return t=>wn(t,n,n)};function dn(t){return t.Gt||(t.Gt=new Map),t.Gt}function wn(t,e,n){const r=Gt(t);if(!r)return n(t);const o=dn(r);if(o.has(e))return o.get(e);const i=n(t);return o.set(e,i),i}const pn=()=>{throw new Error("property has not been set")};function mn({realm:t,extractAndValidateToken:e,fallbackTokenFetcher:n,closeOnExpiry:r=!0,softCloseBufferTime:o=0,onSoftCloseError:i}){const s=un(t);return{...Ne(async t=>{const a=Date.now(),c=await s(t),f={"www-authenticate":`Bearer realm="${c}"`},u=tn(t),l="bearer"===u?.[0]?u[1]:await(n?.(t));if(!l)throw new bt(401,{headers:f,body:"no token provided"});let h;try{h=await e(l,c,t)}catch(t){throw new bt(401,{headers:f,body:"invalid token",cause:t})}if(!h)throw new bt(401,{headers:f,body:"invalid token"});if("object"==typeof h){if("nbf"in h&&"number"==typeof h.nbf&&a<1e3*h.nbf)throw new bt(401,{headers:f,body:"token not valid yet"});if("exp"in h&&"number"==typeof h.exp){const e=1e3*h.exp;if(a>=e-o)throw new bt(401,{headers:f,body:"token expired"});r&&Qt(t,"token expired",e,o,i)}}return vn.set(t,{Vt:c,Xt:!0,Zt:h,Yt:_n(h)}),fe}),getTokenData:t=>{const e=vn.get(t);if(!e.Xt)throw new TypeError("cannot use getTokenData in an unauthenticated endpoint");return e.Zt}}}const yn=(t,e)=>vn.get(t).Yt.has(e),gn=t=>new Set(vn.get(t).Yt),bn=t=>Ne(e=>{const n=vn.get(e);if(!n.Yt.has(t))throw new bt(403,{headers:{"www-authenticate":`Bearer realm="${n.Vt}", scope="${t}"`},body:`scope required: ${t}`});return fe}),vn=/*@__PURE__*/new ln({Vt:"",Xt:!1,Zt:null,Yt:new Set});function _n(t){if(!t||"object"!=typeof t||!("scopes"in t))return new Set;const{scopes:e}=t;return st(e)?new Set(e):"string"==typeof e?new Set([e]):e&&"object"==typeof e?new Set(Object.entries(e).filter(([t,e])=>e).map(([t])=>t)):new Set}function En(t,e){const n=`${0|e.mtimeMs} ${e.size} ${t??""}`;return`W/"${x("sha256").update(n).digest("base64").substring(0,12)}"`}async function Sn(t){const e=x("sha256");return"string"==typeof t?await k(E(t),e):await k(rt(t,{start:0,autoClose:!1}),e),`"sha256-${e.digest("base64")}"`}const $n=t=>{const e=x("sha256");return e.write(t),`"sha256-${e.digest("base64")}"`},xn={type:{Kt:"accept",Qt:"content-type"},language:{Kt:"accept-language",Qt:"content-language"},encoding:{Kt:"accept-encoding",Qt:"content-encoding"}},Tn=/*@__PURE__*/new Map([["zstd","{file}.zst"],["br","{file}.br"],["gzip","{file}.gz"],["deflate","{file}.deflate"],["identity","{file}"]]),kn=t=>{return{feature:"encoding",options:(e=t,n=Tn,st(e)?e.map(t=>({value:t,file:n.get(t)})):Object.entries(e).map(([t,e])=>({value:t,file:e})))};var e,n};class Nn{constructor(t,{maxFailedAttempts:e=10}={}){this.te=t.map(t=>{if(!Object.prototype.hasOwnProperty.call(xn,t.feature))throw new RangeError(`unknown negotiation feature: ${t.feature}`);return{ee:t.feature,ne:ct(t.match,!0),re:t.options.map(t=>({oe:t.file,ie:t.value,ne:ct(t.for??t.value,!0)}))}}).filter(t=>t.re.length>0),this.se=e}*options(t,e){const n=this.te,r=new Set,o=this.se,i={},s=new Set;let a=!1;o>0&&(yield*function*c(f,u){const l=n[u];if(!l)return void(r.has(f)||(r.add(f),a&&(i.vary=[...s].join(", "),a=!1),yield{filename:f,headers:i}));if(!l.ne(t))return void(yield*c(f,u+1));const h=xn[l.ee];s.add(xn[l.ee].Kt),a=!0;const d=an(e[h.Kt])?.sort(Rn);if(!d?.length)return void(yield*c(f,u+1));const w=new Set,p=[];for(const t of l.re){const e=d.find(e=>t.ne(e.name));e&&p.push({...e,ae:t})}for(const t of p.sort(Rn)){const e=On(f,t.ae.oe);if(!w.has(e)&&(w.add(e),i[h.Qt]=t.ae.ie,yield*c(e,u+1),r.size>=o))return}delete i[h.Qt],!w.has(f)&&r.size<o&&(yield*c(f,u+1))}(t,0)),r.has(t)||(a&&(i.vary=[...s].join(", ")),yield{filename:t,headers:i})}}const Rn=(t,e)=>e.q-t.q||e.specificity-t.specificity;function On(t,e){return e.replaceAll(/\{(?:file|base|ext)\}/g,e=>"{file}"===e?t:"{base}"===e?t.replace(/\.[^.]*$/,""):N(t))}const An=/*@__PURE__*/Cn("bin=application/octet-stream;gz(ip),json,ogg,pdf,wasm,xml,y(a)ml,zip,zst(d)=application/{ext};webmanifest=application/manifest+json;aac,flac,mid(i),wav(e)=audio/{ext};mp3=audio/mpeg;oga,opus=audio/ogg;otf,ttf,woff,woff2=font/{ext};apng,avif,bmp,gif,heic,heif,jp(e)g,png,tif(f),webp=image/{ext};ico,cur=image/x-icon;svg=image/svg+xml;3mf,obj,stl,u3d=model/{ext};wrl=model/vrml;x3d=model/x3d+xml;x3db=model/x3d+binary;x3dv=model/x3d+vrml;css,csv,htm(l),rtf,vcard=text/{ext};(m)js=text/javascript;md=text/markdown;txt=text/plain;3gp(p),3g(pp)2,mp4,mp(e)g,h264=video/{ext};mov=video/quicktime;ogv=video/ogg");let Pn=/*@__PURE__*/new Map(An);function Fn(){Pn=new Map(An)}function Mn(t){const e=new Map;for(const n of t.split("\n")){const[t,...r]=n.replaceAll(/\s+/g," ").trim().split(" ");if(!t.startsWith("#"))for(const n of r)e.set(n.toLowerCase(),t)}return e}function Cn(t){const e=new Map;for(const n of t.split(/[\n;]/g)){const[t,r,o]=/^ *([^ =]+)=(.*)$/.exec(n)??[null,null,""];for(const t of r?.split(",")??[]){const[n,r,i="",s=""]=/^([^(]*)(?:\(([^)]*)\)(.*))?$/.exec(t),a=r+i+s,c=o.replace("{ext}",a);e.set(a.toLowerCase(),c),i&&e.set((r+s).toLowerCase(),c)}}return e}function Un(t){for(const[e,n]of t)Pn.set(e.toLowerCase(),n)}function Bn(t,e="utf-8"){"."===t[0]&&(t=t.substring(1));const n=Pn.get(t)??"application/octet-stream";return/^text\/|\+xml$|^application\/xml$/i.test(n)&&!n.includes("charset=")?`${n}; charset=${e}`:n}const Dn=/*@__PURE__*/new Map([["zstd",t=>U({params:{[C.ZSTD_c_compressionLevel]:t.zs}})],["br",(t,e)=>B({params:{[C.BROTLI_PARAM_QUALITY]:t.br,[C.BROTLI_PARAM_SIZE_HINT]:e??0}})],["gzip",t=>D({level:t.z})],["deflate",t=>z({level:t.z})]]),zn=(t,e,n)=>{const r=Dn.get(t);if(r)return r(new Map([["fast",{z:C.Z_BEST_SPEED,br:C.BROTLI_MIN_QUALITY,zs:2}],["max",{z:C.Z_BEST_COMPRESSION,br:C.BROTLI_MAX_QUALITY,zs:9}]]).get(e)??{z:C.Z_DEFAULT_COMPRESSION,br:C.BROTLI_DEFAULT_QUALITY,zs:C.ZSTD_CLEVEL_DEFAULT},n)};async function In(t,e,n,r){const o=t.byteLength-r;if(o<=0)return;const i=zn(e,n,t.byteLength);if(!i)return;const s=await k(H.from(t),i,J);return s.byteLength<=o?s:void 0}class Hn{constructor({subDirectories:t=!0,caseSensitive:e="exact",allowAllDotfiles:n=!1,allowAllTildefiles:r=!1,allowDirectIndexAccess:o=!1,allow:i=[".well-known"],hide:s=[],indexFiles:a=["index.htm","index.html"],implicitSuffixes:c=[],negotiator:f}){this.ce=!0===t?Number.POSITIVE_INFINITY:t||0,this.fe=e,this.ue=n,this.le=r,this.he=o,this.de=a,this.we=["",...c],this.pe=new Set(i.map(t=>this.me(t))),this.ye=ct(s,!e),this.ge=new Set(a.map(t=>this.me(t))),this.be=f}me(t){return"exact"===this.fe?t:t.toLowerCase()}ve(t){const e=this.me(t);if(this.pe.has(e))return!0;const n=e.trim();return!(!("~"!==n[0]&&"~"!==n[n.length-1]||this.le)||"."===n[0]&&!this.ue||this.ye(n))}_e(t){const e=t[t.length-1];return e&&this.ge.has(this.me(e))?t.slice(0,t.length-1):t}}const jn=async(t,e={})=>new qn(await Jn(t),new Hn(e));class qn{constructor(t,e){this.Ee=t,this.Se=e}get isStaticListing(){return!1}toNormalisedPath(t){return this.Se._e(t)}async find(t,e={},n){let r=t.join(R);if("force-lowercase"===this.Se.fe&&(r=r.toLowerCase()),/(^|[\\\/])\.\.($|[\\\/])|^[\\\/]/.test(r))return n?.push(`${JSON.stringify(r)} is not permitted`),null;let o=O(this.Ee,r);if(!o.startsWith(this.Ee)&&o+R!==this.Ee)return n?.push(`${JSON.stringify(o)} is not inside root ${JSON.stringify(this.Ee)}`),null;let a=null,c=null;for(const t of this.Se.we){const e=o+t;if(a=e.substring(this.Ee.length).split(R).filter(t=>t),a.length-1>this.Se.ce)return n?.push(`${JSON.stringify(o)} is nested too deeply (${a.length-1} > ${this.Se.ce})`),null;if(a.some(t=>!this.Se.ve(t)))return n?.push(`${JSON.stringify(o)} is not permitted`),null;const r=a[a.length-1]??"";if(!this.Se.he&&this.Se.ge.has(this.Se.me(r))&&!this.Se.pe.has(this.Se.me(r)))return n?.push(`${JSON.stringify(o)} is a hidden index file`),null;if(c=await i(e,{encoding:"utf-8"}).catch(()=>null),c){o=e;break}}if(!c||!a)return n?.push(`file ${JSON.stringify(o)} does not exist`),null;if(this.Se.me(c)!==this.Se.me(o))return n?.push(`realpath ${JSON.stringify(c)} does not match request ${JSON.stringify(o)}`),null;let f=c,u=await s(c).catch(()=>null);if(!u)return n?.push(`file ${JSON.stringify(c)} does not exist`),null;if(u.isDirectory()){if(a.length>this.Se.ce)return n?.push(`${JSON.stringify(c)} index file is nested too deeply (${a.length} > ${this.Se.ce})`),null;for(const t of this.Se.de){const e=A(c,t);if(u=await s(e).catch(()=>null),u?.isFile()){f=e;break}}}if(!u?.isFile())return n?.push(`${JSON.stringify(c)} exists but is not a file`),null;const l=P(f);if(!this.Se.be)return Ln(f,{canonicalFilename:l,headers:{}},n);const h=F(f);for(const t of this.Se.be.options(l,e)){if(!t.filename||t.filename.includes(R))continue;const e=await Ln(A(h,t.filename),{canonicalFilename:l,headers:t.headers},n);if(e)return e}return null}}const Jn=async t=>await i(O(process.cwd(),t),{encoding:"utf-8"})+R;async function Ln(t,e,n){const i=await o(t,r.O_RDONLY).catch(()=>null);if(!i)return n?.push(`failed to open ${JSON.stringify(t)}`),null;const s=()=>(i.close().catch(()=>{}),null),a=await i.stat().catch(s);return a?.isFile()?{handle:i,stats:a,filesystemPath:t,...e}:(n?.push(`${JSON.stringify(t)} exists but is not a file`),s())}async function Wn(t,e={}){const n=await Jn(t),r=new Hn(e),o=new Gn(r,Ln);return await Vn(n,r,(t,e,r)=>o.$e(t,e,A(n,...t,e),r),t=>o.xe(t)),o}class Gn{get isStaticListing(){return!0}constructor(t,e){this.Te=new Map,this.Se=t,this.ke=e}Ne(t,e){const n=this.Te.get(t);(!n||e.p>n.p)&&this.Te.set(t,e)}$e(t,e,n,r){const o=this.Se.me(e),i={data:n,basename:o,siblings:r},s=this.Se.de.indexOf(o);if(-1!==s&&(this.Ne(this.Se.me(t.join("/")),{...i,p:this.Se.de.length+1-s}),!this.Se.he&&!this.Se.pe.has(o)))return;const a=this.Se.me([...t,e].join("/"));for(let t=0;t<this.Se.we.length;++t){const n=this.Se.we[t];e.endsWith(n)&&this.Ne(a.substring(0,a.length-n.length),{...i,p:-t})}}xe(t){this.Ne(this.Se.me(t.join("/")),Xn)}toNormalisedPath(t){return this.Se._e(t)}async find(t,e={},n){const r=this.Te.get(this.Se.me(t.join("/")));if(!r||void 0===r.data)return n?.push(`${JSON.stringify(t.join("/"))} not found in static file paths`),null;if(!this.Se.be)return this.ke(r.data,{canonicalFilename:r.basename,headers:{}},n);for(const t of this.Se.be.options(r.basename,e)){const e=r.siblings.get(this.Se.me(t.filename));if(void 0===e)continue;const o=await this.ke(e,{canonicalFilename:r.basename,headers:t.headers},n);if(o)return o}return null}staticPaths(){return new Set([...this.Te].filter(([t,e])=>e.basename).map(([t])=>t))}}async function Vn(t,e,n,r){const o=new et([]);for(const i of o){const s=await a(A(t,...i),{withFileTypes:!0,encoding:"utf-8"}),c=new Map(s.map(n=>[e.me(n.name),A(t,...i,n.name)]));for(const t of s)if(e.ve(t.name))if(t.isDirectory()){const n=[...i,t.name];r?.(n),i.length<e.ce&&o.push(n)}else t.isFile()&&n(i,t.name,c)}}const Xn={data:void 0,basename:"",siblings:new Map,p:1},Zn=(t,e)=>!["image","video","audio","font"].includes(e.split("/")[0]);async function Yn(t,e,{minCompression:n=0,deleteObsolete:r=!1,matchModifiedTime:o=!0,filter:i=Zn}={}){const a=await c(t),h={file:t,mime:Bn(N(t)),rawSize:a.byteLength,bestSize:a.byteLength,created:0};if(!i(t,h.mime))return h;const d=await s(t);for(const i of e){const e=A(F(t),On(P(t),i.file));if(e===i.file)continue;const s=await In(a,i.value,"max",n);s?(await f(e,s),o&&await u(e,d.atime,d.mtime),h.bestSize=Math.min(h.bestSize,s.byteLength),++h.created):r&&await l(e).catch(()=>{})}return h}async function Kn(t,e,n={}){const r=new Hn(n),o=new Set;await Vn(t,r,(e,n)=>o.add(A(t,...e,n)));for(const t of o)for(const n of e){const e=A(F(t),On(P(t),n.file));e!==t&&o.delete(e)}return Promise.all([...o].map(t=>Yn(t,e,n)))}const Qn=(t,e,n)=>{const r=Xt(t);r.K(e,n??(r.nt?"handling upgrade":"handling request"),t)},tr=(t,{onlyIfRequested:e=!0,emitError:n=!0,forceStatus:r,contentType:o="application/json"}={})=>({handleError:(i,s,a)=>{if(a.hasUpgraded||e&&!er(s,o))throw i;n&&Qn(s,i);const c=qe(a);if(!c)return;const f=ot(i,bt)??new bt(500),u=JSON.stringify(t(f));c.setHeaders(f.headers),c.setHeader("content-type",o),c.setHeader("x-content-type-options","nosniff"),c.setHeader("content-length",String(Buffer.byteLength(u,"utf-8"))),a.response||c.setHeader("connection","close"),r?c.writeHead(r):c.writeHead(f.statusCode,f.statusMessage),c.end(u,"utf-8")},shouldHandleError:(t,n,r)=>!r.hasUpgraded&&(!e||er(n,o))}),er=(t,e)=>an(t.headers.accept)?.some(t=>t.name===e||"application/json"===t.name)??!1;function nr(t,e={}){const n=new Hn(e),r=new Gn(n,async(t,e)=>({handle:await t.open(),stats:t.stat(),filesystemPath:t.filesystemPath,...e})),o=new et({dir:t,path:[]});for(const{dir:t,path:e}of o){const i=new Map([...t.children.entries()].filter(([t,e])=>!e.isDirectory).map(([t,e])=>[n.me(t),e]));for(const[s,a]of t.children)if(!a.virtual&&n.ve(s))if(a.isDirectory){const t=[...e,s];r.xe(t),e.length<n.ce&&o.push({dir:a,path:t})}else r.$e(e,s,a,i)}return r}const rr=/*@__PURE__*/hn(async t=>{const e=se(t);if(e.aborted)throw ce;e.throwIfAborted();const n=await h(A(L(),"upload"));ie(t,()=>l(n,{recursive:!0}));let r=0;const o=()=>{if(e.aborted)throw ce;return A(n,(++r).toString(10).padStart(6,"0"))};return{dir:n,nextFile:o,save:async(t,{mode:n=384}={})=>{const r=o(),i=S(r,{mode:n});try{return await k(t,i,{signal:e}),{path:r,size:i.bytesWritten}}finally{i.close()}}}});function or(t,...e){const n=e.filter(t=>t);if(1===n.length&&"function"==typeof n[0])return n[0]();const r=new j(t);let o=0;const i=()=>{const t=n[o++];if("function"==typeof t){const e=t();e.pipe(r,{end:!1}),e.once("end",i),e.once("error",t=>r.destroy(t))}else t?r.write(t,i):r.end()};return i(),r}class ir extends Error{constructor(t,e){super(`${t} is not a valid zip archive: ${e}`)}}async function sr(t){const e=new ft(t,r.O_RDONLY),n=await e.open();try{const r=(await n.stat()).size,o=Math.max(r-65535-22-20,0);let i;const s=async(e,s)=>{if(e<0||e>r||e+s>r)throw new ir(t,`byte range ${e}-${e+s} is not within 0-${r}`);if(e>=o&&i)return new Uint8Array(i.buffer,i.byteOffset+e-o,s);const a=new Uint8Array(s),{bytesRead:c}=await n.read(a,0,s,e);if(c!==s)throw new ir(t,"modified while reading");return a};i=await s(o,r-o);const a=i.byteLength,c=Math.min(65535,a-22);let f=-1;for(let t=0;t<c;++t)if(hr(i,a-t-2)===t&&1347093766===yr(i,a-t-22)){f=t;break}if(-1===f)throw new ir(t,"no EOCD found");const u=r-f-22,l=pr(i,u-o,22);let h=hr(l,10),d=dr(l,12),w=dr(l,16);if((65535===h||4294967295===d||4294967295===w)&&u>=o+20){const e=pr(i,u-o-20,20);if(1347094023!==yr(e,0))throw new ir(t,"missing EOCDL in 64-bit zip");const n=wr(e,8),r=await s(n,56);if(1347094022!==yr(r,0))throw new ir(t,"EOCD64 is invalid");h=wr(r,32),d=wr(r,40),w=wr(r,48)}const p=new ar(t,[]),m=await s(w,d);let y=0;for(let n=0;n<h;++n){if(1347092738!==yr(m,y))throw new ir(t,`missing CDFH for record #${n+1} at 0x${y.toString(16)}`);const o=hr(m,y+8),i=Boolean(1024&o),a=hr(m,y+10);if(0!==a&&8!==a)throw new ir(t,`unsupported compression type: ${a}`);let c=lr(hr(m,y+12),hr(m,y+14));const f=dr(m,y+16);let u=dr(m,y+20),l=dr(m,y+24);const h=hr(m,y+28),d=hr(m,y+30),w=hr(m,y+32);let g=dr(m,y+42);const b=pr(m,y+46,h);let v=i?mr(b):[...b].map(t=>fr[t]).join("");const _=pr(m,y+46+h,d);y+=46+h+d+w;for(let t=0;t<d;){const e=hr(_,t+2),n=pr(_,t+4,e);switch(hr(_,t)){case 1:{let t=0;4294967295===l&&(l=wr(n,t),t+=8),4294967295===u&&(u=wr(n,t),t+=8),4294967295===g&&(g=wr(n,t),t+=8);break}case 21589:1&n[0]&&(c=1e3*dr(n,1));break;case 28789:v=mr(pr(n,5,n.byteLength-5))}t+=e+4}if(v.startsWith("__MACOSX/"))continue;const E=v.split("/");if(!E[E.length-1]){p.Re(new ar(t,E.slice(0,E.length-1)));continue}const S=await s(g,30);if(1347093252!==yr(S,0))throw new ir(t,`invalid local header for ${v}`);const $=30+hr(S,26)+hr(S,28);if(g<0||g+$+u>r)throw new ir(t,`invalid location for ${v}`);const x={Oe:g+$,Ae:u,Pe:l,Fe:c,Me:f};if(8===a){p.Re(new cr(e,E,x,!0,!1));const t=[...E];t[t.length-1]+=".deflate-raw",p.Re(new cr(e,t,x,!1,!0));const n=[...E];n[n.length-1]+=".gz";const r=Buffer.alloc(8);r.writeUint32LE(f,0),r.writeUint32LE(l>>>0,4),p.Re(new cr(e,n,x,!1,!0,[ur,r]))}else p.Re(new cr(e,E,x,!1,!1))}return p}finally{await n.close()}}class ar{constructor(t,e){this.zipFilePath=t,this.k=e,this.children=new Map}get isDirectory(){return!0}get virtual(){return!1}get filesystemPath(){return A(this.zipFilePath,...this.k)}Re(t){const e=t.k;let n=this;for(let r=0;r<e.length-1;++r){const o=e[r];let i=n.children.get(o);if(!i||i.virtual)i=new ar(this.zipFilePath,e.slice(0,r+1)),n.children.set(o,i);else if(!i.isDirectory){if(t.virtual)return;throw new ir(this.zipFilePath,`mix of file and directory at ${e.join("/")}`)}n=i}const r=e[e.length-1],o=n.children.get(r);if(o&&!o.virtual){if(t.virtual)return;throw o.isDirectory!==t.isDirectory?new ir(this.zipFilePath,`mix of file and directory at ${e.join("/")}`):new ir(this.zipFilePath,`duplicate file/directory at ${e.join("/")}`)}n.children.set(r,t)}*allFiles(t=[]){for(const[e,n]of this.children)n.isDirectory?yield*n.allFiles([...t,e]):yield{path:[...t,e],node:n}}find(t){let e=this;for(const n of t){if(!e.isDirectory)return;const t=e.children.get(n);if(!t)return;e=t}return e}}class cr{constructor(t,e,n,r,o,i){this.k=e,this.Ce=t,this.Ue=n,this.Be=r,this.virtual=o,this.De=i}get isDirectory(){return!1}get zipFilePath(){return this.Ce.path}meta(){return{p:this.Ue.Oe,z:this.Be,s:this.Ue.Ae}}get filesystemPath(){return A(this.Ce.path,...this.k)}get crc32(){return this.Ue.Me}ze(){return this.Ue.Ae+(this.De?this.De[0].byteLength+this.De[1].byteLength:0)}stat({bigint:t=!1}={}){const e=e=>t?BigInt(e):e,n={isFile:()=>!0,mode:e(33060),size:e(this.Be?this.Ue.Pe:this.ze()),mtimeMs:e(this.Ue.Fe),mtime:new Date(this.Ue.Fe)};return new Proxy({},{get:(t,r)=>n[r]??("string"!=typeof r?void 0:r.startsWith("is")?()=>!1:r.endsWith("time")?new Date(0):r.endsWith("Instant")?void 0:e(0))})}async open(){const t=this.ze(),e=t=>Promise.resolve(this.stat(t));if(!t)return{noRandomAccess:this.Be,createReadStream:({start:t=0,end:e,...n}={})=>{if(0!==t)throw new RangeError(`invalid byte range ${t}-${e}`);return or({...n,encoding:n.encoding??void 0})},stat:e,close:()=>Promise.resolve(),[Symbol.asyncDispose]:()=>Promise.resolve()};const n=await this.Ce.open(),r=this.Ue.Ae,o=(t,e,o)=>rt(n,{...o,start:this.Ue.Oe+Math.max(t,0),end:this.Ue.Oe+Math.min(e,r-1)});return{noRandomAccess:this.Be,createReadStream:({start:e=0,end:n=t-1,...i}={})=>{if(this.Be){if(0!==e)throw new RangeError("start offset must be 0 for compressed files");const n=o(0,t-1,{...i,highWaterMark:void 0,encoding:void 0}).compose(I({chunkSize:i.highWaterMark}));return i.encoding&&n.setEncoding(i.encoding),n}if(e<0||n<e||n>=t)throw new RangeError(`invalid byte range ${e}-${n}`);const s=this.De,a=s?s[0].byteLength:0,c=a+r;return or({...i,encoding:i.encoding??void 0},s&&e<a?s[0].subarray(e,n+1):null,e<c&&n>=a&&r?()=>o(e-a,n-a,i):null,s&&n>=c?s[1].subarray(Math.max(e-c,0),n+1-c):null)},stat:e,close:n.close,[Symbol.asyncDispose]:n.close}}}const fr="\0\u263a\u263b\u2665\u2666\u2663\u2660\u2022\u25d8\u25cb\u25d9\u2642\u2640\u266a\u266b\u263c\u25ba\u25c4\u2195\u203c\xb6\xa7\u25ac\u21a8\u2191\u2193\u2192\u2190\u221f\u2194\u25b2\u25bc !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u2302\xc7\xfc\xe9\xe2\xe4\xe0\xe5\xe7\xea\xeb\xe8\xef\xee\xec\xc4\xc5\xc9\xe6\xc6\xf4\xf6\xf2\xfb\xf9\xff\xd6\xdc\xa2\xa3\xa5\u20a7\u0192\xe1\xed\xf3\xfa\xf1\xd1\xaa\xba\xbf\u2310\xac\xbd\xbc\xa1\xab\xbb\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255d\u255c\u255b\u2510\u2514\u2534\u252c\u251c\u2500\u253c\u255e\u255f\u255a\u2554\u2569\u2566\u2560\u2550\u256c\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256b\u256a\u2518\u250c\u2588\u2584\u258c\u2590\u2580\u03b1\xdf\u0393\u03c0\u03a3\u03c3\xb5\u03c4\u03a6\u0398\u03a9\u03b4\u221e\u03c6\u03b5\u2229\u2261\xb1\u2265\u2264\u2320\u2321\xf7\u2248\xb0\u2219\xb7\u221a\u207f\xb2\u25a0\xa0",ur=/*@__PURE__*/Buffer.from([31,139,8,0,0,0,0,0,0,255]),lr=(t,e)=>Date.UTC(1980+(e>>>9&127),(e>>>5&15)-1,e>>>0&31,t>>>11&31,t>>>5&63,(t>>>0&31)<<1,0),hr=(t,e)=>t[e+1]<<8|t[e],dr=(t,e)=>(t[e+3]<<24|t[e+2]<<16|t[e+1]<<8|t[e])>>>0,wr=(t,e)=>(t=>{if(t>Number.MAX_SAFE_INTEGER||t<Number.MIN_SAFE_INTEGER)throw new RangeError(`unsupported size (limited to ${Number.MAX_SAFE_INTEGER})`);return Number(t)})(BigInt(dr(t,e+4))<<32n|BigInt(dr(t,e))),pr=(t,e,n)=>new Uint8Array(t.buffer,t.byteOffset+e,n),mr=t=>new TextDecoder("utf-8").decode(t),yr=(t,e)=>(t[e]<<24|t[e+1]<<16|t[e+2]<<8|t[e+3])>>>0,gr=(t,e)=>e instanceof Error&&"ERR_STREAM_PREMATURE_CLOSE"===e.code&&t.closed;function br(t){const e=Xt(t);if(!e.ot)throw new TypeError("cannot call acceptBody from shouldUpgrade");if(e.Y.signal.aborted)throw ce;e.qt&&(e.qt=!1,e.ot.it.writeContinue())}function vr(t){const e=Xt(t);return!e.Y.signal.aborted&&!e.qt}function _r(t,{blockRequestHeaders:e=[],requestHeaders:n=[],blockResponseHeaders:r=[],responseHeaders:o=[],agent:i,...s}={}){const a=new URL(t);let c;"https:"===a.protocol?(i??=new G({keepAlive:!0,...s}),c=v):(i??=new b({keepAlive:!0,...s}),c=V);const f=a.pathname,u=f+(f.endsWith("/")?"":"/"),l="a://a"+u;return Te((t,s)=>new Promise((h,d)=>{if(s.closed||!s.writable)return d(ce);const w=se(t),p=t=>d(w.aborted?ce:new bt(502,{cause:t})),m=new URL(l+t.url?.substring(1));if(!m.pathname.startsWith(u)&&m.pathname!==f)return d(new bt(400,{message:"directory traversal blocked"}));br(t);let y={...t.headers};Er(y,e),delete y.host,y.expect&&Sr.test(y.expect)&&delete y.expect;for(const e of n)y=e(t,y);const g=c(a,{agent:i,path:m.pathname+m.search,method:t.method,headers:y,signal:w});g.once("error",p),g.once("response",e=>{if(s.closed||!s.writable)return d(ce);if(!s.headersSent){let n={...e.headers};Er(n,r);for(const r of o)n=r(t,e,n);s.writeHead(e.statusCode??200,e.statusMessage,n)}k(e,s).then(h,t=>d(gr(s,t)?ce:t))}),k(t,g).catch(p)}))}function Er(t,e){for(const e of on(t.connection)??[])be(t,e.toLowerCase());for(const e of $r)be(t,e);for(const n of e)be(t,n)}const Sr=/(?:^|\W)100-continue(?:$|\W)/i,$r=["connection","keep-alive","proxy-authenticate","proxy-authorization","te","trailer","transfer-encoding","upgrade"];function xr({trustedProxyCount:t,trustedProxyAddresses:e,trustedHeaders:n}){const r=e?Z(e):()=>!0,o=t??(e?Number.POSITIVE_INFINITY:0),i=new Set(n);return hn(t=>{const e=e=>{if(i.has(e))return on(t.headers[e])?.reverse()},n=e("forwarded"),s=e("x-forwarded-for"),a=e("x-forwarded-host"),c=e("x-forwarded-proto"),f=e("x-forwarded-protocol"),u=e("x-url-scheme"),l=e("via")?.map(t=>{const e=/^([^/ ]+\/)?([^/ ]+) (.+)$/.exec(t);return e?.[3]?X(e[3]):void 0}),h=[Tr(t)];if(n)for(const t of n)try{const e=cn(t);h.push({client:X(e.get("for")),server:X(e.get("by")),host:e.get("host"),proto:e.get("proto")})}catch{h.push({client:void 0,server:void 0,host:void 0,proto:void 0})}else if(s){const t=s.map(X),e=a??[],n=c??f??u??[];let r=h[0].client;for(let o=0;o<t.length;++o){const i=t[o];h.push({client:i,server:l?.[o]??(r?{...r,port:void 0}:void 0),host:e[o],proto:n[o]}),r=i}}else if(l)for(const t of l)h.push({client:void 0,server:t,host:void 0,proto:void 0});let d=Math.min(1+o,h.length);for(let t=0;t<d-1;++t)r(h[t].client)||(d=t+1);return Object.freeze({trusted:h.slice(0,d),untrusted:h.slice(d),outwardChain:h,edge:h[d-1]})})}const Tr=t=>({client:{...X(t.socket.remoteAddress)??kr,port:t.socket.remotePort},server:{...X(t.socket.localAddress)??kr,port:t.socket.localPort},host:t.headers.host,proto:t.socket.encrypted?"https":"http"}),kr={family:"alias",address:"_disconnected",port:void 0};function Nr(t,e){return delete e.forwarded,delete e["x-forwarded-for"],delete e["x-forwarded-host"],delete e["x-forwarded-proto"],delete e["x-forwarded-protocol"],delete e["x-url-scheme"],delete e.via,e}function Rr(t,e){const n=Nr(0,e);return n.forwarded=Pr([Tr(t)]),n}const Or=(t,{onlyTrusted:e=!1}={})=>(n,r)=>{const o=Nr(0,r),i=t(n);return o.forwarded=Pr([...e?i.trusted:i.outwardChain].reverse()),o};function Ar(t,e){let n=t.headers.forwarded;const r=Pr([Tr(t)]);n?n+=", "+r:n=r;const o=Nr(0,e);return o.forwarded=n,o}function Pr(t){return t.filter(t=>t.server||t.client).map(t=>Object.entries({for:t.client?.address,by:t.server?.address,host:t.host,proto:t.proto}).filter(([t,e])=>e).map(([t,e])=>e&&/[^a-zA-Z0-9._]/.test(e)?`${t}="${e.replaceAll("\\","\\\\").replaceAll('"','\\"').replaceAll(",","-")}"`:`${t}=${e}`).join("; ")).join(", ")}function Fr(t,e,n){const r=fn(t.headers["if-modified-since"]),o=on(t.headers["if-none-match"]);if(o){if(Cr(e,n,o))return!1}else if(n&&r&&(n.mtimeMs/1e3|0)<=r)return!1;return!0}function Mr(t,e,n){let r=!0;const o=nn(t);return o.etag&&(r&&=Cr(e,n,o.etag)),o.modifiedSeconds&&(r&&=(n.mtimeMs/1e3|0)===o.modifiedSeconds),r}function Cr(t,e,n){if(n.includes("*"))return!0;const r=t.getHeader("etag");if("string"==typeof r){if(n.includes(r))return!0;if(r.startsWith('W/"'))return!1}return!(!e||!n.some(t=>t.startsWith('W/"')))&&n.includes(En(t.getHeader("content-encoding"),e))}class Ur extends d{constructor(t,e){super({transform(r,o){n+=r.byteLength,n>t?o.error(e):o.enqueue(r)}});let n=0}}function Br(t,{maxContentBytes:e=Number.POSITIVE_INFINITY,maxNetworkBytes:n=e,maxEncodingSteps:r=1}={}){const o=sn(t.headers["content-length"]);if(void 0!==o&&o>n)throw new bt(413);const i=on(t.headers["content-encoding"])??[];if(i.length>r)throw new bt(415,{body:"too many content-encoding stages"});br(t);let s=H.toWeb(t);void 0===o&&Number.isFinite(n)&&(s=s.pipeThrough(new Ur(n,new bt(413))));for(const t of i.reverse())s=s.pipeThrough(Hr(t));return Number.isFinite(e)&&(s=s.pipeThrough(new Ur(e,new bt(413,{body:"decoded content too large"})))),s}function Dr(t,e={}){const n=Br(t,e),r=en(t)??e.defaultCharset??"utf-8";return n.pipeThrough(xt(r,e))}async function zr(t,e={}){let n="";for await(const r of Dr(t,e))n+=r;return n}async function Ir(t,e={}){const n=await(async(t,e)=>{const n=t.getReader(),r=new Uint8Array(4);r[0]=1;let o=0,i=null;for(;;){const t=await n.read(),e=4-o;if(t.done){o<3&&(o<2&&(r[1]=r[0]),r[2]=r[0]),r[3]=r[1],i=null;break}if(i=t.value,i.byteLength>=e){r.set(i.subarray(0,e),o);break}r.set(i,o),o+=i.byteLength}const s=Tt[(r[0]?8:0)|(r[1]?4:0)|(r[2]?2:0)|(r[3]?1:0)];if(!s)throw n.cancel(),new bt(415,{body:"invalid JSON encoding"});const a=xt(s,e),c=a.writable.getWriter();return o&&c.write(r.subarray(0,o)),i&&c.write(i),n.releaseLock(),c.releaseLock(),t.pipeThrough(a)})(Br(t,e),e);let r="";for await(const t of n)r+=t;try{return JSON.parse(r,e.reviver)}catch(t){throw new bt(400,{body:"invalid JSON",cause:t})}}function Hr(t){switch(t.toLowerCase()){case"gzip":case"x-gzip":return new p("gzip");case"deflate":return new p("deflate");case"br":try{return new p("brotli")}catch{return q.toWeb(M.createBrotliDecompress())}case"zstd":try{return q.toWeb(M.createZstdDecompress())}catch{throw new bt(415,{body:"unsupported content encoding"})}default:throw new bt(415,{body:"unknown content encoding"})}}class jr{constructor(t,e,n){const r=t.byteLength;if(!r||r>65535)throw new RangeError("invalid needle");this.Ie=t,this.He=e,this.je=n,this.qe=null,this.Je=0,this.Le=null}push(t){let e=0;const n=t.byteLength,r=this.Ie,o=r.byteLength-1,i=n-o;let s=-this.Je;if(this.Je){const a=this.Le,c=this.qe,f=r[o];if(s<i){const n=t[s+o];n!==f||t.compare(r,-s,o,0,s+o)?s+=a[n]:(this.je(),this.Je=0,e=s+=o+1)}const u=i<0?i:0;for(;s<u;){const n=t[s+o];if(n===f&&!c.compare(r,0,-s,this.Je+s,this.Je)&&!t.compare(r,-s,o,0,s+o)){this.He(c,0,this.Je+s,!1),this.je(),this.Je=0,e=s+=o+1;break}s+=a[n]}const l=this.Je;if(l>0){const e=r[0];for(;s<0;){const o=c.subarray(0,l).indexOf(e,l+s);if(-1===o){s=0;break}const i=l-o;if(!c.compare(r,1,i,o+1,l)&&!t.compare(r,i,i+n))return o&&(this.He(c,0,o,!1),c.copy(c,0,o,i)),c.set(t,i),void(this.Je+=n-o);s=o+1-l}this.He(c,0,l,!1),this.Je=0}}for(;s<i;){const n=t.indexOf(r,s);if(-1!==n){if(n>e&&this.He(t,e,n,!0),this.je(),n===i+1)return;e=s=n+o+1}else s=i}const a=r[0];for(;s<n;){const i=t.indexOf(a,s);if(-1===i)return void this.He(t,e,n,!0);if(!t.compare(r,1,n-i,i+1)){if(!this.qe){this.qe=Buffer.allocUnsafe(o),this.Le=new Uint16Array(256).fill(o+1);for(let t=0;t<o;++t)this.Le[r[t]]=o-t}return t.copy(this.qe,0,i),this.Je=n-i,void(i>e&&this.He(t,e,i,!0))}s=i+1}n>e&&this.He(t,e,n,!0)}destroy(){const t=this.Je;t&&this.qe&&this.He(this.qe,0,t,!1),this.Je=0}}class qr{constructor(t){this.He=t,this.reset()}reset(){this.H=[],this.We=16384,this.m=0,this.Ge="",this.Ve=void 0}push(t,e,n){let r=e,o=e;const i=Math.min(n,e+this.We);for(;o<i;)switch(this.m){case 0:for(;o<i&&Rt[t[o]];++o);if(o>r&&(this.Ge+=t.latin1Slice(r,o)),o<i){if(58!==t[o])return-1;if(!this.Ge)return-1;++o,this.Ve=Gr.get(this.Ge.toLowerCase()),this.Ge="",this.m=1}break;case 1:for(;o<i;++o){const e=t[o];if(32!==e&&9!==e){r=o,this.m=2;break}}break;case 2:for(;o<i;++o){const e=t[o];if(e<32||127===e){if(13!==e)return-1;this.m=3;break}}this.Ve&&(this.Ge+=t.latin1Slice(r,o)),++o;break;case 3:if(10!==t[o++])return-1;this.m=4;break;case 4:{const e=t[o];if(32===e||9===e)r=o,this.m=2;else{if(this.Ve){const t=this.Ve.Xe;void 0===this.H[t]?this.H[t]=this.Ge:this.Ve.Ze&&(this.H[t]+=","+this.Ge)}13===e?(this.m=5,++o):(r=o,this.m=0,this.Ge="",this.Ve=void 0)}break}case 5:{if(10!==t[o++])return-1;const e=this.H;return this.reset(),this.He(e),o}}return i<n?-1:(this.We-=i-e,i)}}const Jr=0,Lr=1,Wr=2,Gr=new Map([["content-type",{Xe:Jr,Ze:!1}],["content-disposition",{Xe:Lr,Ze:!1}],["content-transfer-encoding",{Xe:Wr,Ze:!0}]]);function Vr(t){const e=this.Ye;e&&(this.Ye=void 0,e())}const Xr=/*@__PURE__*/Buffer.from("\r\n"),Zr=()=>{},Yr=37,Kr=43,Qr=/*@__PURE__*/new Uint8Array(256);function to(t,e={}){const n=t["content-type"];if(!n)throw new bt(400,{body:"missing content-type"});const r=kt(n);if(!r)throw new bt(400,{body:"malformed content-type"});const o=sn(t["content-length"]);if(void 0!==o&&void 0!==e.maxNetworkBytes&&o>e.maxNetworkBytes)throw new bt(413,{body:"content too large"});if("application/x-www-form-urlencoded"===r.mime)return(({defCharset:t="utf-8",maxNetworkBytes:e=Number.POSITIVE_INFINITY,maxContentBytes:n=e,maxFieldSize:r=1048576,maxFieldNameSize:o=100,maxFields:i=Number.POSITIVE_INFINITY},s)=>{const a=s.get("charset")??t,c=/^utf-?8$/i.test(a)?1:/^(latin-?1|iso[\-_]?8859-?1|(us-)?ascii)$/i.test(a)?2:0,f=$t(a);return(t,s)=>new Promise((u,l)=>{let h=e,d=n,w=i,p=!0,m="",y=Math.min(o,d),g=0,b="",v=-2;const _=()=>{const t=!c||1===c&&8&g?f.decode(Buffer.from(m,"latin1")):m;if(p){if(y<0)return $(new bt(413,{body:`field name ${JSON.stringify(t)}... too long`})),!1;t&&s({name:t,type:"string",value:"",encoding:a,mimeType:"text/plain"})}else{if(y<0)return $(new bt(413,{body:`value for ${JSON.stringify(b)} too long`})),!1;s({name:b,type:"string",value:t,encoding:a,mimeType:"text/plain"})}return!0},E=t=>{if(!t.byteLength)return;if((h-=t.byteLength)<0)return $(new bt(413,{body:"content too large"}));if(!w)return $(new bt(413,{body:"too many fields"}));const e=t.byteLength;let n=0,i=v;if(-2!==i){if(-1===i){if(16===(i=Ft[t[n++]]))return $(new bt(400,{body:"malformed urlencoded form"}));if(g|=i,n===e)return void(v=i)}const r=Ft[t[n++]];if(16===r)return $(new bt(400,{body:"malformed urlencoded form"}));if(m+=String.fromCharCode((i<<4)+r),v=-2,n===e)return}for(Qr[37]=1,Qr[38]=1,Qr[43]=1,Qr[61]=p?1:0;;){const i=n;for(;n<e&&!Qr[t[n]];++n);if(n>i&&y>=0&&((y-=n-i)<0?m+=t.latin1Slice(i,n+y):(d-=n-i,m+=t.latin1Slice(i,n))),n===e)return;switch(t[n++]){case Yr:for(;;){if(--y<0){Qr[37]=0,Qr[43]=0;break}if(--d,n===e){v=-1;break}const r=Ft[t[n++]];if(16===r)return $(new bt(400,{body:"malformed urlencoded form"}));if(g|=r,n===e)return void(v=r);const o=Ft[t[n++]];if(16===o)return $(new bt(400,{body:"malformed urlencoded form"}));if(m+=String.fromCharCode((r<<4)+o),n===e)return;if(t[n]!==Yr)break;n++}break;case 38:if(!_())return;if(b="",p=!0,Qr[61]=1,Qr[37]=1,Qr[43]=1,m="",y=Math.min(o,d),g=0,! --w)return $(new bt(413,{body:"too many fields"}));break;case Kr:--y<0?(Qr[37]=0,Qr[43]=0):(--d,m+=" ");break;case 61:if(b=!c||1===c&&8&g?f.decode(Buffer.from(m,"latin1")):m,y<0)return $(new bt(413,{body:`field name ${JSON.stringify(b)}... too long`}));p=!1,Qr[61]=0,Qr[37]=1,Qr[43]=1,m="",g=0,y=Math.min(r,d)}if(n===e)return}},S=()=>{if(-2!==v)return $(new bt(400,{body:"malformed urlencoded form"}));_()&&(t.off("data",E),t.off("end",S),t.off("error",$),u())},$=e=>{t.off("data",E),t.off("end",S),t.off("error",$),l(e)};t.on("data",E),t.once("end",S),t.once("error",$)})})(e,r.params);if("multipart/form-data"===r.mime&&!e.blockMultipart)return function({preservePath:t,fileHwm:e,defParamCharset:n="utf-8",defCharset:r="utf-8",maxNetworkBytes:o=Number.POSITIVE_INFINITY,maxContentBytes:i=o,maxFieldSize:s=1048576,maxFileSize:a=Number.POSITIVE_INFINITY,maxTotalFileSize:c=Number.POSITIVE_INFINITY,maxFieldNameSize:f=100,maxParts:u=Number.POSITIVE_INFINITY,maxFields:l=Number.POSITIVE_INFINITY,maxFiles:h=Number.POSITIVE_INFINITY},d){const w=d.get("boundary");if(!w)throw new bt(400,{body:"multipart boundary not found"});if(w.length>70)throw new bt(400,{body:"multipart boundary too long"});const p=$t(n),m={autoDestroy:!0,emitClose:!0,highWaterMark:e,read:Vr};return(e,n)=>new Promise((d,y)=>{let g,b,v,_,E,S,$,x=5,T=o,k=i,N=c,R=u,O=l,A=h,P=0,F=!1,M=0,C="";const U=new qr(e=>{const o=e[Lr];if(!o)return void(x=5);const i=((t,e)=>{if(!t.byteLength)return null;const n=new Map;let r=0;for(;r<t.byteLength;++r)if(!Rt[t[r]]){if(!Nt(t,r,n,e))return null;break}return{type:t.latin1Slice(0,r).toLowerCase(),params:n}})(Buffer.from(o,"latin1"),p);if("form-data"!==i?.type)return void(x=5);if(v=i.params.get("name"),void 0===v)return j(new bt(400,{body:"missing field name"}));const c=Buffer.byteLength(v,"utf-8"),u=Math.min(f,k);if(c>u)return j(new bt(413,{body:`field name ${JSON.stringify(v.substring(0,u))}... too long`}));k-=c,_=i.params.get("filename*")??i.params.get("filename");const l=kt(e[Jr]);if(E=l?.mime??"text/plain",S=e[Wr]?.toLowerCase()??"7bit","application/octet-stream"===E||void 0!==_){if(!A--)return j(new bt(413,{body:"too many files"}));if(!_)return void(x=5);t||(_=(t=>{for(let e=t.length;e-- >0;)if("/"===t[e]||"\\"===t[e]){t=t.slice(e+1);break}return".."===t||"."===t?"":t})(_));const e=new H(m);e.once("error",Zr),e.once("close",()=>{e.Ye?.(),e.off("error",Zr),! --M&&b&&process.nextTick(b)}),g=e,++M,P=Math.min(a,N,k,T),n({name:v,type:"file",value:e,filename:_,encoding:S,mimeType:E,sizeLimit:P}),x=4}else{if(!O--)return j(new bt(413,{body:"too many fields"}));x=4,P=Math.min(s,k,T);const t=l?.params.get("charset")?.toLowerCase()??r;$=$t(t)}}),B=Buffer.from(`\r\n--${w}`,"latin1"),D=new jr(B,(t,n,r,o)=>{if(x<=2){if(0===x){if(13===t[n])x=1;else{if(45!==t[n])return void(x=5);x=2}if(++n===r)return}if(1!==x)return 45!==t[n]?void(x=5):(x=6,e.off("data",z),void e.resume());if(10!==t[n++])return void(x=5);if(!R--)return j(new bt(413,{body:"too many parts"}));if(x=3,n===r)return}if(3===x){if(-1===(n=U.push(t,n,r)))return j(new bt(400,{body:"malformed part header"}));if(n===r)return}if(4===x){const e=Math.min(r,n+P);if(P-=r-n,k-=r-n,g){if(N-=r-n,e>n){let r;r=o?t.subarray(n,e):Buffer.copyBytesFrom(t,n,e-n),g.push(r)||(F=!0)}if(P<0)return j(new bt(413,{body:`uploaded file for ${JSON.stringify(v)}: ${JSON.stringify(_)} too large`}))}else{if(P<0)return j(new bt(413,{body:`value for ${JSON.stringify(v)} too long`}));C+=t.latin1Slice(n,e)}}},()=>{if(3===x)return j(new bt(400,{body:"unexpected end of headers"}));if(4===x)if(g)g.push(null),g=void 0,F=!1;else{const t=Buffer.from(C,"latin1");C="",n({name:v,type:"string",value:$.decode(t),encoding:S,mimeType:E})}x<6&&(x=0)});D.push(Xr);const z=t=>{if((T-=t.byteLength)<0)return j(new bt(413,{body:"content too large"}));F=!1,D.push(t),g&&F&&(e.pause(),g.Ye=()=>e.resume())},I=()=>{if(7!==x){if(6!==x&&(D.destroy(),6!==x))return j(new bt(400,{body:"unexpected end of form"}));e.off("data",z),e.off("end",I),b=()=>{e.off("error",j),d()},M||b()}},j=t=>{7!==x&&(x=7,e.off("data",z),e.off("end",I),e.off("error",j),g?.destroy(t),g=void 0,y(t))};e.on("data",z),e.once("end",I),e.once("error",j)})}(e,r.params);throw new bt(415)}function eo(t,{closeAfterErrorDelay:e=500,...n}={}){tt(e,"closeAfterErrorDelay",!0);const r=()=>{if(e>=0&&t.readable){const n=setTimeout(()=>t.socket.destroy(),e);t.once("end",()=>clearTimeout(n))}};try{const e=to(t.headers,n);br(t);const o=new nt;return e(t,t=>o.push(t)).then(()=>o.close("complete"),e=>{o.fail(t.readableAborted?ce:e),t.resume(),r()}),o}catch(e){throw vr(t)&&(t.resume(),r()),e}}async function no(t,e={}){const n=new FormData,r=new Map;for await(const o of eo(t,e))if("file"===o.type){const i=o.value;let s=await(e.preCheckFile?.({fieldName:o.name,filename:o.filename,encoding:o.encoding,mimeType:o.mimeType,maxBytes:o.sizeLimit}));const a=t=>{if("function"==typeof s){const e=s;return s=void 0,e({actualBytes:t})}};ie(t,()=>a(0));const c=await rr(t),f=await c.save(i,{mode:384});await a(f.size);const u=new File([await $(f.path)],o.filename,{type:o.mimeType});r.set(u,f.path),n.append(o.name,u)}else{let t=o.value;e.trimAllValues&&(t=t.trim()),n.append(o.name,t)}return Object.assign(n,{getTempFilePath(t){const e=r.get(t);if(!e)throw new RangeError("unknown file");return e},getBoolean(t){const e=n.get(t);return null===e?null:"true"===e||"on"===e},getString(t){const e=n.get(t);return"string"==typeof e?e:null},getAllStrings:t=>n.getAll(t).filter(t=>"string"==typeof t),getFile(t){const e=n.get(t);return"string"==typeof e?null:e},getAllFiles:t=>n.getAll(t).filter(t=>"string"!=typeof t)})}const ro="win32"===/*@__PURE__*/W();function oo(t,{rejectPotentiallyUnsafe:e=!0}={}){let n=[];const r=Gt(t);if(r&&!r.rt){if("/"===r.Z)return[];n=r.Z.split("/")}else{const e=r?.rt??Mt(t).pathname;if("/"===e)return[];n=e.split("/").map(decodeURIComponent)}if(""!==n[0])throw new bt(400,{body:"invalid path"});if(n.shift(),e){const t=ro?so:io;if(n.some(e=>t.test(e)||e.includes(R)))throw new bt(400,{body:"invalid path"});if(n.slice(0,n.length-1).includes(""))throw new bt(400,{body:"invalid path"})}return n}const io=/[\x00-\x1F\x7F/]|^(\.\.?|~)$/,so=/[\x00-\x1F"*/:<>?\\|\x7F]|^[\s.]*$|^(CON|PRN|AUX|NUL|(COM|LPT)[\d\xB9\xB2\xB3])(\.|$)/i;class ao{constructor(t){this.load=t}}const co=t=>new ao(t);function fo(t){if(t&&("object"==typeof t||"function"==typeof t)){if(t instanceof H)return void t.destroy();if(t instanceof m)return t.cancel();if(Symbol.dispose&&"function"==typeof t[Symbol.dispose])return void t[Symbol.dispose]();if(Symbol.asyncDispose&&"function"==typeof t[Symbol.asyncDispose])return t[Symbol.asyncDispose]();if("function"==typeof t.return){const e=t.return();return e instanceof Promise?e:void 0}}}const uo=/*@__PURE__*/lo("accelerometer,attribution-reporting,autoplay,bluetooth,browsing-topics,camera,cross-origin-isolated,deferred-fetch-minimal,deferred-fetch,display-capture,encrypted-media,fullscreen,gamepad,geolocation,gyroscope,identity-credentials-get,idle-detection,language-detector,microphone,midi,otp-credentials,payment,picture-in-picture,private-state-token-issuance,private-state-token-redemption,publickey-credentials-create,publickey-credentials-get,screen-wake-lock,serial,storage-access,translator,usb,web-share,window-management,xr-spatial-tracking");function lo(...t){const e=new Map;for(const n of t){const t=/ *([^,= ]+) *(?:= *((?:[^,"]|"(?:[^\\"]|\\.)*")*))?(,|$)/gy;for(;t.lastIndex<n.length;){const r=t.exec(n);if(!r)throw new Error(`invalid policy syntax: ${n}`);const o=r[1],i=r[2]??"",s=e.get(o)??new Set,a=/([^" ]+|"(?:[^"\\]|\\.)*")(?: +|$)/gy;for(;a.lastIndex<i.length;){const t=a.exec(i);if(!t)throw new Error(`invalid policy syntax: ${o}=${i}`);s.add(t[1])}e.set(o,s)}}const n=[];for(const[t,r]of e)r.delete("()"),n.push(`${t}=${r.has("*")?"*":[...r].join(" ")||"()"}`);return n.join(",")}const ho=t=>new Promise(e=>{if(!t.writable)return e();const n=()=>{t.off("close",n),t.off("drain",n),t.cork(),e()};t.once("close",n),t instanceof _?t.write(ut,n):t.once("drain",n),t.uncork()});async function wo(t,e,{delimiter:n=",",newline:r="\n",quote:o='"',encoding:i="utf-8",headerRow:s,end:a=!0}={}){if(!t.writable)return;"string"==typeof n&&(n=Buffer.from(n,i)),"string"==typeof r&&(r=Buffer.from(r,i));const c="string"==typeof o?Buffer.from(o,i):o,f=o+o,u=e=>{if(!e||!t.writable)return!0;if("string"==typeof e){const n=e.includes(o);return!n&&po.test(e)?t.write(e,i)||ho(t):(t.write(c),n?t.write(e.replaceAll(o,f),i):t.write(e,i),t.write(c)||ho(t))}return(async()=>{t.write(c);for await(const n of e){if("string"!=typeof n)throw new TypeError("Readables must have an encoding");if(!t.writable)break;t.write(n.replaceAll(o,f),i)||await ho(t)}t.write(c)})()};t instanceof _&&!t.headersSent&&!t.hasHeader("content-type")&&t.setHeader("content-type","text/csv; charset="+i+(s?"; header=present":!1===s?"; header=absent":"")),t.cork(),e instanceof ao&&(e=await e.load());try{t.write(ut);for await(let o of e){if(!t.writable)break;o instanceof ao&&(o=await o.load());try{let e=0;if(Symbol.iterator in o)for(let r of o){if(!t.writable)break;e&&t.write(n),r instanceof ao&&(r=await r.load());try{const t=u(r);t&&await t}finally{const t=fo(r);t&&await t}++e}else for await(let r of o){if(!t.writable)break;e&&t.write(n),r instanceof ao&&(r=await r.load());try{const t=u(r);t&&await t}finally{const t=fo(r);t&&await t}++e}}finally{const t=fo(o);t&&await t}t.write(r)||await ho(t)}}finally{t.uncork();const n=fo(e);n&&await n}a&&t.end()}const po=/^[^"':;,\\\r\n\t ]*$/i,mo=(t,e)=>{e&&"identity"!==e&&t.setHeader("content-encoding",e)},yo=(t,e)=>{if(e){const n=t.getHeader("vary")??"";t.setHeader("vary",(n?n+", ":"")+e)}},go=["zstd","br","gzip"],bo=/*@__PURE__*/new Nn([
3
+ /*@__PURE__*/kn(["zstd","br","gzip","deflate"])]);function vo(t,e,{encodings:n=go,encodingQuality:r="fast",estimatedLength:o,compressionSizeThreshold:i=0}={}){if(void 0===o||o>=i){for(const{headers:i}of bo.options("",t.headers)){const t=i["content-encoding"];if(!n.includes(t))continue;const s=zn(t,r,o);if(s)return mo(e,t),yo(e,i.vary),s.on("error",()=>e.destroy()),s.pipe(e),s}yo(e,"accept")}return e}async function _o(t,e,n,{encoding:r="utf-8",...o}={}){let i;"string"==typeof n&&(n=Buffer.from(n,r)),"byteLength"in n&&(i=n.byteLength,n=H.from(n instanceof Uint8Array?n:new Uint8Array(n.buffer,n.byteOffset,n.byteLength)));const s=vo(t,e,{...o,estimatedLength:i??o.estimatedLength});if(e.hasHeader("content-encoding")||void 0===i||e.setHeader("content-length",i),e.closed||!e.writable)throw ce;if("HEAD"!==t.method)try{await k(n,s)}catch(t){throw gr(e,t)?ce:t}else e.end()}function Eo(t,{forceSequential:e=!1,mergeOverlapDistance:n=100}={}){const r=[];if(n>=0)for(const e of t.ranges){let t=null,o=0;for(let i=0;i<r.length;++i){const s=r[i];e.end>=s.start-n-1&&s.end>=e.start-n-1?t?(++o,t.start=Math.min(t.start,s.start),t.end=Math.max(t.end,s.end)):(t=s,t.start=Math.min(t.start,e.start),t.end=Math.max(t.end,e.end)):o>0&&(r[i-o]=s)}t?r.length-=o:r.push({...e})}else r.push(...t.ranges);if(e)for(let t=0;t<r.length-1;++t)if(r[t].start>r[t+1].start){r.sort((t,e)=>t.start-e.start);break}return{ranges:r,totalSize:t.totalSize}}class So{constructor(t){(t=>"Ke"in t&&"function"==typeof t.pipe)(t)&&(t=H.toWeb(t)),this.Ot=t.getReader(),this.Qe=null,this.tn=0,this.m=0}getRange(t,e){if(e<t)throw new RangeError("invalid range");if(t<this.tn)throw new RangeError("non-sequential range");if(this.m)throw new TypeError("previous range still active");let n=e-t+1,r=t-this.tn;this.tn=e+1,this.m=1;const o=this,i=(t,e)=>{const o=t.byteLength;o<=r?r-=o:o>r+n?(this.Qe=t.subarray(r+n),e.enqueue(t.subarray(r,r+n)),n=0):r>0?(e.enqueue(t.subarray(r)),n-=o-r,r=0):(e.enqueue(t),n-=o)};return new m({start(t){if(o.Qe){const e=o.Qe;o.Qe=null,i(e,t)}},async pull(t){if(n<=0)return o.m=0,void t.close();const e=await o.Ot.read();e.done?t.error(new RangeError("range exceeds content")):"string"==typeof e.value?i(Buffer.from(e.value,"utf-8"),t):e.value instanceof Uint8Array?i(e.value,t):t.error(new TypeError("invalid stream type: must contain bytes or UTF-8 text"))}})}async close(){await this.Ot.cancel(),this.Ot.releaseLock()}}async function $o(t,e,n,r){if(e.closed||!e.writable)throw ce;if("string"==typeof n||"createReadStream"in n&&!n.noRandomAccess||(r=Eo(r,{mergeOverlapDistance:0,forceSequential:!0})),1===r.ranges.length){const o=r.ranges[0];if(e.setHeader("content-length",o.end-o.start+1),e.setHeader("content-range",`bytes ${o.start}-${o.end}/${r.totalSize??"*"}`),e.writeHead(206),"HEAD"===t.method)return void e.end();const i=await xo(n);try{if(e.closed||!e.writable)throw ce;await k(i.en(o.start,o.end),e)}catch(t){throw gr(e,t)?ce:t}finally{i.nn&&await i.nn()}return}const o=e.getHeader("content-type"),i=T()+T()+"ABCDEFGHIJKLMNOPQRSTUVWXYZ";e.setHeader("content-type",`multipart/byteranges; boundary=${i}`);const s=r.ranges.map(t=>({i:[`--${i}`,...pt({"content-type":o,"content-range":`bytes ${t.start}-${t.end}/${r.totalSize??"*"}`}),"",""].join("\r\n"),rn:t})),a=`--${i}--`;let c=a.length;for(const{i:t,rn:e}of s)c+=t.length+e.end-e.start+1+2;if(e.setHeader("content-length",c),"HEAD"===t.method)return void e.end();let f="";const u=await xo(n);try{for(const{i:t,rn:n}of s){if(e.closed||!e.writable)throw ce;e.write(f+t,"ascii"),await k(u.en(n.start,n.end),e,{end:!1}),f="\r\n"}e.end(f+a)}catch(t){throw gr(e,t)?ce:t}finally{u.nn&&await u.nn()}}async function xo(t){if("string"==typeof t){const e=await o(t,"r");return{en:(t,n)=>rt(e,{start:t,end:n,autoClose:!1}),nn:()=>e.close()}}if("createReadStream"in t){if(t.noRandomAccess){const e=rt(t,{start:0,autoClose:!1}),n=new So(e);return{en:(t,e)=>n.getRange(t,e),nn:()=>n.close()}}return{en:(e,n)=>rt(t,{start:e,end:n,autoClose:!1})}}{const e=new So(t);return{en:(t,n)=>e.getRange(t,n),nn:()=>e.close()}}}async function To(t,e,n,r=null,o){if(e.closed||!e.writable)throw ce;if(!r&&("string"==typeof n?r=await s(n):"stat"in n&&(r=await n.stat()),e.closed||!e.writable))throw ce;if(r){if("GET"===t.method||"HEAD"===t.method){if(!Fr(t,e,r))return void e.writeHead(304).end();e.setHeader("accept-ranges","bytes");const i=rn(t,r.size,o);if(i&&Mr(t,e,r))return $o(t,e,n,Eo(i,o))}e.setHeader("content-length",r.size)}if(e.writeHead(e.statusCode,e.statusMessage),"HEAD"!==t.method){"string"==typeof n?n=E(n):"createReadStream"in n&&(n=rt(n,{start:0,autoClose:!1}));try{await k(n,e)}catch(t){throw gr(e,t)?ce:t}}else e.end()}function ko(t,e,{replacer:n,space:r,undefinedAsNull:o=!1,encoding:i="utf-8",end:s=!0}={}){const a=JSON.stringify(e,n,r??void 0)??(o?"null":void 0);t instanceof _&&!t.headersSent&&(t.hasHeader("content-type")||t.setHeader("content-type","application/json"),s&&t.setHeader("content-length",Buffer.byteLength(a,i))),s?t.end(a,i):a&&t.write(a,i)}async function No(t,e,{replacer:n=null,space:r=null,undefinedAsNull:o=!1,encoding:i="utf-8",end:s=!0}={}){if(st(n)){const t=new Set(n.map(t=>String(t)));n=function(e,n){return null===this||st(this)||t.has(e)?n:void 0}}"number"==typeof r&&(r=" ".substring(0,r));try{if(!t.writable)return;const s={it:t,sn:e=>t.write(e,i),an:n,cn:r??""};t instanceof _&&!t.headersSent&&!t.hasHeader("content-type")&&t.setHeader("content-type","application/json"),e instanceof ao&&(e=await e.load());const a=Oo(null,"",e,s);if(Ao(a))o&&s.sn("null");else{t.cork(),t.write(ut);try{await Ro(s,a,r?"\n":"")}finally{t.uncork()}}}finally{const t=fo(e);t&&await t}s&&t.end()}async function Ro(t,e,n){const r=(r,o,i)=>{t.sn(r);const s=n+t.cn,a=t.cn?": ":":";let c=!0;return{o:async(n,r)=>{if(t.it.writable){r instanceof ao&&(r=await r.load());try{const o=Oo(e,n,r,t);i&&Ao(o)||(c?c=!1:t.sn(","),t.sn(s),i&&(t.sn(JSON.stringify(n))||await ho(t.it),t.sn(a)),await Ro(t,o,s))}finally{const t=fo(r);t&&await t}}},nn:()=>{c||t.sn(n),t.sn(o)}}};if(t.it.writable)if(null===e||"object"!=typeof e||e instanceof String||e instanceof Number||e instanceof Boolean||e instanceof Function||e instanceof Symbol||e instanceof BigInt||JSON.isRawJSON(e))t.sn(JSON.stringify(e)??"null")||await ho(t.it);else if(e instanceof H||e instanceof m){t.sn('"');for await(const n of e){if("string"!=typeof n)throw new TypeError("Readables must have an encoding");if(!t.it.writable)break;const e=JSON.stringify(n);t.sn(e.substring(1,e.length-1))||await ho(t.it)}t.sn('"')}else if(e instanceof Map){const t=r("{","}",!0);for(const[n,r]of e)await t.o(n,r);t.nn()}else if(Po(e)){let n=0;const o=r("[","]",!1);for(const r of e){if(!t.it.writable)break;await o.o(String(n++),r)}o.nn()}else if(Fo(e)){let n=0;const o=r("[","]",!1);for await(const r of e){if(!t.it.writable)break;await o.o(String(n++),r)}o.nn()}else{const t=r("{","}",!0);for(const[n,r]of Object.entries(e))await t.o(n,r);t.nn()}}function Oo(t,e,n,r){return r.an&&(n=r.an.call(t,e,n)),n&&"object"==typeof n&&"function"==typeof n.toJSON&&(n=n.toJSON(e)),n}const Ao=t=>void 0===t||"function"==typeof t||"symbol"==typeof t||t instanceof Function||t instanceof Symbol,Po=t=>Symbol.iterator in t,Fo=t=>Symbol.asyncIterator in t;class Mo{constructor(t,e,{keepaliveInterval:n=15e3,softCloseReconnectDelay:r=500,softCloseReconnectStagger:o=2e3}={}){tt(n,"keepaliveInterval",!0),this.fn=e,this.un=n,this.Y=new AbortController,e.setHeader("content-type","text/event-stream"),e.setHeader("x-accel-buffering","no"),e.setHeader("cache-control","no-store"),e.writeHead(200),e.flushHeaders(),this.ping=this.ping.bind(this),this.ln(),t.once("close",()=>this.close()),Zt(t,()=>this.close(r,o))}get signal(){return this.Y.signal}get open(){return!this.Y.signal.aborted}ln(){this.un>0&&(this.hn=setTimeout(this.ping,this.un))}ping(){!this.Y.signal.aborted&&this.fn.writable&&(clearTimeout(this.hn),this.fn.write(":\n\n",()=>this.ln()))}send({event:t,id:e,data:n,reconnectDelay:r=-1}){return this.sendFields([["event",t],["id",e],["data",n],["retry",r>=0?String(0|r):void 0]])}async sendFields(t){let e;this.Y.signal.throwIfAborted(),this.fn.cork();try{let n=!1;for(const[e,r]of t){if(void 0===r)continue;const t=r.split(/(?<=\n)|(?<=\r)(?!\n)/g);for(let n of t)this.fn.write(e)," "===n[0]?this.fn.write(": "):this.fn.write(":"),this.fn.write(n);/[\r\n]$/.test(r)?(this.fn.write(e),this.fn.write(":\n")):this.fn.write("\n"),n=!0}if(!n)return;clearTimeout(this.hn),this.fn.write("\n",()=>e())}finally{this.fn.uncork()}await new Promise(t=>{e=t}),this.ln()}async close(t=0,e=0){if(this.Y.signal.aborted){if(this.fn.closed)return;return new Promise(t=>this.fn.once("close",t))}this.un=0,clearTimeout(this.hn),this.Y.abort(new Error("ServerSentEvents closed")),await new Promise(n=>{if(this.fn.writable&&(t>0||e>0)){const r=t+Math.random()*e;this.fn.end(`retry:${0|r}\n\n`,n)}else this.fn.end(n)})}}const Co=(t,{fallback:e,verbose:n,headers:r,dynamicHeaders:o=["etag","last-modified"],callback:i}={})=>{let s=null;const a=e?.statusCode??200;if(e){let n=e.filePath;n.startsWith("/")&&(n=n.substring(1)),s=t.toNormalisedPath(n.split("/"))}const c={rejectPotentiallyUnsafe:!t.isStaticListing},f=gt(r),u=new Set((o||[]).map(t=>t.toLowerCase()));for(const t of f.keys())u.delete(t);return{handleRequest:async(e,r)=>{if("GET"!==e.method&&"HEAD"!==e.method)return fe;let o=!1;const l=oo(e,c),h=[];let d=await t.find(l,e.headers,n?h:void 0);if(!d){if(!s)return n&&Qn(e,new Error(h.join(", ")),"serving static content"),fe;if(o=!0,d=await t.find(s,e.headers,h),!d)throw new bt(500,{message:`failed to find fallback file: ${h.join(", ")}`})}try{o&&(r.statusCode=a);const t=d.headers["content-type"]??Bn(N(d.canonicalFilename));r.setHeader("content-type",t);const n=d.headers["content-language"];n&&r.setHeader("content-language",n),mo(r,d.headers["content-encoding"]),yo(r,d.headers.vary),r.setHeaders(f),u.has("etag")&&r.setHeader("etag",En(r.getHeader("content-encoding"),d.stats)),u.has("last-modified")&&r.setHeader("last-modified",d.stats.mtime.toUTCString()),await(i?.(e,r,d,o)),await To(e,r,d.handle,d.stats)}finally{d.handle.close().catch(()=>{})}}}},Uo=async(t,e={})=>Co("static-paths"===e.mode?await Wn(t,e):await jn(t,e),e),Bo=(t,e,{headers:n,encodings:r=[],minCompression:o=0}={})=>{const i=(async()=>{const e=new Map;e.set("",{Zt:t,dn:$n(t)});const n=[];for(const i of r){const r=await In(t,i,"max",o);r&&(e.set(i,{Zt:r,dn:$n(r)}),n.push({value:i,file:i}))}const i=new Nn([{feature:"encoding",options:n}]);return t=>{for(const n of i.options("",t)){const t=e.get(n.filename);if(t)return{H:n.headers,...t}}throw new Error("failed to serve static content")}})();return{handleRequest:async(t,r)=>{if("GET"!==t.method&&"HEAD"!==t.method)return fe;const{H:o,dn:s,Zt:a}=(await i)(t.headers);!r.closed&&r.writable&&(n&&r.setHeaders(gt(n)),mo(r,o["content-encoding"]),yo(r,o.vary),r.setHeader("content-type",e),r.setHeader("etag",s),Fr(t,r,null)?(r.setHeader("content-length",a.byteLength),r.end(a)):r.writeHead(304).end())}}},Do=(t,e)=>Bo(Buffer.from(JSON.stringify(t),"utf-8"),"application/json",e);class zo extends Error{constructor(t,{message:e,closeReason:n,...r}={}){super(e,r),this.closeCode=0|t,this.closeReason=n??"",this.name=`WebSocketError(${this.closeCode} ${this.closeReason})`}static NORMAL_CLOSURE=1e3;static GOING_AWAY=1001;static UNSUPPORTED_DATA=1003;static POLICY_VIOLATION=1008;static MESSAGE_TOO_BIG=1009;static INTERNAL_SERVER_ERROR=1011;static SERVICE_RESTART=1012;static TRY_AGAIN_LATER=1013;static BAD_GATEWAY=1014}function Io(t,{softCloseStatusCode:e=zo.GOING_AWAY,...n}={}){const r=(r,o,i)=>new Promise((s,a)=>{const c=new t({...n,noServer:!0,clientTracking:!1});c.once("wsClientError",a),c.handleUpgrade(r,o,i,t=>{c.off("wsClientError",a),i=ut,s({return:t,onError:e=>{const n=ot(e,zo);if(n)return void t.close(n.closeCode,n.closeReason);const r=ot(e,bt)??new bt(500),o=r.statusCode>=500?zo.INTERNAL_SERVER_ERROR:4e3+r.statusCode;t.close(o,r.statusMessage)},softCloseHandler:n=>t.close(e,n)})})});return t=>he(t,r)}class Ho{constructor(t,e){this.data=t,this.isBinary=e}get text(){if(this.isBinary)throw new zo(zo.UNSUPPORTED_DATA,{closeReason:"expected text"});return this.data.toString("utf-8")}get binary(){if(!this.isBinary)throw new zo(zo.UNSUPPORTED_DATA,{closeReason:"expected binary"});return this.data}}class jo{constructor(t,{limit:e=-1,signal:n}={}){this.wn=new nt;const r=e=>{t.off("message",i),t.off("close",o),this.wn.close(new Error(e))},o=()=>r("connection closed"),i=(t,n)=>{void 0!==n?this.wn.push(new Ho(t,n)):"string"==typeof t?this.wn.push(new Ho(Buffer.from(t,"utf-8"),!1)):this.wn.push(new Ho(t,!0)),e>0&&0===--e&&this.detach()};this.detach=()=>{},n?.aborted?this.wn.close(n.reason):2===t.readyState||3===t.readyState?this.wn.close(new Error("connection closed")):(t.on("message",i),t.on("close",o),n?.addEventListener("abort",()=>r("signal aborted")),this.detach=()=>r("WebSocket listener detached"))}next(t){return this.wn.shift(t)}[Symbol.asyncIterator](){return this.wn[Symbol.asyncIterator]()}}function qo(t,{timeout:e,signal:n}={}){const r=new jo(t,{limit:1,signal:n});return r.next(e).finally(()=>r.detach())}function Jo(t){const e=Xt(t);return"GET"===t.method&&(e.nt?.has("websocket")??!1)}const Lo=t=>t.headers.origin??mt(t.headers["sec-websocket-origin"]),Wo=(t,e=5e3)=>async n=>{if(!Jo(n))return;const r=await t(n);let o;try{o=await qo(r,{timeout:e})}catch(t){if((r.readyState??0)>=2)throw ce;throw new zo(zo.POLICY_VIOLATION,{closeReason:"timeout waiting for authentication token",cause:t})}if(o.isBinary)throw new zo(zo.UNSUPPORTED_DATA,{closeReason:"authentication token must be sent as text"});return o.data.toString("utf-8")};export{nt as BlockingQueue,fe as CONTINUE,bt as HTTPError,ue as NEXT_ROUTE,le as NEXT_ROUTER,Nn as Negotiator,uo as PP_BASE_DENY_2026,ln as Property,et as Queue,Ce as Router,ce as STOP,Mo as ServerSentEvents,ft as SharedFileHandle,Xe as WebListener,zo as WebSocketError,Ho as WebSocketMessage,jo as WebSocketMessages,br as acceptBody,he as acceptUpgrade,ie as addTeardown,Ne as anyHandler,Co as assetServer,Fr as checkIfModified,Mr as checkIfRange,Cr as compareETag,Yn as compressFileOffline,Kn as compressFilesInDir,Ae as conditionalErrorHandler,rt as createSafeReadStream,Cn as decompressMime,oe as defer,de as delegateUpgrade,jn as dynamicFileFinder,Qn as emitError,Re as errorHandler,Uo as fileServer,ot as findCause,Sn as generateStrongETag,En as generateWeakETag,se as getAbortSignal,$e as getAbsolutePath,it as getAddressURL,gn as getAuthScopes,tn as getAuthorization,Ir as getBodyJSON,Br as getBodyStream,zr as getBodyText,Dr as getBodyTextStream,en as getCharset,no as getFormData,eo as getFormFields,nn as getIfRange,Bn as getMime,Se as getPathParameter,Ee as getPathParameters,Qe as getQuery,rn as getRange,oo as getRemainingPathComponents,Ye as getSearch,Ke as getSearchParams,$t as getTextDecoder,xt as getTextDecoderStream,Lo as getWebSocketOrigin,yn as hasAuthScope,Kt as isSoftClosed,Jo as isWebSocketRequest,tr as jsonErrorHandler,co as loadOnDemand,Io as makeAcceptWebSocket,Z as makeAddressTester,xr as makeGetClient,hn as makeMemo,vo as makeResponseEncoder,rr as makeTempFileStorage,Wo as makeWebSocketFallbackTokenFetcher,lo as mergePermissionsPolicy,kn as negotiateEncoding,qo as nextWebSocketMessage,X as parseAddress,_r as proxy,fn as readHTTPDateSeconds,sn as readHTTPInteger,cn as readHTTPKeyValues,an as readHTTPQualityValues,on as readHTTPUnquotedCommaSeparated,Mn as readMimeTypes,sr as readZip,Et as registerCharset,Un as registerMime,St as registerUTF32,Nr as removeForwarded,Rr as replaceForwarded,Te as requestHandler,bn as requireAuthScope,mn as requireBearerAuth,Fn as resetMime,xe as restoreAbsolutePath,Or as sanitiseAndAppendForwarded,Qt as scheduleClose,wo as sendCSVStream,_o as sendEncoded,To as sendFile,ko as sendJSON,No as sendJSONStream,$o as sendRanges,Zt as setSoftCloseHandler,Ar as simpleAppendForwarded,Eo as simplifyRange,Bo as staticContent,Wn as staticFileFinder,Do as staticJSON,ct as stringPredicate,Je as toListeners,Oe as typedErrorHandler,ke as upgradeHandler,vr as willSendBody,nr as zipFileFinder};
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-listener",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "description": "a small server abstraction for creating API and resource endpoints with middleware",
5
5
  "author": "David Evans",
6
6
  "license": "MIT",