@noxfly/noxus 3.0.0-dev.0 → 3.0.0-dev.10
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/README.md +132 -16
- package/dist/child.d.mts +118 -4
- package/dist/child.d.ts +118 -4
- package/dist/child.js +402 -859
- package/dist/child.js.map +1 -0
- package/dist/child.mjs +389 -847
- package/dist/child.mjs.map +1 -0
- package/dist/main.d.mts +517 -25
- package/dist/main.d.ts +517 -25
- package/dist/main.js +1088 -988
- package/dist/main.js.map +1 -0
- package/dist/main.mjs +983 -884
- package/dist/main.mjs.map +1 -0
- package/dist/preload.d.mts +28 -0
- package/dist/preload.d.ts +28 -0
- package/dist/preload.js +95 -0
- package/dist/preload.js.map +1 -0
- package/dist/preload.mjs +70 -0
- package/dist/preload.mjs.map +1 -0
- package/dist/renderer.d.mts +186 -23
- package/dist/renderer.d.ts +186 -23
- package/dist/renderer.js +170 -170
- package/dist/renderer.js.map +1 -0
- package/dist/renderer.mjs +159 -157
- package/dist/renderer.mjs.map +1 -0
- package/package.json +35 -21
- package/.editorconfig +0 -16
- package/.github/copilot-instructions.md +0 -32
- package/.vscode/settings.json +0 -3
- package/eslint.config.js +0 -109
- package/scripts/postbuild.js +0 -31
- package/src/DI/app-injector.ts +0 -151
- package/src/DI/injector-explorer.ts +0 -143
- package/src/DI/token.ts +0 -53
- package/src/app.ts +0 -217
- package/src/bootstrap.ts +0 -108
- package/src/decorators/controller.decorator.ts +0 -58
- package/src/decorators/guards.decorator.ts +0 -15
- package/src/decorators/injectable.decorator.ts +0 -81
- package/src/decorators/method.decorator.ts +0 -66
- package/src/decorators/middleware.decorator.ts +0 -15
- package/src/exceptions.ts +0 -57
- package/src/index.ts +0 -13
- package/src/main.ts +0 -26
- package/src/non-electron-process.ts +0 -22
- package/src/preload-bridge.ts +0 -75
- package/src/renderer-client.ts +0 -338
- package/src/renderer-events.ts +0 -110
- package/src/request.ts +0 -97
- package/src/router.ts +0 -353
- package/src/routes.ts +0 -78
- package/src/socket.ts +0 -73
- package/src/utils/forward-ref.ts +0 -31
- package/src/utils/logger.ts +0 -430
- package/src/utils/radix-tree.ts +0 -210
- package/src/utils/types.ts +0 -21
- package/src/window/window-manager.ts +0 -255
- package/tsconfig.json +0 -29
- package/tsup.config.ts +0 -34
package/dist/renderer.d.mts
CHANGED
|
@@ -1,12 +1,169 @@
|
|
|
1
|
-
import { I as IRendererEventMessage, a as IResponse, b as IRequest, c as IBatchRequestItem, d as IBatchResponsePayload } from './request-qJ9EiDZc.mjs';
|
|
2
|
-
export { A as AtomicHttpMethod, H as HttpMethod, e as IBatchRequestPayload, R as RENDERER_EVENT_TYPE, f as Request, g as createRendererEventMessage, i as isRendererEventMessage } from './request-qJ9EiDZc.mjs';
|
|
3
|
-
import './app-injector-Bz3Upc0y.mjs';
|
|
4
|
-
|
|
5
1
|
/**
|
|
6
2
|
* @copyright 2025 NoxFly
|
|
7
3
|
* @license MIT
|
|
8
4
|
* @author NoxFly
|
|
9
5
|
*/
|
|
6
|
+
interface Type<T> extends Function {
|
|
7
|
+
new (...args: any[]): T;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'BATCH';
|
|
12
|
+
type AtomicHttpMethod = Exclude<HttpMethod, 'BATCH'>;
|
|
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
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A DI token uniquely identifies a dependency.
|
|
33
|
+
* It can wrap a class (Type<T>) or be a named symbol token.
|
|
34
|
+
*
|
|
35
|
+
* Using tokens instead of reflect-metadata means dependencies are
|
|
36
|
+
* declared explicitly — no magic type inference, no emitDecoratorMetadata.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* // Class token (most common)
|
|
40
|
+
* const MY_SERVICE = token(MyService);
|
|
41
|
+
*
|
|
42
|
+
* // Named symbol token (for interfaces or non-class values)
|
|
43
|
+
* const DB_URL = token<string>('DB_URL');
|
|
44
|
+
*/
|
|
45
|
+
declare class Token<T> {
|
|
46
|
+
readonly target: Type<T> | string;
|
|
47
|
+
readonly description: string;
|
|
48
|
+
constructor(target: Type<T> | string);
|
|
49
|
+
toString(): string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The key used to look up a class token in the registry.
|
|
53
|
+
* For class tokens, the key is the class constructor itself.
|
|
54
|
+
* For named tokens, the key is the Token instance.
|
|
55
|
+
*/
|
|
56
|
+
type TokenKey<T = unknown> = Type<T> | Token<T>;
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Lifetime of a binding in the DI container.
|
|
61
|
+
* - singleton: created once, shared for the lifetime of the app.
|
|
62
|
+
* - scope: created once per request scope.
|
|
63
|
+
* - transient: new instance every time it is resolved.
|
|
64
|
+
*/
|
|
65
|
+
type Lifetime = 'singleton' | 'scope' | 'transient';
|
|
66
|
+
/**
|
|
67
|
+
* Internal representation of a registered binding.
|
|
68
|
+
*/
|
|
69
|
+
interface IBinding<T = unknown> {
|
|
70
|
+
lifetime: Lifetime;
|
|
71
|
+
implementation: Type<T>;
|
|
72
|
+
/** Explicit constructor dependencies, declared by the class itself. */
|
|
73
|
+
deps: ReadonlyArray<TokenKey>;
|
|
74
|
+
instance?: T;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* AppInjector is the core DI container.
|
|
78
|
+
* It no longer uses reflect-metadata — all dependency information
|
|
79
|
+
* comes from explicitly declared `deps` arrays on each binding.
|
|
80
|
+
*/
|
|
81
|
+
declare class AppInjector {
|
|
82
|
+
readonly name: string | null;
|
|
83
|
+
readonly bindings: Map<Type<unknown> | Token<unknown>, IBinding<unknown>>;
|
|
84
|
+
readonly singletons: Map<Type<unknown> | Token<unknown>, unknown>;
|
|
85
|
+
readonly scoped: Map<Type<unknown> | Token<unknown>, unknown>;
|
|
86
|
+
constructor(name?: string | null);
|
|
87
|
+
/**
|
|
88
|
+
* Creates a child scope for per-request lifetime resolution.
|
|
89
|
+
*/
|
|
90
|
+
createScope(): AppInjector;
|
|
91
|
+
/**
|
|
92
|
+
* Registers a binding explicitly.
|
|
93
|
+
*/
|
|
94
|
+
register<T>(key: TokenKey<T>, implementation: Type<T>, lifetime: Lifetime, deps?: ReadonlyArray<TokenKey>): void;
|
|
95
|
+
/**
|
|
96
|
+
* Resolves a dependency by token or class reference.
|
|
97
|
+
*/
|
|
98
|
+
resolve<T>(target: TokenKey<T> | ForwardReference<T>): T;
|
|
99
|
+
private _resolveForwardRef;
|
|
100
|
+
private _instantiate;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* The Request class represents an HTTP request in the Noxus framework.
|
|
106
|
+
* It encapsulates the request data, including the event, ID, method, path, and body.
|
|
107
|
+
* It also provides a context for dependency injection through the AppInjector.
|
|
108
|
+
*/
|
|
109
|
+
declare class Request {
|
|
110
|
+
readonly event: Electron.MessageEvent;
|
|
111
|
+
readonly senderId: number;
|
|
112
|
+
readonly id: string;
|
|
113
|
+
readonly method: HttpMethod;
|
|
114
|
+
readonly path: string;
|
|
115
|
+
readonly body: unknown;
|
|
116
|
+
readonly context: AppInjector;
|
|
117
|
+
readonly params: Record<string, string>;
|
|
118
|
+
readonly query: Record<string, unknown>;
|
|
119
|
+
constructor(event: Electron.MessageEvent, senderId: number, id: string, method: HttpMethod, path: string, body: unknown, query?: Record<string, unknown>);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The IRequest interface defines the structure of a request object.
|
|
123
|
+
* It includes properties for the sender ID, request ID, path, method, and an optional body.
|
|
124
|
+
* This interface is used to standardize the request data across the application.
|
|
125
|
+
*/
|
|
126
|
+
interface IRequest<TBody = unknown> {
|
|
127
|
+
senderId: number;
|
|
128
|
+
requestId: string;
|
|
129
|
+
path: string;
|
|
130
|
+
method: HttpMethod;
|
|
131
|
+
body?: TBody;
|
|
132
|
+
query?: Record<string, unknown>;
|
|
133
|
+
}
|
|
134
|
+
interface IBatchRequestItem<TBody = unknown> {
|
|
135
|
+
requestId?: string;
|
|
136
|
+
path: string;
|
|
137
|
+
method: AtomicHttpMethod;
|
|
138
|
+
body?: TBody;
|
|
139
|
+
query?: Record<string, unknown>;
|
|
140
|
+
}
|
|
141
|
+
interface IBatchRequestPayload {
|
|
142
|
+
requests: IBatchRequestItem[];
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Creates a Request object from the IPC event data.
|
|
146
|
+
* This function extracts the necessary information from the IPC event and constructs a Request instance.
|
|
147
|
+
*/
|
|
148
|
+
interface IResponse<TBody = unknown> {
|
|
149
|
+
requestId: string;
|
|
150
|
+
status: number;
|
|
151
|
+
body?: TBody;
|
|
152
|
+
error?: string;
|
|
153
|
+
stack?: string;
|
|
154
|
+
}
|
|
155
|
+
interface IBatchResponsePayload {
|
|
156
|
+
responses: IResponse[];
|
|
157
|
+
}
|
|
158
|
+
declare const RENDERER_EVENT_TYPE = "noxus:event";
|
|
159
|
+
interface IRendererEventMessage<TPayload = unknown> {
|
|
160
|
+
type: typeof RENDERER_EVENT_TYPE;
|
|
161
|
+
event: string;
|
|
162
|
+
payload?: TPayload;
|
|
163
|
+
}
|
|
164
|
+
declare function createRendererEventMessage<TPayload = unknown>(event: string, payload?: TPayload): IRendererEventMessage<TPayload>;
|
|
165
|
+
declare function isRendererEventMessage(value: unknown): value is IRendererEventMessage;
|
|
166
|
+
|
|
10
167
|
/**
|
|
11
168
|
* Lightweight event registry to help renderer processes subscribe to
|
|
12
169
|
* push messages sent by the main process through Noxus.
|
|
@@ -48,18 +205,39 @@ declare class RendererEventRegistry {
|
|
|
48
205
|
interface IPortRequester {
|
|
49
206
|
requestPort(): void;
|
|
50
207
|
}
|
|
208
|
+
/**
|
|
209
|
+
* Per-request options that can override global client defaults.
|
|
210
|
+
*/
|
|
211
|
+
interface RequestOptions {
|
|
212
|
+
/**
|
|
213
|
+
* Timeout in milliseconds for this specific request.
|
|
214
|
+
* Overrides the global `requestTimeout` set on the client.
|
|
215
|
+
* Set to 0 to disable timeout for this request.
|
|
216
|
+
*/
|
|
217
|
+
timeout?: number;
|
|
218
|
+
}
|
|
51
219
|
interface RendererClientOptions {
|
|
52
220
|
bridge?: IPortRequester | null;
|
|
53
221
|
bridgeName?: string | string[];
|
|
54
222
|
initMessageType?: string;
|
|
55
223
|
windowRef?: Window;
|
|
56
224
|
generateRequestId?: () => string;
|
|
225
|
+
/**
|
|
226
|
+
* Timeout in milliseconds for IPC requests.
|
|
227
|
+
* If the main process does not respond within this duration,
|
|
228
|
+
* the request Promise is rejected and the pending entry cleaned up.
|
|
229
|
+
* Defaults to 10 000 ms. Set to 0 to disable.
|
|
230
|
+
*/
|
|
231
|
+
requestTimeout?: number;
|
|
232
|
+
/** @default true */
|
|
233
|
+
enableLogging?: boolean;
|
|
57
234
|
}
|
|
58
235
|
interface PendingRequest<T = unknown> {
|
|
59
236
|
resolve: (value: T) => void;
|
|
60
237
|
reject: (reason: IResponse<T>) => void;
|
|
61
238
|
request: IRequest;
|
|
62
239
|
submittedAt: number;
|
|
240
|
+
timer?: ReturnType<typeof setTimeout>;
|
|
63
241
|
}
|
|
64
242
|
declare class NoxRendererClient {
|
|
65
243
|
readonly events: RendererEventRegistry;
|
|
@@ -71,14 +249,16 @@ declare class NoxRendererClient {
|
|
|
71
249
|
private readonly initMessageType;
|
|
72
250
|
private readonly windowRef;
|
|
73
251
|
private readonly generateRequestId;
|
|
252
|
+
private readonly requestTimeout;
|
|
74
253
|
private isReady;
|
|
75
254
|
private setupPromise;
|
|
76
255
|
private setupResolve;
|
|
77
256
|
private setupReject;
|
|
257
|
+
private enableLogging;
|
|
78
258
|
constructor(options?: RendererClientOptions);
|
|
79
259
|
setup(): Promise<void>;
|
|
80
260
|
dispose(): void;
|
|
81
|
-
request<TResponse, TBody = unknown>(request: Omit<IRequest<TBody>, 'requestId' | 'senderId'
|
|
261
|
+
request<TResponse, TBody = unknown>(request: Omit<IRequest<TBody>, 'requestId' | 'senderId'>, options?: RequestOptions): Promise<TResponse>;
|
|
82
262
|
batch(requests: Omit<IBatchRequestItem<unknown>, 'requestId'>[]): Promise<IBatchResponsePayload>;
|
|
83
263
|
getSenderId(): number | undefined;
|
|
84
264
|
private readonly onWindowMessage;
|
|
@@ -93,21 +273,4 @@ declare class NoxRendererClient {
|
|
|
93
273
|
isElectronEnvironment(): boolean;
|
|
94
274
|
}
|
|
95
275
|
|
|
96
|
-
|
|
97
|
-
interface NoxusPreloadAPI extends IPortRequester {
|
|
98
|
-
}
|
|
99
|
-
interface NoxusPreloadOptions {
|
|
100
|
-
exposeAs?: string;
|
|
101
|
-
initMessageType?: string;
|
|
102
|
-
requestChannel?: string;
|
|
103
|
-
responseChannel?: string;
|
|
104
|
-
targetWindow?: Window;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Exposes a minimal bridge in the isolated preload context so renderer processes
|
|
108
|
-
* can request the two MessagePorts required by Noxus. The bridge forwards both
|
|
109
|
-
* request/response and socket ports to the renderer via window.postMessage.
|
|
110
|
-
*/
|
|
111
|
-
declare function exposeNoxusBridge(options?: NoxusPreloadOptions): NoxusPreloadAPI;
|
|
112
|
-
|
|
113
|
-
export { IBatchRequestItem, IBatchResponsePayload, type IPortRequester, IRendererEventMessage, IRequest, IResponse, NoxRendererClient, type NoxusPreloadAPI, type NoxusPreloadOptions, type RendererClientOptions, type RendererEventHandler, RendererEventRegistry, type RendererEventSubscription, exposeNoxusBridge };
|
|
276
|
+
export { type AtomicHttpMethod, type HttpMethod, type IBatchRequestItem, type IBatchRequestPayload, type IBatchResponsePayload, type IPortRequester, type IRendererEventMessage, type IRequest, type IResponse, NoxRendererClient, RENDERER_EVENT_TYPE, type RendererClientOptions, type RendererEventHandler, RendererEventRegistry, type RendererEventSubscription, Request, type RequestOptions, createRendererEventMessage, isRendererEventMessage };
|
package/dist/renderer.d.ts
CHANGED
|
@@ -1,12 +1,169 @@
|
|
|
1
|
-
import { I as IRendererEventMessage, a as IResponse, b as IRequest, c as IBatchRequestItem, d as IBatchResponsePayload } from './request-BlTtiHbi.js';
|
|
2
|
-
export { A as AtomicHttpMethod, H as HttpMethod, e as IBatchRequestPayload, R as RENDERER_EVENT_TYPE, f as Request, g as createRendererEventMessage, i as isRendererEventMessage } from './request-BlTtiHbi.js';
|
|
3
|
-
import './app-injector-Bz3Upc0y.js';
|
|
4
|
-
|
|
5
1
|
/**
|
|
6
2
|
* @copyright 2025 NoxFly
|
|
7
3
|
* @license MIT
|
|
8
4
|
* @author NoxFly
|
|
9
5
|
*/
|
|
6
|
+
interface Type<T> extends Function {
|
|
7
|
+
new (...args: any[]): T;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'BATCH';
|
|
12
|
+
type AtomicHttpMethod = Exclude<HttpMethod, 'BATCH'>;
|
|
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
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A DI token uniquely identifies a dependency.
|
|
33
|
+
* It can wrap a class (Type<T>) or be a named symbol token.
|
|
34
|
+
*
|
|
35
|
+
* Using tokens instead of reflect-metadata means dependencies are
|
|
36
|
+
* declared explicitly — no magic type inference, no emitDecoratorMetadata.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* // Class token (most common)
|
|
40
|
+
* const MY_SERVICE = token(MyService);
|
|
41
|
+
*
|
|
42
|
+
* // Named symbol token (for interfaces or non-class values)
|
|
43
|
+
* const DB_URL = token<string>('DB_URL');
|
|
44
|
+
*/
|
|
45
|
+
declare class Token<T> {
|
|
46
|
+
readonly target: Type<T> | string;
|
|
47
|
+
readonly description: string;
|
|
48
|
+
constructor(target: Type<T> | string);
|
|
49
|
+
toString(): string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The key used to look up a class token in the registry.
|
|
53
|
+
* For class tokens, the key is the class constructor itself.
|
|
54
|
+
* For named tokens, the key is the Token instance.
|
|
55
|
+
*/
|
|
56
|
+
type TokenKey<T = unknown> = Type<T> | Token<T>;
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Lifetime of a binding in the DI container.
|
|
61
|
+
* - singleton: created once, shared for the lifetime of the app.
|
|
62
|
+
* - scope: created once per request scope.
|
|
63
|
+
* - transient: new instance every time it is resolved.
|
|
64
|
+
*/
|
|
65
|
+
type Lifetime = 'singleton' | 'scope' | 'transient';
|
|
66
|
+
/**
|
|
67
|
+
* Internal representation of a registered binding.
|
|
68
|
+
*/
|
|
69
|
+
interface IBinding<T = unknown> {
|
|
70
|
+
lifetime: Lifetime;
|
|
71
|
+
implementation: Type<T>;
|
|
72
|
+
/** Explicit constructor dependencies, declared by the class itself. */
|
|
73
|
+
deps: ReadonlyArray<TokenKey>;
|
|
74
|
+
instance?: T;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* AppInjector is the core DI container.
|
|
78
|
+
* It no longer uses reflect-metadata — all dependency information
|
|
79
|
+
* comes from explicitly declared `deps` arrays on each binding.
|
|
80
|
+
*/
|
|
81
|
+
declare class AppInjector {
|
|
82
|
+
readonly name: string | null;
|
|
83
|
+
readonly bindings: Map<Type<unknown> | Token<unknown>, IBinding<unknown>>;
|
|
84
|
+
readonly singletons: Map<Type<unknown> | Token<unknown>, unknown>;
|
|
85
|
+
readonly scoped: Map<Type<unknown> | Token<unknown>, unknown>;
|
|
86
|
+
constructor(name?: string | null);
|
|
87
|
+
/**
|
|
88
|
+
* Creates a child scope for per-request lifetime resolution.
|
|
89
|
+
*/
|
|
90
|
+
createScope(): AppInjector;
|
|
91
|
+
/**
|
|
92
|
+
* Registers a binding explicitly.
|
|
93
|
+
*/
|
|
94
|
+
register<T>(key: TokenKey<T>, implementation: Type<T>, lifetime: Lifetime, deps?: ReadonlyArray<TokenKey>): void;
|
|
95
|
+
/**
|
|
96
|
+
* Resolves a dependency by token or class reference.
|
|
97
|
+
*/
|
|
98
|
+
resolve<T>(target: TokenKey<T> | ForwardReference<T>): T;
|
|
99
|
+
private _resolveForwardRef;
|
|
100
|
+
private _instantiate;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* The Request class represents an HTTP request in the Noxus framework.
|
|
106
|
+
* It encapsulates the request data, including the event, ID, method, path, and body.
|
|
107
|
+
* It also provides a context for dependency injection through the AppInjector.
|
|
108
|
+
*/
|
|
109
|
+
declare class Request {
|
|
110
|
+
readonly event: Electron.MessageEvent;
|
|
111
|
+
readonly senderId: number;
|
|
112
|
+
readonly id: string;
|
|
113
|
+
readonly method: HttpMethod;
|
|
114
|
+
readonly path: string;
|
|
115
|
+
readonly body: unknown;
|
|
116
|
+
readonly context: AppInjector;
|
|
117
|
+
readonly params: Record<string, string>;
|
|
118
|
+
readonly query: Record<string, unknown>;
|
|
119
|
+
constructor(event: Electron.MessageEvent, senderId: number, id: string, method: HttpMethod, path: string, body: unknown, query?: Record<string, unknown>);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The IRequest interface defines the structure of a request object.
|
|
123
|
+
* It includes properties for the sender ID, request ID, path, method, and an optional body.
|
|
124
|
+
* This interface is used to standardize the request data across the application.
|
|
125
|
+
*/
|
|
126
|
+
interface IRequest<TBody = unknown> {
|
|
127
|
+
senderId: number;
|
|
128
|
+
requestId: string;
|
|
129
|
+
path: string;
|
|
130
|
+
method: HttpMethod;
|
|
131
|
+
body?: TBody;
|
|
132
|
+
query?: Record<string, unknown>;
|
|
133
|
+
}
|
|
134
|
+
interface IBatchRequestItem<TBody = unknown> {
|
|
135
|
+
requestId?: string;
|
|
136
|
+
path: string;
|
|
137
|
+
method: AtomicHttpMethod;
|
|
138
|
+
body?: TBody;
|
|
139
|
+
query?: Record<string, unknown>;
|
|
140
|
+
}
|
|
141
|
+
interface IBatchRequestPayload {
|
|
142
|
+
requests: IBatchRequestItem[];
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Creates a Request object from the IPC event data.
|
|
146
|
+
* This function extracts the necessary information from the IPC event and constructs a Request instance.
|
|
147
|
+
*/
|
|
148
|
+
interface IResponse<TBody = unknown> {
|
|
149
|
+
requestId: string;
|
|
150
|
+
status: number;
|
|
151
|
+
body?: TBody;
|
|
152
|
+
error?: string;
|
|
153
|
+
stack?: string;
|
|
154
|
+
}
|
|
155
|
+
interface IBatchResponsePayload {
|
|
156
|
+
responses: IResponse[];
|
|
157
|
+
}
|
|
158
|
+
declare const RENDERER_EVENT_TYPE = "noxus:event";
|
|
159
|
+
interface IRendererEventMessage<TPayload = unknown> {
|
|
160
|
+
type: typeof RENDERER_EVENT_TYPE;
|
|
161
|
+
event: string;
|
|
162
|
+
payload?: TPayload;
|
|
163
|
+
}
|
|
164
|
+
declare function createRendererEventMessage<TPayload = unknown>(event: string, payload?: TPayload): IRendererEventMessage<TPayload>;
|
|
165
|
+
declare function isRendererEventMessage(value: unknown): value is IRendererEventMessage;
|
|
166
|
+
|
|
10
167
|
/**
|
|
11
168
|
* Lightweight event registry to help renderer processes subscribe to
|
|
12
169
|
* push messages sent by the main process through Noxus.
|
|
@@ -48,18 +205,39 @@ declare class RendererEventRegistry {
|
|
|
48
205
|
interface IPortRequester {
|
|
49
206
|
requestPort(): void;
|
|
50
207
|
}
|
|
208
|
+
/**
|
|
209
|
+
* Per-request options that can override global client defaults.
|
|
210
|
+
*/
|
|
211
|
+
interface RequestOptions {
|
|
212
|
+
/**
|
|
213
|
+
* Timeout in milliseconds for this specific request.
|
|
214
|
+
* Overrides the global `requestTimeout` set on the client.
|
|
215
|
+
* Set to 0 to disable timeout for this request.
|
|
216
|
+
*/
|
|
217
|
+
timeout?: number;
|
|
218
|
+
}
|
|
51
219
|
interface RendererClientOptions {
|
|
52
220
|
bridge?: IPortRequester | null;
|
|
53
221
|
bridgeName?: string | string[];
|
|
54
222
|
initMessageType?: string;
|
|
55
223
|
windowRef?: Window;
|
|
56
224
|
generateRequestId?: () => string;
|
|
225
|
+
/**
|
|
226
|
+
* Timeout in milliseconds for IPC requests.
|
|
227
|
+
* If the main process does not respond within this duration,
|
|
228
|
+
* the request Promise is rejected and the pending entry cleaned up.
|
|
229
|
+
* Defaults to 10 000 ms. Set to 0 to disable.
|
|
230
|
+
*/
|
|
231
|
+
requestTimeout?: number;
|
|
232
|
+
/** @default true */
|
|
233
|
+
enableLogging?: boolean;
|
|
57
234
|
}
|
|
58
235
|
interface PendingRequest<T = unknown> {
|
|
59
236
|
resolve: (value: T) => void;
|
|
60
237
|
reject: (reason: IResponse<T>) => void;
|
|
61
238
|
request: IRequest;
|
|
62
239
|
submittedAt: number;
|
|
240
|
+
timer?: ReturnType<typeof setTimeout>;
|
|
63
241
|
}
|
|
64
242
|
declare class NoxRendererClient {
|
|
65
243
|
readonly events: RendererEventRegistry;
|
|
@@ -71,14 +249,16 @@ declare class NoxRendererClient {
|
|
|
71
249
|
private readonly initMessageType;
|
|
72
250
|
private readonly windowRef;
|
|
73
251
|
private readonly generateRequestId;
|
|
252
|
+
private readonly requestTimeout;
|
|
74
253
|
private isReady;
|
|
75
254
|
private setupPromise;
|
|
76
255
|
private setupResolve;
|
|
77
256
|
private setupReject;
|
|
257
|
+
private enableLogging;
|
|
78
258
|
constructor(options?: RendererClientOptions);
|
|
79
259
|
setup(): Promise<void>;
|
|
80
260
|
dispose(): void;
|
|
81
|
-
request<TResponse, TBody = unknown>(request: Omit<IRequest<TBody>, 'requestId' | 'senderId'
|
|
261
|
+
request<TResponse, TBody = unknown>(request: Omit<IRequest<TBody>, 'requestId' | 'senderId'>, options?: RequestOptions): Promise<TResponse>;
|
|
82
262
|
batch(requests: Omit<IBatchRequestItem<unknown>, 'requestId'>[]): Promise<IBatchResponsePayload>;
|
|
83
263
|
getSenderId(): number | undefined;
|
|
84
264
|
private readonly onWindowMessage;
|
|
@@ -93,21 +273,4 @@ declare class NoxRendererClient {
|
|
|
93
273
|
isElectronEnvironment(): boolean;
|
|
94
274
|
}
|
|
95
275
|
|
|
96
|
-
|
|
97
|
-
interface NoxusPreloadAPI extends IPortRequester {
|
|
98
|
-
}
|
|
99
|
-
interface NoxusPreloadOptions {
|
|
100
|
-
exposeAs?: string;
|
|
101
|
-
initMessageType?: string;
|
|
102
|
-
requestChannel?: string;
|
|
103
|
-
responseChannel?: string;
|
|
104
|
-
targetWindow?: Window;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Exposes a minimal bridge in the isolated preload context so renderer processes
|
|
108
|
-
* can request the two MessagePorts required by Noxus. The bridge forwards both
|
|
109
|
-
* request/response and socket ports to the renderer via window.postMessage.
|
|
110
|
-
*/
|
|
111
|
-
declare function exposeNoxusBridge(options?: NoxusPreloadOptions): NoxusPreloadAPI;
|
|
112
|
-
|
|
113
|
-
export { IBatchRequestItem, IBatchResponsePayload, type IPortRequester, IRendererEventMessage, IRequest, IResponse, NoxRendererClient, type NoxusPreloadAPI, type NoxusPreloadOptions, type RendererClientOptions, type RendererEventHandler, RendererEventRegistry, type RendererEventSubscription, exposeNoxusBridge };
|
|
276
|
+
export { type AtomicHttpMethod, type HttpMethod, type IBatchRequestItem, type IBatchRequestPayload, type IBatchResponsePayload, type IPortRequester, type IRendererEventMessage, type IRequest, type IResponse, NoxRendererClient, RENDERER_EVENT_TYPE, type RendererClientOptions, type RendererEventHandler, RendererEventRegistry, type RendererEventSubscription, Request, type RequestOptions, createRendererEventMessage, isRendererEventMessage };
|