@noxfly/noxus 1.1.10 → 2.0.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/.github/copilot-instructions.md +32 -0
- package/README.md +104 -135
- package/dist/index-CI3OMzNR.d.mts +318 -0
- package/dist/index-CI3OMzNR.d.ts +318 -0
- package/dist/{noxus.d.mts → main.d.mts} +45 -233
- package/dist/{noxus.d.ts → main.d.ts} +45 -233
- package/dist/{noxus.js → main.js} +536 -59
- package/dist/{noxus.mjs → main.mjs} +523 -54
- package/dist/renderer.d.mts +1 -0
- package/dist/renderer.d.ts +1 -0
- package/dist/renderer.js +515 -0
- package/dist/renderer.mjs +485 -0
- package/package.json +73 -48
- package/scripts/postbuild.js +10 -5
- package/src/DI/injector-explorer.ts +1 -1
- package/src/app.ts +51 -46
- package/src/decorators/injectable.decorator.ts +6 -17
- package/src/decorators/injectable.metadata.ts +15 -0
- package/src/index.ts +2 -13
- package/src/main.ts +28 -0
- package/src/preload-bridge.ts +75 -0
- package/src/renderer-client.ts +338 -0
- package/src/renderer-events.ts +110 -0
- package/src/request.ts +27 -0
- package/src/router.ts +1 -1
- package/src/socket.ts +73 -0
- package/tsup.config.ts +2 -1
|
@@ -0,0 +1,318 @@
|
|
|
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 senderId: number;
|
|
180
|
+
readonly id: string;
|
|
181
|
+
readonly method: HttpMethod;
|
|
182
|
+
readonly path: string;
|
|
183
|
+
readonly body: any;
|
|
184
|
+
readonly context: AppInjector;
|
|
185
|
+
readonly params: Record<string, string>;
|
|
186
|
+
constructor(event: Electron.MessageEvent, senderId: number, id: string, method: HttpMethod, path: string, body: any);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* The IRequest interface defines the structure of a request object.
|
|
190
|
+
* It includes properties for the sender ID, request ID, path, method, and an optional body.
|
|
191
|
+
* This interface is used to standardize the request data across the application.
|
|
192
|
+
*/
|
|
193
|
+
interface IRequest<TBody = unknown> {
|
|
194
|
+
senderId: number;
|
|
195
|
+
requestId: string;
|
|
196
|
+
path: string;
|
|
197
|
+
method: HttpMethod;
|
|
198
|
+
body?: TBody;
|
|
199
|
+
}
|
|
200
|
+
interface IBatchRequestItem<TBody = unknown> {
|
|
201
|
+
requestId?: string;
|
|
202
|
+
path: string;
|
|
203
|
+
method: AtomicHttpMethod;
|
|
204
|
+
body?: TBody;
|
|
205
|
+
}
|
|
206
|
+
interface IBatchRequestPayload {
|
|
207
|
+
requests: IBatchRequestItem[];
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Creates a Request object from the IPC event data.
|
|
211
|
+
* This function extracts the necessary information from the IPC event and constructs a Request instance.
|
|
212
|
+
*/
|
|
213
|
+
interface IResponse<TBody = unknown> {
|
|
214
|
+
requestId: string;
|
|
215
|
+
status: number;
|
|
216
|
+
body?: TBody;
|
|
217
|
+
error?: string;
|
|
218
|
+
stack?: string;
|
|
219
|
+
}
|
|
220
|
+
interface IBatchResponsePayload {
|
|
221
|
+
responses: IResponse[];
|
|
222
|
+
}
|
|
223
|
+
declare const RENDERER_EVENT_TYPE = "noxus:event";
|
|
224
|
+
interface IRendererEventMessage<TPayload = unknown> {
|
|
225
|
+
type: typeof RENDERER_EVENT_TYPE;
|
|
226
|
+
event: string;
|
|
227
|
+
payload?: TPayload;
|
|
228
|
+
}
|
|
229
|
+
declare function createRendererEventMessage<TPayload = unknown>(event: string, payload?: TPayload): IRendererEventMessage<TPayload>;
|
|
230
|
+
declare function isRendererEventMessage(value: unknown): value is IRendererEventMessage;
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Lightweight event registry to help renderer processes subscribe to
|
|
234
|
+
* push messages sent by the main process through Noxus.
|
|
235
|
+
*/
|
|
236
|
+
|
|
237
|
+
type RendererEventHandler<TPayload = unknown> = (payload: TPayload) => void;
|
|
238
|
+
interface RendererEventSubscription {
|
|
239
|
+
unsubscribe(): void;
|
|
240
|
+
}
|
|
241
|
+
declare class RendererEventRegistry {
|
|
242
|
+
private readonly listeners;
|
|
243
|
+
/**
|
|
244
|
+
*
|
|
245
|
+
*/
|
|
246
|
+
subscribe<TPayload>(eventName: string, handler: RendererEventHandler<TPayload>): RendererEventSubscription;
|
|
247
|
+
/**
|
|
248
|
+
*
|
|
249
|
+
*/
|
|
250
|
+
unsubscribe<TPayload>(eventName: string, handler: RendererEventHandler<TPayload>): void;
|
|
251
|
+
/**
|
|
252
|
+
*
|
|
253
|
+
*/
|
|
254
|
+
clear(eventName?: string): void;
|
|
255
|
+
/**
|
|
256
|
+
*
|
|
257
|
+
*/
|
|
258
|
+
dispatch<TPayload>(message: IRendererEventMessage<TPayload>): void;
|
|
259
|
+
/**
|
|
260
|
+
*
|
|
261
|
+
*/
|
|
262
|
+
tryDispatchFromMessageEvent(event: MessageEvent): boolean;
|
|
263
|
+
/**
|
|
264
|
+
*
|
|
265
|
+
*/
|
|
266
|
+
hasHandlers(eventName: string): boolean;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
interface IPortRequester {
|
|
271
|
+
requestPort(): void;
|
|
272
|
+
}
|
|
273
|
+
interface RendererClientOptions {
|
|
274
|
+
bridge?: IPortRequester | null;
|
|
275
|
+
bridgeName?: string | string[];
|
|
276
|
+
initMessageType?: string;
|
|
277
|
+
windowRef?: Window;
|
|
278
|
+
generateRequestId?: () => string;
|
|
279
|
+
}
|
|
280
|
+
interface PendingRequest<T = unknown> {
|
|
281
|
+
resolve: (value: T) => void;
|
|
282
|
+
reject: (reason: IResponse<T>) => void;
|
|
283
|
+
request: IRequest;
|
|
284
|
+
submittedAt: number;
|
|
285
|
+
}
|
|
286
|
+
declare class NoxRendererClient {
|
|
287
|
+
readonly events: RendererEventRegistry;
|
|
288
|
+
protected readonly pendingRequests: Map<string, PendingRequest<unknown>>;
|
|
289
|
+
protected requestPort: MessagePort | undefined;
|
|
290
|
+
protected socketPort: MessagePort | undefined;
|
|
291
|
+
protected senderId: number | undefined;
|
|
292
|
+
private readonly bridge;
|
|
293
|
+
private readonly initMessageType;
|
|
294
|
+
private readonly windowRef;
|
|
295
|
+
private readonly generateRequestId;
|
|
296
|
+
private isReady;
|
|
297
|
+
private setupPromise;
|
|
298
|
+
private setupResolve;
|
|
299
|
+
private setupReject;
|
|
300
|
+
constructor(options?: RendererClientOptions);
|
|
301
|
+
setup(): Promise<void>;
|
|
302
|
+
dispose(): void;
|
|
303
|
+
request<TResponse, TBody = unknown>(request: Omit<IRequest<TBody>, 'requestId' | 'senderId'>): Promise<TResponse>;
|
|
304
|
+
batch(requests: Omit<IBatchRequestItem<unknown>, 'requestId'>[]): Promise<IBatchResponsePayload>;
|
|
305
|
+
getSenderId(): number | undefined;
|
|
306
|
+
private readonly onWindowMessage;
|
|
307
|
+
private readonly onSocketMessage;
|
|
308
|
+
private readonly onRequestMessage;
|
|
309
|
+
protected onRequestCompleted(pending: PendingRequest, response: IResponse): void;
|
|
310
|
+
private attachRequestPort;
|
|
311
|
+
private attachSocketPort;
|
|
312
|
+
private validateReady;
|
|
313
|
+
private createErrorResponse;
|
|
314
|
+
private resetSetupState;
|
|
315
|
+
isElectronEnvironment(): boolean;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
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, NoxRendererClient as N, Post as P, Request as R, type Type as T, type IGuard as a, type IPortRequester as b, type IBinding as c, RootInjector as d, Authorize as e, getGuardForControllerAction as f, getGuardForController as g, type IRouteMetadata as h, inject as i, type AtomicHttpMethod as j, getRouteMetadata as k, Put as l, Patch as m, ROUTE_METADATA_KEY as n, type IRequest as o, type IBatchRequestItem as p, type IBatchRequestPayload as q, type IBatchResponsePayload as r, RENDERER_EVENT_TYPE as s, type IRendererEventMessage as t, createRendererEventMessage as u, isRendererEventMessage as v, type RendererEventHandler as w, type RendererEventSubscription as x, RendererEventRegistry as y, type RendererClientOptions as z };
|
|
@@ -0,0 +1,318 @@
|
|
|
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 senderId: number;
|
|
180
|
+
readonly id: string;
|
|
181
|
+
readonly method: HttpMethod;
|
|
182
|
+
readonly path: string;
|
|
183
|
+
readonly body: any;
|
|
184
|
+
readonly context: AppInjector;
|
|
185
|
+
readonly params: Record<string, string>;
|
|
186
|
+
constructor(event: Electron.MessageEvent, senderId: number, id: string, method: HttpMethod, path: string, body: any);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* The IRequest interface defines the structure of a request object.
|
|
190
|
+
* It includes properties for the sender ID, request ID, path, method, and an optional body.
|
|
191
|
+
* This interface is used to standardize the request data across the application.
|
|
192
|
+
*/
|
|
193
|
+
interface IRequest<TBody = unknown> {
|
|
194
|
+
senderId: number;
|
|
195
|
+
requestId: string;
|
|
196
|
+
path: string;
|
|
197
|
+
method: HttpMethod;
|
|
198
|
+
body?: TBody;
|
|
199
|
+
}
|
|
200
|
+
interface IBatchRequestItem<TBody = unknown> {
|
|
201
|
+
requestId?: string;
|
|
202
|
+
path: string;
|
|
203
|
+
method: AtomicHttpMethod;
|
|
204
|
+
body?: TBody;
|
|
205
|
+
}
|
|
206
|
+
interface IBatchRequestPayload {
|
|
207
|
+
requests: IBatchRequestItem[];
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Creates a Request object from the IPC event data.
|
|
211
|
+
* This function extracts the necessary information from the IPC event and constructs a Request instance.
|
|
212
|
+
*/
|
|
213
|
+
interface IResponse<TBody = unknown> {
|
|
214
|
+
requestId: string;
|
|
215
|
+
status: number;
|
|
216
|
+
body?: TBody;
|
|
217
|
+
error?: string;
|
|
218
|
+
stack?: string;
|
|
219
|
+
}
|
|
220
|
+
interface IBatchResponsePayload {
|
|
221
|
+
responses: IResponse[];
|
|
222
|
+
}
|
|
223
|
+
declare const RENDERER_EVENT_TYPE = "noxus:event";
|
|
224
|
+
interface IRendererEventMessage<TPayload = unknown> {
|
|
225
|
+
type: typeof RENDERER_EVENT_TYPE;
|
|
226
|
+
event: string;
|
|
227
|
+
payload?: TPayload;
|
|
228
|
+
}
|
|
229
|
+
declare function createRendererEventMessage<TPayload = unknown>(event: string, payload?: TPayload): IRendererEventMessage<TPayload>;
|
|
230
|
+
declare function isRendererEventMessage(value: unknown): value is IRendererEventMessage;
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Lightweight event registry to help renderer processes subscribe to
|
|
234
|
+
* push messages sent by the main process through Noxus.
|
|
235
|
+
*/
|
|
236
|
+
|
|
237
|
+
type RendererEventHandler<TPayload = unknown> = (payload: TPayload) => void;
|
|
238
|
+
interface RendererEventSubscription {
|
|
239
|
+
unsubscribe(): void;
|
|
240
|
+
}
|
|
241
|
+
declare class RendererEventRegistry {
|
|
242
|
+
private readonly listeners;
|
|
243
|
+
/**
|
|
244
|
+
*
|
|
245
|
+
*/
|
|
246
|
+
subscribe<TPayload>(eventName: string, handler: RendererEventHandler<TPayload>): RendererEventSubscription;
|
|
247
|
+
/**
|
|
248
|
+
*
|
|
249
|
+
*/
|
|
250
|
+
unsubscribe<TPayload>(eventName: string, handler: RendererEventHandler<TPayload>): void;
|
|
251
|
+
/**
|
|
252
|
+
*
|
|
253
|
+
*/
|
|
254
|
+
clear(eventName?: string): void;
|
|
255
|
+
/**
|
|
256
|
+
*
|
|
257
|
+
*/
|
|
258
|
+
dispatch<TPayload>(message: IRendererEventMessage<TPayload>): void;
|
|
259
|
+
/**
|
|
260
|
+
*
|
|
261
|
+
*/
|
|
262
|
+
tryDispatchFromMessageEvent(event: MessageEvent): boolean;
|
|
263
|
+
/**
|
|
264
|
+
*
|
|
265
|
+
*/
|
|
266
|
+
hasHandlers(eventName: string): boolean;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
interface IPortRequester {
|
|
271
|
+
requestPort(): void;
|
|
272
|
+
}
|
|
273
|
+
interface RendererClientOptions {
|
|
274
|
+
bridge?: IPortRequester | null;
|
|
275
|
+
bridgeName?: string | string[];
|
|
276
|
+
initMessageType?: string;
|
|
277
|
+
windowRef?: Window;
|
|
278
|
+
generateRequestId?: () => string;
|
|
279
|
+
}
|
|
280
|
+
interface PendingRequest<T = unknown> {
|
|
281
|
+
resolve: (value: T) => void;
|
|
282
|
+
reject: (reason: IResponse<T>) => void;
|
|
283
|
+
request: IRequest;
|
|
284
|
+
submittedAt: number;
|
|
285
|
+
}
|
|
286
|
+
declare class NoxRendererClient {
|
|
287
|
+
readonly events: RendererEventRegistry;
|
|
288
|
+
protected readonly pendingRequests: Map<string, PendingRequest<unknown>>;
|
|
289
|
+
protected requestPort: MessagePort | undefined;
|
|
290
|
+
protected socketPort: MessagePort | undefined;
|
|
291
|
+
protected senderId: number | undefined;
|
|
292
|
+
private readonly bridge;
|
|
293
|
+
private readonly initMessageType;
|
|
294
|
+
private readonly windowRef;
|
|
295
|
+
private readonly generateRequestId;
|
|
296
|
+
private isReady;
|
|
297
|
+
private setupPromise;
|
|
298
|
+
private setupResolve;
|
|
299
|
+
private setupReject;
|
|
300
|
+
constructor(options?: RendererClientOptions);
|
|
301
|
+
setup(): Promise<void>;
|
|
302
|
+
dispose(): void;
|
|
303
|
+
request<TResponse, TBody = unknown>(request: Omit<IRequest<TBody>, 'requestId' | 'senderId'>): Promise<TResponse>;
|
|
304
|
+
batch(requests: Omit<IBatchRequestItem<unknown>, 'requestId'>[]): Promise<IBatchResponsePayload>;
|
|
305
|
+
getSenderId(): number | undefined;
|
|
306
|
+
private readonly onWindowMessage;
|
|
307
|
+
private readonly onSocketMessage;
|
|
308
|
+
private readonly onRequestMessage;
|
|
309
|
+
protected onRequestCompleted(pending: PendingRequest, response: IResponse): void;
|
|
310
|
+
private attachRequestPort;
|
|
311
|
+
private attachSocketPort;
|
|
312
|
+
private validateReady;
|
|
313
|
+
private createErrorResponse;
|
|
314
|
+
private resetSetupState;
|
|
315
|
+
isElectronEnvironment(): boolean;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
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, NoxRendererClient as N, Post as P, Request as R, type Type as T, type IGuard as a, type IPortRequester as b, type IBinding as c, RootInjector as d, Authorize as e, getGuardForControllerAction as f, getGuardForController as g, type IRouteMetadata as h, inject as i, type AtomicHttpMethod as j, getRouteMetadata as k, Put as l, Patch as m, ROUTE_METADATA_KEY as n, type IRequest as o, type IBatchRequestItem as p, type IBatchRequestPayload as q, type IBatchResponsePayload as r, RENDERER_EVENT_TYPE as s, type IRendererEventMessage as t, createRendererEventMessage as u, isRendererEventMessage as v, type RendererEventHandler as w, type RendererEventSubscription as x, RendererEventRegistry as y, type RendererClientOptions as z };
|