@meirblachman/azure-pipelines-visualizer 0.1.2 → 0.1.3
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 +24 -24
- package/package.json +1 -1
package/dist/index.min.js
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{existsSync as xt,readFileSync as vt}from"node:fs";import{extname as ma,join as kr}from"node:path";import{fileURLToPath as ga}from"node:url";import{createServer as Rt}from"http";import{Http2ServerRequest as Ir,constants as wt}from"http2";import{Http2ServerRequest as We}from"http2";import{Readable as Pr}from"stream";import Ft from"crypto";var N=class extends Error{constructor(e,r){super(e,r),this.name="RequestError"}},Ct=e=>e instanceof N?e:new N(e.message,{cause:e}),Et=global.Request,se=class extends Et{constructor(e,r){typeof e=="object"&&W in e&&(e=e[W]()),typeof r?.body?.getReader<"u"&&(r.duplex??="half"),super(e,r)}},kt=e=>{let r=[],n=e.rawHeaders;for(let t=0;t<n.length;t+=2){let{[t]:i,[t+1]:o}=n;i.charCodeAt(0)!==58&&r.push([i,o])}return new Headers(r)},_r=Symbol("wrapBodyStream"),St=(e,r,n,t,i)=>{let o={method:e,headers:n,signal:i.signal};if(e==="TRACE"){o.method="GET";let s=new se(r,o);return Object.defineProperty(s,"method",{get(){return"TRACE"}}),s}if(!(e==="GET"||e==="HEAD"))if("rawBody"in t&&t.rawBody instanceof Buffer)o.body=new ReadableStream({start(s){s.enqueue(t.rawBody),s.close()}});else if(t[_r]){let s;o.body=new ReadableStream({async pull(a){try{s||=Pr.toWeb(t).getReader();let{done:l,value:c}=await s.read();l?a.close():a.enqueue(c)}catch(l){a.error(l)}}})}else o.body=Pr.toWeb(t);return new se(r,o)},W=Symbol("getRequestCache"),jr=Symbol("requestCache"),Re=Symbol("incomingKey"),we=Symbol("urlKey"),Tt=Symbol("headersKey"),q=Symbol("abortControllerKey"),Pt=Symbol("getAbortController"),ae={get method(){return this[Re].method||"GET"},get url(){return this[we]},get headers(){return this[Tt]||=kt(this[Re])},[Pt](){return this[W](),this[q]},[W](){return this[q]||=new AbortController,this[jr]||=St(this.method,this[we],this.headers,this[Re],this[q])}};["body","bodyUsed","cache","credentials","destination","integrity","mode","redirect","referrer","referrerPolicy","signal","keepalive"].forEach(e=>{Object.defineProperty(ae,e,{get(){return this[W]()[e]}})});["arrayBuffer","blob","clone","formData","json","text"].forEach(e=>{Object.defineProperty(ae,e,{value:function(){return this[W]()[e]()}})});Object.defineProperty(ae,Symbol.for("nodejs.util.inspect.custom"),{value:function(e,r,n){let t={method:this.method,url:this.url,headers:this.headers,nativeRequest:this[jr]};return`Request (lightweight) ${n(t,{...r,depth:e==null?null:e-1})}`}});Object.setPrototypeOf(ae,se.prototype);var Ot=(e,r)=>{let n=Object.create(ae);n[Re]=e;let t=e.url||"";if(t[0]!=="/"&&(t.startsWith("http://")||t.startsWith("https://"))){if(e instanceof We)throw new N("Absolute URL for :path is not allowed in HTTP/2");try{let a=new URL(t);n[we]=a.href}catch(a){throw new N("Invalid absolute URL",{cause:a})}return n}let i=(e instanceof We?e.authority:e.headers.host)||r;if(!i)throw new N("Missing host header");let o;if(e instanceof We){if(o=e.scheme,!(o==="http"||o==="https"))throw new N("Unsupported scheme")}else o=e.socket&&e.socket.encrypted?"https":"http";let s=new URL(`${o}://${i}${t}`);if(s.hostname.length!==i.length&&s.hostname!==i.replace(/:\d+$/,""))throw new N("Invalid host header");return n[we]=s.href,n},Ke=Symbol("responseCache"),U=Symbol("getResponseCache"),L=Symbol("cache"),Je=global.Response,G=class Fr{#r;#e;[U](){return delete this[L],this[Ke]||=new Je(this.#r,this.#e)}constructor(r,n){let t;if(this.#r=r,n instanceof Fr){let i=n[Ke];if(i){this.#e=i,this[U]();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[U]().headers}get status(){return this[L]?.[0]??this[U]().status}get ok(){let r=this.status;return r>=200&&r<300}};["body","bodyUsed","redirected","statusText","trailers","type","url"].forEach(e=>{Object.defineProperty(G.prototype,e,{get(){return this[U]()[e]}})});["arrayBuffer","blob","clone","formData","json","text"].forEach(e=>{Object.defineProperty(G.prototype,e,{value:function(){return this[U]()[e]()}})});Object.defineProperty(G.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[Ke]};return`Response (lightweight) ${n(t,{...r,depth:e==null?null:e-1})}`}});Object.setPrototypeOf(G,Je);Object.setPrototypeOf(G.prototype,Je.prototype);async function It(e){return Promise.race([e,Promise.resolve().then(()=>Promise.resolve(void 0))])}function Nr(e,r,n){let t=a=>{e.cancel(a).catch(()=>{})};return r.on("close",t),r.on("error",t),(n??e.read()).then(s,i),e.closed.finally(()=>{r.off("close",t),r.off("error",t)});function i(a){a&&r.destroy(a)}function o(){e.read().then(s,i)}function s({done:a,value:l}){try{if(a)r.end();else if(!r.write(l))r.once("drain",o);else return e.read().then(s,i)}catch(c){i(c)}}}function _t(e,r){if(e.locked)throw new TypeError("ReadableStream is locked.");return r.destroyed?void 0:Nr(e.getReader(),r)}var Ye=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},jt="x-hono-already-sent";typeof global.crypto>"u"&&(global.crypto=Ft);var Qe=Symbol("outgoingEnded"),Or=Symbol("incomingDraining"),Nt=500,Lt=64*1024*1024,Ge=e=>{let r=e;if(e.destroyed||r[Or])return;if(r[Or]=!0,e instanceof Ir){try{e.stream?.close?.(wt.NGHTTP2_NO_ERROR)}catch{}return}let n=0,t=()=>{clearTimeout(o),e.off("data",s),e.off("end",t),e.off("error",t)},i=()=>{t();let a=e.socket;a&&!a.destroyed&&a.destroySoon()},o=setTimeout(i,Nt);o.unref?.();let s=a=>{n+=a.length,n>Lt&&i()};e.on("data",s),e.on("end",t),e.on("error",t),e.resume()},Dt=()=>new Response(null,{status:400}),Lr=e=>new Response(null,{status:e instanceof Error&&(e.name==="TimeoutError"||e.constructor.name==="TimeoutError")?504:500}),Ve=(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))},Dr=e=>{"flushHeaders"in e&&e.writable&&e.flushHeaders()},Mr=async(e,r)=>{let[n,t,i]=e[L],o=!1;if(!i)i={"content-type":"text/plain; charset=UTF-8"};else if(i instanceof Headers)o=i.has("content-length"),i=Ye(i);else if(Array.isArray(i)){let s=new Headers(i);o=s.has("content-length"),i=Ye(s)}else for(let s in i)if(s.length===14&&s.toLowerCase()==="content-length"){o=!0;break}o||(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())):(Dr(r),await _t(t,r)?.catch(s=>Ve(s,r))),r[Qe]?.()},Mt=e=>typeof e.then=="function",$t=async(e,r,n={})=>{if(Mt(e))if(n.errorHandler)try{e=await e}catch(i){let o=await n.errorHandler(i);if(!o)return;e=o}else e=await e.catch(Lr);if(L in e)return Mr(e,r);let t=Ye(e.headers);if(e.body){let i=e.body.getReader(),o=[],s=!1,a;if(t["transfer-encoding"]!=="chunked"){let l=2;for(let c=0;c<l;c++){a||=i.read();let f=await It(a).catch(u=>{console.error(u),s=!0});if(!f){if(c===1){await new Promise(u=>setTimeout(u)),l=3;continue}break}if(a=void 0,f.value&&o.push(f.value),f.done){s=!0;break}}s&&!("content-length"in t)&&(t["content-length"]=o.reduce((c,f)=>c+f.length,0))}r.writeHead(e.status,t),o.forEach(l=>{r.write(l)}),s?r.end():(o.length===0&&Dr(r),await Nr(i,r,a))}else t[jt]||(r.writeHead(e.status,t),r.end());r[Qe]?.()},Ht=(e,r={})=>{let n=r.autoCleanupIncoming??!0;return r.overrideGlobalObjects!==!1&&global.Request!==se&&(Object.defineProperty(global,"Request",{value:se}),Object.defineProperty(global,"Response",{value:G})),async(t,i)=>{let o,s;try{s=Ot(t,r.hostname);let a=!n||t.method==="GET"||t.method==="HEAD";if(a||(t[_r]=!0,t.on("end",()=>{a=!0}),t instanceof Ir&&(i[Qe]=()=>{a||setTimeout(()=>{a||setTimeout(()=>{Ge(t)})})}),i.on("finish",()=>{a||Ge(t)})),i.on("close",()=>{s[q]&&(t.errored?s[q].abort(t.errored.toString()):i.writableFinished||s[q].abort("Client connection prematurely closed.")),a||setTimeout(()=>{a||setTimeout(()=>{Ge(t)})})}),o=e(s,{incoming:t,outgoing:i}),L in o)return Mr(o,i)}catch(a){if(o)return Ve(a,i);if(r.errorHandler){if(o=await r.errorHandler(s?a:Ct(a)),!o)return}else s?o=Lr(a):o=Dt()}try{return await $t(o,i,r)}catch(a){return Ve(a,i)}}},Bt=e=>{let r=e.fetch,n=Ht(r,{hostname:e.hostname,overrideGlobalObjects:e.overrideGlobalObjects,autoCleanupIncoming:e.autoCleanupIncoming});return(e.createServer||Rt)(e.serverOptions||{},n)},$r=(e,r)=>{let n=Bt(e);return n.listen(e?.port??3e3,e.hostname,()=>{let t=n.address();r&&r(t)}),n};var Xe=(e,r,n)=>(t,i)=>{let o=-1;return s(0);async function s(a){if(a<=o)throw new Error("next() called multiple times");o=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,()=>s(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 Hr=Symbol();var Br=async(e,r=Object.create(null))=>{let{all:n=!1,dot:t=!1}=r,o=(e instanceof Ce?e.raw.headers:e.headers).get("Content-Type");return o?.startsWith("multipart/form-data")||o?.startsWith("application/x-www-form-urlencoded")?zt(e,{all:n,dot:t}):{}};async function zt(e,r){let n=await e.formData();return n?Ut(n,r):{}}function Ut(e,r){let n=Object.create(null);return e.forEach((t,i)=>{r.all||i.endsWith("[]")?qt(n,i,t):n[i]=t}),r.dot&&Object.entries(n).forEach(([t,i])=>{t.includes(".")&&(Wt(n,t,i),delete n[t])}),n}var qt=(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},Wt=(e,r,n)=>{if(/(?:^|\.)__proto__\./.test(r))return;let t=e,i=r.split(".");i.forEach((o,s)=>{s===i.length-1?t[o]=n:((!t[o]||typeof t[o]!="object"||Array.isArray(t[o])||t[o]instanceof File)&&(t[o]=Object.create(null)),t=t[o])})};var er=e=>{let r=e.split("/");return r[0]===""&&r.shift(),r},zr=e=>{let{groups:r,path:n}=Gt(e),t=er(n);return Kt(t,r)},Gt=e=>{let r=[];return e=e.replace(/\{[^}]+\}/g,(n,t)=>{let i=`@${t}`;return r.push([i,n]),i}),{groups:r,path:e}},Kt=(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},Ee={},Ur=(e,r)=>{if(e==="*")return"*";let n=e.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);if(n){let t=`${e}#${r}`;return Ee[t]||(n[2]?Ee[t]=r&&r[0]!==":"&&r[0]!=="*"?[t,n[1],new RegExp(`^${n[2]}(?=/${r})`)]:[e,n[1],new RegExp(`^${n[2]}$`)]:Ee[t]=[e,n[1],!0]),Ee[t]}return null},ke=(e,r)=>{try{return r(e)}catch{return e.replace(/(?:%[0-9A-Fa-f]{2})+/g,n=>{try{return r(n)}catch{return n}})}},Yt=e=>ke(e,decodeURI),rr=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 o=r.indexOf("?",t),s=r.indexOf("#",t),a=o===-1?s===-1?void 0:s:s===-1?o:Math.min(o,s),l=r.slice(n,a);return Yt(l.includes("%25")?l.replace(/%25/g,"%2525"):l)}else if(i===63||i===35)break}return r.slice(n,t)};var qr=e=>{let r=rr(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}`}`),Se=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 o=i.replace("?","");t+="/"+o,n.push(t)}else t+="/"+i}),n.filter((i,o,s)=>s.indexOf(i)===o)},Ze=e=>/[%+]/.test(e)?(e.indexOf("+")!==-1&&(e=e.replace(/\+/g," ")),e.indexOf("%")!==-1?ke(e,nr):e):e,Wr=(e,r,n)=>{let t;if(!n&&r&&!/[%+]/.test(r)){let s=e.indexOf("?",8);if(s===-1)return;for(e.startsWith(r,s+1)||(s=e.indexOf(`&${r}`,s+1));s!==-1;){let a=e.charCodeAt(s+r.length+1);if(a===61){let l=s+r.length+2,c=e.indexOf("&",l);return Ze(e.slice(l,c===-1?void 0:c))}else if(a==38||isNaN(a))return"";s=e.indexOf(`&${r}`,s+1)}if(t=/[%+]/.test(e),!t)return}let i={};t??=/[%+]/.test(e);let o=e.indexOf("?",8);for(;o!==-1;){let s=e.indexOf("&",o+1),a=e.indexOf("=",o);a>s&&s!==-1&&(a=-1);let l=e.slice(o+1,a===-1?s===-1?void 0:s:a);if(t&&(l=Ze(l)),o=s,l==="")continue;let c;a===-1?c="":(c=e.slice(a+1,s===-1?void 0:s),t&&(c=Ze(c))),n?(i[l]&&Array.isArray(i[l])||(i[l]=[]),i[l].push(c)):i[l]??=c}return r?i[r]:i},Gr=Wr,Kr=(e,r)=>Wr(e,r,!0),nr=decodeURIComponent;var Yr=e=>ke(e,nr),Ce=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)?Yr(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)?Yr(t):t)}return e}#i(e){return this.#e[1]?this.#e[1][e]:e}query(e){return Gr(this.url,e)}queries(e){return Kr(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 Br(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(o=>(i==="json"&&(o=JSON.stringify(o)),new Response(o)[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[Hr](){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 Vr={Stringify:1,BeforeStream:2,Stream:3},Vt=(e,r)=>{let n=new String(e);return n.isEscaped=!0,n.callbacks=r,n};var tr=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 o=e.callbacks;if(!o?.length)return Promise.resolve(e);i?i[0]+=e:i=[e];let s=Promise.all(o.map(a=>a({phase:r,buffer:i,context:t}))).then(a=>Promise.all(a.filter(Boolean).map(l=>tr(l,r,!1,t,i))).then(()=>i[0]));return n?Vt(await s,o):s};var Jt="text/plain; charset=UTF-8",ir=(e,r)=>({"Content-Type":e,...r}),le=(e,r)=>new Response(e,r),Jr=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 Ce(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||=le(null,{headers:this.#a??=new Headers})}set res(e){if(this.#t&&e){e=le(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=le(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 o=r.headers instanceof Headers?r.headers:new Headers(r.headers);for(let[s,a]of o)s.toLowerCase()==="set-cookie"?t.append(s,a):t.set(s,a)}if(n)for(let[o,s]of Object.entries(n))if(typeof s=="string")t.set(o,s);else{t.delete(o);for(let a of s)t.append(o,a)}let i=typeof r=="number"?r:r?.status??this.#o;return le(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,ir(Jt,n));json=(e,r,n)=>this.#s(JSON.stringify(e),r,ir("application/json",n));html=(e,r,n)=>{let t=i=>this.#s(i,r,ir("text/html; charset=UTF-8",n));return typeof e=="object"?tr(e,Vr.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??=()=>le(),this.#c(this))};var A="ALL",Qr="all",Xr=["get","post","put","delete","options","patch"],Te="Can not add a route since the matcher is already built.",Pe=class extends Error{};var Zr="__COMPOSED_HANDLER";var Qt=e=>e.text("404 Not Found",404),en=(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)},rn=class nn{get;post;put;delete;options;patch;all;on;use;router;getPath;_basePath="/";#r="/";routes=[];constructor(r={}){[...Xr,Qr].forEach(o=>{this[o]=(s,...a)=>(typeof s=="string"?this.#r=s:this.#o(o,this.#r,s),a.forEach(l=>{this.#o(o,this.#r,l)}),this)}),this.on=(o,s,...a)=>{for(let l of[s].flat()){this.#r=l;for(let c of[o].flat())a.map(f=>{this.#o(c.toUpperCase(),this.#r,f)})}return this},this.use=(o,...s)=>(typeof o=="string"?this.#r=o:(this.#r="*",s.unshift(o)),s.forEach(a=>{this.#o(A,this.#r,a)}),this);let{strict:t,...i}=r;Object.assign(this,i),this.getPath=t??!0?r.getPath??rr:qr}#e(){let r=new nn({router:this.router,getPath:this.getPath});return r.errorHandler=this.errorHandler,r.#n=this.#n,r.routes=this.routes,r}#n=Qt;errorHandler=en;route(r,n){let t=this.basePath(r);return n.routes.map(i=>{let o;n.errorHandler===en?o=i.handler:(o=async(s,a)=>(await Xe([],n.errorHandler)(s,()=>i.handler(s,a))).res,o[Zr]=i.handler),t.#o(i.method,i.path,o)}),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,o;t&&(typeof t=="function"?o=t:(o=t.optionHandler,t.replaceRequest===!1?i=l=>l:i=t.replaceRequest));let s=o?l=>{let c=o(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),...s(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 o=this.getPath(r,{env:t}),s=this.router.match(i,o),a=new Jr(r,{path:o,matchResult:s,env:t,executionCtx:n,notFoundHandler:this.#n});if(s[0].length===1){let c;try{c=s[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=Xe(s[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 Oe=[];function or(e,r){let n=this.buildAllMatchers(),t=((i,o)=>{let s=n[i]||n[A],a=s[2][o];if(a)return a;let l=o.match(s[0]);if(!l)return[[],Oe];let c=l.indexOf("",1);return[s[1][c],l]});return this.match=t,t(e,r)}var Ie="[^/]+",ce=".*",ue="(?:|/.*)",M=Symbol(),Xt=new Set(".\\+*[^]$()");function Zt(e,r){return e.length===1?r.length===1?e<r?-1:1:-1:r.length===1||e===ce||e===ue?1:r===ce||r===ue?-1:e===Ie?1:r===Ie?-1:e.length===r.length?e<r?-1:1:r.length-e.length}var tn=class sr{#r;#e;#n=Object.create(null);insert(r,n,t,i,o){if(r.length===0){if(this.#r!==void 0)throw M;if(o)return;this.#r=n;return}let[s,...a]=r,l=s==="*"?a.length===0?["","",ce]:["","",Ie]:s==="/*"?["","",ue]:s.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/),c;if(l){let f=l[1],u=l[2]||Ie;if(f&&l[2]&&(u===".*"||(u=u.replace(/^\((?!\?:)(?=[^)]+\)$)/,"(?:"),/\((?!\?:)/.test(u))))throw M;if(c=this.#n[u],!c){if(Object.keys(this.#n).some(p=>p!==ce&&p!==ue))throw M;if(o)return;c=this.#n[u]=new sr,f!==""&&(c.#e=i.varIndex++)}!o&&f!==""&&t.push([f,c.#e])}else if(c=this.#n[s],!c){if(Object.keys(this.#n).some(f=>f.length>1&&f!==ce&&f!==ue))throw M;if(o)return;c=this.#n[s]=new sr}c.insert(a,n,t,i,o)}buildRegExpStr(){let n=Object.keys(this.#n).sort(Zt).map(t=>{let i=this.#n[t];return(typeof i.#e=="number"?`(${t})@${i.#e}`:Xt.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 on=class{#r={varIndex:0};#e=new tn;insert(e,r,n){let t=[],i=[];for(let s=0;;){let a=!1;if(e=e.replace(/\{[^}]+\}/g,l=>{let c=`@\\${s}`;return i[s]=[c,l],s++,a=!0,c}),!a)break}let o=e.match(/(?::[^\/]+)|(?:\/\*$)|./g)||[];for(let s=i.length-1;s>=0;s--){let[a]=i[s];for(let l=o.length-1;l>=0;l--)if(o[l].indexOf(a)!==-1){o[l]=o[l].replace(a,i[s][1]);break}}return this.#e.insert(o,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,o,s)=>o!==void 0?(n[++r]=Number(o),"$()"):(s!==void 0&&(t[Number(s)]=++r),"")),[new RegExp(`^${e}`),n,t]}};var ei=[/^$/,[],Object.create(null)],sn=Object.create(null);function an(e){return sn[e]??=new RegExp(e==="*"?"":`^${e.replace(/\/\*$|([.\\+*[^\]$()])/g,(r,n)=>n?`\\${n}`:"(?:|/.*)")}$`)}function ri(){sn=Object.create(null)}function ni(e){let r=new on,n=[];if(e.length===0)return ei;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)]),Oe]:f++;let y;try{y=r.insert(d,f,p)}catch(x){throw x===M?new Pe(d):x}p||(n[f]=m.map(([x,v])=>{let g=Object.create(null);for(v-=1;v>=0;v--){let[te,Ue]=y[v];g[te]=Ue}return[x,g]}))}let[o,s,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 s)l[c]=n[s[c]];return[o,l,i]}function K(e,r){if(e){for(let n of Object.keys(e).sort((t,i)=>i.length-t.length))if(an(n).test(r))return[...e[n]]}}var _e=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(Te);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 o=(r.match(/\/:/g)||[]).length;if(/\*$/.test(r)){let a=an(r);e===A?Object.keys(t).forEach(l=>{t[l][r]||=K(t[l],r)||K(t[A],r)||[]}):t[e][r]||=K(t[e],r)||K(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,o])})}),Object.keys(i).forEach(l=>{(e===A||e===l)&&Object.keys(i[l]).forEach(c=>a.test(c)&&i[l][c].push([n,o]))});return}let s=Se(r)||[r];for(let a=0,l=s.length;a<l;a++){let c=s[a];Object.keys(i).forEach(f=>{(e===A||e===f)&&(i[f][c]||=[...K(t[f],c)||K(t[A],c)||[]],i[f][c].push([n,o-l+a+1]))})}}match=or;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,ri(),e}#n(e){let r=[],n=e===A;return[this.#r,this.#e].forEach(t=>{let i=t[e]?Object.keys(t[e]).map(o=>[o,t[e][o]]):[];i.length!==0?(n||=!0,r.push(...i)):e!==A&&r.push(...Object.keys(t[A]).map(o=>[o,t[A][o]]))}),n?ni(r):null}};var ar=class{name="SmartRouter";#r=[];#e=[];constructor(e){this.#r=e.routers}add(e,r,n){if(!this.#e)throw new Error(Te);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,o=0,s;for(;o<i;o++){let a=n[o];try{for(let l=0,c=t.length;l<c;l++)a.add(...t[l]);s=a.match(e,r)}catch(l){if(l instanceof Pe)continue;throw l}this.match=a.match.bind(a),this.#r=[a],this.#e=void 0;break}if(o===i)throw new Error("Fatal error");return this.name=`SmartRouter + ${this.activeRouter.name}`,s}get activeRouter(){if(this.#e||this.#r.length!==1)throw new Error("No active router has been determined yet.");return this.#r[0]}};var fe=Object.create(null),ti=e=>{for(let r in e)return!0;return!1},ln=class cn{#r;#e;#n;#o=0;#i=fe;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,o=zr(n),s=[];for(let a=0,l=o.length;a<l;a++){let c=o[a],f=o[a+1],u=Ur(c,f),p=Array.isArray(u)?u[0]:c;if(p in i.#e){i=i.#e[p],u&&s.push(u[1]);continue}i.#e[p]=new cn,u&&(i.#n.push(u),s.push(u[1])),i=i.#e[p]}return i.#r.push({[r]:{handler:t,possibleKeys:s.filter((a,l,c)=>c.indexOf(a)===l),score:this.#o}}),i}#t(r,n,t,i,o){for(let s=0,a=n.#r.length;s<a;s++){let l=n.#r[s],c=l[t]||l[A],f={};if(c!==void 0&&(c.params=Object.create(null),r.push(c),i!==fe||o&&o!==fe))for(let u=0,p=c.possibleKeys.length;u<p;u++){let d=c.possibleKeys[u],m=f[c.score];c.params[d]=o?.[d]&&!m?o[d]:i[d]??o?.[d],f[c.score]=!0}}}search(r,n){let t=[];this.#i=fe;let o=[this],s=er(n),a=[],l=s.length,c=null;for(let f=0;f<l;f++){let u=s[f],p=f===l-1,d=[];for(let y=0,x=o.length;y<x;y++){let v=o[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 te=0,Ue=v.#n.length;te<Ue;te++){let Sr=v.#n[te],_=v.#i===fe?{}:{...v.#i};if(Sr==="*"){let z=v.#e["*"];z&&(this.#t(t,z,r,v.#i),z.#i=_,d.push(z));continue}let[bt,Tr,ie]=Sr;if(!u&&!(ie instanceof RegExp))continue;let P=v.#e[bt];if(ie instanceof RegExp){if(c===null){c=new Array(l);let be=n[0]==="/"?1:0;for(let oe=0;oe<l;oe++)c[oe]=be,be+=s[oe].length+1}let z=n.substring(c[f]),qe=ie.exec(z);if(qe){if(_[Tr]=qe[0],this.#t(t,P,r,v.#i,_),ti(P.#e)){P.#i=_;let be=qe[0].match(/\//)?.length??0;(a[be]||=[]).push(P)}continue}}(ie===!0||ie.test(u))&&(_[Tr]=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();o=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 lr=class{name="TrieRouter";#r;constructor(){this.#r=new ln}add(e,r,n){let t=Se(r);if(t){for(let i=0,o=t.length;i<o;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 rn{constructor(e={}){super(e),this.router=e.router??new ar({routers:[new _e,new lr]})}};var un=e=>{let n={...{origin:"*",allowMethods:["GET","HEAD","PUT","POST","DELETE","PATCH"],allowHeaders:[],exposeHeaders:[]},...e},t=(o=>typeof o=="string"?o==="*"?n.credentials?s=>s||null:()=>o:s=>o===s?s:null:typeof o=="function"?o:s=>o.includes(s)?s:null)(n.origin),i=(o=>typeof o=="function"?o:Array.isArray(o)?()=>o:()=>[])(n.allowMethods);return async function(s,a){function l(f,u){s.res.headers.set(f,u)}let c=await t(s.req.header("origin")||"",s);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(",")),s.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(s.req.header("origin")||"",s);f.length&&l("Access-Control-Allow-Methods",f.join(","));let u=n.allowHeaders;if(!u?.length){let p=s.req.header("Access-Control-Request-Headers");p&&(u=p.split(/\s*,\s*/))}return u?.length&&(l("Access-Control-Allow-Headers",u.join(",")),s.res.headers.append("Vary","Access-Control-Request-Headers")),s.res.headers.delete("Content-Length"),s.res.headers.delete("Content-Type"),new Response(null,{headers:s.res.headers,status:204,statusText:"No Content"})}await a(),(n.origin!=="*"||n.credentials)&&s.header("Vary","Origin",{append:!0})}};function ii(){let{process:e,Deno:r}=globalThis;return!(typeof r?.noColor=="boolean"?r.noColor:e!==void 0?"NO_COLOR"in e?.env:!1)}async function fn(){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}})():!ii())}var oi=e=>{let[r,n]=[",","."];return e.map(i=>i.replace(/(\d)(?=(\d\d\d)+(?!\d))/g,"$1"+r)).join(n)},si=e=>{let r=Date.now()-e;return oi([r<1e3?r+"ms":Math.round(r/1e3)+"s"])},ai=async e=>{if(await fn())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 pn(e,r,n,t,i=0,o){let s=r==="<--"?`${r} ${n} ${t}`:`${r} ${n} ${t} ${await ai(i)} ${o}`;e(s)}var dn=(e=console.log)=>async function(n,t){let{method:i,url:o}=n.req,s=o.slice(o.indexOf("/",8));await pn(e,"<--",i,s);let a=Date.now();await t(),await pn(e,"-->",i,s,n.res.status,si(a))};import{existsSync as li,readFileSync as ci}from"node:fs";import{dirname as ui,resolve as hn}from"node:path";import{fileURLToPath as fi}from"node:url";var mn="apv.config.json",$=null;function Y(){if($)return $;let r=[process.env.APV_CONFIG,hn(process.cwd(),mn),hn(ui(fi(import.meta.url)),"..","..","..",mn)].filter(Boolean);for(let n of r)if(li(n))try{let t=ci(n,"utf-8"),i=JSON.parse(t);return $={cacheDir:i.cacheDir,localRepos:i.localRepos??{},customTaskDocs:i.customTaskDocs??{}},console.log(`Loaded config from ${n}`),pi($),$}catch(t){console.warn(`Failed to parse ${n}:`,t)}return $={localRepos:{},customTaskDocs:{}},$}function gn(e,r,n){let t=Y(),i=`${e}/${r}/${n}`;if(t.localRepos[i])return t.localRepos[i];let o=i.toLowerCase();for(let[s,a]of Object.entries(t.localRepos))if(s.toLowerCase()===o)return a}function pi(e){let r=Object.entries(e.localRepos);if(r.length===0){console.log(" No local repo mappings configured");return}console.log(` ${r.length} local repo mapping(s):`);for(let[n,t]of r)console.log(` ${n} \u2192 ${t}`)}function je(e){let r=e.startsWith("/"),n=e.split("/").filter(o=>o!==""&&o!=="."),t=[];for(let o of n)o===".."?t.length>0&&t[t.length-1]!==".."?t.pop():r||t.push(o):t.push(o);let i=t.join("/");return r?`/${i}`:i}function _n(e){return typeof e>"u"||e===null}function hi(e){return typeof e=="object"&&e!==null}function mi(e){return Array.isArray(e)?e:_n(e)?[]:[e]}function gi(e,r){var n,t,i,o;if(r)for(o=Object.keys(r),n=0,t=o.length;n<t;n+=1)i=o[n],e[i]=r[i];return e}function yi(e,r){var n="",t;for(t=0;t<r;t+=1)n+=e;return n}function xi(e){return e===0&&Number.NEGATIVE_INFINITY===1/e}var vi=_n,Ai=hi,bi=mi,Ri=yi,wi=xi,Ci=gi,R={isNothing:vi,isObject:Ai,toArray:bi,repeat:Ri,isNegativeZero:wi,extend:Ci};function jn(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 Tt,readFileSync as Pt}from"node:fs";import{extname as Na,join as Fr}from"node:path";import{fileURLToPath as La}from"node:url";import{createServer as _t}from"http";import{Http2ServerRequest as $r,constants as Ft}from"http2";import{Http2ServerRequest as Ze}from"http2";import{Readable as Lr}from"stream";import qt from"crypto";var L=class extends Error{constructor(e,r){super(e,r),this.name="RequestError"}},jt=e=>e instanceof L?e:new L(e.message,{cause:e}),Nt=global.Request,fe=class extends Nt{constructor(e,r){typeof e=="object"&&K in e&&(e=e[K]()),typeof r?.body?.getReader<"u"&&(r.duplex??="half"),super(e,r)}},Lt=e=>{let r=[],n=e.rawHeaders;for(let t=0;t<n.length;t+=2){let{[t]:i,[t+1]:o}=n;i.charCodeAt(0)!==58&&r.push([i,o])}return new Headers(r)},Mr=Symbol("wrapBodyStream"),Dt=(e,r,n,t,i)=>{let o={method:e,headers:n,signal:i.signal};if(e==="TRACE"){o.method="GET";let s=new fe(r,o);return Object.defineProperty(s,"method",{get(){return"TRACE"}}),s}if(!(e==="GET"||e==="HEAD"))if("rawBody"in t&&t.rawBody instanceof Buffer)o.body=new ReadableStream({start(s){s.enqueue(t.rawBody),s.close()}});else if(t[Mr]){let s;o.body=new ReadableStream({async pull(a){try{s||=Lr.toWeb(t).getReader();let{done:l,value:c}=await s.read();l?a.close():a.enqueue(c)}catch(l){a.error(l)}}})}else o.body=Lr.toWeb(t);return new fe(r,o)},K=Symbol("getRequestCache"),Hr=Symbol("requestCache"),ke=Symbol("incomingKey"),Se=Symbol("urlKey"),$t=Symbol("headersKey"),G=Symbol("abortControllerKey"),Mt=Symbol("getAbortController"),pe={get method(){return this[ke].method||"GET"},get url(){return this[Se]},get headers(){return this[$t]||=Lt(this[ke])},[Mt](){return this[K](),this[G]},[K](){return this[G]||=new AbortController,this[Hr]||=Dt(this.method,this[Se],this.headers,this[ke],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[Hr]};return`Request (lightweight) ${n(t,{...r,depth:e==null?null:e-1})}`}});Object.setPrototypeOf(pe,fe.prototype);var Ht=(e,r)=>{let n=Object.create(pe);n[ke]=e;let t=e.url||"";if(t[0]!=="/"&&(t.startsWith("http://")||t.startsWith("https://"))){if(e instanceof Ze)throw new L("Absolute URL for :path is not allowed in HTTP/2");try{let a=new URL(t);n[Se]=a.href}catch(a){throw new L("Invalid absolute URL",{cause:a})}return n}let i=(e instanceof Ze?e.authority:e.headers.host)||r;if(!i)throw new L("Missing host header");let o;if(e instanceof Ze){if(o=e.scheme,!(o==="http"||o==="https"))throw new L("Unsupported scheme")}else o=e.socket&&e.socket.encrypted?"https":"http";let s=new URL(`${o}://${i}${t}`);if(s.hostname.length!==i.length&&s.hostname!==i.replace(/:\d+$/,""))throw new L("Invalid host header");return n[Se]=s.href,n},Qe=Symbol("responseCache"),W=Symbol("getResponseCache"),D=Symbol("cache"),rr=global.Response,Y=class zr{#r;#e;[W](){return delete this[D],this[Qe]||=new rr(this.#r,this.#e)}constructor(r,n){let t;if(this.#r=r,n instanceof zr){let i=n[Qe];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[D]=[n?.status||200,r,t||n?.headers])}get headers(){let r=this[D];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[D]?.[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[Qe]};return`Response (lightweight) ${n(t,{...r,depth:e==null?null:e-1})}`}});Object.setPrototypeOf(Y,rr);Object.setPrototypeOf(Y.prototype,rr.prototype);async function zt(e){return Promise.race([e,Promise.resolve().then(()=>Promise.resolve(void 0))])}function Br(e,r,n){let t=a=>{e.cancel(a).catch(()=>{})};return r.on("close",t),r.on("error",t),(n??e.read()).then(s,i),e.closed.finally(()=>{r.off("close",t),r.off("error",t)});function i(a){a&&r.destroy(a)}function o(){e.read().then(s,i)}function s({done:a,value:l}){try{if(a)r.end();else if(!r.write(l))r.once("drain",o);else return e.read().then(s,i)}catch(c){i(c)}}}function Bt(e,r){if(e.locked)throw new TypeError("ReadableStream is locked.");return r.destroyed?void 0:Br(e.getReader(),r)}var Xe=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},Ut="x-hono-already-sent";typeof global.crypto>"u"&&(global.crypto=qt);var nr=Symbol("outgoingEnded"),Dr=Symbol("incomingDraining"),Wt=500,Gt=64*1024*1024,Je=e=>{let r=e;if(e.destroyed||r[Dr])return;if(r[Dr]=!0,e instanceof $r){try{e.stream?.close?.(Ft.NGHTTP2_NO_ERROR)}catch{}return}let n=0,t=()=>{clearTimeout(o),e.off("data",s),e.off("end",t),e.off("error",t)},i=()=>{t();let a=e.socket;a&&!a.destroyed&&a.destroySoon()},o=setTimeout(i,Wt);o.unref?.();let s=a=>{n+=a.length,n>Gt&&i()};e.on("data",s),e.on("end",t),e.on("error",t),e.resume()},Kt=()=>new Response(null,{status:400}),Ur=e=>new Response(null,{status:e instanceof Error&&(e.name==="TimeoutError"||e.constructor.name==="TimeoutError")?504:500}),er=(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))},qr=e=>{"flushHeaders"in e&&e.writable&&e.flushHeaders()},Wr=async(e,r)=>{let[n,t,i]=e[D],o=!1;if(!i)i={"content-type":"text/plain; charset=UTF-8"};else if(i instanceof Headers)o=i.has("content-length"),i=Xe(i);else if(Array.isArray(i)){let s=new Headers(i);o=s.has("content-length"),i=Xe(s)}else for(let s in i)if(s.length===14&&s.toLowerCase()==="content-length"){o=!0;break}o||(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())):(qr(r),await Bt(t,r)?.catch(s=>er(s,r))),r[nr]?.()},Yt=e=>typeof e.then=="function",Vt=async(e,r,n={})=>{if(Yt(e))if(n.errorHandler)try{e=await e}catch(i){let o=await n.errorHandler(i);if(!o)return;e=o}else e=await e.catch(Ur);if(D in e)return Wr(e,r);let t=Xe(e.headers);if(e.body){let i=e.body.getReader(),o=[],s=!1,a;if(t["transfer-encoding"]!=="chunked"){let l=2;for(let c=0;c<l;c++){a||=i.read();let f=await zt(a).catch(u=>{console.error(u),s=!0});if(!f){if(c===1){await new Promise(u=>setTimeout(u)),l=3;continue}break}if(a=void 0,f.value&&o.push(f.value),f.done){s=!0;break}}s&&!("content-length"in t)&&(t["content-length"]=o.reduce((c,f)=>c+f.length,0))}r.writeHead(e.status,t),o.forEach(l=>{r.write(l)}),s?r.end():(o.length===0&&qr(r),await Br(i,r,a))}else t[Ut]||(r.writeHead(e.status,t),r.end());r[nr]?.()},Zt=(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 o,s;try{s=Ht(t,r.hostname);let a=!n||t.method==="GET"||t.method==="HEAD";if(a||(t[Mr]=!0,t.on("end",()=>{a=!0}),t instanceof $r&&(i[nr]=()=>{a||setTimeout(()=>{a||setTimeout(()=>{Je(t)})})}),i.on("finish",()=>{a||Je(t)})),i.on("close",()=>{s[G]&&(t.errored?s[G].abort(t.errored.toString()):i.writableFinished||s[G].abort("Client connection prematurely closed.")),a||setTimeout(()=>{a||setTimeout(()=>{Je(t)})})}),o=e(s,{incoming:t,outgoing:i}),D in o)return Wr(o,i)}catch(a){if(o)return er(a,i);if(r.errorHandler){if(o=await r.errorHandler(s?a:jt(a)),!o)return}else s?o=Ur(a):o=Kt()}try{return await Vt(o,i,r)}catch(a){return er(a,i)}}},Jt=e=>{let r=e.fetch,n=Zt(r,{hostname:e.hostname,overrideGlobalObjects:e.overrideGlobalObjects,autoCleanupIncoming:e.autoCleanupIncoming});return(e.createServer||_t)(e.serverOptions||{},n)},Gr=(e,r)=>{let n=Jt(e);return n.listen(e?.port??3e3,e.hostname,()=>{let t=n.address();r&&r(t)}),n};var tr=(e,r,n)=>(t,i)=>{let o=-1;return s(0);async function s(a){if(a<=o)throw new Error("next() called multiple times");o=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,()=>s(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 Kr=Symbol();var Yr=async(e,r=Object.create(null))=>{let{all:n=!1,dot:t=!1}=r,o=(e instanceof Te?e.raw.headers:e.headers).get("Content-Type");return o?.startsWith("multipart/form-data")||o?.startsWith("application/x-www-form-urlencoded")?Qt(e,{all:n,dot:t}):{}};async function Qt(e,r){let n=await e.formData();return n?Xt(n,r):{}}function Xt(e,r){let n=Object.create(null);return e.forEach((t,i)=>{r.all||i.endsWith("[]")?ei(n,i,t):n[i]=t}),r.dot&&Object.entries(n).forEach(([t,i])=>{t.includes(".")&&(ri(n,t,i),delete n[t])}),n}var ei=(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},ri=(e,r,n)=>{if(/(?:^|\.)__proto__\./.test(r))return;let t=e,i=r.split(".");i.forEach((o,s)=>{s===i.length-1?t[o]=n:((!t[o]||typeof t[o]!="object"||Array.isArray(t[o])||t[o]instanceof File)&&(t[o]=Object.create(null)),t=t[o])})};var or=e=>{let r=e.split("/");return r[0]===""&&r.shift(),r},Vr=e=>{let{groups:r,path:n}=ni(e),t=or(n);return ti(t,r)},ni=e=>{let r=[];return e=e.replace(/\{[^}]+\}/g,(n,t)=>{let i=`@${t}`;return r.push([i,n]),i}),{groups:r,path:e}},ti=(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},Pe={},Zr=(e,r)=>{if(e==="*")return"*";let n=e.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);if(n){let t=`${e}#${r}`;return Pe[t]||(n[2]?Pe[t]=r&&r[0]!==":"&&r[0]!=="*"?[t,n[1],new RegExp(`^${n[2]}(?=/${r})`)]:[e,n[1],new RegExp(`^${n[2]}$`)]:Pe[t]=[e,n[1],!0]),Pe[t]}return null},Oe=(e,r)=>{try{return r(e)}catch{return e.replace(/(?:%[0-9A-Fa-f]{2})+/g,n=>{try{return r(n)}catch{return n}})}},ii=e=>Oe(e,decodeURI),sr=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 o=r.indexOf("?",t),s=r.indexOf("#",t),a=o===-1?s===-1?void 0:s:s===-1?o:Math.min(o,s),l=r.slice(n,a);return ii(l.includes("%25")?l.replace(/%25/g,"%2525"):l)}else if(i===63||i===35)break}return r.slice(n,t)};var Jr=e=>{let r=sr(e);return r.length>1&&r.at(-1)==="/"?r.slice(0,-1):r},$=(e,r,...n)=>(n.length&&(r=$(r,...n)),`${e?.[0]==="/"?"":"/"}${e}${r==="/"?"":`${e?.at(-1)==="/"?"":"/"}${r?.[0]==="/"?r.slice(1):r}`}`),Ie=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 o=i.replace("?","");t+="/"+o,n.push(t)}else t+="/"+i}),n.filter((i,o,s)=>s.indexOf(i)===o)},ir=e=>/[%+]/.test(e)?(e.indexOf("+")!==-1&&(e=e.replace(/\+/g," ")),e.indexOf("%")!==-1?Oe(e,ar):e):e,Qr=(e,r,n)=>{let t;if(!n&&r&&!/[%+]/.test(r)){let s=e.indexOf("?",8);if(s===-1)return;for(e.startsWith(r,s+1)||(s=e.indexOf(`&${r}`,s+1));s!==-1;){let a=e.charCodeAt(s+r.length+1);if(a===61){let l=s+r.length+2,c=e.indexOf("&",l);return ir(e.slice(l,c===-1?void 0:c))}else if(a==38||isNaN(a))return"";s=e.indexOf(`&${r}`,s+1)}if(t=/[%+]/.test(e),!t)return}let i={};t??=/[%+]/.test(e);let o=e.indexOf("?",8);for(;o!==-1;){let s=e.indexOf("&",o+1),a=e.indexOf("=",o);a>s&&s!==-1&&(a=-1);let l=e.slice(o+1,a===-1?s===-1?void 0:s:a);if(t&&(l=ir(l)),o=s,l==="")continue;let c;a===-1?c="":(c=e.slice(a+1,s===-1?void 0:s),t&&(c=ir(c))),n?(i[l]&&Array.isArray(i[l])||(i[l]=[]),i[l].push(c)):i[l]??=c}return r?i[r]:i},Xr=Qr,en=(e,r)=>Qr(e,r,!0),ar=decodeURIComponent;var rn=e=>Oe(e,ar),Te=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)?rn(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)?rn(t):t)}return e}#i(e){return this.#e[1]?this.#e[1][e]:e}query(e){return Xr(this.url,e)}queries(e){return en(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 Yr(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(o=>(i==="json"&&(o=JSON.stringify(o)),new Response(o)[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[Kr](){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 nn={Stringify:1,BeforeStream:2,Stream:3},oi=(e,r)=>{let n=new String(e);return n.isEscaped=!0,n.callbacks=r,n};var lr=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 o=e.callbacks;if(!o?.length)return Promise.resolve(e);i?i[0]+=e:i=[e];let s=Promise.all(o.map(a=>a({phase:r,buffer:i,context:t}))).then(a=>Promise.all(a.filter(Boolean).map(l=>lr(l,r,!1,t,i))).then(()=>i[0]));return n?oi(await s,o):s};var si="text/plain; charset=UTF-8",cr=(e,r)=>({"Content-Type":e,...r}),de=(e,r)=>new Response(e,r),tn=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 Te(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 o=r.headers instanceof Headers?r.headers:new Headers(r.headers);for(let[s,a]of o)s.toLowerCase()==="set-cookie"?t.append(s,a):t.set(s,a)}if(n)for(let[o,s]of Object.entries(n))if(typeof s=="string")t.set(o,s);else{t.delete(o);for(let a of s)t.append(o,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,cr(si,n));json=(e,r,n)=>this.#s(JSON.stringify(e),r,cr("application/json",n));html=(e,r,n)=>{let t=i=>this.#s(i,r,cr("text/html; charset=UTF-8",n));return typeof e=="object"?lr(e,nn.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",on="all",sn=["get","post","put","delete","options","patch"],_e="Can not add a route since the matcher is already built.",Fe=class extends Error{};var an="__COMPOSED_HANDLER";var ai=e=>e.text("404 Not Found",404),ln=(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)},cn=class un{get;post;put;delete;options;patch;all;on;use;router;getPath;_basePath="/";#r="/";routes=[];constructor(r={}){[...sn,on].forEach(o=>{this[o]=(s,...a)=>(typeof s=="string"?this.#r=s:this.#o(o,this.#r,s),a.forEach(l=>{this.#o(o,this.#r,l)}),this)}),this.on=(o,s,...a)=>{for(let l of[s].flat()){this.#r=l;for(let c of[o].flat())a.map(f=>{this.#o(c.toUpperCase(),this.#r,f)})}return this},this.use=(o,...s)=>(typeof o=="string"?this.#r=o:(this.#r="*",s.unshift(o)),s.forEach(a=>{this.#o(A,this.#r,a)}),this);let{strict:t,...i}=r;Object.assign(this,i),this.getPath=t??!0?r.getPath??sr:Jr}#e(){let r=new un({router:this.router,getPath:this.getPath});return r.errorHandler=this.errorHandler,r.#n=this.#n,r.routes=this.routes,r}#n=ai;errorHandler=ln;route(r,n){let t=this.basePath(r);return n.routes.map(i=>{let o;n.errorHandler===ln?o=i.handler:(o=async(s,a)=>(await tr([],n.errorHandler)(s,()=>i.handler(s,a))).res,o[an]=i.handler),t.#o(i.method,i.path,o)}),this}basePath(r){let n=this.#e();return n._basePath=$(this._basePath,r),n}onError=r=>(this.errorHandler=r,this);notFound=r=>(this.#n=r,this);mount(r,n,t){let i,o;t&&(typeof t=="function"?o=t:(o=t.optionHandler,t.replaceRequest===!1?i=l=>l:i=t.replaceRequest));let s=o?l=>{let c=o(l);return Array.isArray(c)?c:[c]}:l=>{let c;try{c=l.executionCtx}catch{}return[l.env,c]};i||=(()=>{let l=$(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),...s(l));if(f)return f;await c()};return this.#o(A,$(r,"*"),a),this}#o(r,n,t){r=r.toUpperCase(),n=$(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 o=this.getPath(r,{env:t}),s=this.router.match(i,o),a=new tn(r,{path:o,matchResult:s,env:t,executionCtx:n,notFoundHandler:this.#n});if(s[0].length===1){let c;try{c=s[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=tr(s[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${$("/",r)}`,n),t,i));fire=()=>{addEventListener("fetch",r=>{r.respondWith(this.#t(r.request,r,void 0,r.request.method))})}};var je=[];function ur(e,r){let n=this.buildAllMatchers(),t=((i,o)=>{let s=n[i]||n[A],a=s[2][o];if(a)return a;let l=o.match(s[0]);if(!l)return[[],je];let c=l.indexOf("",1);return[s[1][c],l]});return this.match=t,t(e,r)}var Ne="[^/]+",he=".*",me="(?:|/.*)",M=Symbol(),li=new Set(".\\+*[^]$()");function ci(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===Ne?1:r===Ne?-1:e.length===r.length?e<r?-1:1:r.length-e.length}var fn=class fr{#r;#e;#n=Object.create(null);insert(r,n,t,i,o){if(r.length===0){if(this.#r!==void 0)throw M;if(o)return;this.#r=n;return}let[s,...a]=r,l=s==="*"?a.length===0?["","",he]:["","",Ne]:s==="/*"?["","",me]:s.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/),c;if(l){let f=l[1],u=l[2]||Ne;if(f&&l[2]&&(u===".*"||(u=u.replace(/^\((?!\?:)(?=[^)]+\)$)/,"(?:"),/\((?!\?:)/.test(u))))throw M;if(c=this.#n[u],!c){if(Object.keys(this.#n).some(p=>p!==he&&p!==me))throw M;if(o)return;c=this.#n[u]=new fr,f!==""&&(c.#e=i.varIndex++)}!o&&f!==""&&t.push([f,c.#e])}else if(c=this.#n[s],!c){if(Object.keys(this.#n).some(f=>f.length>1&&f!==he&&f!==me))throw M;if(o)return;c=this.#n[s]=new fr}c.insert(a,n,t,i,o)}buildRegExpStr(){let n=Object.keys(this.#n).sort(ci).map(t=>{let i=this.#n[t];return(typeof i.#e=="number"?`(${t})@${i.#e}`:li.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 pn=class{#r={varIndex:0};#e=new fn;insert(e,r,n){let t=[],i=[];for(let s=0;;){let a=!1;if(e=e.replace(/\{[^}]+\}/g,l=>{let c=`@\\${s}`;return i[s]=[c,l],s++,a=!0,c}),!a)break}let o=e.match(/(?::[^\/]+)|(?:\/\*$)|./g)||[];for(let s=i.length-1;s>=0;s--){let[a]=i[s];for(let l=o.length-1;l>=0;l--)if(o[l].indexOf(a)!==-1){o[l]=o[l].replace(a,i[s][1]);break}}return this.#e.insert(o,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,o,s)=>o!==void 0?(n[++r]=Number(o),"$()"):(s!==void 0&&(t[Number(s)]=++r),"")),[new RegExp(`^${e}`),n,t]}};var ui=[/^$/,[],Object.create(null)],dn=Object.create(null);function hn(e){return dn[e]??=new RegExp(e==="*"?"":`^${e.replace(/\/\*$|([.\\+*[^\]$()])/g,(r,n)=>n?`\\${n}`:"(?:|/.*)")}$`)}function fi(){dn=Object.create(null)}function pi(e){let r=new pn,n=[];if(e.length===0)return ui;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)]),je]:f++;let y;try{y=r.insert(d,f,p)}catch(x){throw x===M?new Fe(d):x}p||(n[f]=m.map(([x,v])=>{let g=Object.create(null);for(v-=1;v>=0;v--){let[le,Ye]=y[v];g[le]=Ye}return[x,g]}))}let[o,s,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 s)l[c]=n[s[c]];return[o,l,i]}function V(e,r){if(e){for(let n of Object.keys(e).sort((t,i)=>i.length-t.length))if(hn(n).test(r))return[...e[n]]}}var Le=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(_e);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 o=(r.match(/\/:/g)||[]).length;if(/\*$/.test(r)){let a=hn(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,o])})}),Object.keys(i).forEach(l=>{(e===A||e===l)&&Object.keys(i[l]).forEach(c=>a.test(c)&&i[l][c].push([n,o]))});return}let s=Ie(r)||[r];for(let a=0,l=s.length;a<l;a++){let c=s[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,o-l+a+1]))})}}match=ur;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,fi(),e}#n(e){let r=[],n=e===A;return[this.#r,this.#e].forEach(t=>{let i=t[e]?Object.keys(t[e]).map(o=>[o,t[e][o]]):[];i.length!==0?(n||=!0,r.push(...i)):e!==A&&r.push(...Object.keys(t[A]).map(o=>[o,t[A][o]]))}),n?pi(r):null}};var pr=class{name="SmartRouter";#r=[];#e=[];constructor(e){this.#r=e.routers}add(e,r,n){if(!this.#e)throw new Error(_e);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,o=0,s;for(;o<i;o++){let a=n[o];try{for(let l=0,c=t.length;l<c;l++)a.add(...t[l]);s=a.match(e,r)}catch(l){if(l instanceof Fe)continue;throw l}this.match=a.match.bind(a),this.#r=[a],this.#e=void 0;break}if(o===i)throw new Error("Fatal error");return this.name=`SmartRouter + ${this.activeRouter.name}`,s}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),di=e=>{for(let r in e)return!0;return!1},mn=class gn{#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,o=Vr(n),s=[];for(let a=0,l=o.length;a<l;a++){let c=o[a],f=o[a+1],u=Zr(c,f),p=Array.isArray(u)?u[0]:c;if(p in i.#e){i=i.#e[p],u&&s.push(u[1]);continue}i.#e[p]=new gn,u&&(i.#n.push(u),s.push(u[1])),i=i.#e[p]}return i.#r.push({[r]:{handler:t,possibleKeys:s.filter((a,l,c)=>c.indexOf(a)===l),score:this.#o}}),i}#t(r,n,t,i,o){for(let s=0,a=n.#r.length;s<a;s++){let l=n.#r[s],c=l[t]||l[A],f={};if(c!==void 0&&(c.params=Object.create(null),r.push(c),i!==ge||o&&o!==ge))for(let u=0,p=c.possibleKeys.length;u<p;u++){let d=c.possibleKeys[u],m=f[c.score];c.params[d]=o?.[d]&&!m?o[d]:i[d]??o?.[d],f[c.score]=!0}}}search(r,n){let t=[];this.#i=ge;let o=[this],s=or(n),a=[],l=s.length,c=null;for(let f=0;f<l;f++){let u=s[f],p=f===l-1,d=[];for(let y=0,x=o.length;y<x;y++){let v=o[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,Ye=v.#n.length;le<Ye;le++){let jr=v.#n[le],_=v.#i===ge?{}:{...v.#i};if(jr==="*"){let q=v.#e["*"];q&&(this.#t(t,q,r,v.#i),q.#i=_,d.push(q));continue}let[It,Nr,ce]=jr;if(!u&&!(ce instanceof RegExp))continue;let P=v.#e[It];if(ce instanceof RegExp){if(c===null){c=new Array(l);let Ee=n[0]==="/"?1:0;for(let ue=0;ue<l;ue++)c[ue]=Ee,Ee+=s[ue].length+1}let q=n.substring(c[f]),Ve=ce.exec(q);if(Ve){if(_[Nr]=Ve[0],this.#t(t,P,r,v.#i,_),di(P.#e)){P.#i=_;let Ee=Ve[0].match(/\//)?.length??0;(a[Ee]||=[]).push(P)}continue}}(ce===!0||ce.test(u))&&(_[Nr]=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();o=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 dr=class{name="TrieRouter";#r;constructor(){this.#r=new mn}add(e,r,n){let t=Ie(r);if(t){for(let i=0,o=t.length;i<o;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 cn{constructor(e={}){super(e),this.router=e.router??new pr({routers:[new Le,new dr]})}};var yn=e=>{let n={...{origin:"*",allowMethods:["GET","HEAD","PUT","POST","DELETE","PATCH"],allowHeaders:[],exposeHeaders:[]},...e},t=(o=>typeof o=="string"?o==="*"?n.credentials?s=>s||null:()=>o:s=>o===s?s:null:typeof o=="function"?o:s=>o.includes(s)?s:null)(n.origin),i=(o=>typeof o=="function"?o:Array.isArray(o)?()=>o:()=>[])(n.allowMethods);return async function(s,a){function l(f,u){s.res.headers.set(f,u)}let c=await t(s.req.header("origin")||"",s);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(",")),s.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(s.req.header("origin")||"",s);f.length&&l("Access-Control-Allow-Methods",f.join(","));let u=n.allowHeaders;if(!u?.length){let p=s.req.header("Access-Control-Request-Headers");p&&(u=p.split(/\s*,\s*/))}return u?.length&&(l("Access-Control-Allow-Headers",u.join(",")),s.res.headers.append("Vary","Access-Control-Request-Headers")),s.res.headers.delete("Content-Length"),s.res.headers.delete("Content-Type"),new Response(null,{headers:s.res.headers,status:204,statusText:"No Content"})}await a(),(n.origin!=="*"||n.credentials)&&s.header("Vary","Origin",{append:!0})}};function hi(){let{process:e,Deno:r}=globalThis;return!(typeof r?.noColor=="boolean"?r.noColor:e!==void 0?"NO_COLOR"in e?.env:!1)}async function xn(){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}})():!hi())}var mi=e=>{let[r,n]=[",","."];return e.map(i=>i.replace(/(\d)(?=(\d\d\d)+(?!\d))/g,"$1"+r)).join(n)},gi=e=>{let r=Date.now()-e;return mi([r<1e3?r+"ms":Math.round(r/1e3)+"s"])},yi=async e=>{if(await xn())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 vn(e,r,n,t,i=0,o){let s=r==="<--"?`${r} ${n} ${t}`:`${r} ${n} ${t} ${await yi(i)} ${o}`;e(s)}var An=(e=console.log)=>async function(n,t){let{method:i,url:o}=n.req,s=o.slice(o.indexOf("/",8));await vn(e,"<--",i,s);let a=Date.now();await t(),await vn(e,"-->",i,s,n.res.status,gi(a))};import{existsSync as xi,readFileSync as vi}from"node:fs";import{dirname as Ai,resolve as bn}from"node:path";import{fileURLToPath as bi}from"node:url";var wn="apv.config.json",H=null;function F(){if(H)return H;let r=[process.env.APV_CONFIG,bn(process.cwd(),wn),bn(Ai(bi(import.meta.url)),"..","..","..",wn)].filter(Boolean);for(let n of r)if(xi(n))try{let t=vi(n,"utf-8"),i=JSON.parse(t);return H={cacheDir:i.cacheDir,localRepos:i.localRepos??{},customTaskDocs:i.customTaskDocs??{}},console.log(`Loaded config from ${n}`),wi(H),H}catch(t){console.warn(`Failed to parse ${n}:`,t)}return H={localRepos:{},customTaskDocs:{}},H}function Rn(e,r,n){let t=F(),i=`${e}/${r}/${n}`;if(t.localRepos[i])return t.localRepos[i];let o=i.toLowerCase();for(let[s,a]of Object.entries(t.localRepos))if(s.toLowerCase()===o)return a}function wi(e){let r=Object.entries(e.localRepos);if(r.length===0){console.log(" No local repo mappings configured");return}console.log(` ${r.length} local repo mapping(s):`);for(let[n,t]of r)console.log(` ${n} \u2192 ${t}`)}function De(e){let r=e.startsWith("/"),n=e.split("/").filter(o=>o!==""&&o!=="."),t=[];for(let o of n)o===".."?t.length>0&&t[t.length-1]!==".."?t.pop():r||t.push(o):t.push(o);let i=t.join("/");return r?`/${i}`:i}function Mn(e){return typeof e>"u"||e===null}function Ci(e){return typeof e=="object"&&e!==null}function Ei(e){return Array.isArray(e)?e:Mn(e)?[]:[e]}function ki(e,r){var n,t,i,o;if(r)for(o=Object.keys(r),n=0,t=o.length;n<t;n+=1)i=o[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=Mn,Oi=Ci,Ii=Ei,_i=Si,Fi=Ti,ji=ki,w={isNothing:Pi,isObject:Oi,toArray:Ii,repeat:_i,isNegativeZero:Fi,extend:ji};function Hn(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
|
-
`+e.mark.snippet),t+" "+n):t}function
|
|
5
|
-
`+a;for(c=
|
|
6
|
-
`,a+=
|
|
7
|
-
`,l=1;l<=r.linesAfter&&!(s+l>=i.length);l++)c=
|
|
8
|
-
`;return a.replace(/\n$/,"")}var
|
|
9
|
-
\r`;function
|
|
10
|
-
`:e===118?"\v":e===102?"\f":e===114?"\r":e===101?"\x1B":e===32?" ":e===34?'"':e===47?"/":e===92?"\\":e===78?"\x85":e===95?"\xA0":e===76?"\u2028":e===80?"\u2029":""}function
|
|
11
|
-
`,r-1))}function
|
|
12
|
-
`,o?1+l:l):i===
|
|
13
|
-
`);break}for(t?B(u)?(c=!0,e.result+=
|
|
14
|
-
`,o?1+l:l)):c?(c=!1,e.result+=
|
|
15
|
-
`,l+1)):l===0?o&&(e.result+=" "):e.result+=
|
|
16
|
-
`,l):e.result+=
|
|
17
|
-
`,o?1+l:l),o=!0,s=!0,l=0,n=e.position;!T(u)&&u!==0;)u=e.input.charCodeAt(++e.position);j(e,n,e.position,!1)}return!0}function
|
|
18
|
-
`),e.charCodeAt(0)===65279&&(e=e.slice(1)));var n=new
|
|
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=Hn(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+": "+Hn(this,r)};var E=xe;function hr(e,r,n,t,i){var o="",s="",a=Math.floor(i/2)-1;return t-r>a&&(o=" ... ",r=t-a+o.length),n-t>a&&(s=" ...",n=t+a-s.length),{str:o+e.slice(r,n).replace(/\t/g,"\u2192")+s,pos:t-r+o.length}}function mr(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=[],o,s=-1;o=n.exec(e.buffer);)i.push(o.index),t.push(o.index+o[0].length),e.position<=o.index&&s<0&&(s=t.length-2);s<0&&(s=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&&!(s-l<0);l++)c=hr(e.buffer,t[s-l],i[s-l],e.position-(t[s]-t[s-l]),u),a=w.repeat(" ",r.indent)+mr((e.line-l+1).toString(),f)+" | "+c.str+`
|
|
5
|
+
`+a;for(c=hr(e.buffer,t[s],i[s],e.position,u),a+=w.repeat(" ",r.indent)+mr((e.line+1).toString(),f)+" | "+c.str+`
|
|
6
|
+
`,a+=w.repeat("-",r.indent+f+3+c.pos)+`^
|
|
7
|
+
`,l=1;l<=r.linesAfter&&!(s+l>=i.length);l++)c=hr(e.buffer,t[s+l],i[s+l],e.position-(t[s]-t[s+l]),u),a+=w.repeat(" ",r.indent)+mr((e.line+l+1).toString(),f)+" | "+c.str+`
|
|
8
|
+
`;return a.replace(/\n$/,"")}var Li=Ni,Di=["kind","multi","resolve","construct","instanceOf","predicate","represent","representName","defaultStyle","styleAliases"],$i=["scalar","sequence","mapping"];function Mi(e){var r={};return e!==null&&Object.keys(e).forEach(function(n){e[n].forEach(function(t){r[String(t)]=n})}),r}function Hi(e,r){if(r=r||{},Object.keys(r).forEach(function(n){if(Di.indexOf(n)===-1)throw new E('Unknown option "'+n+'" is met in definition of "'+e+'" YAML type.')}),this.options=r,this.tag=e,this.kind=r.kind||null,this.resolve=r.resolve||function(){return!0},this.construct=r.construct||function(n){return n},this.instanceOf=r.instanceOf||null,this.predicate=r.predicate||null,this.represent=r.represent||null,this.representName=r.representName||null,this.defaultStyle=r.defaultStyle||null,this.multi=r.multi||!1,this.styleAliases=Mi(r.styleAliases||null),$i.indexOf(this.kind)===-1)throw new E('Unknown kind "'+this.kind+'" is specified for "'+e+'" YAML type.')}var R=Hi;function Cn(e,r){var n=[];return e[r].forEach(function(t){var i=n.length;n.forEach(function(o,s){o.tag===t.tag&&o.kind===t.kind&&o.multi===t.multi&&(i=s)}),n[i]=t}),n}function zi(){var e={scalar:{},sequence:{},mapping:{},fallback:{},multi:{scalar:[],sequence:[],mapping:[],fallback:[]}},r,n;function t(i){i.multi?(e.multi[i.kind].push(i),e.multi.fallback.push(i)):e[i.kind][i.tag]=e.fallback[i.tag]=i}for(r=0,n=arguments.length;r<n;r+=1)arguments[r].forEach(t);return e}function yr(e){return this.extend(e)}yr.prototype.extend=function(r){var n=[],t=[];if(r instanceof R)t.push(r);else if(Array.isArray(r))t=t.concat(r);else if(r&&(Array.isArray(r.implicit)||Array.isArray(r.explicit)))r.implicit&&(n=n.concat(r.implicit)),r.explicit&&(t=t.concat(r.explicit));else throw new E("Schema.extend argument should be a Type, [ Type ], or a schema definition ({ implicit: [...], explicit: [...] })");n.forEach(function(o){if(!(o instanceof R))throw new E("Specified list of YAML types (or a single Type object) contains a non-Type object.");if(o.loadKind&&o.loadKind!=="scalar")throw new E("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.");if(o.multi)throw new E("There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.")}),t.forEach(function(o){if(!(o instanceof R))throw new E("Specified list of YAML types (or a single Type object) contains a non-Type object.")});var i=Object.create(yr.prototype);return i.implicit=(this.implicit||[]).concat(n),i.explicit=(this.explicit||[]).concat(t),i.compiledImplicit=Cn(i,"implicit"),i.compiledExplicit=Cn(i,"explicit"),i.compiledTypeMap=zi(i.compiledImplicit,i.compiledExplicit),i};var Bi=yr,Ui=new R("tag:yaml.org,2002:str",{kind:"scalar",construct:function(e){return e!==null?e:""}}),qi=new R("tag:yaml.org,2002:seq",{kind:"sequence",construct:function(e){return e!==null?e:[]}}),Wi=new R("tag:yaml.org,2002:map",{kind:"mapping",construct:function(e){return e!==null?e:{}}}),Gi=new Bi({explicit:[Ui,qi,Wi]});function Ki(e){if(e===null)return!0;var r=e.length;return r===1&&e==="~"||r===4&&(e==="null"||e==="Null"||e==="NULL")}function Yi(){return null}function Vi(e){return e===null}var Zi=new R("tag:yaml.org,2002:null",{kind:"scalar",resolve:Ki,construct:Yi,predicate:Vi,represent:{canonical:function(){return"~"},lowercase:function(){return"null"},uppercase:function(){return"NULL"},camelcase:function(){return"Null"},empty:function(){return""}},defaultStyle:"lowercase"});function Ji(e){if(e===null)return!1;var r=e.length;return r===4&&(e==="true"||e==="True"||e==="TRUE")||r===5&&(e==="false"||e==="False"||e==="FALSE")}function Qi(e){return e==="true"||e==="True"||e==="TRUE"}function Xi(e){return Object.prototype.toString.call(e)==="[object Boolean]"}var eo=new R("tag:yaml.org,2002:bool",{kind:"scalar",resolve:Ji,construct:Qi,predicate:Xi,represent:{lowercase:function(e){return e?"true":"false"},uppercase:function(e){return e?"TRUE":"FALSE"},camelcase:function(e){return e?"True":"False"}},defaultStyle:"lowercase"});function ro(e){return 48<=e&&e<=57||65<=e&&e<=70||97<=e&&e<=102}function no(e){return 48<=e&&e<=55}function to(e){return 48<=e&&e<=57}function io(e){if(e===null)return!1;var r=e.length,n=0,t=!1,i;if(!r)return!1;if(i=e[n],(i==="-"||i==="+")&&(i=e[++n]),i==="0"){if(n+1===r)return!0;if(i=e[++n],i==="b"){for(n++;n<r;n++)if(i=e[n],i!=="_"){if(i!=="0"&&i!=="1")return!1;t=!0}return t&&i!=="_"}if(i==="x"){for(n++;n<r;n++)if(i=e[n],i!=="_"){if(!ro(e.charCodeAt(n)))return!1;t=!0}return t&&i!=="_"}if(i==="o"){for(n++;n<r;n++)if(i=e[n],i!=="_"){if(!no(e.charCodeAt(n)))return!1;t=!0}return t&&i!=="_"}}if(i==="_")return!1;for(;n<r;n++)if(i=e[n],i!=="_"){if(!to(e.charCodeAt(n)))return!1;t=!0}return!(!t||i==="_")}function oo(e){var r=e,n=1,t;if(r.indexOf("_")!==-1&&(r=r.replace(/_/g,"")),t=r[0],(t==="-"||t==="+")&&(t==="-"&&(n=-1),r=r.slice(1),t=r[0]),r==="0")return 0;if(t==="0"){if(r[1]==="b")return n*parseInt(r.slice(2),2);if(r[1]==="x")return n*parseInt(r.slice(2),16);if(r[1]==="o")return n*parseInt(r.slice(2),8)}return n*parseInt(r,10)}function so(e){return Object.prototype.toString.call(e)==="[object Number]"&&e%1===0&&!w.isNegativeZero(e)}var ao=new R("tag:yaml.org,2002:int",{kind:"scalar",resolve:io,construct:oo,predicate:so,represent:{binary:function(e){return e>=0?"0b"+e.toString(2):"-0b"+e.toString(2).slice(1)},octal:function(e){return e>=0?"0o"+e.toString(8):"-0o"+e.toString(8).slice(1)},decimal:function(e){return e.toString(10)},hexadecimal:function(e){return e>=0?"0x"+e.toString(16).toUpperCase():"-0x"+e.toString(16).toUpperCase().slice(1)}},defaultStyle:"decimal",styleAliases:{binary:[2,"bin"],octal:[8,"oct"],decimal:[10,"dec"],hexadecimal:[16,"hex"]}}),lo=new RegExp("^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");function co(e){return!(e===null||!lo.test(e)||e[e.length-1]==="_")}function uo(e){var r,n;return r=e.replace(/_/g,"").toLowerCase(),n=r[0]==="-"?-1:1,"+-".indexOf(r[0])>=0&&(r=r.slice(1)),r===".inf"?n===1?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:r===".nan"?NaN:n*parseFloat(r,10)}var fo=/^[-+]?[0-9]+e/;function po(e,r){var n;if(isNaN(e))switch(r){case"lowercase":return".nan";case"uppercase":return".NAN";case"camelcase":return".NaN"}else if(Number.POSITIVE_INFINITY===e)switch(r){case"lowercase":return".inf";case"uppercase":return".INF";case"camelcase":return".Inf"}else if(Number.NEGATIVE_INFINITY===e)switch(r){case"lowercase":return"-.inf";case"uppercase":return"-.INF";case"camelcase":return"-.Inf"}else if(w.isNegativeZero(e))return"-0.0";return n=e.toString(10),fo.test(n)?n.replace("e",".e"):n}function ho(e){return Object.prototype.toString.call(e)==="[object Number]"&&(e%1!==0||w.isNegativeZero(e))}var mo=new R("tag:yaml.org,2002:float",{kind:"scalar",resolve:co,construct:uo,predicate:ho,represent:po,defaultStyle:"lowercase"}),go=Gi.extend({implicit:[Zi,eo,ao,mo]}),yo=go,zn=new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$"),Bn=new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:[Tt]|[ \\t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\\.([0-9]*))?(?:[ \\t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?$");function xo(e){return e===null?!1:zn.exec(e)!==null||Bn.exec(e)!==null}function vo(e){var r,n,t,i,o,s,a,l=0,c=null,f,u,p;if(r=zn.exec(e),r===null&&(r=Bn.exec(e)),r===null)throw new Error("Date resolve error");if(n=+r[1],t=+r[2]-1,i=+r[3],!r[4])return new Date(Date.UTC(n,t,i));if(o=+r[4],s=+r[5],a=+r[6],r[7]){for(l=r[7].slice(0,3);l.length<3;)l+="0";l=+l}return r[9]&&(f=+r[10],u=+(r[11]||0),c=(f*60+u)*6e4,r[9]==="-"&&(c=-c)),p=new Date(Date.UTC(n,t,i,o,s,a,l)),c&&p.setTime(p.getTime()-c),p}function Ao(e){return e.toISOString()}var bo=new R("tag:yaml.org,2002:timestamp",{kind:"scalar",resolve:xo,construct:vo,instanceOf:Date,represent:Ao});function wo(e){return e==="<<"||e===null}var Ro=new R("tag:yaml.org,2002:merge",{kind:"scalar",resolve:wo}),wr=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=
|
|
9
|
+
\r`;function Co(e){if(e===null)return!1;var r,n,t=0,i=e.length,o=wr;for(n=0;n<i;n++)if(r=o.indexOf(e.charAt(n)),!(r>64)){if(r<0)return!1;t+=6}return t%8===0}function Eo(e){var r,n,t=e.replace(/[\r\n=]/g,""),i=t.length,o=wr,s=0,a=[];for(r=0;r<i;r++)r%4===0&&r&&(a.push(s>>16&255),a.push(s>>8&255),a.push(s&255)),s=s<<6|o.indexOf(t.charAt(r));return n=i%4*6,n===0?(a.push(s>>16&255),a.push(s>>8&255),a.push(s&255)):n===18?(a.push(s>>10&255),a.push(s>>2&255)):n===12&&a.push(s>>4&255),new Uint8Array(a)}function ko(e){var r="",n=0,t,i,o=e.length,s=wr;for(t=0;t<o;t++)t%3===0&&t&&(r+=s[n>>18&63],r+=s[n>>12&63],r+=s[n>>6&63],r+=s[n&63]),n=(n<<8)+e[t];return i=o%3,i===0?(r+=s[n>>18&63],r+=s[n>>12&63],r+=s[n>>6&63],r+=s[n&63]):i===2?(r+=s[n>>10&63],r+=s[n>>4&63],r+=s[n<<2&63],r+=s[64]):i===1&&(r+=s[n>>2&63],r+=s[n<<4&63],r+=s[64],r+=s[64]),r}function So(e){return Object.prototype.toString.call(e)==="[object Uint8Array]"}var To=new R("tag:yaml.org,2002:binary",{kind:"scalar",resolve:Co,construct:Eo,predicate:So,represent:ko}),Po=Object.prototype.hasOwnProperty,Oo=Object.prototype.toString;function Io(e){if(e===null)return!0;var r=[],n,t,i,o,s,a=e;for(n=0,t=a.length;n<t;n+=1){if(i=a[n],s=!1,Oo.call(i)!=="[object Object]")return!1;for(o in i)if(Po.call(i,o))if(!s)s=!0;else return!1;if(!s)return!1;if(r.indexOf(o)===-1)r.push(o);else return!1}return!0}function _o(e){return e!==null?e:[]}var Fo=new R("tag:yaml.org,2002:omap",{kind:"sequence",resolve:Io,construct:_o}),jo=Object.prototype.toString;function No(e){if(e===null)return!0;var r,n,t,i,o,s=e;for(o=new Array(s.length),r=0,n=s.length;r<n;r+=1){if(t=s[r],jo.call(t)!=="[object Object]"||(i=Object.keys(t),i.length!==1))return!1;o[r]=[i[0],t[i[0]]]}return!0}function Lo(e){if(e===null)return[];var r,n,t,i,o,s=e;for(o=new Array(s.length),r=0,n=s.length;r<n;r+=1)t=s[r],i=Object.keys(t),o[r]=[i[0],t[i[0]]];return o}var Do=new R("tag:yaml.org,2002:pairs",{kind:"sequence",resolve:No,construct:Lo}),$o=Object.prototype.hasOwnProperty;function Mo(e){if(e===null)return!0;var r,n=e;for(r in n)if($o.call(n,r)&&n[r]!==null)return!1;return!0}function Ho(e){return e!==null?e:{}}var zo=new R("tag:yaml.org,2002:set",{kind:"mapping",resolve:Mo,construct:Ho}),Un=yo.extend({implicit:[bo,Ro],explicit:[To,Fo,Do,zo]}),N=Object.prototype.hasOwnProperty,$e=1,qn=2,Wn=3,Me=4,gr=1,Bo=2,En=3,Uo=/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/,qo=/[\x85\u2028\u2029]/,Wo=/[,\[\]\{\}]/,Gn=/^(?:!|!!|![a-z\-]+!)$/i,Kn=/^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;function kn(e){return Object.prototype.toString.call(e)}function T(e){return e===10||e===13}function B(e){return e===9||e===32}function k(e){return e===9||e===32||e===10||e===13}function J(e){return e===44||e===91||e===93||e===123||e===125}function Go(e){var r;return 48<=e&&e<=57?e-48:(r=e|32,97<=r&&r<=102?r-97+10:-1)}function Ko(e){return e===120?2:e===117?4:e===85?8:0}function Yo(e){return 48<=e&&e<=57?e-48:-1}function Sn(e){return e===48?"\0":e===97?"\x07":e===98?"\b":e===116||e===9?" ":e===110?`
|
|
10
|
+
`:e===118?"\v":e===102?"\f":e===114?"\r":e===101?"\x1B":e===32?" ":e===34?'"':e===47?"/":e===92?"\\":e===78?"\x85":e===95?"\xA0":e===76?"\u2028":e===80?"\u2029":""}function Vo(e){return e<=65535?String.fromCharCode(e):String.fromCharCode((e-65536>>10)+55296,(e-65536&1023)+56320)}function Yn(e,r,n){r==="__proto__"?Object.defineProperty(e,r,{configurable:!0,enumerable:!0,writable:!0,value:n}):e[r]=n}var Vn=new Array(256),Zn=new Array(256);for(z=0;z<256;z++)Vn[z]=Sn(z)?1:0,Zn[z]=Sn(z);var z;function Zo(e,r){this.input=e,this.filename=r.filename||null,this.schema=r.schema||Un,this.onWarning=r.onWarning||null,this.legacy=r.legacy||!1,this.json=r.json||!1,this.listener=r.listener||null,this.implicitTypes=this.schema.compiledImplicit,this.typeMap=this.schema.compiledTypeMap,this.length=e.length,this.position=0,this.line=0,this.lineStart=0,this.lineIndent=0,this.firstTabInLine=-1,this.documents=[]}function Jn(e,r){var n={name:e.filename,buffer:e.input.slice(0,-1),position:e.position,line:e.line,column:e.position-e.lineStart};return n.snippet=Li(n),new E(r,n)}function h(e,r){throw Jn(e,r)}function He(e,r){e.onWarning&&e.onWarning.call(null,Jn(e,r))}var Tn={YAML:function(r,n,t){var i,o,s;r.version!==null&&h(r,"duplication of %YAML directive"),t.length!==1&&h(r,"YAML directive accepts exactly one argument"),i=/^([0-9]+)\.([0-9]+)$/.exec(t[0]),i===null&&h(r,"ill-formed argument of the YAML directive"),o=parseInt(i[1],10),s=parseInt(i[2],10),o!==1&&h(r,"unacceptable YAML version of the document"),r.version=t[0],r.checkLineBreaks=s<2,s!==1&&s!==2&&He(r,"unsupported YAML version of the document")},TAG:function(r,n,t){var i,o;t.length!==2&&h(r,"TAG directive accepts exactly two arguments"),i=t[0],o=t[1],Gn.test(i)||h(r,"ill-formed tag handle (first argument) of the TAG directive"),N.call(r.tagMap,i)&&h(r,'there is a previously declared suffix for "'+i+'" tag handle'),Kn.test(o)||h(r,"ill-formed tag prefix (second argument) of the TAG directive");try{o=decodeURIComponent(o)}catch{h(r,"tag prefix is malformed: "+o)}r.tagMap[i]=o}};function j(e,r,n,t){var i,o,s,a;if(r<n){if(a=e.input.slice(r,n),t)for(i=0,o=a.length;i<o;i+=1)s=a.charCodeAt(i),s===9||32<=s&&s<=1114111||h(e,"expected valid JSON character");else Uo.test(a)&&h(e,"the stream contains non-printable characters");e.result+=a}}function Pn(e,r,n,t){var i,o,s,a;for(w.isObject(n)||h(e,"cannot merge mappings; the provided source object is unacceptable"),i=Object.keys(n),s=0,a=i.length;s<a;s+=1)o=i[s],N.call(r,o)||(Yn(r,o,n[o]),t[o]=!0)}function Q(e,r,n,t,i,o,s,a,l){var c,f;if(Array.isArray(i))for(i=Array.prototype.slice.call(i),c=0,f=i.length;c<f;c+=1)Array.isArray(i[c])&&h(e,"nested arrays are not supported inside keys"),typeof i=="object"&&kn(i[c])==="[object Object]"&&(i[c]="[object Object]");if(typeof i=="object"&&kn(i)==="[object Object]"&&(i="[object Object]"),i=String(i),r===null&&(r={}),t==="tag:yaml.org,2002:merge")if(Array.isArray(o))for(c=0,f=o.length;c<f;c+=1)Pn(e,r,o[c],n);else Pn(e,r,o,n);else!e.json&&!N.call(n,i)&&N.call(r,i)&&(e.line=s||e.line,e.lineStart=a||e.lineStart,e.position=l||e.position,h(e,"duplicated mapping key")),Yn(r,i,o),delete n[i];return r}function Rr(e){var r;r=e.input.charCodeAt(e.position),r===10?e.position++:r===13?(e.position++,e.input.charCodeAt(e.position)===10&&e.position++):h(e,"a line break is expected"),e.line+=1,e.lineStart=e.position,e.firstTabInLine=-1}function b(e,r,n){for(var t=0,i=e.input.charCodeAt(e.position);i!==0;){for(;B(i);)i===9&&e.firstTabInLine===-1&&(e.firstTabInLine=e.position),i=e.input.charCodeAt(++e.position);if(r&&i===35)do i=e.input.charCodeAt(++e.position);while(i!==10&&i!==13&&i!==0);if(T(i))for(Rr(e),i=e.input.charCodeAt(e.position),t++,e.lineIndent=0;i===32;)e.lineIndent++,i=e.input.charCodeAt(++e.position);else break}return n!==-1&&t!==0&&e.lineIndent<n&&He(e,"deficient indentation"),t}function Ue(e){var r=e.position,n;return n=e.input.charCodeAt(r),!!((n===45||n===46)&&n===e.input.charCodeAt(r+1)&&n===e.input.charCodeAt(r+2)&&(r+=3,n=e.input.charCodeAt(r),n===0||k(n)))}function Cr(e,r){r===1?e.result+=" ":r>1&&(e.result+=w.repeat(`
|
|
11
|
+
`,r-1))}function Jo(e,r,n){var t,i,o,s,a,l,c,f,u=e.kind,p=e.result,d;if(d=e.input.charCodeAt(e.position),k(d)||J(d)||d===35||d===38||d===42||d===33||d===124||d===62||d===39||d===34||d===37||d===64||d===96||(d===63||d===45)&&(i=e.input.charCodeAt(e.position+1),k(i)||n&&J(i)))return!1;for(e.kind="scalar",e.result="",o=s=e.position,a=!1;d!==0;){if(d===58){if(i=e.input.charCodeAt(e.position+1),k(i)||n&&J(i))break}else if(d===35){if(t=e.input.charCodeAt(e.position-1),k(t))break}else{if(e.position===e.lineStart&&Ue(e)||n&&J(d))break;if(T(d))if(l=e.line,c=e.lineStart,f=e.lineIndent,b(e,!1,-1),e.lineIndent>=r){a=!0,d=e.input.charCodeAt(e.position);continue}else{e.position=s,e.line=l,e.lineStart=c,e.lineIndent=f;break}}a&&(j(e,o,s,!1),Cr(e,e.line-l),o=s=e.position,a=!1),B(d)||(s=e.position+1),d=e.input.charCodeAt(++e.position)}return j(e,o,s,!1),e.result?!0:(e.kind=u,e.result=p,!1)}function Qo(e,r){var n,t,i;if(n=e.input.charCodeAt(e.position),n!==39)return!1;for(e.kind="scalar",e.result="",e.position++,t=i=e.position;(n=e.input.charCodeAt(e.position))!==0;)if(n===39)if(j(e,t,e.position,!0),n=e.input.charCodeAt(++e.position),n===39)t=e.position,e.position++,i=e.position;else return!0;else T(n)?(j(e,t,i,!0),Cr(e,b(e,!1,r)),t=i=e.position):e.position===e.lineStart&&Ue(e)?h(e,"unexpected end of the document within a single quoted scalar"):(e.position++,i=e.position);h(e,"unexpected end of the stream within a single quoted scalar")}function Xo(e,r){var n,t,i,o,s,a;if(a=e.input.charCodeAt(e.position),a!==34)return!1;for(e.kind="scalar",e.result="",e.position++,n=t=e.position;(a=e.input.charCodeAt(e.position))!==0;){if(a===34)return j(e,n,e.position,!0),e.position++,!0;if(a===92){if(j(e,n,e.position,!0),a=e.input.charCodeAt(++e.position),T(a))b(e,!1,r);else if(a<256&&Vn[a])e.result+=Zn[a],e.position++;else if((s=Ko(a))>0){for(i=s,o=0;i>0;i--)a=e.input.charCodeAt(++e.position),(s=Go(a))>=0?o=(o<<4)+s:h(e,"expected hexadecimal character");e.result+=Vo(o),e.position++}else h(e,"unknown escape sequence");n=t=e.position}else T(a)?(j(e,n,t,!0),Cr(e,b(e,!1,r)),n=t=e.position):e.position===e.lineStart&&Ue(e)?h(e,"unexpected end of the document within a double quoted scalar"):(e.position++,t=e.position)}h(e,"unexpected end of the stream within a double quoted scalar")}function es(e,r){var n=!0,t,i,o,s=e.tag,a,l=e.anchor,c,f,u,p,d,m=Object.create(null),y,x,v,g;if(g=e.input.charCodeAt(e.position),g===91)f=93,d=!1,a=[];else if(g===123)f=125,d=!0,a={};else return!1;for(e.anchor!==null&&(e.anchorMap[e.anchor]=a),g=e.input.charCodeAt(++e.position);g!==0;){if(b(e,!0,r),g=e.input.charCodeAt(e.position),g===f)return e.position++,e.tag=s,e.anchor=l,e.kind=d?"mapping":"sequence",e.result=a,!0;n?g===44&&h(e,"expected the node content, but found ','"):h(e,"missed comma between flow collection entries"),x=y=v=null,u=p=!1,g===63&&(c=e.input.charCodeAt(e.position+1),k(c)&&(u=p=!0,e.position++,b(e,!0,r))),t=e.line,i=e.lineStart,o=e.position,X(e,r,$e,!1,!0),x=e.tag,y=e.result,b(e,!0,r),g=e.input.charCodeAt(e.position),(p||e.line===t)&&g===58&&(u=!0,g=e.input.charCodeAt(++e.position),b(e,!0,r),X(e,r,$e,!1,!0),v=e.result),d?Q(e,a,m,x,y,v,t,i,o):u?a.push(Q(e,null,m,x,y,v,t,i,o)):a.push(y),b(e,!0,r),g=e.input.charCodeAt(e.position),g===44?(n=!0,g=e.input.charCodeAt(++e.position)):n=!1}h(e,"unexpected end of the stream within a flow collection")}function rs(e,r){var n,t,i=gr,o=!1,s=!1,a=r,l=0,c=!1,f,u;if(u=e.input.charCodeAt(e.position),u===124)t=!1;else if(u===62)t=!0;else return!1;for(e.kind="scalar",e.result="";u!==0;)if(u=e.input.charCodeAt(++e.position),u===43||u===45)gr===i?i=u===43?En:Bo:h(e,"repeat of a chomping mode identifier");else if((f=Yo(u))>=0)f===0?h(e,"bad explicit indentation width of a block scalar; it cannot be less than one"):s?h(e,"repeat of an indentation width identifier"):(a=r+f-1,s=!0);else break;if(B(u)){do u=e.input.charCodeAt(++e.position);while(B(u));if(u===35)do u=e.input.charCodeAt(++e.position);while(!T(u)&&u!==0)}for(;u!==0;){for(Rr(e),e.lineIndent=0,u=e.input.charCodeAt(e.position);(!s||e.lineIndent<a)&&u===32;)e.lineIndent++,u=e.input.charCodeAt(++e.position);if(!s&&e.lineIndent>a&&(a=e.lineIndent),T(u)){l++;continue}if(e.lineIndent<a){i===En?e.result+=w.repeat(`
|
|
12
|
+
`,o?1+l:l):i===gr&&o&&(e.result+=`
|
|
13
|
+
`);break}for(t?B(u)?(c=!0,e.result+=w.repeat(`
|
|
14
|
+
`,o?1+l:l)):c?(c=!1,e.result+=w.repeat(`
|
|
15
|
+
`,l+1)):l===0?o&&(e.result+=" "):e.result+=w.repeat(`
|
|
16
|
+
`,l):e.result+=w.repeat(`
|
|
17
|
+
`,o?1+l:l),o=!0,s=!0,l=0,n=e.position;!T(u)&&u!==0;)u=e.input.charCodeAt(++e.position);j(e,n,e.position,!1)}return!0}function On(e,r){var n,t=e.tag,i=e.anchor,o=[],s,a=!1,l;if(e.firstTabInLine!==-1)return!1;for(e.anchor!==null&&(e.anchorMap[e.anchor]=o),l=e.input.charCodeAt(e.position);l!==0&&(e.firstTabInLine!==-1&&(e.position=e.firstTabInLine,h(e,"tab characters must not be used in indentation")),!(l!==45||(s=e.input.charCodeAt(e.position+1),!k(s))));){if(a=!0,e.position++,b(e,!0,-1)&&e.lineIndent<=r){o.push(null),l=e.input.charCodeAt(e.position);continue}if(n=e.line,X(e,r,Wn,!1,!0),o.push(e.result),b(e,!0,-1),l=e.input.charCodeAt(e.position),(e.line===n||e.lineIndent>r)&&l!==0)h(e,"bad indentation of a sequence entry");else if(e.lineIndent<r)break}return a?(e.tag=t,e.anchor=i,e.kind="sequence",e.result=o,!0):!1}function ns(e,r,n){var t,i,o,s,a,l,c=e.tag,f=e.anchor,u={},p=Object.create(null),d=null,m=null,y=null,x=!1,v=!1,g;if(e.firstTabInLine!==-1)return!1;for(e.anchor!==null&&(e.anchorMap[e.anchor]=u),g=e.input.charCodeAt(e.position);g!==0;){if(!x&&e.firstTabInLine!==-1&&(e.position=e.firstTabInLine,h(e,"tab characters must not be used in indentation")),t=e.input.charCodeAt(e.position+1),o=e.line,(g===63||g===58)&&k(t))g===63?(x&&(Q(e,u,p,d,m,null,s,a,l),d=m=y=null),v=!0,x=!0,i=!0):x?(x=!1,i=!0):h(e,"incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line"),e.position+=1,g=t;else{if(s=e.line,a=e.lineStart,l=e.position,!X(e,n,qn,!1,!0))break;if(e.line===o){for(g=e.input.charCodeAt(e.position);B(g);)g=e.input.charCodeAt(++e.position);if(g===58)g=e.input.charCodeAt(++e.position),k(g)||h(e,"a whitespace character is expected after the key-value separator within a block mapping"),x&&(Q(e,u,p,d,m,null,s,a,l),d=m=y=null),v=!0,x=!1,i=!1,d=e.tag,m=e.result;else if(v)h(e,"can not read an implicit mapping pair; a colon is missed");else return e.tag=c,e.anchor=f,!0}else if(v)h(e,"can not read a block mapping entry; a multiline key may not be an implicit key");else return e.tag=c,e.anchor=f,!0}if((e.line===o||e.lineIndent>r)&&(x&&(s=e.line,a=e.lineStart,l=e.position),X(e,r,Me,!0,i)&&(x?m=e.result:y=e.result),x||(Q(e,u,p,d,m,y,s,a,l),d=m=y=null),b(e,!0,-1),g=e.input.charCodeAt(e.position)),(e.line===o||e.lineIndent>r)&&g!==0)h(e,"bad indentation of a mapping entry");else if(e.lineIndent<r)break}return x&&Q(e,u,p,d,m,null,s,a,l),v&&(e.tag=c,e.anchor=f,e.kind="mapping",e.result=u),v}function ts(e){var r,n=!1,t=!1,i,o,s;if(s=e.input.charCodeAt(e.position),s!==33)return!1;if(e.tag!==null&&h(e,"duplication of a tag property"),s=e.input.charCodeAt(++e.position),s===60?(n=!0,s=e.input.charCodeAt(++e.position)):s===33?(t=!0,i="!!",s=e.input.charCodeAt(++e.position)):i="!",r=e.position,n){do s=e.input.charCodeAt(++e.position);while(s!==0&&s!==62);e.position<e.length?(o=e.input.slice(r,e.position),s=e.input.charCodeAt(++e.position)):h(e,"unexpected end of the stream within a verbatim tag")}else{for(;s!==0&&!k(s);)s===33&&(t?h(e,"tag suffix cannot contain exclamation marks"):(i=e.input.slice(r-1,e.position+1),Gn.test(i)||h(e,"named tag handle cannot contain such characters"),t=!0,r=e.position+1)),s=e.input.charCodeAt(++e.position);o=e.input.slice(r,e.position),Wo.test(o)&&h(e,"tag suffix cannot contain flow indicator characters")}o&&!Kn.test(o)&&h(e,"tag name cannot contain such characters: "+o);try{o=decodeURIComponent(o)}catch{h(e,"tag name is malformed: "+o)}return n?e.tag=o:N.call(e.tagMap,i)?e.tag=e.tagMap[i]+o:i==="!"?e.tag="!"+o:i==="!!"?e.tag="tag:yaml.org,2002:"+o:h(e,'undeclared tag handle "'+i+'"'),!0}function is(e){var r,n;if(n=e.input.charCodeAt(e.position),n!==38)return!1;for(e.anchor!==null&&h(e,"duplication of an anchor property"),n=e.input.charCodeAt(++e.position),r=e.position;n!==0&&!k(n)&&!J(n);)n=e.input.charCodeAt(++e.position);return e.position===r&&h(e,"name of an anchor node must contain at least one character"),e.anchor=e.input.slice(r,e.position),!0}function os(e){var r,n,t;if(t=e.input.charCodeAt(e.position),t!==42)return!1;for(t=e.input.charCodeAt(++e.position),r=e.position;t!==0&&!k(t)&&!J(t);)t=e.input.charCodeAt(++e.position);return e.position===r&&h(e,"name of an alias node must contain at least one character"),n=e.input.slice(r,e.position),N.call(e.anchorMap,n)||h(e,'unidentified alias "'+n+'"'),e.result=e.anchorMap[n],b(e,!0,-1),!0}function X(e,r,n,t,i){var o,s,a,l=1,c=!1,f=!1,u,p,d,m,y,x;if(e.listener!==null&&e.listener("open",e),e.tag=null,e.anchor=null,e.kind=null,e.result=null,o=s=a=Me===n||Wn===n,t&&b(e,!0,-1)&&(c=!0,e.lineIndent>r?l=1:e.lineIndent===r?l=0:e.lineIndent<r&&(l=-1)),l===1)for(;ts(e)||is(e);)b(e,!0,-1)?(c=!0,a=o,e.lineIndent>r?l=1:e.lineIndent===r?l=0:e.lineIndent<r&&(l=-1)):a=!1;if(a&&(a=c||i),(l===1||Me===n)&&($e===n||qn===n?y=r:y=r+1,x=e.position-e.lineStart,l===1?a&&(On(e,x)||ns(e,x,y))||es(e,y)?f=!0:(s&&rs(e,y)||Qo(e,y)||Xo(e,y)?f=!0:os(e)?(f=!0,(e.tag!==null||e.anchor!==null)&&h(e,"alias node should not have any properties")):Jo(e,y,$e===n)&&(f=!0,e.tag===null&&(e.tag="?")),e.anchor!==null&&(e.anchorMap[e.anchor]=e.result)):l===0&&(f=a&&On(e,x))),e.tag===null)e.anchor!==null&&(e.anchorMap[e.anchor]=e.result);else if(e.tag==="?"){for(e.result!==null&&e.kind!=="scalar"&&h(e,'unacceptable node kind for !<?> tag; it should be "scalar", not "'+e.kind+'"'),u=0,p=e.implicitTypes.length;u<p;u+=1)if(m=e.implicitTypes[u],m.resolve(e.result)){e.result=m.construct(e.result),e.tag=m.tag,e.anchor!==null&&(e.anchorMap[e.anchor]=e.result);break}}else if(e.tag!=="!"){if(N.call(e.typeMap[e.kind||"fallback"],e.tag))m=e.typeMap[e.kind||"fallback"][e.tag];else for(m=null,d=e.typeMap.multi[e.kind||"fallback"],u=0,p=d.length;u<p;u+=1)if(e.tag.slice(0,d[u].tag.length)===d[u].tag){m=d[u];break}m||h(e,"unknown tag !<"+e.tag+">"),e.result!==null&&m.kind!==e.kind&&h(e,"unacceptable node kind for !<"+e.tag+'> tag; it should be "'+m.kind+'", not "'+e.kind+'"'),m.resolve(e.result,e.tag)?(e.result=m.construct(e.result,e.tag),e.anchor!==null&&(e.anchorMap[e.anchor]=e.result)):h(e,"cannot resolve a node with !<"+e.tag+"> explicit tag")}return e.listener!==null&&e.listener("close",e),e.tag!==null||e.anchor!==null||f}function ss(e){var r=e.position,n,t,i,o=!1,s;for(e.version=null,e.checkLineBreaks=e.legacy,e.tagMap=Object.create(null),e.anchorMap=Object.create(null);(s=e.input.charCodeAt(e.position))!==0&&(b(e,!0,-1),s=e.input.charCodeAt(e.position),!(e.lineIndent>0||s!==37));){for(o=!0,s=e.input.charCodeAt(++e.position),n=e.position;s!==0&&!k(s);)s=e.input.charCodeAt(++e.position);for(t=e.input.slice(n,e.position),i=[],t.length<1&&h(e,"directive name must not be less than one character in length");s!==0;){for(;B(s);)s=e.input.charCodeAt(++e.position);if(s===35){do s=e.input.charCodeAt(++e.position);while(s!==0&&!T(s));break}if(T(s))break;for(n=e.position;s!==0&&!k(s);)s=e.input.charCodeAt(++e.position);i.push(e.input.slice(n,e.position))}s!==0&&Rr(e),N.call(Tn,t)?Tn[t](e,t,i):He(e,'unknown document directive "'+t+'"')}if(b(e,!0,-1),e.lineIndent===0&&e.input.charCodeAt(e.position)===45&&e.input.charCodeAt(e.position+1)===45&&e.input.charCodeAt(e.position+2)===45?(e.position+=3,b(e,!0,-1)):o&&h(e,"directives end mark is expected"),X(e,e.lineIndent-1,Me,!1,!0),b(e,!0,-1),e.checkLineBreaks&&qo.test(e.input.slice(r,e.position))&&He(e,"non-ASCII line breaks are interpreted as content"),e.documents.push(e.result),e.position===e.lineStart&&Ue(e)){e.input.charCodeAt(e.position)===46&&(e.position+=3,b(e,!0,-1));return}if(e.position<e.length-1)h(e,"end of the stream or a document separator is expected");else return}function Qn(e,r){e=String(e),r=r||{},e.length!==0&&(e.charCodeAt(e.length-1)!==10&&e.charCodeAt(e.length-1)!==13&&(e+=`
|
|
18
|
+
`),e.charCodeAt(0)===65279&&(e=e.slice(1)));var n=new Zo(e,r),t=e.indexOf("\0");for(t!==-1&&(n.position=t,h(n,"null byte is not allowed in input")),n.input+="\0";n.input.charCodeAt(n.position)===32;)n.lineIndent+=1,n.position+=1;for(;n.position<n.length-1;)ss(n);return n.documents}function as(e,r,n){r!==null&&typeof r=="object"&&typeof n>"u"&&(n=r,r=null);var t=Qn(e,n);if(typeof r!="function")return t;for(var i=0,o=t.length;i<o;i+=1)r(t[i])}function ls(e,r){var n=Qn(e,r);if(n.length!==0){if(n.length===1)return n[0];throw new E("expected a single document in the stream, but found more")}}var cs=as,us=ls,Xn={loadAll:cs,load:us},et=Object.prototype.toString,rt=Object.prototype.hasOwnProperty,Er=65279,fs=9,ve=10,ps=13,ds=32,hs=33,ms=34,xr=35,gs=37,ys=38,xs=39,vs=42,nt=44,As=45,ze=58,bs=61,ws=62,Rs=63,Cs=64,tt=91,it=93,Es=96,ot=123,ks=124,st=125,C={};C[0]="\\0";C[7]="\\a";C[8]="\\b";C[9]="\\t";C[10]="\\n";C[11]="\\v";C[12]="\\f";C[13]="\\r";C[27]="\\e";C[34]='\\"';C[92]="\\\\";C[133]="\\N";C[160]="\\_";C[8232]="\\L";C[8233]="\\P";var Ss=["y","Y","yes","Yes","YES","on","On","ON","n","N","no","No","NO","off","Off","OFF"],Ts=/^[-+]?[0-9_]+(?::[0-9_]+)+(?:\.[0-9_]*)?$/;function Ps(e,r){var n,t,i,o,s,a,l;if(r===null)return{};for(n={},t=Object.keys(r),i=0,o=t.length;i<o;i+=1)s=t[i],a=String(r[s]),s.slice(0,2)==="!!"&&(s="tag:yaml.org,2002:"+s.slice(2)),l=e.compiledTypeMap.fallback[s],l&&rt.call(l.styleAliases,a)&&(a=l.styleAliases[a]),n[s]=a;return n}function Os(e){var r,n,t;if(r=e.toString(16).toUpperCase(),e<=255)n="x",t=2;else if(e<=65535)n="u",t=4;else if(e<=4294967295)n="U",t=8;else throw new E("code point within a string may not be greater than 0xFFFFFFFF");return"\\"+n+w.repeat("0",t-r.length)+r}var Is=1,Ae=2;function _s(e){this.schema=e.schema||Un,this.indent=Math.max(1,e.indent||2),this.noArrayIndent=e.noArrayIndent||!1,this.skipInvalid=e.skipInvalid||!1,this.flowLevel=w.isNothing(e.flowLevel)?-1:e.flowLevel,this.styleMap=Ps(this.schema,e.styles||null),this.sortKeys=e.sortKeys||!1,this.lineWidth=e.lineWidth||80,this.noRefs=e.noRefs||!1,this.noCompatMode=e.noCompatMode||!1,this.condenseFlow=e.condenseFlow||!1,this.quotingType=e.quotingType==='"'?Ae:Is,this.forceQuotes=e.forceQuotes||!1,this.replacer=typeof e.replacer=="function"?e.replacer:null,this.implicitTypes=this.schema.compiledImplicit,this.explicitTypes=this.schema.compiledExplicit,this.tag=null,this.result="",this.duplicates=[],this.usedDuplicates=null}function In(e,r){for(var n=w.repeat(" ",r),t=0,i=-1,o="",s,a=e.length;t<a;)i=e.indexOf(`
|
|
19
19
|
`,t),i===-1?(s=e.slice(t),t=a):(s=e.slice(t,i+1),t=i+1),s.length&&s!==`
|
|
20
|
-
`&&(o+=n),o+=s;return o}function
|
|
21
|
-
`+
|
|
20
|
+
`&&(o+=n),o+=s;return o}function vr(e,r){return`
|
|
21
|
+
`+w.repeat(" ",e.indent*r)}function Fs(e,r){var n,t,i;for(n=0,t=e.implicitTypes.length;n<t;n+=1)if(i=e.implicitTypes[n],i.resolve(r))return!0;return!1}function Be(e){return e===ds||e===fs}function be(e){return 32<=e&&e<=126||161<=e&&e<=55295&&e!==8232&&e!==8233||57344<=e&&e<=65533&&e!==Er||65536<=e&&e<=1114111}function _n(e){return be(e)&&e!==Er&&e!==ps&&e!==ve}function Fn(e,r,n){var t=_n(e),i=t&&!Be(e);return(n?t:t&&e!==nt&&e!==tt&&e!==it&&e!==ot&&e!==st)&&e!==xr&&!(r===ze&&!i)||_n(r)&&!Be(r)&&e===xr||r===ze&&i}function js(e){return be(e)&&e!==Er&&!Be(e)&&e!==As&&e!==Rs&&e!==ze&&e!==nt&&e!==tt&&e!==it&&e!==ot&&e!==st&&e!==xr&&e!==ys&&e!==vs&&e!==hs&&e!==ks&&e!==bs&&e!==ws&&e!==xs&&e!==ms&&e!==gs&&e!==Cs&&e!==Es}function Ns(e){return!Be(e)&&e!==ze}function ye(e,r){var n=e.charCodeAt(r),t;return n>=55296&&n<=56319&&r+1<e.length&&(t=e.charCodeAt(r+1),t>=56320&&t<=57343)?(n-55296)*1024+t-56320+65536:n}function at(e){var r=/^\n* /;return r.test(e)}var lt=1,Ar=2,ct=3,ut=4,Z=5;function Ls(e,r,n,t,i,o,s,a){var l,c=0,f=null,u=!1,p=!1,d=t!==-1,m=-1,y=js(ye(e,0))&&Ns(ye(e,e.length-1));if(r||s)for(l=0;l<e.length;c>=65536?l+=2:l++){if(c=ye(e,l),!be(c))return Z;y=y&&Fn(c,f,a),f=c}else{for(l=0;l<e.length;c>=65536?l+=2:l++){if(c=ye(e,l),c===ve)u=!0,d&&(p=p||l-m-1>t&&e[m+1]!==" ",m=l);else if(!be(c))return Z;y=y&&Fn(c,f,a),f=c}p=p||d&&l-m-1>t&&e[m+1]!==" "}return!u&&!p?y&&!s&&!i(e)?lt:o===Ae?Z:Ar:n>9&&at(e)?Z:s?o===Ae?Z:Ar:p?ut:ct}function Ds(e,r,n,t,i){e.dump=(function(){if(r.length===0)return e.quotingType===Ae?'""':"''";if(!e.noCompatMode&&(Ss.indexOf(r)!==-1||Ts.test(r)))return e.quotingType===Ae?'"'+r+'"':"'"+r+"'";var o=e.indent*Math.max(1,n),s=e.lineWidth===-1?-1:Math.max(Math.min(e.lineWidth,40),e.lineWidth-o),a=t||e.flowLevel>-1&&n>=e.flowLevel;function l(c){return Fs(e,c)}switch(Ls(r,a,e.indent,s,l,e.quotingType,e.forceQuotes&&!t,i)){case lt:return r;case Ar:return"'"+r.replace(/'/g,"''")+"'";case ct:return"|"+jn(r,e.indent)+Nn(In(r,o));case ut:return">"+jn(r,e.indent)+Nn(In($s(r,s),o));case Z:return'"'+Ms(r)+'"';default:throw new E("impossible error: invalid scalar style")}})()}function jn(e,r){var n=at(e)?String(r):"",t=e[e.length-1]===`
|
|
22
22
|
`,i=t&&(e[e.length-2]===`
|
|
23
23
|
`||e===`
|
|
24
24
|
`),o=i?"+":t?"":"-";return n+o+`
|
|
25
|
-
`}function
|
|
26
|
-
`?e.slice(0,-1):e}function
|
|
27
|
-
`);return c=c!==-1?c:e.length,n.lastIndex=c,
|
|
25
|
+
`}function Nn(e){return e[e.length-1]===`
|
|
26
|
+
`?e.slice(0,-1):e}function $s(e,r){for(var n=/(\n+)([^\n]*)/g,t=(function(){var c=e.indexOf(`
|
|
27
|
+
`);return c=c!==-1?c:e.length,n.lastIndex=c,Ln(e.slice(0,c),r)})(),i=e[0]===`
|
|
28
28
|
`||e[0]===" ",o,s;s=n.exec(e);){var a=s[1],l=s[2];o=l[0]===" ",t+=a+(!i&&!o&&l!==""?`
|
|
29
|
-
`:"")+
|
|
29
|
+
`:"")+Ln(l,r),i=o}return t}function Ln(e,r){if(e===""||e[0]===" ")return e;for(var n=/ [^ ]/g,t,i=0,o,s=0,a=0,l="";t=n.exec(e);)a=t.index,a-i>r&&(o=s>i?s:a,l+=`
|
|
30
30
|
`+e.slice(i,o),i=o+1),s=a;return l+=`
|
|
31
31
|
`,e.length-i>r&&s>i?l+=e.slice(i,s)+`
|
|
32
|
-
`+e.slice(s+1):l+=e.slice(i),l.slice(1)}function
|
|
33
|
-
`:""}var Ns=Fs,Ls={dump:Ns};function br(e,r){return function(){throw new Error("Function yaml."+e+" is removed in js-yaml 4. Use yaml."+r+" instead, which is now safe by default.")}}var pc=Gn.load,dc=Gn.loadAll,hc=Ls.dump;var mc=br("safeLoad","load"),gc=br("safeLoadAll","loadAll"),yc=br("safeDump","dump");import{DefaultAzureCredential as zs}from"@azure/identity";var Us="499b84ac-1321-427f-aa17-267ca6975798/.default",Rr=null;function qs(){return Rr||(Rr=new zs),Rr}async function He(){return(await qs().getToken(Us)).token}var ye=class{store=new Map;ttlMs;maxSize;constructor(r,n=1e3){this.ttlMs=r*1e3,this.maxSize=n}get(r){let n=this.store.get(r);if(n){if(Date.now()>n.expiresAt){this.store.delete(r);return}return n.value}}set(r,n){if(this.store.size>=this.maxSize&&!this.store.has(r)){let t=this.store.keys().next().value;t!==void 0&&this.store.delete(t)}this.store.set(r,{value:n,expiresAt:Date.now()+this.ttlMs})}async getOrFetch(r,n){let t=this.get(r);if(t!==void 0)return t;let i=await n();return this.set(r,i),i}get size(){return this.store.size}clear(){this.store.clear()}};var Z="7.1",Ws=new ye(600),Gs=new ye(120),Ks=/^[0-9a-f]{7,40}$/i;async function ee(e){let r=await He(),n=await fetch(e,{headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json"}});if(!n.ok){let t=await n.text();throw new Error(`Azure DevOps API error (${n.status}): ${t}`)}return n}function re(e,r){return`https://dev.azure.com/${encodeURIComponent(e)}/${encodeURIComponent(r)}/_apis`}function Be(e){return e.startsWith("refs/")||Ks.test(e)?e:`refs/heads/${e}`}function ze(e){let r=Be(e);return r.startsWith("refs/heads/")?{version:r.slice(11),versionType:"branch"}:r.startsWith("refs/tags/")?{version:r.slice(10),versionType:"tag"}:{version:r,versionType:"commit"}}async function ot(e,r,n,t){let i=Be(t),o=ze(i);if(o.versionType==="commit")return o.version;let s=`${e}/${r}/${n}/${i}`.toLowerCase();return Gs.getOrFetch(s,async()=>{let a=i.replace(/^refs\//,""),l=`${re(e,r)}/git/repositories/${encodeURIComponent(n)}/refs?filter=${encodeURIComponent(a)}&api-version=${Z}`,u=(await(await ee(l)).json()).value?.find(p=>p.name===i);if(!u?.objectId)throw new Error(`Git ref not found: ${i}`);return u.objectId})}async function st(e,r){let n=`${re(e,r)}/pipelines?api-version=${Z}`;return(await(await ee(n)).json()).value}async function wr(e,r,n){let t=`${re(e,r)}/build/definitions/${n}?api-version=${Z}`,o=await(await ee(t)).json();return{id:o.id,name:o.name,path:o.process?.yamlFilename??o.path,repository:{id:o.repository?.id,name:o.repository?.name,type:o.repository?.type,defaultBranch:o.repository?.defaultBranch}}}async function at(e,r){let n=`${re(e,r)}/git/repositories?api-version=${Z}`;return(await(await ee(n)).json()).value}async function Cr(e,r,n){let t=`${e}/${r}/${n}`.toLowerCase();return Ws.getOrFetch(t,async()=>{let i=`${re(e,r)}/git/repositories/${encodeURIComponent(n)}?api-version=${Z}`;return(await ee(i)).json()})}async function lt(e,r,n,t,i){let o=t.startsWith("/")?t:`/${t}`,s=je(o),a=`${re(e,r)}/git/repositories/${encodeURIComponent(n)}/items?scopePath=${encodeURIComponent(s)}&api-version=${Z}&$format=text`;if(i){let c=ze(i);a+=`&versionDescriptor.version=${encodeURIComponent(c.version)}&versionDescriptor.versionType=${c.versionType}`}return(await ee(a)).text()}import{existsSync as Ys}from"node:fs";import{readFile as Vs}from"node:fs/promises";import{join as Js,normalize as ct}from"node:path";async function ut(e,r){let n=r.replace(/\\/g,"/").replace(/^\/+/,""),t=ct(Js(e,n)),i=ct(e);if(!t.startsWith(i))throw new Error(`Path traversal attempt: ${r}`);if(!Ys(t))throw new Error(`File not found locally: ${t}`);return Vs(t,"utf-8")}import{createHash as Qs}from"node:crypto";import{existsSync as ft}from"node:fs";import{mkdir as Xs,readFile as pt,writeFile as dt}from"node:fs/promises";import{dirname as Zs,resolve as ne}from"node:path";import{fileURLToPath as ea}from"node:url";function ra(e){if(e)return ne(e);let r=Y().cacheDir;return r?ne(r):ne(Zs(ea(import.meta.url)),"..","..","..",".cache","ado-file-cache")}function na(e){return Qs("sha256").update(JSON.stringify(e)).digest("hex")}function ta(e,r){let n=ne(e,r.slice(0,2),r.slice(2,4),r);return{dir:n,metadataPath:ne(n,"metadata.json"),contentPath:ne(n,"content.txt")}}async function ia(e){if(!ft(e.metadataPath)||!ft(e.contentPath))return null;let[r,n]=await Promise.all([pt(e.metadataPath,"utf-8"),pt(e.contentPath,"utf-8")]);return{metadata:JSON.parse(r),content:n}}async function oa(e,r,n){await Xs(e.dir,{recursive:!0}),await Promise.all([dt(e.metadataPath,JSON.stringify(r,null,2),"utf-8"),dt(e.contentPath,n,"utf-8")])}async function xe(e){let r=je(e.path.startsWith("/")?e.path:`/${e.path}`),n=Be(e.ref),t=ze(n).versionType,i=ra(e.cacheRoot),o=e.resolveCommitShaFn??ot,s=e.fetchFileContentFn??lt,a=await o(e.org,e.project,e.repoId,n),l={org:e.org,project:e.project,repoId:e.repoId,repoName:e.repoName,path:r,requestedRef:e.ref,normalizedRef:n,refType:t,commitSha:a},c=na(l),f=ta(i,c),u=await ia(f);if(u)return{content:u.content,path:r,repoId:e.repoId,repoName:e.repoName,requestedRef:u.metadata.requestedRef,normalizedRef:u.metadata.normalizedRef,refType:u.metadata.refType,commitSha:u.metadata.commitSha,cache:"hit"};let p=await s(e.org,e.project,e.repoId,r,a),d={...l,fetchedAt:new Date().toISOString()};return await oa(f,d,p),{content:p,path:r,repoId:e.repoId,repoName:e.repoName,requestedRef:e.ref,normalizedRef:n,refType:t,commitSha:a,cache:"miss"}}var ve=new O;ve.get("/:org/:project/repos",async e=>{let{org:r,project:n}=e.req.param(),t=await at(r,n);return e.json(t)});ve.get("/:org/:project/repos/:repoId/file",async e=>{let{org:r,project:n,repoId:t}=e.req.param(),i=e.req.query("path"),o=e.req.query("branch");if(!i)return e.json({error:"path query parameter is required"},400);let s=await Cr(r,n,t),a=await xe({org:r,project:n,repoId:s.id,repoName:s.name,path:i,ref:o||s.defaultBranch});return e.json({content:a.content,path:a.path,repoId:a.repoId,repoName:a.repoName,branch:a.requestedRef,commitSha:a.commitSha,cache:a.cache})});ve.get("/:org/:project/file-by-repo-name",async e=>{let{org:r,project:n}=e.req.param(),t=e.req.query("repo"),i=e.req.query("path"),o=e.req.query("branch");if(!t||!i)return e.json({error:"repo and path query parameters are required"},400);let s=gn(r,n,t);if(s)try{let c=await ut(s,i);return e.json({content:c,path:i,repoId:t,repoName:t,branch:o||"local",commitSha:"local",cache:"local"})}catch{}let a=await Cr(r,n,t);if(!a)return e.json({error:`Repository not found: ${t}`},404);let l=await xe({org:r,project:n,repoId:a.id,repoName:a.name,path:i,ref:o||a.defaultBranch});return e.json({content:l.content,path:l.path,repoId:l.repoId,repoName:l.repoName,branch:l.requestedRef,commitSha:l.commitSha,cache:l.cache})});var Ae=new O;Ae.get("/:org/:project/pipelines",async e=>{let{org:r,project:n}=e.req.param(),t=await st(r,n);return e.json(t)});Ae.get("/:org/:project/pipelines/:id",async e=>{let{org:r,project:n,id:t}=e.req.param(),i=await wr(r,n,Number(t));return e.json(i)});Ae.get("/:org/:project/pipelines/:id/yaml",async e=>{let{org:r,project:n,id:t}=e.req.param(),i=await wr(r,n,Number(t)),o=await xe({org:r,project:n,repoId:i.repository.id,repoName:i.repository.name,path:i.path,ref:i.repository.defaultBranch});return e.json({definition:i,yaml:o.content,branch:o.requestedRef,commitSha:o.commitSha,cache:o.cache})});import{existsSync as mt,mkdirSync as sa,readFileSync as aa,statSync as la,writeFileSync as ca}from"node:fs";import{dirname as gt,resolve as ht}from"node:path";import{fileURLToPath as ua}from"node:url";var Er=new O,fa=1440*60*1e3;function yt(e){let r=ht(gt(ua(import.meta.url)),"..","..","..","..");return ht(r,".cache",`task-schema-${e.toLowerCase()}.json`)}function pa(e){let r=yt(e);if(!mt(r))return null;try{let n=la(r);return Date.now()-n.mtimeMs>fa?null:JSON.parse(aa(r,"utf-8"))}catch{return null}}function da(e,r){let n=yt(e),t=gt(n);mt(t)||sa(t,{recursive:!0}),ca(n,JSON.stringify(r,null,2))}function ha(e){let r=e.definitions;if(!r)return[];let i=r.task?.properties?.task?.anyOf;if(!i)return[];let o=[];for(let s of i){let a=s.enum;if(!a?.length)continue;let l=a[0],c=typeof s.description=="string"?s.description:"",f=l.lastIndexOf("@"),u,p;f>0?(u=l.slice(0,f),p=parseInt(l.slice(f+1),10),Number.isNaN(p)&&(p=0)):(u=l,p=0),o.push({name:u,description:c,version:p,inputs:[]})}return o}Er.get("/:org/schema/tasks",async e=>{let{org:r}=e.req.param(),n=pa(r);if(n)return e.json({tasks:n,cached:!0});let t=await He(),i=`https://dev.azure.com/${encodeURIComponent(r)}/_apis/distributedtask/yamlschema?api-version=7.1`,o=await fetch(i,{headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"}});if(!o.ok){let l=await o.text();return e.json({error:`Failed to fetch schema: ${o.status} ${l}`},o.status)}let s=await o.json(),a=ha(s);return da(r,a),console.log(`Cached ${a.length} task definitions for org "${r}"`),e.json({tasks:a,cached:!1})});var ya=ga(new URL(".",import.meta.url)),At=kr(ya,"web"),xa={".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 va(e){let r=ma(e);return xa[r]??"application/octet-stream"}Y();var S=new O;S.use("/*",dn());S.use("/*",un({origin:"*"}));S.get("/health",e=>e.json({status:"ok"}));S.get("/api/config/task-docs",e=>{let r=Y();return e.json({customTaskDocs:r.customTaskDocs??{}})});S.route("/api",Ae);S.route("/api",ve);S.route("/api",Er);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=kr(At,r);if(!xt(n))return e.notFound();let t=vt(n);return e.body(t,200,{"Content-Type":va(r),"Cache-Control":"public, immutable, max-age=31536000"})});S.get("*",e=>{let r=kr(At,"index.html");if(!xt(r))return e.notFound();let n=vt(r,"utf-8");return e.html(n)});var Aa=Number(process.env.PORT)||3001;$r({fetch:S.fetch,port:Aa},e=>{console.log(`APV server listening on http://localhost:${e.port}`)});export{S as app};
|
|
32
|
+
`+e.slice(s+1):l+=e.slice(i),l.slice(1)}function Ms(e){for(var r="",n=0,t,i=0;i<e.length;n>=65536?i+=2:i++)n=ye(e,i),t=C[n],!t&&be(n)?(r+=e[i],n>=65536&&(r+=e[i+1])):r+=t||Os(n);return r}function Hs(e,r,n){var t="",i=e.tag,o,s,a;for(o=0,s=n.length;o<s;o+=1)a=n[o],e.replacer&&(a=e.replacer.call(n,String(o),a)),(I(e,r,a,!1,!1)||typeof a>"u"&&I(e,r,null,!1,!1))&&(t!==""&&(t+=","+(e.condenseFlow?"":" ")),t+=e.dump);e.tag=i,e.dump="["+t+"]"}function Dn(e,r,n,t){var i="",o=e.tag,s,a,l;for(s=0,a=n.length;s<a;s+=1)l=n[s],e.replacer&&(l=e.replacer.call(n,String(s),l)),(I(e,r+1,l,!0,!0,!1,!0)||typeof l>"u"&&I(e,r+1,null,!0,!0,!1,!0))&&((!t||i!=="")&&(i+=vr(e,r)),e.dump&&ve===e.dump.charCodeAt(0)?i+="-":i+="- ",i+=e.dump);e.tag=o,e.dump=i||"[]"}function zs(e,r,n){var t="",i=e.tag,o=Object.keys(n),s,a,l,c,f;for(s=0,a=o.length;s<a;s+=1)f="",t!==""&&(f+=", "),e.condenseFlow&&(f+='"'),l=o[s],c=n[l],e.replacer&&(c=e.replacer.call(n,l,c)),I(e,r,l,!1,!1)&&(e.dump.length>1024&&(f+="? "),f+=e.dump+(e.condenseFlow?'"':"")+":"+(e.condenseFlow?"":" "),I(e,r,c,!1,!1)&&(f+=e.dump,t+=f));e.tag=i,e.dump="{"+t+"}"}function Bs(e,r,n,t){var i="",o=e.tag,s=Object.keys(n),a,l,c,f,u,p;if(e.sortKeys===!0)s.sort();else if(typeof e.sortKeys=="function")s.sort(e.sortKeys);else if(e.sortKeys)throw new E("sortKeys must be a boolean or a function");for(a=0,l=s.length;a<l;a+=1)p="",(!t||i!=="")&&(p+=vr(e,r)),c=s[a],f=n[c],e.replacer&&(f=e.replacer.call(n,c,f)),I(e,r+1,c,!0,!0,!0)&&(u=e.tag!==null&&e.tag!=="?"||e.dump&&e.dump.length>1024,u&&(e.dump&&ve===e.dump.charCodeAt(0)?p+="?":p+="? "),p+=e.dump,u&&(p+=vr(e,r)),I(e,r+1,f,!0,u)&&(e.dump&&ve===e.dump.charCodeAt(0)?p+=":":p+=": ",p+=e.dump,i+=p));e.tag=o,e.dump=i||"{}"}function $n(e,r,n){var t,i,o,s,a,l;for(i=n?e.explicitTypes:e.implicitTypes,o=0,s=i.length;o<s;o+=1)if(a=i[o],(a.instanceOf||a.predicate)&&(!a.instanceOf||typeof r=="object"&&r instanceof a.instanceOf)&&(!a.predicate||a.predicate(r))){if(n?a.multi&&a.representName?e.tag=a.representName(r):e.tag=a.tag:e.tag="?",a.represent){if(l=e.styleMap[a.tag]||a.defaultStyle,et.call(a.represent)==="[object Function]")t=a.represent(r,l);else if(rt.call(a.represent,l))t=a.represent[l](r,l);else throw new E("!<"+a.tag+'> tag resolver accepts not "'+l+'" style');e.dump=t}return!0}return!1}function I(e,r,n,t,i,o,s){e.tag=null,e.dump=n,$n(e,n,!1)||$n(e,n,!0);var a=et.call(e.dump),l=t,c;t&&(t=e.flowLevel<0||e.flowLevel>r);var f=a==="[object Object]"||a==="[object Array]",u,p;if(f&&(u=e.duplicates.indexOf(n),p=u!==-1),(e.tag!==null&&e.tag!=="?"||p||e.indent!==2&&r>0)&&(i=!1),p&&e.usedDuplicates[u])e.dump="*ref_"+u;else{if(f&&p&&!e.usedDuplicates[u]&&(e.usedDuplicates[u]=!0),a==="[object Object]")t&&Object.keys(e.dump).length!==0?(Bs(e,r,e.dump,i),p&&(e.dump="&ref_"+u+e.dump)):(zs(e,r,e.dump),p&&(e.dump="&ref_"+u+" "+e.dump));else if(a==="[object Array]")t&&e.dump.length!==0?(e.noArrayIndent&&!s&&r>0?Dn(e,r-1,e.dump,i):Dn(e,r,e.dump,i),p&&(e.dump="&ref_"+u+e.dump)):(Hs(e,r,e.dump),p&&(e.dump="&ref_"+u+" "+e.dump));else if(a==="[object String]")e.tag!=="?"&&Ds(e,e.dump,r,o,l);else{if(a==="[object Undefined]")return!1;if(e.skipInvalid)return!1;throw new E("unacceptable kind of an object to dump "+a)}e.tag!==null&&e.tag!=="?"&&(c=encodeURI(e.tag[0]==="!"?e.tag.slice(1):e.tag).replace(/!/g,"%21"),e.tag[0]==="!"?c="!"+c:c.slice(0,18)==="tag:yaml.org,2002:"?c="!!"+c.slice(18):c="!<"+c+">",e.dump=c+" "+e.dump)}return!0}function Us(e,r){var n=[],t=[],i,o;for(br(e,n,t),i=0,o=t.length;i<o;i+=1)r.duplicates.push(n[t[i]]);r.usedDuplicates=new Array(o)}function br(e,r,n){var t,i,o;if(e!==null&&typeof e=="object")if(i=r.indexOf(e),i!==-1)n.indexOf(i)===-1&&n.push(i);else if(r.push(e),Array.isArray(e))for(i=0,o=e.length;i<o;i+=1)br(e[i],r,n);else for(t=Object.keys(e),i=0,o=t.length;i<o;i+=1)br(e[t[i]],r,n)}function qs(e,r){r=r||{};var n=new _s(r);n.noRefs||Us(e,n);var t=e;return n.replacer&&(t=n.replacer.call({"":t},"",t)),I(n,0,t,!0,!0)?n.dump+`
|
|
33
|
+
`:""}var Ws=qs,Gs={dump:Ws};function kr(e,r){return function(){throw new Error("Function yaml."+e+" is removed in js-yaml 4. Use yaml."+r+" instead, which is now safe by default.")}}var _c=Xn.load,Fc=Xn.loadAll,jc=Gs.dump;var Nc=kr("safeLoad","load"),Lc=kr("safeLoadAll","loadAll"),Dc=kr("safeDump","dump");import{DefaultAzureCredential as Qs}from"@azure/identity";var Xs="499b84ac-1321-427f-aa17-267ca6975798/.default",Sr=null;function ea(){return Sr||(Sr=new Qs),Sr}async function ee(){return(await ea().getToken(Xs)).token}var we=class{store=new Map;ttlMs;maxSize;constructor(r,n=1e3){this.ttlMs=r*1e3,this.maxSize=n}get(r){let n=this.store.get(r);if(n){if(Date.now()>n.expiresAt){this.store.delete(r);return}return n.value}}set(r,n){if(this.store.size>=this.maxSize&&!this.store.has(r)){let t=this.store.keys().next().value;t!==void 0&&this.store.delete(t)}this.store.set(r,{value:n,expiresAt:Date.now()+this.ttlMs})}async getOrFetch(r,n){let t=this.get(r);if(t!==void 0)return t;let i=await n();return this.set(r,i),i}get size(){return this.store.size}clear(){this.store.clear()}};var re="7.1",ra=new we(600),na=new we(120),ta=/^[0-9a-f]{7,40}$/i;async function ne(e){let r=await ee(),n=await fetch(e,{headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json"}});if(!n.ok){let t=await n.text();throw new Error(`Azure DevOps API error (${n.status}): ${t}`)}return n}function te(e,r){return`https://dev.azure.com/${encodeURIComponent(e)}/${encodeURIComponent(r)}/_apis`}function ie(e){return e.startsWith("refs/")||ta.test(e)?e:`refs/heads/${e}`}function oe(e){let r=ie(e);return r.startsWith("refs/heads/")?{version:r.slice(11),versionType:"branch"}:r.startsWith("refs/tags/")?{version:r.slice(10),versionType:"tag"}:{version:r,versionType:"commit"}}async function qe(e,r,n,t){let i=ie(t),o=oe(i);if(o.versionType==="commit")return o.version;let s=`${e}/${r}/${n}/${i}`.toLowerCase();return na.getOrFetch(s,async()=>{let a=i.replace(/^refs\//,""),l=`${te(e,r)}/git/repositories/${encodeURIComponent(n)}/refs?filter=${encodeURIComponent(a)}&api-version=${re}`,u=(await(await ne(l)).json()).value?.find(p=>p.name===i);if(!u?.objectId)throw new Error(`Git ref not found: ${i}`);return u.objectId})}async function pt(e,r){let n=`${te(e,r)}/pipelines?api-version=${re}`;return(await(await ne(n)).json()).value}async function Tr(e,r,n){let t=`${te(e,r)}/build/definitions/${n}?api-version=${re}`,o=await(await ne(t)).json();return{id:o.id,name:o.name,path:o.process?.yamlFilename??o.path,repository:{id:o.repository?.id,name:o.repository?.name,type:o.repository?.type,defaultBranch:o.repository?.defaultBranch}}}async function dt(e,r){let n=`${te(e,r)}/git/repositories?api-version=${re}`;return(await(await ne(n)).json()).value}async function We(e,r,n){let t=`${e}/${r}/${n}`.toLowerCase();return ra.getOrFetch(t,async()=>{let i=`${te(e,r)}/git/repositories/${encodeURIComponent(n)}?api-version=${re}`;return(await ne(i)).json()})}async function ht(e,r,n,t,i){let o=t.startsWith("/")?t:`/${t}`,s=De(o),a=`${te(e,r)}/git/repositories/${encodeURIComponent(n)}/items?scopePath=${encodeURIComponent(s)}&api-version=${re}&$format=text`;if(i){let c=oe(i);a+=`&versionDescriptor.version=${encodeURIComponent(c.version)}&versionDescriptor.versionType=${c.versionType}`}return(await ne(a)).text()}import{existsSync as ia}from"node:fs";import{readFile as oa}from"node:fs/promises";import{join as sa,normalize as mt}from"node:path";async function gt(e,r){let n=r.replace(/\\/g,"/").replace(/^\/+/,""),t=mt(sa(e,n)),i=mt(e);if(!t.startsWith(i))throw new Error(`Path traversal attempt: ${r}`);if(!ia(t))throw new Error(`File not found locally: ${t}`);return oa(t,"utf-8")}import{createHash as aa}from"node:crypto";import{existsSync as yt}from"node:fs";import{mkdir as la,readFile as xt,writeFile as vt}from"node:fs/promises";import{dirname as ca,resolve as se}from"node:path";import{fileURLToPath as ua}from"node:url";function fa(e){if(e)return se(e);let r=F().cacheDir;return r?se(r):se(ca(ua(import.meta.url)),"..","..","..",".cache","ado-file-cache")}function pa(e){return aa("sha256").update(JSON.stringify(e)).digest("hex")}function da(e,r){let n=se(e,r.slice(0,2),r.slice(2,4),r);return{dir:n,metadataPath:se(n,"metadata.json"),contentPath:se(n,"content.txt")}}async function ha(e){if(!yt(e.metadataPath)||!yt(e.contentPath))return null;let[r,n]=await Promise.all([xt(e.metadataPath,"utf-8"),xt(e.contentPath,"utf-8")]);return{metadata:JSON.parse(r),content:n}}async function ma(e,r,n){await la(e.dir,{recursive:!0}),await Promise.all([vt(e.metadataPath,JSON.stringify(r,null,2),"utf-8"),vt(e.contentPath,n,"utf-8")])}async function Re(e){let r=De(e.path.startsWith("/")?e.path:`/${e.path}`),n=ie(e.ref),t=oe(n).versionType,i=fa(e.cacheRoot),o=e.resolveCommitShaFn??qe,s=e.fetchFileContentFn??ht,a=await o(e.org,e.project,e.repoId,n),l={org:e.org,project:e.project,repoId:e.repoId,repoName:e.repoName,path:r,requestedRef:e.ref,normalizedRef:n,refType:t,commitSha:a},c=pa(l),f=da(i,c),u=await ha(f);if(u)return{content:u.content,path:r,repoId:e.repoId,repoName:e.repoName,requestedRef:u.metadata.requestedRef,normalizedRef:u.metadata.normalizedRef,refType:u.metadata.refType,commitSha:u.metadata.commitSha,cache:"hit"};let p=await s(e.org,e.project,e.repoId,r,a),d={...l,fetchedAt:new Date().toISOString()};return await ma(f,d,p),{content:p,path:r,repoId:e.repoId,repoName:e.repoName,requestedRef:e.ref,normalizedRef:n,refType:t,commitSha:a,cache:"miss"}}import{existsSync as Ke}from"node:fs";import{mkdir as ga,readdir as ya,readFile as bt,writeFile as Pr}from"node:fs/promises";import{dirname as xa,join as U,normalize as At,resolve as Ge}from"node:path";import{fileURLToPath as va}from"node:url";var Aa="7.1";async function ba(e,r,n,t){let i=await ee(),o=oe(t),s=`https://dev.azure.com/${encodeURIComponent(e)}/${encodeURIComponent(r)}/_apis/git/repositories/${encodeURIComponent(n)}/items?scopePath=/&download=true&$format=zip&versionDescriptor.version=${encodeURIComponent(o.version)}&versionDescriptor.versionType=${o.versionType}&api-version=${Aa}`,a=await fetch(s,{headers:{Authorization:`Bearer ${i}`}});if(!a.ok){let l=await a.text();throw new Error(`Failed to download repo ZIP (${a.status}): ${l}`)}return Buffer.from(await a.arrayBuffer())}function wa(e){if(e)return Ge(e);let r=F().cacheDir;return r?Ge(r,"..","ado-zip-cache"):Ge(xa(va(import.meta.url)),"..","..","..",".cache","ado-zip-cache")}function wt(e,r,n,t,i){return Ge(e,r.toLowerCase(),n.toLowerCase(),t.toLowerCase(),i.toLowerCase())}function Ra(e,r,n,t,i){let o=wt(e,r,n,t,i);return Ke(U(o,".zip-cache-complete"))}async function Ca(e,r){await ga(r,{recursive:!0});let n=U(r,"__repo.zip");if(await Pr(n,e),await Bun.spawn(["tar","-xf",n,"-C",r],{stdout:"pipe",stderr:"pipe"}).exited!==0)if(process.platform==="win32"){let s=Bun.spawn(["powershell","-NoProfile","-Command",`Expand-Archive -Path '${n}' -DestinationPath '${r}' -Force`],{stdout:"pipe",stderr:"pipe"});if(await s.exited!==0){let l=await new Response(s.stderr).text();throw new Error(`Failed to extract ZIP: ${l}`)}}else{let s=Bun.spawn(["unzip","-o",n,"-d",r],{stdout:"pipe",stderr:"pipe"});if(await s.exited!==0){let l=await new Response(s.stderr).text();throw new Error(`Failed to extract ZIP: ${l}`)}}await Pr(U(r,".zip-cache-complete"),"","utf-8")}async function Rt(e){let r=await ya(e,{withFileTypes:!0}),n=r.filter(i=>i.isDirectory()&&i.name!=="__MACOSX"&&!i.name.startsWith(".")),t=r.filter(i=>i.isFile()&&i.name!=="__repo.zip"&&i.name!==".zip-cache-complete");return n.length===1&&t.length===0?U(e,n[0].name):e}async function Ea(e){let r=U(e,".zip-cache-root");if(Ke(r)){let n=(await bt(r,"utf-8")).trim();if(n&&Ke(n))return n}return Rt(e)}async function Or(e){let r=wa(e.cacheRoot),n=ie(e.ref),t=e.resolveCommitShaFn??qe,i=e.downloadZipFn??ba,o=await t(e.org,e.project,e.repoId,n),s=wt(r,e.org,e.project,e.repoId,o);if(Ra(r,e.org,e.project,e.repoId,o))return{repoDir:await Ea(s),commitSha:o,cache:"hit"};let a=await i(e.org,e.project,e.repoId,n);await(e.extractZipFn??Ca)(a,s);let c=await Rt(s);return await Pr(U(s,".zip-cache-root"),c,"utf-8"),{repoDir:c,commitSha:o,cache:"miss"}}async function Ir(e){let{repoDir:r,commitSha:n,cache:t}=await Or(e),i=e.path.replace(/\\/g,"/").replace(/^\/+/,""),o=At(U(r,i)),s=At(r);if(!o.startsWith(s))throw new Error(`Path traversal attempt: ${e.path}`);if(!Ke(o))throw new Error(`File not found in cached repo: ${i}`);return{content:await bt(o,"utf-8"),cache:t,commitSha:n}}var ae=new O;ae.get("/:org/:project/repos",async e=>{let{org:r,project:n}=e.req.param(),t=await dt(r,n);return e.json(t)});ae.get("/:org/:project/repos/:repoId/file",async e=>{let{org:r,project:n,repoId:t}=e.req.param(),i=e.req.query("path"),o=e.req.query("branch");if(!i)return e.json({error:"path query parameter is required"},400);let s=await We(r,n,t),a=o||s.defaultBranch;try{let c=await Ir({org:r,project:n,repoId:s.id,path:i,ref:a});return e.json({content:c.content,path:i,repoId:s.id,repoName:s.name,branch:a,commitSha:c.commitSha,cache:`zip-${c.cache}`})}catch{}let l=await Re({org:r,project:n,repoId:s.id,repoName:s.name,path:i,ref:a});return e.json({content:l.content,path:l.path,repoId:l.repoId,repoName:l.repoName,branch:l.requestedRef,commitSha:l.commitSha,cache:l.cache})});ae.get("/:org/:project/file-by-repo-name",async e=>{let{org:r,project:n}=e.req.param(),t=e.req.query("repo"),i=e.req.query("path"),o=e.req.query("branch");if(!t||!i)return e.json({error:"repo and path query parameters are required"},400);let s=Rn(r,n,t);if(s)try{let f=await gt(s,i);return e.json({content:f,path:i,repoId:t,repoName:t,branch:o||"local",commitSha:"local",cache:"local"})}catch{}let a=await We(r,n,t);if(!a)return e.json({error:`Repository not found: ${t}`},404);let l=o||a.defaultBranch;try{let f=await Ir({org:r,project:n,repoId:a.id,path:i,ref:l});return e.json({content:f.content,path:i,repoId:a.id,repoName:a.name,branch:l,commitSha:f.commitSha,cache:`zip-${f.cache}`})}catch{}let c=await Re({org:r,project:n,repoId:a.id,repoName:a.name,path:i,ref:l});return e.json({content:c.content,path:c.path,repoId:c.repoId,repoName:c.repoName,branch:c.requestedRef,commitSha:c.commitSha,cache:c.cache})});ae.post("/:org/:project/repos/:repoId/cache",async e=>{let{org:r,project:n,repoId:t}=e.req.param(),i=e.req.query("branch"),o=await We(r,n,t),s=i||o.defaultBranch,a=await Or({org:r,project:n,repoId:o.id,ref:s});return e.json({repoId:o.id,repoName:o.name,branch:s,commitSha:a.commitSha,cache:a.cache})});var Ce=new O;Ce.get("/:org/:project/pipelines",async e=>{let{org:r,project:n}=e.req.param(),t=await pt(r,n);return e.json(t)});Ce.get("/:org/:project/pipelines/:id",async e=>{let{org:r,project:n,id:t}=e.req.param(),i=await Tr(r,n,Number(t));return e.json(i)});Ce.get("/:org/:project/pipelines/:id/yaml",async e=>{let{org:r,project:n,id:t}=e.req.param(),i=await Tr(r,n,Number(t)),o=await Re({org:r,project:n,repoId:i.repository.id,repoName:i.repository.name,path:i.path,ref:i.repository.defaultBranch});return e.json({definition:i,yaml:o.content,branch:o.requestedRef,commitSha:o.commitSha,cache:o.cache})});import{existsSync as Et,mkdirSync as ka,readFileSync as Sa,statSync as Ta,writeFileSync as Pa}from"node:fs";import{dirname as kt,resolve as Ct}from"node:path";import{fileURLToPath as Oa}from"node:url";var _r=new O,Ia=1440*60*1e3;function St(e){let r=Ct(kt(Oa(import.meta.url)),"..","..","..","..");return Ct(r,".cache",`task-schema-${e.toLowerCase()}.json`)}function _a(e){let r=St(e);if(!Et(r))return null;try{let n=Ta(r);return Date.now()-n.mtimeMs>Ia?null:JSON.parse(Sa(r,"utf-8"))}catch{return null}}function Fa(e,r){let n=St(e),t=kt(n);Et(t)||ka(t,{recursive:!0}),Pa(n,JSON.stringify(r,null,2))}function ja(e){let r=e.definitions;if(!r)return[];let i=r.task?.properties?.task?.anyOf;if(!i)return[];let o=[];for(let s of i){let a=s.enum;if(!a?.length)continue;let l=a[0],c=typeof s.description=="string"?s.description:"",f=l.lastIndexOf("@"),u,p;f>0?(u=l.slice(0,f),p=parseInt(l.slice(f+1),10),Number.isNaN(p)&&(p=0)):(u=l,p=0),o.push({name:u,description:c,version:p,inputs:[]})}return o}_r.get("/:org/schema/tasks",async e=>{let{org:r}=e.req.param(),n=_a(r);if(n)return e.json({tasks:n,cached:!0});let t=await ee(),i=`https://dev.azure.com/${encodeURIComponent(r)}/_apis/distributedtask/yamlschema?api-version=7.1`,o=await fetch(i,{headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"}});if(!o.ok){let l=await o.text();return e.json({error:`Failed to fetch schema: ${o.status} ${l}`},o.status)}let s=await o.json(),a=ja(s);return Fa(r,a),console.log(`Cached ${a.length} task definitions for org "${r}"`),e.json({tasks:a,cached:!1})});var Da=La(new URL(".",import.meta.url)),Ot=Fr(Da,"web"),$a={".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 Ma(e){let r=Na(e);return $a[r]??"application/octet-stream"}F();var S=new O;S.use("/*",An());S.use("/*",yn({origin:"*"}));S.get("/health",e=>e.json({status:"ok"}));S.get("/api/config/task-docs",e=>{let r=F();return e.json({customTaskDocs:r.customTaskDocs??{}})});S.route("/api",Ce);S.route("/api",ae);S.route("/api",_r);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=Fr(Ot,r);if(!Tt(n))return e.notFound();let t=Pt(n);return e.body(t,200,{"Content-Type":Ma(r),"Cache-Control":"public, immutable, max-age=31536000"})});S.get("*",e=>{let r=Fr(Ot,"index.html");if(!Tt(r))return e.notFound();let n=Pt(r,"utf-8");return e.html(n)});var Ha=Number(process.env.PORT)||3001;Gr({fetch:S.fetch,port:Ha},e=>{console.log(`APV server listening on http://localhost:${e.port}`)});export{S as app};
|
|
34
34
|
/*! Bundled license information:
|
|
35
35
|
|
|
36
36
|
js-yaml/dist/js-yaml.mjs:
|