@visulima/error-handler 2.0.0 → 2.0.2

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 (41) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/LICENSE.md +14 -17
  3. package/dist/error-handler/fetch-utils.js +1 -1
  4. package/dist/error-handler/html-error-handler.d.ts +17 -29
  5. package/dist/error-handler/html-error-handler.js +20 -20
  6. package/dist/error-handler/json-error-handler.js +1 -1
  7. package/dist/error-handler/jsonapi-error-handler.js +1 -1
  8. package/dist/error-handler/jsonp-error-handler.js +1 -1
  9. package/dist/error-handler/problem-error-handler.d.ts +3 -3
  10. package/dist/error-handler/problem-error-handler.js +1 -1
  11. package/dist/error-handler/text-error-handler.js +2 -2
  12. package/dist/error-handler/xml-error-handler.js +1 -1
  13. package/dist/handler/cli-handler.js +1 -1
  14. package/dist/handler/http/create-error-middleware.d.ts +19 -18
  15. package/dist/handler/http/create-error-middleware.js +1 -1
  16. package/dist/handler/http/fetch-handler.js +1 -1
  17. package/dist/handler/http/node-handler.js +1 -1
  18. package/dist/index.js +1 -1
  19. package/dist/packem_shared/cliHandler-Cybm9E8l.js +12 -0
  20. package/dist/packem_shared/createNegotiatedErrorHandler-CqLndPbO.js +1 -0
  21. package/dist/packem_shared/extractStatusCode-CBYszxF1.js +1 -0
  22. package/dist/packem_shared/fetchCreateNegotiatedErrorHandler-Dwem_rrE.js +1 -0
  23. package/dist/packem_shared/fetchHtmlErrorHandler-D2Kb40aa.js +1 -0
  24. package/dist/packem_shared/get-file-source-DfjkvIv_.js +1 -0
  25. package/dist/packem_shared/mock-server-response-Ci40Hny9.js +1 -0
  26. package/dist/packem_shared/safe-reason-phrase-6OKw5Op8.js +1 -0
  27. package/dist/packem_shared/send-json-DKhv0fDY.js +1 -0
  28. package/dist/packem_shared/sendFetchJson-CKUVEmV3.js +1 -0
  29. package/dist/packem_shared/set-error-headers-FicmiR1z.js +1 -0
  30. package/dist/packem_shared/with-expose-BhBvHI1y.js +1 -0
  31. package/package.json +19 -19
  32. package/dist/packem_shared/add-status-code-to-response-DwELM1q2.js +0 -1
  33. package/dist/packem_shared/cliHandler-BGq-ckC0.js +0 -35
  34. package/dist/packem_shared/createNegotiatedErrorHandler-CcWOSpO5.js +0 -1
  35. package/dist/packem_shared/extractStatusCode-D0UOgNnr.js +0 -1
  36. package/dist/packem_shared/fetchCreateNegotiatedErrorHandler-D9YQ8pOH.js +0 -1
  37. package/dist/packem_shared/fetchHtmlErrorHandler-Cu50Zu5a.js +0 -1
  38. package/dist/packem_shared/get-file-source-By3_8e1o.js +0 -1
  39. package/dist/packem_shared/send-json-fz8r6NBW.js +0 -1
  40. package/dist/packem_shared/sendFetchJson-BNmfrMYp.js +0 -1
  41. package/dist/packem_shared/set-error-headers-g9hns3cZ.js +0 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## @visulima/error-handler [2.0.2](https://github.com/visulima/visulima/compare/%40visulima%2Ferror-handler%402.0.1...%40visulima%2Ferror-handler%402.0.2) (2026-08-17)
2
+
3
+ ## @visulima/error-handler [2.0.1](https://github.com/visulima/visulima/compare/%40visulima%2Ferror-handler%402.0.0...%40visulima%2Ferror-handler%402.0.1) (2026-08-02)
4
+
5
+
6
+ ### Dependencies
7
+
8
+ * **@visulima/error:** upgraded to 6.1.0
9
+
1
10
  ## @visulima/error-handler [2.0.0](https://github.com/visulima/visulima/compare/@visulima/error-handler@1.0.13...@visulima/error-handler@2.0.0) (2026-07-03)
2
11
 
3
12
  ### ⚠ BREAKING CHANGES
package/LICENSE.md CHANGED
@@ -100,6 +100,20 @@ Repository: https://github.com/visulima/visulima.git
100
100
  >
101
101
  > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
102
102
  >
103
+ > ---
104
+ >
105
+ > File: src/vendor/terminal-size/index.ts
106
+ >
107
+ > MIT License
108
+ >
109
+ > Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
110
+ >
111
+ > Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
112
+ >
113
+ > The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
114
+ >
115
+ > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
116
+ >
103
117
  >
104
118
  >
105
119
  > # Licenses of bundled dependencies
@@ -742,23 +756,6 @@ Repository: https://github.com/visulima/visulima.git
742
756
  > > > The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
743
757
  > > >
744
758
  > > > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
745
- >
746
- > ---------------------------------------
747
- >
748
- > ## terminal-size
749
- > License: MIT
750
- > By: Sindre Sorhus
751
- > Repository: sindresorhus/terminal-size
752
- >
753
- > > MIT License
754
- > >
755
- > > Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
756
- > >
757
- > > Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
758
- > >
759
- > > The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
760
- > >
761
- > > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
762
759
 
763
760
  <!-- /DEPENDENCIES -->
764
761
 
@@ -1 +1 @@
1
- import{default as a}from"../packem_shared/extractStatusCode-D0UOgNnr.js";import{default as r}from"../packem_shared/sendFetchJson-BNmfrMYp.js";export{a as extractStatusCode,r as sendFetchJson};
1
+ import{default as a}from"../packem_shared/extractStatusCode-CBYszxF1.js";import{default as r}from"../packem_shared/sendFetchJson-CKUVEmV3.js";export{a as extractStatusCode,r as sendFetchJson};
@@ -2,45 +2,33 @@ import { IncomingMessage, ServerResponse } from 'node:http';
2
2
  import { E as ErrorHandler } from "../packem_shared/types.d-Btzbxdod.js";
3
3
  import { SolutionFinder } from '@visulima/error/solution';
4
4
  /**
5
- * Options that influence how the development HTML error inspector is rendered.
6
- */
5
+ * Options that influence how the development HTML error inspector is rendered.
6
+ */
7
7
  type HtmlErrorInspectorOptions = {
8
8
  /**
9
- * Permit the underlying code-frame reader to fetch `http(s):`/`data:`
10
- * stack-frame URLs over the network. Off by default to avoid an SSRF
11
- * surface; only enable when frame URLs are known to be trusted.
12
- * @default false
13
- */
9
+ * Permit the underlying code-frame reader to fetch `http(s):`/`data:`
10
+ * stack-frame URLs over the network. Off by default to avoid an SSRF
11
+ * surface; only enable when frame URLs are known to be trusted.
12
+ * @default false
13
+ */
14
14
  allowRemoteSources?: boolean;
15
15
  /**
16
- * Number of source lines rendered above the offending line in the code frame.
17
- * @default 4
18
- */
16
+ * Number of source lines rendered above the offending line in the code frame.
17
+ * @default 4
18
+ */
19
19
  linesAbove?: number;
20
20
  /**
21
- * Number of source lines rendered below the offending line in the code frame.
22
- * @default 4
23
- */
21
+ * Number of source lines rendered below the offending line in the code frame.
22
+ * @default 4
23
+ */
24
24
  linesBelow?: number;
25
25
  /**
26
- * Extra solution finders to run before the built-in rule-based and
27
- * error-hint finders. The first finder (sorted by descending priority)
28
- * that returns a hint wins. Matches the CLI handler's behaviour.
29
- */
26
+ * Extra solution finders to run before the built-in rule-based and
27
+ * error-hint finders. The first finder (sorted by descending priority)
28
+ * that returns a hint wins. Matches the CLI handler's behaviour.
29
+ */
30
30
  solutionFinders?: SolutionFinder[];
31
31
  };
32
- /**
33
- * Builds the inner HTML for the development error inspector: error name +
34
- * message, a syntax-free code frame for the offending source line, the parsed
35
- * stack trace (one entry per cause), and a possible-solution hint.
36
- *
37
- * All dynamic content is HTML-escaped. This is intended for development output
38
- * only — callers must keep it off the production path so stack/source are not
39
- * leaked.
40
- * @param error The error to render.
41
- * @param options Inspector rendering options.
42
- * @returns The escaped inner HTML for the inspector.
43
- */
44
32
  declare const htmlErrorHandler: (options?: HtmlErrorHandlerOptions) => ErrorHandler;
45
33
  type HtmlErrorHandlerOptions = HtmlErrorInspectorOptions & {
46
34
  cspNonce?: string;
@@ -1,22 +1,22 @@
1
- import{getReasonPhrase as x}from"http-status-codes";import{a as u}from"../packem_shared/add-status-code-to-response-DwELM1q2.js";import{codeFrame as v}from"@visulima/error/code-frame";import{getErrorCauses as w}from"@visulima/error/error";import{ruleBasedFinder as k,errorHintFinder as S}from"@visulima/error/solution";import{parseStacktrace as $}from"@visulima/error/stacktrace";import{h as j,a as C}from"../packem_shared/get-file-source-By3_8e1o.js";const A=/^\s*#+\s*/,l=e=>e.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;").replaceAll('"',"&quot;").replaceAll("'","&#39;"),z=e=>e.replace(A,"").trim(),M=async(e,r,t,o)=>{const n=[...r,k,S].toSorted((i,s)=>i.priority-s.priority);for(const i of n){if(typeof i.handle!="function")continue;const s=await i.handle(e,{file:t.file??"",language:C(t.file??""),line:t.line??0,snippet:o});if(s)return s}},N=e=>{if(!e.file)return l(e.raw);let r=l(e.file);return e.line!==void 0&&(r+=`:${String(e.line)}`,e.column!==void 0&&(r+=`:${String(e.column)}`)),r},E=e=>{if(e.length===0)return"";const r=e.map(t=>{const o=l(t.methodName??"<anonymous>"),n=N(t);return String.raw`<li class="vis-frame"><span class="vis-frame-method">${o}</span><span class="vis-frame-loc">${n}</span></li>`}).join("");return String.raw`<ol class="vis-frames">${r}</ol>`},B=e=>{if(!e)return"";const r=l(z(e.header??"A possible solution to this error")),t=l(e.body);return String.raw`
1
+ import{a as u,s as v}from"../packem_shared/safe-reason-phrase-6OKw5Op8.js";import{codeFrame as w}from"@visulima/error/code-frame";import{getErrorCauses as k}from"@visulima/error/error";import{ruleBasedFinder as S,errorHintFinder as $}from"@visulima/error/solution";import{parseStacktrace as C}from"@visulima/error/stacktrace";import{g as A,f as E}from"../packem_shared/get-file-source-DfjkvIv_.js";const j=/^\s*#+\s*/,s=e=>e.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;").replaceAll('"',"&quot;").replaceAll("'","&#39;"),N=e=>e.replace(j,"").trim(),z=async(e,r,t,o)=>{const i=[...r,S,$].toSorted((a,n)=>a.priority-n.priority);for(const a of i){if(typeof a.handle!="function")continue;const n=await a.handle(e,{file:t.file??"",language:E(t.file??""),line:t.line??0,snippet:o});if(n)return n}},M=e=>{if(!e.file)return s(e.raw);let r=s(e.file);return e.line!==void 0&&(r+=`:${String(e.line)}`,e.column!==void 0&&(r+=`:${String(e.column)}`)),r},F=e=>{if(e.length===0)return"";const r=e.map(t=>{const o=s(t.methodName??"<anonymous>"),i=M(t);return String.raw`<li class="vis-frame"><span class="vis-frame-method">${o}</span><span class="vis-frame-loc">${i}</span></li>`}).join("");return String.raw`<ol class="vis-frames">${r}</ol>`},H=e=>{if(!e)return"";const r=s(N(e.header??"A possible solution to this error")),t=s(e.body);return String.raw`
2
2
  <section class="vis-card vis-solution">
3
3
  <h2 class="vis-card-title">💡 ${r}</h2>
4
4
  <pre class="vis-solution-body">${t}</pre>
5
- </section>`},F=async(e,r={})=>{const{allowRemoteSources:t=!1,linesAbove:o=4,linesBelow:n=4,solutionFinders:i=[]}=r,s=w(e)[0]??e,c=$(s),a=c.find(d=>!!d.file)??c[0]??{};let m="",g="";if(a.file&&a.line!==void 0){const d=await j(a.file,{allowRemote:t});if(d){g=d;const h=v(d,{start:{column:a.column,line:a.line}},{linesAbove:o,linesBelow:n});m=String.raw`
5
+ </section>`},I=async(e,r={})=>{const{allowRemoteSources:t=!1,linesAbove:o=4,linesBelow:i=4,solutionFinders:a=[]}=r,m=k(e)[0]??e,c=C(m),l=c.find(d=>!!d.file)??c[0]??{};let g="",p="";if(l.file&&l.line!==void 0){const d=await A(l.file,{allowRemote:t});if(d){p=d;const x=w(d,{start:{column:l.column,line:l.line}},{linesAbove:o,linesBelow:i});g=String.raw`
6
6
  <section class="vis-card">
7
- <h2 class="vis-card-title">${l(`${a.file}:${String(a.line)}`)}</h2>
8
- <pre class="vis-codeframe"><code>${l(h)}</code></pre>
9
- </section>`}}const p=await M(e,i,a,g),f=l(e.name||"Error"),b=l(e.message||""),y=c.length>0?String.raw`
7
+ <h2 class="vis-card-title">${s(`${l.file}:${String(l.line)}`)}</h2>
8
+ <pre class="vis-codeframe"><code>${s(x)}</code></pre>
9
+ </section>`}}const f=await z(e,a,l,p),b=s(e.name||"Error"),y=s(e.message||""),h=c.length>0?String.raw`
10
10
  <section class="vis-card">
11
11
  <h2 class="vis-card-title">Stack trace</h2>
12
- ${E(c)}
12
+ ${F(c)}
13
13
  </section>`:"";return String.raw`
14
14
  <div class="vis-inspector max-w-6xl mx-auto px-6 mt-8">
15
15
  <section class="vis-card vis-headline">
16
- <span class="vis-error-name">${f}</span>
17
- <p class="vis-error-message">${b}</p>
18
- </section>${m}${B(p)}${y}
19
- </div>`},I=String.raw`
16
+ <span class="vis-error-name">${b}</span>
17
+ <p class="vis-error-message">${y}</p>
18
+ </section>${g}${H(f)}${h}
19
+ </div>`},R=String.raw`
20
20
  .vis-inspector { display: flex; flex-direction: column; gap: 1rem; }
21
21
  .vis-card { background: #fff; border-radius: .5rem; box-shadow: 0 1px 3px 0 rgba(0,0,0,.1),0 1px 2px 0 rgba(0,0,0,.06); overflow: hidden; }
22
22
  .vis-card-title { margin: 0; padding: .75rem 1.5rem; font-size: .8125rem; font-weight: 600; color: #1a202c; border-bottom: 1px solid #edf2f7; word-break: break-word; }
@@ -36,29 +36,29 @@ import{getReasonPhrase as x}from"http-status-codes";import{a as u}from"../packem
36
36
  .vis-error-message, .vis-codeframe, .vis-solution-body, .vis-frame-method { color: #e2e8f0; }
37
37
  .vis-frame { border-bottom-color: #4a5568; }
38
38
  .vis-frame-loc { color: #a0aec0; }
39
- }`,D=(e={})=>async(r,t,o)=>{u(o,r),o.setHeader("content-type","text/html; charset=utf-8");const n=x(o.statusCode)||"Error",i=e.cspNonce?` nonce="${e.cspNonce}"`:"",{expose:s}=r,c=s?await F(r,{allowRemoteSources:e.allowRemoteSources,linesAbove:e.linesAbove,linesBelow:e.linesBelow,solutionFinders:e.solutionFinders}):"";if(e.errorPage){const a=typeof e.errorPage=="function"?await e.errorPage({error:r,reasonPhrase:n,request:t,response:o,statusCode:o.statusCode}):e.errorPage;if(a){o.end(a);return}}o.end(String.raw`<!DOCTYPE html>
39
+ }`,O=(e={})=>async(r,t,o)=>{u(o,r),o.setHeader("content-type","text/html; charset=utf-8");const i=v(o.statusCode,"Error"),a=e.cspNonce?` nonce="${e.cspNonce}"`:"";if(e.errorPage){const c=typeof e.errorPage=="function"?await e.errorPage({error:r,reasonPhrase:i,request:t,response:o,statusCode:o.statusCode}):e.errorPage;if(c){o.end(c);return}}const{expose:n}=r,m=n?await I(r,{allowRemoteSources:e.allowRemoteSources,linesAbove:e.linesAbove,linesBelow:e.linesBelow,solutionFinders:e.solutionFinders}):"";o.end(String.raw`<!DOCTYPE html>
40
40
  <html lang="en">
41
41
  <head>
42
42
  <meta charset="utf-8">
43
43
  <meta name="viewport" content="width=device-width, initial-scale=1">
44
44
 
45
- <title>${n}</title>
45
+ <title>${i}</title>
46
46
  <meta name="robots" content="noindex">
47
47
 
48
- <style${i}>
48
+ <style${a}>
49
49
  /*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */html{line-height:1.15;-webkit-text-size-adjust:100%}body{margin:0}a{background-color:transparent}code{font-family:monospace,monospace;font-size:1em}[hidden]{display:none}html{font-family:system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;line-height:1.5}*,:after,:before{box-sizing:border-box;border:0 solid #e2e8f0}a{color:inherit;text-decoration:inherit}code{font-family:Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace}svg,video{display:block;vertical-align:middle}video{max-width:100%;height:auto}.bg-white{--bg-opacity:1;background-color:#fff;background-color:rgba(255,255,255,var(--bg-opacity))}.bg-gray-100{--bg-opacity:1;background-color:#f7fafc;background-color:rgba(247,250,252,var(--bg-opacity))}.border-gray-200{--border-opacity:1;border-color:#edf2f7;border-color:rgba(237,242,247,var(--border-opacity))}.border-gray-400{--border-opacity:1;border-color:#cbd5e0;border-color:rgba(203,213,224,var(--border-opacity))}.border-r{border-right-width:1px}.flex{display:flex}.grid{display:grid}.hidden{display:none}.items-center{align-items:center}.justify-center{justify-content:center}.font-semibold{font-weight:600}.h-5{height:1.25rem}.h-8{height:2rem}.h-16{height:4rem}.text-sm{font-size:.875rem}.text-lg{font-size:1.125rem}.leading-7{line-height:1.75rem}.mx-auto{margin-left:auto;margin-right:auto}.ml-1{margin-left:.25rem}.mt-2{margin-top:.5rem}.mr-2{margin-right:.5rem}.ml-2{margin-left:.5rem}.mt-4{margin-top:1rem}.ml-4{margin-left:1rem}.mt-8{margin-top:2rem}.ml-12{margin-left:3rem}.-mt-px{margin-top:-1px}.max-w-xl{max-width:36rem}.max-w-6xl{max-width:72rem}.min-h-screen{min-height:100vh}.overflow-hidden{overflow:hidden}.p-6{padding:1.5rem}.py-4{padding-top:1rem;padding-bottom:1rem}.px-4{padding-left:1rem;padding-right:1rem}.px-6{padding-left:1.5rem;padding-right:1.5rem}.pt-8{padding-top:2rem}.fixed{position:fixed}.relative{position:relative}.top-0{top:0}.right-0{right:0}.shadow{box-shadow:0 1px 3px 0 rgba(0,0,0,.1),0 1px 2px 0 rgba(0,0,0,.06)}.text-center{text-align:center}.text-gray-200{--text-opacity:1;color:#edf2f7;color:rgba(237,242,247,var(--text-opacity))}.text-gray-300{--text-opacity:1;color:#e2e8f0;color:rgba(226,232,240,var(--text-opacity))}.text-gray-400{--text-opacity:1;color:#cbd5e0;color:rgba(203,213,224,var(--text-opacity))}.text-gray-500{--text-opacity:1;color:#a0aec0;color:rgba(160,174,192,var(--text-opacity))}.text-gray-600{--text-opacity:1;color:#718096;color:rgba(113,128,150,var(--text-opacity))}.text-gray-700{--text-opacity:1;color:#4a5568;color:rgba(74,85,104,var(--text-opacity))}.text-gray-900{--text-opacity:1;color:#1a202c;color:rgba(26,32,44,var(--text-opacity))}.uppercase{text-transform:uppercase}.underline{text-decoration:underline}.antialiased{-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.tracking-wider{letter-spacing:.05em}.w-5{width:1.25rem}.w-8{width:2rem}.w-auto{width:auto}.grid-cols-1{grid-template-columns:repeat(1,minmax(0,1fr))}@media (min-width:640px){.sm\:rounded-lg{border-radius:.5rem}.sm\:block{display:block}.sm\:items-center{align-items:center}.sm\:justify-start{justify-content:flex-start}.sm\:justify-between{justify-content:space-between}.sm\:h-20{height:5rem}.sm\:ml-0{margin-left:0}.sm\:px-6{padding-left:1.5rem;padding-right:1.5rem}.sm\:pt-0{padding-top:0}.sm\:text-left{text-align:left}.sm\:text-right{text-align:right}}@media (min-width:768px){.md\:border-t-0{border-top-width:0}.md\:border-l{border-left-width:1px}.md\:grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}}@media (min-width:1024px){.lg\:px-8{padding-left:2rem;padding-right:2rem}}@media (prefers-color-scheme:dark){.dark\:bg-gray-800{--bg-opacity:1;background-color:#2d3748;background-color:rgba(45,55,72,var(--bg-opacity))}.dark\:bg-gray-900{--bg-opacity:1;background-color:#1a202c;background-color:rgba(26,32,44,var(--bg-opacity))}.dark\:border-gray-700{--border-opacity:1;border-color:#4a5568;border-color:rgba(74,85,104,var(--border-opacity))}.dark\:text-white{--text-opacity:1;color:#fff;color:rgba(255,255,255,var(--text-opacity))}.dark\:text-gray-400{--text-opacity:1;color:#cbd5e0;color:rgba(203,213,224,var(--text-opacity))}}
50
50
  </style>
51
51
 
52
- <style${i}>
52
+ <style${a}>
53
53
  body {
54
54
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
55
55
  }
56
- </style>${s?`
57
- <style${i}>${I}
56
+ </style>${n?`
57
+ <style${a}>${R}
58
58
  </style>`:""}
59
59
  </head>
60
60
  <body class="antialiased">
61
- <div class="relative flex items-center justify-center ${s?"pt-8":"min-h-screen"} bg-gray-100 dark:bg-gray-900">
61
+ <div class="relative flex items-center justify-center ${n?"pt-8":"min-h-screen"} bg-gray-100 dark:bg-gray-900">
62
62
  <div class="max-w-xl mx-auto sm:px-6 lg:px-8">
63
63
  <div class="flex items-center justify-center">
64
64
  <div class="px-6 text-lg text-gray-600 dark:text-gray-400 border-r border-gray-400 dark:border-gray-700 tracking-wider font-semibold">
@@ -66,10 +66,10 @@ import{getReasonPhrase as x}from"http-status-codes";import{a as u}from"../packem
66
66
  </div>
67
67
 
68
68
  <div class="ml-4 text-lg text-gray-600 dark:text-gray-400 uppercase tracking-wider">
69
- ${n}
69
+ ${i}
70
70
  </div>
71
71
  </div>
72
72
  </div>
73
- </div>${c}
73
+ </div>${m}
74
74
  </body>
75
- </html>`)};export{D as htmlErrorHandler};
75
+ </html>`)};export{O as htmlErrorHandler};
@@ -1 +1 @@
1
- import{getReasonPhrase as p}from"http-status-codes";import{a as f}from"../packem_shared/add-status-code-to-response-DwELM1q2.js";import{o as a}from"../packem_shared/send-json-fz8r6NBW.js";import{o as i}from"../packem_shared/set-error-headers-g9hns3cZ.js";const h=(t={})=>async(r,m,e)=>{f(e,r),i(e,r);const{statusCode:s}=e,o=p(s)||"An error occurred";if(t.formatter){const c=await t.formatter({error:r,reasonPhrase:o,request:m,response:e,statusCode:s});a(e,c);return}const{expose:n}=r;a(e,{message:r.message||o,error:o,statusCode:s,...n?{stack:r.stack}:{}})};export{h as jsonErrorHandler};
1
+ import{a as f,s as r}from"../packem_shared/safe-reason-phrase-6OKw5Op8.js";import{s as m}from"../packem_shared/send-json-DKhv0fDY.js";import{s as i}from"../packem_shared/set-error-headers-FicmiR1z.js";const k=(e={})=>async(a,c,s)=>{f(s,a),i(s,a);const{statusCode:t}=s,o=r(t);if(e.formatter){const n=await e.formatter({error:a,reasonPhrase:o,request:c,response:s,statusCode:t});m(s,n);return}const{expose:d}=a;m(s,{message:a.message||o,error:o,statusCode:t,...d?{stack:a.stack}:{}})};export{k as jsonErrorHandler};
@@ -1 +1 @@
1
- import{isHttpError as f}from"http-errors";import{getReasonPhrase as m}from"http-status-codes";import i from"ts-japi";import{a as p}from"../packem_shared/add-status-code-to-response-DwELM1q2.js";import{o as t}from"../packem_shared/send-json-fz8r6NBW.js";import{o as l}from"../packem_shared/set-error-headers-g9hns3cZ.js";const u=(e,a)=>"statusCode"in e&&typeof e.statusCode=="number"?e.statusCode:"status"in e&&typeof e.status=="number"?e.status:a,J=(e,a,r)=>{if(p(r,e),l(r,e),e instanceof i.JapiError||i.JapiError.isLikeJapiError(e)){const o=new i.ErrorSerializer;t(r,o.serialize(e))}else if(f(e)){const o=u(e,r.statusCode),s="title"in e&&typeof e.title=="string"?e.title:void 0,n="message"in e&&typeof e.message=="string"?e.message:"";t(r,{errors:[{code:o,title:s??m(o),detail:n}]})}else{const{message:o}=e,{statusCode:s}=r;t(r,{errors:[{code:s,title:m(s),detail:o}]})}};export{J as default};
1
+ import{isHttpError as l}from"http-errors";import e from"ts-japi";import{a as c,s as d}from"../packem_shared/safe-reason-phrase-6OKw5Op8.js";import f from"../packem_shared/extractStatusCode-CBYszxF1.js";import{s as o}from"../packem_shared/send-json-DKhv0fDY.js";import{s as p}from"../packem_shared/set-error-headers-FicmiR1z.js";const n="application/vnd.api+json; charset=utf-8",T=(t,E,s)=>{if(c(s,t),p(s,t),t instanceof e.JapiError||e.JapiError.isLikeJapiError(t)){const a=new e.ErrorSerializer;o(s,a.serialize(t),n)}else if(l(t)){const a=f(t,s.statusCode),i="title"in t&&typeof t.title=="string"?t.title:void 0,m="message"in t&&typeof t.message=="string"?t.message:"";o(s,{errors:[{code:a,title:i??d(a),detail:m}]},n)}else{const{message:a}=t,{statusCode:i}=s;o(s,{errors:[{code:i,title:d(i),detail:a}]},n)}};export{T as default};
@@ -1 +1 @@
1
- import{getReasonPhrase as f}from"http-status-codes";import{a as h}from"../packem_shared/add-status-code-to-response-DwELM1q2.js";import{o as d}from"../packem_shared/set-error-headers-g9hns3cZ.js";const c="callback",g=/^[A-Za-z_$][\w$.]*$/u,k=(s={})=>async(e,l,t)=>{h(t,e),d(t,e);const{statusCode:o}=t,r=f(o),p=new URL(l.url??"http://localhost","http://localhost"),i=s.callbackParamName??c;let a=p.searchParams.get(i)??c,n;if(s.formatter)n=await s.formatter({error:e,reasonPhrase:r,request:l,response:t,statusCode:o});else{const{expose:u}=e;n={message:e.message||r,error:r,statusCode:o,...u?{stack:e.stack}:{}}}(a.length>64||!g.test(a))&&(a=c),t.setHeader("content-type","application/javascript; charset=utf-8"),t.setHeader("x-content-type-options","nosniff");const m=JSON.stringify(n).replaceAll("\u2028",String.raw`\u2028`).replaceAll("\u2029",String.raw`\u2029`);t.end(`/**/ typeof ${a} === 'function' && ${a}(${m});`)};export{k as jsonpErrorHandler};
1
+ import{a as u,s as p}from"../packem_shared/safe-reason-phrase-6OKw5Op8.js";import{s as h}from"../packem_shared/set-error-headers-FicmiR1z.js";const n="callback",k=/^[A-Za-z_$][\w$.]*$/u,y=(s={})=>async(t,r,a)=>{u(a,t),h(a,t);const{statusCode:c}=a,l=p(c),m=new URL(r.url??"http://localhost","http://localhost"),f=s.callbackParamName??n;let e=m.searchParams.get(f)??n,o;if(s.formatter)o=await s.formatter({error:t,reasonPhrase:l,request:r,response:a,statusCode:c});else{const{expose:d}=t;o={message:t.message||l,error:l,statusCode:c,...d?{stack:t.stack}:{}}}(e.length>64||!k.test(e))&&(e=n),a.setHeader("content-type","application/javascript; charset=utf-8"),a.setHeader("x-content-type-options","nosniff");const i=JSON.stringify(o).replaceAll("\u2028",String.raw`\u2028`).replaceAll("\u2029",String.raw`\u2029`);a.end(`/**/ typeof ${e} === 'function' && ${e}(${i});`)};export{y as jsonpErrorHandler};
@@ -1,8 +1,8 @@
1
1
  import { E as ErrorHandler } from "../packem_shared/types.d-Btzbxdod.js";
2
2
  import 'node:http';
3
3
  /**
4
- * Normalizes errors according to the API Problem spec (RFC 7807).
5
- * @see https://tools.ietf.org/html/rfc7807
6
- */
4
+ * Normalizes errors according to the API Problem spec (RFC 7807).
5
+ * @see https://tools.ietf.org/html/rfc7807
6
+ */
7
7
  declare const problemErrorHandler: ErrorHandler;
8
8
  export { problemErrorHandler as default };
@@ -1 +1 @@
1
- import{isHttpError as d}from"http-errors";import{getReasonPhrase as p}from"http-status-codes";import{a as f}from"../packem_shared/add-status-code-to-response-DwELM1q2.js";import{o as r}from"../packem_shared/send-json-fz8r6NBW.js";import{o as c}from"../packem_shared/set-error-headers-g9hns3cZ.js";const n="about:blank",y=(t,s)=>"statusCode"in t&&typeof t.statusCode=="number"?t.statusCode:"status"in t&&typeof t.status=="number"?t.status:s,$=(t,s,e)=>{const{message:a,stack:i}=t;if(d(t)){const m="expose"in t?t.expose:void 0,o=y(t,e.statusCode),u="title"in t&&typeof t.title=="string"?t.title:void 0,l="type"in t&&typeof t.type=="string"?t.type:void 0;e.statusCode=o,c(e,t),r(e,{type:l??n,title:u??p(o),status:o,detail:a,...m?{trace:i}:{}},"application/problem+json")}else f(e,t),r(e,{type:n,title:p(e.statusCode),status:e.statusCode,detail:a,...t.expose?{trace:i}:{}},"application/problem+json")};export{$ as default};
1
+ import{isHttpError as f}from"http-errors";import{a as o,s as p}from"../packem_shared/safe-reason-phrase-6OKw5Op8.js";import{s as l}from"../packem_shared/send-json-DKhv0fDY.js";import{s as u}from"../packem_shared/set-error-headers-FicmiR1z.js";const d="about:blank",v=(t,y,s)=>{const{message:a,stack:e}=t;if(f(t)){const n="expose"in t?t.expose:void 0,c="title"in t&&typeof t.title=="string"?t.title:void 0,m="type"in t&&typeof t.type=="string"?t.type:void 0;o(s,t);const{statusCode:i}=s;u(s,t),l(s,{type:m??d,title:c??p(i),status:i,detail:a,...n?{trace:e}:{}},"application/problem+json")}else o(s,t),l(s,{type:d,title:p(s.statusCode),status:s.statusCode,detail:a,...t.expose?{trace:e}:{}},"application/problem+json")};export{v as default};
@@ -1,3 +1,3 @@
1
- import{getReasonPhrase as i}from"http-status-codes";import{a as d}from"../packem_shared/add-status-code-to-response-DwELM1q2.js";import{o as f}from"../packem_shared/set-error-headers-g9hns3cZ.js";const h=(o={})=>async(e,m,t)=>{d(t,e),f(t,e);const{statusCode:r}=t,s=i(r)||"Error";if(t.setHeader("content-type","text/plain; charset=utf-8"),o.formatter){const c=await o.formatter({error:e,reasonPhrase:s,request:m,response:t,statusCode:r});t.end(c);return}const a=e.message||s,{expose:p}=e,n=p?e.stack:void 0;t.end(n?`${a}
1
+ import{a as r,s as i}from"../packem_shared/safe-reason-phrase-6OKw5Op8.js";import{s as x}from"../packem_shared/set-error-headers-FicmiR1z.js";const E=(s={})=>async(a,d,t)=>{r(t,a),x(t,a);const{statusCode:e}=t,o=i(e,"Error");if(t.setHeader("content-type","text/plain; charset=utf-8"),s.formatter){const f=await s.formatter({error:a,reasonPhrase:o,request:d,response:t,statusCode:e});t.end(f);return}const c=a.message||o,{expose:m}=a,n=m?a.stack:void 0;t.end(n?`${c}
2
2
 
3
- ${n}`:a)};export{h as textErrorHandler};
3
+ ${n}`:c)};export{E as textErrorHandler};
@@ -1 +1 @@
1
- import{getReasonPhrase as i}from"http-status-codes";import{toXML as c}from"jstoxml";import{a as p}from"../packem_shared/add-status-code-to-response-DwELM1q2.js";import{o as u}from"../packem_shared/set-error-headers-g9hns3cZ.js";const x=(t={})=>async(e,l,o)=>{p(o,e),u(o,e);const{statusCode:r}=o,a=i(r)||"An error occurred";let s;if(t.formatter)s=await t.formatter({error:e,reasonPhrase:a,request:l,response:o,statusCode:r});else{const{expose:m}=e;s={error:{statusCode:r,name:a,message:e.message||a,...m?{stack:e.stack}:{}}}}const n=c(s,{header:t.toXml?.header??t.xmlHeader??!0,indent:t.toXml?.indent??" ",...t.toXml?.attributeReplacements?{attributeReplacements:t.toXml.attributeReplacements}:{},...t.toXml?.attributeFilter?{attributeFilter:t.toXml.attributeFilter}:{},...t.toXml?.attributeExplicitTrue===void 0?{}:{attributeExplicitTrue:t.toXml.attributeExplicitTrue},...t.toXml?.contentMap?{contentMap:t.toXml.contentMap}:{},...t.toXml?.contentReplacements?{contentReplacements:t.toXml.contentReplacements}:{},...t.toXml?.selfCloseTags===void 0?{}:{selfCloseTags:t.toXml.selfCloseTags}});o.setHeader("content-type","application/xml; charset=utf-8"),o.end(n)};export{x as xmlErrorHandler};
1
+ import{toXML as n}from"jstoxml";import{a as u,s as X}from"../packem_shared/safe-reason-phrase-6OKw5Op8.js";import{s as i}from"../packem_shared/set-error-headers-FicmiR1z.js";const x=(t={})=>async(e,r,a)=>{u(a,e),i(a,e);const{statusCode:l}=a,m=X(l);let c;if(t.formatter)c=await t.formatter({error:e,reasonPhrase:m,request:r,response:a,statusCode:l});else{const{expose:d}=e;c={error:{statusCode:l,name:m,message:e.message||m,...d?{stack:e.stack}:{}}}}const s=n(c,{header:t.toXml?.header??t.xmlHeader??!0,indent:t.toXml?.indent??" ",...t.toXml?.attributeReplacements?{attributeReplacements:t.toXml.attributeReplacements}:{},...t.toXml?.attributeFilter?{attributeFilter:t.toXml.attributeFilter}:{},...t.toXml?.attributeExplicitTrue===void 0?{}:{attributeExplicitTrue:t.toXml.attributeExplicitTrue},...t.toXml?.contentMap?{contentMap:t.toXml.contentMap}:{},...t.toXml?.contentReplacements?{contentReplacements:t.toXml.contentReplacements}:{},...t.toXml?.selfCloseTags===void 0?{}:{selfCloseTags:t.toXml.selfCloseTags}});a.setHeader("content-type","application/xml; charset=utf-8"),a.end(s)};export{x as xmlErrorHandler};
@@ -1,3 +1,3 @@
1
- import{buildOutput as n}from"../packem_shared/cliHandler-BGq-ckC0.js";import{terminalOutput as l}from"../packem_shared/cliHandler-BGq-ckC0.js";const e=async(o,i={})=>{const{errorAnsi:r,solutionBox:t}=await n(o,i);return t===void 0?r:`${r}
1
+ import{buildOutput as i}from"../packem_shared/cliHandler-Cybm9E8l.js";import{terminalOutput as l}from"../packem_shared/cliHandler-Cybm9E8l.js";const e=async(o,n={})=>{const{errorAnsi:r,solutionBox:t}=await i(o,n);return t===void 0?r:`${r}
2
2
 
3
3
  ${t}`};export{e as ansiHandler,l as cliHandler};
@@ -3,29 +3,30 @@ import { HtmlErrorHandlerOptions } from "../../error-handler/html-error-handler.
3
3
  import { a as ErrorHandlers } from "../../packem_shared/types.d-Btzbxdod.js";
4
4
  import '@visulima/error/solution';
5
5
  type ErrorMiddlewareOptions = HtmlErrorHandlerOptions & {
6
- extraHandlers?: ErrorHandlers; /** Callback to handle error logging. */
6
+ extraHandlers?: ErrorHandlers;
7
+ /** Callback to handle error logging. */
7
8
  onError?: (error: Error, request: IncomingMessage, response: ServerResponse) => void | Promise<void>;
8
9
  /** Include stack traces in responses. Defaults to `NODE_ENV !== "production"`. */
9
10
  showTrace?: boolean;
10
11
  };
11
12
  type ErrorMiddleware = (error: Error, request: IncomingMessage, response: ServerResponse, next?: (error?: unknown) => void) => Promise<void>;
12
13
  /**
13
- * Express/Connect-style error middleware.
14
- *
15
- * Unlike {@link nodeHandler}, which takes the error at construction time and so
16
- * has to be rebuilt inside every `catch` block, this returns a four-argument
17
- * error middleware you register once:
18
- *
19
- * ```ts
20
- * import { createErrorMiddleware } from "@visulima/error-handler";
21
- *
22
- * app.use(createErrorMiddleware({ showTrace: "production" !== "production" }));
23
- * ```
24
- *
25
- * The returned function matches the Express/Connect `(err, req, res, next)`
26
- * signature. If the response has already started streaming
27
- * (`response.headersSent`), it delegates to `next(error)` so the framework's
28
- * default handler can close the connection rather than double-writing.
29
- */
14
+ * Express/Connect-style error middleware.
15
+ *
16
+ * Unlike {@link nodeHandler}, which takes the error at construction time and so
17
+ * has to be rebuilt inside every `catch` block, this returns a four-argument
18
+ * error middleware you register once:
19
+ *
20
+ * ```ts
21
+ * import { createErrorMiddleware } from "@visulima/error-handler";
22
+ *
23
+ * app.use(createErrorMiddleware({ showTrace: "production" !== "production" }));
24
+ * ```
25
+ *
26
+ * The returned function matches the Express/Connect `(err, req, res, next)`
27
+ * signature. If the response has already started streaming
28
+ * (`response.headersSent`), it delegates to `next(error)` so the framework's
29
+ * default handler can close the connection rather than double-writing.
30
+ */
30
31
  declare const createErrorMiddleware: (options?: ErrorMiddlewareOptions) => ErrorMiddleware;
31
32
  export { type ErrorMiddleware, type ErrorMiddlewareOptions, createErrorMiddleware as default };
@@ -1 +1 @@
1
- import n from"./node-handler.js";const f=(r={})=>async(t,i,a,e)=>{if(a.headersSent){e&&e(t);return}await n(t,r)(i,a)};export{f as default};
1
+ import i from"./node-handler.js";const n=(t={})=>async(a,d,e,r)=>{if(e.headersSent){r&&r(a);return}await i(a,t)(d,e)};export{n as default};
@@ -1 +1 @@
1
- import s from"../../packem_shared/fetchCreateNegotiatedErrorHandler-D9YQ8pOH.js";import c from"../../packem_shared/fetchHtmlErrorHandler-Cu50Zu5a.js";const i=(o,r={})=>{const a=c(r),n=r.showTrace??globalThis.process?.env?.NODE_ENV!=="production",e=s(r.extraHandlers??[],n,a);return async t=>(r.onError&&await r.onError(o,t),e(o,t))};export{i as default};
1
+ import d from"../../packem_shared/fetchCreateNegotiatedErrorHandler-Dwem_rrE.js";import s from"../../packem_shared/fetchHtmlErrorHandler-D2Kb40aa.js";const h=(e,r={})=>{const a=s(r),o=globalThis.process?.env,n=r.showTrace??(o===void 0?!1:o.NODE_ENV!=="production"),c=d(r.extraHandlers??[],n,a);return async t=>{if(r.onError)try{await r.onError(e,t)}catch(l){console.error(l)}return c(e,t)}};export{h as default};
@@ -1 +1 @@
1
- import c from"../../packem_shared/createNegotiatedErrorHandler-CcWOSpO5.js";import{htmlErrorHandler as i}from"../../error-handler/html-error-handler.js";const p=(o,r={})=>{const s=i(r),n=r.showTrace??globalThis.process?.env?.NODE_ENV!=="production",e=c(r.extraHandlers??[],n,s);return async(a,t)=>{r.onError&&await r.onError(o,a,t),await e(o,a,t)}};export{p as default};
1
+ import s from"../../packem_shared/createNegotiatedErrorHandler-CqLndPbO.js";import{htmlErrorHandler as E}from"../../error-handler/html-error-handler.js";const f=(o,r={})=>{const n=E(r),a=globalThis.process?.env,c=r.showTrace??(a===void 0?!1:a.NODE_ENV!=="production"),l=s(r.extraHandlers??[],c,n);return async(e,t)=>{if(r.onError)try{await r.onError(o,e,t)}catch(d){console.error(d)}await l(o,e,t)}};export{f as default};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{default as o}from"./packem_shared/createNegotiatedErrorHandler-CcWOSpO5.js";import{default as a}from"./packem_shared/fetchCreateNegotiatedErrorHandler-D9YQ8pOH.js";import{default as f}from"./packem_shared/fetchHtmlErrorHandler-Cu50Zu5a.js";import{htmlErrorHandler as m}from"./error-handler/html-error-handler.js";import{jsonErrorHandler as p}from"./error-handler/json-error-handler.js";import{default as s}from"./error-handler/jsonapi-error-handler.js";import{jsonpErrorHandler as u}from"./error-handler/jsonp-error-handler.js";import{default as c}from"./error-handler/problem-error-handler.js";import{textErrorHandler as i}from"./error-handler/text-error-handler.js";import{default as g}from"./packem_shared/extractStatusCode-D0UOgNnr.js";import{default as N}from"./packem_shared/sendFetchJson-BNmfrMYp.js";import{xmlErrorHandler as w}from"./error-handler/xml-error-handler.js";import{default as J}from"./handler/http/create-error-middleware.js";import{default as S}from"./handler/http/fetch-handler.js";import{default as q}from"./handler/http/node-handler.js";export{J as createErrorMiddleware,o as createNegotiatedErrorHandler,g as extractStatusCode,a as fetchCreateNegotiatedErrorHandler,S as fetchHandler,f as fetchHtmlErrorHandler,m as htmlErrorHandler,p as jsonErrorHandler,s as jsonapiErrorHandler,u as jsonpErrorHandler,q as nodeHandler,c as problemErrorHandler,N as sendFetchJson,i as textErrorHandler,w as xmlErrorHandler};
1
+ import{default as o}from"./packem_shared/createNegotiatedErrorHandler-CqLndPbO.js";import{default as a}from"./packem_shared/fetchCreateNegotiatedErrorHandler-Dwem_rrE.js";import{default as f}from"./packem_shared/fetchHtmlErrorHandler-D2Kb40aa.js";import{htmlErrorHandler as m}from"./error-handler/html-error-handler.js";import{jsonErrorHandler as p}from"./error-handler/json-error-handler.js";import{default as s}from"./error-handler/jsonapi-error-handler.js";import{jsonpErrorHandler as u}from"./error-handler/jsonp-error-handler.js";import{default as c}from"./error-handler/problem-error-handler.js";import{textErrorHandler as i}from"./error-handler/text-error-handler.js";import{default as g}from"./packem_shared/extractStatusCode-CBYszxF1.js";import{default as N}from"./packem_shared/sendFetchJson-CKUVEmV3.js";import{xmlErrorHandler as w}from"./error-handler/xml-error-handler.js";import{default as J}from"./handler/http/create-error-middleware.js";import{default as S}from"./handler/http/fetch-handler.js";import{default as q}from"./handler/http/node-handler.js";export{J as createErrorMiddleware,o as createNegotiatedErrorHandler,g as extractStatusCode,a as fetchCreateNegotiatedErrorHandler,S as fetchHandler,f as fetchHtmlErrorHandler,m as htmlErrorHandler,p as jsonErrorHandler,s as jsonapiErrorHandler,u as jsonpErrorHandler,q as nodeHandler,c as problemErrorHandler,N as sendFetchJson,i as textErrorHandler,w as xmlErrorHandler};
@@ -0,0 +1,12 @@
1
+ import{parseStacktrace as Mt}from"@visulima/error/stacktrace";import{renderError as Nt}from"@visulima/error/error";import{g as Ft,f as Lt}from"./get-file-source-DfjkvIv_.js";import{ruleBasedFinder as Ct,errorHintFinder as Ot}from"@visulima/error/solution";const $t=[161,161,164,164,167,168,170,170,173,174,176,180,182,186,188,191,198,198,208,208,215,216,222,225,230,230,232,234,236,237,240,240,242,243,247,250,252,252,254,254,257,257,273,273,275,275,283,283,294,295,299,299,305,307,312,312,319,322,324,324,328,331,333,333,338,339,358,359,363,363,462,462,464,464,466,466,468,468,470,470,472,472,474,474,476,476,593,593,609,609,708,708,711,711,713,715,717,717,720,720,728,731,733,733,735,735,768,879,913,929,931,937,945,961,963,969,1025,1025,1040,1103,1105,1105,8208,8208,8211,8214,8216,8217,8220,8221,8224,8226,8228,8231,8240,8240,8242,8243,8245,8245,8251,8251,8254,8254,8308,8308,8319,8319,8321,8324,8364,8364,8451,8451,8453,8453,8457,8457,8467,8467,8470,8470,8481,8482,8486,8486,8491,8491,8531,8532,8539,8542,8544,8555,8560,8569,8585,8585,8592,8601,8632,8633,8658,8658,8660,8660,8679,8679,8704,8704,8706,8707,8711,8712,8715,8715,8719,8719,8721,8721,8725,8725,8730,8730,8733,8736,8739,8739,8741,8741,8743,8748,8750,8750,8756,8759,8764,8765,8776,8776,8780,8780,8786,8786,8800,8801,8804,8807,8810,8811,8814,8815,8834,8835,8838,8839,8853,8853,8857,8857,8869,8869,8895,8895,8978,8978,9312,9449,9451,9547,9552,9587,9600,9615,9618,9621,9632,9633,9635,9641,9650,9651,9654,9655,9660,9661,9664,9665,9670,9672,9675,9675,9678,9681,9698,9701,9711,9711,9733,9734,9737,9737,9742,9743,9756,9756,9758,9758,9792,9792,9794,9794,9824,9825,9827,9829,9831,9834,9836,9837,9839,9839,9886,9887,9919,9919,9926,9933,9935,9939,9941,9953,9955,9955,9960,9961,9963,9969,9972,9972,9974,9977,9979,9980,9982,9983,10045,10045,10102,10111,11094,11097,12872,12879,57344,63743,65024,65039,65533,65533,127232,127242,127248,127277,127280,127337,127344,127373,127375,127376,127387,127404,917760,917999,983040,1048573,1048576,1114109],jt=12288,_t=65510,zt=[12288,12288,65281,65376,65504,65510],Ht=8361,Dt=65518,Kt=[8361,8361,65377,65470,65474,65479,65482,65487,65490,65495,65498,65500,65512,65518],Pt=32,qt=10630,Gt=[32,126,162,163,165,166,172,172,175,175,10214,10221,10629,10630],Vt=4352,Ut=262141,bt=[4352,4447,8986,8987,9001,9002,9193,9196,9200,9200,9203,9203,9725,9726,9748,9749,9776,9783,9800,9811,9855,9855,9866,9871,9875,9875,9889,9889,9898,9899,9917,9918,9924,9925,9934,9934,9940,9940,9962,9962,9970,9971,9973,9973,9978,9978,9981,9981,9989,9989,9994,9995,10024,10024,10060,10060,10062,10062,10067,10069,10071,10071,10133,10135,10160,10160,10175,10175,11035,11036,11088,11088,11093,11093,11904,11929,11931,12019,12032,12245,12272,12287,12289,12350,12353,12438,12441,12543,12549,12591,12593,12686,12688,12773,12783,12830,12832,12871,12880,42124,42128,42182,43360,43388,44032,55203,63744,64255,65040,65049,65072,65106,65108,65126,65128,65131,94176,94180,94192,94198,94208,101589,101631,101662,101760,101874,110576,110579,110581,110587,110589,110590,110592,110882,110898,110898,110928,110930,110933,110933,110948,110951,110960,111355,119552,119638,119648,119670,126980,126980,127183,127183,127374,127374,127377,127386,127488,127490,127504,127547,127552,127560,127568,127569,127584,127589,127744,127776,127789,127797,127799,127868,127870,127891,127904,127946,127951,127955,127968,127984,127988,127988,127992,128062,128064,128064,128066,128252,128255,128317,128331,128334,128336,128359,128378,128378,128405,128406,128420,128420,128507,128591,128640,128709,128716,128716,128720,128722,128725,128728,128732,128735,128747,128748,128756,128764,128992,129003,129008,129008,129292,129338,129340,129349,129351,129535,129648,129660,129664,129674,129678,129734,129736,129736,129741,129756,129759,129770,129775,129784,131072,196605,196608,262141],L=(t,o)=>{let e=0,i=Math.floor(t.length/2)-1;for(;e<=i;){const l=Math.floor((e+i)/2),s=l*2;if(o<t[s])i=l-1;else if(o>t[s+1])e=l+1;else return!0}return!1},Q=19968,[Yt,Zt]=Jt(bt);function Jt(t){let o=t[0],e=t[1];for(let i=0;i<t.length;i+=2){const l=t[i],s=t[i+1];if(Q>=l&&Q<=s)return[l,s];s-l>e-o&&(o=l,e=s)}return[o,e]}const Xt=t=>t<161||t>1114109?!1:L($t,t),Qt=t=>t<jt||t>_t?!1:L(zt,t),te=t=>t<Ht||t>Dt?!1:L(Kt,t),ee=t=>t<Pt||t>qt?!1:L(Gt,t),oe=t=>t>=Yt&&t<=Zt?!0:t<Vt||t>Ut?!1:L(bt,t);function ie(t){return Xt(t)?"ambiguous":Qt(t)?"fullwidth":te(t)?"halfwidth":ee(t)?"narrow":oe(t)?"wide":"neutral"}function ne(t){if(!Number.isSafeInteger(t))throw new TypeError(`Expected a code point, got \`${typeof t}\`.`)}function xt(t){return ne(t),ie(t)}const wt=String.raw,tt=wt`\p{Emoji}(?:\p{EMod}|[\u{E0020}-\u{E007E}]+\u{E007F}|\uFE0F?\u20E3?)`,se=()=>new RegExp(wt`\p{RI}{2}|(?![#*\d](?!\uFE0F?\u20E3))${tt}(?:\u200D${tt})*`,"gu"),R=new Set(["\x1B","›"]),P="\x07",Bt="[",J="m",M="]8;;",re=39,le=/[\u200B\uFEFF\u2060-\u2064]/g,ce=new RegExp(`(?:\\${Bt}(?<code>\\d+)m|\\${M}(?<uri>.*)${P})`),ae=Object.freeze(new Map([[0,0],[1,22],[2,22],[3,23],[4,24],[7,27],[8,28],[9,29],[30,39],[31,39],[32,39],[33,39],[34,39],[35,39],[36,39],[37,39],[40,49],[41,49],[42,49],[43,49],[44,49],[45,49],[46,49],[47,49],[90,39]])),D=/[\u001B\u009B](?:[[()#;?]{0,10}(?:\d{1,4}(?:;\d{0,4})*)?[0-9A-ORZcf-nqry=><]|\]8;;[^\u0007\u001B]{0,100}(?:\u0007|\u001B\\))/g,et=/\u001B\[[\d;]*m[^\u001B]*(?:\u001B\[[\d;]*m|$)/g,ot=/\u001B\]8;[^\u0007\u001B]*(?:\u0007|\u001B\\)[^\u001B]*\u001B\]8;;(?:\u0007|\u001B\\)/g,O=/[\u0000-\u0008\n-\u001F\u007F-\u009F]{1,1000}/y,he=se(),it=new Map,ue=t=>[t.ambiguousIsNarrow?1:0,t.control,t.fullWidth,t.regular,t.wide].join("|"),fe=t=>{const o=ue(t.width);let e=it.get(o);return e||(e=new Map,it.set(o,e)),e},$=new RegExp(D.source,"y"),G=new RegExp(he.source,"uy"),j=/(?:[\u0020-\u007E\u00A0-\u00FF](?!\uFE0F)){1,1000}/y,yt=t=>t>=32&&t<=126?"latin":t===8203||t===8204||t===8205||t===8288?"zero":t<=31||t>=127&&t<=159?"control":t>=160&&t<=255||t>=9472&&t<=9599?"latin":t>=4352&&t<=4607||t>=11904&&t<=40959||t>=44032&&t<=55215||t>=63744&&t<=64255||t>=65280&&t<=65519&&!(t>=65377&&t<=65439)||t>=12352&&t<=12543?"wide":t===8230?"latin":"other",de=(t,o)=>{const e=fe(o),i=Math.floor(t/65536),l=t%65536;let s=e.get(i);if(s||(s=new Map,e.set(i,s)),s.has(l))return s.get(l);let n;switch(yt(t)){case"control":{n=o.width.control;break}case"latin":{n=o.width.regular;break}case"wide":{n=o.width.wide;break}case"zero":{n=0;break}default:switch(xt(t)){case"ambiguous":{n=o.width.ambiguousIsNarrow?o.width.regular:o.width.wide;break}case"fullwidth":{n=o.width.fullWidth;break}case"wide":{n=o.width.wide;break}default:n=o.width.regular}}return s.set(l,n),n},me=t=>t>=768&&t<=879||t>=6832&&t<=6911||t>=7616&&t<=7679||t>=8400&&t<=8447||t>=65056&&t<=65071||t>=917760&&t<=917999||t>=65024&&t<=65039||t>=3633&&t<=3642||t>=3655&&t<=3662||t>=3761&&t<=3769||t>=3771&&t<=3772||t>=3784&&t<=3789||t>=2304&&t<=2307||t>=2362&&t<=2383||t>=2385&&t<=2391||t>=2402&&t<=2403||t>=2433&&t<=2435||t>=2492&&t<=2500||t>=2509&&t<=2509||t>=2561&&t<=2563||t>=2620&&t<=2637||t>=1611&&t<=1631||t>=1648&&t<=1648||t>=1750&&t<=1773||t>=2276&&t<=2302||t>=1425&&t<=1469||t>=1471&&t<=1471||t>=1473&&t<=1474||t>=1476&&t<=1477||t>=1479&&t<=1479||t>=3893&&t<=3893||t>=3895&&t<=3895||t>=3897&&t<=3897||t>=3953&&t<=3966||t>=3968&&t<=3972||t>=3974&&t<=3975?!0:t>=768&&t<=777||t>=803&&t<=803,Y=(t,o={})=>{if(!t||t.length===0)return{ellipsed:!1,index:0,truncated:!1,width:0};const e={truncation:{countAnsiEscapeCodes:o.countAnsiEscapeCodes??!1,ellipsis:o.ellipsis??"",ellipsisWidth:o.ellipsisWidth??(o.ellipsis?Y(o.ellipsis,{...o,ellipsis:"",ellipsisWidth:0,limit:Number.POSITIVE_INFINITY}).width:0),limit:o.limit??Number.POSITIVE_INFINITY},width:{ambiguousIsNarrow:o.ambiguousIsNarrow??!1,ansi:o.ansiWidth??0,control:o.controlWidth??0,emoji:o.emojiWidth??2,fullWidth:o.fullWidth??2,halfWidth:o.halfWidth??1,regular:o.regularWidth??1,tab:o.tabWidth??8,wide:o.wideWidth??2}},i=Math.max(0,e.truncation.limit-e.truncation.ellipsisWidth),{length:l}=t,s=l>1e4;let n=0,c=0,a=l,r=!1;const f=t.includes("\x1B")||t.includes("›");for(;n<l;){if(f&&(t[n]==="\x1B"||t[n]==="›")){if(t.startsWith("\x1B]8;;",n)){const m="\x1B]8;;\x07",h=m.length,w=t.indexOf("\x07",n+5);if(w!==-1){const v=t.indexOf(m,w+1);if(v!==-1){const B=v+h,E=t.slice(w+1,v).replace(D,""),X=Y(E,{ambiguousIsNarrow:e.width.ambiguousIsNarrow,ansiWidth:e.width.ansi,controlWidth:e.width.control,countAnsiEscapeCodes:!1,ellipsis:e.truncation.ellipsis,ellipsisWidth:e.truncation.ellipsisWidth,emojiWidth:e.width.emoji,fullWidth:e.width.fullWidth,halfWidth:e.width.halfWidth,limit:Math.max(0,i-c),regularWidth:e.width.regular,tabWidth:e.width.tab,wideWidth:e.width.wide}),q=X.width;if(X.truncated)r=!0,a=Math.min(a,n);else if(c+q>i&&(a=Math.min(a,n),r=!0,c+q>e.truncation.limit))break;if(c+=q,n=B,r&&c>=e.truncation.limit)break;continue}}}if($.lastIndex=n,$.test(t)){const m=$.lastIndex-n,h=e.truncation.countAnsiEscapeCodes?m:e.width.ansi;if(c+h>i&&(a=Math.min(a,n),c+h>e.truncation.limit)){r=!0;break}c+=h,n=$.lastIndex;continue}}const g=t.codePointAt(n);if(g===8203||g===65279||g>=8288&&g<=8292){n+=1;continue}if(g===9){if(c+e.width.tab>i&&(a=Math.min(a,n),c+e.width.tab>e.truncation.limit)){r=!0;break}c+=e.width.tab,n+=1;continue}if(j.lastIndex=n,j.test(t)){const m=(j.lastIndex-n)*e.width.regular;if(c+m>i){const h=e.width.regular>0?Math.floor((i-c)/e.width.regular):0;if(a=Math.min(a,n+h),c+m>e.truncation.limit){r=!0;break}}c+=m,n=j.lastIndex;continue}if((g<=31||g>=127&&g<=159)&&(O.lastIndex=n,O.test(t))){const m=(O.lastIndex-n)*e.width.control;if(c+m>i){const h=e.width.control>0?Math.floor((i-c)/e.width.control):0;if(a=Math.min(a,n+h),c+m>e.truncation.limit){r=!0;break}}c+=m,n=O.lastIndex;continue}if(G.lastIndex=n,G.test(t)){if(c+e.width.emoji>i&&(a=Math.min(a,n),c+e.width.emoji>e.truncation.limit)){r=!0;break}c+=e.width.emoji,n=G.lastIndex;continue}const x=t.codePointAt(n)??0;if(me(x)){n+=x>65535?2:1;continue}let d;if(s)d=de(x,e);else switch(yt(x)){case"control":{d=e.width.control;break}case"latin":{d=e.width.regular;break}case"wide":{d=e.width.wide;break}case"zero":{d=0;break}default:switch(xt(x)){case"ambiguous":{d=e.width.ambiguousIsNarrow?e.width.regular:e.width.wide;break}case"fullwidth":{d=e.width.fullWidth;break}case"wide":{d=e.width.wide;break}default:d=e.width.regular}}if(c+d>i&&(a=Math.min(a,n),c+d>e.truncation.limit)){r=!0;break}c+=d,n+=x>65535?2:1}let u=c,p=!1;return r&&e.truncation.limit>=e.truncation.ellipsisWidth&&(u=e.truncation.limit,p=!0),{ellipsed:p,index:r?a:l,truncated:r,width:u}},b=(t,o={})=>Y(t,{...o,ellipsis:"",ellipsisWidth:0,limit:Number.POSITIVE_INFINITY}).width,pe=(t,o)=>Math.floor((t-o)/2),ge=(t,o)=>t-o,nt=(t,o={})=>{const e=o.align??"center";if(e==="left")return t;const i=o.split??`
2
+ `,l=o.pad??" ",s=e==="right"?ge:pe;let n=!1,c;Array.isArray(t)?c=t:(n=!0,c=t.split(i));let a,r=0;const f=c.map(u=>(a=b(u,o.stringWidthOptions),r=Math.max(a,r),{str:u,width:a})).map(u=>Array.from({length:s(r,u.width)+1}).join(l)+u.str);return n?f.join(i):f};class be{capacity;cache;constructor(o){this.capacity=o,this.cache=new Map}get(o){if(!this.cache.has(o))return;const e=this.cache.get(o);return this.cache.delete(o),this.cache.set(o,e),e}has(o){return this.cache.has(o)}set(o,e){if(this.cache.has(o))this.cache.delete(o);else if(this.cache.size>=this.capacity){const i=this.cache.keys().next().value;i!==void 0&&this.cache.delete(i)}this.cache.set(o,e)}delete(o){this.cache.delete(o)}clear(){this.cache.clear()}size(){return this.cache.size}}const st=new be(100),xe=new Intl.Segmenter("en",{granularity:"grapheme"}),we=/^[\u0000-\u007F]*$/,Be=new Set(["0","22","23","24","27","28","29","39","49"]),ye=new Set(["1","3","4","7","8","9"]),rt=new Map([["22","1"],["23","3"],["24","4"],["27","7"],["28","8"],["29","9"]]),_=t=>t>="30"&&t<="37"||t>="90"&&t<="97"||t.startsWith("38;"),z=t=>t>="40"&&t<="47"||t>="100"&&t<="107"||t.startsWith("48;"),Ee=[{close:"\x1B[22m",open:"\x1B[1m"},{close:"\x1B[23m",open:"\x1B[3m"},{close:"\x1B[24m",open:"\x1B[4m"},{close:"\x1B[27m",open:"\x1B[7m"},{close:"\x1B[28m",open:"\x1B[8m"},{close:"\x1B[29m",open:"\x1B[9m"}],lt=(t,o)=>{let e=-1;for(const i of o){const l=t.indexOf(i);l!==-1&&(e===-1||l<e)&&(e=l)}return e},ve=(t,o)=>{if(!t.includes("\x1B"))return[{after:"",before:"",content:t,visibleLength:b(t,o.width)}];const e=`${JSON.stringify(o.width??void 0)}\0${t}`,i=st.get(e);if(i)return i;const l=[],s=[];let n=0,c;for(D.lastIndex=0;(c=D.exec(t))!==null;){const u=c[0];l.push(t.slice(n,c.index)),s.push(u),n=c.index+u.length}n<t.length&&l.push(t.slice(n));const a=[];for(const u of s){if(u==="\x1B[0m"||u==="\x1B]8;;\x07"){a.push(u);continue}if(u.startsWith("\x1B[")&&u.endsWith("m")){const p=u.slice(2,-1);if(Be.has(p)){a.push(u);continue}}}const r=new Set,f=[];for(const[u,p]of l.entries()){if(u>0&&s[u-1]){const d=s[u-1];if(d==="\x1B[0m")r.clear();else if(d==="\x1B]8;;\x07"){for(const m of r)if(m.startsWith("\x1B]8;;")&&!m.endsWith("\x1B]8;;\x07")){r.delete(m);break}}else if(d.startsWith("\x1B[")&&d.endsWith("m")){const m=d.slice(2,-1);if(m==="39"){for(const h of r)if(h.startsWith("\x1B[")&&h.endsWith("m")){const w=h.slice(2,-1);if(_(w)){r.delete(h);break}}}else if(m==="49"){for(const h of r)if(h.startsWith("\x1B[")&&h.endsWith("m")){const w=h.slice(2,-1);if(z(w)){r.delete(h);break}}}else if(rt.has(m)){const h=rt.get(m);for(const w of r)if(w===`\x1B[${h}m`){r.delete(w);break}}else{if(_(m)){for(const h of r)if(h.startsWith("\x1B[")&&h.endsWith("m")){const w=h.slice(2,-1);if(_(w)){r.delete(h);break}}}else if(z(m)){for(const h of r)if(h.startsWith("\x1B[")&&h.endsWith("m")){const w=h.slice(2,-1);if(z(w)){r.delete(h);break}}}else if(ye.has(m)){const h=`\x1B[${m}m`;r.has(h)&&r.delete(h)}r.add(d)}}else if(d.startsWith("\x1B]8;;")&&!d.endsWith("\x1B]8;;\x07")){for(const m of r)if(m.startsWith("\x1B]8;;")&&!m.endsWith("\x1B]8;;\x07")){r.delete(m);break}r.add(d)}}if(p==="")continue;let g="";if(r.size>0)if(a.includes("\x1B[0m"))g="\x1B[0m";else{const d=[];let m=!1;for(const B of r)if(B.startsWith("\x1B]8;;")&&!B.endsWith("\x1B]8;;\x07")){m=!0;break}m&&a.includes("\x1B]8;;\x07")&&d.push("\x1B]8;;\x07");let h=!1,w=!1;for(const B of r)if(B.startsWith("\x1B[")&&B.endsWith("m")){const E=B.slice(2,-1);_(E)?h=!0:z(E)&&(w=!0)}if(h&&w){const B=lt(t,["\x1B[3","\x1B[9","\x1B[38;"]),E=lt(t,["\x1B[4","\x1B[10","\x1B[48;"]);B>=0&&E>=0?B>E?d.push("\x1B[39m","\x1B[49m"):d.push("\x1B[49m","\x1B[39m"):d.push("\x1B[39m","\x1B[49m")}else h&&d.push("\x1B[39m"),w&&d.push("\x1B[49m");h&&w&&t.includes("\x1B[39m")&&t.includes("\x1B[49m")&&(t.indexOf("\x1B[39m")<t.indexOf("\x1B[49m")?(d.length-=2,d.push("\x1B[39m","\x1B[49m")):t.indexOf("\x1B[49m")<t.indexOf("\x1B[39m")&&(d.length-=2,d.push("\x1B[49m","\x1B[39m")));const v=Ee.filter(B=>r.has(B.open)).map(B=>({position:t.indexOf(B.open),style:B})).filter(B=>B.position>=0).toSorted((B,E)=>E.position-B.position);for(const B of v){const E=B;a.includes(E.style.close)&&d.push(E.style.close)}g=d.join("")}const x=[...r].join("");f.push({after:g,before:x,content:p,visibleLength:b(p,o.width)})}return st.set(e,f),f},ct=(t,o,e,i)=>{const l=[...i.segmenter.segment(t)],s=[];let n=0,c=!1;for(const a of l){const r=b(a.segment,i.width),f=n,u=n+r;if(!c)if(f<o){n=u;continue}else c=!0;if(f>=e||u>e)break;s.push(a.segment),n=u}return s.join("")},A=(t,o=0,e=Number.MAX_SAFE_INTEGER,i={})=>{const l={segmenter:xe,...i};if(o>=e||t==="")return"";const s=b(t,l.width);if(o===0&&e>=s)return t;if(o<0||e<0)throw new RangeError("Negative indices aren't supported");if(!t.includes("\x1B"))return we.test(t)?t.slice(o,e):ct(t,o,e,l);if(et.lastIndex=0,ot.lastIndex=0,!et.test(t)&&!ot.test(t))return t;const n=ve(t,l);if(n.length===0)return"";let c=0;const a=[];for(const[u,p]of n.entries()){const g=c,x=c+p.visibleLength;if(x>o&&g<e){const d=Math.max(0,o-g),m=Math.min(p.visibleLength,e-g);a.push({end:m,index:u,segment:p,start:d})}c=x}if(a.length===0)return"";const r=[],f=a[0].segment;r.push(f.before);for(let u=0;u<a.length;u++){const{end:p,segment:g,start:x}=a[u];if(x===0&&p===g.visibleLength?r.push(g.content):r.push(ct(g.content,x,p,l)),u<a.length-1){const d=a[u+1].segment,m=g.after,h=d.before;m!==h&&(m||h)&&r.push(m,h)}}return r.push(a.at(-1).segment.after),r.join("")},Se=/\x1B\[(\d+)m/;class Et{activeForeground=void 0;activeBackground=void 0;activeFormatting=[];processEscape(o){const e=Se.exec(o);if(!e)return;const i=Number.parseInt(e[1],10);switch(i){case 0:{this.activeForeground=void 0,this.activeBackground=void 0,this.activeFormatting=[];break}case 39:{this.activeForeground=void 0;break}case 49:{this.activeBackground=void 0;break}default:if(i>=30&&i<=37||i>=90&&i<=97)this.activeForeground=o;else if(i>=40&&i<=47||i>=100&&i<=107)this.activeBackground=o;else if([1,2,3,4,7,8,9].includes(i))this.activeFormatting.push(o);else if([22,23,24,27,28,29].includes(i)){const l={22:"[1m",23:"[3m",24:"[4m",27:"[7m",28:"[8m",29:"[9m"}[i];l&&(this.activeFormatting=this.activeFormatting.filter(s=>!s.includes(l)))}}}getStartEscapesForAllActiveAttributes(){return[this.activeBackground,this.activeForeground,...this.activeFormatting].filter(Boolean).join("")}getEndEscapesForAllActiveAttributes(){const o=[];if(this.activeFormatting.length>0){const e={"\x1B[1m":"\x1B[22m","\x1B[2m":"\x1B[22m","\x1B[3m":"\x1B[23m","\x1B[4m":"\x1B[24m","\x1B[7m":"\x1B[27m","\x1B[8m":"\x1B[28m","\x1B[9m":"\x1B[29m"};[...this.activeFormatting].toReversed().forEach(i=>{const l=e[i];l&&o.push(l)})}return this.activeForeground&&o.push("\x1B[39m"),this.activeBackground&&o.push("\x1B[49m"),o.join("")}}const Ae=(t,o)=>{if(!R.has(t[o]))return{isInsideEscape:!1,isInsideLinkEscape:!1};const e=!0,i=t.slice(o+1,o+1+M.length).join("")===M;return{isInsideEscape:e,isInsideLinkEscape:i}},ke=(t,o={})=>{const e=new Et;let i="",l=!1,s="",n="",c=!1;const a=[...t];for(let r=0;r<a.length;r++){const f=a[r];if(f&&R.has(f)){if(i){const d=o.getWidth?.(i)??0,m={isEscapeSequence:!1,isGrapheme:!0,text:i,width:d};if(c&&(m.isHyperlink=!0,m.hyperlinkUrl=n),o.onSegment?.(m,e)===!1)return;i=""}l=!0,s=f;const g=Ae(a,r),{isInsideLinkEscape:x}=g;if(x){let d=r+1;for(n="";d<a.length;){const h=a[d];if(h===P)break;n+=h,d+=1}n=n.slice(4);const m={hyperlinkUrl:n,isEscapeSequence:!0,isGrapheme:!1,isHyperlink:!0,isHyperlinkStart:!0,width:0};if(o.onSegment?.(m,e)===!1)return;r=d,c=!0,l=!1,s="";continue}if(r+1<a.length&&a[r+1]==="\\"&&c){const d={isEscapeSequence:!0,isGrapheme:!1,isHyperlink:!0,isHyperlinkEnd:!0,width:0};if(o.onSegment?.(d,e)===!1)return;c=!1,n="",r+=1,l=!1,s="";continue}}if(l){if(s!==f&&(s+=f),f===J){l=!1,e.processEscape(s);const g={isEscapeSequence:!0,isGrapheme:!1,text:s,width:0};if(o.onSegment?.(g,e)===!1)return;s=""}continue}i+=f;const u=o.getWidth?.(i)??0,p={isEscapeSequence:!1,isGrapheme:!0,text:i,width:u};if(c&&(p.isHyperlink=!0,p.hyperlinkUrl=n),o.onSegment?.(p,e)===!1)return;i=""}if(i){const r=o.getWidth?.(i)??0,f={isEscapeSequence:!1,isGrapheme:!0,text:i,width:r};c&&(f.isHyperlink=!0,f.hyperlinkUrl=n),o.onSegment?.(f,e)}if(s){const r={isEscapeSequence:!0,isGrapheme:!1,text:s,width:0};o.onSegment?.(r,e)}},at=t=>`${R.values().next().value}${Bt}${String(t)}${J}`,ht=t=>`${R.values().next().value}${M}${t}${P}`,We=t=>{if(t.length===0)return"";if(t.length===1)return t[0];let o="",e,i;const l=t.join(`
3
+ `),s=[...l];let n=0;for(const[c,a]of s.entries()){if(o+=a,R.has(a)){const f=ce.exec(l.slice(n))?.groups??{};if(f.code!==void 0){const u=Number.parseFloat(f.code);e=u===re?void 0:u}else f.uri!==void 0&&(i=f.uri.length===0?void 0:f.uri)}const r=ae.get(Number(e));s[c+1]===`
4
+ `?(i&&(o+=ht("")),e&&r&&(o+=at(r))):a===`
5
+ `&&(e&&r&&(o+=at(e)),i&&(o+=ht(i))),n+=a.length}return o},vt=/(?=\s)|(?<=\s)/,St=/^\s+$/,ut=new Map,Te=t=>{const o=ut.get(t);if(o!==void 0)return o;const e=b(t);return ut.set(t,e),e},V=t=>{if(!t.includes("\x1B"))return t;let o=t;return t.includes("\x1B[30m")&&(o+="\x1B[39m"),t.includes("\x1B[42m")&&(o+="\x1B[49m"),o},W=t=>{const o=t.split(" ");let e=o.length;for(;e>0&&b(o[e-1])===0;)e--;return e===o.length?t:o.slice(0,e).join(" ")+o.slice(e).join("")},At=(t,o,e)=>{if(t.length===0)return[""];if(o<=0)return[t];const i=[],l=new Et;let s="",n=0,c=!1,a=!1,r="",f=0;for(;f<t.length;){const u=t.codePointAt(f),p=String.fromCodePoint(u),g=p.length;if(R.has(p)){c=!0,r=p,s+=p,a=t.startsWith(M,f+1),f+=1;continue}if(c){r+=p,s+=p,a?p===P&&(c=a=!1):p===J&&(c=!1,l.processEscape(r)),f+=1;continue}const x=Te(p),d=p===" ";if(x===0){s+=p,f+=g;continue}if(n+x>o&&(s&&i.push(s+l.getEndEscapesForAllActiveAttributes()),s=l.getStartEscapesForAllActiveAttributes(),n=b(s),d&&e)){for(;f<t.length&&t[f]===" ";)f+=1;continue}if(s+=p,n+=x,n===o&&f+g<t.length&&(i.push(s+l.getEndEscapesForAllActiveAttributes()),s=l.getStartEscapesForAllActiveAttributes(),n=b(s),f+g<t.length&&t[f+g]===" "&&e)){for(f+=g;f<t.length&&t[f]===" ";)f+=1;continue}f+=g}return s&&i.push(s+l.getEndEscapesForAllActiveAttributes()),e?i.map(u=>W(u)):i},Re=(t,o,e)=>{if(t.length===0)return[];const i=e?t.trim():t;if(i.length===0)return[];const l=[];let s="",n=0;return ke(i,{getWidth:b,onSegment:(c,a)=>{const r=c.text??"";if(c.isEscapeSequence)s+=r;else{const f=r===" ";if(c.width===0)return s+=r,!0;if(n+c.width>o&&(s&&l.push(s),s=a.getStartEscapesForAllActiveAttributes(),n=0,f))return e||l.push(a.getStartEscapesForAllActiveAttributes()+r),!0;s+=r,n+=c.width}return!0}}),s&&l.push(s),e?l.map(c=>W(c)):l},Ie=(t,o,e)=>{if(t.length===0)return[];const i=e?t.trim():t;if(i.length===0)return[];const l=i.split(vt),s=[];let n="",c=0,a=0;for(;a<l.length;){const r=l[a],f=St.test(r),u=b(r);if(r.length===0){a+=1;continue}if(e&&f&&c===0){a+=1;continue}if(c+u>o&&c>0){e?s.push(W(n)):s.push(n),n="",c=0;continue}n+=r,c+=u,a+=1}return n&&(e?s.push(W(n)):s.push(n)),s},Me=(t,o,e)=>{if(t.length===0)return[];const i=e?t.trim():t;if(i.length===0)return[];const l=i.split(vt),s=[];let n="",c=0,a=0;for(;a<l.length;){const r=l[a],f=St.test(r),u=b(r);if(r.length===0){a+=1;continue}if(e&&f&&c===0){a+=1;continue}if(u>o){n&&s.push(V(e?W(n):n));const p=At(r,o,e);if(p.length>0){for(let g=0;g<p.length-1;g+=1)s.push(p[g]);n=p.at(-1),c=b(n)}else n="",c=0;a+=1;continue}if(c+u>o&&c>0&&(s.push(V(e?W(n):n)),n="",c=0,e&&f)){a+=1;continue}n+=r,c+=u,a+=1}return n&&s.push(V(e?W(n):n)),s},T={BREAK_AT_CHARACTERS:"BREAK_AT_CHARACTERS",BREAK_WORDS:"BREAK_WORDS",PRESERVE_WORDS:"PRESERVE_WORDS",STRICT_WIDTH:"STRICT_WIDTH"},kt=(t,o={})=>{const{removeZeroWidthCharacters:e=!0,trim:i=!0,width:l=80,wrapMode:s=T.PRESERVE_WORDS}=o;if(i&&t.trim()==="")return"";let n=t.normalize("NFC").replaceAll(`\r
6
+ `,`
7
+ `);return e&&(n=n.replaceAll(le,"")),n.split(`
8
+ `).map(c=>{if(i&&c.trim()==="")return"";let a;switch(s){case T.BREAK_AT_CHARACTERS:{a=Re(c,l,i);break}case T.BREAK_WORDS:{a=Me(c,l,i);break}case T.STRICT_WIDTH:{a=At(c,l,i);break}default:a=Ie(c,l,i)}return We(a)}).join(`
9
+ `)},Ne={arrow:{bottom:"↑",bottomLeft:"↗",bottomRight:"↖",left:"→",right:"←",top:"↓",topLeft:"↘",topRight:"↙"},bold:{bottom:"━",bottomLeft:"┗",bottomRight:"┛",left:"┃",right:"┃",top:"━",topLeft:"┏",topRight:"┓"},classic:{bottom:"-",bottomLeft:"+",bottomRight:"+",left:"|",right:"|",top:"-",topLeft:"+",topRight:"+"},double:{bottom:"═",bottomLeft:"╚",bottomRight:"╝",left:"║",right:"║",top:"═",topLeft:"╔",topRight:"╗"},doubleSingle:{bottom:"═",bottomLeft:"╘",bottomRight:"╛",left:"│",right:"│",top:"═",topLeft:"╒",topRight:"╕"},none:{bottom:"",bottomLeft:"",bottomRight:"",left:"",right:"",top:"",topLeft:"",topRight:""},round:{bottom:"─",bottomLeft:"╰",bottomRight:"╯",left:"│",right:"│",top:"─",topLeft:"╭",topRight:"╮"},single:{bottom:"─",bottomLeft:"└",bottomRight:"┘",left:"│",right:"│",top:"─",topLeft:"┌",topRight:"┐"},singleDouble:{bottom:"─",bottomLeft:"╙",bottomRight:"╜",left:"║",right:"║",top:"─",topLeft:"╓",topRight:"╖"}},Wt=80,Tt=24,C=()=>globalThis.process,K=t=>{const o=C();if(typeof o?.getBuiltinModule=="function")try{return o.getBuiltinModule(t)}catch{return}},H=(t,o)=>({columns:Number.parseInt(String(t),10),rows:Number.parseInt(String(o),10)}),Rt=(t,o)=>{const{columns:e,rows:i}=H(t,o);if(!(Number.isNaN(e)||Number.isNaN(i))&&!(e===Wt&&i===Tt))return{columns:e,rows:i}},Z=(t,o,e)=>{const i=K("node:child_process");if(i?.execFileSync!==void 0)return i.execFileSync(t,o,{encoding:"utf8",env:e,stdio:["ignore","pipe","ignore"],timeout:500}).trim()},Fe=()=>{if(C()?.platform!=="linux")return!0;try{const t=K("node:fs");if(t===void 0)return!1;const o=t.readFileSync("/proc/self/stat","utf8"),e=o.lastIndexOf(") ");if(e===-1)return!1;const i=o.slice(e+2).trim().split(/\s+/),l=Number.parseInt(i[2],10),s=Number.parseInt(i[5],10);return Number.isNaN(l)||Number.isNaN(s)||s<=0?!1:l===s}catch{return!1}},ft=()=>{try{const t=K("node:fs"),o=K("node:tty");if(t===void 0||o===void 0)return;const e=C()?.platform==="darwin"?t.constants.O_EVTONLY|t.constants.O_NONBLOCK:t.constants.O_NONBLOCK,{columns:i,rows:l}=o.WriteStream(t.openSync("/dev/tty",e));return i===void 0||l===void 0?void 0:{columns:i,rows:l}}catch{return}},U=()=>{try{const t={TERM:"dumb",...C()?.env},o=Z("tput",["cols"],t),e=Z("tput",["lines"],t);return o&&e?Rt(o,e):void 0}catch{return}},Le=()=>{try{if(!Fe())return;const t=Z("resize",["-u"])?.match(/\d+/g);return t?.length===2?Rt(t[0],t[1]):void 0}catch{return}},Ce=()=>{const t=C(),{env:o,stderr:e,stdout:i}=t??{};if(i?.columns&&i?.rows)return H(i.columns,i.rows);if(e?.columns&&e?.rows)return H(e.columns,e.rows);if(o?.COLUMNS&&o?.LINES)return H(o.COLUMNS,o.LINES);const l={columns:Wt,rows:Tt};return typeof t?.getBuiltinModule!="function"?l:t.platform==="win32"?U()??l:t.platform==="darwin"?ft()??U()??l:ft()??U()??Le()??l},It=t=>{let o=0;for(const e of t.split(`
10
+ `))o=Math.max(o,b(e));return o},k=`
11
+ `,y=" ",N="none";let dt;const Oe=()=>(dt??=Ce(),dt),S=t=>Math.max(0,Math.floor(t)),mt=t=>{if(typeof t=="number")return{bottom:S(t),left:S(t*3),right:S(t*3),top:S(t)};const o={bottom:0,left:0,right:0,top:0,...t};return{bottom:S(o.bottom),left:S(o.left),right:S(o.right),top:S(o.top)}},F=t=>t===N?0:2,$e=t=>{const o=["topLeft","topRight","bottomRight","bottomLeft","left","right","top","bottom"];let e;if(t===N){t={};for(const i of o)t[i]=""}if(typeof t=="string"){const i=Ne[t];if(i===void 0)throw new TypeError(`Invalid border style: ${t}`);e=i}else{t={...t},typeof t.vertical=="string"&&(t.left=t.vertical,t.right=t.vertical),typeof t.horizontal=="string"&&(t.top=t.horizontal,t.bottom=t.horizontal);for(const i of o)if(typeof t[i]!="string")throw new TypeError(`Invalid border style: ${i}`);e=t}return e},pt=(t,o,e,i,l)=>{t=o(t);const s=b(t);let n;switch(l){case"left":{const c=A(e,s);n=t+i(c,b(c));break}case"right":{const c=A(e,s+2);n=`${i(c,b(c))} ${t} `;break}default:{if(e=e.slice(s),b(e)%2===1)e=A(e,Math.floor(b(e)/2)),n=i(A(e,1),b(A(e,1)))+t+i(e,b(e));else{e=A(e,b(e)/2);const c=b(e);n=i(e,c)+t+i(e,c)}break}}return n},je=(t,{height:o,padding:e,textAlignment:i,verticalAlignment:l,width:s})=>{t=nt(t,{align:i});let n=t.split(k);const c=It(t),a=s-e.left-e.right;if(c>a){const u=[];for(const p of n){const g=kt(p,{width:a,wrapMode:T.BREAK_WORDS}),x=nt(g,{align:i}).split(`
12
+ `),d=Math.max(...x.map(m=>b(m)));for(const m of x){let h;switch(i){case"center":{h=y.repeat(Math.max(0,(a-d)/2))+m;break}case"right":{h=y.repeat(Math.max(0,a-d))+m;break}default:{h=m;break}}u.push(h)}}n=u}i==="center"&&c<a?n=n.map(u=>y.repeat((a-c)/2)+u):i==="right"&&c<a&&(n=n.map(u=>y.repeat(a-c)+u));const r=y.repeat(e.left),f=y.repeat(e.right);if(n=n.map(u=>{const p=r+u+f,g=s-b(p);return p+y.repeat(Math.max(g,0))}),e.top>0&&(n=[...Array.from({length:e.top}).fill(y.repeat(s)),...n]),e.bottom>0&&(n=[...n,...Array.from({length:e.bottom}).fill(y.repeat(s))]),o&&n.length>o)n=n.slice(0,o);else if(o&&n.length<o){const u=o-n.length,p=y.repeat(s);switch(l){case"bottom":{n=[...Array.from({length:u}).fill(p),...n];break}case"center":{const g=Math.floor(u/2),x=u-g;n=[...Array.from({length:g}).fill(p),...n,...Array.from({length:x}).fill(p)];break}default:{n=[...n,...Array.from({length:u}).fill(p)];break}}}return n.join(k)},_e=(t,o,e,i)=>{const l=(h,w,v)=>i.borderColor?i.borderColor(h,w,v):h,s=h=>i.headerTextColor?i.headerTextColor(h):h,n=h=>i.footerTextColor?i.footerTextColor(h):h,c=h=>i.textColor?i.textColor(h):h,a=h=>i.backgroundColor?i.backgroundColor(h):h,r=$e(i.borderStyle);let f=y.repeat(i.margin.left);if(i.float==="center"){const h=Math.max((e-o-F(i.borderStyle))/2,0);f=y.repeat(h)}else if(i.float==="right"){const h=Math.max(e-o-i.margin.right-F(i.borderStyle),0);f=y.repeat(h)}let u="";if(i.margin.top&&(u+=k.repeat(i.margin.top)),i.borderStyle!==N||i.headerText){let h=l(r.top.repeat(o),"top",o);i.headerText&&(h=pt(i.headerText,s,r.top.repeat(o),(v,B)=>l(v,"top",B),i.headerAlignment));const w=f+l(r.topLeft,"topLeft",b(r.topLeft));u+=w+h+l(r.topRight,"topRight",b(r.topRight))+k}const p=t.split(k),g=b(r.left),x=b(r.right),d=f+l(r.left,"left",g),m=l(r.right,"right",x);if(u+=p.map(h=>d+a(c(h))+m).join(k),i.borderStyle!==N||i.footerText){const h=k+f+l(r.bottomLeft,"bottomLeft",b(r.bottomLeft));let w=l(r.bottom.repeat(o),"bottom",o);i.footerText&&(w=pt(i.footerText,n,r.bottom.repeat(o),(v,B)=>l(v,"bottom",B),i.footerAlignment)),u+=h+w+l(r.bottomRight,"bottomRight",b(r.bottomRight))}return i.margin.bottom&&(u+=k.repeat(i.margin.bottom)),u},ze=t=>{let o,e;if(Array.isArray(t))[o,e]=t;else if(t&&typeof t=="object")({columns:o,rows:e}=t);else throw new TypeError(`"fullscreen" callback must return a [width, height] tuple or { columns, rows } object, got ${typeof t}`);if(typeof o!="number"||typeof e!="number"||Number.isNaN(o)||Number.isNaN(e))throw new TypeError('"fullscreen" callback returned invalid dimensions; both width and height must be numbers');return{columns:o,rows:e}},He=(t,o)=>{if(t.fullscreen){const{columns:e,rows:i}=typeof t.fullscreen=="function"?ze(t.fullscreen(o.columns,o.rows)):o;t.width??=e,t.height??=i}return t.width&&(t.width=Math.max(1,t.width-F(t.borderStyle))),t.height&&(t.height=Math.max(1,t.height-F(t.borderStyle))),t},gt=(t,o)=>o===N?t:` ${t} `,De=(t,o,e,i)=>{e=He(e,i);const l=e.width!==void 0,s=F(e.borderStyle),n=o-e.margin.left-e.margin.right-s,c=l?0:It(kt(t,{trim:!1,width:o-s,wrapMode:T.BREAK_WORDS}))+e.padding.left+e.padding.right;if(e.headerText&&l?(e.headerText=A(e.headerText,0,Math.max(0,e.width-2)),e.headerText&&(e.headerText=gt(e.headerText,e.borderStyle))):e.headerText&&(e.headerText=A(e.headerText,0,Math.max(0,n-2)),e.headerText&&(e.headerText=gt(e.headerText,e.borderStyle),b(e.headerText)>c&&(e.width=b(e.headerText)))),e.width=e.width??c,!l){if(e.margin.left&&e.margin.right&&e.width>n){const a=(o-e.width-s)/(e.margin.left+e.margin.right);e.margin.left=Math.max(0,Math.floor(e.margin.left*a)),e.margin.right=Math.max(0,Math.floor(e.margin.right*a))}e.width=Math.min(e.width,o-s-e.margin.left-e.margin.right)}return e.width-(e.padding.left+e.padding.right)<=0&&(e.padding.left=0,e.padding.right=0),e.height&&e.height-(e.padding.top+e.padding.bottom)<=0&&(e.padding.top=0,e.padding.bottom=0),e},Ke=t=>t===null?"null":typeof t,I=(t,o)=>{if(t!==void 0&&typeof t!="function")throw new TypeError(`"${o}" must be a function, got ${Ke(t)}`)},Pe=(t,o={})=>{if(I(o.borderColor,"borderColor"),I(o.textColor,"textColor"),I(o.backgroundColor,"backgroundColor"),I(o.headerTextColor,"headerTextColor"),I(o.footerTextColor,"footerTextColor"),o.fullscreen!==void 0&&typeof o.fullscreen!="boolean"&&typeof o.fullscreen!="function")throw new TypeError(`"fullscreen" must be a boolean or a function, got ${typeof o.fullscreen}`);let e={borderStyle:"single",float:"left",footerAlignment:"right",headerAlignment:"left",textAlignment:"left",transformTabToSpace:4,verticalAlignment:"top",...o};e.padding=mt(o.padding??0),e.margin=mt(o.margin),e.transformTabToSpace&&(t=t.replaceAll(" "," ".repeat(e.transformTabToSpace)));const i=o.terminalColumns===void 0||e.fullscreen&&o.terminalRows===void 0?Oe():{columns:0,rows:0},l={columns:o.terminalColumns??i.columns,rows:o.terminalRows??i.rows},{columns:s}=l;return e=De(t,s,e,l),_e(je(t,e),e.width,s,e)},qe=t=>t.replace(/^\s*#+\s*/,"").trim(),Ge=async(t,o,e=!1,i)=>{const l=[...o,Ct,Ot].toSorted((c,a)=>a.priority-c.priority),s=Mt(t,{frameLimit:1})[0]??{},n=s.file?await Ft(s.file):"";for(const c of l){const{handle:a,name:r}=c;if(e&&(i??console).log(`[solution-finder] running: ${r??"anonymous"}`),typeof a!="function")continue;const f=await a(t,{file:s.file??"",language:Lt(s.file??""),line:s.line??0,snippet:n});if(f)return e&&(i??console).log(`[solution-finder] matched: ${r??"anonymous"}`),f}},Ve=async(t,o,e)=>{const{solutionFinders:i=[],solutionTitle:l,color:s,debug:n=!1,...c}=o,a=Nt(t,{...c,color:s?.codeFrame}),r=await Ge(t,i,n,e);if(!r)return{errorAnsi:a,solutionBox:void 0};const f=qe(r.header??l??"A possible solution to this error"),u=Pe(r.body,{borderStyle:"round",padding:{top:1,right:2,bottom:1,left:2},margin:{top:0,right:0,bottom:0,left:0},headerText:`💡 ${f}`,headerAlignment:"left",textAlignment:"left",...s?.boxen});return{errorAnsi:a,solutionBox:u}},Xe=async(t,o={})=>{const{logger:e=console,...i}=o,{errorAnsi:l,solutionBox:s}=await Ve(t,i,e);e.error(l),s&&(e.log(""),e.log(s))};export{Ve as buildOutput,Xe as terminalOutput};
@@ -0,0 +1 @@
1
+ import{Accepts as f}from"@tinyhttp/accepts";import{jsonErrorHandler as h}from"../error-handler/json-error-handler.js";import{jsonpErrorHandler as b}from"../error-handler/jsonp-error-handler.js";import p from"../error-handler/problem-error-handler.js";import{textErrorHandler as H}from"../error-handler/text-error-handler.js";import{w as k}from"./with-expose-BhBvHI1y.js";const w=b(),y=h(),E=H();let s,c;const v=async()=>(s??=import("../error-handler/jsonapi-error-handler.js").then(t=>t.default),s),u=async()=>(c??=import("../error-handler/xml-error-handler.js").then(t=>t.xmlErrorHandler()),c),V=(t,l,e)=>async(n,r,m)=>{const i=new f(r).type(["text/html","application/vnd.api+json","application/problem+json","application/json","text/plain","application/javascript","text/javascript","application/xml","text/xml"]);let a=e??p;if(i==="text/html"&&e)a=e;else switch(i){case"application/javascript":case"text/javascript":{a=w;break}case"application/json":{a=y;break}case"application/problem+json":{a=p;break}case"application/vnd.api+json":{a=await v();break}case"application/xml":case"text/xml":{a=await u();break}case"text/plain":{a=E;break}}for(const{handler:d,regex:x}of t){const o=r.headers.accept??"",j=Array.isArray(o)?o.join(","):o;if(x.test(j)){a=d;break}}await k(n,l,()=>a(n,r,m))};export{V as default};
@@ -0,0 +1 @@
1
+ import{StatusCodes as u}from"http-status-codes";const n=(e,s=u.INTERNAL_SERVER_ERROR)=>{if(!e)return s;const t=Number(e.statusCode??e.status);return Number.isInteger(t)&&t>=400&&t<=599?t:s};export{n as default};
@@ -0,0 +1 @@
1
+ import{jsonErrorHandler as w}from"../error-handler/json-error-handler.js";import{jsonpErrorHandler as k}from"../error-handler/jsonp-error-handler.js";import H from"../error-handler/problem-error-handler.js";import{textErrorHandler as v}from"../error-handler/text-error-handler.js";import{M as E}from"./mock-server-response-Ci40Hny9.js";import{w as T}from"./with-expose-BhBvHI1y.js";const g=[{chosen:"text/html",types:["text/html"]},{chosen:"application/vnd.api+json",types:["application/vnd.api+json"]},{chosen:"application/problem+json",types:["application/problem+json"]},{chosen:"application/json",types:["application/json"]},{chosen:"text/plain",types:["text/plain"]},{chosen:"application/javascript",types:["application/javascript","text/javascript"]},{chosen:"application/xml",types:["application/xml","text/xml"]}],F=n=>{if(!n)return"text/html";const i=[];for(const o of n.split(",")){const[r,...t]=o.trim().split(";"),s=(r??"").trim().toLowerCase();if(s==="")continue;let a=1;for(const h of t){const[f,y]=h.trim().split("=");if((f??"").trim().toLowerCase()==="q"){const u=Number.parseFloat((y??"").trim());Number.isNaN(u)||(a=u)}}if(a<=0)continue;const[l="",d=""]=s.split("/");i.push({quality:a,subtype:d,type:l})}if(i.length===0)return"text/html";const c=o=>{const[r,t]=o.split("/");let s=-1;for(const{quality:a,subtype:l,type:d}of i)(d==="*"&&l==="*"||d===r&&l==="*"||d===r&&l===t)&&a>s&&(s=a);return s};let p="text/html",e=-1;for(const{chosen:o,types:r}of g){let t=-1;for(const s of r){const a=c(s);a>t&&(t=a)}t>e&&(e=t,p=o)}return e<0?"text/html":p},m=n=>async(i,c)=>{const p={headers:Object.fromEntries(c.headers.entries()),method:c.method,url:c.url},e=new E;await n(i,p,e);const o={};for(const[r,t]of Object.entries(e.headers))o[r]=Array.isArray(t)?t.join(", "):String(t);return new Response(e.body,{headers:o,status:e.statusCode})},S=m(k()),N=m(w()),x=m(H),A=m(v());let b,j;const C=async()=>(b??=import("../error-handler/jsonapi-error-handler.js").then(n=>m(n.default)),b),J=async()=>(j??=import("../error-handler/xml-error-handler.js").then(n=>m(n.xmlErrorHandler())),j),Q=(n,i,c)=>async(p,e)=>{const o=e.headers.get("accept"),r=F(o);let t=c??x;if(r==="text/html"&&c)t=c;else switch(r){case"application/javascript":{t=S;break}case"application/json":{t=N;break}case"application/problem+json":{t=x;break}case"application/vnd.api+json":{t=await C();break}case"application/xml":{t=await J();break}case"text/plain":{t=A;break}}for(const{handler:s,regex:a}of n){const l=o??"";if(a.test(l)){t=s;break}}return T(p,i,()=>t(p,e))};export{Q as default};
@@ -0,0 +1 @@
1
+ import{htmlErrorHandler as m}from"../error-handler/html-error-handler.js";import{M as i}from"./mock-server-response-Ci40Hny9.js";const y=(s={})=>{const c=m(s);return async(a,t)=>{const d={headers:Object.fromEntries(t.headers.entries()),method:t.method,url:t.url},e=new i;await c(a,d,e);const r={"content-type":e.getHeader("content-type")??"text/html; charset=utf-8"};for(const[o,n]of Object.entries(e.headers))o!=="content-type"&&(r[o]=Array.isArray(n)?n.join(", "):String(n));return new Response(e.body,{headers:r,status:e.statusCode})}};export{y as default,y as fetchHtmlErrorHandler};
@@ -0,0 +1 @@
1
+ import{createRequire as d}from"node:module";let p;const h=e=>(p??=d(import.meta.url))(e),c=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,o=e=>{if(typeof c<"u"&&c.versions&&c.versions.node){const[t,s]=c.versions.node.split(".").map(Number);if(t>22||t===22&&s>=3||t===20&&s>=16)return c.getBuiltinModule(e)}return h(e)},{readFile:l}=o("node:fs/promises"),{isAbsolute:m}=o("node:path"),{fileURLToPath:f}=o("node:url"),_=new Set(["cjs","mjs"]),v=new Set(["cts","mts"]),j=new Set(["mdoc"]),T=e=>{const s=(e.split("?")[0]??e).split(".").pop()?.toLowerCase();if(!s)return"text";if(_.has(s))return"javascript";if(v.has(s))return"typescript";if(j.has(s))return"markdown";switch(s){case"js":return"javascript";case"json":return"json";case"json5":return"json5";case"jsonc":return"jsonc";case"jsx":return"jsx";case"sql":return"sql";case"ts":return"typescript";case"tsx":return"tsx";case"xml":return"xml";case"md":return"markdown";case"mdx":return"mdx";case"svelte":return"svelte";case"vue":return"vue";case"html":return"html";case"css":return"css";case"scss":return"scss";case"less":return"less";case"sass":return"sass";case"stylus":return"stylus";case"styl":return"styl";case"yaml":case"yml":return"yaml";case"toml":return"toml";case"py":return"python";case"go":return"go";case"rs":return"rust";case"rb":return"ruby";case"php":return"php";case"graphql":case"gql":return"graphql";case"dockerfile":return"dockerfile";case"sh":case"bash":return"bash";case"txt":return"text";default:return"text"}},g=50,r=new Map,x=e=>{const t=r.get(e);if(t!==void 0)return r.delete(e),r.set(e,t),t},a=(e,t)=>{if(r.has(e))r.delete(e);else if(r.size>=g){const s=r.keys().next().value;s!==void 0&&r.delete(s)}r.set(e,t)},w=async(e,t={})=>{const{allowRemote:s=!1}=t,u=x(e);if(u!==void 0)return u;if(e.startsWith("file:"))try{const n=await l(f(e),"utf8");return a(e,n),n}catch{return}if(/^(?:https?|data):/.test(e)){if(!s)return;try{const n=await fetch(e);if(!n.ok)return;const i=await n.text();return a(e,i),i}catch{return}}if(m(e))try{const n=await l(e,"utf8");return a(e,n),n}catch{return}};export{T as f,w as g};
@@ -0,0 +1 @@
1
+ class a{statusCode=200;statusMessage="";headers={};headersSent=!1;writable=!0;finished=!1;writableEnded=!1;writableFinished=!1;writableHighWaterMark=16384;writableLength=0;destroyed=!1;writableCorked=0;readable=!1;readableHighWaterMark=16384;readableLength=0;errored=void 0;closed=!1;readableAborted=!1;readableDidRead=!1;readableEncoding=void 0;readableEnded=!1;readableFlowing=void 0;body="";sendDate=!0;strictContentLength=!1;chunkedEncoding=!1;shouldKeepAlive=!0;useChunkedEncodingByDefault=!0;connection=void 0;socket=void 0;setHeader(e,t){return this.headers[e.toLowerCase()]=t,this}getHeader(e){return this.headers[e.toLowerCase()]}getHeaders(){return{...this.headers}}getHeaderNames(){return Object.keys(this.headers)}hasHeader(e){return e.toLowerCase()in this.headers}removeHeader(e){return delete this.headers[e.toLowerCase()],this}writeHead(e,t,r){this.statusCode=e;let s=r;return typeof t=="string"&&(this.statusMessage=t),typeof t=="object"&&(s=t),s&&Object.assign(this.headers,s),this}write(e){return this.body+=e.toString(),!0}end(e,t,r){return e&&(this.body+=e.toString()),this.finished=!0,this}flushHeaders(){this.headersSent=!0}addListener=()=>this;on=()=>this;once=()=>this;removeListener=()=>this;off=()=>this;removeAllListeners=()=>this;setMaxListeners=()=>this;getMaxListeners=()=>10;listeners=()=>[];rawListeners=()=>[];emit=()=>!1;eventNames=()=>[];listenerCount=()=>0;prependListener=()=>this;prependOnceListener=()=>this;cork=()=>{};uncork=()=>{};destroy=()=>this;read=()=>{};setEncoding=()=>this;pause=()=>this;resume=()=>this;isPaused=()=>!1;destroySoon=()=>this;pipe=()=>({});unpipe=()=>this;unshift=()=>{};wrap=()=>this;setTimeout=()=>this;assignSocket=()=>{};detachSocket=()=>{};writeContinue=()=>{};writeEarlyHints=()=>{}}export{a as M};
@@ -0,0 +1 @@
1
+ import{StatusCodes as a,getReasonPhrase as o}from"http-status-codes";const d=(t,e)=>{const r=e,s=Number(r.statusCode??r.status);if(Number.isInteger(s)&&s>=400&&s<=599){t.statusCode=s;return}t.statusCode<400&&(t.statusCode=a.INTERNAL_SERVER_ERROR)},n=(t,e="An error occurred")=>{try{return o(t)}catch{return e}};export{d as a,n as s};
@@ -0,0 +1 @@
1
+ const s=(t,n,e="application/json; charset=utf-8")=>{t.setHeader("content-type",e),t.end(JSON.stringify(n))};export{s};
@@ -0,0 +1 @@
1
+ const n=(e,s,t="application/json; charset=utf-8")=>Response.json(e,{headers:{"content-type":t},status:s});export{n as default};
@@ -0,0 +1 @@
1
+ const a=(r,t)=>{const e=t.headers??{};Object.keys(e).forEach(s=>{r.setHeader(s,e[s])})};export{a as s};
@@ -0,0 +1 @@
1
+ const n=async(e,s,p)=>{const t=Object.hasOwn(e,"expose"),x=e.expose;s?"expose"in e||(e.expose=!0):e.expose=!1;try{return await p()}finally{t?e.expose=x:delete e.expose}};export{n as w};