@visulima/connect 3.0.16 → 3.0.17
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 +8 -16
- package/dist/index.d.mts +8 -16
- package/dist/index.d.ts +8 -16
- package/dist/index.mjs +6 -1
- package/dist/packem_shared/EdgeRouter-CFgSlm_Z.mjs +96 -0
- package/dist/packem_shared/EdgeRouter-TBKA2Kga.cjs +102 -0
- package/dist/packem_shared/Router-C6WMSlDY.cjs +146 -0
- package/dist/packem_shared/Router-T36iDyOm.mjs +142 -0
- package/dist/packem_shared/createRouter-L_jA7a27.cjs +107 -0
- package/dist/packem_shared/createRouter-wIi6EqTp.mjs +101 -0
- package/dist/packem_shared/expressWrapper-Cp6GmLZm.cjs +12 -0
- package/dist/packem_shared/expressWrapper-Dfp803bO.mjs +10 -0
- package/dist/packem_shared/sendJson-CIcILWip.mjs +9 -0
- package/dist/packem_shared/sendJson-CvRoSFt-.cjs +11 -0
- package/dist/packem_shared/withZod-DGhSvb93.mjs +20 -0
- package/dist/packem_shared/withZod-DdTDLdDj.cjs +26 -0
- package/package.json +10 -10
- package/dist/packem_shared/EdgeRouter-BkXpG9tj.cjs +0 -1
- package/dist/packem_shared/EdgeRouter-ClPRPmNt.mjs +0 -1
- package/dist/packem_shared/Router-DQo_NccL.mjs +0 -1
- package/dist/packem_shared/Router-DxPKBXlz.cjs +0 -1
- package/dist/packem_shared/createRouter-CFoX3Ket.cjs +0 -1
- package/dist/packem_shared/createRouter-CNJLjtUE.mjs +0 -1
- package/dist/packem_shared/expressWrapper-B9GtFzAx.mjs +0 -1
- package/dist/packem_shared/expressWrapper-CnZ-5oTw.cjs +0 -1
- package/dist/packem_shared/sendJson-CGeHDvjq.mjs +0 -1
- package/dist/packem_shared/sendJson-l4jM19lK.cjs +0 -1
- package/dist/packem_shared/withZod--KKMTPIV.cjs +0 -1
- package/dist/packem_shared/withZod-BzJ68p36.mjs +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
## @visulima/connect [3.0.17](https://github.com/visulima/visulima/compare/@visulima/connect@3.0.16...@visulima/connect@3.0.17) (2025-01-12)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
* updated @visulima/packem, and all other dev dependencies ([7797a1c](https://github.com/visulima/visulima/commit/7797a1c3e6f1fc532895247bd88285a8a9883c40))
|
|
6
|
+
|
|
7
|
+
### Miscellaneous Chores
|
|
8
|
+
|
|
9
|
+
* updated dev dependencies ([9de2eab](https://github.com/visulima/visulima/commit/9de2eab91e95c8b9289d12f863a5167218770650))
|
|
10
|
+
|
|
1
11
|
## @visulima/connect [3.0.16](https://github.com/visulima/visulima/compare/@visulima/connect@3.0.15...@visulima/connect@3.0.16) (2024-12-12)
|
|
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-Cp6GmLZm.cjs');
|
|
6
|
+
const withZod = require('./packem_shared/withZod-DdTDLdDj.cjs');
|
|
7
|
+
const EdgeRouter = require('./packem_shared/EdgeRouter-TBKA2Kga.cjs');
|
|
8
|
+
const createRouter = require('./packem_shared/createRouter-L_jA7a27.cjs');
|
|
9
|
+
const Router = require('./packem_shared/Router-C6WMSlDY.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;
|
package/dist/index.d.cts
CHANGED
|
@@ -82,10 +82,10 @@ declare class NodeRouter<Request extends IncomingMessage = IncomingMessage, Resp
|
|
|
82
82
|
private add;
|
|
83
83
|
private prepareRequest;
|
|
84
84
|
}
|
|
85
|
-
declare const createRouter: <Request extends IncomingMessage, Response extends ServerResponse
|
|
86
|
-
body?: AnyZodObject
|
|
87
|
-
headers?: AnyZodObject
|
|
88
|
-
query?: AnyZodObject
|
|
85
|
+
declare const createRouter: <Request extends IncomingMessage, Response extends ServerResponse, Schema extends AnyZodObject = ZodObject<{
|
|
86
|
+
body?: AnyZodObject;
|
|
87
|
+
headers?: AnyZodObject;
|
|
88
|
+
query?: AnyZodObject;
|
|
89
89
|
}, zod.UnknownKeysParam, zod.ZodTypeAny, {
|
|
90
90
|
body?: unknown;
|
|
91
91
|
headers?: unknown;
|
|
@@ -97,21 +97,13 @@ declare const createRouter: <Request extends IncomingMessage, Response extends S
|
|
|
97
97
|
}>>(options?: HandlerOptions<RoutesExtendedRequestHandler<Request, Response, Response, Route<Nextable<FunctionLike>>[]>>) => NodeRouter<Request, Response, Schema>;
|
|
98
98
|
|
|
99
99
|
type NextFunction = (error?: any) => void;
|
|
100
|
-
declare const expressWrapper: <Request extends IncomingMessage, Response extends ServerResponse
|
|
100
|
+
declare const expressWrapper: <Request extends IncomingMessage, Response extends ServerResponse>(function_: ExpressRequestHandler<Request, Response>) => Nextable<RequestHandler$1<Request, Response>>;
|
|
101
101
|
type ExpressRequestHandler<Request, Response> = (request: Request, response: Response, next: NextFunction) => void;
|
|
102
102
|
|
|
103
103
|
declare const withZod: <Request, Response, Handler extends Nextable<any>, Schema extends ZodObject<{
|
|
104
|
-
body?: AnyZodObject
|
|
105
|
-
headers?: AnyZodObject
|
|
106
|
-
query?: AnyZodObject
|
|
107
|
-
}, zod.UnknownKeysParam, zod.ZodTypeAny, {
|
|
108
|
-
body?: unknown;
|
|
109
|
-
headers?: unknown;
|
|
110
|
-
query?: unknown;
|
|
111
|
-
}, {
|
|
112
|
-
body?: unknown;
|
|
113
|
-
headers?: unknown;
|
|
114
|
-
query?: unknown;
|
|
104
|
+
body?: AnyZodObject;
|
|
105
|
+
headers?: AnyZodObject;
|
|
106
|
+
query?: AnyZodObject;
|
|
115
107
|
}>>(schema: Schema, handler: Handler) => ((request: Request, response: Response, next: NextHandler) => Promise<Response>);
|
|
116
108
|
|
|
117
109
|
type RequestHandler<R extends Request, Context> = (request: R, context_: Context) => ValueOrPromise<Response | void>;
|
package/dist/index.d.mts
CHANGED
|
@@ -82,10 +82,10 @@ declare class NodeRouter<Request extends IncomingMessage = IncomingMessage, Resp
|
|
|
82
82
|
private add;
|
|
83
83
|
private prepareRequest;
|
|
84
84
|
}
|
|
85
|
-
declare const createRouter: <Request extends IncomingMessage, Response extends ServerResponse
|
|
86
|
-
body?: AnyZodObject
|
|
87
|
-
headers?: AnyZodObject
|
|
88
|
-
query?: AnyZodObject
|
|
85
|
+
declare const createRouter: <Request extends IncomingMessage, Response extends ServerResponse, Schema extends AnyZodObject = ZodObject<{
|
|
86
|
+
body?: AnyZodObject;
|
|
87
|
+
headers?: AnyZodObject;
|
|
88
|
+
query?: AnyZodObject;
|
|
89
89
|
}, zod.UnknownKeysParam, zod.ZodTypeAny, {
|
|
90
90
|
body?: unknown;
|
|
91
91
|
headers?: unknown;
|
|
@@ -97,21 +97,13 @@ declare const createRouter: <Request extends IncomingMessage, Response extends S
|
|
|
97
97
|
}>>(options?: HandlerOptions<RoutesExtendedRequestHandler<Request, Response, Response, Route<Nextable<FunctionLike>>[]>>) => NodeRouter<Request, Response, Schema>;
|
|
98
98
|
|
|
99
99
|
type NextFunction = (error?: any) => void;
|
|
100
|
-
declare const expressWrapper: <Request extends IncomingMessage, Response extends ServerResponse
|
|
100
|
+
declare const expressWrapper: <Request extends IncomingMessage, Response extends ServerResponse>(function_: ExpressRequestHandler<Request, Response>) => Nextable<RequestHandler$1<Request, Response>>;
|
|
101
101
|
type ExpressRequestHandler<Request, Response> = (request: Request, response: Response, next: NextFunction) => void;
|
|
102
102
|
|
|
103
103
|
declare const withZod: <Request, Response, Handler extends Nextable<any>, Schema extends ZodObject<{
|
|
104
|
-
body?: AnyZodObject
|
|
105
|
-
headers?: AnyZodObject
|
|
106
|
-
query?: AnyZodObject
|
|
107
|
-
}, zod.UnknownKeysParam, zod.ZodTypeAny, {
|
|
108
|
-
body?: unknown;
|
|
109
|
-
headers?: unknown;
|
|
110
|
-
query?: unknown;
|
|
111
|
-
}, {
|
|
112
|
-
body?: unknown;
|
|
113
|
-
headers?: unknown;
|
|
114
|
-
query?: unknown;
|
|
104
|
+
body?: AnyZodObject;
|
|
105
|
+
headers?: AnyZodObject;
|
|
106
|
+
query?: AnyZodObject;
|
|
115
107
|
}>>(schema: Schema, handler: Handler) => ((request: Request, response: Response, next: NextHandler) => Promise<Response>);
|
|
116
108
|
|
|
117
109
|
type RequestHandler<R extends Request, Context> = (request: R, context_: Context) => ValueOrPromise<Response | void>;
|
package/dist/index.d.ts
CHANGED
|
@@ -82,10 +82,10 @@ declare class NodeRouter<Request extends IncomingMessage = IncomingMessage, Resp
|
|
|
82
82
|
private add;
|
|
83
83
|
private prepareRequest;
|
|
84
84
|
}
|
|
85
|
-
declare const createRouter: <Request extends IncomingMessage, Response extends ServerResponse
|
|
86
|
-
body?: AnyZodObject
|
|
87
|
-
headers?: AnyZodObject
|
|
88
|
-
query?: AnyZodObject
|
|
85
|
+
declare const createRouter: <Request extends IncomingMessage, Response extends ServerResponse, Schema extends AnyZodObject = ZodObject<{
|
|
86
|
+
body?: AnyZodObject;
|
|
87
|
+
headers?: AnyZodObject;
|
|
88
|
+
query?: AnyZodObject;
|
|
89
89
|
}, zod.UnknownKeysParam, zod.ZodTypeAny, {
|
|
90
90
|
body?: unknown;
|
|
91
91
|
headers?: unknown;
|
|
@@ -97,21 +97,13 @@ declare const createRouter: <Request extends IncomingMessage, Response extends S
|
|
|
97
97
|
}>>(options?: HandlerOptions<RoutesExtendedRequestHandler<Request, Response, Response, Route<Nextable<FunctionLike>>[]>>) => NodeRouter<Request, Response, Schema>;
|
|
98
98
|
|
|
99
99
|
type NextFunction = (error?: any) => void;
|
|
100
|
-
declare const expressWrapper: <Request extends IncomingMessage, Response extends ServerResponse
|
|
100
|
+
declare const expressWrapper: <Request extends IncomingMessage, Response extends ServerResponse>(function_: ExpressRequestHandler<Request, Response>) => Nextable<RequestHandler$1<Request, Response>>;
|
|
101
101
|
type ExpressRequestHandler<Request, Response> = (request: Request, response: Response, next: NextFunction) => void;
|
|
102
102
|
|
|
103
103
|
declare const withZod: <Request, Response, Handler extends Nextable<any>, Schema extends ZodObject<{
|
|
104
|
-
body?: AnyZodObject
|
|
105
|
-
headers?: AnyZodObject
|
|
106
|
-
query?: AnyZodObject
|
|
107
|
-
}, zod.UnknownKeysParam, zod.ZodTypeAny, {
|
|
108
|
-
body?: unknown;
|
|
109
|
-
headers?: unknown;
|
|
110
|
-
query?: unknown;
|
|
111
|
-
}, {
|
|
112
|
-
body?: unknown;
|
|
113
|
-
headers?: unknown;
|
|
114
|
-
query?: unknown;
|
|
104
|
+
body?: AnyZodObject;
|
|
105
|
+
headers?: AnyZodObject;
|
|
106
|
+
query?: AnyZodObject;
|
|
115
107
|
}>>(schema: Schema, handler: Handler) => ((request: Request, response: Response, next: NextHandler) => Promise<Response>);
|
|
116
108
|
|
|
117
109
|
type RequestHandler<R extends Request, Context> = (request: R, context_: Context) => ValueOrPromise<Response | void>;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
export { default as expressWrapper } from './packem_shared/expressWrapper-Dfp803bO.mjs';
|
|
2
|
+
export { default as withZod } from './packem_shared/withZod-DGhSvb93.mjs';
|
|
3
|
+
export { EdgeRouter, createEdgeRouter } from './packem_shared/EdgeRouter-CFgSlm_Z.mjs';
|
|
4
|
+
export { NodeRouter, createRouter as createNodeRouter, createRouter } from './packem_shared/createRouter-wIi6EqTp.mjs';
|
|
5
|
+
export { Router } from './packem_shared/Router-T36iDyOm.mjs';
|
|
6
|
+
export { default as sendJson } from './packem_shared/sendJson-CIcILWip.mjs';
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import withZod from './withZod-DGhSvb93.mjs';
|
|
2
|
+
import { Router } from './Router-T36iDyOm.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 };
|
|
@@ -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-DdTDLdDj.cjs');
|
|
6
|
+
const Router = require('./Router-C6WMSlDY.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;
|
|
@@ -0,0 +1,146 @@
|
|
|
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_ === undefined) {
|
|
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 !== undefined) {
|
|
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;
|
|
@@ -0,0 +1,142 @@
|
|
|
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_ === undefined) {
|
|
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 !== undefined) {
|
|
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 };
|
|
@@ -0,0 +1,107 @@
|
|
|
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-C6WMSlDY.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" ? undefined : `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;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import withZod from './withZod-DGhSvb93.mjs';
|
|
2
|
+
import { Router } from './Router-T36iDyOm.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" ? undefined : `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 };
|
|
@@ -0,0 +1,12 @@
|
|
|
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;
|
|
@@ -0,0 +1,10 @@
|
|
|
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 };
|
|
@@ -0,0 +1,9 @@
|
|
|
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 };
|
|
@@ -0,0 +1,11 @@
|
|
|
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;
|
|
@@ -0,0 +1,20 @@
|
|
|
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 };
|
|
@@ -0,0 +1,26 @@
|
|
|
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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visulima/connect",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.17",
|
|
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",
|
|
@@ -76,20 +76,20 @@
|
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@anolilab/eslint-config": "^15.0.3",
|
|
78
78
|
"@anolilab/prettier-config": "^5.0.14",
|
|
79
|
-
"@anolilab/semantic-release-pnpm": "^1.1.
|
|
80
|
-
"@anolilab/semantic-release-preset": "^9.0.
|
|
81
|
-
"@arethetypeswrong/cli": "^0.17.
|
|
79
|
+
"@anolilab/semantic-release-pnpm": "^1.1.6",
|
|
80
|
+
"@anolilab/semantic-release-preset": "^9.0.3",
|
|
81
|
+
"@arethetypeswrong/cli": "^0.17.2",
|
|
82
82
|
"@babel/core": "^7.26.0",
|
|
83
83
|
"@rushstack/eslint-plugin-security": "^0.8.3",
|
|
84
84
|
"@types/http-errors": "^2.0.4",
|
|
85
85
|
"@types/node": "18.19.15",
|
|
86
86
|
"@visulima/nextra-theme-docs": "4.0.26",
|
|
87
|
-
"@visulima/packem": "1.
|
|
87
|
+
"@visulima/packem": "1.10.7",
|
|
88
88
|
"@vitest/coverage-v8": "^2.1.8",
|
|
89
89
|
"@vitest/ui": "^2.1.8",
|
|
90
90
|
"conventional-changelog-conventionalcommits": "8.0.0",
|
|
91
91
|
"cross-env": "^7.0.3",
|
|
92
|
-
"esbuild": "0.24.
|
|
92
|
+
"esbuild": "0.24.2",
|
|
93
93
|
"eslint": "8.57.0",
|
|
94
94
|
"eslint-plugin-deprecation": "^3.0.0",
|
|
95
95
|
"eslint-plugin-etc": "^2.0.3",
|
|
@@ -99,12 +99,12 @@
|
|
|
99
99
|
"eslint-plugin-vitest-globals": "^1.5.0",
|
|
100
100
|
"eslint-plugin-zod": "^1.4.0",
|
|
101
101
|
"express": "^4.21.2",
|
|
102
|
-
"fastify": "^5.1
|
|
102
|
+
"fastify": "^5.2.1",
|
|
103
103
|
"isomorphic-fetch": "^3.0.0",
|
|
104
104
|
"prettier": "^3.4.2",
|
|
105
|
-
"rimraf": "
|
|
106
|
-
"semantic-release": "24.
|
|
107
|
-
"typescript": "5.
|
|
105
|
+
"rimraf": "6.0.1",
|
|
106
|
+
"semantic-release": "24.2.1",
|
|
107
|
+
"typescript": "5.7.3",
|
|
108
108
|
"vitest": "^2.1.8",
|
|
109
109
|
"zod": "^3.24.1"
|
|
110
110
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var p=Object.defineProperty;var h=(o,t)=>p(o,"name",{value:t,configurable:!0});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./withZod--KKMTPIV.cjs"),d=require("./Router-DxPKBXlz.cjs");var f=Object.defineProperty,i=h((o,t)=>f(o,"name",{value:t,configurable:!0}),"r");const l=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??l,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 p=Object.defineProperty;var h=(n,t)=>p(n,"name",{value:t,configurable:!0});import c from"./withZod-BzJ68p36.mjs";import{Router as d}from"./Router-DQo_NccL.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
|
-
var g=Object.defineProperty;var p=(f,e)=>g(f,"name",{value:e,configurable:!0});import{parse as d}from"regexparam";var k=Object.defineProperty,m=p((f,e)=>k(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 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 l(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 u=!1;if("matchAll"in n)u=!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]}),u=!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 c=n.keys[a];s[c]=o[++a]}u=!0}else n.pattern.test(t)&&(u=!0);u&&(i.push(...n.fns.flatMap(o=>{if(o instanceof l){const{base:a}=o;let c=t.slice(a.length);c.startsWith("/")||(c=`/${c}`);const h=o.find(e,c);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 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:r,pattern:i}=d(e,!0);return this.routes.push({fns:t,isMiddleware:!0,keys:r,method:"",pattern:i}),this}}export{l as Router};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var g=Object.defineProperty;var p=(f,e)=>g(f,"name",{value:e,configurable:!0});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("regexparam");var b=Object.defineProperty,y=p((f,e)=>b(f,"name",{value:e,configurable:!0}),"p");class c{static{p(this,"Router")}constructor(e="/",t=[]){this.base=e,this.routes=t}static{y(this,"Router")}static async exec(e,...t){let r=0;const i=y(()=>{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.parse(t);this.routes.push({fns:r,isMiddleware:!1,keys:i,method:e,pattern:s})}return this}clone(e){return new c(e,[...this.routes])}find(e,t){let r=!0;const i=[],s={},m=e==="HEAD";for(const n of this.routes){if(n.method!==e&&n.method!==""&&!(m&&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 c){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 c)&&(t.unshift(e),e="/"),t=t.map(s=>{if(s instanceof c){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.parse(e,!0);return this.routes.push({fns:t,isMiddleware:!0,keys:r,method:"",pattern:i}),this}}exports.Router=c;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var f=Object.defineProperty;var h=(o,t)=>f(o,"name",{value:t,configurable:!0});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./withZod--KKMTPIV.cjs"),d=require("./Router-DxPKBXlz.cjs");var p=Object.defineProperty,s=h((o,t)=>p(o,"name",{value:t,configurable:!0}),"r");const l=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??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(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
|
-
var f=Object.defineProperty;var h=(n,t)=>f(n,"name",{value:t,configurable:!0});import c from"./withZod-BzJ68p36.mjs";import{Router as d}from"./Router-DQo_NccL.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
|
-
var c=Object.defineProperty;var n=(e,a)=>c(e,"name",{value:a,configurable:!0});var i=Object.defineProperty,u=n((e,a)=>i(e,"name",{value:a,configurable:!0}),"n");const l=u(e=>async(a,s,t)=>await new Promise((o,p)=>{e(a,s,r=>r?p(r):o())}).then(t),"expressWrapper");export{l as default};
|
|
@@ -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 s=Object.defineProperty;var n=(e,t)=>s(e,"name",{value:t,configurable:!0});var r=Object.defineProperty,o=n((e,t)=>r(e,"name",{value:t,configurable:!0}),"n");const d=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{d 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
|
-
"use strict";var u=Object.defineProperty;var a=(t,e)=>u(t,"name",{value:e,configurable:!0});const p=require("http-errors"),d=require("zod"),l=a(t=>t&&typeof t=="object"&&"default"in t?t.default:t,"_interopDefaultCompat"),y=l(p);var m=Object.defineProperty,h=a((t,e)=>m(t,"name",{value:e,configurable:!0}),"d");const j=h((t,e)=>async(n,i,f)=>{let r=n;try{r=await t.parseAsync(n)}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(r,i,f)},"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(r,f,m)=>{let a=r;try{a=await e.parseAsync(r)}catch(o){let{message:n}=o;throw o instanceof u&&typeof o.format=="function"&&(n=o.issues.map(s=>`${s.path.join("/")} - ${s.message}`).join("/n")),p(422,n)}return t(a,f,m)},"withZod");export{j as default};
|