@visulima/error-handler 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/LICENSE.md +14 -17
- package/dist/error-handler/html-error-handler.d.ts +17 -29
- package/dist/error-handler/html-error-handler.js +5 -5
- package/dist/error-handler/json-error-handler.js +1 -1
- package/dist/error-handler/jsonapi-error-handler.js +1 -1
- package/dist/error-handler/jsonp-error-handler.js +1 -1
- package/dist/error-handler/problem-error-handler.d.ts +3 -3
- package/dist/error-handler/problem-error-handler.js +1 -1
- package/dist/error-handler/text-error-handler.js +2 -2
- package/dist/error-handler/xml-error-handler.js +1 -1
- package/dist/handler/cli-handler.js +1 -1
- package/dist/handler/http/create-error-middleware.d.ts +19 -18
- package/dist/handler/http/create-error-middleware.js +1 -1
- package/dist/handler/http/fetch-handler.js +1 -1
- package/dist/handler/http/node-handler.js +1 -1
- package/dist/index.js +1 -1
- package/dist/packem_shared/{cliHandler-BGq-ckC0.js → cliHandler-SiB_2eYh.js} +25 -25
- package/dist/packem_shared/createNegotiatedErrorHandler-B5QZvIsI.js +1 -0
- package/dist/packem_shared/fetchCreateNegotiatedErrorHandler-BZIDeXwJ.js +1 -0
- package/dist/packem_shared/fetchHtmlErrorHandler-C_tTx5yo.js +1 -0
- package/dist/packem_shared/get-file-source-DizRP9BY.js +1 -0
- package/dist/packem_shared/mock-server-response-B0aq8b_2.js +1 -0
- package/dist/packem_shared/safe-reason-phrase-DgnEIVUq.js +1 -0
- package/dist/packem_shared/with-expose-B0GLDHH8.js +1 -0
- package/package.json +17 -17
- package/dist/packem_shared/add-status-code-to-response-DwELM1q2.js +0 -1
- package/dist/packem_shared/createNegotiatedErrorHandler-CcWOSpO5.js +0 -1
- package/dist/packem_shared/fetchCreateNegotiatedErrorHandler-D9YQ8pOH.js +0 -1
- package/dist/packem_shared/fetchHtmlErrorHandler-Cu50Zu5a.js +0 -1
- package/dist/packem_shared/get-file-source-By3_8e1o.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Accepts as d}from"@tinyhttp/accepts";import{jsonErrorHandler as b}from"../error-handler/json-error-handler.js";import{jsonpErrorHandler as k}from"../error-handler/jsonp-error-handler.js";import n from"../error-handler/problem-error-handler.js";import{textErrorHandler as y}from"../error-handler/text-error-handler.js";import{x as h}from"./with-expose-B0GLDHH8.js";const v=k(),w=b(),E=y();let s,c;const H=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),B=(t,l,r)=>async(i,e,m)=>{const p=new d(e).type(["text/html","application/vnd.api+json","application/problem+json","application/json","text/plain","application/javascript","text/javascript","application/xml","text/xml"]);let a=r??n;if(p==="text/html"&&r)a=r;else switch(p){case"application/javascript":case"text/javascript":{a=v;break}case"application/json":{a=w;break}case"application/problem+json":{a=n;break}case"application/vnd.api+json":{a=await H();break}case"application/xml":case"text/xml":{a=await u();break}case"text/plain":{a=E;break}}for(const{handler:x,regex:f}of t){const o=e.headers.accept??"",j=Array.isArray(o)?o.join(","):o;if(f.test(j)){a=x;break}}await h(i,l,()=>a(i,e,m))};export{B as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsonErrorHandler as v}from"../error-handler/json-error-handler.js";import{jsonpErrorHandler as w}from"../error-handler/jsonp-error-handler.js";import k from"../error-handler/problem-error-handler.js";import{textErrorHandler as E}from"../error-handler/text-error-handler.js";import{s as N}from"./mock-server-response-B0aq8b_2.js";import{x as g}from"./with-expose-B0GLDHH8.js";const q=[{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"]}],H=n=>{if(!n)return"text/html";const p=[];for(const o of n.split(",")){const[a,...t]=o.trim().split(";"),s=(a??"").trim().toLowerCase();if(s==="")continue;let r=1;for(const d of t){const[b,j]=d.trim().split("=");if((b??"").trim().toLowerCase()==="q"){const h=Number.parseFloat((j??"").trim());Number.isNaN(h)||(r=h)}}if(r<=0)continue;const[l="",f=""]=s.split("/");p.push({quality:r,subtype:f,type:l})}if(p.length===0)return"text/html";const i=o=>{const[a,t]=o.split("/");let s=-1;for(const{quality:r,subtype:l,type:f}of p)(f==="*"&&l==="*"||f===a&&l==="*"||f===a&&l===t)&&r>s&&(s=r);return s};let c="text/html",e=-1;for(const{chosen:o,types:a}of q){let t=-1;for(const s of a){const r=i(s);r>t&&(t=r)}t>e&&(e=t,c=o)}return e<0?"text/html":c},m=n=>async(p,i)=>{const c={headers:Object.fromEntries(i.headers.entries()),method:i.method,url:i.url},e=new N;await n(p,c,e);const o={};for(const[a,t]of Object.entries(e.headers))o[a]=Array.isArray(t)?t.join(", "):String(t);return new Response(e.body,{headers:o,status:e.statusCode})},A=m(w()),C=m(v()),x=m(k),F=m(E());let y,u;const L=async()=>(y??=import("../error-handler/jsonapi-error-handler.js").then(n=>m(n.default)),y),O=async()=>(u??=import("../error-handler/xml-error-handler.js").then(n=>m(n.xmlErrorHandler())),u),B=(n,p,i)=>async(c,e)=>{const o=e.headers.get("accept"),a=H(o);let t=i??x;if(a==="text/html"&&i)t=i;else switch(a){case"application/javascript":{t=A;break}case"application/json":{t=C;break}case"application/problem+json":{t=x;break}case"application/vnd.api+json":{t=await L();break}case"application/xml":{t=await O();break}case"text/plain":{t=F;break}}for(const{handler:s,regex:r}of n){const l=o??"";if(r.test(l)){t=s;break}}return g(c,p,()=>t(c,e))};export{B as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{htmlErrorHandler as m}from"../error-handler/html-error-handler.js";import{s as h}from"./mock-server-response-B0aq8b_2.js";const l=(s={})=>{const a=m(s);return async(c,e)=>{const d={headers:Object.fromEntries(e.headers.entries()),method:e.method,url:e.url},t=new h;await a(c,d,t);const n={"content-type":t.getHeader("content-type")??"text/html; charset=utf-8"};for(const[o,r]of Object.entries(t.headers))o!=="content-type"&&(n[o]=Array.isArray(r)?r.join(", "):String(r));return new Response(t.body,{headers:n,status:t.statusCode})}};export{l as default,l as fetchHtmlErrorHandler};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createRequire as f}from"node:module";let p;const d=e=>(p??=f(import.meta.url))(e),c=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,u=e=>{if(typeof c<"u"&&c.versions&&c.versions.node){const[t,n]=c.versions.node.split(".").map(Number);if(t>22||t===22&&n>=3||t===20&&n>=16)return c.getBuiltinModule(e)}return d(e)},{readFile:l}=u("node:fs/promises"),{isAbsolute:h}=u("node:path"),{fileURLToPath:m}=u("node:url"),y=new Set(["cjs","mjs"]),j=new Set(["cts","mts"]),x=new Set(["mdoc"]),g=e=>{const t=(e.split("?")[0]??e).split(".").pop()?.toLowerCase();if(!t)return"text";if(y.has(t))return"javascript";if(j.has(t))return"typescript";if(x.has(t))return"markdown";switch(t){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"}},_=50,s=new Map,v=e=>{const t=s.get(e);if(t!==void 0)return s.delete(e),s.set(e,t),t},a=(e,t)=>{if(s.has(e))s.delete(e);else if(s.size>=_){const n=s.keys().next().value;n!==void 0&&s.delete(n)}s.set(e,t)},b=async(e,t={})=>{const{allowRemote:n=!1}=t,o=v(e);if(o!==void 0)return o;if(e.startsWith("file:"))try{const r=await l(m(e),"utf8");return a(e,r),r}catch{return}if(/^(?:https?|data):/.test(e)){if(!n)return;try{const r=await fetch(e);if(!r.ok)return;const i=await r.text();return a(e,i),i}catch{return}}if(h(e))try{const r=await l(e,"utf8");return a(e,r),r}catch{return}};export{g as a,b as h};
|
|
@@ -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 s};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{StatusCodes as o,getReasonPhrase as u}from"http-status-codes";const n=(t,s)=>{const r=s,e=Number(r.statusCode??r.status);if(Number.isInteger(e)&&e>=400&&e<=599){t.statusCode=e;return}t.statusCode<400&&(t.statusCode=o.INTERNAL_SERVER_ERROR)},c=(t,s="An error occurred")=>{try{return u(t)}catch{return s}};export{n as a,c as n};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const x=async(e,s,o)=>{const p=Object.hasOwn(e,"expose"),t=e.expose;s?"expose"in e||(e.expose=!0):e.expose=!1;try{return await o()}finally{p?e.expose=t:delete e.expose}};export{x};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visulima/error-handler",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Error handlers for use in development and production environments.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"anolilab",
|
|
@@ -36,6 +36,11 @@
|
|
|
36
36
|
],
|
|
37
37
|
"homepage": "https://visulima.com/packages/error-handler",
|
|
38
38
|
"bugs": "https://github.com/visulima/visulima/issues",
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"author": {
|
|
41
|
+
"name": "Daniel Bannert",
|
|
42
|
+
"email": "d.bannert@anolilab.de"
|
|
43
|
+
},
|
|
39
44
|
"repository": {
|
|
40
45
|
"type": "git",
|
|
41
46
|
"url": "git+https://github.com/visulima/visulima.git",
|
|
@@ -51,13 +56,13 @@
|
|
|
51
56
|
"url": "https://anolilab.com/support"
|
|
52
57
|
}
|
|
53
58
|
],
|
|
54
|
-
"
|
|
55
|
-
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
|
|
59
|
-
"sideEffects": false,
|
|
59
|
+
"files": [
|
|
60
|
+
"dist",
|
|
61
|
+
"README.md",
|
|
62
|
+
"CHANGELOG.md"
|
|
63
|
+
],
|
|
60
64
|
"type": "module",
|
|
65
|
+
"sideEffects": false,
|
|
61
66
|
"exports": {
|
|
62
67
|
".": {
|
|
63
68
|
"types": "./dist/index.d.ts",
|
|
@@ -133,14 +138,13 @@
|
|
|
133
138
|
},
|
|
134
139
|
"./package.json": "./package.json"
|
|
135
140
|
},
|
|
136
|
-
"
|
|
137
|
-
"
|
|
138
|
-
"
|
|
139
|
-
|
|
140
|
-
],
|
|
141
|
+
"publishConfig": {
|
|
142
|
+
"access": "public",
|
|
143
|
+
"provenance": true
|
|
144
|
+
},
|
|
141
145
|
"dependencies": {
|
|
142
146
|
"@tinyhttp/accepts": "^2.3.0",
|
|
143
|
-
"@visulima/error": "6.
|
|
147
|
+
"@visulima/error": "6.1.0",
|
|
144
148
|
"http-errors": "^2.0.1",
|
|
145
149
|
"http-status-codes": "^2.3.0",
|
|
146
150
|
"jstoxml": "^7.1.0",
|
|
@@ -148,9 +152,5 @@
|
|
|
148
152
|
},
|
|
149
153
|
"engines": {
|
|
150
154
|
"node": "^22.14.0 || >=24.10.0"
|
|
151
|
-
},
|
|
152
|
-
"publishConfig": {
|
|
153
|
-
"access": "public",
|
|
154
|
-
"provenance": true
|
|
155
155
|
}
|
|
156
156
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{StatusCodes as u}from"http-status-codes";const r=(s,o)=>{const e=o,t=Number(e.statusCode??e.status);if(Number.isInteger(t)&&t>=400&&t<=599){s.statusCode=t;return}s.statusCode<400&&(s.statusCode=u.INTERNAL_SERVER_ERROR)};export{r as a};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Accepts as d}from"@tinyhttp/accepts";import{jsonErrorHandler as b}from"../error-handler/json-error-handler.js";import{jsonpErrorHandler as y}from"../error-handler/jsonp-error-handler.js";import n from"../error-handler/problem-error-handler.js";import{textErrorHandler as h}from"../error-handler/text-error-handler.js";const w=y(),k=b(),v=h();let c,l;const E=async()=>(c??=import("../error-handler/jsonapi-error-handler.js").then(a=>a.default),c),u=async()=>(l??=import("../error-handler/xml-error-handler.js").then(a=>a.xmlErrorHandler()),l),H=async(a,p,e)=>{const o=Object.hasOwn(a,"expose"),r=a.expose;p?"expose"in a||(a.expose=!0):a.expose=!1;try{await e()}finally{o?a.expose=r:delete a.expose}},q=(a,p,e)=>async(o,r,x)=>{const s=new d(r).type(["text/html","application/vnd.api+json","application/problem+json","application/json","text/plain","application/javascript","text/javascript","application/xml","text/xml"]);let t=e??n;if(s==="text/html"&&e)t=e;else switch(s){case"application/javascript":case"text/javascript":{t=w;break}case"application/json":{t=k;break}case"application/problem+json":{t=n;break}case"application/vnd.api+json":{t=await E();break}case"application/xml":case"text/xml":{t=await u();break}case"text/plain":{t=v;break}}for(const{handler:m,regex:j}of a){const i=r.headers.accept??"",f=Array.isArray(i)?i.join(","):i;if(j.test(f)){t=m;break}}await H(o,p,()=>t(o,r,x))};export{q as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{jsonErrorHandler as w}from"../error-handler/json-error-handler.js";import{jsonpErrorHandler as g}from"../error-handler/jsonp-error-handler.js";import H from"../error-handler/problem-error-handler.js";import{textErrorHandler as k}from"../error-handler/text-error-handler.js";class v{statusCode=200;headers={};responseBody="";setHeader(t,o){this.headers[t.toLowerCase()]=o}getHeader(t){return this.headers[t.toLowerCase()]}getHeaders(){return{...this.headers}}writeHead(t){this.statusCode=t}write(t){this.responseBody+=t.toString()}end(t){t&&(this.responseBody+=t.toString())}flushHeaders(){}}const C=[{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"]}],E=s=>{if(!s)return"text/html";const t=[];for(const r of s.split(",")){const[n,...e]=r.trim().split(";"),p=(n??"").trim().toLowerCase();if(p==="")continue;let i=1;for(const y of e){const[j,b]=y.trim().split("=");if((j??"").trim().toLowerCase()==="q"){const m=Number.parseFloat((b??"").trim());Number.isNaN(m)||(i=m)}}if(i<=0)continue;const[l="",d=""]=p.split("/");t.push({quality:i,subtype:d,type:l})}if(t.length===0)return"text/html";const o=r=>{const[n,e]=r.split("/");let p=-1;for(const{quality:i,subtype:l,type:d}of t)(d==="*"&&l==="*"||d===n&&l==="*"||d===n&&l===e)&&i>p&&(p=i);return p};let c="text/html",a=-1;for(const{chosen:r,types:n}of C){let e=-1;for(const p of n){const i=o(p);i>e&&(e=i)}e>a&&(a=e,c=r)}return a<0?"text/html":c},h=s=>async(t,o)=>{const c={headers:Object.fromEntries(o.headers.entries()),method:o.method,url:o.url},a=new v;await s(t,c,a);const r={};for(const[n,e]of Object.entries(a.headers))r[n]=Array.isArray(e)?e.join(", "):String(e);return new Response(a.responseBody,{headers:r,status:a.statusCode})},B=h(g()),q=h(w()),f=h(H),L=h(k());let u,x;const N=async()=>(u??=import("../error-handler/jsonapi-error-handler.js").then(s=>h(s.default)),u),O=async()=>(x??=import("../error-handler/xml-error-handler.js").then(s=>h(s.xmlErrorHandler())),x),S=async(s,t,o)=>{const c=Object.hasOwn(s,"expose"),a=s.expose;t?"expose"in s||(s.expose=!0):s.expose=!1;try{return await o()}finally{c?s.expose=a:delete s.expose}},T=(s,t,o)=>async(c,a)=>{const r=a.headers.get("accept"),n=E(r);let e=o??f;if(n==="text/html"&&o)e=o;else switch(n){case"application/javascript":{e=B;break}case"application/json":{e=q;break}case"application/problem+json":{e=f;break}case"application/vnd.api+json":{e=await N();break}case"application/xml":{e=await O();break}case"text/plain":{e=L;break}}for(const{handler:p,regex:i}of s){const l=r??"";if(i.test(l)){e=p;break}}return S(c,t,()=>e(c,a))};export{T as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{htmlErrorHandler as h}from"../error-handler/html-error-handler.js";class l{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,s){this.statusCode=e;let r=s;return typeof t=="string"&&(this.statusMessage=t),typeof t=="object"&&(r=t),r&&Object.assign(this.headers,r),this}write(e){return this.body+=e.toString(),!0}end(e,t,s){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=()=>{}}const c=(n={})=>{const e=h(n);return async(t,s)=>{const r={headers:Object.fromEntries(s.headers.entries()),method:s.method,url:s.url},a=new l;await e(t,r,a);const d={"content-type":a.getHeader("content-type")??"text/html; charset=utf-8"};for(const[o,i]of Object.entries(a.headers))o!=="content-type"&&(d[o]=Array.isArray(i)?i.join(", "):String(i));return new Response(a.body,{headers:d,status:a.statusCode})}};export{c as default,c as fetchHtmlErrorHandler};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{createRequire as f}from"node:module";const p=f(import.meta.url),a=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,o=e=>{if(typeof a<"u"&&a.versions&&a.versions.node){const[s,n]=a.versions.node.split(".").map(Number);if(s>22||s===22&&n>=3||s===20&&n>=16)return a.getBuiltinModule(e)}return p(e)},{readFile:l}=o("node:fs/promises"),{isAbsolute:d}=o("node:path"),{fileURLToPath:h}=o("node:url"),m=new Set(["cjs","mjs"]),y=new Set(["cts","mts"]),j=new Set(["mdoc"]),g=e=>{const s=(e.split("?")[0]??e).split(".").pop()?.toLowerCase();if(!s)return"text";if(m.has(s))return"javascript";if(y.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"}},x=50,t=new Map,v=e=>{const s=t.get(e);if(s!==void 0)return t.delete(e),t.set(e,s),s},c=(e,s)=>{if(t.has(e))t.delete(e);else if(t.size>=x){const n=t.keys().next().value;n!==void 0&&t.delete(n)}t.set(e,s)},_=async(e,s={})=>{const{allowRemote:n=!1}=s,u=v(e);if(u!==void 0)return u;if(e.startsWith("file:"))try{const r=await l(h(e),"utf8");return c(e,r),r}catch{return}if(/^(?:https?|data):/.test(e)){if(!n)return;try{const r=await fetch(e);if(!r.ok)return;const i=await r.text();return c(e,i),i}catch{return}}if(d(e))try{const r=await l(e,"utf8");return c(e,r),r}catch{return}};export{g as a,_ as h};
|