@noxfly/noxus 2.5.0 → 3.0.0-dev.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.
Files changed (48) hide show
  1. package/README.md +403 -341
  2. package/dist/app-injector-Bz3Upc0y.d.mts +125 -0
  3. package/dist/app-injector-Bz3Upc0y.d.ts +125 -0
  4. package/dist/child.d.mts +48 -22
  5. package/dist/child.d.ts +48 -22
  6. package/dist/child.js +1111 -1341
  7. package/dist/child.mjs +1087 -1295
  8. package/dist/main.d.mts +301 -309
  9. package/dist/main.d.ts +301 -309
  10. package/dist/main.js +1471 -1650
  11. package/dist/main.mjs +1420 -1570
  12. package/dist/renderer.d.mts +3 -3
  13. package/dist/renderer.d.ts +3 -3
  14. package/dist/renderer.js +109 -135
  15. package/dist/renderer.mjs +109 -135
  16. package/dist/request-BlTtiHbi.d.ts +112 -0
  17. package/dist/request-qJ9EiDZc.d.mts +112 -0
  18. package/package.json +7 -7
  19. package/src/DI/app-injector.ts +95 -106
  20. package/src/DI/injector-explorer.ts +93 -119
  21. package/src/DI/token.ts +53 -0
  22. package/src/app.ts +141 -168
  23. package/src/bootstrap.ts +78 -54
  24. package/src/decorators/controller.decorator.ts +38 -27
  25. package/src/decorators/guards.decorator.ts +5 -64
  26. package/src/decorators/injectable.decorator.ts +68 -15
  27. package/src/decorators/method.decorator.ts +40 -81
  28. package/src/decorators/middleware.decorator.ts +5 -72
  29. package/src/index.ts +2 -0
  30. package/src/main.ts +4 -8
  31. package/src/non-electron-process.ts +0 -1
  32. package/src/preload-bridge.ts +1 -1
  33. package/src/renderer-client.ts +2 -2
  34. package/src/renderer-events.ts +1 -1
  35. package/src/request.ts +3 -3
  36. package/src/router.ts +190 -431
  37. package/src/routes.ts +78 -0
  38. package/src/socket.ts +4 -4
  39. package/src/window/window-manager.ts +255 -0
  40. package/tsconfig.json +5 -10
  41. package/tsup.config.ts +2 -2
  42. package/dist/app-injector-B3MvgV3k.d.mts +0 -95
  43. package/dist/app-injector-B3MvgV3k.d.ts +0 -95
  44. package/dist/request-CdpZ9qZL.d.ts +0 -167
  45. package/dist/request-Dx_5Prte.d.mts +0 -167
  46. package/src/decorators/inject.decorator.ts +0 -24
  47. package/src/decorators/injectable.metadata.ts +0 -15
  48. package/src/decorators/module.decorator.ts +0 -75
@@ -0,0 +1,125 @@
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
+ * A function that returns a type.
17
+ * Used for forward references to types that are not yet defined.
18
+ */
19
+ interface ForwardRefFn<T = any> {
20
+ (): Type<T>;
21
+ }
22
+ /**
23
+ * A wrapper class for forward referenced types.
24
+ */
25
+ declare class ForwardReference<T = any> {
26
+ readonly forwardRefFn: ForwardRefFn<T>;
27
+ constructor(forwardRefFn: ForwardRefFn<T>);
28
+ }
29
+ /**
30
+ * Creates a forward reference to a type.
31
+ * @param fn A function that returns the type.
32
+ * @returns A ForwardReference instance.
33
+ */
34
+ declare function forwardRef<T = any>(fn: ForwardRefFn<T>): ForwardReference<T>;
35
+
36
+
37
+ /**
38
+ * A DI token uniquely identifies a dependency.
39
+ * It can wrap a class (Type<T>) or be a named symbol token.
40
+ *
41
+ * Using tokens instead of reflect-metadata means dependencies are
42
+ * declared explicitly — no magic type inference, no emitDecoratorMetadata.
43
+ *
44
+ * @example
45
+ * // Class token (most common)
46
+ * const MY_SERVICE = token(MyService);
47
+ *
48
+ * // Named symbol token (for interfaces or non-class values)
49
+ * const DB_URL = token<string>('DB_URL');
50
+ */
51
+ declare class Token<T> {
52
+ readonly target: Type<T> | string;
53
+ readonly description: string;
54
+ constructor(target: Type<T> | string);
55
+ toString(): string;
56
+ }
57
+ /**
58
+ * Creates a DI token for a class type or a named value.
59
+ *
60
+ * @example
61
+ * export const MY_SERVICE = token(MyService);
62
+ * export const DB_URL = token<string>('DB_URL');
63
+ */
64
+ declare function token<T>(target: Type<T> | string): Token<T>;
65
+ /**
66
+ * The key used to look up a class token in the registry.
67
+ * For class tokens, the key is the class constructor itself.
68
+ * For named tokens, the key is the Token instance.
69
+ */
70
+ type TokenKey<T = unknown> = Type<T> | Token<T>;
71
+
72
+
73
+ /**
74
+ * Lifetime of a binding in the DI container.
75
+ * - singleton: created once, shared for the lifetime of the app.
76
+ * - scope: created once per request scope.
77
+ * - transient: new instance every time it is resolved.
78
+ */
79
+ type Lifetime = 'singleton' | 'scope' | 'transient';
80
+ /**
81
+ * Internal representation of a registered binding.
82
+ */
83
+ interface IBinding<T = unknown> {
84
+ lifetime: Lifetime;
85
+ implementation: Type<T>;
86
+ /** Explicit constructor dependencies, declared by the class itself. */
87
+ deps: ReadonlyArray<TokenKey>;
88
+ instance?: T;
89
+ }
90
+ /**
91
+ * AppInjector is the core DI container.
92
+ * It no longer uses reflect-metadata — all dependency information
93
+ * comes from explicitly declared `deps` arrays on each binding.
94
+ */
95
+ declare class AppInjector {
96
+ readonly name: string | null;
97
+ readonly bindings: Map<Type<unknown> | Token<unknown>, IBinding<unknown>>;
98
+ readonly singletons: Map<Type<unknown> | Token<unknown>, unknown>;
99
+ readonly scoped: Map<Type<unknown> | Token<unknown>, unknown>;
100
+ constructor(name?: string | null);
101
+ /**
102
+ * Creates a child scope for per-request lifetime resolution.
103
+ */
104
+ createScope(): AppInjector;
105
+ /**
106
+ * Registers a binding explicitly.
107
+ */
108
+ register<T>(key: TokenKey<T>, implementation: Type<T>, lifetime: Lifetime, deps?: ReadonlyArray<TokenKey>): void;
109
+ /**
110
+ * Resolves a dependency by token or class reference.
111
+ */
112
+ resolve<T>(target: TokenKey<T> | ForwardReference<T>): T;
113
+ private _resolveForwardRef;
114
+ private _instantiate;
115
+ }
116
+ /**
117
+ * The global root injector. All singletons live here.
118
+ */
119
+ declare const RootInjector: AppInjector;
120
+ /**
121
+ * Convenience function: resolve a token from the root injector.
122
+ */
123
+ declare function inject<T>(t: TokenKey<T> | ForwardReference<T>): T;
124
+
125
+ export { AppInjector as A, type ForwardRefFn as F, type IBinding as I, type Lifetime as L, type MaybeAsync as M, RootInjector as R, type Type as T, type TokenKey as a, ForwardReference as b, Token as c, forwardRef as f, inject as i, token as t };
@@ -0,0 +1,125 @@
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
+ * A function that returns a type.
17
+ * Used for forward references to types that are not yet defined.
18
+ */
19
+ interface ForwardRefFn<T = any> {
20
+ (): Type<T>;
21
+ }
22
+ /**
23
+ * A wrapper class for forward referenced types.
24
+ */
25
+ declare class ForwardReference<T = any> {
26
+ readonly forwardRefFn: ForwardRefFn<T>;
27
+ constructor(forwardRefFn: ForwardRefFn<T>);
28
+ }
29
+ /**
30
+ * Creates a forward reference to a type.
31
+ * @param fn A function that returns the type.
32
+ * @returns A ForwardReference instance.
33
+ */
34
+ declare function forwardRef<T = any>(fn: ForwardRefFn<T>): ForwardReference<T>;
35
+
36
+
37
+ /**
38
+ * A DI token uniquely identifies a dependency.
39
+ * It can wrap a class (Type<T>) or be a named symbol token.
40
+ *
41
+ * Using tokens instead of reflect-metadata means dependencies are
42
+ * declared explicitly — no magic type inference, no emitDecoratorMetadata.
43
+ *
44
+ * @example
45
+ * // Class token (most common)
46
+ * const MY_SERVICE = token(MyService);
47
+ *
48
+ * // Named symbol token (for interfaces or non-class values)
49
+ * const DB_URL = token<string>('DB_URL');
50
+ */
51
+ declare class Token<T> {
52
+ readonly target: Type<T> | string;
53
+ readonly description: string;
54
+ constructor(target: Type<T> | string);
55
+ toString(): string;
56
+ }
57
+ /**
58
+ * Creates a DI token for a class type or a named value.
59
+ *
60
+ * @example
61
+ * export const MY_SERVICE = token(MyService);
62
+ * export const DB_URL = token<string>('DB_URL');
63
+ */
64
+ declare function token<T>(target: Type<T> | string): Token<T>;
65
+ /**
66
+ * The key used to look up a class token in the registry.
67
+ * For class tokens, the key is the class constructor itself.
68
+ * For named tokens, the key is the Token instance.
69
+ */
70
+ type TokenKey<T = unknown> = Type<T> | Token<T>;
71
+
72
+
73
+ /**
74
+ * Lifetime of a binding in the DI container.
75
+ * - singleton: created once, shared for the lifetime of the app.
76
+ * - scope: created once per request scope.
77
+ * - transient: new instance every time it is resolved.
78
+ */
79
+ type Lifetime = 'singleton' | 'scope' | 'transient';
80
+ /**
81
+ * Internal representation of a registered binding.
82
+ */
83
+ interface IBinding<T = unknown> {
84
+ lifetime: Lifetime;
85
+ implementation: Type<T>;
86
+ /** Explicit constructor dependencies, declared by the class itself. */
87
+ deps: ReadonlyArray<TokenKey>;
88
+ instance?: T;
89
+ }
90
+ /**
91
+ * AppInjector is the core DI container.
92
+ * It no longer uses reflect-metadata — all dependency information
93
+ * comes from explicitly declared `deps` arrays on each binding.
94
+ */
95
+ declare class AppInjector {
96
+ readonly name: string | null;
97
+ readonly bindings: Map<Type<unknown> | Token<unknown>, IBinding<unknown>>;
98
+ readonly singletons: Map<Type<unknown> | Token<unknown>, unknown>;
99
+ readonly scoped: Map<Type<unknown> | Token<unknown>, unknown>;
100
+ constructor(name?: string | null);
101
+ /**
102
+ * Creates a child scope for per-request lifetime resolution.
103
+ */
104
+ createScope(): AppInjector;
105
+ /**
106
+ * Registers a binding explicitly.
107
+ */
108
+ register<T>(key: TokenKey<T>, implementation: Type<T>, lifetime: Lifetime, deps?: ReadonlyArray<TokenKey>): void;
109
+ /**
110
+ * Resolves a dependency by token or class reference.
111
+ */
112
+ resolve<T>(target: TokenKey<T> | ForwardReference<T>): T;
113
+ private _resolveForwardRef;
114
+ private _instantiate;
115
+ }
116
+ /**
117
+ * The global root injector. All singletons live here.
118
+ */
119
+ declare const RootInjector: AppInjector;
120
+ /**
121
+ * Convenience function: resolve a token from the root injector.
122
+ */
123
+ declare function inject<T>(t: TokenKey<T> | ForwardReference<T>): T;
124
+
125
+ export { AppInjector as A, type ForwardRefFn as F, type IBinding as I, type Lifetime as L, type MaybeAsync as M, RootInjector as R, type Type as T, type TokenKey as a, ForwardReference as b, Token as c, forwardRef as f, inject as i, token as t };
package/dist/child.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { L as Lifetime } from './app-injector-B3MvgV3k.mjs';
2
- export { A as AppInjector, F as ForwardRefFn, a as ForwardReference, I as IBinding, M as MaybeAsync, R as RootInjector, T as Type, f as forwardRef, i as inject } from './app-injector-B3MvgV3k.mjs';
1
+ import { L as Lifetime, a as TokenKey } from './app-injector-Bz3Upc0y.mjs';
2
+ export { A as AppInjector, F as ForwardRefFn, b as ForwardReference, I as IBinding, M as MaybeAsync, R as RootInjector, c as Token, T as Type, f as forwardRef, i as inject } from './app-injector-Bz3Upc0y.mjs';
3
3
 
4
4
  /**
5
5
  * @copyright 2025 NoxFly
@@ -81,29 +81,55 @@ declare class NetworkConnectTimeoutException extends ResponseException {
81
81
  readonly status = 599;
82
82
  }
83
83
 
84
- declare const INJECTABLE_METADATA_KEY: unique symbol;
85
- declare function getInjectableMetadata(target: Function): Lifetime | undefined;
86
- declare function hasInjectableMetadata(target: Function): boolean;
87
84
 
88
-
89
- /**
90
- * The Injectable decorator marks a class as injectable.
91
- * It allows the class to be registered in the dependency injection system.
92
- * A class decorated with @Injectable can be injected into other classes
93
- * either from the constructor of the class that needs it of from the `inject` function.
94
- * @param lifetime - The lifetime of the injectable. Can be 'singleton', 'scope', or 'transient'.
95
- */
96
- declare function Injectable(lifetime?: Lifetime): ClassDecorator;
97
-
98
-
99
- declare const INJECT_METADATA_KEY = "custom:inject";
85
+ interface InjectableOptions {
86
+ /**
87
+ * Lifetime of this injectable.
88
+ * @default 'scope'
89
+ */
90
+ lifetime?: Lifetime;
91
+ /**
92
+ * Explicit list of constructor dependencies, in the same order as the constructor parameters.
93
+ * Each entry is either a class constructor or a Token created with token().
94
+ *
95
+ * This replaces reflect-metadata / emitDecoratorMetadata entirely.
96
+ *
97
+ * @example
98
+ * @Injectable({ lifetime: 'singleton', deps: [MyRepo, DB_URL] })
99
+ * class MyService {
100
+ * constructor(private repo: MyRepo, private dbUrl: string) {}
101
+ * }
102
+ */
103
+ deps?: ReadonlyArray<TokenKey>;
104
+ }
100
105
  /**
101
- * Decorator to manually inject a dependency.
102
- * Useful for handling circular dependencies with `forwardRef` or injecting specific tokens.
106
+ * Marks a class as injectable into the Noxus DI container.
107
+ *
108
+ * Unlike the v2 @Injectable, this decorator:
109
+ * - Does NOT require reflect-metadata or emitDecoratorMetadata.
110
+ * - Requires you to declare deps explicitly when the class has constructor parameters.
111
+ * - Supports standalone usage — no module declaration needed.
112
+ *
113
+ * @example
114
+ * // No dependencies
115
+ * @Injectable()
116
+ * class Logger {}
117
+ *
118
+ * // With dependencies
119
+ * @Injectable({ lifetime: 'singleton', deps: [Logger, MyRepo] })
120
+ * class MyService {
121
+ * constructor(private logger: Logger, private repo: MyRepo) {}
122
+ * }
123
+ *
124
+ * // With a named token
125
+ * const DB_URL = token<string>('DB_URL');
103
126
  *
104
- * @param token The token or forward reference to inject.
127
+ * @Injectable({ deps: [DB_URL] })
128
+ * class DbService {
129
+ * constructor(private url: string) {}
130
+ * }
105
131
  */
106
- declare function Inject(token: any): ParameterDecorator;
132
+ declare function Injectable(options?: InjectableOptions): ClassDecorator;
107
133
 
108
134
  /**
109
135
  * Logger is a utility class for logging messages to the console.
@@ -206,4 +232,4 @@ declare namespace Logger {
206
232
  };
207
233
  }
208
234
 
209
- export { BadGatewayException, BadRequestException, ConflictException, ForbiddenException, GatewayTimeoutException, HttpVersionNotSupportedException, INJECTABLE_METADATA_KEY, INJECT_METADATA_KEY, Inject, Injectable, InsufficientStorageException, InternalServerException, Lifetime, type LogLevel, Logger, LoopDetectedException, MethodNotAllowedException, NetworkAuthenticationRequiredException, NetworkConnectTimeoutException, NotAcceptableException, NotExtendedException, NotFoundException, NotImplementedException, PaymentRequiredException, RequestTimeoutException, ResponseException, ServiceUnavailableException, TooManyRequestsException, UnauthorizedException, UpgradeRequiredException, VariantAlsoNegotiatesException, getInjectableMetadata, hasInjectableMetadata };
235
+ export { BadGatewayException, BadRequestException, ConflictException, ForbiddenException, GatewayTimeoutException, HttpVersionNotSupportedException, Injectable, type InjectableOptions, InsufficientStorageException, InternalServerException, Lifetime, type LogLevel, Logger, LoopDetectedException, MethodNotAllowedException, NetworkAuthenticationRequiredException, NetworkConnectTimeoutException, NotAcceptableException, NotExtendedException, NotFoundException, NotImplementedException, PaymentRequiredException, RequestTimeoutException, ResponseException, ServiceUnavailableException, TokenKey, TooManyRequestsException, UnauthorizedException, UpgradeRequiredException, VariantAlsoNegotiatesException };
package/dist/child.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { L as Lifetime } from './app-injector-B3MvgV3k.js';
2
- export { A as AppInjector, F as ForwardRefFn, a as ForwardReference, I as IBinding, M as MaybeAsync, R as RootInjector, T as Type, f as forwardRef, i as inject } from './app-injector-B3MvgV3k.js';
1
+ import { L as Lifetime, a as TokenKey } from './app-injector-Bz3Upc0y.js';
2
+ export { A as AppInjector, F as ForwardRefFn, b as ForwardReference, I as IBinding, M as MaybeAsync, R as RootInjector, c as Token, T as Type, f as forwardRef, i as inject } from './app-injector-Bz3Upc0y.js';
3
3
 
4
4
  /**
5
5
  * @copyright 2025 NoxFly
@@ -81,29 +81,55 @@ declare class NetworkConnectTimeoutException extends ResponseException {
81
81
  readonly status = 599;
82
82
  }
83
83
 
84
- declare const INJECTABLE_METADATA_KEY: unique symbol;
85
- declare function getInjectableMetadata(target: Function): Lifetime | undefined;
86
- declare function hasInjectableMetadata(target: Function): boolean;
87
84
 
88
-
89
- /**
90
- * The Injectable decorator marks a class as injectable.
91
- * It allows the class to be registered in the dependency injection system.
92
- * A class decorated with @Injectable can be injected into other classes
93
- * either from the constructor of the class that needs it of from the `inject` function.
94
- * @param lifetime - The lifetime of the injectable. Can be 'singleton', 'scope', or 'transient'.
95
- */
96
- declare function Injectable(lifetime?: Lifetime): ClassDecorator;
97
-
98
-
99
- declare const INJECT_METADATA_KEY = "custom:inject";
85
+ interface InjectableOptions {
86
+ /**
87
+ * Lifetime of this injectable.
88
+ * @default 'scope'
89
+ */
90
+ lifetime?: Lifetime;
91
+ /**
92
+ * Explicit list of constructor dependencies, in the same order as the constructor parameters.
93
+ * Each entry is either a class constructor or a Token created with token().
94
+ *
95
+ * This replaces reflect-metadata / emitDecoratorMetadata entirely.
96
+ *
97
+ * @example
98
+ * @Injectable({ lifetime: 'singleton', deps: [MyRepo, DB_URL] })
99
+ * class MyService {
100
+ * constructor(private repo: MyRepo, private dbUrl: string) {}
101
+ * }
102
+ */
103
+ deps?: ReadonlyArray<TokenKey>;
104
+ }
100
105
  /**
101
- * Decorator to manually inject a dependency.
102
- * Useful for handling circular dependencies with `forwardRef` or injecting specific tokens.
106
+ * Marks a class as injectable into the Noxus DI container.
107
+ *
108
+ * Unlike the v2 @Injectable, this decorator:
109
+ * - Does NOT require reflect-metadata or emitDecoratorMetadata.
110
+ * - Requires you to declare deps explicitly when the class has constructor parameters.
111
+ * - Supports standalone usage — no module declaration needed.
112
+ *
113
+ * @example
114
+ * // No dependencies
115
+ * @Injectable()
116
+ * class Logger {}
117
+ *
118
+ * // With dependencies
119
+ * @Injectable({ lifetime: 'singleton', deps: [Logger, MyRepo] })
120
+ * class MyService {
121
+ * constructor(private logger: Logger, private repo: MyRepo) {}
122
+ * }
123
+ *
124
+ * // With a named token
125
+ * const DB_URL = token<string>('DB_URL');
103
126
  *
104
- * @param token The token or forward reference to inject.
127
+ * @Injectable({ deps: [DB_URL] })
128
+ * class DbService {
129
+ * constructor(private url: string) {}
130
+ * }
105
131
  */
106
- declare function Inject(token: any): ParameterDecorator;
132
+ declare function Injectable(options?: InjectableOptions): ClassDecorator;
107
133
 
108
134
  /**
109
135
  * Logger is a utility class for logging messages to the console.
@@ -206,4 +232,4 @@ declare namespace Logger {
206
232
  };
207
233
  }
208
234
 
209
- export { BadGatewayException, BadRequestException, ConflictException, ForbiddenException, GatewayTimeoutException, HttpVersionNotSupportedException, INJECTABLE_METADATA_KEY, INJECT_METADATA_KEY, Inject, Injectable, InsufficientStorageException, InternalServerException, Lifetime, type LogLevel, Logger, LoopDetectedException, MethodNotAllowedException, NetworkAuthenticationRequiredException, NetworkConnectTimeoutException, NotAcceptableException, NotExtendedException, NotFoundException, NotImplementedException, PaymentRequiredException, RequestTimeoutException, ResponseException, ServiceUnavailableException, TooManyRequestsException, UnauthorizedException, UpgradeRequiredException, VariantAlsoNegotiatesException, getInjectableMetadata, hasInjectableMetadata };
235
+ export { BadGatewayException, BadRequestException, ConflictException, ForbiddenException, GatewayTimeoutException, HttpVersionNotSupportedException, Injectable, type InjectableOptions, InsufficientStorageException, InternalServerException, Lifetime, type LogLevel, Logger, LoopDetectedException, MethodNotAllowedException, NetworkAuthenticationRequiredException, NetworkConnectTimeoutException, NotAcceptableException, NotExtendedException, NotFoundException, NotImplementedException, PaymentRequiredException, RequestTimeoutException, ResponseException, ServiceUnavailableException, TokenKey, TooManyRequestsException, UnauthorizedException, UpgradeRequiredException, VariantAlsoNegotiatesException };