UNPKG

sample-api

Version:

A Hono.js library to generate random 16-digit codes

3 lines (2 loc) 19.6 kB
"use strict";var k=Object.defineProperty;var Et=Object.getOwnPropertyDescriptor;var Rt=Object.getOwnPropertyNames;var bt=Object.prototype.hasOwnProperty;var wt=(t,e)=>{for(var s in e)k(t,s,{get:e[s],enumerable:!0})},xt=(t,e,s,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Rt(e))!bt.call(t,n)&&n!==s&&k(t,n,{get:()=>e[n],enumerable:!(r=Et(e,n))||r.enumerable});return t};var vt=t=>xt(k({},"__esModule",{value:!0}),t);var Bt={};wt(Bt,{handler:()=>Ft});module.exports=vt(Bt);var et=async(t,e=Object.create(null))=>{let{all:s=!1,dot:r=!1}=e,i=(t instanceof A?t.raw.headers:t.headers).get("Content-Type");return i?.startsWith("multipart/form-data")||i?.startsWith("application/x-www-form-urlencoded")?Ot(t,{all:s,dot:r}):{}};async function Ot(t,e){let s=await t.formData();return s?Pt(s,e):{}}function Pt(t,e){let s=Object.create(null);return t.forEach((r,n)=>{e.all||n.endsWith("[]")?jt(s,n,r):s[n]=r}),e.dot&&Object.entries(s).forEach(([r,n])=>{r.includes(".")&&(St(s,r,n),delete s[r])}),s}var jt=(t,e,s)=>{t[e]!==void 0?Array.isArray(t[e])?t[e].push(s):t[e]=[t[e],s]:t[e]=s},St=(t,e,s)=>{let r=t,n=e.split(".");n.forEach((i,a)=>{a===n.length-1?r[i]=s:((!r[i]||typeof r[i]!="object"||Array.isArray(r[i])||r[i]instanceof File)&&(r[i]=Object.create(null)),r=r[i])})};var F=t=>{let e=t.split("/");return e[0]===""&&e.shift(),e},rt=t=>{let{groups:e,path:s}=At(t),r=F(s);return Ht(r,e)},At=t=>{let e=[];return t=t.replace(/\{[^}]+\}/g,(s,r)=>{let n=`@${r}`;return e.push([n,s]),n}),{groups:e,path:t}},Ht=(t,e)=>{for(let s=e.length-1;s>=0;s--){let[r]=e[s];for(let n=t.length-1;n>=0;n--)if(t[n].includes(r)){t[n]=t[n].replace(r,e[s][1]);break}}return t},H={},B=t=>{if(t==="*")return"*";let e=t.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);return e?(H[t]||(e[2]?H[t]=[t,e[1],new RegExp("^"+e[2]+"$")]:H[t]=[t,e[1],!0]),H[t]):null},U=(t,e)=>{try{return e(t)}catch{return t.replace(/(?:%[0-9A-Fa-f]{2})+/g,s=>{try{return e(s)}catch{return s}})}},_t=t=>U(t,decodeURI),q=t=>{let e=t.url,s=e.indexOf("/",8),r=s;for(;r<e.length;r++){let n=e.charCodeAt(r);if(n===37){let i=e.indexOf("?",r),a=e.slice(s,i===-1?void 0:i);return _t(a.includes("%25")?a.replace(/%25/g,"%2525"):a)}else if(n===63)break}return e.slice(s,r)};var st=t=>{let e=q(t);return e.length>1&&e.at(-1)==="/"?e.slice(0,-1):e},w=(...t)=>{let e="",s=!1;for(let r of t)e.at(-1)==="/"&&(e=e.slice(0,-1),s=!0),r[0]!=="/"&&(r=`/${r}`),r==="/"&&s?e=`${e}/`:r!=="/"&&(e=`${e}${r}`),r==="/"&&e===""&&(e="/");return e},_=t=>{if(!t.match(/\:.+\?$/))return null;let e=t.split("/"),s=[],r="";return e.forEach(n=>{if(n!==""&&!/\:/.test(n))r+="/"+n;else if(/\:/.test(n))if(/\?/.test(n)){s.length===0&&r===""?s.push("/"):s.push(r);let i=n.replace("?","");r+="/"+i,s.push(r)}else r+="/"+n}),s.filter((n,i,a)=>a.indexOf(n)===i)},N=t=>/[%+]/.test(t)?(t.indexOf("+")!==-1&&(t=t.replace(/\+/g," ")),t.indexOf("%")!==-1?W(t):t):t,nt=(t,e,s)=>{let r;if(!s&&e&&!/[%+]/.test(e)){let a=t.indexOf(`?${e}`,8);for(a===-1&&(a=t.indexOf(`&${e}`,8));a!==-1;){let c=t.charCodeAt(a+e.length+1);if(c===61){let o=a+e.length+2,h=t.indexOf("&",o);return N(t.slice(o,h===-1?void 0:h))}else if(c==38||isNaN(c))return"";a=t.indexOf(`&${e}`,a+1)}if(r=/[%+]/.test(t),!r)return}let n={};r??=/[%+]/.test(t);let i=t.indexOf("?",8);for(;i!==-1;){let a=t.indexOf("&",i+1),c=t.indexOf("=",i);c>a&&a!==-1&&(c=-1);let o=t.slice(i+1,c===-1?a===-1?void 0:a:c);if(r&&(o=N(o)),i=a,o==="")continue;let h;c===-1?h="":(h=t.slice(c+1,a===-1?void 0:a),r&&(h=N(h))),s?(n[o]&&Array.isArray(n[o])||(n[o]=[]),n[o].push(h)):n[o]??=h}return e?n[e]:n},it=nt,ot=(t,e)=>nt(t,e,!0),W=decodeURIComponent;var at=t=>U(t,W),A=class{raw;#e;#t;routeIndex=0;path;bodyCache={};constructor(t,e="/",s=[[]]){this.raw=t,this.path=e,this.#t=s,this.#e={}}param(t){return t?this.#s(t):this.#i()}#s(t){let e=this.#t[0][this.routeIndex][1][t],s=this.#n(e);return s?/\%/.test(s)?at(s):s:void 0}#i(){let t={},e=Object.keys(this.#t[0][this.routeIndex][1]);for(let s of e){let r=this.#n(this.#t[0][this.routeIndex][1][s]);r&&typeof r=="string"&&(t[s]=/\%/.test(r)?at(r):r)}return t}#n(t){return this.#t[1]?this.#t[1][t]:t}query(t){return it(this.url,t)}queries(t){return ot(this.url,t)}header(t){if(t)return this.raw.headers.get(t.toLowerCase())??void 0;let e={};return this.raw.headers.forEach((s,r)=>{e[r]=s}),e}async parseBody(t){return this.bodyCache.parsedBody??=await et(this,t)}#r=t=>{let{bodyCache:e,raw:s}=this,r=e[t];if(r)return r;let n=Object.keys(e)[0];return n?e[n].then(i=>(n==="json"&&(i=JSON.stringify(i)),new Response(i)[t]())):e[t]=s[t]()};json(){return this.#r("json")}text(){return this.#r("text")}arrayBuffer(){return this.#r("arrayBuffer")}blob(){return this.#r("blob")}formData(){return this.#r("formData")}addValidatedData(t,e){this.#e[t]=e}valid(t){return this.#e[t]}get url(){return this.raw.url}get method(){return this.raw.method}get matchedRoutes(){return this.#t[0].map(([[,t]])=>t)}get routePath(){return this.#t[0].map(([[,t]])=>t)[this.routeIndex].path}};var ct={Stringify:1,BeforeStream:2,Stream:3},Ct=(t,e)=>{let s=new String(t);return s.isEscaped=!0,s.callbacks=e,s};var K=async(t,e,s,r,n)=>{typeof t=="object"&&!(t instanceof String)&&(t instanceof Promise||(t=t.toString()),t instanceof Promise&&(t=await t));let i=t.callbacks;if(!i?.length)return Promise.resolve(t);n?n[0]+=t:n=[t];let a=Promise.all(i.map(c=>c({phase:e,buffer:n,context:r}))).then(c=>Promise.all(c.filter(Boolean).map(o=>K(o,e,!1,r,n))).then(()=>n[0]));return s?Ct(await a,i):a};var Lt="text/plain; charset=UTF-8",z=(t,e={})=>{for(let s of Object.keys(e))t.set(s,e[s]);return t},C=class{#e;#t;env={};#s;finalized=!1;error;#i=200;#n;#r;#o;#c;#h=!0;#f;#l;#u;#d;#p;constructor(t,e){this.#e=t,e&&(this.#n=e.executionCtx,this.env=e.env,this.#u=e.notFoundHandler,this.#p=e.path,this.#d=e.matchResult)}get req(){return this.#t??=new A(this.#e,this.#p,this.#d),this.#t}get event(){if(this.#n&&"respondWith"in this.#n)return this.#n;throw Error("This context has no FetchEvent")}get executionCtx(){if(this.#n)return this.#n;throw Error("This context has no ExecutionContext")}get res(){return this.#h=!1,this.#c||=new Response("404 Not Found",{status:404})}set res(t){if(this.#h=!1,this.#c&&t)try{for(let[e,s]of this.#c.headers.entries())if(e!=="content-type")if(e==="set-cookie"){let r=this.#c.headers.getSetCookie();t.headers.delete("set-cookie");for(let n of r)t.headers.append("set-cookie",n)}else t.headers.set(e,s)}catch(e){if(e instanceof TypeError&&e.message.includes("immutable")){this.res=new Response(t.body,{headers:t.headers,status:t.status});return}else throw e}this.#c=t,this.finalized=!0}render=(...t)=>(this.#l??=e=>this.html(e),this.#l(...t));setLayout=t=>this.#f=t;getLayout=()=>this.#f;setRenderer=t=>{this.#l=t};header=(t,e,s)=>{if(e===void 0){this.#r?this.#r.delete(t):this.#o&&delete this.#o[t.toLocaleLowerCase()],this.finalized&&this.res.headers.delete(t);return}s?.append?(this.#r||(this.#h=!1,this.#r=new Headers(this.#o),this.#o={}),this.#r.append(t,e)):this.#r?this.#r.set(t,e):(this.#o??={},this.#o[t.toLowerCase()]=e),this.finalized&&(s?.append?this.res.headers.append(t,e):this.res.headers.set(t,e))};status=t=>{this.#h=!1,this.#i=t};set=(t,e)=>{this.#s??=new Map,this.#s.set(t,e)};get=t=>this.#s?this.#s.get(t):void 0;get var(){return this.#s?Object.fromEntries(this.#s):{}}#a(t,e,s){if(this.#h&&!s&&!e&&this.#i===200)return new Response(t,{headers:this.#o});if(e&&typeof e!="number"){let n=new Headers(e.headers);this.#r&&this.#r.forEach((a,c)=>{c==="set-cookie"?n.append(c,a):n.set(c,a)});let i=z(n,this.#o);return new Response(t,{headers:i,status:e.status??this.#i})}let r=typeof e=="number"?e:this.#i;this.#o??={},this.#r??=new Headers,z(this.#r,this.#o),this.#c&&(this.#c.headers.forEach((n,i)=>{i==="set-cookie"?this.#r?.append(i,n):this.#r?.set(i,n)}),z(this.#r,this.#o)),s??={};for(let[n,i]of Object.entries(s))if(typeof i=="string")this.#r.set(n,i);else{this.#r.delete(n);for(let a of i)this.#r.append(n,a)}return new Response(t,{status:r,headers:this.#r})}newResponse=(...t)=>this.#a(...t);body=(t,e,s)=>typeof e=="number"?this.#a(t,e,s):this.#a(t,e);text=(t,e,s)=>{if(!this.#o){if(this.#h&&!s&&!e)return new Response(t);this.#o={}}return this.#o["content-type"]=Lt,typeof e=="number"?this.#a(t,e,s):this.#a(t,e)};json=(t,e,s)=>{let r=JSON.stringify(t);return this.#o??={},this.#o["content-type"]="application/json; charset=UTF-8",typeof e=="number"?this.#a(r,e,s):this.#a(r,e)};html=(t,e,s)=>(this.#o??={},this.#o["content-type"]="text/html; charset=UTF-8",typeof t=="object"?K(t,ct.Stringify,!1,{}).then(r=>typeof e=="number"?this.#a(r,e,s):this.#a(r,e)):typeof e=="number"?this.#a(t,e,s):this.#a(t,e));redirect=(t,e)=>(this.#r??=new Headers,this.#r.set("Location",String(t)),this.newResponse(null,e??302));notFound=()=>(this.#u??=()=>new Response,this.#u(this))};var G=(t,e,s)=>(r,n)=>{let i=-1,a=r instanceof C;return c(0);async function c(o){if(o<=i)throw new Error("next() called multiple times");i=o;let h,l=!1,u;if(t[o]?(u=t[o][0][0],a&&(r.req.routeIndex=o)):u=o===t.length&&n||void 0,!u)a&&r.finalized===!1&&s&&(h=await s(r));else try{h=await u(r,()=>c(o+1))}catch(d){if(d instanceof Error&&a&&e)r.error=d,h=await e(d,r),l=!0;else throw d}return h&&(r.finalized===!1||l)&&(r.res=h),r}};var p="ALL",ht="all",lt=["get","post","put","delete","options","patch"],L="Can not add a route since the matcher is already built.",T=class extends Error{};var Tt=Symbol("composedHandler"),Dt=t=>t.text("404 Not Found",404),ut=(t,e)=>"getResponse"in t?t.getResponse():(console.error(t),e.text("Internal Server Error",500)),V=class{get;post;put;delete;options;patch;all;on;use;router;getPath;_basePath="/";#e="/";routes=[];constructor(t={}){[...lt,ht].forEach(r=>{this[r]=(n,...i)=>(typeof n=="string"?this.#e=n:this.#i(r,this.#e,n),i.forEach(a=>{this.#i(r,this.#e,a)}),this)}),this.on=(r,n,...i)=>{for(let a of[n].flat()){this.#e=a;for(let c of[r].flat())i.map(o=>{this.#i(c.toUpperCase(),this.#e,o)})}return this},this.use=(r,...n)=>(typeof r=="string"?this.#e=r:(this.#e="*",n.unshift(r)),n.forEach(i=>{this.#i(p,this.#e,i)}),this);let s=t.strict??!0;delete t.strict,Object.assign(this,t),this.getPath=s?t.getPath??q:st}#t(){let t=new V({router:this.router,getPath:this.getPath});return t.routes=this.routes,t}#s=Dt;errorHandler=ut;route(t,e){let s=this.basePath(t);return e.routes.map(r=>{let n;e.errorHandler===ut?n=r.handler:(n=async(i,a)=>(await G([],e.errorHandler)(i,()=>r.handler(i,a))).res,n[Tt]=r.handler),s.#i(r.method,r.path,n)}),this}basePath(t){let e=this.#t();return e._basePath=w(this._basePath,t),e}onError=t=>(this.errorHandler=t,this);notFound=t=>(this.#s=t,this);mount(t,e,s){let r,n;s&&(typeof s=="function"?n=s:(n=s.optionHandler,r=s.replaceRequest));let i=n?c=>{let o=n(c);return Array.isArray(o)?o:[o]}:c=>{let o;try{o=c.executionCtx}catch{}return[c.env,o]};r||=(()=>{let c=w(this._basePath,t),o=c==="/"?0:c.length;return h=>{let l=new URL(h.url);return l.pathname=l.pathname.slice(o)||"/",new Request(l,h)}})();let a=async(c,o)=>{let h=await e(r(c.req.raw),...i(c));if(h)return h;await o()};return this.#i(p,w(t,"*"),a),this}#i(t,e,s){t=t.toUpperCase(),e=w(this._basePath,e);let r={path:e,method:t,handler:s};this.router.add(t,e,[s,r]),this.routes.push(r)}#n(t,e){if(t instanceof Error)return this.errorHandler(t,e);throw t}#r(t,e,s,r){if(r==="HEAD")return(async()=>new Response(null,await this.#r(t,e,s,"GET")))();let n=this.getPath(t,{env:s}),i=this.router.match(r,n),a=new C(t,{path:n,matchResult:i,env:s,executionCtx:e,notFoundHandler:this.#s});if(i[0].length===1){let o;try{o=i[0][0][0][0](a,async()=>{a.res=await this.#s(a)})}catch(h){return this.#n(h,a)}return o instanceof Promise?o.then(h=>h||(a.finalized?a.res:this.#s(a))).catch(h=>this.#n(h,a)):o??this.#s(a)}let c=G(i[0],this.errorHandler,this.#s);return(async()=>{try{let o=await c(a);if(!o.finalized)throw new Error("Context is not finalized. Did you forget to return a Response object or `await next()`?");return o.res}catch(o){return this.#n(o,a)}})()}fetch=(t,...e)=>this.#r(t,e[1],e[0],t.method);request=(t,e,s,r)=>t instanceof Request?this.fetch(e?new Request(t,e):t,s,r):(t=t.toString(),this.fetch(new Request(/^https?:\/\//.test(t)?t:`http://localhost${w("/",t)}`,e),s,r));fire=()=>{addEventListener("fetch",t=>{t.respondWith(this.#r(t.request,t,void 0,t.request.method))})}};var D="[^/]+",O=".*",P="(?:|/.*)",x=Symbol(),Mt=new Set(".\\+*[^]$()");function It(t,e){return t.length===1?e.length===1?t<e?-1:1:-1:e.length===1||t===O||t===P?1:e===O||e===P?-1:t===D?1:e===D?-1:t.length===e.length?t<e?-1:1:e.length-t.length}var M=class{#e;#t;#s=Object.create(null);insert(t,e,s,r,n){if(t.length===0){if(this.#e!==void 0)throw x;if(n)return;this.#e=e;return}let[i,...a]=t,c=i==="*"?a.length===0?["","",O]:["","",D]:i==="/*"?["","",P]:i.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/),o;if(c){let h=c[1],l=c[2]||D;if(h&&c[2]&&(l=l.replace(/^\((?!\?:)(?=[^)]+\)$)/,"(?:"),/\((?!\?:)/.test(l)))throw x;if(o=this.#s[l],!o){if(Object.keys(this.#s).some(u=>u!==O&&u!==P))throw x;if(n)return;o=this.#s[l]=new M,h!==""&&(o.#t=r.varIndex++)}!n&&h!==""&&s.push([h,o.#t])}else if(o=this.#s[i],!o){if(Object.keys(this.#s).some(h=>h.length>1&&h!==O&&h!==P))throw x;if(n)return;o=this.#s[i]=new M}o.insert(a,e,s,r,n)}buildRegExpStr(){let e=Object.keys(this.#s).sort(It).map(s=>{let r=this.#s[s];return(typeof r.#t=="number"?`(${s})@${r.#t}`:Mt.has(s)?`\\${s}`:s)+r.buildRegExpStr()});return typeof this.#e=="number"&&e.unshift(`#${this.#e}`),e.length===0?"":e.length===1?e[0]:"(?:"+e.join("|")+")"}};var ft=class{#e={varIndex:0};#t=new M;insert(t,e,s){let r=[],n=[];for(let a=0;;){let c=!1;if(t=t.replace(/\{[^}]+\}/g,o=>{let h=`@\\${a}`;return n[a]=[h,o],a++,c=!0,h}),!c)break}let i=t.match(/(?::[^\/]+)|(?:\/\*$)|./g)||[];for(let a=n.length-1;a>=0;a--){let[c]=n[a];for(let o=i.length-1;o>=0;o--)if(i[o].indexOf(c)!==-1){i[o]=i[o].replace(c,n[a][1]);break}}return this.#t.insert(i,e,r,this.#e,s),r}buildRegExp(){let t=this.#t.buildRegExpStr();if(t==="")return[/^$/,[],[]];let e=0,s=[],r=[];return t=t.replace(/#(\d+)|@(\d+)|\.\*\$/g,(n,i,a)=>i!==void 0?(s[++e]=Number(i),"$()"):(a!==void 0&&(r[Number(a)]=++e),"")),[new RegExp(`^${t}`),s,r]}};var dt=[],$t=[/^$/,[],Object.create(null)],pt=Object.create(null);function mt(t){return pt[t]??=new RegExp(t==="*"?"":`^${t.replace(/\/\*$|([.\\+*[^\]$()])/g,(e,s)=>s?`\\${s}`:"(?:|/.*)")}$`)}function kt(){pt=Object.create(null)}function Nt(t){let e=new ft,s=[];if(t.length===0)return $t;let r=t.map(h=>[!/\*|\/:/.test(h[0]),...h]).sort(([h,l],[u,d])=>h?1:u?-1:l.length-d.length),n=Object.create(null);for(let h=0,l=-1,u=r.length;h<u;h++){let[d,f,m]=r[h];d?n[f]=[m.map(([y])=>[y,Object.create(null)]),dt]:l++;let g;try{g=e.insert(f,l,d)}catch(y){throw y===x?new T(f):y}d||(s[l]=m.map(([y,R])=>{let E=Object.create(null);for(R-=1;R>=0;R--){let[I,j]=g[R];E[I]=j}return[y,E]}))}let[i,a,c]=e.buildRegExp();for(let h=0,l=s.length;h<l;h++)for(let u=0,d=s[h].length;u<d;u++){let f=s[h][u]?.[1];if(!f)continue;let m=Object.keys(f);for(let g=0,y=m.length;g<y;g++)f[m[g]]=c[f[m[g]]]}let o=[];for(let h in a)o[h]=s[a[h]];return[i,o,n]}function v(t,e){if(t){for(let s of Object.keys(t).sort((r,n)=>n.length-r.length))if(mt(s).test(e))return[...t[s]]}}var Q=class{name="RegExpRouter";#e;#t;constructor(){this.#e={[p]:Object.create(null)},this.#t={[p]:Object.create(null)}}add(t,e,s){let r=this.#e,n=this.#t;if(!r||!n)throw new Error(L);r[t]||[r,n].forEach(c=>{c[t]=Object.create(null),Object.keys(c[p]).forEach(o=>{c[t][o]=[...c[p][o]]})}),e==="/*"&&(e="*");let i=(e.match(/\/:/g)||[]).length;if(/\*$/.test(e)){let c=mt(e);t===p?Object.keys(r).forEach(o=>{r[o][e]||=v(r[o],e)||v(r[p],e)||[]}):r[t][e]||=v(r[t],e)||v(r[p],e)||[],Object.keys(r).forEach(o=>{(t===p||t===o)&&Object.keys(r[o]).forEach(h=>{c.test(h)&&r[o][h].push([s,i])})}),Object.keys(n).forEach(o=>{(t===p||t===o)&&Object.keys(n[o]).forEach(h=>c.test(h)&&n[o][h].push([s,i]))});return}let a=_(e)||[e];for(let c=0,o=a.length;c<o;c++){let h=a[c];Object.keys(n).forEach(l=>{(t===p||t===l)&&(n[l][h]||=[...v(r[l],h)||v(r[p],h)||[]],n[l][h].push([s,i-o+c+1]))})}}match(t,e){kt();let s=this.#s();return this.match=(r,n)=>{let i=s[r]||s[p],a=i[2][n];if(a)return a;let c=n.match(i[0]);if(!c)return[[],dt];let o=c.indexOf("",1);return[i[1][o],c]},this.match(t,e)}#s(){let t=Object.create(null);return Object.keys(this.#t).concat(Object.keys(this.#e)).forEach(e=>{t[e]||=this.#i(e)}),this.#e=this.#t=void 0,t}#i(t){let e=[],s=t===p;return[this.#e,this.#t].forEach(r=>{let n=r[t]?Object.keys(r[t]).map(i=>[i,r[t][i]]):[];n.length!==0?(s||=!0,e.push(...n)):t!==p&&e.push(...Object.keys(r[p]).map(i=>[i,r[p][i]]))}),s?Nt(e):null}};var X=class{name="SmartRouter";#e=[];#t=[];constructor(t){this.#e=t.routers}add(t,e,s){if(!this.#t)throw new Error(L);this.#t.push([t,e,s])}match(t,e){if(!this.#t)throw new Error("Fatal error");let s=this.#e,r=this.#t,n=s.length,i=0,a;for(;i<n;i++){let c=s[i];try{for(let o=0,h=r.length;o<h;o++)c.add(...r[o]);a=c.match(t,e)}catch(o){if(o instanceof T)continue;throw o}this.match=c.match.bind(c),this.#e=[c],this.#t=void 0;break}if(i===n)throw new Error("Fatal error");return this.name=`SmartRouter + ${this.activeRouter.name}`,a}get activeRouter(){if(this.#t||this.#e.length!==1)throw new Error("No active router has been determined yet.");return this.#e[0]}};var Y=class{#e;#t;#s;#i=0;#n=Object.create(null);constructor(t,e,s){if(this.#t=s||Object.create(null),this.#e=[],t&&e){let r=Object.create(null);r[t]={handler:e,possibleKeys:[],score:0},this.#e=[r]}this.#s=[]}insert(t,e,s){this.#i=++this.#i;let r=this,n=rt(e),i=[];for(let o=0,h=n.length;o<h;o++){let l=n[o];if(Object.keys(r.#t).includes(l)){r=r.#t[l];let d=B(l);d&&i.push(d[1]);continue}r.#t[l]=new Y;let u=B(l);u&&(r.#s.push(u),i.push(u[1])),r=r.#t[l]}let a=Object.create(null),c={handler:s,possibleKeys:i.filter((o,h,l)=>l.indexOf(o)===h),score:this.#i};return a[t]=c,r.#e.push(a),r}#r(t,e,s,r){let n=[];for(let i=0,a=t.#e.length;i<a;i++){let c=t.#e[i],o=c[e]||c[p],h={};if(o!==void 0){o.params=Object.create(null);for(let l=0,u=o.possibleKeys.length;l<u;l++){let d=o.possibleKeys[l],f=h[o.score];o.params[d]=r[d]&&!f?r[d]:s[d]??r[d],h[o.score]=!0}n.push(o)}}return n}search(t,e){let s=[];this.#n=Object.create(null);let n=[this],i=F(e);for(let a=0,c=i.length;a<c;a++){let o=i[a],h=a===c-1,l=[];for(let u=0,d=n.length;u<d;u++){let f=n[u],m=f.#t[o];m&&(m.#n=f.#n,h?(m.#t["*"]&&s.push(...this.#r(m.#t["*"],t,f.#n,Object.create(null))),s.push(...this.#r(m,t,f.#n,Object.create(null)))):l.push(m));for(let g=0,y=f.#s.length;g<y;g++){let R=f.#s[g],E={...f.#n};if(R==="*"){let $=f.#t["*"];$&&(s.push(...this.#r($,t,f.#n,Object.create(null))),l.push($));continue}if(o==="")continue;let[I,j,S]=R,b=f.#t[I],tt=i.slice(a).join("/");if(S instanceof RegExp&&S.test(tt)){E[j]=tt,s.push(...this.#r(b,t,f.#n,E));continue}(S===!0||S.test(o))&&(E[j]=o,h?(s.push(...this.#r(b,t,E,f.#n)),b.#t["*"]&&s.push(...this.#r(b.#t["*"],t,E,f.#n))):(b.#n=E,l.push(b)))}}n=l}return s.length>1&&s.sort((a,c)=>a.score-c.score),[s.map(({handler:a,params:c})=>[a,c])]}};var J=class{name="TrieRouter";#e;constructor(){this.#e=new Y}add(t,e,s){let r=_(e);if(r){for(let n=0,i=r.length;n<i;n++)this.#e.insert(t,r[n],s);return}this.#e.insert(t,e,s)}match(t,e){return this.#e.search(t,e)}};var Z=class extends V{constructor(t={}){super(t),this.router=t.router??new X({routers:[new Q,new J]})}};function gt(){let t="0123456789",e="";for(let s=0;s<16;s++)e+=t.charAt(Math.floor(Math.random()*t.length));return e}var yt=new Z;yt.get("/generate",t=>{let e=gt();return t.text(e)});var Ft=yt.fetch;0&&(module.exports={handler}); //# sourceMappingURL=index.js.map