@likec4/mcp 1.57.0 → 1.59.0

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.
Files changed (78) hide show
  1. package/dist/chunks/libs/@chevrotain/cst-dts-gen.mjs +1 -0
  2. package/dist/chunks/libs/@chevrotain/regexp-to-ast.mjs +1 -1
  3. package/dist/chunks/libs/@hono/mcp.mjs +6 -6
  4. package/dist/chunks/libs/@hono/node-server.mjs +3 -1
  5. package/dist/chunks/libs/@logtape/logtape.mjs +4 -3
  6. package/dist/chunks/libs/@modelcontextprotocol/sdk.mjs +4 -11
  7. package/dist/chunks/libs/@ts-graphviz/core.mjs +1 -1
  8. package/dist/chunks/libs/chevrotain-allstar.mjs +2 -2
  9. package/dist/chunks/libs/chevrotain.mjs +33 -33
  10. package/dist/chunks/libs/chokidar.mjs +2 -2
  11. package/dist/chunks/libs/chroma-js.mjs +2 -2
  12. package/dist/chunks/libs/eventemitter3.mjs +1 -1
  13. package/dist/chunks/libs/graphology-dag.mjs +1 -1
  14. package/dist/chunks/libs/graphology.mjs +1 -1
  15. package/dist/chunks/libs/hast-util-sanitize.mjs +1 -1
  16. package/dist/chunks/libs/hast-util-to-html.mjs +2 -2
  17. package/dist/chunks/libs/hono.mjs +1 -1
  18. package/dist/chunks/libs/immer.mjs +1 -1
  19. package/dist/chunks/libs/langium.mjs +9 -22
  20. package/dist/chunks/libs/markdown-table.mjs +1 -1
  21. package/dist/chunks/libs/mdast-util-find-and-replace.mjs +1 -1
  22. package/dist/chunks/libs/mdast-util-from-markdown.mjs +2 -2
  23. package/dist/chunks/libs/mdast-util-gfm.mjs +5 -5
  24. package/dist/chunks/libs/mdast-util-to-hast.mjs +2 -2
  25. package/dist/chunks/libs/merge-error-cause.mjs +2 -2
  26. package/dist/chunks/libs/micromark-extension-gfm.mjs +1 -1
  27. package/dist/chunks/libs/mnemonist.mjs +1 -1
  28. package/dist/chunks/libs/nano-spawn.mjs +2 -2
  29. package/dist/chunks/libs/p-queue.mjs +1 -1
  30. package/dist/chunks/libs/picomatch.mjs +1 -0
  31. package/dist/chunks/libs/pretty-ms.mjs +1 -1
  32. package/dist/chunks/libs/remark-github-blockquote-alert.mjs +1 -1
  33. package/dist/chunks/libs/remeda.mjs +1 -1
  34. package/dist/chunks/libs/ufo.mjs +1 -1
  35. package/dist/chunks/libs/unified.mjs +1 -1
  36. package/dist/chunks/libs/unstorage.mjs +1 -1
  37. package/dist/chunks/rolldown-runtime.mjs +1 -1
  38. package/dist/chunks/src.mjs +124 -104
  39. package/dist/cli.mjs +5 -1
  40. package/package.json +23 -23
  41. package/dist/chunks/libs/@chevrotain/gast.mjs +0 -1
  42. package/dist/chunks/libs/@chevrotain/utils.mjs +0 -1
  43. package/dist/chunks/libs/@lume/kiwi.mjs +0 -1
  44. package/dist/chunks/libs/bail.mjs +0 -1
  45. package/dist/chunks/libs/ccount.mjs +0 -1
  46. package/dist/chunks/libs/character-entities-html4.mjs +0 -1
  47. package/dist/chunks/libs/character-entities-legacy.mjs +0 -1
  48. package/dist/chunks/libs/citty.mjs +0 -5
  49. package/dist/chunks/libs/comma-separated-tokens.mjs +0 -1
  50. package/dist/chunks/libs/decode-named-character-reference.mjs +0 -1
  51. package/dist/chunks/libs/defu.mjs +0 -1
  52. package/dist/chunks/libs/destr.mjs +0 -1
  53. package/dist/chunks/libs/devlop.mjs +0 -1
  54. package/dist/chunks/libs/escape-string-regexp.mjs +0 -1
  55. package/dist/chunks/libs/extend.mjs +0 -1
  56. package/dist/chunks/libs/fdir.mjs +0 -1
  57. package/dist/chunks/libs/is-error-instance.mjs +0 -1
  58. package/dist/chunks/libs/is-plain-obj.mjs +0 -1
  59. package/dist/chunks/libs/isexe.mjs +0 -1
  60. package/dist/chunks/libs/json5.mjs +0 -14
  61. package/dist/chunks/libs/longest-streak.mjs +0 -1
  62. package/dist/chunks/libs/natural-compare-lite.mjs +0 -9
  63. package/dist/chunks/libs/ohash.mjs +0 -1
  64. package/dist/chunks/libs/p-limit.mjs +0 -1
  65. package/dist/chunks/libs/p-timeout.mjs +0 -1
  66. package/dist/chunks/libs/parse-ms.mjs +0 -1
  67. package/dist/chunks/libs/rehype-sanitize.mjs +0 -1
  68. package/dist/chunks/libs/rehype-stringify.mjs +0 -1
  69. package/dist/chunks/libs/remark-gfm.mjs +0 -1
  70. package/dist/chunks/libs/remark-parse.mjs +0 -1
  71. package/dist/chunks/libs/safe-stringify.mjs +0 -1
  72. package/dist/chunks/libs/strip-indent.mjs +0 -1
  73. package/dist/chunks/libs/tinyrainbow.mjs +0 -1
  74. package/dist/chunks/libs/trough.mjs +0 -1
  75. package/dist/chunks/libs/ts-graphviz.mjs +0 -1
  76. package/dist/chunks/libs/unctx.mjs +0 -1
  77. package/dist/chunks/libs/which.mjs +0 -1
  78. package/dist/chunks/libs/word-wrap.mjs +0 -12
@@ -1 +1 @@
1
- import"../rolldown-runtime.mjs";import{a as e,i as t}from"./@hono/mcp.mjs";var compose=(e,t,n)=>(r,i)=>{let a=-1;return dispatch(0);async function dispatch(o){if(o<=a)throw Error(`next() called multiple times`);a=o;let s,c=!1,l;if(e[o]?(l=e[o][0][0],r.req.routeIndex=o):l=o===e.length&&i||void 0,l)try{s=await l(r,()=>dispatch(o+1))}catch(e){if(e instanceof Error&&t)r.error=e,s=await t(e,r),c=!0;else throw e}else r.finalized===!1&&n&&(s=await n(r));return s&&(r.finalized===!1||c)&&(r.res=s),r}},n=Symbol(),parseBody=async(e,t=Object.create(null))=>{let{all:n=!1,dot:r=!1}=t,i=(e instanceof HonoRequest?e.raw.headers:e.headers).get(`Content-Type`);return i?.startsWith(`multipart/form-data`)||i?.startsWith(`application/x-www-form-urlencoded`)?parseFormData(e,{all:n,dot:r}):{}};async function parseFormData(e,t){let n=await e.formData();return n?convertFormDataToBodyData(n,t):{}}function convertFormDataToBodyData(e,t){let n=Object.create(null);return e.forEach((e,r)=>{t.all||r.endsWith(`[]`)?handleParsingAllValues(n,r,e):n[r]=e}),t.dot&&Object.entries(n).forEach(([e,t])=>{e.includes(`.`)&&(handleParsingNestedValues(n,e,t),delete n[e])}),n}var handleParsingAllValues=(e,t,n)=>{e[t]===void 0?t.endsWith(`[]`)?e[t]=[n]:e[t]=n:Array.isArray(e[t])?e[t].push(n):e[t]=[e[t],n]},handleParsingNestedValues=(e,t,n)=>{if(/(?:^|\.)__proto__\./.test(t))return;let r=e,i=t.split(`.`);i.forEach((e,t)=>{t===i.length-1?r[e]=n:((!r[e]||typeof r[e]!=`object`||Array.isArray(r[e])||r[e]instanceof File)&&(r[e]=Object.create(null)),r=r[e])})},splitPath=e=>{let t=e.split(`/`);return t[0]===``&&t.shift(),t},splitRoutingPath=e=>{let{groups:t,path:n}=extractGroupsFromPath(e);return replaceGroupMarks(splitPath(n),t)},extractGroupsFromPath=e=>{let t=[];return e=e.replace(/\{[^}]+\}/g,(e,n)=>{let r=`@${n}`;return t.push([r,e]),r}),{groups:t,path:e}},replaceGroupMarks=(e,t)=>{for(let n=t.length-1;n>=0;n--){let[r]=t[n];for(let i=e.length-1;i>=0;i--)if(e[i].includes(r)){e[i]=e[i].replace(r,t[n][1]);break}}return e},r={},getPattern=(e,t)=>{if(e===`*`)return`*`;let n=e.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);if(n){let i=`${e}#${t}`;return r[i]||(n[2]?r[i]=t&&t[0]!==`:`&&t[0]!==`*`?[i,n[1],RegExp(`^${n[2]}(?=/${t})`)]:[e,n[1],RegExp(`^${n[2]}$`)]:r[i]=[e,n[1],!0]),r[i]}return null},tryDecode=(e,t)=>{try{return t(e)}catch{return e.replace(/(?:%[0-9A-Fa-f]{2})+/g,e=>{try{return t(e)}catch{return e}})}},tryDecodeURI=e=>tryDecode(e,decodeURI),getPath=e=>{let t=e.url,n=t.indexOf(`/`,t.indexOf(`:`)+4),r=n;for(;r<t.length;r++){let e=t.charCodeAt(r);if(e===37){let e=t.indexOf(`?`,r),i=t.indexOf(`#`,r),a=e===-1?i===-1?void 0:i:i===-1?e:Math.min(e,i),o=t.slice(n,a);return tryDecodeURI(o.includes(`%25`)?o.replace(/%25/g,`%2525`):o)}else if(e===63||e===35)break}return t.slice(n,r)},getPathNoStrict=e=>{let t=getPath(e);return t.length>1&&t.at(-1)===`/`?t.slice(0,-1):t},mergePath=(e,t,...n)=>(n.length&&(t=mergePath(t,...n)),`${e?.[0]===`/`?``:`/`}${e}${t===`/`?``:`${e?.at(-1)===`/`?``:`/`}${t?.[0]===`/`?t.slice(1):t}`}`),checkOptionalParameter=e=>{if(e.charCodeAt(e.length-1)!==63||!e.includes(`:`))return null;let t=e.split(`/`),n=[],r=``;return t.forEach(e=>{if(e!==``&&!/\:/.test(e))r+=`/`+e;else if(/\:/.test(e))if(/\?/.test(e)){n.length===0&&r===``?n.push(`/`):n.push(r);let t=e.replace(`?`,``);r+=`/`+t,n.push(r)}else r+=`/`+e}),n.filter((e,t,n)=>n.indexOf(e)===t)},_decodeURI=e=>/[%+]/.test(e)?(e.indexOf(`+`)!==-1&&(e=e.replace(/\+/g,` `)),e.indexOf(`%`)===-1?e:tryDecode(e,a)):e,_getQueryParam=(e,t,n)=>{let r;if(!n&&t&&!/[%+]/.test(t)){let n=e.indexOf(`?`,8);if(n===-1)return;for(e.startsWith(t,n+1)||(n=e.indexOf(`&${t}`,n+1));n!==-1;){let r=e.charCodeAt(n+t.length+1);if(r===61){let r=n+t.length+2,i=e.indexOf(`&`,r);return _decodeURI(e.slice(r,i===-1?void 0:i))}else if(r==38||isNaN(r))return``;n=e.indexOf(`&${t}`,n+1)}if(r=/[%+]/.test(e),!r)return}let i={};r??=/[%+]/.test(e);let a=e.indexOf(`?`,8);for(;a!==-1;){let t=e.indexOf(`&`,a+1),o=e.indexOf(`=`,a);o>t&&t!==-1&&(o=-1);let s=e.slice(a+1,o===-1?t===-1?void 0:t:o);if(r&&(s=_decodeURI(s)),a=t,s===``)continue;let c;o===-1?c=``:(c=e.slice(o+1,t===-1?void 0:t),r&&(c=_decodeURI(c))),n?(i[s]&&Array.isArray(i[s])||(i[s]=[]),i[s].push(c)):i[s]??=c}return t?i[t]:i},i=_getQueryParam,getQueryParams=(e,t)=>_getQueryParam(e,t,!0),a=decodeURIComponent,tryDecodeURIComponent=e=>tryDecode(e,a),HonoRequest=class{raw;#e;#t;routeIndex=0;path;bodyCache={};constructor(e,t=`/`,n=[[]]){this.raw=e,this.path=t,this.#t=n,this.#e={}}param(e){return e?this.#n(e):this.#r()}#n(e){let t=this.#t[0][this.routeIndex][1][e],n=this.#i(t);return n&&/\%/.test(n)?tryDecodeURIComponent(n):n}#r(){let e={},t=Object.keys(this.#t[0][this.routeIndex][1]);for(let n of t){let t=this.#i(this.#t[0][this.routeIndex][1][n]);t!==void 0&&(e[n]=/\%/.test(t)?tryDecodeURIComponent(t):t)}return e}#i(e){return this.#t[1]?this.#t[1][e]:e}query(e){return i(this.url,e)}queries(e){return getQueryParams(this.url,e)}header(e){if(e)return this.raw.headers.get(e)??void 0;let t={};return this.raw.headers.forEach((e,n)=>{t[n]=e}),t}async parseBody(e){return parseBody(this,e)}#a=e=>{let{bodyCache:t,raw:n}=this,r=t[e];if(r)return r;let i=Object.keys(t)[0];return i?t[i].then(t=>(i===`json`&&(t=JSON.stringify(t)),new Response(t)[e]())):t[e]=n[e]()};json(){return this.#a(`text`).then(e=>JSON.parse(e))}text(){return this.#a(`text`)}arrayBuffer(){return this.#a(`arrayBuffer`)}blob(){return this.#a(`blob`)}formData(){return this.#a(`formData`)}addValidatedData(e,t){this.#e[e]=t}valid(e){return this.#e[e]}get url(){return this.raw.url}get method(){return this.raw.method}get[n](){return this.#t}get matchedRoutes(){return this.#t[0].map(([[,e]])=>e)}get routePath(){return this.#t[0].map(([[,e]])=>e)[this.routeIndex].path}},o=`text/plain; charset=UTF-8`,setDefaultContentType=(e,t)=>({"Content-Type":e,...t}),createResponseInstance=(e,t)=>new Response(e,t),Context=class{#e;#t;env={};#n;finalized=!1;error;#r;#i;#a;#o;#s;#c;#l;#u;#d;constructor(e,t){this.#e=e,t&&(this.#i=t.executionCtx,this.env=t.env,this.#c=t.notFoundHandler,this.#d=t.path,this.#u=t.matchResult)}get req(){return this.#t??=new HonoRequest(this.#e,this.#d,this.#u),this.#t}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.#a||=createResponseInstance(null,{headers:this.#l??=new Headers})}set res(e){if(this.#a&&e){e=createResponseInstance(e.body,e);for(let[t,n]of this.#a.headers.entries())if(t!==`content-type`)if(t===`set-cookie`){let t=this.#a.headers.getSetCookie();e.headers.delete(`set-cookie`);for(let n of t)e.headers.append(`set-cookie`,n)}else e.headers.set(t,n)}this.#a=e,this.finalized=!0}render=(...e)=>(this.#s??=e=>this.html(e),this.#s(...e));setLayout=e=>this.#o=e;getLayout=()=>this.#o;setRenderer=e=>{this.#s=e};header=(e,t,n)=>{this.finalized&&(this.#a=createResponseInstance(this.#a.body,this.#a));let r=this.#a?this.#a.headers:this.#l??=new Headers;t===void 0?r.delete(e):n?.append?r.append(e,t):r.set(e,t)};status=e=>{this.#r=e};set=(e,t)=>{this.#n??=new Map,this.#n.set(e,t)};get=e=>this.#n?this.#n.get(e):void 0;get var(){return this.#n?Object.fromEntries(this.#n):{}}#f(e,t,n){let r=this.#a?new Headers(this.#a.headers):this.#l??new Headers;if(typeof t==`object`&&`headers`in t){let e=t.headers instanceof Headers?t.headers:new Headers(t.headers);for(let[t,n]of e)t.toLowerCase()===`set-cookie`?r.append(t,n):r.set(t,n)}if(n)for(let[e,t]of Object.entries(n))if(typeof t==`string`)r.set(e,t);else{r.delete(e);for(let n of t)r.append(e,n)}return createResponseInstance(e,{status:typeof t==`number`?t:t?.status??this.#r,headers:r})}newResponse=(...e)=>this.#f(...e);body=(e,t,n)=>this.#f(e,t,n);text=(e,t,n)=>!this.#l&&!this.#r&&!t&&!n&&!this.finalized?new Response(e):this.#f(e,t,setDefaultContentType(o,n));json=(e,t,n)=>this.#f(JSON.stringify(e),t,setDefaultContentType(`application/json`,n));html=(n,r,i)=>{let res=e=>this.#f(e,r,setDefaultContentType(`text/html; charset=UTF-8`,i));return typeof n==`object`?e(n,t.Stringify,!1,{}).then(res):res(n)};redirect=(e,t)=>{let n=String(e);return this.header(`Location`,/[^\x00-\xFF]/.test(n)?encodeURI(n):n),this.newResponse(null,t??302)};notFound=()=>(this.#c??=()=>createResponseInstance(),this.#c(this))},s=[`get`,`post`,`put`,`delete`,`options`,`patch`],c=`Can not add a route since the matcher is already built.`,UnsupportedPathError=class extends Error{},l=`__COMPOSED_HANDLER`,notFoundHandler=e=>e.text(`404 Not Found`,404),errorHandler=(e,t)=>{if(`getResponse`in e){let n=e.getResponse();return t.newResponse(n.body,n)}return console.error(e),t.text(`Internal Server Error`,500)},u=class _Hono{get;post;put;delete;options;patch;all;on;use;router;getPath;_basePath=`/`;#e=`/`;routes=[];constructor(e={}){[...s,`all`].forEach(e=>{this[e]=(t,...n)=>(typeof t==`string`?this.#e=t:this.#r(e,this.#e,t),n.forEach(t=>{this.#r(e,this.#e,t)}),this)}),this.on=(e,t,...n)=>{for(let r of[t].flat()){this.#e=r;for(let t of[e].flat())n.map(e=>{this.#r(t.toUpperCase(),this.#e,e)})}return this},this.use=(e,...t)=>(typeof e==`string`?this.#e=e:(this.#e=`*`,t.unshift(e)),t.forEach(e=>{this.#r(`ALL`,this.#e,e)}),this);let{strict:t,...n}=e;Object.assign(this,n),this.getPath=t??!0?e.getPath??getPath:getPathNoStrict}#t(){let e=new _Hono({router:this.router,getPath:this.getPath});return e.errorHandler=this.errorHandler,e.#n=this.#n,e.routes=this.routes,e}#n=notFoundHandler;errorHandler=errorHandler;route(e,t){let n=this.basePath(e);return t.routes.map(e=>{let handler;t.errorHandler===errorHandler?handler=e.handler:(handler=async(n,r)=>(await compose([],t.errorHandler)(n,()=>e.handler(n,r))).res,handler[l]=e.handler),n.#r(e.method,e.path,handler)}),this}basePath(e){let t=this.#t();return t._basePath=mergePath(this._basePath,e),t}onError=e=>(this.errorHandler=e,this);notFound=e=>(this.#n=e,this);mount(e,t,n){let r,i;n&&(typeof n==`function`?i=n:(i=n.optionHandler,r=n.replaceRequest===!1?e=>e:n.replaceRequest));let a=i?e=>{let t=i(e);return Array.isArray(t)?t:[t]}:e=>{let t;try{t=e.executionCtx}catch{}return[e.env,t]};r||=(()=>{let t=mergePath(this._basePath,e),n=t===`/`?0:t.length;return e=>{let t=new URL(e.url);return t.pathname=t.pathname.slice(n)||`/`,new Request(t,e)}})();let handler=async(e,n)=>{let i=await t(r(e.req.raw),...a(e));if(i)return i;await n()};return this.#r(`ALL`,mergePath(e,`*`),handler),this}#r(e,t,n){e=e.toUpperCase(),t=mergePath(this._basePath,t);let r={basePath:this._basePath,path:t,method:e,handler:n};this.router.add(e,t,[n,r]),this.routes.push(r)}#i(e,t){if(e instanceof Error)return this.errorHandler(e,t);throw e}#a(e,t,n,r){if(r===`HEAD`)return(async()=>new Response(null,await this.#a(e,t,n,`GET`)))();let i=this.getPath(e,{env:n}),a=this.router.match(r,i),o=new Context(e,{path:i,matchResult:a,env:n,executionCtx:t,notFoundHandler:this.#n});if(a[0].length===1){let e;try{e=a[0][0][0][0](o,async()=>{o.res=await this.#n(o)})}catch(e){return this.#i(e,o)}return e instanceof Promise?e.then(e=>e||(o.finalized?o.res:this.#n(o))).catch(e=>this.#i(e,o)):e??this.#n(o)}let s=compose(a[0],this.errorHandler,this.#n);return(async()=>{try{let e=await s(o);if(!e.finalized)throw Error("Context is not finalized. Did you forget to return a Response object or `await next()`?");return e.res}catch(e){return this.#i(e,o)}})()}fetch=(e,...t)=>this.#a(e,t[1],t[0],e.method);request=(e,t,n,r)=>e instanceof Request?this.fetch(t?new Request(e,t):e,n,r):(e=e.toString(),this.fetch(new Request(/^https?:\/\//.test(e)?e:`http://localhost${mergePath(`/`,e)}`,t),n,r));fire=()=>{addEventListener(`fetch`,e=>{e.respondWith(this.#a(e.request,e,void 0,e.request.method))})}},d=[];function match(e,t){let n=this.buildAllMatchers(),match2=((e,t)=>{let r=n[e]||n.ALL,i=r[2][t];if(i)return i;let a=t.match(r[0]);if(!a)return[[],d];let o=a.indexOf(``,1);return[r[1][o],a]});return this.match=match2,match2(e,t)}var f=`[^/]+`,p=`.*`,m=`(?:|/.*)`,h=Symbol(),g=new Set(`.\\+*[^]$()`);function compareKey(e,t){return e.length===1?t.length===1?e<t?-1:1:-1:t.length===1||e===p||e===m?1:t===p||t===m?-1:e===f?1:t===f?-1:e.length===t.length?e<t?-1:1:t.length-e.length}var _=class _Node{#e;#t;#n=Object.create(null);insert(e,t,n,r,i){if(e.length===0){if(this.#e!==void 0)throw h;if(i)return;this.#e=t;return}let[a,...o]=e,s=a===`*`?o.length===0?[``,``,p]:[``,``,f]:a===`/*`?[``,``,m]:a.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/),c;if(s){let e=s[1],t=s[2]||f;if(e&&s[2]&&(t===`.*`||(t=t.replace(/^\((?!\?:)(?=[^)]+\)$)/,`(?:`),/\((?!\?:)/.test(t))))throw h;if(c=this.#n[t],!c){if(Object.keys(this.#n).some(e=>e!==p&&e!==m))throw h;if(i)return;c=this.#n[t]=new _Node,e!==``&&(c.#t=r.varIndex++)}!i&&e!==``&&n.push([e,c.#t])}else if(c=this.#n[a],!c){if(Object.keys(this.#n).some(e=>e.length>1&&e!==p&&e!==m))throw h;if(i)return;c=this.#n[a]=new _Node}c.insert(o,t,n,r,i)}buildRegExpStr(){let e=Object.keys(this.#n).sort(compareKey).map(e=>{let t=this.#n[e];return(typeof t.#t==`number`?`(${e})@${t.#t}`:g.has(e)?`\\${e}`:e)+t.buildRegExpStr()});return typeof this.#e==`number`&&e.unshift(`#${this.#e}`),e.length===0?``:e.length===1?e[0]:`(?:`+e.join(`|`)+`)`}},Trie=class{#e={varIndex:0};#t=new _;insert(e,t,n){let r=[],i=[];for(let t=0;;){let n=!1;if(e=e.replace(/\{[^}]+\}/g,e=>{let r=`@\\${t}`;return i[t]=[r,e],t++,n=!0,r}),!n)break}let a=e.match(/(?::[^\/]+)|(?:\/\*$)|./g)||[];for(let e=i.length-1;e>=0;e--){let[t]=i[e];for(let n=a.length-1;n>=0;n--)if(a[n].indexOf(t)!==-1){a[n]=a[n].replace(t,i[e][1]);break}}return this.#t.insert(a,t,r,this.#e,n),r}buildRegExp(){let e=this.#t.buildRegExpStr();if(e===``)return[/^$/,[],[]];let t=0,n=[],r=[];return e=e.replace(/#(\d+)|@(\d+)|\.\*\$/g,(e,i,a)=>i===void 0?(a===void 0||(r[Number(a)]=++t),``):(n[++t]=Number(i),`$()`)),[RegExp(`^${e}`),n,r]}},v=[/^$/,[],Object.create(null)],y=Object.create(null);function buildWildcardRegExp(e){return y[e]??=RegExp(e===`*`?``:`^${e.replace(/\/\*$|([.\\+*[^\]$()])/g,(e,t)=>t?`\\${t}`:`(?:|/.*)`)}$`)}function clearWildcardRegExpCache(){y=Object.create(null)}function buildMatcherFromPreprocessedRoutes(e){let t=new Trie,n=[];if(e.length===0)return v;let r=e.map(e=>[!/\*|\/:/.test(e[0]),...e]).sort(([e,t],[n,r])=>e?1:n?-1:t.length-r.length),i=Object.create(null);for(let e=0,a=-1,o=r.length;e<o;e++){let[o,s,c]=r[e];o?i[s]=[c.map(([e])=>[e,Object.create(null)]),d]:a++;let l;try{l=t.insert(s,a,o)}catch(e){throw e===h?new UnsupportedPathError(s):e}o||(n[a]=c.map(([e,t])=>{let n=Object.create(null);for(--t;t>=0;t--){let[e,r]=l[t];n[e]=r}return[e,n]}))}let[a,o,s]=t.buildRegExp();for(let e=0,t=n.length;e<t;e++)for(let t=0,r=n[e].length;t<r;t++){let r=n[e][t]?.[1];if(!r)continue;let i=Object.keys(r);for(let e=0,t=i.length;e<t;e++)r[i[e]]=s[r[i[e]]]}let c=[];for(let e in o)c[e]=n[o[e]];return[a,c,i]}function findMiddleware(e,t){if(e){for(let n of Object.keys(e).sort((e,t)=>t.length-e.length))if(buildWildcardRegExp(n).test(t))return[...e[n]]}}var RegExpRouter=class{name=`RegExpRouter`;#e;#t;constructor(){this.#e={ALL:Object.create(null)},this.#t={ALL:Object.create(null)}}add(e,t,n){let r=this.#e,i=this.#t;if(!r||!i)throw Error(c);r[e]||[r,i].forEach(t=>{t[e]=Object.create(null),Object.keys(t.ALL).forEach(n=>{t[e][n]=[...t.ALL[n]]})}),t===`/*`&&(t=`*`);let a=(t.match(/\/:/g)||[]).length;if(/\*$/.test(t)){let o=buildWildcardRegExp(t);e===`ALL`?Object.keys(r).forEach(e=>{r[e][t]||=findMiddleware(r[e],t)||findMiddleware(r.ALL,t)||[]}):r[e][t]||=findMiddleware(r[e],t)||findMiddleware(r.ALL,t)||[],Object.keys(r).forEach(t=>{(e===`ALL`||e===t)&&Object.keys(r[t]).forEach(e=>{o.test(e)&&r[t][e].push([n,a])})}),Object.keys(i).forEach(t=>{(e===`ALL`||e===t)&&Object.keys(i[t]).forEach(e=>o.test(e)&&i[t][e].push([n,a]))});return}let o=checkOptionalParameter(t)||[t];for(let t=0,s=o.length;t<s;t++){let c=o[t];Object.keys(i).forEach(o=>{(e===`ALL`||e===o)&&(i[o][c]||=[...findMiddleware(r[o],c)||findMiddleware(r.ALL,c)||[]],i[o][c].push([n,a-s+t+1]))})}}match=match;buildAllMatchers(){let e=Object.create(null);return Object.keys(this.#t).concat(Object.keys(this.#e)).forEach(t=>{e[t]||=this.#n(t)}),this.#e=this.#t=void 0,clearWildcardRegExpCache(),e}#n(e){let t=[],n=e===`ALL`;return[this.#e,this.#t].forEach(r=>{let i=r[e]?Object.keys(r[e]).map(t=>[t,r[e][t]]):[];i.length===0?e!==`ALL`&&t.push(...Object.keys(r.ALL).map(e=>[e,r.ALL[e]])):(n||=!0,t.push(...i))}),n?buildMatcherFromPreprocessedRoutes(t):null}},SmartRouter=class{name=`SmartRouter`;#e=[];#t=[];constructor(e){this.#e=e.routers}add(e,t,n){if(!this.#t)throw Error(c);this.#t.push([e,t,n])}match(e,t){if(!this.#t)throw Error(`Fatal error`);let n=this.#e,r=this.#t,i=n.length,a=0,o;for(;a<i;a++){let i=n[a];try{for(let e=0,t=r.length;e<t;e++)i.add(...r[e]);o=i.match(e,t)}catch(e){if(e instanceof UnsupportedPathError)continue;throw e}this.match=i.match.bind(i),this.#e=[i],this.#t=void 0;break}if(a===i)throw Error(`Fatal error`);return this.name=`SmartRouter + ${this.activeRouter.name}`,o}get activeRouter(){if(this.#t||this.#e.length!==1)throw Error(`No active router has been determined yet.`);return this.#e[0]}},b=Object.create(null),hasChildren=e=>{for(let t in e)return!0;return!1},x=class _Node{#e;#t;#n;#r=0;#i=b;constructor(e,t,n){if(this.#t=n||Object.create(null),this.#e=[],e&&t){let n=Object.create(null);n[e]={handler:t,possibleKeys:[],score:0},this.#e=[n]}this.#n=[]}insert(e,t,n){this.#r=++this.#r;let r=this,i=splitRoutingPath(t),a=[];for(let e=0,t=i.length;e<t;e++){let t=i[e],n=i[e+1],o=getPattern(t,n),s=Array.isArray(o)?o[0]:t;if(s in r.#t){r=r.#t[s],o&&a.push(o[1]);continue}r.#t[s]=new _Node,o&&(r.#n.push(o),a.push(o[1])),r=r.#t[s]}return r.#e.push({[e]:{handler:n,possibleKeys:a.filter((e,t,n)=>n.indexOf(e)===t),score:this.#r}}),r}#a(e,t,n,r,i){for(let a=0,o=t.#e.length;a<o;a++){let o=t.#e[a],s=o[n]||o.ALL,c={};if(s!==void 0&&(s.params=Object.create(null),e.push(s),r!==b||i&&i!==b))for(let e=0,t=s.possibleKeys.length;e<t;e++){let t=s.possibleKeys[e],n=c[s.score];s.params[t]=i?.[t]&&!n?i[t]:r[t]??i?.[t],c[s.score]=!0}}}search(e,t){let n=[];this.#i=b;let r=[this],i=splitPath(t),a=[],o=i.length,s=null;for(let c=0;c<o;c++){let l=i[c],u=c===o-1,d=[];for(let f=0,p=r.length;f<p;f++){let p=r[f],m=p.#t[l];m&&(m.#i=p.#i,u?(m.#t[`*`]&&this.#a(n,m.#t[`*`],e,p.#i),this.#a(n,m,e,p.#i)):d.push(m));for(let r=0,f=p.#n.length;r<f;r++){let f=p.#n[r],m=p.#i===b?{}:{...p.#i};if(f===`*`){let t=p.#t[`*`];t&&(this.#a(n,t,e,p.#i),t.#i=m,d.push(t));continue}let[h,g,_]=f;if(!l&&!(_ instanceof RegExp))continue;let v=p.#t[h];if(_ instanceof RegExp){if(s===null){s=Array(o);let e=+(t[0]===`/`);for(let t=0;t<o;t++)s[t]=e,e+=i[t].length+1}let r=t.substring(s[c]),l=_.exec(r);if(l){if(m[g]=l[0],this.#a(n,v,e,p.#i,m),hasChildren(v.#t)){v.#i=m;let e=l[0].match(/\//)?.length??0;(a[e]||=[]).push(v)}continue}}(_===!0||_.test(l))&&(m[g]=l,u?(this.#a(n,v,e,m,p.#i),v.#t[`*`]&&this.#a(n,v.#t[`*`],e,m,p.#i)):(v.#i=m,d.push(v)))}}let f=a.shift();r=f?d.concat(f):d}return n.length>1&&n.sort((e,t)=>e.score-t.score),[n.map(({handler:e,params:t})=>[e,t])]}},TrieRouter=class{name=`TrieRouter`;#e;constructor(){this.#e=new x}add(e,t,n){let r=checkOptionalParameter(t);if(r){for(let t=0,i=r.length;t<i;t++)this.#e.insert(e,r[t],n);return}this.#e.insert(e,t,n)}match(e,t){return this.#e.search(e,t)}},Hono=class extends u{constructor(e={}){super(e),this.router=e.router??new SmartRouter({routers:[new RegExpRouter,new TrieRouter]})}};export{Hono as t};
1
+ import"../rolldown-runtime.mjs";import{a as e,i as t}from"./@hono/mcp.mjs";var compose=(e,t,n)=>(r,i)=>{let a=-1;return dispatch(0);async function dispatch(o){if(o<=a)throw Error(`next() called multiple times`);a=o;let s,c=!1,l;if(e[o]?(l=e[o][0][0],r.req.routeIndex=o):l=o===e.length&&i||void 0,l)try{s=await l(r,()=>dispatch(o+1))}catch(e){if(e instanceof Error&&t)r.error=e,s=await t(e,r),c=!0;else throw e}else r.finalized===!1&&n&&(s=await n(r));return s&&(r.finalized===!1||c)&&(r.res=s),r}},n=Symbol(),parseBody=async(e,t=Object.create(null))=>{let{all:n=!1,dot:r=!1}=t,i=(e instanceof HonoRequest?e.raw.headers:e.headers).get(`Content-Type`);return i?.startsWith(`multipart/form-data`)||i?.startsWith(`application/x-www-form-urlencoded`)?parseFormData(e,{all:n,dot:r}):{}};async function parseFormData(e,t){let n=await e.formData();return n?convertFormDataToBodyData(n,t):{}}function convertFormDataToBodyData(e,t){let n=Object.create(null);return e.forEach((e,r)=>{t.all||r.endsWith(`[]`)?handleParsingAllValues(n,r,e):n[r]=e}),t.dot&&Object.entries(n).forEach(([e,t])=>{e.includes(`.`)&&(handleParsingNestedValues(n,e,t),delete n[e])}),n}var handleParsingAllValues=(e,t,n)=>{e[t]===void 0?t.endsWith(`[]`)?e[t]=[n]:e[t]=n:Array.isArray(e[t])?e[t].push(n):e[t]=[e[t],n]},handleParsingNestedValues=(e,t,n)=>{if(/(?:^|\.)__proto__\./.test(t))return;let r=e,i=t.split(`.`);i.forEach((e,t)=>{t===i.length-1?r[e]=n:((!r[e]||typeof r[e]!=`object`||Array.isArray(r[e])||r[e]instanceof File)&&(r[e]=Object.create(null)),r=r[e])})},splitPath=e=>{let t=e.split(`/`);return t[0]===``&&t.shift(),t},splitRoutingPath=e=>{let{groups:t,path:n}=extractGroupsFromPath(e);return replaceGroupMarks(splitPath(n),t)},extractGroupsFromPath=e=>{let t=[];return e=e.replace(/\{[^}]+\}/g,(e,n)=>{let r=`@${n}`;return t.push([r,e]),r}),{groups:t,path:e}},replaceGroupMarks=(e,t)=>{for(let n=t.length-1;n>=0;n--){let[r]=t[n];for(let i=e.length-1;i>=0;i--)if(e[i].includes(r)){e[i]=e[i].replace(r,t[n][1]);break}}return e},r={},getPattern=(e,t)=>{if(e===`*`)return`*`;let n=e.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);if(n){let i=`${e}#${t}`;return r[i]||(n[2]?r[i]=t&&t[0]!==`:`&&t[0]!==`*`?[i,n[1],RegExp(`^${n[2]}(?=/${t})`)]:[e,n[1],RegExp(`^${n[2]}$`)]:r[i]=[e,n[1],!0]),r[i]}return null},tryDecode=(e,t)=>{try{return t(e)}catch{return e.replace(/(?:%[0-9A-Fa-f]{2})+/g,e=>{try{return t(e)}catch{return e}})}},tryDecodeURI=e=>tryDecode(e,decodeURI),getPath=e=>{let t=e.url,n=t.indexOf(`/`,t.indexOf(`:`)+4),r=n;for(;r<t.length;r++){let e=t.charCodeAt(r);if(e===37){let e=t.indexOf(`?`,r),i=t.indexOf(`#`,r),a=e===-1?i===-1?void 0:i:i===-1?e:Math.min(e,i),o=t.slice(n,a);return tryDecodeURI(o.includes(`%25`)?o.replace(/%25/g,`%2525`):o)}else if(e===63||e===35)break}return t.slice(n,r)},getPathNoStrict=e=>{let t=getPath(e);return t.length>1&&t.at(-1)===`/`?t.slice(0,-1):t},mergePath=(e,t,...n)=>(n.length&&(t=mergePath(t,...n)),`${e?.[0]===`/`?``:`/`}${e}${t===`/`?``:`${e?.at(-1)===`/`?``:`/`}${t?.[0]===`/`?t.slice(1):t}`}`),checkOptionalParameter=e=>{if(e.charCodeAt(e.length-1)!==63||!e.includes(`:`))return null;let t=e.split(`/`),n=[],r=``;return t.forEach(e=>{if(e!==``&&!/\:/.test(e))r+=`/`+e;else if(/\:/.test(e))if(/\?/.test(e)){n.length===0&&r===``?n.push(`/`):n.push(r);let t=e.replace(`?`,``);r+=`/`+t,n.push(r)}else r+=`/`+e}),n.filter((e,t,n)=>n.indexOf(e)===t)},_decodeURI=e=>/[%+]/.test(e)?(e.indexOf(`+`)!==-1&&(e=e.replace(/\+/g,` `)),e.indexOf(`%`)===-1?e:tryDecode(e,a)):e,_getQueryParam=(e,t,n)=>{let r;if(!n&&t&&!/[%+]/.test(t)){let n=e.indexOf(`?`,8);if(n===-1)return;for(e.startsWith(t,n+1)||(n=e.indexOf(`&${t}`,n+1));n!==-1;){let r=e.charCodeAt(n+t.length+1);if(r===61){let r=n+t.length+2,i=e.indexOf(`&`,r);return _decodeURI(e.slice(r,i===-1?void 0:i))}else if(r==38||isNaN(r))return``;n=e.indexOf(`&${t}`,n+1)}if(r=/[%+]/.test(e),!r)return}let i={};r??=/[%+]/.test(e);let a=e.indexOf(`?`,8);for(;a!==-1;){let t=e.indexOf(`&`,a+1),o=e.indexOf(`=`,a);o>t&&t!==-1&&(o=-1);let s=e.slice(a+1,o===-1?t===-1?void 0:t:o);if(r&&(s=_decodeURI(s)),a=t,s===``)continue;let c;o===-1?c=``:(c=e.slice(o+1,t===-1?void 0:t),r&&(c=_decodeURI(c))),n?(i[s]&&Array.isArray(i[s])||(i[s]=[]),i[s].push(c)):i[s]??=c}return t?i[t]:i},i=_getQueryParam,getQueryParams=(e,t)=>_getQueryParam(e,t,!0),a=decodeURIComponent,tryDecodeURIComponent=e=>tryDecode(e,a),HonoRequest=class{raw;#e;#t;routeIndex=0;path;bodyCache={};constructor(e,t=`/`,n=[[]]){this.raw=e,this.path=t,this.#t=n,this.#e={}}param(e){return e?this.#n(e):this.#r()}#n(e){let t=this.#t[0][this.routeIndex][1][e],n=this.#i(t);return n&&/\%/.test(n)?tryDecodeURIComponent(n):n}#r(){let e={},t=Object.keys(this.#t[0][this.routeIndex][1]);for(let n of t){let t=this.#i(this.#t[0][this.routeIndex][1][n]);t!==void 0&&(e[n]=/\%/.test(t)?tryDecodeURIComponent(t):t)}return e}#i(e){return this.#t[1]?this.#t[1][e]:e}query(e){return i(this.url,e)}queries(e){return getQueryParams(this.url,e)}header(e){if(e)return this.raw.headers.get(e)??void 0;let t={};return this.raw.headers.forEach((e,n)=>{t[n]=e}),t}async parseBody(e){return parseBody(this,e)}#a=e=>{let{bodyCache:t,raw:n}=this,r=t[e];if(r)return r;let i=Object.keys(t)[0];return i?t[i].then(t=>(i===`json`&&(t=JSON.stringify(t)),new Response(t)[e]())):t[e]=n[e]()};json(){return this.#a(`text`).then(e=>JSON.parse(e))}text(){return this.#a(`text`)}arrayBuffer(){return this.#a(`arrayBuffer`)}bytes(){return this.#a(`arrayBuffer`).then(e=>new Uint8Array(e))}blob(){return this.#a(`blob`)}formData(){return this.#a(`formData`)}addValidatedData(e,t){this.#e[e]=t}valid(e){return this.#e[e]}get url(){return this.raw.url}get method(){return this.raw.method}get[n](){return this.#t}get matchedRoutes(){return this.#t[0].map(([[,e]])=>e)}get routePath(){return this.#t[0].map(([[,e]])=>e)[this.routeIndex].path}},o=`text/plain; charset=UTF-8`,setDefaultContentType=(e,t)=>({"Content-Type":e,...t}),createResponseInstance=(e,t)=>new Response(e,t),Context=class{#e;#t;env={};#n;finalized=!1;error;#r;#i;#a;#o;#s;#c;#l;#u;#d;constructor(e,t){this.#e=e,t&&(this.#i=t.executionCtx,this.env=t.env,this.#c=t.notFoundHandler,this.#d=t.path,this.#u=t.matchResult)}get req(){return this.#t??=new HonoRequest(this.#e,this.#d,this.#u),this.#t}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.#a||=createResponseInstance(null,{headers:this.#l??=new Headers})}set res(e){if(this.#a&&e){e=createResponseInstance(e.body,e);for(let[t,n]of this.#a.headers.entries())if(t!==`content-type`)if(t===`set-cookie`){let t=this.#a.headers.getSetCookie();e.headers.delete(`set-cookie`);for(let n of t)e.headers.append(`set-cookie`,n)}else e.headers.set(t,n)}this.#a=e,this.finalized=!0}render=(...e)=>(this.#s??=e=>this.html(e),this.#s(...e));setLayout=e=>this.#o=e;getLayout=()=>this.#o;setRenderer=e=>{this.#s=e};header=(e,t,n)=>{this.finalized&&(this.#a=createResponseInstance(this.#a.body,this.#a));let r=this.#a?this.#a.headers:this.#l??=new Headers;t===void 0?r.delete(e):n?.append?r.append(e,t):r.set(e,t)};status=e=>{this.#r=e};set=(e,t)=>{this.#n??=new Map,this.#n.set(e,t)};get=e=>this.#n?this.#n.get(e):void 0;get var(){return this.#n?Object.fromEntries(this.#n):{}}#f(e,t,n){let r=this.#a?new Headers(this.#a.headers):this.#l??new Headers;if(typeof t==`object`&&`headers`in t){let e=t.headers instanceof Headers?t.headers:new Headers(t.headers);for(let[t,n]of e)t.toLowerCase()===`set-cookie`?r.append(t,n):r.set(t,n)}if(n)for(let[e,t]of Object.entries(n))if(typeof t==`string`)r.set(e,t);else{r.delete(e);for(let n of t)r.append(e,n)}return createResponseInstance(e,{status:typeof t==`number`?t:t?.status??this.#r,headers:r})}newResponse=(...e)=>this.#f(...e);body=(e,t,n)=>this.#f(e,t,n);text=(e,t,n)=>!this.#l&&!this.#r&&!t&&!n&&!this.finalized?new Response(e):this.#f(e,t,setDefaultContentType(o,n));json=(e,t,n)=>this.#f(JSON.stringify(e),t,setDefaultContentType(`application/json`,n));html=(n,r,i)=>{let res=e=>this.#f(e,r,setDefaultContentType(`text/html; charset=UTF-8`,i));return typeof n==`object`?e(n,t.Stringify,!1,{}).then(res):res(n)};redirect=(e,t)=>{let n=String(e);return this.header(`Location`,/[^\x00-\xFF]/.test(n)?encodeURI(n):n),this.newResponse(null,t??302)};notFound=()=>(this.#c??=()=>createResponseInstance(),this.#c(this))},s=[`get`,`post`,`put`,`delete`,`options`,`patch`],c=`Can not add a route since the matcher is already built.`,UnsupportedPathError=class extends Error{},l=`__COMPOSED_HANDLER`,notFoundHandler=e=>e.text(`404 Not Found`,404),errorHandler=(e,t)=>{if(`getResponse`in e){let n=e.getResponse();return t.newResponse(n.body,n)}return console.error(e),t.text(`Internal Server Error`,500)},u=class _Hono{get;post;put;delete;options;patch;all;on;use;router;getPath;_basePath=`/`;#e=`/`;routes=[];constructor(e={}){[...s,`all`].forEach(e=>{this[e]=(t,...n)=>(typeof t==`string`?this.#e=t:this.#r(e,this.#e,t),n.forEach(t=>{this.#r(e,this.#e,t)}),this)}),this.on=(e,t,...n)=>{for(let r of[t].flat()){this.#e=r;for(let t of[e].flat())n.map(e=>{this.#r(t.toUpperCase(),this.#e,e)})}return this},this.use=(e,...t)=>(typeof e==`string`?this.#e=e:(this.#e=`*`,t.unshift(e)),t.forEach(e=>{this.#r(`ALL`,this.#e,e)}),this);let{strict:t,...n}=e;Object.assign(this,n),this.getPath=t??!0?e.getPath??getPath:getPathNoStrict}#t(){let e=new _Hono({router:this.router,getPath:this.getPath});return e.errorHandler=this.errorHandler,e.#n=this.#n,e.routes=this.routes,e}#n=notFoundHandler;errorHandler=errorHandler;route(e,t){let n=this.basePath(e);return t.routes.map(e=>{let handler;t.errorHandler===errorHandler?handler=e.handler:(handler=async(n,r)=>(await compose([],t.errorHandler)(n,()=>e.handler(n,r))).res,handler[l]=e.handler),n.#r(e.method,e.path,handler,e.basePath)}),this}basePath(e){let t=this.#t();return t._basePath=mergePath(this._basePath,e),t}onError=e=>(this.errorHandler=e,this);notFound=e=>(this.#n=e,this);mount(e,t,n){let r,i;n&&(typeof n==`function`?i=n:(i=n.optionHandler,r=n.replaceRequest===!1?e=>e:n.replaceRequest));let a=i?e=>{let t=i(e);return Array.isArray(t)?t:[t]}:e=>{let t;try{t=e.executionCtx}catch{}return[e.env,t]};r||=(()=>{let t=mergePath(this._basePath,e),n=t===`/`?0:t.length;return e=>{let t=new URL(e.url);return t.pathname=this.getPath(e).slice(n)||`/`,new Request(t,e)}})();let handler=async(e,n)=>{let i=await t(r(e.req.raw),...a(e));if(i)return i;await n()};return this.#r(`ALL`,mergePath(e,`*`),handler),this}#r(e,t,n,r){e=e.toUpperCase(),t=mergePath(this._basePath,t);let i={basePath:r===void 0?this._basePath:mergePath(this._basePath,r),path:t,method:e,handler:n};this.router.add(e,t,[n,i]),this.routes.push(i)}#i(e,t){if(e instanceof Error)return this.errorHandler(e,t);throw e}#a(e,t,n,r){if(r===`HEAD`)return(async()=>new Response(null,await this.#a(e,t,n,`GET`)))();let i=this.getPath(e,{env:n}),a=this.router.match(r,i),o=new Context(e,{path:i,matchResult:a,env:n,executionCtx:t,notFoundHandler:this.#n});if(a[0].length===1){let e;try{e=a[0][0][0][0](o,async()=>{o.res=await this.#n(o)})}catch(e){return this.#i(e,o)}return e instanceof Promise?e.then(e=>e||(o.finalized?o.res:this.#n(o))).catch(e=>this.#i(e,o)):e??this.#n(o)}let s=compose(a[0],this.errorHandler,this.#n);return(async()=>{try{let e=await s(o);if(!e.finalized)throw Error("Context is not finalized. Did you forget to return a Response object or `await next()`?");return e.res}catch(e){return this.#i(e,o)}})()}fetch=(e,...t)=>this.#a(e,t[1],t[0],e.method);request=(e,t,n,r)=>e instanceof Request?this.fetch(t?new Request(e,t):e,n,r):(e=e.toString(),this.fetch(new Request(/^https?:\/\//.test(e)?e:`http://localhost${mergePath(`/`,e)}`,t),n,r));fire=()=>{addEventListener(`fetch`,e=>{e.respondWith(this.#a(e.request,e,void 0,e.request.method))})}},d=[];function match(e,t){let n=this.buildAllMatchers(),match2=((e,t)=>{let r=n[e]||n.ALL,i=r[2][t];if(i)return i;let a=t.match(r[0]);if(!a)return[[],d];let o=a.indexOf(``,1);return[r[1][o],a]});return this.match=match2,match2(e,t)}var f=`[^/]+`,p=`.*`,m=`(?:|/.*)`,h=Symbol(),g=new Set(`.\\+*[^]$()`);function compareKey(e,t){return e.length===1?t.length===1?e<t?-1:1:-1:t.length===1||e===p||e===m?1:t===p||t===m?-1:e===f?1:t===f?-1:e.length===t.length?e<t?-1:1:t.length-e.length}var _=class _Node{#e;#t;#n=Object.create(null);insert(e,t,n,r,i){if(e.length===0){if(this.#e!==void 0)throw h;if(i)return;this.#e=t;return}let[a,...o]=e,s=a===`*`?o.length===0?[``,``,p]:[``,``,f]:a===`/*`?[``,``,m]:a.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/),c;if(s){let e=s[1],t=s[2]||f;if(e&&s[2]&&(t===`.*`||(t=t.replace(/^\((?!\?:)(?=[^)]+\)$)/,`(?:`),/\((?!\?:)/.test(t))))throw h;if(c=this.#n[t],!c){if(Object.keys(this.#n).some(e=>e!==p&&e!==m))throw h;if(i)return;c=this.#n[t]=new _Node,e!==``&&(c.#t=r.varIndex++)}!i&&e!==``&&n.push([e,c.#t])}else if(c=this.#n[a],!c){if(Object.keys(this.#n).some(e=>e.length>1&&e!==p&&e!==m))throw h;if(i)return;c=this.#n[a]=new _Node}c.insert(o,t,n,r,i)}buildRegExpStr(){let e=Object.keys(this.#n).sort(compareKey).map(e=>{let t=this.#n[e];return(typeof t.#t==`number`?`(${e})@${t.#t}`:g.has(e)?`\\${e}`:e)+t.buildRegExpStr()});return typeof this.#e==`number`&&e.unshift(`#${this.#e}`),e.length===0?``:e.length===1?e[0]:`(?:`+e.join(`|`)+`)`}},Trie=class{#e={varIndex:0};#t=new _;insert(e,t,n){let r=[],i=[];for(let t=0;;){let n=!1;if(e=e.replace(/\{[^}]+\}/g,e=>{let r=`@\\${t}`;return i[t]=[r,e],t++,n=!0,r}),!n)break}let a=e.match(/(?::[^\/]+)|(?:\/\*$)|./g)||[];for(let e=i.length-1;e>=0;e--){let[t]=i[e];for(let n=a.length-1;n>=0;n--)if(a[n].indexOf(t)!==-1){a[n]=a[n].replace(t,i[e][1]);break}}return this.#t.insert(a,t,r,this.#e,n),r}buildRegExp(){let e=this.#t.buildRegExpStr();if(e===``)return[/^$/,[],[]];let t=0,n=[],r=[];return e=e.replace(/#(\d+)|@(\d+)|\.\*\$/g,(e,i,a)=>i===void 0?(a===void 0||(r[Number(a)]=++t),``):(n[++t]=Number(i),`$()`)),[RegExp(`^${e}`),n,r]}},v=[/^$/,[],Object.create(null)],y=Object.create(null);function buildWildcardRegExp(e){return y[e]??=RegExp(e===`*`?``:`^${e.replace(/\/\*$|([.\\+*[^\]$()])/g,(e,t)=>t?`\\${t}`:`(?:|/.*)`)}$`)}function clearWildcardRegExpCache(){y=Object.create(null)}function buildMatcherFromPreprocessedRoutes(e){let t=new Trie,n=[];if(e.length===0)return v;let r=e.map(e=>[!/\*|\/:/.test(e[0]),...e]).sort(([e,t],[n,r])=>e?1:n?-1:t.length-r.length),i=Object.create(null);for(let e=0,a=-1,o=r.length;e<o;e++){let[o,s,c]=r[e];o?i[s]=[c.map(([e])=>[e,Object.create(null)]),d]:a++;let l;try{l=t.insert(s,a,o)}catch(e){throw e===h?new UnsupportedPathError(s):e}o||(n[a]=c.map(([e,t])=>{let n=Object.create(null);for(--t;t>=0;t--){let[e,r]=l[t];n[e]=r}return[e,n]}))}let[a,o,s]=t.buildRegExp();for(let e=0,t=n.length;e<t;e++)for(let t=0,r=n[e].length;t<r;t++){let r=n[e][t]?.[1];if(!r)continue;let i=Object.keys(r);for(let e=0,t=i.length;e<t;e++)r[i[e]]=s[r[i[e]]]}let c=[];for(let e in o)c[e]=n[o[e]];return[a,c,i]}function findMiddleware(e,t){if(e){for(let n of Object.keys(e).sort((e,t)=>t.length-e.length))if(buildWildcardRegExp(n).test(t))return[...e[n]]}}var RegExpRouter=class{name=`RegExpRouter`;#e;#t;constructor(){this.#e={ALL:Object.create(null)},this.#t={ALL:Object.create(null)}}add(e,t,n){let r=this.#e,i=this.#t;if(!r||!i)throw Error(c);r[e]||[r,i].forEach(t=>{t[e]=Object.create(null),Object.keys(t.ALL).forEach(n=>{t[e][n]=[...t.ALL[n]]})}),t===`/*`&&(t=`*`);let a=(t.match(/\/:/g)||[]).length;if(/\*$/.test(t)){let o=buildWildcardRegExp(t);e===`ALL`?Object.keys(r).forEach(e=>{r[e][t]||=findMiddleware(r[e],t)||findMiddleware(r.ALL,t)||[]}):r[e][t]||=findMiddleware(r[e],t)||findMiddleware(r.ALL,t)||[],Object.keys(r).forEach(t=>{(e===`ALL`||e===t)&&Object.keys(r[t]).forEach(e=>{o.test(e)&&r[t][e].push([n,a])})}),Object.keys(i).forEach(t=>{(e===`ALL`||e===t)&&Object.keys(i[t]).forEach(e=>o.test(e)&&i[t][e].push([n,a]))});return}let o=checkOptionalParameter(t)||[t];for(let t=0,s=o.length;t<s;t++){let c=o[t];Object.keys(i).forEach(o=>{(e===`ALL`||e===o)&&(i[o][c]||=[...findMiddleware(r[o],c)||findMiddleware(r.ALL,c)||[]],i[o][c].push([n,a-s+t+1]))})}}match=match;buildAllMatchers(){let e=Object.create(null);return Object.keys(this.#t).concat(Object.keys(this.#e)).forEach(t=>{e[t]||=this.#n(t)}),this.#e=this.#t=void 0,clearWildcardRegExpCache(),e}#n(e){let t=[],n=e===`ALL`;return[this.#e,this.#t].forEach(r=>{let i=r[e]?Object.keys(r[e]).map(t=>[t,r[e][t]]):[];i.length===0?e!==`ALL`&&t.push(...Object.keys(r.ALL).map(e=>[e,r.ALL[e]])):(n||=!0,t.push(...i))}),n?buildMatcherFromPreprocessedRoutes(t):null}},SmartRouter=class{name=`SmartRouter`;#e=[];#t=[];constructor(e){this.#e=e.routers}add(e,t,n){if(!this.#t)throw Error(c);this.#t.push([e,t,n])}match(e,t){if(!this.#t)throw Error(`Fatal error`);let n=this.#e,r=this.#t,i=n.length,a=0,o;for(;a<i;a++){let i=n[a];try{for(let e=0,t=r.length;e<t;e++)i.add(...r[e]);o=i.match(e,t)}catch(e){if(e instanceof UnsupportedPathError)continue;throw e}this.match=i.match.bind(i),this.#e=[i],this.#t=void 0;break}if(a===i)throw Error(`Fatal error`);return this.name=`SmartRouter + ${this.activeRouter.name}`,o}get activeRouter(){if(this.#t||this.#e.length!==1)throw Error(`No active router has been determined yet.`);return this.#e[0]}},b=Object.create(null),hasChildren=e=>{for(let t in e)return!0;return!1},x=class _Node{#e;#t;#n;#r=0;#i=b;constructor(e,t,n){if(this.#t=n||Object.create(null),this.#e=[],e&&t){let n=Object.create(null);n[e]={handler:t,possibleKeys:[],score:0},this.#e=[n]}this.#n=[]}insert(e,t,n){this.#r=++this.#r;let r=this,i=splitRoutingPath(t),a=[];for(let e=0,t=i.length;e<t;e++){let t=i[e],n=i[e+1],o=getPattern(t,n),s=Array.isArray(o)?o[0]:t;if(s in r.#t){r=r.#t[s],o&&a.push(o[1]);continue}r.#t[s]=new _Node,o&&(r.#n.push(o),a.push(o[1])),r=r.#t[s]}return r.#e.push({[e]:{handler:n,possibleKeys:a.filter((e,t,n)=>n.indexOf(e)===t),score:this.#r}}),r}#a(e,t,n,r,i){for(let a=0,o=t.#e.length;a<o;a++){let o=t.#e[a],s=o[n]||o.ALL,c={};if(s!==void 0&&(s.params=Object.create(null),e.push(s),r!==b||i&&i!==b))for(let e=0,t=s.possibleKeys.length;e<t;e++){let t=s.possibleKeys[e],n=c[s.score];s.params[t]=i?.[t]&&!n?i[t]:r[t]??i?.[t],c[s.score]=!0}}}search(e,t){let n=[];this.#i=b;let r=[this],i=splitPath(t),a=[],o=i.length,s=null;for(let c=0;c<o;c++){let l=i[c],u=c===o-1,d=[];for(let f=0,p=r.length;f<p;f++){let p=r[f],m=p.#t[l];m&&(m.#i=p.#i,u?(m.#t[`*`]&&this.#a(n,m.#t[`*`],e,p.#i),this.#a(n,m,e,p.#i)):d.push(m));for(let r=0,f=p.#n.length;r<f;r++){let f=p.#n[r],m=p.#i===b?{}:{...p.#i};if(f===`*`){let t=p.#t[`*`];t&&(this.#a(n,t,e,p.#i),t.#i=m,d.push(t));continue}let[h,g,_]=f;if(!l&&!(_ instanceof RegExp))continue;let v=p.#t[h];if(_ instanceof RegExp){if(s===null){s=Array(o);let e=+(t[0]===`/`);for(let t=0;t<o;t++)s[t]=e,e+=i[t].length+1}let r=t.substring(s[c]),l=_.exec(r);if(l){if(m[g]=l[0],this.#a(n,v,e,p.#i,m),hasChildren(v.#t)){v.#i=m;let e=l[0].match(/\//)?.length??0;(a[e]||=[]).push(v)}continue}}(_===!0||_.test(l))&&(m[g]=l,u?(this.#a(n,v,e,m,p.#i),v.#t[`*`]&&this.#a(n,v.#t[`*`],e,m,p.#i)):(v.#i=m,d.push(v)))}}let f=a.shift();r=f?d.concat(f):d}return n.length>1&&n.sort((e,t)=>e.score-t.score),[n.map(({handler:e,params:t})=>[e,t])]}},TrieRouter=class{name=`TrieRouter`;#e;constructor(){this.#e=new x}add(e,t,n){let r=checkOptionalParameter(t);if(r){for(let t=0,i=r.length;t<i;t++)this.#e.insert(e,r[t],n);return}this.#e.insert(e,t,n)}match(e,t){return this.#e.search(e,t)}},Hono=class extends u{constructor(e={}){super(e),this.router=e.router??new SmartRouter({routers:[new RegExpRouter,new TrieRouter]})}};export{Hono as t};
@@ -1 +1 @@
1
- import"../rolldown-runtime.mjs";var e=Symbol.for(`immer-nothing`),t=Symbol.for(`immer-draftable`),n=Symbol.for(`immer-state`);function die(e,...t){throw Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var r=Object,i=r.getPrototypeOf,a=`constructor`,o=`prototype`,s=`configurable`,c=`enumerable`,l=`writable`,u=`value`,isDraft=e=>!!e&&!!e[n];function isDraftable(e){return e?isPlainObject(e)||p(e)||!!e[t]||!!e[a]?.[t]||isMap(e)||isSet(e):!1}var d=r[o][a].toString(),f=new WeakMap;function isPlainObject(e){if(!e||!isObjectish(e))return!1;let t=i(e);if(t===null||t===r[o])return!0;let n=r.hasOwnProperty.call(t,a)&&t[a];if(n===Object)return!0;if(!isFunction(n))return!1;let s=f.get(n);return s===void 0&&(s=Function.toString.call(n),f.set(n,s)),s===d}function each(e,t,n=!0){getArchtype(e)===0?(n?Reflect.ownKeys(e):r.keys(e)).forEach(n=>{t(n,e[n],e)}):e.forEach((n,r)=>t(r,n,e))}function getArchtype(e){let t=e[n];return t?t.type_:p(e)?1:isMap(e)?2:isSet(e)?3:0}var has=(e,t,n=getArchtype(e))=>n===2?e.has(t):r[o].hasOwnProperty.call(e,t),get=(e,t,n=getArchtype(e))=>n===2?e.get(t):e[t],set=(e,t,n,r=getArchtype(e))=>{r===2?e.set(t,n):r===3?e.add(n):e[t]=n};function is(e,t){return e===t?e!==0||1/e==1/t:e!==e&&t!==t}var p=Array.isArray,isMap=e=>e instanceof Map,isSet=e=>e instanceof Set,isObjectish=e=>typeof e==`object`,isFunction=e=>typeof e==`function`,isBoolean=e=>typeof e==`boolean`;function isArrayIndex(e){let t=+e;return Number.isInteger(t)&&String(t)===e}var latest=e=>e.copy_||e.base_,getFinalValue=e=>e.modified_?e.copy_:e.base_;function shallowCopy(e,t){if(isMap(e))return new Map(e);if(isSet(e))return new Set(e);if(p(e))return Array[o].slice.call(e);let a=isPlainObject(e);if(t===!0||t===`class_only`&&!a){let t=r.getOwnPropertyDescriptors(e);delete t[n];let a=Reflect.ownKeys(t);for(let n=0;n<a.length;n++){let r=a[n],i=t[r];i[l]===!1&&(i[l]=!0,i[s]=!0),(i.get||i.set)&&(t[r]={[s]:!0,[l]:!0,[c]:i[c],[u]:e[r]})}return r.create(i(e),t)}else{let t=i(e);if(t!==null&&a)return{...e};let n=r.create(t);return r.assign(n,e)}}function freeze(e,t=!1){return isFrozen(e)||isDraft(e)||!isDraftable(e)?e:(getArchtype(e)>1&&r.defineProperties(e,{set:m,add:m,clear:m,delete:m}),r.freeze(e),t&&each(e,(e,t)=>{freeze(t,!0)},!1),e)}function dontMutateFrozenCollections(){die(2)}var m={[u]:dontMutateFrozenCollections};function isFrozen(e){return e===null||!isObjectish(e)?!0:r.isFrozen(e)}var h=`MapSet`,g=`Patches`,_=`ArrayMethods`,v={};function getPlugin(e){let t=v[e];return t||die(0,e),t}var isPluginLoaded=e=>!!v[e],y,getCurrentScope=()=>y,createScope=(e,t)=>({drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0,handledSet_:new Set,processedForPatches_:new Set,mapSetPlugin_:isPluginLoaded(h)?getPlugin(h):void 0,arrayMethodsPlugin_:isPluginLoaded(_)?getPlugin(_):void 0});function usePatchesInScope(e,t){t&&(e.patchPlugin_=getPlugin(g),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function revokeScope(e){leaveScope(e),e.drafts_.forEach(revokeDraft),e.drafts_=null}function leaveScope(e){e===y&&(y=e.parent_)}var enterScope=e=>y=createScope(y,e);function revokeDraft(e){let t=e[n];t.type_===0||t.type_===1?t.revoke_():t.revoked_=!0}function processResult(t,r){r.unfinalizedDrafts_=r.drafts_.length;let i=r.drafts_[0];if(t!==void 0&&t!==i){i[n].modified_&&(revokeScope(r),die(4)),isDraftable(t)&&(t=finalize(r,t));let{patchPlugin_:e}=r;e&&e.generateReplacementPatches_(i[n].base_,t,r)}else t=finalize(r,i);return maybeFreeze(r,t,!0),revokeScope(r),r.patches_&&r.patchListener_(r.patches_,r.inversePatches_),t===e?void 0:t}function finalize(e,t){if(isFrozen(t))return t;let r=t[n];if(!r)return handleValue(t,e.handledSet_,e);if(!isSameScope(r,e))return t;if(!r.modified_)return r.base_;if(!r.finalized_){let{callbacks_:t}=r;if(t)for(;t.length>0;)t.pop()(e);generatePatchesAndFinalize(r,e)}return r.copy_}function maybeFreeze(e,t,n=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&freeze(t,n)}function markStateFinalized(e){e.finalized_=!0,e.scope_.unfinalizedDrafts_--}var isSameScope=(e,t)=>e.scope_===t,b=[];function updateDraftInParent(e,t,n,r){let i=latest(e),a=e.type_;if(r!==void 0&&get(i,r,a)===t){set(i,r,n,a);return}if(!e.draftLocations_){let t=e.draftLocations_=new Map;each(i,(e,n)=>{if(isDraft(n)){let r=t.get(n)||[];r.push(e),t.set(n,r)}})}let o=e.draftLocations_.get(t)??b;for(let e of o)set(i,e,n,a)}function registerChildFinalizationCallback(e,t,n){e.callbacks_.push(function childCleanup(r){let i=t;if(!i||!isSameScope(i,r))return;r.mapSetPlugin_?.fixSetContents(i);let a=getFinalValue(i);updateDraftInParent(e,i.draft_??i,a,n),generatePatchesAndFinalize(i,r)})}function generatePatchesAndFinalize(e,t){if(e.modified_&&!e.finalized_&&(e.type_===3||e.type_===1&&e.allIndicesReassigned_||(e.assigned_?.size??0)>0)){let{patchPlugin_:n}=t;if(n){let r=n.getPath(e);r&&n.generatePatches_(e,r,t)}markStateFinalized(e)}}function handleCrossReference(e,t,r){let{scope_:i}=e;if(isDraft(r)){let a=r[n];isSameScope(a,i)&&a.callbacks_.push(function crossReferenceCleanup(){prepareCopy(e),updateDraftInParent(e,r,getFinalValue(a),t)})}else isDraftable(r)&&e.callbacks_.push(function nestedDraftCleanup(){let n=latest(e);e.type_===3?n.has(r)&&handleValue(r,i.handledSet_,i):get(n,t,e.type_)===r&&i.drafts_.length>1&&(e.assigned_.get(t)??!1)===!0&&e.copy_&&handleValue(get(e.copy_,t,e.type_),i.handledSet_,i)})}function handleValue(e,t,r){return!r.immer_.autoFreeze_&&r.unfinalizedDrafts_<1||isDraft(e)||t.has(e)||!isDraftable(e)||isFrozen(e)?e:(t.add(e),each(e,(i,a)=>{if(isDraft(a)){let t=a[n];isSameScope(t,r)&&(set(e,i,getFinalValue(t),e.type_),markStateFinalized(t))}else isDraftable(a)&&handleValue(a,t,r)}),e)}function createProxyProxy(e,t){let n=p(e),r={type_:+!!n,scope_:t?t.scope_:getCurrentScope(),modified_:!1,finalized_:!1,assigned_:void 0,parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1,callbacks_:void 0},i=r,a=x;n&&(i=[r],a=S);let{revoke:o,proxy:s}=Proxy.revocable(i,a);return r.draft_=s,r.revoke_=o,[s,r]}var x={get(e,t){if(t===n)return e;let r=e.scope_.arrayMethodsPlugin_,i=e.type_===1&&typeof t==`string`;if(i&&r?.isArrayOperationMethod(t))return r.createMethodInterceptor(e,t);let a=latest(e);if(!has(a,t,e.type_))return readPropFromProto(e,a,t);let o=a[t];if(e.finalized_||!isDraftable(o)||i&&e.operationMethod&&r?.isMutatingArrayMethod(e.operationMethod)&&isArrayIndex(t))return o;if(o===peek(e.base_,t)){prepareCopy(e);let n=e.type_===1?+t:t,r=createProxy(e.scope_,o,e,n);return e.copy_[n]=r}return o},has(e,t){return t in latest(e)},ownKeys(e){return Reflect.ownKeys(latest(e))},set(e,t,r){let i=getDescriptorFromProto(latest(e),t);if(i?.set)return i.set.call(e.draft_,r),!0;if(!e.modified_){let i=peek(latest(e),t),a=i?.[n];if(a&&a.base_===r)return e.copy_[t]=r,e.assigned_.set(t,!1),!0;if(is(r,i)&&(r!==void 0||has(e.base_,t,e.type_)))return!0;prepareCopy(e),markChanged(e)}return e.copy_[t]===r&&(r!==void 0||t in e.copy_)||Number.isNaN(r)&&Number.isNaN(e.copy_[t])?!0:(e.copy_[t]=r,e.assigned_.set(t,!0),handleCrossReference(e,t,r),!0)},deleteProperty(e,t){return prepareCopy(e),peek(e.base_,t)!==void 0||t in e.base_?(e.assigned_.set(t,!1),markChanged(e)):e.assigned_.delete(t),e.copy_&&delete e.copy_[t],!0},getOwnPropertyDescriptor(e,t){let n=latest(e),r=Reflect.getOwnPropertyDescriptor(n,t);return r&&{[l]:!0,[s]:e.type_!==1||t!==`length`,[c]:r[c],[u]:n[t]}},defineProperty(){die(11)},getPrototypeOf(e){return i(e.base_)},setPrototypeOf(){die(12)}},S={};for(let e in x){let t=x[e];S[e]=function(){let e=arguments;return e[0]=e[0][0],t.apply(this,e)}}S.deleteProperty=function(e,t){return S.set.call(this,e,t,void 0)},S.set=function(e,t,n){return x.set.call(this,e[0],t,n,e[0])};function peek(e,t){let r=e[n];return(r?latest(r):e)[t]}function readPropFromProto(e,t,n){let r=getDescriptorFromProto(t,n);return r?u in r?r[u]:r.get?.call(e.draft_):void 0}function getDescriptorFromProto(e,t){if(!(t in e))return;let n=i(e);for(;n;){let e=Object.getOwnPropertyDescriptor(n,t);if(e)return e;n=i(n)}}function markChanged(e){e.modified_||(e.modified_=!0,e.parent_&&markChanged(e.parent_))}function prepareCopy(e){e.copy_||=(e.assigned_=new Map,shallowCopy(e.base_,e.scope_.immer_.useStrictShallowCopy_))}var Immer2=class{constructor(t){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!1,this.produce=(t,n,r)=>{if(isFunction(t)&&!isFunction(n)){let e=n;n=t;let r=this;return function curriedProduce(t=e,...i){return r.produce(t,e=>n.call(this,e,...i))}}isFunction(n)||die(6),r!==void 0&&!isFunction(r)&&die(7);let i;if(isDraftable(t)){let e=enterScope(this),a=createProxy(e,t,void 0),o=!0;try{i=n(a),o=!1}finally{o?revokeScope(e):leaveScope(e)}return usePatchesInScope(e,r),processResult(i,e)}else if(!t||!isObjectish(t)){if(i=n(t),i===void 0&&(i=t),i===e&&(i=void 0),this.autoFreeze_&&freeze(i,!0),r){let e=[],n=[];getPlugin(g).generateReplacementPatches_(t,i,{patches_:e,inversePatches_:n}),r(e,n)}return i}else die(1,t)},this.produceWithPatches=(e,t)=>{if(isFunction(e))return(t,...n)=>this.produceWithPatches(t,t=>e(t,...n));let n,r;return[this.produce(e,t,(e,t)=>{n=e,r=t}),n,r]},isBoolean(t?.autoFreeze)&&this.setAutoFreeze(t.autoFreeze),isBoolean(t?.useStrictShallowCopy)&&this.setUseStrictShallowCopy(t.useStrictShallowCopy),isBoolean(t?.useStrictIteration)&&this.setUseStrictIteration(t.useStrictIteration)}createDraft(e){isDraftable(e)||die(8),isDraft(e)&&(e=current(e));let t=enterScope(this),r=createProxy(t,e,void 0);return r[n].isManual_=!0,leaveScope(t),r}finishDraft(e,t){let r=e&&e[n];(!r||!r.isManual_)&&die(9);let{scope_:i}=r;return usePatchesInScope(i,t),processResult(void 0,i)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}setUseStrictIteration(e){this.useStrictIteration_=e}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(e,t){let n;for(n=t.length-1;n>=0;n--){let r=t[n];if(r.path.length===0&&r.op===`replace`){e=r.value;break}}n>-1&&(t=t.slice(n+1));let r=getPlugin(g).applyPatches_;return isDraft(e)?r(e,t):this.produce(e,e=>r(e,t))}};function createProxy(e,t,n,r){let[i,a]=isMap(t)?getPlugin(h).proxyMap_(t,n):isSet(t)?getPlugin(h).proxySet_(t,n):createProxyProxy(t,n);return(n?.scope_??getCurrentScope()).drafts_.push(i),a.callbacks_=n?.callbacks_??[],a.key_=r,n&&r!==void 0?registerChildFinalizationCallback(n,a,r):a.callbacks_.push(function rootDraftCleanup(e){e.mapSetPlugin_?.fixSetContents(a);let{patchPlugin_:t}=e;a.modified_&&t&&t.generatePatches_(a,[],e)}),i}function current(e){return isDraft(e)||die(10,e),currentImpl(e)}function currentImpl(e){if(!isDraftable(e)||isFrozen(e))return e;let t=e[n],r,i=!0;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,r=shallowCopy(e,t.scope_.immer_.useStrictShallowCopy_),i=t.scope_.immer_.shouldUseStrictIteration()}else r=shallowCopy(e,!0);return each(r,(e,t)=>{set(r,e,currentImpl(t))},i),t&&(t.finalized_=!1),r}var C=new Immer2().produce,castDraft=e=>e;export{C as n,castDraft as t};
1
+ import"../rolldown-runtime.mjs";var e=Symbol.for(`immer-nothing`),t=Symbol.for(`immer-draftable`),n=Symbol.for(`immer-state`);function die(e,...t){throw Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var r=Object,i=r.getPrototypeOf,a=`constructor`,o=`prototype`,s=`configurable`,c=`enumerable`,l=`writable`,u=`value`,isDraft=e=>!!e&&!!e[n];function isDraftable(e){return e?isPlainObject(e)||p(e)||!!e[t]||!!e[a]?.[t]||isMap(e)||isSet(e):!1}var d=r[o][a].toString(),f=new WeakMap;function isPlainObject(e){if(!e||!isObjectish(e))return!1;let t=i(e);if(t===null||t===r[o])return!0;let n=r.hasOwnProperty.call(t,a)&&t[a];if(n===Object)return!0;if(!isFunction(n))return!1;let s=f.get(n);return s===void 0&&(s=Function.toString.call(n),f.set(n,s)),s===d}function each(e,t,n=!0){getArchtype(e)===0?(n?Reflect.ownKeys(e):r.keys(e)).forEach(n=>{t(n,e[n],e)}):e.forEach((n,r)=>t(r,n,e))}function getArchtype(e){let t=e[n];return t?t.type_:p(e)?1:isMap(e)?2:isSet(e)?3:0}var has=(e,t,n=getArchtype(e))=>n===2?e.has(t):r[o].hasOwnProperty.call(e,t),get=(e,t,n=getArchtype(e))=>n===2?e.get(t):e[t],set=(e,t,n,r=getArchtype(e))=>{r===2?e.set(t,n):r===3?e.add(n):e[t]=n};function is(e,t){return e===t?e!==0||1/e==1/t:e!==e&&t!==t}var p=Array.isArray,isMap=e=>e instanceof Map,isSet=e=>e instanceof Set,isObjectish=e=>typeof e==`object`,isFunction=e=>typeof e==`function`,isBoolean=e=>typeof e==`boolean`;function isArrayIndex(e){let t=+e;return Number.isInteger(t)&&String(t)===e}var latest=e=>e.copy_||e.base_,getFinalValue=e=>e.modified_?e.copy_:e.base_;function shallowCopy(e,t){if(isMap(e))return new Map(e);if(isSet(e))return new Set(e);if(p(e))return Array[o].slice.call(e);let a=isPlainObject(e);if(t===!0||t===`class_only`&&!a){let t=r.getOwnPropertyDescriptors(e);delete t[n];let a=Reflect.ownKeys(t);for(let n=0;n<a.length;n++){let r=a[n],i=t[r];i[l]===!1&&(i[l]=!0,i[s]=!0),(i.get||i.set)&&(t[r]={[s]:!0,[l]:!0,[c]:i[c],[u]:e[r]})}return r.create(i(e),t)}else{let t=i(e);if(t!==null&&a)return{...e};let n=r.create(t);return r.assign(n,e)}}function freeze(e,t=!1){return isFrozen(e)||isDraft(e)||!isDraftable(e)?e:(getArchtype(e)>1&&r.defineProperties(e,{set:m,add:m,clear:m,delete:m}),r.freeze(e),t&&each(e,(e,t)=>{freeze(t,!0)},!1),e)}function dontMutateFrozenCollections(){die(2)}var m={[u]:dontMutateFrozenCollections};function isFrozen(e){return e===null||!isObjectish(e)||r.isFrozen(e)}var h=`MapSet`,g=`Patches`,_=`ArrayMethods`,v={};function getPlugin(e){let t=v[e];return t||die(0,e),t}var isPluginLoaded=e=>!!v[e],y,getCurrentScope=()=>y,createScope=(e,t)=>({drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0,handledSet_:new Set,processedForPatches_:new Set,mapSetPlugin_:isPluginLoaded(h)?getPlugin(h):void 0,arrayMethodsPlugin_:isPluginLoaded(_)?getPlugin(_):void 0});function usePatchesInScope(e,t){t&&(e.patchPlugin_=getPlugin(g),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function revokeScope(e){leaveScope(e),e.drafts_.forEach(revokeDraft),e.drafts_=null}function leaveScope(e){e===y&&(y=e.parent_)}var enterScope=e=>y=createScope(y,e);function revokeDraft(e){let t=e[n];t.type_===0||t.type_===1?t.revoke_():t.revoked_=!0}function processResult(t,r){r.unfinalizedDrafts_=r.drafts_.length;let i=r.drafts_[0];if(t!==void 0&&t!==i){i[n].modified_&&(revokeScope(r),die(4)),isDraftable(t)&&(t=finalize(r,t));let{patchPlugin_:e}=r;e&&e.generateReplacementPatches_(i[n].base_,t,r)}else t=finalize(r,i);return maybeFreeze(r,t,!0),revokeScope(r),r.patches_&&r.patchListener_(r.patches_,r.inversePatches_),t===e?void 0:t}function finalize(e,t){if(isFrozen(t))return t;let r=t[n];if(!r)return handleValue(t,e.handledSet_,e);if(!isSameScope(r,e))return t;if(!r.modified_)return r.base_;if(!r.finalized_){let{callbacks_:t}=r;if(t)for(;t.length>0;)t.pop()(e);generatePatchesAndFinalize(r,e)}return r.copy_}function maybeFreeze(e,t,n=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&freeze(t,n)}function markStateFinalized(e){e.finalized_=!0,e.scope_.unfinalizedDrafts_--}var isSameScope=(e,t)=>e.scope_===t,b=[];function updateDraftInParent(e,t,n,r){let i=latest(e),a=e.type_;if(r!==void 0&&get(i,r,a)===t){set(i,r,n,a);return}if(!e.draftLocations_){let t=e.draftLocations_=new Map;each(i,(e,n)=>{if(isDraft(n)){let r=t.get(n)||[];r.push(e),t.set(n,r)}})}let o=e.draftLocations_.get(t)??b;for(let e of o)set(i,e,n,a)}function registerChildFinalizationCallback(e,t,n){e.callbacks_.push(function childCleanup(r){let i=t;if(!i||!isSameScope(i,r))return;r.mapSetPlugin_?.fixSetContents(i);let a=getFinalValue(i);updateDraftInParent(e,i.draft_??i,a,n),generatePatchesAndFinalize(i,r)})}function generatePatchesAndFinalize(e,t){if(e.modified_&&!e.finalized_&&(e.type_===3||e.type_===1&&e.allIndicesReassigned_||(e.assigned_?.size??0)>0)){let{patchPlugin_:n}=t;if(n){let r=n.getPath(e);r&&n.generatePatches_(e,r,t)}markStateFinalized(e)}}function handleCrossReference(e,t,r){let{scope_:i}=e;if(isDraft(r)){let a=r[n];isSameScope(a,i)&&a.callbacks_.push(function crossReferenceCleanup(){prepareCopy(e),updateDraftInParent(e,r,getFinalValue(a),t)})}else isDraftable(r)&&e.callbacks_.push(function nestedDraftCleanup(){let n=latest(e);e.type_===3?n.has(r)&&handleValue(r,i.handledSet_,i):get(n,t,e.type_)===r&&i.drafts_.length>1&&(e.assigned_.get(t)??!1)===!0&&e.copy_&&handleValue(get(e.copy_,t,e.type_),i.handledSet_,i)})}function handleValue(e,t,r){return!r.immer_.autoFreeze_&&r.unfinalizedDrafts_<1||isDraft(e)||t.has(e)||!isDraftable(e)||isFrozen(e)?e:(t.add(e),each(e,(i,a)=>{if(isDraft(a)){let t=a[n];isSameScope(t,r)&&(set(e,i,getFinalValue(t),e.type_),markStateFinalized(t))}else isDraftable(a)&&handleValue(a,t,r)}),e)}function createProxyProxy(e,t){let n=p(e),r={type_:+!!n,scope_:t?t.scope_:getCurrentScope(),modified_:!1,finalized_:!1,assigned_:void 0,parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1,callbacks_:void 0},i=r,a=x;n&&(i=[r],a=S);let{revoke:o,proxy:s}=Proxy.revocable(i,a);return r.draft_=s,r.revoke_=o,[s,r]}var x={get(e,t){if(t===n)return e;if(t===`constructor`||t===`__proto__`){let n=latest(e)[t];return new Proxy(n||{},{get:(e,t)=>t===`__proto__`||t===`prototype`?Object.freeze(Object.create(null)):Reflect.get(e,t),set:()=>!0,apply:(e,t,n)=>Reflect.apply(e,t,n)})}let r=e.scope_.arrayMethodsPlugin_,i=e.type_===1&&typeof t==`string`;if(i&&r?.isArrayOperationMethod(t))return r.createMethodInterceptor(e,t);let a=latest(e);if(!has(a,t,e.type_))return readPropFromProto(e,a,t);let o=a[t];if(e.finalized_||!isDraftable(o)||i&&e.operationMethod&&r?.isMutatingArrayMethod(e.operationMethod)&&isArrayIndex(t))return o;if(o===peek(e.base_,t)){prepareCopy(e);let n=e.type_===1?+t:t,r=createProxy(e.scope_,o,e,n);return e.copy_[n]=r}return o},has(e,t){return t===`constructor`||t===`__proto__`||t===`prototype`?!1:t in latest(e)},ownKeys(e){return Reflect.ownKeys(latest(e))},set(e,t,r){if(t===`constructor`||t===`__proto__`||t===`prototype`)return!0;let i=getDescriptorFromProto(latest(e),t);if(i?.set)return i.set.call(e.draft_,r),!0;if(!e.modified_){let i=peek(latest(e),t),a=i?.[n];if(a&&a.base_===r)return e.copy_[t]=r,e.assigned_.set(t,!1),!0;if(is(r,i)&&(r!==void 0||has(e.base_,t,e.type_)))return!0;prepareCopy(e),markChanged(e)}return e.copy_[t]===r&&(r!==void 0||t in e.copy_)||Number.isNaN(r)&&Number.isNaN(e.copy_[t])?!0:(e.copy_[t]=r,e.assigned_.set(t,!0),handleCrossReference(e,t,r),!0)},deleteProperty(e,t){return prepareCopy(e),peek(e.base_,t)!==void 0||t in e.base_?(e.assigned_.set(t,!1),markChanged(e)):e.assigned_.delete(t),e.copy_&&delete e.copy_[t],!0},getOwnPropertyDescriptor(e,t){let n=latest(e),r=Reflect.getOwnPropertyDescriptor(n,t);return r&&{[l]:!0,[s]:e.type_!==1||t!==`length`,[c]:r[c],[u]:n[t]}},defineProperty(){die(11)},getPrototypeOf(e){return i(e.base_)},setPrototypeOf(){die(12)}},S={};for(let e in x){let t=x[e];S[e]=function(){let e=arguments;return e[0]=e[0][0],t.apply(this,e)}}S.deleteProperty=function(e,t){return S.set.call(this,e,t,void 0)},S.set=function(e,t,n){return x.set.call(this,e[0],t,n,e[0])};function peek(e,t){let r=e[n];return(r?latest(r):e)[t]}function readPropFromProto(e,t,n){let r=getDescriptorFromProto(t,n);return r?u in r?r[u]:r.get?.call(e.draft_):void 0}function getDescriptorFromProto(e,t){if(!(t in e))return;let n=i(e);for(;n;){let e=Object.getOwnPropertyDescriptor(n,t);if(e)return e;n=i(n)}}function markChanged(e){e.modified_||(e.modified_=!0,e.parent_&&markChanged(e.parent_))}function prepareCopy(e){e.copy_||=(e.assigned_=new Map,shallowCopy(e.base_,e.scope_.immer_.useStrictShallowCopy_))}var Immer2=class{constructor(t){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!1,this.produce=(t,n,r)=>{if(isFunction(t)&&!isFunction(n)){let e=n;n=t;let r=this;return function curriedProduce(t=e,...i){return r.produce(t,e=>n.call(this,e,...i))}}isFunction(n)||die(6),r!==void 0&&!isFunction(r)&&die(7);let i;if(isDraftable(t)){let e=enterScope(this),a=createProxy(e,t,void 0),o=!0;try{i=n(a),o=!1}finally{o?revokeScope(e):leaveScope(e)}return usePatchesInScope(e,r),processResult(i,e)}else if(!t||!isObjectish(t)){if(i=n(t),i===void 0&&(i=t),i===e&&(i=void 0),this.autoFreeze_&&freeze(i,!0),r){let e=[],n=[];getPlugin(g).generateReplacementPatches_(t,i,{patches_:e,inversePatches_:n}),r(e,n)}return i}else die(1,t)},this.produceWithPatches=(e,t)=>{if(isFunction(e))return(t,...n)=>this.produceWithPatches(t,t=>e(t,...n));let n,r;return[this.produce(e,t,(e,t)=>{n=e,r=t}),n,r]},isBoolean(t?.autoFreeze)&&this.setAutoFreeze(t.autoFreeze),isBoolean(t?.useStrictShallowCopy)&&this.setUseStrictShallowCopy(t.useStrictShallowCopy),isBoolean(t?.useStrictIteration)&&this.setUseStrictIteration(t.useStrictIteration)}createDraft(e){isDraftable(e)||die(8),isDraft(e)&&(e=current(e));let t=enterScope(this),r=createProxy(t,e,void 0);return r[n].isManual_=!0,leaveScope(t),r}finishDraft(e,t){let r=e&&e[n];(!r||!r.isManual_)&&die(9);let{scope_:i}=r;return usePatchesInScope(i,t),processResult(void 0,i)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}setUseStrictIteration(e){this.useStrictIteration_=e}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(e,t){let n;for(n=t.length-1;n>=0;n--){let r=t[n];if(r.path.length===0&&r.op===`replace`){e=r.value;break}}n>-1&&(t=t.slice(n+1));let r=getPlugin(g).applyPatches_;return isDraft(e)?r(e,t):this.produce(e,e=>r(e,t))}};function createProxy(e,t,n,r){let[i,a]=isMap(t)?getPlugin(h).proxyMap_(t,n):isSet(t)?getPlugin(h).proxySet_(t,n):createProxyProxy(t,n);return(n?.scope_??getCurrentScope()).drafts_.push(i),a.callbacks_=n?.callbacks_??[],a.key_=r,n&&r!==void 0?registerChildFinalizationCallback(n,a,r):a.callbacks_.push(function rootDraftCleanup(e){e.mapSetPlugin_?.fixSetContents(a);let{patchPlugin_:t}=e;a.modified_&&t&&t.generatePatches_(a,[],e)}),i}function current(e){return isDraft(e)||die(10,e),currentImpl(e)}function currentImpl(e){if(!isDraftable(e)||isFrozen(e))return e;let t=e[n],r,i=!0;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,r=shallowCopy(e,t.scope_.immer_.useStrictShallowCopy_),i=t.scope_.immer_.shouldUseStrictIteration()}else r=shallowCopy(e,!0);return each(r,(e,t)=>{set(r,e,currentImpl(t))},i),t&&(t.finalized_=!1),r}var C=new Immer2().produce,castDraft=e=>e;export{C as n,castDraft as t};