@noxfly/noxus 1.1.10 → 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/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} +17 -225
- package/dist/{noxus.d.ts → main.d.ts} +17 -225
- package/dist/{noxus.js → main.js} +211 -45
- package/dist/{noxus.mjs → main.mjs} +201 -40
- 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/index.ts +1 -13
- package/src/main.ts +25 -0
- package/src/renderer-events.ts +110 -0
- package/src/request.ts +26 -0
- package/src/socket.ts +68 -0
- package/tsup.config.ts +2 -1
|
@@ -25,9 +25,9 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
25
25
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
26
26
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
27
27
|
|
|
28
|
-
// src/
|
|
29
|
-
var
|
|
30
|
-
__export(
|
|
28
|
+
// src/main.ts
|
|
29
|
+
var main_exports = {};
|
|
30
|
+
__export(main_exports, {
|
|
31
31
|
AppInjector: () => AppInjector,
|
|
32
32
|
Authorize: () => Authorize,
|
|
33
33
|
BadGatewayException: () => BadGatewayException,
|
|
@@ -56,11 +56,14 @@ __export(src_exports, {
|
|
|
56
56
|
NotFoundException: () => NotFoundException,
|
|
57
57
|
NotImplementedException: () => NotImplementedException,
|
|
58
58
|
NoxApp: () => NoxApp,
|
|
59
|
+
NoxSocket: () => NoxSocket,
|
|
59
60
|
Patch: () => Patch,
|
|
60
61
|
PaymentRequiredException: () => PaymentRequiredException,
|
|
61
62
|
Post: () => Post,
|
|
62
63
|
Put: () => Put,
|
|
64
|
+
RENDERER_EVENT_TYPE: () => RENDERER_EVENT_TYPE,
|
|
63
65
|
ROUTE_METADATA_KEY: () => ROUTE_METADATA_KEY,
|
|
66
|
+
RendererEventRegistry: () => RendererEventRegistry,
|
|
64
67
|
Request: () => Request,
|
|
65
68
|
RequestTimeoutException: () => RequestTimeoutException,
|
|
66
69
|
ResponseException: () => ResponseException,
|
|
@@ -73,6 +76,7 @@ __export(src_exports, {
|
|
|
73
76
|
UseMiddlewares: () => UseMiddlewares,
|
|
74
77
|
VariantAlsoNegotiatesException: () => VariantAlsoNegotiatesException,
|
|
75
78
|
bootstrapApplication: () => bootstrapApplication,
|
|
79
|
+
createRendererEventMessage: () => createRendererEventMessage,
|
|
76
80
|
getControllerMetadata: () => getControllerMetadata,
|
|
77
81
|
getGuardForController: () => getGuardForController,
|
|
78
82
|
getGuardForControllerAction: () => getGuardForControllerAction,
|
|
@@ -81,9 +85,10 @@ __export(src_exports, {
|
|
|
81
85
|
getMiddlewaresForControllerAction: () => getMiddlewaresForControllerAction,
|
|
82
86
|
getModuleMetadata: () => getModuleMetadata,
|
|
83
87
|
getRouteMetadata: () => getRouteMetadata,
|
|
84
|
-
inject: () => inject
|
|
88
|
+
inject: () => inject,
|
|
89
|
+
isRendererEventMessage: () => isRendererEventMessage
|
|
85
90
|
});
|
|
86
|
-
module.exports = __toCommonJS(
|
|
91
|
+
module.exports = __toCommonJS(main_exports);
|
|
87
92
|
|
|
88
93
|
// src/DI/app-injector.ts
|
|
89
94
|
var import_reflect_metadata = require("reflect-metadata");
|
|
@@ -720,6 +725,23 @@ var _Request = class _Request {
|
|
|
720
725
|
};
|
|
721
726
|
__name(_Request, "Request");
|
|
722
727
|
var Request = _Request;
|
|
728
|
+
var RENDERER_EVENT_TYPE = "noxus:event";
|
|
729
|
+
function createRendererEventMessage(event, payload) {
|
|
730
|
+
return {
|
|
731
|
+
type: RENDERER_EVENT_TYPE,
|
|
732
|
+
event,
|
|
733
|
+
payload
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
__name(createRendererEventMessage, "createRendererEventMessage");
|
|
737
|
+
function isRendererEventMessage(value) {
|
|
738
|
+
if (value === null || typeof value !== "object") {
|
|
739
|
+
return false;
|
|
740
|
+
}
|
|
741
|
+
const possibleMessage = value;
|
|
742
|
+
return possibleMessage.type === RENDERER_EVENT_TYPE && typeof possibleMessage.event === "string";
|
|
743
|
+
}
|
|
744
|
+
__name(isRendererEventMessage, "isRendererEventMessage");
|
|
723
745
|
|
|
724
746
|
// src/utils/radix-tree.ts
|
|
725
747
|
var _a;
|
|
@@ -1238,6 +1260,8 @@ Router = _ts_decorate([
|
|
|
1238
1260
|
|
|
1239
1261
|
// src/app.ts
|
|
1240
1262
|
var import_main = require("electron/main");
|
|
1263
|
+
|
|
1264
|
+
// src/socket.ts
|
|
1241
1265
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
1242
1266
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1243
1267
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -1245,16 +1269,98 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
1245
1269
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1246
1270
|
}
|
|
1247
1271
|
__name(_ts_decorate2, "_ts_decorate");
|
|
1272
|
+
var _NoxSocket = class _NoxSocket {
|
|
1273
|
+
constructor() {
|
|
1274
|
+
__publicField(this, "messagePorts", /* @__PURE__ */ new Map());
|
|
1275
|
+
}
|
|
1276
|
+
register(senderId, channel) {
|
|
1277
|
+
this.messagePorts.set(senderId, channel);
|
|
1278
|
+
}
|
|
1279
|
+
get(senderId) {
|
|
1280
|
+
return this.messagePorts.get(senderId);
|
|
1281
|
+
}
|
|
1282
|
+
unregister(senderId) {
|
|
1283
|
+
this.messagePorts.delete(senderId);
|
|
1284
|
+
}
|
|
1285
|
+
getSenderIds() {
|
|
1286
|
+
return [
|
|
1287
|
+
...this.messagePorts.keys()
|
|
1288
|
+
];
|
|
1289
|
+
}
|
|
1290
|
+
emit(eventName, payload, targetSenderIds) {
|
|
1291
|
+
const normalizedEvent = eventName.trim();
|
|
1292
|
+
if (normalizedEvent.length === 0) {
|
|
1293
|
+
throw new Error("Renderer event name must be a non-empty string.");
|
|
1294
|
+
}
|
|
1295
|
+
const recipients = targetSenderIds ?? this.getSenderIds();
|
|
1296
|
+
let delivered = 0;
|
|
1297
|
+
for (const senderId of recipients) {
|
|
1298
|
+
const channel = this.messagePorts.get(senderId);
|
|
1299
|
+
if (!channel) {
|
|
1300
|
+
Logger.warn(`No message channel found for sender ID: ${senderId} while emitting "${normalizedEvent}".`);
|
|
1301
|
+
continue;
|
|
1302
|
+
}
|
|
1303
|
+
try {
|
|
1304
|
+
channel.port1.postMessage(createRendererEventMessage(normalizedEvent, payload));
|
|
1305
|
+
delivered++;
|
|
1306
|
+
} catch (error) {
|
|
1307
|
+
Logger.error(`[Noxus] Failed to emit "${normalizedEvent}" to sender ${senderId}.`, error);
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
return delivered;
|
|
1311
|
+
}
|
|
1312
|
+
emitToRenderer(senderId, eventName, payload) {
|
|
1313
|
+
return this.emit(eventName, payload, [
|
|
1314
|
+
senderId
|
|
1315
|
+
]) > 0;
|
|
1316
|
+
}
|
|
1317
|
+
};
|
|
1318
|
+
__name(_NoxSocket, "NoxSocket");
|
|
1319
|
+
var NoxSocket = _NoxSocket;
|
|
1320
|
+
NoxSocket = _ts_decorate2([
|
|
1321
|
+
Injectable("singleton")
|
|
1322
|
+
], NoxSocket);
|
|
1323
|
+
|
|
1324
|
+
// src/app.ts
|
|
1325
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
1326
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1327
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1328
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1329
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1330
|
+
}
|
|
1331
|
+
__name(_ts_decorate3, "_ts_decorate");
|
|
1248
1332
|
function _ts_metadata(k, v) {
|
|
1249
1333
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1250
1334
|
}
|
|
1251
1335
|
__name(_ts_metadata, "_ts_metadata");
|
|
1252
1336
|
var _NoxApp = class _NoxApp {
|
|
1253
|
-
constructor(router) {
|
|
1337
|
+
constructor(router, socket) {
|
|
1254
1338
|
__publicField(this, "router");
|
|
1255
|
-
__publicField(this, "
|
|
1339
|
+
__publicField(this, "socket");
|
|
1256
1340
|
__publicField(this, "app");
|
|
1341
|
+
__publicField(this, "onRendererMessage", /* @__PURE__ */ __name(async (event) => {
|
|
1342
|
+
const { senderId, requestId, path, method, body } = event.data;
|
|
1343
|
+
const channel = this.socket.get(senderId);
|
|
1344
|
+
if (!channel) {
|
|
1345
|
+
Logger.error(`No message channel found for sender ID: ${senderId}`);
|
|
1346
|
+
return;
|
|
1347
|
+
}
|
|
1348
|
+
try {
|
|
1349
|
+
const request = new Request(event, requestId, method, path, body);
|
|
1350
|
+
const response = await this.router.handle(request);
|
|
1351
|
+
channel.port1.postMessage(response);
|
|
1352
|
+
} catch (err) {
|
|
1353
|
+
const response = {
|
|
1354
|
+
requestId,
|
|
1355
|
+
status: 500,
|
|
1356
|
+
body: null,
|
|
1357
|
+
error: err.message || "Internal Server Error"
|
|
1358
|
+
};
|
|
1359
|
+
channel.port1.postMessage(response);
|
|
1360
|
+
}
|
|
1361
|
+
}, "onRendererMessage"));
|
|
1257
1362
|
this.router = router;
|
|
1363
|
+
this.socket = socket;
|
|
1258
1364
|
}
|
|
1259
1365
|
/**
|
|
1260
1366
|
* Initializes the NoxApp instance.
|
|
@@ -1276,44 +1382,19 @@ var _NoxApp = class _NoxApp {
|
|
|
1276
1382
|
*/
|
|
1277
1383
|
giveTheRendererAPort(event) {
|
|
1278
1384
|
const senderId = event.sender.id;
|
|
1279
|
-
if (this.
|
|
1385
|
+
if (this.socket.get(senderId)) {
|
|
1280
1386
|
this.shutdownChannel(senderId);
|
|
1281
1387
|
}
|
|
1282
1388
|
const channel = new import_main.MessageChannelMain();
|
|
1283
|
-
|
|
1284
|
-
channel.port1.on("message", this.onRendererMessage.bind(this));
|
|
1389
|
+
channel.port1.on("message", this.onRendererMessage);
|
|
1285
1390
|
channel.port1.start();
|
|
1391
|
+
this.socket.register(senderId, channel);
|
|
1286
1392
|
event.sender.postMessage("port", {
|
|
1287
1393
|
senderId
|
|
1288
1394
|
}, [
|
|
1289
1395
|
channel.port2
|
|
1290
1396
|
]);
|
|
1291
1397
|
}
|
|
1292
|
-
/**
|
|
1293
|
-
* Electron specific message handling.
|
|
1294
|
-
* Replaces HTTP calls by using Electron's IPC mechanism.
|
|
1295
|
-
*/
|
|
1296
|
-
async onRendererMessage(event) {
|
|
1297
|
-
const { senderId, requestId, path, method, body } = event.data;
|
|
1298
|
-
const channel = this.messagePorts.get(senderId);
|
|
1299
|
-
if (!channel) {
|
|
1300
|
-
Logger.error(`No message channel found for sender ID: ${senderId}`);
|
|
1301
|
-
return;
|
|
1302
|
-
}
|
|
1303
|
-
try {
|
|
1304
|
-
const request = new Request(event, requestId, method, path, body);
|
|
1305
|
-
const response = await this.router.handle(request);
|
|
1306
|
-
channel.port1.postMessage(response);
|
|
1307
|
-
} catch (err) {
|
|
1308
|
-
const response = {
|
|
1309
|
-
requestId,
|
|
1310
|
-
status: 500,
|
|
1311
|
-
body: null,
|
|
1312
|
-
error: err.message || "Internal Server Error"
|
|
1313
|
-
};
|
|
1314
|
-
channel.port1.postMessage(response);
|
|
1315
|
-
}
|
|
1316
|
-
}
|
|
1317
1398
|
/**
|
|
1318
1399
|
* MacOS specific behavior.
|
|
1319
1400
|
*/
|
|
@@ -1330,25 +1411,24 @@ var _NoxApp = class _NoxApp {
|
|
|
1330
1411
|
* @param remove - Whether to remove the channel from the messagePorts map.
|
|
1331
1412
|
*/
|
|
1332
1413
|
shutdownChannel(channelSenderId) {
|
|
1333
|
-
const channel = this.
|
|
1414
|
+
const channel = this.socket.get(channelSenderId);
|
|
1334
1415
|
if (!channel) {
|
|
1335
1416
|
Logger.warn(`No message channel found for sender ID: ${channelSenderId}`);
|
|
1336
1417
|
return;
|
|
1337
1418
|
}
|
|
1338
|
-
channel.port1.off("message", this.onRendererMessage
|
|
1419
|
+
channel.port1.off("message", this.onRendererMessage);
|
|
1339
1420
|
channel.port1.close();
|
|
1340
1421
|
channel.port2.close();
|
|
1341
|
-
this.
|
|
1422
|
+
this.socket.unregister(channelSenderId);
|
|
1342
1423
|
}
|
|
1343
1424
|
/**
|
|
1344
1425
|
* Handles the application shutdown process.
|
|
1345
1426
|
* This method is called when all windows are closed, and it cleans up the message channels
|
|
1346
1427
|
*/
|
|
1347
1428
|
async onAllWindowsClosed() {
|
|
1348
|
-
this.
|
|
1429
|
+
for (const senderId of this.socket.getSenderIds()) {
|
|
1349
1430
|
this.shutdownChannel(senderId);
|
|
1350
|
-
}
|
|
1351
|
-
this.messagePorts.clear();
|
|
1431
|
+
}
|
|
1352
1432
|
Logger.info("All windows closed, shutting down application...");
|
|
1353
1433
|
await this.app?.dispose();
|
|
1354
1434
|
if (process.platform !== "darwin") {
|
|
@@ -1387,11 +1467,12 @@ var _NoxApp = class _NoxApp {
|
|
|
1387
1467
|
};
|
|
1388
1468
|
__name(_NoxApp, "NoxApp");
|
|
1389
1469
|
var NoxApp = _NoxApp;
|
|
1390
|
-
NoxApp =
|
|
1470
|
+
NoxApp = _ts_decorate3([
|
|
1391
1471
|
Injectable("singleton"),
|
|
1392
1472
|
_ts_metadata("design:type", Function),
|
|
1393
1473
|
_ts_metadata("design:paramtypes", [
|
|
1394
|
-
typeof Router === "undefined" ? Object : Router
|
|
1474
|
+
typeof Router === "undefined" ? Object : Router,
|
|
1475
|
+
typeof NoxSocket === "undefined" ? Object : NoxSocket
|
|
1395
1476
|
])
|
|
1396
1477
|
], NoxApp);
|
|
1397
1478
|
|
|
@@ -1407,6 +1488,86 @@ async function bootstrapApplication(rootModule) {
|
|
|
1407
1488
|
return noxApp;
|
|
1408
1489
|
}
|
|
1409
1490
|
__name(bootstrapApplication, "bootstrapApplication");
|
|
1491
|
+
|
|
1492
|
+
// src/renderer-events.ts
|
|
1493
|
+
var _RendererEventRegistry = class _RendererEventRegistry {
|
|
1494
|
+
constructor() {
|
|
1495
|
+
__publicField(this, "listeners", /* @__PURE__ */ new Map());
|
|
1496
|
+
}
|
|
1497
|
+
/**
|
|
1498
|
+
*
|
|
1499
|
+
*/
|
|
1500
|
+
subscribe(eventName, handler) {
|
|
1501
|
+
const normalizedEventName = eventName.trim();
|
|
1502
|
+
if (normalizedEventName.length === 0) {
|
|
1503
|
+
throw new Error("Renderer event name must be a non-empty string.");
|
|
1504
|
+
}
|
|
1505
|
+
const handlers = this.listeners.get(normalizedEventName) ?? /* @__PURE__ */ new Set();
|
|
1506
|
+
handlers.add(handler);
|
|
1507
|
+
this.listeners.set(normalizedEventName, handlers);
|
|
1508
|
+
return {
|
|
1509
|
+
unsubscribe: /* @__PURE__ */ __name(() => this.unsubscribe(normalizedEventName, handler), "unsubscribe")
|
|
1510
|
+
};
|
|
1511
|
+
}
|
|
1512
|
+
/**
|
|
1513
|
+
*
|
|
1514
|
+
*/
|
|
1515
|
+
unsubscribe(eventName, handler) {
|
|
1516
|
+
const handlers = this.listeners.get(eventName);
|
|
1517
|
+
if (!handlers) {
|
|
1518
|
+
return;
|
|
1519
|
+
}
|
|
1520
|
+
handlers.delete(handler);
|
|
1521
|
+
if (handlers.size === 0) {
|
|
1522
|
+
this.listeners.delete(eventName);
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
/**
|
|
1526
|
+
*
|
|
1527
|
+
*/
|
|
1528
|
+
clear(eventName) {
|
|
1529
|
+
if (eventName) {
|
|
1530
|
+
this.listeners.delete(eventName);
|
|
1531
|
+
return;
|
|
1532
|
+
}
|
|
1533
|
+
this.listeners.clear();
|
|
1534
|
+
}
|
|
1535
|
+
/**
|
|
1536
|
+
*
|
|
1537
|
+
*/
|
|
1538
|
+
dispatch(message) {
|
|
1539
|
+
const handlers = this.listeners.get(message.event);
|
|
1540
|
+
if (!handlers || handlers.size === 0) {
|
|
1541
|
+
return;
|
|
1542
|
+
}
|
|
1543
|
+
handlers.forEach((handler) => {
|
|
1544
|
+
try {
|
|
1545
|
+
handler(message.payload);
|
|
1546
|
+
} catch (error) {
|
|
1547
|
+
console.error(`[Noxus] Renderer event handler for "${message.event}" threw an error.`, error);
|
|
1548
|
+
}
|
|
1549
|
+
});
|
|
1550
|
+
}
|
|
1551
|
+
/**
|
|
1552
|
+
*
|
|
1553
|
+
*/
|
|
1554
|
+
tryDispatchFromMessageEvent(event) {
|
|
1555
|
+
if (!isRendererEventMessage(event.data)) {
|
|
1556
|
+
return false;
|
|
1557
|
+
}
|
|
1558
|
+
this.dispatch(event.data);
|
|
1559
|
+
return true;
|
|
1560
|
+
}
|
|
1561
|
+
/**
|
|
1562
|
+
*
|
|
1563
|
+
*/
|
|
1564
|
+
hasHandlers(eventName) {
|
|
1565
|
+
const handlers = this.listeners.get(eventName);
|
|
1566
|
+
return !!handlers && handlers.size > 0;
|
|
1567
|
+
}
|
|
1568
|
+
};
|
|
1569
|
+
__name(_RendererEventRegistry, "RendererEventRegistry");
|
|
1570
|
+
var RendererEventRegistry = _RendererEventRegistry;
|
|
1410
1571
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1411
1572
|
0 && (module.exports = {
|
|
1412
1573
|
AppInjector,
|
|
@@ -1437,11 +1598,14 @@ __name(bootstrapApplication, "bootstrapApplication");
|
|
|
1437
1598
|
NotFoundException,
|
|
1438
1599
|
NotImplementedException,
|
|
1439
1600
|
NoxApp,
|
|
1601
|
+
NoxSocket,
|
|
1440
1602
|
Patch,
|
|
1441
1603
|
PaymentRequiredException,
|
|
1442
1604
|
Post,
|
|
1443
1605
|
Put,
|
|
1606
|
+
RENDERER_EVENT_TYPE,
|
|
1444
1607
|
ROUTE_METADATA_KEY,
|
|
1608
|
+
RendererEventRegistry,
|
|
1445
1609
|
Request,
|
|
1446
1610
|
RequestTimeoutException,
|
|
1447
1611
|
ResponseException,
|
|
@@ -1454,6 +1618,7 @@ __name(bootstrapApplication, "bootstrapApplication");
|
|
|
1454
1618
|
UseMiddlewares,
|
|
1455
1619
|
VariantAlsoNegotiatesException,
|
|
1456
1620
|
bootstrapApplication,
|
|
1621
|
+
createRendererEventMessage,
|
|
1457
1622
|
getControllerMetadata,
|
|
1458
1623
|
getGuardForController,
|
|
1459
1624
|
getGuardForControllerAction,
|
|
@@ -1462,11 +1627,12 @@ __name(bootstrapApplication, "bootstrapApplication");
|
|
|
1462
1627
|
getMiddlewaresForControllerAction,
|
|
1463
1628
|
getModuleMetadata,
|
|
1464
1629
|
getRouteMetadata,
|
|
1465
|
-
inject
|
|
1630
|
+
inject,
|
|
1631
|
+
isRendererEventMessage
|
|
1466
1632
|
});
|
|
1467
1633
|
/**
|
|
1468
1634
|
* @copyright 2025 NoxFly
|
|
1469
1635
|
* @license MIT
|
|
1470
1636
|
* @author NoxFly
|
|
1471
1637
|
*/
|
|
1472
|
-
//# sourceMappingURL=
|
|
1638
|
+
//# sourceMappingURL=main.js.map
|