@visulima/connect 3.0.19 → 3.0.21
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 +24 -0
- package/dist/index.cjs +1 -22
- package/dist/index.d.cts +3 -2
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.mjs +1 -6
- package/dist/packem_shared/Router-fcD22mVn.cjs +1 -0
- package/dist/packem_shared/Router-kh2RTgYJ.mjs +1 -0
- package/dist/packem_shared/createEdgeRouter-BYUWjtW1.mjs +1 -0
- package/dist/packem_shared/createEdgeRouter-KIBlNPX3.cjs +1 -0
- package/dist/packem_shared/createRouter-CEifSa_f.mjs +1 -0
- package/dist/packem_shared/createRouter-CcKo5sWT.cjs +1 -0
- package/dist/packem_shared/expressWrapper-CnZ-5oTw.cjs +1 -0
- package/dist/packem_shared/expressWrapper-D-d31tgs.mjs +1 -0
- package/dist/packem_shared/sendJson-l4jM19lK.cjs +1 -0
- package/dist/packem_shared/sendJson-zUtTFUYn.mjs +1 -0
- package/dist/packem_shared/withZod-CTl1zUbN.mjs +1 -0
- package/dist/packem_shared/withZod-CvygheEk.cjs +1 -0
- package/package.json +6 -6
- package/dist/packem_shared/EdgeRouter-D0oWFTsY.mjs +0 -96
- package/dist/packem_shared/EdgeRouter-DxN8Qadz.cjs +0 -102
- package/dist/packem_shared/Router-Bh6INaMr.cjs +0 -146
- package/dist/packem_shared/Router-CcNSmWZS.mjs +0 -142
- package/dist/packem_shared/createRouter-Cnl03FK3.mjs +0 -101
- package/dist/packem_shared/createRouter-mXdLB4lt.cjs +0 -107
- package/dist/packem_shared/expressWrapper-Cp6GmLZm.cjs +0 -12
- package/dist/packem_shared/expressWrapper-Dfp803bO.mjs +0 -10
- package/dist/packem_shared/sendJson-CIcILWip.mjs +0 -9
- package/dist/packem_shared/sendJson-CvRoSFt-.cjs +0 -11
- package/dist/packem_shared/withZod-DGhSvb93.mjs +0 -20
- package/dist/packem_shared/withZod-DdTDLdDj.cjs +0 -26
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
## @visulima/connect [3.0.21](https://github.com/visulima/visulima/compare/@visulima/connect@3.0.20...@visulima/connect@3.0.21) (2025-10-15)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
* consolidate ESLint configuration and remove obsolete files for improved maintainability ([670cc9e](https://github.com/visulima/visulima/commit/670cc9e2a16aaf43aafddc5b00bb3d34144bb1df))
|
|
6
|
+
* update @visulima/packem to 2.0.0-alpha.30 across multiple packages for improved compatibility ([27b346e](https://github.com/visulima/visulima/commit/27b346eaa1c0fb0e420d9a9824482028307f4249))
|
|
7
|
+
* update @visulima/packem to version 2.0.0-alpha.29 and adjust packem.config.ts settings ([e505bcf](https://github.com/visulima/visulima/commit/e505bcfba65e8fede4286b8cd08557d976081de5))
|
|
8
|
+
|
|
9
|
+
### Miscellaneous Chores
|
|
10
|
+
|
|
11
|
+
* **deps:** update build scripts and remove cross-env dependency ([7510e82](https://github.com/visulima/visulima/commit/7510e826b9235a0013fe61c82a7eb333bc4cbb78))
|
|
12
|
+
* update package dependencies across multiple packages for improved compatibility and performance ([9567591](https://github.com/visulima/visulima/commit/9567591c415da3002f3a4fe08f8caf7ce01ca5f7))
|
|
13
|
+
* update package.json and pnpm-lock.yaml to include publint@0.3.12 and adjust build/test commands to exclude shared-utils ([1f7b3c0](https://github.com/visulima/visulima/commit/1f7b3c0381d77edfeec80ea1bf57b3469e929414))
|
|
14
|
+
|
|
15
|
+
## @visulima/connect [3.0.20](https://github.com/visulima/visulima/compare/@visulima/connect@3.0.19...@visulima/connect@3.0.20) (2025-05-30)
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* **connect:** update dependencies ([76d5963](https://github.com/visulima/visulima/commit/76d5963b1ed59632a80e02a653c3f46163aa6d25))
|
|
20
|
+
|
|
21
|
+
### Miscellaneous Chores
|
|
22
|
+
|
|
23
|
+
* updated dev dependencies ([2433ed5](https://github.com/visulima/visulima/commit/2433ed5fb662e0303c37edee8ddc21b46c21263f))
|
|
24
|
+
|
|
1
25
|
## @visulima/connect [3.0.19](https://github.com/visulima/visulima/compare/@visulima/connect@3.0.18...@visulima/connect@3.0.19) (2025-03-07)
|
|
2
26
|
|
|
3
27
|
### Bug Fixes
|
package/dist/index.cjs
CHANGED
|
@@ -1,22 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
|
-
|
|
5
|
-
const expressWrapper = require('./packem_shared/expressWrapper-Cp6GmLZm.cjs');
|
|
6
|
-
const withZod = require('./packem_shared/withZod-DdTDLdDj.cjs');
|
|
7
|
-
const EdgeRouter = require('./packem_shared/EdgeRouter-DxN8Qadz.cjs');
|
|
8
|
-
const createRouter = require('./packem_shared/createRouter-mXdLB4lt.cjs');
|
|
9
|
-
const Router = require('./packem_shared/Router-Bh6INaMr.cjs');
|
|
10
|
-
const sendJson = require('./packem_shared/sendJson-CvRoSFt-.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-CnZ-5oTw.cjs"),o=require("./packem_shared/withZod-CvygheEk.cjs"),r=require("./packem_shared/createEdgeRouter-KIBlNPX3.cjs"),e=require("./packem_shared/createRouter-CcKo5sWT.cjs"),u=require("./packem_shared/Router-fcD22mVn.cjs"),d=require("./packem_shared/sendJson-l4jM19lK.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.d.cts
CHANGED
|
@@ -95,7 +95,7 @@ declare const withZod: <Request, Response, Handler extends Nextable<any>, Schema
|
|
|
95
95
|
body?: AnyZodObject;
|
|
96
96
|
headers?: AnyZodObject;
|
|
97
97
|
query?: AnyZodObject;
|
|
98
|
-
}>>(schema: Schema, handler: Handler) => (
|
|
98
|
+
}>>(schema: Schema, handler: Handler) => (request: Request, response: Response, next: NextHandler) => Promise<Response>;
|
|
99
99
|
|
|
100
100
|
type RequestHandler<R extends Request, Context> = (request: R, context_: Context) => ValueOrPromise<Response | void>;
|
|
101
101
|
declare class EdgeRouter<R extends Request = Request, Context = unknown, RResponse extends Response = Response, Schema extends AnyZodObject = ZodObject<any>> {
|
|
@@ -124,4 +124,5 @@ declare const createEdgeRouter: <R extends Request, Context>(options?: HandlerOp
|
|
|
124
124
|
|
|
125
125
|
declare const sendJson: (response: ServerResponse, statusCode: number, jsonBody: unknown) => void;
|
|
126
126
|
|
|
127
|
-
export {
|
|
127
|
+
export { EdgeRouter, NodeRouter, Router, createEdgeRouter, createRouter as createNodeRouter, createRouter, expressWrapper, sendJson, withZod };
|
|
128
|
+
export type { RequestHandler as EdgeRequestHandler, ExpressRequestHandler, FindResult, FunctionLike, HandlerOptions, HttpMethod, NextHandler, Nextable, RequestHandler$1 as NodeRequestHandler, Route, RouteShortcutMethod, ValueOrPromise };
|
package/dist/index.d.mts
CHANGED
|
@@ -95,7 +95,7 @@ declare const withZod: <Request, Response, Handler extends Nextable<any>, Schema
|
|
|
95
95
|
body?: AnyZodObject;
|
|
96
96
|
headers?: AnyZodObject;
|
|
97
97
|
query?: AnyZodObject;
|
|
98
|
-
}>>(schema: Schema, handler: Handler) => (
|
|
98
|
+
}>>(schema: Schema, handler: Handler) => (request: Request, response: Response, next: NextHandler) => Promise<Response>;
|
|
99
99
|
|
|
100
100
|
type RequestHandler<R extends Request, Context> = (request: R, context_: Context) => ValueOrPromise<Response | void>;
|
|
101
101
|
declare class EdgeRouter<R extends Request = Request, Context = unknown, RResponse extends Response = Response, Schema extends AnyZodObject = ZodObject<any>> {
|
|
@@ -124,4 +124,5 @@ declare const createEdgeRouter: <R extends Request, Context>(options?: HandlerOp
|
|
|
124
124
|
|
|
125
125
|
declare const sendJson: (response: ServerResponse, statusCode: number, jsonBody: unknown) => void;
|
|
126
126
|
|
|
127
|
-
export {
|
|
127
|
+
export { EdgeRouter, NodeRouter, Router, createEdgeRouter, createRouter as createNodeRouter, createRouter, expressWrapper, sendJson, withZod };
|
|
128
|
+
export type { RequestHandler as EdgeRequestHandler, ExpressRequestHandler, FindResult, FunctionLike, HandlerOptions, HttpMethod, NextHandler, Nextable, RequestHandler$1 as NodeRequestHandler, Route, RouteShortcutMethod, ValueOrPromise };
|
package/dist/index.d.ts
CHANGED
|
@@ -95,7 +95,7 @@ declare const withZod: <Request, Response, Handler extends Nextable<any>, Schema
|
|
|
95
95
|
body?: AnyZodObject;
|
|
96
96
|
headers?: AnyZodObject;
|
|
97
97
|
query?: AnyZodObject;
|
|
98
|
-
}>>(schema: Schema, handler: Handler) => (
|
|
98
|
+
}>>(schema: Schema, handler: Handler) => (request: Request, response: Response, next: NextHandler) => Promise<Response>;
|
|
99
99
|
|
|
100
100
|
type RequestHandler<R extends Request, Context> = (request: R, context_: Context) => ValueOrPromise<Response | void>;
|
|
101
101
|
declare class EdgeRouter<R extends Request = Request, Context = unknown, RResponse extends Response = Response, Schema extends AnyZodObject = ZodObject<any>> {
|
|
@@ -124,4 +124,5 @@ declare const createEdgeRouter: <R extends Request, Context>(options?: HandlerOp
|
|
|
124
124
|
|
|
125
125
|
declare const sendJson: (response: ServerResponse, statusCode: number, jsonBody: unknown) => void;
|
|
126
126
|
|
|
127
|
-
export {
|
|
127
|
+
export { EdgeRouter, NodeRouter, Router, createEdgeRouter, createRouter as createNodeRouter, createRouter, expressWrapper, sendJson, withZod };
|
|
128
|
+
export type { RequestHandler as EdgeRequestHandler, ExpressRequestHandler, FindResult, FunctionLike, HandlerOptions, HttpMethod, NextHandler, Nextable, RequestHandler$1 as NodeRequestHandler, Route, RouteShortcutMethod, ValueOrPromise };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { default as withZod } from './packem_shared/withZod-DGhSvb93.mjs';
|
|
3
|
-
export { EdgeRouter, createEdgeRouter } from './packem_shared/EdgeRouter-D0oWFTsY.mjs';
|
|
4
|
-
export { NodeRouter, createRouter as createNodeRouter, createRouter } from './packem_shared/createRouter-Cnl03FK3.mjs';
|
|
5
|
-
export { Router } from './packem_shared/Router-CcNSmWZS.mjs';
|
|
6
|
-
export { default as sendJson } from './packem_shared/sendJson-CIcILWip.mjs';
|
|
1
|
+
import{default as o}from"./packem_shared/expressWrapper-D-d31tgs.mjs";import{default as a}from"./packem_shared/withZod-CTl1zUbN.mjs";import{EdgeRouter as d,createEdgeRouter as f}from"./packem_shared/createEdgeRouter-BYUWjtW1.mjs";import{NodeRouter as s,createRouter as x,createRouter as R}from"./packem_shared/createRouter-CEifSa_f.mjs";import{Router as c}from"./packem_shared/Router-kh2RTgYJ.mjs";import{default as g}from"./packem_shared/sendJson-zUtTFUYn.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
|
+
"use strict";var g=Object.defineProperty;var p=(f,e)=>g(f,"name",{value:e,configurable:!0});Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const d=require("regexparam");var b=Object.defineProperty,m=p((f,e)=>b(f,"name",{value:e,configurable:!0}),"p");class l{static{p(this,"Router")}constructor(e="/",t=[]){this.base=e,this.routes=t}static{m(this,"Router")}static async exec(e,...t){let n=0;const i=m(()=>{const s=e[++n];return s===void 0?Promise.resolve():s(...t,i)},"next");return e[n](...t,i)}add(e,t,...n){if(typeof t=="function"&&(n.unshift(t),t=""),t==="")this.routes.push({fns:n,isMiddleware:!1,matchAll:!0,method:e});else{const{keys:i,pattern:s}=d.parse(t);this.routes.push({fns:n,isMiddleware:!1,keys:i,method:e,pattern:s})}return this}clone(e){return new l(e,[...this.routes])}find(e,t){let n=!0;const i=[],s={},y=e==="HEAD";for(const r of this.routes){if(r.method!==e&&r.method!==""&&!(y&&r.method==="GET"))continue;let c=!1;if("matchAll"in r)c=!0;else if(r.keys===!1){const o=r.pattern.exec(t);if(o===null)continue;o.groups!==void 0&&Object.keys(o.groups).forEach(u=>{s[u]=o.groups[u]}),c=!0}else if(r.keys.length>0){const o=r.pattern.exec(t);if(o===null)continue;for(let u=0;u<r.keys.length;){const a=r.keys[u];s[a]=o[++u]}c=!0}else r.pattern.test(t)&&(c=!0);c&&(i.push(...r.fns.flatMap(o=>{if(o instanceof l){const{base:u}=o;let a=t.slice(u.length);a.startsWith("/")||(a=`/${a}`);const h=o.find(e,a);return h.middleOnly||(n=!1),Object.assign(s,h.params),h.fns}return o})),r.isMiddleware||(n=!1))}return{fns:i,middleOnly:n,params:s}}use(e,...t){(typeof e=="function"||e instanceof l)&&(t.unshift(e),e="/"),t=t.map(s=>{if(s instanceof l){if(typeof e=="string")return s.clone(e);throw new Error("Mounting a router to RegExp base is not supported")}return s});const{keys:n,pattern:i}=d.parse(e,!0);return this.routes.push({fns:t,isMiddleware:!0,keys:n,method:"",pattern:i}),this}}exports.Router=l;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var g=Object.defineProperty;var d=(f,e)=>g(f,"name",{value:e,configurable:!0});import{createRequire as b}from"node:module";const k=b(import.meta.url),_=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process;const{parse:h}=k("regexparam");var v=Object.defineProperty,m=d((f,e)=>v(f,"name",{value:e,configurable:!0}),"p");class l{static{d(this,"Router")}constructor(e="/",t=[]){this.base=e,this.routes=t}static{m(this,"Router")}static async exec(e,...t){let n=0;const i=m(()=>{const s=e[++n];return s===void 0?Promise.resolve():s(...t,i)},"next");return e[n](...t,i)}add(e,t,...n){if(typeof t=="function"&&(n.unshift(t),t=""),t==="")this.routes.push({fns:n,isMiddleware:!1,matchAll:!0,method:e});else{const{keys:i,pattern:s}=h(t);this.routes.push({fns:n,isMiddleware:!1,keys:i,method:e,pattern:s})}return this}clone(e){return new l(e,[...this.routes])}find(e,t){let n=!0;const i=[],s={},y=e==="HEAD";for(const r of this.routes){if(r.method!==e&&r.method!==""&&!(y&&r.method==="GET"))continue;let c=!1;if("matchAll"in r)c=!0;else if(r.keys===!1){const o=r.pattern.exec(t);if(o===null)continue;o.groups!==void 0&&Object.keys(o.groups).forEach(u=>{s[u]=o.groups[u]}),c=!0}else if(r.keys.length>0){const o=r.pattern.exec(t);if(o===null)continue;for(let u=0;u<r.keys.length;){const a=r.keys[u];s[a]=o[++u]}c=!0}else r.pattern.test(t)&&(c=!0);c&&(i.push(...r.fns.flatMap(o=>{if(o instanceof l){const{base:u}=o;let a=t.slice(u.length);a.startsWith("/")||(a=`/${a}`);const p=o.find(e,a);return p.middleOnly||(n=!1),Object.assign(s,p.params),p.fns}return o})),r.isMiddleware||(n=!1))}return{fns:i,middleOnly:n,params:s}}use(e,...t){(typeof e=="function"||e instanceof l)&&(t.unshift(e),e="/"),t=t.map(s=>{if(s instanceof l){if(typeof e=="string")return s.clone(e);throw new Error("Mounting a router to RegExp base is not supported")}return s});const{keys:n,pattern:i}=h(e,!0);return this.routes.push({fns:t,isMiddleware:!0,keys:n,method:"",pattern:i}),this}}export{l as Router};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var p=Object.defineProperty;var h=(n,t)=>p(n,"name",{value:t,configurable:!0});import c from"./withZod-CTl1zUbN.mjs";import{Router as d}from"./Router-kh2RTgYJ.mjs";var f=Object.defineProperty,i=h((n,t)=>f(n,"name",{value:t,configurable:!0}),"r");const l=i(async n=>new Response(n.method==="HEAD"?null:`Route ${n.method} ${n.url} not found`,{status:404}),"onNoMatch"),m=i(async n=>(console.error(n),new Response("Internal Server Error",{status:500})),"onError"),u=i(n=>(n.nextUrl??new URL(n.url)).pathname,"getPathname");class s{static{h(this,"EdgeRouter")}static{i(this,"EdgeRouter")}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 d;constructor(t={}){this.onNoMatch=t.onNoMatch??l,this.onError=t.onError??m}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 o=this.router.find(e.method,u(e));this.prepareRequest(e,o);try{return await(o.fns.length===0||o.middleOnly?this.onNoMatch(e,r,t):d.exec(o.fns,e,r))}catch(a){return await this.onError(a,e,r,t)}}}async run(t,e){const r=this.router.find(t.method,u(t));if(r.fns.length!==0)return this.prepareRequest(t,r),await d.exec(r.fns,t,e)}use(t,...e){return(typeof t=="function"||t instanceof s)&&(e.unshift(t),t="/"),this.router.use(t,...e.map(r=>r instanceof s?r.router:r)),this}add(t,e,r,...o){return typeof e=="string"&&typeof r=="function"?o=[r]:typeof r=="object"?typeof e=="function"?o=[c(r,e)]:o=o.map(a=>c(r,a)):typeof r=="function"&&(o=[r]),this.router.add(t,e,...o),this}prepareRequest(t,e){t.params={...e.params,...t.params}}}const N=i((n={})=>new s(n),"createEdgeRouter");export{s as EdgeRouter,N as createEdgeRouter,u as getPathname};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var p=Object.defineProperty;var h=(o,t)=>p(o,"name",{value:t,configurable:!0});Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const c=require("./withZod-CvygheEk.cjs"),d=require("./Router-fcD22mVn.cjs");var l=Object.defineProperty,i=h((o,t)=>l(o,"name",{value:t,configurable:!0}),"r");const f=i(async o=>new Response(o.method==="HEAD"?null:`Route ${o.method} ${o.url} not found`,{status:404}),"onNoMatch"),E=i(async o=>(console.error(o),new Response("Internal Server Error",{status:500})),"onError"),u=i(o=>(o.nextUrl??new URL(o.url)).pathname,"getPathname");class s{static{h(this,"EdgeRouter")}static{i(this,"EdgeRouter")}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 d.Router;constructor(t={}){this.onNoMatch=t.onNoMatch??f,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(r,e)=>{const n=this.router.find(r.method,u(r));this.prepareRequest(r,n);try{return await(n.fns.length===0||n.middleOnly?this.onNoMatch(r,e,t):d.Router.exec(n.fns,r,e))}catch(a){return await this.onError(a,r,e,t)}}}async run(t,r){const e=this.router.find(t.method,u(t));if(e.fns.length!==0)return this.prepareRequest(t,e),await d.Router.exec(e.fns,t,r)}use(t,...r){return(typeof t=="function"||t instanceof s)&&(r.unshift(t),t="/"),this.router.use(t,...r.map(e=>e instanceof s?e.router:e)),this}add(t,r,e,...n){return typeof r=="string"&&typeof e=="function"?n=[e]:typeof e=="object"?typeof r=="function"?n=[c(e,r)]:n=n.map(a=>c(e,a)):typeof e=="function"&&(n=[e]),this.router.add(t,r,...n),this}prepareRequest(t,r){t.params={...r.params,...t.params}}}const m=i((o={})=>new s(o),"createEdgeRouter");exports.EdgeRouter=s;exports.createEdgeRouter=m;exports.getPathname=u;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var f=Object.defineProperty;var h=(n,t)=>f(n,"name",{value:t,configurable:!0});import c from"./withZod-CTl1zUbN.mjs";import{Router as d}from"./Router-kh2RTgYJ.mjs";var p=Object.defineProperty,s=h((n,t)=>p(n,"name",{value:t,configurable:!0}),"r");const l=s(async(n,t)=>{t.statusCode=404,t.end(n.method==="HEAD"?void 0:`Route ${n.method} ${n.url} not found`)},"onNoMatch"),m=s(async(n,t,r)=>{r.statusCode=500,console.error(n),r.end("Internal Server Error")},"onError"),u=s(n=>{const t=n.indexOf("?");return t===-1?n:n.slice(0,Math.max(0,t))},"getPathname");class i{static{h(this,"NodeRouter")}static{s(this,"NodeRouter")}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 d;constructor(t={}){this.onNoMatch=t.onNoMatch??l,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(r,e)=>{const o=this.router.find(r.method,u(r.url));this.prepareRequest(r,o);try{await(o.fns.length===0||o.middleOnly?this.onNoMatch(r,e,t):d.exec(o.fns,r,e))}catch(a){await this.onError(a,r,e,t)}}}async run(t,r){const e=this.router.find(t.method,u(t.url));if(e.fns.length!==0)return this.prepareRequest(t,e),await d.exec(e.fns,t,r)}use(t,...r){return(typeof t=="function"||t instanceof i)&&(r.unshift(t),t="/"),this.router.use(t,...r.map(e=>e instanceof i?e.router:e)),this}add(t,r,e,...o){return typeof r=="string"&&typeof e=="function"?o=[e]:typeof e=="object"?typeof r=="function"?o=[c(e,r)]:o=o.map(a=>c(e,a)):typeof e=="function"&&(o=[e]),this.router.add(t,r,...o),this}prepareRequest(t,r){t.params={...r.params,...t.params}}}const N=s((n={})=>new i(n),"createRouter");export{i as NodeRouter,N as createRouter,u as getPathname};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var f=Object.defineProperty;var h=(o,t)=>f(o,"name",{value:t,configurable:!0});Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const c=require("./withZod-CvygheEk.cjs"),d=require("./Router-fcD22mVn.cjs");var l=Object.defineProperty,s=h((o,t)=>l(o,"name",{value:t,configurable:!0}),"r");const p=s(async(o,t)=>{t.statusCode=404,t.end(o.method==="HEAD"?void 0:`Route ${o.method} ${o.url} not found`)},"onNoMatch"),m=s(async(o,t,e)=>{e.statusCode=500,console.error(o),e.end("Internal Server Error")},"onError"),u=s(o=>{const t=o.indexOf("?");return t===-1?o:o.slice(0,Math.max(0,t))},"getPathname");class i{static{h(this,"NodeRouter")}static{s(this,"NodeRouter")}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 d.Router;constructor(t={}){this.onNoMatch=t.onNoMatch??p,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 n=this.router.find(e.method,u(e.url));this.prepareRequest(e,n);try{await(n.fns.length===0||n.middleOnly?this.onNoMatch(e,r,t):d.Router.exec(n.fns,e,r))}catch(a){await this.onError(a,e,r,t)}}}async run(t,e){const r=this.router.find(t.method,u(t.url));if(r.fns.length!==0)return this.prepareRequest(t,r),await d.Router.exec(r.fns,t,e)}use(t,...e){return(typeof t=="function"||t instanceof i)&&(e.unshift(t),t="/"),this.router.use(t,...e.map(r=>r instanceof i?r.router:r)),this}add(t,e,r,...n){return typeof e=="string"&&typeof r=="function"?n=[r]:typeof r=="object"?typeof e=="function"?n=[c(r,e)]:n=n.map(a=>c(r,a)):typeof r=="function"&&(n=[r]),this.router.add(t,e,...n),this}prepareRequest(t,e){t.params={...e.params,...t.params}}}const E=s((o={})=>new i(o),"createRouter");exports.NodeRouter=i;exports.createRouter=E;exports.getPathname=u;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var o=Object.defineProperty;var n=(e,r)=>o(e,"name",{value:r,configurable:!0});var p=Object.defineProperty,u=n((e,r)=>p(e,"name",{value:r,configurable:!0}),"n");const v=u(e=>async(r,s,t)=>await new Promise((c,i)=>{e(r,s,a=>a?i(a):c())}).then(t),"expressWrapper");module.exports=v;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var u=Object.defineProperty;var n=(e,a)=>u(e,"name",{value:a,configurable:!0});var c=Object.defineProperty,i=n((e,a)=>c(e,"name",{value:a,configurable:!0}),"n");const l=i(e=>async(a,t,s)=>await new Promise((o,p)=>{e(a,t,r=>r?p(r):o())}).then(s),"expressWrapper");export{l as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var r=Object.defineProperty;var n=(e,t)=>r(e,"name",{value:t,configurable:!0});var a=Object.defineProperty,o=n((e,t)=>a(e,"name",{value:t,configurable:!0}),"n");const c=o((e,t,s)=>{e.setHeader("content-type","application/json; charset=utf-8"),e.statusCode=t,e.end(JSON.stringify(s,null,2))},"sendJson");module.exports=c;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var r=Object.defineProperty;var n=(e,t)=>r(e,"name",{value:t,configurable:!0});var s=Object.defineProperty,o=n((e,t)=>s(e,"name",{value:t,configurable:!0}),"n");const c=o((e,t,a)=>{e.setHeader("content-type","application/json; charset=utf-8"),e.statusCode=t,e.end(JSON.stringify(a,null,2))},"sendJson");export{c as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var f=Object.defineProperty;var a=(e,r)=>f(e,"name",{value:r,configurable:!0});import{createRequire as p}from"node:module";import{ZodError as d}from"zod";const l=p(import.meta.url),j=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process;const m=l("http-errors");var _=Object.defineProperty,g=a((e,r)=>_(e,"name",{value:r,configurable:!0}),"d");const v=g((e,r)=>async(s,c,u)=>{let t=s;try{t=await e.parseAsync(s)}catch(o){let{message:n}=o;throw o instanceof d&&typeof o.format=="function"&&(n=o.issues.map(i=>`${i.path.join("/")} - ${i.message}`).join("/n")),m(422,n)}return r(t,c,u)},"withZod");export{v as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var f=Object.defineProperty;var r=(t,e)=>f(t,"name",{value:e,configurable:!0});const p=require("http-errors"),d=require("zod"),l=r(t=>t&&typeof t=="object"&&"default"in t?t.default:t,"_interopDefaultCompat"),y=l(p);var m=Object.defineProperty,h=r((t,e)=>m(t,"name",{value:e,configurable:!0}),"d");const j=h((t,e)=>async(a,i,u)=>{let n=a;try{n=await t.parseAsync(a)}catch(o){let{message:s}=o;throw o instanceof d.ZodError&&typeof o.format=="function"&&(s=o.issues.map(c=>`${c.path.join("/")} - ${c.message}`).join("/n")),y(422,s)}return e(n,i,u)},"withZod");module.exports=j;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visulima/connect",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.21",
|
|
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,13 +42,13 @@
|
|
|
42
42
|
"type": "module",
|
|
43
43
|
"exports": {
|
|
44
44
|
".": {
|
|
45
|
-
"require": {
|
|
46
|
-
"types": "./dist/index.d.cts",
|
|
47
|
-
"default": "./dist/index.cjs"
|
|
48
|
-
},
|
|
49
45
|
"import": {
|
|
50
46
|
"types": "./dist/index.d.mts",
|
|
51
47
|
"default": "./dist/index.mjs"
|
|
48
|
+
},
|
|
49
|
+
"require": {
|
|
50
|
+
"types": "./dist/index.d.cts",
|
|
51
|
+
"default": "./dist/index.cjs"
|
|
52
52
|
}
|
|
53
53
|
},
|
|
54
54
|
"./package.json": "./package.json"
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"zod": "^3.22.4"
|
|
78
78
|
},
|
|
79
79
|
"engines": {
|
|
80
|
-
"node": ">=18.0.0 <=
|
|
80
|
+
"node": ">=18.0.0 <=24.x"
|
|
81
81
|
},
|
|
82
82
|
"os": [
|
|
83
83
|
"darwin",
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import withZod from './withZod-DGhSvb93.mjs';
|
|
2
|
-
import { Router } from './Router-CcNSmWZS.mjs';
|
|
3
|
-
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
-
const onNoMatch = /* @__PURE__ */ __name(async (request) => new Response(request.method === "HEAD" ? null : `Route ${request.method} ${request.url} not found`, { status: 404 }), "onNoMatch");
|
|
7
|
-
const onError = /* @__PURE__ */ __name(async (error) => {
|
|
8
|
-
console.error(error);
|
|
9
|
-
return new Response("Internal Server Error", { status: 500 });
|
|
10
|
-
}, "onError");
|
|
11
|
-
const getPathname = /* @__PURE__ */ __name((request) => (
|
|
12
|
-
// eslint-disable-next-line compat/compat
|
|
13
|
-
(request.nextUrl ?? new URL(request.url)).pathname
|
|
14
|
-
), "getPathname");
|
|
15
|
-
class EdgeRouter {
|
|
16
|
-
static {
|
|
17
|
-
__name(this, "EdgeRouter");
|
|
18
|
-
}
|
|
19
|
-
all = this.add.bind(this, "");
|
|
20
|
-
connect = this.add.bind(this, "CONNECT");
|
|
21
|
-
delete = this.add.bind(this, "DELETE");
|
|
22
|
-
get = this.add.bind(this, "GET");
|
|
23
|
-
head = this.add.bind(this, "HEAD");
|
|
24
|
-
options = this.add.bind(this, "OPTIONS");
|
|
25
|
-
patch = this.add.bind(this, "PATCH");
|
|
26
|
-
post = this.add.bind(this, "POST");
|
|
27
|
-
put = this.add.bind(this, "PUT");
|
|
28
|
-
trace = this.add.bind(this, "TRACE");
|
|
29
|
-
onError;
|
|
30
|
-
onNoMatch;
|
|
31
|
-
router = new Router();
|
|
32
|
-
constructor(options = {}) {
|
|
33
|
-
this.onNoMatch = options.onNoMatch ?? onNoMatch;
|
|
34
|
-
this.onError = options.onError ?? onError;
|
|
35
|
-
}
|
|
36
|
-
clone() {
|
|
37
|
-
const r = new EdgeRouter({ onError: this.onError, onNoMatch: this.onNoMatch });
|
|
38
|
-
r.router = this.router.clone();
|
|
39
|
-
return r;
|
|
40
|
-
}
|
|
41
|
-
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
|
42
|
-
handler() {
|
|
43
|
-
const { routes } = this.router;
|
|
44
|
-
return async (request, context_) => {
|
|
45
|
-
const result = this.router.find(request.method, getPathname(request));
|
|
46
|
-
this.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 result = this.router.find(request.method, getPathname(request));
|
|
56
|
-
if (result.fns.length === 0) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
this.prepareRequest(request, result);
|
|
60
|
-
return await Router.exec(result.fns, request, context_);
|
|
61
|
-
}
|
|
62
|
-
use(base, ...fns) {
|
|
63
|
-
if (typeof base === "function" || base instanceof EdgeRouter) {
|
|
64
|
-
fns.unshift(base);
|
|
65
|
-
base = "/";
|
|
66
|
-
}
|
|
67
|
-
this.router.use(base, ...fns.map((function_) => function_ instanceof EdgeRouter ? function_.router : function_));
|
|
68
|
-
return this;
|
|
69
|
-
}
|
|
70
|
-
add(method, routeOrFunction, zodOrRouteOrFunction, ...fns) {
|
|
71
|
-
if (typeof routeOrFunction === "string" && typeof zodOrRouteOrFunction === "function") {
|
|
72
|
-
fns = [zodOrRouteOrFunction];
|
|
73
|
-
} else if (typeof zodOrRouteOrFunction === "object") {
|
|
74
|
-
if (typeof routeOrFunction === "function") {
|
|
75
|
-
fns = [withZod(zodOrRouteOrFunction, routeOrFunction)];
|
|
76
|
-
} else {
|
|
77
|
-
fns = fns.map((function_) => withZod(zodOrRouteOrFunction, function_));
|
|
78
|
-
}
|
|
79
|
-
} else if (typeof zodOrRouteOrFunction === "function") {
|
|
80
|
-
fns = [zodOrRouteOrFunction];
|
|
81
|
-
}
|
|
82
|
-
this.router.add(method, routeOrFunction, ...fns);
|
|
83
|
-
return this;
|
|
84
|
-
}
|
|
85
|
-
// eslint-disable-next-line class-methods-use-this
|
|
86
|
-
prepareRequest(request, findResult) {
|
|
87
|
-
request.params = {
|
|
88
|
-
...findResult.params,
|
|
89
|
-
...request.params
|
|
90
|
-
// original params will take precedence
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
const createEdgeRouter = /* @__PURE__ */ __name((options = {}) => new EdgeRouter(options), "createEdgeRouter");
|
|
95
|
-
|
|
96
|
-
export { EdgeRouter, createEdgeRouter, getPathname };
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
|
-
|
|
5
|
-
const withZod = require('./withZod-DdTDLdDj.cjs');
|
|
6
|
-
const Router = require('./Router-Bh6INaMr.cjs');
|
|
7
|
-
|
|
8
|
-
var __defProp = Object.defineProperty;
|
|
9
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
10
|
-
const onNoMatch = /* @__PURE__ */ __name(async (request) => new Response(request.method === "HEAD" ? null : `Route ${request.method} ${request.url} not found`, { status: 404 }), "onNoMatch");
|
|
11
|
-
const onError = /* @__PURE__ */ __name(async (error) => {
|
|
12
|
-
console.error(error);
|
|
13
|
-
return new Response("Internal Server Error", { status: 500 });
|
|
14
|
-
}, "onError");
|
|
15
|
-
const getPathname = /* @__PURE__ */ __name((request) => (
|
|
16
|
-
// eslint-disable-next-line compat/compat
|
|
17
|
-
(request.nextUrl ?? new URL(request.url)).pathname
|
|
18
|
-
), "getPathname");
|
|
19
|
-
class EdgeRouter {
|
|
20
|
-
static {
|
|
21
|
-
__name(this, "EdgeRouter");
|
|
22
|
-
}
|
|
23
|
-
all = this.add.bind(this, "");
|
|
24
|
-
connect = this.add.bind(this, "CONNECT");
|
|
25
|
-
delete = this.add.bind(this, "DELETE");
|
|
26
|
-
get = this.add.bind(this, "GET");
|
|
27
|
-
head = this.add.bind(this, "HEAD");
|
|
28
|
-
options = this.add.bind(this, "OPTIONS");
|
|
29
|
-
patch = this.add.bind(this, "PATCH");
|
|
30
|
-
post = this.add.bind(this, "POST");
|
|
31
|
-
put = this.add.bind(this, "PUT");
|
|
32
|
-
trace = this.add.bind(this, "TRACE");
|
|
33
|
-
onError;
|
|
34
|
-
onNoMatch;
|
|
35
|
-
router = new Router.Router();
|
|
36
|
-
constructor(options = {}) {
|
|
37
|
-
this.onNoMatch = options.onNoMatch ?? onNoMatch;
|
|
38
|
-
this.onError = options.onError ?? onError;
|
|
39
|
-
}
|
|
40
|
-
clone() {
|
|
41
|
-
const r = new EdgeRouter({ onError: this.onError, onNoMatch: this.onNoMatch });
|
|
42
|
-
r.router = this.router.clone();
|
|
43
|
-
return r;
|
|
44
|
-
}
|
|
45
|
-
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
|
46
|
-
handler() {
|
|
47
|
-
const { routes } = this.router;
|
|
48
|
-
return async (request, context_) => {
|
|
49
|
-
const result = this.router.find(request.method, getPathname(request));
|
|
50
|
-
this.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 result = this.router.find(request.method, getPathname(request));
|
|
60
|
-
if (result.fns.length === 0) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
this.prepareRequest(request, result);
|
|
64
|
-
return await Router.Router.exec(result.fns, request, context_);
|
|
65
|
-
}
|
|
66
|
-
use(base, ...fns) {
|
|
67
|
-
if (typeof base === "function" || base instanceof EdgeRouter) {
|
|
68
|
-
fns.unshift(base);
|
|
69
|
-
base = "/";
|
|
70
|
-
}
|
|
71
|
-
this.router.use(base, ...fns.map((function_) => function_ instanceof EdgeRouter ? function_.router : function_));
|
|
72
|
-
return this;
|
|
73
|
-
}
|
|
74
|
-
add(method, routeOrFunction, zodOrRouteOrFunction, ...fns) {
|
|
75
|
-
if (typeof routeOrFunction === "string" && typeof zodOrRouteOrFunction === "function") {
|
|
76
|
-
fns = [zodOrRouteOrFunction];
|
|
77
|
-
} else if (typeof zodOrRouteOrFunction === "object") {
|
|
78
|
-
if (typeof routeOrFunction === "function") {
|
|
79
|
-
fns = [withZod(zodOrRouteOrFunction, routeOrFunction)];
|
|
80
|
-
} else {
|
|
81
|
-
fns = fns.map((function_) => withZod(zodOrRouteOrFunction, function_));
|
|
82
|
-
}
|
|
83
|
-
} else if (typeof zodOrRouteOrFunction === "function") {
|
|
84
|
-
fns = [zodOrRouteOrFunction];
|
|
85
|
-
}
|
|
86
|
-
this.router.add(method, routeOrFunction, ...fns);
|
|
87
|
-
return this;
|
|
88
|
-
}
|
|
89
|
-
// eslint-disable-next-line class-methods-use-this
|
|
90
|
-
prepareRequest(request, findResult) {
|
|
91
|
-
request.params = {
|
|
92
|
-
...findResult.params,
|
|
93
|
-
...request.params
|
|
94
|
-
// original params will take precedence
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
const createEdgeRouter = /* @__PURE__ */ __name((options = {}) => new EdgeRouter(options), "createEdgeRouter");
|
|
99
|
-
|
|
100
|
-
exports.EdgeRouter = EdgeRouter;
|
|
101
|
-
exports.createEdgeRouter = createEdgeRouter;
|
|
102
|
-
exports.getPathname = getPathname;
|
|
@@ -1,146 +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
|
-
var __defProp = Object.defineProperty;
|
|
8
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
-
class Router {
|
|
10
|
-
constructor(base = "/", routes = []) {
|
|
11
|
-
this.base = base;
|
|
12
|
-
this.routes = routes;
|
|
13
|
-
}
|
|
14
|
-
static {
|
|
15
|
-
__name(this, "Router");
|
|
16
|
-
}
|
|
17
|
-
static async exec(fns, ...arguments_) {
|
|
18
|
-
let index = 0;
|
|
19
|
-
const next = /* @__PURE__ */ __name(() => {
|
|
20
|
-
const function_ = fns[++index];
|
|
21
|
-
if (function_ === void 0) {
|
|
22
|
-
return Promise.resolve();
|
|
23
|
-
}
|
|
24
|
-
return function_(...arguments_, next);
|
|
25
|
-
}, "next");
|
|
26
|
-
return fns[index](...arguments_, next);
|
|
27
|
-
}
|
|
28
|
-
add(method, route, ...fns) {
|
|
29
|
-
if (typeof route === "function") {
|
|
30
|
-
fns.unshift(route);
|
|
31
|
-
route = "";
|
|
32
|
-
}
|
|
33
|
-
if (route === "") {
|
|
34
|
-
this.routes.push({
|
|
35
|
-
fns,
|
|
36
|
-
isMiddleware: false,
|
|
37
|
-
matchAll: true,
|
|
38
|
-
method
|
|
39
|
-
});
|
|
40
|
-
} else {
|
|
41
|
-
const { keys, pattern } = regexparam.parse(route);
|
|
42
|
-
this.routes.push({
|
|
43
|
-
fns,
|
|
44
|
-
isMiddleware: false,
|
|
45
|
-
keys,
|
|
46
|
-
method,
|
|
47
|
-
pattern
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
return this;
|
|
51
|
-
}
|
|
52
|
-
clone(base) {
|
|
53
|
-
return new Router(base, [...this.routes]);
|
|
54
|
-
}
|
|
55
|
-
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
56
|
-
find(method, pathname) {
|
|
57
|
-
let middleOnly = true;
|
|
58
|
-
const fns = [];
|
|
59
|
-
const parameters = {};
|
|
60
|
-
const isHead = method === "HEAD";
|
|
61
|
-
for (const route of this.routes) {
|
|
62
|
-
if (route.method !== method && // matches any method
|
|
63
|
-
route.method !== "" && // The HEAD method requests that the target resource transfer a representation of its state, as for a GET request...
|
|
64
|
-
!(isHead && route.method === "GET")) {
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
let matched = false;
|
|
68
|
-
if ("matchAll" in route) {
|
|
69
|
-
matched = true;
|
|
70
|
-
} else if (route.keys === false) {
|
|
71
|
-
const matches = route.pattern.exec(pathname);
|
|
72
|
-
if (matches === null) {
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
if (matches.groups !== void 0) {
|
|
76
|
-
Object.keys(matches.groups).forEach((key) => {
|
|
77
|
-
parameters[key] = matches.groups[key];
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
matched = true;
|
|
81
|
-
} else if (route.keys.length > 0) {
|
|
82
|
-
const matches = route.pattern.exec(pathname);
|
|
83
|
-
if (matches === null) {
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
for (let index = 0; index < route.keys.length; ) {
|
|
87
|
-
const parameterKey = route.keys[index];
|
|
88
|
-
parameters[parameterKey] = matches[++index];
|
|
89
|
-
}
|
|
90
|
-
matched = true;
|
|
91
|
-
} else if (route.pattern.test(pathname)) {
|
|
92
|
-
matched = true;
|
|
93
|
-
}
|
|
94
|
-
if (matched) {
|
|
95
|
-
fns.push(
|
|
96
|
-
...route.fns.flatMap((function_) => {
|
|
97
|
-
if (function_ instanceof Router) {
|
|
98
|
-
const { base } = function_;
|
|
99
|
-
let stripPathname = pathname.slice(base.length);
|
|
100
|
-
if (!stripPathname.startsWith("/")) {
|
|
101
|
-
stripPathname = `/${stripPathname}`;
|
|
102
|
-
}
|
|
103
|
-
const result = function_.find(method, stripPathname);
|
|
104
|
-
if (!result.middleOnly) {
|
|
105
|
-
middleOnly = false;
|
|
106
|
-
}
|
|
107
|
-
Object.assign(parameters, result.params);
|
|
108
|
-
return result.fns;
|
|
109
|
-
}
|
|
110
|
-
return function_;
|
|
111
|
-
})
|
|
112
|
-
);
|
|
113
|
-
if (!route.isMiddleware) {
|
|
114
|
-
middleOnly = false;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return { fns, middleOnly, params: parameters };
|
|
119
|
-
}
|
|
120
|
-
use(base, ...fns) {
|
|
121
|
-
if (typeof base === "function" || base instanceof Router) {
|
|
122
|
-
fns.unshift(base);
|
|
123
|
-
base = "/";
|
|
124
|
-
}
|
|
125
|
-
fns = fns.map((function_) => {
|
|
126
|
-
if (function_ instanceof Router) {
|
|
127
|
-
if (typeof base === "string") {
|
|
128
|
-
return function_.clone(base);
|
|
129
|
-
}
|
|
130
|
-
throw new Error("Mounting a router to RegExp base is not supported");
|
|
131
|
-
}
|
|
132
|
-
return function_;
|
|
133
|
-
});
|
|
134
|
-
const { keys, pattern } = regexparam.parse(base, true);
|
|
135
|
-
this.routes.push({
|
|
136
|
-
fns,
|
|
137
|
-
isMiddleware: true,
|
|
138
|
-
keys,
|
|
139
|
-
method: "",
|
|
140
|
-
pattern
|
|
141
|
-
});
|
|
142
|
-
return this;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
exports.Router = Router;
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { parse } from 'regexparam';
|
|
2
|
-
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
-
class Router {
|
|
6
|
-
constructor(base = "/", routes = []) {
|
|
7
|
-
this.base = base;
|
|
8
|
-
this.routes = routes;
|
|
9
|
-
}
|
|
10
|
-
static {
|
|
11
|
-
__name(this, "Router");
|
|
12
|
-
}
|
|
13
|
-
static async exec(fns, ...arguments_) {
|
|
14
|
-
let index = 0;
|
|
15
|
-
const next = /* @__PURE__ */ __name(() => {
|
|
16
|
-
const function_ = fns[++index];
|
|
17
|
-
if (function_ === void 0) {
|
|
18
|
-
return Promise.resolve();
|
|
19
|
-
}
|
|
20
|
-
return function_(...arguments_, next);
|
|
21
|
-
}, "next");
|
|
22
|
-
return fns[index](...arguments_, next);
|
|
23
|
-
}
|
|
24
|
-
add(method, route, ...fns) {
|
|
25
|
-
if (typeof route === "function") {
|
|
26
|
-
fns.unshift(route);
|
|
27
|
-
route = "";
|
|
28
|
-
}
|
|
29
|
-
if (route === "") {
|
|
30
|
-
this.routes.push({
|
|
31
|
-
fns,
|
|
32
|
-
isMiddleware: false,
|
|
33
|
-
matchAll: true,
|
|
34
|
-
method
|
|
35
|
-
});
|
|
36
|
-
} else {
|
|
37
|
-
const { keys, pattern } = parse(route);
|
|
38
|
-
this.routes.push({
|
|
39
|
-
fns,
|
|
40
|
-
isMiddleware: false,
|
|
41
|
-
keys,
|
|
42
|
-
method,
|
|
43
|
-
pattern
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
return this;
|
|
47
|
-
}
|
|
48
|
-
clone(base) {
|
|
49
|
-
return new Router(base, [...this.routes]);
|
|
50
|
-
}
|
|
51
|
-
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
52
|
-
find(method, pathname) {
|
|
53
|
-
let middleOnly = true;
|
|
54
|
-
const fns = [];
|
|
55
|
-
const parameters = {};
|
|
56
|
-
const isHead = method === "HEAD";
|
|
57
|
-
for (const route of this.routes) {
|
|
58
|
-
if (route.method !== method && // matches any method
|
|
59
|
-
route.method !== "" && // The HEAD method requests that the target resource transfer a representation of its state, as for a GET request...
|
|
60
|
-
!(isHead && route.method === "GET")) {
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
let matched = false;
|
|
64
|
-
if ("matchAll" in route) {
|
|
65
|
-
matched = true;
|
|
66
|
-
} else if (route.keys === false) {
|
|
67
|
-
const matches = route.pattern.exec(pathname);
|
|
68
|
-
if (matches === null) {
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
if (matches.groups !== void 0) {
|
|
72
|
-
Object.keys(matches.groups).forEach((key) => {
|
|
73
|
-
parameters[key] = matches.groups[key];
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
matched = true;
|
|
77
|
-
} else if (route.keys.length > 0) {
|
|
78
|
-
const matches = route.pattern.exec(pathname);
|
|
79
|
-
if (matches === null) {
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
for (let index = 0; index < route.keys.length; ) {
|
|
83
|
-
const parameterKey = route.keys[index];
|
|
84
|
-
parameters[parameterKey] = matches[++index];
|
|
85
|
-
}
|
|
86
|
-
matched = true;
|
|
87
|
-
} else if (route.pattern.test(pathname)) {
|
|
88
|
-
matched = true;
|
|
89
|
-
}
|
|
90
|
-
if (matched) {
|
|
91
|
-
fns.push(
|
|
92
|
-
...route.fns.flatMap((function_) => {
|
|
93
|
-
if (function_ instanceof Router) {
|
|
94
|
-
const { base } = function_;
|
|
95
|
-
let stripPathname = pathname.slice(base.length);
|
|
96
|
-
if (!stripPathname.startsWith("/")) {
|
|
97
|
-
stripPathname = `/${stripPathname}`;
|
|
98
|
-
}
|
|
99
|
-
const result = function_.find(method, stripPathname);
|
|
100
|
-
if (!result.middleOnly) {
|
|
101
|
-
middleOnly = false;
|
|
102
|
-
}
|
|
103
|
-
Object.assign(parameters, result.params);
|
|
104
|
-
return result.fns;
|
|
105
|
-
}
|
|
106
|
-
return function_;
|
|
107
|
-
})
|
|
108
|
-
);
|
|
109
|
-
if (!route.isMiddleware) {
|
|
110
|
-
middleOnly = false;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return { fns, middleOnly, params: parameters };
|
|
115
|
-
}
|
|
116
|
-
use(base, ...fns) {
|
|
117
|
-
if (typeof base === "function" || base instanceof Router) {
|
|
118
|
-
fns.unshift(base);
|
|
119
|
-
base = "/";
|
|
120
|
-
}
|
|
121
|
-
fns = fns.map((function_) => {
|
|
122
|
-
if (function_ instanceof Router) {
|
|
123
|
-
if (typeof base === "string") {
|
|
124
|
-
return function_.clone(base);
|
|
125
|
-
}
|
|
126
|
-
throw new Error("Mounting a router to RegExp base is not supported");
|
|
127
|
-
}
|
|
128
|
-
return function_;
|
|
129
|
-
});
|
|
130
|
-
const { keys, pattern } = parse(base, true);
|
|
131
|
-
this.routes.push({
|
|
132
|
-
fns,
|
|
133
|
-
isMiddleware: true,
|
|
134
|
-
keys,
|
|
135
|
-
method: "",
|
|
136
|
-
pattern
|
|
137
|
-
});
|
|
138
|
-
return this;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export { Router };
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import withZod from './withZod-DGhSvb93.mjs';
|
|
2
|
-
import { Router } from './Router-CcNSmWZS.mjs';
|
|
3
|
-
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
-
const onNoMatch = /* @__PURE__ */ __name(async (request, response) => {
|
|
7
|
-
response.statusCode = 404;
|
|
8
|
-
response.end(request.method === "HEAD" ? void 0 : `Route ${request.method} ${request.url} not found`);
|
|
9
|
-
}, "onNoMatch");
|
|
10
|
-
const onError = /* @__PURE__ */ __name(async (error, _request, response) => {
|
|
11
|
-
response.statusCode = 500;
|
|
12
|
-
console.error(error);
|
|
13
|
-
response.end("Internal Server Error");
|
|
14
|
-
}, "onError");
|
|
15
|
-
const getPathname = /* @__PURE__ */ __name((url) => {
|
|
16
|
-
const queryIndex = url.indexOf("?");
|
|
17
|
-
return queryIndex === -1 ? url : url.slice(0, Math.max(0, queryIndex));
|
|
18
|
-
}, "getPathname");
|
|
19
|
-
class NodeRouter {
|
|
20
|
-
static {
|
|
21
|
-
__name(this, "NodeRouter");
|
|
22
|
-
}
|
|
23
|
-
all = this.add.bind(this, "");
|
|
24
|
-
connect = this.add.bind(this, "CONNECT");
|
|
25
|
-
delete = this.add.bind(this, "DELETE");
|
|
26
|
-
get = this.add.bind(this, "GET");
|
|
27
|
-
head = this.add.bind(this, "HEAD");
|
|
28
|
-
options = this.add.bind(this, "OPTIONS");
|
|
29
|
-
patch = this.add.bind(this, "PATCH");
|
|
30
|
-
post = this.add.bind(this, "POST");
|
|
31
|
-
put = this.add.bind(this, "PUT");
|
|
32
|
-
trace = this.add.bind(this, "TRACE");
|
|
33
|
-
onError;
|
|
34
|
-
onNoMatch;
|
|
35
|
-
router = new Router();
|
|
36
|
-
constructor(options = {}) {
|
|
37
|
-
this.onNoMatch = options.onNoMatch ?? onNoMatch;
|
|
38
|
-
this.onError = options.onError ?? onError;
|
|
39
|
-
}
|
|
40
|
-
clone() {
|
|
41
|
-
const r = new NodeRouter({ onError: this.onError, onNoMatch: this.onNoMatch });
|
|
42
|
-
r.router = this.router.clone();
|
|
43
|
-
return r;
|
|
44
|
-
}
|
|
45
|
-
handler() {
|
|
46
|
-
const { routes } = this.router;
|
|
47
|
-
return async (request, response) => {
|
|
48
|
-
const result = this.router.find(request.method, getPathname(request.url));
|
|
49
|
-
this.prepareRequest(request, result);
|
|
50
|
-
try {
|
|
51
|
-
await (result.fns.length === 0 || result.middleOnly ? this.onNoMatch(request, response, routes) : Router.exec(result.fns, request, response));
|
|
52
|
-
} catch (error) {
|
|
53
|
-
await this.onError(error, request, response, routes);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
async run(request, response) {
|
|
58
|
-
const result = this.router.find(request.method, getPathname(request.url));
|
|
59
|
-
if (result.fns.length === 0) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
this.prepareRequest(request, result);
|
|
63
|
-
return await Router.exec(result.fns, request, response);
|
|
64
|
-
}
|
|
65
|
-
use(base, ...fns) {
|
|
66
|
-
if (typeof base === "function" || base instanceof NodeRouter) {
|
|
67
|
-
fns.unshift(base);
|
|
68
|
-
base = "/";
|
|
69
|
-
}
|
|
70
|
-
this.router.use(base, ...fns.map((function_) => function_ instanceof NodeRouter ? function_.router : function_));
|
|
71
|
-
return this;
|
|
72
|
-
}
|
|
73
|
-
add(method, routeOrFunction, zodOrRouteOrFunction, ...fns) {
|
|
74
|
-
if (typeof routeOrFunction === "string" && typeof zodOrRouteOrFunction === "function") {
|
|
75
|
-
fns = [zodOrRouteOrFunction];
|
|
76
|
-
} else if (typeof zodOrRouteOrFunction === "object") {
|
|
77
|
-
if (typeof routeOrFunction === "function") {
|
|
78
|
-
fns = [withZod(zodOrRouteOrFunction, routeOrFunction)];
|
|
79
|
-
} else {
|
|
80
|
-
fns = fns.map(
|
|
81
|
-
(function_) => withZod(zodOrRouteOrFunction, function_)
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
} else if (typeof zodOrRouteOrFunction === "function") {
|
|
85
|
-
fns = [zodOrRouteOrFunction];
|
|
86
|
-
}
|
|
87
|
-
this.router.add(method, routeOrFunction, ...fns);
|
|
88
|
-
return this;
|
|
89
|
-
}
|
|
90
|
-
// eslint-disable-next-line class-methods-use-this
|
|
91
|
-
prepareRequest(request, findResult) {
|
|
92
|
-
request.params = {
|
|
93
|
-
...findResult.params,
|
|
94
|
-
...request.params
|
|
95
|
-
// original params will take precedence
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
const createRouter = /* @__PURE__ */ __name((options = {}) => new NodeRouter(options), "createRouter");
|
|
100
|
-
|
|
101
|
-
export { NodeRouter, createRouter, getPathname };
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
|
-
|
|
5
|
-
const withZod = require('./withZod-DdTDLdDj.cjs');
|
|
6
|
-
const Router = require('./Router-Bh6INaMr.cjs');
|
|
7
|
-
|
|
8
|
-
var __defProp = Object.defineProperty;
|
|
9
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
10
|
-
const onNoMatch = /* @__PURE__ */ __name(async (request, response) => {
|
|
11
|
-
response.statusCode = 404;
|
|
12
|
-
response.end(request.method === "HEAD" ? void 0 : `Route ${request.method} ${request.url} not found`);
|
|
13
|
-
}, "onNoMatch");
|
|
14
|
-
const onError = /* @__PURE__ */ __name(async (error, _request, response) => {
|
|
15
|
-
response.statusCode = 500;
|
|
16
|
-
console.error(error);
|
|
17
|
-
response.end("Internal Server Error");
|
|
18
|
-
}, "onError");
|
|
19
|
-
const getPathname = /* @__PURE__ */ __name((url) => {
|
|
20
|
-
const queryIndex = url.indexOf("?");
|
|
21
|
-
return queryIndex === -1 ? url : url.slice(0, Math.max(0, queryIndex));
|
|
22
|
-
}, "getPathname");
|
|
23
|
-
class NodeRouter {
|
|
24
|
-
static {
|
|
25
|
-
__name(this, "NodeRouter");
|
|
26
|
-
}
|
|
27
|
-
all = this.add.bind(this, "");
|
|
28
|
-
connect = this.add.bind(this, "CONNECT");
|
|
29
|
-
delete = this.add.bind(this, "DELETE");
|
|
30
|
-
get = this.add.bind(this, "GET");
|
|
31
|
-
head = this.add.bind(this, "HEAD");
|
|
32
|
-
options = this.add.bind(this, "OPTIONS");
|
|
33
|
-
patch = this.add.bind(this, "PATCH");
|
|
34
|
-
post = this.add.bind(this, "POST");
|
|
35
|
-
put = this.add.bind(this, "PUT");
|
|
36
|
-
trace = this.add.bind(this, "TRACE");
|
|
37
|
-
onError;
|
|
38
|
-
onNoMatch;
|
|
39
|
-
router = new Router.Router();
|
|
40
|
-
constructor(options = {}) {
|
|
41
|
-
this.onNoMatch = options.onNoMatch ?? onNoMatch;
|
|
42
|
-
this.onError = options.onError ?? onError;
|
|
43
|
-
}
|
|
44
|
-
clone() {
|
|
45
|
-
const r = new NodeRouter({ onError: this.onError, onNoMatch: this.onNoMatch });
|
|
46
|
-
r.router = this.router.clone();
|
|
47
|
-
return r;
|
|
48
|
-
}
|
|
49
|
-
handler() {
|
|
50
|
-
const { routes } = this.router;
|
|
51
|
-
return async (request, response) => {
|
|
52
|
-
const result = this.router.find(request.method, getPathname(request.url));
|
|
53
|
-
this.prepareRequest(request, result);
|
|
54
|
-
try {
|
|
55
|
-
await (result.fns.length === 0 || result.middleOnly ? this.onNoMatch(request, response, routes) : Router.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 result = this.router.find(request.method, getPathname(request.url));
|
|
63
|
-
if (result.fns.length === 0) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
this.prepareRequest(request, result);
|
|
67
|
-
return await Router.Router.exec(result.fns, request, response);
|
|
68
|
-
}
|
|
69
|
-
use(base, ...fns) {
|
|
70
|
-
if (typeof base === "function" || base instanceof NodeRouter) {
|
|
71
|
-
fns.unshift(base);
|
|
72
|
-
base = "/";
|
|
73
|
-
}
|
|
74
|
-
this.router.use(base, ...fns.map((function_) => function_ instanceof NodeRouter ? function_.router : function_));
|
|
75
|
-
return this;
|
|
76
|
-
}
|
|
77
|
-
add(method, routeOrFunction, zodOrRouteOrFunction, ...fns) {
|
|
78
|
-
if (typeof routeOrFunction === "string" && typeof zodOrRouteOrFunction === "function") {
|
|
79
|
-
fns = [zodOrRouteOrFunction];
|
|
80
|
-
} else if (typeof zodOrRouteOrFunction === "object") {
|
|
81
|
-
if (typeof routeOrFunction === "function") {
|
|
82
|
-
fns = [withZod(zodOrRouteOrFunction, routeOrFunction)];
|
|
83
|
-
} else {
|
|
84
|
-
fns = fns.map(
|
|
85
|
-
(function_) => withZod(zodOrRouteOrFunction, function_)
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
} else if (typeof zodOrRouteOrFunction === "function") {
|
|
89
|
-
fns = [zodOrRouteOrFunction];
|
|
90
|
-
}
|
|
91
|
-
this.router.add(method, routeOrFunction, ...fns);
|
|
92
|
-
return this;
|
|
93
|
-
}
|
|
94
|
-
// eslint-disable-next-line class-methods-use-this
|
|
95
|
-
prepareRequest(request, findResult) {
|
|
96
|
-
request.params = {
|
|
97
|
-
...findResult.params,
|
|
98
|
-
...request.params
|
|
99
|
-
// original params will take precedence
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
const createRouter = /* @__PURE__ */ __name((options = {}) => new NodeRouter(options), "createRouter");
|
|
104
|
-
|
|
105
|
-
exports.NodeRouter = NodeRouter;
|
|
106
|
-
exports.createRouter = createRouter;
|
|
107
|
-
exports.getPathname = getPathname;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
-
const expressWrapper = /* @__PURE__ */ __name((function_) => async (request, response, next) => (
|
|
6
|
-
// eslint-disable-next-line compat/compat
|
|
7
|
-
await new Promise((resolve, reject) => {
|
|
8
|
-
function_(request, response, (error) => error ? reject(error) : resolve());
|
|
9
|
-
}).then(next)
|
|
10
|
-
), "expressWrapper");
|
|
11
|
-
|
|
12
|
-
module.exports = expressWrapper;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
const expressWrapper = /* @__PURE__ */ __name((function_) => async (request, response, next) => (
|
|
4
|
-
// eslint-disable-next-line compat/compat
|
|
5
|
-
await new Promise((resolve, reject) => {
|
|
6
|
-
function_(request, response, (error) => error ? reject(error) : resolve());
|
|
7
|
-
}).then(next)
|
|
8
|
-
), "expressWrapper");
|
|
9
|
-
|
|
10
|
-
export { expressWrapper as default };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
const sendJson = /* @__PURE__ */ __name((response, statusCode, jsonBody) => {
|
|
4
|
-
response.setHeader("content-type", "application/json; charset=utf-8");
|
|
5
|
-
response.statusCode = statusCode;
|
|
6
|
-
response.end(JSON.stringify(jsonBody, null, 2));
|
|
7
|
-
}, "sendJson");
|
|
8
|
-
|
|
9
|
-
export { sendJson as default };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
-
const sendJson = /* @__PURE__ */ __name((response, statusCode, jsonBody) => {
|
|
6
|
-
response.setHeader("content-type", "application/json; charset=utf-8");
|
|
7
|
-
response.statusCode = statusCode;
|
|
8
|
-
response.end(JSON.stringify(jsonBody, null, 2));
|
|
9
|
-
}, "sendJson");
|
|
10
|
-
|
|
11
|
-
module.exports = sendJson;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import createHttpError from 'http-errors';
|
|
2
|
-
import { ZodError } from 'zod';
|
|
3
|
-
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
-
const withZod = /* @__PURE__ */ __name((schema, handler) => async (request, response, next) => {
|
|
7
|
-
let transformedRequest = request;
|
|
8
|
-
try {
|
|
9
|
-
transformedRequest = await schema.parseAsync(request);
|
|
10
|
-
} catch (error) {
|
|
11
|
-
let { message } = error;
|
|
12
|
-
if (error instanceof ZodError && typeof error.format === "function") {
|
|
13
|
-
message = error.issues.map((issue) => `${issue.path.join("/")} - ${issue.message}`).join("/n");
|
|
14
|
-
}
|
|
15
|
-
throw createHttpError(422, message);
|
|
16
|
-
}
|
|
17
|
-
return handler(transformedRequest, response, next);
|
|
18
|
-
}, "withZod");
|
|
19
|
-
|
|
20
|
-
export { withZod as default };
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const createHttpError = require('http-errors');
|
|
4
|
-
const zod = require('zod');
|
|
5
|
-
|
|
6
|
-
const _interopDefaultCompat = e => e && typeof e === 'object' && 'default' in e ? e.default : e;
|
|
7
|
-
|
|
8
|
-
const createHttpError__default = /*#__PURE__*/_interopDefaultCompat(createHttpError);
|
|
9
|
-
|
|
10
|
-
var __defProp = Object.defineProperty;
|
|
11
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
12
|
-
const withZod = /* @__PURE__ */ __name((schema, handler) => async (request, response, next) => {
|
|
13
|
-
let transformedRequest = request;
|
|
14
|
-
try {
|
|
15
|
-
transformedRequest = await schema.parseAsync(request);
|
|
16
|
-
} catch (error) {
|
|
17
|
-
let { message } = error;
|
|
18
|
-
if (error instanceof zod.ZodError && typeof error.format === "function") {
|
|
19
|
-
message = error.issues.map((issue) => `${issue.path.join("/")} - ${issue.message}`).join("/n");
|
|
20
|
-
}
|
|
21
|
-
throw createHttpError__default(422, message);
|
|
22
|
-
}
|
|
23
|
-
return handler(transformedRequest, response, next);
|
|
24
|
-
}, "withZod");
|
|
25
|
-
|
|
26
|
-
module.exports = withZod;
|