@visulima/connect 4.0.0-alpha.11 → 4.0.0-alpha.13

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 (28) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/index.cjs +1 -22
  3. package/dist/index.mjs +1 -6
  4. package/dist/packem_shared/EdgeRouter-BcLsFhoc.mjs +1 -0
  5. package/dist/packem_shared/EdgeRouter-C2WRZNVK.cjs +1 -0
  6. package/dist/packem_shared/Router-CtUe2eVq.cjs +1 -0
  7. package/dist/packem_shared/Router-ZvrvfK8e.mjs +1 -0
  8. package/dist/packem_shared/createRouter-DgHlwXny.cjs +1 -0
  9. package/dist/packem_shared/createRouter-DrcL8lRU.mjs +1 -0
  10. package/dist/packem_shared/expressWrapper-BMEaodw_.mjs +1 -0
  11. package/dist/packem_shared/expressWrapper-C745BRwk.cjs +1 -0
  12. package/dist/packem_shared/sendJson-CIEUTdsi.mjs +1 -0
  13. package/dist/packem_shared/sendJson-CnJbUMZT.cjs +1 -0
  14. package/dist/packem_shared/withZod-B5rDrse4.mjs +1 -0
  15. package/dist/packem_shared/withZod-CQOb0zZR.cjs +1 -0
  16. package/package.json +32 -32
  17. package/dist/packem_shared/EdgeRouter-BHls0yWC.mjs +0 -100
  18. package/dist/packem_shared/EdgeRouter-DTvPX_JS.cjs +0 -106
  19. package/dist/packem_shared/Router-CT_g_29S.mjs +0 -168
  20. package/dist/packem_shared/Router-DMp6zIkp.cjs +0 -172
  21. package/dist/packem_shared/createRouter-B4-TLOnM.cjs +0 -113
  22. package/dist/packem_shared/createRouter-DGGDIRda.mjs +0 -107
  23. package/dist/packem_shared/expressWrapper-CeTFmeNH.mjs +0 -14
  24. package/dist/packem_shared/expressWrapper-oEj2tv9s.cjs +0 -16
  25. package/dist/packem_shared/sendJson-Cd6CsJC_.mjs +0 -7
  26. package/dist/packem_shared/sendJson-DjC80Qht.cjs +0 -9
  27. package/dist/packem_shared/withZod-DMHxmHJB.mjs +0 -15
  28. package/dist/packem_shared/withZod-hpoT0ByV.cjs +0 -34
package/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## @visulima/connect [4.0.0-alpha.13](https://github.com/visulima/visulima/compare/@visulima/connect@4.0.0-alpha.12...@visulima/connect@4.0.0-alpha.13) (2026-05-06)
2
+
3
+ ### Miscellaneous Chores
4
+
5
+ * **connect:** apply lint cleanup from agent batch ([cad7f98](https://github.com/visulima/visulima/commit/cad7f9857c6c86b0d196e9353f094bdc93594f22))
6
+
7
+ ## @visulima/connect [4.0.0-alpha.12](https://github.com/visulima/visulima/compare/@visulima/connect@4.0.0-alpha.11...@visulima/connect@4.0.0-alpha.12) (2026-05-04)
8
+
1
9
  ## @visulima/connect [4.0.0-alpha.11](https://github.com/visulima/visulima/compare/@visulima/connect@4.0.0-alpha.10...@visulima/connect@4.0.0-alpha.11) (2026-04-30)
2
10
 
3
11
  ### Miscellaneous Chores
package/dist/index.cjs CHANGED
@@ -1,22 +1 @@
1
- 'use strict';
2
-
3
- Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
-
5
- const expressWrapper = require('./packem_shared/expressWrapper-oEj2tv9s.cjs');
6
- const withZod = require('./packem_shared/withZod-hpoT0ByV.cjs');
7
- const EdgeRouter = require('./packem_shared/EdgeRouter-DTvPX_JS.cjs');
8
- const createRouter = require('./packem_shared/createRouter-B4-TLOnM.cjs');
9
- const Router = require('./packem_shared/Router-DMp6zIkp.cjs');
10
- const sendJson = require('./packem_shared/sendJson-DjC80Qht.cjs');
11
-
12
-
13
-
14
- exports.expressWrapper = expressWrapper;
15
- exports.withZod = withZod;
16
- exports.EdgeRouter = EdgeRouter.EdgeRouter;
17
- exports.createEdgeRouter = EdgeRouter.createEdgeRouter;
18
- exports.NodeRouter = createRouter.NodeRouter;
19
- exports.createNodeRouter = createRouter.createRouter;
20
- exports.createRouter = createRouter.createRouter;
21
- exports.Router = Router.Router;
22
- exports.sendJson = sendJson;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("./packem_shared/expressWrapper-C745BRwk.cjs"),o=require("./packem_shared/withZod-CQOb0zZR.cjs"),r=require("./packem_shared/EdgeRouter-C2WRZNVK.cjs"),e=require("./packem_shared/createRouter-DgHlwXny.cjs"),u=require("./packem_shared/Router-CtUe2eVq.cjs"),d=require("./packem_shared/sendJson-CnJbUMZT.cjs");exports.expressWrapper=t;exports.withZod=o;exports.EdgeRouter=r.EdgeRouter;exports.createEdgeRouter=r.createEdgeRouter;exports.NodeRouter=e.NodeRouter;exports.createNodeRouter=e.createRouter;exports.createRouter=e.createRouter;exports.Router=u.Router;exports.sendJson=d;
package/dist/index.mjs CHANGED
@@ -1,6 +1 @@
1
- export { default as expressWrapper } from './packem_shared/expressWrapper-CeTFmeNH.mjs';
2
- export { default as withZod } from './packem_shared/withZod-DMHxmHJB.mjs';
3
- export { EdgeRouter, createEdgeRouter } from './packem_shared/EdgeRouter-BHls0yWC.mjs';
4
- export { NodeRouter, createRouter as createNodeRouter, createRouter } from './packem_shared/createRouter-DGGDIRda.mjs';
5
- export { Router } from './packem_shared/Router-CT_g_29S.mjs';
6
- export { default as sendJson } from './packem_shared/sendJson-Cd6CsJC_.mjs';
1
+ import{default as o}from"./packem_shared/expressWrapper-BMEaodw_.mjs";import{default as a}from"./packem_shared/withZod-B5rDrse4.mjs";import{EdgeRouter as d,createEdgeRouter as f}from"./packem_shared/EdgeRouter-BcLsFhoc.mjs";import{NodeRouter as s,createRouter as x,createRouter as R}from"./packem_shared/createRouter-DrcL8lRU.mjs";import{Router as c}from"./packem_shared/Router-ZvrvfK8e.mjs";import{default as g}from"./packem_shared/sendJson-CIEUTdsi.mjs";export{d as EdgeRouter,s as NodeRouter,c as Router,f as createEdgeRouter,x as createNodeRouter,R as createRouter,o as expressWrapper,g as sendJson,a as withZod};
@@ -0,0 +1 @@
1
+ var l=Object.defineProperty;var d=(n,t)=>l(n,"name",{value:t,configurable:!0});import u from"./withZod-B5rDrse4.mjs";import{Router as c}from"./Router-ZvrvfK8e.mjs";var m=Object.defineProperty,h=d((n,t)=>m(n,"name",{value:t,configurable:!0}),"R");const E=h(n=>new Response(n.method==="HEAD"?void 0:`Route ${n.method} ${n.url} not found`,{status:404}),"onNoMatch"),b=h(n=>(globalThis.console.error(n),new Response("Internal Server Error",{status:500})),"onError"),p=h(n=>(n.nextUrl??new URL(n.url)).pathname,"getPathname");class i{static{d(this,"EdgeRouter")}static{h(this,"EdgeRouter")}static prepareRequest(t,r){t.params={...r.params,...t.params}}all=this.add.bind(this,"");connect=this.add.bind(this,"CONNECT");delete=this.add.bind(this,"DELETE");get=this.add.bind(this,"GET");head=this.add.bind(this,"HEAD");options=this.add.bind(this,"OPTIONS");patch=this.add.bind(this,"PATCH");post=this.add.bind(this,"POST");put=this.add.bind(this,"PUT");trace=this.add.bind(this,"TRACE");onError;onNoMatch;router=new c;constructor(t={}){this.onNoMatch=t.onNoMatch??E,this.onError=t.onError??b}clone(){const t=new i({onError:this.onError,onNoMatch:this.onNoMatch});return t.router=this.router.clone(),t}handler(){const{routes:t}=this.router;return async(r,e)=>{const s=p(r),o=r.method,a=this.router.find(o,s);i.prepareRequest(r,a);try{return await(a.fns.length===0||a.middleOnly?this.onNoMatch(r,e,t):c.exec(a.fns,r,e))}catch(f){return await this.onError(f,r,e,t)}}}async run(t,r){const e=p(t),s=t.method,o=this.router.find(s,e);if(o.fns.length!==0)return i.prepareRequest(t,o),c.exec(o.fns,t,r)}use(t,...r){let e;return typeof t=="function"||t instanceof i?(r.unshift(t),e="/"):e=t,this.router.use(e,...r.map(s=>s instanceof i?s.router:s)),this}add(t,r,e,...s){let o;return typeof r=="string"&&typeof e=="function"?o=[e]:typeof e=="object"?o=typeof r=="function"?[u(e,r)]:s.map(a=>u(e,a)):typeof e=="function"?o=[e]:o=s,this.router.add(t,r,...o),this}}const T=h((n={})=>new i(n),"createEdgeRouter");export{i as EdgeRouter,T as createEdgeRouter,p as getPathname};
@@ -0,0 +1 @@
1
+ "use strict";var f=Object.defineProperty;var d=(o,t)=>f(o,"name",{value:t,configurable:!0});Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const l=require("./withZod-CQOb0zZR.cjs"),u=require("./Router-CtUe2eVq.cjs");var E=Object.defineProperty,h=d((o,t)=>E(o,"name",{value:t,configurable:!0}),"R");const b=h(o=>new Response(o.method==="HEAD"?void 0:`Route ${o.method} ${o.url} not found`,{status:404}),"onNoMatch"),m=h(o=>(globalThis.console.error(o),new Response("Internal Server Error",{status:500})),"onError"),c=h(o=>(o.nextUrl??new URL(o.url)).pathname,"getPathname");class i{static{d(this,"EdgeRouter")}static{h(this,"EdgeRouter")}static prepareRequest(t,e){t.params={...e.params,...t.params}}all=this.add.bind(this,"");connect=this.add.bind(this,"CONNECT");delete=this.add.bind(this,"DELETE");get=this.add.bind(this,"GET");head=this.add.bind(this,"HEAD");options=this.add.bind(this,"OPTIONS");patch=this.add.bind(this,"PATCH");post=this.add.bind(this,"POST");put=this.add.bind(this,"PUT");trace=this.add.bind(this,"TRACE");onError;onNoMatch;router=new u.Router;constructor(t={}){this.onNoMatch=t.onNoMatch??b,this.onError=t.onError??m}clone(){const t=new i({onError:this.onError,onNoMatch:this.onNoMatch});return t.router=this.router.clone(),t}handler(){const{routes:t}=this.router;return async(e,r)=>{const s=c(e),n=e.method,a=this.router.find(n,s);i.prepareRequest(e,a);try{return await(a.fns.length===0||a.middleOnly?this.onNoMatch(e,r,t):u.Router.exec(a.fns,e,r))}catch(p){return await this.onError(p,e,r,t)}}}async run(t,e){const r=c(t),s=t.method,n=this.router.find(s,r);if(n.fns.length!==0)return i.prepareRequest(t,n),u.Router.exec(n.fns,t,e)}use(t,...e){let r;return typeof t=="function"||t instanceof i?(e.unshift(t),r="/"):r=t,this.router.use(r,...e.map(s=>s instanceof i?s.router:s)),this}add(t,e,r,...s){let n;return typeof e=="string"&&typeof r=="function"?n=[r]:typeof r=="object"?n=typeof e=="function"?[l(r,e)]:s.map(a=>l(r,a)):typeof r=="function"?n=[r]:n=s,this.router.add(t,e,...n),this}}const R=h((o={})=>new i(o),"createEdgeRouter");exports.EdgeRouter=i;exports.createEdgeRouter=R;exports.getPathname=c;
@@ -0,0 +1 @@
1
+ "use strict";var g=Object.defineProperty;var l=(u,t)=>g(u,"name",{value:t,configurable:!0});Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const h=require("regexparam");var y=Object.defineProperty,d=l((u,t)=>y(u,"name",{value:t,configurable:!0}),"c");class o{static{l(this,"Router")}constructor(t="/",s=[]){this.base=t,this.routes=s}base;routes;static{d(this,"Router")}static exec(t,...s){let e=0;const n=d(()=>{e+=1;const r=t[e];return r===void 0?Promise.resolve():r(...s,n)},"next");return t[e](...s,n)}static extractRegExpParams(t){const s={};if(t.groups===void 0)return s;for(const e of Object.keys(t.groups))s[e]=t.groups[e];return s}static extractKeyedParams(t,s){const e={};for(const[n,r]of s.entries())e[r]=t[n+1];return e}static isMethodMatch(t,s,e){return t===s||t===""||e&&t==="GET"}static matchRoute(t,s){if("matchAll"in t)return{matched:!0,params:{}};if(t.keys===!1){const e=t.pattern.exec(s);return e===null?{matched:!1}:{matched:!0,params:o.extractRegExpParams(e)}}if(t.keys.length>0){const e=t.pattern.exec(s);return e===null?{matched:!1}:{matched:!0,params:o.extractKeyedParams(e,t.keys)}}return t.pattern.test(s)?{matched:!0,params:{}}:{matched:!1}}static resolveRouteFns(t,s,e,n){return t.flatMap(r=>{if(r instanceof o){const{base:c}=r;let a=e.slice(c.length);a.startsWith("/")||(a=`/${a}`);const i=r.find(s,a);return n(i.params,i.middleOnly),i.fns}return[r]})}add(t,s,...e){let n;if(typeof s=="function"?(e.unshift(s),n=""):n=s,n==="")this.routes.push({fns:e,isMiddleware:!1,matchAll:!0,method:t});else{const{keys:r,pattern:c}=h.parse(n);this.routes.push({fns:e,isMiddleware:!1,keys:r,method:t,pattern:c})}return this}clone(t){return new o(t,[...this.routes])}find(t,s){let e=!0;const n=[],r={},c=t==="HEAD";for(let a=0;a<this.routes.length;a+=1){const i=this.routes[a];if(!o.isMethodMatch(i.method,t,c))continue;const f=o.matchRoute(i,s);f.matched&&(Object.assign(r,f.params),n.push(...o.resolveRouteFns(i.fns,t,s,(p,m)=>{Object.assign(r,p),m||(e=!1)})),i.isMiddleware||(e=!1))}return{fns:n,middleOnly:e,params:r}}use(t,...s){let e;typeof t=="function"||t instanceof o?(s.unshift(t),e="/"):e=t;const n=s.map(a=>{if(a instanceof o){if(typeof e=="string")return a.clone(e);throw new Error("Mounting a router to RegExp base is not supported")}return a}),{keys:r,pattern:c}=h.parse(e,!0);return this.routes.push({fns:n,isMiddleware:!0,keys:r,method:"",pattern:c}),this}}exports.Router=o;
@@ -0,0 +1 @@
1
+ var y=Object.defineProperty;var f=(u,t)=>y(u,"name",{value:t,configurable:!0});import{parse as h}from"regexparam";var g=Object.defineProperty,d=f((u,t)=>g(u,"name",{value:t,configurable:!0}),"c");class o{static{f(this,"Router")}constructor(t="/",s=[]){this.base=t,this.routes=s}base;routes;static{d(this,"Router")}static exec(t,...s){let e=0;const n=d(()=>{e+=1;const r=t[e];return r===void 0?Promise.resolve():r(...s,n)},"next");return t[e](...s,n)}static extractRegExpParams(t){const s={};if(t.groups===void 0)return s;for(const e of Object.keys(t.groups))s[e]=t.groups[e];return s}static extractKeyedParams(t,s){const e={};for(const[n,r]of s.entries())e[r]=t[n+1];return e}static isMethodMatch(t,s,e){return t===s||t===""||e&&t==="GET"}static matchRoute(t,s){if("matchAll"in t)return{matched:!0,params:{}};if(t.keys===!1){const e=t.pattern.exec(s);return e===null?{matched:!1}:{matched:!0,params:o.extractRegExpParams(e)}}if(t.keys.length>0){const e=t.pattern.exec(s);return e===null?{matched:!1}:{matched:!0,params:o.extractKeyedParams(e,t.keys)}}return t.pattern.test(s)?{matched:!0,params:{}}:{matched:!1}}static resolveRouteFns(t,s,e,n){return t.flatMap(r=>{if(r instanceof o){const{base:c}=r;let a=e.slice(c.length);a.startsWith("/")||(a=`/${a}`);const i=r.find(s,a);return n(i.params,i.middleOnly),i.fns}return[r]})}add(t,s,...e){let n;if(typeof s=="function"?(e.unshift(s),n=""):n=s,n==="")this.routes.push({fns:e,isMiddleware:!1,matchAll:!0,method:t});else{const{keys:r,pattern:c}=h(n);this.routes.push({fns:e,isMiddleware:!1,keys:r,method:t,pattern:c})}return this}clone(t){return new o(t,[...this.routes])}find(t,s){let e=!0;const n=[],r={},c=t==="HEAD";for(let a=0;a<this.routes.length;a+=1){const i=this.routes[a];if(!o.isMethodMatch(i.method,t,c))continue;const l=o.matchRoute(i,s);l.matched&&(Object.assign(r,l.params),n.push(...o.resolveRouteFns(i.fns,t,s,(p,m)=>{Object.assign(r,p),m||(e=!1)})),i.isMiddleware||(e=!1))}return{fns:n,middleOnly:e,params:r}}use(t,...s){let e;typeof t=="function"||t instanceof o?(s.unshift(t),e="/"):e=t;const n=s.map(a=>{if(a instanceof o){if(typeof e=="string")return a.clone(e);throw new Error("Mounting a router to RegExp base is not supported")}return a}),{keys:r,pattern:c}=h(e,!0);return this.routes.push({fns:n,isMiddleware:!0,keys:r,method:"",pattern:c}),this}}export{o as Router};
@@ -0,0 +1 @@
1
+ "use strict";var p=Object.defineProperty;var d=(o,t)=>p(o,"name",{value:t,configurable:!0});Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const l=require("./withZod-CQOb0zZR.cjs"),u=require("./Router-CtUe2eVq.cjs");var b=Object.defineProperty,h=d((o,t)=>b(o,"name",{value:t,configurable:!0}),"u");const m=h((o,t)=>{t.statusCode=404,t.end(o.method==="HEAD"?void 0:`Route ${String(o.method)} ${String(o.url)} not found`)},"onNoMatch"),E=h((o,t,e)=>{e.statusCode=500,globalThis.console.error(o),e.end("Internal Server Error")},"onError"),c=h(o=>{const t=o.indexOf("?");return t===-1?o:o.slice(0,Math.max(0,t))},"getPathname");class s{static{d(this,"NodeRouter")}static{h(this,"NodeRouter")}static prepareRequest(t,e){t.params={...e.params,...t.params}}all=this.add.bind(this,"");connect=this.add.bind(this,"CONNECT");delete=this.add.bind(this,"DELETE");get=this.add.bind(this,"GET");head=this.add.bind(this,"HEAD");options=this.add.bind(this,"OPTIONS");patch=this.add.bind(this,"PATCH");post=this.add.bind(this,"POST");put=this.add.bind(this,"PUT");trace=this.add.bind(this,"TRACE");onError;onNoMatch;router=new u.Router;constructor(t={}){this.onNoMatch=t.onNoMatch??m,this.onError=t.onError??E}clone(){const t=new s({onError:this.onError,onNoMatch:this.onNoMatch});return t.router=this.router.clone(),t}handler(){const{routes:t}=this.router;return async(e,r)=>{const i=c(e.url),n=e.method,a=this.router.find(n,i);s.prepareRequest(e,a);try{await(a.fns.length===0||a.middleOnly?this.onNoMatch(e,r,t):u.Router.exec(a.fns,e,r))}catch(f){await this.onError(f,e,r,t)}}}async run(t,e){const r=c(t.url),i=t.method,n=this.router.find(i,r);if(n.fns.length!==0)return s.prepareRequest(t,n),u.Router.exec(n.fns,t,e)}use(t,...e){let r;return typeof t=="function"||t instanceof s?(e.unshift(t),r="/"):r=t,this.router.use(r,...e.map(i=>i instanceof s?i.router:i)),this}add(t,e,r,...i){let n;return typeof e=="string"&&typeof r=="function"?n=[r]:typeof r=="object"?n=typeof e=="function"?[l(r,e)]:i.map(a=>l(r,a)):typeof r=="function"?n=[r]:n=i,this.router.add(t,e,...n),this}}const g=h((o={})=>new s(o),"createRouter");exports.NodeRouter=s;exports.createRouter=g;exports.getPathname=c;
@@ -0,0 +1 @@
1
+ var l=Object.defineProperty;var d=(e,t)=>l(e,"name",{value:t,configurable:!0});import u from"./withZod-B5rDrse4.mjs";import{Router as c}from"./Router-ZvrvfK8e.mjs";var m=Object.defineProperty,h=d((e,t)=>m(e,"name",{value:t,configurable:!0}),"u");const E=h((e,t)=>{t.statusCode=404,t.end(e.method==="HEAD"?void 0:`Route ${String(e.method)} ${String(e.url)} not found`)},"onNoMatch"),b=h((e,t,r)=>{r.statusCode=500,globalThis.console.error(e),r.end("Internal Server Error")},"onError"),f=h(e=>{const t=e.indexOf("?");return t===-1?e:e.slice(0,Math.max(0,t))},"getPathname");class s{static{d(this,"NodeRouter")}static{h(this,"NodeRouter")}static prepareRequest(t,r){t.params={...r.params,...t.params}}all=this.add.bind(this,"");connect=this.add.bind(this,"CONNECT");delete=this.add.bind(this,"DELETE");get=this.add.bind(this,"GET");head=this.add.bind(this,"HEAD");options=this.add.bind(this,"OPTIONS");patch=this.add.bind(this,"PATCH");post=this.add.bind(this,"POST");put=this.add.bind(this,"PUT");trace=this.add.bind(this,"TRACE");onError;onNoMatch;router=new c;constructor(t={}){this.onNoMatch=t.onNoMatch??E,this.onError=t.onError??b}clone(){const t=new s({onError:this.onError,onNoMatch:this.onNoMatch});return t.router=this.router.clone(),t}handler(){const{routes:t}=this.router;return async(r,o)=>{const i=f(r.url),n=r.method,a=this.router.find(n,i);s.prepareRequest(r,a);try{await(a.fns.length===0||a.middleOnly?this.onNoMatch(r,o,t):c.exec(a.fns,r,o))}catch(p){await this.onError(p,r,o,t)}}}async run(t,r){const o=f(t.url),i=t.method,n=this.router.find(i,o);if(n.fns.length!==0)return s.prepareRequest(t,n),c.exec(n.fns,t,r)}use(t,...r){let o;return typeof t=="function"||t instanceof s?(r.unshift(t),o="/"):o=t,this.router.use(o,...r.map(i=>i instanceof s?i.router:i)),this}add(t,r,o,...i){let n;return typeof r=="string"&&typeof o=="function"?n=[o]:typeof o=="object"?n=typeof r=="function"?[u(o,r)]:i.map(a=>u(o,a)):typeof o=="function"?n=[o]:n=i,this.router.add(t,r,...n),this}}const M=h((e={})=>new s(e),"createRouter");export{s as NodeRouter,M as createRouter,f as getPathname};
@@ -0,0 +1 @@
1
+ var p=Object.defineProperty;var n=(e,a)=>p(e,"name",{value:a,configurable:!0});var c=Object.defineProperty,u=n((e,a)=>c(e,"name",{value:a,configurable:!0}),"r");const l=u(e=>async(a,s,t)=>(await new Promise((i,o)=>{e(a,s,r=>{r?o(r):i()})}),t()),"expressWrapper");export{l as default};
@@ -0,0 +1 @@
1
+ "use strict";var o=Object.defineProperty;var s=(e,r)=>o(e,"name",{value:r,configurable:!0});var p=Object.defineProperty,u=s((e,r)=>p(e,"name",{value:r,configurable:!0}),"r");const v=u(e=>async(r,t,i)=>(await new Promise((n,c)=>{e(r,t,a=>{a?c(a):n()})}),i()),"expressWrapper");module.exports=v;
@@ -0,0 +1 @@
1
+ var r=Object.defineProperty;var n=(e,t)=>r(e,"name",{value:t,configurable:!0});var o=Object.defineProperty,s=n((e,t)=>o(e,"name",{value:t,configurable:!0}),"n");const i=s((e,t,a)=>{e.setHeader("content-type","application/json; charset=utf-8"),e.statusCode=t,e.end(JSON.stringify(a,void 0,2))},"sendJson");export{i as default};
@@ -0,0 +1 @@
1
+ "use strict";var s=Object.defineProperty;var n=(e,t)=>s(e,"name",{value:t,configurable:!0});var a=Object.defineProperty,o=n((e,t)=>a(e,"name",{value:t,configurable:!0}),"n");const i=o((e,t,r)=>{e.setHeader("content-type","application/json; charset=utf-8"),e.statusCode=t,e.end(JSON.stringify(r,void 0,2))},"sendJson");module.exports=i;
@@ -0,0 +1 @@
1
+ var f=Object.defineProperty;var n=(t,a)=>f(t,"name",{value:a,configurable:!0});import p from"http-errors";import*as u from"zod";var y=Object.defineProperty,d=n((t,a)=>y(t,"name",{value:a,configurable:!0}),"a");const w=d((t,a)=>async(s,c,i)=>{let o;try{o=await t.parseAsync(s)}catch(e){const m=e instanceof u.ZodError&&typeof e.format=="function"?e.issues.map(r=>`${r.path.join("/")} - ${r.message}`).join("/n"):e.message;throw p(422,m)}return a(o,c,i)},"withZod");export{w as default};
@@ -0,0 +1 @@
1
+ "use strict";var f=Object.defineProperty;var a=(t,e)=>f(t,"name",{value:e,configurable:!0});const p=require("http-errors"),l=require("zod"),m=a(t=>t&&typeof t=="object"&&"default"in t?t.default:t,"_interopDefaultCompat");function d(t){if(t&&typeof t=="object"&&"default"in t)return t;const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t)for(const n in t)e[n]=t[n];return e.default=t,e}a(d,"_interopNamespaceCompat");const y=m(p),b=d(l);var j=Object.defineProperty,_=a((t,e)=>j(t,"name",{value:e,configurable:!0}),"a");const g=_((t,e)=>async(n,s,i)=>{let r;try{r=await t.parseAsync(n)}catch(o){const u=o instanceof b.ZodError&&typeof o.format=="function"?o.issues.map(c=>`${c.path.join("/")} - ${c.message}`).join("/n"):o.message;throw y(422,u)}return e(r,s,i)},"withZod");module.exports=g;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/connect",
3
- "version": "4.0.0-alpha.11",
3
+ "version": "4.0.0-alpha.13",
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
  "connect",
@@ -19,6 +19,11 @@
19
19
  "bugs": {
20
20
  "url": "https://github.com/visulima/visulima/issues"
21
21
  },
22
+ "license": "MIT",
23
+ "author": {
24
+ "name": "Daniel Bannert",
25
+ "email": "d.bannert@anolilab.de"
26
+ },
22
27
  "repository": {
23
28
  "type": "git",
24
29
  "url": "https://github.com/visulima/visulima.git",
@@ -34,13 +39,29 @@
34
39
  "url": "https://anolilab.com/support"
35
40
  }
36
41
  ],
37
- "license": "MIT",
38
- "author": {
39
- "name": "Daniel Bannert",
40
- "email": "d.bannert@anolilab.de"
41
- },
42
- "sideEffects": false,
42
+ "files": [
43
+ "dist/**",
44
+ "README.md",
45
+ "CHANGELOG.md",
46
+ "LICENSE.md"
47
+ ],
48
+ "os": [
49
+ "darwin",
50
+ "linux",
51
+ "win32"
52
+ ],
43
53
  "type": "module",
54
+ "sideEffects": false,
55
+ "main": "dist/index.cjs",
56
+ "module": "dist/index.mjs",
57
+ "types": "dist/index.d.ts",
58
+ "typesVersions": {
59
+ ">=5.0": {
60
+ ".": [
61
+ "./dist/index.d.ts"
62
+ ]
63
+ }
64
+ },
44
65
  "exports": {
45
66
  ".": {
46
67
  "import": {
@@ -54,39 +75,18 @@
54
75
  },
55
76
  "./package.json": "./package.json"
56
77
  },
57
- "main": "dist/index.cjs",
58
- "module": "dist/index.mjs",
59
- "types": "dist/index.d.ts",
60
- "typesVersions": {
61
- ">=5.0": {
62
- ".": [
63
- "./dist/index.d.ts"
64
- ]
65
- }
78
+ "publishConfig": {
79
+ "access": "public",
80
+ "provenance": true
66
81
  },
67
- "files": [
68
- "dist/**",
69
- "README.md",
70
- "CHANGELOG.md",
71
- "LICENSE.md"
72
- ],
73
82
  "dependencies": {
74
83
  "http-errors": "^2.0.1",
75
84
  "regexparam": "^3.0.0"
76
85
  },
77
86
  "peerDependencies": {
78
- "zod": "4.4.1"
87
+ "zod": "4.4.3"
79
88
  },
80
89
  "engines": {
81
90
  "node": "^22.14.0 || >=24.10.0"
82
- },
83
- "os": [
84
- "darwin",
85
- "linux",
86
- "win32"
87
- ],
88
- "publishConfig": {
89
- "access": "public",
90
- "provenance": true
91
91
  }
92
92
  }
@@ -1,100 +0,0 @@
1
- import withZod from './withZod-DMHxmHJB.mjs';
2
- import { Router } from './Router-CT_g_29S.mjs';
3
-
4
- const onNoMatch = (request) => new Response(request.method === "HEAD" ? void 0 : `Route ${request.method} ${request.url} not found`, { status: 404 });
5
- const onError = (error) => {
6
- globalThis.console.error(error);
7
- return new Response("Internal Server Error", { status: 500 });
8
- };
9
- const getPathname = (request) => (request.nextUrl ?? new URL(request.url)).pathname;
10
- class EdgeRouter {
11
- static prepareRequest(request, findResult) {
12
- request.params = {
13
- ...findResult.params,
14
- ...request.params
15
- // original params will take precedence
16
- };
17
- }
18
- all = this.add.bind(this, "");
19
- connect = this.add.bind(this, "CONNECT");
20
- delete = this.add.bind(this, "DELETE");
21
- get = this.add.bind(this, "GET");
22
- head = this.add.bind(this, "HEAD");
23
- options = this.add.bind(this, "OPTIONS");
24
- patch = this.add.bind(this, "PATCH");
25
- post = this.add.bind(this, "POST");
26
- put = this.add.bind(this, "PUT");
27
- trace = this.add.bind(this, "TRACE");
28
- onError;
29
- onNoMatch;
30
- router = new Router();
31
- constructor(options = {}) {
32
- this.onNoMatch = options.onNoMatch ?? onNoMatch;
33
- this.onError = options.onError ?? onError;
34
- }
35
- clone() {
36
- const r = new EdgeRouter({ onError: this.onError, onNoMatch: this.onNoMatch });
37
- r.router = this.router.clone();
38
- return r;
39
- }
40
- handler() {
41
- const { routes } = this.router;
42
- return async (request, context_) => {
43
- const pathname = getPathname(request);
44
- const method = request.method;
45
- const result = this.router.find(method, pathname);
46
- EdgeRouter.prepareRequest(request, result);
47
- try {
48
- return await (result.fns.length === 0 || result.middleOnly ? this.onNoMatch(request, context_, routes) : Router.exec(result.fns, request, context_));
49
- } catch (error) {
50
- return await this.onError(error, request, context_, routes);
51
- }
52
- };
53
- }
54
- async run(request, context_) {
55
- const pathname = getPathname(request);
56
- const method = request.method;
57
- const result = this.router.find(method, pathname);
58
- if (result.fns.length === 0) {
59
- return void 0;
60
- }
61
- EdgeRouter.prepareRequest(request, result);
62
- return Router.exec(result.fns, request, context_);
63
- }
64
- use(base, ...fns) {
65
- let resolvedBase;
66
- if (typeof base === "function" || base instanceof EdgeRouter) {
67
- fns.unshift(base);
68
- resolvedBase = "/";
69
- } else {
70
- resolvedBase = base;
71
- }
72
- this.router.use(
73
- resolvedBase,
74
- ...fns.map((function_) => {
75
- if (function_ instanceof EdgeRouter) {
76
- return function_.router;
77
- }
78
- return function_;
79
- })
80
- );
81
- return this;
82
- }
83
- add(method, routeOrFunction, zodOrRouteOrFunction, ...fns) {
84
- let resolvedFns;
85
- if (typeof routeOrFunction === "string" && typeof zodOrRouteOrFunction === "function") {
86
- resolvedFns = [zodOrRouteOrFunction];
87
- } else if (typeof zodOrRouteOrFunction === "object") {
88
- resolvedFns = typeof routeOrFunction === "function" ? [withZod(zodOrRouteOrFunction, routeOrFunction)] : fns.map((function_) => withZod(zodOrRouteOrFunction, function_));
89
- } else if (typeof zodOrRouteOrFunction === "function") {
90
- resolvedFns = [zodOrRouteOrFunction];
91
- } else {
92
- resolvedFns = fns;
93
- }
94
- this.router.add(method, routeOrFunction, ...resolvedFns);
95
- return this;
96
- }
97
- }
98
- const createEdgeRouter = (options = {}) => new EdgeRouter(options);
99
-
100
- export { EdgeRouter, createEdgeRouter, getPathname };
@@ -1,106 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
-
5
- const withZod = require('./withZod-hpoT0ByV.cjs');
6
- const Router = require('./Router-DMp6zIkp.cjs');
7
-
8
- const onNoMatch = (request) => new Response(request.method === "HEAD" ? void 0 : `Route ${request.method} ${request.url} not found`, { status: 404 });
9
- const onError = (error) => {
10
- globalThis.console.error(error);
11
- return new Response("Internal Server Error", { status: 500 });
12
- };
13
- const getPathname = (request) => (request.nextUrl ?? new URL(request.url)).pathname;
14
- class EdgeRouter {
15
- static prepareRequest(request, findResult) {
16
- request.params = {
17
- ...findResult.params,
18
- ...request.params
19
- // original params will take precedence
20
- };
21
- }
22
- all = this.add.bind(this, "");
23
- connect = this.add.bind(this, "CONNECT");
24
- delete = this.add.bind(this, "DELETE");
25
- get = this.add.bind(this, "GET");
26
- head = this.add.bind(this, "HEAD");
27
- options = this.add.bind(this, "OPTIONS");
28
- patch = this.add.bind(this, "PATCH");
29
- post = this.add.bind(this, "POST");
30
- put = this.add.bind(this, "PUT");
31
- trace = this.add.bind(this, "TRACE");
32
- onError;
33
- onNoMatch;
34
- router = new Router.Router();
35
- constructor(options = {}) {
36
- this.onNoMatch = options.onNoMatch ?? onNoMatch;
37
- this.onError = options.onError ?? onError;
38
- }
39
- clone() {
40
- const r = new EdgeRouter({ onError: this.onError, onNoMatch: this.onNoMatch });
41
- r.router = this.router.clone();
42
- return r;
43
- }
44
- handler() {
45
- const { routes } = this.router;
46
- return async (request, context_) => {
47
- const pathname = getPathname(request);
48
- const method = request.method;
49
- const result = this.router.find(method, pathname);
50
- EdgeRouter.prepareRequest(request, result);
51
- try {
52
- return await (result.fns.length === 0 || result.middleOnly ? this.onNoMatch(request, context_, routes) : Router.Router.exec(result.fns, request, context_));
53
- } catch (error) {
54
- return await this.onError(error, request, context_, routes);
55
- }
56
- };
57
- }
58
- async run(request, context_) {
59
- const pathname = getPathname(request);
60
- const method = request.method;
61
- const result = this.router.find(method, pathname);
62
- if (result.fns.length === 0) {
63
- return void 0;
64
- }
65
- EdgeRouter.prepareRequest(request, result);
66
- return Router.Router.exec(result.fns, request, context_);
67
- }
68
- use(base, ...fns) {
69
- let resolvedBase;
70
- if (typeof base === "function" || base instanceof EdgeRouter) {
71
- fns.unshift(base);
72
- resolvedBase = "/";
73
- } else {
74
- resolvedBase = base;
75
- }
76
- this.router.use(
77
- resolvedBase,
78
- ...fns.map((function_) => {
79
- if (function_ instanceof EdgeRouter) {
80
- return function_.router;
81
- }
82
- return function_;
83
- })
84
- );
85
- return this;
86
- }
87
- add(method, routeOrFunction, zodOrRouteOrFunction, ...fns) {
88
- let resolvedFns;
89
- if (typeof routeOrFunction === "string" && typeof zodOrRouteOrFunction === "function") {
90
- resolvedFns = [zodOrRouteOrFunction];
91
- } else if (typeof zodOrRouteOrFunction === "object") {
92
- resolvedFns = typeof routeOrFunction === "function" ? [withZod(zodOrRouteOrFunction, routeOrFunction)] : fns.map((function_) => withZod(zodOrRouteOrFunction, function_));
93
- } else if (typeof zodOrRouteOrFunction === "function") {
94
- resolvedFns = [zodOrRouteOrFunction];
95
- } else {
96
- resolvedFns = fns;
97
- }
98
- this.router.add(method, routeOrFunction, ...resolvedFns);
99
- return this;
100
- }
101
- }
102
- const createEdgeRouter = (options = {}) => new EdgeRouter(options);
103
-
104
- exports.EdgeRouter = EdgeRouter;
105
- exports.createEdgeRouter = createEdgeRouter;
106
- exports.getPathname = getPathname;
@@ -1,168 +0,0 @@
1
- import { parse } from 'regexparam';
2
-
3
- class Router {
4
- constructor(base = "/", routes = []) {
5
- this.base = base;
6
- this.routes = routes;
7
- }
8
- base;
9
- routes;
10
- static exec(fns, ...arguments_) {
11
- let index = 0;
12
- const next = () => {
13
- index += 1;
14
- const currentFunction = fns[index];
15
- if (currentFunction === void 0) {
16
- return Promise.resolve();
17
- }
18
- return currentFunction(...arguments_, next);
19
- };
20
- return fns[index](...arguments_, next);
21
- }
22
- static extractRegExpParams(matches) {
23
- const result = {};
24
- if (matches.groups === void 0) {
25
- return result;
26
- }
27
- for (const key of Object.keys(matches.groups)) {
28
- result[key] = matches.groups[key];
29
- }
30
- return result;
31
- }
32
- static extractKeyedParams(matches, keys) {
33
- const result = {};
34
- for (const [index, parameterKey] of keys.entries()) {
35
- result[parameterKey] = matches[index + 1];
36
- }
37
- return result;
38
- }
39
- static isMethodMatch(routeMethod, method, isHead) {
40
- return routeMethod === method || routeMethod === "" || isHead && routeMethod === "GET";
41
- }
42
- static matchRoute(route, pathname) {
43
- if ("matchAll" in route) {
44
- return { matched: true, params: {} };
45
- }
46
- if (route.keys === false) {
47
- const matches = route.pattern.exec(pathname);
48
- if (matches === null) {
49
- return { matched: false };
50
- }
51
- return { matched: true, params: Router.extractRegExpParams(matches) };
52
- }
53
- if (route.keys.length > 0) {
54
- const matches = route.pattern.exec(pathname);
55
- if (matches === null) {
56
- return { matched: false };
57
- }
58
- return { matched: true, params: Router.extractKeyedParams(matches, route.keys) };
59
- }
60
- if (route.pattern.test(pathname)) {
61
- return { matched: true, params: {} };
62
- }
63
- return { matched: false };
64
- }
65
- static resolveRouteFns(routeFns, method, pathname, onSubResult) {
66
- return routeFns.flatMap((function_) => {
67
- if (function_ instanceof Router) {
68
- const { base } = function_;
69
- let stripPathname = pathname.slice(base.length);
70
- if (!stripPathname.startsWith("/")) {
71
- stripPathname = `/${stripPathname}`;
72
- }
73
- const result = function_.find(method, stripPathname);
74
- onSubResult(result.params, result.middleOnly);
75
- return result.fns;
76
- }
77
- return [function_];
78
- });
79
- }
80
- add(method, route, ...fns) {
81
- let resolvedRoute;
82
- if (typeof route === "function") {
83
- fns.unshift(route);
84
- resolvedRoute = "";
85
- } else {
86
- resolvedRoute = route;
87
- }
88
- if (resolvedRoute === "") {
89
- this.routes.push({
90
- fns,
91
- isMiddleware: false,
92
- matchAll: true,
93
- method
94
- });
95
- } else {
96
- const { keys, pattern } = parse(resolvedRoute);
97
- this.routes.push({
98
- fns,
99
- isMiddleware: false,
100
- keys,
101
- method,
102
- pattern
103
- });
104
- }
105
- return this;
106
- }
107
- clone(base) {
108
- return new Router(base, [...this.routes]);
109
- }
110
- find(method, pathname) {
111
- let middleOnly = true;
112
- const fns = [];
113
- const parameters = {};
114
- const isHead = method === "HEAD";
115
- for (let routeIndex = 0; routeIndex < this.routes.length; routeIndex += 1) {
116
- const route = this.routes[routeIndex];
117
- if (!Router.isMethodMatch(route.method, method, isHead)) {
118
- continue;
119
- }
120
- const matchResult = Router.matchRoute(route, pathname);
121
- if (!matchResult.matched) {
122
- continue;
123
- }
124
- Object.assign(parameters, matchResult.params);
125
- fns.push(
126
- ...Router.resolveRouteFns(route.fns, method, pathname, (subParams, subMiddleOnly) => {
127
- Object.assign(parameters, subParams);
128
- if (!subMiddleOnly) {
129
- middleOnly = false;
130
- }
131
- })
132
- );
133
- if (!route.isMiddleware) {
134
- middleOnly = false;
135
- }
136
- }
137
- return { fns, middleOnly, params: parameters };
138
- }
139
- use(base, ...fns) {
140
- let resolvedBase;
141
- if (typeof base === "function" || base instanceof Router) {
142
- fns.unshift(base);
143
- resolvedBase = "/";
144
- } else {
145
- resolvedBase = base;
146
- }
147
- const resolvedFns = fns.map((function_) => {
148
- if (function_ instanceof Router) {
149
- if (typeof resolvedBase === "string") {
150
- return function_.clone(resolvedBase);
151
- }
152
- throw new Error("Mounting a router to RegExp base is not supported");
153
- }
154
- return function_;
155
- });
156
- const { keys, pattern } = parse(resolvedBase, true);
157
- this.routes.push({
158
- fns: resolvedFns,
159
- isMiddleware: true,
160
- keys,
161
- method: "",
162
- pattern
163
- });
164
- return this;
165
- }
166
- }
167
-
168
- export { Router };
@@ -1,172 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
-
5
- const regexparam = require('regexparam');
6
-
7
- class Router {
8
- constructor(base = "/", routes = []) {
9
- this.base = base;
10
- this.routes = routes;
11
- }
12
- base;
13
- routes;
14
- static exec(fns, ...arguments_) {
15
- let index = 0;
16
- const next = () => {
17
- index += 1;
18
- const currentFunction = fns[index];
19
- if (currentFunction === void 0) {
20
- return Promise.resolve();
21
- }
22
- return currentFunction(...arguments_, next);
23
- };
24
- return fns[index](...arguments_, next);
25
- }
26
- static extractRegExpParams(matches) {
27
- const result = {};
28
- if (matches.groups === void 0) {
29
- return result;
30
- }
31
- for (const key of Object.keys(matches.groups)) {
32
- result[key] = matches.groups[key];
33
- }
34
- return result;
35
- }
36
- static extractKeyedParams(matches, keys) {
37
- const result = {};
38
- for (const [index, parameterKey] of keys.entries()) {
39
- result[parameterKey] = matches[index + 1];
40
- }
41
- return result;
42
- }
43
- static isMethodMatch(routeMethod, method, isHead) {
44
- return routeMethod === method || routeMethod === "" || isHead && routeMethod === "GET";
45
- }
46
- static matchRoute(route, pathname) {
47
- if ("matchAll" in route) {
48
- return { matched: true, params: {} };
49
- }
50
- if (route.keys === false) {
51
- const matches = route.pattern.exec(pathname);
52
- if (matches === null) {
53
- return { matched: false };
54
- }
55
- return { matched: true, params: Router.extractRegExpParams(matches) };
56
- }
57
- if (route.keys.length > 0) {
58
- const matches = route.pattern.exec(pathname);
59
- if (matches === null) {
60
- return { matched: false };
61
- }
62
- return { matched: true, params: Router.extractKeyedParams(matches, route.keys) };
63
- }
64
- if (route.pattern.test(pathname)) {
65
- return { matched: true, params: {} };
66
- }
67
- return { matched: false };
68
- }
69
- static resolveRouteFns(routeFns, method, pathname, onSubResult) {
70
- return routeFns.flatMap((function_) => {
71
- if (function_ instanceof Router) {
72
- const { base } = function_;
73
- let stripPathname = pathname.slice(base.length);
74
- if (!stripPathname.startsWith("/")) {
75
- stripPathname = `/${stripPathname}`;
76
- }
77
- const result = function_.find(method, stripPathname);
78
- onSubResult(result.params, result.middleOnly);
79
- return result.fns;
80
- }
81
- return [function_];
82
- });
83
- }
84
- add(method, route, ...fns) {
85
- let resolvedRoute;
86
- if (typeof route === "function") {
87
- fns.unshift(route);
88
- resolvedRoute = "";
89
- } else {
90
- resolvedRoute = route;
91
- }
92
- if (resolvedRoute === "") {
93
- this.routes.push({
94
- fns,
95
- isMiddleware: false,
96
- matchAll: true,
97
- method
98
- });
99
- } else {
100
- const { keys, pattern } = regexparam.parse(resolvedRoute);
101
- this.routes.push({
102
- fns,
103
- isMiddleware: false,
104
- keys,
105
- method,
106
- pattern
107
- });
108
- }
109
- return this;
110
- }
111
- clone(base) {
112
- return new Router(base, [...this.routes]);
113
- }
114
- find(method, pathname) {
115
- let middleOnly = true;
116
- const fns = [];
117
- const parameters = {};
118
- const isHead = method === "HEAD";
119
- for (let routeIndex = 0; routeIndex < this.routes.length; routeIndex += 1) {
120
- const route = this.routes[routeIndex];
121
- if (!Router.isMethodMatch(route.method, method, isHead)) {
122
- continue;
123
- }
124
- const matchResult = Router.matchRoute(route, pathname);
125
- if (!matchResult.matched) {
126
- continue;
127
- }
128
- Object.assign(parameters, matchResult.params);
129
- fns.push(
130
- ...Router.resolveRouteFns(route.fns, method, pathname, (subParams, subMiddleOnly) => {
131
- Object.assign(parameters, subParams);
132
- if (!subMiddleOnly) {
133
- middleOnly = false;
134
- }
135
- })
136
- );
137
- if (!route.isMiddleware) {
138
- middleOnly = false;
139
- }
140
- }
141
- return { fns, middleOnly, params: parameters };
142
- }
143
- use(base, ...fns) {
144
- let resolvedBase;
145
- if (typeof base === "function" || base instanceof Router) {
146
- fns.unshift(base);
147
- resolvedBase = "/";
148
- } else {
149
- resolvedBase = base;
150
- }
151
- const resolvedFns = fns.map((function_) => {
152
- if (function_ instanceof Router) {
153
- if (typeof resolvedBase === "string") {
154
- return function_.clone(resolvedBase);
155
- }
156
- throw new Error("Mounting a router to RegExp base is not supported");
157
- }
158
- return function_;
159
- });
160
- const { keys, pattern } = regexparam.parse(resolvedBase, true);
161
- this.routes.push({
162
- fns: resolvedFns,
163
- isMiddleware: true,
164
- keys,
165
- method: "",
166
- pattern
167
- });
168
- return this;
169
- }
170
- }
171
-
172
- exports.Router = Router;
@@ -1,113 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
-
5
- const withZod = require('./withZod-hpoT0ByV.cjs');
6
- const Router = require('./Router-DMp6zIkp.cjs');
7
-
8
- const onNoMatch = (request, response) => {
9
- response.statusCode = 404;
10
- response.end(request.method === "HEAD" ? void 0 : `Route ${String(request.method)} ${String(request.url)} not found`);
11
- };
12
- const onError = (error, _request, response) => {
13
- response.statusCode = 500;
14
- globalThis.console.error(error);
15
- response.end("Internal Server Error");
16
- };
17
- const getPathname = (url) => {
18
- const queryIndex = url.indexOf("?");
19
- return queryIndex === -1 ? url : url.slice(0, Math.max(0, queryIndex));
20
- };
21
- class NodeRouter {
22
- static prepareRequest(request, findResult) {
23
- request.params = {
24
- ...findResult.params,
25
- ...request.params
26
- // original params will take precedence
27
- };
28
- }
29
- all = this.add.bind(this, "");
30
- connect = this.add.bind(this, "CONNECT");
31
- delete = this.add.bind(this, "DELETE");
32
- get = this.add.bind(this, "GET");
33
- head = this.add.bind(this, "HEAD");
34
- options = this.add.bind(this, "OPTIONS");
35
- patch = this.add.bind(this, "PATCH");
36
- post = this.add.bind(this, "POST");
37
- put = this.add.bind(this, "PUT");
38
- trace = this.add.bind(this, "TRACE");
39
- onError;
40
- onNoMatch;
41
- router = new Router.Router();
42
- constructor(options = {}) {
43
- this.onNoMatch = options.onNoMatch ?? onNoMatch;
44
- this.onError = options.onError ?? onError;
45
- }
46
- clone() {
47
- const r = new NodeRouter({ onError: this.onError, onNoMatch: this.onNoMatch });
48
- r.router = this.router.clone();
49
- return r;
50
- }
51
- handler() {
52
- const { routes } = this.router;
53
- return async (request, response) => {
54
- const pathname = getPathname(request.url);
55
- const method = request.method;
56
- const result = this.router.find(method, pathname);
57
- NodeRouter.prepareRequest(request, result);
58
- try {
59
- await (result.fns.length === 0 || result.middleOnly ? this.onNoMatch(request, response, routes) : Router.Router.exec(result.fns, request, response));
60
- } catch (error) {
61
- await this.onError(error, request, response, routes);
62
- }
63
- };
64
- }
65
- async run(request, response) {
66
- const pathname = getPathname(request.url);
67
- const method = request.method;
68
- const result = this.router.find(method, pathname);
69
- if (result.fns.length === 0) {
70
- return void 0;
71
- }
72
- NodeRouter.prepareRequest(request, result);
73
- return Router.Router.exec(result.fns, request, response);
74
- }
75
- use(base, ...fns) {
76
- let resolvedBase;
77
- if (typeof base === "function" || base instanceof NodeRouter) {
78
- fns.unshift(base);
79
- resolvedBase = "/";
80
- } else {
81
- resolvedBase = base;
82
- }
83
- this.router.use(
84
- resolvedBase,
85
- ...fns.map((function_) => {
86
- if (function_ instanceof NodeRouter) {
87
- return function_.router;
88
- }
89
- return function_;
90
- })
91
- );
92
- return this;
93
- }
94
- add(method, routeOrFunction, zodOrRouteOrFunction, ...fns) {
95
- let resolvedFns;
96
- if (typeof routeOrFunction === "string" && typeof zodOrRouteOrFunction === "function") {
97
- resolvedFns = [zodOrRouteOrFunction];
98
- } else if (typeof zodOrRouteOrFunction === "object") {
99
- resolvedFns = typeof routeOrFunction === "function" ? [withZod(zodOrRouteOrFunction, routeOrFunction)] : fns.map((function_) => withZod(zodOrRouteOrFunction, function_));
100
- } else if (typeof zodOrRouteOrFunction === "function") {
101
- resolvedFns = [zodOrRouteOrFunction];
102
- } else {
103
- resolvedFns = fns;
104
- }
105
- this.router.add(method, routeOrFunction, ...resolvedFns);
106
- return this;
107
- }
108
- }
109
- const createRouter = (options = {}) => new NodeRouter(options);
110
-
111
- exports.NodeRouter = NodeRouter;
112
- exports.createRouter = createRouter;
113
- exports.getPathname = getPathname;
@@ -1,107 +0,0 @@
1
- import withZod from './withZod-DMHxmHJB.mjs';
2
- import { Router } from './Router-CT_g_29S.mjs';
3
-
4
- const onNoMatch = (request, response) => {
5
- response.statusCode = 404;
6
- response.end(request.method === "HEAD" ? void 0 : `Route ${String(request.method)} ${String(request.url)} not found`);
7
- };
8
- const onError = (error, _request, response) => {
9
- response.statusCode = 500;
10
- globalThis.console.error(error);
11
- response.end("Internal Server Error");
12
- };
13
- const getPathname = (url) => {
14
- const queryIndex = url.indexOf("?");
15
- return queryIndex === -1 ? url : url.slice(0, Math.max(0, queryIndex));
16
- };
17
- class NodeRouter {
18
- static prepareRequest(request, findResult) {
19
- request.params = {
20
- ...findResult.params,
21
- ...request.params
22
- // original params will take precedence
23
- };
24
- }
25
- all = this.add.bind(this, "");
26
- connect = this.add.bind(this, "CONNECT");
27
- delete = this.add.bind(this, "DELETE");
28
- get = this.add.bind(this, "GET");
29
- head = this.add.bind(this, "HEAD");
30
- options = this.add.bind(this, "OPTIONS");
31
- patch = this.add.bind(this, "PATCH");
32
- post = this.add.bind(this, "POST");
33
- put = this.add.bind(this, "PUT");
34
- trace = this.add.bind(this, "TRACE");
35
- onError;
36
- onNoMatch;
37
- router = new Router();
38
- constructor(options = {}) {
39
- this.onNoMatch = options.onNoMatch ?? onNoMatch;
40
- this.onError = options.onError ?? onError;
41
- }
42
- clone() {
43
- const r = new NodeRouter({ onError: this.onError, onNoMatch: this.onNoMatch });
44
- r.router = this.router.clone();
45
- return r;
46
- }
47
- handler() {
48
- const { routes } = this.router;
49
- return async (request, response) => {
50
- const pathname = getPathname(request.url);
51
- const method = request.method;
52
- const result = this.router.find(method, pathname);
53
- NodeRouter.prepareRequest(request, result);
54
- try {
55
- await (result.fns.length === 0 || result.middleOnly ? this.onNoMatch(request, response, routes) : Router.exec(result.fns, request, response));
56
- } catch (error) {
57
- await this.onError(error, request, response, routes);
58
- }
59
- };
60
- }
61
- async run(request, response) {
62
- const pathname = getPathname(request.url);
63
- const method = request.method;
64
- const result = this.router.find(method, pathname);
65
- if (result.fns.length === 0) {
66
- return void 0;
67
- }
68
- NodeRouter.prepareRequest(request, result);
69
- return Router.exec(result.fns, request, response);
70
- }
71
- use(base, ...fns) {
72
- let resolvedBase;
73
- if (typeof base === "function" || base instanceof NodeRouter) {
74
- fns.unshift(base);
75
- resolvedBase = "/";
76
- } else {
77
- resolvedBase = base;
78
- }
79
- this.router.use(
80
- resolvedBase,
81
- ...fns.map((function_) => {
82
- if (function_ instanceof NodeRouter) {
83
- return function_.router;
84
- }
85
- return function_;
86
- })
87
- );
88
- return this;
89
- }
90
- add(method, routeOrFunction, zodOrRouteOrFunction, ...fns) {
91
- let resolvedFns;
92
- if (typeof routeOrFunction === "string" && typeof zodOrRouteOrFunction === "function") {
93
- resolvedFns = [zodOrRouteOrFunction];
94
- } else if (typeof zodOrRouteOrFunction === "object") {
95
- resolvedFns = typeof routeOrFunction === "function" ? [withZod(zodOrRouteOrFunction, routeOrFunction)] : fns.map((function_) => withZod(zodOrRouteOrFunction, function_));
96
- } else if (typeof zodOrRouteOrFunction === "function") {
97
- resolvedFns = [zodOrRouteOrFunction];
98
- } else {
99
- resolvedFns = fns;
100
- }
101
- this.router.add(method, routeOrFunction, ...resolvedFns);
102
- return this;
103
- }
104
- }
105
- const createRouter = (options = {}) => new NodeRouter(options);
106
-
107
- export { NodeRouter, createRouter, getPathname };
@@ -1,14 +0,0 @@
1
- const expressWrapper = (function_) => async (request, response, next) => {
2
- await new Promise((resolve, reject) => {
3
- function_(request, response, (error) => {
4
- if (error) {
5
- reject(error);
6
- } else {
7
- resolve();
8
- }
9
- });
10
- });
11
- return next();
12
- };
13
-
14
- export { expressWrapper as default };
@@ -1,16 +0,0 @@
1
- 'use strict';
2
-
3
- const expressWrapper = (function_) => async (request, response, next) => {
4
- await new Promise((resolve, reject) => {
5
- function_(request, response, (error) => {
6
- if (error) {
7
- reject(error);
8
- } else {
9
- resolve();
10
- }
11
- });
12
- });
13
- return next();
14
- };
15
-
16
- module.exports = expressWrapper;
@@ -1,7 +0,0 @@
1
- const sendJson = (response, statusCode, jsonBody) => {
2
- response.setHeader("content-type", "application/json; charset=utf-8");
3
- response.statusCode = statusCode;
4
- response.end(JSON.stringify(jsonBody, void 0, 2));
5
- };
6
-
7
- export { sendJson as default };
@@ -1,9 +0,0 @@
1
- 'use strict';
2
-
3
- const sendJson = (response, statusCode, jsonBody) => {
4
- response.setHeader("content-type", "application/json; charset=utf-8");
5
- response.statusCode = statusCode;
6
- response.end(JSON.stringify(jsonBody, void 0, 2));
7
- };
8
-
9
- module.exports = sendJson;
@@ -1,15 +0,0 @@
1
- import createHttpError from 'http-errors';
2
- import * as z from 'zod';
3
-
4
- const withZod = (schema, handler) => async (request, response, next) => {
5
- let transformedRequest;
6
- try {
7
- transformedRequest = await schema.parseAsync(request);
8
- } catch (error) {
9
- const message = error instanceof z.ZodError && typeof error.format === "function" ? error.issues.map((issue) => `${issue.path.join("/")} - ${issue.message}`).join("/n") : error.message;
10
- throw createHttpError(422, message);
11
- }
12
- return handler(transformedRequest, response, next);
13
- };
14
-
15
- export { withZod as default };
@@ -1,34 +0,0 @@
1
- 'use strict';
2
-
3
- const createHttpError = require('http-errors');
4
- const z = require('zod');
5
-
6
- const _interopDefaultCompat = e => e && typeof e === 'object' && 'default' in e ? e.default : e;
7
-
8
- function _interopNamespaceCompat(e) {
9
- if (e && typeof e === 'object' && 'default' in e) return e;
10
- const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
11
- if (e) {
12
- for (const k in e) {
13
- n[k] = e[k];
14
- }
15
- }
16
- n.default = e;
17
- return n;
18
- }
19
-
20
- const createHttpError__default = /*#__PURE__*/_interopDefaultCompat(createHttpError);
21
- const z__namespace = /*#__PURE__*/_interopNamespaceCompat(z);
22
-
23
- const withZod = (schema, handler) => async (request, response, next) => {
24
- let transformedRequest;
25
- try {
26
- transformedRequest = await schema.parseAsync(request);
27
- } catch (error) {
28
- const message = error instanceof z__namespace.ZodError && typeof error.format === "function" ? error.issues.map((issue) => `${issue.path.join("/")} - ${issue.message}`).join("/n") : error.message;
29
- throw createHttpError__default(422, message);
30
- }
31
- return handler(transformedRequest, response, next);
32
- };
33
-
34
- module.exports = withZod;