@noxfly/noxus 3.0.0-dev.3 → 3.0.0-dev.4

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/main.d.ts CHANGED
@@ -119,6 +119,12 @@ declare class AppInjector {
119
119
  * The global root injector. All singletons live here.
120
120
  */
121
121
  declare const RootInjector: AppInjector;
122
+ /**
123
+ * Resets the root injector to a clean state.
124
+ * **Intended for testing only** — clears all bindings, singletons, and scoped instances
125
+ * so that each test can start from a fresh DI container without restarting the process.
126
+ */
127
+ declare function resetRootInjector(): void;
122
128
  /**
123
129
  * Convenience function: resolve a token from the root injector.
124
130
  */
@@ -172,10 +178,11 @@ declare class Request {
172
178
  readonly id: string;
173
179
  readonly method: HttpMethod;
174
180
  readonly path: string;
175
- readonly body: any;
181
+ readonly body: unknown;
176
182
  readonly context: AppInjector;
177
183
  readonly params: Record<string, string>;
178
- constructor(event: Electron.MessageEvent, senderId: number, id: string, method: HttpMethod, path: string, body: any);
184
+ readonly query: Record<string, string>;
185
+ constructor(event: Electron.MessageEvent, senderId: number, id: string, method: HttpMethod, path: string, body: unknown, query?: Record<string, string>);
179
186
  }
180
187
  /**
181
188
  * The IRequest interface defines the structure of a request object.
@@ -188,12 +195,14 @@ interface IRequest<TBody = unknown> {
188
195
  path: string;
189
196
  method: HttpMethod;
190
197
  body?: TBody;
198
+ query?: Record<string, string>;
191
199
  }
192
200
  interface IBatchRequestItem<TBody = unknown> {
193
201
  requestId?: string;
194
202
  path: string;
195
203
  method: AtomicHttpMethod;
196
204
  body?: TBody;
205
+ query?: Record<string, string>;
197
206
  }
198
207
  interface IBatchRequestPayload {
199
208
  requests: IBatchRequestItem[];
@@ -252,6 +261,14 @@ declare class Router {
252
261
  registerController(controllerClass: Type<unknown>, pathPrefix: string, routeGuards?: Guard[], routeMiddlewares?: Middleware[]): this;
253
262
  registerLazyRoute(pathPrefix: string, load: () => Promise<unknown>, guards?: Guard[], middlewares?: Middleware[]): this;
254
263
  defineRootMiddleware(middleware: Middleware): this;
264
+ getRegisteredRoutes(): Array<{
265
+ method: string;
266
+ path: string;
267
+ }>;
268
+ getLazyRoutes(): Array<{
269
+ prefix: string;
270
+ loaded: boolean;
271
+ }>;
255
272
  handle(request: Request): Promise<IResponse>;
256
273
  private handleAtomic;
257
274
  private handleBatch;
@@ -290,6 +307,11 @@ interface WindowRecord {
290
307
  window: BrowserWindow;
291
308
  id: number;
292
309
  }
310
+ /**
311
+ * @description
312
+ * The events emitted by WindowManager when windows are created, closed, focused, or blurred.
313
+ */
314
+ type WindowEvent = 'created' | 'closed' | 'focused' | 'blurred';
293
315
  /**
294
316
  * WindowManager is a singleton service that centralizes BrowserWindow lifecycle.
295
317
  *
@@ -314,6 +336,7 @@ interface WindowRecord {
314
336
  */
315
337
  declare class WindowManager {
316
338
  private readonly _windows;
339
+ private readonly listeners;
317
340
  private _mainWindowId;
318
341
  /**
319
342
  * Creates a BrowserWindow, optionally performs an animated expand to the
@@ -372,6 +395,8 @@ declare class WindowManager {
372
395
  * Broadcasts a message to all open windows.
373
396
  */
374
397
  broadcast(channel: string, ...args: unknown[]): void;
398
+ on(event: WindowEvent, handler: (win: BrowserWindow) => void): () => void;
399
+ private _emit;
375
400
  private _register;
376
401
  /**
377
402
  * Animates the window to the full work area of the primary display.
@@ -381,6 +406,20 @@ declare class WindowManager {
381
406
  private _expandToWorkArea;
382
407
  }
383
408
 
409
+ interface RendererChannels {
410
+ request: Electron.MessageChannelMain;
411
+ socket: Electron.MessageChannelMain;
412
+ }
413
+ declare class NoxSocket {
414
+ private readonly channels;
415
+ register(senderId: number, requestChannel: Electron.MessageChannelMain, socketChannel: Electron.MessageChannelMain): void;
416
+ get(senderId: number): RendererChannels | undefined;
417
+ unregister(senderId: number): void;
418
+ getSenderIds(): number[];
419
+ emit<TPayload = unknown>(eventName: string, payload?: TPayload, targetSenderIds?: number[]): void;
420
+ emitToRenderer<TPayload = unknown>(senderId: number, eventName: string, payload?: TPayload): boolean;
421
+ }
422
+
384
423
 
385
424
  /**
386
425
  * Your application service should implement IApp.
@@ -410,10 +449,11 @@ interface IApp {
410
449
  onActivated(): Promise<void>;
411
450
  }
412
451
  declare class NoxApp {
413
- private appService;
414
452
  private readonly router;
415
453
  private readonly socket;
416
454
  readonly windowManager: WindowManager;
455
+ private appService;
456
+ constructor(router: Router, socket: NoxSocket, windowManager: WindowManager);
417
457
  init(): Promise<this>;
418
458
  /**
419
459
  * Registers a lazy route. The file behind this prefix is dynamically
@@ -455,6 +495,107 @@ declare class NoxApp {
455
495
  private shutdownChannel;
456
496
  }
457
497
 
498
+ /**
499
+ * Logger is a utility class for logging messages to the console.
500
+ */
501
+ type LogLevel = 'debug' | 'comment' | 'log' | 'info' | 'warn' | 'error' | 'critical';
502
+ declare namespace Logger {
503
+ /**
504
+ * Sets the log level for the logger.
505
+ * This function allows you to change the log level dynamically at runtime.
506
+ * This won't affect the startup logs.
507
+ *
508
+ * If the parameter is a single LogLevel, all log levels with equal or higher severity will be enabled.
509
+
510
+ * If the parameter is an array of LogLevels, only the specified levels will be enabled.
511
+ *
512
+ * @param level Sets the log level for the logger.
513
+ */
514
+ function setLogLevel(level: LogLevel | LogLevel[]): void;
515
+ /**
516
+ * Logs a message to the console with log level LOG.
517
+ * This function formats the message with a timestamp, process ID, and the name of the caller function or class.
518
+ * It uses different colors for different log levels to enhance readability.
519
+ * @param args The arguments to log.
520
+ */
521
+ function log(...args: any[]): void;
522
+ /**
523
+ * Logs a message to the console with log level INFO.
524
+ * This function formats the message with a timestamp, process ID, and the name of the caller function or class.
525
+ * It uses different colors for different log levels to enhance readability.
526
+ * @param args The arguments to log.
527
+ */
528
+ function info(...args: any[]): void;
529
+ /**
530
+ * Logs a message to the console with log level WARN.
531
+ * This function formats the message with a timestamp, process ID, and the name of the caller function or class.
532
+ * It uses different colors for different log levels to enhance readability.
533
+ * @param args The arguments to log.
534
+ */
535
+ function warn(...args: any[]): void;
536
+ /**
537
+ * Logs a message to the console with log level ERROR.
538
+ * This function formats the message with a timestamp, process ID, and the name of the caller function or class.
539
+ * It uses different colors for different log levels to enhance readability.
540
+ * @param args The arguments to log.
541
+ */
542
+ function error(...args: any[]): void;
543
+ /**
544
+ * Logs a message to the console with log level ERROR and a grey color scheme.
545
+ */
546
+ function errorStack(...args: any[]): void;
547
+ /**
548
+ * Logs a message to the console with log level DEBUG.
549
+ * This function formats the message with a timestamp, process ID, and the name of the caller function or class.
550
+ * It uses different colors for different log levels to enhance readability.
551
+ * @param args The arguments to log.
552
+ */
553
+ function debug(...args: any[]): void;
554
+ /**
555
+ * Logs a message to the console with log level COMMENT.
556
+ * This function formats the message with a timestamp, process ID, and the name of the caller function or class.
557
+ * It uses different colors for different log levels to enhance readability.
558
+ * @param args The arguments to log.
559
+ */
560
+ function comment(...args: any[]): void;
561
+ /**
562
+ * Logs a message to the console with log level CRITICAL.
563
+ * This function formats the message with a timestamp, process ID, and the name of the caller function or class.
564
+ * It uses different colors for different log levels to enhance readability.
565
+ * @param args The arguments to log.
566
+ */
567
+ function critical(...args: any[]): void;
568
+ /**
569
+ * Enables logging to a file output for the specified log levels.
570
+ * @param filepath The path to the log file.
571
+ * @param levels The log levels to enable file logging for. Defaults to all levels.
572
+ */
573
+ function enableFileLogging(filepath: string, levels?: LogLevel[]): void;
574
+ /**
575
+ * Disables logging to a file output for the specified log levels.
576
+ * @param levels The log levels to disable file logging for. Defaults to all levels.
577
+ */
578
+ function disableFileLogging(levels?: LogLevel[]): void;
579
+ const colors: {
580
+ black: string;
581
+ grey: string;
582
+ red: string;
583
+ green: string;
584
+ brown: string;
585
+ blue: string;
586
+ purple: string;
587
+ darkGrey: string;
588
+ lightRed: string;
589
+ lightGreen: string;
590
+ yellow: string;
591
+ lightBlue: string;
592
+ magenta: string;
593
+ cyan: string;
594
+ white: string;
595
+ initial: string;
596
+ };
597
+ }
598
+
458
599
 
459
600
  /**
460
601
  * A single route entry in the application routing table.
@@ -469,10 +610,12 @@ interface RouteDefinition {
469
610
  * Dynamic import function returning the controller file.
470
611
  * The controller is loaded lazily on the first IPC request targeting this prefix.
471
612
  *
613
+ * Optional when the route only serves as a parent for `children`.
614
+ *
472
615
  * @example
473
616
  * load: () => import('./modules/users/users.controller')
474
617
  */
475
- load: () => Promise<unknown>;
618
+ load?: () => Promise<unknown>;
476
619
  /**
477
620
  * Guards applied to every action in this controller.
478
621
  * Merged with action-level guards.
@@ -483,6 +626,11 @@ interface RouteDefinition {
483
626
  * Merged with action-level middlewares.
484
627
  */
485
628
  middlewares?: Middleware[];
629
+ /**
630
+ * Nested child routes. Guards and middlewares declared here are
631
+ * inherited (merged) by all children.
632
+ */
633
+ children?: RouteDefinition[];
486
634
  }
487
635
  /**
488
636
  * Defines the application routing table.
@@ -491,6 +639,9 @@ interface RouteDefinition {
491
639
  * This is the single source of truth for routing — no path is declared
492
640
  * in @Controller(), preventing duplicate route prefixes across controllers.
493
641
  *
642
+ * Supports nested routes via the `children` property. Guards and middlewares
643
+ * from parent entries are inherited (merged) into each child.
644
+ *
494
645
  * @example
495
646
  * export const routes = defineRoutes([
496
647
  * {
@@ -499,16 +650,17 @@ interface RouteDefinition {
499
650
  * guards: [authGuard],
500
651
  * },
501
652
  * {
502
- * path: 'orders',
503
- * load: () => import('./modules/orders/orders.controller'),
504
- * guards: [authGuard],
505
- * middlewares: [logMiddleware],
653
+ * path: 'admin',
654
+ * guards: [authGuard, adminGuard],
655
+ * children: [
656
+ * { path: 'users', load: () => import('./admin/users.controller') },
657
+ * { path: 'products', load: () => import('./admin/products.controller') },
658
+ * ],
506
659
  * },
507
660
  * ]);
508
661
  */
509
662
  declare function defineRoutes(routes: RouteDefinition[]): RouteDefinition[];
510
663
 
511
-
512
664
  /**
513
665
  * A singleton value override: provides an already-constructed instance
514
666
  * for a given token, bypassing the DI factory.
@@ -563,6 +715,15 @@ interface BootstrapConfig {
563
715
  * ]
564
716
  */
565
717
  eagerLoad?: Array<() => Promise<unknown>>;
718
+ /**
719
+ * Controls framework log verbosity.
720
+ * - `'debug'`: all messages (default during development).
721
+ * - `'info'`: info, warn, error, critical only.
722
+ * - `'none'`: completely silent — no framework logs.
723
+ *
724
+ * You can also pass an array of specific log levels to enable.
725
+ */
726
+ logLevel?: 'debug' | 'info' | 'none' | LogLevel[];
566
727
  }
567
728
  /**
568
729
  * Bootstraps the Noxus application.
@@ -721,119 +882,4 @@ interface InjectableOptions {
721
882
  */
722
883
  declare function Injectable(options?: InjectableOptions): ClassDecorator;
723
884
 
724
- /**
725
- * Logger is a utility class for logging messages to the console.
726
- */
727
- type LogLevel = 'debug' | 'comment' | 'log' | 'info' | 'warn' | 'error' | 'critical';
728
- declare namespace Logger {
729
- /**
730
- * Sets the log level for the logger.
731
- * This function allows you to change the log level dynamically at runtime.
732
- * This won't affect the startup logs.
733
- *
734
- * If the parameter is a single LogLevel, all log levels with equal or higher severity will be enabled.
735
-
736
- * If the parameter is an array of LogLevels, only the specified levels will be enabled.
737
- *
738
- * @param level Sets the log level for the logger.
739
- */
740
- function setLogLevel(level: LogLevel | LogLevel[]): void;
741
- /**
742
- * Logs a message to the console with log level LOG.
743
- * This function formats the message with a timestamp, process ID, and the name of the caller function or class.
744
- * It uses different colors for different log levels to enhance readability.
745
- * @param args The arguments to log.
746
- */
747
- function log(...args: any[]): void;
748
- /**
749
- * Logs a message to the console with log level INFO.
750
- * This function formats the message with a timestamp, process ID, and the name of the caller function or class.
751
- * It uses different colors for different log levels to enhance readability.
752
- * @param args The arguments to log.
753
- */
754
- function info(...args: any[]): void;
755
- /**
756
- * Logs a message to the console with log level WARN.
757
- * This function formats the message with a timestamp, process ID, and the name of the caller function or class.
758
- * It uses different colors for different log levels to enhance readability.
759
- * @param args The arguments to log.
760
- */
761
- function warn(...args: any[]): void;
762
- /**
763
- * Logs a message to the console with log level ERROR.
764
- * This function formats the message with a timestamp, process ID, and the name of the caller function or class.
765
- * It uses different colors for different log levels to enhance readability.
766
- * @param args The arguments to log.
767
- */
768
- function error(...args: any[]): void;
769
- /**
770
- * Logs a message to the console with log level ERROR and a grey color scheme.
771
- */
772
- function errorStack(...args: any[]): void;
773
- /**
774
- * Logs a message to the console with log level DEBUG.
775
- * This function formats the message with a timestamp, process ID, and the name of the caller function or class.
776
- * It uses different colors for different log levels to enhance readability.
777
- * @param args The arguments to log.
778
- */
779
- function debug(...args: any[]): void;
780
- /**
781
- * Logs a message to the console with log level COMMENT.
782
- * This function formats the message with a timestamp, process ID, and the name of the caller function or class.
783
- * It uses different colors for different log levels to enhance readability.
784
- * @param args The arguments to log.
785
- */
786
- function comment(...args: any[]): void;
787
- /**
788
- * Logs a message to the console with log level CRITICAL.
789
- * This function formats the message with a timestamp, process ID, and the name of the caller function or class.
790
- * It uses different colors for different log levels to enhance readability.
791
- * @param args The arguments to log.
792
- */
793
- function critical(...args: any[]): void;
794
- /**
795
- * Enables logging to a file output for the specified log levels.
796
- * @param filepath The path to the log file.
797
- * @param levels The log levels to enable file logging for. Defaults to all levels.
798
- */
799
- function enableFileLogging(filepath: string, levels?: LogLevel[]): void;
800
- /**
801
- * Disables logging to a file output for the specified log levels.
802
- * @param levels The log levels to disable file logging for. Defaults to all levels.
803
- */
804
- function disableFileLogging(levels?: LogLevel[]): void;
805
- const colors: {
806
- black: string;
807
- grey: string;
808
- red: string;
809
- green: string;
810
- brown: string;
811
- blue: string;
812
- purple: string;
813
- darkGrey: string;
814
- lightRed: string;
815
- lightGreen: string;
816
- yellow: string;
817
- lightBlue: string;
818
- magenta: string;
819
- cyan: string;
820
- white: string;
821
- initial: string;
822
- };
823
- }
824
-
825
- interface RendererChannels {
826
- request: Electron.MessageChannelMain;
827
- socket: Electron.MessageChannelMain;
828
- }
829
- declare class NoxSocket {
830
- private readonly channels;
831
- register(senderId: number, requestChannel: Electron.MessageChannelMain, socketChannel: Electron.MessageChannelMain): void;
832
- get(senderId: number): RendererChannels | undefined;
833
- unregister(senderId: number): void;
834
- getSenderIds(): number[];
835
- emit<TPayload = unknown>(eventName: string, payload?: TPayload, targetSenderIds?: number[]): number;
836
- emitToRenderer<TPayload = unknown>(senderId: number, eventName: string, payload?: TPayload): boolean;
837
- }
838
-
839
- export { AppInjector, type AtomicHttpMethod, BadGatewayException, BadRequestException, type BootstrapConfig, ConflictException, Controller, type ControllerAction, type ControllerOptions, Delete, ForbiddenException, type ForwardRefFn, ForwardReference, GatewayTimeoutException, Get, type Guard, type HttpMethod, HttpVersionNotSupportedException, type IApp, type IBatchRequestItem, type IBatchRequestPayload, type IBatchResponsePayload, type IBinding, type IControllerMetadata, type ILazyRoute, type IRendererEventMessage, type IRequest, type IResponse, type IRouteDefinition, type IRouteMetadata, type IRouteOptions, Injectable, type InjectableOptions, InsufficientStorageException, InternalServerException, type Lifetime, type LogLevel, Logger, LoopDetectedException, type MaybeAsync, MethodNotAllowedException, type Middleware, NetworkAuthenticationRequiredException, NetworkConnectTimeoutException, type NextFunction, NotAcceptableException, NotExtendedException, NotFoundException, NotImplementedException, NoxApp, NoxSocket, Patch, PaymentRequiredException, Post, Put, RENDERER_EVENT_TYPE, Request, RequestTimeoutException, ResponseException, RootInjector, type RouteDefinition, Router, ServiceUnavailableException, type SingletonOverride, Token, type TokenKey, TooManyRequestsException, type Type, UnauthorizedException, UpgradeRequiredException, VariantAlsoNegotiatesException, type WindowConfig, WindowManager, type WindowRecord, bootstrapApplication, createRendererEventMessage, defineRoutes, forwardRef, getControllerMetadata, getRouteMetadata, inject, isAtomicHttpMethod, isRendererEventMessage, token };
885
+ export { AppInjector, type AtomicHttpMethod, BadGatewayException, BadRequestException, type BootstrapConfig, ConflictException, Controller, type ControllerAction, type ControllerOptions, Delete, ForbiddenException, type ForwardRefFn, ForwardReference, GatewayTimeoutException, Get, type Guard, type HttpMethod, HttpVersionNotSupportedException, type IApp, type IBatchRequestItem, type IBatchRequestPayload, type IBatchResponsePayload, type IBinding, type IControllerMetadata, type ILazyRoute, type IRendererEventMessage, type IRequest, type IResponse, type IRouteDefinition, type IRouteMetadata, type IRouteOptions, Injectable, type InjectableOptions, InsufficientStorageException, InternalServerException, type Lifetime, type LogLevel, Logger, LoopDetectedException, type MaybeAsync, MethodNotAllowedException, type Middleware, NetworkAuthenticationRequiredException, NetworkConnectTimeoutException, type NextFunction, NotAcceptableException, NotExtendedException, NotFoundException, NotImplementedException, NoxApp, NoxSocket, Patch, PaymentRequiredException, Post, Put, RENDERER_EVENT_TYPE, Request, RequestTimeoutException, ResponseException, RootInjector, type RouteDefinition, Router, ServiceUnavailableException, type SingletonOverride, Token, type TokenKey, TooManyRequestsException, type Type, UnauthorizedException, UpgradeRequiredException, VariantAlsoNegotiatesException, type WindowConfig, type WindowEvent, WindowManager, type WindowRecord, bootstrapApplication, createRendererEventMessage, defineRoutes, forwardRef, getControllerMetadata, getRouteMetadata, inject, isAtomicHttpMethod, isRendererEventMessage, resetRootInjector, token };