@navios/core 0.1.0 → 0.1.1
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/index.d.mts +432 -11
- package/dist/index.d.ts +432 -11
- package/dist/index.js +798 -38
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +771 -37
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/index.mts +1 -0
- package/src/logger/README.md +3 -0
- package/src/logger/console-logger.service.mts +588 -0
- package/src/logger/index.mts +7 -0
- package/src/logger/log-levels.mts +12 -0
- package/src/logger/logger-service.interface.mts +42 -0
- package/src/logger/logger.factory.mts +37 -0
- package/src/logger/logger.service.mts +214 -0
- package/src/logger/pino-wrapper.mts +63 -0
- package/src/logger/utils/cli-colors.util.mts +17 -0
- package/src/logger/utils/filter-log-levelts.util.mts +29 -0
- package/src/logger/utils/index.mts +5 -0
- package/src/logger/utils/is-log-level-enabled.mts +33 -0
- package/src/logger/utils/is-log-level.util.mts +10 -0
- package/src/logger/utils/shared.utils.mts +51 -0
- package/src/navios.application.mts +71 -18
- package/src/navios.factory.mts +18 -1
- package/src/service-locator/inject.mts +6 -1
- package/src/service-locator/injection-token.mts +11 -6
- package/src/service-locator/service-locator.mts +44 -15
- package/src/service-locator/sync-injector.mts +6 -1
- package/src/services/controller-adapter.service.mts +8 -0
- package/src/services/module-loader.service.mts +6 -1
package/dist/index.mjs
CHANGED
|
@@ -164,6 +164,7 @@ var InjectableScope = /* @__PURE__ */ ((InjectableScope2) => {
|
|
|
164
164
|
|
|
165
165
|
// packages/core/src/service-locator/injection-token.mts
|
|
166
166
|
import { randomUUID } from "crypto";
|
|
167
|
+
import "zod";
|
|
167
168
|
var InjectionToken = class _InjectionToken {
|
|
168
169
|
constructor(name2, schema) {
|
|
169
170
|
this.name = name2;
|
|
@@ -1152,6 +1153,655 @@ var ConflictException = class extends HttpException {
|
|
|
1152
1153
|
}
|
|
1153
1154
|
};
|
|
1154
1155
|
|
|
1156
|
+
// packages/core/src/logger/utils/cli-colors.util.mts
|
|
1157
|
+
var isColorAllowed = () => !process.env.NO_COLOR;
|
|
1158
|
+
var colorIfAllowed = (colorFn) => (text) => isColorAllowed() ? colorFn(text) : text;
|
|
1159
|
+
var clc = {
|
|
1160
|
+
bold: colorIfAllowed((text) => `\x1B[1m${text}\x1B[0m`),
|
|
1161
|
+
green: colorIfAllowed((text) => `\x1B[32m${text}\x1B[39m`),
|
|
1162
|
+
yellow: colorIfAllowed((text) => `\x1B[33m${text}\x1B[39m`),
|
|
1163
|
+
red: colorIfAllowed((text) => `\x1B[31m${text}\x1B[39m`),
|
|
1164
|
+
magentaBright: colorIfAllowed((text) => `\x1B[95m${text}\x1B[39m`),
|
|
1165
|
+
cyanBright: colorIfAllowed((text) => `\x1B[96m${text}\x1B[39m`)
|
|
1166
|
+
};
|
|
1167
|
+
var yellow = colorIfAllowed(
|
|
1168
|
+
(text) => `\x1B[38;5;3m${text}\x1B[39m`
|
|
1169
|
+
);
|
|
1170
|
+
|
|
1171
|
+
// packages/core/src/logger/log-levels.mts
|
|
1172
|
+
var LOG_LEVELS = [
|
|
1173
|
+
"verbose",
|
|
1174
|
+
"debug",
|
|
1175
|
+
"log",
|
|
1176
|
+
"warn",
|
|
1177
|
+
"error",
|
|
1178
|
+
"fatal"
|
|
1179
|
+
];
|
|
1180
|
+
|
|
1181
|
+
// packages/core/src/logger/utils/is-log-level.util.mts
|
|
1182
|
+
function isLogLevel(maybeLogLevel) {
|
|
1183
|
+
return LOG_LEVELS.includes(maybeLogLevel);
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
// packages/core/src/logger/utils/filter-log-levelts.util.mts
|
|
1187
|
+
function filterLogLevels(parseableString = "") {
|
|
1188
|
+
const sanitizedString = parseableString.replaceAll(" ", "").toLowerCase();
|
|
1189
|
+
if (sanitizedString[0] === ">") {
|
|
1190
|
+
const orEqual = sanitizedString[1] === "=";
|
|
1191
|
+
const logLevelIndex = LOG_LEVELS.indexOf(
|
|
1192
|
+
sanitizedString.substring(orEqual ? 2 : 1)
|
|
1193
|
+
);
|
|
1194
|
+
if (logLevelIndex === -1) {
|
|
1195
|
+
throw new Error(`parse error (unknown log level): ${sanitizedString}`);
|
|
1196
|
+
}
|
|
1197
|
+
return LOG_LEVELS.slice(orEqual ? logLevelIndex : logLevelIndex + 1);
|
|
1198
|
+
} else if (sanitizedString.includes(",")) {
|
|
1199
|
+
return sanitizedString.split(",").filter(isLogLevel);
|
|
1200
|
+
}
|
|
1201
|
+
return isLogLevel(sanitizedString) ? [sanitizedString] : LOG_LEVELS;
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
// packages/core/src/logger/utils/is-log-level-enabled.mts
|
|
1205
|
+
var LOG_LEVEL_VALUES = {
|
|
1206
|
+
verbose: 0,
|
|
1207
|
+
debug: 1,
|
|
1208
|
+
log: 2,
|
|
1209
|
+
warn: 3,
|
|
1210
|
+
error: 4,
|
|
1211
|
+
fatal: 5
|
|
1212
|
+
};
|
|
1213
|
+
function isLogLevelEnabled(targetLevel, logLevels) {
|
|
1214
|
+
var _a;
|
|
1215
|
+
if (!logLevels || Array.isArray(logLevels) && (logLevels == null ? void 0 : logLevels.length) === 0) {
|
|
1216
|
+
return false;
|
|
1217
|
+
}
|
|
1218
|
+
if (logLevels.includes(targetLevel)) {
|
|
1219
|
+
return true;
|
|
1220
|
+
}
|
|
1221
|
+
const highestLogLevelValue = (_a = logLevels.map((level) => LOG_LEVEL_VALUES[level]).sort((a, b) => b - a)) == null ? void 0 : _a[0];
|
|
1222
|
+
const targetLevelValue = LOG_LEVEL_VALUES[targetLevel];
|
|
1223
|
+
return targetLevelValue >= highestLogLevelValue;
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
// packages/core/src/logger/utils/shared.utils.mts
|
|
1227
|
+
var isUndefined = (obj) => typeof obj === "undefined";
|
|
1228
|
+
var isObject = (fn) => !isNil(fn) && typeof fn === "object";
|
|
1229
|
+
var isPlainObject = (fn) => {
|
|
1230
|
+
if (!isObject(fn)) {
|
|
1231
|
+
return false;
|
|
1232
|
+
}
|
|
1233
|
+
const proto = Object.getPrototypeOf(fn);
|
|
1234
|
+
if (proto === null) {
|
|
1235
|
+
return true;
|
|
1236
|
+
}
|
|
1237
|
+
const ctor = Object.prototype.hasOwnProperty.call(proto, "constructor") && proto.constructor;
|
|
1238
|
+
return typeof ctor === "function" && ctor instanceof ctor && Function.prototype.toString.call(ctor) === Function.prototype.toString.call(Object);
|
|
1239
|
+
};
|
|
1240
|
+
var addLeadingSlash = (path) => path && typeof path === "string" ? path.charAt(0) !== "/" && path.substring(0, 2) !== "{/" ? "/" + path : path : "";
|
|
1241
|
+
var normalizePath = (path) => path ? path.startsWith("/") ? ("/" + path.replace(/\/+$/, "")).replace(/\/+/g, "/") : "/" + path.replace(/\/+$/, "") : "/";
|
|
1242
|
+
var stripEndSlash = (path) => path[path.length - 1] === "/" ? path.slice(0, path.length - 1) : path;
|
|
1243
|
+
var isFunction = (val) => typeof val === "function";
|
|
1244
|
+
var isString = (val) => typeof val === "string";
|
|
1245
|
+
var isNumber = (val) => typeof val === "number";
|
|
1246
|
+
var isConstructor = (val) => val === "constructor";
|
|
1247
|
+
var isNil = (val) => isUndefined(val) || val === null;
|
|
1248
|
+
var isEmpty = (array) => !(array && array.length > 0);
|
|
1249
|
+
var isSymbol = (val) => typeof val === "symbol";
|
|
1250
|
+
|
|
1251
|
+
// packages/core/src/logger/console-logger.service.mts
|
|
1252
|
+
import { inspect } from "util";
|
|
1253
|
+
var DEFAULT_DEPTH = 5;
|
|
1254
|
+
var DEFAULT_LOG_LEVELS = [
|
|
1255
|
+
"log",
|
|
1256
|
+
"error",
|
|
1257
|
+
"warn",
|
|
1258
|
+
"debug",
|
|
1259
|
+
"verbose",
|
|
1260
|
+
"fatal"
|
|
1261
|
+
];
|
|
1262
|
+
var dateTimeFormatter = new Intl.DateTimeFormat(void 0, {
|
|
1263
|
+
year: "numeric",
|
|
1264
|
+
hour: "numeric",
|
|
1265
|
+
minute: "numeric",
|
|
1266
|
+
second: "numeric",
|
|
1267
|
+
day: "2-digit",
|
|
1268
|
+
month: "2-digit"
|
|
1269
|
+
});
|
|
1270
|
+
var _ConsoleLogger_decorators, _init;
|
|
1271
|
+
_ConsoleLogger_decorators = [Injectable()];
|
|
1272
|
+
var _ConsoleLogger = class _ConsoleLogger {
|
|
1273
|
+
/**
|
|
1274
|
+
* The options of the logger.
|
|
1275
|
+
*/
|
|
1276
|
+
options;
|
|
1277
|
+
/**
|
|
1278
|
+
* The context of the logger (can be set manually or automatically inferred).
|
|
1279
|
+
*/
|
|
1280
|
+
context;
|
|
1281
|
+
/**
|
|
1282
|
+
* The original context of the logger (set in the constructor).
|
|
1283
|
+
*/
|
|
1284
|
+
originalContext;
|
|
1285
|
+
/**
|
|
1286
|
+
* The options used for the "inspect" method.
|
|
1287
|
+
*/
|
|
1288
|
+
inspectOptions;
|
|
1289
|
+
/**
|
|
1290
|
+
* The last timestamp at which the log message was printed.
|
|
1291
|
+
*/
|
|
1292
|
+
static lastTimestampAt;
|
|
1293
|
+
constructor(contextOrOptions, options) {
|
|
1294
|
+
let [context, opts] = isString(contextOrOptions) ? [contextOrOptions, options] : options ? [void 0, options] : [contextOrOptions == null ? void 0 : contextOrOptions.context, contextOrOptions];
|
|
1295
|
+
opts = opts ?? {};
|
|
1296
|
+
opts.logLevels ??= DEFAULT_LOG_LEVELS;
|
|
1297
|
+
opts.colors ??= opts.colors ?? (opts.json ? false : true);
|
|
1298
|
+
opts.prefix ??= "Navios";
|
|
1299
|
+
this.options = opts;
|
|
1300
|
+
this.inspectOptions = this.getInspectOptions();
|
|
1301
|
+
if (context) {
|
|
1302
|
+
this.context = context;
|
|
1303
|
+
this.originalContext = context;
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
log(message, ...optionalParams) {
|
|
1307
|
+
if (!this.isLevelEnabled("log")) {
|
|
1308
|
+
return;
|
|
1309
|
+
}
|
|
1310
|
+
const { messages, context } = this.getContextAndMessagesToPrint([
|
|
1311
|
+
message,
|
|
1312
|
+
...optionalParams
|
|
1313
|
+
]);
|
|
1314
|
+
this.printMessages(messages, context, "log");
|
|
1315
|
+
}
|
|
1316
|
+
error(message, ...optionalParams) {
|
|
1317
|
+
if (!this.isLevelEnabled("error")) {
|
|
1318
|
+
return;
|
|
1319
|
+
}
|
|
1320
|
+
const { messages, context, stack } = this.getContextAndStackAndMessagesToPrint([message, ...optionalParams]);
|
|
1321
|
+
this.printMessages(messages, context, "error", "stderr", stack);
|
|
1322
|
+
this.printStackTrace(stack);
|
|
1323
|
+
}
|
|
1324
|
+
warn(message, ...optionalParams) {
|
|
1325
|
+
if (!this.isLevelEnabled("warn")) {
|
|
1326
|
+
return;
|
|
1327
|
+
}
|
|
1328
|
+
const { messages, context } = this.getContextAndMessagesToPrint([
|
|
1329
|
+
message,
|
|
1330
|
+
...optionalParams
|
|
1331
|
+
]);
|
|
1332
|
+
this.printMessages(messages, context, "warn");
|
|
1333
|
+
}
|
|
1334
|
+
debug(message, ...optionalParams) {
|
|
1335
|
+
if (!this.isLevelEnabled("debug")) {
|
|
1336
|
+
return;
|
|
1337
|
+
}
|
|
1338
|
+
const { messages, context } = this.getContextAndMessagesToPrint([
|
|
1339
|
+
message,
|
|
1340
|
+
...optionalParams
|
|
1341
|
+
]);
|
|
1342
|
+
this.printMessages(messages, context, "debug");
|
|
1343
|
+
}
|
|
1344
|
+
verbose(message, ...optionalParams) {
|
|
1345
|
+
if (!this.isLevelEnabled("verbose")) {
|
|
1346
|
+
return;
|
|
1347
|
+
}
|
|
1348
|
+
const { messages, context } = this.getContextAndMessagesToPrint([
|
|
1349
|
+
message,
|
|
1350
|
+
...optionalParams
|
|
1351
|
+
]);
|
|
1352
|
+
this.printMessages(messages, context, "verbose");
|
|
1353
|
+
}
|
|
1354
|
+
fatal(message, ...optionalParams) {
|
|
1355
|
+
if (!this.isLevelEnabled("fatal")) {
|
|
1356
|
+
return;
|
|
1357
|
+
}
|
|
1358
|
+
const { messages, context } = this.getContextAndMessagesToPrint([
|
|
1359
|
+
message,
|
|
1360
|
+
...optionalParams
|
|
1361
|
+
]);
|
|
1362
|
+
this.printMessages(messages, context, "fatal");
|
|
1363
|
+
}
|
|
1364
|
+
/**
|
|
1365
|
+
* Set log levels
|
|
1366
|
+
* @param levels log levels
|
|
1367
|
+
*/
|
|
1368
|
+
setLogLevels(levels) {
|
|
1369
|
+
if (!this.options) {
|
|
1370
|
+
this.options = {};
|
|
1371
|
+
}
|
|
1372
|
+
this.options.logLevels = levels;
|
|
1373
|
+
}
|
|
1374
|
+
/**
|
|
1375
|
+
* Set logger context
|
|
1376
|
+
* @param context context
|
|
1377
|
+
*/
|
|
1378
|
+
setContext(context) {
|
|
1379
|
+
this.context = context;
|
|
1380
|
+
}
|
|
1381
|
+
/**
|
|
1382
|
+
* Resets the logger context to the value that was passed in the constructor.
|
|
1383
|
+
*/
|
|
1384
|
+
resetContext() {
|
|
1385
|
+
this.context = this.originalContext;
|
|
1386
|
+
}
|
|
1387
|
+
isLevelEnabled(level) {
|
|
1388
|
+
var _a;
|
|
1389
|
+
const logLevels = (_a = this.options) == null ? void 0 : _a.logLevels;
|
|
1390
|
+
return isLogLevelEnabled(level, logLevels);
|
|
1391
|
+
}
|
|
1392
|
+
getTimestamp() {
|
|
1393
|
+
return dateTimeFormatter.format(Date.now());
|
|
1394
|
+
}
|
|
1395
|
+
printMessages(messages, context = "", logLevel = "log", writeStreamType, errorStack) {
|
|
1396
|
+
messages.forEach((message) => {
|
|
1397
|
+
if (this.options.json) {
|
|
1398
|
+
this.printAsJson(message, {
|
|
1399
|
+
context,
|
|
1400
|
+
logLevel,
|
|
1401
|
+
writeStreamType,
|
|
1402
|
+
errorStack
|
|
1403
|
+
});
|
|
1404
|
+
return;
|
|
1405
|
+
}
|
|
1406
|
+
const pidMessage = this.formatPid(process.pid);
|
|
1407
|
+
const contextMessage = this.formatContext(context);
|
|
1408
|
+
const timestampDiff = this.updateAndGetTimestampDiff();
|
|
1409
|
+
const formattedLogLevel = logLevel.toUpperCase().padStart(7, " ");
|
|
1410
|
+
const formattedMessage = this.formatMessage(
|
|
1411
|
+
logLevel,
|
|
1412
|
+
message,
|
|
1413
|
+
pidMessage,
|
|
1414
|
+
formattedLogLevel,
|
|
1415
|
+
contextMessage,
|
|
1416
|
+
timestampDiff
|
|
1417
|
+
);
|
|
1418
|
+
process[writeStreamType ?? "stdout"].write(formattedMessage);
|
|
1419
|
+
});
|
|
1420
|
+
}
|
|
1421
|
+
printAsJson(message, options) {
|
|
1422
|
+
const logObject = {
|
|
1423
|
+
level: options.logLevel,
|
|
1424
|
+
pid: process.pid,
|
|
1425
|
+
timestamp: Date.now(),
|
|
1426
|
+
message
|
|
1427
|
+
};
|
|
1428
|
+
if (options.context) {
|
|
1429
|
+
logObject.context = options.context;
|
|
1430
|
+
}
|
|
1431
|
+
if (options.errorStack) {
|
|
1432
|
+
logObject.stack = options.errorStack;
|
|
1433
|
+
}
|
|
1434
|
+
const formattedMessage = !this.options.colors && this.inspectOptions.compact === true ? JSON.stringify(logObject, this.stringifyReplacer) : inspect(logObject, this.inspectOptions);
|
|
1435
|
+
process[options.writeStreamType ?? "stdout"].write(`${formattedMessage}
|
|
1436
|
+
`);
|
|
1437
|
+
}
|
|
1438
|
+
formatPid(pid) {
|
|
1439
|
+
return `[${this.options.prefix}] ${pid} - `;
|
|
1440
|
+
}
|
|
1441
|
+
formatContext(context) {
|
|
1442
|
+
if (!context) {
|
|
1443
|
+
return "";
|
|
1444
|
+
}
|
|
1445
|
+
context = `[${context}] `;
|
|
1446
|
+
return this.options.colors ? yellow(context) : context;
|
|
1447
|
+
}
|
|
1448
|
+
formatMessage(logLevel, message, pidMessage, formattedLogLevel, contextMessage, timestampDiff) {
|
|
1449
|
+
const output = this.stringifyMessage(message, logLevel);
|
|
1450
|
+
pidMessage = this.colorize(pidMessage, logLevel);
|
|
1451
|
+
formattedLogLevel = this.colorize(formattedLogLevel, logLevel);
|
|
1452
|
+
return `${pidMessage}${this.getTimestamp()} ${formattedLogLevel} ${contextMessage}${output}${timestampDiff}
|
|
1453
|
+
`;
|
|
1454
|
+
}
|
|
1455
|
+
stringifyMessage(message, logLevel) {
|
|
1456
|
+
if (isFunction(message)) {
|
|
1457
|
+
const messageAsStr = Function.prototype.toString.call(message);
|
|
1458
|
+
const isClass = messageAsStr.startsWith("class ");
|
|
1459
|
+
if (isClass) {
|
|
1460
|
+
return this.stringifyMessage(message.name, logLevel);
|
|
1461
|
+
}
|
|
1462
|
+
return this.stringifyMessage(message(), logLevel);
|
|
1463
|
+
}
|
|
1464
|
+
if (typeof message === "string") {
|
|
1465
|
+
return this.colorize(message, logLevel);
|
|
1466
|
+
}
|
|
1467
|
+
const outputText = inspect(message, this.inspectOptions);
|
|
1468
|
+
if (isPlainObject(message)) {
|
|
1469
|
+
return `Object(${Object.keys(message).length}) ${outputText}`;
|
|
1470
|
+
}
|
|
1471
|
+
if (Array.isArray(message)) {
|
|
1472
|
+
return `Array(${message.length}) ${outputText}`;
|
|
1473
|
+
}
|
|
1474
|
+
return outputText;
|
|
1475
|
+
}
|
|
1476
|
+
colorize(message, logLevel) {
|
|
1477
|
+
if (!this.options.colors || this.options.json) {
|
|
1478
|
+
return message;
|
|
1479
|
+
}
|
|
1480
|
+
const color = this.getColorByLogLevel(logLevel);
|
|
1481
|
+
return color(message);
|
|
1482
|
+
}
|
|
1483
|
+
printStackTrace(stack) {
|
|
1484
|
+
if (!stack || this.options.json) {
|
|
1485
|
+
return;
|
|
1486
|
+
}
|
|
1487
|
+
process.stderr.write(`${stack}
|
|
1488
|
+
`);
|
|
1489
|
+
}
|
|
1490
|
+
updateAndGetTimestampDiff() {
|
|
1491
|
+
var _a;
|
|
1492
|
+
const includeTimestamp = _ConsoleLogger.lastTimestampAt && ((_a = this.options) == null ? void 0 : _a.timestamp);
|
|
1493
|
+
const result = includeTimestamp ? this.formatTimestampDiff(Date.now() - _ConsoleLogger.lastTimestampAt) : "";
|
|
1494
|
+
_ConsoleLogger.lastTimestampAt = Date.now();
|
|
1495
|
+
return result;
|
|
1496
|
+
}
|
|
1497
|
+
formatTimestampDiff(timestampDiff) {
|
|
1498
|
+
const formattedDiff = ` +${timestampDiff}ms`;
|
|
1499
|
+
return this.options.colors ? yellow(formattedDiff) : formattedDiff;
|
|
1500
|
+
}
|
|
1501
|
+
getInspectOptions() {
|
|
1502
|
+
let breakLength = this.options.breakLength;
|
|
1503
|
+
if (typeof breakLength === "undefined") {
|
|
1504
|
+
breakLength = this.options.colors ? this.options.compact ? Infinity : void 0 : this.options.compact === false ? void 0 : Infinity;
|
|
1505
|
+
}
|
|
1506
|
+
const inspectOptions = {
|
|
1507
|
+
depth: this.options.depth ?? DEFAULT_DEPTH,
|
|
1508
|
+
sorted: this.options.sorted,
|
|
1509
|
+
showHidden: this.options.showHidden,
|
|
1510
|
+
compact: this.options.compact ?? (this.options.json ? true : false),
|
|
1511
|
+
colors: this.options.colors,
|
|
1512
|
+
breakLength
|
|
1513
|
+
};
|
|
1514
|
+
if (this.options.maxArrayLength) {
|
|
1515
|
+
inspectOptions.maxArrayLength = this.options.maxArrayLength;
|
|
1516
|
+
}
|
|
1517
|
+
if (this.options.maxStringLength) {
|
|
1518
|
+
inspectOptions.maxStringLength = this.options.maxStringLength;
|
|
1519
|
+
}
|
|
1520
|
+
return inspectOptions;
|
|
1521
|
+
}
|
|
1522
|
+
stringifyReplacer(key, value) {
|
|
1523
|
+
if (typeof value === "bigint") {
|
|
1524
|
+
return value.toString();
|
|
1525
|
+
}
|
|
1526
|
+
if (typeof value === "symbol") {
|
|
1527
|
+
return value.toString();
|
|
1528
|
+
}
|
|
1529
|
+
if (value instanceof Map || value instanceof Set || value instanceof Error) {
|
|
1530
|
+
return `${inspect(value, this.inspectOptions)}`;
|
|
1531
|
+
}
|
|
1532
|
+
return value;
|
|
1533
|
+
}
|
|
1534
|
+
getContextAndMessagesToPrint(args) {
|
|
1535
|
+
if ((args == null ? void 0 : args.length) <= 1) {
|
|
1536
|
+
return { messages: args, context: this.context };
|
|
1537
|
+
}
|
|
1538
|
+
const lastElement = args[args.length - 1];
|
|
1539
|
+
const isContext = isString(lastElement);
|
|
1540
|
+
if (!isContext) {
|
|
1541
|
+
return { messages: args, context: this.context };
|
|
1542
|
+
}
|
|
1543
|
+
return {
|
|
1544
|
+
context: lastElement,
|
|
1545
|
+
messages: args.slice(0, args.length - 1)
|
|
1546
|
+
};
|
|
1547
|
+
}
|
|
1548
|
+
getContextAndStackAndMessagesToPrint(args) {
|
|
1549
|
+
if (args.length === 2) {
|
|
1550
|
+
return this.isStackFormat(args[1]) ? {
|
|
1551
|
+
messages: [args[0]],
|
|
1552
|
+
stack: args[1],
|
|
1553
|
+
context: this.context
|
|
1554
|
+
} : {
|
|
1555
|
+
messages: [args[0]],
|
|
1556
|
+
context: args[1]
|
|
1557
|
+
};
|
|
1558
|
+
}
|
|
1559
|
+
const { messages, context } = this.getContextAndMessagesToPrint(args);
|
|
1560
|
+
if ((messages == null ? void 0 : messages.length) <= 1) {
|
|
1561
|
+
return { messages, context };
|
|
1562
|
+
}
|
|
1563
|
+
const lastElement = messages[messages.length - 1];
|
|
1564
|
+
const isStack = isString(lastElement);
|
|
1565
|
+
if (!isStack && !isUndefined(lastElement)) {
|
|
1566
|
+
return { messages, context };
|
|
1567
|
+
}
|
|
1568
|
+
return {
|
|
1569
|
+
stack: lastElement,
|
|
1570
|
+
messages: messages.slice(0, messages.length - 1),
|
|
1571
|
+
context
|
|
1572
|
+
};
|
|
1573
|
+
}
|
|
1574
|
+
isStackFormat(stack) {
|
|
1575
|
+
if (!isString(stack) && !isUndefined(stack)) {
|
|
1576
|
+
return false;
|
|
1577
|
+
}
|
|
1578
|
+
return /^(.)+\n\s+at .+:\d+:\d+/.test(stack);
|
|
1579
|
+
}
|
|
1580
|
+
getColorByLogLevel(level) {
|
|
1581
|
+
switch (level) {
|
|
1582
|
+
case "debug":
|
|
1583
|
+
return clc.magentaBright;
|
|
1584
|
+
case "warn":
|
|
1585
|
+
return clc.yellow;
|
|
1586
|
+
case "error":
|
|
1587
|
+
return clc.red;
|
|
1588
|
+
case "verbose":
|
|
1589
|
+
return clc.cyanBright;
|
|
1590
|
+
case "fatal":
|
|
1591
|
+
return clc.bold;
|
|
1592
|
+
default:
|
|
1593
|
+
return clc.green;
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
};
|
|
1597
|
+
_init = __decoratorStart(null);
|
|
1598
|
+
_ConsoleLogger = __decorateElement(_init, 0, "ConsoleLogger", _ConsoleLogger_decorators, _ConsoleLogger);
|
|
1599
|
+
__runInitializers(_init, 1, _ConsoleLogger);
|
|
1600
|
+
var ConsoleLogger = _ConsoleLogger;
|
|
1601
|
+
|
|
1602
|
+
// packages/core/src/logger/logger.factory.mts
|
|
1603
|
+
import { z } from "zod";
|
|
1604
|
+
|
|
1605
|
+
// packages/core/src/logger/logger.service.mts
|
|
1606
|
+
var DEFAULT_LOGGER = new ConsoleLogger();
|
|
1607
|
+
var dateTimeFormatter2 = new Intl.DateTimeFormat(void 0, {
|
|
1608
|
+
year: "numeric",
|
|
1609
|
+
hour: "numeric",
|
|
1610
|
+
minute: "numeric",
|
|
1611
|
+
second: "numeric",
|
|
1612
|
+
day: "2-digit",
|
|
1613
|
+
month: "2-digit"
|
|
1614
|
+
});
|
|
1615
|
+
var _LoggerInstance_decorators, _init2;
|
|
1616
|
+
_LoggerInstance_decorators = [Injectable()];
|
|
1617
|
+
var _LoggerInstance = class _LoggerInstance {
|
|
1618
|
+
constructor(context, options = {}) {
|
|
1619
|
+
this.context = context;
|
|
1620
|
+
this.options = options;
|
|
1621
|
+
}
|
|
1622
|
+
static staticInstanceRef = DEFAULT_LOGGER;
|
|
1623
|
+
static logLevels;
|
|
1624
|
+
localInstanceRef;
|
|
1625
|
+
get localInstance() {
|
|
1626
|
+
if (_LoggerInstance.staticInstanceRef === DEFAULT_LOGGER) {
|
|
1627
|
+
return this.registerLocalInstanceRef();
|
|
1628
|
+
} else if (_LoggerInstance.staticInstanceRef instanceof _LoggerInstance) {
|
|
1629
|
+
const prototype = Object.getPrototypeOf(_LoggerInstance.staticInstanceRef);
|
|
1630
|
+
if (prototype.constructor === _LoggerInstance) {
|
|
1631
|
+
return this.registerLocalInstanceRef();
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
return _LoggerInstance.staticInstanceRef;
|
|
1635
|
+
}
|
|
1636
|
+
error(message, ...optionalParams) {
|
|
1637
|
+
var _a;
|
|
1638
|
+
optionalParams = this.context ? (optionalParams.length ? optionalParams : [void 0]).concat(
|
|
1639
|
+
this.context
|
|
1640
|
+
) : optionalParams;
|
|
1641
|
+
(_a = this.localInstance) == null ? void 0 : _a.error(message, ...optionalParams);
|
|
1642
|
+
}
|
|
1643
|
+
log(message, ...optionalParams) {
|
|
1644
|
+
var _a;
|
|
1645
|
+
optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
|
|
1646
|
+
(_a = this.localInstance) == null ? void 0 : _a.log(message, ...optionalParams);
|
|
1647
|
+
}
|
|
1648
|
+
warn(message, ...optionalParams) {
|
|
1649
|
+
var _a;
|
|
1650
|
+
optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
|
|
1651
|
+
(_a = this.localInstance) == null ? void 0 : _a.warn(message, ...optionalParams);
|
|
1652
|
+
}
|
|
1653
|
+
debug(message, ...optionalParams) {
|
|
1654
|
+
var _a, _b;
|
|
1655
|
+
optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
|
|
1656
|
+
(_b = (_a = this.localInstance) == null ? void 0 : _a.debug) == null ? void 0 : _b.call(_a, message, ...optionalParams);
|
|
1657
|
+
}
|
|
1658
|
+
verbose(message, ...optionalParams) {
|
|
1659
|
+
var _a, _b;
|
|
1660
|
+
optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
|
|
1661
|
+
(_b = (_a = this.localInstance) == null ? void 0 : _a.verbose) == null ? void 0 : _b.call(_a, message, ...optionalParams);
|
|
1662
|
+
}
|
|
1663
|
+
fatal(message, ...optionalParams) {
|
|
1664
|
+
var _a, _b;
|
|
1665
|
+
optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
|
|
1666
|
+
(_b = (_a = this.localInstance) == null ? void 0 : _a.fatal) == null ? void 0 : _b.call(_a, message, ...optionalParams);
|
|
1667
|
+
}
|
|
1668
|
+
static error(message, ...optionalParams) {
|
|
1669
|
+
var _a;
|
|
1670
|
+
(_a = this.staticInstanceRef) == null ? void 0 : _a.error(message, ...optionalParams);
|
|
1671
|
+
}
|
|
1672
|
+
static log(message, ...optionalParams) {
|
|
1673
|
+
var _a;
|
|
1674
|
+
(_a = this.staticInstanceRef) == null ? void 0 : _a.log(message, ...optionalParams);
|
|
1675
|
+
}
|
|
1676
|
+
static warn(message, ...optionalParams) {
|
|
1677
|
+
var _a;
|
|
1678
|
+
(_a = this.staticInstanceRef) == null ? void 0 : _a.warn(message, ...optionalParams);
|
|
1679
|
+
}
|
|
1680
|
+
static debug(message, ...optionalParams) {
|
|
1681
|
+
var _a, _b;
|
|
1682
|
+
(_b = (_a = this.staticInstanceRef) == null ? void 0 : _a.debug) == null ? void 0 : _b.call(_a, message, ...optionalParams);
|
|
1683
|
+
}
|
|
1684
|
+
static verbose(message, ...optionalParams) {
|
|
1685
|
+
var _a, _b;
|
|
1686
|
+
(_b = (_a = this.staticInstanceRef) == null ? void 0 : _a.verbose) == null ? void 0 : _b.call(_a, message, ...optionalParams);
|
|
1687
|
+
}
|
|
1688
|
+
static fatal(message, ...optionalParams) {
|
|
1689
|
+
var _a, _b;
|
|
1690
|
+
(_b = (_a = this.staticInstanceRef) == null ? void 0 : _a.fatal) == null ? void 0 : _b.call(_a, message, ...optionalParams);
|
|
1691
|
+
}
|
|
1692
|
+
static getTimestamp() {
|
|
1693
|
+
return dateTimeFormatter2.format(Date.now());
|
|
1694
|
+
}
|
|
1695
|
+
static overrideLogger(logger) {
|
|
1696
|
+
var _a, _b;
|
|
1697
|
+
console.log(logger);
|
|
1698
|
+
if (Array.isArray(logger)) {
|
|
1699
|
+
_LoggerInstance.logLevels = logger;
|
|
1700
|
+
return (_b = (_a = this.staticInstanceRef) == null ? void 0 : _a.setLogLevels) == null ? void 0 : _b.call(_a, logger);
|
|
1701
|
+
}
|
|
1702
|
+
if (isObject(logger)) {
|
|
1703
|
+
this.staticInstanceRef = logger;
|
|
1704
|
+
} else {
|
|
1705
|
+
this.staticInstanceRef = void 0;
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
static isLevelEnabled(level) {
|
|
1709
|
+
const logLevels = _LoggerInstance.logLevels;
|
|
1710
|
+
return isLogLevelEnabled(level, logLevels);
|
|
1711
|
+
}
|
|
1712
|
+
registerLocalInstanceRef() {
|
|
1713
|
+
var _a;
|
|
1714
|
+
if (this.localInstanceRef) {
|
|
1715
|
+
return this.localInstanceRef;
|
|
1716
|
+
}
|
|
1717
|
+
this.localInstanceRef = new ConsoleLogger(this.context, {
|
|
1718
|
+
timestamp: (_a = this.options) == null ? void 0 : _a.timestamp,
|
|
1719
|
+
logLevels: _LoggerInstance.logLevels
|
|
1720
|
+
});
|
|
1721
|
+
return this.localInstanceRef;
|
|
1722
|
+
}
|
|
1723
|
+
};
|
|
1724
|
+
_init2 = __decoratorStart(null);
|
|
1725
|
+
_LoggerInstance = __decorateElement(_init2, 0, "LoggerInstance", _LoggerInstance_decorators, _LoggerInstance);
|
|
1726
|
+
__runInitializers(_init2, 1, _LoggerInstance);
|
|
1727
|
+
var LoggerInstance = _LoggerInstance;
|
|
1728
|
+
|
|
1729
|
+
// packages/core/src/logger/logger.factory.mts
|
|
1730
|
+
var LoggerInjectionToken = "LoggerInjectionToken";
|
|
1731
|
+
var LoggerOptions = z.object({
|
|
1732
|
+
context: z.string().optional(),
|
|
1733
|
+
options: z.object({
|
|
1734
|
+
timestamp: z.boolean().optional()
|
|
1735
|
+
}).optional()
|
|
1736
|
+
}).optional();
|
|
1737
|
+
var Logger = InjectionToken.create(LoggerInjectionToken, LoggerOptions);
|
|
1738
|
+
var _LoggerFactory_decorators, _init3;
|
|
1739
|
+
_LoggerFactory_decorators = [Injectable({
|
|
1740
|
+
type: "Factory" /* Factory */,
|
|
1741
|
+
token: Logger
|
|
1742
|
+
})];
|
|
1743
|
+
var LoggerFactory = class {
|
|
1744
|
+
create(ctx, args) {
|
|
1745
|
+
return new LoggerInstance(args == null ? void 0 : args.context, args == null ? void 0 : args.options);
|
|
1746
|
+
}
|
|
1747
|
+
};
|
|
1748
|
+
_init3 = __decoratorStart(null);
|
|
1749
|
+
LoggerFactory = __decorateElement(_init3, 0, "LoggerFactory", _LoggerFactory_decorators, LoggerFactory);
|
|
1750
|
+
__runInitializers(_init3, 1, LoggerFactory);
|
|
1751
|
+
|
|
1752
|
+
// packages/core/src/logger/pino-wrapper.mts
|
|
1753
|
+
var PinoWrapper = class _PinoWrapper {
|
|
1754
|
+
constructor(logger) {
|
|
1755
|
+
this.logger = logger;
|
|
1756
|
+
}
|
|
1757
|
+
fatal(message, ...optionalParams) {
|
|
1758
|
+
if (this.logger.fatal === void 0) {
|
|
1759
|
+
return this.error(message, ...optionalParams);
|
|
1760
|
+
}
|
|
1761
|
+
this.logger.fatal(message, ...optionalParams);
|
|
1762
|
+
}
|
|
1763
|
+
error(message, ...optionalParams) {
|
|
1764
|
+
this.logger.error(message, ...optionalParams);
|
|
1765
|
+
}
|
|
1766
|
+
warn(message, ...optionalParams) {
|
|
1767
|
+
this.logger.warn(message, ...optionalParams);
|
|
1768
|
+
}
|
|
1769
|
+
info(message, ...optionalParams) {
|
|
1770
|
+
this.logger.log(message, ...optionalParams);
|
|
1771
|
+
}
|
|
1772
|
+
debug(message, ...optionalParams) {
|
|
1773
|
+
var _a, _b;
|
|
1774
|
+
(_b = (_a = this.logger).debug) == null ? void 0 : _b.call(_a, message, ...optionalParams);
|
|
1775
|
+
}
|
|
1776
|
+
trace(message, ...optionalParams) {
|
|
1777
|
+
var _a, _b;
|
|
1778
|
+
(_b = (_a = this.logger).verbose) == null ? void 0 : _b.call(_a, message, ...optionalParams);
|
|
1779
|
+
}
|
|
1780
|
+
silent(message, ...optionalParams) {
|
|
1781
|
+
}
|
|
1782
|
+
child(options) {
|
|
1783
|
+
const keys = Object.keys(options);
|
|
1784
|
+
let newContext = this.logger["context"] ?? "";
|
|
1785
|
+
if (keys.length > 1) {
|
|
1786
|
+
newContext = `${this.logger["context"] ?? ""}:${JSON.stringify(options)}`;
|
|
1787
|
+
}
|
|
1788
|
+
return new _PinoWrapper(
|
|
1789
|
+
// @ts-expect-error We don't need to support this in the current version
|
|
1790
|
+
new LoggerInstance(newContext, this.logger["options"])
|
|
1791
|
+
);
|
|
1792
|
+
}
|
|
1793
|
+
get level() {
|
|
1794
|
+
if ("level" in this.logger && this.logger.level) {
|
|
1795
|
+
return this.logger.level;
|
|
1796
|
+
}
|
|
1797
|
+
const levels = LoggerInstance["logLevels"];
|
|
1798
|
+
if (levels) {
|
|
1799
|
+
return levels[0];
|
|
1800
|
+
}
|
|
1801
|
+
return "info";
|
|
1802
|
+
}
|
|
1803
|
+
};
|
|
1804
|
+
|
|
1155
1805
|
// packages/core/src/tokens/application.token.mts
|
|
1156
1806
|
var ApplicationInjectionToken = "ApplicationInjectionToken";
|
|
1157
1807
|
var Application = InjectionToken.create(
|
|
@@ -1217,7 +1867,7 @@ var ExecutionContext2 = class {
|
|
|
1217
1867
|
};
|
|
1218
1868
|
|
|
1219
1869
|
// packages/core/src/services/guard-runner.service.mts
|
|
1220
|
-
var _GuardRunnerService_decorators,
|
|
1870
|
+
var _GuardRunnerService_decorators, _init4;
|
|
1221
1871
|
_GuardRunnerService_decorators = [Injectable()];
|
|
1222
1872
|
var GuardRunnerService = class {
|
|
1223
1873
|
async runGuards(allGuards, executionContext) {
|
|
@@ -1280,15 +1930,18 @@ var GuardRunnerService = class {
|
|
|
1280
1930
|
return guards;
|
|
1281
1931
|
}
|
|
1282
1932
|
};
|
|
1283
|
-
|
|
1284
|
-
GuardRunnerService = __decorateElement(
|
|
1285
|
-
__runInitializers(
|
|
1933
|
+
_init4 = __decoratorStart(null);
|
|
1934
|
+
GuardRunnerService = __decorateElement(_init4, 0, "GuardRunnerService", _GuardRunnerService_decorators, GuardRunnerService);
|
|
1935
|
+
__runInitializers(_init4, 1, GuardRunnerService);
|
|
1286
1936
|
|
|
1287
1937
|
// packages/core/src/services/controller-adapter.service.mts
|
|
1288
|
-
var _ControllerAdapterService_decorators,
|
|
1938
|
+
var _ControllerAdapterService_decorators, _init5;
|
|
1289
1939
|
_ControllerAdapterService_decorators = [Injectable()];
|
|
1290
|
-
var
|
|
1940
|
+
var _ControllerAdapterService = class _ControllerAdapterService {
|
|
1291
1941
|
guardRunner = syncInject(GuardRunnerService);
|
|
1942
|
+
logger = syncInject(Logger, {
|
|
1943
|
+
context: _ControllerAdapterService.name
|
|
1944
|
+
});
|
|
1292
1945
|
setupController(controller, instance, moduleMetadata) {
|
|
1293
1946
|
const controllerMetadata = extractControllerMetadata(controller);
|
|
1294
1947
|
for (const endpoint of controllerMetadata.endpoints) {
|
|
@@ -1383,17 +2036,24 @@ var ControllerAdapterService = class {
|
|
|
1383
2036
|
}
|
|
1384
2037
|
}
|
|
1385
2038
|
});
|
|
2039
|
+
this.logger.debug(
|
|
2040
|
+
`Registered ${httpMethod} ${url} for ${controller.name}:${classMethod}`
|
|
2041
|
+
);
|
|
1386
2042
|
}
|
|
1387
2043
|
}
|
|
1388
2044
|
};
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
__runInitializers(
|
|
2045
|
+
_init5 = __decoratorStart(null);
|
|
2046
|
+
_ControllerAdapterService = __decorateElement(_init5, 0, "ControllerAdapterService", _ControllerAdapterService_decorators, _ControllerAdapterService);
|
|
2047
|
+
__runInitializers(_init5, 1, _ControllerAdapterService);
|
|
2048
|
+
var ControllerAdapterService = _ControllerAdapterService;
|
|
1392
2049
|
|
|
1393
2050
|
// packages/core/src/services/module-loader.service.mts
|
|
1394
|
-
var _ModuleLoaderService_decorators,
|
|
2051
|
+
var _ModuleLoaderService_decorators, _init6;
|
|
1395
2052
|
_ModuleLoaderService_decorators = [Injectable()];
|
|
1396
|
-
var
|
|
2053
|
+
var _ModuleLoaderService = class _ModuleLoaderService {
|
|
2054
|
+
logger = syncInject(Logger, {
|
|
2055
|
+
context: _ModuleLoaderService.name
|
|
2056
|
+
});
|
|
1397
2057
|
modulesMetadata = /* @__PURE__ */ new Map();
|
|
1398
2058
|
loadedModules = /* @__PURE__ */ new Map();
|
|
1399
2059
|
initialized = false;
|
|
@@ -1423,6 +2083,7 @@ var ModuleLoaderService = class {
|
|
|
1423
2083
|
if (instance.onModuleInit) {
|
|
1424
2084
|
await instance.onModuleInit();
|
|
1425
2085
|
}
|
|
2086
|
+
this.logger.debug(`Module ${moduleName} loaded`);
|
|
1426
2087
|
this.loadedModules.set(moduleName, instance);
|
|
1427
2088
|
}
|
|
1428
2089
|
mergeMetadata(metadata, parentMetadata) {
|
|
@@ -1444,9 +2105,10 @@ var ModuleLoaderService = class {
|
|
|
1444
2105
|
return this.modulesMetadata;
|
|
1445
2106
|
}
|
|
1446
2107
|
};
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
__runInitializers(
|
|
2108
|
+
_init6 = __decoratorStart(null);
|
|
2109
|
+
_ModuleLoaderService = __decorateElement(_init6, 0, "ModuleLoaderService", _ModuleLoaderService_decorators, _ModuleLoaderService);
|
|
2110
|
+
__runInitializers(_init6, 1, _ModuleLoaderService);
|
|
2111
|
+
var ModuleLoaderService = _ModuleLoaderService;
|
|
1450
2112
|
|
|
1451
2113
|
// packages/core/src/attribute.factory.mts
|
|
1452
2114
|
var AttributeFactory = class {
|
|
@@ -1512,11 +2174,14 @@ import {
|
|
|
1512
2174
|
serializerCompiler,
|
|
1513
2175
|
validatorCompiler
|
|
1514
2176
|
} from "fastify-type-provider-zod";
|
|
1515
|
-
var _NaviosApplication_decorators,
|
|
2177
|
+
var _NaviosApplication_decorators, _init7;
|
|
1516
2178
|
_NaviosApplication_decorators = [Injectable()];
|
|
1517
|
-
var
|
|
2179
|
+
var _NaviosApplication = class _NaviosApplication {
|
|
1518
2180
|
moduleLoader = syncInject(ModuleLoaderService);
|
|
1519
2181
|
controllerAdapter = syncInject(ControllerAdapterService);
|
|
2182
|
+
logger = syncInject(Logger, {
|
|
2183
|
+
context: _NaviosApplication.name
|
|
2184
|
+
});
|
|
1520
2185
|
server = null;
|
|
1521
2186
|
corsOptions = null;
|
|
1522
2187
|
globalPrefix = null;
|
|
@@ -1531,40 +2196,72 @@ var NaviosApplication = class {
|
|
|
1531
2196
|
throw new Error("App module is not set. Call setAppModule() first.");
|
|
1532
2197
|
}
|
|
1533
2198
|
await this.moduleLoader.loadModules(this.appModule);
|
|
1534
|
-
this.server =
|
|
2199
|
+
this.server = await this.getFastifyInstance(this.options);
|
|
1535
2200
|
getServiceLocator().registerInstance(Application, this.server);
|
|
1536
2201
|
this.server.setValidatorCompiler(validatorCompiler);
|
|
1537
2202
|
this.server.setSerializerCompiler(serializerCompiler);
|
|
1538
2203
|
if (this.corsOptions) {
|
|
1539
2204
|
await this.server.register(cors, this.corsOptions);
|
|
1540
2205
|
}
|
|
2206
|
+
await this.initModules();
|
|
2207
|
+
this.logger.debug("Navios application initialized");
|
|
2208
|
+
}
|
|
2209
|
+
async getFastifyInstance(rawOptions) {
|
|
2210
|
+
const { logger, ...options } = rawOptions;
|
|
2211
|
+
if (logger) {
|
|
2212
|
+
const fastifyOptions = options;
|
|
2213
|
+
if (typeof logger === "boolean") {
|
|
2214
|
+
if (!logger) {
|
|
2215
|
+
fastifyOptions.logger = false;
|
|
2216
|
+
}
|
|
2217
|
+
} else {
|
|
2218
|
+
fastifyOptions.loggerInstance = new PinoWrapper(
|
|
2219
|
+
await inject(Logger, {
|
|
2220
|
+
context: "FastifyAdapter"
|
|
2221
|
+
})
|
|
2222
|
+
);
|
|
2223
|
+
}
|
|
2224
|
+
return fastify(fastifyOptions);
|
|
2225
|
+
} else {
|
|
2226
|
+
return fastify({
|
|
2227
|
+
...options,
|
|
2228
|
+
loggerInstance: new PinoWrapper(
|
|
2229
|
+
await inject(Logger, {
|
|
2230
|
+
context: "FastifyAdapter"
|
|
2231
|
+
})
|
|
2232
|
+
)
|
|
2233
|
+
});
|
|
2234
|
+
}
|
|
2235
|
+
}
|
|
2236
|
+
async initModules() {
|
|
1541
2237
|
const modules = this.moduleLoader.getAllModules();
|
|
1542
|
-
const
|
|
2238
|
+
const promises = [];
|
|
1543
2239
|
for (const [moduleName, moduleMetadata] of modules) {
|
|
1544
2240
|
if (!moduleMetadata.controllers || moduleMetadata.controllers.size === 0) {
|
|
1545
2241
|
continue;
|
|
1546
2242
|
}
|
|
1547
|
-
|
|
1548
|
-
(
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
2243
|
+
promises.push(
|
|
2244
|
+
this.server.register(
|
|
2245
|
+
(instance, opts, done) => {
|
|
2246
|
+
for (const controller of moduleMetadata.controllers) {
|
|
2247
|
+
this.controllerAdapter.setupController(
|
|
2248
|
+
controller,
|
|
2249
|
+
instance,
|
|
2250
|
+
moduleMetadata
|
|
2251
|
+
);
|
|
2252
|
+
}
|
|
2253
|
+
done();
|
|
2254
|
+
},
|
|
2255
|
+
{
|
|
2256
|
+
prefix: this.globalPrefix ?? ""
|
|
1555
2257
|
}
|
|
1556
|
-
|
|
1557
|
-
},
|
|
1558
|
-
{
|
|
1559
|
-
prefix: globalPrefix
|
|
1560
|
-
}
|
|
2258
|
+
)
|
|
1561
2259
|
);
|
|
1562
2260
|
}
|
|
2261
|
+
await Promise.all(promises);
|
|
1563
2262
|
}
|
|
1564
2263
|
enableCors(options) {
|
|
1565
|
-
var _a;
|
|
1566
2264
|
this.corsOptions = options;
|
|
1567
|
-
(_a = this.server) == null ? void 0 : _a.register;
|
|
1568
2265
|
}
|
|
1569
2266
|
setGlobalPrefix(prefix) {
|
|
1570
2267
|
this.globalPrefix = prefix;
|
|
@@ -1582,23 +2279,35 @@ var NaviosApplication = class {
|
|
|
1582
2279
|
await this.server.listen(options);
|
|
1583
2280
|
}
|
|
1584
2281
|
};
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
__runInitializers(
|
|
2282
|
+
_init7 = __decoratorStart(null);
|
|
2283
|
+
_NaviosApplication = __decorateElement(_init7, 0, "NaviosApplication", _NaviosApplication_decorators, _NaviosApplication);
|
|
2284
|
+
__runInitializers(_init7, 1, _NaviosApplication);
|
|
2285
|
+
var NaviosApplication = _NaviosApplication;
|
|
1588
2286
|
|
|
1589
2287
|
// packages/core/src/navios.factory.mts
|
|
1590
2288
|
var NaviosFactory = class {
|
|
1591
2289
|
static async create(appModule, options = {}) {
|
|
1592
2290
|
const app = await inject(NaviosApplication);
|
|
2291
|
+
this.registerLoggerConfiguration(options);
|
|
1593
2292
|
app.setup(appModule, options);
|
|
1594
2293
|
return app;
|
|
1595
2294
|
}
|
|
2295
|
+
static registerLoggerConfiguration(options) {
|
|
2296
|
+
if (!options) {
|
|
2297
|
+
return;
|
|
2298
|
+
}
|
|
2299
|
+
const { logger } = options;
|
|
2300
|
+
if (logger !== true && !isNil(logger)) {
|
|
2301
|
+
LoggerInstance.overrideLogger(logger);
|
|
2302
|
+
}
|
|
2303
|
+
}
|
|
1596
2304
|
};
|
|
1597
2305
|
export {
|
|
1598
2306
|
Application,
|
|
1599
2307
|
AttributeFactory,
|
|
1600
2308
|
BadRequestException,
|
|
1601
2309
|
ConflictException,
|
|
2310
|
+
ConsoleLogger,
|
|
1602
2311
|
Controller,
|
|
1603
2312
|
ControllerAdapterService,
|
|
1604
2313
|
ControllerMetadataKey,
|
|
@@ -1622,12 +2331,19 @@ export {
|
|
|
1622
2331
|
InstanceExpired,
|
|
1623
2332
|
InstanceNotFound,
|
|
1624
2333
|
InternalServerErrorException,
|
|
2334
|
+
LOG_LEVELS,
|
|
2335
|
+
Logger,
|
|
2336
|
+
LoggerFactory,
|
|
2337
|
+
LoggerInjectionToken,
|
|
2338
|
+
LoggerInstance,
|
|
2339
|
+
LoggerOptions,
|
|
1625
2340
|
Module,
|
|
1626
2341
|
ModuleLoaderService,
|
|
1627
2342
|
ModuleMetadataKey,
|
|
1628
2343
|
NaviosApplication,
|
|
1629
2344
|
NaviosFactory,
|
|
1630
2345
|
NotFoundException,
|
|
2346
|
+
PinoWrapper,
|
|
1631
2347
|
Reply,
|
|
1632
2348
|
Request,
|
|
1633
2349
|
ServiceLocator,
|
|
@@ -1638,8 +2354,11 @@ export {
|
|
|
1638
2354
|
UnauthorizedException,
|
|
1639
2355
|
UnknownError,
|
|
1640
2356
|
UseGuards,
|
|
2357
|
+
addLeadingSlash,
|
|
2358
|
+
clc,
|
|
1641
2359
|
extractControllerMetadata,
|
|
1642
2360
|
extractModuleMetadata,
|
|
2361
|
+
filterLogLevels,
|
|
1643
2362
|
getAllEndpointMetadata,
|
|
1644
2363
|
getControllerMetadata,
|
|
1645
2364
|
getEndpointMetadata,
|
|
@@ -1649,9 +2368,24 @@ export {
|
|
|
1649
2368
|
hasControllerMetadata,
|
|
1650
2369
|
hasModuleMetadata,
|
|
1651
2370
|
inject,
|
|
2371
|
+
isConstructor,
|
|
2372
|
+
isEmpty,
|
|
2373
|
+
isFunction,
|
|
2374
|
+
isLogLevel,
|
|
2375
|
+
isLogLevelEnabled,
|
|
2376
|
+
isNil,
|
|
2377
|
+
isNumber,
|
|
2378
|
+
isObject,
|
|
2379
|
+
isPlainObject,
|
|
2380
|
+
isString,
|
|
2381
|
+
isSymbol,
|
|
2382
|
+
isUndefined,
|
|
2383
|
+
normalizePath,
|
|
1652
2384
|
override,
|
|
1653
2385
|
provideServiceLocator,
|
|
1654
2386
|
setPromiseCollector,
|
|
1655
|
-
|
|
2387
|
+
stripEndSlash,
|
|
2388
|
+
syncInject,
|
|
2389
|
+
yellow
|
|
1656
2390
|
};
|
|
1657
2391
|
//# sourceMappingURL=index.mjs.map
|