clear-router 2.8.9 → 2.9.1
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/README.md +15 -1
- 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 +1 -0
- package/dist/RouteGroup.mjs +1 -0
- 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 +309 -0
- package/dist/core/CoreRouter.d.cts +168 -0
- package/dist/core/CoreRouter.d.mts +168 -0
- package/dist/core/CoreRouter.mjs +309 -0
- package/dist/core/index.cjs +3 -0
- package/dist/core/index.d.cts +2 -1
- package/dist/core/index.d.mts +2 -1
- package/dist/core/index.mjs +2 -1
- package/dist/decorators/index.cjs +4 -1
- package/dist/decorators/index.d.cts +2 -1
- package/dist/decorators/index.d.mts +2 -1
- package/dist/decorators/index.mjs +2 -1
- package/dist/decorators/middleware.cjs +100 -0
- package/dist/decorators/middleware.d.cts +51 -0
- package/dist/decorators/middleware.d.mts +51 -0
- package/dist/decorators/middleware.mjs +98 -0
- package/dist/decorators/setup.cjs +4 -1
- package/dist/decorators/setup.d.cts +2 -1
- package/dist/decorators/setup.d.mts +2 -2
- package/dist/decorators/setup.mjs +2 -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 +6 -0
- package/dist/index.d.cts +4 -2
- package/dist/index.d.mts +4 -3
- package/dist/index.mjs +4 -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 +1 -1
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,9 +4,11 @@ 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');
|
|
11
|
+
const require_middleware = require('./decorators/middleware.cjs');
|
|
10
12
|
const require_CoreRouter = require('./core/CoreRouter.cjs');
|
|
11
13
|
require('./core/index.cjs');
|
|
12
14
|
|
|
@@ -17,6 +19,10 @@ exports.Request = require_Request.Request;
|
|
|
17
19
|
exports.Response = require_Response.Response;
|
|
18
20
|
exports.Route = require_Route.Route;
|
|
19
21
|
exports.RouteGroup = require_RouteGroup.RouteGroup;
|
|
22
|
+
exports.RouteRegistrar = require_RouteRegistrar.RouteRegistrar;
|
|
20
23
|
exports.definePlugin = require_plugins.definePlugin;
|
|
24
|
+
exports.getControllerMiddlewares = require_middleware.getControllerMiddlewares;
|
|
21
25
|
exports.importFile = require_helpers.importFile;
|
|
26
|
+
exports.middleware = require_middleware.middleware;
|
|
27
|
+
exports.parseDomainParameters = require_Route.parseDomainParameters;
|
|
22
28
|
exports.wrap = require_helpers.wrap;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
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
|
+
import { MiddlewareDecorator, MiddlewareInput, getControllerMiddlewares, middleware } from "./decorators/middleware.cjs";
|
|
7
8
|
import { Controller } from "./Controller.cjs";
|
|
8
9
|
import { RouteGroup } from "./RouteGroup.cjs";
|
|
10
|
+
import { RouteRegistrar, RouteRegistrarGroupFactory } from "./RouteRegistrar.cjs";
|
|
9
11
|
import { CoreRouter } from "./core/CoreRouter.cjs";
|
|
10
12
|
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 };
|
|
13
|
+
export { ClearHttpContext, ClearRequest, ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, Controller, CoreRouter, MiddlewareDecorator, MiddlewareInput, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response, Route, RouteGroup, RouteParameter, RouteRegistrar, RouteRegistrarGroupFactory, definePlugin, getControllerMiddlewares, importFile, middleware, parseDomainParameters, wrap };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
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
|
+
import { MiddlewareDecorator, MiddlewareInput, getControllerMiddlewares, middleware } from "./decorators/middleware.mjs";
|
|
7
8
|
import { Controller } from "./Controller.mjs";
|
|
8
9
|
import { RouteGroup } from "./RouteGroup.mjs";
|
|
10
|
+
import { RouteRegistrar, RouteRegistrarGroupFactory } from "./RouteRegistrar.mjs";
|
|
9
11
|
import { CoreRouter } from "./core/CoreRouter.mjs";
|
|
10
12
|
import { importFile, wrap } from "./core/helpers.mjs";
|
|
11
|
-
|
|
12
|
-
export { ClearHttpContext, ClearRequest, ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, Controller, CoreRouter, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response, Route, RouteGroup, RouteParameter, definePlugin, importFile, wrap };
|
|
13
|
+
export { ClearHttpContext, ClearRequest, ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, Controller, CoreRouter, MiddlewareDecorator, MiddlewareInput, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response, Route, RouteGroup, RouteParameter, RouteRegistrar, RouteRegistrarGroupFactory, definePlugin, getControllerMiddlewares, importFile, middleware, parseDomainParameters, wrap };
|
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
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";
|
|
10
|
+
import { getControllerMiddlewares, middleware } from "./decorators/middleware.mjs";
|
|
9
11
|
import { CoreRouter } from "./core/CoreRouter.mjs";
|
|
10
12
|
import "./core/index.mjs";
|
|
11
13
|
|
|
12
|
-
export { ClearRequest, Controller, CoreRouter, Request, Response, Route, RouteGroup, definePlugin, importFile, wrap };
|
|
14
|
+
export { ClearRequest, Controller, CoreRouter, Request, Response, Route, RouteGroup, RouteRegistrar, definePlugin, getControllerMiddlewares, importFile, middleware, 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);
|
package/dist/types/basic.d.cts
CHANGED
|
@@ -79,12 +79,14 @@ type ResourceRoutesOptions<M = any> = {
|
|
|
79
79
|
interface RouteGroupContext {
|
|
80
80
|
prefix: string;
|
|
81
81
|
groupMiddlewares: any[];
|
|
82
|
+
domain?: string;
|
|
82
83
|
routeCollectors?: Array<Set<Route<any, any, any>>>;
|
|
83
84
|
}
|
|
84
85
|
interface RouteGroupOptions<S extends RouteGroupSource = RouteGroupSource> {
|
|
85
86
|
prefix: string;
|
|
86
87
|
source: S;
|
|
87
88
|
middlewares?: any[];
|
|
89
|
+
domain?: string;
|
|
88
90
|
context: AsyncLocalStorage<RouteGroupContext>;
|
|
89
91
|
defaultPrefix: string;
|
|
90
92
|
defaultMiddlewares: any[];
|
package/dist/types/basic.d.mts
CHANGED
|
@@ -79,12 +79,14 @@ type ResourceRoutesOptions<M = any> = {
|
|
|
79
79
|
interface RouteGroupContext {
|
|
80
80
|
prefix: string;
|
|
81
81
|
groupMiddlewares: any[];
|
|
82
|
+
domain?: string;
|
|
82
83
|
routeCollectors?: Array<Set<Route<any, any, any>>>;
|
|
83
84
|
}
|
|
84
85
|
interface RouteGroupOptions<S extends RouteGroupSource = RouteGroupSource> {
|
|
85
86
|
prefix: string;
|
|
86
87
|
source: S;
|
|
87
88
|
middlewares?: any[];
|
|
89
|
+
domain?: string;
|
|
88
90
|
context: AsyncLocalStorage<RouteGroupContext>;
|
|
89
91
|
defaultPrefix: string;
|
|
90
92
|
defaultMiddlewares: any[];
|
package/package.json
CHANGED