@noxfly/noxus 3.0.0-dev.0 → 3.0.0-dev.2
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 +14 -11
- package/dist/child.d.mts +112 -4
- package/dist/child.d.ts +112 -4
- package/dist/child.js +33 -30
- package/dist/child.mjs +33 -30
- package/dist/main.d.mts +450 -6
- package/dist/main.d.ts +450 -6
- package/dist/main.js +232 -229
- package/dist/main.mjs +234 -231
- package/dist/preload.d.mts +28 -0
- package/dist/preload.d.ts +28 -0
- package/dist/preload.js +95 -0
- package/dist/preload.mjs +70 -0
- package/dist/renderer.d.mts +159 -22
- package/dist/renderer.d.ts +159 -22
- package/dist/renderer.js +14 -58
- package/dist/renderer.mjs +10 -53
- package/package.json +26 -13
- package/src/DI/app-injector.ts +10 -1
- package/src/DI/injector-explorer.ts +2 -2
- package/src/decorators/guards.decorator.ts +1 -1
- package/src/decorators/middleware.decorator.ts +1 -1
- package/src/index.ts +2 -5
- package/src/{app.ts → internal/app.ts} +8 -8
- package/src/{bootstrap.ts → internal/bootstrap.ts} +5 -4
- package/src/{request.ts → internal/request.ts} +2 -2
- package/src/{router.ts → internal/router.ts} +9 -9
- package/src/{routes.ts → internal/routes.ts} +2 -2
- package/src/{socket.ts → internal/socket.ts} +2 -2
- package/src/main.ts +7 -7
- package/src/non-electron-process.ts +1 -1
- package/src/preload.ts +10 -0
- package/src/renderer.ts +13 -0
- package/tsup.config.ts +27 -11
- /package/src/{exceptions.ts → internal/exceptions.ts} +0 -0
- /package/src/{preload-bridge.ts → internal/preload-bridge.ts} +0 -0
- /package/src/{renderer-client.ts → internal/renderer-client.ts} +0 -0
- /package/src/{renderer-events.ts → internal/renderer-events.ts} +0 -0
package/dist/preload.mjs
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright 2025 NoxFly
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @author NoxFly
|
|
5
|
+
*/
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
|
|
9
|
+
// src/internal/preload-bridge.ts
|
|
10
|
+
import { contextBridge, ipcRenderer } from "electron/renderer";
|
|
11
|
+
var DEFAULT_EXPOSE_NAME = "noxus";
|
|
12
|
+
var DEFAULT_INIT_EVENT = "init-port";
|
|
13
|
+
var DEFAULT_REQUEST_CHANNEL = "gimme-my-port";
|
|
14
|
+
var DEFAULT_RESPONSE_CHANNEL = "port";
|
|
15
|
+
function exposeNoxusBridge(options = {}) {
|
|
16
|
+
const {
|
|
17
|
+
exposeAs = DEFAULT_EXPOSE_NAME,
|
|
18
|
+
initMessageType = DEFAULT_INIT_EVENT,
|
|
19
|
+
requestChannel = DEFAULT_REQUEST_CHANNEL,
|
|
20
|
+
responseChannel = DEFAULT_RESPONSE_CHANNEL,
|
|
21
|
+
targetWindow = window
|
|
22
|
+
} = options;
|
|
23
|
+
const api = {
|
|
24
|
+
requestPort: /* @__PURE__ */ __name(() => {
|
|
25
|
+
ipcRenderer.send(requestChannel);
|
|
26
|
+
ipcRenderer.once(responseChannel, (event, message) => {
|
|
27
|
+
const ports = (event.ports ?? []).filter((port) => port !== void 0);
|
|
28
|
+
if (ports.length === 0) {
|
|
29
|
+
console.error("[Noxus] No MessagePort received from main process.");
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
for (const port of ports) {
|
|
33
|
+
try {
|
|
34
|
+
port.start();
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.error("[Noxus] Failed to start MessagePort.", error);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
targetWindow.postMessage(
|
|
40
|
+
{
|
|
41
|
+
type: initMessageType,
|
|
42
|
+
senderId: message?.senderId
|
|
43
|
+
},
|
|
44
|
+
"*",
|
|
45
|
+
ports
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
}, "requestPort")
|
|
49
|
+
};
|
|
50
|
+
contextBridge.exposeInMainWorld(exposeAs, api);
|
|
51
|
+
return api;
|
|
52
|
+
}
|
|
53
|
+
__name(exposeNoxusBridge, "exposeNoxusBridge");
|
|
54
|
+
export {
|
|
55
|
+
exposeNoxusBridge
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* @copyright 2025 NoxFly
|
|
59
|
+
* @license MIT
|
|
60
|
+
* @author NoxFly
|
|
61
|
+
*/
|
|
62
|
+
/**
|
|
63
|
+
* @copyright 2025 NoxFly
|
|
64
|
+
* @license MIT
|
|
65
|
+
* @author NoxFly
|
|
66
|
+
*
|
|
67
|
+
* Entry point for Electron preload scripts.
|
|
68
|
+
* Imports electron/renderer — must NOT be bundled into renderer web code.
|
|
69
|
+
*/
|
|
70
|
+
//# sourceMappingURL=preload.mjs.map
|
package/dist/renderer.d.mts
CHANGED
|
@@ -1,12 +1,166 @@
|
|
|
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: any;
|
|
116
|
+
readonly context: AppInjector;
|
|
117
|
+
readonly params: Record<string, string>;
|
|
118
|
+
constructor(event: Electron.MessageEvent, senderId: number, id: string, method: HttpMethod, path: string, body: any);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* The IRequest interface defines the structure of a request object.
|
|
122
|
+
* It includes properties for the sender ID, request ID, path, method, and an optional body.
|
|
123
|
+
* This interface is used to standardize the request data across the application.
|
|
124
|
+
*/
|
|
125
|
+
interface IRequest<TBody = unknown> {
|
|
126
|
+
senderId: number;
|
|
127
|
+
requestId: string;
|
|
128
|
+
path: string;
|
|
129
|
+
method: HttpMethod;
|
|
130
|
+
body?: TBody;
|
|
131
|
+
}
|
|
132
|
+
interface IBatchRequestItem<TBody = unknown> {
|
|
133
|
+
requestId?: string;
|
|
134
|
+
path: string;
|
|
135
|
+
method: AtomicHttpMethod;
|
|
136
|
+
body?: TBody;
|
|
137
|
+
}
|
|
138
|
+
interface IBatchRequestPayload {
|
|
139
|
+
requests: IBatchRequestItem[];
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Creates a Request object from the IPC event data.
|
|
143
|
+
* This function extracts the necessary information from the IPC event and constructs a Request instance.
|
|
144
|
+
*/
|
|
145
|
+
interface IResponse<TBody = unknown> {
|
|
146
|
+
requestId: string;
|
|
147
|
+
status: number;
|
|
148
|
+
body?: TBody;
|
|
149
|
+
error?: string;
|
|
150
|
+
stack?: string;
|
|
151
|
+
}
|
|
152
|
+
interface IBatchResponsePayload {
|
|
153
|
+
responses: IResponse[];
|
|
154
|
+
}
|
|
155
|
+
declare const RENDERER_EVENT_TYPE = "noxus:event";
|
|
156
|
+
interface IRendererEventMessage<TPayload = unknown> {
|
|
157
|
+
type: typeof RENDERER_EVENT_TYPE;
|
|
158
|
+
event: string;
|
|
159
|
+
payload?: TPayload;
|
|
160
|
+
}
|
|
161
|
+
declare function createRendererEventMessage<TPayload = unknown>(event: string, payload?: TPayload): IRendererEventMessage<TPayload>;
|
|
162
|
+
declare function isRendererEventMessage(value: unknown): value is IRendererEventMessage;
|
|
163
|
+
|
|
10
164
|
/**
|
|
11
165
|
* Lightweight event registry to help renderer processes subscribe to
|
|
12
166
|
* push messages sent by the main process through Noxus.
|
|
@@ -93,21 +247,4 @@ declare class NoxRendererClient {
|
|
|
93
247
|
isElectronEnvironment(): boolean;
|
|
94
248
|
}
|
|
95
249
|
|
|
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 };
|
|
250
|
+
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, createRendererEventMessage, isRendererEventMessage };
|
package/dist/renderer.d.ts
CHANGED
|
@@ -1,12 +1,166 @@
|
|
|
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: any;
|
|
116
|
+
readonly context: AppInjector;
|
|
117
|
+
readonly params: Record<string, string>;
|
|
118
|
+
constructor(event: Electron.MessageEvent, senderId: number, id: string, method: HttpMethod, path: string, body: any);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* The IRequest interface defines the structure of a request object.
|
|
122
|
+
* It includes properties for the sender ID, request ID, path, method, and an optional body.
|
|
123
|
+
* This interface is used to standardize the request data across the application.
|
|
124
|
+
*/
|
|
125
|
+
interface IRequest<TBody = unknown> {
|
|
126
|
+
senderId: number;
|
|
127
|
+
requestId: string;
|
|
128
|
+
path: string;
|
|
129
|
+
method: HttpMethod;
|
|
130
|
+
body?: TBody;
|
|
131
|
+
}
|
|
132
|
+
interface IBatchRequestItem<TBody = unknown> {
|
|
133
|
+
requestId?: string;
|
|
134
|
+
path: string;
|
|
135
|
+
method: AtomicHttpMethod;
|
|
136
|
+
body?: TBody;
|
|
137
|
+
}
|
|
138
|
+
interface IBatchRequestPayload {
|
|
139
|
+
requests: IBatchRequestItem[];
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Creates a Request object from the IPC event data.
|
|
143
|
+
* This function extracts the necessary information from the IPC event and constructs a Request instance.
|
|
144
|
+
*/
|
|
145
|
+
interface IResponse<TBody = unknown> {
|
|
146
|
+
requestId: string;
|
|
147
|
+
status: number;
|
|
148
|
+
body?: TBody;
|
|
149
|
+
error?: string;
|
|
150
|
+
stack?: string;
|
|
151
|
+
}
|
|
152
|
+
interface IBatchResponsePayload {
|
|
153
|
+
responses: IResponse[];
|
|
154
|
+
}
|
|
155
|
+
declare const RENDERER_EVENT_TYPE = "noxus:event";
|
|
156
|
+
interface IRendererEventMessage<TPayload = unknown> {
|
|
157
|
+
type: typeof RENDERER_EVENT_TYPE;
|
|
158
|
+
event: string;
|
|
159
|
+
payload?: TPayload;
|
|
160
|
+
}
|
|
161
|
+
declare function createRendererEventMessage<TPayload = unknown>(event: string, payload?: TPayload): IRendererEventMessage<TPayload>;
|
|
162
|
+
declare function isRendererEventMessage(value: unknown): value is IRendererEventMessage;
|
|
163
|
+
|
|
10
164
|
/**
|
|
11
165
|
* Lightweight event registry to help renderer processes subscribe to
|
|
12
166
|
* push messages sent by the main process through Noxus.
|
|
@@ -93,21 +247,4 @@ declare class NoxRendererClient {
|
|
|
93
247
|
isElectronEnvironment(): boolean;
|
|
94
248
|
}
|
|
95
249
|
|
|
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 };
|
|
250
|
+
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, createRendererEventMessage, isRendererEventMessage };
|
package/dist/renderer.js
CHANGED
|
@@ -23,18 +23,17 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
23
23
|
};
|
|
24
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
25
|
|
|
26
|
-
// src/
|
|
27
|
-
var
|
|
28
|
-
__export(
|
|
26
|
+
// src/renderer.ts
|
|
27
|
+
var renderer_exports = {};
|
|
28
|
+
__export(renderer_exports, {
|
|
29
29
|
NoxRendererClient: () => NoxRendererClient,
|
|
30
30
|
RENDERER_EVENT_TYPE: () => RENDERER_EVENT_TYPE,
|
|
31
31
|
RendererEventRegistry: () => RendererEventRegistry,
|
|
32
32
|
Request: () => Request,
|
|
33
33
|
createRendererEventMessage: () => createRendererEventMessage,
|
|
34
|
-
exposeNoxusBridge: () => exposeNoxusBridge,
|
|
35
34
|
isRendererEventMessage: () => isRendererEventMessage
|
|
36
35
|
});
|
|
37
|
-
module.exports = __toCommonJS(
|
|
36
|
+
module.exports = __toCommonJS(renderer_exports);
|
|
38
37
|
|
|
39
38
|
// src/utils/forward-ref.ts
|
|
40
39
|
var _ForwardReference = class _ForwardReference {
|
|
@@ -96,6 +95,9 @@ var _AppInjector = class _AppInjector {
|
|
|
96
95
|
return this._resolveForwardRef(target);
|
|
97
96
|
}
|
|
98
97
|
const k = keyOf(target);
|
|
98
|
+
if (this.singletons.has(k)) {
|
|
99
|
+
return this.singletons.get(k);
|
|
100
|
+
}
|
|
99
101
|
const binding = this.bindings.get(k);
|
|
100
102
|
if (!binding) {
|
|
101
103
|
const name = target instanceof Token ? target.description : target.name ?? "unknown";
|
|
@@ -153,7 +155,7 @@ __name(_AppInjector, "AppInjector");
|
|
|
153
155
|
var AppInjector = _AppInjector;
|
|
154
156
|
var RootInjector = new AppInjector("root");
|
|
155
157
|
|
|
156
|
-
// src/request.ts
|
|
158
|
+
// src/internal/request.ts
|
|
157
159
|
var _Request = class _Request {
|
|
158
160
|
constructor(event, senderId, id, method, path, body) {
|
|
159
161
|
this.event = event;
|
|
@@ -187,53 +189,7 @@ function isRendererEventMessage(value) {
|
|
|
187
189
|
}
|
|
188
190
|
__name(isRendererEventMessage, "isRendererEventMessage");
|
|
189
191
|
|
|
190
|
-
// src/
|
|
191
|
-
var import_renderer = require("electron/renderer");
|
|
192
|
-
var DEFAULT_EXPOSE_NAME = "noxus";
|
|
193
|
-
var DEFAULT_INIT_EVENT = "init-port";
|
|
194
|
-
var DEFAULT_REQUEST_CHANNEL = "gimme-my-port";
|
|
195
|
-
var DEFAULT_RESPONSE_CHANNEL = "port";
|
|
196
|
-
function exposeNoxusBridge(options = {}) {
|
|
197
|
-
const {
|
|
198
|
-
exposeAs = DEFAULT_EXPOSE_NAME,
|
|
199
|
-
initMessageType = DEFAULT_INIT_EVENT,
|
|
200
|
-
requestChannel = DEFAULT_REQUEST_CHANNEL,
|
|
201
|
-
responseChannel = DEFAULT_RESPONSE_CHANNEL,
|
|
202
|
-
targetWindow = window
|
|
203
|
-
} = options;
|
|
204
|
-
const api = {
|
|
205
|
-
requestPort: /* @__PURE__ */ __name(() => {
|
|
206
|
-
import_renderer.ipcRenderer.send(requestChannel);
|
|
207
|
-
import_renderer.ipcRenderer.once(responseChannel, (event, message) => {
|
|
208
|
-
const ports = (event.ports ?? []).filter((port) => port !== void 0);
|
|
209
|
-
if (ports.length === 0) {
|
|
210
|
-
console.error("[Noxus] No MessagePort received from main process.");
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
for (const port of ports) {
|
|
214
|
-
try {
|
|
215
|
-
port.start();
|
|
216
|
-
} catch (error) {
|
|
217
|
-
console.error("[Noxus] Failed to start MessagePort.", error);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
targetWindow.postMessage(
|
|
221
|
-
{
|
|
222
|
-
type: initMessageType,
|
|
223
|
-
senderId: message?.senderId
|
|
224
|
-
},
|
|
225
|
-
"*",
|
|
226
|
-
ports
|
|
227
|
-
);
|
|
228
|
-
});
|
|
229
|
-
}, "requestPort")
|
|
230
|
-
};
|
|
231
|
-
import_renderer.contextBridge.exposeInMainWorld(exposeAs, api);
|
|
232
|
-
return api;
|
|
233
|
-
}
|
|
234
|
-
__name(exposeNoxusBridge, "exposeNoxusBridge");
|
|
235
|
-
|
|
236
|
-
// src/renderer-events.ts
|
|
192
|
+
// src/internal/renderer-events.ts
|
|
237
193
|
var _RendererEventRegistry = class _RendererEventRegistry {
|
|
238
194
|
constructor() {
|
|
239
195
|
this.listeners = /* @__PURE__ */ new Map();
|
|
@@ -313,8 +269,8 @@ var _RendererEventRegistry = class _RendererEventRegistry {
|
|
|
313
269
|
__name(_RendererEventRegistry, "RendererEventRegistry");
|
|
314
270
|
var RendererEventRegistry = _RendererEventRegistry;
|
|
315
271
|
|
|
316
|
-
// src/renderer-client.ts
|
|
317
|
-
var
|
|
272
|
+
// src/internal/renderer-client.ts
|
|
273
|
+
var DEFAULT_INIT_EVENT = "init-port";
|
|
318
274
|
var DEFAULT_BRIDGE_NAMES = ["noxus", "ipcRenderer"];
|
|
319
275
|
function defaultRequestId() {
|
|
320
276
|
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
@@ -424,7 +380,7 @@ var _NoxRendererClient = class _NoxRendererClient {
|
|
|
424
380
|
this.windowRef = options.windowRef ?? window;
|
|
425
381
|
const resolvedBridge = options.bridge ?? resolveBridgeFromWindow(this.windowRef, options.bridgeName);
|
|
426
382
|
this.bridge = resolvedBridge ?? null;
|
|
427
|
-
this.initMessageType = options.initMessageType ??
|
|
383
|
+
this.initMessageType = options.initMessageType ?? DEFAULT_INIT_EVENT;
|
|
428
384
|
this.generateRequestId = options.generateRequestId ?? defaultRequestId;
|
|
429
385
|
}
|
|
430
386
|
async setup() {
|
|
@@ -553,7 +509,6 @@ var NoxRendererClient = _NoxRendererClient;
|
|
|
553
509
|
RendererEventRegistry,
|
|
554
510
|
Request,
|
|
555
511
|
createRendererEventMessage,
|
|
556
|
-
exposeNoxusBridge,
|
|
557
512
|
isRendererEventMessage
|
|
558
513
|
});
|
|
559
514
|
/**
|
|
@@ -566,6 +521,7 @@ var NoxRendererClient = _NoxRendererClient;
|
|
|
566
521
|
* @license MIT
|
|
567
522
|
* @author NoxFly
|
|
568
523
|
*
|
|
569
|
-
* Entry point for renderer
|
|
524
|
+
* Entry point for renderer web consumers (Angular, React, Vue, Vanilla...).
|
|
525
|
+
* No Electron imports — safe to bundle with any web bundler.
|
|
570
526
|
*/
|
|
571
527
|
//# sourceMappingURL=renderer.js.map
|
package/dist/renderer.mjs
CHANGED
|
@@ -66,6 +66,9 @@ var _AppInjector = class _AppInjector {
|
|
|
66
66
|
return this._resolveForwardRef(target);
|
|
67
67
|
}
|
|
68
68
|
const k = keyOf(target);
|
|
69
|
+
if (this.singletons.has(k)) {
|
|
70
|
+
return this.singletons.get(k);
|
|
71
|
+
}
|
|
69
72
|
const binding = this.bindings.get(k);
|
|
70
73
|
if (!binding) {
|
|
71
74
|
const name = target instanceof Token ? target.description : target.name ?? "unknown";
|
|
@@ -123,7 +126,7 @@ __name(_AppInjector, "AppInjector");
|
|
|
123
126
|
var AppInjector = _AppInjector;
|
|
124
127
|
var RootInjector = new AppInjector("root");
|
|
125
128
|
|
|
126
|
-
// src/request.ts
|
|
129
|
+
// src/internal/request.ts
|
|
127
130
|
var _Request = class _Request {
|
|
128
131
|
constructor(event, senderId, id, method, path, body) {
|
|
129
132
|
this.event = event;
|
|
@@ -157,53 +160,7 @@ function isRendererEventMessage(value) {
|
|
|
157
160
|
}
|
|
158
161
|
__name(isRendererEventMessage, "isRendererEventMessage");
|
|
159
162
|
|
|
160
|
-
// src/
|
|
161
|
-
import { contextBridge, ipcRenderer } from "electron/renderer";
|
|
162
|
-
var DEFAULT_EXPOSE_NAME = "noxus";
|
|
163
|
-
var DEFAULT_INIT_EVENT = "init-port";
|
|
164
|
-
var DEFAULT_REQUEST_CHANNEL = "gimme-my-port";
|
|
165
|
-
var DEFAULT_RESPONSE_CHANNEL = "port";
|
|
166
|
-
function exposeNoxusBridge(options = {}) {
|
|
167
|
-
const {
|
|
168
|
-
exposeAs = DEFAULT_EXPOSE_NAME,
|
|
169
|
-
initMessageType = DEFAULT_INIT_EVENT,
|
|
170
|
-
requestChannel = DEFAULT_REQUEST_CHANNEL,
|
|
171
|
-
responseChannel = DEFAULT_RESPONSE_CHANNEL,
|
|
172
|
-
targetWindow = window
|
|
173
|
-
} = options;
|
|
174
|
-
const api = {
|
|
175
|
-
requestPort: /* @__PURE__ */ __name(() => {
|
|
176
|
-
ipcRenderer.send(requestChannel);
|
|
177
|
-
ipcRenderer.once(responseChannel, (event, message) => {
|
|
178
|
-
const ports = (event.ports ?? []).filter((port) => port !== void 0);
|
|
179
|
-
if (ports.length === 0) {
|
|
180
|
-
console.error("[Noxus] No MessagePort received from main process.");
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
for (const port of ports) {
|
|
184
|
-
try {
|
|
185
|
-
port.start();
|
|
186
|
-
} catch (error) {
|
|
187
|
-
console.error("[Noxus] Failed to start MessagePort.", error);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
targetWindow.postMessage(
|
|
191
|
-
{
|
|
192
|
-
type: initMessageType,
|
|
193
|
-
senderId: message?.senderId
|
|
194
|
-
},
|
|
195
|
-
"*",
|
|
196
|
-
ports
|
|
197
|
-
);
|
|
198
|
-
});
|
|
199
|
-
}, "requestPort")
|
|
200
|
-
};
|
|
201
|
-
contextBridge.exposeInMainWorld(exposeAs, api);
|
|
202
|
-
return api;
|
|
203
|
-
}
|
|
204
|
-
__name(exposeNoxusBridge, "exposeNoxusBridge");
|
|
205
|
-
|
|
206
|
-
// src/renderer-events.ts
|
|
163
|
+
// src/internal/renderer-events.ts
|
|
207
164
|
var _RendererEventRegistry = class _RendererEventRegistry {
|
|
208
165
|
constructor() {
|
|
209
166
|
this.listeners = /* @__PURE__ */ new Map();
|
|
@@ -283,8 +240,8 @@ var _RendererEventRegistry = class _RendererEventRegistry {
|
|
|
283
240
|
__name(_RendererEventRegistry, "RendererEventRegistry");
|
|
284
241
|
var RendererEventRegistry = _RendererEventRegistry;
|
|
285
242
|
|
|
286
|
-
// src/renderer-client.ts
|
|
287
|
-
var
|
|
243
|
+
// src/internal/renderer-client.ts
|
|
244
|
+
var DEFAULT_INIT_EVENT = "init-port";
|
|
288
245
|
var DEFAULT_BRIDGE_NAMES = ["noxus", "ipcRenderer"];
|
|
289
246
|
function defaultRequestId() {
|
|
290
247
|
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
@@ -394,7 +351,7 @@ var _NoxRendererClient = class _NoxRendererClient {
|
|
|
394
351
|
this.windowRef = options.windowRef ?? window;
|
|
395
352
|
const resolvedBridge = options.bridge ?? resolveBridgeFromWindow(this.windowRef, options.bridgeName);
|
|
396
353
|
this.bridge = resolvedBridge ?? null;
|
|
397
|
-
this.initMessageType = options.initMessageType ??
|
|
354
|
+
this.initMessageType = options.initMessageType ?? DEFAULT_INIT_EVENT;
|
|
398
355
|
this.generateRequestId = options.generateRequestId ?? defaultRequestId;
|
|
399
356
|
}
|
|
400
357
|
async setup() {
|
|
@@ -522,7 +479,6 @@ export {
|
|
|
522
479
|
RendererEventRegistry,
|
|
523
480
|
Request,
|
|
524
481
|
createRendererEventMessage,
|
|
525
|
-
exposeNoxusBridge,
|
|
526
482
|
isRendererEventMessage
|
|
527
483
|
};
|
|
528
484
|
/**
|
|
@@ -535,6 +491,7 @@ export {
|
|
|
535
491
|
* @license MIT
|
|
536
492
|
* @author NoxFly
|
|
537
493
|
*
|
|
538
|
-
* Entry point for renderer
|
|
494
|
+
* Entry point for renderer web consumers (Angular, React, Vue, Vanilla...).
|
|
495
|
+
* No Electron imports — safe to bundle with any web bundler.
|
|
539
496
|
*/
|
|
540
497
|
//# sourceMappingURL=renderer.mjs.map
|