clear-router 2.7.5 → 2.7.7
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/ClearRequest.cjs +23 -0
- package/dist/ClearRequest.d.cts +28 -0
- package/dist/ClearRequest.d.mts +28 -0
- package/dist/ClearRequest.mjs +22 -0
- package/dist/Contracts.d.cts +12 -0
- package/dist/Contracts.d.mts +12 -0
- package/dist/Controller.cjs +12 -0
- package/dist/Controller.d.cts +14 -0
- package/dist/Controller.d.mts +14 -0
- package/dist/Controller.mjs +11 -0
- package/dist/{Request-DKXwa_W0.d.mts → Request-BhTJDR_5.d.mts} +5 -5
- package/dist/Route.cjs +58 -0
- package/dist/Route.d.cts +35 -0
- package/dist/Route.d.mts +35 -0
- package/dist/Route.mjs +57 -0
- package/dist/core/Request.cjs +35 -0
- package/dist/core/Request.d.cts +25 -0
- package/dist/core/Request.d.mts +25 -0
- package/dist/core/Request.mjs +35 -0
- package/dist/core/Response.cjs +59 -0
- package/dist/core/Response.d.cts +24 -0
- package/dist/core/Response.d.mts +24 -0
- package/dist/core/Response.mjs +58 -0
- package/dist/{bindings-CLsZjOEy.cjs → core/bindings.cjs} +10 -160
- package/dist/{bindings-CNL7bpz5.d.mts → core/bindings.d.cts} +1 -1
- package/dist/{bindings-CxvtC8XS.d.cts → core/bindings.d.mts} +1 -1
- package/dist/{bindings-XLDXFpHZ.mjs → core/bindings.mjs} +3 -110
- package/dist/core/index.cjs +4 -20
- package/dist/core/index.d.cts +4 -1
- package/dist/core/index.d.mts +4 -1
- package/dist/core/index.mjs +4 -14
- package/dist/core/plugins.cjs +14 -0
- package/dist/core/plugins.d.cts +109 -0
- package/dist/core/plugins.d.mts +109 -0
- package/dist/core/plugins.mjs +13 -0
- package/dist/{responses-Bvnk0uvc.cjs → core/responses.cjs} +5 -20
- package/dist/{responses-BvETUeDL.mjs → core/responses.mjs} +2 -2
- package/dist/{router-C6W-k6sS.cjs → core/router.cjs} +11 -69
- package/dist/core/router.d.cts +274 -0
- package/dist/core/router.d.mts +274 -0
- package/dist/{router-Dc9w86Wn.mjs → core/router.mjs} +5 -58
- package/dist/decorators/index.cjs +1 -1
- package/dist/decorators/index.d.cts +1 -1
- package/dist/decorators/index.d.mts +1 -1
- package/dist/decorators/index.mjs +1 -1
- package/dist/decorators/setup.cjs +2 -2
- package/dist/decorators/setup.d.cts +1 -1
- package/dist/decorators/setup.d.mts +1 -1
- package/dist/decorators/setup.mjs +2 -2
- package/dist/express/index.cjs +2 -265
- package/dist/express/index.d.cts +1 -127
- package/dist/express/index.d.mts +1 -127
- package/dist/express/index.mjs +1 -264
- package/dist/express/router.cjs +265 -0
- package/dist/express/router.d.cts +131 -0
- package/dist/express/router.d.mts +131 -0
- package/dist/express/router.mjs +265 -0
- package/dist/fastify/index.cjs +2 -254
- package/dist/fastify/index.d.cts +1 -125
- package/dist/fastify/index.d.mts +1 -125
- package/dist/fastify/index.mjs +1 -253
- package/dist/fastify/router.cjs +254 -0
- package/dist/fastify/router.d.cts +129 -0
- package/dist/fastify/router.d.mts +129 -0
- package/dist/fastify/router.mjs +254 -0
- package/dist/h3/index.cjs +2 -260
- package/dist/h3/index.d.cts +1 -128
- package/dist/h3/index.d.mts +1 -128
- package/dist/h3/index.mjs +1 -259
- package/dist/h3/router.cjs +260 -0
- package/dist/h3/router.d.cts +132 -0
- package/dist/h3/router.d.mts +132 -0
- package/dist/h3/router.mjs +260 -0
- package/dist/hono/index.cjs +2 -251
- package/dist/hono/index.d.cts +1 -130
- package/dist/hono/index.d.mts +1 -130
- package/dist/hono/index.mjs +1 -250
- package/dist/hono/router.cjs +251 -0
- package/dist/hono/router.d.cts +134 -0
- package/dist/hono/router.d.mts +134 -0
- package/dist/hono/router.mjs +251 -0
- package/dist/index.cjs +16 -1097
- package/dist/index.d.cts +9 -563
- package/dist/index.d.mts +9 -563
- package/dist/index.mjs +8 -1089
- package/dist/koa/index.cjs +2 -261
- package/dist/koa/index.d.cts +1 -131
- package/dist/koa/index.d.mts +1 -131
- package/dist/koa/index.mjs +1 -260
- package/dist/koa/router.cjs +261 -0
- package/dist/koa/router.d.cts +135 -0
- package/dist/koa/router.d.mts +135 -0
- package/dist/koa/router.mjs +261 -0
- package/dist/types/basic.d.cts +43 -0
- package/dist/types/express.d.cts +44 -0
- package/dist/types/express.d.mts +4 -2
- package/dist/types/fastify.d.cts +23 -0
- package/dist/types/fastify.d.mts +4 -2
- package/dist/types/h3.d.cts +41 -0
- package/dist/types/h3.d.mts +5 -6
- package/dist/types/hono.d.cts +21 -0
- package/dist/types/hono.d.mts +5 -5
- package/dist/types/koa.d.cts +25 -0
- package/dist/types/koa.d.mts +5 -5
- package/package.json +1 -1
- package/dist/router-CYBshGMl.d.mts +0 -652
- package/dist/router-tpnSi_Y7.d.cts +0 -652
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_Response = require('./Response.cjs');
|
|
2
2
|
|
|
3
3
|
//#region src/core/responses.ts
|
|
4
4
|
function isFetchResponse(value) {
|
|
5
5
|
return typeof globalThis.Response !== "undefined" && value instanceof globalThis.Response;
|
|
6
6
|
}
|
|
7
7
|
function isCoreResponse(value) {
|
|
8
|
-
return value instanceof
|
|
8
|
+
return value instanceof require_Response.Response;
|
|
9
9
|
}
|
|
10
10
|
function isH3Response(value) {
|
|
11
11
|
return Boolean(value && typeof value === "object" && value.constructor?.name === "HTTPResponse");
|
|
@@ -88,21 +88,6 @@ function inferStringContentType(value, apiRequest) {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
//#endregion
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return isFetchResponse;
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
Object.defineProperty(exports, 'resolveResponseMeta', {
|
|
98
|
-
enumerable: true,
|
|
99
|
-
get: function () {
|
|
100
|
-
return resolveResponseMeta;
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
Object.defineProperty(exports, 'responseWasSent', {
|
|
104
|
-
enumerable: true,
|
|
105
|
-
get: function () {
|
|
106
|
-
return responseWasSent;
|
|
107
|
-
}
|
|
108
|
-
});
|
|
91
|
+
exports.isFetchResponse = isFetchResponse;
|
|
92
|
+
exports.resolveResponseMeta = resolveResponseMeta;
|
|
93
|
+
exports.responseWasSent = responseWasSent;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Response } from "./Response.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/core/responses.ts
|
|
4
4
|
function isFetchResponse(value) {
|
|
@@ -88,4 +88,4 @@ function inferStringContentType(value, apiRequest) {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
//#endregion
|
|
91
|
-
export { resolveResponseMeta
|
|
91
|
+
export { isFetchResponse, resolveResponseMeta, responseWasSent };
|
|
@@ -1,63 +1,10 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_Request = require('./Request.cjs');
|
|
2
|
+
const require_Response = require('./Response.cjs');
|
|
3
|
+
const require_bindings = require('./bindings.cjs');
|
|
4
|
+
const require_Route = require('../Route.cjs');
|
|
2
5
|
let node_async_hooks = require("node:async_hooks");
|
|
3
6
|
let node_module = require("node:module");
|
|
4
7
|
|
|
5
|
-
//#region src/Route.ts
|
|
6
|
-
var Route = class {
|
|
7
|
-
ctx;
|
|
8
|
-
body = {};
|
|
9
|
-
query = {};
|
|
10
|
-
params = {};
|
|
11
|
-
clearRequest;
|
|
12
|
-
methods;
|
|
13
|
-
path;
|
|
14
|
-
registrationPaths;
|
|
15
|
-
parameters;
|
|
16
|
-
routeName;
|
|
17
|
-
handler;
|
|
18
|
-
middlewares;
|
|
19
|
-
controllerName;
|
|
20
|
-
actionName;
|
|
21
|
-
handlerType;
|
|
22
|
-
middlewareCount;
|
|
23
|
-
constructor(methods, path, handler, middlewares = [], options = {}) {
|
|
24
|
-
this.methods = methods;
|
|
25
|
-
this.path = path;
|
|
26
|
-
this.registrationPaths = options.registrationPaths || [path];
|
|
27
|
-
this.parameters = options.parameters || [];
|
|
28
|
-
this.handler = handler;
|
|
29
|
-
this.middlewares = middlewares;
|
|
30
|
-
this.handlerType = Array.isArray(handler) ? "controller" : "function";
|
|
31
|
-
this.middlewareCount = middlewares.length;
|
|
32
|
-
this.controllerName = Array.isArray(handler) ? handler[0]?.name : void 0;
|
|
33
|
-
this.actionName = Array.isArray(handler) ? handler[1] : typeof handler === "function" ? handler.constructor.name ?? handler.name : void 0;
|
|
34
|
-
this.onName = options.onName;
|
|
35
|
-
}
|
|
36
|
-
onName;
|
|
37
|
-
name(name) {
|
|
38
|
-
const previousName = this.routeName;
|
|
39
|
-
this.routeName = name;
|
|
40
|
-
this.onName?.(name, this, previousName);
|
|
41
|
-
return this;
|
|
42
|
-
}
|
|
43
|
-
toPath(params = {}) {
|
|
44
|
-
return this.path.replace(/\/?\{([^{}]+)\}/g, (segment, raw) => {
|
|
45
|
-
const optional = raw.endsWith("?");
|
|
46
|
-
const [rawName, rawField] = (optional ? raw.slice(0, -1) : raw).split(":", 2);
|
|
47
|
-
const name = rawName.trim();
|
|
48
|
-
const field = rawField?.trim();
|
|
49
|
-
const value = params[name];
|
|
50
|
-
const resolved = field && value && typeof value === "object" ? value[field] : value;
|
|
51
|
-
if (typeof resolved === "undefined" || resolved === null || resolved === "") {
|
|
52
|
-
if (optional) return "";
|
|
53
|
-
throw new Error(`Missing required route parameter: ${name}`);
|
|
54
|
-
}
|
|
55
|
-
return `${segment.startsWith("/") ? "/" : ""}${encodeURIComponent(String(resolved))}`;
|
|
56
|
-
}) || "/";
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
//#endregion
|
|
61
8
|
//#region src/core/router.ts
|
|
62
9
|
/**
|
|
63
10
|
* @class clear-router CoreRouter
|
|
@@ -509,7 +456,7 @@ var CoreRouter = class {
|
|
|
509
456
|
const fullPath = this.normalizePath(`${activePrefix}/${path}`);
|
|
510
457
|
const registrationPaths = this.routeRegistrationPaths(fullPath);
|
|
511
458
|
const parameters = this.parseRouteParameters(fullPath);
|
|
512
|
-
const route = new Route(methods.includes("options") ? methods : methods.concat("options"), fullPath, handler, [
|
|
459
|
+
const route = new require_Route.Route(methods.includes("options") ? methods : methods.concat("options"), fullPath, handler, [
|
|
513
460
|
...this.globalMiddlewares,
|
|
514
461
|
...activeGroupMiddlewares,
|
|
515
462
|
...middlewares || []
|
|
@@ -823,7 +770,7 @@ var CoreRouter = class {
|
|
|
823
770
|
});
|
|
824
771
|
}
|
|
825
772
|
static bindRequestToInstance(ctx, instance, route, payload) {
|
|
826
|
-
const clearRequest = ctx.clearRequest instanceof
|
|
773
|
+
const clearRequest = ctx.clearRequest instanceof require_Request.Request ? ctx.clearRequest : this.initializeInstance(require_Request.Request, {
|
|
827
774
|
ctx,
|
|
828
775
|
route,
|
|
829
776
|
body: payload.body,
|
|
@@ -841,10 +788,10 @@ var CoreRouter = class {
|
|
|
841
788
|
clearRequest.query = payload.query;
|
|
842
789
|
clearRequest.params = payload.params;
|
|
843
790
|
ctx.clearRequest = clearRequest;
|
|
844
|
-
require_bindings.Container.bind(
|
|
845
|
-
if (!(ctx.clearResponse instanceof
|
|
846
|
-
ctx.clearResponse = this.initializeInstance(
|
|
847
|
-
require_bindings.Container.bind(
|
|
791
|
+
require_bindings.Container.bind(require_Request.Request, ctx.clearRequest);
|
|
792
|
+
if (!(ctx.clearResponse instanceof require_Response.Response)) {
|
|
793
|
+
ctx.clearResponse = this.initializeInstance(require_Response.Response, ctx.response ?? ctx.reply ?? ctx.res);
|
|
794
|
+
require_bindings.Container.bind(require_Response.Response, ctx.clearResponse);
|
|
848
795
|
}
|
|
849
796
|
if (!instance) return;
|
|
850
797
|
instance.ctx = ctx;
|
|
@@ -856,9 +803,4 @@ var CoreRouter = class {
|
|
|
856
803
|
};
|
|
857
804
|
|
|
858
805
|
//#endregion
|
|
859
|
-
|
|
860
|
-
enumerable: true,
|
|
861
|
-
get: function () {
|
|
862
|
-
return CoreRouter;
|
|
863
|
-
}
|
|
864
|
-
});
|
|
806
|
+
exports.CoreRouter = CoreRouter;
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { ApiResourceMiddleware, ControllerAction, HttpMethod, RouterConfig } from "../types/basic.cjs";
|
|
2
|
+
import { Response } from "./Response.cjs";
|
|
3
|
+
import { Route } from "../Route.cjs";
|
|
4
|
+
import { Request } from "./Request.cjs";
|
|
5
|
+
import { ClearRouterPluginArgumentsContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, PluginArgumentsResolver, PluginBind } from "./plugins.cjs";
|
|
6
|
+
import { Controller } from "../Controller.cjs";
|
|
7
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
8
|
+
|
|
9
|
+
//#region src/core/router.d.ts
|
|
10
|
+
/**
|
|
11
|
+
* @class clear-router CoreRouter
|
|
12
|
+
* @description Core routing logic for clear-router, shared between all supported adapters (Express.js, H3, etc.)
|
|
13
|
+
* @author 3m1n3nc3
|
|
14
|
+
* @repository https://github.com/arkstack-tmp/clear-router
|
|
15
|
+
*/
|
|
16
|
+
declare abstract class CoreRouter {
|
|
17
|
+
protected static routerStateNamespace: string;
|
|
18
|
+
private static readonly stateStoreKey;
|
|
19
|
+
private static readonly stateBoundKey;
|
|
20
|
+
private static readonly defaultConfigKey;
|
|
21
|
+
private static readonly pluginStoreKey;
|
|
22
|
+
private static readonly pluginPendingKey;
|
|
23
|
+
private static readonly pluginHttpCtxResolversKey;
|
|
24
|
+
private static readonly pluginArgumentResolversKey;
|
|
25
|
+
private static requestProvider?;
|
|
26
|
+
private static responseProvider?;
|
|
27
|
+
static config: RouterConfig;
|
|
28
|
+
protected static groupContext: AsyncLocalStorage<{
|
|
29
|
+
prefix: string;
|
|
30
|
+
groupMiddlewares: any[];
|
|
31
|
+
}>;
|
|
32
|
+
protected static pluginRequestContext: AsyncLocalStorage<ClearRouterPluginRequestContext<any>>;
|
|
33
|
+
static routes: Set<Route<any, any, any>>;
|
|
34
|
+
static routesByPathMethod: Map<string, Route<any, any, any>>;
|
|
35
|
+
static routesByMethod: Map<"GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "OPTIONS" | "HEAD", Route<any, any, any>[]>;
|
|
36
|
+
static routesByName: Map<string, Route<any, any, any>>;
|
|
37
|
+
static prefix: string;
|
|
38
|
+
static groupMiddlewares: any[];
|
|
39
|
+
static globalMiddlewares: any[];
|
|
40
|
+
/**
|
|
41
|
+
* Resets the router to it's default state
|
|
42
|
+
*/
|
|
43
|
+
static reset(): typeof CoreRouter;
|
|
44
|
+
protected static createBaseConfig(): RouterConfig;
|
|
45
|
+
protected static mergeConfig(target: RouterConfig, source?: RouterConfig): RouterConfig;
|
|
46
|
+
protected static getDefaultConfig(): RouterConfig;
|
|
47
|
+
protected static resolveStateNamespace(): string;
|
|
48
|
+
protected static getStateStore(): Record<string, any>;
|
|
49
|
+
protected static getPluginStore(): Set<string>;
|
|
50
|
+
protected static getPluginPendingStore(): Set<Promise<void>>;
|
|
51
|
+
protected static getPluginArgumentResolvers(): Set<PluginArgumentsResolver>;
|
|
52
|
+
protected static getPluginHttpCtxResolvers(): Set<PluginArgumentsResolver>;
|
|
53
|
+
protected static createDefaultState(): {
|
|
54
|
+
config: RouterConfig;
|
|
55
|
+
groupContext: AsyncLocalStorage<{
|
|
56
|
+
prefix: string;
|
|
57
|
+
groupMiddlewares: any[];
|
|
58
|
+
}>;
|
|
59
|
+
routes: Set<never>;
|
|
60
|
+
routesByPathMethod: Map<any, any>;
|
|
61
|
+
routesByMethod: Map<any, any>;
|
|
62
|
+
routesByName: Map<any, any>;
|
|
63
|
+
prefix: string;
|
|
64
|
+
groupMiddlewares: any[];
|
|
65
|
+
globalMiddlewares: any[];
|
|
66
|
+
};
|
|
67
|
+
protected static bindStateAccessors(): void;
|
|
68
|
+
protected static createDefaultOptionsHandler(): any;
|
|
69
|
+
/**
|
|
70
|
+
* Default configuration used for everytime the router is reset
|
|
71
|
+
*
|
|
72
|
+
* @param options
|
|
73
|
+
*/
|
|
74
|
+
static configureDefaults(options?: RouterConfig): void;
|
|
75
|
+
/**
|
|
76
|
+
* Use a registered plugin
|
|
77
|
+
*
|
|
78
|
+
* @param this
|
|
79
|
+
* @param plugin
|
|
80
|
+
* @param options
|
|
81
|
+
* @returns
|
|
82
|
+
*/
|
|
83
|
+
static use<Options = any>(plugin: ClearRouterPluginInput<Options>, options?: Options): Promise<void>;
|
|
84
|
+
protected static pluginsReady(): Promise<void>;
|
|
85
|
+
protected static getCurrentPluginRequestContext(): ClearRouterPluginRequestContext | undefined;
|
|
86
|
+
protected static createPluginRequestContext(ctx: any): ClearRouterPluginRequestContext;
|
|
87
|
+
protected static createPluginBind(): PluginBind;
|
|
88
|
+
protected static resolvePluginArguments(ctx: any, routeContext: Omit<ClearRouterPluginArgumentsContext, keyof ClearRouterPluginRequestContext>): Promise<any[] | undefined>;
|
|
89
|
+
protected static resolvePluginHttpCtx(ctx: any): Promise<void>;
|
|
90
|
+
protected static ensureState(): void;
|
|
91
|
+
/**
|
|
92
|
+
* Normalizes a path by ensuring it starts with a single slash and does not have trailing
|
|
93
|
+
* slashes, while preserving dynamic segments and parameters.
|
|
94
|
+
*
|
|
95
|
+
* @param path The path to normalize.
|
|
96
|
+
* @returns The normalized path.
|
|
97
|
+
*/
|
|
98
|
+
static normalizePath(path: string): string;
|
|
99
|
+
protected static parseRouteParameters(path: string): Array<{
|
|
100
|
+
name: string;
|
|
101
|
+
field?: string;
|
|
102
|
+
optional: boolean;
|
|
103
|
+
}>;
|
|
104
|
+
protected static expandRoutePath(path: string): string[];
|
|
105
|
+
protected static routeRegistrationPaths(path: string): string[];
|
|
106
|
+
/**
|
|
107
|
+
* Configures the router with the given options, such as method override settings.
|
|
108
|
+
*
|
|
109
|
+
* @param this
|
|
110
|
+
* @param options
|
|
111
|
+
* @returns
|
|
112
|
+
*/
|
|
113
|
+
static configure(this: any, options?: RouterConfig): void;
|
|
114
|
+
protected static resolveMethodOverride(method: string, headers: Headers | Record<string, any>, body: unknown): HttpMethod | null;
|
|
115
|
+
/**
|
|
116
|
+
* Adds a new route to the router.
|
|
117
|
+
*
|
|
118
|
+
* @param this
|
|
119
|
+
* @param methods
|
|
120
|
+
* @param path
|
|
121
|
+
* @param handler
|
|
122
|
+
* @param middlewares
|
|
123
|
+
*/
|
|
124
|
+
static add(methods: HttpMethod | HttpMethod[], path: string, handler: any, middlewares?: any[] | any): Route<any, any, any>;
|
|
125
|
+
/**
|
|
126
|
+
* Define a resourceful API controller with standard CRUD routes.
|
|
127
|
+
*
|
|
128
|
+
* @param this
|
|
129
|
+
* @param basePath
|
|
130
|
+
* @param controller
|
|
131
|
+
* @param options
|
|
132
|
+
*/
|
|
133
|
+
static apiResource(basePath: string, controller: any, options?: {
|
|
134
|
+
only?: ControllerAction[];
|
|
135
|
+
except?: ControllerAction[];
|
|
136
|
+
middlewares?: ApiResourceMiddleware<any>;
|
|
137
|
+
}): void;
|
|
138
|
+
/**
|
|
139
|
+
* Adds a new GET route to the router.
|
|
140
|
+
*
|
|
141
|
+
* @param this The router instance.
|
|
142
|
+
* @param path The path for the GET route.
|
|
143
|
+
* @param handler The handler function for the GET route.
|
|
144
|
+
* @param middlewares Optional middlewares to apply to the GET route.
|
|
145
|
+
*/
|
|
146
|
+
static get(path: string, handler: any, middlewares?: any[] | any): Route<any, any, any>;
|
|
147
|
+
/**
|
|
148
|
+
* Adds a new POST route to the router.
|
|
149
|
+
*
|
|
150
|
+
* @param this
|
|
151
|
+
* @param path
|
|
152
|
+
* @param handler
|
|
153
|
+
* @param middlewares
|
|
154
|
+
*/
|
|
155
|
+
static post(path: string, handler: any, middlewares?: any[] | any): Route<any, any, any>;
|
|
156
|
+
/**
|
|
157
|
+
* Adds a new PUT route to the router.
|
|
158
|
+
*
|
|
159
|
+
* @param this
|
|
160
|
+
* @param path
|
|
161
|
+
* @param handler
|
|
162
|
+
* @param middlewares
|
|
163
|
+
*/
|
|
164
|
+
static put(path: string, handler: any, middlewares?: any[] | any): Route<any, any, any>;
|
|
165
|
+
/**
|
|
166
|
+
* Adds a new DELETE route to the router.
|
|
167
|
+
*
|
|
168
|
+
* @param this
|
|
169
|
+
* @param path
|
|
170
|
+
* @param handler
|
|
171
|
+
* @param middlewares
|
|
172
|
+
*/
|
|
173
|
+
static delete(path: string, handler: any, middlewares?: any[] | any): Route<any, any, any>;
|
|
174
|
+
/**
|
|
175
|
+
* Adds a new PATCH route to the router.
|
|
176
|
+
*
|
|
177
|
+
* @param this
|
|
178
|
+
* @param path
|
|
179
|
+
* @param handler
|
|
180
|
+
* @param middlewares
|
|
181
|
+
*/
|
|
182
|
+
static patch(path: string, handler: any, middlewares?: any[] | any): Route<any, any, any>;
|
|
183
|
+
/**
|
|
184
|
+
* Adds a new OPTIONS route to the router.
|
|
185
|
+
*
|
|
186
|
+
* @param this
|
|
187
|
+
* @param path
|
|
188
|
+
* @param handler
|
|
189
|
+
* @param middlewares
|
|
190
|
+
*/
|
|
191
|
+
static options(path: string, handler: any, middlewares?: any[] | any): Route<any, any, any>;
|
|
192
|
+
/**
|
|
193
|
+
* Adds a new HEAD route to the router.
|
|
194
|
+
*
|
|
195
|
+
* @param this
|
|
196
|
+
* @param path
|
|
197
|
+
* @param handler
|
|
198
|
+
* @param middlewares
|
|
199
|
+
*/
|
|
200
|
+
static head(path: string, handler: any, middlewares?: any[] | any): Route<any, any, any>;
|
|
201
|
+
/**
|
|
202
|
+
* Defines a group of routes with a common prefix.
|
|
203
|
+
*
|
|
204
|
+
* @param this
|
|
205
|
+
* @param prefix
|
|
206
|
+
* @param callback
|
|
207
|
+
* @param middlewares
|
|
208
|
+
*/
|
|
209
|
+
static group(prefix: string, callback: () => void | Promise<void>, middlewares?: any[]): Promise<void>;
|
|
210
|
+
/**
|
|
211
|
+
* Adds global middlewares to the router, which will be applied to all routes.
|
|
212
|
+
*
|
|
213
|
+
* @param this
|
|
214
|
+
* @param middlewares
|
|
215
|
+
* @param callback
|
|
216
|
+
*/
|
|
217
|
+
static middleware(middlewares: any[], callback: () => void): void;
|
|
218
|
+
/**
|
|
219
|
+
* Retrieves all registered routes in the router, optionally organized by path or method
|
|
220
|
+
* for easier access and management.
|
|
221
|
+
*
|
|
222
|
+
* @param this
|
|
223
|
+
*/
|
|
224
|
+
static allRoutes(): Array<Route<any, any, any>>;
|
|
225
|
+
/**
|
|
226
|
+
* @param this
|
|
227
|
+
* @param type - 'path' to get routes organized by path
|
|
228
|
+
*/
|
|
229
|
+
static allRoutes(type: 'path'): Record<string, Route<any, any, any>>;
|
|
230
|
+
/**
|
|
231
|
+
* @param this
|
|
232
|
+
* @param type - 'method' to get routes organized by method
|
|
233
|
+
*/
|
|
234
|
+
static allRoutes(type: 'method'): { [method in Uppercase<HttpMethod>]?: Array<Route<any, any, any>> };
|
|
235
|
+
static allRoutes(type: 'name'): Record<string, Route<any, any, any>>;
|
|
236
|
+
static route(name: string): Route<any, any, any> | undefined;
|
|
237
|
+
static url(name: string, params?: Record<string, any>): string | undefined;
|
|
238
|
+
/**
|
|
239
|
+
* Provide a class that will overide the base Request instance
|
|
240
|
+
*
|
|
241
|
+
* @param provider
|
|
242
|
+
*/
|
|
243
|
+
static setRequestProvider(provider: typeof Request): void;
|
|
244
|
+
/**
|
|
245
|
+
* Provide a class that will overide the base Response instance
|
|
246
|
+
*
|
|
247
|
+
* @param provider
|
|
248
|
+
*/
|
|
249
|
+
static setResponseProvider(provider: typeof Response): void;
|
|
250
|
+
private static hasPackageInstalled;
|
|
251
|
+
/**
|
|
252
|
+
* Provide a class that will overide the base Response instance
|
|
253
|
+
*
|
|
254
|
+
* @param provider
|
|
255
|
+
*/
|
|
256
|
+
private static initializeInstance;
|
|
257
|
+
protected static resolveHandler(route: Route<any, any, any>): {
|
|
258
|
+
handlerFunction: ((ctx: any, req: Request) => any | Promise<any>) | null;
|
|
259
|
+
instance: Controller<any> | null;
|
|
260
|
+
bindingTarget?: object;
|
|
261
|
+
bindingMethod?: PropertyKey;
|
|
262
|
+
bindingHandler?: object;
|
|
263
|
+
bindingMetadata?: object;
|
|
264
|
+
};
|
|
265
|
+
protected static callHandler(handlerFunction: (ctx: any, req: Request) => any | Promise<any>, ctx: any, bindingTarget?: object, bindingMethod?: PropertyKey, bindingHandler?: object, bindingMetadata?: object): Promise<any>;
|
|
266
|
+
protected static bindRequestToInstance(ctx: any, instance: Controller<any> | Route<any, any, any> | null, route: Route<any, any, any>, payload: {
|
|
267
|
+
body: Record<string, any>;
|
|
268
|
+
query: Record<string, any>;
|
|
269
|
+
params: Record<string, any>;
|
|
270
|
+
method?: HttpMethod | string;
|
|
271
|
+
}): void;
|
|
272
|
+
}
|
|
273
|
+
//#endregion
|
|
274
|
+
export { CoreRouter };
|