@navios/core 0.1.0 → 0.1.2

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.
Files changed (38) hide show
  1. package/dist/index.d.mts +485 -11
  2. package/dist/index.d.ts +485 -11
  3. package/dist/index.js +1028 -136
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +993 -135
  6. package/dist/index.mjs.map +1 -1
  7. package/package.json +1 -1
  8. package/src/config/config-service.interface.mts +16 -0
  9. package/src/config/config.provider.mts +63 -0
  10. package/src/config/config.service.mts +69 -0
  11. package/src/config/index.mts +5 -0
  12. package/src/config/types.mts +58 -0
  13. package/src/config/utils/helpers.mts +23 -0
  14. package/src/config/utils/index.mts +1 -0
  15. package/src/index.mts +2 -0
  16. package/src/logger/README.md +3 -0
  17. package/src/logger/console-logger.service.mts +588 -0
  18. package/src/logger/index.mts +7 -0
  19. package/src/logger/log-levels.mts +12 -0
  20. package/src/logger/logger-service.interface.mts +42 -0
  21. package/src/logger/logger.factory.mts +37 -0
  22. package/src/logger/logger.service.mts +214 -0
  23. package/src/logger/pino-wrapper.mts +63 -0
  24. package/src/logger/utils/cli-colors.util.mts +17 -0
  25. package/src/logger/utils/filter-log-levelts.util.mts +29 -0
  26. package/src/logger/utils/index.mts +5 -0
  27. package/src/logger/utils/is-log-level-enabled.mts +33 -0
  28. package/src/logger/utils/is-log-level.util.mts +10 -0
  29. package/src/logger/utils/shared.utils.mts +51 -0
  30. package/src/navios.application.mts +71 -18
  31. package/src/navios.factory.mts +18 -1
  32. package/src/service-locator/inject.mts +6 -1
  33. package/src/service-locator/injection-token.mts +11 -6
  34. package/src/service-locator/proxy-service-locator.mts +28 -9
  35. package/src/service-locator/service-locator.mts +53 -16
  36. package/src/service-locator/sync-injector.mts +6 -1
  37. package/src/services/controller-adapter.service.mts +8 -0
  38. package/src/services/module-loader.service.mts +6 -1
package/dist/index.mjs CHANGED
@@ -46,115 +46,117 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
46
46
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
47
47
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
48
48
 
49
- // packages/core/src/metadata/endpoint.metadata.mts
50
- var EndpointMetadataKey = Symbol("EndpointMetadataKey");
51
- function getAllEndpointMetadata(context) {
52
- if (context.metadata) {
53
- const metadata = context.metadata[EndpointMetadataKey];
54
- if (metadata) {
55
- return metadata;
56
- } else {
57
- context.metadata[EndpointMetadataKey] = /* @__PURE__ */ new Set();
58
- return context.metadata[EndpointMetadataKey];
59
- }
60
- }
61
- throw new Error("[Navios] Wrong environment.");
49
+ // packages/core/src/config/utils/helpers.mts
50
+ import { env } from "node:process";
51
+ function envInt(key, defaultValue) {
52
+ const envKey = env[key] || process.env[key];
53
+ return envKey ? parseInt(envKey, 10) : defaultValue;
62
54
  }
63
- function getEndpointMetadata(target, context) {
64
- if (context.metadata) {
65
- const metadata = getAllEndpointMetadata(context);
66
- if (metadata) {
67
- const endpointMetadata = Array.from(metadata).find(
68
- (item) => item.classMethod === target.name
69
- );
70
- if (endpointMetadata) {
71
- return endpointMetadata;
72
- } else {
73
- const newMetadata = {
74
- classMethod: target.name,
75
- url: "",
76
- httpMethod: "GET",
77
- config: null,
78
- guards: /* @__PURE__ */ new Set(),
79
- customAttributes: /* @__PURE__ */ new Map()
80
- };
81
- metadata.add(newMetadata);
82
- return newMetadata;
83
- }
84
- }
85
- }
86
- throw new Error("[Navios] Wrong environment.");
55
+ function envString(key, defaultValue) {
56
+ return env[key] || process.env[key] || defaultValue || void 0;
87
57
  }
88
58
 
89
- // packages/core/src/metadata/controller.metadata.mts
90
- var ControllerMetadataKey = Symbol("ControllerMetadataKey");
91
- function getControllerMetadata(target, context) {
92
- if (context.metadata) {
93
- const metadata = context.metadata[ControllerMetadataKey];
94
- if (metadata) {
95
- return metadata;
96
- } else {
97
- const endpointsMetadata = getAllEndpointMetadata(context);
98
- const newMetadata = {
99
- endpoints: endpointsMetadata,
100
- guards: /* @__PURE__ */ new Set(),
101
- customAttributes: /* @__PURE__ */ new Map()
102
- };
103
- context.metadata[ControllerMetadataKey] = newMetadata;
104
- target[ControllerMetadataKey] = newMetadata;
105
- return newMetadata;
106
- }
107
- }
108
- throw new Error("[Navios] Wrong environment.");
59
+ // packages/core/src/config/config.provider.mts
60
+ import { z as z2 } from "zod";
61
+
62
+ // packages/core/src/logger/utils/cli-colors.util.mts
63
+ var isColorAllowed = () => !process.env.NO_COLOR;
64
+ var colorIfAllowed = (colorFn) => (text) => isColorAllowed() ? colorFn(text) : text;
65
+ var clc = {
66
+ bold: colorIfAllowed((text) => `\x1B[1m${text}\x1B[0m`),
67
+ green: colorIfAllowed((text) => `\x1B[32m${text}\x1B[39m`),
68
+ yellow: colorIfAllowed((text) => `\x1B[33m${text}\x1B[39m`),
69
+ red: colorIfAllowed((text) => `\x1B[31m${text}\x1B[39m`),
70
+ magentaBright: colorIfAllowed((text) => `\x1B[95m${text}\x1B[39m`),
71
+ cyanBright: colorIfAllowed((text) => `\x1B[96m${text}\x1B[39m`)
72
+ };
73
+ var yellow = colorIfAllowed(
74
+ (text) => `\x1B[38;5;3m${text}\x1B[39m`
75
+ );
76
+
77
+ // packages/core/src/logger/log-levels.mts
78
+ var LOG_LEVELS = [
79
+ "verbose",
80
+ "debug",
81
+ "log",
82
+ "warn",
83
+ "error",
84
+ "fatal"
85
+ ];
86
+
87
+ // packages/core/src/logger/utils/is-log-level.util.mts
88
+ function isLogLevel(maybeLogLevel) {
89
+ return LOG_LEVELS.includes(maybeLogLevel);
109
90
  }
110
- function extractControllerMetadata(target) {
111
- const metadata = target[ControllerMetadataKey];
112
- if (!metadata) {
113
- throw new Error(
114
- "[Navios] Controller metadata not found. Make sure to use @Controller decorator."
91
+
92
+ // packages/core/src/logger/utils/filter-log-levelts.util.mts
93
+ function filterLogLevels(parseableString = "") {
94
+ const sanitizedString = parseableString.replaceAll(" ", "").toLowerCase();
95
+ if (sanitizedString[0] === ">") {
96
+ const orEqual = sanitizedString[1] === "=";
97
+ const logLevelIndex = LOG_LEVELS.indexOf(
98
+ sanitizedString.substring(orEqual ? 2 : 1)
115
99
  );
100
+ if (logLevelIndex === -1) {
101
+ throw new Error(`parse error (unknown log level): ${sanitizedString}`);
102
+ }
103
+ return LOG_LEVELS.slice(orEqual ? logLevelIndex : logLevelIndex + 1);
104
+ } else if (sanitizedString.includes(",")) {
105
+ return sanitizedString.split(",").filter(isLogLevel);
116
106
  }
117
- return metadata;
118
- }
119
- function hasControllerMetadata(target) {
120
- const metadata = target[ControllerMetadataKey];
121
- return !!metadata;
107
+ return isLogLevel(sanitizedString) ? [sanitizedString] : LOG_LEVELS;
122
108
  }
123
109
 
124
- // packages/core/src/metadata/module.metadata.mts
125
- var ModuleMetadataKey = Symbol("ControllerMetadataKey");
126
- function getModuleMetadata(target, context) {
127
- if (context.metadata) {
128
- const metadata = context.metadata[ModuleMetadataKey];
129
- if (metadata) {
130
- return metadata;
131
- } else {
132
- const newMetadata = {
133
- controllers: /* @__PURE__ */ new Set(),
134
- imports: /* @__PURE__ */ new Set(),
135
- guards: /* @__PURE__ */ new Set(),
136
- customAttributes: /* @__PURE__ */ new Map()
137
- };
138
- context.metadata[ModuleMetadataKey] = newMetadata;
139
- target[ModuleMetadataKey] = newMetadata;
140
- return newMetadata;
141
- }
110
+ // packages/core/src/logger/utils/is-log-level-enabled.mts
111
+ var LOG_LEVEL_VALUES = {
112
+ verbose: 0,
113
+ debug: 1,
114
+ log: 2,
115
+ warn: 3,
116
+ error: 4,
117
+ fatal: 5
118
+ };
119
+ function isLogLevelEnabled(targetLevel, logLevels) {
120
+ var _a;
121
+ if (!logLevels || Array.isArray(logLevels) && (logLevels == null ? void 0 : logLevels.length) === 0) {
122
+ return false;
142
123
  }
143
- throw new Error("[Navios] Wrong environment.");
144
- }
145
- function extractModuleMetadata(target) {
146
- const metadata = target[ModuleMetadataKey];
147
- if (!metadata) {
148
- throw new Error(
149
- "[Navios] Module metadata not found. Make sure to use @Module decorator."
150
- );
124
+ if (logLevels.includes(targetLevel)) {
125
+ return true;
151
126
  }
152
- return metadata;
153
- }
154
- function hasModuleMetadata(target) {
155
- return !!target[ModuleMetadataKey];
127
+ const highestLogLevelValue = (_a = logLevels.map((level) => LOG_LEVEL_VALUES[level]).sort((a, b) => b - a)) == null ? void 0 : _a[0];
128
+ const targetLevelValue = LOG_LEVEL_VALUES[targetLevel];
129
+ return targetLevelValue >= highestLogLevelValue;
156
130
  }
157
131
 
132
+ // packages/core/src/logger/utils/shared.utils.mts
133
+ var isUndefined = (obj) => typeof obj === "undefined";
134
+ var isObject = (fn) => !isNil(fn) && typeof fn === "object";
135
+ var isPlainObject = (fn) => {
136
+ if (!isObject(fn)) {
137
+ return false;
138
+ }
139
+ const proto = Object.getPrototypeOf(fn);
140
+ if (proto === null) {
141
+ return true;
142
+ }
143
+ const ctor = Object.prototype.hasOwnProperty.call(proto, "constructor") && proto.constructor;
144
+ return typeof ctor === "function" && ctor instanceof ctor && Function.prototype.toString.call(ctor) === Function.prototype.toString.call(Object);
145
+ };
146
+ var addLeadingSlash = (path) => path && typeof path === "string" ? path.charAt(0) !== "/" && path.substring(0, 2) !== "{/" ? "/" + path : path : "";
147
+ var normalizePath = (path) => path ? path.startsWith("/") ? ("/" + path.replace(/\/+$/, "")).replace(/\/+/g, "/") : "/" + path.replace(/\/+$/, "") : "/";
148
+ var stripEndSlash = (path) => path[path.length - 1] === "/" ? path.slice(0, path.length - 1) : path;
149
+ var isFunction = (val) => typeof val === "function";
150
+ var isString = (val) => typeof val === "string";
151
+ var isNumber = (val) => typeof val === "number";
152
+ var isConstructor = (val) => val === "constructor";
153
+ var isNil = (val) => isUndefined(val) || val === null;
154
+ var isEmpty = (array) => !(array && array.length > 0);
155
+ var isSymbol = (val) => typeof val === "symbol";
156
+
157
+ // packages/core/src/logger/console-logger.service.mts
158
+ import { inspect } from "util";
159
+
158
160
  // packages/core/src/service-locator/enums/injectable-scope.enum.mts
159
161
  var InjectableScope = /* @__PURE__ */ ((InjectableScope2) => {
160
162
  InjectableScope2["Singleton"] = "Singleton";
@@ -164,6 +166,7 @@ var InjectableScope = /* @__PURE__ */ ((InjectableScope2) => {
164
166
 
165
167
  // packages/core/src/service-locator/injection-token.mts
166
168
  import { randomUUID } from "crypto";
169
+ import "zod";
167
170
  var InjectionToken = class _InjectionToken {
168
171
  constructor(name2, schema) {
169
172
  this.name = name2;
@@ -712,7 +715,15 @@ var ServiceLocator = class {
712
715
  ).then(() => null);
713
716
  }
714
717
  makeInstanceName(token, args) {
715
- let stringifiedArgs = args ? ":" + JSON.stringify(args).replaceAll(/"/g, "").replaceAll(/:/g, "=").replaceAll(/,/g, "|") : "";
718
+ let stringifiedArgs = args ? ":" + JSON.stringify(args, (_, value) => {
719
+ if (typeof value === "function") {
720
+ return `function:${value.name}(${value.length})`;
721
+ }
722
+ if (typeof value === "symbol") {
723
+ return value.toString();
724
+ }
725
+ return value;
726
+ }).replaceAll(/"/g, "").replaceAll(/:/g, "=").replaceAll(/,/g, "|") : "";
716
727
  const { name: name2 } = token;
717
728
  if (typeof name2 === "function") {
718
729
  const className = name2.name;
@@ -988,6 +999,761 @@ function override(token, target) {
988
999
  };
989
1000
  }
990
1001
 
1002
+ // packages/core/src/logger/console-logger.service.mts
1003
+ var DEFAULT_DEPTH = 5;
1004
+ var DEFAULT_LOG_LEVELS = [
1005
+ "log",
1006
+ "error",
1007
+ "warn",
1008
+ "debug",
1009
+ "verbose",
1010
+ "fatal"
1011
+ ];
1012
+ var dateTimeFormatter = new Intl.DateTimeFormat(void 0, {
1013
+ year: "numeric",
1014
+ hour: "numeric",
1015
+ minute: "numeric",
1016
+ second: "numeric",
1017
+ day: "2-digit",
1018
+ month: "2-digit"
1019
+ });
1020
+ var _ConsoleLogger_decorators, _init;
1021
+ _ConsoleLogger_decorators = [Injectable()];
1022
+ var _ConsoleLogger = class _ConsoleLogger {
1023
+ /**
1024
+ * The options of the logger.
1025
+ */
1026
+ options;
1027
+ /**
1028
+ * The context of the logger (can be set manually or automatically inferred).
1029
+ */
1030
+ context;
1031
+ /**
1032
+ * The original context of the logger (set in the constructor).
1033
+ */
1034
+ originalContext;
1035
+ /**
1036
+ * The options used for the "inspect" method.
1037
+ */
1038
+ inspectOptions;
1039
+ /**
1040
+ * The last timestamp at which the log message was printed.
1041
+ */
1042
+ static lastTimestampAt;
1043
+ constructor(contextOrOptions, options) {
1044
+ let [context, opts] = isString(contextOrOptions) ? [contextOrOptions, options] : options ? [void 0, options] : [contextOrOptions == null ? void 0 : contextOrOptions.context, contextOrOptions];
1045
+ opts = opts ?? {};
1046
+ opts.logLevels ??= DEFAULT_LOG_LEVELS;
1047
+ opts.colors ??= opts.colors ?? (opts.json ? false : true);
1048
+ opts.prefix ??= "Navios";
1049
+ this.options = opts;
1050
+ this.inspectOptions = this.getInspectOptions();
1051
+ if (context) {
1052
+ this.context = context;
1053
+ this.originalContext = context;
1054
+ }
1055
+ }
1056
+ log(message, ...optionalParams) {
1057
+ if (!this.isLevelEnabled("log")) {
1058
+ return;
1059
+ }
1060
+ const { messages, context } = this.getContextAndMessagesToPrint([
1061
+ message,
1062
+ ...optionalParams
1063
+ ]);
1064
+ this.printMessages(messages, context, "log");
1065
+ }
1066
+ error(message, ...optionalParams) {
1067
+ if (!this.isLevelEnabled("error")) {
1068
+ return;
1069
+ }
1070
+ const { messages, context, stack } = this.getContextAndStackAndMessagesToPrint([message, ...optionalParams]);
1071
+ this.printMessages(messages, context, "error", "stderr", stack);
1072
+ this.printStackTrace(stack);
1073
+ }
1074
+ warn(message, ...optionalParams) {
1075
+ if (!this.isLevelEnabled("warn")) {
1076
+ return;
1077
+ }
1078
+ const { messages, context } = this.getContextAndMessagesToPrint([
1079
+ message,
1080
+ ...optionalParams
1081
+ ]);
1082
+ this.printMessages(messages, context, "warn");
1083
+ }
1084
+ debug(message, ...optionalParams) {
1085
+ if (!this.isLevelEnabled("debug")) {
1086
+ return;
1087
+ }
1088
+ const { messages, context } = this.getContextAndMessagesToPrint([
1089
+ message,
1090
+ ...optionalParams
1091
+ ]);
1092
+ this.printMessages(messages, context, "debug");
1093
+ }
1094
+ verbose(message, ...optionalParams) {
1095
+ if (!this.isLevelEnabled("verbose")) {
1096
+ return;
1097
+ }
1098
+ const { messages, context } = this.getContextAndMessagesToPrint([
1099
+ message,
1100
+ ...optionalParams
1101
+ ]);
1102
+ this.printMessages(messages, context, "verbose");
1103
+ }
1104
+ fatal(message, ...optionalParams) {
1105
+ if (!this.isLevelEnabled("fatal")) {
1106
+ return;
1107
+ }
1108
+ const { messages, context } = this.getContextAndMessagesToPrint([
1109
+ message,
1110
+ ...optionalParams
1111
+ ]);
1112
+ this.printMessages(messages, context, "fatal");
1113
+ }
1114
+ /**
1115
+ * Set log levels
1116
+ * @param levels log levels
1117
+ */
1118
+ setLogLevels(levels) {
1119
+ if (!this.options) {
1120
+ this.options = {};
1121
+ }
1122
+ this.options.logLevels = levels;
1123
+ }
1124
+ /**
1125
+ * Set logger context
1126
+ * @param context context
1127
+ */
1128
+ setContext(context) {
1129
+ this.context = context;
1130
+ }
1131
+ /**
1132
+ * Resets the logger context to the value that was passed in the constructor.
1133
+ */
1134
+ resetContext() {
1135
+ this.context = this.originalContext;
1136
+ }
1137
+ isLevelEnabled(level) {
1138
+ var _a;
1139
+ const logLevels = (_a = this.options) == null ? void 0 : _a.logLevels;
1140
+ return isLogLevelEnabled(level, logLevels);
1141
+ }
1142
+ getTimestamp() {
1143
+ return dateTimeFormatter.format(Date.now());
1144
+ }
1145
+ printMessages(messages, context = "", logLevel = "log", writeStreamType, errorStack) {
1146
+ messages.forEach((message) => {
1147
+ if (this.options.json) {
1148
+ this.printAsJson(message, {
1149
+ context,
1150
+ logLevel,
1151
+ writeStreamType,
1152
+ errorStack
1153
+ });
1154
+ return;
1155
+ }
1156
+ const pidMessage = this.formatPid(process.pid);
1157
+ const contextMessage = this.formatContext(context);
1158
+ const timestampDiff = this.updateAndGetTimestampDiff();
1159
+ const formattedLogLevel = logLevel.toUpperCase().padStart(7, " ");
1160
+ const formattedMessage = this.formatMessage(
1161
+ logLevel,
1162
+ message,
1163
+ pidMessage,
1164
+ formattedLogLevel,
1165
+ contextMessage,
1166
+ timestampDiff
1167
+ );
1168
+ process[writeStreamType ?? "stdout"].write(formattedMessage);
1169
+ });
1170
+ }
1171
+ printAsJson(message, options) {
1172
+ const logObject = {
1173
+ level: options.logLevel,
1174
+ pid: process.pid,
1175
+ timestamp: Date.now(),
1176
+ message
1177
+ };
1178
+ if (options.context) {
1179
+ logObject.context = options.context;
1180
+ }
1181
+ if (options.errorStack) {
1182
+ logObject.stack = options.errorStack;
1183
+ }
1184
+ const formattedMessage = !this.options.colors && this.inspectOptions.compact === true ? JSON.stringify(logObject, this.stringifyReplacer) : inspect(logObject, this.inspectOptions);
1185
+ process[options.writeStreamType ?? "stdout"].write(`${formattedMessage}
1186
+ `);
1187
+ }
1188
+ formatPid(pid) {
1189
+ return `[${this.options.prefix}] ${pid} - `;
1190
+ }
1191
+ formatContext(context) {
1192
+ if (!context) {
1193
+ return "";
1194
+ }
1195
+ context = `[${context}] `;
1196
+ return this.options.colors ? yellow(context) : context;
1197
+ }
1198
+ formatMessage(logLevel, message, pidMessage, formattedLogLevel, contextMessage, timestampDiff) {
1199
+ const output = this.stringifyMessage(message, logLevel);
1200
+ pidMessage = this.colorize(pidMessage, logLevel);
1201
+ formattedLogLevel = this.colorize(formattedLogLevel, logLevel);
1202
+ return `${pidMessage}${this.getTimestamp()} ${formattedLogLevel} ${contextMessage}${output}${timestampDiff}
1203
+ `;
1204
+ }
1205
+ stringifyMessage(message, logLevel) {
1206
+ if (isFunction(message)) {
1207
+ const messageAsStr = Function.prototype.toString.call(message);
1208
+ const isClass = messageAsStr.startsWith("class ");
1209
+ if (isClass) {
1210
+ return this.stringifyMessage(message.name, logLevel);
1211
+ }
1212
+ return this.stringifyMessage(message(), logLevel);
1213
+ }
1214
+ if (typeof message === "string") {
1215
+ return this.colorize(message, logLevel);
1216
+ }
1217
+ const outputText = inspect(message, this.inspectOptions);
1218
+ if (isPlainObject(message)) {
1219
+ return `Object(${Object.keys(message).length}) ${outputText}`;
1220
+ }
1221
+ if (Array.isArray(message)) {
1222
+ return `Array(${message.length}) ${outputText}`;
1223
+ }
1224
+ return outputText;
1225
+ }
1226
+ colorize(message, logLevel) {
1227
+ if (!this.options.colors || this.options.json) {
1228
+ return message;
1229
+ }
1230
+ const color = this.getColorByLogLevel(logLevel);
1231
+ return color(message);
1232
+ }
1233
+ printStackTrace(stack) {
1234
+ if (!stack || this.options.json) {
1235
+ return;
1236
+ }
1237
+ process.stderr.write(`${stack}
1238
+ `);
1239
+ }
1240
+ updateAndGetTimestampDiff() {
1241
+ var _a;
1242
+ const includeTimestamp = _ConsoleLogger.lastTimestampAt && ((_a = this.options) == null ? void 0 : _a.timestamp);
1243
+ const result = includeTimestamp ? this.formatTimestampDiff(Date.now() - _ConsoleLogger.lastTimestampAt) : "";
1244
+ _ConsoleLogger.lastTimestampAt = Date.now();
1245
+ return result;
1246
+ }
1247
+ formatTimestampDiff(timestampDiff) {
1248
+ const formattedDiff = ` +${timestampDiff}ms`;
1249
+ return this.options.colors ? yellow(formattedDiff) : formattedDiff;
1250
+ }
1251
+ getInspectOptions() {
1252
+ let breakLength = this.options.breakLength;
1253
+ if (typeof breakLength === "undefined") {
1254
+ breakLength = this.options.colors ? this.options.compact ? Infinity : void 0 : this.options.compact === false ? void 0 : Infinity;
1255
+ }
1256
+ const inspectOptions = {
1257
+ depth: this.options.depth ?? DEFAULT_DEPTH,
1258
+ sorted: this.options.sorted,
1259
+ showHidden: this.options.showHidden,
1260
+ compact: this.options.compact ?? (this.options.json ? true : false),
1261
+ colors: this.options.colors,
1262
+ breakLength
1263
+ };
1264
+ if (this.options.maxArrayLength) {
1265
+ inspectOptions.maxArrayLength = this.options.maxArrayLength;
1266
+ }
1267
+ if (this.options.maxStringLength) {
1268
+ inspectOptions.maxStringLength = this.options.maxStringLength;
1269
+ }
1270
+ return inspectOptions;
1271
+ }
1272
+ stringifyReplacer(key, value) {
1273
+ if (typeof value === "bigint") {
1274
+ return value.toString();
1275
+ }
1276
+ if (typeof value === "symbol") {
1277
+ return value.toString();
1278
+ }
1279
+ if (value instanceof Map || value instanceof Set || value instanceof Error) {
1280
+ return `${inspect(value, this.inspectOptions)}`;
1281
+ }
1282
+ return value;
1283
+ }
1284
+ getContextAndMessagesToPrint(args) {
1285
+ if ((args == null ? void 0 : args.length) <= 1) {
1286
+ return { messages: args, context: this.context };
1287
+ }
1288
+ const lastElement = args[args.length - 1];
1289
+ const isContext = isString(lastElement);
1290
+ if (!isContext) {
1291
+ return { messages: args, context: this.context };
1292
+ }
1293
+ return {
1294
+ context: lastElement,
1295
+ messages: args.slice(0, args.length - 1)
1296
+ };
1297
+ }
1298
+ getContextAndStackAndMessagesToPrint(args) {
1299
+ if (args.length === 2) {
1300
+ return this.isStackFormat(args[1]) ? {
1301
+ messages: [args[0]],
1302
+ stack: args[1],
1303
+ context: this.context
1304
+ } : {
1305
+ messages: [args[0]],
1306
+ context: args[1]
1307
+ };
1308
+ }
1309
+ const { messages, context } = this.getContextAndMessagesToPrint(args);
1310
+ if ((messages == null ? void 0 : messages.length) <= 1) {
1311
+ return { messages, context };
1312
+ }
1313
+ const lastElement = messages[messages.length - 1];
1314
+ const isStack = isString(lastElement);
1315
+ if (!isStack && !isUndefined(lastElement)) {
1316
+ return { messages, context };
1317
+ }
1318
+ return {
1319
+ stack: lastElement,
1320
+ messages: messages.slice(0, messages.length - 1),
1321
+ context
1322
+ };
1323
+ }
1324
+ isStackFormat(stack) {
1325
+ if (!isString(stack) && !isUndefined(stack)) {
1326
+ return false;
1327
+ }
1328
+ return /^(.)+\n\s+at .+:\d+:\d+/.test(stack);
1329
+ }
1330
+ getColorByLogLevel(level) {
1331
+ switch (level) {
1332
+ case "debug":
1333
+ return clc.magentaBright;
1334
+ case "warn":
1335
+ return clc.yellow;
1336
+ case "error":
1337
+ return clc.red;
1338
+ case "verbose":
1339
+ return clc.cyanBright;
1340
+ case "fatal":
1341
+ return clc.bold;
1342
+ default:
1343
+ return clc.green;
1344
+ }
1345
+ }
1346
+ };
1347
+ _init = __decoratorStart(null);
1348
+ _ConsoleLogger = __decorateElement(_init, 0, "ConsoleLogger", _ConsoleLogger_decorators, _ConsoleLogger);
1349
+ __runInitializers(_init, 1, _ConsoleLogger);
1350
+ var ConsoleLogger = _ConsoleLogger;
1351
+
1352
+ // packages/core/src/logger/logger.factory.mts
1353
+ import { z } from "zod";
1354
+
1355
+ // packages/core/src/logger/logger.service.mts
1356
+ var DEFAULT_LOGGER = new ConsoleLogger();
1357
+ var dateTimeFormatter2 = new Intl.DateTimeFormat(void 0, {
1358
+ year: "numeric",
1359
+ hour: "numeric",
1360
+ minute: "numeric",
1361
+ second: "numeric",
1362
+ day: "2-digit",
1363
+ month: "2-digit"
1364
+ });
1365
+ var _LoggerInstance_decorators, _init2;
1366
+ _LoggerInstance_decorators = [Injectable()];
1367
+ var _LoggerInstance = class _LoggerInstance {
1368
+ constructor(context, options = {}) {
1369
+ this.context = context;
1370
+ this.options = options;
1371
+ }
1372
+ static staticInstanceRef = DEFAULT_LOGGER;
1373
+ static logLevels;
1374
+ localInstanceRef;
1375
+ get localInstance() {
1376
+ if (_LoggerInstance.staticInstanceRef === DEFAULT_LOGGER) {
1377
+ return this.registerLocalInstanceRef();
1378
+ } else if (_LoggerInstance.staticInstanceRef instanceof _LoggerInstance) {
1379
+ const prototype = Object.getPrototypeOf(_LoggerInstance.staticInstanceRef);
1380
+ if (prototype.constructor === _LoggerInstance) {
1381
+ return this.registerLocalInstanceRef();
1382
+ }
1383
+ }
1384
+ return _LoggerInstance.staticInstanceRef;
1385
+ }
1386
+ error(message, ...optionalParams) {
1387
+ var _a;
1388
+ optionalParams = this.context ? (optionalParams.length ? optionalParams : [void 0]).concat(
1389
+ this.context
1390
+ ) : optionalParams;
1391
+ (_a = this.localInstance) == null ? void 0 : _a.error(message, ...optionalParams);
1392
+ }
1393
+ log(message, ...optionalParams) {
1394
+ var _a;
1395
+ optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1396
+ (_a = this.localInstance) == null ? void 0 : _a.log(message, ...optionalParams);
1397
+ }
1398
+ warn(message, ...optionalParams) {
1399
+ var _a;
1400
+ optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1401
+ (_a = this.localInstance) == null ? void 0 : _a.warn(message, ...optionalParams);
1402
+ }
1403
+ debug(message, ...optionalParams) {
1404
+ var _a, _b;
1405
+ optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1406
+ (_b = (_a = this.localInstance) == null ? void 0 : _a.debug) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1407
+ }
1408
+ verbose(message, ...optionalParams) {
1409
+ var _a, _b;
1410
+ optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1411
+ (_b = (_a = this.localInstance) == null ? void 0 : _a.verbose) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1412
+ }
1413
+ fatal(message, ...optionalParams) {
1414
+ var _a, _b;
1415
+ optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1416
+ (_b = (_a = this.localInstance) == null ? void 0 : _a.fatal) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1417
+ }
1418
+ static error(message, ...optionalParams) {
1419
+ var _a;
1420
+ (_a = this.staticInstanceRef) == null ? void 0 : _a.error(message, ...optionalParams);
1421
+ }
1422
+ static log(message, ...optionalParams) {
1423
+ var _a;
1424
+ (_a = this.staticInstanceRef) == null ? void 0 : _a.log(message, ...optionalParams);
1425
+ }
1426
+ static warn(message, ...optionalParams) {
1427
+ var _a;
1428
+ (_a = this.staticInstanceRef) == null ? void 0 : _a.warn(message, ...optionalParams);
1429
+ }
1430
+ static debug(message, ...optionalParams) {
1431
+ var _a, _b;
1432
+ (_b = (_a = this.staticInstanceRef) == null ? void 0 : _a.debug) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1433
+ }
1434
+ static verbose(message, ...optionalParams) {
1435
+ var _a, _b;
1436
+ (_b = (_a = this.staticInstanceRef) == null ? void 0 : _a.verbose) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1437
+ }
1438
+ static fatal(message, ...optionalParams) {
1439
+ var _a, _b;
1440
+ (_b = (_a = this.staticInstanceRef) == null ? void 0 : _a.fatal) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1441
+ }
1442
+ static getTimestamp() {
1443
+ return dateTimeFormatter2.format(Date.now());
1444
+ }
1445
+ static overrideLogger(logger) {
1446
+ var _a, _b;
1447
+ console.log(logger);
1448
+ if (Array.isArray(logger)) {
1449
+ _LoggerInstance.logLevels = logger;
1450
+ return (_b = (_a = this.staticInstanceRef) == null ? void 0 : _a.setLogLevels) == null ? void 0 : _b.call(_a, logger);
1451
+ }
1452
+ if (isObject(logger)) {
1453
+ this.staticInstanceRef = logger;
1454
+ } else {
1455
+ this.staticInstanceRef = void 0;
1456
+ }
1457
+ }
1458
+ static isLevelEnabled(level) {
1459
+ const logLevels = _LoggerInstance.logLevels;
1460
+ return isLogLevelEnabled(level, logLevels);
1461
+ }
1462
+ registerLocalInstanceRef() {
1463
+ var _a;
1464
+ if (this.localInstanceRef) {
1465
+ return this.localInstanceRef;
1466
+ }
1467
+ this.localInstanceRef = new ConsoleLogger(this.context, {
1468
+ timestamp: (_a = this.options) == null ? void 0 : _a.timestamp,
1469
+ logLevels: _LoggerInstance.logLevels
1470
+ });
1471
+ return this.localInstanceRef;
1472
+ }
1473
+ };
1474
+ _init2 = __decoratorStart(null);
1475
+ _LoggerInstance = __decorateElement(_init2, 0, "LoggerInstance", _LoggerInstance_decorators, _LoggerInstance);
1476
+ __runInitializers(_init2, 1, _LoggerInstance);
1477
+ var LoggerInstance = _LoggerInstance;
1478
+
1479
+ // packages/core/src/logger/logger.factory.mts
1480
+ var LoggerInjectionToken = "LoggerInjectionToken";
1481
+ var LoggerOptions = z.object({
1482
+ context: z.string().optional(),
1483
+ options: z.object({
1484
+ timestamp: z.boolean().optional()
1485
+ }).optional()
1486
+ }).optional();
1487
+ var Logger = InjectionToken.create(LoggerInjectionToken, LoggerOptions);
1488
+ var _LoggerFactory_decorators, _init3;
1489
+ _LoggerFactory_decorators = [Injectable({
1490
+ type: "Factory" /* Factory */,
1491
+ token: Logger
1492
+ })];
1493
+ var LoggerFactory = class {
1494
+ create(ctx, args) {
1495
+ return new LoggerInstance(args == null ? void 0 : args.context, args == null ? void 0 : args.options);
1496
+ }
1497
+ };
1498
+ _init3 = __decoratorStart(null);
1499
+ LoggerFactory = __decorateElement(_init3, 0, "LoggerFactory", _LoggerFactory_decorators, LoggerFactory);
1500
+ __runInitializers(_init3, 1, LoggerFactory);
1501
+
1502
+ // packages/core/src/logger/pino-wrapper.mts
1503
+ var PinoWrapper = class _PinoWrapper {
1504
+ constructor(logger) {
1505
+ this.logger = logger;
1506
+ }
1507
+ fatal(message, ...optionalParams) {
1508
+ if (this.logger.fatal === void 0) {
1509
+ return this.error(message, ...optionalParams);
1510
+ }
1511
+ this.logger.fatal(message, ...optionalParams);
1512
+ }
1513
+ error(message, ...optionalParams) {
1514
+ this.logger.error(message, ...optionalParams);
1515
+ }
1516
+ warn(message, ...optionalParams) {
1517
+ this.logger.warn(message, ...optionalParams);
1518
+ }
1519
+ info(message, ...optionalParams) {
1520
+ this.logger.log(message, ...optionalParams);
1521
+ }
1522
+ debug(message, ...optionalParams) {
1523
+ var _a, _b;
1524
+ (_b = (_a = this.logger).debug) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1525
+ }
1526
+ trace(message, ...optionalParams) {
1527
+ var _a, _b;
1528
+ (_b = (_a = this.logger).verbose) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1529
+ }
1530
+ silent(message, ...optionalParams) {
1531
+ }
1532
+ child(options) {
1533
+ const keys = Object.keys(options);
1534
+ let newContext = this.logger["context"] ?? "";
1535
+ if (keys.length > 1) {
1536
+ newContext = `${this.logger["context"] ?? ""}:${JSON.stringify(options)}`;
1537
+ }
1538
+ return new _PinoWrapper(
1539
+ // @ts-expect-error We don't need to support this in the current version
1540
+ new LoggerInstance(newContext, this.logger["options"])
1541
+ );
1542
+ }
1543
+ get level() {
1544
+ if ("level" in this.logger && this.logger.level) {
1545
+ return this.logger.level;
1546
+ }
1547
+ const levels = LoggerInstance["logLevels"];
1548
+ if (levels) {
1549
+ return levels[0];
1550
+ }
1551
+ return "info";
1552
+ }
1553
+ };
1554
+
1555
+ // packages/core/src/config/config.service.mts
1556
+ import { NaviosException } from "@navios/common";
1557
+ var ConfigServiceInstance = class {
1558
+ constructor(config = {}, logger) {
1559
+ this.config = config;
1560
+ this.logger = logger;
1561
+ }
1562
+ getConfig() {
1563
+ return this.config;
1564
+ }
1565
+ get(key) {
1566
+ var _a, _b;
1567
+ try {
1568
+ const parts = String(key).split(".");
1569
+ let value = this.config;
1570
+ for (const part of parts) {
1571
+ if (value === null || value === void 0 || typeof value !== "object") {
1572
+ return null;
1573
+ }
1574
+ value = value[part];
1575
+ }
1576
+ return value ?? null;
1577
+ } catch (error) {
1578
+ (_b = (_a = this.logger).debug) == null ? void 0 : _b.call(
1579
+ _a,
1580
+ `Failed to get config value for key ${String(key)}`,
1581
+ error
1582
+ );
1583
+ return null;
1584
+ }
1585
+ }
1586
+ getOrDefault(key, defaultValue) {
1587
+ const value = this.get(key);
1588
+ return value !== null ? value : defaultValue;
1589
+ }
1590
+ getOrThrow(key, errorMessage) {
1591
+ const value = this.get(key);
1592
+ if (value === null) {
1593
+ const message = errorMessage || `Configuration value for key "${String(key)}" is not defined`;
1594
+ this.logger.error(message);
1595
+ throw new NaviosException(message);
1596
+ }
1597
+ return value;
1598
+ }
1599
+ };
1600
+
1601
+ // packages/core/src/config/config.provider.mts
1602
+ var ConfigProviderInjectionToken = "ConfigProvider";
1603
+ var ConfigProviderOptions = z2.object({
1604
+ load: z2.function()
1605
+ });
1606
+ var ConfigProvider = InjectionToken.create(ConfigProviderInjectionToken, ConfigProviderOptions);
1607
+ var _ConfigProviderFactory_decorators, _init4;
1608
+ _ConfigProviderFactory_decorators = [Injectable({
1609
+ token: ConfigProvider,
1610
+ type: "Factory" /* Factory */
1611
+ })];
1612
+ var ConfigProviderFactory = class {
1613
+ logger = inject(Logger, {
1614
+ context: "ConfigService"
1615
+ });
1616
+ async create(ctx, args) {
1617
+ const { load } = args;
1618
+ const logger = await this.logger;
1619
+ try {
1620
+ const config = await load();
1621
+ return new ConfigServiceInstance(config, logger);
1622
+ } catch (error) {
1623
+ logger.error("Error loading config", error);
1624
+ throw error;
1625
+ }
1626
+ }
1627
+ };
1628
+ _init4 = __decoratorStart(null);
1629
+ ConfigProviderFactory = __decorateElement(_init4, 0, "ConfigProviderFactory", _ConfigProviderFactory_decorators, ConfigProviderFactory);
1630
+ __runInitializers(_init4, 1, ConfigProviderFactory);
1631
+ function makeConfigToken(options) {
1632
+ var _ConfigServiceImpl_decorators, _init9;
1633
+ _ConfigServiceImpl_decorators = [Injectable({
1634
+ type: "Factory" /* Factory */
1635
+ })];
1636
+ class ConfigServiceImpl {
1637
+ configService = inject(ConfigProvider, options);
1638
+ create() {
1639
+ return this.configService;
1640
+ }
1641
+ }
1642
+ _init9 = __decoratorStart(null);
1643
+ ConfigServiceImpl = __decorateElement(_init9, 0, "ConfigServiceImpl", _ConfigServiceImpl_decorators, ConfigServiceImpl);
1644
+ __runInitializers(_init9, 1, ConfigServiceImpl);
1645
+ return getInjectableToken(ConfigServiceImpl);
1646
+ }
1647
+
1648
+ // packages/core/src/metadata/endpoint.metadata.mts
1649
+ var EndpointMetadataKey = Symbol("EndpointMetadataKey");
1650
+ function getAllEndpointMetadata(context) {
1651
+ if (context.metadata) {
1652
+ const metadata = context.metadata[EndpointMetadataKey];
1653
+ if (metadata) {
1654
+ return metadata;
1655
+ } else {
1656
+ context.metadata[EndpointMetadataKey] = /* @__PURE__ */ new Set();
1657
+ return context.metadata[EndpointMetadataKey];
1658
+ }
1659
+ }
1660
+ throw new Error("[Navios] Wrong environment.");
1661
+ }
1662
+ function getEndpointMetadata(target, context) {
1663
+ if (context.metadata) {
1664
+ const metadata = getAllEndpointMetadata(context);
1665
+ if (metadata) {
1666
+ const endpointMetadata = Array.from(metadata).find(
1667
+ (item) => item.classMethod === target.name
1668
+ );
1669
+ if (endpointMetadata) {
1670
+ return endpointMetadata;
1671
+ } else {
1672
+ const newMetadata = {
1673
+ classMethod: target.name,
1674
+ url: "",
1675
+ httpMethod: "GET",
1676
+ config: null,
1677
+ guards: /* @__PURE__ */ new Set(),
1678
+ customAttributes: /* @__PURE__ */ new Map()
1679
+ };
1680
+ metadata.add(newMetadata);
1681
+ return newMetadata;
1682
+ }
1683
+ }
1684
+ }
1685
+ throw new Error("[Navios] Wrong environment.");
1686
+ }
1687
+
1688
+ // packages/core/src/metadata/controller.metadata.mts
1689
+ var ControllerMetadataKey = Symbol("ControllerMetadataKey");
1690
+ function getControllerMetadata(target, context) {
1691
+ if (context.metadata) {
1692
+ const metadata = context.metadata[ControllerMetadataKey];
1693
+ if (metadata) {
1694
+ return metadata;
1695
+ } else {
1696
+ const endpointsMetadata = getAllEndpointMetadata(context);
1697
+ const newMetadata = {
1698
+ endpoints: endpointsMetadata,
1699
+ guards: /* @__PURE__ */ new Set(),
1700
+ customAttributes: /* @__PURE__ */ new Map()
1701
+ };
1702
+ context.metadata[ControllerMetadataKey] = newMetadata;
1703
+ target[ControllerMetadataKey] = newMetadata;
1704
+ return newMetadata;
1705
+ }
1706
+ }
1707
+ throw new Error("[Navios] Wrong environment.");
1708
+ }
1709
+ function extractControllerMetadata(target) {
1710
+ const metadata = target[ControllerMetadataKey];
1711
+ if (!metadata) {
1712
+ throw new Error(
1713
+ "[Navios] Controller metadata not found. Make sure to use @Controller decorator."
1714
+ );
1715
+ }
1716
+ return metadata;
1717
+ }
1718
+ function hasControllerMetadata(target) {
1719
+ const metadata = target[ControllerMetadataKey];
1720
+ return !!metadata;
1721
+ }
1722
+
1723
+ // packages/core/src/metadata/module.metadata.mts
1724
+ var ModuleMetadataKey = Symbol("ControllerMetadataKey");
1725
+ function getModuleMetadata(target, context) {
1726
+ if (context.metadata) {
1727
+ const metadata = context.metadata[ModuleMetadataKey];
1728
+ if (metadata) {
1729
+ return metadata;
1730
+ } else {
1731
+ const newMetadata = {
1732
+ controllers: /* @__PURE__ */ new Set(),
1733
+ imports: /* @__PURE__ */ new Set(),
1734
+ guards: /* @__PURE__ */ new Set(),
1735
+ customAttributes: /* @__PURE__ */ new Map()
1736
+ };
1737
+ context.metadata[ModuleMetadataKey] = newMetadata;
1738
+ target[ModuleMetadataKey] = newMetadata;
1739
+ return newMetadata;
1740
+ }
1741
+ }
1742
+ throw new Error("[Navios] Wrong environment.");
1743
+ }
1744
+ function extractModuleMetadata(target) {
1745
+ const metadata = target[ModuleMetadataKey];
1746
+ if (!metadata) {
1747
+ throw new Error(
1748
+ "[Navios] Module metadata not found. Make sure to use @Module decorator."
1749
+ );
1750
+ }
1751
+ return metadata;
1752
+ }
1753
+ function hasModuleMetadata(target) {
1754
+ return !!target[ModuleMetadataKey];
1755
+ }
1756
+
991
1757
  // packages/core/src/decorators/controller.decorator.mts
992
1758
  function Controller({ guards } = {}) {
993
1759
  return function(target, context) {
@@ -1217,7 +1983,7 @@ var ExecutionContext2 = class {
1217
1983
  };
1218
1984
 
1219
1985
  // packages/core/src/services/guard-runner.service.mts
1220
- var _GuardRunnerService_decorators, _init;
1986
+ var _GuardRunnerService_decorators, _init5;
1221
1987
  _GuardRunnerService_decorators = [Injectable()];
1222
1988
  var GuardRunnerService = class {
1223
1989
  async runGuards(allGuards, executionContext) {
@@ -1280,15 +2046,18 @@ var GuardRunnerService = class {
1280
2046
  return guards;
1281
2047
  }
1282
2048
  };
1283
- _init = __decoratorStart(null);
1284
- GuardRunnerService = __decorateElement(_init, 0, "GuardRunnerService", _GuardRunnerService_decorators, GuardRunnerService);
1285
- __runInitializers(_init, 1, GuardRunnerService);
2049
+ _init5 = __decoratorStart(null);
2050
+ GuardRunnerService = __decorateElement(_init5, 0, "GuardRunnerService", _GuardRunnerService_decorators, GuardRunnerService);
2051
+ __runInitializers(_init5, 1, GuardRunnerService);
1286
2052
 
1287
2053
  // packages/core/src/services/controller-adapter.service.mts
1288
- var _ControllerAdapterService_decorators, _init2;
2054
+ var _ControllerAdapterService_decorators, _init6;
1289
2055
  _ControllerAdapterService_decorators = [Injectable()];
1290
- var ControllerAdapterService = class {
2056
+ var _ControllerAdapterService = class _ControllerAdapterService {
1291
2057
  guardRunner = syncInject(GuardRunnerService);
2058
+ logger = syncInject(Logger, {
2059
+ context: _ControllerAdapterService.name
2060
+ });
1292
2061
  setupController(controller, instance, moduleMetadata) {
1293
2062
  const controllerMetadata = extractControllerMetadata(controller);
1294
2063
  for (const endpoint of controllerMetadata.endpoints) {
@@ -1383,17 +2152,24 @@ var ControllerAdapterService = class {
1383
2152
  }
1384
2153
  }
1385
2154
  });
2155
+ this.logger.debug(
2156
+ `Registered ${httpMethod} ${url} for ${controller.name}:${classMethod}`
2157
+ );
1386
2158
  }
1387
2159
  }
1388
2160
  };
1389
- _init2 = __decoratorStart(null);
1390
- ControllerAdapterService = __decorateElement(_init2, 0, "ControllerAdapterService", _ControllerAdapterService_decorators, ControllerAdapterService);
1391
- __runInitializers(_init2, 1, ControllerAdapterService);
2161
+ _init6 = __decoratorStart(null);
2162
+ _ControllerAdapterService = __decorateElement(_init6, 0, "ControllerAdapterService", _ControllerAdapterService_decorators, _ControllerAdapterService);
2163
+ __runInitializers(_init6, 1, _ControllerAdapterService);
2164
+ var ControllerAdapterService = _ControllerAdapterService;
1392
2165
 
1393
2166
  // packages/core/src/services/module-loader.service.mts
1394
- var _ModuleLoaderService_decorators, _init3;
2167
+ var _ModuleLoaderService_decorators, _init7;
1395
2168
  _ModuleLoaderService_decorators = [Injectable()];
1396
- var ModuleLoaderService = class {
2169
+ var _ModuleLoaderService = class _ModuleLoaderService {
2170
+ logger = syncInject(Logger, {
2171
+ context: _ModuleLoaderService.name
2172
+ });
1397
2173
  modulesMetadata = /* @__PURE__ */ new Map();
1398
2174
  loadedModules = /* @__PURE__ */ new Map();
1399
2175
  initialized = false;
@@ -1423,6 +2199,7 @@ var ModuleLoaderService = class {
1423
2199
  if (instance.onModuleInit) {
1424
2200
  await instance.onModuleInit();
1425
2201
  }
2202
+ this.logger.debug(`Module ${moduleName} loaded`);
1426
2203
  this.loadedModules.set(moduleName, instance);
1427
2204
  }
1428
2205
  mergeMetadata(metadata, parentMetadata) {
@@ -1444,9 +2221,10 @@ var ModuleLoaderService = class {
1444
2221
  return this.modulesMetadata;
1445
2222
  }
1446
2223
  };
1447
- _init3 = __decoratorStart(null);
1448
- ModuleLoaderService = __decorateElement(_init3, 0, "ModuleLoaderService", _ModuleLoaderService_decorators, ModuleLoaderService);
1449
- __runInitializers(_init3, 1, ModuleLoaderService);
2224
+ _init7 = __decoratorStart(null);
2225
+ _ModuleLoaderService = __decorateElement(_init7, 0, "ModuleLoaderService", _ModuleLoaderService_decorators, _ModuleLoaderService);
2226
+ __runInitializers(_init7, 1, _ModuleLoaderService);
2227
+ var ModuleLoaderService = _ModuleLoaderService;
1450
2228
 
1451
2229
  // packages/core/src/attribute.factory.mts
1452
2230
  var AttributeFactory = class {
@@ -1512,11 +2290,14 @@ import {
1512
2290
  serializerCompiler,
1513
2291
  validatorCompiler
1514
2292
  } from "fastify-type-provider-zod";
1515
- var _NaviosApplication_decorators, _init4;
2293
+ var _NaviosApplication_decorators, _init8;
1516
2294
  _NaviosApplication_decorators = [Injectable()];
1517
- var NaviosApplication = class {
2295
+ var _NaviosApplication = class _NaviosApplication {
1518
2296
  moduleLoader = syncInject(ModuleLoaderService);
1519
2297
  controllerAdapter = syncInject(ControllerAdapterService);
2298
+ logger = syncInject(Logger, {
2299
+ context: _NaviosApplication.name
2300
+ });
1520
2301
  server = null;
1521
2302
  corsOptions = null;
1522
2303
  globalPrefix = null;
@@ -1531,40 +2312,72 @@ var NaviosApplication = class {
1531
2312
  throw new Error("App module is not set. Call setAppModule() first.");
1532
2313
  }
1533
2314
  await this.moduleLoader.loadModules(this.appModule);
1534
- this.server = fastify(this.options);
2315
+ this.server = await this.getFastifyInstance(this.options);
1535
2316
  getServiceLocator().registerInstance(Application, this.server);
1536
2317
  this.server.setValidatorCompiler(validatorCompiler);
1537
2318
  this.server.setSerializerCompiler(serializerCompiler);
1538
2319
  if (this.corsOptions) {
1539
2320
  await this.server.register(cors, this.corsOptions);
1540
2321
  }
2322
+ await this.initModules();
2323
+ this.logger.debug("Navios application initialized");
2324
+ }
2325
+ async getFastifyInstance(rawOptions) {
2326
+ const { logger, ...options } = rawOptions;
2327
+ if (logger) {
2328
+ const fastifyOptions = options;
2329
+ if (typeof logger === "boolean") {
2330
+ if (!logger) {
2331
+ fastifyOptions.logger = false;
2332
+ }
2333
+ } else {
2334
+ fastifyOptions.loggerInstance = new PinoWrapper(
2335
+ await inject(Logger, {
2336
+ context: "FastifyAdapter"
2337
+ })
2338
+ );
2339
+ }
2340
+ return fastify(fastifyOptions);
2341
+ } else {
2342
+ return fastify({
2343
+ ...options,
2344
+ loggerInstance: new PinoWrapper(
2345
+ await inject(Logger, {
2346
+ context: "FastifyAdapter"
2347
+ })
2348
+ )
2349
+ });
2350
+ }
2351
+ }
2352
+ async initModules() {
1541
2353
  const modules = this.moduleLoader.getAllModules();
1542
- const globalPrefix = this.globalPrefix ?? "";
2354
+ const promises = [];
1543
2355
  for (const [moduleName, moduleMetadata] of modules) {
1544
2356
  if (!moduleMetadata.controllers || moduleMetadata.controllers.size === 0) {
1545
2357
  continue;
1546
2358
  }
1547
- this.server.register(
1548
- (instance, opts, done) => {
1549
- for (const controller of moduleMetadata.controllers) {
1550
- this.controllerAdapter.setupController(
1551
- controller,
1552
- instance,
1553
- moduleMetadata
1554
- );
2359
+ promises.push(
2360
+ this.server.register(
2361
+ (instance, opts, done) => {
2362
+ for (const controller of moduleMetadata.controllers) {
2363
+ this.controllerAdapter.setupController(
2364
+ controller,
2365
+ instance,
2366
+ moduleMetadata
2367
+ );
2368
+ }
2369
+ done();
2370
+ },
2371
+ {
2372
+ prefix: this.globalPrefix ?? ""
1555
2373
  }
1556
- done();
1557
- },
1558
- {
1559
- prefix: globalPrefix
1560
- }
2374
+ )
1561
2375
  );
1562
2376
  }
2377
+ await Promise.all(promises);
1563
2378
  }
1564
2379
  enableCors(options) {
1565
- var _a;
1566
2380
  this.corsOptions = options;
1567
- (_a = this.server) == null ? void 0 : _a.register;
1568
2381
  }
1569
2382
  setGlobalPrefix(prefix) {
1570
2383
  this.globalPrefix = prefix;
@@ -1582,23 +2395,40 @@ var NaviosApplication = class {
1582
2395
  await this.server.listen(options);
1583
2396
  }
1584
2397
  };
1585
- _init4 = __decoratorStart(null);
1586
- NaviosApplication = __decorateElement(_init4, 0, "NaviosApplication", _NaviosApplication_decorators, NaviosApplication);
1587
- __runInitializers(_init4, 1, NaviosApplication);
2398
+ _init8 = __decoratorStart(null);
2399
+ _NaviosApplication = __decorateElement(_init8, 0, "NaviosApplication", _NaviosApplication_decorators, _NaviosApplication);
2400
+ __runInitializers(_init8, 1, _NaviosApplication);
2401
+ var NaviosApplication = _NaviosApplication;
1588
2402
 
1589
2403
  // packages/core/src/navios.factory.mts
1590
2404
  var NaviosFactory = class {
1591
2405
  static async create(appModule, options = {}) {
1592
2406
  const app = await inject(NaviosApplication);
2407
+ this.registerLoggerConfiguration(options);
1593
2408
  app.setup(appModule, options);
1594
2409
  return app;
1595
2410
  }
2411
+ static registerLoggerConfiguration(options) {
2412
+ if (!options) {
2413
+ return;
2414
+ }
2415
+ const { logger } = options;
2416
+ if (logger !== true && !isNil(logger)) {
2417
+ LoggerInstance.overrideLogger(logger);
2418
+ }
2419
+ }
1596
2420
  };
1597
2421
  export {
1598
2422
  Application,
1599
2423
  AttributeFactory,
1600
2424
  BadRequestException,
2425
+ ConfigProvider,
2426
+ ConfigProviderFactory,
2427
+ ConfigProviderInjectionToken,
2428
+ ConfigProviderOptions,
2429
+ ConfigServiceInstance,
1601
2430
  ConflictException,
2431
+ ConsoleLogger,
1602
2432
  Controller,
1603
2433
  ControllerAdapterService,
1604
2434
  ControllerMetadataKey,
@@ -1622,12 +2452,19 @@ export {
1622
2452
  InstanceExpired,
1623
2453
  InstanceNotFound,
1624
2454
  InternalServerErrorException,
2455
+ LOG_LEVELS,
2456
+ Logger,
2457
+ LoggerFactory,
2458
+ LoggerInjectionToken,
2459
+ LoggerInstance,
2460
+ LoggerOptions,
1625
2461
  Module,
1626
2462
  ModuleLoaderService,
1627
2463
  ModuleMetadataKey,
1628
2464
  NaviosApplication,
1629
2465
  NaviosFactory,
1630
2466
  NotFoundException,
2467
+ PinoWrapper,
1631
2468
  Reply,
1632
2469
  Request,
1633
2470
  ServiceLocator,
@@ -1638,8 +2475,13 @@ export {
1638
2475
  UnauthorizedException,
1639
2476
  UnknownError,
1640
2477
  UseGuards,
2478
+ addLeadingSlash,
2479
+ clc,
2480
+ envInt,
2481
+ envString,
1641
2482
  extractControllerMetadata,
1642
2483
  extractModuleMetadata,
2484
+ filterLogLevels,
1643
2485
  getAllEndpointMetadata,
1644
2486
  getControllerMetadata,
1645
2487
  getEndpointMetadata,
@@ -1649,9 +2491,25 @@ export {
1649
2491
  hasControllerMetadata,
1650
2492
  hasModuleMetadata,
1651
2493
  inject,
2494
+ isConstructor,
2495
+ isEmpty,
2496
+ isFunction,
2497
+ isLogLevel,
2498
+ isLogLevelEnabled,
2499
+ isNil,
2500
+ isNumber,
2501
+ isObject,
2502
+ isPlainObject,
2503
+ isString,
2504
+ isSymbol,
2505
+ isUndefined,
2506
+ makeConfigToken,
2507
+ normalizePath,
1652
2508
  override,
1653
2509
  provideServiceLocator,
1654
2510
  setPromiseCollector,
1655
- syncInject
2511
+ stripEndSlash,
2512
+ syncInject,
2513
+ yellow
1656
2514
  };
1657
2515
  //# sourceMappingURL=index.mjs.map