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