@visulima/connect 4.0.0-alpha.7 → 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.
- package/CHANGELOG.md +15 -0
- package/dist/adapter/express.d.cts +1 -1
- package/dist/adapter/express.d.mts +1 -1
- package/dist/adapter/express.d.ts +1 -1
- package/dist/adapter/with-zod.d.cts +3 -7
- package/dist/adapter/with-zod.d.mts +3 -7
- package/dist/adapter/with-zod.d.ts +3 -7
- package/dist/edge.d.cts +5 -5
- package/dist/edge.d.mts +5 -5
- package/dist/edge.d.ts +5 -5
- package/dist/index.cjs +6 -6
- package/dist/index.mjs +6 -6
- package/dist/node.d.cts +4 -8
- package/dist/node.d.mts +4 -8
- package/dist/node.d.ts +4 -8
- package/dist/packem_shared/{EdgeRouter-B-e2l9un.cjs → EdgeRouter-Dx7Q5duD.cjs} +40 -33
- package/dist/packem_shared/{EdgeRouter-CdtQHTwm.mjs → EdgeRouter-x-Px7BEe.mjs} +40 -33
- package/dist/packem_shared/Router-CT_g_29S.mjs +168 -0
- package/dist/packem_shared/Router-DMp6zIkp.cjs +172 -0
- package/dist/packem_shared/{createRouter-_G1XhaP4.mjs → createRouter-BRGcdDwj.mjs} +40 -32
- package/dist/packem_shared/{createRouter-C8hDVJcV.cjs → createRouter-D-kQjdxT.cjs} +40 -32
- package/dist/packem_shared/expressWrapper-CeTFmeNH.mjs +14 -0
- package/dist/packem_shared/expressWrapper-oEj2tv9s.cjs +16 -0
- package/dist/packem_shared/{sendJson-DwLYLDbt.mjs → sendJson-Cd6CsJC_.mjs} +1 -1
- package/dist/packem_shared/{sendJson-pJY2tT2n.cjs → sendJson-DjC80Qht.cjs} +1 -1
- package/dist/packem_shared/{withZod-HYgoC7AX.mjs → withZod-DMHxmHJB.mjs} +3 -6
- package/dist/packem_shared/withZod-hpoT0ByV.cjs +34 -0
- package/dist/router.d.cts +6 -1
- package/dist/router.d.mts +6 -1
- package/dist/router.d.ts +6 -1
- package/dist/utils/send-json.d.cts +4 -4
- package/dist/utils/send-json.d.mts +4 -4
- package/dist/utils/send-json.d.ts +4 -4
- package/package.json +1 -2
- package/dist/packem_shared/Router-ChnTdYfl.mjs +0 -135
- package/dist/packem_shared/Router-Eg_OPxIL.cjs +0 -139
- package/dist/packem_shared/expressWrapper-CTExfWvM.cjs +0 -10
- package/dist/packem_shared/expressWrapper-spfs58is.mjs +0 -8
- package/dist/packem_shared/withZod-ULTsdyM5.cjs +0 -24
package/dist/router.d.cts
CHANGED
|
@@ -12,7 +12,12 @@ export type Route<H> = {
|
|
|
12
12
|
export declare class Router<H extends FunctionLike> {
|
|
13
13
|
base: string;
|
|
14
14
|
routes: Route<Nextable<H>>[];
|
|
15
|
-
static exec<FL extends FunctionLike>(fns: (Nextable<FL> | undefined)[], ...arguments_: Parameters<FL>): Promise<
|
|
15
|
+
static exec<FL extends FunctionLike>(fns: (Nextable<FL> | undefined)[], ...arguments_: Parameters<FL>): Promise<unknown>;
|
|
16
|
+
private static extractRegExpParams;
|
|
17
|
+
private static extractKeyedParams;
|
|
18
|
+
private static isMethodMatch;
|
|
19
|
+
private static matchRoute;
|
|
20
|
+
private static resolveRouteFns;
|
|
16
21
|
constructor(base?: string, routes?: Route<Nextable<H>>[]);
|
|
17
22
|
add(method: HttpMethod | "", route: Nextable<H> | RouteMatch, ...fns: Nextable<H>[]): this;
|
|
18
23
|
clone(base?: string): Router<H>;
|
package/dist/router.d.mts
CHANGED
|
@@ -12,7 +12,12 @@ export type Route<H> = {
|
|
|
12
12
|
export declare class Router<H extends FunctionLike> {
|
|
13
13
|
base: string;
|
|
14
14
|
routes: Route<Nextable<H>>[];
|
|
15
|
-
static exec<FL extends FunctionLike>(fns: (Nextable<FL> | undefined)[], ...arguments_: Parameters<FL>): Promise<
|
|
15
|
+
static exec<FL extends FunctionLike>(fns: (Nextable<FL> | undefined)[], ...arguments_: Parameters<FL>): Promise<unknown>;
|
|
16
|
+
private static extractRegExpParams;
|
|
17
|
+
private static extractKeyedParams;
|
|
18
|
+
private static isMethodMatch;
|
|
19
|
+
private static matchRoute;
|
|
20
|
+
private static resolveRouteFns;
|
|
16
21
|
constructor(base?: string, routes?: Route<Nextable<H>>[]);
|
|
17
22
|
add(method: HttpMethod | "", route: Nextable<H> | RouteMatch, ...fns: Nextable<H>[]): this;
|
|
18
23
|
clone(base?: string): Router<H>;
|
package/dist/router.d.ts
CHANGED
|
@@ -12,7 +12,12 @@ export type Route<H> = {
|
|
|
12
12
|
export declare class Router<H extends FunctionLike> {
|
|
13
13
|
base: string;
|
|
14
14
|
routes: Route<Nextable<H>>[];
|
|
15
|
-
static exec<FL extends FunctionLike>(fns: (Nextable<FL> | undefined)[], ...arguments_: Parameters<FL>): Promise<
|
|
15
|
+
static exec<FL extends FunctionLike>(fns: (Nextable<FL> | undefined)[], ...arguments_: Parameters<FL>): Promise<unknown>;
|
|
16
|
+
private static extractRegExpParams;
|
|
17
|
+
private static extractKeyedParams;
|
|
18
|
+
private static isMethodMatch;
|
|
19
|
+
private static matchRoute;
|
|
20
|
+
private static resolveRouteFns;
|
|
16
21
|
constructor(base?: string, routes?: Route<Nextable<H>>[]);
|
|
17
22
|
add(method: HttpMethod | "", route: Nextable<H> | RouteMatch, ...fns: Nextable<H>[]): this;
|
|
18
23
|
clone(base?: string): Router<H>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { ServerResponse } from "node:http";
|
|
2
2
|
/**
|
|
3
|
-
* Send `JSON` object
|
|
4
|
-
* @param response
|
|
5
|
-
* @param statusCode
|
|
6
|
-
* @param jsonBody of data
|
|
3
|
+
* Send `JSON` object.
|
|
4
|
+
* @param response Response object.
|
|
5
|
+
* @param statusCode The HTTP status code.
|
|
6
|
+
* @param jsonBody The body of data.
|
|
7
7
|
*/
|
|
8
8
|
declare const sendJson: (response: ServerResponse, statusCode: number, jsonBody: unknown) => void;
|
|
9
9
|
export = sendJson;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { ServerResponse } from "node:http";
|
|
2
2
|
/**
|
|
3
|
-
* Send `JSON` object
|
|
4
|
-
* @param response
|
|
5
|
-
* @param statusCode
|
|
6
|
-
* @param jsonBody of data
|
|
3
|
+
* Send `JSON` object.
|
|
4
|
+
* @param response Response object.
|
|
5
|
+
* @param statusCode The HTTP status code.
|
|
6
|
+
* @param jsonBody The body of data.
|
|
7
7
|
*/
|
|
8
8
|
declare const sendJson: (response: ServerResponse, statusCode: number, jsonBody: unknown) => void;
|
|
9
9
|
export default sendJson;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { ServerResponse } from "node:http";
|
|
2
2
|
/**
|
|
3
|
-
* Send `JSON` object
|
|
4
|
-
* @param response
|
|
5
|
-
* @param statusCode
|
|
6
|
-
* @param jsonBody of data
|
|
3
|
+
* Send `JSON` object.
|
|
4
|
+
* @param response Response object.
|
|
5
|
+
* @param statusCode The HTTP status code.
|
|
6
|
+
* @param jsonBody The body of data.
|
|
7
7
|
*/
|
|
8
8
|
declare const sendJson: (response: ServerResponse, statusCode: number, jsonBody: unknown) => void;
|
|
9
9
|
export = sendJson;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visulima/connect",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.8",
|
|
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
|
"visulima",
|
|
@@ -77,7 +77,6 @@
|
|
|
77
77
|
"peerDependencies": {
|
|
78
78
|
"zod": "4.3.6"
|
|
79
79
|
},
|
|
80
|
-
"optionalDependencies": {},
|
|
81
80
|
"engines": {
|
|
82
81
|
"node": ">=22.13 <=25.x"
|
|
83
82
|
},
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import { parse } from 'regexparam';
|
|
2
|
-
|
|
3
|
-
class Router {
|
|
4
|
-
constructor(base = "/", routes = []) {
|
|
5
|
-
this.base = base;
|
|
6
|
-
this.routes = routes;
|
|
7
|
-
}
|
|
8
|
-
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 };
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
|
-
|
|
5
|
-
const regexparam = require('regexparam');
|
|
6
|
-
|
|
7
|
-
class Router {
|
|
8
|
-
constructor(base = "/", routes = []) {
|
|
9
|
-
this.base = base;
|
|
10
|
-
this.routes = routes;
|
|
11
|
-
}
|
|
12
|
-
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;
|
|
@@ -1,10 +0,0 @@
|
|
|
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;
|
|
@@ -1,8 +0,0 @@
|
|
|
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 };
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const createHttpError = require('http-errors');
|
|
4
|
-
const zod = require('zod');
|
|
5
|
-
|
|
6
|
-
const _interopDefaultCompat = e => e && typeof e === 'object' && 'default' in e ? e.default : e;
|
|
7
|
-
|
|
8
|
-
const createHttpError__default = /*#__PURE__*/_interopDefaultCompat(createHttpError);
|
|
9
|
-
|
|
10
|
-
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;
|