@noxfly/noxus 1.1.9 → 1.2.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.
- package/.vscode/settings.json +3 -0
- package/README.md +69 -9
- package/dist/index-5OkVPHfI.d.mts +268 -0
- package/dist/index-5OkVPHfI.d.ts +268 -0
- package/dist/{noxus.d.mts → main.d.mts} +21 -209
- package/dist/{noxus.d.ts → main.d.ts} +21 -209
- package/dist/{noxus.js → main.js} +336 -67
- package/dist/{noxus.mjs → main.mjs} +325 -61
- package/dist/renderer.d.mts +1 -0
- package/dist/renderer.d.ts +1 -0
- package/dist/renderer.js +265 -0
- package/dist/renderer.mjs +236 -0
- package/package.json +73 -48
- package/scripts/postbuild.js +10 -5
- package/src/app.ts +37 -41
- package/src/decorators/method.decorator.ts +6 -1
- package/src/index.ts +1 -13
- package/src/main.ts +25 -0
- package/src/renderer-events.ts +110 -0
- package/src/request.ts +46 -5
- package/src/router.ts +133 -3
- package/src/socket.ts +68 -0
- package/tsup.config.ts +2 -1
package/dist/renderer.js
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright 2025 NoxFly
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @author NoxFly
|
|
5
|
+
*/
|
|
6
|
+
"use strict";
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
9
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
13
|
+
var __export = (target, all) => {
|
|
14
|
+
for (var name in all)
|
|
15
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
16
|
+
};
|
|
17
|
+
var __copyProps = (to, from, except, desc) => {
|
|
18
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
19
|
+
for (let key of __getOwnPropNames(from))
|
|
20
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
21
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
26
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
27
|
+
|
|
28
|
+
// src/index.ts
|
|
29
|
+
var src_exports = {};
|
|
30
|
+
__export(src_exports, {
|
|
31
|
+
RENDERER_EVENT_TYPE: () => RENDERER_EVENT_TYPE,
|
|
32
|
+
RendererEventRegistry: () => RendererEventRegistry,
|
|
33
|
+
Request: () => Request,
|
|
34
|
+
createRendererEventMessage: () => createRendererEventMessage,
|
|
35
|
+
isRendererEventMessage: () => isRendererEventMessage
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(src_exports);
|
|
38
|
+
|
|
39
|
+
// src/request.ts
|
|
40
|
+
var import_reflect_metadata2 = require("reflect-metadata");
|
|
41
|
+
|
|
42
|
+
// src/DI/app-injector.ts
|
|
43
|
+
var import_reflect_metadata = require("reflect-metadata");
|
|
44
|
+
|
|
45
|
+
// src/exceptions.ts
|
|
46
|
+
var _ResponseException = class _ResponseException extends Error {
|
|
47
|
+
constructor(statusOrMessage, message) {
|
|
48
|
+
let statusCode;
|
|
49
|
+
if (typeof statusOrMessage === "number") {
|
|
50
|
+
statusCode = statusOrMessage;
|
|
51
|
+
} else if (typeof statusOrMessage === "string") {
|
|
52
|
+
message = statusOrMessage;
|
|
53
|
+
}
|
|
54
|
+
super(message ?? "");
|
|
55
|
+
__publicField(this, "status", 0);
|
|
56
|
+
if (statusCode !== void 0) {
|
|
57
|
+
this.status = statusCode;
|
|
58
|
+
}
|
|
59
|
+
this.name = this.constructor.name.replace(/([A-Z])/g, " $1");
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
__name(_ResponseException, "ResponseException");
|
|
63
|
+
var ResponseException = _ResponseException;
|
|
64
|
+
var _InternalServerException = class _InternalServerException extends ResponseException {
|
|
65
|
+
constructor() {
|
|
66
|
+
super(...arguments);
|
|
67
|
+
__publicField(this, "status", 500);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
__name(_InternalServerException, "InternalServerException");
|
|
71
|
+
var InternalServerException = _InternalServerException;
|
|
72
|
+
|
|
73
|
+
// src/DI/app-injector.ts
|
|
74
|
+
var _AppInjector = class _AppInjector {
|
|
75
|
+
constructor(name = null) {
|
|
76
|
+
__publicField(this, "name");
|
|
77
|
+
__publicField(this, "bindings", /* @__PURE__ */ new Map());
|
|
78
|
+
__publicField(this, "singletons", /* @__PURE__ */ new Map());
|
|
79
|
+
__publicField(this, "scoped", /* @__PURE__ */ new Map());
|
|
80
|
+
this.name = name;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Typically used to create a dependency injection scope
|
|
84
|
+
* at the "scope" level (i.e., per-request lifetime).
|
|
85
|
+
*
|
|
86
|
+
* SHOULD NOT BE USED by anything else than the framework itself.
|
|
87
|
+
*/
|
|
88
|
+
createScope() {
|
|
89
|
+
const scope = new _AppInjector();
|
|
90
|
+
scope.bindings = this.bindings;
|
|
91
|
+
scope.singletons = this.singletons;
|
|
92
|
+
return scope;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Called when resolving a dependency,
|
|
96
|
+
* i.e., retrieving the instance of a given class.
|
|
97
|
+
*/
|
|
98
|
+
resolve(target) {
|
|
99
|
+
const binding = this.bindings.get(target);
|
|
100
|
+
if (!binding) throw new InternalServerException(`Failed to resolve a dependency injection : No binding for type ${target.name}.
|
|
101
|
+
Did you forget to use @Injectable() decorator ?`);
|
|
102
|
+
switch (binding.lifetime) {
|
|
103
|
+
case "transient":
|
|
104
|
+
return this.instantiate(binding.implementation);
|
|
105
|
+
case "scope": {
|
|
106
|
+
if (this.scoped.has(target)) {
|
|
107
|
+
return this.scoped.get(target);
|
|
108
|
+
}
|
|
109
|
+
const instance = this.instantiate(binding.implementation);
|
|
110
|
+
this.scoped.set(target, instance);
|
|
111
|
+
return instance;
|
|
112
|
+
}
|
|
113
|
+
case "singleton": {
|
|
114
|
+
if (binding.instance === void 0 && this.name === "root") {
|
|
115
|
+
binding.instance = this.instantiate(binding.implementation);
|
|
116
|
+
this.singletons.set(target, binding.instance);
|
|
117
|
+
}
|
|
118
|
+
return binding.instance;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
*
|
|
124
|
+
*/
|
|
125
|
+
instantiate(target) {
|
|
126
|
+
const paramTypes = Reflect.getMetadata("design:paramtypes", target) || [];
|
|
127
|
+
const params = paramTypes.map((p) => this.resolve(p));
|
|
128
|
+
return new target(...params);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
__name(_AppInjector, "AppInjector");
|
|
132
|
+
var AppInjector = _AppInjector;
|
|
133
|
+
var RootInjector = new AppInjector("root");
|
|
134
|
+
|
|
135
|
+
// src/request.ts
|
|
136
|
+
var _Request = class _Request {
|
|
137
|
+
constructor(event, id, method, path, body) {
|
|
138
|
+
__publicField(this, "event");
|
|
139
|
+
__publicField(this, "id");
|
|
140
|
+
__publicField(this, "method");
|
|
141
|
+
__publicField(this, "path");
|
|
142
|
+
__publicField(this, "body");
|
|
143
|
+
__publicField(this, "context", RootInjector.createScope());
|
|
144
|
+
__publicField(this, "params", {});
|
|
145
|
+
this.event = event;
|
|
146
|
+
this.id = id;
|
|
147
|
+
this.method = method;
|
|
148
|
+
this.path = path;
|
|
149
|
+
this.body = body;
|
|
150
|
+
this.path = path.replace(/^\/|\/$/g, "");
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
__name(_Request, "Request");
|
|
154
|
+
var Request = _Request;
|
|
155
|
+
var RENDERER_EVENT_TYPE = "noxus:event";
|
|
156
|
+
function createRendererEventMessage(event, payload) {
|
|
157
|
+
return {
|
|
158
|
+
type: RENDERER_EVENT_TYPE,
|
|
159
|
+
event,
|
|
160
|
+
payload
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
__name(createRendererEventMessage, "createRendererEventMessage");
|
|
164
|
+
function isRendererEventMessage(value) {
|
|
165
|
+
if (value === null || typeof value !== "object") {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
const possibleMessage = value;
|
|
169
|
+
return possibleMessage.type === RENDERER_EVENT_TYPE && typeof possibleMessage.event === "string";
|
|
170
|
+
}
|
|
171
|
+
__name(isRendererEventMessage, "isRendererEventMessage");
|
|
172
|
+
|
|
173
|
+
// src/renderer-events.ts
|
|
174
|
+
var _RendererEventRegistry = class _RendererEventRegistry {
|
|
175
|
+
constructor() {
|
|
176
|
+
__publicField(this, "listeners", /* @__PURE__ */ new Map());
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
*
|
|
180
|
+
*/
|
|
181
|
+
subscribe(eventName, handler) {
|
|
182
|
+
const normalizedEventName = eventName.trim();
|
|
183
|
+
if (normalizedEventName.length === 0) {
|
|
184
|
+
throw new Error("Renderer event name must be a non-empty string.");
|
|
185
|
+
}
|
|
186
|
+
const handlers = this.listeners.get(normalizedEventName) ?? /* @__PURE__ */ new Set();
|
|
187
|
+
handlers.add(handler);
|
|
188
|
+
this.listeners.set(normalizedEventName, handlers);
|
|
189
|
+
return {
|
|
190
|
+
unsubscribe: /* @__PURE__ */ __name(() => this.unsubscribe(normalizedEventName, handler), "unsubscribe")
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
*
|
|
195
|
+
*/
|
|
196
|
+
unsubscribe(eventName, handler) {
|
|
197
|
+
const handlers = this.listeners.get(eventName);
|
|
198
|
+
if (!handlers) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
handlers.delete(handler);
|
|
202
|
+
if (handlers.size === 0) {
|
|
203
|
+
this.listeners.delete(eventName);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
*
|
|
208
|
+
*/
|
|
209
|
+
clear(eventName) {
|
|
210
|
+
if (eventName) {
|
|
211
|
+
this.listeners.delete(eventName);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
this.listeners.clear();
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
*
|
|
218
|
+
*/
|
|
219
|
+
dispatch(message) {
|
|
220
|
+
const handlers = this.listeners.get(message.event);
|
|
221
|
+
if (!handlers || handlers.size === 0) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
handlers.forEach((handler) => {
|
|
225
|
+
try {
|
|
226
|
+
handler(message.payload);
|
|
227
|
+
} catch (error) {
|
|
228
|
+
console.error(`[Noxus] Renderer event handler for "${message.event}" threw an error.`, error);
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
*
|
|
234
|
+
*/
|
|
235
|
+
tryDispatchFromMessageEvent(event) {
|
|
236
|
+
if (!isRendererEventMessage(event.data)) {
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
this.dispatch(event.data);
|
|
240
|
+
return true;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
*
|
|
244
|
+
*/
|
|
245
|
+
hasHandlers(eventName) {
|
|
246
|
+
const handlers = this.listeners.get(eventName);
|
|
247
|
+
return !!handlers && handlers.size > 0;
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
__name(_RendererEventRegistry, "RendererEventRegistry");
|
|
251
|
+
var RendererEventRegistry = _RendererEventRegistry;
|
|
252
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
253
|
+
0 && (module.exports = {
|
|
254
|
+
RENDERER_EVENT_TYPE,
|
|
255
|
+
RendererEventRegistry,
|
|
256
|
+
Request,
|
|
257
|
+
createRendererEventMessage,
|
|
258
|
+
isRendererEventMessage
|
|
259
|
+
});
|
|
260
|
+
/**
|
|
261
|
+
* @copyright 2025 NoxFly
|
|
262
|
+
* @license MIT
|
|
263
|
+
* @author NoxFly
|
|
264
|
+
*/
|
|
265
|
+
//# sourceMappingURL=renderer.js.map
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright 2025 NoxFly
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @author NoxFly
|
|
5
|
+
*/
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
10
|
+
|
|
11
|
+
// src/request.ts
|
|
12
|
+
import "reflect-metadata";
|
|
13
|
+
|
|
14
|
+
// src/DI/app-injector.ts
|
|
15
|
+
import "reflect-metadata";
|
|
16
|
+
|
|
17
|
+
// src/exceptions.ts
|
|
18
|
+
var _ResponseException = class _ResponseException extends Error {
|
|
19
|
+
constructor(statusOrMessage, message) {
|
|
20
|
+
let statusCode;
|
|
21
|
+
if (typeof statusOrMessage === "number") {
|
|
22
|
+
statusCode = statusOrMessage;
|
|
23
|
+
} else if (typeof statusOrMessage === "string") {
|
|
24
|
+
message = statusOrMessage;
|
|
25
|
+
}
|
|
26
|
+
super(message ?? "");
|
|
27
|
+
__publicField(this, "status", 0);
|
|
28
|
+
if (statusCode !== void 0) {
|
|
29
|
+
this.status = statusCode;
|
|
30
|
+
}
|
|
31
|
+
this.name = this.constructor.name.replace(/([A-Z])/g, " $1");
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
__name(_ResponseException, "ResponseException");
|
|
35
|
+
var ResponseException = _ResponseException;
|
|
36
|
+
var _InternalServerException = class _InternalServerException extends ResponseException {
|
|
37
|
+
constructor() {
|
|
38
|
+
super(...arguments);
|
|
39
|
+
__publicField(this, "status", 500);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
__name(_InternalServerException, "InternalServerException");
|
|
43
|
+
var InternalServerException = _InternalServerException;
|
|
44
|
+
|
|
45
|
+
// src/DI/app-injector.ts
|
|
46
|
+
var _AppInjector = class _AppInjector {
|
|
47
|
+
constructor(name = null) {
|
|
48
|
+
__publicField(this, "name");
|
|
49
|
+
__publicField(this, "bindings", /* @__PURE__ */ new Map());
|
|
50
|
+
__publicField(this, "singletons", /* @__PURE__ */ new Map());
|
|
51
|
+
__publicField(this, "scoped", /* @__PURE__ */ new Map());
|
|
52
|
+
this.name = name;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Typically used to create a dependency injection scope
|
|
56
|
+
* at the "scope" level (i.e., per-request lifetime).
|
|
57
|
+
*
|
|
58
|
+
* SHOULD NOT BE USED by anything else than the framework itself.
|
|
59
|
+
*/
|
|
60
|
+
createScope() {
|
|
61
|
+
const scope = new _AppInjector();
|
|
62
|
+
scope.bindings = this.bindings;
|
|
63
|
+
scope.singletons = this.singletons;
|
|
64
|
+
return scope;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Called when resolving a dependency,
|
|
68
|
+
* i.e., retrieving the instance of a given class.
|
|
69
|
+
*/
|
|
70
|
+
resolve(target) {
|
|
71
|
+
const binding = this.bindings.get(target);
|
|
72
|
+
if (!binding) throw new InternalServerException(`Failed to resolve a dependency injection : No binding for type ${target.name}.
|
|
73
|
+
Did you forget to use @Injectable() decorator ?`);
|
|
74
|
+
switch (binding.lifetime) {
|
|
75
|
+
case "transient":
|
|
76
|
+
return this.instantiate(binding.implementation);
|
|
77
|
+
case "scope": {
|
|
78
|
+
if (this.scoped.has(target)) {
|
|
79
|
+
return this.scoped.get(target);
|
|
80
|
+
}
|
|
81
|
+
const instance = this.instantiate(binding.implementation);
|
|
82
|
+
this.scoped.set(target, instance);
|
|
83
|
+
return instance;
|
|
84
|
+
}
|
|
85
|
+
case "singleton": {
|
|
86
|
+
if (binding.instance === void 0 && this.name === "root") {
|
|
87
|
+
binding.instance = this.instantiate(binding.implementation);
|
|
88
|
+
this.singletons.set(target, binding.instance);
|
|
89
|
+
}
|
|
90
|
+
return binding.instance;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
*
|
|
96
|
+
*/
|
|
97
|
+
instantiate(target) {
|
|
98
|
+
const paramTypes = Reflect.getMetadata("design:paramtypes", target) || [];
|
|
99
|
+
const params = paramTypes.map((p) => this.resolve(p));
|
|
100
|
+
return new target(...params);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
__name(_AppInjector, "AppInjector");
|
|
104
|
+
var AppInjector = _AppInjector;
|
|
105
|
+
var RootInjector = new AppInjector("root");
|
|
106
|
+
|
|
107
|
+
// src/request.ts
|
|
108
|
+
var _Request = class _Request {
|
|
109
|
+
constructor(event, id, method, path, body) {
|
|
110
|
+
__publicField(this, "event");
|
|
111
|
+
__publicField(this, "id");
|
|
112
|
+
__publicField(this, "method");
|
|
113
|
+
__publicField(this, "path");
|
|
114
|
+
__publicField(this, "body");
|
|
115
|
+
__publicField(this, "context", RootInjector.createScope());
|
|
116
|
+
__publicField(this, "params", {});
|
|
117
|
+
this.event = event;
|
|
118
|
+
this.id = id;
|
|
119
|
+
this.method = method;
|
|
120
|
+
this.path = path;
|
|
121
|
+
this.body = body;
|
|
122
|
+
this.path = path.replace(/^\/|\/$/g, "");
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
__name(_Request, "Request");
|
|
126
|
+
var Request = _Request;
|
|
127
|
+
var RENDERER_EVENT_TYPE = "noxus:event";
|
|
128
|
+
function createRendererEventMessage(event, payload) {
|
|
129
|
+
return {
|
|
130
|
+
type: RENDERER_EVENT_TYPE,
|
|
131
|
+
event,
|
|
132
|
+
payload
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
__name(createRendererEventMessage, "createRendererEventMessage");
|
|
136
|
+
function isRendererEventMessage(value) {
|
|
137
|
+
if (value === null || typeof value !== "object") {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
const possibleMessage = value;
|
|
141
|
+
return possibleMessage.type === RENDERER_EVENT_TYPE && typeof possibleMessage.event === "string";
|
|
142
|
+
}
|
|
143
|
+
__name(isRendererEventMessage, "isRendererEventMessage");
|
|
144
|
+
|
|
145
|
+
// src/renderer-events.ts
|
|
146
|
+
var _RendererEventRegistry = class _RendererEventRegistry {
|
|
147
|
+
constructor() {
|
|
148
|
+
__publicField(this, "listeners", /* @__PURE__ */ new Map());
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
*
|
|
152
|
+
*/
|
|
153
|
+
subscribe(eventName, handler) {
|
|
154
|
+
const normalizedEventName = eventName.trim();
|
|
155
|
+
if (normalizedEventName.length === 0) {
|
|
156
|
+
throw new Error("Renderer event name must be a non-empty string.");
|
|
157
|
+
}
|
|
158
|
+
const handlers = this.listeners.get(normalizedEventName) ?? /* @__PURE__ */ new Set();
|
|
159
|
+
handlers.add(handler);
|
|
160
|
+
this.listeners.set(normalizedEventName, handlers);
|
|
161
|
+
return {
|
|
162
|
+
unsubscribe: /* @__PURE__ */ __name(() => this.unsubscribe(normalizedEventName, handler), "unsubscribe")
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
*
|
|
167
|
+
*/
|
|
168
|
+
unsubscribe(eventName, handler) {
|
|
169
|
+
const handlers = this.listeners.get(eventName);
|
|
170
|
+
if (!handlers) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
handlers.delete(handler);
|
|
174
|
+
if (handlers.size === 0) {
|
|
175
|
+
this.listeners.delete(eventName);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
*
|
|
180
|
+
*/
|
|
181
|
+
clear(eventName) {
|
|
182
|
+
if (eventName) {
|
|
183
|
+
this.listeners.delete(eventName);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
this.listeners.clear();
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
*
|
|
190
|
+
*/
|
|
191
|
+
dispatch(message) {
|
|
192
|
+
const handlers = this.listeners.get(message.event);
|
|
193
|
+
if (!handlers || handlers.size === 0) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
handlers.forEach((handler) => {
|
|
197
|
+
try {
|
|
198
|
+
handler(message.payload);
|
|
199
|
+
} catch (error) {
|
|
200
|
+
console.error(`[Noxus] Renderer event handler for "${message.event}" threw an error.`, error);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
*
|
|
206
|
+
*/
|
|
207
|
+
tryDispatchFromMessageEvent(event) {
|
|
208
|
+
if (!isRendererEventMessage(event.data)) {
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
this.dispatch(event.data);
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
*
|
|
216
|
+
*/
|
|
217
|
+
hasHandlers(eventName) {
|
|
218
|
+
const handlers = this.listeners.get(eventName);
|
|
219
|
+
return !!handlers && handlers.size > 0;
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
__name(_RendererEventRegistry, "RendererEventRegistry");
|
|
223
|
+
var RendererEventRegistry = _RendererEventRegistry;
|
|
224
|
+
export {
|
|
225
|
+
RENDERER_EVENT_TYPE,
|
|
226
|
+
RendererEventRegistry,
|
|
227
|
+
Request,
|
|
228
|
+
createRendererEventMessage,
|
|
229
|
+
isRendererEventMessage
|
|
230
|
+
};
|
|
231
|
+
/**
|
|
232
|
+
* @copyright 2025 NoxFly
|
|
233
|
+
* @license MIT
|
|
234
|
+
* @author NoxFly
|
|
235
|
+
*/
|
|
236
|
+
//# sourceMappingURL=renderer.mjs.map
|
package/package.json
CHANGED
|
@@ -1,50 +1,75 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"
|
|
49
|
-
|
|
2
|
+
"name": "@noxfly/noxus",
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"main": "dist/main.js",
|
|
5
|
+
"module": "dist/main.mjs",
|
|
6
|
+
"types": "dist/main.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"browser": {
|
|
10
|
+
"types": "./dist/renderer.d.ts",
|
|
11
|
+
"import": "./dist/renderer.mjs",
|
|
12
|
+
"require": "./dist/renderer.js"
|
|
13
|
+
},
|
|
14
|
+
"default": {
|
|
15
|
+
"types": "./dist/main.d.ts",
|
|
16
|
+
"import": "./dist/main.mjs",
|
|
17
|
+
"require": "./dist/main.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"./renderer": {
|
|
21
|
+
"types": "./dist/renderer.d.ts",
|
|
22
|
+
"import": "./dist/renderer.mjs",
|
|
23
|
+
"require": "./dist/renderer.js"
|
|
24
|
+
},
|
|
25
|
+
"./main": {
|
|
26
|
+
"types": "./dist/main.d.ts",
|
|
27
|
+
"import": "./dist/main.mjs",
|
|
28
|
+
"require": "./dist/main.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsup",
|
|
33
|
+
"prepublishOnly": "npm run build",
|
|
34
|
+
"prepush": "npm run build",
|
|
35
|
+
"postbuild": "node scripts/postbuild.js"
|
|
36
|
+
},
|
|
37
|
+
"keywords": [
|
|
38
|
+
"noxus",
|
|
39
|
+
"nox",
|
|
40
|
+
"nodejs",
|
|
41
|
+
"typescript",
|
|
42
|
+
"framework",
|
|
43
|
+
"web framework",
|
|
44
|
+
"electron"
|
|
45
|
+
],
|
|
46
|
+
"author": "NoxFly",
|
|
47
|
+
"license": "MIT",
|
|
48
|
+
"description": "Simulate lightweight HTTP-like requests between renderer and main process in Electron applications with MessagePort, with structured and modular design.",
|
|
49
|
+
"homepage": "https://github.com/NoxFly/noxus",
|
|
50
|
+
"repository": {
|
|
51
|
+
"type": "git",
|
|
52
|
+
"url": "https://github.com/NoxFly/noxus.git"
|
|
53
|
+
},
|
|
54
|
+
"engines": {
|
|
55
|
+
"node": ">= 20"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@stylistic/eslint-plugin": "^5.1.0",
|
|
59
|
+
"@swc/core": "^1.12.14",
|
|
60
|
+
"@typescript-eslint/eslint-plugin": "^8.36.0",
|
|
61
|
+
"@typescript-eslint/parser": "^8.36.0",
|
|
62
|
+
"electron": "^37.2.1",
|
|
63
|
+
"eslint": "^9.31.0",
|
|
64
|
+
"eslint-plugin-import": "^2.32.0",
|
|
65
|
+
"eslint-plugin-jsdoc": "^51.3.4",
|
|
66
|
+
"eslint-plugin-prefer-arrow": "^1.2.3",
|
|
67
|
+
"tsc-alias": "^1.8.16",
|
|
68
|
+
"tsup": "^8.5.0",
|
|
69
|
+
"typescript": "^5.8.3",
|
|
70
|
+
"typescript-eslint": "^8.36.0"
|
|
71
|
+
},
|
|
72
|
+
"peerDependencies": {
|
|
73
|
+
"reflect-metadata": "^0.2.2"
|
|
74
|
+
}
|
|
50
75
|
}
|
package/scripts/postbuild.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
function uniqueDocBlocks(filepath) {
|
|
5
|
+
if(!fs.existsSync(filepath)) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
5
8
|
|
|
6
|
-
function removeDuplicateCopyrights(filename) {
|
|
7
|
-
const filepath = path.join(__dirname, '../dist/' + filename);
|
|
8
9
|
const content = fs.readFileSync(filepath, 'utf8');
|
|
9
10
|
|
|
10
11
|
const reg = /\/\*\*[\t ]*\n(?: \*.*\n)*? \* *@copyright.*\n(?: \*.*\n)*? \*\/\n?/gm;
|
|
@@ -21,6 +22,10 @@ function removeDuplicateCopyrights(filename) {
|
|
|
21
22
|
fs.writeFileSync(filepath, deduped);
|
|
22
23
|
}
|
|
23
24
|
|
|
25
|
+
const distDir = path.join(__dirname, '../dist');
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
for(const filename of fs.readdirSync(distDir)) {
|
|
28
|
+
if(filename.endsWith('.d.ts') || filename.endsWith('.d.mts')) {
|
|
29
|
+
uniqueDocBlocks(path.join(distDir, filename));
|
|
30
|
+
}
|
|
31
|
+
}
|