clear-router 2.8.8 → 2.9.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/dist/Route.cjs +200 -12
- package/dist/Route.d.cts +125 -1
- package/dist/Route.d.mts +125 -1
- package/dist/Route.mjs +199 -12
- package/dist/RouteGroup.cjs +2 -1
- package/dist/RouteGroup.mjs +2 -1
- package/dist/RouteRegistrar.cjs +68 -0
- package/dist/RouteRegistrar.d.cts +62 -0
- package/dist/RouteRegistrar.d.mts +62 -0
- package/dist/RouteRegistrar.mjs +67 -0
- package/dist/core/CoreRouter.cjs +307 -0
- package/dist/core/CoreRouter.d.cts +168 -0
- package/dist/core/CoreRouter.d.mts +168 -0
- package/dist/core/CoreRouter.mjs +307 -0
- package/dist/decorators/setup.d.mts +0 -1
- package/dist/express/router.cjs +13 -4
- package/dist/express/router.d.cts +1 -0
- package/dist/express/router.d.mts +1 -0
- package/dist/express/router.mjs +13 -4
- package/dist/fastify/router.cjs +13 -4
- package/dist/fastify/router.d.cts +1 -0
- package/dist/fastify/router.d.mts +1 -0
- package/dist/fastify/router.mjs +13 -4
- package/dist/h3/router.cjs +13 -4
- package/dist/h3/router.d.cts +1 -0
- package/dist/h3/router.d.mts +1 -0
- package/dist/h3/router.mjs +13 -4
- package/dist/hono/router.cjs +11 -4
- package/dist/hono/router.d.cts +1 -0
- package/dist/hono/router.d.mts +1 -0
- package/dist/hono/router.mjs +11 -4
- package/dist/index.cjs +3 -0
- package/dist/index.d.cts +3 -2
- package/dist/index.d.mts +3 -2
- package/dist/index.mjs +3 -2
- package/dist/koa/router.cjs +13 -4
- package/dist/koa/router.d.cts +1 -0
- package/dist/koa/router.d.mts +1 -0
- package/dist/koa/router.mjs +13 -4
- package/dist/types/basic.d.cts +2 -0
- package/dist/types/basic.d.mts +2 -0
- package/package.json +2 -2
package/dist/express/router.mjs
CHANGED
|
@@ -11,6 +11,9 @@ import { isFetchResponse, resolveResponseMeta, responseWasSent } from "../core/r
|
|
|
11
11
|
*/
|
|
12
12
|
var Router = class Router extends CoreRouter {
|
|
13
13
|
static routerStateNamespace = "clear-router:express";
|
|
14
|
+
static formatWildcardParam(name) {
|
|
15
|
+
return `*${name}`;
|
|
16
|
+
}
|
|
14
17
|
static ensureRequestBodyAccessor(req) {
|
|
15
18
|
if (typeof req.getBody !== "function") req.getBody = () => req.body ?? {};
|
|
16
19
|
}
|
|
@@ -196,7 +199,7 @@ var Router = class Router extends CoreRouter {
|
|
|
196
199
|
console.error("[ROUTES]", error.message);
|
|
197
200
|
throw error;
|
|
198
201
|
}
|
|
199
|
-
for (const registrationPath of route
|
|
202
|
+
for (const registrationPath of this.resolveRegistrationPaths(route)) router[method](registrationPath, (req, _res, next) => {
|
|
200
203
|
Router.ensureRequestBodyAccessor(req);
|
|
201
204
|
const override = Router.resolveMethodOverride(req.method, req.headers, req.body);
|
|
202
205
|
if (method === "post" && override && override !== "post") return next("route");
|
|
@@ -210,10 +213,13 @@ var Router = class Router extends CoreRouter {
|
|
|
210
213
|
next
|
|
211
214
|
};
|
|
212
215
|
const inst = instance ?? route;
|
|
216
|
+
const params = Router.matchRoute(route, ctx, ctx.req.params);
|
|
217
|
+
if (params === false) return next("route");
|
|
218
|
+
Object.assign(ctx.req.params, params);
|
|
213
219
|
Router.bindRequestToInstance(ctx, inst, route, {
|
|
214
220
|
body: ctx.req.getBody(),
|
|
215
221
|
query: ctx.req.query,
|
|
216
|
-
params
|
|
222
|
+
params,
|
|
217
223
|
method
|
|
218
224
|
});
|
|
219
225
|
const result = await Router.callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata);
|
|
@@ -228,7 +234,7 @@ var Router = class Router extends CoreRouter {
|
|
|
228
234
|
"put",
|
|
229
235
|
"patch",
|
|
230
236
|
"delete"
|
|
231
|
-
].includes(method)) for (const registrationPath of route
|
|
237
|
+
].includes(method)) for (const registrationPath of this.resolveRegistrationPaths(route)) router.post(registrationPath, (req, _res, next) => {
|
|
232
238
|
Router.ensureRequestBodyAccessor(req);
|
|
233
239
|
if (Router.resolveMethodOverride(req.method, req.headers, req.body) !== method) return next("route");
|
|
234
240
|
req.method = method.toUpperCase();
|
|
@@ -242,10 +248,13 @@ var Router = class Router extends CoreRouter {
|
|
|
242
248
|
next
|
|
243
249
|
};
|
|
244
250
|
const inst = instance ?? route;
|
|
251
|
+
const params = Router.matchRoute(route, ctx, ctx.req.params);
|
|
252
|
+
if (params === false) return next("route");
|
|
253
|
+
Object.assign(ctx.req.params, params);
|
|
245
254
|
Router.bindRequestToInstance(ctx, inst, route, {
|
|
246
255
|
body: ctx.req.getBody(),
|
|
247
256
|
query: ctx.req.query,
|
|
248
|
-
params
|
|
257
|
+
params,
|
|
249
258
|
method
|
|
250
259
|
});
|
|
251
260
|
const result = await Router.callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata);
|
package/dist/fastify/router.cjs
CHANGED
|
@@ -10,6 +10,9 @@ const require_responses = require('../core/responses.cjs');
|
|
|
10
10
|
*/
|
|
11
11
|
var Router = class Router extends require_CoreRouter.CoreRouter {
|
|
12
12
|
static routerStateNamespace = "clear-router:fastify";
|
|
13
|
+
static formatWildcardParam() {
|
|
14
|
+
return "*";
|
|
15
|
+
}
|
|
13
16
|
static ensureRequestBodyAccessor(req) {
|
|
14
17
|
if (typeof req.getBody !== "function") req.getBody = () => req.body ?? {};
|
|
15
18
|
}
|
|
@@ -191,7 +194,7 @@ var Router = class Router extends require_CoreRouter.CoreRouter {
|
|
|
191
194
|
];
|
|
192
195
|
if (method === "options" && route.methods.length > 1) continue;
|
|
193
196
|
if (!allowedMethods.includes(method)) throw new Error(`Invalid HTTP method: ${method} for route: ${route.path}`);
|
|
194
|
-
for (const registrationPath of route
|
|
197
|
+
for (const registrationPath of this.resolveRegistrationPaths(route)) app.route({
|
|
195
198
|
method: method.toUpperCase(),
|
|
196
199
|
url: registrationPath,
|
|
197
200
|
preHandler: route.middlewares,
|
|
@@ -204,10 +207,13 @@ var Router = class Router extends require_CoreRouter.CoreRouter {
|
|
|
204
207
|
reply
|
|
205
208
|
};
|
|
206
209
|
const inst = instance ?? route;
|
|
210
|
+
const params = Router.matchRoute(route, ctx, ctx.req.params ?? {});
|
|
211
|
+
if (params === false) return reply.code(404).send();
|
|
212
|
+
Object.assign(ctx.req.params ??= {}, params);
|
|
207
213
|
Router.bindRequestToInstance(ctx, inst, route, {
|
|
208
214
|
body: ctx.req.getBody(),
|
|
209
215
|
query: ctx.req.query ?? {},
|
|
210
|
-
params
|
|
216
|
+
params,
|
|
211
217
|
method
|
|
212
218
|
});
|
|
213
219
|
const result = await Router.callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata);
|
|
@@ -220,7 +226,7 @@ var Router = class Router extends require_CoreRouter.CoreRouter {
|
|
|
220
226
|
"put",
|
|
221
227
|
"patch",
|
|
222
228
|
"delete"
|
|
223
|
-
].includes(method)) for (const registrationPath of route
|
|
229
|
+
].includes(method)) for (const registrationPath of this.resolveRegistrationPaths(route)) app.route({
|
|
224
230
|
method: "POST",
|
|
225
231
|
url: registrationPath,
|
|
226
232
|
preHandler: route.middlewares,
|
|
@@ -232,10 +238,13 @@ var Router = class Router extends require_CoreRouter.CoreRouter {
|
|
|
232
238
|
reply
|
|
233
239
|
};
|
|
234
240
|
const inst = instance ?? route;
|
|
241
|
+
const params = Router.matchRoute(route, ctx, ctx.req.params ?? {});
|
|
242
|
+
if (params === false) return reply.code(404).send();
|
|
243
|
+
Object.assign(ctx.req.params ??= {}, params);
|
|
235
244
|
Router.bindRequestToInstance(ctx, inst, route, {
|
|
236
245
|
body: ctx.req.getBody(),
|
|
237
246
|
query: ctx.req.query ?? {},
|
|
238
|
-
params
|
|
247
|
+
params,
|
|
239
248
|
method
|
|
240
249
|
});
|
|
241
250
|
const result = await Router.callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata);
|
|
@@ -14,6 +14,7 @@ import { CoreRouter } from "../core/CoreRouter.cjs";
|
|
|
14
14
|
*/
|
|
15
15
|
declare class Router extends CoreRouter {
|
|
16
16
|
protected static routerStateNamespace: string;
|
|
17
|
+
protected static formatWildcardParam(): string;
|
|
17
18
|
private static ensureRequestBodyAccessor;
|
|
18
19
|
private static sendReturnValue;
|
|
19
20
|
/**
|
|
@@ -14,6 +14,7 @@ import { CoreRouter } from "../core/CoreRouter.mjs";
|
|
|
14
14
|
*/
|
|
15
15
|
declare class Router extends CoreRouter {
|
|
16
16
|
protected static routerStateNamespace: string;
|
|
17
|
+
protected static formatWildcardParam(): string;
|
|
17
18
|
private static ensureRequestBodyAccessor;
|
|
18
19
|
private static sendReturnValue;
|
|
19
20
|
/**
|
package/dist/fastify/router.mjs
CHANGED
|
@@ -10,6 +10,9 @@ import { isFetchResponse, resolveResponseMeta, responseWasSent } from "../core/r
|
|
|
10
10
|
*/
|
|
11
11
|
var Router = class Router extends CoreRouter {
|
|
12
12
|
static routerStateNamespace = "clear-router:fastify";
|
|
13
|
+
static formatWildcardParam() {
|
|
14
|
+
return "*";
|
|
15
|
+
}
|
|
13
16
|
static ensureRequestBodyAccessor(req) {
|
|
14
17
|
if (typeof req.getBody !== "function") req.getBody = () => req.body ?? {};
|
|
15
18
|
}
|
|
@@ -191,7 +194,7 @@ var Router = class Router extends CoreRouter {
|
|
|
191
194
|
];
|
|
192
195
|
if (method === "options" && route.methods.length > 1) continue;
|
|
193
196
|
if (!allowedMethods.includes(method)) throw new Error(`Invalid HTTP method: ${method} for route: ${route.path}`);
|
|
194
|
-
for (const registrationPath of route
|
|
197
|
+
for (const registrationPath of this.resolveRegistrationPaths(route)) app.route({
|
|
195
198
|
method: method.toUpperCase(),
|
|
196
199
|
url: registrationPath,
|
|
197
200
|
preHandler: route.middlewares,
|
|
@@ -204,10 +207,13 @@ var Router = class Router extends CoreRouter {
|
|
|
204
207
|
reply
|
|
205
208
|
};
|
|
206
209
|
const inst = instance ?? route;
|
|
210
|
+
const params = Router.matchRoute(route, ctx, ctx.req.params ?? {});
|
|
211
|
+
if (params === false) return reply.code(404).send();
|
|
212
|
+
Object.assign(ctx.req.params ??= {}, params);
|
|
207
213
|
Router.bindRequestToInstance(ctx, inst, route, {
|
|
208
214
|
body: ctx.req.getBody(),
|
|
209
215
|
query: ctx.req.query ?? {},
|
|
210
|
-
params
|
|
216
|
+
params,
|
|
211
217
|
method
|
|
212
218
|
});
|
|
213
219
|
const result = await Router.callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata);
|
|
@@ -220,7 +226,7 @@ var Router = class Router extends CoreRouter {
|
|
|
220
226
|
"put",
|
|
221
227
|
"patch",
|
|
222
228
|
"delete"
|
|
223
|
-
].includes(method)) for (const registrationPath of route
|
|
229
|
+
].includes(method)) for (const registrationPath of this.resolveRegistrationPaths(route)) app.route({
|
|
224
230
|
method: "POST",
|
|
225
231
|
url: registrationPath,
|
|
226
232
|
preHandler: route.middlewares,
|
|
@@ -232,10 +238,13 @@ var Router = class Router extends CoreRouter {
|
|
|
232
238
|
reply
|
|
233
239
|
};
|
|
234
240
|
const inst = instance ?? route;
|
|
241
|
+
const params = Router.matchRoute(route, ctx, ctx.req.params ?? {});
|
|
242
|
+
if (params === false) return reply.code(404).send();
|
|
243
|
+
Object.assign(ctx.req.params ??= {}, params);
|
|
235
244
|
Router.bindRequestToInstance(ctx, inst, route, {
|
|
236
245
|
body: ctx.req.getBody(),
|
|
237
246
|
query: ctx.req.query ?? {},
|
|
238
|
-
params
|
|
247
|
+
params,
|
|
239
248
|
method
|
|
240
249
|
});
|
|
241
250
|
const result = await Router.callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata);
|
package/dist/h3/router.cjs
CHANGED
|
@@ -11,6 +11,9 @@ let h3 = require("h3");
|
|
|
11
11
|
*/
|
|
12
12
|
var Router = class Router extends require_CoreRouter.CoreRouter {
|
|
13
13
|
static routerStateNamespace = "clear-router:h3";
|
|
14
|
+
static formatWildcardParam(name) {
|
|
15
|
+
return `**:${name}`;
|
|
16
|
+
}
|
|
14
17
|
static bodyCache = /* @__PURE__ */ new WeakMap();
|
|
15
18
|
static toResponse(ctx, value, method, path) {
|
|
16
19
|
const meta = require_responses.resolveResponseMeta(value, {
|
|
@@ -205,17 +208,20 @@ var Router = class Router extends require_CoreRouter.CoreRouter {
|
|
|
205
208
|
console.error("[ROUTES]", error.message);
|
|
206
209
|
throw error;
|
|
207
210
|
}
|
|
208
|
-
for (const registrationPath of route
|
|
211
|
+
for (const registrationPath of this.resolveRegistrationPaths(route)) app[method](registrationPath, async (event) => {
|
|
209
212
|
try {
|
|
210
213
|
const ctx = event;
|
|
211
214
|
const reqBody = await Router.readBodyCached(ctx);
|
|
212
215
|
const override = Router.resolveMethodOverride(ctx.req.method, ctx.req.headers, reqBody);
|
|
213
216
|
if (method === "post" && override && override !== "post") return;
|
|
214
217
|
const inst = instance ?? route;
|
|
218
|
+
const params = Router.matchRoute(route, ctx, (0, h3.getRouterParams)(ctx, { decode: true }));
|
|
219
|
+
if (params === false) return Symbol.for("h3.notFound");
|
|
220
|
+
ctx.context = Object.assign(ctx.context ?? {}, { params });
|
|
215
221
|
Router.bindRequestToInstance(ctx, inst, route, {
|
|
216
222
|
body: reqBody,
|
|
217
223
|
query: (0, h3.getQuery)(ctx),
|
|
218
|
-
params
|
|
224
|
+
params,
|
|
219
225
|
method
|
|
220
226
|
});
|
|
221
227
|
const result = await Router.callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata);
|
|
@@ -230,16 +236,19 @@ var Router = class Router extends require_CoreRouter.CoreRouter {
|
|
|
230
236
|
"put",
|
|
231
237
|
"patch",
|
|
232
238
|
"delete"
|
|
233
|
-
].includes(method)) for (const registrationPath of route
|
|
239
|
+
].includes(method)) for (const registrationPath of this.resolveRegistrationPaths(route)) app.post(registrationPath, async (event) => {
|
|
234
240
|
try {
|
|
235
241
|
const ctx = event;
|
|
236
242
|
const reqBody = await Router.readBodyCached(ctx);
|
|
237
243
|
if (Router.resolveMethodOverride(ctx.req.method, ctx.req.headers, reqBody) !== method) return Symbol.for("h3.notFound");
|
|
238
244
|
const inst = instance ?? route;
|
|
245
|
+
const params = Router.matchRoute(route, ctx, (0, h3.getRouterParams)(ctx, { decode: true }));
|
|
246
|
+
if (params === false) return Symbol.for("h3.notFound");
|
|
247
|
+
ctx.context = Object.assign(ctx.context ?? {}, { params });
|
|
239
248
|
Router.bindRequestToInstance(ctx, inst, route, {
|
|
240
249
|
body: reqBody,
|
|
241
250
|
query: (0, h3.getQuery)(ctx),
|
|
242
|
-
params
|
|
251
|
+
params,
|
|
243
252
|
method
|
|
244
253
|
});
|
|
245
254
|
const result = await Router.callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata);
|
package/dist/h3/router.d.cts
CHANGED
|
@@ -15,6 +15,7 @@ import { H3 } from "h3";
|
|
|
15
15
|
*/
|
|
16
16
|
declare class Router extends CoreRouter {
|
|
17
17
|
protected static routerStateNamespace: string;
|
|
18
|
+
protected static formatWildcardParam(name: string): string;
|
|
18
19
|
private static readonly bodyCache;
|
|
19
20
|
private static toResponse;
|
|
20
21
|
private static readBodyCached;
|
package/dist/h3/router.d.mts
CHANGED
|
@@ -15,6 +15,7 @@ import { H3 } from "h3";
|
|
|
15
15
|
*/
|
|
16
16
|
declare class Router extends CoreRouter {
|
|
17
17
|
protected static routerStateNamespace: string;
|
|
18
|
+
protected static formatWildcardParam(name: string): string;
|
|
18
19
|
private static readonly bodyCache;
|
|
19
20
|
private static toResponse;
|
|
20
21
|
private static readBodyCached;
|
package/dist/h3/router.mjs
CHANGED
|
@@ -11,6 +11,9 @@ import { HTTPResponse, getQuery, getRouterParams, readBody } from "h3";
|
|
|
11
11
|
*/
|
|
12
12
|
var Router = class Router extends CoreRouter {
|
|
13
13
|
static routerStateNamespace = "clear-router:h3";
|
|
14
|
+
static formatWildcardParam(name) {
|
|
15
|
+
return `**:${name}`;
|
|
16
|
+
}
|
|
14
17
|
static bodyCache = /* @__PURE__ */ new WeakMap();
|
|
15
18
|
static toResponse(ctx, value, method, path) {
|
|
16
19
|
const meta = resolveResponseMeta(value, {
|
|
@@ -205,17 +208,20 @@ var Router = class Router extends CoreRouter {
|
|
|
205
208
|
console.error("[ROUTES]", error.message);
|
|
206
209
|
throw error;
|
|
207
210
|
}
|
|
208
|
-
for (const registrationPath of route
|
|
211
|
+
for (const registrationPath of this.resolveRegistrationPaths(route)) app[method](registrationPath, async (event) => {
|
|
209
212
|
try {
|
|
210
213
|
const ctx = event;
|
|
211
214
|
const reqBody = await Router.readBodyCached(ctx);
|
|
212
215
|
const override = Router.resolveMethodOverride(ctx.req.method, ctx.req.headers, reqBody);
|
|
213
216
|
if (method === "post" && override && override !== "post") return;
|
|
214
217
|
const inst = instance ?? route;
|
|
218
|
+
const params = Router.matchRoute(route, ctx, getRouterParams(ctx, { decode: true }));
|
|
219
|
+
if (params === false) return Symbol.for("h3.notFound");
|
|
220
|
+
ctx.context = Object.assign(ctx.context ?? {}, { params });
|
|
215
221
|
Router.bindRequestToInstance(ctx, inst, route, {
|
|
216
222
|
body: reqBody,
|
|
217
223
|
query: getQuery(ctx),
|
|
218
|
-
params
|
|
224
|
+
params,
|
|
219
225
|
method
|
|
220
226
|
});
|
|
221
227
|
const result = await Router.callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata);
|
|
@@ -230,16 +236,19 @@ var Router = class Router extends CoreRouter {
|
|
|
230
236
|
"put",
|
|
231
237
|
"patch",
|
|
232
238
|
"delete"
|
|
233
|
-
].includes(method)) for (const registrationPath of route
|
|
239
|
+
].includes(method)) for (const registrationPath of this.resolveRegistrationPaths(route)) app.post(registrationPath, async (event) => {
|
|
234
240
|
try {
|
|
235
241
|
const ctx = event;
|
|
236
242
|
const reqBody = await Router.readBodyCached(ctx);
|
|
237
243
|
if (Router.resolveMethodOverride(ctx.req.method, ctx.req.headers, reqBody) !== method) return Symbol.for("h3.notFound");
|
|
238
244
|
const inst = instance ?? route;
|
|
245
|
+
const params = Router.matchRoute(route, ctx, getRouterParams(ctx, { decode: true }));
|
|
246
|
+
if (params === false) return Symbol.for("h3.notFound");
|
|
247
|
+
ctx.context = Object.assign(ctx.context ?? {}, { params });
|
|
239
248
|
Router.bindRequestToInstance(ctx, inst, route, {
|
|
240
249
|
body: reqBody,
|
|
241
250
|
query: getQuery(ctx),
|
|
242
|
-
params
|
|
251
|
+
params,
|
|
243
252
|
method
|
|
244
253
|
});
|
|
245
254
|
const result = await Router.callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata);
|
package/dist/hono/router.cjs
CHANGED
|
@@ -10,6 +10,9 @@ const require_responses = require('../core/responses.cjs');
|
|
|
10
10
|
*/
|
|
11
11
|
var Router = class Router extends require_CoreRouter.CoreRouter {
|
|
12
12
|
static routerStateNamespace = "clear-router:hono";
|
|
13
|
+
static formatWildcardParam(name) {
|
|
14
|
+
return `:${name}{.+}`;
|
|
15
|
+
}
|
|
13
16
|
static bodyCache = /* @__PURE__ */ new WeakMap();
|
|
14
17
|
static toResponse(ctx, value, method, path) {
|
|
15
18
|
const meta = require_responses.resolveResponseMeta(value, {
|
|
@@ -204,16 +207,18 @@ var Router = class Router extends require_CoreRouter.CoreRouter {
|
|
|
204
207
|
];
|
|
205
208
|
if (method === "options" && route.methods.length > 1) continue;
|
|
206
209
|
if (!allowedMethods.includes(method)) throw new Error(`Invalid HTTP method: ${method} for route: ${route.path}`);
|
|
207
|
-
for (const registrationPath of route
|
|
210
|
+
for (const registrationPath of this.resolveRegistrationPaths(route)) app[method](registrationPath, ...route.middlewares || [], async (context) => {
|
|
208
211
|
const ctx = context;
|
|
209
212
|
const reqBody = await Router.readBodyCached(ctx);
|
|
210
213
|
const override = Router.resolveMethodOverride(ctx.req.method, ctx.req.header(), reqBody);
|
|
211
214
|
if (method === "post" && override && override !== "post") return;
|
|
212
215
|
const inst = instance ?? route;
|
|
216
|
+
const params = Router.matchRoute(route, ctx, Router.getParams(ctx));
|
|
217
|
+
if (params === false) return ctx.notFound();
|
|
213
218
|
Router.bindRequestToInstance(ctx, inst, route, {
|
|
214
219
|
body: reqBody,
|
|
215
220
|
query: ctx.req.query(),
|
|
216
|
-
params
|
|
221
|
+
params,
|
|
217
222
|
method
|
|
218
223
|
});
|
|
219
224
|
const result = await Router.callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata);
|
|
@@ -225,15 +230,17 @@ var Router = class Router extends require_CoreRouter.CoreRouter {
|
|
|
225
230
|
"put",
|
|
226
231
|
"patch",
|
|
227
232
|
"delete"
|
|
228
|
-
].includes(method)) for (const registrationPath of route
|
|
233
|
+
].includes(method)) for (const registrationPath of this.resolveRegistrationPaths(route)) app.post(registrationPath, ...route.middlewares || [], async (context) => {
|
|
229
234
|
const ctx = context;
|
|
230
235
|
const reqBody = await Router.readBodyCached(ctx);
|
|
231
236
|
if (Router.resolveMethodOverride(ctx.req.method, ctx.req.header(), reqBody) !== method) return;
|
|
232
237
|
const inst = instance ?? route;
|
|
238
|
+
const params = Router.matchRoute(route, ctx, Router.getParams(ctx));
|
|
239
|
+
if (params === false) return ctx.notFound();
|
|
233
240
|
Router.bindRequestToInstance(ctx, inst, route, {
|
|
234
241
|
body: reqBody,
|
|
235
242
|
query: ctx.req.query(),
|
|
236
|
-
params
|
|
243
|
+
params,
|
|
237
244
|
method
|
|
238
245
|
});
|
|
239
246
|
const result = await Router.callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata);
|
package/dist/hono/router.d.cts
CHANGED
|
@@ -14,6 +14,7 @@ import { CoreRouter } from "../core/CoreRouter.cjs";
|
|
|
14
14
|
*/
|
|
15
15
|
declare class Router extends CoreRouter {
|
|
16
16
|
protected static routerStateNamespace: string;
|
|
17
|
+
protected static formatWildcardParam(name: string): string;
|
|
17
18
|
private static readonly bodyCache;
|
|
18
19
|
private static toResponse;
|
|
19
20
|
private static getParams;
|
package/dist/hono/router.d.mts
CHANGED
|
@@ -14,6 +14,7 @@ import { CoreRouter } from "../core/CoreRouter.mjs";
|
|
|
14
14
|
*/
|
|
15
15
|
declare class Router extends CoreRouter {
|
|
16
16
|
protected static routerStateNamespace: string;
|
|
17
|
+
protected static formatWildcardParam(name: string): string;
|
|
17
18
|
private static readonly bodyCache;
|
|
18
19
|
private static toResponse;
|
|
19
20
|
private static getParams;
|
package/dist/hono/router.mjs
CHANGED
|
@@ -10,6 +10,9 @@ import { resolveResponseMeta } from "../core/responses.mjs";
|
|
|
10
10
|
*/
|
|
11
11
|
var Router = class Router extends CoreRouter {
|
|
12
12
|
static routerStateNamespace = "clear-router:hono";
|
|
13
|
+
static formatWildcardParam(name) {
|
|
14
|
+
return `:${name}{.+}`;
|
|
15
|
+
}
|
|
13
16
|
static bodyCache = /* @__PURE__ */ new WeakMap();
|
|
14
17
|
static toResponse(ctx, value, method, path) {
|
|
15
18
|
const meta = resolveResponseMeta(value, {
|
|
@@ -204,16 +207,18 @@ var Router = class Router extends CoreRouter {
|
|
|
204
207
|
];
|
|
205
208
|
if (method === "options" && route.methods.length > 1) continue;
|
|
206
209
|
if (!allowedMethods.includes(method)) throw new Error(`Invalid HTTP method: ${method} for route: ${route.path}`);
|
|
207
|
-
for (const registrationPath of route
|
|
210
|
+
for (const registrationPath of this.resolveRegistrationPaths(route)) app[method](registrationPath, ...route.middlewares || [], async (context) => {
|
|
208
211
|
const ctx = context;
|
|
209
212
|
const reqBody = await Router.readBodyCached(ctx);
|
|
210
213
|
const override = Router.resolveMethodOverride(ctx.req.method, ctx.req.header(), reqBody);
|
|
211
214
|
if (method === "post" && override && override !== "post") return;
|
|
212
215
|
const inst = instance ?? route;
|
|
216
|
+
const params = Router.matchRoute(route, ctx, Router.getParams(ctx));
|
|
217
|
+
if (params === false) return ctx.notFound();
|
|
213
218
|
Router.bindRequestToInstance(ctx, inst, route, {
|
|
214
219
|
body: reqBody,
|
|
215
220
|
query: ctx.req.query(),
|
|
216
|
-
params
|
|
221
|
+
params,
|
|
217
222
|
method
|
|
218
223
|
});
|
|
219
224
|
const result = await Router.callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata);
|
|
@@ -225,15 +230,17 @@ var Router = class Router extends CoreRouter {
|
|
|
225
230
|
"put",
|
|
226
231
|
"patch",
|
|
227
232
|
"delete"
|
|
228
|
-
].includes(method)) for (const registrationPath of route
|
|
233
|
+
].includes(method)) for (const registrationPath of this.resolveRegistrationPaths(route)) app.post(registrationPath, ...route.middlewares || [], async (context) => {
|
|
229
234
|
const ctx = context;
|
|
230
235
|
const reqBody = await Router.readBodyCached(ctx);
|
|
231
236
|
if (Router.resolveMethodOverride(ctx.req.method, ctx.req.header(), reqBody) !== method) return;
|
|
232
237
|
const inst = instance ?? route;
|
|
238
|
+
const params = Router.matchRoute(route, ctx, Router.getParams(ctx));
|
|
239
|
+
if (params === false) return ctx.notFound();
|
|
233
240
|
Router.bindRequestToInstance(ctx, inst, route, {
|
|
234
241
|
body: reqBody,
|
|
235
242
|
query: ctx.req.query(),
|
|
236
|
-
params
|
|
243
|
+
params,
|
|
237
244
|
method
|
|
238
245
|
});
|
|
239
246
|
const result = await Router.callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata);
|
package/dist/index.cjs
CHANGED
|
@@ -4,6 +4,7 @@ const require_Controller = require('./Controller.cjs');
|
|
|
4
4
|
const require_Route = require('./Route.cjs');
|
|
5
5
|
const require_helpers = require('./core/helpers.cjs');
|
|
6
6
|
const require_RouteGroup = require('./RouteGroup.cjs');
|
|
7
|
+
const require_RouteRegistrar = require('./RouteRegistrar.cjs');
|
|
7
8
|
const require_Request = require('./core/Request.cjs');
|
|
8
9
|
const require_Response = require('./core/Response.cjs');
|
|
9
10
|
const require_plugins = require('./core/plugins.cjs');
|
|
@@ -17,6 +18,8 @@ exports.Request = require_Request.Request;
|
|
|
17
18
|
exports.Response = require_Response.Response;
|
|
18
19
|
exports.Route = require_Route.Route;
|
|
19
20
|
exports.RouteGroup = require_RouteGroup.RouteGroup;
|
|
21
|
+
exports.RouteRegistrar = require_RouteRegistrar.RouteRegistrar;
|
|
20
22
|
exports.definePlugin = require_plugins.definePlugin;
|
|
21
23
|
exports.importFile = require_helpers.importFile;
|
|
24
|
+
exports.parseDomainParameters = require_Route.parseDomainParameters;
|
|
22
25
|
exports.wrap = require_helpers.wrap;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { ClearHttpContext, RouteParameter } from "./Contracts.cjs";
|
|
2
2
|
import { Response } from "./core/Response.cjs";
|
|
3
3
|
import { ClearRequest } from "./ClearRequest.cjs";
|
|
4
|
-
import { Route } from "./Route.cjs";
|
|
4
|
+
import { Route, parseDomainParameters } from "./Route.cjs";
|
|
5
5
|
import { Request } from "./core/Request.cjs";
|
|
6
6
|
import { ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, definePlugin } from "./core/plugins.cjs";
|
|
7
7
|
import { Controller } from "./Controller.cjs";
|
|
8
8
|
import { RouteGroup } from "./RouteGroup.cjs";
|
|
9
|
+
import { RouteRegistrar, RouteRegistrarGroupFactory } from "./RouteRegistrar.cjs";
|
|
9
10
|
import { CoreRouter } from "./core/CoreRouter.cjs";
|
|
10
11
|
import { importFile, wrap } from "./core/helpers.cjs";
|
|
11
|
-
export { ClearHttpContext, ClearRequest, ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, Controller, CoreRouter, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response, Route, RouteGroup, RouteParameter, definePlugin, importFile, wrap };
|
|
12
|
+
export { ClearHttpContext, ClearRequest, ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, Controller, CoreRouter, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response, Route, RouteGroup, RouteParameter, RouteRegistrar, RouteRegistrarGroupFactory, definePlugin, importFile, parseDomainParameters, wrap };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { ClearHttpContext, RouteParameter } from "./Contracts.mjs";
|
|
2
2
|
import { Response } from "./core/Response.mjs";
|
|
3
3
|
import { ClearRequest } from "./ClearRequest.mjs";
|
|
4
|
-
import { Route } from "./Route.mjs";
|
|
4
|
+
import { Route, parseDomainParameters } from "./Route.mjs";
|
|
5
5
|
import { Request } from "./core/Request.mjs";
|
|
6
6
|
import { ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, definePlugin } from "./core/plugins.mjs";
|
|
7
7
|
import { Controller } from "./Controller.mjs";
|
|
8
8
|
import { RouteGroup } from "./RouteGroup.mjs";
|
|
9
|
+
import { RouteRegistrar, RouteRegistrarGroupFactory } from "./RouteRegistrar.mjs";
|
|
9
10
|
import { CoreRouter } from "./core/CoreRouter.mjs";
|
|
10
11
|
import { importFile, wrap } from "./core/helpers.mjs";
|
|
11
|
-
export { ClearHttpContext, ClearRequest, ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, Controller, CoreRouter, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response, Route, RouteGroup, RouteParameter, definePlugin, importFile, wrap };
|
|
12
|
+
export { ClearHttpContext, ClearRequest, ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, Controller, CoreRouter, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response, Route, RouteGroup, RouteParameter, RouteRegistrar, RouteRegistrarGroupFactory, definePlugin, importFile, parseDomainParameters, wrap };
|
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { ClearRequest } from "./ClearRequest.mjs";
|
|
2
2
|
import { Controller } from "./Controller.mjs";
|
|
3
|
-
import { Route } from "./Route.mjs";
|
|
3
|
+
import { Route, parseDomainParameters } from "./Route.mjs";
|
|
4
4
|
import { importFile, wrap } from "./core/helpers.mjs";
|
|
5
5
|
import { RouteGroup } from "./RouteGroup.mjs";
|
|
6
|
+
import { RouteRegistrar } from "./RouteRegistrar.mjs";
|
|
6
7
|
import { Request } from "./core/Request.mjs";
|
|
7
8
|
import { Response } from "./core/Response.mjs";
|
|
8
9
|
import { definePlugin } from "./core/plugins.mjs";
|
|
9
10
|
import { CoreRouter } from "./core/CoreRouter.mjs";
|
|
10
11
|
import "./core/index.mjs";
|
|
11
12
|
|
|
12
|
-
export { ClearRequest, Controller, CoreRouter, Request, Response, Route, RouteGroup, definePlugin, importFile, wrap };
|
|
13
|
+
export { ClearRequest, Controller, CoreRouter, Request, Response, Route, RouteGroup, RouteRegistrar, definePlugin, importFile, parseDomainParameters, wrap };
|
package/dist/koa/router.cjs
CHANGED
|
@@ -10,6 +10,9 @@ const require_responses = require('../core/responses.cjs');
|
|
|
10
10
|
*/
|
|
11
11
|
var Router = class Router extends require_CoreRouter.CoreRouter {
|
|
12
12
|
static routerStateNamespace = "clear-router:koa";
|
|
13
|
+
static formatWildcardParam(name) {
|
|
14
|
+
return `*${name}`;
|
|
15
|
+
}
|
|
13
16
|
static bodyCache = /* @__PURE__ */ new WeakMap();
|
|
14
17
|
static async readBodyCached(ctx) {
|
|
15
18
|
if (this.bodyCache.has(ctx)) {
|
|
@@ -214,16 +217,19 @@ var Router = class Router extends require_CoreRouter.CoreRouter {
|
|
|
214
217
|
];
|
|
215
218
|
if (method === "options" && route.methods.length > 1) continue;
|
|
216
219
|
if (!allowedMethods.includes(method)) throw new Error(`Invalid HTTP method: ${method} for route: ${route.path}`);
|
|
217
|
-
for (const registrationPath of route
|
|
220
|
+
for (const registrationPath of this.resolveRegistrationPaths(route)) router[method](registrationPath, ...route.middlewares || [], async (context, next) => {
|
|
218
221
|
const ctx = context;
|
|
219
222
|
const reqBody = await Router.readBodyCached(ctx);
|
|
220
223
|
const override = Router.resolveMethodOverride(ctx.method, ctx.headers, reqBody);
|
|
221
224
|
if (method === "post" && override && override !== "post") return next();
|
|
222
225
|
const inst = instance ?? route;
|
|
226
|
+
const params = Router.matchRoute(route, ctx, ctx.params ?? {});
|
|
227
|
+
if (params === false) return next();
|
|
228
|
+
Object.assign(ctx.params ??= {}, params);
|
|
223
229
|
Router.bindRequestToInstance(ctx, inst, route, {
|
|
224
230
|
body: reqBody,
|
|
225
231
|
query: ctx.query,
|
|
226
|
-
params
|
|
232
|
+
params,
|
|
227
233
|
method
|
|
228
234
|
});
|
|
229
235
|
const result = await Router.callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata);
|
|
@@ -235,15 +241,18 @@ var Router = class Router extends require_CoreRouter.CoreRouter {
|
|
|
235
241
|
"put",
|
|
236
242
|
"patch",
|
|
237
243
|
"delete"
|
|
238
|
-
].includes(method)) for (const registrationPath of route
|
|
244
|
+
].includes(method)) for (const registrationPath of this.resolveRegistrationPaths(route)) router.post(registrationPath, ...route.middlewares || [], async (context, next) => {
|
|
239
245
|
const ctx = context;
|
|
240
246
|
const reqBody = await Router.readBodyCached(ctx);
|
|
241
247
|
if (Router.resolveMethodOverride(ctx.method, ctx.headers, reqBody) !== method) return next();
|
|
242
248
|
const inst = instance ?? route;
|
|
249
|
+
const params = Router.matchRoute(route, ctx, ctx.params ?? {});
|
|
250
|
+
if (params === false) return next();
|
|
251
|
+
Object.assign(ctx.params ??= {}, params);
|
|
243
252
|
Router.bindRequestToInstance(ctx, inst, route, {
|
|
244
253
|
body: reqBody,
|
|
245
254
|
query: ctx.query,
|
|
246
|
-
params
|
|
255
|
+
params,
|
|
247
256
|
method
|
|
248
257
|
});
|
|
249
258
|
const result = await Router.callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata);
|
package/dist/koa/router.d.cts
CHANGED
|
@@ -14,6 +14,7 @@ import { CoreRouter } from "../core/CoreRouter.cjs";
|
|
|
14
14
|
*/
|
|
15
15
|
declare class Router extends CoreRouter {
|
|
16
16
|
protected static routerStateNamespace: string;
|
|
17
|
+
protected static formatWildcardParam(name: string): string;
|
|
17
18
|
private static readonly bodyCache;
|
|
18
19
|
private static readBodyCached;
|
|
19
20
|
private static readBody;
|
package/dist/koa/router.d.mts
CHANGED
|
@@ -14,6 +14,7 @@ import { CoreRouter } from "../core/CoreRouter.mjs";
|
|
|
14
14
|
*/
|
|
15
15
|
declare class Router extends CoreRouter {
|
|
16
16
|
protected static routerStateNamespace: string;
|
|
17
|
+
protected static formatWildcardParam(name: string): string;
|
|
17
18
|
private static readonly bodyCache;
|
|
18
19
|
private static readBodyCached;
|
|
19
20
|
private static readBody;
|
package/dist/koa/router.mjs
CHANGED
|
@@ -10,6 +10,9 @@ import { isFetchResponse, resolveResponseMeta } from "../core/responses.mjs";
|
|
|
10
10
|
*/
|
|
11
11
|
var Router = class Router extends CoreRouter {
|
|
12
12
|
static routerStateNamespace = "clear-router:koa";
|
|
13
|
+
static formatWildcardParam(name) {
|
|
14
|
+
return `*${name}`;
|
|
15
|
+
}
|
|
13
16
|
static bodyCache = /* @__PURE__ */ new WeakMap();
|
|
14
17
|
static async readBodyCached(ctx) {
|
|
15
18
|
if (this.bodyCache.has(ctx)) {
|
|
@@ -214,16 +217,19 @@ var Router = class Router extends CoreRouter {
|
|
|
214
217
|
];
|
|
215
218
|
if (method === "options" && route.methods.length > 1) continue;
|
|
216
219
|
if (!allowedMethods.includes(method)) throw new Error(`Invalid HTTP method: ${method} for route: ${route.path}`);
|
|
217
|
-
for (const registrationPath of route
|
|
220
|
+
for (const registrationPath of this.resolveRegistrationPaths(route)) router[method](registrationPath, ...route.middlewares || [], async (context, next) => {
|
|
218
221
|
const ctx = context;
|
|
219
222
|
const reqBody = await Router.readBodyCached(ctx);
|
|
220
223
|
const override = Router.resolveMethodOverride(ctx.method, ctx.headers, reqBody);
|
|
221
224
|
if (method === "post" && override && override !== "post") return next();
|
|
222
225
|
const inst = instance ?? route;
|
|
226
|
+
const params = Router.matchRoute(route, ctx, ctx.params ?? {});
|
|
227
|
+
if (params === false) return next();
|
|
228
|
+
Object.assign(ctx.params ??= {}, params);
|
|
223
229
|
Router.bindRequestToInstance(ctx, inst, route, {
|
|
224
230
|
body: reqBody,
|
|
225
231
|
query: ctx.query,
|
|
226
|
-
params
|
|
232
|
+
params,
|
|
227
233
|
method
|
|
228
234
|
});
|
|
229
235
|
const result = await Router.callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata);
|
|
@@ -235,15 +241,18 @@ var Router = class Router extends CoreRouter {
|
|
|
235
241
|
"put",
|
|
236
242
|
"patch",
|
|
237
243
|
"delete"
|
|
238
|
-
].includes(method)) for (const registrationPath of route
|
|
244
|
+
].includes(method)) for (const registrationPath of this.resolveRegistrationPaths(route)) router.post(registrationPath, ...route.middlewares || [], async (context, next) => {
|
|
239
245
|
const ctx = context;
|
|
240
246
|
const reqBody = await Router.readBodyCached(ctx);
|
|
241
247
|
if (Router.resolveMethodOverride(ctx.method, ctx.headers, reqBody) !== method) return next();
|
|
242
248
|
const inst = instance ?? route;
|
|
249
|
+
const params = Router.matchRoute(route, ctx, ctx.params ?? {});
|
|
250
|
+
if (params === false) return next();
|
|
251
|
+
Object.assign(ctx.params ??= {}, params);
|
|
243
252
|
Router.bindRequestToInstance(ctx, inst, route, {
|
|
244
253
|
body: reqBody,
|
|
245
254
|
query: ctx.query,
|
|
246
|
-
params
|
|
255
|
+
params,
|
|
247
256
|
method
|
|
248
257
|
});
|
|
249
258
|
const result = await Router.callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata);
|