@visulima/connect 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 CHANGED
@@ -1,3 +1,11 @@
1
+ ## @visulima/connect [2.0.1](https://github.com/visulima/visulima/compare/@visulima/connect@2.0.0...@visulima/connect@2.0.1) (2023-08-29)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * fixed wrong settings for node 18+ in typescript ([ac6711f](https://github.com/visulima/visulima/commit/ac6711fd2b4fdc5506b03e3a6ae25bb983aa6ea3))
7
+ * remove unused files and refactor imports and typings ([ba2ab03](https://github.com/visulima/visulima/commit/ba2ab03d2d7aff5f49c4d6714a61b99706778f19))
8
+
1
9
  ## @visulima/connect [2.0.0](https://github.com/visulima/visulima/compare/@visulima/connect@1.3.8...@visulima/connect@2.0.0) (2023-08-28)
2
10
 
3
11
 
package/dist/index.js CHANGED
@@ -1,23 +1,23 @@
1
1
  'use strict';
2
2
 
3
- var S = require('http-errors');
3
+ var N = require('http-errors');
4
4
  var zod = require('zod');
5
5
  var regexparam = require('regexparam');
6
6
 
7
7
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
8
 
9
- var S__default = /*#__PURE__*/_interopDefault(S);
9
+ var N__default = /*#__PURE__*/_interopDefault(N);
10
10
 
11
- var q=o=>async(e,t,s)=>await new Promise((n,r)=>{o(e,t,R=>R?r(R):n());}).then(s),M=q;var g=(o,e)=>async(t,s,n)=>{let r=t;try{r=await o.parseAsync(t);}catch(R){let{message:a}=R;throw R instanceof zod.ZodError&&typeof R.format=="function"&&(a=R.issues.map(d=>`${d.path.join("/")} - ${d.message}`).join("/n")),S__default.default(422,a)}return e(r,s,n)},l=g;var i=class o{constructor(e="/",t=[]){this.base=e;this.routes=t;}static async exec(e,...t){let s=0,n=()=>e[++s](...t,n);return e[s](...t,n)}add(e,t,...s){if(typeof t=="function"&&(s.unshift(t),t=""),t==="")this.routes.push({fns:s,isMiddleware:!1,matchAll:!0,method:e});else {let{keys:n,pattern:r}=regexparam.parse(t);this.routes.push({fns:s,isMiddleware:!1,keys:n,method:e,pattern:r});}return this}clone(e){return new o(e,[...this.routes])}find(e,t){let s=!0,n=[],r={},R=e==="HEAD";return Object.values(this.routes).forEach(a=>{if(a.method!==e&&a.method!==""&&!(R&&a.method==="GET"))return;let d=!1;if("matchAll"in a)d=!0;else if(a.keys===!1){let u=a.pattern.exec(t);if(u===null)return;u.groups!==void 0&&Object.keys(u.groups).forEach(p=>{r[p]=u.groups[p];}),d=!0;}else if(a.keys.length>0){let u=a.pattern.exec(t);if(u===null)return;for(let p=0;p<a.keys.length;){let c=a.keys[p];r[c]=u[++p];}d=!0;}else a.pattern.test(t)&&(d=!0);d&&(n.push(...a.fns.flatMap(u=>{if(u instanceof o){let{base:p}=u,c=t.slice(p.length);c.startsWith("/")||(c=`/${c}`);let m=u.find(e,c);return m.middleOnly||(s=!1),Object.assign(r,m.params),m.fns}return u})),a.isMiddleware||(s=!1));}),{fns:n,middleOnly:s,params:r}}use(e,...t){(typeof e=="function"||e instanceof o)&&(t.unshift(e),e="/"),t=t.map(r=>{if(r instanceof o){if(typeof e=="string")return r.clone(e);throw new Error("Mounting a router to RegExp base is not supported")}return r});let{keys:s,pattern:n}=regexparam.parse(e,!0);return this.routes.push({fns:t,isMiddleware:!0,keys:s,method:"",pattern:n}),this}};var E=async o=>new Response(o.method==="HEAD"?null:`Route ${o.method} ${o.url} not found`,{status:404}),k=async o=>(console.error(o),new Response("Internal Server Error",{status:500})),H=o=>(o.nextUrl??new URL(o.url)).pathname,h=class o{constructor(e={}){this.router=new i;this.all=this.add.bind(this,"");this.delete=this.add.bind(this,"DELETE");this.get=this.add.bind(this,"GET");this.head=this.add.bind(this,"HEAD");this.patch=this.add.bind(this,"PATCH");this.post=this.add.bind(this,"POST");this.put=this.add.bind(this,"PUT");this.onNoMatch=e.onNoMatch??E,this.onError=e.onError??k;}add(e,t,s,...n){return typeof t=="string"&&typeof s=="function"?n=[s]:typeof s=="object"?typeof t=="function"?n=[l(s,t)]:n=n.map(r=>l(s,r)):typeof s=="function"&&(n=[s]),this.router.add(e,t,...n),this}prepareRequest(e,t){e.params={...t.params,...e.params};}clone(){let e=new o({onError:this.onError,onNoMatch:this.onNoMatch});return e.router=this.router.clone(),e}handler(){let{routes:e}=this.router;return async(t,s)=>{let n=this.router.find(t.method,H(t));this.prepareRequest(t,n);try{return await(n.fns.length===0||n.middleOnly?this.onNoMatch(t,s,e):i.exec(n.fns,t,s))}catch(r){return await this.onError(r,t,s,e)}}}async run(e,t){let s=this.router.find(e.method,H(e));if(s.fns.length!==0)return this.prepareRequest(e,s),await i.exec(s.fns,e,t)}use(e,...t){return (typeof e=="function"||e instanceof o)&&(t.unshift(e),e="/"),this.router.use(e,...t.map(s=>s instanceof o?s.router:s)),this}},C=(o={})=>new h(o);var w=async(o,e)=>{e.statusCode=404,e.end(o.method==="HEAD"?void 0:`Route ${o.method} ${o.url} not found`);},v=async(o,e,t)=>{t.statusCode=500,console.error(o),t.end("Internal Server Error");},y=o=>{let e=o.indexOf("?");return e===-1?o:o.slice(0,Math.max(0,e))},x=class o{constructor(e={}){this.router=new i;this.all=this.add.bind(this,"");this.delete=this.add.bind(this,"DELETE");this.get=this.add.bind(this,"GET");this.head=this.add.bind(this,"HEAD");this.patch=this.add.bind(this,"PATCH");this.post=this.add.bind(this,"POST");this.put=this.add.bind(this,"PUT");this.onNoMatch=e.onNoMatch??w,this.onError=e.onError??v;}add(e,t,s,...n){return typeof t=="string"&&typeof s=="function"?n=[s]:typeof s=="object"?typeof t=="function"?n=[l(s,t)]:n=n.map(r=>l(s,r)):typeof s=="function"&&(n=[s]),this.router.add(e,t,...n),this}prepareRequest(e,t){e.params={...t.params,...e.params};}clone(){let e=new o({onError:this.onError,onNoMatch:this.onNoMatch});return e.router=this.router.clone(),e}handler(){let{routes:e}=this.router;return async(t,s)=>{let n=this.router.find(t.method,y(t.url));this.prepareRequest(t,n);try{await(n.fns.length===0||n.middleOnly?this.onNoMatch(t,s,e):i.exec(n.fns,t,s));}catch(r){await this.onError(r,t,s,e);}}}async run(e,t){let s=this.router.find(e.method,y(e.url));if(s.fns.length!==0)return this.prepareRequest(e,s),await i.exec(s.fns,e,t)}use(e,...t){return (typeof e=="function"||e instanceof o)&&(t.unshift(e),e="/"),this.router.use(e,...t.map(s=>s instanceof o?s.router:s)),this}},b=(o={})=>new x(o);var L=(o,e,t)=>{o.setHeader("content-type","application/json; charset=utf-8"),o.statusCode=e,o.end(JSON.stringify(t,null,2));},j=L;
11
+ var M=o=>async(e,t,s)=>await new Promise((n,r)=>{o(e,t,R=>R?r(R):n());}).then(s),S=M;var E=(o,e)=>async(t,s,n)=>{let r=t;try{r=await o.parseAsync(t);}catch(R){let{message:a}=R;throw R instanceof zod.ZodError&&typeof R.format=="function"&&(a=R.issues.map(d=>`${d.path.join("/")} - ${d.message}`).join("/n")),N__default.default(422,a)}return e(r,s,n)},l=E;var i=class o{constructor(e="/",t=[]){this.base=e;this.routes=t;}static async exec(e,...t){let s=0,n=()=>e[++s](...t,n);return e[s](...t,n)}add(e,t,...s){if(typeof t=="function"&&(s.unshift(t),t=""),t==="")this.routes.push({fns:s,isMiddleware:!1,matchAll:!0,method:e});else {let{keys:n,pattern:r}=regexparam.parse(t);this.routes.push({fns:s,isMiddleware:!1,keys:n,method:e,pattern:r});}return this}clone(e){return new o(e,[...this.routes])}find(e,t){let s=!0,n=[],r={},R=e==="HEAD";return Object.values(this.routes).forEach(a=>{if(a.method!==e&&a.method!==""&&!(R&&a.method==="GET"))return;let d=!1;if("matchAll"in a)d=!0;else if(a.keys===!1){let u=a.pattern.exec(t);if(u===null)return;u.groups!==void 0&&Object.keys(u.groups).forEach(p=>{r[p]=u.groups[p];}),d=!0;}else if(a.keys.length>0){let u=a.pattern.exec(t);if(u===null)return;for(let p=0;p<a.keys.length;){let c=a.keys[p];r[c]=u[++p];}d=!0;}else a.pattern.test(t)&&(d=!0);d&&(n.push(...a.fns.flatMap(u=>{if(u instanceof o){let{base:p}=u,c=t.slice(p.length);c.startsWith("/")||(c=`/${c}`);let f=u.find(e,c);return f.middleOnly||(s=!1),Object.assign(r,f.params),f.fns}return u})),a.isMiddleware||(s=!1));}),{fns:n,middleOnly:s,params:r}}use(e,...t){(typeof e=="function"||e instanceof o)&&(t.unshift(e),e="/"),t=t.map(r=>{if(r instanceof o){if(typeof e=="string")return r.clone(e);throw new Error("Mounting a router to RegExp base is not supported")}return r});let{keys:s,pattern:n}=regexparam.parse(e,!0);return this.routes.push({fns:t,isMiddleware:!0,keys:s,method:"",pattern:n}),this}};var k=async o=>new Response(o.method==="HEAD"?null:`Route ${o.method} ${o.url} not found`,{status:404}),C=async o=>(console.error(o),new Response("Internal Server Error",{status:500})),y=o=>(o.nextUrl??new URL(o.url)).pathname,x=class o{constructor(e={}){this.router=new i;this.all=this.add.bind(this,"");this.delete=this.add.bind(this,"DELETE");this.get=this.add.bind(this,"GET");this.head=this.add.bind(this,"HEAD");this.patch=this.add.bind(this,"PATCH");this.post=this.add.bind(this,"POST");this.put=this.add.bind(this,"PUT");this.onNoMatch=e.onNoMatch??k,this.onError=e.onError??C;}add(e,t,s,...n){return typeof t=="string"&&typeof s=="function"?n=[s]:typeof s=="object"?typeof t=="function"?n=[l(s,t)]:n=n.map(r=>l(s,r)):typeof s=="function"&&(n=[s]),this.router.add(e,t,...n),this}prepareRequest(e,t){e.params={...t.params,...e.params};}clone(){let e=new o({onError:this.onError,onNoMatch:this.onNoMatch});return e.router=this.router.clone(),e}handler(){let{routes:e}=this.router;return async(t,s)=>{let n=this.router.find(t.method,y(t));this.prepareRequest(t,n);try{return await(n.fns.length===0||n.middleOnly?this.onNoMatch(t,s,e):i.exec(n.fns,t,s))}catch(r){return await this.onError(r,t,s,e)}}}async run(e,t){let s=this.router.find(e.method,y(e));if(s.fns.length!==0)return this.prepareRequest(e,s),await i.exec(s.fns,e,t)}use(e,...t){return (typeof e=="function"||e instanceof o)&&(t.unshift(e),e="/"),this.router.use(e,...t.map(s=>s instanceof o?s.router:s)),this}},w=(o={})=>new x(o);var v=async(o,e)=>{e.statusCode=404,e.end(o.method==="HEAD"?void 0:`Route ${o.method} ${o.url} not found`);},L=async(o,e,t)=>{t.statusCode=500,console.error(o),t.end("Internal Server Error");},b=o=>{let e=o.indexOf("?");return e===-1?o:o.slice(0,Math.max(0,e))},m=class o{constructor(e={}){this.router=new i;this.all=this.add.bind(this,"");this.delete=this.add.bind(this,"DELETE");this.get=this.add.bind(this,"GET");this.head=this.add.bind(this,"HEAD");this.patch=this.add.bind(this,"PATCH");this.post=this.add.bind(this,"POST");this.put=this.add.bind(this,"PUT");this.onNoMatch=e.onNoMatch??v,this.onError=e.onError??L;}add(e,t,s,...n){return typeof t=="string"&&typeof s=="function"?n=[s]:typeof s=="object"?typeof t=="function"?n=[l(s,t)]:n=n.map(r=>l(s,r)):typeof s=="function"&&(n=[s]),this.router.add(e,t,...n),this}prepareRequest(e,t){e.params={...t.params,...e.params};}clone(){let e=new o({onError:this.onError,onNoMatch:this.onNoMatch});return e.router=this.router.clone(),e}handler(){let{routes:e}=this.router;return async(t,s)=>{let n=this.router.find(t.method,b(t.url));this.prepareRequest(t,n);try{await(n.fns.length===0||n.middleOnly?this.onNoMatch(t,s,e):i.exec(n.fns,t,s));}catch(r){await this.onError(r,t,s,e);}}}async run(e,t){let s=this.router.find(e.method,b(e.url));if(s.fns.length!==0)return this.prepareRequest(e,s),await i.exec(s.fns,e,t)}use(e,...t){return (typeof e=="function"||e instanceof o)&&(t.unshift(e),e="/"),this.router.use(e,...t.map(s=>s instanceof o?s.router:s)),this}},q=(o={})=>new m(o);var j=(o,e,t)=>{o.setHeader("content-type","application/json; charset=utf-8"),o.statusCode=e,o.end(JSON.stringify(t,null,2));},P=j;
12
12
 
13
- exports.EdgeRouter = h;
14
- exports.NodeRouter = x;
13
+ exports.EdgeRouter = x;
14
+ exports.NodeRouter = m;
15
15
  exports.Router = i;
16
- exports.createEdgeRouter = C;
17
- exports.createNodeRouter = b;
18
- exports.createRouter = b;
19
- exports.expressWrapper = M;
20
- exports.sendJson = j;
16
+ exports.createEdgeRouter = w;
17
+ exports.createNodeRouter = q;
18
+ exports.createRouter = q;
19
+ exports.expressWrapper = S;
20
+ exports.sendJson = P;
21
21
  exports.withZod = l;
22
22
  //# sourceMappingURL=out.js.map
23
23
  //# sourceMappingURL=index.js.map
package/dist/index.mjs CHANGED
@@ -1,9 +1,9 @@
1
- import S from 'http-errors';
1
+ import g from 'http-errors';
2
2
  import { ZodError } from 'zod';
3
3
  import { parse } from 'regexparam';
4
4
 
5
- var q=o=>async(e,t,s)=>await new Promise((n,r)=>{o(e,t,R=>R?r(R):n());}).then(s),M=q;var g=(o,e)=>async(t,s,n)=>{let r=t;try{r=await o.parseAsync(t);}catch(R){let{message:a}=R;throw R instanceof ZodError&&typeof R.format=="function"&&(a=R.issues.map(d=>`${d.path.join("/")} - ${d.message}`).join("/n")),S(422,a)}return e(r,s,n)},l=g;var i=class o{constructor(e="/",t=[]){this.base=e;this.routes=t;}static async exec(e,...t){let s=0,n=()=>e[++s](...t,n);return e[s](...t,n)}add(e,t,...s){if(typeof t=="function"&&(s.unshift(t),t=""),t==="")this.routes.push({fns:s,isMiddleware:!1,matchAll:!0,method:e});else {let{keys:n,pattern:r}=parse(t);this.routes.push({fns:s,isMiddleware:!1,keys:n,method:e,pattern:r});}return this}clone(e){return new o(e,[...this.routes])}find(e,t){let s=!0,n=[],r={},R=e==="HEAD";return Object.values(this.routes).forEach(a=>{if(a.method!==e&&a.method!==""&&!(R&&a.method==="GET"))return;let d=!1;if("matchAll"in a)d=!0;else if(a.keys===!1){let u=a.pattern.exec(t);if(u===null)return;u.groups!==void 0&&Object.keys(u.groups).forEach(p=>{r[p]=u.groups[p];}),d=!0;}else if(a.keys.length>0){let u=a.pattern.exec(t);if(u===null)return;for(let p=0;p<a.keys.length;){let c=a.keys[p];r[c]=u[++p];}d=!0;}else a.pattern.test(t)&&(d=!0);d&&(n.push(...a.fns.flatMap(u=>{if(u instanceof o){let{base:p}=u,c=t.slice(p.length);c.startsWith("/")||(c=`/${c}`);let m=u.find(e,c);return m.middleOnly||(s=!1),Object.assign(r,m.params),m.fns}return u})),a.isMiddleware||(s=!1));}),{fns:n,middleOnly:s,params:r}}use(e,...t){(typeof e=="function"||e instanceof o)&&(t.unshift(e),e="/"),t=t.map(r=>{if(r instanceof o){if(typeof e=="string")return r.clone(e);throw new Error("Mounting a router to RegExp base is not supported")}return r});let{keys:s,pattern:n}=parse(e,!0);return this.routes.push({fns:t,isMiddleware:!0,keys:s,method:"",pattern:n}),this}};var E=async o=>new Response(o.method==="HEAD"?null:`Route ${o.method} ${o.url} not found`,{status:404}),k=async o=>(console.error(o),new Response("Internal Server Error",{status:500})),H=o=>(o.nextUrl??new URL(o.url)).pathname,h=class o{constructor(e={}){this.router=new i;this.all=this.add.bind(this,"");this.delete=this.add.bind(this,"DELETE");this.get=this.add.bind(this,"GET");this.head=this.add.bind(this,"HEAD");this.patch=this.add.bind(this,"PATCH");this.post=this.add.bind(this,"POST");this.put=this.add.bind(this,"PUT");this.onNoMatch=e.onNoMatch??E,this.onError=e.onError??k;}add(e,t,s,...n){return typeof t=="string"&&typeof s=="function"?n=[s]:typeof s=="object"?typeof t=="function"?n=[l(s,t)]:n=n.map(r=>l(s,r)):typeof s=="function"&&(n=[s]),this.router.add(e,t,...n),this}prepareRequest(e,t){e.params={...t.params,...e.params};}clone(){let e=new o({onError:this.onError,onNoMatch:this.onNoMatch});return e.router=this.router.clone(),e}handler(){let{routes:e}=this.router;return async(t,s)=>{let n=this.router.find(t.method,H(t));this.prepareRequest(t,n);try{return await(n.fns.length===0||n.middleOnly?this.onNoMatch(t,s,e):i.exec(n.fns,t,s))}catch(r){return await this.onError(r,t,s,e)}}}async run(e,t){let s=this.router.find(e.method,H(e));if(s.fns.length!==0)return this.prepareRequest(e,s),await i.exec(s.fns,e,t)}use(e,...t){return (typeof e=="function"||e instanceof o)&&(t.unshift(e),e="/"),this.router.use(e,...t.map(s=>s instanceof o?s.router:s)),this}},C=(o={})=>new h(o);var w=async(o,e)=>{e.statusCode=404,e.end(o.method==="HEAD"?void 0:`Route ${o.method} ${o.url} not found`);},v=async(o,e,t)=>{t.statusCode=500,console.error(o),t.end("Internal Server Error");},y=o=>{let e=o.indexOf("?");return e===-1?o:o.slice(0,Math.max(0,e))},x=class o{constructor(e={}){this.router=new i;this.all=this.add.bind(this,"");this.delete=this.add.bind(this,"DELETE");this.get=this.add.bind(this,"GET");this.head=this.add.bind(this,"HEAD");this.patch=this.add.bind(this,"PATCH");this.post=this.add.bind(this,"POST");this.put=this.add.bind(this,"PUT");this.onNoMatch=e.onNoMatch??w,this.onError=e.onError??v;}add(e,t,s,...n){return typeof t=="string"&&typeof s=="function"?n=[s]:typeof s=="object"?typeof t=="function"?n=[l(s,t)]:n=n.map(r=>l(s,r)):typeof s=="function"&&(n=[s]),this.router.add(e,t,...n),this}prepareRequest(e,t){e.params={...t.params,...e.params};}clone(){let e=new o({onError:this.onError,onNoMatch:this.onNoMatch});return e.router=this.router.clone(),e}handler(){let{routes:e}=this.router;return async(t,s)=>{let n=this.router.find(t.method,y(t.url));this.prepareRequest(t,n);try{await(n.fns.length===0||n.middleOnly?this.onNoMatch(t,s,e):i.exec(n.fns,t,s));}catch(r){await this.onError(r,t,s,e);}}}async run(e,t){let s=this.router.find(e.method,y(e.url));if(s.fns.length!==0)return this.prepareRequest(e,s),await i.exec(s.fns,e,t)}use(e,...t){return (typeof e=="function"||e instanceof o)&&(t.unshift(e),e="/"),this.router.use(e,...t.map(s=>s instanceof o?s.router:s)),this}},b=(o={})=>new x(o);var L=(o,e,t)=>{o.setHeader("content-type","application/json; charset=utf-8"),o.statusCode=e,o.end(JSON.stringify(t,null,2));},j=L;
5
+ var S=o=>async(e,t,s)=>await new Promise((n,r)=>{o(e,t,R=>R?r(R):n());}).then(s),N=S;var k=(o,e)=>async(t,s,n)=>{let r=t;try{r=await o.parseAsync(t);}catch(R){let{message:a}=R;throw R instanceof ZodError&&typeof R.format=="function"&&(a=R.issues.map(d=>`${d.path.join("/")} - ${d.message}`).join("/n")),g(422,a)}return e(r,s,n)},l=k;var i=class o{constructor(e="/",t=[]){this.base=e;this.routes=t;}static async exec(e,...t){let s=0,n=()=>e[++s](...t,n);return e[s](...t,n)}add(e,t,...s){if(typeof t=="function"&&(s.unshift(t),t=""),t==="")this.routes.push({fns:s,isMiddleware:!1,matchAll:!0,method:e});else {let{keys:n,pattern:r}=parse(t);this.routes.push({fns:s,isMiddleware:!1,keys:n,method:e,pattern:r});}return this}clone(e){return new o(e,[...this.routes])}find(e,t){let s=!0,n=[],r={},R=e==="HEAD";return Object.values(this.routes).forEach(a=>{if(a.method!==e&&a.method!==""&&!(R&&a.method==="GET"))return;let d=!1;if("matchAll"in a)d=!0;else if(a.keys===!1){let u=a.pattern.exec(t);if(u===null)return;u.groups!==void 0&&Object.keys(u.groups).forEach(p=>{r[p]=u.groups[p];}),d=!0;}else if(a.keys.length>0){let u=a.pattern.exec(t);if(u===null)return;for(let p=0;p<a.keys.length;){let c=a.keys[p];r[c]=u[++p];}d=!0;}else a.pattern.test(t)&&(d=!0);d&&(n.push(...a.fns.flatMap(u=>{if(u instanceof o){let{base:p}=u,c=t.slice(p.length);c.startsWith("/")||(c=`/${c}`);let H=u.find(e,c);return H.middleOnly||(s=!1),Object.assign(r,H.params),H.fns}return u})),a.isMiddleware||(s=!1));}),{fns:n,middleOnly:s,params:r}}use(e,...t){(typeof e=="function"||e instanceof o)&&(t.unshift(e),e="/"),t=t.map(r=>{if(r instanceof o){if(typeof e=="string")return r.clone(e);throw new Error("Mounting a router to RegExp base is not supported")}return r});let{keys:s,pattern:n}=parse(e,!0);return this.routes.push({fns:t,isMiddleware:!0,keys:s,method:"",pattern:n}),this}};var C=async o=>new Response(o.method==="HEAD"?null:`Route ${o.method} ${o.url} not found`,{status:404}),w=async o=>(console.error(o),new Response("Internal Server Error",{status:500})),b=o=>(o.nextUrl??new URL(o.url)).pathname,m=class o{constructor(e={}){this.router=new i;this.all=this.add.bind(this,"");this.delete=this.add.bind(this,"DELETE");this.get=this.add.bind(this,"GET");this.head=this.add.bind(this,"HEAD");this.patch=this.add.bind(this,"PATCH");this.post=this.add.bind(this,"POST");this.put=this.add.bind(this,"PUT");this.onNoMatch=e.onNoMatch??C,this.onError=e.onError??w;}add(e,t,s,...n){return typeof t=="string"&&typeof s=="function"?n=[s]:typeof s=="object"?typeof t=="function"?n=[l(s,t)]:n=n.map(r=>l(s,r)):typeof s=="function"&&(n=[s]),this.router.add(e,t,...n),this}prepareRequest(e,t){e.params={...t.params,...e.params};}clone(){let e=new o({onError:this.onError,onNoMatch:this.onNoMatch});return e.router=this.router.clone(),e}handler(){let{routes:e}=this.router;return async(t,s)=>{let n=this.router.find(t.method,b(t));this.prepareRequest(t,n);try{return await(n.fns.length===0||n.middleOnly?this.onNoMatch(t,s,e):i.exec(n.fns,t,s))}catch(r){return await this.onError(r,t,s,e)}}}async run(e,t){let s=this.router.find(e.method,b(e));if(s.fns.length!==0)return this.prepareRequest(e,s),await i.exec(s.fns,e,t)}use(e,...t){return (typeof e=="function"||e instanceof o)&&(t.unshift(e),e="/"),this.router.use(e,...t.map(s=>s instanceof o?s.router:s)),this}},v=(o={})=>new m(o);var L=async(o,e)=>{e.statusCode=404,e.end(o.method==="HEAD"?void 0:`Route ${o.method} ${o.url} not found`);},j=async(o,e,t)=>{t.statusCode=500,console.error(o),t.end("Internal Server Error");},q=o=>{let e=o.indexOf("?");return e===-1?o:o.slice(0,Math.max(0,e))},f=class o{constructor(e={}){this.router=new i;this.all=this.add.bind(this,"");this.delete=this.add.bind(this,"DELETE");this.get=this.add.bind(this,"GET");this.head=this.add.bind(this,"HEAD");this.patch=this.add.bind(this,"PATCH");this.post=this.add.bind(this,"POST");this.put=this.add.bind(this,"PUT");this.onNoMatch=e.onNoMatch??L,this.onError=e.onError??j;}add(e,t,s,...n){return typeof t=="string"&&typeof s=="function"?n=[s]:typeof s=="object"?typeof t=="function"?n=[l(s,t)]:n=n.map(r=>l(s,r)):typeof s=="function"&&(n=[s]),this.router.add(e,t,...n),this}prepareRequest(e,t){e.params={...t.params,...e.params};}clone(){let e=new o({onError:this.onError,onNoMatch:this.onNoMatch});return e.router=this.router.clone(),e}handler(){let{routes:e}=this.router;return async(t,s)=>{let n=this.router.find(t.method,q(t.url));this.prepareRequest(t,n);try{await(n.fns.length===0||n.middleOnly?this.onNoMatch(t,s,e):i.exec(n.fns,t,s));}catch(r){await this.onError(r,t,s,e);}}}async run(e,t){let s=this.router.find(e.method,q(e.url));if(s.fns.length!==0)return this.prepareRequest(e,s),await i.exec(s.fns,e,t)}use(e,...t){return (typeof e=="function"||e instanceof o)&&(t.unshift(e),e="/"),this.router.use(e,...t.map(s=>s instanceof o?s.router:s)),this}},M=(o={})=>new f(o);var P=(o,e,t)=>{o.setHeader("content-type","application/json; charset=utf-8"),o.statusCode=e,o.end(JSON.stringify(t,null,2));},Z=P;
6
6
 
7
- export { h as EdgeRouter, x as NodeRouter, i as Router, C as createEdgeRouter, b as createNodeRouter, b as createRouter, M as expressWrapper, j as sendJson, l as withZod };
7
+ export { m as EdgeRouter, f as NodeRouter, i as Router, v as createEdgeRouter, M as createNodeRouter, M as createRouter, N as expressWrapper, Z as sendJson, l as withZod };
8
8
  //# sourceMappingURL=out.js.map
9
9
  //# sourceMappingURL=index.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/connect",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "The minimal router and middleware layer for Next.js, Micro, Vercel, or Node.js http/http2 with support for zod validation.",
5
5
  "keywords": [
6
6
  "javascript",
@@ -42,8 +42,14 @@
42
42
  "exports": {
43
43
  ".": {
44
44
  "types": "./dist/index.d.ts",
45
- "require": "./dist/index.js",
46
- "import": "./dist/index.mjs"
45
+ "require": {
46
+ "types": "./dist/index.d.ts",
47
+ "default": "./dist/index.js"
48
+ },
49
+ "import": {
50
+ "types": "./dist/index.d.mts",
51
+ "default": "./dist/index.mjs"
52
+ }
47
53
  },
48
54
  "./package.json": "./package.json"
49
55
  },
@@ -63,7 +69,7 @@
63
69
  "clean": "rimraf node_modules dist .eslintcache",
64
70
  "coverage": "vitest run --coverage",
65
71
  "dev": "pnpm run build --watch",
66
- "lint:eslint": "eslint . --ext js,cjs,mjs,ts,tsx,json,yaml,yml,md,mdx --max-warnings=0 --config .eslintrc.js",
72
+ "lint:eslint": "eslint . --ext js,cjs,mjs,jsx,ts,tsx,json,yaml,yml,md,mdx --max-warnings=0 --config .eslintrc.js",
67
73
  "lint:eslint:fix": "pnpm run lint:eslint --fix",
68
74
  "lint:prettier": "prettier --config=.prettierrc.js --check .",
69
75
  "lint:prettier:fix": "prettier --config=.prettierrc.js --write .",