@navios/core 0.1.1 → 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.
package/dist/index.js CHANGED
@@ -77,6 +77,11 @@ __export(src_exports, {
77
77
  Application: () => Application,
78
78
  AttributeFactory: () => AttributeFactory,
79
79
  BadRequestException: () => BadRequestException,
80
+ ConfigProvider: () => ConfigProvider,
81
+ ConfigProviderFactory: () => ConfigProviderFactory,
82
+ ConfigProviderInjectionToken: () => ConfigProviderInjectionToken,
83
+ ConfigProviderOptions: () => ConfigProviderOptions,
84
+ ConfigServiceInstance: () => ConfigServiceInstance,
80
85
  ConflictException: () => ConflictException,
81
86
  ConsoleLogger: () => ConsoleLogger,
82
87
  Controller: () => Controller,
@@ -127,6 +132,8 @@ __export(src_exports, {
127
132
  UseGuards: () => UseGuards,
128
133
  addLeadingSlash: () => addLeadingSlash,
129
134
  clc: () => clc,
135
+ envInt: () => envInt,
136
+ envString: () => envString,
130
137
  extractControllerMetadata: () => extractControllerMetadata,
131
138
  extractModuleMetadata: () => extractModuleMetadata,
132
139
  filterLogLevels: () => filterLogLevels,
@@ -151,6 +158,7 @@ __export(src_exports, {
151
158
  isString: () => isString,
152
159
  isSymbol: () => isSymbol,
153
160
  isUndefined: () => isUndefined,
161
+ makeConfigToken: () => makeConfigToken,
154
162
  normalizePath: () => normalizePath,
155
163
  override: () => override,
156
164
  provideServiceLocator: () => provideServiceLocator,
@@ -161,115 +169,117 @@ __export(src_exports, {
161
169
  });
162
170
  module.exports = __toCommonJS(src_exports);
163
171
 
164
- // packages/core/src/metadata/endpoint.metadata.mts
165
- var EndpointMetadataKey = Symbol("EndpointMetadataKey");
166
- function getAllEndpointMetadata(context) {
167
- if (context.metadata) {
168
- const metadata = context.metadata[EndpointMetadataKey];
169
- if (metadata) {
170
- return metadata;
171
- } else {
172
- context.metadata[EndpointMetadataKey] = /* @__PURE__ */ new Set();
173
- return context.metadata[EndpointMetadataKey];
174
- }
175
- }
176
- throw new Error("[Navios] Wrong environment.");
172
+ // packages/core/src/config/utils/helpers.mts
173
+ var import_node_process = require("process");
174
+ function envInt(key, defaultValue) {
175
+ const envKey = import_node_process.env[key] || process.env[key];
176
+ return envKey ? parseInt(envKey, 10) : defaultValue;
177
177
  }
178
- function getEndpointMetadata(target, context) {
179
- if (context.metadata) {
180
- const metadata = getAllEndpointMetadata(context);
181
- if (metadata) {
182
- const endpointMetadata = Array.from(metadata).find(
183
- (item) => item.classMethod === target.name
184
- );
185
- if (endpointMetadata) {
186
- return endpointMetadata;
187
- } else {
188
- const newMetadata = {
189
- classMethod: target.name,
190
- url: "",
191
- httpMethod: "GET",
192
- config: null,
193
- guards: /* @__PURE__ */ new Set(),
194
- customAttributes: /* @__PURE__ */ new Map()
195
- };
196
- metadata.add(newMetadata);
197
- return newMetadata;
198
- }
199
- }
200
- }
201
- throw new Error("[Navios] Wrong environment.");
178
+ function envString(key, defaultValue) {
179
+ return import_node_process.env[key] || process.env[key] || defaultValue || void 0;
202
180
  }
203
181
 
204
- // packages/core/src/metadata/controller.metadata.mts
205
- var ControllerMetadataKey = Symbol("ControllerMetadataKey");
206
- function getControllerMetadata(target, context) {
207
- if (context.metadata) {
208
- const metadata = context.metadata[ControllerMetadataKey];
209
- if (metadata) {
210
- return metadata;
211
- } else {
212
- const endpointsMetadata = getAllEndpointMetadata(context);
213
- const newMetadata = {
214
- endpoints: endpointsMetadata,
215
- guards: /* @__PURE__ */ new Set(),
216
- customAttributes: /* @__PURE__ */ new Map()
217
- };
218
- context.metadata[ControllerMetadataKey] = newMetadata;
219
- target[ControllerMetadataKey] = newMetadata;
220
- return newMetadata;
221
- }
222
- }
223
- throw new Error("[Navios] Wrong environment.");
182
+ // packages/core/src/config/config.provider.mts
183
+ var import_zod3 = require("zod");
184
+
185
+ // packages/core/src/logger/utils/cli-colors.util.mts
186
+ var isColorAllowed = () => !process.env.NO_COLOR;
187
+ var colorIfAllowed = (colorFn) => (text) => isColorAllowed() ? colorFn(text) : text;
188
+ var clc = {
189
+ bold: colorIfAllowed((text) => `\x1B[1m${text}\x1B[0m`),
190
+ green: colorIfAllowed((text) => `\x1B[32m${text}\x1B[39m`),
191
+ yellow: colorIfAllowed((text) => `\x1B[33m${text}\x1B[39m`),
192
+ red: colorIfAllowed((text) => `\x1B[31m${text}\x1B[39m`),
193
+ magentaBright: colorIfAllowed((text) => `\x1B[95m${text}\x1B[39m`),
194
+ cyanBright: colorIfAllowed((text) => `\x1B[96m${text}\x1B[39m`)
195
+ };
196
+ var yellow = colorIfAllowed(
197
+ (text) => `\x1B[38;5;3m${text}\x1B[39m`
198
+ );
199
+
200
+ // packages/core/src/logger/log-levels.mts
201
+ var LOG_LEVELS = [
202
+ "verbose",
203
+ "debug",
204
+ "log",
205
+ "warn",
206
+ "error",
207
+ "fatal"
208
+ ];
209
+
210
+ // packages/core/src/logger/utils/is-log-level.util.mts
211
+ function isLogLevel(maybeLogLevel) {
212
+ return LOG_LEVELS.includes(maybeLogLevel);
224
213
  }
225
- function extractControllerMetadata(target) {
226
- const metadata = target[ControllerMetadataKey];
227
- if (!metadata) {
228
- throw new Error(
229
- "[Navios] Controller metadata not found. Make sure to use @Controller decorator."
214
+
215
+ // packages/core/src/logger/utils/filter-log-levelts.util.mts
216
+ function filterLogLevels(parseableString = "") {
217
+ const sanitizedString = parseableString.replaceAll(" ", "").toLowerCase();
218
+ if (sanitizedString[0] === ">") {
219
+ const orEqual = sanitizedString[1] === "=";
220
+ const logLevelIndex = LOG_LEVELS.indexOf(
221
+ sanitizedString.substring(orEqual ? 2 : 1)
230
222
  );
223
+ if (logLevelIndex === -1) {
224
+ throw new Error(`parse error (unknown log level): ${sanitizedString}`);
225
+ }
226
+ return LOG_LEVELS.slice(orEqual ? logLevelIndex : logLevelIndex + 1);
227
+ } else if (sanitizedString.includes(",")) {
228
+ return sanitizedString.split(",").filter(isLogLevel);
231
229
  }
232
- return metadata;
233
- }
234
- function hasControllerMetadata(target) {
235
- const metadata = target[ControllerMetadataKey];
236
- return !!metadata;
230
+ return isLogLevel(sanitizedString) ? [sanitizedString] : LOG_LEVELS;
237
231
  }
238
232
 
239
- // packages/core/src/metadata/module.metadata.mts
240
- var ModuleMetadataKey = Symbol("ControllerMetadataKey");
241
- function getModuleMetadata(target, context) {
242
- if (context.metadata) {
243
- const metadata = context.metadata[ModuleMetadataKey];
244
- if (metadata) {
245
- return metadata;
246
- } else {
247
- const newMetadata = {
248
- controllers: /* @__PURE__ */ new Set(),
249
- imports: /* @__PURE__ */ new Set(),
250
- guards: /* @__PURE__ */ new Set(),
251
- customAttributes: /* @__PURE__ */ new Map()
252
- };
253
- context.metadata[ModuleMetadataKey] = newMetadata;
254
- target[ModuleMetadataKey] = newMetadata;
255
- return newMetadata;
256
- }
233
+ // packages/core/src/logger/utils/is-log-level-enabled.mts
234
+ var LOG_LEVEL_VALUES = {
235
+ verbose: 0,
236
+ debug: 1,
237
+ log: 2,
238
+ warn: 3,
239
+ error: 4,
240
+ fatal: 5
241
+ };
242
+ function isLogLevelEnabled(targetLevel, logLevels) {
243
+ var _a;
244
+ if (!logLevels || Array.isArray(logLevels) && (logLevels == null ? void 0 : logLevels.length) === 0) {
245
+ return false;
257
246
  }
258
- throw new Error("[Navios] Wrong environment.");
259
- }
260
- function extractModuleMetadata(target) {
261
- const metadata = target[ModuleMetadataKey];
262
- if (!metadata) {
263
- throw new Error(
264
- "[Navios] Module metadata not found. Make sure to use @Module decorator."
265
- );
247
+ if (logLevels.includes(targetLevel)) {
248
+ return true;
266
249
  }
267
- return metadata;
268
- }
269
- function hasModuleMetadata(target) {
270
- return !!target[ModuleMetadataKey];
250
+ const highestLogLevelValue = (_a = logLevels.map((level) => LOG_LEVEL_VALUES[level]).sort((a, b) => b - a)) == null ? void 0 : _a[0];
251
+ const targetLevelValue = LOG_LEVEL_VALUES[targetLevel];
252
+ return targetLevelValue >= highestLogLevelValue;
271
253
  }
272
254
 
255
+ // packages/core/src/logger/utils/shared.utils.mts
256
+ var isUndefined = (obj) => typeof obj === "undefined";
257
+ var isObject = (fn) => !isNil(fn) && typeof fn === "object";
258
+ var isPlainObject = (fn) => {
259
+ if (!isObject(fn)) {
260
+ return false;
261
+ }
262
+ const proto = Object.getPrototypeOf(fn);
263
+ if (proto === null) {
264
+ return true;
265
+ }
266
+ const ctor = Object.prototype.hasOwnProperty.call(proto, "constructor") && proto.constructor;
267
+ return typeof ctor === "function" && ctor instanceof ctor && Function.prototype.toString.call(ctor) === Function.prototype.toString.call(Object);
268
+ };
269
+ var addLeadingSlash = (path) => path && typeof path === "string" ? path.charAt(0) !== "/" && path.substring(0, 2) !== "{/" ? "/" + path : path : "";
270
+ var normalizePath = (path) => path ? path.startsWith("/") ? ("/" + path.replace(/\/+$/, "")).replace(/\/+/g, "/") : "/" + path.replace(/\/+$/, "") : "/";
271
+ var stripEndSlash = (path) => path[path.length - 1] === "/" ? path.slice(0, path.length - 1) : path;
272
+ var isFunction = (val) => typeof val === "function";
273
+ var isString = (val) => typeof val === "string";
274
+ var isNumber = (val) => typeof val === "number";
275
+ var isConstructor = (val) => val === "constructor";
276
+ var isNil = (val) => isUndefined(val) || val === null;
277
+ var isEmpty = (array) => !(array && array.length > 0);
278
+ var isSymbol = (val) => typeof val === "symbol";
279
+
280
+ // packages/core/src/logger/console-logger.service.mts
281
+ var import_util = require("util");
282
+
273
283
  // packages/core/src/service-locator/enums/injectable-scope.enum.mts
274
284
  var InjectableScope = /* @__PURE__ */ ((InjectableScope2) => {
275
285
  InjectableScope2["Singleton"] = "Singleton";
@@ -828,7 +838,15 @@ var ServiceLocator = class {
828
838
  ).then(() => null);
829
839
  }
830
840
  makeInstanceName(token, args) {
831
- let stringifiedArgs = args ? ":" + JSON.stringify(args).replaceAll(/"/g, "").replaceAll(/:/g, "=").replaceAll(/,/g, "|") : "";
841
+ let stringifiedArgs = args ? ":" + JSON.stringify(args, (_, value) => {
842
+ if (typeof value === "function") {
843
+ return `function:${value.name}(${value.length})`;
844
+ }
845
+ if (typeof value === "symbol") {
846
+ return value.toString();
847
+ }
848
+ return value;
849
+ }).replaceAll(/"/g, "").replaceAll(/:/g, "=").replaceAll(/,/g, "|") : "";
832
850
  const { name: name2 } = token;
833
851
  if (typeof name2 === "function") {
834
852
  const className = name2.name;
@@ -1104,277 +1122,362 @@ function override(token, target) {
1104
1122
  };
1105
1123
  }
1106
1124
 
1107
- // packages/core/src/decorators/controller.decorator.mts
1108
- function Controller({ guards } = {}) {
1109
- return function(target, context) {
1110
- if (context.kind !== "class") {
1111
- throw new Error(
1112
- "[Navios] @Controller decorator can only be used on classes."
1113
- );
1125
+ // packages/core/src/logger/console-logger.service.mts
1126
+ var DEFAULT_DEPTH = 5;
1127
+ var DEFAULT_LOG_LEVELS = [
1128
+ "log",
1129
+ "error",
1130
+ "warn",
1131
+ "debug",
1132
+ "verbose",
1133
+ "fatal"
1134
+ ];
1135
+ var dateTimeFormatter = new Intl.DateTimeFormat(void 0, {
1136
+ year: "numeric",
1137
+ hour: "numeric",
1138
+ minute: "numeric",
1139
+ second: "numeric",
1140
+ day: "2-digit",
1141
+ month: "2-digit"
1142
+ });
1143
+ var _ConsoleLogger_decorators, _init;
1144
+ _ConsoleLogger_decorators = [Injectable()];
1145
+ var _ConsoleLogger = class _ConsoleLogger {
1146
+ /**
1147
+ * The options of the logger.
1148
+ */
1149
+ options;
1150
+ /**
1151
+ * The context of the logger (can be set manually or automatically inferred).
1152
+ */
1153
+ context;
1154
+ /**
1155
+ * The original context of the logger (set in the constructor).
1156
+ */
1157
+ originalContext;
1158
+ /**
1159
+ * The options used for the "inspect" method.
1160
+ */
1161
+ inspectOptions;
1162
+ /**
1163
+ * The last timestamp at which the log message was printed.
1164
+ */
1165
+ static lastTimestampAt;
1166
+ constructor(contextOrOptions, options) {
1167
+ let [context, opts] = isString(contextOrOptions) ? [contextOrOptions, options] : options ? [void 0, options] : [contextOrOptions == null ? void 0 : contextOrOptions.context, contextOrOptions];
1168
+ opts = opts ?? {};
1169
+ opts.logLevels ??= DEFAULT_LOG_LEVELS;
1170
+ opts.colors ??= opts.colors ?? (opts.json ? false : true);
1171
+ opts.prefix ??= "Navios";
1172
+ this.options = opts;
1173
+ this.inspectOptions = this.getInspectOptions();
1174
+ if (context) {
1175
+ this.context = context;
1176
+ this.originalContext = context;
1114
1177
  }
1115
- const token = InjectionToken.create(target);
1116
- if (context.metadata) {
1117
- const controllerMetadata = getControllerMetadata(target, context);
1118
- if (guards) {
1119
- for (const guard of Array.from(guards).reverse()) {
1120
- controllerMetadata.guards.add(guard);
1121
- }
1122
- }
1123
- }
1124
- return Injectable({
1125
- token,
1126
- type: "Class" /* Class */,
1127
- scope: "Instance" /* Instance */
1128
- })(target, context);
1129
- };
1130
- }
1131
-
1132
- // packages/core/src/decorators/endpoint.decorator.mts
1133
- function Endpoint(endpoint) {
1134
- return (target, context) => {
1135
- if (typeof target !== "function") {
1136
- throw new Error(
1137
- "[Navios] Endpoint decorator can only be used on functions."
1138
- );
1178
+ }
1179
+ log(message, ...optionalParams) {
1180
+ if (!this.isLevelEnabled("log")) {
1181
+ return;
1139
1182
  }
1140
- if (context.kind !== "method") {
1141
- throw new Error(
1142
- "[Navios] Endpoint decorator can only be used on methods."
1143
- );
1183
+ const { messages, context } = this.getContextAndMessagesToPrint([
1184
+ message,
1185
+ ...optionalParams
1186
+ ]);
1187
+ this.printMessages(messages, context, "log");
1188
+ }
1189
+ error(message, ...optionalParams) {
1190
+ if (!this.isLevelEnabled("error")) {
1191
+ return;
1144
1192
  }
1145
- const config = endpoint.config;
1146
- if (context.metadata) {
1147
- let endpointMetadata = getEndpointMetadata(target, context);
1148
- if (endpointMetadata.config && endpointMetadata.config.url) {
1149
- throw new Error(
1150
- `[Navios] Endpoint ${config.method} ${config.url} already exists. Please use a different method or url.`
1151
- );
1152
- }
1153
- endpointMetadata.config = config;
1154
- endpointMetadata.classMethod = target.name;
1155
- endpointMetadata.httpMethod = config.method;
1156
- endpointMetadata.url = config.url;
1193
+ const { messages, context, stack } = this.getContextAndStackAndMessagesToPrint([message, ...optionalParams]);
1194
+ this.printMessages(messages, context, "error", "stderr", stack);
1195
+ this.printStackTrace(stack);
1196
+ }
1197
+ warn(message, ...optionalParams) {
1198
+ if (!this.isLevelEnabled("warn")) {
1199
+ return;
1157
1200
  }
1158
- return target;
1159
- };
1160
- }
1161
-
1162
- // packages/core/src/decorators/module.decorator.mts
1163
- function Module(metadata) {
1164
- return (target, context) => {
1165
- if (context.kind !== "class") {
1166
- throw new Error("[Navios] @Module decorator can only be used on classes.");
1201
+ const { messages, context } = this.getContextAndMessagesToPrint([
1202
+ message,
1203
+ ...optionalParams
1204
+ ]);
1205
+ this.printMessages(messages, context, "warn");
1206
+ }
1207
+ debug(message, ...optionalParams) {
1208
+ if (!this.isLevelEnabled("debug")) {
1209
+ return;
1167
1210
  }
1168
- const token = InjectionToken.create(target);
1169
- const moduleMetadata = getModuleMetadata(target, context);
1170
- if (metadata.controllers) {
1171
- for (const controller of metadata.controllers) {
1172
- moduleMetadata.controllers.add(controller);
1173
- }
1211
+ const { messages, context } = this.getContextAndMessagesToPrint([
1212
+ message,
1213
+ ...optionalParams
1214
+ ]);
1215
+ this.printMessages(messages, context, "debug");
1216
+ }
1217
+ verbose(message, ...optionalParams) {
1218
+ if (!this.isLevelEnabled("verbose")) {
1219
+ return;
1174
1220
  }
1175
- if (metadata.imports) {
1176
- for (const importedModule of metadata.imports) {
1177
- moduleMetadata.imports.add(importedModule);
1178
- }
1221
+ const { messages, context } = this.getContextAndMessagesToPrint([
1222
+ message,
1223
+ ...optionalParams
1224
+ ]);
1225
+ this.printMessages(messages, context, "verbose");
1226
+ }
1227
+ fatal(message, ...optionalParams) {
1228
+ if (!this.isLevelEnabled("fatal")) {
1229
+ return;
1179
1230
  }
1180
- if (metadata.guards) {
1181
- for (const guard of Array.from(metadata.guards).reverse()) {
1182
- moduleMetadata.guards.add(guard);
1183
- }
1231
+ const { messages, context } = this.getContextAndMessagesToPrint([
1232
+ message,
1233
+ ...optionalParams
1234
+ ]);
1235
+ this.printMessages(messages, context, "fatal");
1236
+ }
1237
+ /**
1238
+ * Set log levels
1239
+ * @param levels log levels
1240
+ */
1241
+ setLogLevels(levels) {
1242
+ if (!this.options) {
1243
+ this.options = {};
1184
1244
  }
1185
- return Injectable({
1186
- token,
1187
- type: "Class" /* Class */,
1188
- scope: "Singleton" /* Singleton */
1189
- })(target, context);
1190
- };
1191
- }
1192
-
1193
- // packages/core/src/decorators/use-guards.decorator.mts
1194
- function UseGuards(...guards) {
1195
- return function(target, context) {
1196
- if (context.kind === "class") {
1197
- const controllerMetadata = getControllerMetadata(
1198
- target,
1199
- context
1200
- );
1201
- for (const guard of guards.reverse()) {
1202
- controllerMetadata.guards.add(guard);
1203
- }
1204
- } else if (context.kind === "method") {
1205
- const endpointMetadata = getEndpointMetadata(target, context);
1206
- for (const guard of guards.reverse()) {
1207
- endpointMetadata.guards.add(guard);
1245
+ this.options.logLevels = levels;
1246
+ }
1247
+ /**
1248
+ * Set logger context
1249
+ * @param context context
1250
+ */
1251
+ setContext(context) {
1252
+ this.context = context;
1253
+ }
1254
+ /**
1255
+ * Resets the logger context to the value that was passed in the constructor.
1256
+ */
1257
+ resetContext() {
1258
+ this.context = this.originalContext;
1259
+ }
1260
+ isLevelEnabled(level) {
1261
+ var _a;
1262
+ const logLevels = (_a = this.options) == null ? void 0 : _a.logLevels;
1263
+ return isLogLevelEnabled(level, logLevels);
1264
+ }
1265
+ getTimestamp() {
1266
+ return dateTimeFormatter.format(Date.now());
1267
+ }
1268
+ printMessages(messages, context = "", logLevel = "log", writeStreamType, errorStack) {
1269
+ messages.forEach((message) => {
1270
+ if (this.options.json) {
1271
+ this.printAsJson(message, {
1272
+ context,
1273
+ logLevel,
1274
+ writeStreamType,
1275
+ errorStack
1276
+ });
1277
+ return;
1208
1278
  }
1209
- } else {
1210
- throw new Error(
1211
- "[Navios] @UseGuards decorator can only be used on classes or methods."
1279
+ const pidMessage = this.formatPid(process.pid);
1280
+ const contextMessage = this.formatContext(context);
1281
+ const timestampDiff = this.updateAndGetTimestampDiff();
1282
+ const formattedLogLevel = logLevel.toUpperCase().padStart(7, " ");
1283
+ const formattedMessage = this.formatMessage(
1284
+ logLevel,
1285
+ message,
1286
+ pidMessage,
1287
+ formattedLogLevel,
1288
+ contextMessage,
1289
+ timestampDiff
1212
1290
  );
1291
+ process[writeStreamType ?? "stdout"].write(formattedMessage);
1292
+ });
1293
+ }
1294
+ printAsJson(message, options) {
1295
+ const logObject = {
1296
+ level: options.logLevel,
1297
+ pid: process.pid,
1298
+ timestamp: Date.now(),
1299
+ message
1300
+ };
1301
+ if (options.context) {
1302
+ logObject.context = options.context;
1213
1303
  }
1214
- return target;
1215
- };
1216
- }
1217
-
1218
- // packages/core/src/exceptions/http.exception.mts
1219
- var HttpException = class {
1220
- constructor(statusCode, response, error) {
1221
- this.statusCode = statusCode;
1222
- this.response = response;
1223
- this.error = error;
1304
+ if (options.errorStack) {
1305
+ logObject.stack = options.errorStack;
1306
+ }
1307
+ const formattedMessage = !this.options.colors && this.inspectOptions.compact === true ? JSON.stringify(logObject, this.stringifyReplacer) : (0, import_util.inspect)(logObject, this.inspectOptions);
1308
+ process[options.writeStreamType ?? "stdout"].write(`${formattedMessage}
1309
+ `);
1224
1310
  }
1225
- };
1226
-
1227
- // packages/core/src/exceptions/bad-request.exception.mts
1228
- var BadRequestException = class extends HttpException {
1229
- constructor(message) {
1230
- super(400, message);
1311
+ formatPid(pid) {
1312
+ return `[${this.options.prefix}] ${pid} - `;
1231
1313
  }
1232
- };
1233
-
1234
- // packages/core/src/exceptions/forbidden.exception.mts
1235
- var ForbiddenException = class extends HttpException {
1236
- constructor(message) {
1237
- super(403, message);
1314
+ formatContext(context) {
1315
+ if (!context) {
1316
+ return "";
1317
+ }
1318
+ context = `[${context}] `;
1319
+ return this.options.colors ? yellow(context) : context;
1238
1320
  }
1239
- };
1240
-
1241
- // packages/core/src/exceptions/internal-server-error.exception.mts
1242
- var InternalServerErrorException = class extends HttpException {
1243
- constructor(message, error) {
1244
- super(500, message, error);
1321
+ formatMessage(logLevel, message, pidMessage, formattedLogLevel, contextMessage, timestampDiff) {
1322
+ const output = this.stringifyMessage(message, logLevel);
1323
+ pidMessage = this.colorize(pidMessage, logLevel);
1324
+ formattedLogLevel = this.colorize(formattedLogLevel, logLevel);
1325
+ return `${pidMessage}${this.getTimestamp()} ${formattedLogLevel} ${contextMessage}${output}${timestampDiff}
1326
+ `;
1245
1327
  }
1246
- };
1247
-
1248
- // packages/core/src/exceptions/not-found.exception.mts
1249
- var NotFoundException = class extends HttpException {
1250
- constructor(response, error) {
1251
- super(404, response, error);
1252
- this.response = response;
1253
- this.error = error;
1328
+ stringifyMessage(message, logLevel) {
1329
+ if (isFunction(message)) {
1330
+ const messageAsStr = Function.prototype.toString.call(message);
1331
+ const isClass = messageAsStr.startsWith("class ");
1332
+ if (isClass) {
1333
+ return this.stringifyMessage(message.name, logLevel);
1334
+ }
1335
+ return this.stringifyMessage(message(), logLevel);
1336
+ }
1337
+ if (typeof message === "string") {
1338
+ return this.colorize(message, logLevel);
1339
+ }
1340
+ const outputText = (0, import_util.inspect)(message, this.inspectOptions);
1341
+ if (isPlainObject(message)) {
1342
+ return `Object(${Object.keys(message).length}) ${outputText}`;
1343
+ }
1344
+ if (Array.isArray(message)) {
1345
+ return `Array(${message.length}) ${outputText}`;
1346
+ }
1347
+ return outputText;
1254
1348
  }
1255
- };
1256
-
1257
- // packages/core/src/exceptions/unauthorized.exception.mts
1258
- var UnauthorizedException = class extends HttpException {
1259
- constructor(message, error) {
1260
- super(401, message, error);
1349
+ colorize(message, logLevel) {
1350
+ if (!this.options.colors || this.options.json) {
1351
+ return message;
1352
+ }
1353
+ const color = this.getColorByLogLevel(logLevel);
1354
+ return color(message);
1261
1355
  }
1262
- };
1263
-
1264
- // packages/core/src/exceptions/conflict.exception.mts
1265
- var ConflictException = class extends HttpException {
1266
- constructor(message, error) {
1267
- super(409, message, error);
1356
+ printStackTrace(stack) {
1357
+ if (!stack || this.options.json) {
1358
+ return;
1359
+ }
1360
+ process.stderr.write(`${stack}
1361
+ `);
1268
1362
  }
1269
- };
1270
-
1271
- // packages/core/src/logger/utils/cli-colors.util.mts
1272
- var isColorAllowed = () => !process.env.NO_COLOR;
1273
- var colorIfAllowed = (colorFn) => (text) => isColorAllowed() ? colorFn(text) : text;
1274
- var clc = {
1275
- bold: colorIfAllowed((text) => `\x1B[1m${text}\x1B[0m`),
1276
- green: colorIfAllowed((text) => `\x1B[32m${text}\x1B[39m`),
1277
- yellow: colorIfAllowed((text) => `\x1B[33m${text}\x1B[39m`),
1278
- red: colorIfAllowed((text) => `\x1B[31m${text}\x1B[39m`),
1279
- magentaBright: colorIfAllowed((text) => `\x1B[95m${text}\x1B[39m`),
1280
- cyanBright: colorIfAllowed((text) => `\x1B[96m${text}\x1B[39m`)
1281
- };
1282
- var yellow = colorIfAllowed(
1283
- (text) => `\x1B[38;5;3m${text}\x1B[39m`
1284
- );
1285
-
1286
- // packages/core/src/logger/log-levels.mts
1287
- var LOG_LEVELS = [
1288
- "verbose",
1289
- "debug",
1290
- "log",
1291
- "warn",
1292
- "error",
1293
- "fatal"
1294
- ];
1295
-
1296
- // packages/core/src/logger/utils/is-log-level.util.mts
1297
- function isLogLevel(maybeLogLevel) {
1298
- return LOG_LEVELS.includes(maybeLogLevel);
1299
- }
1300
-
1301
- // packages/core/src/logger/utils/filter-log-levelts.util.mts
1302
- function filterLogLevels(parseableString = "") {
1303
- const sanitizedString = parseableString.replaceAll(" ", "").toLowerCase();
1304
- if (sanitizedString[0] === ">") {
1305
- const orEqual = sanitizedString[1] === "=";
1306
- const logLevelIndex = LOG_LEVELS.indexOf(
1307
- sanitizedString.substring(orEqual ? 2 : 1)
1308
- );
1309
- if (logLevelIndex === -1) {
1310
- throw new Error(`parse error (unknown log level): ${sanitizedString}`);
1363
+ updateAndGetTimestampDiff() {
1364
+ var _a;
1365
+ const includeTimestamp = _ConsoleLogger.lastTimestampAt && ((_a = this.options) == null ? void 0 : _a.timestamp);
1366
+ const result = includeTimestamp ? this.formatTimestampDiff(Date.now() - _ConsoleLogger.lastTimestampAt) : "";
1367
+ _ConsoleLogger.lastTimestampAt = Date.now();
1368
+ return result;
1369
+ }
1370
+ formatTimestampDiff(timestampDiff) {
1371
+ const formattedDiff = ` +${timestampDiff}ms`;
1372
+ return this.options.colors ? yellow(formattedDiff) : formattedDiff;
1373
+ }
1374
+ getInspectOptions() {
1375
+ let breakLength = this.options.breakLength;
1376
+ if (typeof breakLength === "undefined") {
1377
+ breakLength = this.options.colors ? this.options.compact ? Infinity : void 0 : this.options.compact === false ? void 0 : Infinity;
1311
1378
  }
1312
- return LOG_LEVELS.slice(orEqual ? logLevelIndex : logLevelIndex + 1);
1313
- } else if (sanitizedString.includes(",")) {
1314
- return sanitizedString.split(",").filter(isLogLevel);
1379
+ const inspectOptions = {
1380
+ depth: this.options.depth ?? DEFAULT_DEPTH,
1381
+ sorted: this.options.sorted,
1382
+ showHidden: this.options.showHidden,
1383
+ compact: this.options.compact ?? (this.options.json ? true : false),
1384
+ colors: this.options.colors,
1385
+ breakLength
1386
+ };
1387
+ if (this.options.maxArrayLength) {
1388
+ inspectOptions.maxArrayLength = this.options.maxArrayLength;
1389
+ }
1390
+ if (this.options.maxStringLength) {
1391
+ inspectOptions.maxStringLength = this.options.maxStringLength;
1392
+ }
1393
+ return inspectOptions;
1394
+ }
1395
+ stringifyReplacer(key, value) {
1396
+ if (typeof value === "bigint") {
1397
+ return value.toString();
1398
+ }
1399
+ if (typeof value === "symbol") {
1400
+ return value.toString();
1401
+ }
1402
+ if (value instanceof Map || value instanceof Set || value instanceof Error) {
1403
+ return `${(0, import_util.inspect)(value, this.inspectOptions)}`;
1404
+ }
1405
+ return value;
1315
1406
  }
1316
- return isLogLevel(sanitizedString) ? [sanitizedString] : LOG_LEVELS;
1317
- }
1318
-
1319
- // packages/core/src/logger/utils/is-log-level-enabled.mts
1320
- var LOG_LEVEL_VALUES = {
1321
- verbose: 0,
1322
- debug: 1,
1323
- log: 2,
1324
- warn: 3,
1325
- error: 4,
1326
- fatal: 5
1327
- };
1328
- function isLogLevelEnabled(targetLevel, logLevels) {
1329
- var _a;
1330
- if (!logLevels || Array.isArray(logLevels) && (logLevels == null ? void 0 : logLevels.length) === 0) {
1331
- return false;
1407
+ getContextAndMessagesToPrint(args) {
1408
+ if ((args == null ? void 0 : args.length) <= 1) {
1409
+ return { messages: args, context: this.context };
1410
+ }
1411
+ const lastElement = args[args.length - 1];
1412
+ const isContext = isString(lastElement);
1413
+ if (!isContext) {
1414
+ return { messages: args, context: this.context };
1415
+ }
1416
+ return {
1417
+ context: lastElement,
1418
+ messages: args.slice(0, args.length - 1)
1419
+ };
1332
1420
  }
1333
- if (logLevels.includes(targetLevel)) {
1334
- return true;
1421
+ getContextAndStackAndMessagesToPrint(args) {
1422
+ if (args.length === 2) {
1423
+ return this.isStackFormat(args[1]) ? {
1424
+ messages: [args[0]],
1425
+ stack: args[1],
1426
+ context: this.context
1427
+ } : {
1428
+ messages: [args[0]],
1429
+ context: args[1]
1430
+ };
1431
+ }
1432
+ const { messages, context } = this.getContextAndMessagesToPrint(args);
1433
+ if ((messages == null ? void 0 : messages.length) <= 1) {
1434
+ return { messages, context };
1435
+ }
1436
+ const lastElement = messages[messages.length - 1];
1437
+ const isStack = isString(lastElement);
1438
+ if (!isStack && !isUndefined(lastElement)) {
1439
+ return { messages, context };
1440
+ }
1441
+ return {
1442
+ stack: lastElement,
1443
+ messages: messages.slice(0, messages.length - 1),
1444
+ context
1445
+ };
1335
1446
  }
1336
- const highestLogLevelValue = (_a = logLevels.map((level) => LOG_LEVEL_VALUES[level]).sort((a, b) => b - a)) == null ? void 0 : _a[0];
1337
- const targetLevelValue = LOG_LEVEL_VALUES[targetLevel];
1338
- return targetLevelValue >= highestLogLevelValue;
1339
- }
1340
-
1341
- // packages/core/src/logger/utils/shared.utils.mts
1342
- var isUndefined = (obj) => typeof obj === "undefined";
1343
- var isObject = (fn) => !isNil(fn) && typeof fn === "object";
1344
- var isPlainObject = (fn) => {
1345
- if (!isObject(fn)) {
1346
- return false;
1447
+ isStackFormat(stack) {
1448
+ if (!isString(stack) && !isUndefined(stack)) {
1449
+ return false;
1450
+ }
1451
+ return /^(.)+\n\s+at .+:\d+:\d+/.test(stack);
1347
1452
  }
1348
- const proto = Object.getPrototypeOf(fn);
1349
- if (proto === null) {
1350
- return true;
1453
+ getColorByLogLevel(level) {
1454
+ switch (level) {
1455
+ case "debug":
1456
+ return clc.magentaBright;
1457
+ case "warn":
1458
+ return clc.yellow;
1459
+ case "error":
1460
+ return clc.red;
1461
+ case "verbose":
1462
+ return clc.cyanBright;
1463
+ case "fatal":
1464
+ return clc.bold;
1465
+ default:
1466
+ return clc.green;
1467
+ }
1351
1468
  }
1352
- const ctor = Object.prototype.hasOwnProperty.call(proto, "constructor") && proto.constructor;
1353
- return typeof ctor === "function" && ctor instanceof ctor && Function.prototype.toString.call(ctor) === Function.prototype.toString.call(Object);
1354
1469
  };
1355
- var addLeadingSlash = (path) => path && typeof path === "string" ? path.charAt(0) !== "/" && path.substring(0, 2) !== "{/" ? "/" + path : path : "";
1356
- var normalizePath = (path) => path ? path.startsWith("/") ? ("/" + path.replace(/\/+$/, "")).replace(/\/+/g, "/") : "/" + path.replace(/\/+$/, "") : "/";
1357
- var stripEndSlash = (path) => path[path.length - 1] === "/" ? path.slice(0, path.length - 1) : path;
1358
- var isFunction = (val) => typeof val === "function";
1359
- var isString = (val) => typeof val === "string";
1360
- var isNumber = (val) => typeof val === "number";
1361
- var isConstructor = (val) => val === "constructor";
1362
- var isNil = (val) => isUndefined(val) || val === null;
1363
- var isEmpty = (array) => !(array && array.length > 0);
1364
- var isSymbol = (val) => typeof val === "symbol";
1470
+ _init = __decoratorStart(null);
1471
+ _ConsoleLogger = __decorateElement(_init, 0, "ConsoleLogger", _ConsoleLogger_decorators, _ConsoleLogger);
1472
+ __runInitializers(_init, 1, _ConsoleLogger);
1473
+ var ConsoleLogger = _ConsoleLogger;
1365
1474
 
1366
- // packages/core/src/logger/console-logger.service.mts
1367
- var import_util = require("util");
1368
- var DEFAULT_DEPTH = 5;
1369
- var DEFAULT_LOG_LEVELS = [
1370
- "log",
1371
- "error",
1372
- "warn",
1373
- "debug",
1374
- "verbose",
1375
- "fatal"
1376
- ];
1377
- var dateTimeFormatter = new Intl.DateTimeFormat(void 0, {
1475
+ // packages/core/src/logger/logger.factory.mts
1476
+ var import_zod2 = require("zod");
1477
+
1478
+ // packages/core/src/logger/logger.service.mts
1479
+ var DEFAULT_LOGGER = new ConsoleLogger();
1480
+ var dateTimeFormatter2 = new Intl.DateTimeFormat(void 0, {
1378
1481
  year: "numeric",
1379
1482
  hour: "numeric",
1380
1483
  minute: "numeric",
@@ -1382,538 +1485,559 @@ var dateTimeFormatter = new Intl.DateTimeFormat(void 0, {
1382
1485
  day: "2-digit",
1383
1486
  month: "2-digit"
1384
1487
  });
1385
- var _ConsoleLogger_decorators, _init;
1386
- _ConsoleLogger_decorators = [Injectable()];
1387
- var _ConsoleLogger = class _ConsoleLogger {
1388
- /**
1389
- * The options of the logger.
1390
- */
1391
- options;
1392
- /**
1393
- * The context of the logger (can be set manually or automatically inferred).
1394
- */
1395
- context;
1396
- /**
1397
- * The original context of the logger (set in the constructor).
1398
- */
1399
- originalContext;
1400
- /**
1401
- * The options used for the "inspect" method.
1402
- */
1403
- inspectOptions;
1404
- /**
1405
- * The last timestamp at which the log message was printed.
1406
- */
1407
- static lastTimestampAt;
1408
- constructor(contextOrOptions, options) {
1409
- let [context, opts] = isString(contextOrOptions) ? [contextOrOptions, options] : options ? [void 0, options] : [contextOrOptions == null ? void 0 : contextOrOptions.context, contextOrOptions];
1410
- opts = opts ?? {};
1411
- opts.logLevels ??= DEFAULT_LOG_LEVELS;
1412
- opts.colors ??= opts.colors ?? (opts.json ? false : true);
1413
- opts.prefix ??= "Navios";
1414
- this.options = opts;
1415
- this.inspectOptions = this.getInspectOptions();
1416
- if (context) {
1417
- this.context = context;
1418
- this.originalContext = context;
1419
- }
1488
+ var _LoggerInstance_decorators, _init2;
1489
+ _LoggerInstance_decorators = [Injectable()];
1490
+ var _LoggerInstance = class _LoggerInstance {
1491
+ constructor(context, options = {}) {
1492
+ this.context = context;
1493
+ this.options = options;
1420
1494
  }
1421
- log(message, ...optionalParams) {
1422
- if (!this.isLevelEnabled("log")) {
1423
- return;
1495
+ static staticInstanceRef = DEFAULT_LOGGER;
1496
+ static logLevels;
1497
+ localInstanceRef;
1498
+ get localInstance() {
1499
+ if (_LoggerInstance.staticInstanceRef === DEFAULT_LOGGER) {
1500
+ return this.registerLocalInstanceRef();
1501
+ } else if (_LoggerInstance.staticInstanceRef instanceof _LoggerInstance) {
1502
+ const prototype = Object.getPrototypeOf(_LoggerInstance.staticInstanceRef);
1503
+ if (prototype.constructor === _LoggerInstance) {
1504
+ return this.registerLocalInstanceRef();
1505
+ }
1424
1506
  }
1425
- const { messages, context } = this.getContextAndMessagesToPrint([
1426
- message,
1427
- ...optionalParams
1428
- ]);
1429
- this.printMessages(messages, context, "log");
1507
+ return _LoggerInstance.staticInstanceRef;
1430
1508
  }
1431
1509
  error(message, ...optionalParams) {
1432
- if (!this.isLevelEnabled("error")) {
1433
- return;
1434
- }
1435
- const { messages, context, stack } = this.getContextAndStackAndMessagesToPrint([message, ...optionalParams]);
1436
- this.printMessages(messages, context, "error", "stderr", stack);
1437
- this.printStackTrace(stack);
1510
+ var _a;
1511
+ optionalParams = this.context ? (optionalParams.length ? optionalParams : [void 0]).concat(
1512
+ this.context
1513
+ ) : optionalParams;
1514
+ (_a = this.localInstance) == null ? void 0 : _a.error(message, ...optionalParams);
1515
+ }
1516
+ log(message, ...optionalParams) {
1517
+ var _a;
1518
+ optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1519
+ (_a = this.localInstance) == null ? void 0 : _a.log(message, ...optionalParams);
1438
1520
  }
1439
1521
  warn(message, ...optionalParams) {
1440
- if (!this.isLevelEnabled("warn")) {
1441
- return;
1442
- }
1443
- const { messages, context } = this.getContextAndMessagesToPrint([
1444
- message,
1445
- ...optionalParams
1446
- ]);
1447
- this.printMessages(messages, context, "warn");
1522
+ var _a;
1523
+ optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1524
+ (_a = this.localInstance) == null ? void 0 : _a.warn(message, ...optionalParams);
1448
1525
  }
1449
1526
  debug(message, ...optionalParams) {
1450
- if (!this.isLevelEnabled("debug")) {
1451
- return;
1452
- }
1453
- const { messages, context } = this.getContextAndMessagesToPrint([
1454
- message,
1455
- ...optionalParams
1456
- ]);
1457
- this.printMessages(messages, context, "debug");
1527
+ var _a, _b;
1528
+ optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1529
+ (_b = (_a = this.localInstance) == null ? void 0 : _a.debug) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1458
1530
  }
1459
1531
  verbose(message, ...optionalParams) {
1460
- if (!this.isLevelEnabled("verbose")) {
1461
- return;
1462
- }
1463
- const { messages, context } = this.getContextAndMessagesToPrint([
1464
- message,
1465
- ...optionalParams
1466
- ]);
1467
- this.printMessages(messages, context, "verbose");
1468
- }
1469
- fatal(message, ...optionalParams) {
1470
- if (!this.isLevelEnabled("fatal")) {
1471
- return;
1472
- }
1473
- const { messages, context } = this.getContextAndMessagesToPrint([
1474
- message,
1475
- ...optionalParams
1476
- ]);
1477
- this.printMessages(messages, context, "fatal");
1478
- }
1479
- /**
1480
- * Set log levels
1481
- * @param levels log levels
1482
- */
1483
- setLogLevels(levels) {
1484
- if (!this.options) {
1485
- this.options = {};
1486
- }
1487
- this.options.logLevels = levels;
1532
+ var _a, _b;
1533
+ optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1534
+ (_b = (_a = this.localInstance) == null ? void 0 : _a.verbose) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1488
1535
  }
1489
- /**
1490
- * Set logger context
1491
- * @param context context
1492
- */
1493
- setContext(context) {
1494
- this.context = context;
1536
+ fatal(message, ...optionalParams) {
1537
+ var _a, _b;
1538
+ optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1539
+ (_b = (_a = this.localInstance) == null ? void 0 : _a.fatal) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1495
1540
  }
1496
- /**
1497
- * Resets the logger context to the value that was passed in the constructor.
1498
- */
1499
- resetContext() {
1500
- this.context = this.originalContext;
1541
+ static error(message, ...optionalParams) {
1542
+ var _a;
1543
+ (_a = this.staticInstanceRef) == null ? void 0 : _a.error(message, ...optionalParams);
1501
1544
  }
1502
- isLevelEnabled(level) {
1545
+ static log(message, ...optionalParams) {
1503
1546
  var _a;
1504
- const logLevels = (_a = this.options) == null ? void 0 : _a.logLevels;
1505
- return isLogLevelEnabled(level, logLevels);
1547
+ (_a = this.staticInstanceRef) == null ? void 0 : _a.log(message, ...optionalParams);
1506
1548
  }
1507
- getTimestamp() {
1508
- return dateTimeFormatter.format(Date.now());
1549
+ static warn(message, ...optionalParams) {
1550
+ var _a;
1551
+ (_a = this.staticInstanceRef) == null ? void 0 : _a.warn(message, ...optionalParams);
1509
1552
  }
1510
- printMessages(messages, context = "", logLevel = "log", writeStreamType, errorStack) {
1511
- messages.forEach((message) => {
1512
- if (this.options.json) {
1513
- this.printAsJson(message, {
1514
- context,
1515
- logLevel,
1516
- writeStreamType,
1517
- errorStack
1518
- });
1519
- return;
1520
- }
1521
- const pidMessage = this.formatPid(process.pid);
1522
- const contextMessage = this.formatContext(context);
1523
- const timestampDiff = this.updateAndGetTimestampDiff();
1524
- const formattedLogLevel = logLevel.toUpperCase().padStart(7, " ");
1525
- const formattedMessage = this.formatMessage(
1526
- logLevel,
1527
- message,
1528
- pidMessage,
1529
- formattedLogLevel,
1530
- contextMessage,
1531
- timestampDiff
1532
- );
1533
- process[writeStreamType ?? "stdout"].write(formattedMessage);
1534
- });
1553
+ static debug(message, ...optionalParams) {
1554
+ var _a, _b;
1555
+ (_b = (_a = this.staticInstanceRef) == null ? void 0 : _a.debug) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1535
1556
  }
1536
- printAsJson(message, options) {
1537
- const logObject = {
1538
- level: options.logLevel,
1539
- pid: process.pid,
1540
- timestamp: Date.now(),
1541
- message
1542
- };
1543
- if (options.context) {
1544
- logObject.context = options.context;
1557
+ static verbose(message, ...optionalParams) {
1558
+ var _a, _b;
1559
+ (_b = (_a = this.staticInstanceRef) == null ? void 0 : _a.verbose) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1560
+ }
1561
+ static fatal(message, ...optionalParams) {
1562
+ var _a, _b;
1563
+ (_b = (_a = this.staticInstanceRef) == null ? void 0 : _a.fatal) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1564
+ }
1565
+ static getTimestamp() {
1566
+ return dateTimeFormatter2.format(Date.now());
1567
+ }
1568
+ static overrideLogger(logger) {
1569
+ var _a, _b;
1570
+ console.log(logger);
1571
+ if (Array.isArray(logger)) {
1572
+ _LoggerInstance.logLevels = logger;
1573
+ return (_b = (_a = this.staticInstanceRef) == null ? void 0 : _a.setLogLevels) == null ? void 0 : _b.call(_a, logger);
1545
1574
  }
1546
- if (options.errorStack) {
1547
- logObject.stack = options.errorStack;
1575
+ if (isObject(logger)) {
1576
+ this.staticInstanceRef = logger;
1577
+ } else {
1578
+ this.staticInstanceRef = void 0;
1548
1579
  }
1549
- const formattedMessage = !this.options.colors && this.inspectOptions.compact === true ? JSON.stringify(logObject, this.stringifyReplacer) : (0, import_util.inspect)(logObject, this.inspectOptions);
1550
- process[options.writeStreamType ?? "stdout"].write(`${formattedMessage}
1551
- `);
1552
1580
  }
1553
- formatPid(pid) {
1554
- return `[${this.options.prefix}] ${pid} - `;
1581
+ static isLevelEnabled(level) {
1582
+ const logLevels = _LoggerInstance.logLevels;
1583
+ return isLogLevelEnabled(level, logLevels);
1555
1584
  }
1556
- formatContext(context) {
1557
- if (!context) {
1558
- return "";
1585
+ registerLocalInstanceRef() {
1586
+ var _a;
1587
+ if (this.localInstanceRef) {
1588
+ return this.localInstanceRef;
1559
1589
  }
1560
- context = `[${context}] `;
1561
- return this.options.colors ? yellow(context) : context;
1590
+ this.localInstanceRef = new ConsoleLogger(this.context, {
1591
+ timestamp: (_a = this.options) == null ? void 0 : _a.timestamp,
1592
+ logLevels: _LoggerInstance.logLevels
1593
+ });
1594
+ return this.localInstanceRef;
1562
1595
  }
1563
- formatMessage(logLevel, message, pidMessage, formattedLogLevel, contextMessage, timestampDiff) {
1564
- const output = this.stringifyMessage(message, logLevel);
1565
- pidMessage = this.colorize(pidMessage, logLevel);
1566
- formattedLogLevel = this.colorize(formattedLogLevel, logLevel);
1567
- return `${pidMessage}${this.getTimestamp()} ${formattedLogLevel} ${contextMessage}${output}${timestampDiff}
1568
- `;
1596
+ };
1597
+ _init2 = __decoratorStart(null);
1598
+ _LoggerInstance = __decorateElement(_init2, 0, "LoggerInstance", _LoggerInstance_decorators, _LoggerInstance);
1599
+ __runInitializers(_init2, 1, _LoggerInstance);
1600
+ var LoggerInstance = _LoggerInstance;
1601
+
1602
+ // packages/core/src/logger/logger.factory.mts
1603
+ var LoggerInjectionToken = "LoggerInjectionToken";
1604
+ var LoggerOptions = import_zod2.z.object({
1605
+ context: import_zod2.z.string().optional(),
1606
+ options: import_zod2.z.object({
1607
+ timestamp: import_zod2.z.boolean().optional()
1608
+ }).optional()
1609
+ }).optional();
1610
+ var Logger = InjectionToken.create(LoggerInjectionToken, LoggerOptions);
1611
+ var _LoggerFactory_decorators, _init3;
1612
+ _LoggerFactory_decorators = [Injectable({
1613
+ type: "Factory" /* Factory */,
1614
+ token: Logger
1615
+ })];
1616
+ var LoggerFactory = class {
1617
+ create(ctx, args) {
1618
+ return new LoggerInstance(args == null ? void 0 : args.context, args == null ? void 0 : args.options);
1569
1619
  }
1570
- stringifyMessage(message, logLevel) {
1571
- if (isFunction(message)) {
1572
- const messageAsStr = Function.prototype.toString.call(message);
1573
- const isClass = messageAsStr.startsWith("class ");
1574
- if (isClass) {
1575
- return this.stringifyMessage(message.name, logLevel);
1576
- }
1577
- return this.stringifyMessage(message(), logLevel);
1578
- }
1579
- if (typeof message === "string") {
1580
- return this.colorize(message, logLevel);
1581
- }
1582
- const outputText = (0, import_util.inspect)(message, this.inspectOptions);
1583
- if (isPlainObject(message)) {
1584
- return `Object(${Object.keys(message).length}) ${outputText}`;
1585
- }
1586
- if (Array.isArray(message)) {
1587
- return `Array(${message.length}) ${outputText}`;
1588
- }
1589
- return outputText;
1620
+ };
1621
+ _init3 = __decoratorStart(null);
1622
+ LoggerFactory = __decorateElement(_init3, 0, "LoggerFactory", _LoggerFactory_decorators, LoggerFactory);
1623
+ __runInitializers(_init3, 1, LoggerFactory);
1624
+
1625
+ // packages/core/src/logger/pino-wrapper.mts
1626
+ var PinoWrapper = class _PinoWrapper {
1627
+ constructor(logger) {
1628
+ this.logger = logger;
1590
1629
  }
1591
- colorize(message, logLevel) {
1592
- if (!this.options.colors || this.options.json) {
1593
- return message;
1630
+ fatal(message, ...optionalParams) {
1631
+ if (this.logger.fatal === void 0) {
1632
+ return this.error(message, ...optionalParams);
1594
1633
  }
1595
- const color = this.getColorByLogLevel(logLevel);
1596
- return color(message);
1634
+ this.logger.fatal(message, ...optionalParams);
1597
1635
  }
1598
- printStackTrace(stack) {
1599
- if (!stack || this.options.json) {
1600
- return;
1601
- }
1602
- process.stderr.write(`${stack}
1603
- `);
1636
+ error(message, ...optionalParams) {
1637
+ this.logger.error(message, ...optionalParams);
1604
1638
  }
1605
- updateAndGetTimestampDiff() {
1606
- var _a;
1607
- const includeTimestamp = _ConsoleLogger.lastTimestampAt && ((_a = this.options) == null ? void 0 : _a.timestamp);
1608
- const result = includeTimestamp ? this.formatTimestampDiff(Date.now() - _ConsoleLogger.lastTimestampAt) : "";
1609
- _ConsoleLogger.lastTimestampAt = Date.now();
1610
- return result;
1639
+ warn(message, ...optionalParams) {
1640
+ this.logger.warn(message, ...optionalParams);
1611
1641
  }
1612
- formatTimestampDiff(timestampDiff) {
1613
- const formattedDiff = ` +${timestampDiff}ms`;
1614
- return this.options.colors ? yellow(formattedDiff) : formattedDiff;
1642
+ info(message, ...optionalParams) {
1643
+ this.logger.log(message, ...optionalParams);
1615
1644
  }
1616
- getInspectOptions() {
1617
- let breakLength = this.options.breakLength;
1618
- if (typeof breakLength === "undefined") {
1619
- breakLength = this.options.colors ? this.options.compact ? Infinity : void 0 : this.options.compact === false ? void 0 : Infinity;
1645
+ debug(message, ...optionalParams) {
1646
+ var _a, _b;
1647
+ (_b = (_a = this.logger).debug) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1648
+ }
1649
+ trace(message, ...optionalParams) {
1650
+ var _a, _b;
1651
+ (_b = (_a = this.logger).verbose) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1652
+ }
1653
+ silent(message, ...optionalParams) {
1654
+ }
1655
+ child(options) {
1656
+ const keys = Object.keys(options);
1657
+ let newContext = this.logger["context"] ?? "";
1658
+ if (keys.length > 1) {
1659
+ newContext = `${this.logger["context"] ?? ""}:${JSON.stringify(options)}`;
1620
1660
  }
1621
- const inspectOptions = {
1622
- depth: this.options.depth ?? DEFAULT_DEPTH,
1623
- sorted: this.options.sorted,
1624
- showHidden: this.options.showHidden,
1625
- compact: this.options.compact ?? (this.options.json ? true : false),
1626
- colors: this.options.colors,
1627
- breakLength
1628
- };
1629
- if (this.options.maxArrayLength) {
1630
- inspectOptions.maxArrayLength = this.options.maxArrayLength;
1661
+ return new _PinoWrapper(
1662
+ // @ts-expect-error We don't need to support this in the current version
1663
+ new LoggerInstance(newContext, this.logger["options"])
1664
+ );
1665
+ }
1666
+ get level() {
1667
+ if ("level" in this.logger && this.logger.level) {
1668
+ return this.logger.level;
1631
1669
  }
1632
- if (this.options.maxStringLength) {
1633
- inspectOptions.maxStringLength = this.options.maxStringLength;
1670
+ const levels = LoggerInstance["logLevels"];
1671
+ if (levels) {
1672
+ return levels[0];
1634
1673
  }
1635
- return inspectOptions;
1674
+ return "info";
1636
1675
  }
1637
- stringifyReplacer(key, value) {
1638
- if (typeof value === "bigint") {
1639
- return value.toString();
1640
- }
1641
- if (typeof value === "symbol") {
1642
- return value.toString();
1676
+ };
1677
+
1678
+ // packages/core/src/config/config.service.mts
1679
+ var import_common = require("@navios/common");
1680
+ var ConfigServiceInstance = class {
1681
+ constructor(config = {}, logger) {
1682
+ this.config = config;
1683
+ this.logger = logger;
1684
+ }
1685
+ getConfig() {
1686
+ return this.config;
1687
+ }
1688
+ get(key) {
1689
+ var _a, _b;
1690
+ try {
1691
+ const parts = String(key).split(".");
1692
+ let value = this.config;
1693
+ for (const part of parts) {
1694
+ if (value === null || value === void 0 || typeof value !== "object") {
1695
+ return null;
1696
+ }
1697
+ value = value[part];
1698
+ }
1699
+ return value ?? null;
1700
+ } catch (error) {
1701
+ (_b = (_a = this.logger).debug) == null ? void 0 : _b.call(
1702
+ _a,
1703
+ `Failed to get config value for key ${String(key)}`,
1704
+ error
1705
+ );
1706
+ return null;
1643
1707
  }
1644
- if (value instanceof Map || value instanceof Set || value instanceof Error) {
1645
- return `${(0, import_util.inspect)(value, this.inspectOptions)}`;
1708
+ }
1709
+ getOrDefault(key, defaultValue) {
1710
+ const value = this.get(key);
1711
+ return value !== null ? value : defaultValue;
1712
+ }
1713
+ getOrThrow(key, errorMessage) {
1714
+ const value = this.get(key);
1715
+ if (value === null) {
1716
+ const message = errorMessage || `Configuration value for key "${String(key)}" is not defined`;
1717
+ this.logger.error(message);
1718
+ throw new import_common.NaviosException(message);
1646
1719
  }
1647
1720
  return value;
1648
1721
  }
1649
- getContextAndMessagesToPrint(args) {
1650
- if ((args == null ? void 0 : args.length) <= 1) {
1651
- return { messages: args, context: this.context };
1652
- }
1653
- const lastElement = args[args.length - 1];
1654
- const isContext = isString(lastElement);
1655
- if (!isContext) {
1656
- return { messages: args, context: this.context };
1722
+ };
1723
+
1724
+ // packages/core/src/config/config.provider.mts
1725
+ var ConfigProviderInjectionToken = "ConfigProvider";
1726
+ var ConfigProviderOptions = import_zod3.z.object({
1727
+ load: import_zod3.z.function()
1728
+ });
1729
+ var ConfigProvider = InjectionToken.create(ConfigProviderInjectionToken, ConfigProviderOptions);
1730
+ var _ConfigProviderFactory_decorators, _init4;
1731
+ _ConfigProviderFactory_decorators = [Injectable({
1732
+ token: ConfigProvider,
1733
+ type: "Factory" /* Factory */
1734
+ })];
1735
+ var ConfigProviderFactory = class {
1736
+ logger = inject(Logger, {
1737
+ context: "ConfigService"
1738
+ });
1739
+ async create(ctx, args) {
1740
+ const { load } = args;
1741
+ const logger = await this.logger;
1742
+ try {
1743
+ const config = await load();
1744
+ return new ConfigServiceInstance(config, logger);
1745
+ } catch (error) {
1746
+ logger.error("Error loading config", error);
1747
+ throw error;
1657
1748
  }
1658
- return {
1659
- context: lastElement,
1660
- messages: args.slice(0, args.length - 1)
1661
- };
1662
1749
  }
1663
- getContextAndStackAndMessagesToPrint(args) {
1664
- if (args.length === 2) {
1665
- return this.isStackFormat(args[1]) ? {
1666
- messages: [args[0]],
1667
- stack: args[1],
1668
- context: this.context
1669
- } : {
1670
- messages: [args[0]],
1671
- context: args[1]
1672
- };
1673
- }
1674
- const { messages, context } = this.getContextAndMessagesToPrint(args);
1675
- if ((messages == null ? void 0 : messages.length) <= 1) {
1676
- return { messages, context };
1750
+ };
1751
+ _init4 = __decoratorStart(null);
1752
+ ConfigProviderFactory = __decorateElement(_init4, 0, "ConfigProviderFactory", _ConfigProviderFactory_decorators, ConfigProviderFactory);
1753
+ __runInitializers(_init4, 1, ConfigProviderFactory);
1754
+ function makeConfigToken(options) {
1755
+ var _ConfigServiceImpl_decorators, _init9;
1756
+ _ConfigServiceImpl_decorators = [Injectable({
1757
+ type: "Factory" /* Factory */
1758
+ })];
1759
+ class ConfigServiceImpl {
1760
+ configService = inject(ConfigProvider, options);
1761
+ create() {
1762
+ return this.configService;
1763
+ }
1764
+ }
1765
+ _init9 = __decoratorStart(null);
1766
+ ConfigServiceImpl = __decorateElement(_init9, 0, "ConfigServiceImpl", _ConfigServiceImpl_decorators, ConfigServiceImpl);
1767
+ __runInitializers(_init9, 1, ConfigServiceImpl);
1768
+ return getInjectableToken(ConfigServiceImpl);
1769
+ }
1770
+
1771
+ // packages/core/src/metadata/endpoint.metadata.mts
1772
+ var EndpointMetadataKey = Symbol("EndpointMetadataKey");
1773
+ function getAllEndpointMetadata(context) {
1774
+ if (context.metadata) {
1775
+ const metadata = context.metadata[EndpointMetadataKey];
1776
+ if (metadata) {
1777
+ return metadata;
1778
+ } else {
1779
+ context.metadata[EndpointMetadataKey] = /* @__PURE__ */ new Set();
1780
+ return context.metadata[EndpointMetadataKey];
1677
1781
  }
1678
- const lastElement = messages[messages.length - 1];
1679
- const isStack = isString(lastElement);
1680
- if (!isStack && !isUndefined(lastElement)) {
1681
- return { messages, context };
1782
+ }
1783
+ throw new Error("[Navios] Wrong environment.");
1784
+ }
1785
+ function getEndpointMetadata(target, context) {
1786
+ if (context.metadata) {
1787
+ const metadata = getAllEndpointMetadata(context);
1788
+ if (metadata) {
1789
+ const endpointMetadata = Array.from(metadata).find(
1790
+ (item) => item.classMethod === target.name
1791
+ );
1792
+ if (endpointMetadata) {
1793
+ return endpointMetadata;
1794
+ } else {
1795
+ const newMetadata = {
1796
+ classMethod: target.name,
1797
+ url: "",
1798
+ httpMethod: "GET",
1799
+ config: null,
1800
+ guards: /* @__PURE__ */ new Set(),
1801
+ customAttributes: /* @__PURE__ */ new Map()
1802
+ };
1803
+ metadata.add(newMetadata);
1804
+ return newMetadata;
1805
+ }
1682
1806
  }
1683
- return {
1684
- stack: lastElement,
1685
- messages: messages.slice(0, messages.length - 1),
1686
- context
1687
- };
1688
1807
  }
1689
- isStackFormat(stack) {
1690
- if (!isString(stack) && !isUndefined(stack)) {
1691
- return false;
1808
+ throw new Error("[Navios] Wrong environment.");
1809
+ }
1810
+
1811
+ // packages/core/src/metadata/controller.metadata.mts
1812
+ var ControllerMetadataKey = Symbol("ControllerMetadataKey");
1813
+ function getControllerMetadata(target, context) {
1814
+ if (context.metadata) {
1815
+ const metadata = context.metadata[ControllerMetadataKey];
1816
+ if (metadata) {
1817
+ return metadata;
1818
+ } else {
1819
+ const endpointsMetadata = getAllEndpointMetadata(context);
1820
+ const newMetadata = {
1821
+ endpoints: endpointsMetadata,
1822
+ guards: /* @__PURE__ */ new Set(),
1823
+ customAttributes: /* @__PURE__ */ new Map()
1824
+ };
1825
+ context.metadata[ControllerMetadataKey] = newMetadata;
1826
+ target[ControllerMetadataKey] = newMetadata;
1827
+ return newMetadata;
1692
1828
  }
1693
- return /^(.)+\n\s+at .+:\d+:\d+/.test(stack);
1694
1829
  }
1695
- getColorByLogLevel(level) {
1696
- switch (level) {
1697
- case "debug":
1698
- return clc.magentaBright;
1699
- case "warn":
1700
- return clc.yellow;
1701
- case "error":
1702
- return clc.red;
1703
- case "verbose":
1704
- return clc.cyanBright;
1705
- case "fatal":
1706
- return clc.bold;
1707
- default:
1708
- return clc.green;
1830
+ throw new Error("[Navios] Wrong environment.");
1831
+ }
1832
+ function extractControllerMetadata(target) {
1833
+ const metadata = target[ControllerMetadataKey];
1834
+ if (!metadata) {
1835
+ throw new Error(
1836
+ "[Navios] Controller metadata not found. Make sure to use @Controller decorator."
1837
+ );
1838
+ }
1839
+ return metadata;
1840
+ }
1841
+ function hasControllerMetadata(target) {
1842
+ const metadata = target[ControllerMetadataKey];
1843
+ return !!metadata;
1844
+ }
1845
+
1846
+ // packages/core/src/metadata/module.metadata.mts
1847
+ var ModuleMetadataKey = Symbol("ControllerMetadataKey");
1848
+ function getModuleMetadata(target, context) {
1849
+ if (context.metadata) {
1850
+ const metadata = context.metadata[ModuleMetadataKey];
1851
+ if (metadata) {
1852
+ return metadata;
1853
+ } else {
1854
+ const newMetadata = {
1855
+ controllers: /* @__PURE__ */ new Set(),
1856
+ imports: /* @__PURE__ */ new Set(),
1857
+ guards: /* @__PURE__ */ new Set(),
1858
+ customAttributes: /* @__PURE__ */ new Map()
1859
+ };
1860
+ context.metadata[ModuleMetadataKey] = newMetadata;
1861
+ target[ModuleMetadataKey] = newMetadata;
1862
+ return newMetadata;
1709
1863
  }
1710
1864
  }
1711
- };
1712
- _init = __decoratorStart(null);
1713
- _ConsoleLogger = __decorateElement(_init, 0, "ConsoleLogger", _ConsoleLogger_decorators, _ConsoleLogger);
1714
- __runInitializers(_init, 1, _ConsoleLogger);
1715
- var ConsoleLogger = _ConsoleLogger;
1865
+ throw new Error("[Navios] Wrong environment.");
1866
+ }
1867
+ function extractModuleMetadata(target) {
1868
+ const metadata = target[ModuleMetadataKey];
1869
+ if (!metadata) {
1870
+ throw new Error(
1871
+ "[Navios] Module metadata not found. Make sure to use @Module decorator."
1872
+ );
1873
+ }
1874
+ return metadata;
1875
+ }
1876
+ function hasModuleMetadata(target) {
1877
+ return !!target[ModuleMetadataKey];
1878
+ }
1716
1879
 
1717
- // packages/core/src/logger/logger.factory.mts
1718
- var import_zod2 = require("zod");
1880
+ // packages/core/src/decorators/controller.decorator.mts
1881
+ function Controller({ guards } = {}) {
1882
+ return function(target, context) {
1883
+ if (context.kind !== "class") {
1884
+ throw new Error(
1885
+ "[Navios] @Controller decorator can only be used on classes."
1886
+ );
1887
+ }
1888
+ const token = InjectionToken.create(target);
1889
+ if (context.metadata) {
1890
+ const controllerMetadata = getControllerMetadata(target, context);
1891
+ if (guards) {
1892
+ for (const guard of Array.from(guards).reverse()) {
1893
+ controllerMetadata.guards.add(guard);
1894
+ }
1895
+ }
1896
+ }
1897
+ return Injectable({
1898
+ token,
1899
+ type: "Class" /* Class */,
1900
+ scope: "Instance" /* Instance */
1901
+ })(target, context);
1902
+ };
1903
+ }
1719
1904
 
1720
- // packages/core/src/logger/logger.service.mts
1721
- var DEFAULT_LOGGER = new ConsoleLogger();
1722
- var dateTimeFormatter2 = new Intl.DateTimeFormat(void 0, {
1723
- year: "numeric",
1724
- hour: "numeric",
1725
- minute: "numeric",
1726
- second: "numeric",
1727
- day: "2-digit",
1728
- month: "2-digit"
1729
- });
1730
- var _LoggerInstance_decorators, _init2;
1731
- _LoggerInstance_decorators = [Injectable()];
1732
- var _LoggerInstance = class _LoggerInstance {
1733
- constructor(context, options = {}) {
1734
- this.context = context;
1735
- this.options = options;
1736
- }
1737
- static staticInstanceRef = DEFAULT_LOGGER;
1738
- static logLevels;
1739
- localInstanceRef;
1740
- get localInstance() {
1741
- if (_LoggerInstance.staticInstanceRef === DEFAULT_LOGGER) {
1742
- return this.registerLocalInstanceRef();
1743
- } else if (_LoggerInstance.staticInstanceRef instanceof _LoggerInstance) {
1744
- const prototype = Object.getPrototypeOf(_LoggerInstance.staticInstanceRef);
1745
- if (prototype.constructor === _LoggerInstance) {
1746
- return this.registerLocalInstanceRef();
1905
+ // packages/core/src/decorators/endpoint.decorator.mts
1906
+ function Endpoint(endpoint) {
1907
+ return (target, context) => {
1908
+ if (typeof target !== "function") {
1909
+ throw new Error(
1910
+ "[Navios] Endpoint decorator can only be used on functions."
1911
+ );
1912
+ }
1913
+ if (context.kind !== "method") {
1914
+ throw new Error(
1915
+ "[Navios] Endpoint decorator can only be used on methods."
1916
+ );
1917
+ }
1918
+ const config = endpoint.config;
1919
+ if (context.metadata) {
1920
+ let endpointMetadata = getEndpointMetadata(target, context);
1921
+ if (endpointMetadata.config && endpointMetadata.config.url) {
1922
+ throw new Error(
1923
+ `[Navios] Endpoint ${config.method} ${config.url} already exists. Please use a different method or url.`
1924
+ );
1925
+ }
1926
+ endpointMetadata.config = config;
1927
+ endpointMetadata.classMethod = target.name;
1928
+ endpointMetadata.httpMethod = config.method;
1929
+ endpointMetadata.url = config.url;
1930
+ }
1931
+ return target;
1932
+ };
1933
+ }
1934
+
1935
+ // packages/core/src/decorators/module.decorator.mts
1936
+ function Module(metadata) {
1937
+ return (target, context) => {
1938
+ if (context.kind !== "class") {
1939
+ throw new Error("[Navios] @Module decorator can only be used on classes.");
1940
+ }
1941
+ const token = InjectionToken.create(target);
1942
+ const moduleMetadata = getModuleMetadata(target, context);
1943
+ if (metadata.controllers) {
1944
+ for (const controller of metadata.controllers) {
1945
+ moduleMetadata.controllers.add(controller);
1747
1946
  }
1748
1947
  }
1749
- return _LoggerInstance.staticInstanceRef;
1750
- }
1751
- error(message, ...optionalParams) {
1752
- var _a;
1753
- optionalParams = this.context ? (optionalParams.length ? optionalParams : [void 0]).concat(
1754
- this.context
1755
- ) : optionalParams;
1756
- (_a = this.localInstance) == null ? void 0 : _a.error(message, ...optionalParams);
1757
- }
1758
- log(message, ...optionalParams) {
1759
- var _a;
1760
- optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1761
- (_a = this.localInstance) == null ? void 0 : _a.log(message, ...optionalParams);
1762
- }
1763
- warn(message, ...optionalParams) {
1764
- var _a;
1765
- optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1766
- (_a = this.localInstance) == null ? void 0 : _a.warn(message, ...optionalParams);
1767
- }
1768
- debug(message, ...optionalParams) {
1769
- var _a, _b;
1770
- optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1771
- (_b = (_a = this.localInstance) == null ? void 0 : _a.debug) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1772
- }
1773
- verbose(message, ...optionalParams) {
1774
- var _a, _b;
1775
- optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1776
- (_b = (_a = this.localInstance) == null ? void 0 : _a.verbose) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1777
- }
1778
- fatal(message, ...optionalParams) {
1779
- var _a, _b;
1780
- optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1781
- (_b = (_a = this.localInstance) == null ? void 0 : _a.fatal) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1782
- }
1783
- static error(message, ...optionalParams) {
1784
- var _a;
1785
- (_a = this.staticInstanceRef) == null ? void 0 : _a.error(message, ...optionalParams);
1786
- }
1787
- static log(message, ...optionalParams) {
1788
- var _a;
1789
- (_a = this.staticInstanceRef) == null ? void 0 : _a.log(message, ...optionalParams);
1790
- }
1791
- static warn(message, ...optionalParams) {
1792
- var _a;
1793
- (_a = this.staticInstanceRef) == null ? void 0 : _a.warn(message, ...optionalParams);
1794
- }
1795
- static debug(message, ...optionalParams) {
1796
- var _a, _b;
1797
- (_b = (_a = this.staticInstanceRef) == null ? void 0 : _a.debug) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1798
- }
1799
- static verbose(message, ...optionalParams) {
1800
- var _a, _b;
1801
- (_b = (_a = this.staticInstanceRef) == null ? void 0 : _a.verbose) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1802
- }
1803
- static fatal(message, ...optionalParams) {
1804
- var _a, _b;
1805
- (_b = (_a = this.staticInstanceRef) == null ? void 0 : _a.fatal) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1806
- }
1807
- static getTimestamp() {
1808
- return dateTimeFormatter2.format(Date.now());
1809
- }
1810
- static overrideLogger(logger) {
1811
- var _a, _b;
1812
- console.log(logger);
1813
- if (Array.isArray(logger)) {
1814
- _LoggerInstance.logLevels = logger;
1815
- return (_b = (_a = this.staticInstanceRef) == null ? void 0 : _a.setLogLevels) == null ? void 0 : _b.call(_a, logger);
1948
+ if (metadata.imports) {
1949
+ for (const importedModule of metadata.imports) {
1950
+ moduleMetadata.imports.add(importedModule);
1951
+ }
1816
1952
  }
1817
- if (isObject(logger)) {
1818
- this.staticInstanceRef = logger;
1819
- } else {
1820
- this.staticInstanceRef = void 0;
1953
+ if (metadata.guards) {
1954
+ for (const guard of Array.from(metadata.guards).reverse()) {
1955
+ moduleMetadata.guards.add(guard);
1956
+ }
1821
1957
  }
1822
- }
1823
- static isLevelEnabled(level) {
1824
- const logLevels = _LoggerInstance.logLevels;
1825
- return isLogLevelEnabled(level, logLevels);
1826
- }
1827
- registerLocalInstanceRef() {
1828
- var _a;
1829
- if (this.localInstanceRef) {
1830
- return this.localInstanceRef;
1958
+ return Injectable({
1959
+ token,
1960
+ type: "Class" /* Class */,
1961
+ scope: "Singleton" /* Singleton */
1962
+ })(target, context);
1963
+ };
1964
+ }
1965
+
1966
+ // packages/core/src/decorators/use-guards.decorator.mts
1967
+ function UseGuards(...guards) {
1968
+ return function(target, context) {
1969
+ if (context.kind === "class") {
1970
+ const controllerMetadata = getControllerMetadata(
1971
+ target,
1972
+ context
1973
+ );
1974
+ for (const guard of guards.reverse()) {
1975
+ controllerMetadata.guards.add(guard);
1976
+ }
1977
+ } else if (context.kind === "method") {
1978
+ const endpointMetadata = getEndpointMetadata(target, context);
1979
+ for (const guard of guards.reverse()) {
1980
+ endpointMetadata.guards.add(guard);
1981
+ }
1982
+ } else {
1983
+ throw new Error(
1984
+ "[Navios] @UseGuards decorator can only be used on classes or methods."
1985
+ );
1831
1986
  }
1832
- this.localInstanceRef = new ConsoleLogger(this.context, {
1833
- timestamp: (_a = this.options) == null ? void 0 : _a.timestamp,
1834
- logLevels: _LoggerInstance.logLevels
1835
- });
1836
- return this.localInstanceRef;
1987
+ return target;
1988
+ };
1989
+ }
1990
+
1991
+ // packages/core/src/exceptions/http.exception.mts
1992
+ var HttpException = class {
1993
+ constructor(statusCode, response, error) {
1994
+ this.statusCode = statusCode;
1995
+ this.response = response;
1996
+ this.error = error;
1837
1997
  }
1838
1998
  };
1839
- _init2 = __decoratorStart(null);
1840
- _LoggerInstance = __decorateElement(_init2, 0, "LoggerInstance", _LoggerInstance_decorators, _LoggerInstance);
1841
- __runInitializers(_init2, 1, _LoggerInstance);
1842
- var LoggerInstance = _LoggerInstance;
1843
1999
 
1844
- // packages/core/src/logger/logger.factory.mts
1845
- var LoggerInjectionToken = "LoggerInjectionToken";
1846
- var LoggerOptions = import_zod2.z.object({
1847
- context: import_zod2.z.string().optional(),
1848
- options: import_zod2.z.object({
1849
- timestamp: import_zod2.z.boolean().optional()
1850
- }).optional()
1851
- }).optional();
1852
- var Logger = InjectionToken.create(LoggerInjectionToken, LoggerOptions);
1853
- var _LoggerFactory_decorators, _init3;
1854
- _LoggerFactory_decorators = [Injectable({
1855
- type: "Factory" /* Factory */,
1856
- token: Logger
1857
- })];
1858
- var LoggerFactory = class {
1859
- create(ctx, args) {
1860
- return new LoggerInstance(args == null ? void 0 : args.context, args == null ? void 0 : args.options);
2000
+ // packages/core/src/exceptions/bad-request.exception.mts
2001
+ var BadRequestException = class extends HttpException {
2002
+ constructor(message) {
2003
+ super(400, message);
1861
2004
  }
1862
2005
  };
1863
- _init3 = __decoratorStart(null);
1864
- LoggerFactory = __decorateElement(_init3, 0, "LoggerFactory", _LoggerFactory_decorators, LoggerFactory);
1865
- __runInitializers(_init3, 1, LoggerFactory);
1866
2006
 
1867
- // packages/core/src/logger/pino-wrapper.mts
1868
- var PinoWrapper = class _PinoWrapper {
1869
- constructor(logger) {
1870
- this.logger = logger;
1871
- }
1872
- fatal(message, ...optionalParams) {
1873
- if (this.logger.fatal === void 0) {
1874
- return this.error(message, ...optionalParams);
1875
- }
1876
- this.logger.fatal(message, ...optionalParams);
1877
- }
1878
- error(message, ...optionalParams) {
1879
- this.logger.error(message, ...optionalParams);
1880
- }
1881
- warn(message, ...optionalParams) {
1882
- this.logger.warn(message, ...optionalParams);
1883
- }
1884
- info(message, ...optionalParams) {
1885
- this.logger.log(message, ...optionalParams);
1886
- }
1887
- debug(message, ...optionalParams) {
1888
- var _a, _b;
1889
- (_b = (_a = this.logger).debug) == null ? void 0 : _b.call(_a, message, ...optionalParams);
2007
+ // packages/core/src/exceptions/forbidden.exception.mts
2008
+ var ForbiddenException = class extends HttpException {
2009
+ constructor(message) {
2010
+ super(403, message);
1890
2011
  }
1891
- trace(message, ...optionalParams) {
1892
- var _a, _b;
1893
- (_b = (_a = this.logger).verbose) == null ? void 0 : _b.call(_a, message, ...optionalParams);
2012
+ };
2013
+
2014
+ // packages/core/src/exceptions/internal-server-error.exception.mts
2015
+ var InternalServerErrorException = class extends HttpException {
2016
+ constructor(message, error) {
2017
+ super(500, message, error);
1894
2018
  }
1895
- silent(message, ...optionalParams) {
2019
+ };
2020
+
2021
+ // packages/core/src/exceptions/not-found.exception.mts
2022
+ var NotFoundException = class extends HttpException {
2023
+ constructor(response, error) {
2024
+ super(404, response, error);
2025
+ this.response = response;
2026
+ this.error = error;
1896
2027
  }
1897
- child(options) {
1898
- const keys = Object.keys(options);
1899
- let newContext = this.logger["context"] ?? "";
1900
- if (keys.length > 1) {
1901
- newContext = `${this.logger["context"] ?? ""}:${JSON.stringify(options)}`;
1902
- }
1903
- return new _PinoWrapper(
1904
- // @ts-expect-error We don't need to support this in the current version
1905
- new LoggerInstance(newContext, this.logger["options"])
1906
- );
2028
+ };
2029
+
2030
+ // packages/core/src/exceptions/unauthorized.exception.mts
2031
+ var UnauthorizedException = class extends HttpException {
2032
+ constructor(message, error) {
2033
+ super(401, message, error);
1907
2034
  }
1908
- get level() {
1909
- if ("level" in this.logger && this.logger.level) {
1910
- return this.logger.level;
1911
- }
1912
- const levels = LoggerInstance["logLevels"];
1913
- if (levels) {
1914
- return levels[0];
1915
- }
1916
- return "info";
2035
+ };
2036
+
2037
+ // packages/core/src/exceptions/conflict.exception.mts
2038
+ var ConflictException = class extends HttpException {
2039
+ constructor(message, error) {
2040
+ super(409, message, error);
1917
2041
  }
1918
2042
  };
1919
2043
 
@@ -1982,7 +2106,7 @@ var ExecutionContext2 = class {
1982
2106
  };
1983
2107
 
1984
2108
  // packages/core/src/services/guard-runner.service.mts
1985
- var _GuardRunnerService_decorators, _init4;
2109
+ var _GuardRunnerService_decorators, _init5;
1986
2110
  _GuardRunnerService_decorators = [Injectable()];
1987
2111
  var GuardRunnerService = class {
1988
2112
  async runGuards(allGuards, executionContext) {
@@ -2045,12 +2169,12 @@ var GuardRunnerService = class {
2045
2169
  return guards;
2046
2170
  }
2047
2171
  };
2048
- _init4 = __decoratorStart(null);
2049
- GuardRunnerService = __decorateElement(_init4, 0, "GuardRunnerService", _GuardRunnerService_decorators, GuardRunnerService);
2050
- __runInitializers(_init4, 1, GuardRunnerService);
2172
+ _init5 = __decoratorStart(null);
2173
+ GuardRunnerService = __decorateElement(_init5, 0, "GuardRunnerService", _GuardRunnerService_decorators, GuardRunnerService);
2174
+ __runInitializers(_init5, 1, GuardRunnerService);
2051
2175
 
2052
2176
  // packages/core/src/services/controller-adapter.service.mts
2053
- var _ControllerAdapterService_decorators, _init5;
2177
+ var _ControllerAdapterService_decorators, _init6;
2054
2178
  _ControllerAdapterService_decorators = [Injectable()];
2055
2179
  var _ControllerAdapterService = class _ControllerAdapterService {
2056
2180
  guardRunner = syncInject(GuardRunnerService);
@@ -2157,13 +2281,13 @@ var _ControllerAdapterService = class _ControllerAdapterService {
2157
2281
  }
2158
2282
  }
2159
2283
  };
2160
- _init5 = __decoratorStart(null);
2161
- _ControllerAdapterService = __decorateElement(_init5, 0, "ControllerAdapterService", _ControllerAdapterService_decorators, _ControllerAdapterService);
2162
- __runInitializers(_init5, 1, _ControllerAdapterService);
2284
+ _init6 = __decoratorStart(null);
2285
+ _ControllerAdapterService = __decorateElement(_init6, 0, "ControllerAdapterService", _ControllerAdapterService_decorators, _ControllerAdapterService);
2286
+ __runInitializers(_init6, 1, _ControllerAdapterService);
2163
2287
  var ControllerAdapterService = _ControllerAdapterService;
2164
2288
 
2165
2289
  // packages/core/src/services/module-loader.service.mts
2166
- var _ModuleLoaderService_decorators, _init6;
2290
+ var _ModuleLoaderService_decorators, _init7;
2167
2291
  _ModuleLoaderService_decorators = [Injectable()];
2168
2292
  var _ModuleLoaderService = class _ModuleLoaderService {
2169
2293
  logger = syncInject(Logger, {
@@ -2220,9 +2344,9 @@ var _ModuleLoaderService = class _ModuleLoaderService {
2220
2344
  return this.modulesMetadata;
2221
2345
  }
2222
2346
  };
2223
- _init6 = __decoratorStart(null);
2224
- _ModuleLoaderService = __decorateElement(_init6, 0, "ModuleLoaderService", _ModuleLoaderService_decorators, _ModuleLoaderService);
2225
- __runInitializers(_init6, 1, _ModuleLoaderService);
2347
+ _init7 = __decoratorStart(null);
2348
+ _ModuleLoaderService = __decorateElement(_init7, 0, "ModuleLoaderService", _ModuleLoaderService_decorators, _ModuleLoaderService);
2349
+ __runInitializers(_init7, 1, _ModuleLoaderService);
2226
2350
  var ModuleLoaderService = _ModuleLoaderService;
2227
2351
 
2228
2352
  // packages/core/src/attribute.factory.mts
@@ -2286,7 +2410,7 @@ var AttributeFactory = class {
2286
2410
  var import_cors = __toESM(require("@fastify/cors"), 1);
2287
2411
  var import_fastify = require("fastify");
2288
2412
  var import_fastify_type_provider_zod = require("fastify-type-provider-zod");
2289
- var _NaviosApplication_decorators, _init7;
2413
+ var _NaviosApplication_decorators, _init8;
2290
2414
  _NaviosApplication_decorators = [Injectable()];
2291
2415
  var _NaviosApplication = class _NaviosApplication {
2292
2416
  moduleLoader = syncInject(ModuleLoaderService);
@@ -2391,9 +2515,9 @@ var _NaviosApplication = class _NaviosApplication {
2391
2515
  await this.server.listen(options);
2392
2516
  }
2393
2517
  };
2394
- _init7 = __decoratorStart(null);
2395
- _NaviosApplication = __decorateElement(_init7, 0, "NaviosApplication", _NaviosApplication_decorators, _NaviosApplication);
2396
- __runInitializers(_init7, 1, _NaviosApplication);
2518
+ _init8 = __decoratorStart(null);
2519
+ _NaviosApplication = __decorateElement(_init8, 0, "NaviosApplication", _NaviosApplication_decorators, _NaviosApplication);
2520
+ __runInitializers(_init8, 1, _NaviosApplication);
2397
2521
  var NaviosApplication = _NaviosApplication;
2398
2522
 
2399
2523
  // packages/core/src/navios.factory.mts
@@ -2419,6 +2543,11 @@ var NaviosFactory = class {
2419
2543
  Application,
2420
2544
  AttributeFactory,
2421
2545
  BadRequestException,
2546
+ ConfigProvider,
2547
+ ConfigProviderFactory,
2548
+ ConfigProviderInjectionToken,
2549
+ ConfigProviderOptions,
2550
+ ConfigServiceInstance,
2422
2551
  ConflictException,
2423
2552
  ConsoleLogger,
2424
2553
  Controller,
@@ -2469,6 +2598,8 @@ var NaviosFactory = class {
2469
2598
  UseGuards,
2470
2599
  addLeadingSlash,
2471
2600
  clc,
2601
+ envInt,
2602
+ envString,
2472
2603
  extractControllerMetadata,
2473
2604
  extractModuleMetadata,
2474
2605
  filterLogLevels,
@@ -2493,6 +2624,7 @@ var NaviosFactory = class {
2493
2624
  isString,
2494
2625
  isSymbol,
2495
2626
  isUndefined,
2627
+ makeConfigToken,
2496
2628
  normalizePath,
2497
2629
  override,
2498
2630
  provideServiceLocator,