@visulima/connect 4.0.0-alpha.6 → 4.0.0-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/adapter/express.d.cts +1 -1
  3. package/dist/adapter/express.d.mts +1 -1
  4. package/dist/adapter/express.d.ts +1 -1
  5. package/dist/adapter/with-zod.d.cts +3 -7
  6. package/dist/adapter/with-zod.d.mts +3 -7
  7. package/dist/adapter/with-zod.d.ts +3 -7
  8. package/dist/edge.d.cts +5 -5
  9. package/dist/edge.d.mts +5 -5
  10. package/dist/edge.d.ts +5 -5
  11. package/dist/index.cjs +6 -6
  12. package/dist/index.mjs +6 -6
  13. package/dist/node.d.cts +4 -8
  14. package/dist/node.d.mts +4 -8
  15. package/dist/node.d.ts +4 -8
  16. package/dist/packem_shared/{EdgeRouter-B-e2l9un.cjs → EdgeRouter-Dx7Q5duD.cjs} +40 -33
  17. package/dist/packem_shared/{EdgeRouter-CdtQHTwm.mjs → EdgeRouter-x-Px7BEe.mjs} +40 -33
  18. package/dist/packem_shared/Router-CT_g_29S.mjs +168 -0
  19. package/dist/packem_shared/Router-DMp6zIkp.cjs +172 -0
  20. package/dist/packem_shared/{createRouter-_G1XhaP4.mjs → createRouter-BRGcdDwj.mjs} +40 -32
  21. package/dist/packem_shared/{createRouter-C8hDVJcV.cjs → createRouter-D-kQjdxT.cjs} +40 -32
  22. package/dist/packem_shared/expressWrapper-CeTFmeNH.mjs +14 -0
  23. package/dist/packem_shared/expressWrapper-oEj2tv9s.cjs +16 -0
  24. package/dist/packem_shared/{sendJson-DwLYLDbt.mjs → sendJson-Cd6CsJC_.mjs} +1 -1
  25. package/dist/packem_shared/{sendJson-pJY2tT2n.cjs → sendJson-DjC80Qht.cjs} +1 -1
  26. package/dist/packem_shared/{withZod-HYgoC7AX.mjs → withZod-DMHxmHJB.mjs} +3 -6
  27. package/dist/packem_shared/withZod-hpoT0ByV.cjs +34 -0
  28. package/dist/router.d.cts +6 -1
  29. package/dist/router.d.mts +6 -1
  30. package/dist/router.d.ts +6 -1
  31. package/dist/utils/send-json.d.cts +4 -4
  32. package/dist/utils/send-json.d.mts +4 -4
  33. package/dist/utils/send-json.d.ts +4 -4
  34. package/package.json +2 -3
  35. package/dist/packem_shared/Router-ChnTdYfl.mjs +0 -135
  36. package/dist/packem_shared/Router-Eg_OPxIL.cjs +0 -139
  37. package/dist/packem_shared/expressWrapper-CTExfWvM.cjs +0 -10
  38. package/dist/packem_shared/expressWrapper-spfs58is.mjs +0 -8
  39. package/dist/packem_shared/withZod-ULTsdyM5.cjs +0 -24
@@ -0,0 +1,168 @@
1
+ import { parse } from 'regexparam';
2
+
3
+ class Router {
4
+ constructor(base = "/", routes = []) {
5
+ this.base = base;
6
+ this.routes = routes;
7
+ }
8
+ base;
9
+ routes;
10
+ static exec(fns, ...arguments_) {
11
+ let index = 0;
12
+ const next = () => {
13
+ index += 1;
14
+ const currentFunction = fns[index];
15
+ if (currentFunction === void 0) {
16
+ return Promise.resolve();
17
+ }
18
+ return currentFunction(...arguments_, next);
19
+ };
20
+ return fns[index](...arguments_, next);
21
+ }
22
+ static extractRegExpParams(matches) {
23
+ const result = {};
24
+ if (matches.groups === void 0) {
25
+ return result;
26
+ }
27
+ for (const key of Object.keys(matches.groups)) {
28
+ result[key] = matches.groups[key];
29
+ }
30
+ return result;
31
+ }
32
+ static extractKeyedParams(matches, keys) {
33
+ const result = {};
34
+ for (const [index, parameterKey] of keys.entries()) {
35
+ result[parameterKey] = matches[index + 1];
36
+ }
37
+ return result;
38
+ }
39
+ static isMethodMatch(routeMethod, method, isHead) {
40
+ return routeMethod === method || routeMethod === "" || isHead && routeMethod === "GET";
41
+ }
42
+ static matchRoute(route, pathname) {
43
+ if ("matchAll" in route) {
44
+ return { matched: true, params: {} };
45
+ }
46
+ if (route.keys === false) {
47
+ const matches = route.pattern.exec(pathname);
48
+ if (matches === null) {
49
+ return { matched: false };
50
+ }
51
+ return { matched: true, params: Router.extractRegExpParams(matches) };
52
+ }
53
+ if (route.keys.length > 0) {
54
+ const matches = route.pattern.exec(pathname);
55
+ if (matches === null) {
56
+ return { matched: false };
57
+ }
58
+ return { matched: true, params: Router.extractKeyedParams(matches, route.keys) };
59
+ }
60
+ if (route.pattern.test(pathname)) {
61
+ return { matched: true, params: {} };
62
+ }
63
+ return { matched: false };
64
+ }
65
+ static resolveRouteFns(routeFns, method, pathname, onSubResult) {
66
+ return routeFns.flatMap((function_) => {
67
+ if (function_ instanceof Router) {
68
+ const { base } = function_;
69
+ let stripPathname = pathname.slice(base.length);
70
+ if (!stripPathname.startsWith("/")) {
71
+ stripPathname = `/${stripPathname}`;
72
+ }
73
+ const result = function_.find(method, stripPathname);
74
+ onSubResult(result.params, result.middleOnly);
75
+ return result.fns;
76
+ }
77
+ return [function_];
78
+ });
79
+ }
80
+ add(method, route, ...fns) {
81
+ let resolvedRoute;
82
+ if (typeof route === "function") {
83
+ fns.unshift(route);
84
+ resolvedRoute = "";
85
+ } else {
86
+ resolvedRoute = route;
87
+ }
88
+ if (resolvedRoute === "") {
89
+ this.routes.push({
90
+ fns,
91
+ isMiddleware: false,
92
+ matchAll: true,
93
+ method
94
+ });
95
+ } else {
96
+ const { keys, pattern } = parse(resolvedRoute);
97
+ this.routes.push({
98
+ fns,
99
+ isMiddleware: false,
100
+ keys,
101
+ method,
102
+ pattern
103
+ });
104
+ }
105
+ return this;
106
+ }
107
+ clone(base) {
108
+ return new Router(base, [...this.routes]);
109
+ }
110
+ find(method, pathname) {
111
+ let middleOnly = true;
112
+ const fns = [];
113
+ const parameters = {};
114
+ const isHead = method === "HEAD";
115
+ for (let routeIndex = 0; routeIndex < this.routes.length; routeIndex += 1) {
116
+ const route = this.routes[routeIndex];
117
+ if (!Router.isMethodMatch(route.method, method, isHead)) {
118
+ continue;
119
+ }
120
+ const matchResult = Router.matchRoute(route, pathname);
121
+ if (!matchResult.matched) {
122
+ continue;
123
+ }
124
+ Object.assign(parameters, matchResult.params);
125
+ fns.push(
126
+ ...Router.resolveRouteFns(route.fns, method, pathname, (subParams, subMiddleOnly) => {
127
+ Object.assign(parameters, subParams);
128
+ if (!subMiddleOnly) {
129
+ middleOnly = false;
130
+ }
131
+ })
132
+ );
133
+ if (!route.isMiddleware) {
134
+ middleOnly = false;
135
+ }
136
+ }
137
+ return { fns, middleOnly, params: parameters };
138
+ }
139
+ use(base, ...fns) {
140
+ let resolvedBase;
141
+ if (typeof base === "function" || base instanceof Router) {
142
+ fns.unshift(base);
143
+ resolvedBase = "/";
144
+ } else {
145
+ resolvedBase = base;
146
+ }
147
+ const resolvedFns = fns.map((function_) => {
148
+ if (function_ instanceof Router) {
149
+ if (typeof resolvedBase === "string") {
150
+ return function_.clone(resolvedBase);
151
+ }
152
+ throw new Error("Mounting a router to RegExp base is not supported");
153
+ }
154
+ return function_;
155
+ });
156
+ const { keys, pattern } = parse(resolvedBase, true);
157
+ this.routes.push({
158
+ fns: resolvedFns,
159
+ isMiddleware: true,
160
+ keys,
161
+ method: "",
162
+ pattern
163
+ });
164
+ return this;
165
+ }
166
+ }
167
+
168
+ export { Router };
@@ -0,0 +1,172 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
+
5
+ const regexparam = require('regexparam');
6
+
7
+ class Router {
8
+ constructor(base = "/", routes = []) {
9
+ this.base = base;
10
+ this.routes = routes;
11
+ }
12
+ base;
13
+ routes;
14
+ static exec(fns, ...arguments_) {
15
+ let index = 0;
16
+ const next = () => {
17
+ index += 1;
18
+ const currentFunction = fns[index];
19
+ if (currentFunction === void 0) {
20
+ return Promise.resolve();
21
+ }
22
+ return currentFunction(...arguments_, next);
23
+ };
24
+ return fns[index](...arguments_, next);
25
+ }
26
+ static extractRegExpParams(matches) {
27
+ const result = {};
28
+ if (matches.groups === void 0) {
29
+ return result;
30
+ }
31
+ for (const key of Object.keys(matches.groups)) {
32
+ result[key] = matches.groups[key];
33
+ }
34
+ return result;
35
+ }
36
+ static extractKeyedParams(matches, keys) {
37
+ const result = {};
38
+ for (const [index, parameterKey] of keys.entries()) {
39
+ result[parameterKey] = matches[index + 1];
40
+ }
41
+ return result;
42
+ }
43
+ static isMethodMatch(routeMethod, method, isHead) {
44
+ return routeMethod === method || routeMethod === "" || isHead && routeMethod === "GET";
45
+ }
46
+ static matchRoute(route, pathname) {
47
+ if ("matchAll" in route) {
48
+ return { matched: true, params: {} };
49
+ }
50
+ if (route.keys === false) {
51
+ const matches = route.pattern.exec(pathname);
52
+ if (matches === null) {
53
+ return { matched: false };
54
+ }
55
+ return { matched: true, params: Router.extractRegExpParams(matches) };
56
+ }
57
+ if (route.keys.length > 0) {
58
+ const matches = route.pattern.exec(pathname);
59
+ if (matches === null) {
60
+ return { matched: false };
61
+ }
62
+ return { matched: true, params: Router.extractKeyedParams(matches, route.keys) };
63
+ }
64
+ if (route.pattern.test(pathname)) {
65
+ return { matched: true, params: {} };
66
+ }
67
+ return { matched: false };
68
+ }
69
+ static resolveRouteFns(routeFns, method, pathname, onSubResult) {
70
+ return routeFns.flatMap((function_) => {
71
+ if (function_ instanceof Router) {
72
+ const { base } = function_;
73
+ let stripPathname = pathname.slice(base.length);
74
+ if (!stripPathname.startsWith("/")) {
75
+ stripPathname = `/${stripPathname}`;
76
+ }
77
+ const result = function_.find(method, stripPathname);
78
+ onSubResult(result.params, result.middleOnly);
79
+ return result.fns;
80
+ }
81
+ return [function_];
82
+ });
83
+ }
84
+ add(method, route, ...fns) {
85
+ let resolvedRoute;
86
+ if (typeof route === "function") {
87
+ fns.unshift(route);
88
+ resolvedRoute = "";
89
+ } else {
90
+ resolvedRoute = route;
91
+ }
92
+ if (resolvedRoute === "") {
93
+ this.routes.push({
94
+ fns,
95
+ isMiddleware: false,
96
+ matchAll: true,
97
+ method
98
+ });
99
+ } else {
100
+ const { keys, pattern } = regexparam.parse(resolvedRoute);
101
+ this.routes.push({
102
+ fns,
103
+ isMiddleware: false,
104
+ keys,
105
+ method,
106
+ pattern
107
+ });
108
+ }
109
+ return this;
110
+ }
111
+ clone(base) {
112
+ return new Router(base, [...this.routes]);
113
+ }
114
+ find(method, pathname) {
115
+ let middleOnly = true;
116
+ const fns = [];
117
+ const parameters = {};
118
+ const isHead = method === "HEAD";
119
+ for (let routeIndex = 0; routeIndex < this.routes.length; routeIndex += 1) {
120
+ const route = this.routes[routeIndex];
121
+ if (!Router.isMethodMatch(route.method, method, isHead)) {
122
+ continue;
123
+ }
124
+ const matchResult = Router.matchRoute(route, pathname);
125
+ if (!matchResult.matched) {
126
+ continue;
127
+ }
128
+ Object.assign(parameters, matchResult.params);
129
+ fns.push(
130
+ ...Router.resolveRouteFns(route.fns, method, pathname, (subParams, subMiddleOnly) => {
131
+ Object.assign(parameters, subParams);
132
+ if (!subMiddleOnly) {
133
+ middleOnly = false;
134
+ }
135
+ })
136
+ );
137
+ if (!route.isMiddleware) {
138
+ middleOnly = false;
139
+ }
140
+ }
141
+ return { fns, middleOnly, params: parameters };
142
+ }
143
+ use(base, ...fns) {
144
+ let resolvedBase;
145
+ if (typeof base === "function" || base instanceof Router) {
146
+ fns.unshift(base);
147
+ resolvedBase = "/";
148
+ } else {
149
+ resolvedBase = base;
150
+ }
151
+ const resolvedFns = fns.map((function_) => {
152
+ if (function_ instanceof Router) {
153
+ if (typeof resolvedBase === "string") {
154
+ return function_.clone(resolvedBase);
155
+ }
156
+ throw new Error("Mounting a router to RegExp base is not supported");
157
+ }
158
+ return function_;
159
+ });
160
+ const { keys, pattern } = regexparam.parse(resolvedBase, true);
161
+ this.routes.push({
162
+ fns: resolvedFns,
163
+ isMiddleware: true,
164
+ keys,
165
+ method: "",
166
+ pattern
167
+ });
168
+ return this;
169
+ }
170
+ }
171
+
172
+ exports.Router = Router;
@@ -1,13 +1,13 @@
1
- import withZod from './withZod-HYgoC7AX.mjs';
2
- import { Router } from './Router-ChnTdYfl.mjs';
1
+ import withZod from './withZod-DMHxmHJB.mjs';
2
+ import { Router } from './Router-CT_g_29S.mjs';
3
3
 
4
- const onNoMatch = async (request, response) => {
4
+ const onNoMatch = (request, response) => {
5
5
  response.statusCode = 404;
6
- response.end(request.method === "HEAD" ? void 0 : `Route ${request.method} ${request.url} not found`);
6
+ response.end(request.method === "HEAD" ? void 0 : `Route ${String(request.method)} ${String(request.url)} not found`);
7
7
  };
8
- const onError = async (error, _request, response) => {
8
+ const onError = (error, _request, response) => {
9
9
  response.statusCode = 500;
10
- console.error(error);
10
+ globalThis.console.error(error);
11
11
  response.end("Internal Server Error");
12
12
  };
13
13
  const getPathname = (url) => {
@@ -15,6 +15,13 @@ const getPathname = (url) => {
15
15
  return queryIndex === -1 ? url : url.slice(0, Math.max(0, queryIndex));
16
16
  };
17
17
  class NodeRouter {
18
+ static prepareRequest(request, findResult) {
19
+ request.params = {
20
+ ...findResult.params,
21
+ ...request.params
22
+ // original params will take precedence
23
+ };
24
+ }
18
25
  all = this.add.bind(this, "");
19
26
  connect = this.add.bind(this, "CONNECT");
20
27
  delete = this.add.bind(this, "DELETE");
@@ -40,8 +47,10 @@ class NodeRouter {
40
47
  handler() {
41
48
  const { routes } = this.router;
42
49
  return async (request, response) => {
43
- const result = this.router.find(request.method, getPathname(request.url));
44
- this.prepareRequest(request, result);
50
+ const pathname = getPathname(request.url);
51
+ const method = request.method;
52
+ const result = this.router.find(method, pathname);
53
+ NodeRouter.prepareRequest(request, result);
45
54
  try {
46
55
  await (result.fns.length === 0 || result.middleOnly ? this.onNoMatch(request, response, routes) : Router.exec(result.fns, request, response));
47
56
  } catch (error) {
@@ -50,46 +59,45 @@ class NodeRouter {
50
59
  };
51
60
  }
52
61
  async run(request, response) {
53
- const result = this.router.find(request.method, getPathname(request.url));
62
+ const pathname = getPathname(request.url);
63
+ const method = request.method;
64
+ const result = this.router.find(method, pathname);
54
65
  if (result.fns.length === 0) {
55
- return;
66
+ return void 0;
56
67
  }
57
- this.prepareRequest(request, result);
58
- return await Router.exec(result.fns, request, response);
68
+ NodeRouter.prepareRequest(request, result);
69
+ return Router.exec(result.fns, request, response);
59
70
  }
60
71
  use(base, ...fns) {
72
+ let resolvedBase;
61
73
  if (typeof base === "function" || base instanceof NodeRouter) {
62
74
  fns.unshift(base);
63
- base = "/";
75
+ resolvedBase = "/";
76
+ } else {
77
+ resolvedBase = base;
64
78
  }
65
- this.router.use(base, ...fns.map((function_) => function_ instanceof NodeRouter ? function_.router : function_));
79
+ this.router.use(resolvedBase, ...fns.map((function_) => {
80
+ if (function_ instanceof NodeRouter) {
81
+ return function_.router;
82
+ }
83
+ return function_;
84
+ }));
66
85
  return this;
67
86
  }
68
87
  add(method, routeOrFunction, zodOrRouteOrFunction, ...fns) {
88
+ let resolvedFns;
69
89
  if (typeof routeOrFunction === "string" && typeof zodOrRouteOrFunction === "function") {
70
- fns = [zodOrRouteOrFunction];
90
+ resolvedFns = [zodOrRouteOrFunction];
71
91
  } 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
- }
92
+ resolvedFns = typeof routeOrFunction === "function" ? [withZod(zodOrRouteOrFunction, routeOrFunction)] : fns.map((function_) => withZod(zodOrRouteOrFunction, function_));
79
93
  } else if (typeof zodOrRouteOrFunction === "function") {
80
- fns = [zodOrRouteOrFunction];
94
+ resolvedFns = [zodOrRouteOrFunction];
95
+ } else {
96
+ resolvedFns = fns;
81
97
  }
82
- this.router.add(method, routeOrFunction, ...fns);
98
+ this.router.add(method, routeOrFunction, ...resolvedFns);
83
99
  return this;
84
100
  }
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
101
  }
94
102
  const createRouter = (options = {}) => new NodeRouter(options);
95
103
 
@@ -2,16 +2,16 @@
2
2
 
3
3
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
4
 
5
- const withZod = require('./withZod-ULTsdyM5.cjs');
6
- const Router = require('./Router-Eg_OPxIL.cjs');
5
+ const withZod = require('./withZod-hpoT0ByV.cjs');
6
+ const Router = require('./Router-DMp6zIkp.cjs');
7
7
 
8
- const onNoMatch = async (request, response) => {
8
+ const onNoMatch = (request, response) => {
9
9
  response.statusCode = 404;
10
- response.end(request.method === "HEAD" ? void 0 : `Route ${request.method} ${request.url} not found`);
10
+ response.end(request.method === "HEAD" ? void 0 : `Route ${String(request.method)} ${String(request.url)} not found`);
11
11
  };
12
- const onError = async (error, _request, response) => {
12
+ const onError = (error, _request, response) => {
13
13
  response.statusCode = 500;
14
- console.error(error);
14
+ globalThis.console.error(error);
15
15
  response.end("Internal Server Error");
16
16
  };
17
17
  const getPathname = (url) => {
@@ -19,6 +19,13 @@ const getPathname = (url) => {
19
19
  return queryIndex === -1 ? url : url.slice(0, Math.max(0, queryIndex));
20
20
  };
21
21
  class NodeRouter {
22
+ static prepareRequest(request, findResult) {
23
+ request.params = {
24
+ ...findResult.params,
25
+ ...request.params
26
+ // original params will take precedence
27
+ };
28
+ }
22
29
  all = this.add.bind(this, "");
23
30
  connect = this.add.bind(this, "CONNECT");
24
31
  delete = this.add.bind(this, "DELETE");
@@ -44,8 +51,10 @@ class NodeRouter {
44
51
  handler() {
45
52
  const { routes } = this.router;
46
53
  return async (request, response) => {
47
- const result = this.router.find(request.method, getPathname(request.url));
48
- this.prepareRequest(request, result);
54
+ const pathname = getPathname(request.url);
55
+ const method = request.method;
56
+ const result = this.router.find(method, pathname);
57
+ NodeRouter.prepareRequest(request, result);
49
58
  try {
50
59
  await (result.fns.length === 0 || result.middleOnly ? this.onNoMatch(request, response, routes) : Router.Router.exec(result.fns, request, response));
51
60
  } catch (error) {
@@ -54,46 +63,45 @@ class NodeRouter {
54
63
  };
55
64
  }
56
65
  async run(request, response) {
57
- const result = this.router.find(request.method, getPathname(request.url));
66
+ const pathname = getPathname(request.url);
67
+ const method = request.method;
68
+ const result = this.router.find(method, pathname);
58
69
  if (result.fns.length === 0) {
59
- return;
70
+ return void 0;
60
71
  }
61
- this.prepareRequest(request, result);
62
- return await Router.Router.exec(result.fns, request, response);
72
+ NodeRouter.prepareRequest(request, result);
73
+ return Router.Router.exec(result.fns, request, response);
63
74
  }
64
75
  use(base, ...fns) {
76
+ let resolvedBase;
65
77
  if (typeof base === "function" || base instanceof NodeRouter) {
66
78
  fns.unshift(base);
67
- base = "/";
79
+ resolvedBase = "/";
80
+ } else {
81
+ resolvedBase = base;
68
82
  }
69
- this.router.use(base, ...fns.map((function_) => function_ instanceof NodeRouter ? function_.router : function_));
83
+ this.router.use(resolvedBase, ...fns.map((function_) => {
84
+ if (function_ instanceof NodeRouter) {
85
+ return function_.router;
86
+ }
87
+ return function_;
88
+ }));
70
89
  return this;
71
90
  }
72
91
  add(method, routeOrFunction, zodOrRouteOrFunction, ...fns) {
92
+ let resolvedFns;
73
93
  if (typeof routeOrFunction === "string" && typeof zodOrRouteOrFunction === "function") {
74
- fns = [zodOrRouteOrFunction];
94
+ resolvedFns = [zodOrRouteOrFunction];
75
95
  } 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
- }
96
+ resolvedFns = typeof routeOrFunction === "function" ? [withZod(zodOrRouteOrFunction, routeOrFunction)] : fns.map((function_) => withZod(zodOrRouteOrFunction, function_));
83
97
  } else if (typeof zodOrRouteOrFunction === "function") {
84
- fns = [zodOrRouteOrFunction];
98
+ resolvedFns = [zodOrRouteOrFunction];
99
+ } else {
100
+ resolvedFns = fns;
85
101
  }
86
- this.router.add(method, routeOrFunction, ...fns);
102
+ this.router.add(method, routeOrFunction, ...resolvedFns);
87
103
  return this;
88
104
  }
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
105
  }
98
106
  const createRouter = (options = {}) => new NodeRouter(options);
99
107
 
@@ -0,0 +1,14 @@
1
+ const expressWrapper = (function_) => async (request, response, next) => {
2
+ await new Promise((resolve, reject) => {
3
+ function_(request, response, (error) => {
4
+ if (error) {
5
+ reject(error);
6
+ } else {
7
+ resolve();
8
+ }
9
+ });
10
+ });
11
+ return next();
12
+ };
13
+
14
+ export { expressWrapper as default };
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ const expressWrapper = (function_) => async (request, response, next) => {
4
+ await new Promise((resolve, reject) => {
5
+ function_(request, response, (error) => {
6
+ if (error) {
7
+ reject(error);
8
+ } else {
9
+ resolve();
10
+ }
11
+ });
12
+ });
13
+ return next();
14
+ };
15
+
16
+ module.exports = expressWrapper;
@@ -1,7 +1,7 @@
1
1
  const sendJson = (response, statusCode, jsonBody) => {
2
2
  response.setHeader("content-type", "application/json; charset=utf-8");
3
3
  response.statusCode = statusCode;
4
- response.end(JSON.stringify(jsonBody, null, 2));
4
+ response.end(JSON.stringify(jsonBody, void 0, 2));
5
5
  };
6
6
 
7
7
  export { sendJson as default };
@@ -3,7 +3,7 @@
3
3
  const sendJson = (response, statusCode, jsonBody) => {
4
4
  response.setHeader("content-type", "application/json; charset=utf-8");
5
5
  response.statusCode = statusCode;
6
- response.end(JSON.stringify(jsonBody, null, 2));
6
+ response.end(JSON.stringify(jsonBody, void 0, 2));
7
7
  };
8
8
 
9
9
  module.exports = sendJson;
@@ -1,15 +1,12 @@
1
1
  import createHttpError from 'http-errors';
2
- import { ZodError } from 'zod';
2
+ import * as z from 'zod';
3
3
 
4
4
  const withZod = (schema, handler) => async (request, response, next) => {
5
- let transformedRequest = request;
5
+ let transformedRequest;
6
6
  try {
7
7
  transformedRequest = await schema.parseAsync(request);
8
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
- }
9
+ const message = error instanceof z.ZodError && typeof error.format === "function" ? error.issues.map((issue) => `${issue.path.join("/")} - ${issue.message}`).join("/n") : error.message;
13
10
  throw createHttpError(422, message);
14
11
  }
15
12
  return handler(transformedRequest, response, next);
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+
3
+ const createHttpError = require('http-errors');
4
+ const z = require('zod');
5
+
6
+ const _interopDefaultCompat = e => e && typeof e === 'object' && 'default' in e ? e.default : e;
7
+
8
+ function _interopNamespaceCompat(e) {
9
+ if (e && typeof e === 'object' && 'default' in e) return e;
10
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
11
+ if (e) {
12
+ for (const k in e) {
13
+ n[k] = e[k];
14
+ }
15
+ }
16
+ n.default = e;
17
+ return n;
18
+ }
19
+
20
+ const createHttpError__default = /*#__PURE__*/_interopDefaultCompat(createHttpError);
21
+ const z__namespace = /*#__PURE__*/_interopNamespaceCompat(z);
22
+
23
+ const withZod = (schema, handler) => async (request, response, next) => {
24
+ let transformedRequest;
25
+ try {
26
+ transformedRequest = await schema.parseAsync(request);
27
+ } catch (error) {
28
+ const message = error instanceof z__namespace.ZodError && typeof error.format === "function" ? error.issues.map((issue) => `${issue.path.join("/")} - ${issue.message}`).join("/n") : error.message;
29
+ throw createHttpError__default(422, message);
30
+ }
31
+ return handler(transformedRequest, response, next);
32
+ };
33
+
34
+ module.exports = withZod;