@noxfly/noxus 1.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.
@@ -0,0 +1,231 @@
1
+ type MaybeAsync<T> = T | Promise<T>;
2
+
3
+ interface IApp {
4
+ dispose(): Promise<void>;
5
+ onReady(): Promise<void>;
6
+ }
7
+ declare function Injectable(lifetime?: Lifetime): ClassDecorator;
8
+ declare function Module(metadata: IModuleMetadata): ClassDecorator;
9
+
10
+ type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
11
+ interface IRouteDefinition {
12
+ method: string;
13
+ path: string;
14
+ controller: Type<any>;
15
+ handler: string;
16
+ guards: Type<IGuard>[];
17
+ }
18
+ type ControllerAction = (request: Request, response: IResponse) => any;
19
+ declare function Controller(path: string): ClassDecorator;
20
+ declare const Get: (path: string) => MethodDecorator;
21
+ declare const Post: (path: string) => MethodDecorator;
22
+ declare const Put: (path: string) => MethodDecorator;
23
+ declare const Patch: (path: string) => MethodDecorator;
24
+ declare const Delete: (path: string) => MethodDecorator;
25
+ declare class Router {
26
+ private readonly routes;
27
+ registerController(controllerClass: Type<unknown>): Router;
28
+ handle(request: Request): Promise<IResponse>;
29
+ private findRoute;
30
+ private resolveController;
31
+ private verifyRequestBody;
32
+ private extractParams;
33
+ }
34
+
35
+ declare class Request {
36
+ readonly app: IApp;
37
+ readonly event: Electron.MessageEvent;
38
+ readonly id: string;
39
+ readonly method: HttpMethod;
40
+ readonly path: string;
41
+ readonly body: any;
42
+ readonly context: any;
43
+ readonly params: Record<string, string>;
44
+ constructor(app: IApp, event: Electron.MessageEvent, id: string, method: HttpMethod, path: string, body: any);
45
+ }
46
+ interface IRequest<T = any> {
47
+ requestId: string;
48
+ path: string;
49
+ method: HttpMethod;
50
+ body?: T;
51
+ }
52
+ interface IResponse<T = any> {
53
+ requestId: string;
54
+ status: number;
55
+ body?: T;
56
+ error?: string;
57
+ }
58
+
59
+ interface IGuard {
60
+ canActivate(request: Request): MaybeAsync<boolean>;
61
+ }
62
+ /**
63
+ * Peut être utilisé pour protéger les routes d'un contrôleur.
64
+ * Peut être utilisé sur une classe controleur, ou sur une méthode de contrôleur.
65
+ */
66
+ declare function Authorize(...guardClasses: Type<IGuard>[]): MethodDecorator & ClassDecorator;
67
+ declare function getGuardForController(controllerName: string): Type<IGuard>[];
68
+ declare function getGuardForControllerAction(controllerName: string, actionName: string): Type<IGuard>[];
69
+
70
+ interface Type<T> extends Function {
71
+ new (...args: any[]): T;
72
+ }
73
+ declare const MODULE_METADATA_KEY: unique symbol;
74
+ declare const INJECTABLE_METADATA_KEY: unique symbol;
75
+ declare const CONTROLLER_METADATA_KEY: unique symbol;
76
+ declare const ROUTE_METADATA_KEY: unique symbol;
77
+ interface IModuleMetadata {
78
+ imports?: Type<unknown>[];
79
+ providers?: Type<unknown>[];
80
+ controllers?: Type<unknown>[];
81
+ exports?: Type<unknown>[];
82
+ }
83
+ interface IRouteMetadata {
84
+ method: HttpMethod;
85
+ path: string;
86
+ handler: string;
87
+ guards: Type<IGuard>[];
88
+ }
89
+ interface IControllerMetadata {
90
+ path: string;
91
+ guards: Type<IGuard>[];
92
+ }
93
+ declare function getControllerMetadata(target: Type<unknown>): IControllerMetadata | undefined;
94
+ declare function getRouteMetadata(target: Type<unknown>): IRouteMetadata[];
95
+ declare function getModuleMetadata(target: Function): IModuleMetadata | undefined;
96
+ declare function getInjectableMetadata(target: Type<unknown>): Lifetime | undefined;
97
+
98
+ type Lifetime = 'singleton' | 'scope' | 'transient';
99
+ interface IBinding {
100
+ lifetime: Lifetime;
101
+ implementation: Type<unknown>;
102
+ instance?: InstanceType<Type<unknown>>;
103
+ }
104
+ declare class AppInjector {
105
+ readonly name: string | null;
106
+ bindings: Map<Type<unknown>, IBinding>;
107
+ singletons: Map<Type<unknown>, unknown>;
108
+ scoped: Map<Type<unknown>, unknown>;
109
+ constructor(name?: string | null);
110
+ /**
111
+ * Utilisé généralement pour créer un scope d'injection de dépendances
112
+ * au niveau "scope" (donc durée de vie d'une requête)
113
+ */
114
+ createScope(): AppInjector;
115
+ /**
116
+ * Appelé lorsqu'on souhaite résoudre une dépendance,
117
+ * c'est-à-dire récupérer l'instance d'une classe donnée.
118
+ */
119
+ resolve<T extends Type<unknown>>(target: T): InstanceType<T>;
120
+ /**
121
+ *
122
+ */
123
+ private instantiate;
124
+ }
125
+ declare const RootInjector: AppInjector;
126
+
127
+ /**
128
+ *
129
+ */
130
+ declare function bootstrapApplication(root: Type<IApp>, rootModule: Type<any>): Promise<IApp>;
131
+
132
+ declare abstract class ResponseException extends Error {
133
+ abstract readonly status: number;
134
+ constructor(message: string);
135
+ }
136
+ declare class BadRequestException extends ResponseException {
137
+ readonly status = 400;
138
+ }
139
+ declare class UnauthorizedException extends ResponseException {
140
+ readonly status = 401;
141
+ }
142
+ declare class ForbiddenException extends ResponseException {
143
+ readonly status = 403;
144
+ }
145
+ declare class NotFoundException extends ResponseException {
146
+ readonly status = 404;
147
+ }
148
+ declare class MethodNotAllowedException extends ResponseException {
149
+ readonly status = 405;
150
+ }
151
+ declare class NotAcceptableException extends ResponseException {
152
+ readonly status = 406;
153
+ }
154
+ declare class RequestTimeoutException extends ResponseException {
155
+ readonly status = 408;
156
+ }
157
+ declare class ConflictException extends ResponseException {
158
+ readonly status = 409;
159
+ }
160
+ declare class UpgradeRequiredException extends ResponseException {
161
+ readonly status = 426;
162
+ }
163
+ declare class TooManyRequestsException extends ResponseException {
164
+ readonly status = 429;
165
+ }
166
+ declare class InternalServerException extends ResponseException {
167
+ readonly status = 500;
168
+ }
169
+ declare class NotImplementedException extends ResponseException {
170
+ readonly status = 501;
171
+ }
172
+ declare class BadGatewayException extends ResponseException {
173
+ readonly status = 502;
174
+ }
175
+ declare class ServiceUnavailableException extends ResponseException {
176
+ readonly status = 503;
177
+ }
178
+ declare class GatewayTimeoutException extends ResponseException {
179
+ readonly status = 504;
180
+ }
181
+ declare class HttpVersionNotSupportedException extends ResponseException {
182
+ readonly status = 505;
183
+ }
184
+ declare class VariantAlsoNegotiatesException extends ResponseException {
185
+ readonly status = 506;
186
+ }
187
+ declare class InsufficientStorageException extends ResponseException {
188
+ readonly status = 507;
189
+ }
190
+ declare class LoopDetectedException extends ResponseException {
191
+ readonly status = 508;
192
+ }
193
+ declare class NotExtendedException extends ResponseException {
194
+ readonly status = 510;
195
+ }
196
+ declare class NetworkAuthenticationRequiredException extends ResponseException {
197
+ readonly status = 511;
198
+ }
199
+ declare class NetworkConnectTimeoutException extends ResponseException {
200
+ readonly status = 599;
201
+ }
202
+
203
+ type LogLevel = 'log' | 'info' | 'warn' | 'error' | 'debug';
204
+ declare namespace Logger {
205
+ function setLogLevel(level: LogLevel): void;
206
+ const colors: {
207
+ black: string;
208
+ grey: string;
209
+ red: string;
210
+ green: string;
211
+ brown: string;
212
+ blue: string;
213
+ purple: string;
214
+ darkGrey: string;
215
+ lightRed: string;
216
+ lightGreen: string;
217
+ yellow: string;
218
+ lightBlue: string;
219
+ magenta: string;
220
+ cyan: string;
221
+ white: string;
222
+ initial: string;
223
+ };
224
+ function log(...args: any[]): void;
225
+ function info(...args: any[]): void;
226
+ function warn(...args: any[]): void;
227
+ function error(...args: any[]): void;
228
+ function debug(...args: any[]): void;
229
+ }
230
+
231
+ export { 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 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, NotAcceptableException, NotExtendedException, NotFoundException, NotImplementedException, Patch, Post, Put, ROUTE_METADATA_KEY, Request, RequestTimeoutException, ResponseException, RootInjector, Router, ServiceUnavailableException, TooManyRequestsException, type Type, UnauthorizedException, UpgradeRequiredException, VariantAlsoNegotiatesException, bootstrapApplication, getControllerMetadata, getGuardForController, getGuardForControllerAction, getInjectableMetadata, getModuleMetadata, getRouteMetadata };