@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.d.mts
CHANGED
|
@@ -410,15 +410,20 @@ declare function exposeNoxusBridge(options?: NoxusPreloadOptions): NoxusPreloadA
|
|
|
410
410
|
/**
|
|
411
411
|
* Logger is a utility class for logging messages to the console.
|
|
412
412
|
*/
|
|
413
|
-
type LogLevel = '
|
|
413
|
+
type LogLevel = 'debug' | 'comment' | 'log' | 'info' | 'warn' | 'error' | 'critical';
|
|
414
414
|
declare namespace Logger {
|
|
415
415
|
/**
|
|
416
416
|
* Sets the log level for the logger.
|
|
417
417
|
* This function allows you to change the log level dynamically at runtime.
|
|
418
418
|
* This won't affect the startup logs.
|
|
419
|
+
*
|
|
420
|
+
* If the parameter is a single LogLevel, all log levels with equal or higher severity will be enabled.
|
|
421
|
+
|
|
422
|
+
* If the parameter is an array of LogLevels, only the specified levels will be enabled.
|
|
423
|
+
*
|
|
419
424
|
* @param level Sets the log level for the logger.
|
|
420
425
|
*/
|
|
421
|
-
function setLogLevel(level: LogLevel): void;
|
|
426
|
+
function setLogLevel(level: LogLevel | LogLevel[]): void;
|
|
422
427
|
/**
|
|
423
428
|
* Logs a message to the console with log level LOG.
|
|
424
429
|
* This function formats the message with a timestamp, process ID, and the name of the caller function or class.
|
|
@@ -447,6 +452,9 @@ declare namespace Logger {
|
|
|
447
452
|
* @param args The arguments to log.
|
|
448
453
|
*/
|
|
449
454
|
function error(...args: any[]): void;
|
|
455
|
+
/**
|
|
456
|
+
* Logs a message to the console with log level ERROR and a grey color scheme.
|
|
457
|
+
*/
|
|
450
458
|
function errorStack(...args: any[]): void;
|
|
451
459
|
/**
|
|
452
460
|
* Logs a message to the console with log level DEBUG.
|
|
@@ -462,6 +470,24 @@ declare namespace Logger {
|
|
|
462
470
|
* @param args The arguments to log.
|
|
463
471
|
*/
|
|
464
472
|
function comment(...args: any[]): void;
|
|
473
|
+
/**
|
|
474
|
+
* Logs a message to the console with log level CRITICAL.
|
|
475
|
+
* This function formats the message with a timestamp, process ID, and the name of the caller function or class.
|
|
476
|
+
* It uses different colors for different log levels to enhance readability.
|
|
477
|
+
* @param args The arguments to log.
|
|
478
|
+
*/
|
|
479
|
+
function critical(...args: any[]): void;
|
|
480
|
+
/**
|
|
481
|
+
* Enables logging to a file output for the specified log levels.
|
|
482
|
+
* @param filepath The path to the log file.
|
|
483
|
+
* @param levels The log levels to enable file logging for. Defaults to all levels.
|
|
484
|
+
*/
|
|
485
|
+
function enableFileLogging(filepath: string, levels?: LogLevel[]): void;
|
|
486
|
+
/**
|
|
487
|
+
* Disables logging to a file output for the specified log levels.
|
|
488
|
+
* @param levels The log levels to disable file logging for. Defaults to all levels.
|
|
489
|
+
*/
|
|
490
|
+
function disableFileLogging(levels?: LogLevel[]): void;
|
|
465
491
|
const colors: {
|
|
466
492
|
black: string;
|
|
467
493
|
grey: string;
|
package/dist/main.d.ts
CHANGED
|
@@ -410,15 +410,20 @@ declare function exposeNoxusBridge(options?: NoxusPreloadOptions): NoxusPreloadA
|
|
|
410
410
|
/**
|
|
411
411
|
* Logger is a utility class for logging messages to the console.
|
|
412
412
|
*/
|
|
413
|
-
type LogLevel = '
|
|
413
|
+
type LogLevel = 'debug' | 'comment' | 'log' | 'info' | 'warn' | 'error' | 'critical';
|
|
414
414
|
declare namespace Logger {
|
|
415
415
|
/**
|
|
416
416
|
* Sets the log level for the logger.
|
|
417
417
|
* This function allows you to change the log level dynamically at runtime.
|
|
418
418
|
* This won't affect the startup logs.
|
|
419
|
+
*
|
|
420
|
+
* If the parameter is a single LogLevel, all log levels with equal or higher severity will be enabled.
|
|
421
|
+
|
|
422
|
+
* If the parameter is an array of LogLevels, only the specified levels will be enabled.
|
|
423
|
+
*
|
|
419
424
|
* @param level Sets the log level for the logger.
|
|
420
425
|
*/
|
|
421
|
-
function setLogLevel(level: LogLevel): void;
|
|
426
|
+
function setLogLevel(level: LogLevel | LogLevel[]): void;
|
|
422
427
|
/**
|
|
423
428
|
* Logs a message to the console with log level LOG.
|
|
424
429
|
* This function formats the message with a timestamp, process ID, and the name of the caller function or class.
|
|
@@ -447,6 +452,9 @@ declare namespace Logger {
|
|
|
447
452
|
* @param args The arguments to log.
|
|
448
453
|
*/
|
|
449
454
|
function error(...args: any[]): void;
|
|
455
|
+
/**
|
|
456
|
+
* Logs a message to the console with log level ERROR and a grey color scheme.
|
|
457
|
+
*/
|
|
450
458
|
function errorStack(...args: any[]): void;
|
|
451
459
|
/**
|
|
452
460
|
* Logs a message to the console with log level DEBUG.
|
|
@@ -462,6 +470,24 @@ declare namespace Logger {
|
|
|
462
470
|
* @param args The arguments to log.
|
|
463
471
|
*/
|
|
464
472
|
function comment(...args: any[]): void;
|
|
473
|
+
/**
|
|
474
|
+
* Logs a message to the console with log level CRITICAL.
|
|
475
|
+
* This function formats the message with a timestamp, process ID, and the name of the caller function or class.
|
|
476
|
+
* It uses different colors for different log levels to enhance readability.
|
|
477
|
+
* @param args The arguments to log.
|
|
478
|
+
*/
|
|
479
|
+
function critical(...args: any[]): void;
|
|
480
|
+
/**
|
|
481
|
+
* Enables logging to a file output for the specified log levels.
|
|
482
|
+
* @param filepath The path to the log file.
|
|
483
|
+
* @param levels The log levels to enable file logging for. Defaults to all levels.
|
|
484
|
+
*/
|
|
485
|
+
function enableFileLogging(filepath: string, levels?: LogLevel[]): void;
|
|
486
|
+
/**
|
|
487
|
+
* Disables logging to a file output for the specified log levels.
|
|
488
|
+
* @param levels The log levels to disable file logging for. Defaults to all levels.
|
|
489
|
+
*/
|
|
490
|
+
function disableFileLogging(levels?: LogLevel[]): void;
|
|
465
491
|
const colors: {
|
|
466
492
|
black: string;
|
|
467
493
|
grey: string;
|
package/dist/main.js
CHANGED
|
@@ -4,9 +4,11 @@
|
|
|
4
4
|
* @author NoxFly
|
|
5
5
|
*/
|
|
6
6
|
"use strict";
|
|
7
|
+
var __create = Object.create;
|
|
7
8
|
var __defProp = Object.defineProperty;
|
|
8
9
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
9
10
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
10
12
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
13
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
14
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
@@ -22,6 +24,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
22
24
|
}
|
|
23
25
|
return to;
|
|
24
26
|
};
|
|
27
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
28
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
29
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
30
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
31
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
32
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
33
|
+
mod
|
|
34
|
+
));
|
|
25
35
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
26
36
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
27
37
|
|
|
@@ -417,12 +427,12 @@ __name(hasInjectableMetadata, "hasInjectableMetadata");
|
|
|
417
427
|
|
|
418
428
|
// src/decorators/method.decorator.ts
|
|
419
429
|
function createRouteDecorator(verb) {
|
|
420
|
-
return (
|
|
430
|
+
return (path2) => {
|
|
421
431
|
return (target, propertyKey) => {
|
|
422
432
|
const existingRoutes = Reflect.getMetadata(ROUTE_METADATA_KEY, target.constructor) || [];
|
|
423
433
|
const metadata = {
|
|
424
434
|
method: verb,
|
|
425
|
-
path:
|
|
435
|
+
path: path2.trim().replace(/^\/|\/$/g, ""),
|
|
426
436
|
handler: propertyKey,
|
|
427
437
|
guards: getGuardForControllerAction(target.constructor.__controllerName, propertyKey)
|
|
428
438
|
};
|
|
@@ -486,6 +496,8 @@ __name(getModuleMetadata, "getModuleMetadata");
|
|
|
486
496
|
var MODULE_METADATA_KEY = Symbol("MODULE_METADATA_KEY");
|
|
487
497
|
|
|
488
498
|
// src/utils/logger.ts
|
|
499
|
+
var fs = __toESM(require("fs"));
|
|
500
|
+
var path = __toESM(require("path"));
|
|
489
501
|
function getPrettyTimestamp() {
|
|
490
502
|
const now = /* @__PURE__ */ new Date();
|
|
491
503
|
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")}`;
|
|
@@ -494,21 +506,41 @@ __name(getPrettyTimestamp, "getPrettyTimestamp");
|
|
|
494
506
|
function getLogPrefix(callee, messageType, color) {
|
|
495
507
|
const timestamp = getPrettyTimestamp();
|
|
496
508
|
const spaces = " ".repeat(10 - messageType.length);
|
|
497
|
-
|
|
509
|
+
let colReset = Logger.colors.initial;
|
|
510
|
+
let colCallee = Logger.colors.yellow;
|
|
511
|
+
if (color === void 0) {
|
|
512
|
+
color = "";
|
|
513
|
+
colReset = "";
|
|
514
|
+
colCallee = "";
|
|
515
|
+
}
|
|
516
|
+
return `${color}[APP] ${process.pid} - ${colReset}${timestamp}${spaces}${color}${messageType.toUpperCase()}${colReset} ${colCallee}[${callee}]${colReset}`;
|
|
498
517
|
}
|
|
499
518
|
__name(getLogPrefix, "getLogPrefix");
|
|
500
|
-
function formatObject(prefix, arg) {
|
|
519
|
+
function formatObject(prefix, arg, enableColor = true) {
|
|
501
520
|
const json = JSON.stringify(arg, null, 2);
|
|
502
|
-
|
|
521
|
+
let colStart = "";
|
|
522
|
+
let colLine = "";
|
|
523
|
+
let colReset = "";
|
|
524
|
+
if (enableColor) {
|
|
525
|
+
colStart = Logger.colors.darkGrey;
|
|
526
|
+
colLine = Logger.colors.grey;
|
|
527
|
+
colReset = Logger.colors.initial;
|
|
528
|
+
}
|
|
529
|
+
const prefixedJson = json.split("\n").map((line, idx) => idx === 0 ? `${colStart}${line}` : `${prefix} ${colLine}${line}`).join("\n") + colReset;
|
|
503
530
|
return prefixedJson;
|
|
504
531
|
}
|
|
505
532
|
__name(formatObject, "formatObject");
|
|
506
533
|
function formattedArgs(prefix, args, color) {
|
|
534
|
+
let colReset = Logger.colors.initial;
|
|
535
|
+
if (color === void 0) {
|
|
536
|
+
color = "";
|
|
537
|
+
colReset = "";
|
|
538
|
+
}
|
|
507
539
|
return args.map((arg) => {
|
|
508
540
|
if (typeof arg === "string") {
|
|
509
|
-
return `${color}${arg}${
|
|
541
|
+
return `${color}${arg}${colReset}`;
|
|
510
542
|
} else if (typeof arg === "object") {
|
|
511
|
-
return formatObject(prefix, arg);
|
|
543
|
+
return formatObject(prefix, arg, color === "");
|
|
512
544
|
}
|
|
513
545
|
return arg;
|
|
514
546
|
});
|
|
@@ -521,80 +553,163 @@ function getCallee() {
|
|
|
521
553
|
}
|
|
522
554
|
__name(getCallee, "getCallee");
|
|
523
555
|
function canLog(level) {
|
|
524
|
-
return
|
|
556
|
+
return logLevels.has(level);
|
|
525
557
|
}
|
|
526
558
|
__name(canLog, "canLog");
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
559
|
+
function processLogQueue(filepath) {
|
|
560
|
+
const state = fileStates.get(filepath);
|
|
561
|
+
if (!state || state.isWriting || state.queue.length === 0) {
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
564
|
+
state.isWriting = true;
|
|
565
|
+
const messagesToWrite = state.queue.join("\n") + "\n";
|
|
566
|
+
state.queue = [];
|
|
567
|
+
const dir = path.dirname(filepath);
|
|
568
|
+
fs.mkdir(dir, {
|
|
569
|
+
recursive: true
|
|
570
|
+
}, (err) => {
|
|
571
|
+
if (err) {
|
|
572
|
+
console.error(`[Logger] Failed to create directory ${dir}`, err);
|
|
573
|
+
state.isWriting = false;
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
fs.appendFile(filepath, messagesToWrite, {
|
|
577
|
+
encoding: "utf-8"
|
|
578
|
+
}, (err2) => {
|
|
579
|
+
state.isWriting = false;
|
|
580
|
+
if (err2) {
|
|
581
|
+
console.error(`[Logger] Failed to write log to ${filepath}`, err2);
|
|
582
|
+
}
|
|
583
|
+
if (state.queue.length > 0) {
|
|
584
|
+
processLogQueue(filepath);
|
|
585
|
+
}
|
|
586
|
+
});
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
__name(processLogQueue, "processLogQueue");
|
|
590
|
+
function enqueue(filepath, message) {
|
|
591
|
+
if (!fileStates.has(filepath)) {
|
|
592
|
+
fileStates.set(filepath, {
|
|
593
|
+
queue: [],
|
|
594
|
+
isWriting: false
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
const state = fileStates.get(filepath);
|
|
598
|
+
state.queue.push(message);
|
|
599
|
+
processLogQueue(filepath);
|
|
600
|
+
}
|
|
601
|
+
__name(enqueue, "enqueue");
|
|
602
|
+
function output(level, args) {
|
|
603
|
+
if (!canLog(level)) {
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
const callee = getCallee();
|
|
607
|
+
{
|
|
608
|
+
const prefix = getLogPrefix(callee, level, logLevelColors[level]);
|
|
609
|
+
const data = formattedArgs(prefix, args, logLevelColors[level]);
|
|
610
|
+
logLevelChannel[level](prefix, ...data);
|
|
611
|
+
}
|
|
612
|
+
{
|
|
613
|
+
const prefix = getLogPrefix(callee, level);
|
|
614
|
+
const data = formattedArgs(prefix, args);
|
|
615
|
+
const filepath = fileSettings.get(level)?.filepath;
|
|
616
|
+
if (filepath) {
|
|
617
|
+
const message = prefix + " " + data.join(" ");
|
|
618
|
+
enqueue(filepath, message);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
__name(output, "output");
|
|
536
623
|
(function(Logger2) {
|
|
537
624
|
function setLogLevel(level) {
|
|
538
|
-
|
|
625
|
+
logLevels.clear();
|
|
626
|
+
if (Array.isArray(level)) {
|
|
627
|
+
for (const lvl of level) {
|
|
628
|
+
logLevels.add(lvl);
|
|
629
|
+
}
|
|
630
|
+
} else {
|
|
631
|
+
const targetRank = logLevelRank[level];
|
|
632
|
+
for (const [lvl, rank] of Object.entries(logLevelRank)) {
|
|
633
|
+
if (rank >= targetRank) {
|
|
634
|
+
logLevels.add(lvl);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
}
|
|
539
638
|
}
|
|
540
639
|
__name(setLogLevel, "setLogLevel");
|
|
541
640
|
Logger2.setLogLevel = setLogLevel;
|
|
542
641
|
function log(...args) {
|
|
543
|
-
|
|
544
|
-
const callee = getCallee();
|
|
545
|
-
const prefix = getLogPrefix(callee, "log", Logger2.colors.green);
|
|
546
|
-
console.log(prefix, ...formattedArgs(prefix, args, Logger2.colors.green));
|
|
642
|
+
output("log", args);
|
|
547
643
|
}
|
|
548
644
|
__name(log, "log");
|
|
549
645
|
Logger2.log = log;
|
|
550
646
|
function info(...args) {
|
|
551
|
-
|
|
552
|
-
const callee = getCallee();
|
|
553
|
-
const prefix = getLogPrefix(callee, "info", Logger2.colors.blue);
|
|
554
|
-
console.info(prefix, ...formattedArgs(prefix, args, Logger2.colors.blue));
|
|
647
|
+
output("info", args);
|
|
555
648
|
}
|
|
556
649
|
__name(info, "info");
|
|
557
650
|
Logger2.info = info;
|
|
558
651
|
function warn(...args) {
|
|
559
|
-
|
|
560
|
-
const callee = getCallee();
|
|
561
|
-
const prefix = getLogPrefix(callee, "warn", Logger2.colors.brown);
|
|
562
|
-
console.warn(prefix, ...formattedArgs(prefix, args, Logger2.colors.brown));
|
|
652
|
+
output("warn", args);
|
|
563
653
|
}
|
|
564
654
|
__name(warn, "warn");
|
|
565
655
|
Logger2.warn = warn;
|
|
566
656
|
function error(...args) {
|
|
567
|
-
|
|
568
|
-
const callee = getCallee();
|
|
569
|
-
const prefix = getLogPrefix(callee, "error", Logger2.colors.red);
|
|
570
|
-
console.error(prefix, ...formattedArgs(prefix, args, Logger2.colors.red));
|
|
657
|
+
output("error", args);
|
|
571
658
|
}
|
|
572
659
|
__name(error, "error");
|
|
573
660
|
Logger2.error = error;
|
|
574
661
|
function errorStack(...args) {
|
|
575
|
-
|
|
576
|
-
const callee = getCallee();
|
|
577
|
-
const prefix = getLogPrefix(callee, "error", Logger2.colors.grey);
|
|
578
|
-
console.error(prefix, ...formattedArgs(prefix, args, Logger2.colors.grey));
|
|
662
|
+
output("error", args);
|
|
579
663
|
}
|
|
580
664
|
__name(errorStack, "errorStack");
|
|
581
665
|
Logger2.errorStack = errorStack;
|
|
582
666
|
function debug(...args) {
|
|
583
|
-
|
|
584
|
-
const callee = getCallee();
|
|
585
|
-
const prefix = getLogPrefix(callee, "debug", Logger2.colors.purple);
|
|
586
|
-
console.debug(prefix, ...formattedArgs(prefix, args, Logger2.colors.purple));
|
|
667
|
+
output("debug", args);
|
|
587
668
|
}
|
|
588
669
|
__name(debug, "debug");
|
|
589
670
|
Logger2.debug = debug;
|
|
590
671
|
function comment(...args) {
|
|
591
|
-
|
|
592
|
-
const callee = getCallee();
|
|
593
|
-
const prefix = getLogPrefix(callee, "comment", Logger2.colors.grey);
|
|
594
|
-
console.debug(prefix, ...formattedArgs(prefix, args, Logger2.colors.grey));
|
|
672
|
+
output("comment", args);
|
|
595
673
|
}
|
|
596
674
|
__name(comment, "comment");
|
|
597
675
|
Logger2.comment = comment;
|
|
676
|
+
function critical(...args) {
|
|
677
|
+
output("critical", args);
|
|
678
|
+
}
|
|
679
|
+
__name(critical, "critical");
|
|
680
|
+
Logger2.critical = critical;
|
|
681
|
+
function enableFileLogging(filepath, levels = [
|
|
682
|
+
"debug",
|
|
683
|
+
"comment",
|
|
684
|
+
"log",
|
|
685
|
+
"info",
|
|
686
|
+
"warn",
|
|
687
|
+
"error",
|
|
688
|
+
"critical"
|
|
689
|
+
]) {
|
|
690
|
+
for (const level of levels) {
|
|
691
|
+
fileSettings.set(level, {
|
|
692
|
+
filepath
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
__name(enableFileLogging, "enableFileLogging");
|
|
697
|
+
Logger2.enableFileLogging = enableFileLogging;
|
|
698
|
+
function disableFileLogging(levels = [
|
|
699
|
+
"debug",
|
|
700
|
+
"comment",
|
|
701
|
+
"log",
|
|
702
|
+
"info",
|
|
703
|
+
"warn",
|
|
704
|
+
"error",
|
|
705
|
+
"critical"
|
|
706
|
+
]) {
|
|
707
|
+
for (const level of levels) {
|
|
708
|
+
fileSettings.delete(level);
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
__name(disableFileLogging, "disableFileLogging");
|
|
712
|
+
Logger2.disableFileLogging = disableFileLogging;
|
|
598
713
|
Logger2.colors = {
|
|
599
714
|
black: "\x1B[0;30m",
|
|
600
715
|
grey: "\x1B[0;37m",
|
|
@@ -614,6 +729,37 @@ var logLevelRank = {
|
|
|
614
729
|
initial: "\x1B[0m"
|
|
615
730
|
};
|
|
616
731
|
})(Logger || (Logger = {}));
|
|
732
|
+
var fileSettings = /* @__PURE__ */ new Map();
|
|
733
|
+
var fileStates = /* @__PURE__ */ new Map();
|
|
734
|
+
var logLevels = /* @__PURE__ */ new Set();
|
|
735
|
+
var logLevelRank = {
|
|
736
|
+
debug: 0,
|
|
737
|
+
comment: 1,
|
|
738
|
+
log: 2,
|
|
739
|
+
info: 3,
|
|
740
|
+
warn: 4,
|
|
741
|
+
error: 5,
|
|
742
|
+
critical: 6
|
|
743
|
+
};
|
|
744
|
+
var logLevelColors = {
|
|
745
|
+
debug: Logger.colors.purple,
|
|
746
|
+
comment: Logger.colors.grey,
|
|
747
|
+
log: Logger.colors.green,
|
|
748
|
+
info: Logger.colors.blue,
|
|
749
|
+
warn: Logger.colors.brown,
|
|
750
|
+
error: Logger.colors.red,
|
|
751
|
+
critical: Logger.colors.lightRed
|
|
752
|
+
};
|
|
753
|
+
var logLevelChannel = {
|
|
754
|
+
debug: console.debug,
|
|
755
|
+
comment: console.debug,
|
|
756
|
+
log: console.log,
|
|
757
|
+
info: console.info,
|
|
758
|
+
warn: console.warn,
|
|
759
|
+
error: console.error,
|
|
760
|
+
critical: console.error
|
|
761
|
+
};
|
|
762
|
+
Logger.setLogLevel("debug");
|
|
617
763
|
var Logger;
|
|
618
764
|
|
|
619
765
|
// src/DI/injector-explorer.ts
|
|
@@ -669,10 +815,10 @@ function Injectable(lifetime = "scope") {
|
|
|
669
815
|
__name(Injectable, "Injectable");
|
|
670
816
|
|
|
671
817
|
// src/decorators/controller.decorator.ts
|
|
672
|
-
function Controller(
|
|
818
|
+
function Controller(path2) {
|
|
673
819
|
return (target) => {
|
|
674
820
|
const data = {
|
|
675
|
-
path,
|
|
821
|
+
path: path2,
|
|
676
822
|
guards: getGuardForController(target.name)
|
|
677
823
|
};
|
|
678
824
|
Reflect.defineMetadata(CONTROLLER_METADATA_KEY, data, target);
|
|
@@ -720,7 +866,7 @@ var middlewares = /* @__PURE__ */ new Map();
|
|
|
720
866
|
// src/request.ts
|
|
721
867
|
var import_reflect_metadata2 = require("reflect-metadata");
|
|
722
868
|
var _Request = class _Request {
|
|
723
|
-
constructor(event, senderId, id, method,
|
|
869
|
+
constructor(event, senderId, id, method, path2, body) {
|
|
724
870
|
__publicField(this, "event");
|
|
725
871
|
__publicField(this, "senderId");
|
|
726
872
|
__publicField(this, "id");
|
|
@@ -733,9 +879,9 @@ var _Request = class _Request {
|
|
|
733
879
|
this.senderId = senderId;
|
|
734
880
|
this.id = id;
|
|
735
881
|
this.method = method;
|
|
736
|
-
this.path =
|
|
882
|
+
this.path = path2;
|
|
737
883
|
this.body = body;
|
|
738
|
-
this.path =
|
|
884
|
+
this.path = path2.replace(/^\/|\/$/g, "");
|
|
739
885
|
}
|
|
740
886
|
};
|
|
741
887
|
__name(_Request, "Request");
|
|
@@ -817,8 +963,8 @@ var _RadixTree = class _RadixTree {
|
|
|
817
963
|
* @param path - The path to insert into the tree.
|
|
818
964
|
* @param value - The value to associate with the path.
|
|
819
965
|
*/
|
|
820
|
-
insert(
|
|
821
|
-
const segments = this.normalize(
|
|
966
|
+
insert(path2, value) {
|
|
967
|
+
const segments = this.normalize(path2);
|
|
822
968
|
this.insertRecursive(this.root, segments, value);
|
|
823
969
|
}
|
|
824
970
|
/**
|
|
@@ -847,8 +993,8 @@ var _RadixTree = class _RadixTree {
|
|
|
847
993
|
* @param path - The path to search for in the Radix Tree.
|
|
848
994
|
* @returns An ISearchResult containing the node and parameters if a match is found, otherwise undefined.
|
|
849
995
|
*/
|
|
850
|
-
search(
|
|
851
|
-
const segments = this.normalize(
|
|
996
|
+
search(path2) {
|
|
997
|
+
const segments = this.normalize(path2);
|
|
852
998
|
return this.searchRecursive(this.root, segments, {});
|
|
853
999
|
}
|
|
854
1000
|
/**
|
|
@@ -904,8 +1050,8 @@ var _RadixTree = class _RadixTree {
|
|
|
904
1050
|
* @param path - The path to normalize.
|
|
905
1051
|
* @returns An array of normalized path segments.
|
|
906
1052
|
*/
|
|
907
|
-
normalize(
|
|
908
|
-
const segments =
|
|
1053
|
+
normalize(path2) {
|
|
1054
|
+
const segments = path2.replace(/^\/+|\/+$/g, "").split("/").filter(Boolean);
|
|
909
1055
|
return [
|
|
910
1056
|
"",
|
|
911
1057
|
...segments
|
|
@@ -1015,6 +1161,7 @@ var _Router = class _Router {
|
|
|
1015
1161
|
status: 200,
|
|
1016
1162
|
body: null
|
|
1017
1163
|
};
|
|
1164
|
+
let isCritical = false;
|
|
1018
1165
|
try {
|
|
1019
1166
|
const routeDef = this.findRoute(request);
|
|
1020
1167
|
await this.resolveController(request, response, routeDef);
|
|
@@ -1028,10 +1175,12 @@ var _Router = class _Router {
|
|
|
1028
1175
|
response.error = error.message;
|
|
1029
1176
|
response.stack = error.stack;
|
|
1030
1177
|
} else if (error instanceof Error) {
|
|
1178
|
+
isCritical = true;
|
|
1031
1179
|
response.status = 500;
|
|
1032
1180
|
response.error = error.message || "Internal Server Error";
|
|
1033
1181
|
response.stack = error.stack || "No stack trace available";
|
|
1034
1182
|
} else {
|
|
1183
|
+
isCritical = true;
|
|
1035
1184
|
response.status = 500;
|
|
1036
1185
|
response.error = "Unknown error occurred";
|
|
1037
1186
|
response.stack = "No stack trace available";
|
|
@@ -1039,11 +1188,23 @@ var _Router = class _Router {
|
|
|
1039
1188
|
} finally {
|
|
1040
1189
|
const t1 = performance.now();
|
|
1041
1190
|
const message = `< ${response.status} ${request.method} /${request.path} ${Logger.colors.yellow}${Math.round(t1 - t0)}ms${Logger.colors.initial}`;
|
|
1042
|
-
if (response.status < 400)
|
|
1043
|
-
|
|
1044
|
-
else
|
|
1191
|
+
if (response.status < 400) {
|
|
1192
|
+
Logger.log(message);
|
|
1193
|
+
} else if (response.status < 500) {
|
|
1194
|
+
Logger.warn(message);
|
|
1195
|
+
} else {
|
|
1196
|
+
if (isCritical) {
|
|
1197
|
+
Logger.critical(message);
|
|
1198
|
+
} else {
|
|
1199
|
+
Logger.error(message);
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1045
1202
|
if (response.error !== void 0) {
|
|
1046
|
-
|
|
1203
|
+
if (isCritical) {
|
|
1204
|
+
Logger.critical(response.error);
|
|
1205
|
+
} else {
|
|
1206
|
+
Logger.error(response.error);
|
|
1207
|
+
}
|
|
1047
1208
|
if (response.stack !== void 0) {
|
|
1048
1209
|
Logger.errorStack(response.stack);
|
|
1049
1210
|
}
|
|
@@ -1061,6 +1222,7 @@ var _Router = class _Router {
|
|
|
1061
1222
|
responses: []
|
|
1062
1223
|
}
|
|
1063
1224
|
};
|
|
1225
|
+
let isCritical = false;
|
|
1064
1226
|
try {
|
|
1065
1227
|
const payload = this.normalizeBatchPayload(request.body);
|
|
1066
1228
|
const batchResponses = [];
|
|
@@ -1077,10 +1239,12 @@ var _Router = class _Router {
|
|
|
1077
1239
|
response.error = error.message;
|
|
1078
1240
|
response.stack = error.stack;
|
|
1079
1241
|
} else if (error instanceof Error) {
|
|
1242
|
+
isCritical = true;
|
|
1080
1243
|
response.status = 500;
|
|
1081
1244
|
response.error = error.message || "Internal Server Error";
|
|
1082
1245
|
response.stack = error.stack || "No stack trace available";
|
|
1083
1246
|
} else {
|
|
1247
|
+
isCritical = true;
|
|
1084
1248
|
response.status = 500;
|
|
1085
1249
|
response.error = "Unknown error occurred";
|
|
1086
1250
|
response.stack = "No stack trace available";
|
|
@@ -1088,11 +1252,23 @@ var _Router = class _Router {
|
|
|
1088
1252
|
} finally {
|
|
1089
1253
|
const t1 = performance.now();
|
|
1090
1254
|
const message = `< ${response.status} ${request.method} /${request.path} ${Logger.colors.yellow}${Math.round(t1 - t0)}ms${Logger.colors.initial}`;
|
|
1091
|
-
if (response.status < 400)
|
|
1092
|
-
|
|
1093
|
-
else
|
|
1255
|
+
if (response.status < 400) {
|
|
1256
|
+
Logger.log(message);
|
|
1257
|
+
} else if (response.status < 500) {
|
|
1258
|
+
Logger.warn(message);
|
|
1259
|
+
} else {
|
|
1260
|
+
if (isCritical) {
|
|
1261
|
+
Logger.critical(message);
|
|
1262
|
+
} else {
|
|
1263
|
+
Logger.error(message);
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1094
1266
|
if (response.error !== void 0) {
|
|
1095
|
-
|
|
1267
|
+
if (isCritical) {
|
|
1268
|
+
Logger.critical(response.error);
|
|
1269
|
+
} else {
|
|
1270
|
+
Logger.error(response.error);
|
|
1271
|
+
}
|
|
1096
1272
|
if (response.stack !== void 0) {
|
|
1097
1273
|
Logger.errorStack(response.stack);
|
|
1098
1274
|
}
|
|
@@ -1118,11 +1294,11 @@ var _Router = class _Router {
|
|
|
1118
1294
|
if (entry === null || typeof entry !== "object") {
|
|
1119
1295
|
throw new BadRequestException(`Batch request at index ${index} must be an object.`);
|
|
1120
1296
|
}
|
|
1121
|
-
const { requestId, path, method, body } = entry;
|
|
1297
|
+
const { requestId, path: path2, method, body } = entry;
|
|
1122
1298
|
if (requestId !== void 0 && typeof requestId !== "string") {
|
|
1123
1299
|
throw new BadRequestException(`Batch request at index ${index} has an invalid requestId.`);
|
|
1124
1300
|
}
|
|
1125
|
-
if (typeof
|
|
1301
|
+
if (typeof path2 !== "string" || path2.length === 0) {
|
|
1126
1302
|
throw new BadRequestException(`Batch request at index ${index} must define a non-empty path.`);
|
|
1127
1303
|
}
|
|
1128
1304
|
if (typeof method !== "string") {
|
|
@@ -1134,7 +1310,7 @@ var _Router = class _Router {
|
|
|
1134
1310
|
}
|
|
1135
1311
|
return {
|
|
1136
1312
|
requestId,
|
|
1137
|
-
path,
|
|
1313
|
+
path: path2,
|
|
1138
1314
|
method: normalizedMethod,
|
|
1139
1315
|
body
|
|
1140
1316
|
};
|
|
@@ -1360,14 +1536,14 @@ var _NoxApp = class _NoxApp {
|
|
|
1360
1536
|
*
|
|
1361
1537
|
*/
|
|
1362
1538
|
__publicField(this, "onRendererMessage", /* @__PURE__ */ __name(async (event) => {
|
|
1363
|
-
const { senderId, requestId, path, method, body } = event.data;
|
|
1539
|
+
const { senderId, requestId, path: path2, method, body } = event.data;
|
|
1364
1540
|
const channels = this.socket.get(senderId);
|
|
1365
1541
|
if (!channels) {
|
|
1366
1542
|
Logger.error(`No message channel found for sender ID: ${senderId}`);
|
|
1367
1543
|
return;
|
|
1368
1544
|
}
|
|
1369
1545
|
try {
|
|
1370
|
-
const request = new Request(event, senderId, requestId, method,
|
|
1546
|
+
const request = new Request(event, senderId, requestId, method, path2, body);
|
|
1371
1547
|
const response = await this.router.handle(request);
|
|
1372
1548
|
channels.request.port1.postMessage(response);
|
|
1373
1549
|
} catch (err) {
|