@visulima/connect 1.0.0
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 +7 -0
- package/LICENSE +21 -0
- package/README.md +607 -0
- package/dist/index.d.ts +141 -0
- package/dist/index.js +335 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +335 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +126 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
// src/adapter/with-zod.ts
|
|
2
|
+
import createHttpError from "http-errors";
|
|
3
|
+
import { ZodError } from "zod";
|
|
4
|
+
var withZod = (schema, handler) => async (request, response, next) => {
|
|
5
|
+
let transformedRequest = request;
|
|
6
|
+
try {
|
|
7
|
+
transformedRequest = await schema.parseAsync(request);
|
|
8
|
+
} catch (error) {
|
|
9
|
+
let { message } = error;
|
|
10
|
+
if (error instanceof ZodError && typeof error.format === "function") {
|
|
11
|
+
message = error.issues.map((issue) => `${issue.path.join("/")} - ${issue.message}`).join("/n");
|
|
12
|
+
}
|
|
13
|
+
throw createHttpError(422, message);
|
|
14
|
+
}
|
|
15
|
+
return handler(transformedRequest, response, next);
|
|
16
|
+
};
|
|
17
|
+
var with_zod_default = withZod;
|
|
18
|
+
|
|
19
|
+
// src/router.ts
|
|
20
|
+
import { parse } from "regexparam";
|
|
21
|
+
var Router = class {
|
|
22
|
+
constructor(base = "/", routes = []) {
|
|
23
|
+
this.base = base;
|
|
24
|
+
this.routes = routes;
|
|
25
|
+
}
|
|
26
|
+
add(method, route, ...fns) {
|
|
27
|
+
if (typeof route === "function") {
|
|
28
|
+
fns.unshift(route);
|
|
29
|
+
route = "";
|
|
30
|
+
}
|
|
31
|
+
if (route === "") {
|
|
32
|
+
this.routes.push({
|
|
33
|
+
matchAll: true,
|
|
34
|
+
method,
|
|
35
|
+
fns,
|
|
36
|
+
isMiddleware: false
|
|
37
|
+
});
|
|
38
|
+
} else {
|
|
39
|
+
const { keys, pattern } = parse(route);
|
|
40
|
+
this.routes.push({
|
|
41
|
+
keys,
|
|
42
|
+
pattern,
|
|
43
|
+
method,
|
|
44
|
+
fns,
|
|
45
|
+
isMiddleware: false
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
use(base, ...fns) {
|
|
51
|
+
if (typeof base === "function" || base instanceof Router) {
|
|
52
|
+
fns.unshift(base);
|
|
53
|
+
base = "/";
|
|
54
|
+
}
|
|
55
|
+
fns = fns.map((function_) => {
|
|
56
|
+
if (function_ instanceof Router) {
|
|
57
|
+
if (typeof base === "string")
|
|
58
|
+
return function_.clone(base);
|
|
59
|
+
throw new Error("Mounting a router to RegExp base is not supported");
|
|
60
|
+
}
|
|
61
|
+
return function_;
|
|
62
|
+
});
|
|
63
|
+
const { keys, pattern } = parse(base, true);
|
|
64
|
+
this.routes.push({
|
|
65
|
+
keys,
|
|
66
|
+
pattern,
|
|
67
|
+
method: "",
|
|
68
|
+
fns,
|
|
69
|
+
isMiddleware: true
|
|
70
|
+
});
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
clone(base) {
|
|
74
|
+
return new Router(base, [...this.routes]);
|
|
75
|
+
}
|
|
76
|
+
static async exec(fns, ...arguments_) {
|
|
77
|
+
let index = 0;
|
|
78
|
+
const next = () => fns[++index](...arguments_, next);
|
|
79
|
+
return fns[index](...arguments_, next);
|
|
80
|
+
}
|
|
81
|
+
find(method, pathname) {
|
|
82
|
+
let middleOnly = true;
|
|
83
|
+
const fns = [];
|
|
84
|
+
const parameters = {};
|
|
85
|
+
const isHead = method === "HEAD";
|
|
86
|
+
Object.values(this.routes).forEach((route) => {
|
|
87
|
+
if (route.method !== method && route.method !== "" && !(isHead && route.method === "GET")) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
let matched = false;
|
|
91
|
+
if ("matchAll" in route) {
|
|
92
|
+
matched = true;
|
|
93
|
+
} else if (route.keys === false) {
|
|
94
|
+
const matches = route.pattern.exec(pathname);
|
|
95
|
+
if (matches === null) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (matches.groups !== void 0) {
|
|
99
|
+
Object.keys(matches.groups).forEach((key) => {
|
|
100
|
+
parameters[key] = matches.groups[key];
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
matched = true;
|
|
104
|
+
} else if (route.keys.length > 0) {
|
|
105
|
+
const matches = route.pattern.exec(pathname);
|
|
106
|
+
if (matches === null) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
for (let index = 0; index < route.keys.length; ) {
|
|
110
|
+
const parameterKey = route.keys[index];
|
|
111
|
+
parameters[parameterKey] = matches[++index];
|
|
112
|
+
}
|
|
113
|
+
matched = true;
|
|
114
|
+
} else if (route.pattern.test(pathname)) {
|
|
115
|
+
matched = true;
|
|
116
|
+
}
|
|
117
|
+
if (matched) {
|
|
118
|
+
fns.push(
|
|
119
|
+
...route.fns.flatMap((function_) => {
|
|
120
|
+
if (function_ instanceof Router) {
|
|
121
|
+
const base = function_.base;
|
|
122
|
+
let stripPathname = pathname.slice(base.length);
|
|
123
|
+
if (stripPathname[0] != "/") {
|
|
124
|
+
stripPathname = `/${stripPathname}`;
|
|
125
|
+
}
|
|
126
|
+
const result = function_.find(method, stripPathname);
|
|
127
|
+
if (!result.middleOnly) {
|
|
128
|
+
middleOnly = false;
|
|
129
|
+
}
|
|
130
|
+
Object.assign(parameters, result.params);
|
|
131
|
+
return result.fns;
|
|
132
|
+
}
|
|
133
|
+
return function_;
|
|
134
|
+
})
|
|
135
|
+
);
|
|
136
|
+
if (!route.isMiddleware)
|
|
137
|
+
middleOnly = false;
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
return { fns, params: parameters, middleOnly };
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
// src/edge.ts
|
|
145
|
+
var onNoMatch = async (request) => new Response(request.method !== "HEAD" ? `Route ${request.method} ${request.url} not found` : null, { status: 404 });
|
|
146
|
+
var onError = async (error) => {
|
|
147
|
+
console.error(error);
|
|
148
|
+
return new Response("Internal Server Error", { status: 500 });
|
|
149
|
+
};
|
|
150
|
+
function getPathname(request) {
|
|
151
|
+
return (request.nextUrl || new URL(request.url)).pathname;
|
|
152
|
+
}
|
|
153
|
+
var EdgeRouter = class {
|
|
154
|
+
constructor(options = {}) {
|
|
155
|
+
this.router = new Router();
|
|
156
|
+
this.all = this.add.bind(this, "");
|
|
157
|
+
this.get = this.add.bind(this, "GET");
|
|
158
|
+
this.head = this.add.bind(this, "HEAD");
|
|
159
|
+
this.post = this.add.bind(this, "POST");
|
|
160
|
+
this.put = this.add.bind(this, "PUT");
|
|
161
|
+
this.patch = this.add.bind(this, "PATCH");
|
|
162
|
+
this.delete = this.add.bind(this, "DELETE");
|
|
163
|
+
this.onNoMatch = options.onNoMatch || onNoMatch;
|
|
164
|
+
this.onError = options.onError || onError;
|
|
165
|
+
}
|
|
166
|
+
add(method, routeOrFunction, zodOrRouteOrFunction, ...fns) {
|
|
167
|
+
if (typeof routeOrFunction === "string" && typeof zodOrRouteOrFunction === "function") {
|
|
168
|
+
fns = [zodOrRouteOrFunction];
|
|
169
|
+
} else if (typeof zodOrRouteOrFunction === "object") {
|
|
170
|
+
if (typeof routeOrFunction === "function") {
|
|
171
|
+
fns = [with_zod_default(zodOrRouteOrFunction, routeOrFunction)];
|
|
172
|
+
} else {
|
|
173
|
+
fns = fns.map((function_) => with_zod_default(zodOrRouteOrFunction, function_));
|
|
174
|
+
}
|
|
175
|
+
} else if (typeof zodOrRouteOrFunction === "function") {
|
|
176
|
+
fns = [zodOrRouteOrFunction];
|
|
177
|
+
}
|
|
178
|
+
this.router.add(method, routeOrFunction, ...fns);
|
|
179
|
+
return this;
|
|
180
|
+
}
|
|
181
|
+
use(base, ...fns) {
|
|
182
|
+
if (typeof base === "function" || base instanceof EdgeRouter) {
|
|
183
|
+
fns.unshift(base);
|
|
184
|
+
base = "/";
|
|
185
|
+
}
|
|
186
|
+
this.router.use(base, ...fns.map((function_) => function_ instanceof EdgeRouter ? function_.router : function_));
|
|
187
|
+
return this;
|
|
188
|
+
}
|
|
189
|
+
prepareRequest(request, findResult) {
|
|
190
|
+
request.params = {
|
|
191
|
+
...findResult.params,
|
|
192
|
+
...request.params
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
clone() {
|
|
196
|
+
const r = new EdgeRouter({ onNoMatch: this.onNoMatch, onError: this.onError });
|
|
197
|
+
r.router = this.router.clone();
|
|
198
|
+
return r;
|
|
199
|
+
}
|
|
200
|
+
async run(request, context_) {
|
|
201
|
+
const result = this.router.find(request.method, getPathname(request));
|
|
202
|
+
if (result.fns.length === 0) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
this.prepareRequest(request, result);
|
|
206
|
+
return Router.exec(result.fns, request, context_);
|
|
207
|
+
}
|
|
208
|
+
handler() {
|
|
209
|
+
const { routes } = this.router;
|
|
210
|
+
return async (request, context_) => {
|
|
211
|
+
const result = this.router.find(request.method, getPathname(request));
|
|
212
|
+
this.prepareRequest(request, result);
|
|
213
|
+
try {
|
|
214
|
+
return await (result.fns.length === 0 || result.middleOnly ? this.onNoMatch(request, context_, routes) : Router.exec(result.fns, request, context_));
|
|
215
|
+
} catch (error) {
|
|
216
|
+
return this.onError(error, request, context_, routes);
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
function createEdgeRouter(options = {}) {
|
|
222
|
+
return new EdgeRouter(options);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// src/adapter/express.ts
|
|
226
|
+
var expressWrapper = (function_) => (request, response, next) => new Promise((resolve, reject) => {
|
|
227
|
+
function_(request, response, (error) => error ? reject(error) : resolve());
|
|
228
|
+
}).then(next);
|
|
229
|
+
var express_default = expressWrapper;
|
|
230
|
+
|
|
231
|
+
// src/node.ts
|
|
232
|
+
var onNoMatch2 = async (request, response) => {
|
|
233
|
+
response.statusCode = 404;
|
|
234
|
+
response.end(request.method !== "HEAD" ? `Route ${request.method} ${request.url} not found` : void 0);
|
|
235
|
+
};
|
|
236
|
+
var onError2 = async (error, _request, response) => {
|
|
237
|
+
response.statusCode = 500;
|
|
238
|
+
console.error(error);
|
|
239
|
+
response.end("Internal Server Error");
|
|
240
|
+
};
|
|
241
|
+
function getPathname2(url) {
|
|
242
|
+
const queryIndex = url.indexOf("?");
|
|
243
|
+
return queryIndex !== -1 ? url.slice(0, Math.max(0, queryIndex)) : url;
|
|
244
|
+
}
|
|
245
|
+
var NodeRouter = class {
|
|
246
|
+
constructor(options = {}) {
|
|
247
|
+
this.router = new Router();
|
|
248
|
+
this.all = this.add.bind(this, "");
|
|
249
|
+
this.get = this.add.bind(this, "GET");
|
|
250
|
+
this.head = this.add.bind(this, "HEAD");
|
|
251
|
+
this.post = this.add.bind(this, "POST");
|
|
252
|
+
this.put = this.add.bind(this, "PUT");
|
|
253
|
+
this.patch = this.add.bind(this, "PATCH");
|
|
254
|
+
this.delete = this.add.bind(this, "DELETE");
|
|
255
|
+
this.onNoMatch = options.onNoMatch || onNoMatch2;
|
|
256
|
+
this.onError = options.onError || onError2;
|
|
257
|
+
}
|
|
258
|
+
add(method, routeOrFunction, zodOrRouteOrFunction, ...fns) {
|
|
259
|
+
if (typeof routeOrFunction === "string" && typeof zodOrRouteOrFunction === "function") {
|
|
260
|
+
fns = [zodOrRouteOrFunction];
|
|
261
|
+
} else if (typeof zodOrRouteOrFunction === "object") {
|
|
262
|
+
if (typeof routeOrFunction === "function") {
|
|
263
|
+
fns = [with_zod_default(
|
|
264
|
+
zodOrRouteOrFunction,
|
|
265
|
+
routeOrFunction
|
|
266
|
+
)];
|
|
267
|
+
} else {
|
|
268
|
+
fns = fns.map((function_) => with_zod_default(zodOrRouteOrFunction, function_));
|
|
269
|
+
}
|
|
270
|
+
} else if (typeof zodOrRouteOrFunction === "function") {
|
|
271
|
+
fns = [zodOrRouteOrFunction];
|
|
272
|
+
}
|
|
273
|
+
this.router.add(method, routeOrFunction, ...fns);
|
|
274
|
+
return this;
|
|
275
|
+
}
|
|
276
|
+
use(base, ...fns) {
|
|
277
|
+
if (typeof base === "function" || base instanceof NodeRouter) {
|
|
278
|
+
fns.unshift(base);
|
|
279
|
+
base = "/";
|
|
280
|
+
}
|
|
281
|
+
this.router.use(base, ...fns.map((function_) => function_ instanceof NodeRouter ? function_.router : function_));
|
|
282
|
+
return this;
|
|
283
|
+
}
|
|
284
|
+
prepareRequest(request, findResult) {
|
|
285
|
+
request.params = {
|
|
286
|
+
...findResult.params,
|
|
287
|
+
...request.params
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
clone() {
|
|
291
|
+
const r = new NodeRouter({ onNoMatch: this.onNoMatch, onError: this.onError });
|
|
292
|
+
r.router = this.router.clone();
|
|
293
|
+
return r;
|
|
294
|
+
}
|
|
295
|
+
async run(request, response) {
|
|
296
|
+
const result = this.router.find(request.method, getPathname2(request.url));
|
|
297
|
+
if (result.fns.length === 0) {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
this.prepareRequest(request, result);
|
|
301
|
+
return Router.exec(result.fns, request, response);
|
|
302
|
+
}
|
|
303
|
+
handler() {
|
|
304
|
+
const { routes } = this.router;
|
|
305
|
+
return async (request, response) => {
|
|
306
|
+
const result = this.router.find(request.method, getPathname2(request.url));
|
|
307
|
+
this.prepareRequest(request, result);
|
|
308
|
+
try {
|
|
309
|
+
await (result.fns.length === 0 || result.middleOnly ? this.onNoMatch(request, response, routes) : Router.exec(result.fns, request, response));
|
|
310
|
+
} catch (error) {
|
|
311
|
+
await this.onError(error, request, response, routes);
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
var createRouter = (options = {}) => new NodeRouter(options);
|
|
317
|
+
|
|
318
|
+
// src/utils/send-json.ts
|
|
319
|
+
var sendJson = (response, statusCode, jsonBody) => {
|
|
320
|
+
response.setHeader("content-type", "application/json; charset=utf-8");
|
|
321
|
+
response.statusCode = statusCode;
|
|
322
|
+
response.end(JSON.stringify(jsonBody, null, 2));
|
|
323
|
+
};
|
|
324
|
+
var send_json_default = sendJson;
|
|
325
|
+
export {
|
|
326
|
+
EdgeRouter,
|
|
327
|
+
NodeRouter,
|
|
328
|
+
Router,
|
|
329
|
+
createEdgeRouter,
|
|
330
|
+
createRouter,
|
|
331
|
+
express_default as expressWrapper,
|
|
332
|
+
send_json_default as sendJson,
|
|
333
|
+
with_zod_default as withZod
|
|
334
|
+
};
|
|
335
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/adapter/with-zod.ts","../src/router.ts","../src/edge.ts","../src/adapter/express.ts","../src/node.ts","../src/utils/send-json.ts"],"sourcesContent":["import createHttpError from \"http-errors\";\nimport type { AnyZodObject } from \"zod\";\nimport { ZodError, ZodObject } from \"zod\";\n\nimport type { Nextable, NextHandler } from \"../types\";\n\nconst withZod = <\n Request extends object,\n Response extends unknown,\n Handler extends Nextable<any>,\n Schema extends ZodObject<{ body?: AnyZodObject; headers?: AnyZodObject; query?: AnyZodObject }>,\n >(\n schema: Schema,\n handler: Handler,\n ): ((request: Request, response: Response, next: NextHandler) => Promise<Response>) => async (request: Request, response: Response, next) => {\n let transformedRequest: Request = request;\n\n try {\n transformedRequest = (await schema.parseAsync(request)) as Request;\n } catch (error: any) {\n let { message } = error;\n\n // eslint-disable-next-line unicorn/consistent-destructuring\n if (error instanceof ZodError && typeof error.format === \"function\") {\n // eslint-disable-next-line unicorn/consistent-destructuring\n message = error.issues.map((issue) => `${issue.path.join(\"/\")} - ${issue.message}`).join(\"/n\");\n }\n\n throw createHttpError(422, message);\n }\n\n return handler(transformedRequest, response, next);\n };\n\nexport default withZod;\n","/**\n * Agnostic router class\n * Adapted from lukeed/trouter library:\n * https://github.com/lukeed/trouter/blob/master/index.mjs\n */\nimport { parse } from \"regexparam\";\n\nimport type {\n FindResult, FunctionLike, HttpMethod, Nextable, RouteMatch,\n} from \"./types\";\n\nexport type Route<H> = {\n method: HttpMethod | \"\";\n fns: (H | Router<H extends FunctionLike ? H : never>)[];\n isMiddleware: boolean;\n} & (\n | {\n keys: string[] | false;\n pattern: RegExp;\n }\n | { matchAll: true }\n);\n\nexport class Router<H extends FunctionLike> {\n constructor(public base: string = \"/\", public routes: Route<Nextable<H>>[] = []) {}\n\n public add(method: HttpMethod | \"\", route: RouteMatch | Nextable<H>, ...fns: Nextable<H>[]): this {\n if (typeof route === \"function\") {\n fns.unshift(route);\n // eslint-disable-next-line no-param-reassign\n route = \"\";\n }\n\n if (route === \"\") {\n this.routes.push({\n matchAll: true,\n method,\n fns,\n isMiddleware: false,\n });\n } else {\n const { keys, pattern } = parse(route);\n\n this.routes.push({\n keys,\n pattern,\n method,\n fns,\n isMiddleware: false,\n });\n }\n\n return this;\n }\n\n public use(base: RouteMatch | Nextable<H> | Router<H>, ...fns: (Nextable<H> | Router<H>)[]) {\n if (typeof base === \"function\" || base instanceof Router) {\n fns.unshift(base);\n // eslint-disable-next-line no-param-reassign\n base = \"/\";\n }\n // mount subrouter\n // eslint-disable-next-line no-param-reassign\n fns = fns.map((function_) => {\n if (function_ instanceof Router) {\n if (typeof base === \"string\") return function_.clone(base);\n throw new Error(\"Mounting a router to RegExp base is not supported\");\n }\n return function_;\n });\n\n const { keys, pattern } = parse(base, true);\n\n this.routes.push({\n keys,\n pattern,\n method: \"\",\n fns,\n isMiddleware: true,\n });\n\n return this;\n }\n\n public clone(base?: string) {\n return new Router<H>(base, [...this.routes]);\n }\n\n static async exec<H extends FunctionLike>(fns: Nextable<H>[], ...arguments_: Parameters<H>): Promise<unknown> {\n let index = 0;\n\n // eslint-disable-next-line no-plusplus\n const next = () => (fns[++index] as FunctionLike)(...arguments_, next);\n\n return (fns[index] as FunctionLike)(...arguments_, next);\n }\n\n // eslint-disable-next-line radar/cognitive-complexity\n find(method: HttpMethod, pathname: string): FindResult<H> {\n let middleOnly = true;\n\n const fns: Nextable<H>[] = [];\n const parameters: Record<string, string> = {};\n const isHead = method === \"HEAD\";\n\n // eslint-disable-next-line radar/cognitive-complexity\n Object.values(this.routes).forEach((route) => {\n if (\n route.method !== method\n // matches any method\n && route.method !== \"\"\n // The HEAD method requests that the target resource transfer a representation of its state, as for a GET request...\n && !(isHead && route.method === \"GET\")\n ) {\n return;\n }\n\n let matched = false;\n\n if (\"matchAll\" in route) {\n matched = true;\n } else if (route.keys === false) {\n // routes.key is RegExp: https://github.com/lukeed/regexparam/blob/master/src/index.js#L2\n const matches = route.pattern.exec(pathname);\n\n if (matches === null) {\n return;\n }\n\n // eslint-disable-next-line no-void\n if (matches.groups !== void 0) {\n Object.keys(matches.groups).forEach((key) => {\n // @ts-ignore @TODO: fix this\n parameters[key] = matches.groups[key] as string;\n });\n }\n\n matched = true;\n } else if (route.keys.length > 0) {\n const matches = route.pattern.exec(pathname);\n\n if (matches === null) {\n return;\n }\n\n for (let index = 0; index < route.keys.length;) {\n const parameterKey = route.keys[index];\n\n // @ts-ignore @TODO: fix this\n // eslint-disable-next-line no-plusplus\n parameters[parameterKey] = matches[++index];\n }\n\n matched = true;\n } else if (route.pattern.test(pathname)) {\n matched = true;\n } // else not a match\n\n if (matched) {\n fns.push(\n ...route.fns.flatMap((function_) => {\n if (function_ instanceof Router) {\n const base = function_.base as string;\n\n let stripPathname = pathname.slice(base.length);\n\n // fix stripped pathname, not sure why this happens\n // eslint-disable-next-line eqeqeq\n if (stripPathname[0] != \"/\") {\n stripPathname = `/${stripPathname}`;\n }\n\n // eslint-disable-next-line unicorn/no-array-callback-reference, unicorn/no-array-method-this-argument\n const result = function_.find(method, stripPathname);\n\n if (!result.middleOnly) {\n middleOnly = false;\n }\n\n // merge params\n Object.assign(parameters, result.params);\n\n return result.fns;\n }\n\n return function_;\n }),\n );\n if (!route.isMiddleware) middleOnly = false;\n }\n });\n\n return { fns, params: parameters, middleOnly };\n }\n}\n","import type { AnyZodObject } from \"zod\";\nimport { ZodObject } from \"zod\";\n\nimport withZod from \"./adapter/with-zod\";\nimport { Route, Router } from \"./router\";\nimport type {\n FindResult,\n FunctionLike,\n HandlerOptions,\n HttpMethod,\n Nextable,\n RouteMatch,\n RoutesExtendedRequestHandler,\n RouteShortcutMethod,\n ValueOrPromise,\n} from \"./types\";\n\n// eslint-disable-next-line max-len\nconst onNoMatch = async (request: Request) => new Response(request.method !== \"HEAD\" ? `Route ${request.method} ${request.url} not found` : null, { status: 404 });\n\nconst onError = async (error: unknown) => {\n // eslint-disable-next-line no-console\n console.error(error);\n return new Response(\"Internal Server Error\", { status: 500 });\n};\n\nexport function getPathname(request: Request & { nextUrl?: URL }) {\n // eslint-disable-next-line compat/compat\n return (request.nextUrl || new URL(request.url)).pathname;\n}\n\n// eslint-disable-next-line max-len\nexport type RequestHandler<R extends Request, Context> = (request: R, context_: Context) => ValueOrPromise<Response | void>;\n\nexport class EdgeRouter<R extends Request = Request, Context = unknown, RResponse extends Response = Response, Schema extends AnyZodObject = ZodObject<any>> {\n private router = new Router<RequestHandler<R, Context>>();\n\n private readonly onNoMatch: RoutesExtendedRequestHandler<R, Context, RResponse, Route<Nextable<FunctionLike>>[]>;\n\n private readonly onError: (\n error: unknown,\n ...arguments_: Parameters<RoutesExtendedRequestHandler<R, Context, RResponse, Route<Nextable<FunctionLike>>[]>>\n ) => ReturnType<RoutesExtendedRequestHandler<R, Context, RResponse, Route<Nextable<FunctionLike>>[]>>;\n\n constructor(options: HandlerOptions<RoutesExtendedRequestHandler<R, Context, RResponse, Route<Nextable<FunctionLike>>[]>> = {}) {\n this.onNoMatch = options.onNoMatch || onNoMatch as unknown as RoutesExtendedRequestHandler<R, Context, RResponse, Route<Nextable<FunctionLike>>[]>;\n this.onError = options.onError\n || (onError as unknown as (\n error: unknown,\n ...arguments_: Parameters<RoutesExtendedRequestHandler<R, Context, RResponse, Route<Nextable<FunctionLike>>[]>>\n ) => ReturnType<RoutesExtendedRequestHandler<R, Context, RResponse, Route<Nextable<FunctionLike>>[]>>);\n }\n\n private add(\n method: HttpMethod | \"\",\n routeOrFunction: RouteMatch | Nextable<RequestHandler<R, Context>>,\n zodOrRouteOrFunction?: RouteMatch | Schema | Nextable<RequestHandler<R, Context>>,\n ...fns: Nextable<RequestHandler<R, Context>>[]\n ) {\n if (typeof routeOrFunction === \"string\" && typeof zodOrRouteOrFunction === \"function\") {\n // eslint-disable-next-line no-param-reassign\n fns = [zodOrRouteOrFunction];\n } else if (typeof zodOrRouteOrFunction === \"object\") {\n // eslint-disable-next-line unicorn/prefer-ternary\n if (typeof routeOrFunction === \"function\") {\n // eslint-disable-next-line no-param-reassign\n fns = [withZod<R, Context, Nextable<RequestHandler<R, Context>>, Schema>(zodOrRouteOrFunction as Schema, routeOrFunction)];\n } else {\n // eslint-disable-next-line no-param-reassign,max-len\n fns = fns.map((function_) => withZod<R, Context, Nextable<RequestHandler<R, Context>>, Schema>(zodOrRouteOrFunction as Schema, function_));\n }\n } else if (typeof zodOrRouteOrFunction === \"function\") {\n // eslint-disable-next-line no-param-reassign\n fns = [zodOrRouteOrFunction];\n }\n\n this.router.add(method, routeOrFunction, ...fns);\n\n return this;\n }\n\n public all: RouteShortcutMethod<this, Schema, RequestHandler<R, Context>> = this.add.bind(this, \"\");\n\n public get: RouteShortcutMethod<this, Schema, RequestHandler<R, Context>> = this.add.bind(this, \"GET\");\n\n public head: RouteShortcutMethod<this, Schema, RequestHandler<R, Context>> = this.add.bind(this, \"HEAD\");\n\n public post: RouteShortcutMethod<this, Schema, RequestHandler<R, Context>> = this.add.bind(this, \"POST\");\n\n public put: RouteShortcutMethod<this, Schema, RequestHandler<R, Context>> = this.add.bind(this, \"PUT\");\n\n public patch: RouteShortcutMethod<this, Schema, RequestHandler<R, Context>> = this.add.bind(this, \"PATCH\");\n\n public delete: RouteShortcutMethod<this, Schema, RequestHandler<R, Context>> = this.add.bind(this, \"DELETE\");\n\n public use(\n base: RouteMatch | Nextable<RequestHandler<R, Context>> | EdgeRouter<R, Context>,\n ...fns: (Nextable<RequestHandler<R, Context>> | EdgeRouter<R, Context>)[]\n ) {\n if (typeof base === \"function\" || base instanceof EdgeRouter) {\n fns.unshift(base);\n // eslint-disable-next-line no-param-reassign\n base = \"/\";\n }\n\n this.router.use(base, ...fns.map((function_) => (function_ instanceof EdgeRouter ? function_.router : function_)));\n\n return this;\n }\n\n // eslint-disable-next-line class-methods-use-this\n private prepareRequest(request: R & { params?: Record<string, unknown> }, findResult: FindResult<RequestHandler<R, Context>>) {\n request.params = {\n ...findResult.params,\n ...request.params, // original params will take precedence\n };\n }\n\n public clone() {\n const r = new EdgeRouter<R, Context, RResponse, Schema>({ onNoMatch: this.onNoMatch, onError: this.onError });\n\n r.router = this.router.clone();\n\n return r;\n }\n\n async run(request: R, context_: Context) {\n // eslint-disable-next-line unicorn/no-array-callback-reference,unicorn/no-array-method-this-argument\n const result = this.router.find(request.method as HttpMethod, getPathname(request));\n\n if (result.fns.length === 0) {\n return;\n }\n\n this.prepareRequest(request, result);\n\n // eslint-disable-next-line consistent-return\n return Router.exec(result.fns, request, context_);\n }\n\n handler() {\n const { routes } = this.router as Router<FunctionLike>;\n\n return async (request: R, context_: Context): Promise<any> => {\n // eslint-disable-next-line unicorn/no-array-callback-reference,unicorn/no-array-method-this-argument\n const result = this.router.find(request.method as HttpMethod, getPathname(request));\n\n this.prepareRequest(request, result);\n\n try {\n return await (result.fns.length === 0 || result.middleOnly\n ? this.onNoMatch(request, context_, routes)\n : Router.exec(result.fns, request, context_));\n } catch (error) {\n return this.onError(error, request, context_, routes);\n }\n };\n }\n}\n\nexport function createEdgeRouter<R extends Request, Context>(\n options: HandlerOptions<RoutesExtendedRequestHandler<R, Context, Response, Route<Nextable<FunctionLike>>[]>> = {},\n) {\n return new EdgeRouter<R, Context, Response>(options);\n}\n","import type { IncomingMessage, ServerResponse } from \"node:http\";\n\nimport type { RequestHandler } from \"../node\";\nimport type { Nextable } from \"../types\";\n\ntype NextFunction = (error?: any) => void;\n\nconst expressWrapper = <Request extends IncomingMessage, Response extends ServerResponse>(\n function_: ExpressRequestHandler<Request, Response>,\n // eslint-disable-next-line compat/compat\n): Nextable<RequestHandler<Request, Response>> => (request, response, next) => new Promise<void>((resolve, reject) => {\n function_(request, response, (error) => (error ? reject(error) : resolve()));\n // eslint-disable-next-line promise/no-callback-in-promise\n }).then(next);\n\nexport type ExpressRequestHandler<Request, Response> = (request: Request, response: Response, next: NextFunction) => void;\n\nexport default expressWrapper;\n","import type { IncomingMessage, ServerResponse } from \"node:http\";\nimport type { AnyZodObject } from \"zod\";\nimport { ZodObject } from \"zod\";\n\nimport withZod from \"./adapter/with-zod\";\nimport type { Route } from \"./router\";\nimport { Router } from \"./router\";\nimport type {\n FindResult,\n FunctionLike,\n HandlerOptions,\n HttpMethod,\n Nextable,\n RouteMatch,\n RoutesExtendedRequestHandler,\n RouteShortcutMethod,\n ValueOrPromise,\n} from \"./types\";\n\nconst onNoMatch = async (request: IncomingMessage, response: ServerResponse) => {\n response.statusCode = 404;\n response.end(request.method !== \"HEAD\" ? `Route ${request.method} ${request.url} not found` : undefined);\n};\n\nconst onError = async (error: unknown, _request: IncomingMessage, response: ServerResponse) => {\n response.statusCode = 500;\n // eslint-disable-next-line no-console\n console.error(error);\n\n response.end(\"Internal Server Error\");\n};\n\nexport function getPathname(url: string) {\n const queryIndex = url.indexOf(\"?\");\n\n return queryIndex !== -1 ? url.slice(0, Math.max(0, queryIndex)) : url;\n}\n\nexport type RequestHandler<Request extends IncomingMessage, Response extends ServerResponse> = (request: Request, response: Response) => ValueOrPromise<void>;\n\nexport class NodeRouter<\n Request extends IncomingMessage = IncomingMessage,\n Response extends ServerResponse = ServerResponse,\n Schema extends AnyZodObject = ZodObject<any>,\n> {\n private router = new Router<RequestHandler<Request, Response>>();\n\n private readonly onNoMatch: RoutesExtendedRequestHandler<Request, Response, Response, Route<Nextable<FunctionLike>>[]>;\n\n private readonly onError: (\n error: unknown,\n ...arguments_: Parameters<RoutesExtendedRequestHandler<Request, Response, Response, Route<Nextable<FunctionLike>>[]>>\n ) => ReturnType<RoutesExtendedRequestHandler<Request, Response, Response, Route<Nextable<FunctionLike>>[]>>;\n\n constructor(options: HandlerOptions<RoutesExtendedRequestHandler<Request, Response, Response, Route<Nextable<FunctionLike>>[]>> = {}) {\n this.onNoMatch = options.onNoMatch || onNoMatch;\n this.onError = options.onError || onError;\n }\n\n private add(\n method: HttpMethod | \"\",\n routeOrFunction: RouteMatch | Nextable<RequestHandler<Request, Response>>,\n zodOrRouteOrFunction?: RouteMatch | Schema | Nextable<RequestHandler<Request, Response>>,\n ...fns: Nextable<RequestHandler<Request, Response>>[]\n ) {\n if (typeof routeOrFunction === \"string\" && typeof zodOrRouteOrFunction === \"function\") {\n // eslint-disable-next-line no-param-reassign\n fns = [zodOrRouteOrFunction];\n } else if (typeof zodOrRouteOrFunction === \"object\") {\n // eslint-disable-next-line unicorn/prefer-ternary\n if (typeof routeOrFunction === \"function\") {\n // eslint-disable-next-line no-param-reassign\n fns = [withZod<Request, Response, Nextable<RequestHandler<Request, Response>>, Schema>(\n zodOrRouteOrFunction as Schema,\n routeOrFunction,\n )];\n } else {\n // eslint-disable-next-line no-param-reassign,max-len\n fns = fns.map((function_) => withZod<Request, Response, Nextable<RequestHandler<Request, Response>>, Schema>(zodOrRouteOrFunction as Schema, function_));\n }\n } else if (typeof zodOrRouteOrFunction === \"function\") {\n // eslint-disable-next-line no-param-reassign\n fns = [zodOrRouteOrFunction];\n }\n\n this.router.add(method, routeOrFunction, ...fns);\n\n return this;\n }\n\n public all: RouteShortcutMethod<this, Schema, RequestHandler<Request, Response>> = this.add.bind(this, \"\");\n\n public get: RouteShortcutMethod<this, Schema, RequestHandler<Request, Response>> = this.add.bind(this, \"GET\");\n\n public head: RouteShortcutMethod<this, Schema, RequestHandler<Request, Response>> = this.add.bind(this, \"HEAD\");\n\n public post: RouteShortcutMethod<this, Schema, RequestHandler<Request, Response>> = this.add.bind(this, \"POST\");\n\n public put: RouteShortcutMethod<this, Schema, RequestHandler<Request, Response>> = this.add.bind(this, \"PUT\");\n\n public patch: RouteShortcutMethod<this, Schema, RequestHandler<Request, Response>> = this.add.bind(this, \"PATCH\");\n\n public delete: RouteShortcutMethod<this, Schema, RequestHandler<Request, Response>> = this.add.bind(this, \"DELETE\");\n\n public use(\n base: RouteMatch | Nextable<RequestHandler<Request, Response>> | NodeRouter<Request, Response, Schema>,\n ...fns: (Nextable<RequestHandler<Request, Response>> | NodeRouter<Request, Response, Schema>)[]\n ) {\n if (typeof base === \"function\" || base instanceof NodeRouter) {\n fns.unshift(base);\n // eslint-disable-next-line no-param-reassign\n base = \"/\";\n }\n this.router.use(base, ...fns.map((function_) => (function_ instanceof NodeRouter ? function_.router : function_)));\n\n return this;\n }\n\n // eslint-disable-next-line class-methods-use-this\n private prepareRequest(request: Request & { params?: Record<string, unknown> }, findResult: FindResult<RequestHandler<Request, Response>>) {\n request.params = {\n ...findResult.params,\n ...request.params, // original params will take precedence\n };\n }\n\n public clone() {\n const r = new NodeRouter<Request, Response, Schema>({ onNoMatch: this.onNoMatch, onError: this.onError });\n\n r.router = this.router.clone();\n\n return r;\n }\n\n async run(request: Request, response: Response): Promise<unknown> {\n // eslint-disable-next-line unicorn/no-array-callback-reference,unicorn/no-array-method-this-argument\n const result = this.router.find(request.method as HttpMethod, getPathname(request.url as string));\n\n if (result.fns.length === 0) {\n return;\n }\n\n this.prepareRequest(request, result);\n\n // eslint-disable-next-line consistent-return\n return Router.exec(result.fns, request, response);\n }\n\n handler() {\n const { routes } = this.router as Router<FunctionLike>;\n\n return async (request: Request, response: Response) => {\n // eslint-disable-next-line unicorn/no-array-callback-reference,unicorn/no-array-method-this-argument\n const result = this.router.find(request.method as HttpMethod, getPathname(request.url as string));\n\n this.prepareRequest(request, result);\n\n try {\n await (result.fns.length === 0 || result.middleOnly ? this.onNoMatch(request, response, routes) : Router.exec(result.fns, request, response));\n } catch (error) {\n await this.onError(error, request, response, routes);\n }\n };\n }\n}\n\nexport const createRouter = <\n Request extends IncomingMessage,\n Response extends ServerResponse,\n Schema extends AnyZodObject = ZodObject<{ body?: AnyZodObject; headers?: AnyZodObject; query?: AnyZodObject }>,\n>(\n options: HandlerOptions<RoutesExtendedRequestHandler<Request, Response, Response, Route<Nextable<FunctionLike>>[]>> = {},\n ) => new NodeRouter<Request, Response, Schema>(options);\n","import type { ServerResponse } from \"node:http\";\n\n/**\n * Send `JSON` object\n * @param {ServerResponse} response response object\n * @param {number} statusCode\n * @param {any} jsonBody of data\n */\nconst sendJson = (response: ServerResponse, statusCode: number, jsonBody: any): void => {\n // Set header to application/json\n response.setHeader(\"content-type\", \"application/json; charset=utf-8\");\n\n response.statusCode = statusCode;\n response.end(JSON.stringify(jsonBody, null, 2));\n};\n\nexport default sendJson;\n"],"mappings":";AAAA,OAAO,qBAAqB;AAE5B,SAAS,gBAA2B;AAIpC,IAAM,UAAU,CAMR,QACA,YACmF,OAAO,SAAkB,UAAoB,SAAS;AACzI,MAAI,qBAA8B;AAElC,MAAI;AACA,yBAAsB,MAAM,OAAO,WAAW,OAAO;AAAA,EACzD,SAAS,OAAP;AACE,QAAI,EAAE,QAAQ,IAAI;AAGlB,QAAI,iBAAiB,YAAY,OAAO,MAAM,WAAW,YAAY;AAEjE,gBAAU,MAAM,OAAO,IAAI,CAAC,UAAU,GAAG,MAAM,KAAK,KAAK,GAAG,OAAO,MAAM,SAAS,EAAE,KAAK,IAAI;AAAA,IACjG;AAEA,UAAM,gBAAgB,KAAK,OAAO;AAAA,EACtC;AAEA,SAAO,QAAQ,oBAAoB,UAAU,IAAI;AACrD;AAEJ,IAAO,mBAAQ;;;AC7Bf,SAAS,aAAa;AAkBf,IAAM,SAAN,MAAqC;AAAA,EACxC,YAAmB,OAAe,KAAY,SAA+B,CAAC,GAAG;AAA9D;AAA2B;AAAA,EAAoC;AAAA,EAE3E,IAAI,QAAyB,UAAoC,KAA0B;AAC9F,QAAI,OAAO,UAAU,YA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|
2
|
+
"name": "@visulima/connect",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "The minimal router and middleware layer for Next.js, Micro, Vercel, or Node.js http/http2 with support for zod validation.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"javascript",
|
|
7
|
+
"nextjs",
|
|
8
|
+
"middleware",
|
|
9
|
+
"router",
|
|
10
|
+
"connect",
|
|
11
|
+
"vercel",
|
|
12
|
+
"node",
|
|
13
|
+
"http",
|
|
14
|
+
"http2",
|
|
15
|
+
"zod"
|
|
16
|
+
],
|
|
17
|
+
"homepage": "https://visulima.com/packages/connect",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/visulima/visulima/issues"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/visulima/visulima.git",
|
|
24
|
+
"directory": "packages/connect"
|
|
25
|
+
},
|
|
26
|
+
"funding": [
|
|
27
|
+
{
|
|
28
|
+
"type": "github",
|
|
29
|
+
"url": "https://github.com/sponsors/prisis"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"type": "consulting",
|
|
33
|
+
"url": "https://anolilab.com/support"
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"author": {
|
|
38
|
+
"name": "Daniel Bannert",
|
|
39
|
+
"email": "d.bannert@anolilab.de"
|
|
40
|
+
},
|
|
41
|
+
"sideEffects": false,
|
|
42
|
+
"exports": {
|
|
43
|
+
".": {
|
|
44
|
+
"types": "./dist/index.d.ts",
|
|
45
|
+
"require": "./dist/index.js",
|
|
46
|
+
"import": "./dist/index.mjs"
|
|
47
|
+
},
|
|
48
|
+
"./package.json": "./package.json"
|
|
49
|
+
},
|
|
50
|
+
"main": "dist/index.js",
|
|
51
|
+
"module": "dist/index.mjs",
|
|
52
|
+
"source": "src/index.ts",
|
|
53
|
+
"types": "dist/index.d.ts",
|
|
54
|
+
"files": [
|
|
55
|
+
"dist/**",
|
|
56
|
+
"README.md",
|
|
57
|
+
"CHANGELOG.md",
|
|
58
|
+
"LICENSE.md"
|
|
59
|
+
],
|
|
60
|
+
"scripts": {
|
|
61
|
+
"build": "cross-env NODE_ENV=development tsup",
|
|
62
|
+
"build:prod": "cross-env NODE_ENV=production tsup",
|
|
63
|
+
"clean": "rimraf node_modules dist",
|
|
64
|
+
"coverage": "vitest run --coverage",
|
|
65
|
+
"dev": "pnpm predev && pnpm run build --watch",
|
|
66
|
+
"lint:eslint": "cross-env NO_LOGS=true eslint --ext js,jsx,ts,tsx --max-warnings=0 --config .eslintrc.cjs --cache --cache-strategy content .",
|
|
67
|
+
"lint:eslint:fix": "pnpm run lint:eslint --fix",
|
|
68
|
+
"test": "vitest"
|
|
69
|
+
},
|
|
70
|
+
"dependencies": {
|
|
71
|
+
"http-errors": "^2.0.0",
|
|
72
|
+
"regexparam": "^2.0.1"
|
|
73
|
+
},
|
|
74
|
+
"devDependencies": {
|
|
75
|
+
"@anolilab/eslint-config": "^4.1.1",
|
|
76
|
+
"@anolilab/semantic-release-preset": "^2.1.0",
|
|
77
|
+
"@rushstack/eslint-plugin-security": "^0.5.0",
|
|
78
|
+
"@types/http-errors": "^1.8.2",
|
|
79
|
+
"@types/node": "^18.11.5",
|
|
80
|
+
"@typescript-eslint/eslint-plugin": "^5.41.0",
|
|
81
|
+
"@typescript-eslint/parser": "^5.41.0",
|
|
82
|
+
"@vitest/coverage-c8": "^0.24.3",
|
|
83
|
+
"c8": "^7.12.0",
|
|
84
|
+
"cross-env": "^7.0.3",
|
|
85
|
+
"eslint": "^8.26.0",
|
|
86
|
+
"eslint-plugin-compat": "^4.0.2",
|
|
87
|
+
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
88
|
+
"eslint-plugin-import": "^2.26.0",
|
|
89
|
+
"eslint-plugin-json": "^3.1.0",
|
|
90
|
+
"eslint-plugin-jsx-a11y": "^6.6.1",
|
|
91
|
+
"eslint-plugin-markdown": "^3.0.0",
|
|
92
|
+
"eslint-plugin-material-ui": "^1.0.1",
|
|
93
|
+
"eslint-plugin-no-loops": "^0.3.0",
|
|
94
|
+
"eslint-plugin-no-secrets": "^0.8.9",
|
|
95
|
+
"eslint-plugin-node": "^11.1.0",
|
|
96
|
+
"eslint-plugin-optimize-regex": "^1.2.1",
|
|
97
|
+
"eslint-plugin-promise": "^6.1.1",
|
|
98
|
+
"eslint-plugin-radar": "^0.2.1",
|
|
99
|
+
"eslint-plugin-simple-import-sort": "^8.0.0",
|
|
100
|
+
"eslint-plugin-sort-keys-fix": "^1.1.2",
|
|
101
|
+
"eslint-plugin-testing-library": "^5.9.1",
|
|
102
|
+
"eslint-plugin-unicorn": "^44.0.2",
|
|
103
|
+
"eslint-plugin-you-dont-need-lodash-underscore": "^6.12.0",
|
|
104
|
+
"eslint-plugin-you-dont-need-momentjs": "^1.6.0",
|
|
105
|
+
"express": "^4.18.2",
|
|
106
|
+
"fastify": "^4.9.2",
|
|
107
|
+
"isomorphic-fetch": "^3.0.0",
|
|
108
|
+
"prettier": "^2.7.1",
|
|
109
|
+
"read-pkg": "^7.1.0",
|
|
110
|
+
"rimraf": "^3.0.2",
|
|
111
|
+
"semantic-release": "^19.0.5",
|
|
112
|
+
"tsup": "^6.3.0",
|
|
113
|
+
"typescript": "^4.8.4",
|
|
114
|
+
"vitest": "^0.24.3",
|
|
115
|
+
"zod": "^3.19.1"
|
|
116
|
+
},
|
|
117
|
+
"peerDependencies": {
|
|
118
|
+
"zod": "^3.19.1"
|
|
119
|
+
},
|
|
120
|
+
"engines": {
|
|
121
|
+
"node": ">=16"
|
|
122
|
+
},
|
|
123
|
+
"publishConfig": {
|
|
124
|
+
"access": "public"
|
|
125
|
+
}
|
|
126
|
+
}
|