@noxfly/noxus 1.1.1 → 1.1.2
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/noxus.d.mts +344 -30
- package/dist/noxus.d.ts +344 -30
- package/dist/noxus.js +5 -1208
- package/dist/noxus.mjs +5 -1130
- package/dist/noxus.mjs.map +1 -1
- package/package.json +1 -1
- package/src/DI/app-injector.ts +38 -10
- package/src/DI/injector-explorer.ts +9 -7
- package/src/app.ts +40 -7
- package/src/bootstrap.ts +6 -1
- package/src/decorators/controller.decorator.ts +18 -3
- package/src/decorators/guards.decorator.ts +25 -5
- package/src/decorators/injectable.decorator.ts +16 -3
- package/src/decorators/method.decorator.ts +65 -11
- package/src/decorators/middleware.decorator.ts +34 -4
- package/src/decorators/module.decorator.ts +17 -11
- package/src/request.ts +14 -0
- package/src/router.ts +76 -19
- package/src/utils/logger.ts +109 -31
- package/src/utils/radix-tree.ts +71 -4
- package/src/utils/types.ts +8 -3
- package/tsup.config.ts +2 -2
package/dist/noxus.d.mts
CHANGED
|
@@ -6,15 +6,36 @@
|
|
|
6
6
|
interface Type<T> extends Function {
|
|
7
7
|
new (...args: any[]): T;
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Represents a generic type that can be either a value or a promise resolving to that value.
|
|
11
|
+
*/
|
|
9
12
|
type MaybeAsync<T> = T | Promise<T>;
|
|
10
13
|
|
|
11
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Represents a lifetime of a binding in the dependency injection system.
|
|
17
|
+
* It can be one of the following:
|
|
18
|
+
* - 'singleton': The instance is created once and shared across the application.
|
|
19
|
+
* - 'scope': The instance is created once per scope (e.g., per request).
|
|
20
|
+
* - 'transient': A new instance is created every time it is requested.
|
|
21
|
+
*/
|
|
12
22
|
type Lifetime = 'singleton' | 'scope' | 'transient';
|
|
23
|
+
/**
|
|
24
|
+
* Represents a binding in the dependency injection system.
|
|
25
|
+
* It contains the lifetime of the binding, the implementation type, and optionally an instance.
|
|
26
|
+
*/
|
|
13
27
|
interface IBinding {
|
|
14
28
|
lifetime: Lifetime;
|
|
15
29
|
implementation: Type<unknown>;
|
|
16
30
|
instance?: InstanceType<Type<unknown>>;
|
|
17
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* AppInjector is the root dependency injection container.
|
|
34
|
+
* It is used to register and resolve dependencies in the application.
|
|
35
|
+
* It supports different lifetimes for dependencies:
|
|
36
|
+
* This should not be manually instantiated, outside of the framework.
|
|
37
|
+
* Use the `RootInjector` instance instead.
|
|
38
|
+
*/
|
|
18
39
|
declare class AppInjector {
|
|
19
40
|
readonly name: string | null;
|
|
20
41
|
bindings: Map<Type<unknown>, IBinding>;
|
|
@@ -22,13 +43,15 @@ declare class AppInjector {
|
|
|
22
43
|
scoped: Map<Type<unknown>, unknown>;
|
|
23
44
|
constructor(name?: string | null);
|
|
24
45
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
46
|
+
* Typically used to create a dependency injection scope
|
|
47
|
+
* at the "scope" level (i.e., per-request lifetime).
|
|
48
|
+
*
|
|
49
|
+
* SHOULD NOT BE USED by anything else than the framework itself.
|
|
27
50
|
*/
|
|
28
51
|
createScope(): AppInjector;
|
|
29
52
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
53
|
+
* Called when resolving a dependency,
|
|
54
|
+
* i.e., retrieving the instance of a given class.
|
|
32
55
|
*/
|
|
33
56
|
resolve<T extends Type<unknown>>(target: T): InstanceType<T>;
|
|
34
57
|
/**
|
|
@@ -36,26 +59,84 @@ declare class AppInjector {
|
|
|
36
59
|
*/
|
|
37
60
|
private instantiate;
|
|
38
61
|
}
|
|
39
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Injects a type from the dependency injection system.
|
|
64
|
+
* This function is used to retrieve an instance of a type that has been registered in the dependency injection system.
|
|
65
|
+
* It is typically used in the constructor of a class to inject dependencies.
|
|
66
|
+
* @param t - The type to inject.
|
|
67
|
+
* @returns An instance of the type.
|
|
68
|
+
* @throws If the type is not registered in the dependency injection system.
|
|
69
|
+
*/
|
|
40
70
|
declare function inject<T>(t: Type<T>): T;
|
|
71
|
+
declare const RootInjector: AppInjector;
|
|
41
72
|
|
|
42
73
|
|
|
74
|
+
/**
|
|
75
|
+
* IRouteMetadata interface defines the metadata for a route.
|
|
76
|
+
* It includes the HTTP method, path, handler name, and guards associated with the route.
|
|
77
|
+
* This metadata is used to register the route in the application.
|
|
78
|
+
* This is the configuration that waits a route's decorator.
|
|
79
|
+
*/
|
|
43
80
|
interface IRouteMetadata {
|
|
44
81
|
method: HttpMethod;
|
|
45
82
|
path: string;
|
|
46
83
|
handler: string;
|
|
47
84
|
guards: Type<IGuard>[];
|
|
48
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* The different HTTP methods that can be used in the application.
|
|
88
|
+
*/
|
|
49
89
|
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
90
|
+
/**
|
|
91
|
+
* Gets the route metadata for a given target class.
|
|
92
|
+
* This metadata includes the HTTP method, path, handler, and guards defined by the route decorators.
|
|
93
|
+
* @see Get
|
|
94
|
+
* @see Post
|
|
95
|
+
* @see Put
|
|
96
|
+
* @see Patch
|
|
97
|
+
* @see Delete
|
|
98
|
+
* @param target The target class to get the route metadata from.
|
|
99
|
+
* @returns An array of route metadata if it exists, otherwise an empty array.
|
|
100
|
+
*/
|
|
101
|
+
declare function getRouteMetadata(target: Type<unknown>): IRouteMetadata[];
|
|
102
|
+
/**
|
|
103
|
+
* Route decorator that defines a leaf in the routing tree, attaching it to a controller method
|
|
104
|
+
* that will be called when the route is matched.
|
|
105
|
+
* This route will have to be called with the GET method.
|
|
106
|
+
*/
|
|
50
107
|
declare const Get: (path: string) => MethodDecorator;
|
|
108
|
+
/**
|
|
109
|
+
* Route decorator that defines a leaf in the routing tree, attaching it to a controller method
|
|
110
|
+
* that will be called when the route is matched.
|
|
111
|
+
* This route will have to be called with the POST method.
|
|
112
|
+
*/
|
|
51
113
|
declare const Post: (path: string) => MethodDecorator;
|
|
114
|
+
/**
|
|
115
|
+
* Route decorator that defines a leaf in the routing tree, attaching it to a controller method
|
|
116
|
+
* that will be called when the route is matched.
|
|
117
|
+
* This route will have to be called with the PUT method.
|
|
118
|
+
*/
|
|
52
119
|
declare const Put: (path: string) => MethodDecorator;
|
|
120
|
+
/**
|
|
121
|
+
* Route decorator that defines a leaf in the routing tree, attaching it to a controller method
|
|
122
|
+
* that will be called when the route is matched.
|
|
123
|
+
* This route will have to be called with the PATCH method.
|
|
124
|
+
*/
|
|
53
125
|
declare const Patch: (path: string) => MethodDecorator;
|
|
126
|
+
/**
|
|
127
|
+
* Route decorator that defines a leaf in the routing tree, attaching it to a controller method
|
|
128
|
+
* that will be called when the route is matched.
|
|
129
|
+
* This route will have to be called with the DELETE method.
|
|
130
|
+
*/
|
|
54
131
|
declare const Delete: (path: string) => MethodDecorator;
|
|
55
132
|
declare const ROUTE_METADATA_KEY: unique symbol;
|
|
56
|
-
declare function getRouteMetadata(target: Type<unknown>): IRouteMetadata[];
|
|
57
133
|
|
|
58
134
|
|
|
135
|
+
/**
|
|
136
|
+
* The Request class represents an HTTP request in the Noxus framework.
|
|
137
|
+
* It encapsulates the request data, including the event, ID, method, path, and body.
|
|
138
|
+
* It also provides a context for dependency injection through the AppInjector.
|
|
139
|
+
*/
|
|
59
140
|
declare class Request {
|
|
60
141
|
readonly event: Electron.MessageEvent;
|
|
61
142
|
readonly id: string;
|
|
@@ -66,6 +147,11 @@ declare class Request {
|
|
|
66
147
|
readonly params: Record<string, string>;
|
|
67
148
|
constructor(event: Electron.MessageEvent, id: string, method: HttpMethod, path: string, body: any);
|
|
68
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* The IRequest interface defines the structure of a request object.
|
|
152
|
+
* It includes properties for the sender ID, request ID, path, method, and an optional body.
|
|
153
|
+
* This interface is used to standardize the request data across the application.
|
|
154
|
+
*/
|
|
69
155
|
interface IRequest<T = any> {
|
|
70
156
|
senderId: number;
|
|
71
157
|
requestId: string;
|
|
@@ -73,6 +159,10 @@ interface IRequest<T = any> {
|
|
|
73
159
|
method: HttpMethod;
|
|
74
160
|
body?: T;
|
|
75
161
|
}
|
|
162
|
+
/**
|
|
163
|
+
* Creates a Request object from the IPC event data.
|
|
164
|
+
* This function extracts the necessary information from the IPC event and constructs a Request instance.
|
|
165
|
+
*/
|
|
76
166
|
interface IResponse<T = any> {
|
|
77
167
|
requestId: string;
|
|
78
168
|
status: number;
|
|
@@ -81,27 +171,84 @@ interface IResponse<T = any> {
|
|
|
81
171
|
}
|
|
82
172
|
|
|
83
173
|
|
|
174
|
+
/**
|
|
175
|
+
* IGuard interface defines a guard that can be used to protect routes.
|
|
176
|
+
* It has a `canActivate` method that takes a request and returns a MaybeAsync boolean.
|
|
177
|
+
* The `canActivate` method can return either a value or a Promise.
|
|
178
|
+
* Use it on a class that should be registered as a guard in the application.
|
|
179
|
+
* Guards can be used to protect routes or controller actions.
|
|
180
|
+
* For example, you can use guards to check if the user is authenticated or has the right permissions.
|
|
181
|
+
* You can use the `Authorize` decorator to register guards for a controller or a controller action.
|
|
182
|
+
* @see Authorize
|
|
183
|
+
*/
|
|
84
184
|
interface IGuard {
|
|
85
185
|
canActivate(request: Request): MaybeAsync<boolean>;
|
|
86
186
|
}
|
|
87
187
|
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
188
|
+
* Can be used to protect the routes of a controller.
|
|
189
|
+
* Can be used on a controller class or on a controller method.
|
|
90
190
|
*/
|
|
91
191
|
declare function Authorize(...guardClasses: Type<IGuard>[]): MethodDecorator & ClassDecorator;
|
|
192
|
+
/**
|
|
193
|
+
* Gets the guards for a controller or a controller action.
|
|
194
|
+
* @param controllerName The name of the controller to get the guards for.
|
|
195
|
+
* @returns An array of guards for the controller.
|
|
196
|
+
*/
|
|
92
197
|
declare function getGuardForController(controllerName: string): Type<IGuard>[];
|
|
198
|
+
/**
|
|
199
|
+
* Gets the guards for a controller action.
|
|
200
|
+
* @param controllerName The name of the controller to get the guards for.
|
|
201
|
+
* @param actionName The name of the action to get the guards for.
|
|
202
|
+
* @returns An array of guards for the controller action.
|
|
203
|
+
*/
|
|
93
204
|
declare function getGuardForControllerAction(controllerName: string, actionName: string): Type<IGuard>[];
|
|
94
205
|
|
|
95
206
|
|
|
207
|
+
/**
|
|
208
|
+
* NextFunction is a function that is called to continue the middleware chain.
|
|
209
|
+
* It returns an Promise that emits when the next middleware is done.
|
|
210
|
+
*/
|
|
96
211
|
type NextFunction = () => Promise<void>;
|
|
212
|
+
/**
|
|
213
|
+
* IMiddleware interface defines a middleware that can be used in the application.
|
|
214
|
+
* It has an `invoke` method that takes a request, a response, and a next function.
|
|
215
|
+
* The `invoke` method can return a MaybeAsync, which means it can return either a value or a Promise.
|
|
216
|
+
*
|
|
217
|
+
* Use it on a class that should be registered as a middleware in the application.
|
|
218
|
+
*/
|
|
97
219
|
interface IMiddleware {
|
|
98
220
|
invoke(request: Request, response: IResponse, next: NextFunction): MaybeAsync<void>;
|
|
99
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* UseMiddlewares decorator can be used to register middlewares for a controller or a controller action.
|
|
224
|
+
*
|
|
225
|
+
* @param mdlw - The middlewares list to register for the controller or the controller action.
|
|
226
|
+
*/
|
|
100
227
|
declare function UseMiddlewares(mdlw: Type<IMiddleware>[]): ClassDecorator & MethodDecorator;
|
|
228
|
+
/**
|
|
229
|
+
* Gets the middlewares for a controller or a controller action.
|
|
230
|
+
* This function retrieves the middlewares registered with the UseMiddlewares decorator.
|
|
231
|
+
* It returns an array of middleware classes that can be used to process requests for the specified controller.
|
|
232
|
+
* @param controllerName The name of the controller to get the middlewares for.
|
|
233
|
+
* @returns An array of middlewares for the controller.
|
|
234
|
+
*/
|
|
101
235
|
declare function getMiddlewaresForController(controllerName: string): Type<IMiddleware>[];
|
|
236
|
+
/**
|
|
237
|
+
* Gets the middlewares for a controller action.
|
|
238
|
+
* This function retrieves the middlewares registered with the UseMiddlewares decorator for a specific action in a controller.
|
|
239
|
+
* It returns an array of middleware classes that can be used to process requests for the specified controller action.
|
|
240
|
+
* @param controllerName The name of the controller to get the middlewares for.
|
|
241
|
+
* @param actionName The name of the action to get the middlewares for.
|
|
242
|
+
* @returns An array of middlewares for the controller action.
|
|
243
|
+
*/
|
|
102
244
|
declare function getMiddlewaresForControllerAction(controllerName: string, actionName: string): Type<IMiddleware>[];
|
|
103
245
|
|
|
104
246
|
|
|
247
|
+
/**
|
|
248
|
+
* IRouteDefinition interface defines the structure of a route in the application.
|
|
249
|
+
* It includes the HTTP method, path, controller class, handler method name,
|
|
250
|
+
* guards, and middlewares associated with the route.
|
|
251
|
+
*/
|
|
105
252
|
interface IRouteDefinition {
|
|
106
253
|
method: string;
|
|
107
254
|
path: string;
|
|
@@ -110,65 +257,133 @@ interface IRouteDefinition {
|
|
|
110
257
|
guards: Type<IGuard>[];
|
|
111
258
|
middlewares: Type<IMiddleware>[];
|
|
112
259
|
}
|
|
260
|
+
/**
|
|
261
|
+
* This type defines a function that represents an action in a controller.
|
|
262
|
+
* It takes a Request and an IResponse as parameters and returns a value or a Promise.
|
|
263
|
+
*/
|
|
113
264
|
type ControllerAction = (request: Request, response: IResponse) => any;
|
|
265
|
+
/**
|
|
266
|
+
* Router class is responsible for managing the application's routing.
|
|
267
|
+
* It registers controllers, handles requests, and manages middlewares and guards.
|
|
268
|
+
*/
|
|
114
269
|
declare class Router {
|
|
115
270
|
private readonly routes;
|
|
116
271
|
private readonly rootMiddlewares;
|
|
117
272
|
/**
|
|
118
|
-
*
|
|
273
|
+
* Registers a controller class with the router.
|
|
274
|
+
* This method extracts the route metadata from the controller class and registers it in the routing tree.
|
|
275
|
+
* It also handles the guards and middlewares associated with the controller.
|
|
276
|
+
* @param controllerClass - The controller class to register.
|
|
119
277
|
*/
|
|
120
278
|
registerController(controllerClass: Type<unknown>): Router;
|
|
121
279
|
/**
|
|
122
|
-
*
|
|
280
|
+
* Defines a middleware for the root of the application.
|
|
281
|
+
* This method allows you to register a middleware that will be applied to all requests
|
|
282
|
+
* to the application, regardless of the controller or action.
|
|
283
|
+
* @param middleware - The middleware class to register.
|
|
123
284
|
*/
|
|
124
285
|
defineRootMiddleware(middleware: Type<IMiddleware>): Router;
|
|
125
286
|
/**
|
|
126
|
-
*
|
|
287
|
+
* Shuts down the message channel for a specific sender ID.
|
|
288
|
+
* This method closes the IPC channel for the specified sender ID and
|
|
289
|
+
* removes it from the messagePorts map.
|
|
290
|
+
* @param channelSenderId - The ID of the sender channel to shut down.
|
|
127
291
|
*/
|
|
128
292
|
handle(request: Request): Promise<IResponse>;
|
|
129
293
|
/**
|
|
130
|
-
*
|
|
294
|
+
* Finds the route definition for a given request.
|
|
295
|
+
* This method searches the routing tree for a matching route based on the request's path and method.
|
|
296
|
+
* If no matching route is found, it throws a NotFoundException.
|
|
297
|
+
* @param request - The Request object containing the method and path to search for.
|
|
298
|
+
* @returns The IRouteDefinition for the matched route.
|
|
131
299
|
*/
|
|
132
300
|
private findRoute;
|
|
133
301
|
/**
|
|
134
|
-
*
|
|
302
|
+
* Resolves the controller for a given route definition.
|
|
303
|
+
* This method creates an instance of the controller class and prepares the request parameters.
|
|
304
|
+
* It also runs the request pipeline, which includes executing middlewares and guards.
|
|
305
|
+
* @param request - The Request object containing the request data.
|
|
306
|
+
* @param response - The IResponse object to populate with the response data.
|
|
307
|
+
* @param routeDef - The IRouteDefinition for the matched route.
|
|
308
|
+
* @return A Promise that resolves when the controller action has been executed.
|
|
309
|
+
* @throws UnauthorizedException if the request is not authorized by the guards.
|
|
135
310
|
*/
|
|
136
311
|
private resolveController;
|
|
137
312
|
/**
|
|
138
|
-
*
|
|
313
|
+
* Runs the request pipeline for a given request.
|
|
314
|
+
* This method executes the middlewares and guards associated with the route,
|
|
315
|
+
* and finally calls the controller action.
|
|
316
|
+
* @param request - The Request object containing the request data.
|
|
317
|
+
* @param response - The IResponse object to populate with the response data.
|
|
318
|
+
* @param routeDef - The IRouteDefinition for the matched route.
|
|
319
|
+
* @param controllerInstance - The instance of the controller class.
|
|
320
|
+
* @return A Promise that resolves when the request pipeline has been executed.
|
|
321
|
+
* @throws ResponseException if the response status is not successful.
|
|
139
322
|
*/
|
|
140
323
|
private runRequestPipeline;
|
|
141
324
|
/**
|
|
142
|
-
*
|
|
325
|
+
* Runs a middleware function in the request pipeline.
|
|
326
|
+
* This method creates an instance of the middleware and invokes its `invoke` method,
|
|
327
|
+
* passing the request, response, and next function.
|
|
328
|
+
* @param request - The Request object containing the request data.
|
|
329
|
+
* @param response - The IResponse object to populate with the response data.
|
|
330
|
+
* @param next - The NextFunction to call to continue the middleware chain.
|
|
331
|
+
* @param middlewareType - The type of the middleware to run.
|
|
332
|
+
* @return A Promise that resolves when the middleware has been executed.
|
|
143
333
|
*/
|
|
144
334
|
private runMiddleware;
|
|
145
335
|
/**
|
|
146
|
-
*
|
|
336
|
+
* Runs a guard to check if the request is authorized.
|
|
337
|
+
* This method creates an instance of the guard and calls its `canActivate` method.
|
|
338
|
+
* If the guard returns false, it throws an UnauthorizedException.
|
|
339
|
+
* @param request - The Request object containing the request data.
|
|
340
|
+
* @param guardType - The type of the guard to run.
|
|
341
|
+
* @return A Promise that resolves if the guard allows the request, or throws an UnauthorizedException if not.
|
|
342
|
+
* @throws UnauthorizedException if the guard denies access to the request.
|
|
147
343
|
*/
|
|
148
344
|
private runGuard;
|
|
149
345
|
/**
|
|
150
|
-
*
|
|
346
|
+
* Extracts parameters from the actual request path based on the template path.
|
|
347
|
+
* This method splits the actual path and the template path into segments,
|
|
348
|
+
* then maps the segments to parameters based on the template.
|
|
349
|
+
* @param actual - The actual request path.
|
|
350
|
+
* @param template - The template path to extract parameters from.
|
|
351
|
+
* @returns An object containing the extracted parameters.
|
|
151
352
|
*/
|
|
152
353
|
private extractParams;
|
|
153
354
|
}
|
|
154
355
|
|
|
155
356
|
|
|
357
|
+
/**
|
|
358
|
+
* The application service should implement this interface, as
|
|
359
|
+
* the NoxApp class instance will use it to notify the given service
|
|
360
|
+
* about application lifecycle events.
|
|
361
|
+
*/
|
|
156
362
|
interface IApp {
|
|
157
363
|
dispose(): Promise<void>;
|
|
158
364
|
onReady(): Promise<void>;
|
|
159
365
|
onActivated(): Promise<void>;
|
|
160
366
|
}
|
|
367
|
+
/**
|
|
368
|
+
* NoxApp is the main application class that manages the application lifecycle,
|
|
369
|
+
* handles IPC communication, and integrates with the Router.
|
|
370
|
+
*/
|
|
161
371
|
declare class NoxApp {
|
|
162
372
|
private readonly router;
|
|
163
373
|
private readonly messagePorts;
|
|
164
374
|
private app;
|
|
165
375
|
constructor(router: Router);
|
|
166
376
|
/**
|
|
167
|
-
*
|
|
377
|
+
* Initializes the NoxApp instance.
|
|
378
|
+
* This method sets up the IPC communication, registers event listeners,
|
|
379
|
+
* and prepares the application for use.
|
|
168
380
|
*/
|
|
169
381
|
init(): Promise<NoxApp>;
|
|
170
382
|
/**
|
|
171
|
-
*
|
|
383
|
+
* Handles the request from the renderer process.
|
|
384
|
+
* This method creates a Request object from the IPC event data,
|
|
385
|
+
* processes it through the Router, and sends the response back
|
|
386
|
+
* to the renderer process using the MessageChannel.
|
|
172
387
|
*/
|
|
173
388
|
private giveTheRendererAPort;
|
|
174
389
|
/**
|
|
@@ -180,22 +395,48 @@ declare class NoxApp {
|
|
|
180
395
|
* MacOS specific behavior.
|
|
181
396
|
*/
|
|
182
397
|
private onAppActivated;
|
|
398
|
+
/**
|
|
399
|
+
* Shuts down the message channel for a specific sender ID.
|
|
400
|
+
* This method closes the IPC channel for the specified sender ID and
|
|
401
|
+
* removes it from the messagePorts map.
|
|
402
|
+
* @param channelSenderId - The ID of the sender channel to shut down.
|
|
403
|
+
* @param remove - Whether to remove the channel from the messagePorts map.
|
|
404
|
+
*/
|
|
183
405
|
private shutdownChannel;
|
|
184
406
|
/**
|
|
185
|
-
*
|
|
407
|
+
* Handles the application shutdown process.
|
|
408
|
+
* This method is called when all windows are closed, and it cleans up the message channels
|
|
186
409
|
*/
|
|
187
410
|
private onAllWindowsClosed;
|
|
411
|
+
/**
|
|
412
|
+
* Configures the NoxApp instance with the provided application class.
|
|
413
|
+
* This method allows you to set the application class that will handle lifecycle events.
|
|
414
|
+
* @param app - The application class to configure.
|
|
415
|
+
* @returns NoxApp instance for method chaining.
|
|
416
|
+
*/
|
|
188
417
|
configure(app: Type<IApp>): NoxApp;
|
|
418
|
+
/**
|
|
419
|
+
* Registers a middleware for the root of the application.
|
|
420
|
+
* This method allows you to define a middleware that will be applied to all requests
|
|
421
|
+
* @param middleware - The middleware class to register.
|
|
422
|
+
* @returns NoxApp instance for method chaining.
|
|
423
|
+
*/
|
|
189
424
|
use(middleware: Type<IMiddleware>): NoxApp;
|
|
190
425
|
/**
|
|
191
426
|
* Should be called after the bootstrapApplication function is called.
|
|
427
|
+
* @returns NoxApp instance for method chaining.
|
|
192
428
|
*/
|
|
193
429
|
start(): NoxApp;
|
|
194
430
|
}
|
|
195
431
|
|
|
196
432
|
|
|
197
433
|
/**
|
|
198
|
-
*
|
|
434
|
+
* Bootstraps the Noxus application.
|
|
435
|
+
* This function initializes the application by creating an instance of NoxApp,
|
|
436
|
+
* registering the root module, and starting the application.
|
|
437
|
+
* @param rootModule - The root module of the application, decorated with @Module.
|
|
438
|
+
* @return A promise that resolves to the NoxApp instance.
|
|
439
|
+
* @throws Error if the root module is not decorated with @Module, or if the electron process could not start.
|
|
199
440
|
*/
|
|
200
441
|
declare function bootstrapApplication(rootModule: Type<any>): Promise<NoxApp>;
|
|
201
442
|
|
|
@@ -275,33 +516,111 @@ declare class NetworkConnectTimeoutException extends ResponseException {
|
|
|
275
516
|
}
|
|
276
517
|
|
|
277
518
|
|
|
519
|
+
/**
|
|
520
|
+
* The configuration that waits a controller's decorator.
|
|
521
|
+
*/
|
|
278
522
|
interface IControllerMetadata {
|
|
279
523
|
path: string;
|
|
280
524
|
guards: Type<IGuard>[];
|
|
281
525
|
}
|
|
526
|
+
/**
|
|
527
|
+
* Controller decorator is used to define a controller in the application.
|
|
528
|
+
* It is a kind of node in the routing tree, that can contains routes and middlewares.
|
|
529
|
+
*
|
|
530
|
+
* @param path - The path for the controller.
|
|
531
|
+
*/
|
|
282
532
|
declare function Controller(path: string): ClassDecorator;
|
|
283
|
-
|
|
533
|
+
/**
|
|
534
|
+
* Gets the controller metadata for a given target class.
|
|
535
|
+
* This metadata includes the path and guards defined by the @Controller decorator.
|
|
536
|
+
* @param target - The target class to get the controller metadata from.
|
|
537
|
+
* @returns The controller metadata if it exists, otherwise undefined.
|
|
538
|
+
*/
|
|
284
539
|
declare function getControllerMetadata(target: Type<unknown>): IControllerMetadata | undefined;
|
|
540
|
+
declare const CONTROLLER_METADATA_KEY: unique symbol;
|
|
285
541
|
|
|
286
542
|
|
|
543
|
+
/**
|
|
544
|
+
* The Injectable decorator marks a class as injectable.
|
|
545
|
+
* It allows the class to be registered in the dependency injection system.
|
|
546
|
+
* A class decorated with @Injectable can be injected into other classes
|
|
547
|
+
* either from the constructor of the class that needs it of from the `inject` function.
|
|
548
|
+
* @param lifetime - The lifetime of the injectable. Can be 'singleton', 'scope', or 'transient'.
|
|
549
|
+
*/
|
|
287
550
|
declare function Injectable(lifetime?: Lifetime): ClassDecorator;
|
|
288
|
-
|
|
551
|
+
/**
|
|
552
|
+
* Gets the injectable metadata for a given target class.
|
|
553
|
+
* This metadata includes the lifetime of the injectable defined by the @Injectable decorator.
|
|
554
|
+
* @param target - The target class to get the injectable metadata from.
|
|
555
|
+
* @returns The lifetime of the injectable if it exists, otherwise undefined.
|
|
556
|
+
*/
|
|
289
557
|
declare function getInjectableMetadata(target: Type<unknown>): Lifetime | undefined;
|
|
558
|
+
declare const INJECTABLE_METADATA_KEY: unique symbol;
|
|
290
559
|
|
|
291
560
|
|
|
292
|
-
declare function Module(metadata: IModuleMetadata): ClassDecorator;
|
|
293
|
-
declare const MODULE_METADATA_KEY: unique symbol;
|
|
294
561
|
interface IModuleMetadata {
|
|
295
562
|
imports?: Type<unknown>[];
|
|
296
563
|
exports?: Type<unknown>[];
|
|
297
564
|
providers?: Type<unknown>[];
|
|
298
565
|
controllers?: Type<unknown>[];
|
|
299
566
|
}
|
|
567
|
+
/**
|
|
568
|
+
* Module decorator is used to define a module in the application.
|
|
569
|
+
* It is a kind of node in the routing tree, that can contains controllers, services, and other modules.
|
|
570
|
+
*
|
|
571
|
+
* @param metadata - The metadata for the module.
|
|
572
|
+
*/
|
|
573
|
+
declare function Module(metadata: IModuleMetadata): ClassDecorator;
|
|
300
574
|
declare function getModuleMetadata(target: Function): IModuleMetadata | undefined;
|
|
575
|
+
declare const MODULE_METADATA_KEY: unique symbol;
|
|
301
576
|
|
|
577
|
+
/**
|
|
578
|
+
* Logger is a utility class for logging messages to the console.
|
|
579
|
+
*/
|
|
302
580
|
type LogLevel = 'log' | 'info' | 'warn' | 'error' | 'debug';
|
|
303
581
|
declare namespace Logger {
|
|
582
|
+
/**
|
|
583
|
+
* Sets the log level for the logger.
|
|
584
|
+
* This function allows you to change the log level dynamically at runtime.
|
|
585
|
+
* This won't affect the startup logs.
|
|
586
|
+
* @param level Sets the log level for the logger.
|
|
587
|
+
*/
|
|
304
588
|
function setLogLevel(level: LogLevel): void;
|
|
589
|
+
/**
|
|
590
|
+
* Logs a message to the console with log level LOG.
|
|
591
|
+
* This function formats the message with a timestamp, process ID, and the name of the caller function or class.
|
|
592
|
+
* It uses different colors for different log levels to enhance readability.
|
|
593
|
+
* @param args The arguments to log.
|
|
594
|
+
*/
|
|
595
|
+
function log(...args: any[]): void;
|
|
596
|
+
/**
|
|
597
|
+
* Logs a message to the console with log level INFO.
|
|
598
|
+
* This function formats the message with a timestamp, process ID, and the name of the caller function or class.
|
|
599
|
+
* It uses different colors for different log levels to enhance readability.
|
|
600
|
+
* @param args The arguments to log.
|
|
601
|
+
*/
|
|
602
|
+
function info(...args: any[]): void;
|
|
603
|
+
/**
|
|
604
|
+
* Logs a message to the console with log level WARN.
|
|
605
|
+
* This function formats the message with a timestamp, process ID, and the name of the caller function or class.
|
|
606
|
+
* It uses different colors for different log levels to enhance readability.
|
|
607
|
+
* @param args The arguments to log.
|
|
608
|
+
*/
|
|
609
|
+
function warn(...args: any[]): void;
|
|
610
|
+
/**
|
|
611
|
+
* Logs a message to the console with log level ERROR.
|
|
612
|
+
* This function formats the message with a timestamp, process ID, and the name of the caller function or class.
|
|
613
|
+
* It uses different colors for different log levels to enhance readability.
|
|
614
|
+
* @param args The arguments to log.
|
|
615
|
+
*/
|
|
616
|
+
function error(...args: any[]): void;
|
|
617
|
+
/**
|
|
618
|
+
* Logs a message to the console with log level DEBUG.
|
|
619
|
+
* This function formats the message with a timestamp, process ID, and the name of the caller function or class.
|
|
620
|
+
* It uses different colors for different log levels to enhance readability.
|
|
621
|
+
* @param args The arguments to log.
|
|
622
|
+
*/
|
|
623
|
+
function debug(...args: any[]): void;
|
|
305
624
|
const colors: {
|
|
306
625
|
black: string;
|
|
307
626
|
grey: string;
|
|
@@ -320,11 +639,6 @@ declare namespace Logger {
|
|
|
320
639
|
white: string;
|
|
321
640
|
initial: string;
|
|
322
641
|
};
|
|
323
|
-
function log(...args: any[]): void;
|
|
324
|
-
function info(...args: any[]): void;
|
|
325
|
-
function warn(...args: any[]): void;
|
|
326
|
-
function error(...args: any[]): void;
|
|
327
|
-
function debug(...args: any[]): void;
|
|
328
642
|
}
|
|
329
643
|
|
|
330
644
|
export { AppInjector, Authorize, BadGatewayException, BadRequestException, CONTROLLER_METADATA_KEY, ConflictException, Controller, type ControllerAction, Delete, ForbiddenException, GatewayTimeoutException, Get, type HttpMethod, HttpVersionNotSupportedException, type IApp, type IBinding, type IControllerMetadata, type IGuard, type IMiddleware, type IModuleMetadata, INJECTABLE_METADATA_KEY, type IRequest, type IResponse, type IRouteDefinition, type IRouteMetadata, Injectable, InsufficientStorageException, InternalServerException, type Lifetime, type LogLevel, Logger, LoopDetectedException, MODULE_METADATA_KEY, type MaybeAsync, MethodNotAllowedException, Module, NetworkAuthenticationRequiredException, NetworkConnectTimeoutException, type NextFunction, NotAcceptableException, NotExtendedException, NotFoundException, NotImplementedException, NoxApp, Patch, PaymentRequiredException, Post, Put, ROUTE_METADATA_KEY, Request, RequestTimeoutException, ResponseException, RootInjector, Router, ServiceUnavailableException, TooManyRequestsException, type Type, UnauthorizedException, UpgradeRequiredException, UseMiddlewares, VariantAlsoNegotiatesException, bootstrapApplication, getControllerMetadata, getGuardForController, getGuardForControllerAction, getInjectableMetadata, getMiddlewaresForController, getMiddlewaresForControllerAction, getModuleMetadata, getRouteMetadata, inject };
|