@noxfly/noxus 2.0.0 → 2.1.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/dist/main.d.mts +28 -2
- package/dist/main.d.ts +28 -2
- package/dist/main.js +246 -70
- package/dist/main.mjs +236 -70
- package/package.json +2 -2
- package/src/main.ts +3 -0
- package/src/router.ts +44 -10
- package/src/utils/logger.ts +266 -87
package/dist/main.mjs
CHANGED
|
@@ -332,12 +332,12 @@ __name(hasInjectableMetadata, "hasInjectableMetadata");
|
|
|
332
332
|
|
|
333
333
|
// src/decorators/method.decorator.ts
|
|
334
334
|
function createRouteDecorator(verb) {
|
|
335
|
-
return (
|
|
335
|
+
return (path2) => {
|
|
336
336
|
return (target, propertyKey) => {
|
|
337
337
|
const existingRoutes = Reflect.getMetadata(ROUTE_METADATA_KEY, target.constructor) || [];
|
|
338
338
|
const metadata = {
|
|
339
339
|
method: verb,
|
|
340
|
-
path:
|
|
340
|
+
path: path2.trim().replace(/^\/|\/$/g, ""),
|
|
341
341
|
handler: propertyKey,
|
|
342
342
|
guards: getGuardForControllerAction(target.constructor.__controllerName, propertyKey)
|
|
343
343
|
};
|
|
@@ -401,6 +401,8 @@ __name(getModuleMetadata, "getModuleMetadata");
|
|
|
401
401
|
var MODULE_METADATA_KEY = Symbol("MODULE_METADATA_KEY");
|
|
402
402
|
|
|
403
403
|
// src/utils/logger.ts
|
|
404
|
+
import * as fs from "fs";
|
|
405
|
+
import * as path from "path";
|
|
404
406
|
function getPrettyTimestamp() {
|
|
405
407
|
const now = /* @__PURE__ */ new Date();
|
|
406
408
|
return `${now.getDate().toString().padStart(2, "0")}/${(now.getMonth() + 1).toString().padStart(2, "0")}/${now.getFullYear()} ${now.getHours().toString().padStart(2, "0")}:${now.getMinutes().toString().padStart(2, "0")}:${now.getSeconds().toString().padStart(2, "0")}`;
|
|
@@ -409,21 +411,41 @@ __name(getPrettyTimestamp, "getPrettyTimestamp");
|
|
|
409
411
|
function getLogPrefix(callee, messageType, color) {
|
|
410
412
|
const timestamp = getPrettyTimestamp();
|
|
411
413
|
const spaces = " ".repeat(10 - messageType.length);
|
|
412
|
-
|
|
414
|
+
let colReset = Logger.colors.initial;
|
|
415
|
+
let colCallee = Logger.colors.yellow;
|
|
416
|
+
if (color === void 0) {
|
|
417
|
+
color = "";
|
|
418
|
+
colReset = "";
|
|
419
|
+
colCallee = "";
|
|
420
|
+
}
|
|
421
|
+
return `${color}[APP] ${process.pid} - ${colReset}${timestamp}${spaces}${color}${messageType.toUpperCase()}${colReset} ${colCallee}[${callee}]${colReset}`;
|
|
413
422
|
}
|
|
414
423
|
__name(getLogPrefix, "getLogPrefix");
|
|
415
|
-
function formatObject(prefix, arg) {
|
|
424
|
+
function formatObject(prefix, arg, enableColor = true) {
|
|
416
425
|
const json = JSON.stringify(arg, null, 2);
|
|
417
|
-
|
|
426
|
+
let colStart = "";
|
|
427
|
+
let colLine = "";
|
|
428
|
+
let colReset = "";
|
|
429
|
+
if (enableColor) {
|
|
430
|
+
colStart = Logger.colors.darkGrey;
|
|
431
|
+
colLine = Logger.colors.grey;
|
|
432
|
+
colReset = Logger.colors.initial;
|
|
433
|
+
}
|
|
434
|
+
const prefixedJson = json.split("\n").map((line, idx) => idx === 0 ? `${colStart}${line}` : `${prefix} ${colLine}${line}`).join("\n") + colReset;
|
|
418
435
|
return prefixedJson;
|
|
419
436
|
}
|
|
420
437
|
__name(formatObject, "formatObject");
|
|
421
438
|
function formattedArgs(prefix, args, color) {
|
|
439
|
+
let colReset = Logger.colors.initial;
|
|
440
|
+
if (color === void 0) {
|
|
441
|
+
color = "";
|
|
442
|
+
colReset = "";
|
|
443
|
+
}
|
|
422
444
|
return args.map((arg) => {
|
|
423
445
|
if (typeof arg === "string") {
|
|
424
|
-
return `${color}${arg}${
|
|
446
|
+
return `${color}${arg}${colReset}`;
|
|
425
447
|
} else if (typeof arg === "object") {
|
|
426
|
-
return formatObject(prefix, arg);
|
|
448
|
+
return formatObject(prefix, arg, color === "");
|
|
427
449
|
}
|
|
428
450
|
return arg;
|
|
429
451
|
});
|
|
@@ -436,80 +458,163 @@ function getCallee() {
|
|
|
436
458
|
}
|
|
437
459
|
__name(getCallee, "getCallee");
|
|
438
460
|
function canLog(level) {
|
|
439
|
-
return
|
|
461
|
+
return logLevels.has(level);
|
|
440
462
|
}
|
|
441
463
|
__name(canLog, "canLog");
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
464
|
+
function processLogQueue(filepath) {
|
|
465
|
+
const state = fileStates.get(filepath);
|
|
466
|
+
if (!state || state.isWriting || state.queue.length === 0) {
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
state.isWriting = true;
|
|
470
|
+
const messagesToWrite = state.queue.join("\n") + "\n";
|
|
471
|
+
state.queue = [];
|
|
472
|
+
const dir = path.dirname(filepath);
|
|
473
|
+
fs.mkdir(dir, {
|
|
474
|
+
recursive: true
|
|
475
|
+
}, (err) => {
|
|
476
|
+
if (err) {
|
|
477
|
+
console.error(`[Logger] Failed to create directory ${dir}`, err);
|
|
478
|
+
state.isWriting = false;
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
fs.appendFile(filepath, messagesToWrite, {
|
|
482
|
+
encoding: "utf-8"
|
|
483
|
+
}, (err2) => {
|
|
484
|
+
state.isWriting = false;
|
|
485
|
+
if (err2) {
|
|
486
|
+
console.error(`[Logger] Failed to write log to ${filepath}`, err2);
|
|
487
|
+
}
|
|
488
|
+
if (state.queue.length > 0) {
|
|
489
|
+
processLogQueue(filepath);
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
__name(processLogQueue, "processLogQueue");
|
|
495
|
+
function enqueue(filepath, message) {
|
|
496
|
+
if (!fileStates.has(filepath)) {
|
|
497
|
+
fileStates.set(filepath, {
|
|
498
|
+
queue: [],
|
|
499
|
+
isWriting: false
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
const state = fileStates.get(filepath);
|
|
503
|
+
state.queue.push(message);
|
|
504
|
+
processLogQueue(filepath);
|
|
505
|
+
}
|
|
506
|
+
__name(enqueue, "enqueue");
|
|
507
|
+
function output(level, args) {
|
|
508
|
+
if (!canLog(level)) {
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
const callee = getCallee();
|
|
512
|
+
{
|
|
513
|
+
const prefix = getLogPrefix(callee, level, logLevelColors[level]);
|
|
514
|
+
const data = formattedArgs(prefix, args, logLevelColors[level]);
|
|
515
|
+
logLevelChannel[level](prefix, ...data);
|
|
516
|
+
}
|
|
517
|
+
{
|
|
518
|
+
const prefix = getLogPrefix(callee, level);
|
|
519
|
+
const data = formattedArgs(prefix, args);
|
|
520
|
+
const filepath = fileSettings.get(level)?.filepath;
|
|
521
|
+
if (filepath) {
|
|
522
|
+
const message = prefix + " " + data.join(" ");
|
|
523
|
+
enqueue(filepath, message);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
__name(output, "output");
|
|
451
528
|
(function(Logger2) {
|
|
452
529
|
function setLogLevel(level) {
|
|
453
|
-
|
|
530
|
+
logLevels.clear();
|
|
531
|
+
if (Array.isArray(level)) {
|
|
532
|
+
for (const lvl of level) {
|
|
533
|
+
logLevels.add(lvl);
|
|
534
|
+
}
|
|
535
|
+
} else {
|
|
536
|
+
const targetRank = logLevelRank[level];
|
|
537
|
+
for (const [lvl, rank] of Object.entries(logLevelRank)) {
|
|
538
|
+
if (rank >= targetRank) {
|
|
539
|
+
logLevels.add(lvl);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
}
|
|
454
543
|
}
|
|
455
544
|
__name(setLogLevel, "setLogLevel");
|
|
456
545
|
Logger2.setLogLevel = setLogLevel;
|
|
457
546
|
function log(...args) {
|
|
458
|
-
|
|
459
|
-
const callee = getCallee();
|
|
460
|
-
const prefix = getLogPrefix(callee, "log", Logger2.colors.green);
|
|
461
|
-
console.log(prefix, ...formattedArgs(prefix, args, Logger2.colors.green));
|
|
547
|
+
output("log", args);
|
|
462
548
|
}
|
|
463
549
|
__name(log, "log");
|
|
464
550
|
Logger2.log = log;
|
|
465
551
|
function info(...args) {
|
|
466
|
-
|
|
467
|
-
const callee = getCallee();
|
|
468
|
-
const prefix = getLogPrefix(callee, "info", Logger2.colors.blue);
|
|
469
|
-
console.info(prefix, ...formattedArgs(prefix, args, Logger2.colors.blue));
|
|
552
|
+
output("info", args);
|
|
470
553
|
}
|
|
471
554
|
__name(info, "info");
|
|
472
555
|
Logger2.info = info;
|
|
473
556
|
function warn(...args) {
|
|
474
|
-
|
|
475
|
-
const callee = getCallee();
|
|
476
|
-
const prefix = getLogPrefix(callee, "warn", Logger2.colors.brown);
|
|
477
|
-
console.warn(prefix, ...formattedArgs(prefix, args, Logger2.colors.brown));
|
|
557
|
+
output("warn", args);
|
|
478
558
|
}
|
|
479
559
|
__name(warn, "warn");
|
|
480
560
|
Logger2.warn = warn;
|
|
481
561
|
function error(...args) {
|
|
482
|
-
|
|
483
|
-
const callee = getCallee();
|
|
484
|
-
const prefix = getLogPrefix(callee, "error", Logger2.colors.red);
|
|
485
|
-
console.error(prefix, ...formattedArgs(prefix, args, Logger2.colors.red));
|
|
562
|
+
output("error", args);
|
|
486
563
|
}
|
|
487
564
|
__name(error, "error");
|
|
488
565
|
Logger2.error = error;
|
|
489
566
|
function errorStack(...args) {
|
|
490
|
-
|
|
491
|
-
const callee = getCallee();
|
|
492
|
-
const prefix = getLogPrefix(callee, "error", Logger2.colors.grey);
|
|
493
|
-
console.error(prefix, ...formattedArgs(prefix, args, Logger2.colors.grey));
|
|
567
|
+
output("error", args);
|
|
494
568
|
}
|
|
495
569
|
__name(errorStack, "errorStack");
|
|
496
570
|
Logger2.errorStack = errorStack;
|
|
497
571
|
function debug(...args) {
|
|
498
|
-
|
|
499
|
-
const callee = getCallee();
|
|
500
|
-
const prefix = getLogPrefix(callee, "debug", Logger2.colors.purple);
|
|
501
|
-
console.debug(prefix, ...formattedArgs(prefix, args, Logger2.colors.purple));
|
|
572
|
+
output("debug", args);
|
|
502
573
|
}
|
|
503
574
|
__name(debug, "debug");
|
|
504
575
|
Logger2.debug = debug;
|
|
505
576
|
function comment(...args) {
|
|
506
|
-
|
|
507
|
-
const callee = getCallee();
|
|
508
|
-
const prefix = getLogPrefix(callee, "comment", Logger2.colors.grey);
|
|
509
|
-
console.debug(prefix, ...formattedArgs(prefix, args, Logger2.colors.grey));
|
|
577
|
+
output("comment", args);
|
|
510
578
|
}
|
|
511
579
|
__name(comment, "comment");
|
|
512
580
|
Logger2.comment = comment;
|
|
581
|
+
function critical(...args) {
|
|
582
|
+
output("critical", args);
|
|
583
|
+
}
|
|
584
|
+
__name(critical, "critical");
|
|
585
|
+
Logger2.critical = critical;
|
|
586
|
+
function enableFileLogging(filepath, levels = [
|
|
587
|
+
"debug",
|
|
588
|
+
"comment",
|
|
589
|
+
"log",
|
|
590
|
+
"info",
|
|
591
|
+
"warn",
|
|
592
|
+
"error",
|
|
593
|
+
"critical"
|
|
594
|
+
]) {
|
|
595
|
+
for (const level of levels) {
|
|
596
|
+
fileSettings.set(level, {
|
|
597
|
+
filepath
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
__name(enableFileLogging, "enableFileLogging");
|
|
602
|
+
Logger2.enableFileLogging = enableFileLogging;
|
|
603
|
+
function disableFileLogging(levels = [
|
|
604
|
+
"debug",
|
|
605
|
+
"comment",
|
|
606
|
+
"log",
|
|
607
|
+
"info",
|
|
608
|
+
"warn",
|
|
609
|
+
"error",
|
|
610
|
+
"critical"
|
|
611
|
+
]) {
|
|
612
|
+
for (const level of levels) {
|
|
613
|
+
fileSettings.delete(level);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
__name(disableFileLogging, "disableFileLogging");
|
|
617
|
+
Logger2.disableFileLogging = disableFileLogging;
|
|
513
618
|
Logger2.colors = {
|
|
514
619
|
black: "\x1B[0;30m",
|
|
515
620
|
grey: "\x1B[0;37m",
|
|
@@ -529,6 +634,37 @@ var logLevelRank = {
|
|
|
529
634
|
initial: "\x1B[0m"
|
|
530
635
|
};
|
|
531
636
|
})(Logger || (Logger = {}));
|
|
637
|
+
var fileSettings = /* @__PURE__ */ new Map();
|
|
638
|
+
var fileStates = /* @__PURE__ */ new Map();
|
|
639
|
+
var logLevels = /* @__PURE__ */ new Set();
|
|
640
|
+
var logLevelRank = {
|
|
641
|
+
debug: 0,
|
|
642
|
+
comment: 1,
|
|
643
|
+
log: 2,
|
|
644
|
+
info: 3,
|
|
645
|
+
warn: 4,
|
|
646
|
+
error: 5,
|
|
647
|
+
critical: 6
|
|
648
|
+
};
|
|
649
|
+
var logLevelColors = {
|
|
650
|
+
debug: Logger.colors.purple,
|
|
651
|
+
comment: Logger.colors.grey,
|
|
652
|
+
log: Logger.colors.green,
|
|
653
|
+
info: Logger.colors.blue,
|
|
654
|
+
warn: Logger.colors.brown,
|
|
655
|
+
error: Logger.colors.red,
|
|
656
|
+
critical: Logger.colors.lightRed
|
|
657
|
+
};
|
|
658
|
+
var logLevelChannel = {
|
|
659
|
+
debug: console.debug,
|
|
660
|
+
comment: console.debug,
|
|
661
|
+
log: console.log,
|
|
662
|
+
info: console.info,
|
|
663
|
+
warn: console.warn,
|
|
664
|
+
error: console.error,
|
|
665
|
+
critical: console.error
|
|
666
|
+
};
|
|
667
|
+
Logger.setLogLevel("debug");
|
|
532
668
|
var Logger;
|
|
533
669
|
|
|
534
670
|
// src/DI/injector-explorer.ts
|
|
@@ -584,10 +720,10 @@ function Injectable(lifetime = "scope") {
|
|
|
584
720
|
__name(Injectable, "Injectable");
|
|
585
721
|
|
|
586
722
|
// src/decorators/controller.decorator.ts
|
|
587
|
-
function Controller(
|
|
723
|
+
function Controller(path2) {
|
|
588
724
|
return (target) => {
|
|
589
725
|
const data = {
|
|
590
|
-
path,
|
|
726
|
+
path: path2,
|
|
591
727
|
guards: getGuardForController(target.name)
|
|
592
728
|
};
|
|
593
729
|
Reflect.defineMetadata(CONTROLLER_METADATA_KEY, data, target);
|
|
@@ -635,7 +771,7 @@ var middlewares = /* @__PURE__ */ new Map();
|
|
|
635
771
|
// src/request.ts
|
|
636
772
|
import "reflect-metadata";
|
|
637
773
|
var _Request = class _Request {
|
|
638
|
-
constructor(event, senderId, id, method,
|
|
774
|
+
constructor(event, senderId, id, method, path2, body) {
|
|
639
775
|
__publicField(this, "event");
|
|
640
776
|
__publicField(this, "senderId");
|
|
641
777
|
__publicField(this, "id");
|
|
@@ -648,9 +784,9 @@ var _Request = class _Request {
|
|
|
648
784
|
this.senderId = senderId;
|
|
649
785
|
this.id = id;
|
|
650
786
|
this.method = method;
|
|
651
|
-
this.path =
|
|
787
|
+
this.path = path2;
|
|
652
788
|
this.body = body;
|
|
653
|
-
this.path =
|
|
789
|
+
this.path = path2.replace(/^\/|\/$/g, "");
|
|
654
790
|
}
|
|
655
791
|
};
|
|
656
792
|
__name(_Request, "Request");
|
|
@@ -732,8 +868,8 @@ var _RadixTree = class _RadixTree {
|
|
|
732
868
|
* @param path - The path to insert into the tree.
|
|
733
869
|
* @param value - The value to associate with the path.
|
|
734
870
|
*/
|
|
735
|
-
insert(
|
|
736
|
-
const segments = this.normalize(
|
|
871
|
+
insert(path2, value) {
|
|
872
|
+
const segments = this.normalize(path2);
|
|
737
873
|
this.insertRecursive(this.root, segments, value);
|
|
738
874
|
}
|
|
739
875
|
/**
|
|
@@ -762,8 +898,8 @@ var _RadixTree = class _RadixTree {
|
|
|
762
898
|
* @param path - The path to search for in the Radix Tree.
|
|
763
899
|
* @returns An ISearchResult containing the node and parameters if a match is found, otherwise undefined.
|
|
764
900
|
*/
|
|
765
|
-
search(
|
|
766
|
-
const segments = this.normalize(
|
|
901
|
+
search(path2) {
|
|
902
|
+
const segments = this.normalize(path2);
|
|
767
903
|
return this.searchRecursive(this.root, segments, {});
|
|
768
904
|
}
|
|
769
905
|
/**
|
|
@@ -819,8 +955,8 @@ var _RadixTree = class _RadixTree {
|
|
|
819
955
|
* @param path - The path to normalize.
|
|
820
956
|
* @returns An array of normalized path segments.
|
|
821
957
|
*/
|
|
822
|
-
normalize(
|
|
823
|
-
const segments =
|
|
958
|
+
normalize(path2) {
|
|
959
|
+
const segments = path2.replace(/^\/+|\/+$/g, "").split("/").filter(Boolean);
|
|
824
960
|
return [
|
|
825
961
|
"",
|
|
826
962
|
...segments
|
|
@@ -930,6 +1066,7 @@ var _Router = class _Router {
|
|
|
930
1066
|
status: 200,
|
|
931
1067
|
body: null
|
|
932
1068
|
};
|
|
1069
|
+
let isCritical = false;
|
|
933
1070
|
try {
|
|
934
1071
|
const routeDef = this.findRoute(request);
|
|
935
1072
|
await this.resolveController(request, response, routeDef);
|
|
@@ -943,10 +1080,12 @@ var _Router = class _Router {
|
|
|
943
1080
|
response.error = error.message;
|
|
944
1081
|
response.stack = error.stack;
|
|
945
1082
|
} else if (error instanceof Error) {
|
|
1083
|
+
isCritical = true;
|
|
946
1084
|
response.status = 500;
|
|
947
1085
|
response.error = error.message || "Internal Server Error";
|
|
948
1086
|
response.stack = error.stack || "No stack trace available";
|
|
949
1087
|
} else {
|
|
1088
|
+
isCritical = true;
|
|
950
1089
|
response.status = 500;
|
|
951
1090
|
response.error = "Unknown error occurred";
|
|
952
1091
|
response.stack = "No stack trace available";
|
|
@@ -954,11 +1093,23 @@ var _Router = class _Router {
|
|
|
954
1093
|
} finally {
|
|
955
1094
|
const t1 = performance.now();
|
|
956
1095
|
const message = `< ${response.status} ${request.method} /${request.path} ${Logger.colors.yellow}${Math.round(t1 - t0)}ms${Logger.colors.initial}`;
|
|
957
|
-
if (response.status < 400)
|
|
958
|
-
|
|
959
|
-
else
|
|
1096
|
+
if (response.status < 400) {
|
|
1097
|
+
Logger.log(message);
|
|
1098
|
+
} else if (response.status < 500) {
|
|
1099
|
+
Logger.warn(message);
|
|
1100
|
+
} else {
|
|
1101
|
+
if (isCritical) {
|
|
1102
|
+
Logger.critical(message);
|
|
1103
|
+
} else {
|
|
1104
|
+
Logger.error(message);
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
960
1107
|
if (response.error !== void 0) {
|
|
961
|
-
|
|
1108
|
+
if (isCritical) {
|
|
1109
|
+
Logger.critical(response.error);
|
|
1110
|
+
} else {
|
|
1111
|
+
Logger.error(response.error);
|
|
1112
|
+
}
|
|
962
1113
|
if (response.stack !== void 0) {
|
|
963
1114
|
Logger.errorStack(response.stack);
|
|
964
1115
|
}
|
|
@@ -976,6 +1127,7 @@ var _Router = class _Router {
|
|
|
976
1127
|
responses: []
|
|
977
1128
|
}
|
|
978
1129
|
};
|
|
1130
|
+
let isCritical = false;
|
|
979
1131
|
try {
|
|
980
1132
|
const payload = this.normalizeBatchPayload(request.body);
|
|
981
1133
|
const batchResponses = [];
|
|
@@ -992,10 +1144,12 @@ var _Router = class _Router {
|
|
|
992
1144
|
response.error = error.message;
|
|
993
1145
|
response.stack = error.stack;
|
|
994
1146
|
} else if (error instanceof Error) {
|
|
1147
|
+
isCritical = true;
|
|
995
1148
|
response.status = 500;
|
|
996
1149
|
response.error = error.message || "Internal Server Error";
|
|
997
1150
|
response.stack = error.stack || "No stack trace available";
|
|
998
1151
|
} else {
|
|
1152
|
+
isCritical = true;
|
|
999
1153
|
response.status = 500;
|
|
1000
1154
|
response.error = "Unknown error occurred";
|
|
1001
1155
|
response.stack = "No stack trace available";
|
|
@@ -1003,11 +1157,23 @@ var _Router = class _Router {
|
|
|
1003
1157
|
} finally {
|
|
1004
1158
|
const t1 = performance.now();
|
|
1005
1159
|
const message = `< ${response.status} ${request.method} /${request.path} ${Logger.colors.yellow}${Math.round(t1 - t0)}ms${Logger.colors.initial}`;
|
|
1006
|
-
if (response.status < 400)
|
|
1007
|
-
|
|
1008
|
-
else
|
|
1160
|
+
if (response.status < 400) {
|
|
1161
|
+
Logger.log(message);
|
|
1162
|
+
} else if (response.status < 500) {
|
|
1163
|
+
Logger.warn(message);
|
|
1164
|
+
} else {
|
|
1165
|
+
if (isCritical) {
|
|
1166
|
+
Logger.critical(message);
|
|
1167
|
+
} else {
|
|
1168
|
+
Logger.error(message);
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1009
1171
|
if (response.error !== void 0) {
|
|
1010
|
-
|
|
1172
|
+
if (isCritical) {
|
|
1173
|
+
Logger.critical(response.error);
|
|
1174
|
+
} else {
|
|
1175
|
+
Logger.error(response.error);
|
|
1176
|
+
}
|
|
1011
1177
|
if (response.stack !== void 0) {
|
|
1012
1178
|
Logger.errorStack(response.stack);
|
|
1013
1179
|
}
|
|
@@ -1033,11 +1199,11 @@ var _Router = class _Router {
|
|
|
1033
1199
|
if (entry === null || typeof entry !== "object") {
|
|
1034
1200
|
throw new BadRequestException(`Batch request at index ${index} must be an object.`);
|
|
1035
1201
|
}
|
|
1036
|
-
const { requestId, path, method, body } = entry;
|
|
1202
|
+
const { requestId, path: path2, method, body } = entry;
|
|
1037
1203
|
if (requestId !== void 0 && typeof requestId !== "string") {
|
|
1038
1204
|
throw new BadRequestException(`Batch request at index ${index} has an invalid requestId.`);
|
|
1039
1205
|
}
|
|
1040
|
-
if (typeof
|
|
1206
|
+
if (typeof path2 !== "string" || path2.length === 0) {
|
|
1041
1207
|
throw new BadRequestException(`Batch request at index ${index} must define a non-empty path.`);
|
|
1042
1208
|
}
|
|
1043
1209
|
if (typeof method !== "string") {
|
|
@@ -1049,7 +1215,7 @@ var _Router = class _Router {
|
|
|
1049
1215
|
}
|
|
1050
1216
|
return {
|
|
1051
1217
|
requestId,
|
|
1052
|
-
path,
|
|
1218
|
+
path: path2,
|
|
1053
1219
|
method: normalizedMethod,
|
|
1054
1220
|
body
|
|
1055
1221
|
};
|
|
@@ -1275,14 +1441,14 @@ var _NoxApp = class _NoxApp {
|
|
|
1275
1441
|
*
|
|
1276
1442
|
*/
|
|
1277
1443
|
__publicField(this, "onRendererMessage", /* @__PURE__ */ __name(async (event) => {
|
|
1278
|
-
const { senderId, requestId, path, method, body } = event.data;
|
|
1444
|
+
const { senderId, requestId, path: path2, method, body } = event.data;
|
|
1279
1445
|
const channels = this.socket.get(senderId);
|
|
1280
1446
|
if (!channels) {
|
|
1281
1447
|
Logger.error(`No message channel found for sender ID: ${senderId}`);
|
|
1282
1448
|
return;
|
|
1283
1449
|
}
|
|
1284
1450
|
try {
|
|
1285
|
-
const request = new Request(event, senderId, requestId, method,
|
|
1451
|
+
const request = new Request(event, senderId, requestId, method, path2, body);
|
|
1286
1452
|
const response = await this.router.handle(request);
|
|
1287
1453
|
channels.request.port1.postMessage(response);
|
|
1288
1454
|
} catch (err) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noxfly/noxus",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"main": "dist/main.js",
|
|
5
5
|
"module": "dist/main.mjs",
|
|
6
6
|
"types": "dist/main.d.ts",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"homepage": "https://github.com/NoxFly/noxus",
|
|
50
50
|
"repository": {
|
|
51
51
|
"type": "git",
|
|
52
|
-
"url": "https://github.com/NoxFly/noxus.git"
|
|
52
|
+
"url": "git+https://github.com/NoxFly/noxus.git"
|
|
53
53
|
},
|
|
54
54
|
"engines": {
|
|
55
55
|
"node": ">= 20"
|
package/src/main.ts
CHANGED
|
@@ -6,7 +6,10 @@
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Entry point for Electron main-process consumers.
|
|
9
|
+
* order of exports here matters and can affect module resolution.
|
|
10
|
+
* Please be cautious when modifying.
|
|
9
11
|
*/
|
|
12
|
+
|
|
10
13
|
export * from './DI/app-injector';
|
|
11
14
|
export * from './router';
|
|
12
15
|
export * from './app';
|
package/src/router.ts
CHANGED
|
@@ -145,6 +145,8 @@ export class Router {
|
|
|
145
145
|
body: null,
|
|
146
146
|
};
|
|
147
147
|
|
|
148
|
+
let isCritical: boolean = false;
|
|
149
|
+
|
|
148
150
|
try {
|
|
149
151
|
const routeDef = this.findRoute(request);
|
|
150
152
|
await this.resolveController(request, response, routeDef);
|
|
@@ -162,11 +164,13 @@ export class Router {
|
|
|
162
164
|
response.stack = error.stack;
|
|
163
165
|
}
|
|
164
166
|
else if(error instanceof Error) {
|
|
167
|
+
isCritical = true;
|
|
165
168
|
response.status = 500;
|
|
166
169
|
response.error = error.message || 'Internal Server Error';
|
|
167
170
|
response.stack = error.stack || 'No stack trace available';
|
|
168
171
|
}
|
|
169
172
|
else {
|
|
173
|
+
isCritical = true;
|
|
170
174
|
response.status = 500;
|
|
171
175
|
response.error = 'Unknown error occurred';
|
|
172
176
|
response.stack = 'No stack trace available';
|
|
@@ -177,15 +181,28 @@ export class Router {
|
|
|
177
181
|
|
|
178
182
|
const message = `< ${response.status} ${request.method} /${request.path} ${Logger.colors.yellow}${Math.round(t1 - t0)}ms${Logger.colors.initial}`;
|
|
179
183
|
|
|
180
|
-
if(response.status < 400)
|
|
184
|
+
if(response.status < 400) {
|
|
181
185
|
Logger.log(message);
|
|
182
|
-
|
|
186
|
+
}
|
|
187
|
+
else if(response.status < 500) {
|
|
183
188
|
Logger.warn(message);
|
|
184
|
-
|
|
185
|
-
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
if(isCritical) {
|
|
192
|
+
Logger.critical(message);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
Logger.error(message);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
186
198
|
|
|
187
199
|
if(response.error !== undefined) {
|
|
188
|
-
|
|
200
|
+
if(isCritical) {
|
|
201
|
+
Logger.critical(response.error);
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
Logger.error(response.error);
|
|
205
|
+
}
|
|
189
206
|
|
|
190
207
|
if(response.stack !== undefined) {
|
|
191
208
|
Logger.errorStack(response.stack);
|
|
@@ -207,6 +224,8 @@ export class Router {
|
|
|
207
224
|
body: { responses: [] },
|
|
208
225
|
};
|
|
209
226
|
|
|
227
|
+
let isCritical: boolean = false;
|
|
228
|
+
|
|
210
229
|
try {
|
|
211
230
|
const payload = this.normalizeBatchPayload(request.body);
|
|
212
231
|
const batchResponses: IResponse[] = [];
|
|
@@ -228,11 +247,13 @@ export class Router {
|
|
|
228
247
|
response.stack = error.stack;
|
|
229
248
|
}
|
|
230
249
|
else if(error instanceof Error) {
|
|
250
|
+
isCritical = true;
|
|
231
251
|
response.status = 500;
|
|
232
252
|
response.error = error.message || 'Internal Server Error';
|
|
233
253
|
response.stack = error.stack || 'No stack trace available';
|
|
234
254
|
}
|
|
235
255
|
else {
|
|
256
|
+
isCritical = true;
|
|
236
257
|
response.status = 500;
|
|
237
258
|
response.error = 'Unknown error occurred';
|
|
238
259
|
response.stack = 'No stack trace available';
|
|
@@ -243,15 +264,28 @@ export class Router {
|
|
|
243
264
|
|
|
244
265
|
const message = `< ${response.status} ${request.method} /${request.path} ${Logger.colors.yellow}${Math.round(t1 - t0)}ms${Logger.colors.initial}`;
|
|
245
266
|
|
|
246
|
-
if(response.status < 400)
|
|
267
|
+
if(response.status < 400) {
|
|
247
268
|
Logger.log(message);
|
|
248
|
-
|
|
269
|
+
}
|
|
270
|
+
else if(response.status < 500) {
|
|
249
271
|
Logger.warn(message);
|
|
250
|
-
|
|
251
|
-
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
if(isCritical) {
|
|
275
|
+
Logger.critical(message);
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
Logger.error(message);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
252
281
|
|
|
253
282
|
if(response.error !== undefined) {
|
|
254
|
-
|
|
283
|
+
if(isCritical) {
|
|
284
|
+
Logger.critical(response.error);
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
Logger.error(response.error);
|
|
288
|
+
}
|
|
255
289
|
|
|
256
290
|
if(response.stack !== undefined) {
|
|
257
291
|
Logger.errorStack(response.stack);
|