@visulima/connect 3.0.24 → 3.0.25
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 +10 -0
- package/dist/index.cjs +22 -1
- package/dist/index.d.cts +11 -11
- package/dist/index.d.mts +11 -11
- package/dist/index.d.ts +11 -11
- package/dist/index.mjs +6 -1
- package/dist/packem_shared/EdgeRouter-B-e2l9un.cjs +96 -0
- package/dist/packem_shared/EdgeRouter-CdtQHTwm.mjs +90 -0
- package/dist/packem_shared/Router-ChnTdYfl.mjs +135 -0
- package/dist/packem_shared/Router-Eg_OPxIL.cjs +139 -0
- package/dist/packem_shared/createRouter-C8hDVJcV.cjs +102 -0
- package/dist/packem_shared/createRouter-_G1XhaP4.mjs +96 -0
- package/dist/packem_shared/expressWrapper-CTExfWvM.cjs +10 -0
- package/dist/packem_shared/expressWrapper-spfs58is.mjs +8 -0
- package/dist/packem_shared/sendJson-DwLYLDbt.mjs +7 -0
- package/dist/packem_shared/sendJson-pJY2tT2n.cjs +9 -0
- package/dist/packem_shared/withZod-HYgoC7AX.mjs +18 -0
- package/dist/packem_shared/withZod-ULTsdyM5.cjs +24 -0
- package/package.json +1 -1
- package/dist/packem_shared/EdgeRouter-DkYqae6k.mjs +0 -1
- package/dist/packem_shared/EdgeRouter-KIBlNPX3.cjs +0 -1
- package/dist/packem_shared/Router-Dg3J0bWq.mjs +0 -1
- package/dist/packem_shared/Router-fcD22mVn.cjs +0 -1
- package/dist/packem_shared/createRouter-Bp84h_yy.mjs +0 -1
- package/dist/packem_shared/createRouter-CcKo5sWT.cjs +0 -1
- package/dist/packem_shared/expressWrapper-CnZ-5oTw.cjs +0 -1
- package/dist/packem_shared/expressWrapper-D-d31tgs.mjs +0 -1
- package/dist/packem_shared/sendJson-l4jM19lK.cjs +0 -1
- package/dist/packem_shared/sendJson-zUtTFUYn.mjs +0 -1
- package/dist/packem_shared/withZod-CvygheEk.cjs +0 -1
- package/dist/packem_shared/withZod-wmNwBerD.mjs +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
## @visulima/connect [3.0.25](https://github.com/visulima/visulima/compare/@visulima/connect@3.0.24...@visulima/connect@3.0.25) (2025-11-07)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
* update TypeScript configurations and improve linting across multiple packages ([6f25ec7](https://github.com/visulima/visulima/commit/6f25ec7841da7246f8f9166efc5292a7089d37ee))
|
|
6
|
+
|
|
7
|
+
### Miscellaneous Chores
|
|
8
|
+
|
|
9
|
+
* update npm and pnpm configurations for monorepo optimization ([#564](https://github.com/visulima/visulima/issues/564)) ([5512b42](https://github.com/visulima/visulima/commit/5512b42f672c216b6a3c9e39035199a4ebd9a4b8))
|
|
10
|
+
|
|
1
11
|
## @visulima/connect [3.0.24](https://github.com/visulima/visulima/compare/@visulima/connect@3.0.23...@visulima/connect@3.0.24) (2025-11-05)
|
|
2
12
|
|
|
3
13
|
### Bug Fixes
|
package/dist/index.cjs
CHANGED
|
@@ -1 +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-CTExfWvM.cjs');
|
|
6
|
+
const withZod = require('./packem_shared/withZod-ULTsdyM5.cjs');
|
|
7
|
+
const EdgeRouter = require('./packem_shared/EdgeRouter-B-e2l9un.cjs');
|
|
8
|
+
const createRouter = require('./packem_shared/createRouter-C8hDVJcV.cjs');
|
|
9
|
+
const Router = require('./packem_shared/Router-Eg_OPxIL.cjs');
|
|
10
|
+
const sendJson = require('./packem_shared/sendJson-pJY2tT2n.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;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
-
import {
|
|
2
|
+
import { ZodObject } from 'zod';
|
|
3
3
|
|
|
4
4
|
type HttpMethod = "CONNECT" | "DELETE" | "GET" | "HEAD" | "OPTIONS" | "PATCH" | "POST" | "PUT" | "TRACE";
|
|
5
5
|
|
|
@@ -31,7 +31,7 @@ interface HandlerOptions<Handler extends FunctionLike> {
|
|
|
31
31
|
onNoMatch?: Handler;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
type RouteShortcutMethod<This, Schema extends
|
|
34
|
+
type RouteShortcutMethod<This, Schema extends ZodObject<any>, H extends FunctionLike> = (
|
|
35
35
|
route: Nextable<H> | RouteMatch,
|
|
36
36
|
zodSchemaOrRouteOrFns?: Nextable<H> | RouteMatch | Schema | string,
|
|
37
37
|
...fns: Nextable<H>[]
|
|
@@ -59,7 +59,7 @@ declare class Router<H extends FunctionLike> {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
type RequestHandler$1<Request extends IncomingMessage, Response extends ServerResponse> = (request: Request, response: Response) => ValueOrPromise<void>;
|
|
62
|
-
declare class NodeRouter<Request extends IncomingMessage = IncomingMessage, Response extends ServerResponse = ServerResponse, Schema extends
|
|
62
|
+
declare class NodeRouter<Request extends IncomingMessage = IncomingMessage, Response extends ServerResponse = ServerResponse, Schema extends ZodObject<any> = ZodObject<never>> {
|
|
63
63
|
all: RouteShortcutMethod<this, Schema, RequestHandler$1<Request, Response>>;
|
|
64
64
|
connect: RouteShortcutMethod<this, Schema, RequestHandler$1<Request, Response>>;
|
|
65
65
|
delete: RouteShortcutMethod<this, Schema, RequestHandler$1<Request, Response>>;
|
|
@@ -81,10 +81,10 @@ declare class NodeRouter<Request extends IncomingMessage = IncomingMessage, Resp
|
|
|
81
81
|
private add;
|
|
82
82
|
private prepareRequest;
|
|
83
83
|
}
|
|
84
|
-
declare const createRouter: <Request extends IncomingMessage, Response extends ServerResponse, Schema extends
|
|
85
|
-
body?:
|
|
86
|
-
headers?:
|
|
87
|
-
query?:
|
|
84
|
+
declare const createRouter: <Request extends IncomingMessage, Response extends ServerResponse, Schema extends ZodObject<any> = ZodObject<{
|
|
85
|
+
body?: ZodObject<any>;
|
|
86
|
+
headers?: ZodObject<any>;
|
|
87
|
+
query?: ZodObject<any>;
|
|
88
88
|
}>>(options?: HandlerOptions<RoutesExtendedRequestHandler<Request, Response, Response, Route<Nextable<FunctionLike>>[]>>) => NodeRouter<Request, Response, Schema>;
|
|
89
89
|
|
|
90
90
|
type NextFunction = (error?: any) => void;
|
|
@@ -92,13 +92,13 @@ declare const expressWrapper: <Request extends IncomingMessage, Response extends
|
|
|
92
92
|
type ExpressRequestHandler<Request, Response> = (request: Request, response: Response, next: NextFunction) => void;
|
|
93
93
|
|
|
94
94
|
declare const withZod: <Request, Response, Handler extends Nextable<any>, Schema extends ZodObject<{
|
|
95
|
-
body?:
|
|
96
|
-
headers?:
|
|
97
|
-
query?:
|
|
95
|
+
body?: ZodObject<any>;
|
|
96
|
+
headers?: ZodObject<any>;
|
|
97
|
+
query?: ZodObject<any>;
|
|
98
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
|
-
declare class EdgeRouter<R extends Request = Request, Context = unknown, RResponse extends Response = Response, Schema extends
|
|
101
|
+
declare class EdgeRouter<R extends Request = Request, Context = unknown, RResponse extends Response = Response, Schema extends ZodObject<any> = ZodObject<any>> {
|
|
102
102
|
all: RouteShortcutMethod<this, Schema, RequestHandler<R, Context>>;
|
|
103
103
|
connect: RouteShortcutMethod<this, Schema, RequestHandler<R, Context>>;
|
|
104
104
|
delete: RouteShortcutMethod<this, Schema, RequestHandler<R, Context>>;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
-
import {
|
|
2
|
+
import { ZodObject } from 'zod';
|
|
3
3
|
|
|
4
4
|
type HttpMethod = "CONNECT" | "DELETE" | "GET" | "HEAD" | "OPTIONS" | "PATCH" | "POST" | "PUT" | "TRACE";
|
|
5
5
|
|
|
@@ -31,7 +31,7 @@ interface HandlerOptions<Handler extends FunctionLike> {
|
|
|
31
31
|
onNoMatch?: Handler;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
type RouteShortcutMethod<This, Schema extends
|
|
34
|
+
type RouteShortcutMethod<This, Schema extends ZodObject<any>, H extends FunctionLike> = (
|
|
35
35
|
route: Nextable<H> | RouteMatch,
|
|
36
36
|
zodSchemaOrRouteOrFns?: Nextable<H> | RouteMatch | Schema | string,
|
|
37
37
|
...fns: Nextable<H>[]
|
|
@@ -59,7 +59,7 @@ declare class Router<H extends FunctionLike> {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
type RequestHandler$1<Request extends IncomingMessage, Response extends ServerResponse> = (request: Request, response: Response) => ValueOrPromise<void>;
|
|
62
|
-
declare class NodeRouter<Request extends IncomingMessage = IncomingMessage, Response extends ServerResponse = ServerResponse, Schema extends
|
|
62
|
+
declare class NodeRouter<Request extends IncomingMessage = IncomingMessage, Response extends ServerResponse = ServerResponse, Schema extends ZodObject<any> = ZodObject<never>> {
|
|
63
63
|
all: RouteShortcutMethod<this, Schema, RequestHandler$1<Request, Response>>;
|
|
64
64
|
connect: RouteShortcutMethod<this, Schema, RequestHandler$1<Request, Response>>;
|
|
65
65
|
delete: RouteShortcutMethod<this, Schema, RequestHandler$1<Request, Response>>;
|
|
@@ -81,10 +81,10 @@ declare class NodeRouter<Request extends IncomingMessage = IncomingMessage, Resp
|
|
|
81
81
|
private add;
|
|
82
82
|
private prepareRequest;
|
|
83
83
|
}
|
|
84
|
-
declare const createRouter: <Request extends IncomingMessage, Response extends ServerResponse, Schema extends
|
|
85
|
-
body?:
|
|
86
|
-
headers?:
|
|
87
|
-
query?:
|
|
84
|
+
declare const createRouter: <Request extends IncomingMessage, Response extends ServerResponse, Schema extends ZodObject<any> = ZodObject<{
|
|
85
|
+
body?: ZodObject<any>;
|
|
86
|
+
headers?: ZodObject<any>;
|
|
87
|
+
query?: ZodObject<any>;
|
|
88
88
|
}>>(options?: HandlerOptions<RoutesExtendedRequestHandler<Request, Response, Response, Route<Nextable<FunctionLike>>[]>>) => NodeRouter<Request, Response, Schema>;
|
|
89
89
|
|
|
90
90
|
type NextFunction = (error?: any) => void;
|
|
@@ -92,13 +92,13 @@ declare const expressWrapper: <Request extends IncomingMessage, Response extends
|
|
|
92
92
|
type ExpressRequestHandler<Request, Response> = (request: Request, response: Response, next: NextFunction) => void;
|
|
93
93
|
|
|
94
94
|
declare const withZod: <Request, Response, Handler extends Nextable<any>, Schema extends ZodObject<{
|
|
95
|
-
body?:
|
|
96
|
-
headers?:
|
|
97
|
-
query?:
|
|
95
|
+
body?: ZodObject<any>;
|
|
96
|
+
headers?: ZodObject<any>;
|
|
97
|
+
query?: ZodObject<any>;
|
|
98
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
|
-
declare class EdgeRouter<R extends Request = Request, Context = unknown, RResponse extends Response = Response, Schema extends
|
|
101
|
+
declare class EdgeRouter<R extends Request = Request, Context = unknown, RResponse extends Response = Response, Schema extends ZodObject<any> = ZodObject<any>> {
|
|
102
102
|
all: RouteShortcutMethod<this, Schema, RequestHandler<R, Context>>;
|
|
103
103
|
connect: RouteShortcutMethod<this, Schema, RequestHandler<R, Context>>;
|
|
104
104
|
delete: RouteShortcutMethod<this, Schema, RequestHandler<R, Context>>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
-
import {
|
|
2
|
+
import { ZodObject } from 'zod';
|
|
3
3
|
|
|
4
4
|
type HttpMethod = "CONNECT" | "DELETE" | "GET" | "HEAD" | "OPTIONS" | "PATCH" | "POST" | "PUT" | "TRACE";
|
|
5
5
|
|
|
@@ -31,7 +31,7 @@ interface HandlerOptions<Handler extends FunctionLike> {
|
|
|
31
31
|
onNoMatch?: Handler;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
type RouteShortcutMethod<This, Schema extends
|
|
34
|
+
type RouteShortcutMethod<This, Schema extends ZodObject<any>, H extends FunctionLike> = (
|
|
35
35
|
route: Nextable<H> | RouteMatch,
|
|
36
36
|
zodSchemaOrRouteOrFns?: Nextable<H> | RouteMatch | Schema | string,
|
|
37
37
|
...fns: Nextable<H>[]
|
|
@@ -59,7 +59,7 @@ declare class Router<H extends FunctionLike> {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
type RequestHandler$1<Request extends IncomingMessage, Response extends ServerResponse> = (request: Request, response: Response) => ValueOrPromise<void>;
|
|
62
|
-
declare class NodeRouter<Request extends IncomingMessage = IncomingMessage, Response extends ServerResponse = ServerResponse, Schema extends
|
|
62
|
+
declare class NodeRouter<Request extends IncomingMessage = IncomingMessage, Response extends ServerResponse = ServerResponse, Schema extends ZodObject<any> = ZodObject<never>> {
|
|
63
63
|
all: RouteShortcutMethod<this, Schema, RequestHandler$1<Request, Response>>;
|
|
64
64
|
connect: RouteShortcutMethod<this, Schema, RequestHandler$1<Request, Response>>;
|
|
65
65
|
delete: RouteShortcutMethod<this, Schema, RequestHandler$1<Request, Response>>;
|
|
@@ -81,10 +81,10 @@ declare class NodeRouter<Request extends IncomingMessage = IncomingMessage, Resp
|
|
|
81
81
|
private add;
|
|
82
82
|
private prepareRequest;
|
|
83
83
|
}
|
|
84
|
-
declare const createRouter: <Request extends IncomingMessage, Response extends ServerResponse, Schema extends
|
|
85
|
-
body?:
|
|
86
|
-
headers?:
|
|
87
|
-
query?:
|
|
84
|
+
declare const createRouter: <Request extends IncomingMessage, Response extends ServerResponse, Schema extends ZodObject<any> = ZodObject<{
|
|
85
|
+
body?: ZodObject<any>;
|
|
86
|
+
headers?: ZodObject<any>;
|
|
87
|
+
query?: ZodObject<any>;
|
|
88
88
|
}>>(options?: HandlerOptions<RoutesExtendedRequestHandler<Request, Response, Response, Route<Nextable<FunctionLike>>[]>>) => NodeRouter<Request, Response, Schema>;
|
|
89
89
|
|
|
90
90
|
type NextFunction = (error?: any) => void;
|
|
@@ -92,13 +92,13 @@ declare const expressWrapper: <Request extends IncomingMessage, Response extends
|
|
|
92
92
|
type ExpressRequestHandler<Request, Response> = (request: Request, response: Response, next: NextFunction) => void;
|
|
93
93
|
|
|
94
94
|
declare const withZod: <Request, Response, Handler extends Nextable<any>, Schema extends ZodObject<{
|
|
95
|
-
body?:
|
|
96
|
-
headers?:
|
|
97
|
-
query?:
|
|
95
|
+
body?: ZodObject<any>;
|
|
96
|
+
headers?: ZodObject<any>;
|
|
97
|
+
query?: ZodObject<any>;
|
|
98
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
|
-
declare class EdgeRouter<R extends Request = Request, Context = unknown, RResponse extends Response = Response, Schema extends
|
|
101
|
+
declare class EdgeRouter<R extends Request = Request, Context = unknown, RResponse extends Response = Response, Schema extends ZodObject<any> = ZodObject<any>> {
|
|
102
102
|
all: RouteShortcutMethod<this, Schema, RequestHandler<R, Context>>;
|
|
103
103
|
connect: RouteShortcutMethod<this, Schema, RequestHandler<R, Context>>;
|
|
104
104
|
delete: RouteShortcutMethod<this, Schema, RequestHandler<R, Context>>;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
export { default as expressWrapper } from './packem_shared/expressWrapper-spfs58is.mjs';
|
|
2
|
+
export { default as withZod } from './packem_shared/withZod-HYgoC7AX.mjs';
|
|
3
|
+
export { EdgeRouter, createEdgeRouter } from './packem_shared/EdgeRouter-CdtQHTwm.mjs';
|
|
4
|
+
export { NodeRouter, createRouter as createNodeRouter, createRouter } from './packem_shared/createRouter-_G1XhaP4.mjs';
|
|
5
|
+
export { Router } from './packem_shared/Router-ChnTdYfl.mjs';
|
|
6
|
+
export { default as sendJson } from './packem_shared/sendJson-DwLYLDbt.mjs';
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
|
+
|
|
5
|
+
const withZod = require('./withZod-ULTsdyM5.cjs');
|
|
6
|
+
const Router = require('./Router-Eg_OPxIL.cjs');
|
|
7
|
+
|
|
8
|
+
const onNoMatch = async (request) => new Response(request.method === "HEAD" ? null : `Route ${request.method} ${request.url} not found`, { status: 404 });
|
|
9
|
+
const onError = async (error) => {
|
|
10
|
+
console.error(error);
|
|
11
|
+
return new Response("Internal Server Error", { status: 500 });
|
|
12
|
+
};
|
|
13
|
+
const getPathname = (request) => (
|
|
14
|
+
// eslint-disable-next-line compat/compat
|
|
15
|
+
(request.nextUrl ?? new URL(request.url)).pathname
|
|
16
|
+
);
|
|
17
|
+
class EdgeRouter {
|
|
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.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 result = this.router.find(request.method, getPathname(request));
|
|
44
|
+
this.prepareRequest(request, result);
|
|
45
|
+
try {
|
|
46
|
+
return await (result.fns.length === 0 || result.middleOnly ? this.onNoMatch(request, context_, routes) : Router.Router.exec(result.fns, request, context_));
|
|
47
|
+
} catch (error) {
|
|
48
|
+
return await this.onError(error, request, context_, routes);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
async run(request, context_) {
|
|
53
|
+
const result = this.router.find(request.method, getPathname(request));
|
|
54
|
+
if (result.fns.length === 0) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
this.prepareRequest(request, result);
|
|
58
|
+
return await Router.Router.exec(result.fns, request, context_);
|
|
59
|
+
}
|
|
60
|
+
use(base, ...fns) {
|
|
61
|
+
if (typeof base === "function" || base instanceof EdgeRouter) {
|
|
62
|
+
fns.unshift(base);
|
|
63
|
+
base = "/";
|
|
64
|
+
}
|
|
65
|
+
this.router.use(base, ...fns.map((function_) => function_ instanceof EdgeRouter ? function_.router : function_));
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
add(method, routeOrFunction, zodOrRouteOrFunction, ...fns) {
|
|
69
|
+
if (typeof routeOrFunction === "string" && typeof zodOrRouteOrFunction === "function") {
|
|
70
|
+
fns = [zodOrRouteOrFunction];
|
|
71
|
+
} else if (typeof zodOrRouteOrFunction === "object") {
|
|
72
|
+
if (typeof routeOrFunction === "function") {
|
|
73
|
+
fns = [withZod(zodOrRouteOrFunction, routeOrFunction)];
|
|
74
|
+
} else {
|
|
75
|
+
fns = fns.map((function_) => withZod(zodOrRouteOrFunction, function_));
|
|
76
|
+
}
|
|
77
|
+
} else if (typeof zodOrRouteOrFunction === "function") {
|
|
78
|
+
fns = [zodOrRouteOrFunction];
|
|
79
|
+
}
|
|
80
|
+
this.router.add(method, routeOrFunction, ...fns);
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
// eslint-disable-next-line class-methods-use-this
|
|
84
|
+
prepareRequest(request, findResult) {
|
|
85
|
+
request.params = {
|
|
86
|
+
...findResult.params,
|
|
87
|
+
...request.params
|
|
88
|
+
// original params will take precedence
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const createEdgeRouter = (options = {}) => new EdgeRouter(options);
|
|
93
|
+
|
|
94
|
+
exports.EdgeRouter = EdgeRouter;
|
|
95
|
+
exports.createEdgeRouter = createEdgeRouter;
|
|
96
|
+
exports.getPathname = getPathname;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import withZod from './withZod-HYgoC7AX.mjs';
|
|
2
|
+
import { Router } from './Router-ChnTdYfl.mjs';
|
|
3
|
+
|
|
4
|
+
const onNoMatch = async (request) => new Response(request.method === "HEAD" ? null : `Route ${request.method} ${request.url} not found`, { status: 404 });
|
|
5
|
+
const onError = async (error) => {
|
|
6
|
+
console.error(error);
|
|
7
|
+
return new Response("Internal Server Error", { status: 500 });
|
|
8
|
+
};
|
|
9
|
+
const getPathname = (request) => (
|
|
10
|
+
// eslint-disable-next-line compat/compat
|
|
11
|
+
(request.nextUrl ?? new URL(request.url)).pathname
|
|
12
|
+
);
|
|
13
|
+
class EdgeRouter {
|
|
14
|
+
all = this.add.bind(this, "");
|
|
15
|
+
connect = this.add.bind(this, "CONNECT");
|
|
16
|
+
delete = this.add.bind(this, "DELETE");
|
|
17
|
+
get = this.add.bind(this, "GET");
|
|
18
|
+
head = this.add.bind(this, "HEAD");
|
|
19
|
+
options = this.add.bind(this, "OPTIONS");
|
|
20
|
+
patch = this.add.bind(this, "PATCH");
|
|
21
|
+
post = this.add.bind(this, "POST");
|
|
22
|
+
put = this.add.bind(this, "PUT");
|
|
23
|
+
trace = this.add.bind(this, "TRACE");
|
|
24
|
+
onError;
|
|
25
|
+
onNoMatch;
|
|
26
|
+
router = new Router();
|
|
27
|
+
constructor(options = {}) {
|
|
28
|
+
this.onNoMatch = options.onNoMatch ?? onNoMatch;
|
|
29
|
+
this.onError = options.onError ?? onError;
|
|
30
|
+
}
|
|
31
|
+
clone() {
|
|
32
|
+
const r = new EdgeRouter({ onError: this.onError, onNoMatch: this.onNoMatch });
|
|
33
|
+
r.router = this.router.clone();
|
|
34
|
+
return r;
|
|
35
|
+
}
|
|
36
|
+
handler() {
|
|
37
|
+
const { routes } = this.router;
|
|
38
|
+
return async (request, context_) => {
|
|
39
|
+
const result = this.router.find(request.method, getPathname(request));
|
|
40
|
+
this.prepareRequest(request, result);
|
|
41
|
+
try {
|
|
42
|
+
return await (result.fns.length === 0 || result.middleOnly ? this.onNoMatch(request, context_, routes) : Router.exec(result.fns, request, context_));
|
|
43
|
+
} catch (error) {
|
|
44
|
+
return await this.onError(error, request, context_, routes);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
async run(request, context_) {
|
|
49
|
+
const result = this.router.find(request.method, getPathname(request));
|
|
50
|
+
if (result.fns.length === 0) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
this.prepareRequest(request, result);
|
|
54
|
+
return await Router.exec(result.fns, request, context_);
|
|
55
|
+
}
|
|
56
|
+
use(base, ...fns) {
|
|
57
|
+
if (typeof base === "function" || base instanceof EdgeRouter) {
|
|
58
|
+
fns.unshift(base);
|
|
59
|
+
base = "/";
|
|
60
|
+
}
|
|
61
|
+
this.router.use(base, ...fns.map((function_) => function_ instanceof EdgeRouter ? function_.router : function_));
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
add(method, routeOrFunction, zodOrRouteOrFunction, ...fns) {
|
|
65
|
+
if (typeof routeOrFunction === "string" && typeof zodOrRouteOrFunction === "function") {
|
|
66
|
+
fns = [zodOrRouteOrFunction];
|
|
67
|
+
} else if (typeof zodOrRouteOrFunction === "object") {
|
|
68
|
+
if (typeof routeOrFunction === "function") {
|
|
69
|
+
fns = [withZod(zodOrRouteOrFunction, routeOrFunction)];
|
|
70
|
+
} else {
|
|
71
|
+
fns = fns.map((function_) => withZod(zodOrRouteOrFunction, function_));
|
|
72
|
+
}
|
|
73
|
+
} else if (typeof zodOrRouteOrFunction === "function") {
|
|
74
|
+
fns = [zodOrRouteOrFunction];
|
|
75
|
+
}
|
|
76
|
+
this.router.add(method, routeOrFunction, ...fns);
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
// eslint-disable-next-line class-methods-use-this
|
|
80
|
+
prepareRequest(request, findResult) {
|
|
81
|
+
request.params = {
|
|
82
|
+
...findResult.params,
|
|
83
|
+
...request.params
|
|
84
|
+
// original params will take precedence
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const createEdgeRouter = (options = {}) => new EdgeRouter(options);
|
|
89
|
+
|
|
90
|
+
export { EdgeRouter, createEdgeRouter, getPathname };
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { parse } from 'regexparam';
|
|
2
|
+
|
|
3
|
+
class Router {
|
|
4
|
+
constructor(base = "/", routes = []) {
|
|
5
|
+
this.base = base;
|
|
6
|
+
this.routes = routes;
|
|
7
|
+
}
|
|
8
|
+
static async exec(fns, ...arguments_) {
|
|
9
|
+
let index = 0;
|
|
10
|
+
const next = () => {
|
|
11
|
+
const function_ = fns[++index];
|
|
12
|
+
if (function_ === void 0) {
|
|
13
|
+
return Promise.resolve();
|
|
14
|
+
}
|
|
15
|
+
return function_(...arguments_, next);
|
|
16
|
+
};
|
|
17
|
+
return fns[index](...arguments_, next);
|
|
18
|
+
}
|
|
19
|
+
add(method, route, ...fns) {
|
|
20
|
+
if (typeof route === "function") {
|
|
21
|
+
fns.unshift(route);
|
|
22
|
+
route = "";
|
|
23
|
+
}
|
|
24
|
+
if (route === "") {
|
|
25
|
+
this.routes.push({
|
|
26
|
+
fns,
|
|
27
|
+
isMiddleware: false,
|
|
28
|
+
matchAll: true,
|
|
29
|
+
method
|
|
30
|
+
});
|
|
31
|
+
} else {
|
|
32
|
+
const { keys, pattern } = parse(route);
|
|
33
|
+
this.routes.push({
|
|
34
|
+
fns,
|
|
35
|
+
isMiddleware: false,
|
|
36
|
+
keys,
|
|
37
|
+
method,
|
|
38
|
+
pattern
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
clone(base) {
|
|
44
|
+
return new Router(base, [...this.routes]);
|
|
45
|
+
}
|
|
46
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
47
|
+
find(method, pathname) {
|
|
48
|
+
let middleOnly = true;
|
|
49
|
+
const fns = [];
|
|
50
|
+
const parameters = {};
|
|
51
|
+
const isHead = method === "HEAD";
|
|
52
|
+
for (const route of this.routes) {
|
|
53
|
+
if (route.method !== method && route.method !== "" && !(isHead && route.method === "GET")) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
let matched = false;
|
|
57
|
+
if ("matchAll" in route) {
|
|
58
|
+
matched = true;
|
|
59
|
+
} else if (route.keys === false) {
|
|
60
|
+
const matches = route.pattern.exec(pathname);
|
|
61
|
+
if (matches === null) {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (matches.groups !== void 0) {
|
|
65
|
+
Object.keys(matches.groups).forEach((key) => {
|
|
66
|
+
parameters[key] = matches.groups[key];
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
matched = true;
|
|
70
|
+
} else if (route.keys.length > 0) {
|
|
71
|
+
const matches = route.pattern.exec(pathname);
|
|
72
|
+
if (matches === null) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
for (let index = 0; index < route.keys.length; ) {
|
|
76
|
+
const parameterKey = route.keys[index];
|
|
77
|
+
parameters[parameterKey] = matches[++index];
|
|
78
|
+
}
|
|
79
|
+
matched = true;
|
|
80
|
+
} else if (route.pattern.test(pathname)) {
|
|
81
|
+
matched = true;
|
|
82
|
+
}
|
|
83
|
+
if (matched) {
|
|
84
|
+
fns.push(
|
|
85
|
+
...route.fns.flatMap((function_) => {
|
|
86
|
+
if (function_ instanceof Router) {
|
|
87
|
+
const { base } = function_;
|
|
88
|
+
let stripPathname = pathname.slice(base.length);
|
|
89
|
+
if (!stripPathname.startsWith("/")) {
|
|
90
|
+
stripPathname = `/${stripPathname}`;
|
|
91
|
+
}
|
|
92
|
+
const result = function_.find(method, stripPathname);
|
|
93
|
+
if (!result.middleOnly) {
|
|
94
|
+
middleOnly = false;
|
|
95
|
+
}
|
|
96
|
+
Object.assign(parameters, result.params);
|
|
97
|
+
return result.fns;
|
|
98
|
+
}
|
|
99
|
+
return function_;
|
|
100
|
+
})
|
|
101
|
+
);
|
|
102
|
+
if (!route.isMiddleware) {
|
|
103
|
+
middleOnly = false;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return { fns, middleOnly, params: parameters };
|
|
108
|
+
}
|
|
109
|
+
use(base, ...fns) {
|
|
110
|
+
if (typeof base === "function" || base instanceof Router) {
|
|
111
|
+
fns.unshift(base);
|
|
112
|
+
base = "/";
|
|
113
|
+
}
|
|
114
|
+
fns = fns.map((function_) => {
|
|
115
|
+
if (function_ instanceof Router) {
|
|
116
|
+
if (typeof base === "string") {
|
|
117
|
+
return function_.clone(base);
|
|
118
|
+
}
|
|
119
|
+
throw new Error("Mounting a router to RegExp base is not supported");
|
|
120
|
+
}
|
|
121
|
+
return function_;
|
|
122
|
+
});
|
|
123
|
+
const { keys, pattern } = parse(base, true);
|
|
124
|
+
this.routes.push({
|
|
125
|
+
fns,
|
|
126
|
+
isMiddleware: true,
|
|
127
|
+
keys,
|
|
128
|
+
method: "",
|
|
129
|
+
pattern
|
|
130
|
+
});
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export { Router };
|
|
@@ -0,0 +1,139 @@
|
|
|
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
|
+
static async exec(fns, ...arguments_) {
|
|
13
|
+
let index = 0;
|
|
14
|
+
const next = () => {
|
|
15
|
+
const function_ = fns[++index];
|
|
16
|
+
if (function_ === void 0) {
|
|
17
|
+
return Promise.resolve();
|
|
18
|
+
}
|
|
19
|
+
return function_(...arguments_, next);
|
|
20
|
+
};
|
|
21
|
+
return fns[index](...arguments_, next);
|
|
22
|
+
}
|
|
23
|
+
add(method, route, ...fns) {
|
|
24
|
+
if (typeof route === "function") {
|
|
25
|
+
fns.unshift(route);
|
|
26
|
+
route = "";
|
|
27
|
+
}
|
|
28
|
+
if (route === "") {
|
|
29
|
+
this.routes.push({
|
|
30
|
+
fns,
|
|
31
|
+
isMiddleware: false,
|
|
32
|
+
matchAll: true,
|
|
33
|
+
method
|
|
34
|
+
});
|
|
35
|
+
} else {
|
|
36
|
+
const { keys, pattern } = regexparam.parse(route);
|
|
37
|
+
this.routes.push({
|
|
38
|
+
fns,
|
|
39
|
+
isMiddleware: false,
|
|
40
|
+
keys,
|
|
41
|
+
method,
|
|
42
|
+
pattern
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
clone(base) {
|
|
48
|
+
return new Router(base, [...this.routes]);
|
|
49
|
+
}
|
|
50
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
51
|
+
find(method, pathname) {
|
|
52
|
+
let middleOnly = true;
|
|
53
|
+
const fns = [];
|
|
54
|
+
const parameters = {};
|
|
55
|
+
const isHead = method === "HEAD";
|
|
56
|
+
for (const route of this.routes) {
|
|
57
|
+
if (route.method !== method && route.method !== "" && !(isHead && route.method === "GET")) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
let matched = false;
|
|
61
|
+
if ("matchAll" in route) {
|
|
62
|
+
matched = true;
|
|
63
|
+
} else if (route.keys === false) {
|
|
64
|
+
const matches = route.pattern.exec(pathname);
|
|
65
|
+
if (matches === null) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (matches.groups !== void 0) {
|
|
69
|
+
Object.keys(matches.groups).forEach((key) => {
|
|
70
|
+
parameters[key] = matches.groups[key];
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
matched = true;
|
|
74
|
+
} else if (route.keys.length > 0) {
|
|
75
|
+
const matches = route.pattern.exec(pathname);
|
|
76
|
+
if (matches === null) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
for (let index = 0; index < route.keys.length; ) {
|
|
80
|
+
const parameterKey = route.keys[index];
|
|
81
|
+
parameters[parameterKey] = matches[++index];
|
|
82
|
+
}
|
|
83
|
+
matched = true;
|
|
84
|
+
} else if (route.pattern.test(pathname)) {
|
|
85
|
+
matched = true;
|
|
86
|
+
}
|
|
87
|
+
if (matched) {
|
|
88
|
+
fns.push(
|
|
89
|
+
...route.fns.flatMap((function_) => {
|
|
90
|
+
if (function_ instanceof Router) {
|
|
91
|
+
const { base } = function_;
|
|
92
|
+
let stripPathname = pathname.slice(base.length);
|
|
93
|
+
if (!stripPathname.startsWith("/")) {
|
|
94
|
+
stripPathname = `/${stripPathname}`;
|
|
95
|
+
}
|
|
96
|
+
const result = function_.find(method, stripPathname);
|
|
97
|
+
if (!result.middleOnly) {
|
|
98
|
+
middleOnly = false;
|
|
99
|
+
}
|
|
100
|
+
Object.assign(parameters, result.params);
|
|
101
|
+
return result.fns;
|
|
102
|
+
}
|
|
103
|
+
return function_;
|
|
104
|
+
})
|
|
105
|
+
);
|
|
106
|
+
if (!route.isMiddleware) {
|
|
107
|
+
middleOnly = false;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return { fns, middleOnly, params: parameters };
|
|
112
|
+
}
|
|
113
|
+
use(base, ...fns) {
|
|
114
|
+
if (typeof base === "function" || base instanceof Router) {
|
|
115
|
+
fns.unshift(base);
|
|
116
|
+
base = "/";
|
|
117
|
+
}
|
|
118
|
+
fns = fns.map((function_) => {
|
|
119
|
+
if (function_ instanceof Router) {
|
|
120
|
+
if (typeof base === "string") {
|
|
121
|
+
return function_.clone(base);
|
|
122
|
+
}
|
|
123
|
+
throw new Error("Mounting a router to RegExp base is not supported");
|
|
124
|
+
}
|
|
125
|
+
return function_;
|
|
126
|
+
});
|
|
127
|
+
const { keys, pattern } = regexparam.parse(base, true);
|
|
128
|
+
this.routes.push({
|
|
129
|
+
fns,
|
|
130
|
+
isMiddleware: true,
|
|
131
|
+
keys,
|
|
132
|
+
method: "",
|
|
133
|
+
pattern
|
|
134
|
+
});
|
|
135
|
+
return this;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
exports.Router = Router;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
|
+
|
|
5
|
+
const withZod = require('./withZod-ULTsdyM5.cjs');
|
|
6
|
+
const Router = require('./Router-Eg_OPxIL.cjs');
|
|
7
|
+
|
|
8
|
+
const onNoMatch = async (request, response) => {
|
|
9
|
+
response.statusCode = 404;
|
|
10
|
+
response.end(request.method === "HEAD" ? void 0 : `Route ${request.method} ${request.url} not found`);
|
|
11
|
+
};
|
|
12
|
+
const onError = async (error, _request, response) => {
|
|
13
|
+
response.statusCode = 500;
|
|
14
|
+
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
|
+
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 NodeRouter({ 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, response) => {
|
|
47
|
+
const result = this.router.find(request.method, getPathname(request.url));
|
|
48
|
+
this.prepareRequest(request, result);
|
|
49
|
+
try {
|
|
50
|
+
await (result.fns.length === 0 || result.middleOnly ? this.onNoMatch(request, response, routes) : Router.Router.exec(result.fns, request, response));
|
|
51
|
+
} catch (error) {
|
|
52
|
+
await this.onError(error, request, response, routes);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
async run(request, response) {
|
|
57
|
+
const result = this.router.find(request.method, getPathname(request.url));
|
|
58
|
+
if (result.fns.length === 0) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
this.prepareRequest(request, result);
|
|
62
|
+
return await Router.Router.exec(result.fns, request, response);
|
|
63
|
+
}
|
|
64
|
+
use(base, ...fns) {
|
|
65
|
+
if (typeof base === "function" || base instanceof NodeRouter) {
|
|
66
|
+
fns.unshift(base);
|
|
67
|
+
base = "/";
|
|
68
|
+
}
|
|
69
|
+
this.router.use(base, ...fns.map((function_) => function_ instanceof NodeRouter ? function_.router : function_));
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
add(method, routeOrFunction, zodOrRouteOrFunction, ...fns) {
|
|
73
|
+
if (typeof routeOrFunction === "string" && typeof zodOrRouteOrFunction === "function") {
|
|
74
|
+
fns = [zodOrRouteOrFunction];
|
|
75
|
+
} else if (typeof zodOrRouteOrFunction === "object") {
|
|
76
|
+
if (typeof routeOrFunction === "function") {
|
|
77
|
+
fns = [withZod(zodOrRouteOrFunction, routeOrFunction)];
|
|
78
|
+
} else {
|
|
79
|
+
fns = fns.map(
|
|
80
|
+
(function_) => withZod(zodOrRouteOrFunction, function_)
|
|
81
|
+
);
|
|
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 createRouter = (options = {}) => new NodeRouter(options);
|
|
99
|
+
|
|
100
|
+
exports.NodeRouter = NodeRouter;
|
|
101
|
+
exports.createRouter = createRouter;
|
|
102
|
+
exports.getPathname = getPathname;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import withZod from './withZod-HYgoC7AX.mjs';
|
|
2
|
+
import { Router } from './Router-ChnTdYfl.mjs';
|
|
3
|
+
|
|
4
|
+
const onNoMatch = async (request, response) => {
|
|
5
|
+
response.statusCode = 404;
|
|
6
|
+
response.end(request.method === "HEAD" ? void 0 : `Route ${request.method} ${request.url} not found`);
|
|
7
|
+
};
|
|
8
|
+
const onError = async (error, _request, response) => {
|
|
9
|
+
response.statusCode = 500;
|
|
10
|
+
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
|
+
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 NodeRouter({ 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, response) => {
|
|
43
|
+
const result = this.router.find(request.method, getPathname(request.url));
|
|
44
|
+
this.prepareRequest(request, result);
|
|
45
|
+
try {
|
|
46
|
+
await (result.fns.length === 0 || result.middleOnly ? this.onNoMatch(request, response, routes) : Router.exec(result.fns, request, response));
|
|
47
|
+
} catch (error) {
|
|
48
|
+
await this.onError(error, request, response, routes);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
async run(request, response) {
|
|
53
|
+
const result = this.router.find(request.method, getPathname(request.url));
|
|
54
|
+
if (result.fns.length === 0) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
this.prepareRequest(request, result);
|
|
58
|
+
return await Router.exec(result.fns, request, response);
|
|
59
|
+
}
|
|
60
|
+
use(base, ...fns) {
|
|
61
|
+
if (typeof base === "function" || base instanceof NodeRouter) {
|
|
62
|
+
fns.unshift(base);
|
|
63
|
+
base = "/";
|
|
64
|
+
}
|
|
65
|
+
this.router.use(base, ...fns.map((function_) => function_ instanceof NodeRouter ? function_.router : function_));
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
add(method, routeOrFunction, zodOrRouteOrFunction, ...fns) {
|
|
69
|
+
if (typeof routeOrFunction === "string" && typeof zodOrRouteOrFunction === "function") {
|
|
70
|
+
fns = [zodOrRouteOrFunction];
|
|
71
|
+
} else if (typeof zodOrRouteOrFunction === "object") {
|
|
72
|
+
if (typeof routeOrFunction === "function") {
|
|
73
|
+
fns = [withZod(zodOrRouteOrFunction, routeOrFunction)];
|
|
74
|
+
} else {
|
|
75
|
+
fns = fns.map(
|
|
76
|
+
(function_) => withZod(zodOrRouteOrFunction, function_)
|
|
77
|
+
);
|
|
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 createRouter = (options = {}) => new NodeRouter(options);
|
|
95
|
+
|
|
96
|
+
export { NodeRouter, createRouter, getPathname };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const expressWrapper = (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
|
+
);
|
|
9
|
+
|
|
10
|
+
module.exports = expressWrapper;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const expressWrapper = (function_) => async (request, response, next) => (
|
|
2
|
+
// eslint-disable-next-line compat/compat
|
|
3
|
+
await new Promise((resolve, reject) => {
|
|
4
|
+
function_(request, response, (error) => error ? reject(error) : resolve());
|
|
5
|
+
}).then(next)
|
|
6
|
+
);
|
|
7
|
+
|
|
8
|
+
export { expressWrapper as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
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, null, 2));
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
module.exports = sendJson;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import createHttpError from 'http-errors';
|
|
2
|
+
import { ZodError } from 'zod';
|
|
3
|
+
|
|
4
|
+
const withZod = (schema, handler) => async (request, response, next) => {
|
|
5
|
+
let transformedRequest = request;
|
|
6
|
+
try {
|
|
7
|
+
transformedRequest = await schema.parseAsync(request);
|
|
8
|
+
} catch (error) {
|
|
9
|
+
let { message } = error;
|
|
10
|
+
if (error instanceof ZodError && typeof error.format === "function") {
|
|
11
|
+
message = error.issues.map((issue) => `${issue.path.join("/")} - ${issue.message}`).join("/n");
|
|
12
|
+
}
|
|
13
|
+
throw createHttpError(422, message);
|
|
14
|
+
}
|
|
15
|
+
return handler(transformedRequest, response, next);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { withZod as default };
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
const withZod = (schema, handler) => async (request, response, next) => {
|
|
11
|
+
let transformedRequest = request;
|
|
12
|
+
try {
|
|
13
|
+
transformedRequest = await schema.parseAsync(request);
|
|
14
|
+
} catch (error) {
|
|
15
|
+
let { message } = error;
|
|
16
|
+
if (error instanceof zod.ZodError && typeof error.format === "function") {
|
|
17
|
+
message = error.issues.map((issue) => `${issue.path.join("/")} - ${issue.message}`).join("/n");
|
|
18
|
+
}
|
|
19
|
+
throw createHttpError__default(422, message);
|
|
20
|
+
}
|
|
21
|
+
return handler(transformedRequest, response, next);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
module.exports = withZod;
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var p=Object.defineProperty;var h=(n,t)=>p(n,"name",{value:t,configurable:!0});import c from"./withZod-wmNwBerD.mjs";import{Router as d}from"./Router-Dg3J0bWq.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};
|
|
@@ -1 +0,0 @@
|
|
|
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;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var g=Object.defineProperty;var p=(c,e)=>g(c,"name",{value:e,configurable:!0});import{parse as d}from"regexparam";var k=Object.defineProperty,m=p((c,e)=>k(c,"name",{value:e,configurable:!0}),"p");class f{static{p(this,"Router")}constructor(e="/",t=[]){this.base=e,this.routes=t}static{m(this,"Router")}static async exec(e,...t){let r=0;const i=m(()=>{const s=e[++r];return s===void 0?Promise.resolve():s(...t,i)},"next");return e[r](...t,i)}add(e,t,...r){if(typeof t=="function"&&(r.unshift(t),t=""),t==="")this.routes.push({fns:r,isMiddleware:!1,matchAll:!0,method:e});else{const{keys:i,pattern:s}=d(t);this.routes.push({fns:r,isMiddleware:!1,keys:i,method:e,pattern:s})}return this}clone(e){return new f(e,[...this.routes])}find(e,t){let r=!0;const i=[],s={},y=e==="HEAD";for(const n of this.routes){if(n.method!==e&&n.method!==""&&!(y&&n.method==="GET"))continue;let l=!1;if("matchAll"in n)l=!0;else if(n.keys===!1){const o=n.pattern.exec(t);if(o===null)continue;o.groups!==void 0&&Object.keys(o.groups).forEach(a=>{s[a]=o.groups[a]}),l=!0}else if(n.keys.length>0){const o=n.pattern.exec(t);if(o===null)continue;for(let a=0;a<n.keys.length;){const u=n.keys[a];s[u]=o[++a]}l=!0}else n.pattern.test(t)&&(l=!0);l&&(i.push(...n.fns.flatMap(o=>{if(o instanceof f){const{base:a}=o;let u=t.slice(a.length);u.startsWith("/")||(u=`/${u}`);const h=o.find(e,u);return h.middleOnly||(r=!1),Object.assign(s,h.params),h.fns}return o})),n.isMiddleware||(r=!1))}return{fns:i,middleOnly:r,params:s}}use(e,...t){(typeof e=="function"||e instanceof f)&&(t.unshift(e),e="/"),t=t.map(s=>{if(s instanceof f){if(typeof e=="string")return s.clone(e);throw new Error("Mounting a router to RegExp base is not supported")}return s});const{keys:r,pattern:i}=d(e,!0);return this.routes.push({fns:t,isMiddleware:!0,keys:r,method:"",pattern:i}),this}}export{f as Router};
|
|
@@ -1 +0,0 @@
|
|
|
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;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var f=Object.defineProperty;var h=(n,t)=>f(n,"name",{value:t,configurable:!0});import c from"./withZod-wmNwBerD.mjs";import{Router as d}from"./Router-Dg3J0bWq.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};
|
|
@@ -1 +0,0 @@
|
|
|
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;
|
|
@@ -1 +0,0 @@
|
|
|
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;
|
|
@@ -1 +0,0 @@
|
|
|
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};
|
|
@@ -1 +0,0 @@
|
|
|
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;
|
|
@@ -1 +0,0 @@
|
|
|
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};
|
|
@@ -1 +0,0 @@
|
|
|
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;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var c=Object.defineProperty;var i=(e,t)=>c(e,"name",{value:t,configurable:!0});import p from"http-errors";import{ZodError as u}from"zod";var y=Object.defineProperty,d=i((e,t)=>y(e,"name",{value:t,configurable:!0}),"d");const j=d((e,t)=>async(o,f,m)=>{let a=o;try{a=await e.parseAsync(o)}catch(r){let{message:n}=r;throw r instanceof u&&typeof r.format=="function"&&(n=r.issues.map(s=>`${s.path.join("/")} - ${s.message}`).join("/n")),p(422,n)}return t(a,f,m)},"withZod");export{j as default};
|