@shopify/cli
Version:
A CLI tool to build for the Shopify platform
8 lines (7 loc) • 28.5 kB
JavaScript
import{g as h}from"./chunk-VPRTJUIN.js";h();h();var Lt=String.fromCharCode;var Y=/\+/g;var Ce=/%2f/gi;function b(e=""){try{return decodeURIComponent(""+e)}catch{return""+e}}function L(e){return b(e.replace(Ce,"%252F"))}function Ae(e){return b(e.replace(Y," "))}function Se(e){return b(e.replace(Y," "))}function xe(e=""){let t=Object.create(null);e[0]==="?"&&(e=e.slice(1));for(let r of e.split("&")){let n=r.match(/([^=]+)=?(.*)/)||[];if(n.length<2)continue;let o=Ae(n[1]);if(o==="__proto__"||o==="constructor")continue;let s=Se(n[2]||"");t[o]===void 0?t[o]=s:Array.isArray(t[o])?t[o].push(s):t[o]=[t[o],s]}return t}var He=/^[\s\w\0+.-]{2,}:([/\\]{1,2})/,Pe=/^[\s\w\0+.-]{2,}:([/\\]{2})?/,Ne=/^([/\\]\s*){2,}[^/\\]/;var Oe=/\/$|\/\?|\/#/,Te=/^\.?\//;function Me(e,t={}){return typeof t=="boolean"&&(t={acceptRelative:t}),t.strict?He.test(e):Pe.test(e)||(t.acceptRelative?Ne.test(e):!1)}function q(e="",t){return t?Oe.test(e):e.endsWith("/")}function k(e="",t){if(!t)return(q(e)?e.slice(0,-1):e)||"/";if(!q(e,!0))return e||"/";let r=e,n="",o=e.indexOf("#");o!==-1&&(r=e.slice(0,o),n=e.slice(o));let[s,...a]=r.split("?");return((s.endsWith("/")?s.slice(0,-1):s)||"/")+(a.length>0?`?${a.join("?")}`:"")+n}function qe(e="",t){if(!t)return e.endsWith("/")?e:e+"/";if(q(e,!0))return e||"/";let r=e,n="",o=e.indexOf("#");if(o!==-1&&(r=e.slice(0,o),n=e.slice(o),!r))return n;let[s,...a]=r.split("?");return s+"/"+(a.length>0?`?${a.join("?")}`:"")+n}function Le(e=""){return e.startsWith("/")}function I(e=""){return Le(e)?e:"/"+e}function X(e){return xe(C(e).search)}function ke(e){return e&&e!=="/"}function Z(e,...t){let r=e||"";for(let n of t.filter(o=>ke(o)))if(r){let o=n.replace(Te,"");r=qe(r)+o}else r=n;return r}var Ie=Symbol.for("ufo:protocolRelative");function C(e="",t){let r=e.match(/^[\s\0]*(blob:|data:|javascript:|vbscript:)(.*)/i);if(r){let[,d,l=""]=r;return{protocol:d.toLowerCase(),pathname:l,href:d+l,auth:"",host:"",search:"",hash:""}}if(!Me(e,{acceptRelative:!0}))return t?C(t+e):K(e);let[,n="",o,s=""]=e.replace(/\\/g,"/").match(/^[\s\0]*([\w+.-]{2,}:)?\/\/([^/@]+@)?(.*)/)||[],[,a="",u=""]=s.match(/([^#/?]*)(.*)?/)||[];n==="file:"&&(u=u.replace(/\/(?=[A-Za-z]:)/,""));let{pathname:c,search:i,hash:f}=K(u);return{protocol:n.toLowerCase(),auth:o?o.slice(0,Math.max(0,o.length-1)):"",host:a,pathname:c,search:i,hash:f,[Ie]:!n}}function K(e=""){let[t="",r="",n=""]=(e.match(/([^#?]*)(\?[^#]*)?(#.*)?/)||[]).splice(1);return{pathname:t,search:r,hash:n}}h();function v(e,t){if(typeof e!="string")throw new TypeError("argument str must be a string");let r={},n=t||{},o=n.decode||je,s=0;for(;s<e.length;){let a=e.indexOf("=",s);if(a===-1)break;let u=e.indexOf(";",s);if(u===-1)u=e.length;else if(u<a){s=e.lastIndexOf(";",a-1)+1;continue}let c=e.slice(s,a).trim();if(n?.filter&&!n?.filter(c)){s=u+1;continue}if(r[c]===void 0){let i=e.slice(a+1,u).trim();i.codePointAt(0)===34&&(i=i.slice(1,-1)),r[c]=De(i,o)}s=u+1}return r}function je(e){return e.includes("%")?decodeURIComponent(e):e}function De(e,t){try{return t(e)}catch{return e}}h();var y={NORMAL:0,WILDCARD:1,PLACEHOLDER:2};function re(e={}){let t={options:e,rootNode:ne(),staticRoutesMap:{}},r=n=>e.strictTrailingSlash?n:n.replace(/\/$/,"")||"/";if(e.routes)for(let n in e.routes)ee(t,r(n),e.routes[n]);return{ctx:t,lookup:n=>Be(t,r(n)),insert:(n,o)=>ee(t,r(n),o),remove:n=>Fe(t,r(n))}}function Be(e,t){let r=e.staticRoutesMap[t];if(r)return r.data;let n=t.split("/"),o={},s=!1,a=null,u=e.rootNode,c=null;for(let i=0;i<n.length;i++){let f=n[i];u.wildcardChildNode!==null&&(a=u.wildcardChildNode,c=n.slice(i).join("/"));let d=u.children.get(f);if(d===void 0){if(u&&u.placeholderChildren.length>1){let l=n.length-i;u=u.placeholderChildren.find(M=>M.maxDepth===l)||null}else u=u.placeholderChildren[0]||null;if(!u)break;u.paramName&&(o[u.paramName]=f),s=!0}else u=d}return(u===null||u.data===null)&&a!==null&&(u=a,o[u.paramName||"_"]=c,s=!0),u?s?{...u.data,params:s?o:void 0}:u.data:null}function ee(e,t,r){let n=!0,o=t.split("/"),s=e.rootNode,a=0,u=[s];for(let c of o){let i;if(i=s.children.get(c))s=i;else{let f=Ue(c);i=ne({type:f,parent:s}),s.children.set(c,i),f===y.PLACEHOLDER?(i.paramName=c==="*"?`_${a++}`:c.slice(1),s.placeholderChildren.push(i),n=!1):f===y.WILDCARD&&(s.wildcardChildNode=i,i.paramName=c.slice(3)||"_",n=!1),u.push(i),s=i}}for(let[c,i]of u.entries())i.maxDepth=Math.max(u.length-c,i.maxDepth||0);return s.data=r,n===!0&&(e.staticRoutesMap[t]=s),s}function Fe(e,t){let r=!1,n=t.split("/"),o=e.rootNode;for(let s of n)if(o=o.children.get(s),!o)return r;if(o.data){let s=n.at(-1)||"";o.data=null,Object.keys(o.children).length===0&&o.parent&&(o.parent.children.delete(s),o.parent.wildcardChildNode=null,o.parent.placeholderChildren=[]),r=!0}return r}function ne(e={}){return{type:e.type||y.NORMAL,maxDepth:0,parent:e.parent||null,children:new Map,data:e.data||null,paramName:e.paramName||null,wildcardChildNode:null,placeholderChildren:[]}}function Ue(e){return e.startsWith("**")?y.WILDCARD:e[0]===":"||e==="*"?y.PLACEHOLDER:y.NORMAL}function oe(e){let t=ae("",e.ctx.rootNode);return $e(t,e.ctx.options.strictTrailingSlash)}function $e(e,t){return{ctx:{table:e},matchAll:r=>se(r,e,t)}}function We(){return{static:new Map,wildcard:new Map,dynamic:new Map}}function se(e,t,r){r!==!0&&e.endsWith("/")&&(e=e.slice(0,-1)||"/");let n=[];for(let[s,a]of te(t.wildcard))(e===s||e.startsWith(s+"/"))&&n.push(a);for(let[s,a]of te(t.dynamic))if(e.startsWith(s+"/")){let u="/"+e.slice(s.length).split("/").splice(2).join("/");n.push(...se(u,a))}let o=t.static.get(e);return o&&n.push(o),n.filter(Boolean)}function te(e){return[...e.entries()].sort((t,r)=>t[0].length-r[0].length)}function ae(e,t){let r=We();function n(o,s){if(o){if(s.type===y.NORMAL&&!(o.includes("*")||o.includes(":")))s.data&&r.static.set(o,s.data);else if(s.type===y.WILDCARD)r.wildcard.set(o.replace("/**",""),s.data);else if(s.type===y.PLACEHOLDER){let a=ae("",s);s.data&&a.static.set("/",s.data),r.dynamic.set(o.replace(/\/\*|\/:\w+/,""),a);return}}for(let[a,u]of s.children.entries())n(`${o}/${a}`.replace("//","/"),u)}return n(e,t),r}h();function j(e){if(e===null||typeof e!="object")return!1;let t=Object.getPrototypeOf(e);return t!==null&&t!==Object.prototype&&Object.getPrototypeOf(t)!==null||Symbol.iterator in e?!1:Symbol.toStringTag in e?Object.prototype.toString.call(e)==="[object Module]":!0}function D(e,t,r=".",n){if(!j(t))return D(e,{},r,n);let o=Object.assign({},t);for(let s in e){if(s==="__proto__"||s==="constructor")continue;let a=e[s];a!=null&&(n&&n(o,s,a,r)||(Array.isArray(a)&&Array.isArray(o[s])?o[s]=[...a,...o[s]]:j(a)&&j(o[s])?o[s]=D(a,o[s],(r?`${r}.`:"")+s.toString(),n):o[s]=a))}return o}function B(e){return(...t)=>t.reduce((r,n)=>D(r,n,"",e),{})}var ie=B(),Ut=B((e,t,r)=>{if(e[t]!==void 0&&typeof r=="function")return e[t]=r(e[t]),!0}),$t=B((e,t,r)=>{if(Array.isArray(e[t])&&typeof r=="function")return e[t]=r(e[t]),!0});h();var ze=/"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/,Je=/"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/,Qe=/^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;function Ve(e,t){if(e==="__proto__"||e==="constructor"&&t&&typeof t=="object"&&"prototype"in t){Ge(e);return}return t}function Ge(e){console.warn(`[destr] Dropping "${e}" key to prevent prototype pollution.`)}function ce(e,t={}){if(typeof e!="string")return e;if(e[0]==='"'&&e[e.length-1]==='"'&&e.indexOf("\\")===-1)return e.slice(1,-1);let r=e.trim();if(r.length<=9)switch(r.toLowerCase()){case"true":return!0;case"false":return!1;case"undefined":return;case"null":return null;case"nan":return Number.NaN;case"infinity":return Number.POSITIVE_INFINITY;case"-infinity":return Number.NEGATIVE_INFINITY}if(!Qe.test(e)){if(t.strict)throw new SyntaxError("[destr] Invalid JSON");return e}try{if(ze.test(e)||Je.test(e)){if(t.strict)throw new Error("[destr] Possible prototype pollution");return JSON.parse(e,Ve)}return JSON.parse(e)}catch(n){if(t.strict)throw n;return e}}function E(e,t){try{return t in e}catch{return!1}}var N=class extends Error{static __h3_error__=!0;statusCode=500;fatal=!1;unhandled=!1;statusMessage;data;cause;constructor(t,r={}){super(t,r),r.cause&&!this.cause&&(this.cause=r.cause)}toJSON(){let t={message:this.message,statusCode:_(this.statusCode,500)};return this.statusMessage&&(t.statusMessage=O(this.statusMessage)),this.data!==void 0&&(t.data=this.data),t}};function p(e){if(typeof e=="string")return new N(e);if(Q(e))return e;let t=new N(e.message??e.statusMessage??"",{cause:e.cause||e});if(E(e,"stack"))try{Object.defineProperty(t,"stack",{get(){return e.stack}})}catch{try{t.stack=e.stack}catch{}}if(e.data&&(t.data=e.data),e.statusCode?t.statusCode=_(e.statusCode,t.statusCode):e.status&&(t.statusCode=_(e.status,t.statusCode)),e.statusMessage?t.statusMessage=e.statusMessage:e.statusText&&(t.statusMessage=e.statusText),t.statusMessage){let r=t.statusMessage;O(t.statusMessage)!==r&&console.warn("[h3] Please prefer using `message` for longer error messages instead of `statusMessage`. In the future, `statusMessage` will be sanitized by default.")}return e.fatal!==void 0&&(t.fatal=e.fatal),e.unhandled!==void 0&&(t.unhandled=e.unhandled),t}function Ke(e,t,r){if(e.handled)return;let n=Q(t)?t:p(t),o={statusCode:n.statusCode,statusMessage:n.statusMessage,stack:[],data:n.data};if(r&&(o.stack=(n.stack||"").split(`
`).map(a=>a.trim())),e.handled)return;let s=Number.parseInt(n.statusCode);x(e,s,n.statusMessage),e.node.res.setHeader("content-type",S.json),e.node.res.end(JSON.stringify(o,void 0,2))}function Q(e){return e?.constructor?.__h3_error__===!0}function tr(e){return X(e.path||"")}function rr(e,t={}){let r=e.context.params||{};if(t.decode){r={...r};for(let n in r)r[n]=b(r[n])}return r}function Ye(e,t,r){if(r&&e.method==="HEAD")return!0;if(typeof t=="string"){if(e.method===t)return!0}else if(t.includes(e.method))return!0;return!1}function Xe(e,t,r){if(!Ye(e,t,r))throw p({statusCode:405,statusMessage:"HTTP method is not allowed."})}function he(e){let t={};for(let r in e.node.req.headers){let n=e.node.req.headers[r];t[r]=Array.isArray(n)?n.filter(Boolean).join(", "):n}return t}function g(e,t){return he(e)[t.toLowerCase()]}var ue=g;function nr(e,t={}){if(e.context.clientAddress)return e.context.clientAddress;if(t.xForwardedFor){let r=g(e,"x-forwarded-for")?.split(",").shift()?.trim();if(r)return r}if(e.node.req.socket.remoteAddress)return e.node.req.socket.remoteAddress}var $=Symbol.for("h3RawBody"),F=Symbol.for("h3ParsedBody"),pe=["PATCH","POST","PUT","DELETE"];function me(e,t="utf8"){Xe(e,pe);let r=e._requestBody||e.web?.request?.body||e.node.req[$]||e.node.req.rawBody||e.node.req.body;if(r){let s=Promise.resolve(r).then(a=>Buffer.isBuffer(a)?a:typeof a.pipeTo=="function"?new Promise((u,c)=>{let i=[];a.pipeTo(new WritableStream({write(f){i.push(f)},close(){u(Buffer.concat(i))},abort(f){c(f)}})).catch(c)}):typeof a.pipe=="function"?new Promise((u,c)=>{let i=[];a.on("data",f=>{i.push(f)}).on("end",()=>{u(Buffer.concat(i))}).on("error",c)}):a.constructor===Object?Buffer.from(JSON.stringify(a)):a instanceof URLSearchParams?Buffer.from(a.toString()):a instanceof FormData?new Response(a).bytes().then(u=>Buffer.from(u)):Buffer.from(a));return t?s.then(a=>a.toString(t)):s}if(!Number.parseInt(e.node.req.headers["content-length"]||"")&&!/\bchunked\b/i.test(String(e.node.req.headers["transfer-encoding"]??"")))return Promise.resolve(void 0);let n=e.node.req[$]=new Promise((s,a)=>{let u=[];e.node.req.on("error",c=>{a(c)}).on("data",c=>{u.push(c)}).on("end",()=>{s(Buffer.concat(u))})});return t?n.then(s=>s.toString(t)):n}async function or(e,t={}){let r=e.node.req;if(E(r,F))return r[F];let n=r.headers["content-type"]||"",o=await me(e),s;return n==="application/json"?s=fe(o,t.strict??!0):n.startsWith("application/x-www-form-urlencoded")?s=Ze(o):n.startsWith("text/")?s=o:s=fe(o,t.strict??!1),r[F]=s,s}function sr(e){if(!pe.includes(e.method))return;let t=e.web?.request?.body||e._requestBody;return t||($ in e.node.req||"rawBody"in e.node.req||"body"in e.node.req||"__unenv__"in e.node.req?new ReadableStream({async start(n){let o=await me(e,!1);o&&n.enqueue(o),n.close()}}):new ReadableStream({start:n=>{e.node.req.on("data",o=>{n.enqueue(o)}),e.node.req.on("end",()=>{n.close()}),e.node.req.on("error",o=>{n.error(o)})}}))}function fe(e="",t){if(e)try{return ce(e,{strict:t})}catch{throw p({statusCode:400,statusMessage:"Bad Request",message:"Invalid JSON body"})}}function Ze(e){let t=new URLSearchParams(e),r=Object.create(null);for(let[n,o]of t.entries())E(r,n)?(Array.isArray(r[n])||(r[n]=[r[n]]),r[n].push(o)):r[n]=o;return r}var S={html:"text/html",json:"application/json"},ve=/[^\u0009\u0020-\u007E]/g;function O(e=""){return e.replace(ve,"")}function _(e,t=200){return!e||(typeof e=="string"&&(e=Number.parseInt(e,10)),e<100||e>999)?t:e}function et(e){return v(e.node.req.headers.cookie||"")}function ar(e,t){return et(e)[t]}function ye(e){if(Array.isArray(e))return e.flatMap(f=>ye(f));if(typeof e!="string")return[];let t=[],r=0,n,o,s,a,u,c=()=>{for(;r<e.length&&/\s/.test(e.charAt(r));)r+=1;return r<e.length},i=()=>(o=e.charAt(r),o!=="="&&o!==";"&&o!==",");for(;r<e.length;){for(n=r,u=!1;c();)if(o=e.charAt(r),o===","){for(s=r,r+=1,c(),a=r;r<e.length&&i();)r+=1;r<e.length&&e.charAt(r)==="="?(u=!0,r=a,t.push(e.slice(n,s)),n=r):r=s+1}else r+=1;(!u||r>=e.length)&&t.push(e.slice(n))}return t}var tt=typeof setImmediate>"u"?e=>e():setImmediate;function m(e,t,r){return r&&rt(e,r),new Promise(n=>{tt(()=>{e.handled||e.node.res.end(t),n()})})}function ge(e,t){if(e.handled)return;!t&&e.node.res.statusCode!==200&&(t=e.node.res.statusCode);let r=_(t,204);r===204&&e.node.res.removeHeader("content-length"),e.node.res.writeHead(r),e.node.res.end()}function x(e,t,r){t&&(e.node.res.statusCode=_(t,e.node.res.statusCode)),r&&(e.node.res.statusMessage=O(r))}function rt(e,t){t&&e.node.res.statusCode!==304&&!e.node.res.getHeader("content-type")&&e.node.res.setHeader("content-type",t)}function ir(e,t,r=302){e.node.res.statusCode=_(r,e.node.res.statusCode),e.node.res.setHeader("location",t);let o=`<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0; url=${t.replace(/"/g,"%22")}"></head></html>`;return m(e,o,S.html)}function A(e,t){return e.node.res.getHeader(t)}function nt(e,t){for(let[r,n]of Object.entries(t))e.node.res.setHeader(r,n)}function R(e,t,r){e.node.res.setHeader(t,r)}function ot(e,t){for(let[r,n]of Object.entries(t))st(e,r,n)}var w=ot;function st(e,t,r){let n=e.node.res.getHeader(t);if(!n){e.node.res.setHeader(t,r);return}Array.isArray(n)||(n=[n.toString()]),e.node.res.setHeader(t,[...n,r])}function we(e){return!e||typeof e!="object"?!1:typeof e.pipe=="function"&&(typeof e._read=="function"||typeof e.abort=="function")||typeof e.pipeTo=="function"}function at(e){return typeof Response<"u"&&e instanceof Response}function T(e,t){if(!t||typeof t!="object")throw new Error("[h3] Invalid stream provided.");if(e.node.res._data=t,!e.node.res.socket)return e._handled=!0,Promise.resolve();if(E(t,"pipeTo")&&typeof t.pipeTo=="function")return t.pipeTo(new WritableStream({write(r){e.node.res.write(r)}})).then(()=>{e.node.res.end()});if(E(t,"pipe")&&typeof t.pipe=="function")return new Promise((r,n)=>{t.pipe(e.node.res),t.on&&(t.on("end",()=>{e.node.res.end(),r()}),t.on("error",o=>{n(o)})),e.node.res.on("close",()=>{t.abort&&t.abort()})});throw new Error("[h3] Invalid or incompatible stream provided.")}function _e(e,t){for(let[r,n]of t.headers)r==="set-cookie"?e.node.res.appendHeader(r,ye(n)):e.node.res.setHeader(r,n);if(t.status&&(e.node.res.statusCode=_(t.status,e.node.res.statusCode)),t.statusText&&(e.node.res.statusMessage=O(t.statusText)),t.redirected&&e.node.res.setHeader("location",t.url),!t.body){e.node.res.end();return}return T(e,t.body)}function it(e={}){return ie(e,{origin:"*",methods:"*",allowHeaders:"*",exposeHeaders:"*",credentials:!1,maxAge:!1,preflight:{statusCode:204}})}function ct(e){let t=g(e,"origin"),r=g(e,"access-control-request-method");return e.method==="OPTIONS"&&!!t&&!!r}function ut(e,t){let{origin:r}=t;return!e||!r||r==="*"||r==="null"?!0:Array.isArray(r)?r.some(n=>n instanceof RegExp?n.test(e):e===n):r(e)}function Re(e,t){let{origin:r}=t,n=g(e,"origin");return!n||!r||r==="*"?{"access-control-allow-origin":"*"}:typeof r=="string"?{"access-control-allow-origin":r,vary:"origin"}:ut(n,t)?{"access-control-allow-origin":n,vary:"origin"}:{}}function ft(e){let{methods:t}=e;return t?t==="*"?{"access-control-allow-methods":"*"}:t.length>0?{"access-control-allow-methods":t.join(",")}:{}:{}}function Ee(e){let{credentials:t}=e;return t?{"access-control-allow-credentials":"true"}:{}}function dt(e,t){let{allowHeaders:r}=t;if(!r||r==="*"||r.length===0){let n=g(e,"access-control-request-headers");return n?{"access-control-allow-headers":n,vary:"access-control-request-headers"}:{}}return{"access-control-allow-headers":r.join(","),vary:"access-control-request-headers"}}function be(e){let{exposeHeaders:t}=e;return t?t==="*"?{"access-control-expose-headers":t}:{"access-control-expose-headers":t.join(",")}:{}}function lt(e,t){w(e,Re(e,t)),w(e,Ee(t)),w(e,be(t)),w(e,ft(t)),w(e,dt(e,t))}function ht(e,t){w(e,Re(e,t)),w(e,Ee(t)),w(e,be(t))}function cr(e,t){let r=it(t);return ct(e)?(lt(e,t),ge(e,r.preflight.statusCode),!0):(ht(e,t),!1)}var pt=new Set(["transfer-encoding","accept-encoding","connection","keep-alive","upgrade","expect","host","accept"]);function ur(e,t){let r=Object.create(null),n=he(e);for(let o in n)(!pt.has(o)||o==="host"&&t?.host)&&(r[o]=n[o]);return r}function P(e){let t="";e.id&&(t+=`id: ${de(e.id)}
`),e.event&&(t+=`event: ${de(e.event)}
`),typeof e.retry=="number"&&Number.isInteger(e.retry)&&(t+=`retry: ${e.retry}
`);let r=typeof e.data=="string"?e.data:"";for(let n of r.split(/\r\n|\r|\n/))t+=`data: ${n}
`;return t+=`
`,t}function de(e){return e.replace(/[\n\r]/g,"")}function mt(e){let t="";for(let r of e)t+=P(r);return t}function yt(e){let t={"Content-Type":"text/event-stream","Cache-Control":"private, no-cache, no-store, no-transform, must-revalidate, max-age=0","X-Accel-Buffering":"no"};gt(e)||(t.Connection="keep-alive"),nt(e,t)}function gt(e){return ue(e,":path")!==void 0&&ue(e,":method")!==void 0}var W=class{_h3Event;_transformStream=new TransformStream;_writer;_encoder=new TextEncoder;_writerIsClosed=!1;_paused=!1;_unsentData;_disposed=!1;_handled=!1;constructor(t,r={}){this._h3Event=t,this._writer=this._transformStream.writable.getWriter(),this._writer.closed.then(()=>{this._writerIsClosed=!0}),r.autoclose!==!1&&this._h3Event.node.req.on("close",()=>this.close())}async push(t){if(typeof t=="string"){await this._sendEvent({data:t});return}if(Array.isArray(t)){if(t.length===0)return;if(typeof t[0]=="string"){let r=[];for(let n of t)r.push({data:n});await this._sendEvents(r);return}await this._sendEvents(t);return}await this._sendEvent(t)}async _sendEvent(t){if(!this._writerIsClosed){if(this._paused&&!this._unsentData){this._unsentData=P(t);return}if(this._paused){this._unsentData+=P(t);return}await this._writer.write(this._encoder.encode(P(t))).catch()}}async _sendEvents(t){if(this._writerIsClosed)return;let r=mt(t);if(this._paused&&!this._unsentData){this._unsentData=r;return}if(this._paused){this._unsentData+=r;return}await this._writer.write(this._encoder.encode(r)).catch()}pause(){this._paused=!0}get isPaused(){return this._paused}async resume(){this._paused=!1,await this.flush()}async flush(){this._writerIsClosed||this._unsentData?.length&&(await this._writer.write(this._encoder.encode(this._unsentData)),this._unsentData=void 0)}async close(){if(!this._disposed){if(!this._writerIsClosed)try{await this._writer.close()}catch{}this._h3Event._handled&&this._handled&&!this._h3Event.node.res.closed&&this._h3Event.node.res.end(),this._disposed=!0}}onClosed(t){this._writer.closed.then(t)}async send(){yt(this._h3Event),x(this._h3Event,200),this._h3Event._handled=!0,this._handled=!0,await T(this._h3Event,this._transformStream.readable)}};function fr(e,t){return new W(e,t)}async function dr(e,t){if(e.method!=="GET"&&e.method!=="HEAD"){if(!t.fallthrough)throw p({statusMessage:"Method Not Allowed",statusCode:405});return!1}let r=I(k(C(e.path).pathname));if(/(^|[\\/])(\.\.|%2e%2e|%2e\.|\.%2e)($|[\\/])/i.test(r)){if(!t.fallthrough)throw p({statusCode:404});return!1}let n=wt(g(e,"accept-encoding"),t.encodings);n.length>1&&R(e,"vary","accept-encoding");let o=r,s,a=_t(r,n,t.indexNames||["/index.html"]);for(let i of a){let f=await t.getMeta(i);if(f){s=f,o=i;break}}if(!s){if(!t.fallthrough)throw p({statusCode:404});return!1}if(s.etag&&!A(e,"etag")&&R(e,"etag",s.etag),s.etag&&g(e,"if-none-match")===s.etag)return x(e,304,"Not Modified"),m(e,"");if(s.mtime){let i=new Date(s.mtime),f=g(e,"if-modified-since");if(f&&new Date(f)>=i)return x(e,304,"Not Modified"),m(e,null);A(e,"last-modified")||R(e,"last-modified",i.toUTCString())}if(s.type&&!A(e,"content-type")&&R(e,"content-type",s.type),s.encoding&&!A(e,"content-encoding")&&R(e,"content-encoding",s.encoding),s.size!==void 0&&s.size>0&&!A(e,"content-length")&&R(e,"content-length",s.size),e.method==="HEAD")return m(e,null);let c=await t.getContents(o);return we(c)?T(e,c):m(e,c)}function wt(e,t){return!t||!e?[]:String(e||"").split(",").map(r=>t[r.trim()]).filter(Boolean)}function _t(e,t,r){let n=[];for(let o of["",...r])for(let s of[...t,""])n.push(`${e}${o}${s}`);return n}var z=class{__is_event__=!0;node;web;context={};_method;_path;_headers;_requestBody;_handled=!1;_onBeforeResponseCalled;_onAfterResponseCalled;constructor(t,r){this.node={req:t,res:r}}get method(){return this._method||(this._method=(this.node.req.method||"GET").toUpperCase()),this._method}get path(){return this._path||this.node.req.url||"/"}get headers(){return this._headers||(this._headers=Et(this.node.req.headers)),this._headers}get handled(){return this._handled||this.node.res.writableEnded||this.node.res.headersSent}respondWith(t){return Promise.resolve(t).then(r=>_e(this,r))}toString(){return`[${this.method}] ${this.path}`}toJSON(){return this.toString()}get req(){return this.node.req}get res(){return this.node.res}};function Rt(e,t){return new z(e,t)}function Et(e){let t=new Headers;for(let[r,n]of Object.entries(e))if(Array.isArray(n))for(let o of n)t.append(r,o);else n&&t.set(r,n);return t}function bt(e){if(typeof e=="function")return e.__is_handler__=!0,e;let t={onRequest:le(e.onRequest),onBeforeResponse:le(e.onBeforeResponse)},r=n=>Ct(n,e.handler,t);return r.__is_handler__=!0,r.__resolve__=e.handler.__resolve__,r.__websocket__=e.websocket,r}function le(e){return e?Array.isArray(e)?e:[e]:void 0}async function Ct(e,t,r){if(r.onRequest){for(let s of r.onRequest)if(await s(e),e.handled)return}let o={body:await t(e)};if(r.onBeforeResponse)for(let s of r.onBeforeResponse)await s(e,o);return o.body}var V=bt;function At(e){return E(e,"__is_handler__")}function G(e,t,r){return e}function St(e){let t,r,n=()=>r?Promise.resolve(r):(t||(t=Promise.resolve(e()).then(s=>{let a=s.default||s;if(typeof a!="function")throw new TypeError("Invalid lazy handler result. It should be a function:",a);return r={handler:G(s.default||s)},r})),t),o=V(s=>r?r.handler(s):n().then(a=>a.handler(s)));return o.__resolve__=n,o}var xt=St,lr=globalThis.Headers,hr=globalThis.Response;function pr(e={}){let t=[],r=Ht(t,e),n=Pt(t);r.__resolve__=n;let o=Ot(()=>Mt(n,e)),s={use:(a,u,c)=>J(s,a,u,c),resolve:n,handler:r,stack:t,options:e,get websocket(){return o()}};return s}function J(e,t,r,n){if(Array.isArray(t))for(let o of t)J(e,o,r,n);else if(Array.isArray(r))for(let o of r)J(e,t,o,n);else typeof t=="string"?e.stack.push(U({...n,route:t,handler:r})):typeof t=="function"?e.stack.push(U({...r,handler:t})):e.stack.push(U({...t}));return e}function Ht(e,t){let r=t.debug?2:void 0;return V(async n=>{n.node.req.originalUrl=n.node.req.originalUrl||n.node.req.url||"/";let o=Tt(n._path||n.node.req.url||"/");n._path=o;let s;t.onRequest&&await t.onRequest(n);for(let a of e){if(a.route.length>1){if(!o.startsWith(a.route))continue;s=o.slice(a.route.length)||"/"}else s=o;if(a.match&&!a.match(s,n))continue;n._path=s,n.node.req.url=s;let u=await a.handler(n),c=u===void 0?void 0:await u;if(c!==void 0){let i={body:c};t.onBeforeResponse&&(n._onBeforeResponseCalled=!0,await t.onBeforeResponse(n,i)),await Nt(n,i.body,r),t.onAfterResponse&&(n._onAfterResponseCalled=!0,await t.onAfterResponse(n,i));return}if(n.handled){t.onAfterResponse&&(n._onAfterResponseCalled=!0,await t.onAfterResponse(n,void 0));return}}if(!n.handled)throw p({statusCode:404,statusMessage:`Cannot find any path matching ${n.path||"/"}.`});t.onAfterResponse&&(n._onAfterResponseCalled=!0,await t.onAfterResponse(n,void 0))})}function Pt(e){return async t=>{let r;for(let n of e){if(n.route==="/"&&!n.handler.__resolve__||!t.startsWith(n.route)||(r=t.slice(n.route.length)||"/",n.match&&!n.match(r,void 0)))continue;let o={route:n.route,handler:n.handler};if(o.handler.__resolve__){let s=await o.handler.__resolve__(r);if(!s)continue;o={...o,...s,route:Z(o.route||"/",s.route||"/")}}return o}}}function U(e){let t=e.handler;return t.handler&&(t=t.handler),e.lazy?t=xt(t):At(t)||(t=G(t,void 0,e.route)),{route:k(e.route),match:e.match,handler:t}}function Nt(e,t,r){if(t===null)return ge(e);if(t){if(at(t))return _e(e,t);if(we(t))return T(e,t);if(t.buffer)return m(e,t);if(t.arrayBuffer&&typeof t.arrayBuffer=="function")return t.arrayBuffer().then(o=>m(e,Buffer.from(o),t.type));if(t instanceof Error)throw p(t);if(typeof t.end=="function")return!0}let n=typeof t;if(n==="string")return m(e,t,S.html);if(n==="object"||n==="boolean"||n==="number")return m(e,JSON.stringify(t,void 0,r),S.json);if(n==="bigint")return m(e,t.toString(),S.json);throw p({statusCode:500,statusMessage:`[h3] Cannot send ${n} as response.`})}function Ot(e){let t;return()=>(t||(t=e()),t)}function Tt(e){let t=e.indexOf("?"),r=t===-1?e:e.slice(0,t),n=t===-1?"":e.slice(t);return(r.includes("%25")?L(r.replace(/%25/g,"%2525")):L(r))+n}function Mt(e,t){return{...t.websocket,async resolve(r){let n=r.request?.url||r.url||"/",{pathname:o}=typeof n=="string"?C(n):n;return(await e(o))?.handler?.__websocket__||{}}}}var qt=["connect","delete","get","head","options","post","put","trace","patch"];function mr(e={}){let t=re({}),r={},n,o={},s=(c,i,f)=>{let d=r[c];if(d||(r[c]=d={path:c,handlers:{}},t.insert(c,d)),Array.isArray(f))for(let l of f)s(c,i,l);else d.handlers[f]=G(i);return o};o.use=o.add=(c,i,f)=>s(c,i,f||"all");for(let c of qt)o[c]=(i,f)=>o.add(i,f,c);let a=(c="/",i="get")=>{let f=c.indexOf("?");f!==-1&&(c=c.slice(0,Math.max(0,f)));let d=t.lookup(c);if(!d||!d.handlers)return{error:p({statusCode:404,name:"Not Found",statusMessage:`Cannot find any route matching ${c||"/"}.`})};let l=d.handlers[i]||d.handlers.all;if(!l){n||(n=oe(t));let M=n.matchAll(c).reverse();for(let H of M){if(H.handlers[i]){l=H.handlers[i],d.handlers[i]=d.handlers[i]||l;break}if(H.handlers.all){l=H.handlers.all,d.handlers.all=d.handlers.all||l;break}}}return l?{matched:d,handler:l}:{error:p({statusCode:405,name:"Method Not Allowed",statusMessage:`Method ${i} is not allowed on this route.`})}},u=e.preemptive||e.preemtive;return o.handler=V(c=>{let i=a(c.path,c.method.toLowerCase());if("error"in i){if(u)throw i.error;return}c.context.matchedRoute=i.matched;let f=i.matched.params||{};return c.context.params=f,Promise.resolve(i.handler(c)).then(d=>d===void 0&&u?null:d)}),o.handler.__resolve__=async c=>{c=I(c);let i=a(c);if("error"in i)return;let f={route:i.matched.path,handler:i.handler};if(i.handler.__resolve__){let d=await i.handler.__resolve__(c);if(!d)return;f={...f,...d}}return f},o}function yr(e){return async function(r,n){let o=Rt(r,n);try{await e.handler(o)}catch(s){let a=p(s);if(Q(s)||(a.unhandled=!0),x(o,a.statusCode,a.statusMessage),e.options.onError&&await e.options.onError(a,o),o.handled)return;(a.unhandled||a.fatal)&&console.error("[h3]",a.fatal?"[fatal]":"[unhandled]",a),e.options.onBeforeResponse&&!o._onBeforeResponseCalled&&await e.options.onBeforeResponse(o,{body:a}),await Ke(o,a,!!e.options.debug),e.options.onAfterResponse&&!o._onAfterResponseCalled&&await e.options.onAfterResponse(o,{body:a})}}}export{p as a,Ke as b,tr as c,rr as d,he as e,g as f,nr as g,or as h,sr as i,ar as j,m as k,x as l,ir as m,R as n,cr as o,ur as p,fr as q,dr as r,bt as s,St as t,pr as u,mr as v,yr as w};