@meirblachman/azure-pipelines-visualizer 0.1.12 → 0.1.14
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/dist/index.min.js +2 -2
- package/dist/web/assets/{index-Oedmib0W.js → index-C-vxesL2.js} +4 -4
- package/dist/web/assets/react-vendor-Bdswto6F.js +1 -0
- package/dist/web/assets/reactflow-BBgD8bXw.js +62 -0
- package/dist/web/assets/{yaml-C-D6Mpno.js → yaml-DGeXk3xG.js} +1 -1
- package/dist/web/index.html +2 -2
- package/dist/web/lib/index.js +1612 -0
- package/dist/web/lib/style.css +1 -0
- package/package.json +1 -1
- package/dist/web/assets/react-vendor-C7bvnQIN.js +0 -1
- package/dist/web/assets/reactflow-N78VftLX.js +0 -62
package/dist/index.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{existsSync as Pt,readFileSync as Ot}from"node:fs";import{extname as Ia,join as Nr}from"node:path";import{fileURLToPath as _a}from"node:url";import{parseArgs as Fa}from"node:util";import{createServer as Ft}from"http";import{Http2ServerRequest as Hr,constants as jt}from"http2";import{Http2ServerRequest as Qe}from"http2";import{Readable as $r}from"stream";import Wt from"crypto";var N=class extends Error{constructor(e,r){super(e,r),this.name="RequestError"}},Nt=e=>e instanceof N?e:new N(e.message,{cause:e}),Lt=global.Request,fe=class extends Lt{constructor(e,r){typeof e=="object"&&K in e&&(e=e[K]()),typeof r?.body?.getReader<"u"&&(r.duplex??="half"),super(e,r)}},Dt=e=>{let r=[],n=e.rawHeaders;for(let t=0;t<n.length;t+=2){let{[t]:i,[t+1]:s}=n;i.charCodeAt(0)!==58&&r.push([i,s])}return new Headers(r)},zr=Symbol("wrapBodyStream"),$t=(e,r,n,t,i)=>{let s={method:e,headers:n,signal:i.signal};if(e==="TRACE"){s.method="GET";let o=new fe(r,s);return Object.defineProperty(o,"method",{get(){return"TRACE"}}),o}if(!(e==="GET"||e==="HEAD"))if("rawBody"in t&&t.rawBody instanceof Buffer)s.body=new ReadableStream({start(o){o.enqueue(t.rawBody),o.close()}});else if(t[zr]){let o;s.body=new ReadableStream({async pull(a){try{o||=$r.toWeb(t).getReader();let{done:l,value:c}=await o.read();l?a.close():a.enqueue(c)}catch(l){a.error(l)}}})}else s.body=$r.toWeb(t);return new fe(r,s)},K=Symbol("getRequestCache"),Br=Symbol("requestCache"),Se=Symbol("incomingKey"),Te=Symbol("urlKey"),Mt=Symbol("headersKey"),G=Symbol("abortControllerKey"),Ht=Symbol("getAbortController"),pe={get method(){return this[Se].method||"GET"},get url(){return this[Te]},get headers(){return this[Mt]||=Dt(this[Se])},[Ht](){return this[K](),this[G]},[K](){return this[G]||=new AbortController,this[Br]||=$t(this.method,this[Te],this.headers,this[Se],this[G])}};["body","bodyUsed","cache","credentials","destination","integrity","mode","redirect","referrer","referrerPolicy","signal","keepalive"].forEach(e=>{Object.defineProperty(pe,e,{get(){return this[K]()[e]}})});["arrayBuffer","blob","clone","formData","json","text"].forEach(e=>{Object.defineProperty(pe,e,{value:function(){return this[K]()[e]()}})});Object.defineProperty(pe,Symbol.for("nodejs.util.inspect.custom"),{value:function(e,r,n){let t={method:this.method,url:this.url,headers:this.headers,nativeRequest:this[Br]};return`Request (lightweight) ${n(t,{...r,depth:e==null?null:e-1})}`}});Object.setPrototypeOf(pe,fe.prototype);var zt=(e,r)=>{let n=Object.create(pe);n[Se]=e;let t=e.url||"";if(t[0]!=="/"&&(t.startsWith("http://")||t.startsWith("https://"))){if(e instanceof Qe)throw new N("Absolute URL for :path is not allowed in HTTP/2");try{let a=new URL(t);n[Te]=a.href}catch(a){throw new N("Invalid absolute URL",{cause:a})}return n}let i=(e instanceof Qe?e.authority:e.headers.host)||r;if(!i)throw new N("Missing host header");let s;if(e instanceof Qe){if(s=e.scheme,!(s==="http"||s==="https"))throw new N("Unsupported scheme")}else s=e.socket&&e.socket.encrypted?"https":"http";let o=new URL(`${s}://${i}${t}`);if(o.hostname.length!==i.length&&o.hostname!==i.replace(/:\d+$/,""))throw new N("Invalid host header");return n[Te]=o.href,n},er=Symbol("responseCache"),W=Symbol("getResponseCache"),L=Symbol("cache"),tr=global.Response,Y=class Ur{#r;#e;[W](){return delete this[L],this[er]||=new tr(this.#r,this.#e)}constructor(r,n){let t;if(this.#r=r,n instanceof Ur){let i=n[er];if(i){this.#e=i,this[W]();return}else this.#e=n.#e,t=new Headers(n.#e.headers)}else this.#e=n;(typeof r=="string"||typeof r?.getReader<"u"||r instanceof Blob||r instanceof Uint8Array)&&(this[L]=[n?.status||200,r,t||n?.headers])}get headers(){let r=this[L];return r?(r[2]instanceof Headers||(r[2]=new Headers(r[2]||{"content-type":"text/plain; charset=UTF-8"})),r[2]):this[W]().headers}get status(){return this[L]?.[0]??this[W]().status}get ok(){let r=this.status;return r>=200&&r<300}};["body","bodyUsed","redirected","statusText","trailers","type","url"].forEach(e=>{Object.defineProperty(Y.prototype,e,{get(){return this[W]()[e]}})});["arrayBuffer","blob","clone","formData","json","text"].forEach(e=>{Object.defineProperty(Y.prototype,e,{value:function(){return this[W]()[e]()}})});Object.defineProperty(Y.prototype,Symbol.for("nodejs.util.inspect.custom"),{value:function(e,r,n){let t={status:this.status,headers:this.headers,ok:this.ok,nativeResponse:this[er]};return`Response (lightweight) ${n(t,{...r,depth:e==null?null:e-1})}`}});Object.setPrototypeOf(Y,tr);Object.setPrototypeOf(Y.prototype,tr.prototype);async function Bt(e){return Promise.race([e,Promise.resolve().then(()=>Promise.resolve(void 0))])}function qr(e,r,n){let t=a=>{e.cancel(a).catch(()=>{})};return r.on("close",t),r.on("error",t),(n??e.read()).then(o,i),e.closed.finally(()=>{r.off("close",t),r.off("error",t)});function i(a){a&&r.destroy(a)}function s(){e.read().then(o,i)}function o({done:a,value:l}){try{if(a)r.end();else if(!r.write(l))r.once("drain",s);else return e.read().then(o,i)}catch(c){i(c)}}}function Ut(e,r){if(e.locked)throw new TypeError("ReadableStream is locked.");return r.destroyed?void 0:qr(e.getReader(),r)}var rr=e=>{let r={};e instanceof Headers||(e=new Headers(e??void 0));let n=[];for(let[t,i]of e)t==="set-cookie"?n.push(i):r[t]=i;return n.length>0&&(r["set-cookie"]=n),r["content-type"]??="text/plain; charset=UTF-8",r},qt="x-hono-already-sent";typeof global.crypto>"u"&&(global.crypto=Wt);var ir=Symbol("outgoingEnded"),Mr=Symbol("incomingDraining"),Gt=500,Kt=64*1024*1024,Xe=e=>{let r=e;if(e.destroyed||r[Mr])return;if(r[Mr]=!0,e instanceof Hr){try{e.stream?.close?.(jt.NGHTTP2_NO_ERROR)}catch{}return}let n=0,t=()=>{clearTimeout(s),e.off("data",o),e.off("end",t),e.off("error",t)},i=()=>{t();let a=e.socket;a&&!a.destroyed&&a.destroySoon()},s=setTimeout(i,Gt);s.unref?.();let o=a=>{n+=a.length,n>Kt&&i()};e.on("data",o),e.on("end",t),e.on("error",t),e.resume()},Yt=()=>new Response(null,{status:400}),Wr=e=>new Response(null,{status:e instanceof Error&&(e.name==="TimeoutError"||e.constructor.name==="TimeoutError")?504:500}),nr=(e,r)=>{let n=e instanceof Error?e:new Error("unknown error",{cause:e});n.code==="ERR_STREAM_PREMATURE_CLOSE"?console.info("The user aborted a request."):(console.error(e),r.headersSent||r.writeHead(500,{"Content-Type":"text/plain"}),r.end(`Error: ${n.message}`),r.destroy(n))},Gr=e=>{"flushHeaders"in e&&e.writable&&e.flushHeaders()},Kr=async(e,r)=>{let[n,t,i]=e[L],s=!1;if(!i)i={"content-type":"text/plain; charset=UTF-8"};else if(i instanceof Headers)s=i.has("content-length"),i=rr(i);else if(Array.isArray(i)){let o=new Headers(i);s=o.has("content-length"),i=rr(o)}else for(let o in i)if(o.length===14&&o.toLowerCase()==="content-length"){s=!0;break}s||(typeof t=="string"?i["Content-Length"]=Buffer.byteLength(t):t instanceof Uint8Array?i["Content-Length"]=t.byteLength:t instanceof Blob&&(i["Content-Length"]=t.size)),r.writeHead(n,i),typeof t=="string"||t instanceof Uint8Array?r.end(t):t instanceof Blob?r.end(new Uint8Array(await t.arrayBuffer())):(Gr(r),await Ut(t,r)?.catch(o=>nr(o,r))),r[ir]?.()},Vt=e=>typeof e.then=="function",Zt=async(e,r,n={})=>{if(Vt(e))if(n.errorHandler)try{e=await e}catch(i){let s=await n.errorHandler(i);if(!s)return;e=s}else e=await e.catch(Wr);if(L in e)return Kr(e,r);let t=rr(e.headers);if(e.body){let i=e.body.getReader(),s=[],o=!1,a;if(t["transfer-encoding"]!=="chunked"){let l=2;for(let c=0;c<l;c++){a||=i.read();let f=await Bt(a).catch(u=>{console.error(u),o=!0});if(!f){if(c===1){await new Promise(u=>setTimeout(u)),l=3;continue}break}if(a=void 0,f.value&&s.push(f.value),f.done){o=!0;break}}o&&!("content-length"in t)&&(t["content-length"]=s.reduce((c,f)=>c+f.length,0))}r.writeHead(e.status,t),s.forEach(l=>{r.write(l)}),o?r.end():(s.length===0&&Gr(r),await qr(i,r,a))}else t[qt]||(r.writeHead(e.status,t),r.end());r[ir]?.()},Jt=(e,r={})=>{let n=r.autoCleanupIncoming??!0;return r.overrideGlobalObjects!==!1&&global.Request!==fe&&(Object.defineProperty(global,"Request",{value:fe}),Object.defineProperty(global,"Response",{value:Y})),async(t,i)=>{let s,o;try{o=zt(t,r.hostname);let a=!n||t.method==="GET"||t.method==="HEAD";if(a||(t[zr]=!0,t.on("end",()=>{a=!0}),t instanceof Hr&&(i[ir]=()=>{a||setTimeout(()=>{a||setTimeout(()=>{Xe(t)})})}),i.on("finish",()=>{a||Xe(t)})),i.on("close",()=>{o[G]&&(t.errored?o[G].abort(t.errored.toString()):i.writableFinished||o[G].abort("Client connection prematurely closed.")),a||setTimeout(()=>{a||setTimeout(()=>{Xe(t)})})}),s=e(o,{incoming:t,outgoing:i}),L in s)return Kr(s,i)}catch(a){if(s)return nr(a,i);if(r.errorHandler){if(s=await r.errorHandler(o?a:Nt(a)),!s)return}else o?s=Wr(a):s=Yt()}try{return await Zt(s,i,r)}catch(a){return nr(a,i)}}},Qt=e=>{let r=e.fetch,n=Jt(r,{hostname:e.hostname,overrideGlobalObjects:e.overrideGlobalObjects,autoCleanupIncoming:e.autoCleanupIncoming});return(e.createServer||Ft)(e.serverOptions||{},n)},Yr=(e,r)=>{let n=Qt(e);return n.listen(e?.port??3e3,e.hostname,()=>{let t=n.address();r&&r(t)}),n};var or=(e,r,n)=>(t,i)=>{let s=-1;return o(0);async function o(a){if(a<=s)throw new Error("next() called multiple times");s=a;let l,c=!1,f;if(e[a]?(f=e[a][0][0],t.req.routeIndex=a):f=a===e.length&&i||void 0,f)try{l=await f(t,()=>o(a+1))}catch(u){if(u instanceof Error&&r)t.error=u,l=await r(u,t),c=!0;else throw u}else t.finalized===!1&&n&&(l=await n(t));return l&&(t.finalized===!1||c)&&(t.res=l),t}};var Vr=Symbol();var Zr=async(e,r=Object.create(null))=>{let{all:n=!1,dot:t=!1}=r,s=(e instanceof Pe?e.raw.headers:e.headers).get("Content-Type");return s?.startsWith("multipart/form-data")||s?.startsWith("application/x-www-form-urlencoded")?Xt(e,{all:n,dot:t}):{}};async function Xt(e,r){let n=await e.formData();return n?ei(n,r):{}}function ei(e,r){let n=Object.create(null);return e.forEach((t,i)=>{r.all||i.endsWith("[]")?ri(n,i,t):n[i]=t}),r.dot&&Object.entries(n).forEach(([t,i])=>{t.includes(".")&&(ni(n,t,i),delete n[t])}),n}var ri=(e,r,n)=>{e[r]!==void 0?Array.isArray(e[r])?e[r].push(n):e[r]=[e[r],n]:r.endsWith("[]")?e[r]=[n]:e[r]=n},ni=(e,r,n)=>{if(/(?:^|\.)__proto__\./.test(r))return;let t=e,i=r.split(".");i.forEach((s,o)=>{o===i.length-1?t[s]=n:((!t[s]||typeof t[s]!="object"||Array.isArray(t[s])||t[s]instanceof File)&&(t[s]=Object.create(null)),t=t[s])})};var ar=e=>{let r=e.split("/");return r[0]===""&&r.shift(),r},Jr=e=>{let{groups:r,path:n}=ti(e),t=ar(n);return ii(t,r)},ti=e=>{let r=[];return e=e.replace(/\{[^}]+\}/g,(n,t)=>{let i=`@${t}`;return r.push([i,n]),i}),{groups:r,path:e}},ii=(e,r)=>{for(let n=r.length-1;n>=0;n--){let[t]=r[n];for(let i=e.length-1;i>=0;i--)if(e[i].includes(t)){e[i]=e[i].replace(t,r[n][1]);break}}return e},Oe={},Qr=(e,r)=>{if(e==="*")return"*";let n=e.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);if(n){let t=`${e}#${r}`;return Oe[t]||(n[2]?Oe[t]=r&&r[0]!==":"&&r[0]!=="*"?[t,n[1],new RegExp(`^${n[2]}(?=/${r})`)]:[e,n[1],new RegExp(`^${n[2]}$`)]:Oe[t]=[e,n[1],!0]),Oe[t]}return null},Ie=(e,r)=>{try{return r(e)}catch{return e.replace(/(?:%[0-9A-Fa-f]{2})+/g,n=>{try{return r(n)}catch{return n}})}},oi=e=>Ie(e,decodeURI),lr=e=>{let r=e.url,n=r.indexOf("/",r.indexOf(":")+4),t=n;for(;t<r.length;t++){let i=r.charCodeAt(t);if(i===37){let s=r.indexOf("?",t),o=r.indexOf("#",t),a=s===-1?o===-1?void 0:o:o===-1?s:Math.min(s,o),l=r.slice(n,a);return oi(l.includes("%25")?l.replace(/%25/g,"%2525"):l)}else if(i===63||i===35)break}return r.slice(n,t)};var Xr=e=>{let r=lr(e);return r.length>1&&r.at(-1)==="/"?r.slice(0,-1):r},D=(e,r,...n)=>(n.length&&(r=D(r,...n)),`${e?.[0]==="/"?"":"/"}${e}${r==="/"?"":`${e?.at(-1)==="/"?"":"/"}${r?.[0]==="/"?r.slice(1):r}`}`),_e=e=>{if(e.charCodeAt(e.length-1)!==63||!e.includes(":"))return null;let r=e.split("/"),n=[],t="";return r.forEach(i=>{if(i!==""&&!/\:/.test(i))t+="/"+i;else if(/\:/.test(i))if(/\?/.test(i)){n.length===0&&t===""?n.push("/"):n.push(t);let s=i.replace("?","");t+="/"+s,n.push(t)}else t+="/"+i}),n.filter((i,s,o)=>o.indexOf(i)===s)},sr=e=>/[%+]/.test(e)?(e.indexOf("+")!==-1&&(e=e.replace(/\+/g," ")),e.indexOf("%")!==-1?Ie(e,cr):e):e,en=(e,r,n)=>{let t;if(!n&&r&&!/[%+]/.test(r)){let o=e.indexOf("?",8);if(o===-1)return;for(e.startsWith(r,o+1)||(o=e.indexOf(`&${r}`,o+1));o!==-1;){let a=e.charCodeAt(o+r.length+1);if(a===61){let l=o+r.length+2,c=e.indexOf("&",l);return sr(e.slice(l,c===-1?void 0:c))}else if(a==38||isNaN(a))return"";o=e.indexOf(`&${r}`,o+1)}if(t=/[%+]/.test(e),!t)return}let i={};t??=/[%+]/.test(e);let s=e.indexOf("?",8);for(;s!==-1;){let o=e.indexOf("&",s+1),a=e.indexOf("=",s);a>o&&o!==-1&&(a=-1);let l=e.slice(s+1,a===-1?o===-1?void 0:o:a);if(t&&(l=sr(l)),s=o,l==="")continue;let c;a===-1?c="":(c=e.slice(a+1,o===-1?void 0:o),t&&(c=sr(c))),n?(i[l]&&Array.isArray(i[l])||(i[l]=[]),i[l].push(c)):i[l]??=c}return r?i[r]:i},rn=en,nn=(e,r)=>en(e,r,!0),cr=decodeURIComponent;var tn=e=>Ie(e,cr),Pe=class{raw;#r;#e;routeIndex=0;path;bodyCache={};constructor(e,r="/",n=[[]]){this.raw=e,this.path=r,this.#e=n,this.#r={}}param(e){return e?this.#n(e):this.#o()}#n(e){let r=this.#e[0][this.routeIndex][1][e],n=this.#i(r);return n&&/\%/.test(n)?tn(n):n}#o(){let e={},r=Object.keys(this.#e[0][this.routeIndex][1]);for(let n of r){let t=this.#i(this.#e[0][this.routeIndex][1][n]);t!==void 0&&(e[n]=/\%/.test(t)?tn(t):t)}return e}#i(e){return this.#e[1]?this.#e[1][e]:e}query(e){return rn(this.url,e)}queries(e){return nn(this.url,e)}header(e){if(e)return this.raw.headers.get(e)??void 0;let r={};return this.raw.headers.forEach((n,t)=>{r[t]=n}),r}async parseBody(e){return Zr(this,e)}#t=e=>{let{bodyCache:r,raw:n}=this,t=r[e];if(t)return t;let i=Object.keys(r)[0];return i?r[i].then(s=>(i==="json"&&(s=JSON.stringify(s)),new Response(s)[e]())):r[e]=n[e]()};json(){return this.#t("text").then(e=>JSON.parse(e))}text(){return this.#t("text")}arrayBuffer(){return this.#t("arrayBuffer")}blob(){return this.#t("blob")}formData(){return this.#t("formData")}addValidatedData(e,r){this.#r[e]=r}valid(e){return this.#r[e]}get url(){return this.raw.url}get method(){return this.raw.method}get[Vr](){return this.#e}get matchedRoutes(){return this.#e[0].map(([[,e]])=>e)}get routePath(){return this.#e[0].map(([[,e]])=>e)[this.routeIndex].path}};var on={Stringify:1,BeforeStream:2,Stream:3},si=(e,r)=>{let n=new String(e);return n.isEscaped=!0,n.callbacks=r,n};var ur=async(e,r,n,t,i)=>{typeof e=="object"&&!(e instanceof String)&&(e instanceof Promise||(e=e.toString()),e instanceof Promise&&(e=await e));let s=e.callbacks;if(!s?.length)return Promise.resolve(e);i?i[0]+=e:i=[e];let o=Promise.all(s.map(a=>a({phase:r,buffer:i,context:t}))).then(a=>Promise.all(a.filter(Boolean).map(l=>ur(l,r,!1,t,i))).then(()=>i[0]));return n?si(await o,s):o};var ai="text/plain; charset=UTF-8",fr=(e,r)=>({"Content-Type":e,...r}),de=(e,r)=>new Response(e,r),sn=class{#r;#e;env={};#n;finalized=!1;error;#o;#i;#t;#u;#l;#c;#a;#f;#p;constructor(e,r){this.#r=e,r&&(this.#i=r.executionCtx,this.env=r.env,this.#c=r.notFoundHandler,this.#p=r.path,this.#f=r.matchResult)}get req(){return this.#e??=new Pe(this.#r,this.#p,this.#f),this.#e}get event(){if(this.#i&&"respondWith"in this.#i)return this.#i;throw Error("This context has no FetchEvent")}get executionCtx(){if(this.#i)return this.#i;throw Error("This context has no ExecutionContext")}get res(){return this.#t||=de(null,{headers:this.#a??=new Headers})}set res(e){if(this.#t&&e){e=de(e.body,e);for(let[r,n]of this.#t.headers.entries())if(r!=="content-type")if(r==="set-cookie"){let t=this.#t.headers.getSetCookie();e.headers.delete("set-cookie");for(let i of t)e.headers.append("set-cookie",i)}else e.headers.set(r,n)}this.#t=e,this.finalized=!0}render=(...e)=>(this.#l??=r=>this.html(r),this.#l(...e));setLayout=e=>this.#u=e;getLayout=()=>this.#u;setRenderer=e=>{this.#l=e};header=(e,r,n)=>{this.finalized&&(this.#t=de(this.#t.body,this.#t));let t=this.#t?this.#t.headers:this.#a??=new Headers;r===void 0?t.delete(e):n?.append?t.append(e,r):t.set(e,r)};status=e=>{this.#o=e};set=(e,r)=>{this.#n??=new Map,this.#n.set(e,r)};get=e=>this.#n?this.#n.get(e):void 0;get var(){return this.#n?Object.fromEntries(this.#n):{}}#s(e,r,n){let t=this.#t?new Headers(this.#t.headers):this.#a??new Headers;if(typeof r=="object"&&"headers"in r){let s=r.headers instanceof Headers?r.headers:new Headers(r.headers);for(let[o,a]of s)o.toLowerCase()==="set-cookie"?t.append(o,a):t.set(o,a)}if(n)for(let[s,o]of Object.entries(n))if(typeof o=="string")t.set(s,o);else{t.delete(s);for(let a of o)t.append(s,a)}let i=typeof r=="number"?r:r?.status??this.#o;return de(e,{status:i,headers:t})}newResponse=(...e)=>this.#s(...e);body=(e,r,n)=>this.#s(e,r,n);text=(e,r,n)=>!this.#a&&!this.#o&&!r&&!n&&!this.finalized?new Response(e):this.#s(e,r,fr(ai,n));json=(e,r,n)=>this.#s(JSON.stringify(e),r,fr("application/json",n));html=(e,r,n)=>{let t=i=>this.#s(i,r,fr("text/html; charset=UTF-8",n));return typeof e=="object"?ur(e,on.Stringify,!1,{}).then(t):t(e)};redirect=(e,r)=>{let n=String(e);return this.header("Location",/[^\x00-\xFF]/.test(n)?encodeURI(n):n),this.newResponse(null,r??302)};notFound=()=>(this.#c??=()=>de(),this.#c(this))};var A="ALL",an="all",ln=["get","post","put","delete","options","patch"],Fe="Can not add a route since the matcher is already built.",je=class extends Error{};var cn="__COMPOSED_HANDLER";var li=e=>e.text("404 Not Found",404),un=(e,r)=>{if("getResponse"in e){let n=e.getResponse();return r.newResponse(n.body,n)}return console.error(e),r.text("Internal Server Error",500)},fn=class pn{get;post;put;delete;options;patch;all;on;use;router;getPath;_basePath="/";#r="/";routes=[];constructor(r={}){[...ln,an].forEach(s=>{this[s]=(o,...a)=>(typeof o=="string"?this.#r=o:this.#o(s,this.#r,o),a.forEach(l=>{this.#o(s,this.#r,l)}),this)}),this.on=(s,o,...a)=>{for(let l of[o].flat()){this.#r=l;for(let c of[s].flat())a.map(f=>{this.#o(c.toUpperCase(),this.#r,f)})}return this},this.use=(s,...o)=>(typeof s=="string"?this.#r=s:(this.#r="*",o.unshift(s)),o.forEach(a=>{this.#o(A,this.#r,a)}),this);let{strict:t,...i}=r;Object.assign(this,i),this.getPath=t??!0?r.getPath??lr:Xr}#e(){let r=new pn({router:this.router,getPath:this.getPath});return r.errorHandler=this.errorHandler,r.#n=this.#n,r.routes=this.routes,r}#n=li;errorHandler=un;route(r,n){let t=this.basePath(r);return n.routes.map(i=>{let s;n.errorHandler===un?s=i.handler:(s=async(o,a)=>(await or([],n.errorHandler)(o,()=>i.handler(o,a))).res,s[cn]=i.handler),t.#o(i.method,i.path,s)}),this}basePath(r){let n=this.#e();return n._basePath=D(this._basePath,r),n}onError=r=>(this.errorHandler=r,this);notFound=r=>(this.#n=r,this);mount(r,n,t){let i,s;t&&(typeof t=="function"?s=t:(s=t.optionHandler,t.replaceRequest===!1?i=l=>l:i=t.replaceRequest));let o=s?l=>{let c=s(l);return Array.isArray(c)?c:[c]}:l=>{let c;try{c=l.executionCtx}catch{}return[l.env,c]};i||=(()=>{let l=D(this._basePath,r),c=l==="/"?0:l.length;return f=>{let u=new URL(f.url);return u.pathname=u.pathname.slice(c)||"/",new Request(u,f)}})();let a=async(l,c)=>{let f=await n(i(l.req.raw),...o(l));if(f)return f;await c()};return this.#o(A,D(r,"*"),a),this}#o(r,n,t){r=r.toUpperCase(),n=D(this._basePath,n);let i={basePath:this._basePath,path:n,method:r,handler:t};this.router.add(r,n,[t,i]),this.routes.push(i)}#i(r,n){if(r instanceof Error)return this.errorHandler(r,n);throw r}#t(r,n,t,i){if(i==="HEAD")return(async()=>new Response(null,await this.#t(r,n,t,"GET")))();let s=this.getPath(r,{env:t}),o=this.router.match(i,s),a=new sn(r,{path:s,matchResult:o,env:t,executionCtx:n,notFoundHandler:this.#n});if(o[0].length===1){let c;try{c=o[0][0][0][0](a,async()=>{a.res=await this.#n(a)})}catch(f){return this.#i(f,a)}return c instanceof Promise?c.then(f=>f||(a.finalized?a.res:this.#n(a))).catch(f=>this.#i(f,a)):c??this.#n(a)}let l=or(o[0],this.errorHandler,this.#n);return(async()=>{try{let c=await l(a);if(!c.finalized)throw new Error("Context is not finalized. Did you forget to return a Response object or `await next()`?");return c.res}catch(c){return this.#i(c,a)}})()}fetch=(r,...n)=>this.#t(r,n[1],n[0],r.method);request=(r,n,t,i)=>r instanceof Request?this.fetch(n?new Request(r,n):r,t,i):(r=r.toString(),this.fetch(new Request(/^https?:\/\//.test(r)?r:`http://localhost${D("/",r)}`,n),t,i));fire=()=>{addEventListener("fetch",r=>{r.respondWith(this.#t(r.request,r,void 0,r.request.method))})}};var Ne=[];function pr(e,r){let n=this.buildAllMatchers(),t=((i,s)=>{let o=n[i]||n[A],a=o[2][s];if(a)return a;let l=s.match(o[0]);if(!l)return[[],Ne];let c=l.indexOf("",1);return[o[1][c],l]});return this.match=t,t(e,r)}var Le="[^/]+",he=".*",me="(?:|/.*)",$=Symbol(),ci=new Set(".\\+*[^]$()");function ui(e,r){return e.length===1?r.length===1?e<r?-1:1:-1:r.length===1||e===he||e===me?1:r===he||r===me?-1:e===Le?1:r===Le?-1:e.length===r.length?e<r?-1:1:r.length-e.length}var dn=class dr{#r;#e;#n=Object.create(null);insert(r,n,t,i,s){if(r.length===0){if(this.#r!==void 0)throw $;if(s)return;this.#r=n;return}let[o,...a]=r,l=o==="*"?a.length===0?["","",he]:["","",Le]:o==="/*"?["","",me]:o.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/),c;if(l){let f=l[1],u=l[2]||Le;if(f&&l[2]&&(u===".*"||(u=u.replace(/^\((?!\?:)(?=[^)]+\)$)/,"(?:"),/\((?!\?:)/.test(u))))throw $;if(c=this.#n[u],!c){if(Object.keys(this.#n).some(p=>p!==he&&p!==me))throw $;if(s)return;c=this.#n[u]=new dr,f!==""&&(c.#e=i.varIndex++)}!s&&f!==""&&t.push([f,c.#e])}else if(c=this.#n[o],!c){if(Object.keys(this.#n).some(f=>f.length>1&&f!==he&&f!==me))throw $;if(s)return;c=this.#n[o]=new dr}c.insert(a,n,t,i,s)}buildRegExpStr(){let n=Object.keys(this.#n).sort(ui).map(t=>{let i=this.#n[t];return(typeof i.#e=="number"?`(${t})@${i.#e}`:ci.has(t)?`\\${t}`:t)+i.buildRegExpStr()});return typeof this.#r=="number"&&n.unshift(`#${this.#r}`),n.length===0?"":n.length===1?n[0]:"(?:"+n.join("|")+")"}};var hn=class{#r={varIndex:0};#e=new dn;insert(e,r,n){let t=[],i=[];for(let o=0;;){let a=!1;if(e=e.replace(/\{[^}]+\}/g,l=>{let c=`@\\${o}`;return i[o]=[c,l],o++,a=!0,c}),!a)break}let s=e.match(/(?::[^\/]+)|(?:\/\*$)|./g)||[];for(let o=i.length-1;o>=0;o--){let[a]=i[o];for(let l=s.length-1;l>=0;l--)if(s[l].indexOf(a)!==-1){s[l]=s[l].replace(a,i[o][1]);break}}return this.#e.insert(s,r,t,this.#r,n),t}buildRegExp(){let e=this.#e.buildRegExpStr();if(e==="")return[/^$/,[],[]];let r=0,n=[],t=[];return e=e.replace(/#(\d+)|@(\d+)|\.\*\$/g,(i,s,o)=>s!==void 0?(n[++r]=Number(s),"$()"):(o!==void 0&&(t[Number(o)]=++r),"")),[new RegExp(`^${e}`),n,t]}};var fi=[/^$/,[],Object.create(null)],mn=Object.create(null);function gn(e){return mn[e]??=new RegExp(e==="*"?"":`^${e.replace(/\/\*$|([.\\+*[^\]$()])/g,(r,n)=>n?`\\${n}`:"(?:|/.*)")}$`)}function pi(){mn=Object.create(null)}function di(e){let r=new hn,n=[];if(e.length===0)return fi;let t=e.map(c=>[!/\*|\/:/.test(c[0]),...c]).sort(([c,f],[u,p])=>c?1:u?-1:f.length-p.length),i=Object.create(null);for(let c=0,f=-1,u=t.length;c<u;c++){let[p,d,m]=t[c];p?i[d]=[m.map(([x])=>[x,Object.create(null)]),Ne]:f++;let y;try{y=r.insert(d,f,p)}catch(x){throw x===$?new je(d):x}p||(n[f]=m.map(([x,v])=>{let g=Object.create(null);for(v-=1;v>=0;v--){let[le,Ze]=y[v];g[le]=Ze}return[x,g]}))}let[s,o,a]=r.buildRegExp();for(let c=0,f=n.length;c<f;c++)for(let u=0,p=n[c].length;u<p;u++){let d=n[c][u]?.[1];if(!d)continue;let m=Object.keys(d);for(let y=0,x=m.length;y<x;y++)d[m[y]]=a[d[m[y]]]}let l=[];for(let c in o)l[c]=n[o[c]];return[s,l,i]}function V(e,r){if(e){for(let n of Object.keys(e).sort((t,i)=>i.length-t.length))if(gn(n).test(r))return[...e[n]]}}var De=class{name="RegExpRouter";#r;#e;constructor(){this.#r={[A]:Object.create(null)},this.#e={[A]:Object.create(null)}}add(e,r,n){let t=this.#r,i=this.#e;if(!t||!i)throw new Error(Fe);t[e]||[t,i].forEach(a=>{a[e]=Object.create(null),Object.keys(a[A]).forEach(l=>{a[e][l]=[...a[A][l]]})}),r==="/*"&&(r="*");let s=(r.match(/\/:/g)||[]).length;if(/\*$/.test(r)){let a=gn(r);e===A?Object.keys(t).forEach(l=>{t[l][r]||=V(t[l],r)||V(t[A],r)||[]}):t[e][r]||=V(t[e],r)||V(t[A],r)||[],Object.keys(t).forEach(l=>{(e===A||e===l)&&Object.keys(t[l]).forEach(c=>{a.test(c)&&t[l][c].push([n,s])})}),Object.keys(i).forEach(l=>{(e===A||e===l)&&Object.keys(i[l]).forEach(c=>a.test(c)&&i[l][c].push([n,s]))});return}let o=_e(r)||[r];for(let a=0,l=o.length;a<l;a++){let c=o[a];Object.keys(i).forEach(f=>{(e===A||e===f)&&(i[f][c]||=[...V(t[f],c)||V(t[A],c)||[]],i[f][c].push([n,s-l+a+1]))})}}match=pr;buildAllMatchers(){let e=Object.create(null);return Object.keys(this.#e).concat(Object.keys(this.#r)).forEach(r=>{e[r]||=this.#n(r)}),this.#r=this.#e=void 0,pi(),e}#n(e){let r=[],n=e===A;return[this.#r,this.#e].forEach(t=>{let i=t[e]?Object.keys(t[e]).map(s=>[s,t[e][s]]):[];i.length!==0?(n||=!0,r.push(...i)):e!==A&&r.push(...Object.keys(t[A]).map(s=>[s,t[A][s]]))}),n?di(r):null}};var hr=class{name="SmartRouter";#r=[];#e=[];constructor(e){this.#r=e.routers}add(e,r,n){if(!this.#e)throw new Error(Fe);this.#e.push([e,r,n])}match(e,r){if(!this.#e)throw new Error("Fatal error");let n=this.#r,t=this.#e,i=n.length,s=0,o;for(;s<i;s++){let a=n[s];try{for(let l=0,c=t.length;l<c;l++)a.add(...t[l]);o=a.match(e,r)}catch(l){if(l instanceof je)continue;throw l}this.match=a.match.bind(a),this.#r=[a],this.#e=void 0;break}if(s===i)throw new Error("Fatal error");return this.name=`SmartRouter + ${this.activeRouter.name}`,o}get activeRouter(){if(this.#e||this.#r.length!==1)throw new Error("No active router has been determined yet.");return this.#r[0]}};var ge=Object.create(null),hi=e=>{for(let r in e)return!0;return!1},yn=class xn{#r;#e;#n;#o=0;#i=ge;constructor(r,n,t){if(this.#e=t||Object.create(null),this.#r=[],r&&n){let i=Object.create(null);i[r]={handler:n,possibleKeys:[],score:0},this.#r=[i]}this.#n=[]}insert(r,n,t){this.#o=++this.#o;let i=this,s=Jr(n),o=[];for(let a=0,l=s.length;a<l;a++){let c=s[a],f=s[a+1],u=Qr(c,f),p=Array.isArray(u)?u[0]:c;if(p in i.#e){i=i.#e[p],u&&o.push(u[1]);continue}i.#e[p]=new xn,u&&(i.#n.push(u),o.push(u[1])),i=i.#e[p]}return i.#r.push({[r]:{handler:t,possibleKeys:o.filter((a,l,c)=>c.indexOf(a)===l),score:this.#o}}),i}#t(r,n,t,i,s){for(let o=0,a=n.#r.length;o<a;o++){let l=n.#r[o],c=l[t]||l[A],f={};if(c!==void 0&&(c.params=Object.create(null),r.push(c),i!==ge||s&&s!==ge))for(let u=0,p=c.possibleKeys.length;u<p;u++){let d=c.possibleKeys[u],m=f[c.score];c.params[d]=s?.[d]&&!m?s[d]:i[d]??s?.[d],f[c.score]=!0}}}search(r,n){let t=[];this.#i=ge;let s=[this],o=ar(n),a=[],l=o.length,c=null;for(let f=0;f<l;f++){let u=o[f],p=f===l-1,d=[];for(let y=0,x=s.length;y<x;y++){let v=s[y],g=v.#e[u];g&&(g.#i=v.#i,p?(g.#e["*"]&&this.#t(t,g.#e["*"],r,v.#i),this.#t(t,g,r,v.#i)):d.push(g));for(let le=0,Ze=v.#n.length;le<Ze;le++){let Lr=v.#n[le],_=v.#i===ge?{}:{...v.#i};if(Lr==="*"){let q=v.#e["*"];q&&(this.#t(t,q,r,v.#i),q.#i=_,d.push(q));continue}let[_t,Dr,ce]=Lr;if(!u&&!(ce instanceof RegExp))continue;let P=v.#e[_t];if(ce instanceof RegExp){if(c===null){c=new Array(l);let ke=n[0]==="/"?1:0;for(let ue=0;ue<l;ue++)c[ue]=ke,ke+=o[ue].length+1}let q=n.substring(c[f]),Je=ce.exec(q);if(Je){if(_[Dr]=Je[0],this.#t(t,P,r,v.#i,_),hi(P.#e)){P.#i=_;let ke=Je[0].match(/\//)?.length??0;(a[ke]||=[]).push(P)}continue}}(ce===!0||ce.test(u))&&(_[Dr]=u,p?(this.#t(t,P,r,_,v.#i),P.#e["*"]&&this.#t(t,P.#e["*"],r,_,v.#i)):(P.#i=_,d.push(P)))}}let m=a.shift();s=m?d.concat(m):d}return t.length>1&&t.sort((f,u)=>f.score-u.score),[t.map(({handler:f,params:u})=>[f,u])]}};var mr=class{name="TrieRouter";#r;constructor(){this.#r=new yn}add(e,r,n){let t=_e(r);if(t){for(let i=0,s=t.length;i<s;i++)this.#r.insert(e,t[i],n);return}this.#r.insert(e,r,n)}match(e,r){return this.#r.search(e,r)}};var O=class extends fn{constructor(e={}){super(e),this.router=e.router??new hr({routers:[new De,new mr]})}};var vn=e=>{let n={...{origin:"*",allowMethods:["GET","HEAD","PUT","POST","DELETE","PATCH"],allowHeaders:[],exposeHeaders:[]},...e},t=(s=>typeof s=="string"?s==="*"?n.credentials?o=>o||null:()=>s:o=>s===o?o:null:typeof s=="function"?s:o=>s.includes(o)?o:null)(n.origin),i=(s=>typeof s=="function"?s:Array.isArray(s)?()=>s:()=>[])(n.allowMethods);return async function(o,a){function l(f,u){o.res.headers.set(f,u)}let c=await t(o.req.header("origin")||"",o);if(c&&l("Access-Control-Allow-Origin",c),n.credentials&&l("Access-Control-Allow-Credentials","true"),n.exposeHeaders?.length&&l("Access-Control-Expose-Headers",n.exposeHeaders.join(",")),o.req.method==="OPTIONS"){(n.origin!=="*"||n.credentials)&&l("Vary","Origin"),n.maxAge!=null&&l("Access-Control-Max-Age",n.maxAge.toString());let f=await i(o.req.header("origin")||"",o);f.length&&l("Access-Control-Allow-Methods",f.join(","));let u=n.allowHeaders;if(!u?.length){let p=o.req.header("Access-Control-Request-Headers");p&&(u=p.split(/\s*,\s*/))}return u?.length&&(l("Access-Control-Allow-Headers",u.join(",")),o.res.headers.append("Vary","Access-Control-Request-Headers")),o.res.headers.delete("Content-Length"),o.res.headers.delete("Content-Type"),new Response(null,{headers:o.res.headers,status:204,statusText:"No Content"})}await a(),(n.origin!=="*"||n.credentials)&&o.header("Vary","Origin",{append:!0})}};function mi(){let{process:e,Deno:r}=globalThis;return!(typeof r?.noColor=="boolean"?r.noColor:e!==void 0?"NO_COLOR"in e?.env:!1)}async function An(){let{navigator:e}=globalThis,r="cloudflare:workers";return!(e!==void 0&&e.userAgent==="Cloudflare-Workers"?await(async()=>{try{return"NO_COLOR"in((await import(r)).env??{})}catch{return!1}})():!mi())}var gi=e=>{let[r,n]=[",","."];return e.map(i=>i.replace(/(\d)(?=(\d\d\d)+(?!\d))/g,"$1"+r)).join(n)},yi=e=>{let r=Date.now()-e;return gi([r<1e3?r+"ms":Math.round(r/1e3)+"s"])},xi=async e=>{if(await An())switch(e/100|0){case 5:return`\x1B[31m${e}\x1B[0m`;case 4:return`\x1B[33m${e}\x1B[0m`;case 3:return`\x1B[36m${e}\x1B[0m`;case 2:return`\x1B[32m${e}\x1B[0m`}return`${e}`};async function bn(e,r,n,t,i=0,s){let o=r==="<--"?`${r} ${n} ${t}`:`${r} ${n} ${t} ${await xi(i)} ${s}`;e(o)}var wn=(e=console.log)=>async function(n,t){let{method:i,url:s}=n.req,o=s.slice(s.indexOf("/",8));await bn(e,"<--",i,o);let a=Date.now();await t(),await bn(e,"-->",i,o,n.res.status,yi(a))};import{existsSync as vi,readFileSync as Ai}from"node:fs";import{dirname as bi,resolve as Rn}from"node:path";import{fileURLToPath as wi}from"node:url";var Cn="apv.config.json",Z=null,En;function kn(e){En=e}function M(){if(Z)return Z;let e=process.env.APV_CONFIG,r=[En,e,Rn(process.cwd(),Cn),Rn(bi(wi(import.meta.url)),"..","..","..",Cn)].filter(Boolean);for(let n of r)if(vi(n))try{let t=Ai(n,"utf-8"),i=JSON.parse(t);return Z={cacheDir:i.cacheDir,customTaskDocs:i.customTaskDocs??{}},console.log(`Loaded config from ${n}`),Z}catch(t){console.warn(`Failed to parse ${n}:`,t)}return Z={customTaskDocs:{}},Z}function $e(e){let r=e.startsWith("/"),n=e.split("/").filter(s=>s!==""&&s!=="."),t=[];for(let s of n)s===".."?t.length>0&&t[t.length-1]!==".."?t.pop():r||t.push(s):t.push(s);let i=t.join("/");return r?`/${i}`:i}function Bn(e){return typeof e>"u"||e===null}function Ci(e){return typeof e=="object"&&e!==null}function Ei(e){return Array.isArray(e)?e:Bn(e)?[]:[e]}function ki(e,r){var n,t,i,s;if(r)for(s=Object.keys(r),n=0,t=s.length;n<t;n+=1)i=s[n],e[i]=r[i];return e}function Si(e,r){var n="",t;for(t=0;t<r;t+=1)n+=e;return n}function Ti(e){return e===0&&Number.NEGATIVE_INFINITY===1/e}var Pi=Bn,Oi=Ci,Ii=Ei,_i=Si,Fi=Ti,ji=ki,w={isNothing:Pi,isObject:Oi,toArray:Ii,repeat:_i,isNegativeZero:Fi,extend:ji};function Un(e,r){var n="",t=e.reason||"(unknown reason)";return e.mark?(e.mark.name&&(n+='in "'+e.mark.name+'" '),n+="("+(e.mark.line+1)+":"+(e.mark.column+1)+")",!r&&e.mark.snippet&&(n+=`
|
|
2
|
+
import{existsSync as Pt,readFileSync as Ot}from"node:fs";import{extname as Ia,join as Nr}from"node:path";import{fileURLToPath as _a}from"node:url";import{parseArgs as Fa}from"node:util";import{createServer as Ft}from"http";import{Http2ServerRequest as Hr,constants as jt}from"http2";import{Http2ServerRequest as Qe}from"http2";import{Readable as $r}from"stream";import Wt from"crypto";var N=class extends Error{constructor(e,r){super(e,r),this.name="RequestError"}},Nt=e=>e instanceof N?e:new N(e.message,{cause:e}),Lt=global.Request,fe=class extends Lt{constructor(e,r){typeof e=="object"&&K in e&&(e=e[K]()),typeof r?.body?.getReader<"u"&&(r.duplex??="half"),super(e,r)}},Dt=e=>{let r=[],n=e.rawHeaders;for(let t=0;t<n.length;t+=2){let{[t]:i,[t+1]:s}=n;i.charCodeAt(0)!==58&&r.push([i,s])}return new Headers(r)},zr=Symbol("wrapBodyStream"),$t=(e,r,n,t,i)=>{let s={method:e,headers:n,signal:i.signal};if(e==="TRACE"){s.method="GET";let o=new fe(r,s);return Object.defineProperty(o,"method",{get(){return"TRACE"}}),o}if(!(e==="GET"||e==="HEAD"))if("rawBody"in t&&t.rawBody instanceof Buffer)s.body=new ReadableStream({start(o){o.enqueue(t.rawBody),o.close()}});else if(t[zr]){let o;s.body=new ReadableStream({async pull(a){try{o||=$r.toWeb(t).getReader();let{done:l,value:c}=await o.read();l?a.close():a.enqueue(c)}catch(l){a.error(l)}}})}else s.body=$r.toWeb(t);return new fe(r,s)},K=Symbol("getRequestCache"),Br=Symbol("requestCache"),Se=Symbol("incomingKey"),Te=Symbol("urlKey"),Mt=Symbol("headersKey"),G=Symbol("abortControllerKey"),Ht=Symbol("getAbortController"),pe={get method(){return this[Se].method||"GET"},get url(){return this[Te]},get headers(){return this[Mt]||=Dt(this[Se])},[Ht](){return this[K](),this[G]},[K](){return this[G]||=new AbortController,this[Br]||=$t(this.method,this[Te],this.headers,this[Se],this[G])}};["body","bodyUsed","cache","credentials","destination","integrity","mode","redirect","referrer","referrerPolicy","signal","keepalive"].forEach(e=>{Object.defineProperty(pe,e,{get(){return this[K]()[e]}})});["arrayBuffer","blob","clone","formData","json","text"].forEach(e=>{Object.defineProperty(pe,e,{value:function(){return this[K]()[e]()}})});Object.defineProperty(pe,Symbol.for("nodejs.util.inspect.custom"),{value:function(e,r,n){let t={method:this.method,url:this.url,headers:this.headers,nativeRequest:this[Br]};return`Request (lightweight) ${n(t,{...r,depth:e==null?null:e-1})}`}});Object.setPrototypeOf(pe,fe.prototype);var zt=(e,r)=>{let n=Object.create(pe);n[Se]=e;let t=e.url||"";if(t[0]!=="/"&&(t.startsWith("http://")||t.startsWith("https://"))){if(e instanceof Qe)throw new N("Absolute URL for :path is not allowed in HTTP/2");try{let a=new URL(t);n[Te]=a.href}catch(a){throw new N("Invalid absolute URL",{cause:a})}return n}let i=(e instanceof Qe?e.authority:e.headers.host)||r;if(!i)throw new N("Missing host header");let s;if(e instanceof Qe){if(s=e.scheme,!(s==="http"||s==="https"))throw new N("Unsupported scheme")}else s=e.socket&&e.socket.encrypted?"https":"http";let o=new URL(`${s}://${i}${t}`);if(o.hostname.length!==i.length&&o.hostname!==i.replace(/:\d+$/,""))throw new N("Invalid host header");return n[Te]=o.href,n},er=Symbol("responseCache"),W=Symbol("getResponseCache"),L=Symbol("cache"),tr=global.Response,Y=class Ur{#r;#e;[W](){return delete this[L],this[er]||=new tr(this.#r,this.#e)}constructor(r,n){let t;if(this.#r=r,n instanceof Ur){let i=n[er];if(i){this.#e=i,this[W]();return}else this.#e=n.#e,t=new Headers(n.#e.headers)}else this.#e=n;(typeof r=="string"||typeof r?.getReader<"u"||r instanceof Blob||r instanceof Uint8Array)&&(this[L]=[n?.status||200,r,t||n?.headers])}get headers(){let r=this[L];return r?(r[2]instanceof Headers||(r[2]=new Headers(r[2]||{"content-type":"text/plain; charset=UTF-8"})),r[2]):this[W]().headers}get status(){return this[L]?.[0]??this[W]().status}get ok(){let r=this.status;return r>=200&&r<300}};["body","bodyUsed","redirected","statusText","trailers","type","url"].forEach(e=>{Object.defineProperty(Y.prototype,e,{get(){return this[W]()[e]}})});["arrayBuffer","blob","clone","formData","json","text"].forEach(e=>{Object.defineProperty(Y.prototype,e,{value:function(){return this[W]()[e]()}})});Object.defineProperty(Y.prototype,Symbol.for("nodejs.util.inspect.custom"),{value:function(e,r,n){let t={status:this.status,headers:this.headers,ok:this.ok,nativeResponse:this[er]};return`Response (lightweight) ${n(t,{...r,depth:e==null?null:e-1})}`}});Object.setPrototypeOf(Y,tr);Object.setPrototypeOf(Y.prototype,tr.prototype);async function Bt(e){return Promise.race([e,Promise.resolve().then(()=>Promise.resolve(void 0))])}function qr(e,r,n){let t=a=>{e.cancel(a).catch(()=>{})};return r.on("close",t),r.on("error",t),(n??e.read()).then(o,i),e.closed.finally(()=>{r.off("close",t),r.off("error",t)});function i(a){a&&r.destroy(a)}function s(){e.read().then(o,i)}function o({done:a,value:l}){try{if(a)r.end();else if(!r.write(l))r.once("drain",s);else return e.read().then(o,i)}catch(c){i(c)}}}function Ut(e,r){if(e.locked)throw new TypeError("ReadableStream is locked.");return r.destroyed?void 0:qr(e.getReader(),r)}var rr=e=>{let r={};e instanceof Headers||(e=new Headers(e??void 0));let n=[];for(let[t,i]of e)t==="set-cookie"?n.push(i):r[t]=i;return n.length>0&&(r["set-cookie"]=n),r["content-type"]??="text/plain; charset=UTF-8",r},qt="x-hono-already-sent";typeof global.crypto>"u"&&(global.crypto=Wt);var ir=Symbol("outgoingEnded"),Mr=Symbol("incomingDraining"),Gt=500,Kt=64*1024*1024,Xe=e=>{let r=e;if(e.destroyed||r[Mr])return;if(r[Mr]=!0,e instanceof Hr){try{e.stream?.close?.(jt.NGHTTP2_NO_ERROR)}catch{}return}let n=0,t=()=>{clearTimeout(s),e.off("data",o),e.off("end",t),e.off("error",t)},i=()=>{t();let a=e.socket;a&&!a.destroyed&&a.destroySoon()},s=setTimeout(i,Gt);s.unref?.();let o=a=>{n+=a.length,n>Kt&&i()};e.on("data",o),e.on("end",t),e.on("error",t),e.resume()},Yt=()=>new Response(null,{status:400}),Wr=e=>new Response(null,{status:e instanceof Error&&(e.name==="TimeoutError"||e.constructor.name==="TimeoutError")?504:500}),nr=(e,r)=>{let n=e instanceof Error?e:new Error("unknown error",{cause:e});n.code==="ERR_STREAM_PREMATURE_CLOSE"?console.info("The user aborted a request."):(console.error(e),r.headersSent||r.writeHead(500,{"Content-Type":"text/plain"}),r.end(`Error: ${n.message}`),r.destroy(n))},Gr=e=>{"flushHeaders"in e&&e.writable&&e.flushHeaders()},Kr=async(e,r)=>{let[n,t,i]=e[L],s=!1;if(!i)i={"content-type":"text/plain; charset=UTF-8"};else if(i instanceof Headers)s=i.has("content-length"),i=rr(i);else if(Array.isArray(i)){let o=new Headers(i);s=o.has("content-length"),i=rr(o)}else for(let o in i)if(o.length===14&&o.toLowerCase()==="content-length"){s=!0;break}s||(typeof t=="string"?i["Content-Length"]=Buffer.byteLength(t):t instanceof Uint8Array?i["Content-Length"]=t.byteLength:t instanceof Blob&&(i["Content-Length"]=t.size)),r.writeHead(n,i),typeof t=="string"||t instanceof Uint8Array?r.end(t):t instanceof Blob?r.end(new Uint8Array(await t.arrayBuffer())):(Gr(r),await Ut(t,r)?.catch(o=>nr(o,r))),r[ir]?.()},Vt=e=>typeof e.then=="function",Zt=async(e,r,n={})=>{if(Vt(e))if(n.errorHandler)try{e=await e}catch(i){let s=await n.errorHandler(i);if(!s)return;e=s}else e=await e.catch(Wr);if(L in e)return Kr(e,r);let t=rr(e.headers);if(e.body){let i=e.body.getReader(),s=[],o=!1,a;if(t["transfer-encoding"]!=="chunked"){let l=2;for(let c=0;c<l;c++){a||=i.read();let f=await Bt(a).catch(u=>{console.error(u),o=!0});if(!f){if(c===1){await new Promise(u=>setTimeout(u)),l=3;continue}break}if(a=void 0,f.value&&s.push(f.value),f.done){o=!0;break}}o&&!("content-length"in t)&&(t["content-length"]=s.reduce((c,f)=>c+f.length,0))}r.writeHead(e.status,t),s.forEach(l=>{r.write(l)}),o?r.end():(s.length===0&&Gr(r),await qr(i,r,a))}else t[qt]||(r.writeHead(e.status,t),r.end());r[ir]?.()},Jt=(e,r={})=>{let n=r.autoCleanupIncoming??!0;return r.overrideGlobalObjects!==!1&&global.Request!==fe&&(Object.defineProperty(global,"Request",{value:fe}),Object.defineProperty(global,"Response",{value:Y})),async(t,i)=>{let s,o;try{o=zt(t,r.hostname);let a=!n||t.method==="GET"||t.method==="HEAD";if(a||(t[zr]=!0,t.on("end",()=>{a=!0}),t instanceof Hr&&(i[ir]=()=>{a||setTimeout(()=>{a||setTimeout(()=>{Xe(t)})})}),i.on("finish",()=>{a||Xe(t)})),i.on("close",()=>{o[G]&&(t.errored?o[G].abort(t.errored.toString()):i.writableFinished||o[G].abort("Client connection prematurely closed.")),a||setTimeout(()=>{a||setTimeout(()=>{Xe(t)})})}),s=e(o,{incoming:t,outgoing:i}),L in s)return Kr(s,i)}catch(a){if(s)return nr(a,i);if(r.errorHandler){if(s=await r.errorHandler(o?a:Nt(a)),!s)return}else o?s=Wr(a):s=Yt()}try{return await Zt(s,i,r)}catch(a){return nr(a,i)}}},Qt=e=>{let r=e.fetch,n=Jt(r,{hostname:e.hostname,overrideGlobalObjects:e.overrideGlobalObjects,autoCleanupIncoming:e.autoCleanupIncoming});return(e.createServer||Ft)(e.serverOptions||{},n)},Yr=(e,r)=>{let n=Qt(e);return n.listen(e?.port??3e3,e.hostname,()=>{let t=n.address();r&&r(t)}),n};var or=(e,r,n)=>(t,i)=>{let s=-1;return o(0);async function o(a){if(a<=s)throw new Error("next() called multiple times");s=a;let l,c=!1,f;if(e[a]?(f=e[a][0][0],t.req.routeIndex=a):f=a===e.length&&i||void 0,f)try{l=await f(t,()=>o(a+1))}catch(u){if(u instanceof Error&&r)t.error=u,l=await r(u,t),c=!0;else throw u}else t.finalized===!1&&n&&(l=await n(t));return l&&(t.finalized===!1||c)&&(t.res=l),t}};var Vr=Symbol();var Zr=async(e,r=Object.create(null))=>{let{all:n=!1,dot:t=!1}=r,s=(e instanceof Pe?e.raw.headers:e.headers).get("Content-Type");return s?.startsWith("multipart/form-data")||s?.startsWith("application/x-www-form-urlencoded")?Xt(e,{all:n,dot:t}):{}};async function Xt(e,r){let n=await e.formData();return n?ei(n,r):{}}function ei(e,r){let n=Object.create(null);return e.forEach((t,i)=>{r.all||i.endsWith("[]")?ri(n,i,t):n[i]=t}),r.dot&&Object.entries(n).forEach(([t,i])=>{t.includes(".")&&(ni(n,t,i),delete n[t])}),n}var ri=(e,r,n)=>{e[r]!==void 0?Array.isArray(e[r])?e[r].push(n):e[r]=[e[r],n]:r.endsWith("[]")?e[r]=[n]:e[r]=n},ni=(e,r,n)=>{if(/(?:^|\.)__proto__\./.test(r))return;let t=e,i=r.split(".");i.forEach((s,o)=>{o===i.length-1?t[s]=n:((!t[s]||typeof t[s]!="object"||Array.isArray(t[s])||t[s]instanceof File)&&(t[s]=Object.create(null)),t=t[s])})};var ar=e=>{let r=e.split("/");return r[0]===""&&r.shift(),r},Jr=e=>{let{groups:r,path:n}=ti(e),t=ar(n);return ii(t,r)},ti=e=>{let r=[];return e=e.replace(/\{[^}]+\}/g,(n,t)=>{let i=`@${t}`;return r.push([i,n]),i}),{groups:r,path:e}},ii=(e,r)=>{for(let n=r.length-1;n>=0;n--){let[t]=r[n];for(let i=e.length-1;i>=0;i--)if(e[i].includes(t)){e[i]=e[i].replace(t,r[n][1]);break}}return e},Oe={},Qr=(e,r)=>{if(e==="*")return"*";let n=e.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);if(n){let t=`${e}#${r}`;return Oe[t]||(n[2]?Oe[t]=r&&r[0]!==":"&&r[0]!=="*"?[t,n[1],new RegExp(`^${n[2]}(?=/${r})`)]:[e,n[1],new RegExp(`^${n[2]}$`)]:Oe[t]=[e,n[1],!0]),Oe[t]}return null},Ie=(e,r)=>{try{return r(e)}catch{return e.replace(/(?:%[0-9A-Fa-f]{2})+/g,n=>{try{return r(n)}catch{return n}})}},oi=e=>Ie(e,decodeURI),lr=e=>{let r=e.url,n=r.indexOf("/",r.indexOf(":")+4),t=n;for(;t<r.length;t++){let i=r.charCodeAt(t);if(i===37){let s=r.indexOf("?",t),o=r.indexOf("#",t),a=s===-1?o===-1?void 0:o:o===-1?s:Math.min(s,o),l=r.slice(n,a);return oi(l.includes("%25")?l.replace(/%25/g,"%2525"):l)}else if(i===63||i===35)break}return r.slice(n,t)};var Xr=e=>{let r=lr(e);return r.length>1&&r.at(-1)==="/"?r.slice(0,-1):r},D=(e,r,...n)=>(n.length&&(r=D(r,...n)),`${e?.[0]==="/"?"":"/"}${e}${r==="/"?"":`${e?.at(-1)==="/"?"":"/"}${r?.[0]==="/"?r.slice(1):r}`}`),_e=e=>{if(e.charCodeAt(e.length-1)!==63||!e.includes(":"))return null;let r=e.split("/"),n=[],t="";return r.forEach(i=>{if(i!==""&&!/\:/.test(i))t+="/"+i;else if(/\:/.test(i))if(/\?/.test(i)){n.length===0&&t===""?n.push("/"):n.push(t);let s=i.replace("?","");t+="/"+s,n.push(t)}else t+="/"+i}),n.filter((i,s,o)=>o.indexOf(i)===s)},sr=e=>/[%+]/.test(e)?(e.indexOf("+")!==-1&&(e=e.replace(/\+/g," ")),e.indexOf("%")!==-1?Ie(e,cr):e):e,en=(e,r,n)=>{let t;if(!n&&r&&!/[%+]/.test(r)){let o=e.indexOf("?",8);if(o===-1)return;for(e.startsWith(r,o+1)||(o=e.indexOf(`&${r}`,o+1));o!==-1;){let a=e.charCodeAt(o+r.length+1);if(a===61){let l=o+r.length+2,c=e.indexOf("&",l);return sr(e.slice(l,c===-1?void 0:c))}else if(a==38||isNaN(a))return"";o=e.indexOf(`&${r}`,o+1)}if(t=/[%+]/.test(e),!t)return}let i={};t??=/[%+]/.test(e);let s=e.indexOf("?",8);for(;s!==-1;){let o=e.indexOf("&",s+1),a=e.indexOf("=",s);a>o&&o!==-1&&(a=-1);let l=e.slice(s+1,a===-1?o===-1?void 0:o:a);if(t&&(l=sr(l)),s=o,l==="")continue;let c;a===-1?c="":(c=e.slice(a+1,o===-1?void 0:o),t&&(c=sr(c))),n?(i[l]&&Array.isArray(i[l])||(i[l]=[]),i[l].push(c)):i[l]??=c}return r?i[r]:i},rn=en,nn=(e,r)=>en(e,r,!0),cr=decodeURIComponent;var tn=e=>Ie(e,cr),Pe=class{raw;#r;#e;routeIndex=0;path;bodyCache={};constructor(e,r="/",n=[[]]){this.raw=e,this.path=r,this.#e=n,this.#r={}}param(e){return e?this.#n(e):this.#o()}#n(e){let r=this.#e[0][this.routeIndex][1][e],n=this.#i(r);return n&&/\%/.test(n)?tn(n):n}#o(){let e={},r=Object.keys(this.#e[0][this.routeIndex][1]);for(let n of r){let t=this.#i(this.#e[0][this.routeIndex][1][n]);t!==void 0&&(e[n]=/\%/.test(t)?tn(t):t)}return e}#i(e){return this.#e[1]?this.#e[1][e]:e}query(e){return rn(this.url,e)}queries(e){return nn(this.url,e)}header(e){if(e)return this.raw.headers.get(e)??void 0;let r={};return this.raw.headers.forEach((n,t)=>{r[t]=n}),r}async parseBody(e){return this.bodyCache.parsedBody??=await Zr(this,e)}#t=e=>{let{bodyCache:r,raw:n}=this,t=r[e];if(t)return t;let i=Object.keys(r)[0];return i?r[i].then(s=>(i==="json"&&(s=JSON.stringify(s)),new Response(s)[e]())):r[e]=n[e]()};json(){return this.#t("text").then(e=>JSON.parse(e))}text(){return this.#t("text")}arrayBuffer(){return this.#t("arrayBuffer")}blob(){return this.#t("blob")}formData(){return this.#t("formData")}addValidatedData(e,r){this.#r[e]=r}valid(e){return this.#r[e]}get url(){return this.raw.url}get method(){return this.raw.method}get[Vr](){return this.#e}get matchedRoutes(){return this.#e[0].map(([[,e]])=>e)}get routePath(){return this.#e[0].map(([[,e]])=>e)[this.routeIndex].path}};var on={Stringify:1,BeforeStream:2,Stream:3},si=(e,r)=>{let n=new String(e);return n.isEscaped=!0,n.callbacks=r,n};var ur=async(e,r,n,t,i)=>{typeof e=="object"&&!(e instanceof String)&&(e instanceof Promise||(e=e.toString()),e instanceof Promise&&(e=await e));let s=e.callbacks;if(!s?.length)return Promise.resolve(e);i?i[0]+=e:i=[e];let o=Promise.all(s.map(a=>a({phase:r,buffer:i,context:t}))).then(a=>Promise.all(a.filter(Boolean).map(l=>ur(l,r,!1,t,i))).then(()=>i[0]));return n?si(await o,s):o};var ai="text/plain; charset=UTF-8",fr=(e,r)=>({"Content-Type":e,...r}),de=(e,r)=>new Response(e,r),sn=class{#r;#e;env={};#n;finalized=!1;error;#o;#i;#t;#u;#l;#c;#a;#f;#p;constructor(e,r){this.#r=e,r&&(this.#i=r.executionCtx,this.env=r.env,this.#c=r.notFoundHandler,this.#p=r.path,this.#f=r.matchResult)}get req(){return this.#e??=new Pe(this.#r,this.#p,this.#f),this.#e}get event(){if(this.#i&&"respondWith"in this.#i)return this.#i;throw Error("This context has no FetchEvent")}get executionCtx(){if(this.#i)return this.#i;throw Error("This context has no ExecutionContext")}get res(){return this.#t||=de(null,{headers:this.#a??=new Headers})}set res(e){if(this.#t&&e){e=de(e.body,e);for(let[r,n]of this.#t.headers.entries())if(r!=="content-type")if(r==="set-cookie"){let t=this.#t.headers.getSetCookie();e.headers.delete("set-cookie");for(let i of t)e.headers.append("set-cookie",i)}else e.headers.set(r,n)}this.#t=e,this.finalized=!0}render=(...e)=>(this.#l??=r=>this.html(r),this.#l(...e));setLayout=e=>this.#u=e;getLayout=()=>this.#u;setRenderer=e=>{this.#l=e};header=(e,r,n)=>{this.finalized&&(this.#t=de(this.#t.body,this.#t));let t=this.#t?this.#t.headers:this.#a??=new Headers;r===void 0?t.delete(e):n?.append?t.append(e,r):t.set(e,r)};status=e=>{this.#o=e};set=(e,r)=>{this.#n??=new Map,this.#n.set(e,r)};get=e=>this.#n?this.#n.get(e):void 0;get var(){return this.#n?Object.fromEntries(this.#n):{}}#s(e,r,n){let t=this.#t?new Headers(this.#t.headers):this.#a??new Headers;if(typeof r=="object"&&"headers"in r){let s=r.headers instanceof Headers?r.headers:new Headers(r.headers);for(let[o,a]of s)o.toLowerCase()==="set-cookie"?t.append(o,a):t.set(o,a)}if(n)for(let[s,o]of Object.entries(n))if(typeof o=="string")t.set(s,o);else{t.delete(s);for(let a of o)t.append(s,a)}let i=typeof r=="number"?r:r?.status??this.#o;return de(e,{status:i,headers:t})}newResponse=(...e)=>this.#s(...e);body=(e,r,n)=>this.#s(e,r,n);text=(e,r,n)=>!this.#a&&!this.#o&&!r&&!n&&!this.finalized?new Response(e):this.#s(e,r,fr(ai,n));json=(e,r,n)=>this.#s(JSON.stringify(e),r,fr("application/json",n));html=(e,r,n)=>{let t=i=>this.#s(i,r,fr("text/html; charset=UTF-8",n));return typeof e=="object"?ur(e,on.Stringify,!1,{}).then(t):t(e)};redirect=(e,r)=>{let n=String(e);return this.header("Location",/[^\x00-\xFF]/.test(n)?encodeURI(n):n),this.newResponse(null,r??302)};notFound=()=>(this.#c??=()=>de(),this.#c(this))};var A="ALL",an="all",ln=["get","post","put","delete","options","patch"],Fe="Can not add a route since the matcher is already built.",je=class extends Error{};var cn="__COMPOSED_HANDLER";var li=e=>e.text("404 Not Found",404),un=(e,r)=>{if("getResponse"in e){let n=e.getResponse();return r.newResponse(n.body,n)}return console.error(e),r.text("Internal Server Error",500)},fn=class pn{get;post;put;delete;options;patch;all;on;use;router;getPath;_basePath="/";#r="/";routes=[];constructor(r={}){[...ln,an].forEach(s=>{this[s]=(o,...a)=>(typeof o=="string"?this.#r=o:this.#o(s,this.#r,o),a.forEach(l=>{this.#o(s,this.#r,l)}),this)}),this.on=(s,o,...a)=>{for(let l of[o].flat()){this.#r=l;for(let c of[s].flat())a.map(f=>{this.#o(c.toUpperCase(),this.#r,f)})}return this},this.use=(s,...o)=>(typeof s=="string"?this.#r=s:(this.#r="*",o.unshift(s)),o.forEach(a=>{this.#o(A,this.#r,a)}),this);let{strict:t,...i}=r;Object.assign(this,i),this.getPath=t??!0?r.getPath??lr:Xr}#e(){let r=new pn({router:this.router,getPath:this.getPath});return r.errorHandler=this.errorHandler,r.#n=this.#n,r.routes=this.routes,r}#n=li;errorHandler=un;route(r,n){let t=this.basePath(r);return n.routes.map(i=>{let s;n.errorHandler===un?s=i.handler:(s=async(o,a)=>(await or([],n.errorHandler)(o,()=>i.handler(o,a))).res,s[cn]=i.handler),t.#o(i.method,i.path,s)}),this}basePath(r){let n=this.#e();return n._basePath=D(this._basePath,r),n}onError=r=>(this.errorHandler=r,this);notFound=r=>(this.#n=r,this);mount(r,n,t){let i,s;t&&(typeof t=="function"?s=t:(s=t.optionHandler,t.replaceRequest===!1?i=l=>l:i=t.replaceRequest));let o=s?l=>{let c=s(l);return Array.isArray(c)?c:[c]}:l=>{let c;try{c=l.executionCtx}catch{}return[l.env,c]};i||=(()=>{let l=D(this._basePath,r),c=l==="/"?0:l.length;return f=>{let u=new URL(f.url);return u.pathname=u.pathname.slice(c)||"/",new Request(u,f)}})();let a=async(l,c)=>{let f=await n(i(l.req.raw),...o(l));if(f)return f;await c()};return this.#o(A,D(r,"*"),a),this}#o(r,n,t){r=r.toUpperCase(),n=D(this._basePath,n);let i={basePath:this._basePath,path:n,method:r,handler:t};this.router.add(r,n,[t,i]),this.routes.push(i)}#i(r,n){if(r instanceof Error)return this.errorHandler(r,n);throw r}#t(r,n,t,i){if(i==="HEAD")return(async()=>new Response(null,await this.#t(r,n,t,"GET")))();let s=this.getPath(r,{env:t}),o=this.router.match(i,s),a=new sn(r,{path:s,matchResult:o,env:t,executionCtx:n,notFoundHandler:this.#n});if(o[0].length===1){let c;try{c=o[0][0][0][0](a,async()=>{a.res=await this.#n(a)})}catch(f){return this.#i(f,a)}return c instanceof Promise?c.then(f=>f||(a.finalized?a.res:this.#n(a))).catch(f=>this.#i(f,a)):c??this.#n(a)}let l=or(o[0],this.errorHandler,this.#n);return(async()=>{try{let c=await l(a);if(!c.finalized)throw new Error("Context is not finalized. Did you forget to return a Response object or `await next()`?");return c.res}catch(c){return this.#i(c,a)}})()}fetch=(r,...n)=>this.#t(r,n[1],n[0],r.method);request=(r,n,t,i)=>r instanceof Request?this.fetch(n?new Request(r,n):r,t,i):(r=r.toString(),this.fetch(new Request(/^https?:\/\//.test(r)?r:`http://localhost${D("/",r)}`,n),t,i));fire=()=>{addEventListener("fetch",r=>{r.respondWith(this.#t(r.request,r,void 0,r.request.method))})}};var Ne=[];function pr(e,r){let n=this.buildAllMatchers(),t=((i,s)=>{let o=n[i]||n[A],a=o[2][s];if(a)return a;let l=s.match(o[0]);if(!l)return[[],Ne];let c=l.indexOf("",1);return[o[1][c],l]});return this.match=t,t(e,r)}var Le="[^/]+",he=".*",me="(?:|/.*)",$=Symbol(),ci=new Set(".\\+*[^]$()");function ui(e,r){return e.length===1?r.length===1?e<r?-1:1:-1:r.length===1||e===he||e===me?1:r===he||r===me?-1:e===Le?1:r===Le?-1:e.length===r.length?e<r?-1:1:r.length-e.length}var dn=class dr{#r;#e;#n=Object.create(null);insert(r,n,t,i,s){if(r.length===0){if(this.#r!==void 0)throw $;if(s)return;this.#r=n;return}let[o,...a]=r,l=o==="*"?a.length===0?["","",he]:["","",Le]:o==="/*"?["","",me]:o.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/),c;if(l){let f=l[1],u=l[2]||Le;if(f&&l[2]&&(u===".*"||(u=u.replace(/^\((?!\?:)(?=[^)]+\)$)/,"(?:"),/\((?!\?:)/.test(u))))throw $;if(c=this.#n[u],!c){if(Object.keys(this.#n).some(p=>p!==he&&p!==me))throw $;if(s)return;c=this.#n[u]=new dr,f!==""&&(c.#e=i.varIndex++)}!s&&f!==""&&t.push([f,c.#e])}else if(c=this.#n[o],!c){if(Object.keys(this.#n).some(f=>f.length>1&&f!==he&&f!==me))throw $;if(s)return;c=this.#n[o]=new dr}c.insert(a,n,t,i,s)}buildRegExpStr(){let n=Object.keys(this.#n).sort(ui).map(t=>{let i=this.#n[t];return(typeof i.#e=="number"?`(${t})@${i.#e}`:ci.has(t)?`\\${t}`:t)+i.buildRegExpStr()});return typeof this.#r=="number"&&n.unshift(`#${this.#r}`),n.length===0?"":n.length===1?n[0]:"(?:"+n.join("|")+")"}};var hn=class{#r={varIndex:0};#e=new dn;insert(e,r,n){let t=[],i=[];for(let o=0;;){let a=!1;if(e=e.replace(/\{[^}]+\}/g,l=>{let c=`@\\${o}`;return i[o]=[c,l],o++,a=!0,c}),!a)break}let s=e.match(/(?::[^\/]+)|(?:\/\*$)|./g)||[];for(let o=i.length-1;o>=0;o--){let[a]=i[o];for(let l=s.length-1;l>=0;l--)if(s[l].indexOf(a)!==-1){s[l]=s[l].replace(a,i[o][1]);break}}return this.#e.insert(s,r,t,this.#r,n),t}buildRegExp(){let e=this.#e.buildRegExpStr();if(e==="")return[/^$/,[],[]];let r=0,n=[],t=[];return e=e.replace(/#(\d+)|@(\d+)|\.\*\$/g,(i,s,o)=>s!==void 0?(n[++r]=Number(s),"$()"):(o!==void 0&&(t[Number(o)]=++r),"")),[new RegExp(`^${e}`),n,t]}};var fi=[/^$/,[],Object.create(null)],mn=Object.create(null);function gn(e){return mn[e]??=new RegExp(e==="*"?"":`^${e.replace(/\/\*$|([.\\+*[^\]$()])/g,(r,n)=>n?`\\${n}`:"(?:|/.*)")}$`)}function pi(){mn=Object.create(null)}function di(e){let r=new hn,n=[];if(e.length===0)return fi;let t=e.map(c=>[!/\*|\/:/.test(c[0]),...c]).sort(([c,f],[u,p])=>c?1:u?-1:f.length-p.length),i=Object.create(null);for(let c=0,f=-1,u=t.length;c<u;c++){let[p,d,m]=t[c];p?i[d]=[m.map(([x])=>[x,Object.create(null)]),Ne]:f++;let y;try{y=r.insert(d,f,p)}catch(x){throw x===$?new je(d):x}p||(n[f]=m.map(([x,v])=>{let g=Object.create(null);for(v-=1;v>=0;v--){let[le,Ze]=y[v];g[le]=Ze}return[x,g]}))}let[s,o,a]=r.buildRegExp();for(let c=0,f=n.length;c<f;c++)for(let u=0,p=n[c].length;u<p;u++){let d=n[c][u]?.[1];if(!d)continue;let m=Object.keys(d);for(let y=0,x=m.length;y<x;y++)d[m[y]]=a[d[m[y]]]}let l=[];for(let c in o)l[c]=n[o[c]];return[s,l,i]}function V(e,r){if(e){for(let n of Object.keys(e).sort((t,i)=>i.length-t.length))if(gn(n).test(r))return[...e[n]]}}var De=class{name="RegExpRouter";#r;#e;constructor(){this.#r={[A]:Object.create(null)},this.#e={[A]:Object.create(null)}}add(e,r,n){let t=this.#r,i=this.#e;if(!t||!i)throw new Error(Fe);t[e]||[t,i].forEach(a=>{a[e]=Object.create(null),Object.keys(a[A]).forEach(l=>{a[e][l]=[...a[A][l]]})}),r==="/*"&&(r="*");let s=(r.match(/\/:/g)||[]).length;if(/\*$/.test(r)){let a=gn(r);e===A?Object.keys(t).forEach(l=>{t[l][r]||=V(t[l],r)||V(t[A],r)||[]}):t[e][r]||=V(t[e],r)||V(t[A],r)||[],Object.keys(t).forEach(l=>{(e===A||e===l)&&Object.keys(t[l]).forEach(c=>{a.test(c)&&t[l][c].push([n,s])})}),Object.keys(i).forEach(l=>{(e===A||e===l)&&Object.keys(i[l]).forEach(c=>a.test(c)&&i[l][c].push([n,s]))});return}let o=_e(r)||[r];for(let a=0,l=o.length;a<l;a++){let c=o[a];Object.keys(i).forEach(f=>{(e===A||e===f)&&(i[f][c]||=[...V(t[f],c)||V(t[A],c)||[]],i[f][c].push([n,s-l+a+1]))})}}match=pr;buildAllMatchers(){let e=Object.create(null);return Object.keys(this.#e).concat(Object.keys(this.#r)).forEach(r=>{e[r]||=this.#n(r)}),this.#r=this.#e=void 0,pi(),e}#n(e){let r=[],n=e===A;return[this.#r,this.#e].forEach(t=>{let i=t[e]?Object.keys(t[e]).map(s=>[s,t[e][s]]):[];i.length!==0?(n||=!0,r.push(...i)):e!==A&&r.push(...Object.keys(t[A]).map(s=>[s,t[A][s]]))}),n?di(r):null}};var hr=class{name="SmartRouter";#r=[];#e=[];constructor(e){this.#r=e.routers}add(e,r,n){if(!this.#e)throw new Error(Fe);this.#e.push([e,r,n])}match(e,r){if(!this.#e)throw new Error("Fatal error");let n=this.#r,t=this.#e,i=n.length,s=0,o;for(;s<i;s++){let a=n[s];try{for(let l=0,c=t.length;l<c;l++)a.add(...t[l]);o=a.match(e,r)}catch(l){if(l instanceof je)continue;throw l}this.match=a.match.bind(a),this.#r=[a],this.#e=void 0;break}if(s===i)throw new Error("Fatal error");return this.name=`SmartRouter + ${this.activeRouter.name}`,o}get activeRouter(){if(this.#e||this.#r.length!==1)throw new Error("No active router has been determined yet.");return this.#r[0]}};var ge=Object.create(null),hi=e=>{for(let r in e)return!0;return!1},yn=class xn{#r;#e;#n;#o=0;#i=ge;constructor(r,n,t){if(this.#e=t||Object.create(null),this.#r=[],r&&n){let i=Object.create(null);i[r]={handler:n,possibleKeys:[],score:0},this.#r=[i]}this.#n=[]}insert(r,n,t){this.#o=++this.#o;let i=this,s=Jr(n),o=[];for(let a=0,l=s.length;a<l;a++){let c=s[a],f=s[a+1],u=Qr(c,f),p=Array.isArray(u)?u[0]:c;if(p in i.#e){i=i.#e[p],u&&o.push(u[1]);continue}i.#e[p]=new xn,u&&(i.#n.push(u),o.push(u[1])),i=i.#e[p]}return i.#r.push({[r]:{handler:t,possibleKeys:o.filter((a,l,c)=>c.indexOf(a)===l),score:this.#o}}),i}#t(r,n,t,i,s){for(let o=0,a=n.#r.length;o<a;o++){let l=n.#r[o],c=l[t]||l[A],f={};if(c!==void 0&&(c.params=Object.create(null),r.push(c),i!==ge||s&&s!==ge))for(let u=0,p=c.possibleKeys.length;u<p;u++){let d=c.possibleKeys[u],m=f[c.score];c.params[d]=s?.[d]&&!m?s[d]:i[d]??s?.[d],f[c.score]=!0}}}search(r,n){let t=[];this.#i=ge;let s=[this],o=ar(n),a=[],l=o.length,c=null;for(let f=0;f<l;f++){let u=o[f],p=f===l-1,d=[];for(let y=0,x=s.length;y<x;y++){let v=s[y],g=v.#e[u];g&&(g.#i=v.#i,p?(g.#e["*"]&&this.#t(t,g.#e["*"],r,v.#i),this.#t(t,g,r,v.#i)):d.push(g));for(let le=0,Ze=v.#n.length;le<Ze;le++){let Lr=v.#n[le],_=v.#i===ge?{}:{...v.#i};if(Lr==="*"){let q=v.#e["*"];q&&(this.#t(t,q,r,v.#i),q.#i=_,d.push(q));continue}let[_t,Dr,ce]=Lr;if(!u&&!(ce instanceof RegExp))continue;let P=v.#e[_t];if(ce instanceof RegExp){if(c===null){c=new Array(l);let ke=n[0]==="/"?1:0;for(let ue=0;ue<l;ue++)c[ue]=ke,ke+=o[ue].length+1}let q=n.substring(c[f]),Je=ce.exec(q);if(Je){if(_[Dr]=Je[0],this.#t(t,P,r,v.#i,_),hi(P.#e)){P.#i=_;let ke=Je[0].match(/\//)?.length??0;(a[ke]||=[]).push(P)}continue}}(ce===!0||ce.test(u))&&(_[Dr]=u,p?(this.#t(t,P,r,_,v.#i),P.#e["*"]&&this.#t(t,P.#e["*"],r,_,v.#i)):(P.#i=_,d.push(P)))}}let m=a.shift();s=m?d.concat(m):d}return t.length>1&&t.sort((f,u)=>f.score-u.score),[t.map(({handler:f,params:u})=>[f,u])]}};var mr=class{name="TrieRouter";#r;constructor(){this.#r=new yn}add(e,r,n){let t=_e(r);if(t){for(let i=0,s=t.length;i<s;i++)this.#r.insert(e,t[i],n);return}this.#r.insert(e,r,n)}match(e,r){return this.#r.search(e,r)}};var O=class extends fn{constructor(e={}){super(e),this.router=e.router??new hr({routers:[new De,new mr]})}};var vn=e=>{let n={...{origin:"*",allowMethods:["GET","HEAD","PUT","POST","DELETE","PATCH"],allowHeaders:[],exposeHeaders:[]},...e},t=(s=>typeof s=="string"?s==="*"?()=>s:o=>s===o?o:null:typeof s=="function"?s:o=>s.includes(o)?o:null)(n.origin),i=(s=>typeof s=="function"?s:Array.isArray(s)?()=>s:()=>[])(n.allowMethods);return async function(o,a){function l(f,u){o.res.headers.set(f,u)}let c=await t(o.req.header("origin")||"",o);if(c&&l("Access-Control-Allow-Origin",c),n.credentials&&l("Access-Control-Allow-Credentials","true"),n.exposeHeaders?.length&&l("Access-Control-Expose-Headers",n.exposeHeaders.join(",")),o.req.method==="OPTIONS"){n.origin!=="*"&&l("Vary","Origin"),n.maxAge!=null&&l("Access-Control-Max-Age",n.maxAge.toString());let f=await i(o.req.header("origin")||"",o);f.length&&l("Access-Control-Allow-Methods",f.join(","));let u=n.allowHeaders;if(!u?.length){let p=o.req.header("Access-Control-Request-Headers");p&&(u=p.split(/\s*,\s*/))}return u?.length&&(l("Access-Control-Allow-Headers",u.join(",")),o.res.headers.append("Vary","Access-Control-Request-Headers")),o.res.headers.delete("Content-Length"),o.res.headers.delete("Content-Type"),new Response(null,{headers:o.res.headers,status:204,statusText:"No Content"})}await a(),n.origin!=="*"&&o.header("Vary","Origin",{append:!0})}};function mi(){let{process:e,Deno:r}=globalThis;return!(typeof r?.noColor=="boolean"?r.noColor:e!==void 0?"NO_COLOR"in e?.env:!1)}async function An(){let{navigator:e}=globalThis,r="cloudflare:workers";return!(e!==void 0&&e.userAgent==="Cloudflare-Workers"?await(async()=>{try{return"NO_COLOR"in((await import(r)).env??{})}catch{return!1}})():!mi())}var gi=e=>{let[r,n]=[",","."];return e.map(i=>i.replace(/(\d)(?=(\d\d\d)+(?!\d))/g,"$1"+r)).join(n)},yi=e=>{let r=Date.now()-e;return gi([r<1e3?r+"ms":Math.round(r/1e3)+"s"])},xi=async e=>{if(await An())switch(e/100|0){case 5:return`\x1B[31m${e}\x1B[0m`;case 4:return`\x1B[33m${e}\x1B[0m`;case 3:return`\x1B[36m${e}\x1B[0m`;case 2:return`\x1B[32m${e}\x1B[0m`}return`${e}`};async function bn(e,r,n,t,i=0,s){let o=r==="<--"?`${r} ${n} ${t}`:`${r} ${n} ${t} ${await xi(i)} ${s}`;e(o)}var wn=(e=console.log)=>async function(n,t){let{method:i,url:s}=n.req,o=s.slice(s.indexOf("/",8));await bn(e,"<--",i,o);let a=Date.now();await t(),await bn(e,"-->",i,o,n.res.status,yi(a))};import{existsSync as vi,readFileSync as Ai}from"node:fs";import{dirname as bi,resolve as Rn}from"node:path";import{fileURLToPath as wi}from"node:url";var Cn="apv.config.json",Z=null,En;function kn(e){En=e}function M(){if(Z)return Z;let e=process.env.APV_CONFIG,r=[En,e,Rn(process.cwd(),Cn),Rn(bi(wi(import.meta.url)),"..","..","..",Cn)].filter(Boolean);for(let n of r)if(vi(n))try{let t=Ai(n,"utf-8"),i=JSON.parse(t);return Z={cacheDir:i.cacheDir,customTaskDocs:i.customTaskDocs??{}},console.log(`Loaded config from ${n}`),Z}catch(t){console.warn(`Failed to parse ${n}:`,t)}return Z={customTaskDocs:{}},Z}function $e(e){let r=e.startsWith("/"),n=e.split("/").filter(s=>s!==""&&s!=="."),t=[];for(let s of n)s===".."?t.length>0&&t[t.length-1]!==".."?t.pop():r||t.push(s):t.push(s);let i=t.join("/");return r?`/${i}`:i}function Bn(e){return typeof e>"u"||e===null}function Ci(e){return typeof e=="object"&&e!==null}function Ei(e){return Array.isArray(e)?e:Bn(e)?[]:[e]}function ki(e,r){var n,t,i,s;if(r)for(s=Object.keys(r),n=0,t=s.length;n<t;n+=1)i=s[n],e[i]=r[i];return e}function Si(e,r){var n="",t;for(t=0;t<r;t+=1)n+=e;return n}function Ti(e){return e===0&&Number.NEGATIVE_INFINITY===1/e}var Pi=Bn,Oi=Ci,Ii=Ei,_i=Si,Fi=Ti,ji=ki,w={isNothing:Pi,isObject:Oi,toArray:Ii,repeat:_i,isNegativeZero:Fi,extend:ji};function Un(e,r){var n="",t=e.reason||"(unknown reason)";return e.mark?(e.mark.name&&(n+='in "'+e.mark.name+'" '),n+="("+(e.mark.line+1)+":"+(e.mark.column+1)+")",!r&&e.mark.snippet&&(n+=`
|
|
3
3
|
|
|
4
4
|
`+e.mark.snippet),t+" "+n):t}function xe(e,r){Error.call(this),this.name="YAMLException",this.reason=e,this.mark=r,this.message=Un(this,!1),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack||""}xe.prototype=Object.create(Error.prototype);xe.prototype.constructor=xe;xe.prototype.toString=function(r){return this.name+": "+Un(this,r)};var E=xe;function gr(e,r,n,t,i){var s="",o="",a=Math.floor(i/2)-1;return t-r>a&&(s=" ... ",r=t-a+s.length),n-t>a&&(o=" ...",n=t+a-o.length),{str:s+e.slice(r,n).replace(/\t/g,"\u2192")+o,pos:t-r+s.length}}function yr(e,r){return w.repeat(" ",r-e.length)+e}function Ni(e,r){if(r=Object.create(r||null),!e.buffer)return null;r.maxLength||(r.maxLength=79),typeof r.indent!="number"&&(r.indent=1),typeof r.linesBefore!="number"&&(r.linesBefore=3),typeof r.linesAfter!="number"&&(r.linesAfter=2);for(var n=/\r?\n|\r|\0/g,t=[0],i=[],s,o=-1;s=n.exec(e.buffer);)i.push(s.index),t.push(s.index+s[0].length),e.position<=s.index&&o<0&&(o=t.length-2);o<0&&(o=t.length-1);var a="",l,c,f=Math.min(e.line+r.linesAfter,i.length).toString().length,u=r.maxLength-(r.indent+f+3);for(l=1;l<=r.linesBefore&&!(o-l<0);l++)c=gr(e.buffer,t[o-l],i[o-l],e.position-(t[o]-t[o-l]),u),a=w.repeat(" ",r.indent)+yr((e.line-l+1).toString(),f)+" | "+c.str+`
|
|
5
5
|
`+a;for(c=gr(e.buffer,t[o],i[o],e.position,u),a+=w.repeat(" ",r.indent)+yr((e.line+1).toString(),f)+" | "+c.str+`
|
|
@@ -40,7 +40,7 @@ Options:
|
|
|
40
40
|
-p, --port <number> Port to listen on (default: 3001)
|
|
41
41
|
-h, --help Show this help message
|
|
42
42
|
-v, --version Show version number
|
|
43
|
-
`.trim()),process.exit(0));Ee.version&&(console.log("0.1.
|
|
43
|
+
`.trim()),process.exit(0));Ee.version&&(console.log("0.1.14"),process.exit(0));var ja=_a(new URL(".",import.meta.url)),It=Nr(ja,"web"),Na={".html":"text/html; charset=utf-8",".js":"application/javascript",".css":"text/css",".ttf":"font/ttf",".woff":"font/woff",".woff2":"font/woff2",".svg":"image/svg+xml",".png":"image/png",".json":"application/json"};function La(e){let r=Ia(e);return Na[r]??"application/octet-stream"}Ee.config&&kn(Ee.config);M();var S=new O;S.use("/*",wn());S.use("/*",vn({origin:"*"}));S.get("/health",e=>e.json({status:"ok"}));S.get("/api/config/task-docs",e=>{let r=M();return e.json({customTaskDocs:r.customTaskDocs??{}})});S.route("/api",Ce);S.route("/api",ae);S.route("/api",jr);S.all("/api/*",e=>e.json({error:`Not found: ${e.req.path}`},404));S.onError((e,r)=>{if(console.error("Server error:",e.message),e.message.includes("DefaultAzureCredential")||e.message.includes("authentication"))return r.json({error:"Authentication failed. Ensure you are logged in via `az login`.",details:e.message},401);let n=e.message.match(/API error \((\d+)\)/);if(n){let t=Number(n[1]);return r.json({error:e.message},t)}return r.json({error:e.message},500)});S.get("/assets/*",e=>{let r=e.req.path,n=Nr(It,r);if(!Pt(n))return e.notFound();let t=Ot(n);return e.body(t,200,{"Content-Type":La(r),"Cache-Control":"public, immutable, max-age=31536000"})});S.get("*",e=>{let r=Nr(It,"index.html");if(!Pt(r))return e.notFound();let n=Ot(r,"utf-8");return e.html(n)});var Da=Number(Ee.port)||Number(process.env.PORT)||3001;Yr({fetch:S.fetch,port:Da},e=>{console.log(`APV server listening on http://localhost:${e.port}`)});export{S as app};
|
|
44
44
|
/*! Bundled license information:
|
|
45
45
|
|
|
46
46
|
js-yaml/dist/js-yaml.mjs:
|