@noxfly/noxus 1.1.10 → 1.2.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/README.md CHANGED
@@ -48,6 +48,8 @@ npm i -D @noxfly/noxus
48
48
 
49
49
  Because you only need types during development, using the `-D` argument will make this package a `devDependency`, thus won't be present on your build.
50
50
 
51
+ > ⚠️ The default entry (`@noxfly/noxus`) only exposes renderer-friendly helpers and types. Import Electron main-process APIs from `@noxfly/noxus/main`.
52
+
51
53
  ## Basic use
52
54
 
53
55
  When employing "main", we consider this is the electron side of your application.
@@ -61,7 +63,7 @@ However, you can feel free to keep both merged, this won't change anything, but
61
63
  ```ts
62
64
  // main/index.ts
63
65
 
64
- import { bootstrapApplication } from '@noxfly/noxus';
66
+ import { bootstrapApplication } from '@noxfly/noxus/main';
65
67
  import { AppModule } from './modules/app.module.ts';
66
68
  import { Application } from './modules/app.service.ts';
67
69
 
@@ -81,7 +83,7 @@ main();
81
83
  ```ts
82
84
  // main/modules/app.service.ts
83
85
 
84
- import { IApp, Injectable, Logger } from '@noxfly/noxus';
86
+ import { IApp, Injectable, Logger } from '@noxfly/noxus/main';
85
87
 
86
88
  @Injectable('singleton')
87
89
  export class Application implements IApp {
@@ -101,7 +103,7 @@ export class Application implements IApp {
101
103
  ```ts
102
104
  // main/modules/app.module.ts
103
105
 
104
- import { Module } from '@noxfly/noxus';
106
+ import { Module } from '@noxfly/noxus/main';
105
107
 
106
108
  @Module({
107
109
  imports: [UsersModule], // import modules to be found here
@@ -116,7 +118,7 @@ export class AppModule {}
116
118
  ```ts
117
119
  // main/modules/users/users.module.ts
118
120
 
119
- import { Module } from '@noxfly/noxus';
121
+ import { Module } from '@noxfly/noxus/main';
120
122
 
121
123
  @Module({
122
124
  providers: [UsersService],
@@ -128,7 +130,7 @@ export class UsersModule {}
128
130
  ```ts
129
131
  // main/modules/users/users.service.ts
130
132
 
131
- import { Injectable } from '@noxfly/noxus';
133
+ import { Injectable } from '@noxfly/noxus/main';
132
134
 
133
135
  @Injectable()
134
136
  export class UsersService {
@@ -147,7 +149,7 @@ export class UsersService {
147
149
  ```ts
148
150
  // main/modules/users/users.controller.ts
149
151
 
150
- import { Controller, Get } from '@noxfly/noxus';
152
+ import { Controller, Get } from '@noxfly/noxus/main';
151
153
  import { UsersService } from './users.service.ts';
152
154
 
153
155
  @Controller('users')
@@ -174,7 +176,7 @@ Further upgrades might include new decorators like `@Param()`, `@Body()` etc...
174
176
  ```ts
175
177
  // main/guards/auth.guard.ts
176
178
 
177
- import { IGuard, Injectable, MaybeAsync, Request } from '@noxfly/noxus';
179
+ import { IGuard, Injectable, MaybeAsync, Request } from '@noxfly/noxus/main';
178
180
 
179
181
  @Injectable()
180
182
  export class AuthGuard implements IGuard {
@@ -394,7 +396,7 @@ throw new UnavailableException();
394
396
  You can decide to inject an Injectable without passing by the constructor, as follow :
395
397
 
396
398
  ```ts
397
- import { inject } from '@noxfly/noxus';
399
+ import { inject } from '@noxfly/noxus/main';
398
400
  import { MyClass } from 'src/myclass';
399
401
 
400
402
  const instance: MyClass = inject(MyClass);
@@ -407,7 +409,7 @@ Declare middlewares as follow :
407
409
  ```ts
408
410
  // renderer/middlewares.ts
409
411
 
410
- import { IMiddleware, Injectable, Request, IResponse, NextFunction } from '@noxfly/noxus';
412
+ import { IMiddleware, Injectable, Request, IResponse, NextFunction } from '@noxfly/noxus/main';
411
413
 
412
414
  @Injectable()
413
415
  export class MiddlewareA implements IMiddleware {
@@ -481,6 +483,64 @@ A -> B -> C -> D -> AuthGuard -> RoleGuard -> [action] -> D -> C -> B -> A.
481
483
 
482
484
  if a middleware throw any exception or put the response status higher or equal to 400, the pipeline immediatly stops and the response is returned, weither it is done before or after the call to the next function.
483
485
 
486
+
487
+
488
+
489
+
490
+ ## Listening to events from the main process
491
+
492
+ Starting from v1.2, the main process can push messages to renderer processes without the request/response flow.
493
+
494
+ ```ts
495
+ // main/users/users.controller.ts
496
+ import { Controller, Post, Request, NoxSocket } from '@noxfly/noxus/main';
497
+
498
+ @Controller('users')
499
+ export class UsersController {
500
+ constructor(private readonly socket: NoxSocket) {}
501
+
502
+ @Post('create')
503
+ public async create(request: Request): Promise<void> {
504
+ const payload = { nickname: request.body.nickname };
505
+
506
+ this.socket.emitToRenderer(request.event.senderId, 'users:created', payload);
507
+ // or broadcast to every connected renderer: this.socket.emit('users:created', payload);
508
+ }
509
+ }
510
+ ```
511
+
512
+ On the renderer side, leverage the `RendererEventRegistry` to register and clean up listeners. The registry only handles push events, so it plays nicely with the existing request handling code above.
513
+
514
+ ```ts
515
+ import { RendererEventRegistry, RendererEventSubscription } from '@noxfly/noxus';
516
+
517
+ private readonly events = new RendererEventRegistry();
518
+
519
+ constructor() {
520
+ // ... after the MessagePort is ready
521
+ this.port.onmessage = (event) => {
522
+ if(this.events.tryDispatchFromMessageEvent(event)) {
523
+ return;
524
+ }
525
+
526
+ this.onMessage(event); // existing request handling
527
+ };
528
+ }
529
+
530
+ public onUsersCreated(): RendererEventSubscription {
531
+ return this.events.subscribe('users:created', (payload) => {
532
+ // react to the event
533
+ });
534
+ }
535
+
536
+ public teardown(): void {
537
+ this.events.clear();
538
+ }
539
+ ```
540
+
541
+
542
+
543
+
484
544
  ## Contributing
485
545
 
486
546
  1. Clone the repo
@@ -0,0 +1,268 @@
1
+ /**
2
+ * @copyright 2025 NoxFly
3
+ * @license MIT
4
+ * @author NoxFly
5
+ */
6
+ interface Type<T> extends Function {
7
+ new (...args: any[]): T;
8
+ }
9
+ /**
10
+ * Represents a generic type that can be either a value or a promise resolving to that value.
11
+ */
12
+ type MaybeAsync<T> = T | Promise<T>;
13
+
14
+
15
+ /**
16
+ * IGuard interface defines a guard that can be used to protect routes.
17
+ * It has a `canActivate` method that takes a request and returns a MaybeAsync boolean.
18
+ * The `canActivate` method can return either a value or a Promise.
19
+ * Use it on a class that should be registered as a guard in the application.
20
+ * Guards can be used to protect routes or controller actions.
21
+ * For example, you can use guards to check if the user is authenticated or has the right permissions.
22
+ * You can use the `Authorize` decorator to register guards for a controller or a controller action.
23
+ * @see Authorize
24
+ */
25
+ interface IGuard {
26
+ canActivate(request: Request): MaybeAsync<boolean>;
27
+ }
28
+ /**
29
+ * Can be used to protect the routes of a controller.
30
+ * Can be used on a controller class or on a controller method.
31
+ */
32
+ declare function Authorize(...guardClasses: Type<IGuard>[]): MethodDecorator & ClassDecorator;
33
+ /**
34
+ * Gets the guards for a controller or a controller action.
35
+ * @param controllerName The name of the controller to get the guards for.
36
+ * @returns An array of guards for the controller.
37
+ */
38
+ declare function getGuardForController(controllerName: string): Type<IGuard>[];
39
+ /**
40
+ * Gets the guards for a controller action.
41
+ * @param controllerName The name of the controller to get the guards for.
42
+ * @param actionName The name of the action to get the guards for.
43
+ * @returns An array of guards for the controller action.
44
+ */
45
+ declare function getGuardForControllerAction(controllerName: string, actionName: string): Type<IGuard>[];
46
+
47
+
48
+ /**
49
+ * IRouteMetadata interface defines the metadata for a route.
50
+ * It includes the HTTP method, path, handler name, and guards associated with the route.
51
+ * This metadata is used to register the route in the application.
52
+ * This is the configuration that waits a route's decorator.
53
+ */
54
+ interface IRouteMetadata {
55
+ method: HttpMethod;
56
+ path: string;
57
+ handler: string;
58
+ guards: Type<IGuard>[];
59
+ }
60
+ /**
61
+ * The different HTTP methods that can be used in the application.
62
+ */
63
+ type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'BATCH';
64
+ /**
65
+ * Atomic HTTP verbs supported by controllers. BATCH is handled at the router level only.
66
+ */
67
+ type AtomicHttpMethod = Exclude<HttpMethod, 'BATCH'>;
68
+ /**
69
+ * Gets the route metadata for a given target class.
70
+ * This metadata includes the HTTP method, path, handler, and guards defined by the route decorators.
71
+ * @see Get
72
+ * @see Post
73
+ * @see Put
74
+ * @see Patch
75
+ * @see Delete
76
+ * @param target The target class to get the route metadata from.
77
+ * @returns An array of route metadata if it exists, otherwise an empty array.
78
+ */
79
+ declare function getRouteMetadata(target: Type<unknown>): IRouteMetadata[];
80
+ /**
81
+ * Route decorator that defines a leaf in the routing tree, attaching it to a controller method
82
+ * that will be called when the route is matched.
83
+ * This route will have to be called with the GET method.
84
+ */
85
+ declare const Get: (path: string) => MethodDecorator;
86
+ /**
87
+ * Route decorator that defines a leaf in the routing tree, attaching it to a controller method
88
+ * that will be called when the route is matched.
89
+ * This route will have to be called with the POST method.
90
+ */
91
+ declare const Post: (path: string) => MethodDecorator;
92
+ /**
93
+ * Route decorator that defines a leaf in the routing tree, attaching it to a controller method
94
+ * that will be called when the route is matched.
95
+ * This route will have to be called with the PUT method.
96
+ */
97
+ declare const Put: (path: string) => MethodDecorator;
98
+ /**
99
+ * Route decorator that defines a leaf in the routing tree, attaching it to a controller method
100
+ * that will be called when the route is matched.
101
+ * This route will have to be called with the PATCH method.
102
+ */
103
+ declare const Patch: (path: string) => MethodDecorator;
104
+ /**
105
+ * Route decorator that defines a leaf in the routing tree, attaching it to a controller method
106
+ * that will be called when the route is matched.
107
+ * This route will have to be called with the DELETE method.
108
+ */
109
+ declare const Delete: (path: string) => MethodDecorator;
110
+ declare const ROUTE_METADATA_KEY: unique symbol;
111
+
112
+
113
+ /**
114
+ * Represents a lifetime of a binding in the dependency injection system.
115
+ * It can be one of the following:
116
+ * - 'singleton': The instance is created once and shared across the application.
117
+ * - 'scope': The instance is created once per scope (e.g., per request).
118
+ * - 'transient': A new instance is created every time it is requested.
119
+ */
120
+ type Lifetime = 'singleton' | 'scope' | 'transient';
121
+ /**
122
+ * Represents a binding in the dependency injection system.
123
+ * It contains the lifetime of the binding, the implementation type, and optionally an instance.
124
+ */
125
+ interface IBinding {
126
+ lifetime: Lifetime;
127
+ implementation: Type<unknown>;
128
+ instance?: InstanceType<Type<unknown>>;
129
+ }
130
+ /**
131
+ * AppInjector is the root dependency injection container.
132
+ * It is used to register and resolve dependencies in the application.
133
+ * It supports different lifetimes for dependencies:
134
+ * This should not be manually instantiated, outside of the framework.
135
+ * Use the `RootInjector` instance instead.
136
+ */
137
+ declare class AppInjector {
138
+ readonly name: string | null;
139
+ bindings: Map<Type<unknown>, IBinding>;
140
+ singletons: Map<Type<unknown>, unknown>;
141
+ scoped: Map<Type<unknown>, unknown>;
142
+ constructor(name?: string | null);
143
+ /**
144
+ * Typically used to create a dependency injection scope
145
+ * at the "scope" level (i.e., per-request lifetime).
146
+ *
147
+ * SHOULD NOT BE USED by anything else than the framework itself.
148
+ */
149
+ createScope(): AppInjector;
150
+ /**
151
+ * Called when resolving a dependency,
152
+ * i.e., retrieving the instance of a given class.
153
+ */
154
+ resolve<T extends Type<unknown>>(target: T): InstanceType<T>;
155
+ /**
156
+ *
157
+ */
158
+ private instantiate;
159
+ }
160
+ /**
161
+ * Injects a type from the dependency injection system.
162
+ * This function is used to retrieve an instance of a type that has been registered in the dependency injection system.
163
+ * It is typically used in the constructor of a class to inject dependencies.
164
+ * @param t - The type to inject.
165
+ * @returns An instance of the type.
166
+ * @throws If the type is not registered in the dependency injection system.
167
+ */
168
+ declare function inject<T>(t: Type<T>): T;
169
+ declare const RootInjector: AppInjector;
170
+
171
+
172
+ /**
173
+ * The Request class represents an HTTP request in the Noxus framework.
174
+ * It encapsulates the request data, including the event, ID, method, path, and body.
175
+ * It also provides a context for dependency injection through the AppInjector.
176
+ */
177
+ declare class Request {
178
+ readonly event: Electron.MessageEvent;
179
+ readonly id: string;
180
+ readonly method: HttpMethod;
181
+ readonly path: string;
182
+ readonly body: any;
183
+ readonly context: AppInjector;
184
+ readonly params: Record<string, string>;
185
+ constructor(event: Electron.MessageEvent, id: string, method: HttpMethod, path: string, body: any);
186
+ }
187
+ /**
188
+ * The IRequest interface defines the structure of a request object.
189
+ * It includes properties for the sender ID, request ID, path, method, and an optional body.
190
+ * This interface is used to standardize the request data across the application.
191
+ */
192
+ interface IRequest<TBody = unknown> {
193
+ senderId: number;
194
+ requestId: string;
195
+ path: string;
196
+ method: HttpMethod;
197
+ body?: TBody;
198
+ }
199
+ interface IBatchRequestItem<TBody = unknown> {
200
+ requestId?: string;
201
+ path: string;
202
+ method: AtomicHttpMethod;
203
+ body?: TBody;
204
+ }
205
+ interface IBatchRequestPayload {
206
+ requests: IBatchRequestItem[];
207
+ }
208
+ /**
209
+ * Creates a Request object from the IPC event data.
210
+ * This function extracts the necessary information from the IPC event and constructs a Request instance.
211
+ */
212
+ interface IResponse<TBody = unknown> {
213
+ requestId: string;
214
+ status: number;
215
+ body?: TBody;
216
+ error?: string;
217
+ stack?: string;
218
+ }
219
+ interface IBatchResponsePayload {
220
+ responses: IResponse[];
221
+ }
222
+ declare const RENDERER_EVENT_TYPE = "noxus:event";
223
+ interface IRendererEventMessage<TPayload = unknown> {
224
+ type: typeof RENDERER_EVENT_TYPE;
225
+ event: string;
226
+ payload?: TPayload;
227
+ }
228
+ declare function createRendererEventMessage<TPayload = unknown>(event: string, payload?: TPayload): IRendererEventMessage<TPayload>;
229
+ declare function isRendererEventMessage(value: unknown): value is IRendererEventMessage;
230
+
231
+ /**
232
+ * Lightweight event registry to help renderer processes subscribe to
233
+ * push messages sent by the main process through Noxus.
234
+ */
235
+
236
+ type RendererEventHandler<TPayload = unknown> = (payload: TPayload) => void;
237
+ interface RendererEventSubscription {
238
+ unsubscribe(): void;
239
+ }
240
+ declare class RendererEventRegistry {
241
+ private readonly listeners;
242
+ /**
243
+ *
244
+ */
245
+ subscribe<TPayload>(eventName: string, handler: RendererEventHandler<TPayload>): RendererEventSubscription;
246
+ /**
247
+ *
248
+ */
249
+ unsubscribe<TPayload>(eventName: string, handler: RendererEventHandler<TPayload>): void;
250
+ /**
251
+ *
252
+ */
253
+ clear(eventName?: string): void;
254
+ /**
255
+ *
256
+ */
257
+ dispatch<TPayload>(message: IRendererEventMessage<TPayload>): void;
258
+ /**
259
+ *
260
+ */
261
+ tryDispatchFromMessageEvent(event: MessageEvent): boolean;
262
+ /**
263
+ *
264
+ */
265
+ hasHandlers(eventName: string): boolean;
266
+ }
267
+
268
+ export { AppInjector as A, Delete as D, Get as G, type HttpMethod as H, type IResponse as I, type Lifetime as L, type MaybeAsync as M, Post as P, Request as R, type Type as T, type IGuard as a, type IBinding as b, RootInjector as c, Authorize as d, getGuardForControllerAction as e, type IRouteMetadata as f, getGuardForController as g, type AtomicHttpMethod as h, inject as i, getRouteMetadata as j, Put as k, Patch as l, ROUTE_METADATA_KEY as m, type IRequest as n, type IBatchRequestItem as o, type IBatchRequestPayload as p, type IBatchResponsePayload as q, RENDERER_EVENT_TYPE as r, type IRendererEventMessage as s, createRendererEventMessage as t, isRendererEventMessage as u, type RendererEventHandler as v, type RendererEventSubscription as w, RendererEventRegistry as x };
@@ -0,0 +1,268 @@
1
+ /**
2
+ * @copyright 2025 NoxFly
3
+ * @license MIT
4
+ * @author NoxFly
5
+ */
6
+ interface Type<T> extends Function {
7
+ new (...args: any[]): T;
8
+ }
9
+ /**
10
+ * Represents a generic type that can be either a value or a promise resolving to that value.
11
+ */
12
+ type MaybeAsync<T> = T | Promise<T>;
13
+
14
+
15
+ /**
16
+ * IGuard interface defines a guard that can be used to protect routes.
17
+ * It has a `canActivate` method that takes a request and returns a MaybeAsync boolean.
18
+ * The `canActivate` method can return either a value or a Promise.
19
+ * Use it on a class that should be registered as a guard in the application.
20
+ * Guards can be used to protect routes or controller actions.
21
+ * For example, you can use guards to check if the user is authenticated or has the right permissions.
22
+ * You can use the `Authorize` decorator to register guards for a controller or a controller action.
23
+ * @see Authorize
24
+ */
25
+ interface IGuard {
26
+ canActivate(request: Request): MaybeAsync<boolean>;
27
+ }
28
+ /**
29
+ * Can be used to protect the routes of a controller.
30
+ * Can be used on a controller class or on a controller method.
31
+ */
32
+ declare function Authorize(...guardClasses: Type<IGuard>[]): MethodDecorator & ClassDecorator;
33
+ /**
34
+ * Gets the guards for a controller or a controller action.
35
+ * @param controllerName The name of the controller to get the guards for.
36
+ * @returns An array of guards for the controller.
37
+ */
38
+ declare function getGuardForController(controllerName: string): Type<IGuard>[];
39
+ /**
40
+ * Gets the guards for a controller action.
41
+ * @param controllerName The name of the controller to get the guards for.
42
+ * @param actionName The name of the action to get the guards for.
43
+ * @returns An array of guards for the controller action.
44
+ */
45
+ declare function getGuardForControllerAction(controllerName: string, actionName: string): Type<IGuard>[];
46
+
47
+
48
+ /**
49
+ * IRouteMetadata interface defines the metadata for a route.
50
+ * It includes the HTTP method, path, handler name, and guards associated with the route.
51
+ * This metadata is used to register the route in the application.
52
+ * This is the configuration that waits a route's decorator.
53
+ */
54
+ interface IRouteMetadata {
55
+ method: HttpMethod;
56
+ path: string;
57
+ handler: string;
58
+ guards: Type<IGuard>[];
59
+ }
60
+ /**
61
+ * The different HTTP methods that can be used in the application.
62
+ */
63
+ type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'BATCH';
64
+ /**
65
+ * Atomic HTTP verbs supported by controllers. BATCH is handled at the router level only.
66
+ */
67
+ type AtomicHttpMethod = Exclude<HttpMethod, 'BATCH'>;
68
+ /**
69
+ * Gets the route metadata for a given target class.
70
+ * This metadata includes the HTTP method, path, handler, and guards defined by the route decorators.
71
+ * @see Get
72
+ * @see Post
73
+ * @see Put
74
+ * @see Patch
75
+ * @see Delete
76
+ * @param target The target class to get the route metadata from.
77
+ * @returns An array of route metadata if it exists, otherwise an empty array.
78
+ */
79
+ declare function getRouteMetadata(target: Type<unknown>): IRouteMetadata[];
80
+ /**
81
+ * Route decorator that defines a leaf in the routing tree, attaching it to a controller method
82
+ * that will be called when the route is matched.
83
+ * This route will have to be called with the GET method.
84
+ */
85
+ declare const Get: (path: string) => MethodDecorator;
86
+ /**
87
+ * Route decorator that defines a leaf in the routing tree, attaching it to a controller method
88
+ * that will be called when the route is matched.
89
+ * This route will have to be called with the POST method.
90
+ */
91
+ declare const Post: (path: string) => MethodDecorator;
92
+ /**
93
+ * Route decorator that defines a leaf in the routing tree, attaching it to a controller method
94
+ * that will be called when the route is matched.
95
+ * This route will have to be called with the PUT method.
96
+ */
97
+ declare const Put: (path: string) => MethodDecorator;
98
+ /**
99
+ * Route decorator that defines a leaf in the routing tree, attaching it to a controller method
100
+ * that will be called when the route is matched.
101
+ * This route will have to be called with the PATCH method.
102
+ */
103
+ declare const Patch: (path: string) => MethodDecorator;
104
+ /**
105
+ * Route decorator that defines a leaf in the routing tree, attaching it to a controller method
106
+ * that will be called when the route is matched.
107
+ * This route will have to be called with the DELETE method.
108
+ */
109
+ declare const Delete: (path: string) => MethodDecorator;
110
+ declare const ROUTE_METADATA_KEY: unique symbol;
111
+
112
+
113
+ /**
114
+ * Represents a lifetime of a binding in the dependency injection system.
115
+ * It can be one of the following:
116
+ * - 'singleton': The instance is created once and shared across the application.
117
+ * - 'scope': The instance is created once per scope (e.g., per request).
118
+ * - 'transient': A new instance is created every time it is requested.
119
+ */
120
+ type Lifetime = 'singleton' | 'scope' | 'transient';
121
+ /**
122
+ * Represents a binding in the dependency injection system.
123
+ * It contains the lifetime of the binding, the implementation type, and optionally an instance.
124
+ */
125
+ interface IBinding {
126
+ lifetime: Lifetime;
127
+ implementation: Type<unknown>;
128
+ instance?: InstanceType<Type<unknown>>;
129
+ }
130
+ /**
131
+ * AppInjector is the root dependency injection container.
132
+ * It is used to register and resolve dependencies in the application.
133
+ * It supports different lifetimes for dependencies:
134
+ * This should not be manually instantiated, outside of the framework.
135
+ * Use the `RootInjector` instance instead.
136
+ */
137
+ declare class AppInjector {
138
+ readonly name: string | null;
139
+ bindings: Map<Type<unknown>, IBinding>;
140
+ singletons: Map<Type<unknown>, unknown>;
141
+ scoped: Map<Type<unknown>, unknown>;
142
+ constructor(name?: string | null);
143
+ /**
144
+ * Typically used to create a dependency injection scope
145
+ * at the "scope" level (i.e., per-request lifetime).
146
+ *
147
+ * SHOULD NOT BE USED by anything else than the framework itself.
148
+ */
149
+ createScope(): AppInjector;
150
+ /**
151
+ * Called when resolving a dependency,
152
+ * i.e., retrieving the instance of a given class.
153
+ */
154
+ resolve<T extends Type<unknown>>(target: T): InstanceType<T>;
155
+ /**
156
+ *
157
+ */
158
+ private instantiate;
159
+ }
160
+ /**
161
+ * Injects a type from the dependency injection system.
162
+ * This function is used to retrieve an instance of a type that has been registered in the dependency injection system.
163
+ * It is typically used in the constructor of a class to inject dependencies.
164
+ * @param t - The type to inject.
165
+ * @returns An instance of the type.
166
+ * @throws If the type is not registered in the dependency injection system.
167
+ */
168
+ declare function inject<T>(t: Type<T>): T;
169
+ declare const RootInjector: AppInjector;
170
+
171
+
172
+ /**
173
+ * The Request class represents an HTTP request in the Noxus framework.
174
+ * It encapsulates the request data, including the event, ID, method, path, and body.
175
+ * It also provides a context for dependency injection through the AppInjector.
176
+ */
177
+ declare class Request {
178
+ readonly event: Electron.MessageEvent;
179
+ readonly id: string;
180
+ readonly method: HttpMethod;
181
+ readonly path: string;
182
+ readonly body: any;
183
+ readonly context: AppInjector;
184
+ readonly params: Record<string, string>;
185
+ constructor(event: Electron.MessageEvent, id: string, method: HttpMethod, path: string, body: any);
186
+ }
187
+ /**
188
+ * The IRequest interface defines the structure of a request object.
189
+ * It includes properties for the sender ID, request ID, path, method, and an optional body.
190
+ * This interface is used to standardize the request data across the application.
191
+ */
192
+ interface IRequest<TBody = unknown> {
193
+ senderId: number;
194
+ requestId: string;
195
+ path: string;
196
+ method: HttpMethod;
197
+ body?: TBody;
198
+ }
199
+ interface IBatchRequestItem<TBody = unknown> {
200
+ requestId?: string;
201
+ path: string;
202
+ method: AtomicHttpMethod;
203
+ body?: TBody;
204
+ }
205
+ interface IBatchRequestPayload {
206
+ requests: IBatchRequestItem[];
207
+ }
208
+ /**
209
+ * Creates a Request object from the IPC event data.
210
+ * This function extracts the necessary information from the IPC event and constructs a Request instance.
211
+ */
212
+ interface IResponse<TBody = unknown> {
213
+ requestId: string;
214
+ status: number;
215
+ body?: TBody;
216
+ error?: string;
217
+ stack?: string;
218
+ }
219
+ interface IBatchResponsePayload {
220
+ responses: IResponse[];
221
+ }
222
+ declare const RENDERER_EVENT_TYPE = "noxus:event";
223
+ interface IRendererEventMessage<TPayload = unknown> {
224
+ type: typeof RENDERER_EVENT_TYPE;
225
+ event: string;
226
+ payload?: TPayload;
227
+ }
228
+ declare function createRendererEventMessage<TPayload = unknown>(event: string, payload?: TPayload): IRendererEventMessage<TPayload>;
229
+ declare function isRendererEventMessage(value: unknown): value is IRendererEventMessage;
230
+
231
+ /**
232
+ * Lightweight event registry to help renderer processes subscribe to
233
+ * push messages sent by the main process through Noxus.
234
+ */
235
+
236
+ type RendererEventHandler<TPayload = unknown> = (payload: TPayload) => void;
237
+ interface RendererEventSubscription {
238
+ unsubscribe(): void;
239
+ }
240
+ declare class RendererEventRegistry {
241
+ private readonly listeners;
242
+ /**
243
+ *
244
+ */
245
+ subscribe<TPayload>(eventName: string, handler: RendererEventHandler<TPayload>): RendererEventSubscription;
246
+ /**
247
+ *
248
+ */
249
+ unsubscribe<TPayload>(eventName: string, handler: RendererEventHandler<TPayload>): void;
250
+ /**
251
+ *
252
+ */
253
+ clear(eventName?: string): void;
254
+ /**
255
+ *
256
+ */
257
+ dispatch<TPayload>(message: IRendererEventMessage<TPayload>): void;
258
+ /**
259
+ *
260
+ */
261
+ tryDispatchFromMessageEvent(event: MessageEvent): boolean;
262
+ /**
263
+ *
264
+ */
265
+ hasHandlers(eventName: string): boolean;
266
+ }
267
+
268
+ export { AppInjector as A, Delete as D, Get as G, type HttpMethod as H, type IResponse as I, type Lifetime as L, type MaybeAsync as M, Post as P, Request as R, type Type as T, type IGuard as a, type IBinding as b, RootInjector as c, Authorize as d, getGuardForControllerAction as e, type IRouteMetadata as f, getGuardForController as g, type AtomicHttpMethod as h, inject as i, getRouteMetadata as j, Put as k, Patch as l, ROUTE_METADATA_KEY as m, type IRequest as n, type IBatchRequestItem as o, type IBatchRequestPayload as p, type IBatchResponsePayload as q, RENDERER_EVENT_TYPE as r, type IRendererEventMessage as s, createRendererEventMessage as t, isRendererEventMessage as u, type RendererEventHandler as v, type RendererEventSubscription as w, RendererEventRegistry as x };