@noxfly/noxus 3.0.0-dev.2 → 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.mts 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
@@ -347,6 +370,7 @@ declare class WindowManager {
347
370
  */
348
371
  createSplash(options?: Electron.BrowserWindowConstructorOptions & {
349
372
  animationDuration?: number;
373
+ expandToWorkArea?: boolean;
350
374
  }): Promise<BrowserWindow>;
351
375
  /** Returns all currently open windows. */
352
376
  getAll(): BrowserWindow[];
@@ -371,6 +395,8 @@ declare class WindowManager {
371
395
  * Broadcasts a message to all open windows.
372
396
  */
373
397
  broadcast(channel: string, ...args: unknown[]): void;
398
+ on(event: WindowEvent, handler: (win: BrowserWindow) => void): () => void;
399
+ private _emit;
374
400
  private _register;
375
401
  /**
376
402
  * Animates the window to the full work area of the primary display.
@@ -380,6 +406,20 @@ declare class WindowManager {
380
406
  private _expandToWorkArea;
381
407
  }
382
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
+
383
423
 
384
424
  /**
385
425
  * Your application service should implement IApp.
@@ -409,10 +449,11 @@ interface IApp {
409
449
  onActivated(): Promise<void>;
410
450
  }
411
451
  declare class NoxApp {
412
- private appService;
413
452
  private readonly router;
414
453
  private readonly socket;
415
454
  readonly windowManager: WindowManager;
455
+ private appService;
456
+ constructor(router: Router, socket: NoxSocket, windowManager: WindowManager);
416
457
  init(): Promise<this>;
417
458
  /**
418
459
  * Registers a lazy route. The file behind this prefix is dynamically
@@ -454,6 +495,107 @@ declare class NoxApp {
454
495
  private shutdownChannel;
455
496
  }
456
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
+
457
599
 
458
600
  /**
459
601
  * A single route entry in the application routing table.
@@ -468,10 +610,12 @@ interface RouteDefinition {
468
610
  * Dynamic import function returning the controller file.
469
611
  * The controller is loaded lazily on the first IPC request targeting this prefix.
470
612
  *
613
+ * Optional when the route only serves as a parent for `children`.
614
+ *
471
615
  * @example
472
616
  * load: () => import('./modules/users/users.controller')
473
617
  */
474
- load: () => Promise<unknown>;
618
+ load?: () => Promise<unknown>;
475
619
  /**
476
620
  * Guards applied to every action in this controller.
477
621
  * Merged with action-level guards.
@@ -482,6 +626,11 @@ interface RouteDefinition {
482
626
  * Merged with action-level middlewares.
483
627
  */
484
628
  middlewares?: Middleware[];
629
+ /**
630
+ * Nested child routes. Guards and middlewares declared here are
631
+ * inherited (merged) by all children.
632
+ */
633
+ children?: RouteDefinition[];
485
634
  }
486
635
  /**
487
636
  * Defines the application routing table.
@@ -490,6 +639,9 @@ interface RouteDefinition {
490
639
  * This is the single source of truth for routing — no path is declared
491
640
  * in @Controller(), preventing duplicate route prefixes across controllers.
492
641
  *
642
+ * Supports nested routes via the `children` property. Guards and middlewares
643
+ * from parent entries are inherited (merged) into each child.
644
+ *
493
645
  * @example
494
646
  * export const routes = defineRoutes([
495
647
  * {
@@ -498,16 +650,17 @@ interface RouteDefinition {
498
650
  * guards: [authGuard],
499
651
  * },
500
652
  * {
501
- * path: 'orders',
502
- * load: () => import('./modules/orders/orders.controller'),
503
- * guards: [authGuard],
504
- * 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
+ * ],
505
659
  * },
506
660
  * ]);
507
661
  */
508
662
  declare function defineRoutes(routes: RouteDefinition[]): RouteDefinition[];
509
663
 
510
-
511
664
  /**
512
665
  * A singleton value override: provides an already-constructed instance
513
666
  * for a given token, bypassing the DI factory.
@@ -562,6 +715,15 @@ interface BootstrapConfig {
562
715
  * ]
563
716
  */
564
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[];
565
727
  }
566
728
  /**
567
729
  * Bootstraps the Noxus application.
@@ -720,119 +882,4 @@ interface InjectableOptions {
720
882
  */
721
883
  declare function Injectable(options?: InjectableOptions): ClassDecorator;
722
884
 
723
- /**
724
- * Logger is a utility class for logging messages to the console.
725
- */
726
- type LogLevel = 'debug' | 'comment' | 'log' | 'info' | 'warn' | 'error' | 'critical';
727
- declare namespace Logger {
728
- /**
729
- * Sets the log level for the logger.
730
- * This function allows you to change the log level dynamically at runtime.
731
- * This won't affect the startup logs.
732
- *
733
- * If the parameter is a single LogLevel, all log levels with equal or higher severity will be enabled.
734
-
735
- * If the parameter is an array of LogLevels, only the specified levels will be enabled.
736
- *
737
- * @param level Sets the log level for the logger.
738
- */
739
- function setLogLevel(level: LogLevel | LogLevel[]): void;
740
- /**
741
- * Logs a message to the console with log level LOG.
742
- * This function formats the message with a timestamp, process ID, and the name of the caller function or class.
743
- * It uses different colors for different log levels to enhance readability.
744
- * @param args The arguments to log.
745
- */
746
- function log(...args: any[]): void;
747
- /**
748
- * Logs a message to the console with log level INFO.
749
- * This function formats the message with a timestamp, process ID, and the name of the caller function or class.
750
- * It uses different colors for different log levels to enhance readability.
751
- * @param args The arguments to log.
752
- */
753
- function info(...args: any[]): void;
754
- /**
755
- * Logs a message to the console with log level WARN.
756
- * This function formats the message with a timestamp, process ID, and the name of the caller function or class.
757
- * It uses different colors for different log levels to enhance readability.
758
- * @param args The arguments to log.
759
- */
760
- function warn(...args: any[]): void;
761
- /**
762
- * Logs a message to the console with log level ERROR.
763
- * This function formats the message with a timestamp, process ID, and the name of the caller function or class.
764
- * It uses different colors for different log levels to enhance readability.
765
- * @param args The arguments to log.
766
- */
767
- function error(...args: any[]): void;
768
- /**
769
- * Logs a message to the console with log level ERROR and a grey color scheme.
770
- */
771
- function errorStack(...args: any[]): void;
772
- /**
773
- * Logs a message to the console with log level DEBUG.
774
- * This function formats the message with a timestamp, process ID, and the name of the caller function or class.
775
- * It uses different colors for different log levels to enhance readability.
776
- * @param args The arguments to log.
777
- */
778
- function debug(...args: any[]): void;
779
- /**
780
- * Logs a message to the console with log level COMMENT.
781
- * This function formats the message with a timestamp, process ID, and the name of the caller function or class.
782
- * It uses different colors for different log levels to enhance readability.
783
- * @param args The arguments to log.
784
- */
785
- function comment(...args: any[]): void;
786
- /**
787
- * Logs a message to the console with log level CRITICAL.
788
- * This function formats the message with a timestamp, process ID, and the name of the caller function or class.
789
- * It uses different colors for different log levels to enhance readability.
790
- * @param args The arguments to log.
791
- */
792
- function critical(...args: any[]): void;
793
- /**
794
- * Enables logging to a file output for the specified log levels.
795
- * @param filepath The path to the log file.
796
- * @param levels The log levels to enable file logging for. Defaults to all levels.
797
- */
798
- function enableFileLogging(filepath: string, levels?: LogLevel[]): void;
799
- /**
800
- * Disables logging to a file output for the specified log levels.
801
- * @param levels The log levels to disable file logging for. Defaults to all levels.
802
- */
803
- function disableFileLogging(levels?: LogLevel[]): void;
804
- const colors: {
805
- black: string;
806
- grey: string;
807
- red: string;
808
- green: string;
809
- brown: string;
810
- blue: string;
811
- purple: string;
812
- darkGrey: string;
813
- lightRed: string;
814
- lightGreen: string;
815
- yellow: string;
816
- lightBlue: string;
817
- magenta: string;
818
- cyan: string;
819
- white: string;
820
- initial: string;
821
- };
822
- }
823
-
824
- interface RendererChannels {
825
- request: Electron.MessageChannelMain;
826
- socket: Electron.MessageChannelMain;
827
- }
828
- declare class NoxSocket {
829
- private readonly channels;
830
- register(senderId: number, requestChannel: Electron.MessageChannelMain, socketChannel: Electron.MessageChannelMain): void;
831
- get(senderId: number): RendererChannels | undefined;
832
- unregister(senderId: number): void;
833
- getSenderIds(): number[];
834
- emit<TPayload = unknown>(eventName: string, payload?: TPayload, targetSenderIds?: number[]): number;
835
- emitToRenderer<TPayload = unknown>(senderId: number, eventName: string, payload?: TPayload): boolean;
836
- }
837
-
838
- 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 };