@navios/core 1.0.0-alpha.2 → 1.0.0-alpha.4

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 (93) hide show
  1. package/CHANGELOG.md +90 -0
  2. package/lib/{index-BJjk2X1S.d.mts → index-6S7veHKD.d.mts} +845 -294
  3. package/lib/index-6S7veHKD.d.mts.map +1 -0
  4. package/lib/{index-DZ6NU03y.d.cts → index-r0i2txmg.d.cts} +845 -294
  5. package/lib/index-r0i2txmg.d.cts.map +1 -0
  6. package/lib/index.cjs +4420 -84
  7. package/lib/index.cjs.map +1 -0
  8. package/lib/index.d.cts +2 -2
  9. package/lib/index.d.mts +2 -2
  10. package/lib/index.mjs +4328 -3
  11. package/lib/index.mjs.map +1 -0
  12. package/lib/legacy-compat/index.cjs +41 -126
  13. package/lib/legacy-compat/index.cjs.map +1 -1
  14. package/lib/legacy-compat/index.d.cts +4 -60
  15. package/lib/legacy-compat/index.d.cts.map +1 -1
  16. package/lib/legacy-compat/index.d.mts +4 -60
  17. package/lib/legacy-compat/index.d.mts.map +1 -1
  18. package/lib/legacy-compat/index.mjs +14 -119
  19. package/lib/legacy-compat/index.mjs.map +1 -1
  20. package/lib/navios.factory-BanZIvtR.cjs +4134 -0
  21. package/lib/navios.factory-BanZIvtR.cjs.map +1 -0
  22. package/lib/navios.factory-C75yZCoD.mjs +3831 -0
  23. package/lib/navios.factory-C75yZCoD.mjs.map +1 -0
  24. package/lib/testing/index.cjs +3 -3
  25. package/lib/testing/index.cjs.map +1 -1
  26. package/lib/testing/index.d.cts +1 -1
  27. package/lib/testing/index.d.mts +1 -1
  28. package/lib/testing/index.mjs +2 -2
  29. package/lib/tokens-4J9sredA.mjs +100 -0
  30. package/lib/tokens-4J9sredA.mjs.map +1 -0
  31. package/lib/tokens-BuXXB01L.cjs +196 -0
  32. package/lib/tokens-BuXXB01L.cjs.map +1 -0
  33. package/lib/{use-guards.decorator-Be_QUx6b.mjs → use-guards.decorator-BecoQSmE.mjs} +3 -70
  34. package/lib/use-guards.decorator-BecoQSmE.mjs.map +1 -0
  35. package/lib/{use-guards.decorator-B6tghdxM.cjs → use-guards.decorator-DgD-kxF5.cjs} +7 -158
  36. package/lib/use-guards.decorator-DgD-kxF5.cjs.map +1 -0
  37. package/package.json +4 -4
  38. package/src/__tests__/attribute.factory.spec.mts +300 -0
  39. package/src/__tests__/console-logger.service.spec.mts +312 -0
  40. package/src/__tests__/guard-runner.service.spec.mts +399 -0
  41. package/src/__tests__/logger.service.spec.mts +147 -0
  42. package/src/__tests__/responders.spec.mts +6 -5
  43. package/src/factories/adapter.factory.mts +20 -0
  44. package/src/factories/endpoint-adapter.factory.mts +1 -1
  45. package/src/factories/http-adapter.factory.mts +1 -1
  46. package/src/factories/index.mts +1 -0
  47. package/src/factories/multipart-adapter.factory.mts +1 -1
  48. package/src/factories/reply.factory.mts +1 -1
  49. package/src/factories/request.factory.mts +1 -1
  50. package/src/factories/stream-adapter.factory.mts +1 -1
  51. package/src/factories/xml-stream-adapter.factory.mts +1 -1
  52. package/src/index.mts +1 -0
  53. package/src/interfaces/abstract-adapter.interface.mts +32 -0
  54. package/src/interfaces/abstract-http-adapter.interface.mts +27 -20
  55. package/src/interfaces/abstract-http-handler-adapter.interface.mts +86 -2
  56. package/src/interfaces/adapter-environment.interface.mts +74 -0
  57. package/src/interfaces/index.mts +2 -0
  58. package/src/interfaces/plugin.interface.mts +50 -16
  59. package/src/legacy-compat/attribute.factory.mts +2 -2
  60. package/src/legacy-compat/decorators/controller.decorator.mts +1 -1
  61. package/src/legacy-compat/decorators/endpoint.decorator.mts +1 -1
  62. package/src/legacy-compat/decorators/header.decorator.mts +2 -1
  63. package/src/legacy-compat/decorators/http-code.decorator.mts +2 -1
  64. package/src/legacy-compat/decorators/index.mts +2 -2
  65. package/src/legacy-compat/decorators/module.decorator.mts +1 -1
  66. package/src/legacy-compat/decorators/multipart.decorator.mts +1 -1
  67. package/src/legacy-compat/decorators/stream.decorator.mts +1 -1
  68. package/src/legacy-compat/decorators/use-guards.decorator.mts +1 -1
  69. package/src/legacy-compat/index.mts +10 -5
  70. package/src/logger/console-logger.service.mts +97 -7
  71. package/src/metadata/module.metadata.mts +43 -0
  72. package/src/navios.application.mts +172 -60
  73. package/src/navios.environment.mts +22 -12
  74. package/src/navios.factory.mts +31 -10
  75. package/src/services/abstract-handler-adapter.service.mts +366 -0
  76. package/src/services/index.mts +1 -0
  77. package/src/services/module-loader.service.mts +1 -0
  78. package/src/tokens/adapter.token.mts +6 -0
  79. package/src/tokens/http-adapter.token.mts +1 -1
  80. package/src/tokens/index.mts +1 -0
  81. package/src/utils/adapter-supports.util.mts +47 -0
  82. package/src/utils/index.mts +1 -0
  83. package/lib/index-BJjk2X1S.d.mts.map +0 -1
  84. package/lib/index-DZ6NU03y.d.cts.map +0 -1
  85. package/lib/src-C46ePe3d.cjs +0 -8022
  86. package/lib/src-C46ePe3d.cjs.map +0 -1
  87. package/lib/src-K2k0riYJ.mjs +0 -7587
  88. package/lib/src-K2k0riYJ.mjs.map +0 -1
  89. package/lib/use-guards.decorator-B6tghdxM.cjs.map +0 -1
  90. package/lib/use-guards.decorator-Be_QUx6b.mjs.map +0 -1
  91. package/src/legacy-compat/context-compat.mts +0 -95
  92. package/src/legacy-compat/decorators/factory.decorator.mts +0 -37
  93. package/src/legacy-compat/decorators/injectable.decorator.mts +0 -41
@@ -0,0 +1,4134 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+ const require_tokens = require('./tokens-BuXXB01L.cjs');
29
+ let _navios_di = require("@navios/di");
30
+ let zod_v4 = require("zod/v4");
31
+ zod_v4 = __toESM(zod_v4);
32
+ let util = require("util");
33
+ let node_async_hooks = require("node:async_hooks");
34
+
35
+ //#region src/logger/utils/cli-colors.util.mts
36
+ const isColorAllowed = () => !process.env.NO_COLOR;
37
+ const colorIfAllowed = (colorFn) => (text) => isColorAllowed() ? colorFn(text) : text;
38
+ const clc = {
39
+ bold: colorIfAllowed((text) => `\x1B[1m${text}\x1B[0m`),
40
+ green: colorIfAllowed((text) => `\x1B[32m${text}\x1B[39m`),
41
+ yellow: colorIfAllowed((text) => `\x1B[33m${text}\x1B[39m`),
42
+ red: colorIfAllowed((text) => `\x1B[31m${text}\x1B[39m`),
43
+ magentaBright: colorIfAllowed((text) => `\x1B[95m${text}\x1B[39m`),
44
+ cyanBright: colorIfAllowed((text) => `\x1B[96m${text}\x1B[39m`)
45
+ };
46
+ const yellow = colorIfAllowed((text) => `\x1B[38;5;3m${text}\x1B[39m`);
47
+
48
+ //#endregion
49
+ //#region src/logger/log-levels.mts
50
+ /**
51
+ * Available log levels in order of severity (lowest to highest).
52
+ */ const LOG_LEVELS = [
53
+ "verbose",
54
+ "debug",
55
+ "log",
56
+ "warn",
57
+ "error",
58
+ "fatal"
59
+ ];
60
+
61
+ //#endregion
62
+ //#region src/logger/utils/is-log-level.util.mts
63
+ /**
64
+ * @publicApi
65
+ */ function isLogLevel(maybeLogLevel) {
66
+ return LOG_LEVELS.includes(maybeLogLevel);
67
+ }
68
+
69
+ //#endregion
70
+ //#region src/logger/utils/filter-log-levelts.util.mts
71
+ /**
72
+ * @publicApi
73
+ */ function filterLogLevels(parseableString = "") {
74
+ const sanitizedString = parseableString.replaceAll(" ", "").toLowerCase();
75
+ if (sanitizedString[0] === ">") {
76
+ const orEqual = sanitizedString[1] === "=";
77
+ const logLevelIndex = LOG_LEVELS.indexOf(sanitizedString.substring(orEqual ? 2 : 1));
78
+ if (logLevelIndex === -1) throw new Error(`parse error (unknown log level): ${sanitizedString}`);
79
+ return LOG_LEVELS.slice(orEqual ? logLevelIndex : logLevelIndex + 1);
80
+ } else if (sanitizedString.includes(",")) return sanitizedString.split(",").filter(isLogLevel);
81
+ return isLogLevel(sanitizedString) ? [sanitizedString] : LOG_LEVELS;
82
+ }
83
+
84
+ //#endregion
85
+ //#region src/logger/utils/is-log-level-enabled.mts
86
+ const LOG_LEVEL_VALUES = {
87
+ verbose: 0,
88
+ debug: 1,
89
+ log: 2,
90
+ warn: 3,
91
+ error: 4,
92
+ fatal: 5
93
+ };
94
+ /**
95
+ * Checks if target level is enabled.
96
+ * @param targetLevel target level
97
+ * @param logLevels array of enabled log levels
98
+ */ function isLogLevelEnabled(targetLevel, logLevels) {
99
+ if (!logLevels || Array.isArray(logLevels) && logLevels?.length === 0) return false;
100
+ if (logLevels.includes(targetLevel)) return true;
101
+ const highestLogLevelValue = logLevels.map((level) => LOG_LEVEL_VALUES[level]).sort((a, b) => b - a)?.[0];
102
+ return LOG_LEVEL_VALUES[targetLevel] >= highestLogLevelValue;
103
+ }
104
+
105
+ //#endregion
106
+ //#region src/logger/utils/shared.utils.mts
107
+ const isUndefined = (obj) => typeof obj === "undefined";
108
+ const isObject = (fn) => !isNil(fn) && typeof fn === "object";
109
+ const isPlainObject = (fn) => {
110
+ if (!isObject(fn)) return false;
111
+ const proto = Object.getPrototypeOf(fn);
112
+ if (proto === null) return true;
113
+ const ctor = Object.prototype.hasOwnProperty.call(proto, "constructor") && proto.constructor;
114
+ return typeof ctor === "function" && ctor instanceof ctor && Function.prototype.toString.call(ctor) === Function.prototype.toString.call(Object);
115
+ };
116
+ const addLeadingSlash = (path) => path && typeof path === "string" ? path.charAt(0) !== "/" && path.substring(0, 2) !== "{/" ? "/" + path : path : "";
117
+ const normalizePath = (path) => path ? path.startsWith("/") ? ("/" + path.replace(/\/+$/, "")).replace(/\/+/g, "/") : "/" + path.replace(/\/+$/, "") : "/";
118
+ const stripEndSlash = (path) => path[path.length - 1] === "/" ? path.slice(0, path.length - 1) : path;
119
+ const isFunction = (val) => typeof val === "function";
120
+ const isString = (val) => typeof val === "string";
121
+ const isNumber = (val) => typeof val === "number";
122
+ const isConstructor = (val) => val === "constructor";
123
+ const isNil = (val) => isUndefined(val) || val === null;
124
+ const isEmpty = (array) => !(array && array.length > 0);
125
+ const isSymbol = (val) => typeof val === "symbol";
126
+
127
+ //#endregion
128
+ //#region src/stores/request-id.store.mts
129
+ let requestCounter = 0;
130
+ /**
131
+ * Generates a simple incremental request ID.
132
+ * Much faster than crypto.randomUUID() and sufficient for request tracking.
133
+ *
134
+ * @returns A unique request ID string (e.g., "req-1", "req-2", ...)
135
+ */ function generateRequestId() {
136
+ return `req-${++requestCounter}`;
137
+ }
138
+ /**
139
+ * AsyncLocalStorage store for the current request ID.
140
+ *
141
+ * This allows logging and other services to access the current request ID
142
+ * without explicitly passing it through the call stack.
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * import { requestIdStore, runWithRequestId, getRequestId } from '@navios/core'
147
+ *
148
+ * // Run code with a request ID in context
149
+ * runWithRequestId('req-123', () => {
150
+ * // Inside this callback, getRequestId() returns 'req-123'
151
+ * logger.log('Processing request') // Will include request ID if logger is configured
152
+ * })
153
+ *
154
+ * // Get current request ID (returns undefined if not in a request context)
155
+ * const currentId = getRequestId()
156
+ * ```
157
+ */ let requestIdStore = null;
158
+ function getRequestIdStore() {
159
+ if (!requestIdStore) requestIdStore = new node_async_hooks.AsyncLocalStorage();
160
+ return requestIdStore;
161
+ }
162
+ /**
163
+ * Whether request ID propagation is enabled.
164
+ * When disabled, runWithRequestId is a pass-through for better performance.
165
+ */ let requestIdEnabled = false;
166
+ /**
167
+ * Enables or disables request ID propagation.
168
+ * Called by NaviosFactory based on the enableRequestId option.
169
+ *
170
+ * @param enabled - Whether to enable request ID propagation
171
+ */ function setRequestIdEnabled(enabled) {
172
+ requestIdEnabled = enabled;
173
+ }
174
+ /**
175
+ * Runs a function with a request ID in the async local storage context.
176
+ * If request ID propagation is disabled, the function is called directly
177
+ * without AsyncLocalStorage overhead.
178
+ *
179
+ * @param requestId - The request ID to set for this context
180
+ * @param fn - The function to run within this context
181
+ * @returns The return value of the function
182
+ */ function runWithRequestId(requestId, fn) {
183
+ if (!requestIdEnabled) return fn();
184
+ return getRequestIdStore().run(requestId, fn);
185
+ }
186
+ /**
187
+ * Gets the current request ID from the async local storage context.
188
+ *
189
+ * @returns The current request ID, or undefined if not in a request context
190
+ */ function getRequestId() {
191
+ if (!requestIdEnabled) return;
192
+ return getRequestIdStore().getStore();
193
+ }
194
+
195
+ //#endregion
196
+ //#region src/logger/logger.tokens.mts
197
+ /**
198
+ * Injection token for the logger output service.
199
+ *
200
+ * This token is used to provide a custom logger implementation.
201
+ * By default, it's bound to ConsoleLogger.
202
+ */ const LoggerOutput = _navios_di.InjectionToken.create("LoggerOutput");
203
+ /**
204
+ * Schema for logger options.
205
+ */ const loggerOptionsSchema = zod_v4.default.object({ context: zod_v4.default.string().optional() }).optional();
206
+ /**
207
+ * Injection token for the Logger service.
208
+ *
209
+ * Use this token to inject a contextualized logger instance.
210
+ *
211
+ * @example
212
+ * ```typescript
213
+ * const logger = inject(Logger, { context: 'MyService' })
214
+ * logger.log('Hello world') // Logs with context: [MyService]
215
+ * ```
216
+ */ const Logger = _navios_di.InjectionToken.create("Logger", loggerOptionsSchema);
217
+
218
+ //#endregion
219
+ //#region src/logger/console-logger.service.mts
220
+ function applyDecs2203RFactory$7() {
221
+ function createAddInitializerMethod(initializers, decoratorFinishedRef) {
222
+ return function addInitializer(initializer) {
223
+ assertNotFinished(decoratorFinishedRef, "addInitializer");
224
+ assertCallable(initializer, "An initializer");
225
+ initializers.push(initializer);
226
+ };
227
+ }
228
+ function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
229
+ var kindStr;
230
+ switch (kind) {
231
+ case 1:
232
+ kindStr = "accessor";
233
+ break;
234
+ case 2:
235
+ kindStr = "method";
236
+ break;
237
+ case 3:
238
+ kindStr = "getter";
239
+ break;
240
+ case 4:
241
+ kindStr = "setter";
242
+ break;
243
+ default: kindStr = "field";
244
+ }
245
+ var ctx = {
246
+ kind: kindStr,
247
+ name: isPrivate ? "#" + name : name,
248
+ static: isStatic,
249
+ private: isPrivate,
250
+ metadata
251
+ };
252
+ var decoratorFinishedRef = { v: false };
253
+ ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
254
+ var get, set;
255
+ if (kind === 0) if (isPrivate) {
256
+ get = desc.get;
257
+ set = desc.set;
258
+ } else {
259
+ get = function() {
260
+ return this[name];
261
+ };
262
+ set = function(v) {
263
+ this[name] = v;
264
+ };
265
+ }
266
+ else if (kind === 2) get = function() {
267
+ return desc.value;
268
+ };
269
+ else {
270
+ if (kind === 1 || kind === 3) get = function() {
271
+ return desc.get.call(this);
272
+ };
273
+ if (kind === 1 || kind === 4) set = function(v) {
274
+ desc.set.call(this, v);
275
+ };
276
+ }
277
+ ctx.access = get && set ? {
278
+ get,
279
+ set
280
+ } : get ? { get } : { set };
281
+ try {
282
+ return dec(value, ctx);
283
+ } finally {
284
+ decoratorFinishedRef.v = true;
285
+ }
286
+ }
287
+ function assertNotFinished(decoratorFinishedRef, fnName) {
288
+ if (decoratorFinishedRef.v) throw new Error("attempted to call " + fnName + " after decoration was finished");
289
+ }
290
+ function assertCallable(fn, hint) {
291
+ if (typeof fn !== "function") throw new TypeError(hint + " must be a function");
292
+ }
293
+ function assertValidReturnValue(kind, value) {
294
+ var type = typeof value;
295
+ if (kind === 1) {
296
+ if (type !== "object" || value === null) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
297
+ if (value.get !== void 0) assertCallable(value.get, "accessor.get");
298
+ if (value.set !== void 0) assertCallable(value.set, "accessor.set");
299
+ if (value.init !== void 0) assertCallable(value.init, "accessor.init");
300
+ } else if (type !== "function") {
301
+ var hint;
302
+ if (kind === 0) hint = "field";
303
+ else if (kind === 10) hint = "class";
304
+ else hint = "method";
305
+ throw new TypeError(hint + " decorators must return a function or void 0");
306
+ }
307
+ }
308
+ function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
309
+ var decs = decInfo[0];
310
+ var desc, init, value;
311
+ if (isPrivate) if (kind === 0 || kind === 1) desc = {
312
+ get: decInfo[3],
313
+ set: decInfo[4]
314
+ };
315
+ else if (kind === 3) desc = { get: decInfo[3] };
316
+ else if (kind === 4) desc = { set: decInfo[3] };
317
+ else desc = { value: decInfo[3] };
318
+ else if (kind !== 0) desc = Object.getOwnPropertyDescriptor(base, name);
319
+ if (kind === 1) value = {
320
+ get: desc.get,
321
+ set: desc.set
322
+ };
323
+ else if (kind === 2) value = desc.value;
324
+ else if (kind === 3) value = desc.get;
325
+ else if (kind === 4) value = desc.set;
326
+ var newValue, get, set;
327
+ if (typeof decs === "function") {
328
+ newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
329
+ if (newValue !== void 0) {
330
+ assertValidReturnValue(kind, newValue);
331
+ if (kind === 0) init = newValue;
332
+ else if (kind === 1) {
333
+ init = newValue.init;
334
+ get = newValue.get || value.get;
335
+ set = newValue.set || value.set;
336
+ value = {
337
+ get,
338
+ set
339
+ };
340
+ } else value = newValue;
341
+ }
342
+ } else for (var i = decs.length - 1; i >= 0; i--) {
343
+ var dec = decs[i];
344
+ newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
345
+ if (newValue !== void 0) {
346
+ assertValidReturnValue(kind, newValue);
347
+ var newInit;
348
+ if (kind === 0) newInit = newValue;
349
+ else if (kind === 1) {
350
+ newInit = newValue.init;
351
+ get = newValue.get || value.get;
352
+ set = newValue.set || value.set;
353
+ value = {
354
+ get,
355
+ set
356
+ };
357
+ } else value = newValue;
358
+ if (newInit !== void 0) if (init === void 0) init = newInit;
359
+ else if (typeof init === "function") init = [init, newInit];
360
+ else init.push(newInit);
361
+ }
362
+ }
363
+ if (kind === 0 || kind === 1) {
364
+ if (init === void 0) init = function(instance, init$1) {
365
+ return init$1;
366
+ };
367
+ else if (typeof init !== "function") {
368
+ var ownInitializers = init;
369
+ init = function(instance, init$1) {
370
+ var value$1 = init$1;
371
+ for (var i$1 = 0; i$1 < ownInitializers.length; i$1++) value$1 = ownInitializers[i$1].call(instance, value$1);
372
+ return value$1;
373
+ };
374
+ } else {
375
+ var originalInitializer = init;
376
+ init = function(instance, init$1) {
377
+ return originalInitializer.call(instance, init$1);
378
+ };
379
+ }
380
+ ret.push(init);
381
+ }
382
+ if (kind !== 0) {
383
+ if (kind === 1) {
384
+ desc.get = value.get;
385
+ desc.set = value.set;
386
+ } else if (kind === 2) desc.value = value;
387
+ else if (kind === 3) desc.get = value;
388
+ else if (kind === 4) desc.set = value;
389
+ if (isPrivate) if (kind === 1) {
390
+ ret.push(function(instance, args) {
391
+ return value.get.call(instance, args);
392
+ });
393
+ ret.push(function(instance, args) {
394
+ return value.set.call(instance, args);
395
+ });
396
+ } else if (kind === 2) ret.push(value);
397
+ else ret.push(function(instance, args) {
398
+ return value.call(instance, args);
399
+ });
400
+ else Object.defineProperty(base, name, desc);
401
+ }
402
+ }
403
+ function applyMemberDecs(Class, decInfos, metadata) {
404
+ var ret = [];
405
+ var protoInitializers;
406
+ var staticInitializers;
407
+ var existingProtoNonFields = /* @__PURE__ */ new Map();
408
+ var existingStaticNonFields = /* @__PURE__ */ new Map();
409
+ for (var i = 0; i < decInfos.length; i++) {
410
+ var decInfo = decInfos[i];
411
+ if (!Array.isArray(decInfo)) continue;
412
+ var kind = decInfo[1];
413
+ var name = decInfo[2];
414
+ var isPrivate = decInfo.length > 3;
415
+ var isStatic = kind >= 5;
416
+ var base;
417
+ var initializers;
418
+ if (isStatic) {
419
+ base = Class;
420
+ kind = kind - 5;
421
+ staticInitializers = staticInitializers || [];
422
+ initializers = staticInitializers;
423
+ } else {
424
+ base = Class.prototype;
425
+ protoInitializers = protoInitializers || [];
426
+ initializers = protoInitializers;
427
+ }
428
+ if (kind !== 0 && !isPrivate) {
429
+ var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
430
+ var existingKind = existingNonFields.get(name) || 0;
431
+ if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
432
+ else if (!existingKind && kind > 2) existingNonFields.set(name, kind);
433
+ else existingNonFields.set(name, true);
434
+ }
435
+ applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
436
+ }
437
+ pushInitializers(ret, protoInitializers);
438
+ pushInitializers(ret, staticInitializers);
439
+ return ret;
440
+ }
441
+ function pushInitializers(ret, initializers) {
442
+ if (initializers) ret.push(function(instance) {
443
+ for (var i = 0; i < initializers.length; i++) initializers[i].call(instance);
444
+ return instance;
445
+ });
446
+ }
447
+ function applyClassDecs(targetClass, classDecs, metadata) {
448
+ if (classDecs.length > 0) {
449
+ var initializers = [];
450
+ var newClass = targetClass;
451
+ var name = targetClass.name;
452
+ for (var i = classDecs.length - 1; i >= 0; i--) {
453
+ var decoratorFinishedRef = { v: false };
454
+ try {
455
+ var nextNewClass = classDecs[i](newClass, {
456
+ kind: "class",
457
+ name,
458
+ addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
459
+ metadata
460
+ });
461
+ } finally {
462
+ decoratorFinishedRef.v = true;
463
+ }
464
+ if (nextNewClass !== void 0) {
465
+ assertValidReturnValue(10, nextNewClass);
466
+ newClass = nextNewClass;
467
+ }
468
+ }
469
+ return [defineMetadata(newClass, metadata), function() {
470
+ for (var i$1 = 0; i$1 < initializers.length; i$1++) initializers[i$1].call(newClass);
471
+ }];
472
+ }
473
+ }
474
+ function defineMetadata(Class, metadata) {
475
+ return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
476
+ configurable: true,
477
+ enumerable: true,
478
+ value: metadata
479
+ });
480
+ }
481
+ return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
482
+ if (parentClass !== void 0) var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
483
+ var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
484
+ var e = applyMemberDecs(targetClass, memberDecs, metadata);
485
+ if (!classDecs.length) defineMetadata(targetClass, metadata);
486
+ return {
487
+ e,
488
+ get c() {
489
+ return applyClassDecs(targetClass, classDecs, metadata);
490
+ }
491
+ };
492
+ };
493
+ }
494
+ function _apply_decs_2203_r$7(targetClass, memberDecs, classDecs, parentClass) {
495
+ return (_apply_decs_2203_r$7 = applyDecs2203RFactory$7())(targetClass, memberDecs, classDecs, parentClass);
496
+ }
497
+ function _identity(x) {
498
+ return x;
499
+ }
500
+ var _dec$7, _initClass$7;
501
+ const DEFAULT_DEPTH = 5;
502
+ const DEFAULT_LOG_LEVELS = [
503
+ "log",
504
+ "error",
505
+ "warn",
506
+ "debug",
507
+ "verbose",
508
+ "fatal"
509
+ ];
510
+ const dateTimeFormatter = new Intl.DateTimeFormat(void 0, {
511
+ year: "numeric",
512
+ hour: "numeric",
513
+ minute: "numeric",
514
+ second: "numeric",
515
+ day: "2-digit",
516
+ month: "2-digit"
517
+ });
518
+ let _ConsoleLogger;
519
+ _dec$7 = (0, _navios_di.Injectable)({ token: LoggerOutput });
520
+ new class extends _identity {
521
+ constructor() {
522
+ super(_ConsoleLogger), _initClass$7();
523
+ }
524
+ static {
525
+ class ConsoleLogger {
526
+ static {
527
+ ({c: [_ConsoleLogger, _initClass$7]} = _apply_decs_2203_r$7(this, [], [_dec$7]));
528
+ }
529
+ static create(contextOrOptions, options) {
530
+ const logger = new ConsoleLogger();
531
+ if (contextOrOptions !== void 0) if (typeof contextOrOptions === "string") logger.setup(contextOrOptions, options ?? {});
532
+ else logger.setup(contextOrOptions);
533
+ else logger.setup();
534
+ return logger;
535
+ }
536
+ /**
537
+ * The options of the logger.
538
+ */ options = {};
539
+ /**
540
+ * The context of the logger (can be set manually or automatically inferred).
541
+ */ context;
542
+ /**
543
+ * The original context of the logger (set in the constructor).
544
+ */ originalContext;
545
+ /**
546
+ * The options used for the "inspect" method.
547
+ */ inspectOptions = this.getInspectOptions();
548
+ /**
549
+ * The last timestamp at which the log message was printed.
550
+ */ lastTimestampAt;
551
+ setup(contextOrOptions, options) {
552
+ let [context, opts] = isString(contextOrOptions) ? [contextOrOptions, options] : options ? [void 0, options] : [contextOrOptions?.context, contextOrOptions];
553
+ opts = opts ?? {};
554
+ opts.logLevels ??= DEFAULT_LOG_LEVELS;
555
+ opts.colors ??= opts.colors ?? (opts.json ? false : true);
556
+ opts.prefix ??= "Navios";
557
+ this.options = opts;
558
+ this.inspectOptions = this.getInspectOptions();
559
+ if (context) {
560
+ this.context = context;
561
+ this.originalContext = context;
562
+ }
563
+ }
564
+ log(message, ...optionalParams) {
565
+ if (!this.isLevelEnabled("log")) return;
566
+ const { messages, context } = this.getContextAndMessagesToPrint([message, ...optionalParams]);
567
+ this.printMessages(messages, context, "log");
568
+ }
569
+ error(message, ...optionalParams) {
570
+ if (!this.isLevelEnabled("error")) return;
571
+ const { messages, context, stack } = this.getContextAndStackAndMessagesToPrint([message, ...optionalParams]);
572
+ this.printMessages(messages, context, "error", void 0, "stderr", stack);
573
+ this.printStackTrace(stack);
574
+ }
575
+ warn(message, ...optionalParams) {
576
+ if (!this.isLevelEnabled("warn")) return;
577
+ const { messages, context } = this.getContextAndMessagesToPrint([message, ...optionalParams]);
578
+ this.printMessages(messages, context, "warn");
579
+ }
580
+ debug(message, ...optionalParams) {
581
+ if (!this.isLevelEnabled("debug")) return;
582
+ const { messages, context } = this.getContextAndMessagesToPrint([message, ...optionalParams]);
583
+ this.printMessages(messages, context, "debug");
584
+ }
585
+ verbose(message, ...optionalParams) {
586
+ if (!this.isLevelEnabled("verbose")) return;
587
+ const { messages, context } = this.getContextAndMessagesToPrint([message, ...optionalParams]);
588
+ this.printMessages(messages, context, "verbose");
589
+ }
590
+ fatal(message, ...optionalParams) {
591
+ if (!this.isLevelEnabled("fatal")) return;
592
+ const { messages, context } = this.getContextAndMessagesToPrint([message, ...optionalParams]);
593
+ this.printMessages(messages, context, "fatal");
594
+ }
595
+ /**
596
+ * Set log levels
597
+ * @param levels log levels
598
+ */ setLogLevels(levels) {
599
+ if (!this.options) this.options = {};
600
+ this.options.logLevels = levels;
601
+ }
602
+ /**
603
+ * Set logger context
604
+ * @param context context
605
+ */ setContext(context) {
606
+ this.context = context;
607
+ }
608
+ /**
609
+ * Resets the logger context to the value that was passed in the constructor.
610
+ */ resetContext() {
611
+ this.context = this.originalContext;
612
+ }
613
+ isLevelEnabled(level) {
614
+ const logLevels = this.options?.logLevels;
615
+ return isLogLevelEnabled(level, logLevels);
616
+ }
617
+ /**
618
+ * Gets the current request ID from the AsyncLocalStorage store.
619
+ * Only returns a value if the requestId option is enabled.
620
+ */ getCurrentRequestId() {
621
+ if (!this.options.requestId) return;
622
+ return getRequestId();
623
+ }
624
+ getTimestamp() {
625
+ return dateTimeFormatter.format(Date.now());
626
+ }
627
+ printMessages(messages, context = "", logLevel = "log", requestId, writeStreamType, errorStack) {
628
+ const resolvedRequestId = requestId ?? this.getCurrentRequestId();
629
+ messages.forEach((message) => {
630
+ if (this.options.json) {
631
+ this.printAsJson(message, {
632
+ context,
633
+ logLevel,
634
+ writeStreamType,
635
+ errorStack,
636
+ requestId: resolvedRequestId
637
+ });
638
+ return;
639
+ }
640
+ const pidMessage = this.formatPid(process.pid);
641
+ const contextMessage = this.formatContext(context);
642
+ const timestampDiff = this.updateAndGetTimestampDiff();
643
+ const formattedLogLevel = logLevel.toUpperCase().padStart(7, " ");
644
+ const formattedMessage = this.formatMessage(logLevel, message, pidMessage, formattedLogLevel, contextMessage, timestampDiff, resolvedRequestId);
645
+ process[writeStreamType ?? "stdout"].write(formattedMessage);
646
+ });
647
+ }
648
+ printAsJson(message, options) {
649
+ const logObject = {
650
+ level: options.logLevel,
651
+ pid: process.pid,
652
+ timestamp: Date.now(),
653
+ message
654
+ };
655
+ if (options.context) logObject.context = options.context;
656
+ if (options.errorStack) logObject.stack = options.errorStack;
657
+ if (this.options.requestId && options.requestId) logObject.requestId = options.requestId;
658
+ const formattedMessage = !this.options.colors && this.inspectOptions.compact === true ? JSON.stringify(logObject, this.stringifyReplacer) : (0, util.inspect)(logObject, this.inspectOptions);
659
+ process[options.writeStreamType ?? "stdout"].write(`${formattedMessage}\n`);
660
+ }
661
+ formatPid(pid) {
662
+ const showPrefix = this.options.showPrefix ?? true;
663
+ const showPid = this.options.showPid ?? true;
664
+ if (!showPrefix && !showPid) return "";
665
+ const prefix = showPrefix ? `[${this.options.prefix}]` : "";
666
+ const pidPart = showPid ? `${pid}` : "";
667
+ return `${prefix}${showPrefix && showPid ? " " : ""}${pidPart}${showPrefix || showPid ? " - " : ""}`;
668
+ }
669
+ formatContext(context) {
670
+ const showContext = this.options.showContext ?? true;
671
+ if (!context || !showContext) return "";
672
+ context = `[${context}] `;
673
+ return this.options.colors ? yellow(context) : context;
674
+ }
675
+ formatMessage(logLevel, message, pidMessage, formattedLogLevel, contextMessage, timestampDiff, requestId) {
676
+ const output = this.stringifyMessage(message, logLevel);
677
+ const showLogLevel = this.options.showLogLevel ?? true;
678
+ const showTimestamp = this.options.showTimestamp ?? true;
679
+ pidMessage = this.colorize(pidMessage, logLevel);
680
+ formattedLogLevel = showLogLevel ? this.colorize(formattedLogLevel, logLevel) : "";
681
+ const timestamp = showTimestamp ? this.getTimestamp() : "";
682
+ const requestIdPart = this.getRequestId(requestId);
683
+ const parts = [];
684
+ if (pidMessage) parts.push(pidMessage.trimEnd());
685
+ if (requestIdPart) parts.push(requestIdPart.trimEnd());
686
+ if (timestamp) parts.push(timestamp);
687
+ if (formattedLogLevel) parts.push(formattedLogLevel);
688
+ if (contextMessage) parts.push(contextMessage.trimEnd());
689
+ return `${parts.length > 0 ? parts.join(" ") + " " : ""}${output}${timestampDiff}\n`;
690
+ }
691
+ getRequestId(requestId) {
692
+ if (this.options.requestId && requestId) return `(${this.colorize(requestId, "log")}) `;
693
+ return "";
694
+ }
695
+ stringifyMessage(message, logLevel) {
696
+ if (isFunction(message)) {
697
+ if (Function.prototype.toString.call(message).startsWith("class ")) return this.stringifyMessage(message.name, logLevel);
698
+ return this.stringifyMessage(message(), logLevel);
699
+ }
700
+ if (typeof message === "string") return this.colorize(message, logLevel);
701
+ const outputText = (0, util.inspect)(message, this.inspectOptions);
702
+ if (isPlainObject(message)) return `Object(${Object.keys(message).length}) ${outputText}`;
703
+ if (Array.isArray(message)) return `Array(${message.length}) ${outputText}`;
704
+ return outputText;
705
+ }
706
+ colorize(message, logLevel) {
707
+ if (!this.options.colors || this.options.json) return message;
708
+ return this.getColorByLogLevel(logLevel)(message);
709
+ }
710
+ printStackTrace(stack) {
711
+ if (!stack || this.options.json) return;
712
+ process.stderr.write(`${stack}\n`);
713
+ }
714
+ updateAndGetTimestampDiff() {
715
+ const showTimeDiff = this.options?.showTimeDiff ?? false;
716
+ const result = this.lastTimestampAt && showTimeDiff ? this.formatTimestampDiff(Date.now() - this.lastTimestampAt) : "";
717
+ this.lastTimestampAt = Date.now();
718
+ return result;
719
+ }
720
+ formatTimestampDiff(timestampDiff) {
721
+ const formattedDiff = ` +${timestampDiff}ms`;
722
+ return this.options.colors ? yellow(formattedDiff) : formattedDiff;
723
+ }
724
+ getInspectOptions() {
725
+ let breakLength = this.options.breakLength;
726
+ if (typeof breakLength === "undefined") breakLength = this.options.colors ? this.options.compact ? Infinity : void 0 : this.options.compact === false ? void 0 : Infinity;
727
+ const inspectOptions = {
728
+ depth: this.options.depth ?? DEFAULT_DEPTH,
729
+ sorted: this.options.sorted,
730
+ showHidden: this.options.showHidden,
731
+ compact: this.options.compact ?? (this.options.json ? true : false),
732
+ colors: this.options.colors,
733
+ breakLength
734
+ };
735
+ if (this.options.maxArrayLength) inspectOptions.maxArrayLength = this.options.maxArrayLength;
736
+ if (this.options.maxStringLength) inspectOptions.maxStringLength = this.options.maxStringLength;
737
+ return inspectOptions;
738
+ }
739
+ stringifyReplacer(key, value) {
740
+ if (typeof value === "bigint") return value.toString();
741
+ if (typeof value === "symbol") return value.toString();
742
+ if (value instanceof Map || value instanceof Set || value instanceof Error) return `${(0, util.inspect)(value, this.inspectOptions)}`;
743
+ return value;
744
+ }
745
+ getContextAndMessagesToPrint(args) {
746
+ if (args?.length <= 1) return {
747
+ messages: args,
748
+ context: this.context
749
+ };
750
+ const lastElement = args[args.length - 1];
751
+ if (!isString(lastElement)) return {
752
+ messages: args,
753
+ context: this.context
754
+ };
755
+ return {
756
+ context: lastElement,
757
+ messages: args.slice(0, args.length - 1)
758
+ };
759
+ }
760
+ getContextAndStackAndMessagesToPrint(args) {
761
+ if (args.length === 2) return this.isStackFormat(args[1]) ? {
762
+ messages: [args[0]],
763
+ stack: args[1],
764
+ context: this.context
765
+ } : {
766
+ messages: [args[0]],
767
+ context: args[1]
768
+ };
769
+ const { messages, context } = this.getContextAndMessagesToPrint(args);
770
+ if (messages?.length <= 1) return {
771
+ messages,
772
+ context
773
+ };
774
+ const lastElement = messages[messages.length - 1];
775
+ if (!isString(lastElement) && !isUndefined(lastElement)) return {
776
+ messages,
777
+ context
778
+ };
779
+ return {
780
+ stack: lastElement,
781
+ messages: messages.slice(0, messages.length - 1),
782
+ context
783
+ };
784
+ }
785
+ isStackFormat(stack) {
786
+ if (!isString(stack) && !isUndefined(stack)) return false;
787
+ return /^(.)+\n\s+at .+:\d+:\d+/.test(stack);
788
+ }
789
+ getColorByLogLevel(level) {
790
+ switch (level) {
791
+ case "debug": return clc.magentaBright;
792
+ case "warn": return clc.yellow;
793
+ case "error": return clc.red;
794
+ case "verbose": return clc.cyanBright;
795
+ case "fatal": return clc.bold;
796
+ default: return clc.green;
797
+ }
798
+ }
799
+ }
800
+ }
801
+ }();
802
+
803
+ //#endregion
804
+ //#region src/logger/logger.service.mts
805
+ function applyDecs2203RFactory$6() {
806
+ function createAddInitializerMethod(initializers, decoratorFinishedRef) {
807
+ return function addInitializer(initializer) {
808
+ assertNotFinished(decoratorFinishedRef, "addInitializer");
809
+ assertCallable(initializer, "An initializer");
810
+ initializers.push(initializer);
811
+ };
812
+ }
813
+ function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
814
+ var kindStr;
815
+ switch (kind) {
816
+ case 1:
817
+ kindStr = "accessor";
818
+ break;
819
+ case 2:
820
+ kindStr = "method";
821
+ break;
822
+ case 3:
823
+ kindStr = "getter";
824
+ break;
825
+ case 4:
826
+ kindStr = "setter";
827
+ break;
828
+ default: kindStr = "field";
829
+ }
830
+ var ctx = {
831
+ kind: kindStr,
832
+ name: isPrivate ? "#" + name : name,
833
+ static: isStatic,
834
+ private: isPrivate,
835
+ metadata
836
+ };
837
+ var decoratorFinishedRef = { v: false };
838
+ ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
839
+ var get, set;
840
+ if (kind === 0) if (isPrivate) {
841
+ get = desc.get;
842
+ set = desc.set;
843
+ } else {
844
+ get = function() {
845
+ return this[name];
846
+ };
847
+ set = function(v) {
848
+ this[name] = v;
849
+ };
850
+ }
851
+ else if (kind === 2) get = function() {
852
+ return desc.value;
853
+ };
854
+ else {
855
+ if (kind === 1 || kind === 3) get = function() {
856
+ return desc.get.call(this);
857
+ };
858
+ if (kind === 1 || kind === 4) set = function(v) {
859
+ desc.set.call(this, v);
860
+ };
861
+ }
862
+ ctx.access = get && set ? {
863
+ get,
864
+ set
865
+ } : get ? { get } : { set };
866
+ try {
867
+ return dec(value, ctx);
868
+ } finally {
869
+ decoratorFinishedRef.v = true;
870
+ }
871
+ }
872
+ function assertNotFinished(decoratorFinishedRef, fnName) {
873
+ if (decoratorFinishedRef.v) throw new Error("attempted to call " + fnName + " after decoration was finished");
874
+ }
875
+ function assertCallable(fn, hint) {
876
+ if (typeof fn !== "function") throw new TypeError(hint + " must be a function");
877
+ }
878
+ function assertValidReturnValue(kind, value) {
879
+ var type = typeof value;
880
+ if (kind === 1) {
881
+ if (type !== "object" || value === null) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
882
+ if (value.get !== void 0) assertCallable(value.get, "accessor.get");
883
+ if (value.set !== void 0) assertCallable(value.set, "accessor.set");
884
+ if (value.init !== void 0) assertCallable(value.init, "accessor.init");
885
+ } else if (type !== "function") {
886
+ var hint;
887
+ if (kind === 0) hint = "field";
888
+ else if (kind === 10) hint = "class";
889
+ else hint = "method";
890
+ throw new TypeError(hint + " decorators must return a function or void 0");
891
+ }
892
+ }
893
+ function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
894
+ var decs = decInfo[0];
895
+ var desc, init, value;
896
+ if (isPrivate) if (kind === 0 || kind === 1) desc = {
897
+ get: decInfo[3],
898
+ set: decInfo[4]
899
+ };
900
+ else if (kind === 3) desc = { get: decInfo[3] };
901
+ else if (kind === 4) desc = { set: decInfo[3] };
902
+ else desc = { value: decInfo[3] };
903
+ else if (kind !== 0) desc = Object.getOwnPropertyDescriptor(base, name);
904
+ if (kind === 1) value = {
905
+ get: desc.get,
906
+ set: desc.set
907
+ };
908
+ else if (kind === 2) value = desc.value;
909
+ else if (kind === 3) value = desc.get;
910
+ else if (kind === 4) value = desc.set;
911
+ var newValue, get, set;
912
+ if (typeof decs === "function") {
913
+ newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
914
+ if (newValue !== void 0) {
915
+ assertValidReturnValue(kind, newValue);
916
+ if (kind === 0) init = newValue;
917
+ else if (kind === 1) {
918
+ init = newValue.init;
919
+ get = newValue.get || value.get;
920
+ set = newValue.set || value.set;
921
+ value = {
922
+ get,
923
+ set
924
+ };
925
+ } else value = newValue;
926
+ }
927
+ } else for (var i = decs.length - 1; i >= 0; i--) {
928
+ var dec = decs[i];
929
+ newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
930
+ if (newValue !== void 0) {
931
+ assertValidReturnValue(kind, newValue);
932
+ var newInit;
933
+ if (kind === 0) newInit = newValue;
934
+ else if (kind === 1) {
935
+ newInit = newValue.init;
936
+ get = newValue.get || value.get;
937
+ set = newValue.set || value.set;
938
+ value = {
939
+ get,
940
+ set
941
+ };
942
+ } else value = newValue;
943
+ if (newInit !== void 0) if (init === void 0) init = newInit;
944
+ else if (typeof init === "function") init = [init, newInit];
945
+ else init.push(newInit);
946
+ }
947
+ }
948
+ if (kind === 0 || kind === 1) {
949
+ if (init === void 0) init = function(instance, init$1) {
950
+ return init$1;
951
+ };
952
+ else if (typeof init !== "function") {
953
+ var ownInitializers = init;
954
+ init = function(instance, init$1) {
955
+ var value$1 = init$1;
956
+ for (var i$1 = 0; i$1 < ownInitializers.length; i$1++) value$1 = ownInitializers[i$1].call(instance, value$1);
957
+ return value$1;
958
+ };
959
+ } else {
960
+ var originalInitializer = init;
961
+ init = function(instance, init$1) {
962
+ return originalInitializer.call(instance, init$1);
963
+ };
964
+ }
965
+ ret.push(init);
966
+ }
967
+ if (kind !== 0) {
968
+ if (kind === 1) {
969
+ desc.get = value.get;
970
+ desc.set = value.set;
971
+ } else if (kind === 2) desc.value = value;
972
+ else if (kind === 3) desc.get = value;
973
+ else if (kind === 4) desc.set = value;
974
+ if (isPrivate) if (kind === 1) {
975
+ ret.push(function(instance, args) {
976
+ return value.get.call(instance, args);
977
+ });
978
+ ret.push(function(instance, args) {
979
+ return value.set.call(instance, args);
980
+ });
981
+ } else if (kind === 2) ret.push(value);
982
+ else ret.push(function(instance, args) {
983
+ return value.call(instance, args);
984
+ });
985
+ else Object.defineProperty(base, name, desc);
986
+ }
987
+ }
988
+ function applyMemberDecs(Class, decInfos, metadata) {
989
+ var ret = [];
990
+ var protoInitializers;
991
+ var staticInitializers;
992
+ var existingProtoNonFields = /* @__PURE__ */ new Map();
993
+ var existingStaticNonFields = /* @__PURE__ */ new Map();
994
+ for (var i = 0; i < decInfos.length; i++) {
995
+ var decInfo = decInfos[i];
996
+ if (!Array.isArray(decInfo)) continue;
997
+ var kind = decInfo[1];
998
+ var name = decInfo[2];
999
+ var isPrivate = decInfo.length > 3;
1000
+ var isStatic = kind >= 5;
1001
+ var base;
1002
+ var initializers;
1003
+ if (isStatic) {
1004
+ base = Class;
1005
+ kind = kind - 5;
1006
+ staticInitializers = staticInitializers || [];
1007
+ initializers = staticInitializers;
1008
+ } else {
1009
+ base = Class.prototype;
1010
+ protoInitializers = protoInitializers || [];
1011
+ initializers = protoInitializers;
1012
+ }
1013
+ if (kind !== 0 && !isPrivate) {
1014
+ var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
1015
+ var existingKind = existingNonFields.get(name) || 0;
1016
+ if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
1017
+ else if (!existingKind && kind > 2) existingNonFields.set(name, kind);
1018
+ else existingNonFields.set(name, true);
1019
+ }
1020
+ applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
1021
+ }
1022
+ pushInitializers(ret, protoInitializers);
1023
+ pushInitializers(ret, staticInitializers);
1024
+ return ret;
1025
+ }
1026
+ function pushInitializers(ret, initializers) {
1027
+ if (initializers) ret.push(function(instance) {
1028
+ for (var i = 0; i < initializers.length; i++) initializers[i].call(instance);
1029
+ return instance;
1030
+ });
1031
+ }
1032
+ function applyClassDecs(targetClass, classDecs, metadata) {
1033
+ if (classDecs.length > 0) {
1034
+ var initializers = [];
1035
+ var newClass = targetClass;
1036
+ var name = targetClass.name;
1037
+ for (var i = classDecs.length - 1; i >= 0; i--) {
1038
+ var decoratorFinishedRef = { v: false };
1039
+ try {
1040
+ var nextNewClass = classDecs[i](newClass, {
1041
+ kind: "class",
1042
+ name,
1043
+ addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
1044
+ metadata
1045
+ });
1046
+ } finally {
1047
+ decoratorFinishedRef.v = true;
1048
+ }
1049
+ if (nextNewClass !== void 0) {
1050
+ assertValidReturnValue(10, nextNewClass);
1051
+ newClass = nextNewClass;
1052
+ }
1053
+ }
1054
+ return [defineMetadata(newClass, metadata), function() {
1055
+ for (var i$1 = 0; i$1 < initializers.length; i$1++) initializers[i$1].call(newClass);
1056
+ }];
1057
+ }
1058
+ }
1059
+ function defineMetadata(Class, metadata) {
1060
+ return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
1061
+ configurable: true,
1062
+ enumerable: true,
1063
+ value: metadata
1064
+ });
1065
+ }
1066
+ return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
1067
+ if (parentClass !== void 0) var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
1068
+ var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
1069
+ var e = applyMemberDecs(targetClass, memberDecs, metadata);
1070
+ if (!classDecs.length) defineMetadata(targetClass, metadata);
1071
+ return {
1072
+ e,
1073
+ get c() {
1074
+ return applyClassDecs(targetClass, classDecs, metadata);
1075
+ }
1076
+ };
1077
+ };
1078
+ }
1079
+ function _apply_decs_2203_r$6(targetClass, memberDecs, classDecs, parentClass) {
1080
+ return (_apply_decs_2203_r$6 = applyDecs2203RFactory$6())(targetClass, memberDecs, classDecs, parentClass);
1081
+ }
1082
+ var _dec$6, _initClass$6;
1083
+ let _LoggerInstance;
1084
+ _dec$6 = (0, _navios_di.Injectable)({ token: Logger });
1085
+ var LoggerInstance = class {
1086
+ static {
1087
+ ({c: [_LoggerInstance, _initClass$6]} = _apply_decs_2203_r$6(this, [], [_dec$6]));
1088
+ }
1089
+ constructor(config = {}) {
1090
+ this.context = config.context;
1091
+ }
1092
+ localInstance = (0, _navios_di.inject)(LoggerOutput);
1093
+ context;
1094
+ error(message, ...optionalParams) {
1095
+ optionalParams = this.context ? (optionalParams.length ? optionalParams : [void 0]).concat(this.context) : optionalParams;
1096
+ this.localInstance?.error(message, ...optionalParams);
1097
+ }
1098
+ log(message, ...optionalParams) {
1099
+ optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1100
+ this.localInstance?.log(message, ...optionalParams);
1101
+ }
1102
+ warn(message, ...optionalParams) {
1103
+ optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1104
+ this.localInstance?.warn(message, ...optionalParams);
1105
+ }
1106
+ debug(message, ...optionalParams) {
1107
+ optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1108
+ this.localInstance?.debug?.(message, ...optionalParams);
1109
+ }
1110
+ verbose(message, ...optionalParams) {
1111
+ optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1112
+ this.localInstance?.verbose?.(message, ...optionalParams);
1113
+ }
1114
+ fatal(message, ...optionalParams) {
1115
+ optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1116
+ this.localInstance?.fatal?.(message, ...optionalParams);
1117
+ }
1118
+ static {
1119
+ _initClass$6();
1120
+ }
1121
+ };
1122
+
1123
+ //#endregion
1124
+ //#region src/exceptions/http.exception.mts
1125
+ /**
1126
+ * Base exception class for all HTTP exceptions in Navios.
1127
+ *
1128
+ * All HTTP exception classes extend this base class. When thrown from an endpoint handler,
1129
+ * Navios will automatically convert it to an appropriate HTTP response with the specified
1130
+ * status code and response body.
1131
+ *
1132
+ * @example
1133
+ * ```typescript
1134
+ * @Endpoint(getUserEndpoint)
1135
+ * async getUser(request: EndpointParams<typeof getUserEndpoint>) {
1136
+ * const user = await this.userService.findById(request.urlParams.userId)
1137
+ * if (!user) {
1138
+ * throw new HttpException(404, 'User not found')
1139
+ * }
1140
+ * return user
1141
+ * }
1142
+ * ```
1143
+ */ var HttpException = class {
1144
+ statusCode;
1145
+ response;
1146
+ error;
1147
+ /**
1148
+ * Creates a new HttpException instance.
1149
+ *
1150
+ * @param statusCode - HTTP status code (e.g., 400, 404, 500)
1151
+ * @param response - Response body (string or object)
1152
+ * @param error - Optional underlying error for logging/debugging
1153
+ */ constructor(statusCode, response, error) {
1154
+ this.statusCode = statusCode;
1155
+ this.response = response;
1156
+ this.error = error;
1157
+ }
1158
+ };
1159
+
1160
+ //#endregion
1161
+ //#region src/responders/enums/framework-error.enum.mts
1162
+ /**
1163
+ * Enumeration of framework-level error types.
1164
+ * Used to explicitly specify which error responder should handle an error.
1165
+ *
1166
+ * @example
1167
+ * ```typescript
1168
+ * // In adapter error handling
1169
+ * if (error instanceof ZodError) {
1170
+ * return errorProducer.respond(FrameworkError.ValidationError, error)
1171
+ * }
1172
+ * return errorProducer.handleUnknown(error)
1173
+ * ```
1174
+ */ var FrameworkError = /* @__PURE__ */ function(FrameworkError$1) {
1175
+ /**
1176
+ * Resource not found (HTTP 404).
1177
+ * Use when a requested resource does not exist.
1178
+ */ FrameworkError$1["NotFound"] = "NotFound";
1179
+ /**
1180
+ * Forbidden (HTTP 403).
1181
+ * Use when access to a resource is denied (e.g., guard rejection).
1182
+ */ FrameworkError$1["Forbidden"] = "Forbidden";
1183
+ /**
1184
+ * Internal server error (HTTP 500).
1185
+ * Use for unexpected errors that don't fit other categories.
1186
+ */ FrameworkError$1["InternalServerError"] = "InternalServerError";
1187
+ /**
1188
+ * Validation error (HTTP 400).
1189
+ * Use when request data fails validation (e.g., Zod errors).
1190
+ */ FrameworkError$1["ValidationError"] = "ValidationError";
1191
+ return FrameworkError$1;
1192
+ }({});
1193
+
1194
+ //#endregion
1195
+ //#region src/responders/tokens/responder.tokens.mts
1196
+ /**
1197
+ * Injection token for the Internal Server Error responder.
1198
+ * Default implementation returns HTTP 500 with RFC 7807 Problem Details.
1199
+ *
1200
+ * @example Override with custom implementation:
1201
+ * ```typescript
1202
+ * @Injectable({
1203
+ * token: InternalServerErrorResponderToken,
1204
+ * priority: 0, // Higher than default -10
1205
+ * })
1206
+ * export class CustomInternalErrorResponder implements ErrorResponder {
1207
+ * getResponse(error: unknown, description?: string): ErrorResponse {
1208
+ * // Custom implementation
1209
+ * }
1210
+ * }
1211
+ * ```
1212
+ */ const InternalServerErrorResponderToken = _navios_di.InjectionToken.create("InternalServerErrorResponder");
1213
+ /**
1214
+ * Injection token for the Not Found responder.
1215
+ * Default implementation returns HTTP 404 with RFC 7807 Problem Details.
1216
+ *
1217
+ * @example Override with custom implementation:
1218
+ * ```typescript
1219
+ * @Injectable({
1220
+ * token: NotFoundResponderToken,
1221
+ * priority: 0, // Higher than default -10
1222
+ * })
1223
+ * export class CustomNotFoundResponder implements ErrorResponder {
1224
+ * getResponse(error: unknown, description?: string): ErrorResponse {
1225
+ * // Custom implementation
1226
+ * }
1227
+ * }
1228
+ * ```
1229
+ */ const NotFoundResponderToken = _navios_di.InjectionToken.create("NotFoundResponder");
1230
+ /**
1231
+ * Injection token for the Validation Error responder.
1232
+ * Default implementation returns HTTP 400 with RFC 7807 Problem Details
1233
+ * and includes validation errors from ZodError.
1234
+ *
1235
+ * @example Override with custom implementation:
1236
+ * ```typescript
1237
+ * @Injectable({
1238
+ * token: ValidationErrorResponderToken,
1239
+ * priority: 0, // Higher than default -10
1240
+ * })
1241
+ * export class CustomValidationResponder implements ErrorResponder {
1242
+ * getResponse(error: unknown, description?: string): ErrorResponse {
1243
+ * // Custom implementation
1244
+ * }
1245
+ * }
1246
+ * ```
1247
+ */ const ValidationErrorResponderToken = _navios_di.InjectionToken.create("ValidationErrorResponder");
1248
+ /**
1249
+ * Injection token for the Forbidden responder.
1250
+ * Default implementation returns HTTP 403 with RFC 7807 Problem Details.
1251
+ *
1252
+ * @example Override with custom implementation:
1253
+ * ```typescript
1254
+ * @Injectable({
1255
+ * token: ForbiddenResponderToken,
1256
+ * priority: 0, // Higher than default -10
1257
+ * })
1258
+ * export class CustomForbiddenResponder implements ErrorResponder {
1259
+ * getResponse(error: unknown, description?: string): ErrorResponse {
1260
+ * // Custom implementation
1261
+ * }
1262
+ * }
1263
+ * ```
1264
+ */ const ForbiddenResponderToken = _navios_di.InjectionToken.create("ForbiddenResponder");
1265
+
1266
+ //#endregion
1267
+ //#region src/responders/services/error-response-producer.service.mts
1268
+ function applyDecs2203RFactory$5() {
1269
+ function createAddInitializerMethod(initializers, decoratorFinishedRef) {
1270
+ return function addInitializer(initializer) {
1271
+ assertNotFinished(decoratorFinishedRef, "addInitializer");
1272
+ assertCallable(initializer, "An initializer");
1273
+ initializers.push(initializer);
1274
+ };
1275
+ }
1276
+ function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
1277
+ var kindStr;
1278
+ switch (kind) {
1279
+ case 1:
1280
+ kindStr = "accessor";
1281
+ break;
1282
+ case 2:
1283
+ kindStr = "method";
1284
+ break;
1285
+ case 3:
1286
+ kindStr = "getter";
1287
+ break;
1288
+ case 4:
1289
+ kindStr = "setter";
1290
+ break;
1291
+ default: kindStr = "field";
1292
+ }
1293
+ var ctx = {
1294
+ kind: kindStr,
1295
+ name: isPrivate ? "#" + name : name,
1296
+ static: isStatic,
1297
+ private: isPrivate,
1298
+ metadata
1299
+ };
1300
+ var decoratorFinishedRef = { v: false };
1301
+ ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
1302
+ var get, set;
1303
+ if (kind === 0) if (isPrivate) {
1304
+ get = desc.get;
1305
+ set = desc.set;
1306
+ } else {
1307
+ get = function() {
1308
+ return this[name];
1309
+ };
1310
+ set = function(v) {
1311
+ this[name] = v;
1312
+ };
1313
+ }
1314
+ else if (kind === 2) get = function() {
1315
+ return desc.value;
1316
+ };
1317
+ else {
1318
+ if (kind === 1 || kind === 3) get = function() {
1319
+ return desc.get.call(this);
1320
+ };
1321
+ if (kind === 1 || kind === 4) set = function(v) {
1322
+ desc.set.call(this, v);
1323
+ };
1324
+ }
1325
+ ctx.access = get && set ? {
1326
+ get,
1327
+ set
1328
+ } : get ? { get } : { set };
1329
+ try {
1330
+ return dec(value, ctx);
1331
+ } finally {
1332
+ decoratorFinishedRef.v = true;
1333
+ }
1334
+ }
1335
+ function assertNotFinished(decoratorFinishedRef, fnName) {
1336
+ if (decoratorFinishedRef.v) throw new Error("attempted to call " + fnName + " after decoration was finished");
1337
+ }
1338
+ function assertCallable(fn, hint) {
1339
+ if (typeof fn !== "function") throw new TypeError(hint + " must be a function");
1340
+ }
1341
+ function assertValidReturnValue(kind, value) {
1342
+ var type = typeof value;
1343
+ if (kind === 1) {
1344
+ if (type !== "object" || value === null) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
1345
+ if (value.get !== void 0) assertCallable(value.get, "accessor.get");
1346
+ if (value.set !== void 0) assertCallable(value.set, "accessor.set");
1347
+ if (value.init !== void 0) assertCallable(value.init, "accessor.init");
1348
+ } else if (type !== "function") {
1349
+ var hint;
1350
+ if (kind === 0) hint = "field";
1351
+ else if (kind === 10) hint = "class";
1352
+ else hint = "method";
1353
+ throw new TypeError(hint + " decorators must return a function or void 0");
1354
+ }
1355
+ }
1356
+ function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
1357
+ var decs = decInfo[0];
1358
+ var desc, init, value;
1359
+ if (isPrivate) if (kind === 0 || kind === 1) desc = {
1360
+ get: decInfo[3],
1361
+ set: decInfo[4]
1362
+ };
1363
+ else if (kind === 3) desc = { get: decInfo[3] };
1364
+ else if (kind === 4) desc = { set: decInfo[3] };
1365
+ else desc = { value: decInfo[3] };
1366
+ else if (kind !== 0) desc = Object.getOwnPropertyDescriptor(base, name);
1367
+ if (kind === 1) value = {
1368
+ get: desc.get,
1369
+ set: desc.set
1370
+ };
1371
+ else if (kind === 2) value = desc.value;
1372
+ else if (kind === 3) value = desc.get;
1373
+ else if (kind === 4) value = desc.set;
1374
+ var newValue, get, set;
1375
+ if (typeof decs === "function") {
1376
+ newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
1377
+ if (newValue !== void 0) {
1378
+ assertValidReturnValue(kind, newValue);
1379
+ if (kind === 0) init = newValue;
1380
+ else if (kind === 1) {
1381
+ init = newValue.init;
1382
+ get = newValue.get || value.get;
1383
+ set = newValue.set || value.set;
1384
+ value = {
1385
+ get,
1386
+ set
1387
+ };
1388
+ } else value = newValue;
1389
+ }
1390
+ } else for (var i = decs.length - 1; i >= 0; i--) {
1391
+ var dec = decs[i];
1392
+ newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
1393
+ if (newValue !== void 0) {
1394
+ assertValidReturnValue(kind, newValue);
1395
+ var newInit;
1396
+ if (kind === 0) newInit = newValue;
1397
+ else if (kind === 1) {
1398
+ newInit = newValue.init;
1399
+ get = newValue.get || value.get;
1400
+ set = newValue.set || value.set;
1401
+ value = {
1402
+ get,
1403
+ set
1404
+ };
1405
+ } else value = newValue;
1406
+ if (newInit !== void 0) if (init === void 0) init = newInit;
1407
+ else if (typeof init === "function") init = [init, newInit];
1408
+ else init.push(newInit);
1409
+ }
1410
+ }
1411
+ if (kind === 0 || kind === 1) {
1412
+ if (init === void 0) init = function(instance, init$1) {
1413
+ return init$1;
1414
+ };
1415
+ else if (typeof init !== "function") {
1416
+ var ownInitializers = init;
1417
+ init = function(instance, init$1) {
1418
+ var value$1 = init$1;
1419
+ for (var i$1 = 0; i$1 < ownInitializers.length; i$1++) value$1 = ownInitializers[i$1].call(instance, value$1);
1420
+ return value$1;
1421
+ };
1422
+ } else {
1423
+ var originalInitializer = init;
1424
+ init = function(instance, init$1) {
1425
+ return originalInitializer.call(instance, init$1);
1426
+ };
1427
+ }
1428
+ ret.push(init);
1429
+ }
1430
+ if (kind !== 0) {
1431
+ if (kind === 1) {
1432
+ desc.get = value.get;
1433
+ desc.set = value.set;
1434
+ } else if (kind === 2) desc.value = value;
1435
+ else if (kind === 3) desc.get = value;
1436
+ else if (kind === 4) desc.set = value;
1437
+ if (isPrivate) if (kind === 1) {
1438
+ ret.push(function(instance, args) {
1439
+ return value.get.call(instance, args);
1440
+ });
1441
+ ret.push(function(instance, args) {
1442
+ return value.set.call(instance, args);
1443
+ });
1444
+ } else if (kind === 2) ret.push(value);
1445
+ else ret.push(function(instance, args) {
1446
+ return value.call(instance, args);
1447
+ });
1448
+ else Object.defineProperty(base, name, desc);
1449
+ }
1450
+ }
1451
+ function applyMemberDecs(Class, decInfos, metadata) {
1452
+ var ret = [];
1453
+ var protoInitializers;
1454
+ var staticInitializers;
1455
+ var existingProtoNonFields = /* @__PURE__ */ new Map();
1456
+ var existingStaticNonFields = /* @__PURE__ */ new Map();
1457
+ for (var i = 0; i < decInfos.length; i++) {
1458
+ var decInfo = decInfos[i];
1459
+ if (!Array.isArray(decInfo)) continue;
1460
+ var kind = decInfo[1];
1461
+ var name = decInfo[2];
1462
+ var isPrivate = decInfo.length > 3;
1463
+ var isStatic = kind >= 5;
1464
+ var base;
1465
+ var initializers;
1466
+ if (isStatic) {
1467
+ base = Class;
1468
+ kind = kind - 5;
1469
+ staticInitializers = staticInitializers || [];
1470
+ initializers = staticInitializers;
1471
+ } else {
1472
+ base = Class.prototype;
1473
+ protoInitializers = protoInitializers || [];
1474
+ initializers = protoInitializers;
1475
+ }
1476
+ if (kind !== 0 && !isPrivate) {
1477
+ var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
1478
+ var existingKind = existingNonFields.get(name) || 0;
1479
+ if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
1480
+ else if (!existingKind && kind > 2) existingNonFields.set(name, kind);
1481
+ else existingNonFields.set(name, true);
1482
+ }
1483
+ applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
1484
+ }
1485
+ pushInitializers(ret, protoInitializers);
1486
+ pushInitializers(ret, staticInitializers);
1487
+ return ret;
1488
+ }
1489
+ function pushInitializers(ret, initializers) {
1490
+ if (initializers) ret.push(function(instance) {
1491
+ for (var i = 0; i < initializers.length; i++) initializers[i].call(instance);
1492
+ return instance;
1493
+ });
1494
+ }
1495
+ function applyClassDecs(targetClass, classDecs, metadata) {
1496
+ if (classDecs.length > 0) {
1497
+ var initializers = [];
1498
+ var newClass = targetClass;
1499
+ var name = targetClass.name;
1500
+ for (var i = classDecs.length - 1; i >= 0; i--) {
1501
+ var decoratorFinishedRef = { v: false };
1502
+ try {
1503
+ var nextNewClass = classDecs[i](newClass, {
1504
+ kind: "class",
1505
+ name,
1506
+ addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
1507
+ metadata
1508
+ });
1509
+ } finally {
1510
+ decoratorFinishedRef.v = true;
1511
+ }
1512
+ if (nextNewClass !== void 0) {
1513
+ assertValidReturnValue(10, nextNewClass);
1514
+ newClass = nextNewClass;
1515
+ }
1516
+ }
1517
+ return [defineMetadata(newClass, metadata), function() {
1518
+ for (var i$1 = 0; i$1 < initializers.length; i$1++) initializers[i$1].call(newClass);
1519
+ }];
1520
+ }
1521
+ }
1522
+ function defineMetadata(Class, metadata) {
1523
+ return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
1524
+ configurable: true,
1525
+ enumerable: true,
1526
+ value: metadata
1527
+ });
1528
+ }
1529
+ return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
1530
+ if (parentClass !== void 0) var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
1531
+ var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
1532
+ var e = applyMemberDecs(targetClass, memberDecs, metadata);
1533
+ if (!classDecs.length) defineMetadata(targetClass, metadata);
1534
+ return {
1535
+ e,
1536
+ get c() {
1537
+ return applyClassDecs(targetClass, classDecs, metadata);
1538
+ }
1539
+ };
1540
+ };
1541
+ }
1542
+ function _apply_decs_2203_r$5(targetClass, memberDecs, classDecs, parentClass) {
1543
+ return (_apply_decs_2203_r$5 = applyDecs2203RFactory$5())(targetClass, memberDecs, classDecs, parentClass);
1544
+ }
1545
+ var _dec$5, _initClass$5;
1546
+ let _ErrorResponseProducerService;
1547
+ _dec$5 = (0, _navios_di.Injectable)();
1548
+ var ErrorResponseProducerService = class {
1549
+ static {
1550
+ ({c: [_ErrorResponseProducerService, _initClass$5]} = _apply_decs_2203_r$5(this, [], [_dec$5]));
1551
+ }
1552
+ forbiddenResponder = (0, _navios_di.inject)(ForbiddenResponderToken);
1553
+ internalServerErrorResponder = (0, _navios_di.inject)(InternalServerErrorResponderToken);
1554
+ notFoundResponder = (0, _navios_di.inject)(NotFoundResponderToken);
1555
+ validationErrorResponder = (0, _navios_di.inject)(ValidationErrorResponderToken);
1556
+ /**
1557
+ * Produces an error response for a specific framework error type.
1558
+ *
1559
+ * @param type - The type of framework error (from FrameworkError enum)
1560
+ * @param error - The original error that was thrown
1561
+ * @param description - Optional custom description to include in the response
1562
+ * @returns ErrorResponse with status code, RFC 7807 payload, and headers
1563
+ */ respond(type, error, description) {
1564
+ switch (type) {
1565
+ case FrameworkError.NotFound: return this.notFoundResponder.getResponse(error, description);
1566
+ case FrameworkError.Forbidden: return this.forbiddenResponder.getResponse(error, description);
1567
+ case FrameworkError.InternalServerError: return this.internalServerErrorResponder.getResponse(error, description);
1568
+ case FrameworkError.ValidationError: return this.validationErrorResponder.getResponse(error, description);
1569
+ }
1570
+ }
1571
+ /**
1572
+ * Handles unknown errors by producing an Internal Server Error response.
1573
+ *
1574
+ * Use this as a fallback when the error type is not known or doesn't
1575
+ * match any specific framework error type.
1576
+ *
1577
+ * @param error - The original error that was thrown
1578
+ * @param description - Optional custom description to include in the response
1579
+ * @returns ErrorResponse with 500 status code
1580
+ */ handleUnknown(error, description) {
1581
+ return this.internalServerErrorResponder.getResponse(error, description);
1582
+ }
1583
+ /**
1584
+ * Convenience method to produce a Not Found error response.
1585
+ *
1586
+ * @param error - The original error that was thrown
1587
+ * @param description - Optional custom description
1588
+ * @returns ErrorResponse with 404 status code
1589
+ */ notFound(error, description) {
1590
+ return this.notFoundResponder.getResponse(error, description);
1591
+ }
1592
+ /**
1593
+ * Convenience method to produce a Validation Error response.
1594
+ *
1595
+ * @param error - The original error (typically a ZodError)
1596
+ * @param description - Optional custom description
1597
+ * @returns ErrorResponse with 400 status code
1598
+ */ validationError(error, description) {
1599
+ return this.validationErrorResponder.getResponse(error, description);
1600
+ }
1601
+ /**
1602
+ * Convenience method to produce an Internal Server Error response.
1603
+ *
1604
+ * @param error - The original error
1605
+ * @param description - Optional custom description
1606
+ * @returns ErrorResponse with 500 status code
1607
+ */ internalServerError(error, description) {
1608
+ return this.internalServerErrorResponder.getResponse(error, description);
1609
+ }
1610
+ /**
1611
+ * Convenience method to produce a Forbidden error response.
1612
+ *
1613
+ * @param error - The original error
1614
+ * @param description - Optional custom description
1615
+ * @returns ErrorResponse with 403 status code
1616
+ */ forbidden(error, description) {
1617
+ return this.forbiddenResponder.getResponse(error, description);
1618
+ }
1619
+ static {
1620
+ _initClass$5();
1621
+ }
1622
+ };
1623
+
1624
+ //#endregion
1625
+ //#region src/services/instance-resolver.service.mts
1626
+ function applyDecs2203RFactory$4() {
1627
+ function createAddInitializerMethod(initializers, decoratorFinishedRef) {
1628
+ return function addInitializer(initializer) {
1629
+ assertNotFinished(decoratorFinishedRef, "addInitializer");
1630
+ assertCallable(initializer, "An initializer");
1631
+ initializers.push(initializer);
1632
+ };
1633
+ }
1634
+ function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
1635
+ var kindStr;
1636
+ switch (kind) {
1637
+ case 1:
1638
+ kindStr = "accessor";
1639
+ break;
1640
+ case 2:
1641
+ kindStr = "method";
1642
+ break;
1643
+ case 3:
1644
+ kindStr = "getter";
1645
+ break;
1646
+ case 4:
1647
+ kindStr = "setter";
1648
+ break;
1649
+ default: kindStr = "field";
1650
+ }
1651
+ var ctx = {
1652
+ kind: kindStr,
1653
+ name: isPrivate ? "#" + name : name,
1654
+ static: isStatic,
1655
+ private: isPrivate,
1656
+ metadata
1657
+ };
1658
+ var decoratorFinishedRef = { v: false };
1659
+ ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
1660
+ var get, set;
1661
+ if (kind === 0) if (isPrivate) {
1662
+ get = desc.get;
1663
+ set = desc.set;
1664
+ } else {
1665
+ get = function() {
1666
+ return this[name];
1667
+ };
1668
+ set = function(v) {
1669
+ this[name] = v;
1670
+ };
1671
+ }
1672
+ else if (kind === 2) get = function() {
1673
+ return desc.value;
1674
+ };
1675
+ else {
1676
+ if (kind === 1 || kind === 3) get = function() {
1677
+ return desc.get.call(this);
1678
+ };
1679
+ if (kind === 1 || kind === 4) set = function(v) {
1680
+ desc.set.call(this, v);
1681
+ };
1682
+ }
1683
+ ctx.access = get && set ? {
1684
+ get,
1685
+ set
1686
+ } : get ? { get } : { set };
1687
+ try {
1688
+ return dec(value, ctx);
1689
+ } finally {
1690
+ decoratorFinishedRef.v = true;
1691
+ }
1692
+ }
1693
+ function assertNotFinished(decoratorFinishedRef, fnName) {
1694
+ if (decoratorFinishedRef.v) throw new Error("attempted to call " + fnName + " after decoration was finished");
1695
+ }
1696
+ function assertCallable(fn, hint) {
1697
+ if (typeof fn !== "function") throw new TypeError(hint + " must be a function");
1698
+ }
1699
+ function assertValidReturnValue(kind, value) {
1700
+ var type = typeof value;
1701
+ if (kind === 1) {
1702
+ if (type !== "object" || value === null) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
1703
+ if (value.get !== void 0) assertCallable(value.get, "accessor.get");
1704
+ if (value.set !== void 0) assertCallable(value.set, "accessor.set");
1705
+ if (value.init !== void 0) assertCallable(value.init, "accessor.init");
1706
+ } else if (type !== "function") {
1707
+ var hint;
1708
+ if (kind === 0) hint = "field";
1709
+ else if (kind === 10) hint = "class";
1710
+ else hint = "method";
1711
+ throw new TypeError(hint + " decorators must return a function or void 0");
1712
+ }
1713
+ }
1714
+ function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
1715
+ var decs = decInfo[0];
1716
+ var desc, init, value;
1717
+ if (isPrivate) if (kind === 0 || kind === 1) desc = {
1718
+ get: decInfo[3],
1719
+ set: decInfo[4]
1720
+ };
1721
+ else if (kind === 3) desc = { get: decInfo[3] };
1722
+ else if (kind === 4) desc = { set: decInfo[3] };
1723
+ else desc = { value: decInfo[3] };
1724
+ else if (kind !== 0) desc = Object.getOwnPropertyDescriptor(base, name);
1725
+ if (kind === 1) value = {
1726
+ get: desc.get,
1727
+ set: desc.set
1728
+ };
1729
+ else if (kind === 2) value = desc.value;
1730
+ else if (kind === 3) value = desc.get;
1731
+ else if (kind === 4) value = desc.set;
1732
+ var newValue, get, set;
1733
+ if (typeof decs === "function") {
1734
+ newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
1735
+ if (newValue !== void 0) {
1736
+ assertValidReturnValue(kind, newValue);
1737
+ if (kind === 0) init = newValue;
1738
+ else if (kind === 1) {
1739
+ init = newValue.init;
1740
+ get = newValue.get || value.get;
1741
+ set = newValue.set || value.set;
1742
+ value = {
1743
+ get,
1744
+ set
1745
+ };
1746
+ } else value = newValue;
1747
+ }
1748
+ } else for (var i = decs.length - 1; i >= 0; i--) {
1749
+ var dec = decs[i];
1750
+ newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
1751
+ if (newValue !== void 0) {
1752
+ assertValidReturnValue(kind, newValue);
1753
+ var newInit;
1754
+ if (kind === 0) newInit = newValue;
1755
+ else if (kind === 1) {
1756
+ newInit = newValue.init;
1757
+ get = newValue.get || value.get;
1758
+ set = newValue.set || value.set;
1759
+ value = {
1760
+ get,
1761
+ set
1762
+ };
1763
+ } else value = newValue;
1764
+ if (newInit !== void 0) if (init === void 0) init = newInit;
1765
+ else if (typeof init === "function") init = [init, newInit];
1766
+ else init.push(newInit);
1767
+ }
1768
+ }
1769
+ if (kind === 0 || kind === 1) {
1770
+ if (init === void 0) init = function(instance, init$1) {
1771
+ return init$1;
1772
+ };
1773
+ else if (typeof init !== "function") {
1774
+ var ownInitializers = init;
1775
+ init = function(instance, init$1) {
1776
+ var value$1 = init$1;
1777
+ for (var i$1 = 0; i$1 < ownInitializers.length; i$1++) value$1 = ownInitializers[i$1].call(instance, value$1);
1778
+ return value$1;
1779
+ };
1780
+ } else {
1781
+ var originalInitializer = init;
1782
+ init = function(instance, init$1) {
1783
+ return originalInitializer.call(instance, init$1);
1784
+ };
1785
+ }
1786
+ ret.push(init);
1787
+ }
1788
+ if (kind !== 0) {
1789
+ if (kind === 1) {
1790
+ desc.get = value.get;
1791
+ desc.set = value.set;
1792
+ } else if (kind === 2) desc.value = value;
1793
+ else if (kind === 3) desc.get = value;
1794
+ else if (kind === 4) desc.set = value;
1795
+ if (isPrivate) if (kind === 1) {
1796
+ ret.push(function(instance, args) {
1797
+ return value.get.call(instance, args);
1798
+ });
1799
+ ret.push(function(instance, args) {
1800
+ return value.set.call(instance, args);
1801
+ });
1802
+ } else if (kind === 2) ret.push(value);
1803
+ else ret.push(function(instance, args) {
1804
+ return value.call(instance, args);
1805
+ });
1806
+ else Object.defineProperty(base, name, desc);
1807
+ }
1808
+ }
1809
+ function applyMemberDecs(Class, decInfos, metadata) {
1810
+ var ret = [];
1811
+ var protoInitializers;
1812
+ var staticInitializers;
1813
+ var existingProtoNonFields = /* @__PURE__ */ new Map();
1814
+ var existingStaticNonFields = /* @__PURE__ */ new Map();
1815
+ for (var i = 0; i < decInfos.length; i++) {
1816
+ var decInfo = decInfos[i];
1817
+ if (!Array.isArray(decInfo)) continue;
1818
+ var kind = decInfo[1];
1819
+ var name = decInfo[2];
1820
+ var isPrivate = decInfo.length > 3;
1821
+ var isStatic = kind >= 5;
1822
+ var base;
1823
+ var initializers;
1824
+ if (isStatic) {
1825
+ base = Class;
1826
+ kind = kind - 5;
1827
+ staticInitializers = staticInitializers || [];
1828
+ initializers = staticInitializers;
1829
+ } else {
1830
+ base = Class.prototype;
1831
+ protoInitializers = protoInitializers || [];
1832
+ initializers = protoInitializers;
1833
+ }
1834
+ if (kind !== 0 && !isPrivate) {
1835
+ var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
1836
+ var existingKind = existingNonFields.get(name) || 0;
1837
+ if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
1838
+ else if (!existingKind && kind > 2) existingNonFields.set(name, kind);
1839
+ else existingNonFields.set(name, true);
1840
+ }
1841
+ applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
1842
+ }
1843
+ pushInitializers(ret, protoInitializers);
1844
+ pushInitializers(ret, staticInitializers);
1845
+ return ret;
1846
+ }
1847
+ function pushInitializers(ret, initializers) {
1848
+ if (initializers) ret.push(function(instance) {
1849
+ for (var i = 0; i < initializers.length; i++) initializers[i].call(instance);
1850
+ return instance;
1851
+ });
1852
+ }
1853
+ function applyClassDecs(targetClass, classDecs, metadata) {
1854
+ if (classDecs.length > 0) {
1855
+ var initializers = [];
1856
+ var newClass = targetClass;
1857
+ var name = targetClass.name;
1858
+ for (var i = classDecs.length - 1; i >= 0; i--) {
1859
+ var decoratorFinishedRef = { v: false };
1860
+ try {
1861
+ var nextNewClass = classDecs[i](newClass, {
1862
+ kind: "class",
1863
+ name,
1864
+ addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
1865
+ metadata
1866
+ });
1867
+ } finally {
1868
+ decoratorFinishedRef.v = true;
1869
+ }
1870
+ if (nextNewClass !== void 0) {
1871
+ assertValidReturnValue(10, nextNewClass);
1872
+ newClass = nextNewClass;
1873
+ }
1874
+ }
1875
+ return [defineMetadata(newClass, metadata), function() {
1876
+ for (var i$1 = 0; i$1 < initializers.length; i$1++) initializers[i$1].call(newClass);
1877
+ }];
1878
+ }
1879
+ }
1880
+ function defineMetadata(Class, metadata) {
1881
+ return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
1882
+ configurable: true,
1883
+ enumerable: true,
1884
+ value: metadata
1885
+ });
1886
+ }
1887
+ return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
1888
+ if (parentClass !== void 0) var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
1889
+ var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
1890
+ var e = applyMemberDecs(targetClass, memberDecs, metadata);
1891
+ if (!classDecs.length) defineMetadata(targetClass, metadata);
1892
+ return {
1893
+ e,
1894
+ get c() {
1895
+ return applyClassDecs(targetClass, classDecs, metadata);
1896
+ }
1897
+ };
1898
+ };
1899
+ }
1900
+ function _apply_decs_2203_r$4(targetClass, memberDecs, classDecs, parentClass) {
1901
+ return (_apply_decs_2203_r$4 = applyDecs2203RFactory$4())(targetClass, memberDecs, classDecs, parentClass);
1902
+ }
1903
+ var _dec$4, _initClass$4;
1904
+ let _InstanceResolverService;
1905
+ _dec$4 = (0, _navios_di.Injectable)();
1906
+ var InstanceResolverService = class {
1907
+ static {
1908
+ ({c: [_InstanceResolverService, _initClass$4]} = _apply_decs_2203_r$4(this, [], [_dec$4]));
1909
+ }
1910
+ container = (0, _navios_di.inject)(_navios_di.Container);
1911
+ /**
1912
+ * Attempts to resolve a class instance, automatically detecting if it needs
1913
+ * request scope based on its dependencies.
1914
+ *
1915
+ * @param classType - The class to resolve
1916
+ * @returns A resolution result containing either a cached instance or resolver function
1917
+ */ async resolve(classType) {
1918
+ let cachedInstance = null;
1919
+ try {
1920
+ cachedInstance = await this.container.get(classType);
1921
+ } catch {
1922
+ const token = (0, _navios_di.getInjectableToken)(classType);
1923
+ this.container.getRegistry().updateScope(token, _navios_di.InjectableScope.Request);
1924
+ }
1925
+ return {
1926
+ cached: cachedInstance !== null,
1927
+ instance: cachedInstance,
1928
+ resolve: (scoped) => scoped.get(classType)
1929
+ };
1930
+ }
1931
+ /**
1932
+ * Attempts to resolve multiple class instances, automatically detecting if any need
1933
+ * request scope based on their dependencies.
1934
+ *
1935
+ * Returns `cached: true` only if ALL classes can be resolved as singletons.
1936
+ * If any class has request-scoped dependencies, returns `cached: false`.
1937
+ *
1938
+ * @param classTypes - The classes to resolve
1939
+ * @returns A resolution result containing either all cached instances or resolver function
1940
+ */ async resolveMany(classTypes) {
1941
+ if (classTypes.length === 0) return {
1942
+ cached: true,
1943
+ instances: [],
1944
+ classTypes: [],
1945
+ resolve: async () => []
1946
+ };
1947
+ const results = await Promise.all(classTypes.map(async (classType) => {
1948
+ try {
1949
+ return {
1950
+ success: true,
1951
+ instance: await this.container.get(classType)
1952
+ };
1953
+ } catch {
1954
+ const token = (0, _navios_di.getInjectableToken)(classType);
1955
+ this.container.getRegistry().updateScope(token, _navios_di.InjectableScope.Request);
1956
+ return {
1957
+ success: false,
1958
+ instance: null
1959
+ };
1960
+ }
1961
+ }));
1962
+ const allCached = results.every((r) => r.success);
1963
+ return {
1964
+ cached: allCached,
1965
+ instances: allCached ? results.map((r) => r.instance) : null,
1966
+ classTypes,
1967
+ resolve: (scoped) => Promise.all(classTypes.map((classType) => scoped.get(classType)))
1968
+ };
1969
+ }
1970
+ static {
1971
+ _initClass$4();
1972
+ }
1973
+ };
1974
+ /**
1975
+ * @deprecated Use InstanceResolverService instead
1976
+ */ const ControllerResolverService = _InstanceResolverService;
1977
+
1978
+ //#endregion
1979
+ //#region src/services/abstract-handler-adapter.service.mts
1980
+ const defaultOptions = {
1981
+ adapter: [],
1982
+ validateResponses: true,
1983
+ enableRequestId: false
1984
+ };
1985
+ /**
1986
+ * Abstract base class for HTTP handler adapter services.
1987
+ *
1988
+ * Provides shared logic for:
1989
+ * - Controller resolution (singleton vs request-scoped)
1990
+ * - Argument formatting (sync/async detection)
1991
+ * - Handler generation with static/dynamic branching
1992
+ * - Standardized error handling
1993
+ *
1994
+ * Adapters implement abstract methods for framework-specific behavior:
1995
+ * - Request parsing (query, body, URL params)
1996
+ * - Response creation
1997
+ * - Schema provision
1998
+ *
1999
+ * Supports all adapter types:
2000
+ * - Endpoint adapters: JSON request/response with validation
2001
+ * - Stream adapters: Streaming responses with extra context
2002
+ * - Multipart adapters: Form data parsing (extends endpoint)
2003
+ *
2004
+ * @typeParam TRequest - Framework request type (BunRequest, FastifyRequest)
2005
+ * @typeParam TReply - Framework reply type (void for Bun, FastifyReply)
2006
+ * @typeParam TConfig - Endpoint configuration type
2007
+ */ var AbstractHandlerAdapterService = class {
2008
+ instanceResolver = (0, _navios_di.inject)(_InstanceResolverService);
2009
+ options = (0, _navios_di.optional)(require_tokens.NaviosOptionsToken) ?? defaultOptions;
2010
+ /**
2011
+ * Prepares argument getters for parsing request data.
2012
+ *
2013
+ * Public alias for createArgumentGetters to satisfy interface contracts.
2014
+ * Subclasses should override createArgumentGetters instead.
2015
+ *
2016
+ * @param handlerMetadata - Handler metadata with schemas and configuration
2017
+ * @returns Array of getter functions
2018
+ */ prepareArguments(handlerMetadata) {
2019
+ return this.createArgumentGetters(handlerMetadata);
2020
+ }
2021
+ /**
2022
+ * Checks if the handler has any validation schemas defined.
2023
+ *
2024
+ * Override in subclasses to add additional schema checks
2025
+ * (e.g., response schema validation for endpoint adapters).
2026
+ *
2027
+ * @param handlerMetadata - Handler metadata with configuration
2028
+ * @returns true if handler has schemas
2029
+ */ hasSchema(handlerMetadata) {
2030
+ const config = handlerMetadata.config;
2031
+ return !!config.requestSchema || !!config.querySchema;
2032
+ }
2033
+ /**
2034
+ * Provides schema information for the framework's validation system.
2035
+ *
2036
+ * Override in subclasses for frameworks that support schema registration
2037
+ * (e.g., Fastify). Default returns empty object (suitable for Bun).
2038
+ *
2039
+ * @param handlerMetadata - Handler metadata with configuration
2040
+ * @returns Schema object for framework registration
2041
+ */ provideSchema(_handlerMetadata) {
2042
+ return {};
2043
+ }
2044
+ /**
2045
+ * Creates a request handler function for the endpoint.
2046
+ *
2047
+ * This method orchestrates the entire handler creation:
2048
+ * 1. Prepares argument getters for request parsing
2049
+ * 2. Builds optimized formatArguments function (sync/async)
2050
+ * 3. Resolves the controller (singleton vs request-scoped)
2051
+ * 4. Creates appropriate handler (static or dynamic)
2052
+ *
2053
+ * @param controller - Controller class containing the handler method
2054
+ * @param handlerMetadata - Handler metadata with configuration
2055
+ * @returns Handler result (static or dynamic)
2056
+ */ async provideHandler(controller, handlerMetadata) {
2057
+ const getters = this.createArgumentGetters(handlerMetadata);
2058
+ const formatArguments = this.buildFormatArguments(getters);
2059
+ const hasArguments = getters.length > 0;
2060
+ const context = {
2061
+ methodName: handlerMetadata.classMethod,
2062
+ statusCode: handlerMetadata.successStatusCode,
2063
+ headers: handlerMetadata.headers,
2064
+ handlerMetadata,
2065
+ hasArguments
2066
+ };
2067
+ const resolution = await this.instanceResolver.resolve(controller);
2068
+ if (resolution.cached) {
2069
+ const cachedController = resolution.instance;
2070
+ const boundMethod = cachedController[context.methodName].bind(cachedController);
2071
+ return this.createStaticHandler(boundMethod, formatArguments, context);
2072
+ }
2073
+ return this.createDynamicHandler(resolution, formatArguments, context);
2074
+ }
2075
+ /**
2076
+ * Builds a formatArguments function from argument getters.
2077
+ *
2078
+ * Automatically detects sync vs async getters and optimizes accordingly:
2079
+ * - If all getters are sync: returns sync function (no Promise overhead)
2080
+ * - If any getter is async: returns async function with Promise.all
2081
+ * - If no getters: returns frozen empty object (zero allocation)
2082
+ *
2083
+ * This method is public to allow composition-based adapters (like XML adapter)
2084
+ * to reuse the optimized formatArguments logic without inheritance.
2085
+ *
2086
+ * @param getters - Array of argument getter functions
2087
+ * @returns Function to format arguments from request
2088
+ */ buildFormatArguments(getters) {
2089
+ if (getters.length === 0) {
2090
+ const emptyArgs = Object.freeze({});
2091
+ return () => emptyArgs;
2092
+ }
2093
+ if (getters.some((g) => g.constructor.name === "AsyncFunction")) return async (request) => {
2094
+ const argument = {};
2095
+ const promises = [];
2096
+ for (const getter of getters) {
2097
+ const res = getter(argument, request);
2098
+ if (res instanceof Promise) promises.push(res);
2099
+ }
2100
+ await Promise.all(promises);
2101
+ return argument;
2102
+ };
2103
+ return (request) => {
2104
+ const argument = {};
2105
+ for (const getter of getters) getter(argument, request);
2106
+ return argument;
2107
+ };
2108
+ }
2109
+ /**
2110
+ * Checks if the URL pattern contains URL parameters.
2111
+ *
2112
+ * @param config - Endpoint configuration
2113
+ * @returns true if URL contains '$' parameter markers
2114
+ */ hasUrlParams(config) {
2115
+ return config.url.includes("$");
2116
+ }
2117
+ /**
2118
+ * Wraps handler execution with standardized error handling.
2119
+ *
2120
+ * Re-throws HttpExceptions as-is for framework error handlers.
2121
+ * Other errors are re-thrown for global error handling.
2122
+ *
2123
+ * @param fn - Handler function to wrap
2124
+ * @returns Wrapped function with error handling
2125
+ */ wrapWithErrorHandling(fn) {
2126
+ return async (...args) => {
2127
+ try {
2128
+ return await fn(...args);
2129
+ } catch (error) {
2130
+ if (error && typeof error === "object" && "statusCode" in error) throw error;
2131
+ throw error;
2132
+ }
2133
+ };
2134
+ }
2135
+ };
2136
+
2137
+ //#endregion
2138
+ //#region src/services/guard-runner.service.mts
2139
+ function applyDecs2203RFactory$3() {
2140
+ function createAddInitializerMethod(initializers, decoratorFinishedRef) {
2141
+ return function addInitializer(initializer) {
2142
+ assertNotFinished(decoratorFinishedRef, "addInitializer");
2143
+ assertCallable(initializer, "An initializer");
2144
+ initializers.push(initializer);
2145
+ };
2146
+ }
2147
+ function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
2148
+ var kindStr;
2149
+ switch (kind) {
2150
+ case 1:
2151
+ kindStr = "accessor";
2152
+ break;
2153
+ case 2:
2154
+ kindStr = "method";
2155
+ break;
2156
+ case 3:
2157
+ kindStr = "getter";
2158
+ break;
2159
+ case 4:
2160
+ kindStr = "setter";
2161
+ break;
2162
+ default: kindStr = "field";
2163
+ }
2164
+ var ctx = {
2165
+ kind: kindStr,
2166
+ name: isPrivate ? "#" + name : name,
2167
+ static: isStatic,
2168
+ private: isPrivate,
2169
+ metadata
2170
+ };
2171
+ var decoratorFinishedRef = { v: false };
2172
+ ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
2173
+ var get, set;
2174
+ if (kind === 0) if (isPrivate) {
2175
+ get = desc.get;
2176
+ set = desc.set;
2177
+ } else {
2178
+ get = function() {
2179
+ return this[name];
2180
+ };
2181
+ set = function(v) {
2182
+ this[name] = v;
2183
+ };
2184
+ }
2185
+ else if (kind === 2) get = function() {
2186
+ return desc.value;
2187
+ };
2188
+ else {
2189
+ if (kind === 1 || kind === 3) get = function() {
2190
+ return desc.get.call(this);
2191
+ };
2192
+ if (kind === 1 || kind === 4) set = function(v) {
2193
+ desc.set.call(this, v);
2194
+ };
2195
+ }
2196
+ ctx.access = get && set ? {
2197
+ get,
2198
+ set
2199
+ } : get ? { get } : { set };
2200
+ try {
2201
+ return dec(value, ctx);
2202
+ } finally {
2203
+ decoratorFinishedRef.v = true;
2204
+ }
2205
+ }
2206
+ function assertNotFinished(decoratorFinishedRef, fnName) {
2207
+ if (decoratorFinishedRef.v) throw new Error("attempted to call " + fnName + " after decoration was finished");
2208
+ }
2209
+ function assertCallable(fn, hint) {
2210
+ if (typeof fn !== "function") throw new TypeError(hint + " must be a function");
2211
+ }
2212
+ function assertValidReturnValue(kind, value) {
2213
+ var type = typeof value;
2214
+ if (kind === 1) {
2215
+ if (type !== "object" || value === null) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
2216
+ if (value.get !== void 0) assertCallable(value.get, "accessor.get");
2217
+ if (value.set !== void 0) assertCallable(value.set, "accessor.set");
2218
+ if (value.init !== void 0) assertCallable(value.init, "accessor.init");
2219
+ } else if (type !== "function") {
2220
+ var hint;
2221
+ if (kind === 0) hint = "field";
2222
+ else if (kind === 10) hint = "class";
2223
+ else hint = "method";
2224
+ throw new TypeError(hint + " decorators must return a function or void 0");
2225
+ }
2226
+ }
2227
+ function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
2228
+ var decs = decInfo[0];
2229
+ var desc, init, value;
2230
+ if (isPrivate) if (kind === 0 || kind === 1) desc = {
2231
+ get: decInfo[3],
2232
+ set: decInfo[4]
2233
+ };
2234
+ else if (kind === 3) desc = { get: decInfo[3] };
2235
+ else if (kind === 4) desc = { set: decInfo[3] };
2236
+ else desc = { value: decInfo[3] };
2237
+ else if (kind !== 0) desc = Object.getOwnPropertyDescriptor(base, name);
2238
+ if (kind === 1) value = {
2239
+ get: desc.get,
2240
+ set: desc.set
2241
+ };
2242
+ else if (kind === 2) value = desc.value;
2243
+ else if (kind === 3) value = desc.get;
2244
+ else if (kind === 4) value = desc.set;
2245
+ var newValue, get, set;
2246
+ if (typeof decs === "function") {
2247
+ newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
2248
+ if (newValue !== void 0) {
2249
+ assertValidReturnValue(kind, newValue);
2250
+ if (kind === 0) init = newValue;
2251
+ else if (kind === 1) {
2252
+ init = newValue.init;
2253
+ get = newValue.get || value.get;
2254
+ set = newValue.set || value.set;
2255
+ value = {
2256
+ get,
2257
+ set
2258
+ };
2259
+ } else value = newValue;
2260
+ }
2261
+ } else for (var i = decs.length - 1; i >= 0; i--) {
2262
+ var dec = decs[i];
2263
+ newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
2264
+ if (newValue !== void 0) {
2265
+ assertValidReturnValue(kind, newValue);
2266
+ var newInit;
2267
+ if (kind === 0) newInit = newValue;
2268
+ else if (kind === 1) {
2269
+ newInit = newValue.init;
2270
+ get = newValue.get || value.get;
2271
+ set = newValue.set || value.set;
2272
+ value = {
2273
+ get,
2274
+ set
2275
+ };
2276
+ } else value = newValue;
2277
+ if (newInit !== void 0) if (init === void 0) init = newInit;
2278
+ else if (typeof init === "function") init = [init, newInit];
2279
+ else init.push(newInit);
2280
+ }
2281
+ }
2282
+ if (kind === 0 || kind === 1) {
2283
+ if (init === void 0) init = function(instance, init$1) {
2284
+ return init$1;
2285
+ };
2286
+ else if (typeof init !== "function") {
2287
+ var ownInitializers = init;
2288
+ init = function(instance, init$1) {
2289
+ var value$1 = init$1;
2290
+ for (var i$1 = 0; i$1 < ownInitializers.length; i$1++) value$1 = ownInitializers[i$1].call(instance, value$1);
2291
+ return value$1;
2292
+ };
2293
+ } else {
2294
+ var originalInitializer = init;
2295
+ init = function(instance, init$1) {
2296
+ return originalInitializer.call(instance, init$1);
2297
+ };
2298
+ }
2299
+ ret.push(init);
2300
+ }
2301
+ if (kind !== 0) {
2302
+ if (kind === 1) {
2303
+ desc.get = value.get;
2304
+ desc.set = value.set;
2305
+ } else if (kind === 2) desc.value = value;
2306
+ else if (kind === 3) desc.get = value;
2307
+ else if (kind === 4) desc.set = value;
2308
+ if (isPrivate) if (kind === 1) {
2309
+ ret.push(function(instance, args) {
2310
+ return value.get.call(instance, args);
2311
+ });
2312
+ ret.push(function(instance, args) {
2313
+ return value.set.call(instance, args);
2314
+ });
2315
+ } else if (kind === 2) ret.push(value);
2316
+ else ret.push(function(instance, args) {
2317
+ return value.call(instance, args);
2318
+ });
2319
+ else Object.defineProperty(base, name, desc);
2320
+ }
2321
+ }
2322
+ function applyMemberDecs(Class, decInfos, metadata) {
2323
+ var ret = [];
2324
+ var protoInitializers;
2325
+ var staticInitializers;
2326
+ var existingProtoNonFields = /* @__PURE__ */ new Map();
2327
+ var existingStaticNonFields = /* @__PURE__ */ new Map();
2328
+ for (var i = 0; i < decInfos.length; i++) {
2329
+ var decInfo = decInfos[i];
2330
+ if (!Array.isArray(decInfo)) continue;
2331
+ var kind = decInfo[1];
2332
+ var name = decInfo[2];
2333
+ var isPrivate = decInfo.length > 3;
2334
+ var isStatic = kind >= 5;
2335
+ var base;
2336
+ var initializers;
2337
+ if (isStatic) {
2338
+ base = Class;
2339
+ kind = kind - 5;
2340
+ staticInitializers = staticInitializers || [];
2341
+ initializers = staticInitializers;
2342
+ } else {
2343
+ base = Class.prototype;
2344
+ protoInitializers = protoInitializers || [];
2345
+ initializers = protoInitializers;
2346
+ }
2347
+ if (kind !== 0 && !isPrivate) {
2348
+ var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
2349
+ var existingKind = existingNonFields.get(name) || 0;
2350
+ if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
2351
+ else if (!existingKind && kind > 2) existingNonFields.set(name, kind);
2352
+ else existingNonFields.set(name, true);
2353
+ }
2354
+ applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
2355
+ }
2356
+ pushInitializers(ret, protoInitializers);
2357
+ pushInitializers(ret, staticInitializers);
2358
+ return ret;
2359
+ }
2360
+ function pushInitializers(ret, initializers) {
2361
+ if (initializers) ret.push(function(instance) {
2362
+ for (var i = 0; i < initializers.length; i++) initializers[i].call(instance);
2363
+ return instance;
2364
+ });
2365
+ }
2366
+ function applyClassDecs(targetClass, classDecs, metadata) {
2367
+ if (classDecs.length > 0) {
2368
+ var initializers = [];
2369
+ var newClass = targetClass;
2370
+ var name = targetClass.name;
2371
+ for (var i = classDecs.length - 1; i >= 0; i--) {
2372
+ var decoratorFinishedRef = { v: false };
2373
+ try {
2374
+ var nextNewClass = classDecs[i](newClass, {
2375
+ kind: "class",
2376
+ name,
2377
+ addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
2378
+ metadata
2379
+ });
2380
+ } finally {
2381
+ decoratorFinishedRef.v = true;
2382
+ }
2383
+ if (nextNewClass !== void 0) {
2384
+ assertValidReturnValue(10, nextNewClass);
2385
+ newClass = nextNewClass;
2386
+ }
2387
+ }
2388
+ return [defineMetadata(newClass, metadata), function() {
2389
+ for (var i$1 = 0; i$1 < initializers.length; i$1++) initializers[i$1].call(newClass);
2390
+ }];
2391
+ }
2392
+ }
2393
+ function defineMetadata(Class, metadata) {
2394
+ return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
2395
+ configurable: true,
2396
+ enumerable: true,
2397
+ value: metadata
2398
+ });
2399
+ }
2400
+ return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
2401
+ if (parentClass !== void 0) var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
2402
+ var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
2403
+ var e = applyMemberDecs(targetClass, memberDecs, metadata);
2404
+ if (!classDecs.length) defineMetadata(targetClass, metadata);
2405
+ return {
2406
+ e,
2407
+ get c() {
2408
+ return applyClassDecs(targetClass, classDecs, metadata);
2409
+ }
2410
+ };
2411
+ };
2412
+ }
2413
+ function _apply_decs_2203_r$3(targetClass, memberDecs, classDecs, parentClass) {
2414
+ return (_apply_decs_2203_r$3 = applyDecs2203RFactory$3())(targetClass, memberDecs, classDecs, parentClass);
2415
+ }
2416
+ var _dec$3, _initClass$3;
2417
+ let _GuardRunnerService;
2418
+ _dec$3 = (0, _navios_di.Injectable)();
2419
+ var GuardRunnerService = class {
2420
+ static {
2421
+ ({c: [_GuardRunnerService, _initClass$3]} = _apply_decs_2203_r$3(this, [], [_dec$3]));
2422
+ }
2423
+ errorProducer = (0, _navios_di.inject)(_ErrorResponseProducerService);
2424
+ logger = (0, _navios_di.inject)(Logger, { context: _GuardRunnerService.name });
2425
+ /**
2426
+ * Runs guards that need to be resolved from a scoped container.
2427
+ * Use this when guards have request-scoped dependencies.
2428
+ */ async runGuards(allGuards, executionContext, context) {
2429
+ const guardsArray = Array.from(allGuards).reverse();
2430
+ const guardInstances = await Promise.all(guardsArray.map(async (guard) => {
2431
+ const guardInstance = await context.get(guard);
2432
+ if (!guardInstance.canActivate) throw new Error(`[Navios] Guard ${guard.name} does not implement canActivate()`);
2433
+ return guardInstance;
2434
+ }));
2435
+ return this.executeGuards(guardInstances, executionContext);
2436
+ }
2437
+ /**
2438
+ * Runs pre-resolved guard instances.
2439
+ * Use this when all guards are singletons and have been pre-resolved at startup.
2440
+ */ async runGuardsStatic(guardInstances, executionContext) {
2441
+ return this.executeGuards(guardInstances, executionContext);
2442
+ }
2443
+ /**
2444
+ * Shared guard execution logic.
2445
+ * Iterates through guard instances and calls canActivate on each.
2446
+ */ async executeGuards(guardInstances, executionContext) {
2447
+ let canActivate = true;
2448
+ for (const guardInstance of guardInstances) try {
2449
+ canActivate = await guardInstance.canActivate(executionContext);
2450
+ if (!canActivate) break;
2451
+ } catch (error) {
2452
+ if (error instanceof HttpException) {
2453
+ executionContext.getReply().status(error.statusCode).send(error.response);
2454
+ return false;
2455
+ } else {
2456
+ this.logger.error("Error running guard", error);
2457
+ const errorResponse = this.errorProducer.respond(FrameworkError.InternalServerError, error);
2458
+ executionContext.getReply().status(errorResponse.statusCode).send(errorResponse.payload);
2459
+ return false;
2460
+ }
2461
+ }
2462
+ if (!canActivate) {
2463
+ const errorResponse = this.errorProducer.respond(FrameworkError.Forbidden, null);
2464
+ executionContext.getReply().status(errorResponse.statusCode).send(errorResponse.payload);
2465
+ return false;
2466
+ }
2467
+ return canActivate;
2468
+ }
2469
+ makeContext(moduleMetadata, controllerMetadata, endpoint) {
2470
+ const guards = /* @__PURE__ */ new Set();
2471
+ const endpointGuards = endpoint.guards;
2472
+ const controllerGuards = controllerMetadata.guards;
2473
+ const moduleGuards = moduleMetadata.guards;
2474
+ if (endpointGuards.size > 0) for (const guard of endpointGuards) guards.add(guard);
2475
+ if (controllerGuards.size > 0) for (const guard of controllerGuards) guards.add(guard);
2476
+ if (moduleGuards.size > 0) for (const guard of moduleGuards) guards.add(guard);
2477
+ return guards;
2478
+ }
2479
+ static {
2480
+ _initClass$3();
2481
+ }
2482
+ };
2483
+
2484
+ //#endregion
2485
+ //#region src/services/module-loader.service.mts
2486
+ function applyDecs2203RFactory$2() {
2487
+ function createAddInitializerMethod(initializers, decoratorFinishedRef) {
2488
+ return function addInitializer(initializer) {
2489
+ assertNotFinished(decoratorFinishedRef, "addInitializer");
2490
+ assertCallable(initializer, "An initializer");
2491
+ initializers.push(initializer);
2492
+ };
2493
+ }
2494
+ function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
2495
+ var kindStr;
2496
+ switch (kind) {
2497
+ case 1:
2498
+ kindStr = "accessor";
2499
+ break;
2500
+ case 2:
2501
+ kindStr = "method";
2502
+ break;
2503
+ case 3:
2504
+ kindStr = "getter";
2505
+ break;
2506
+ case 4:
2507
+ kindStr = "setter";
2508
+ break;
2509
+ default: kindStr = "field";
2510
+ }
2511
+ var ctx = {
2512
+ kind: kindStr,
2513
+ name: isPrivate ? "#" + name : name,
2514
+ static: isStatic,
2515
+ private: isPrivate,
2516
+ metadata
2517
+ };
2518
+ var decoratorFinishedRef = { v: false };
2519
+ ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
2520
+ var get, set;
2521
+ if (kind === 0) if (isPrivate) {
2522
+ get = desc.get;
2523
+ set = desc.set;
2524
+ } else {
2525
+ get = function() {
2526
+ return this[name];
2527
+ };
2528
+ set = function(v) {
2529
+ this[name] = v;
2530
+ };
2531
+ }
2532
+ else if (kind === 2) get = function() {
2533
+ return desc.value;
2534
+ };
2535
+ else {
2536
+ if (kind === 1 || kind === 3) get = function() {
2537
+ return desc.get.call(this);
2538
+ };
2539
+ if (kind === 1 || kind === 4) set = function(v) {
2540
+ desc.set.call(this, v);
2541
+ };
2542
+ }
2543
+ ctx.access = get && set ? {
2544
+ get,
2545
+ set
2546
+ } : get ? { get } : { set };
2547
+ try {
2548
+ return dec(value, ctx);
2549
+ } finally {
2550
+ decoratorFinishedRef.v = true;
2551
+ }
2552
+ }
2553
+ function assertNotFinished(decoratorFinishedRef, fnName) {
2554
+ if (decoratorFinishedRef.v) throw new Error("attempted to call " + fnName + " after decoration was finished");
2555
+ }
2556
+ function assertCallable(fn, hint) {
2557
+ if (typeof fn !== "function") throw new TypeError(hint + " must be a function");
2558
+ }
2559
+ function assertValidReturnValue(kind, value) {
2560
+ var type = typeof value;
2561
+ if (kind === 1) {
2562
+ if (type !== "object" || value === null) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
2563
+ if (value.get !== void 0) assertCallable(value.get, "accessor.get");
2564
+ if (value.set !== void 0) assertCallable(value.set, "accessor.set");
2565
+ if (value.init !== void 0) assertCallable(value.init, "accessor.init");
2566
+ } else if (type !== "function") {
2567
+ var hint;
2568
+ if (kind === 0) hint = "field";
2569
+ else if (kind === 10) hint = "class";
2570
+ else hint = "method";
2571
+ throw new TypeError(hint + " decorators must return a function or void 0");
2572
+ }
2573
+ }
2574
+ function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
2575
+ var decs = decInfo[0];
2576
+ var desc, init, value;
2577
+ if (isPrivate) if (kind === 0 || kind === 1) desc = {
2578
+ get: decInfo[3],
2579
+ set: decInfo[4]
2580
+ };
2581
+ else if (kind === 3) desc = { get: decInfo[3] };
2582
+ else if (kind === 4) desc = { set: decInfo[3] };
2583
+ else desc = { value: decInfo[3] };
2584
+ else if (kind !== 0) desc = Object.getOwnPropertyDescriptor(base, name);
2585
+ if (kind === 1) value = {
2586
+ get: desc.get,
2587
+ set: desc.set
2588
+ };
2589
+ else if (kind === 2) value = desc.value;
2590
+ else if (kind === 3) value = desc.get;
2591
+ else if (kind === 4) value = desc.set;
2592
+ var newValue, get, set;
2593
+ if (typeof decs === "function") {
2594
+ newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
2595
+ if (newValue !== void 0) {
2596
+ assertValidReturnValue(kind, newValue);
2597
+ if (kind === 0) init = newValue;
2598
+ else if (kind === 1) {
2599
+ init = newValue.init;
2600
+ get = newValue.get || value.get;
2601
+ set = newValue.set || value.set;
2602
+ value = {
2603
+ get,
2604
+ set
2605
+ };
2606
+ } else value = newValue;
2607
+ }
2608
+ } else for (var i = decs.length - 1; i >= 0; i--) {
2609
+ var dec = decs[i];
2610
+ newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
2611
+ if (newValue !== void 0) {
2612
+ assertValidReturnValue(kind, newValue);
2613
+ var newInit;
2614
+ if (kind === 0) newInit = newValue;
2615
+ else if (kind === 1) {
2616
+ newInit = newValue.init;
2617
+ get = newValue.get || value.get;
2618
+ set = newValue.set || value.set;
2619
+ value = {
2620
+ get,
2621
+ set
2622
+ };
2623
+ } else value = newValue;
2624
+ if (newInit !== void 0) if (init === void 0) init = newInit;
2625
+ else if (typeof init === "function") init = [init, newInit];
2626
+ else init.push(newInit);
2627
+ }
2628
+ }
2629
+ if (kind === 0 || kind === 1) {
2630
+ if (init === void 0) init = function(instance, init$1) {
2631
+ return init$1;
2632
+ };
2633
+ else if (typeof init !== "function") {
2634
+ var ownInitializers = init;
2635
+ init = function(instance, init$1) {
2636
+ var value$1 = init$1;
2637
+ for (var i$1 = 0; i$1 < ownInitializers.length; i$1++) value$1 = ownInitializers[i$1].call(instance, value$1);
2638
+ return value$1;
2639
+ };
2640
+ } else {
2641
+ var originalInitializer = init;
2642
+ init = function(instance, init$1) {
2643
+ return originalInitializer.call(instance, init$1);
2644
+ };
2645
+ }
2646
+ ret.push(init);
2647
+ }
2648
+ if (kind !== 0) {
2649
+ if (kind === 1) {
2650
+ desc.get = value.get;
2651
+ desc.set = value.set;
2652
+ } else if (kind === 2) desc.value = value;
2653
+ else if (kind === 3) desc.get = value;
2654
+ else if (kind === 4) desc.set = value;
2655
+ if (isPrivate) if (kind === 1) {
2656
+ ret.push(function(instance, args) {
2657
+ return value.get.call(instance, args);
2658
+ });
2659
+ ret.push(function(instance, args) {
2660
+ return value.set.call(instance, args);
2661
+ });
2662
+ } else if (kind === 2) ret.push(value);
2663
+ else ret.push(function(instance, args) {
2664
+ return value.call(instance, args);
2665
+ });
2666
+ else Object.defineProperty(base, name, desc);
2667
+ }
2668
+ }
2669
+ function applyMemberDecs(Class, decInfos, metadata) {
2670
+ var ret = [];
2671
+ var protoInitializers;
2672
+ var staticInitializers;
2673
+ var existingProtoNonFields = /* @__PURE__ */ new Map();
2674
+ var existingStaticNonFields = /* @__PURE__ */ new Map();
2675
+ for (var i = 0; i < decInfos.length; i++) {
2676
+ var decInfo = decInfos[i];
2677
+ if (!Array.isArray(decInfo)) continue;
2678
+ var kind = decInfo[1];
2679
+ var name = decInfo[2];
2680
+ var isPrivate = decInfo.length > 3;
2681
+ var isStatic = kind >= 5;
2682
+ var base;
2683
+ var initializers;
2684
+ if (isStatic) {
2685
+ base = Class;
2686
+ kind = kind - 5;
2687
+ staticInitializers = staticInitializers || [];
2688
+ initializers = staticInitializers;
2689
+ } else {
2690
+ base = Class.prototype;
2691
+ protoInitializers = protoInitializers || [];
2692
+ initializers = protoInitializers;
2693
+ }
2694
+ if (kind !== 0 && !isPrivate) {
2695
+ var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
2696
+ var existingKind = existingNonFields.get(name) || 0;
2697
+ if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
2698
+ else if (!existingKind && kind > 2) existingNonFields.set(name, kind);
2699
+ else existingNonFields.set(name, true);
2700
+ }
2701
+ applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
2702
+ }
2703
+ pushInitializers(ret, protoInitializers);
2704
+ pushInitializers(ret, staticInitializers);
2705
+ return ret;
2706
+ }
2707
+ function pushInitializers(ret, initializers) {
2708
+ if (initializers) ret.push(function(instance) {
2709
+ for (var i = 0; i < initializers.length; i++) initializers[i].call(instance);
2710
+ return instance;
2711
+ });
2712
+ }
2713
+ function applyClassDecs(targetClass, classDecs, metadata) {
2714
+ if (classDecs.length > 0) {
2715
+ var initializers = [];
2716
+ var newClass = targetClass;
2717
+ var name = targetClass.name;
2718
+ for (var i = classDecs.length - 1; i >= 0; i--) {
2719
+ var decoratorFinishedRef = { v: false };
2720
+ try {
2721
+ var nextNewClass = classDecs[i](newClass, {
2722
+ kind: "class",
2723
+ name,
2724
+ addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
2725
+ metadata
2726
+ });
2727
+ } finally {
2728
+ decoratorFinishedRef.v = true;
2729
+ }
2730
+ if (nextNewClass !== void 0) {
2731
+ assertValidReturnValue(10, nextNewClass);
2732
+ newClass = nextNewClass;
2733
+ }
2734
+ }
2735
+ return [defineMetadata(newClass, metadata), function() {
2736
+ for (var i$1 = 0; i$1 < initializers.length; i$1++) initializers[i$1].call(newClass);
2737
+ }];
2738
+ }
2739
+ }
2740
+ function defineMetadata(Class, metadata) {
2741
+ return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
2742
+ configurable: true,
2743
+ enumerable: true,
2744
+ value: metadata
2745
+ });
2746
+ }
2747
+ return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
2748
+ if (parentClass !== void 0) var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
2749
+ var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
2750
+ var e = applyMemberDecs(targetClass, memberDecs, metadata);
2751
+ if (!classDecs.length) defineMetadata(targetClass, metadata);
2752
+ return {
2753
+ e,
2754
+ get c() {
2755
+ return applyClassDecs(targetClass, classDecs, metadata);
2756
+ }
2757
+ };
2758
+ };
2759
+ }
2760
+ function _apply_decs_2203_r$2(targetClass, memberDecs, classDecs, parentClass) {
2761
+ return (_apply_decs_2203_r$2 = applyDecs2203RFactory$2())(targetClass, memberDecs, classDecs, parentClass);
2762
+ }
2763
+ var _dec$2, _initClass$2;
2764
+ let _ModuleLoaderService;
2765
+ _dec$2 = (0, _navios_di.Injectable)();
2766
+ var ModuleLoaderService = class {
2767
+ static {
2768
+ ({c: [_ModuleLoaderService, _initClass$2]} = _apply_decs_2203_r$2(this, [], [_dec$2]));
2769
+ }
2770
+ logger = (0, _navios_di.inject)(Logger, { context: _ModuleLoaderService.name });
2771
+ container = (0, _navios_di.inject)(_navios_di.Container);
2772
+ modulesMetadata = /* @__PURE__ */ new Map();
2773
+ loadedModules = /* @__PURE__ */ new Map();
2774
+ initialized = false;
2775
+ async loadModules(appModule) {
2776
+ if (this.initialized) return;
2777
+ await this.traverseModules(appModule);
2778
+ this.initialized = true;
2779
+ }
2780
+ /**
2781
+ * Extends the module tree with additional modules or controllers.
2782
+ *
2783
+ * This method is designed to be called by plugins during registration,
2784
+ * which happens after initial module loading but before route registration.
2785
+ *
2786
+ * @param extensions - Array of module extensions to add
2787
+ * @throws Error if not initialized (loadModules must be called first)
2788
+ *
2789
+ * @example
2790
+ * ```typescript
2791
+ * // In plugin registration
2792
+ * const moduleLoader = await context.container.get(ModuleLoaderService)
2793
+ * await moduleLoader.extendModules([{
2794
+ * controllers: [OpenApiJsonController, OpenApiYamlController],
2795
+ * moduleName: 'OpenApiBunModule',
2796
+ * }])
2797
+ * ```
2798
+ */ async extendModules(extensions) {
2799
+ if (!this.initialized) throw new Error("ModuleLoaderService must be initialized before extending. Call loadModules() first.");
2800
+ for (const extension of extensions) if (extension.module) await this.traverseModules(extension.module);
2801
+ else if (extension.controllers && extension.moduleName) await this.registerControllers(extension.controllers, extension.moduleName);
2802
+ else if (extension.controllers) throw new Error("moduleName is required when providing controllers without a module");
2803
+ }
2804
+ /**
2805
+ * Registers controllers under a synthetic module.
2806
+ * Used when plugins want to add controllers without a full module class.
2807
+ */ async registerControllers(controllers, moduleName) {
2808
+ if (this.modulesMetadata.has(moduleName)) {
2809
+ const existing = this.modulesMetadata.get(moduleName);
2810
+ for (const controller of controllers) existing.controllers.add(controller);
2811
+ this.logger.debug(`Extended module ${moduleName} with ${controllers.length} controllers`);
2812
+ } else {
2813
+ const metadata = {
2814
+ controllers: new Set(controllers),
2815
+ imports: /* @__PURE__ */ new Set(),
2816
+ guards: /* @__PURE__ */ new Set(),
2817
+ overrides: /* @__PURE__ */ new Set(),
2818
+ customAttributes: /* @__PURE__ */ new Map(),
2819
+ customEntries: /* @__PURE__ */ new Map()
2820
+ };
2821
+ this.modulesMetadata.set(moduleName, metadata);
2822
+ this.logger.debug(`Created module ${moduleName} with ${controllers.length} controllers`);
2823
+ }
2824
+ }
2825
+ async traverseModules(module$1, parentMetadata) {
2826
+ const metadata = require_tokens.extractModuleMetadata(module$1);
2827
+ if (parentMetadata) this.mergeMetadata(metadata, parentMetadata);
2828
+ const moduleName = (0, _navios_di.getInjectableToken)(module$1).id;
2829
+ if (this.modulesMetadata.has(moduleName)) return;
2830
+ try {
2831
+ this.modulesMetadata.set(moduleName, metadata);
2832
+ const imports = metadata.imports ?? /* @__PURE__ */ new Set();
2833
+ const loadingPromises = Array.from(imports).map(async (importedModule) => this.traverseModules(importedModule, metadata));
2834
+ await Promise.all(loadingPromises);
2835
+ this.validateOverrides(metadata, moduleName);
2836
+ const instance = await this.container.get(module$1);
2837
+ if (instance.onModuleInit) await instance.onModuleInit();
2838
+ this.logger.debug(`Module ${moduleName} loaded`);
2839
+ this.loadedModules.set(moduleName, instance);
2840
+ } catch (error) {
2841
+ this.logger.error(`Error loading module ${moduleName}`, error);
2842
+ throw error;
2843
+ }
2844
+ }
2845
+ validateOverrides(metadata, moduleName) {
2846
+ if (!metadata.overrides || metadata.overrides.size === 0) return;
2847
+ const registry = this.container.getRegistry();
2848
+ for (const overrideClass of metadata.overrides) try {
2849
+ const overrideToken = (0, _navios_di.getInjectableToken)(overrideClass);
2850
+ const allRegistrations = registry.getAll(overrideToken);
2851
+ if (allRegistrations.length === 0) {
2852
+ this.logger.warn(`[Navios] Override ${overrideClass.name} in module ${moduleName} is not registered. Make sure it has @Injectable decorator.`);
2853
+ continue;
2854
+ }
2855
+ const highestPriorityRegistration = allRegistrations[0];
2856
+ if (highestPriorityRegistration.target !== overrideClass) {
2857
+ const overrideRegistration = allRegistrations.find((r) => r.target === overrideClass);
2858
+ if (!overrideRegistration) this.logger.warn(`[Navios] Override ${overrideClass.name} in module ${moduleName} is registered but not found in registry for token ${overrideToken.toString()}.`);
2859
+ else this.logger.warn(`[Navios] Override ${overrideClass.name} in module ${moduleName} is not active. Current active service: ${highestPriorityRegistration.target.name} (priority: ${highestPriorityRegistration.priority}). Override priority: ${overrideRegistration.priority}. Override needs higher priority to take effect.`);
2860
+ } else this.logger.debug(`[Navios] Override ${overrideClass.name} in module ${moduleName} is active (priority: ${highestPriorityRegistration.priority})`);
2861
+ } catch (error) {
2862
+ this.logger.warn(`[Navios] Failed to validate override ${overrideClass.name} in module ${moduleName}: ${error}`);
2863
+ }
2864
+ }
2865
+ mergeMetadata(metadata, parentMetadata) {
2866
+ if (parentMetadata.guards) for (const guard of parentMetadata.guards) metadata.guards.add(guard);
2867
+ if (parentMetadata.customAttributes) for (const [key, value] of parentMetadata.customAttributes) {
2868
+ if (metadata.customAttributes.has(key)) continue;
2869
+ metadata.customAttributes.set(key, value);
2870
+ }
2871
+ }
2872
+ getAllModules() {
2873
+ return this.modulesMetadata;
2874
+ }
2875
+ dispose() {
2876
+ this.modulesMetadata.clear();
2877
+ this.loadedModules.clear();
2878
+ this.initialized = false;
2879
+ }
2880
+ static {
2881
+ _initClass$2();
2882
+ }
2883
+ };
2884
+
2885
+ //#endregion
2886
+ //#region src/utils/adapter-supports.util.mts
2887
+ /**
2888
+ * Type guard to check if adapter implements a specific method.
2889
+ * Narrows the adapter type to include the method.
2890
+ *
2891
+ * @example
2892
+ * ```typescript
2893
+ * if (adapterSupports(adapter, 'getServer')) {
2894
+ * const server = adapter.getServer() // TypeScript knows this exists
2895
+ * }
2896
+ * ```
2897
+ */ function adapterSupports(adapter, method) {
2898
+ return adapter !== null && typeof adapter[method] === "function";
2899
+ }
2900
+ /**
2901
+ * Asserts adapter supports a method, throws if not.
2902
+ * Narrows type after assertion.
2903
+ *
2904
+ * @example
2905
+ * ```typescript
2906
+ * assertAdapterSupports(adapter, 'enableCors')
2907
+ * adapter.enableCors(options) // TypeScript knows this exists
2908
+ * ```
2909
+ */ function assertAdapterSupports(adapter, method) {
2910
+ if (!adapterSupports(adapter, method)) throw new Error(`Current adapter does not implement '${method}()'`);
2911
+ }
2912
+
2913
+ //#endregion
2914
+ //#region src/navios.environment.mts
2915
+ function applyDecs2203RFactory$1() {
2916
+ function createAddInitializerMethod(initializers, decoratorFinishedRef) {
2917
+ return function addInitializer(initializer) {
2918
+ assertNotFinished(decoratorFinishedRef, "addInitializer");
2919
+ assertCallable(initializer, "An initializer");
2920
+ initializers.push(initializer);
2921
+ };
2922
+ }
2923
+ function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
2924
+ var kindStr;
2925
+ switch (kind) {
2926
+ case 1:
2927
+ kindStr = "accessor";
2928
+ break;
2929
+ case 2:
2930
+ kindStr = "method";
2931
+ break;
2932
+ case 3:
2933
+ kindStr = "getter";
2934
+ break;
2935
+ case 4:
2936
+ kindStr = "setter";
2937
+ break;
2938
+ default: kindStr = "field";
2939
+ }
2940
+ var ctx = {
2941
+ kind: kindStr,
2942
+ name: isPrivate ? "#" + name : name,
2943
+ static: isStatic,
2944
+ private: isPrivate,
2945
+ metadata
2946
+ };
2947
+ var decoratorFinishedRef = { v: false };
2948
+ ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
2949
+ var get, set;
2950
+ if (kind === 0) if (isPrivate) {
2951
+ get = desc.get;
2952
+ set = desc.set;
2953
+ } else {
2954
+ get = function() {
2955
+ return this[name];
2956
+ };
2957
+ set = function(v) {
2958
+ this[name] = v;
2959
+ };
2960
+ }
2961
+ else if (kind === 2) get = function() {
2962
+ return desc.value;
2963
+ };
2964
+ else {
2965
+ if (kind === 1 || kind === 3) get = function() {
2966
+ return desc.get.call(this);
2967
+ };
2968
+ if (kind === 1 || kind === 4) set = function(v) {
2969
+ desc.set.call(this, v);
2970
+ };
2971
+ }
2972
+ ctx.access = get && set ? {
2973
+ get,
2974
+ set
2975
+ } : get ? { get } : { set };
2976
+ try {
2977
+ return dec(value, ctx);
2978
+ } finally {
2979
+ decoratorFinishedRef.v = true;
2980
+ }
2981
+ }
2982
+ function assertNotFinished(decoratorFinishedRef, fnName) {
2983
+ if (decoratorFinishedRef.v) throw new Error("attempted to call " + fnName + " after decoration was finished");
2984
+ }
2985
+ function assertCallable(fn, hint) {
2986
+ if (typeof fn !== "function") throw new TypeError(hint + " must be a function");
2987
+ }
2988
+ function assertValidReturnValue(kind, value) {
2989
+ var type = typeof value;
2990
+ if (kind === 1) {
2991
+ if (type !== "object" || value === null) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
2992
+ if (value.get !== void 0) assertCallable(value.get, "accessor.get");
2993
+ if (value.set !== void 0) assertCallable(value.set, "accessor.set");
2994
+ if (value.init !== void 0) assertCallable(value.init, "accessor.init");
2995
+ } else if (type !== "function") {
2996
+ var hint;
2997
+ if (kind === 0) hint = "field";
2998
+ else if (kind === 10) hint = "class";
2999
+ else hint = "method";
3000
+ throw new TypeError(hint + " decorators must return a function or void 0");
3001
+ }
3002
+ }
3003
+ function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
3004
+ var decs = decInfo[0];
3005
+ var desc, init, value;
3006
+ if (isPrivate) if (kind === 0 || kind === 1) desc = {
3007
+ get: decInfo[3],
3008
+ set: decInfo[4]
3009
+ };
3010
+ else if (kind === 3) desc = { get: decInfo[3] };
3011
+ else if (kind === 4) desc = { set: decInfo[3] };
3012
+ else desc = { value: decInfo[3] };
3013
+ else if (kind !== 0) desc = Object.getOwnPropertyDescriptor(base, name);
3014
+ if (kind === 1) value = {
3015
+ get: desc.get,
3016
+ set: desc.set
3017
+ };
3018
+ else if (kind === 2) value = desc.value;
3019
+ else if (kind === 3) value = desc.get;
3020
+ else if (kind === 4) value = desc.set;
3021
+ var newValue, get, set;
3022
+ if (typeof decs === "function") {
3023
+ newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
3024
+ if (newValue !== void 0) {
3025
+ assertValidReturnValue(kind, newValue);
3026
+ if (kind === 0) init = newValue;
3027
+ else if (kind === 1) {
3028
+ init = newValue.init;
3029
+ get = newValue.get || value.get;
3030
+ set = newValue.set || value.set;
3031
+ value = {
3032
+ get,
3033
+ set
3034
+ };
3035
+ } else value = newValue;
3036
+ }
3037
+ } else for (var i = decs.length - 1; i >= 0; i--) {
3038
+ var dec = decs[i];
3039
+ newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
3040
+ if (newValue !== void 0) {
3041
+ assertValidReturnValue(kind, newValue);
3042
+ var newInit;
3043
+ if (kind === 0) newInit = newValue;
3044
+ else if (kind === 1) {
3045
+ newInit = newValue.init;
3046
+ get = newValue.get || value.get;
3047
+ set = newValue.set || value.set;
3048
+ value = {
3049
+ get,
3050
+ set
3051
+ };
3052
+ } else value = newValue;
3053
+ if (newInit !== void 0) if (init === void 0) init = newInit;
3054
+ else if (typeof init === "function") init = [init, newInit];
3055
+ else init.push(newInit);
3056
+ }
3057
+ }
3058
+ if (kind === 0 || kind === 1) {
3059
+ if (init === void 0) init = function(instance, init$1) {
3060
+ return init$1;
3061
+ };
3062
+ else if (typeof init !== "function") {
3063
+ var ownInitializers = init;
3064
+ init = function(instance, init$1) {
3065
+ var value$1 = init$1;
3066
+ for (var i$1 = 0; i$1 < ownInitializers.length; i$1++) value$1 = ownInitializers[i$1].call(instance, value$1);
3067
+ return value$1;
3068
+ };
3069
+ } else {
3070
+ var originalInitializer = init;
3071
+ init = function(instance, init$1) {
3072
+ return originalInitializer.call(instance, init$1);
3073
+ };
3074
+ }
3075
+ ret.push(init);
3076
+ }
3077
+ if (kind !== 0) {
3078
+ if (kind === 1) {
3079
+ desc.get = value.get;
3080
+ desc.set = value.set;
3081
+ } else if (kind === 2) desc.value = value;
3082
+ else if (kind === 3) desc.get = value;
3083
+ else if (kind === 4) desc.set = value;
3084
+ if (isPrivate) if (kind === 1) {
3085
+ ret.push(function(instance, args) {
3086
+ return value.get.call(instance, args);
3087
+ });
3088
+ ret.push(function(instance, args) {
3089
+ return value.set.call(instance, args);
3090
+ });
3091
+ } else if (kind === 2) ret.push(value);
3092
+ else ret.push(function(instance, args) {
3093
+ return value.call(instance, args);
3094
+ });
3095
+ else Object.defineProperty(base, name, desc);
3096
+ }
3097
+ }
3098
+ function applyMemberDecs(Class, decInfos, metadata) {
3099
+ var ret = [];
3100
+ var protoInitializers;
3101
+ var staticInitializers;
3102
+ var existingProtoNonFields = /* @__PURE__ */ new Map();
3103
+ var existingStaticNonFields = /* @__PURE__ */ new Map();
3104
+ for (var i = 0; i < decInfos.length; i++) {
3105
+ var decInfo = decInfos[i];
3106
+ if (!Array.isArray(decInfo)) continue;
3107
+ var kind = decInfo[1];
3108
+ var name = decInfo[2];
3109
+ var isPrivate = decInfo.length > 3;
3110
+ var isStatic = kind >= 5;
3111
+ var base;
3112
+ var initializers;
3113
+ if (isStatic) {
3114
+ base = Class;
3115
+ kind = kind - 5;
3116
+ staticInitializers = staticInitializers || [];
3117
+ initializers = staticInitializers;
3118
+ } else {
3119
+ base = Class.prototype;
3120
+ protoInitializers = protoInitializers || [];
3121
+ initializers = protoInitializers;
3122
+ }
3123
+ if (kind !== 0 && !isPrivate) {
3124
+ var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
3125
+ var existingKind = existingNonFields.get(name) || 0;
3126
+ if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
3127
+ else if (!existingKind && kind > 2) existingNonFields.set(name, kind);
3128
+ else existingNonFields.set(name, true);
3129
+ }
3130
+ applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
3131
+ }
3132
+ pushInitializers(ret, protoInitializers);
3133
+ pushInitializers(ret, staticInitializers);
3134
+ return ret;
3135
+ }
3136
+ function pushInitializers(ret, initializers) {
3137
+ if (initializers) ret.push(function(instance) {
3138
+ for (var i = 0; i < initializers.length; i++) initializers[i].call(instance);
3139
+ return instance;
3140
+ });
3141
+ }
3142
+ function applyClassDecs(targetClass, classDecs, metadata) {
3143
+ if (classDecs.length > 0) {
3144
+ var initializers = [];
3145
+ var newClass = targetClass;
3146
+ var name = targetClass.name;
3147
+ for (var i = classDecs.length - 1; i >= 0; i--) {
3148
+ var decoratorFinishedRef = { v: false };
3149
+ try {
3150
+ var nextNewClass = classDecs[i](newClass, {
3151
+ kind: "class",
3152
+ name,
3153
+ addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
3154
+ metadata
3155
+ });
3156
+ } finally {
3157
+ decoratorFinishedRef.v = true;
3158
+ }
3159
+ if (nextNewClass !== void 0) {
3160
+ assertValidReturnValue(10, nextNewClass);
3161
+ newClass = nextNewClass;
3162
+ }
3163
+ }
3164
+ return [defineMetadata(newClass, metadata), function() {
3165
+ for (var i$1 = 0; i$1 < initializers.length; i$1++) initializers[i$1].call(newClass);
3166
+ }];
3167
+ }
3168
+ }
3169
+ function defineMetadata(Class, metadata) {
3170
+ return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
3171
+ configurable: true,
3172
+ enumerable: true,
3173
+ value: metadata
3174
+ });
3175
+ }
3176
+ return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
3177
+ if (parentClass !== void 0) var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
3178
+ var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
3179
+ var e = applyMemberDecs(targetClass, memberDecs, metadata);
3180
+ if (!classDecs.length) defineMetadata(targetClass, metadata);
3181
+ return {
3182
+ e,
3183
+ get c() {
3184
+ return applyClassDecs(targetClass, classDecs, metadata);
3185
+ }
3186
+ };
3187
+ };
3188
+ }
3189
+ function _apply_decs_2203_r$1(targetClass, memberDecs, classDecs, parentClass) {
3190
+ return (_apply_decs_2203_r$1 = applyDecs2203RFactory$1())(targetClass, memberDecs, classDecs, parentClass);
3191
+ }
3192
+ var _dec$1, _initClass$1;
3193
+ let _NaviosEnvironment;
3194
+ _dec$1 = (0, _navios_di.Injectable)();
3195
+ var NaviosEnvironment = class {
3196
+ static {
3197
+ ({c: [_NaviosEnvironment, _initClass$1]} = _apply_decs_2203_r$1(this, [], [_dec$1]));
3198
+ }
3199
+ adapterConfigured = false;
3200
+ tokens = /* @__PURE__ */ new Map();
3201
+ setupEnvironment(tokens) {
3202
+ const hasAdapterToken = tokens.has(require_tokens.AdapterToken);
3203
+ if (hasAdapterToken && this.adapterConfigured) throw new Error("Adapter already configured. Only one adapter per application.");
3204
+ for (const [token, value] of tokens) this.tokens.set(token, value);
3205
+ if (hasAdapterToken) this.adapterConfigured = true;
3206
+ }
3207
+ getToken(token) {
3208
+ return this.tokens.get(token);
3209
+ }
3210
+ hasAdapterSetup() {
3211
+ return this.adapterConfigured;
3212
+ }
3213
+ static {
3214
+ _initClass$1();
3215
+ }
3216
+ };
3217
+
3218
+ //#endregion
3219
+ //#region src/navios.application.mts
3220
+ function applyDecs2203RFactory() {
3221
+ function createAddInitializerMethod(initializers, decoratorFinishedRef) {
3222
+ return function addInitializer(initializer) {
3223
+ assertNotFinished(decoratorFinishedRef, "addInitializer");
3224
+ assertCallable(initializer, "An initializer");
3225
+ initializers.push(initializer);
3226
+ };
3227
+ }
3228
+ function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
3229
+ var kindStr;
3230
+ switch (kind) {
3231
+ case 1:
3232
+ kindStr = "accessor";
3233
+ break;
3234
+ case 2:
3235
+ kindStr = "method";
3236
+ break;
3237
+ case 3:
3238
+ kindStr = "getter";
3239
+ break;
3240
+ case 4:
3241
+ kindStr = "setter";
3242
+ break;
3243
+ default: kindStr = "field";
3244
+ }
3245
+ var ctx = {
3246
+ kind: kindStr,
3247
+ name: isPrivate ? "#" + name : name,
3248
+ static: isStatic,
3249
+ private: isPrivate,
3250
+ metadata
3251
+ };
3252
+ var decoratorFinishedRef = { v: false };
3253
+ ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
3254
+ var get, set;
3255
+ if (kind === 0) if (isPrivate) {
3256
+ get = desc.get;
3257
+ set = desc.set;
3258
+ } else {
3259
+ get = function() {
3260
+ return this[name];
3261
+ };
3262
+ set = function(v) {
3263
+ this[name] = v;
3264
+ };
3265
+ }
3266
+ else if (kind === 2) get = function() {
3267
+ return desc.value;
3268
+ };
3269
+ else {
3270
+ if (kind === 1 || kind === 3) get = function() {
3271
+ return desc.get.call(this);
3272
+ };
3273
+ if (kind === 1 || kind === 4) set = function(v) {
3274
+ desc.set.call(this, v);
3275
+ };
3276
+ }
3277
+ ctx.access = get && set ? {
3278
+ get,
3279
+ set
3280
+ } : get ? { get } : { set };
3281
+ try {
3282
+ return dec(value, ctx);
3283
+ } finally {
3284
+ decoratorFinishedRef.v = true;
3285
+ }
3286
+ }
3287
+ function assertNotFinished(decoratorFinishedRef, fnName) {
3288
+ if (decoratorFinishedRef.v) throw new Error("attempted to call " + fnName + " after decoration was finished");
3289
+ }
3290
+ function assertCallable(fn, hint) {
3291
+ if (typeof fn !== "function") throw new TypeError(hint + " must be a function");
3292
+ }
3293
+ function assertValidReturnValue(kind, value) {
3294
+ var type = typeof value;
3295
+ if (kind === 1) {
3296
+ if (type !== "object" || value === null) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
3297
+ if (value.get !== void 0) assertCallable(value.get, "accessor.get");
3298
+ if (value.set !== void 0) assertCallable(value.set, "accessor.set");
3299
+ if (value.init !== void 0) assertCallable(value.init, "accessor.init");
3300
+ } else if (type !== "function") {
3301
+ var hint;
3302
+ if (kind === 0) hint = "field";
3303
+ else if (kind === 10) hint = "class";
3304
+ else hint = "method";
3305
+ throw new TypeError(hint + " decorators must return a function or void 0");
3306
+ }
3307
+ }
3308
+ function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
3309
+ var decs = decInfo[0];
3310
+ var desc, init, value;
3311
+ if (isPrivate) if (kind === 0 || kind === 1) desc = {
3312
+ get: decInfo[3],
3313
+ set: decInfo[4]
3314
+ };
3315
+ else if (kind === 3) desc = { get: decInfo[3] };
3316
+ else if (kind === 4) desc = { set: decInfo[3] };
3317
+ else desc = { value: decInfo[3] };
3318
+ else if (kind !== 0) desc = Object.getOwnPropertyDescriptor(base, name);
3319
+ if (kind === 1) value = {
3320
+ get: desc.get,
3321
+ set: desc.set
3322
+ };
3323
+ else if (kind === 2) value = desc.value;
3324
+ else if (kind === 3) value = desc.get;
3325
+ else if (kind === 4) value = desc.set;
3326
+ var newValue, get, set;
3327
+ if (typeof decs === "function") {
3328
+ newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
3329
+ if (newValue !== void 0) {
3330
+ assertValidReturnValue(kind, newValue);
3331
+ if (kind === 0) init = newValue;
3332
+ else if (kind === 1) {
3333
+ init = newValue.init;
3334
+ get = newValue.get || value.get;
3335
+ set = newValue.set || value.set;
3336
+ value = {
3337
+ get,
3338
+ set
3339
+ };
3340
+ } else value = newValue;
3341
+ }
3342
+ } else for (var i = decs.length - 1; i >= 0; i--) {
3343
+ var dec = decs[i];
3344
+ newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
3345
+ if (newValue !== void 0) {
3346
+ assertValidReturnValue(kind, newValue);
3347
+ var newInit;
3348
+ if (kind === 0) newInit = newValue;
3349
+ else if (kind === 1) {
3350
+ newInit = newValue.init;
3351
+ get = newValue.get || value.get;
3352
+ set = newValue.set || value.set;
3353
+ value = {
3354
+ get,
3355
+ set
3356
+ };
3357
+ } else value = newValue;
3358
+ if (newInit !== void 0) if (init === void 0) init = newInit;
3359
+ else if (typeof init === "function") init = [init, newInit];
3360
+ else init.push(newInit);
3361
+ }
3362
+ }
3363
+ if (kind === 0 || kind === 1) {
3364
+ if (init === void 0) init = function(instance, init$1) {
3365
+ return init$1;
3366
+ };
3367
+ else if (typeof init !== "function") {
3368
+ var ownInitializers = init;
3369
+ init = function(instance, init$1) {
3370
+ var value$1 = init$1;
3371
+ for (var i$1 = 0; i$1 < ownInitializers.length; i$1++) value$1 = ownInitializers[i$1].call(instance, value$1);
3372
+ return value$1;
3373
+ };
3374
+ } else {
3375
+ var originalInitializer = init;
3376
+ init = function(instance, init$1) {
3377
+ return originalInitializer.call(instance, init$1);
3378
+ };
3379
+ }
3380
+ ret.push(init);
3381
+ }
3382
+ if (kind !== 0) {
3383
+ if (kind === 1) {
3384
+ desc.get = value.get;
3385
+ desc.set = value.set;
3386
+ } else if (kind === 2) desc.value = value;
3387
+ else if (kind === 3) desc.get = value;
3388
+ else if (kind === 4) desc.set = value;
3389
+ if (isPrivate) if (kind === 1) {
3390
+ ret.push(function(instance, args) {
3391
+ return value.get.call(instance, args);
3392
+ });
3393
+ ret.push(function(instance, args) {
3394
+ return value.set.call(instance, args);
3395
+ });
3396
+ } else if (kind === 2) ret.push(value);
3397
+ else ret.push(function(instance, args) {
3398
+ return value.call(instance, args);
3399
+ });
3400
+ else Object.defineProperty(base, name, desc);
3401
+ }
3402
+ }
3403
+ function applyMemberDecs(Class, decInfos, metadata) {
3404
+ var ret = [];
3405
+ var protoInitializers;
3406
+ var staticInitializers;
3407
+ var existingProtoNonFields = /* @__PURE__ */ new Map();
3408
+ var existingStaticNonFields = /* @__PURE__ */ new Map();
3409
+ for (var i = 0; i < decInfos.length; i++) {
3410
+ var decInfo = decInfos[i];
3411
+ if (!Array.isArray(decInfo)) continue;
3412
+ var kind = decInfo[1];
3413
+ var name = decInfo[2];
3414
+ var isPrivate = decInfo.length > 3;
3415
+ var isStatic = kind >= 5;
3416
+ var base;
3417
+ var initializers;
3418
+ if (isStatic) {
3419
+ base = Class;
3420
+ kind = kind - 5;
3421
+ staticInitializers = staticInitializers || [];
3422
+ initializers = staticInitializers;
3423
+ } else {
3424
+ base = Class.prototype;
3425
+ protoInitializers = protoInitializers || [];
3426
+ initializers = protoInitializers;
3427
+ }
3428
+ if (kind !== 0 && !isPrivate) {
3429
+ var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
3430
+ var existingKind = existingNonFields.get(name) || 0;
3431
+ if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
3432
+ else if (!existingKind && kind > 2) existingNonFields.set(name, kind);
3433
+ else existingNonFields.set(name, true);
3434
+ }
3435
+ applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
3436
+ }
3437
+ pushInitializers(ret, protoInitializers);
3438
+ pushInitializers(ret, staticInitializers);
3439
+ return ret;
3440
+ }
3441
+ function pushInitializers(ret, initializers) {
3442
+ if (initializers) ret.push(function(instance) {
3443
+ for (var i = 0; i < initializers.length; i++) initializers[i].call(instance);
3444
+ return instance;
3445
+ });
3446
+ }
3447
+ function applyClassDecs(targetClass, classDecs, metadata) {
3448
+ if (classDecs.length > 0) {
3449
+ var initializers = [];
3450
+ var newClass = targetClass;
3451
+ var name = targetClass.name;
3452
+ for (var i = classDecs.length - 1; i >= 0; i--) {
3453
+ var decoratorFinishedRef = { v: false };
3454
+ try {
3455
+ var nextNewClass = classDecs[i](newClass, {
3456
+ kind: "class",
3457
+ name,
3458
+ addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
3459
+ metadata
3460
+ });
3461
+ } finally {
3462
+ decoratorFinishedRef.v = true;
3463
+ }
3464
+ if (nextNewClass !== void 0) {
3465
+ assertValidReturnValue(10, nextNewClass);
3466
+ newClass = nextNewClass;
3467
+ }
3468
+ }
3469
+ return [defineMetadata(newClass, metadata), function() {
3470
+ for (var i$1 = 0; i$1 < initializers.length; i$1++) initializers[i$1].call(newClass);
3471
+ }];
3472
+ }
3473
+ }
3474
+ function defineMetadata(Class, metadata) {
3475
+ return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
3476
+ configurable: true,
3477
+ enumerable: true,
3478
+ value: metadata
3479
+ });
3480
+ }
3481
+ return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
3482
+ if (parentClass !== void 0) var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
3483
+ var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
3484
+ var e = applyMemberDecs(targetClass, memberDecs, metadata);
3485
+ if (!classDecs.length) defineMetadata(targetClass, metadata);
3486
+ return {
3487
+ e,
3488
+ get c() {
3489
+ return applyClassDecs(targetClass, classDecs, metadata);
3490
+ }
3491
+ };
3492
+ };
3493
+ }
3494
+ function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
3495
+ return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
3496
+ }
3497
+ var _dec, _initClass;
3498
+ let _NaviosApplication;
3499
+ _dec = (0, _navios_di.Injectable)();
3500
+ var NaviosApplication = class {
3501
+ static {
3502
+ ({c: [_NaviosApplication, _initClass]} = _apply_decs_2203_r(this, [], [_dec]));
3503
+ }
3504
+ environment = (0, _navios_di.inject)(_NaviosEnvironment);
3505
+ moduleLoader = (0, _navios_di.inject)(_ModuleLoaderService);
3506
+ adapter = null;
3507
+ logger = (0, _navios_di.inject)(Logger, { context: _NaviosApplication.name });
3508
+ container = (0, _navios_di.inject)(_navios_di.Container);
3509
+ appModule = null;
3510
+ options = { adapter: [] };
3511
+ plugins = [];
3512
+ /**
3513
+ * Indicates whether the application has been initialized.
3514
+ * Set to `true` after `init()` completes successfully.
3515
+ */ isInitialized = false;
3516
+ /**
3517
+ * Sets up the application with the provided module and options.
3518
+ * This is called automatically by NaviosFactory.create().
3519
+ *
3520
+ * @param appModule - The root application module
3521
+ * @param options - Application configuration options
3522
+ * @internal
3523
+ */ async setup(appModule, options = { adapter: [] }) {
3524
+ this.appModule = appModule;
3525
+ this.options = options;
3526
+ if (this.environment.hasAdapterSetup()) this.adapter = await this.container.get(require_tokens.AdapterToken);
3527
+ }
3528
+ /**
3529
+ * Gets the dependency injection container used by this application.
3530
+ *
3531
+ * @returns The Container instance
3532
+ */ getContainer() {
3533
+ return this.container;
3534
+ }
3535
+ /**
3536
+ * Returns the current adapter instance.
3537
+ *
3538
+ * @returns The adapter instance
3539
+ * @throws Error if adapter is not initialized
3540
+ */ getAdapter() {
3541
+ if (!this.adapter) throw new Error("Adapter not initialized");
3542
+ return this.adapter;
3543
+ }
3544
+ /**
3545
+ * Registers a plugin to be initialized after modules are loaded.
3546
+ *
3547
+ * Plugins are initialized in the order they are registered,
3548
+ * after all modules are loaded but before the server starts listening.
3549
+ *
3550
+ * @param definition - Plugin definition with options
3551
+ * @returns this for method chaining
3552
+ *
3553
+ * @example
3554
+ * ```typescript
3555
+ * import { defineOpenApiPlugin } from '@navios/openapi-fastify'
3556
+ *
3557
+ * app.usePlugin(defineOpenApiPlugin({
3558
+ * info: { title: 'My API', version: '1.0.0' },
3559
+ * }))
3560
+ * ```
3561
+ */ usePlugin(definition) {
3562
+ this.plugins.push(definition);
3563
+ return this;
3564
+ }
3565
+ /**
3566
+ * Initializes the application.
3567
+ *
3568
+ * This method:
3569
+ * - Loads all modules and their dependencies
3570
+ * - Sets up the adapter if one is configured
3571
+ * - Calls onModuleInit hooks on all modules
3572
+ * - Initializes registered plugins
3573
+ * - Marks the application as initialized
3574
+ *
3575
+ * Must be called before `listen()`.
3576
+ *
3577
+ * @throws Error if app module is not set
3578
+ *
3579
+ * @example
3580
+ * ```typescript
3581
+ * const app = await NaviosFactory.create(AppModule, {
3582
+ * adapter: defineFastifyEnvironment(),
3583
+ * })
3584
+ * await app.init()
3585
+ * await app.listen({ port: 3000 })
3586
+ * ```
3587
+ */ async init() {
3588
+ if (!this.appModule) throw new Error("App module is not set. Call setAppModule() first.");
3589
+ await this.moduleLoader.loadModules(this.appModule);
3590
+ if (this.environment.hasAdapterSetup() && this.adapter) await this.adapter.setupAdapter(this.options);
3591
+ await this.initPlugins();
3592
+ await this.initModules();
3593
+ if (this.adapter) await this.adapter.ready();
3594
+ this.isInitialized = true;
3595
+ this.logger.debug("Navios application initialized");
3596
+ }
3597
+ async initModules() {
3598
+ const modules = this.moduleLoader.getAllModules();
3599
+ if (this.adapter) await this.adapter.onModulesInit(modules);
3600
+ }
3601
+ async initPlugins() {
3602
+ if (this.plugins.length === 0) return;
3603
+ if (!this.adapter) throw new Error("Cannot initialize plugins without an adapter");
3604
+ const context = {
3605
+ modules: this.moduleLoader.getAllModules(),
3606
+ adapter: this.adapter,
3607
+ container: this.container,
3608
+ moduleLoader: this.moduleLoader
3609
+ };
3610
+ for (const { plugin, options } of this.plugins) {
3611
+ this.logger.debug(`Initializing plugin: ${plugin.name}`);
3612
+ await plugin.register(context, options);
3613
+ }
3614
+ }
3615
+ async get(token, args) {
3616
+ return this.container.get(token, args);
3617
+ }
3618
+ /**
3619
+ * Configures the adapter with additional options before initialization.
3620
+ *
3621
+ * This method allows setting adapter-specific configuration options
3622
+ * before the adapter is initialized. Must be called before `init()`.
3623
+ *
3624
+ * @param options - Adapter-specific configuration options
3625
+ * @returns this for method chaining
3626
+ * @throws Error if called after init() or if adapter doesn't support configure
3627
+ *
3628
+ * @example
3629
+ * ```typescript
3630
+ * // With Fastify adapter
3631
+ * app.configure({ trustProxy: true, logger: true })
3632
+ *
3633
+ * // With Bun adapter
3634
+ * app.configure({ development: true })
3635
+ * ```
3636
+ */ configure(options) {
3637
+ if (this.isInitialized) throw new Error("configure() must be called before init()");
3638
+ assertAdapterSupports(this.adapter, "configure");
3639
+ this.adapter.configure(options);
3640
+ return this;
3641
+ }
3642
+ /**
3643
+ * Enables CORS (Cross-Origin Resource Sharing) for the application.
3644
+ *
3645
+ * @param options - CORS configuration options (adapter-specific)
3646
+ * @throws Error if adapter doesn't support enableCors
3647
+ *
3648
+ * @example
3649
+ * ```typescript
3650
+ * app.enableCors({
3651
+ * origin: ['http://localhost:3000', 'https://example.com'],
3652
+ * methods: ['GET', 'POST', 'PUT', 'DELETE'],
3653
+ * credentials: true,
3654
+ * })
3655
+ * ```
3656
+ */ enableCors(options) {
3657
+ assertAdapterSupports(this.adapter, "enableCors");
3658
+ this.adapter.enableCors(options);
3659
+ }
3660
+ /**
3661
+ * Enables multipart/form-data support for file uploads.
3662
+ *
3663
+ * @param options - Multipart configuration options (adapter-specific)
3664
+ * @throws Error if adapter doesn't support enableMultipart
3665
+ *
3666
+ * @example
3667
+ * ```typescript
3668
+ * app.enableMultipart({
3669
+ * limits: {
3670
+ * fileSize: 1024 * 1024 * 10, // 10MB
3671
+ * },
3672
+ * })
3673
+ * ```
3674
+ */ enableMultipart(options) {
3675
+ assertAdapterSupports(this.adapter, "enableMultipart");
3676
+ this.adapter.enableMultipart(options);
3677
+ }
3678
+ /**
3679
+ * Sets a global prefix for all routes.
3680
+ *
3681
+ * @param prefix - The prefix to prepend to all route URLs (e.g., '/api')
3682
+ * @throws Error if adapter doesn't support setGlobalPrefix
3683
+ *
3684
+ * @example
3685
+ * ```typescript
3686
+ * app.setGlobalPrefix('/api/v1')
3687
+ * // All routes will be prefixed with /api/v1
3688
+ * ```
3689
+ */ setGlobalPrefix(prefix) {
3690
+ assertAdapterSupports(this.adapter, "setGlobalPrefix");
3691
+ this.adapter.setGlobalPrefix(prefix);
3692
+ }
3693
+ /**
3694
+ * Gets the underlying HTTP server instance.
3695
+ *
3696
+ * The type of the returned server depends on the adapter used:
3697
+ * - Fastify adapter: Returns FastifyInstance
3698
+ * - Bun adapter: Returns Bun.Server
3699
+ *
3700
+ * @returns The HTTP server instance
3701
+ * @throws Error if adapter doesn't support getServer
3702
+ *
3703
+ * @example
3704
+ * ```typescript
3705
+ * const server = app.getServer()
3706
+ * // Use adapter-specific server methods
3707
+ * ```
3708
+ */ getServer() {
3709
+ assertAdapterSupports(this.adapter, "getServer");
3710
+ return this.adapter.getServer();
3711
+ }
3712
+ /**
3713
+ * Starts the HTTP server and begins listening for requests.
3714
+ *
3715
+ * @param options - Listen options (port, host, etc.)
3716
+ * @throws Error if adapter doesn't support listen
3717
+ *
3718
+ * @example
3719
+ * ```typescript
3720
+ * await app.listen({ port: 3000, host: '0.0.0.0' })
3721
+ * ```
3722
+ */ async listen(options) {
3723
+ assertAdapterSupports(this.adapter, "listen");
3724
+ return this.adapter.listen(options);
3725
+ }
3726
+ /**
3727
+ * Disposes of application resources.
3728
+ *
3729
+ * Cleans up the adapter and module loader.
3730
+ * This method is called automatically by `close()`.
3731
+ */ async dispose() {
3732
+ if (this.adapter) await this.adapter.dispose();
3733
+ if (this.moduleLoader) this.moduleLoader.dispose();
3734
+ }
3735
+ /**
3736
+ * Closes the application and cleans up all resources.
3737
+ *
3738
+ * This is an alias for `dispose()`.
3739
+ *
3740
+ * @example
3741
+ * ```typescript
3742
+ * // Graceful shutdown
3743
+ * process.on('SIGTERM', async () => {
3744
+ * await app.close()
3745
+ * process.exit(0)
3746
+ * })
3747
+ * ```
3748
+ */ async close() {
3749
+ await this.dispose();
3750
+ }
3751
+ static {
3752
+ _initClass();
3753
+ }
3754
+ };
3755
+
3756
+ //#endregion
3757
+ //#region src/navios.factory.mts
3758
+ /**
3759
+ * Factory class for creating and configuring Navios applications.
3760
+ *
3761
+ * This is the main entry point for bootstrapping a Navios application.
3762
+ * It handles dependency injection container setup, adapter registration,
3763
+ * and logger configuration.
3764
+ *
3765
+ * @example
3766
+ * ```typescript
3767
+ * import { NaviosFactory } from '@navios/core'
3768
+ * import { defineFastifyEnvironment } from '@navios/adapter-fastify'
3769
+ *
3770
+ * const app = await NaviosFactory.create(AppModule, {
3771
+ * adapter: defineFastifyEnvironment(),
3772
+ * logger: ['log', 'error', 'warn'],
3773
+ * })
3774
+ *
3775
+ * await app.init()
3776
+ * await app.listen({ port: 3000 })
3777
+ * ```
3778
+ */ var NaviosFactory = class {
3779
+ /**
3780
+ * Creates a new Navios application instance.
3781
+ *
3782
+ * This method sets up the dependency injection container, registers the adapter,
3783
+ * configures logging, and initializes the application with the provided module.
3784
+ *
3785
+ * @typeParam Environment - Adapter environment interface for type-safe access
3786
+ * to adapter-specific features. When specified, methods like `getServer()`,
3787
+ * `enableCors()`, `listen()`, and `configure()` will have proper types.
3788
+ *
3789
+ * @param appModule - The root application module class decorated with @Module()
3790
+ * @param options - Configuration options for the application
3791
+ * @param options.adapter - Adapter environment (required for server functionality)
3792
+ * @param options.logger - Logger configuration. Can be:
3793
+ * - A LoggerService instance for custom logging
3794
+ * - An array of LogLevel strings to enable specific log levels
3795
+ * - `false` to disable logging
3796
+ * @param options.container - Optional custom dependency injection container (useful for testing)
3797
+ * @returns A configured NaviosApplication instance ready to be initialized
3798
+ *
3799
+ * @example
3800
+ * ```typescript
3801
+ * // Basic setup with Fastify adapter
3802
+ * const app = await NaviosFactory.create(AppModule, {
3803
+ * adapter: defineFastifyEnvironment(),
3804
+ * })
3805
+ *
3806
+ * // Type-safe setup with Fastify environment
3807
+ * import { FastifyEnvironment } from '@navios/adapter-fastify'
3808
+ *
3809
+ * const app = await NaviosFactory.create<FastifyEnvironment>(AppModule, {
3810
+ * adapter: defineFastifyEnvironment(),
3811
+ * })
3812
+ * app.configure({ trustProxy: true })
3813
+ * const server = app.getServer() // FastifyInstance
3814
+ *
3815
+ * // With custom logger configuration
3816
+ * const app = await NaviosFactory.create(AppModule, {
3817
+ * adapter: defineFastifyEnvironment(),
3818
+ * logger: ['error', 'warn', 'log'],
3819
+ * })
3820
+ *
3821
+ * // With custom container for testing
3822
+ * const container = new Container()
3823
+ * const app = await NaviosFactory.create(AppModule, {
3824
+ * adapter: defineFastifyEnvironment(),
3825
+ * container,
3826
+ * })
3827
+ * ```
3828
+ */ static async create(appModule, options = { adapter: [] }) {
3829
+ const container = options.container ?? new _navios_di.Container(options.registry);
3830
+ if (options.enableRequestId === true) setRequestIdEnabled(true);
3831
+ container.addInstance(require_tokens.NaviosOptionsToken, options);
3832
+ await this.registerLoggerConfiguration(container, options);
3833
+ const adapters = Array.isArray(options.adapter) ? options.adapter : [options.adapter];
3834
+ for (const adapter of adapters) await this.registerEnvironment(container, adapter);
3835
+ const app = await container.get(_NaviosApplication);
3836
+ await app.setup(appModule, options);
3837
+ return app;
3838
+ }
3839
+ static async registerEnvironment(container, environment = {}) {
3840
+ const naviosEnvironment = await container.get(_NaviosEnvironment);
3841
+ const { tokens } = environment;
3842
+ if (tokens) naviosEnvironment.setupEnvironment(tokens);
3843
+ }
3844
+ static async registerLoggerConfiguration(container, options) {
3845
+ const { logger } = options;
3846
+ if (Array.isArray(logger) || isNil(logger) || options.enableRequestId) {
3847
+ (await container.get(LoggerOutput))?.setup({
3848
+ logLevels: Array.isArray(logger) ? logger : void 0,
3849
+ requestId: options.enableRequestId ?? false
3850
+ });
3851
+ return;
3852
+ }
3853
+ if (logger !== true && !isNil(logger)) container.addInstance(LoggerOutput, logger);
3854
+ }
3855
+ };
3856
+
3857
+ //#endregion
3858
+ Object.defineProperty(exports, 'AbstractHandlerAdapterService', {
3859
+ enumerable: true,
3860
+ get: function () {
3861
+ return AbstractHandlerAdapterService;
3862
+ }
3863
+ });
3864
+ Object.defineProperty(exports, 'ControllerResolverService', {
3865
+ enumerable: true,
3866
+ get: function () {
3867
+ return ControllerResolverService;
3868
+ }
3869
+ });
3870
+ Object.defineProperty(exports, 'ForbiddenResponderToken', {
3871
+ enumerable: true,
3872
+ get: function () {
3873
+ return ForbiddenResponderToken;
3874
+ }
3875
+ });
3876
+ Object.defineProperty(exports, 'FrameworkError', {
3877
+ enumerable: true,
3878
+ get: function () {
3879
+ return FrameworkError;
3880
+ }
3881
+ });
3882
+ Object.defineProperty(exports, 'HttpException', {
3883
+ enumerable: true,
3884
+ get: function () {
3885
+ return HttpException;
3886
+ }
3887
+ });
3888
+ Object.defineProperty(exports, 'InternalServerErrorResponderToken', {
3889
+ enumerable: true,
3890
+ get: function () {
3891
+ return InternalServerErrorResponderToken;
3892
+ }
3893
+ });
3894
+ Object.defineProperty(exports, 'LOG_LEVELS', {
3895
+ enumerable: true,
3896
+ get: function () {
3897
+ return LOG_LEVELS;
3898
+ }
3899
+ });
3900
+ Object.defineProperty(exports, 'Logger', {
3901
+ enumerable: true,
3902
+ get: function () {
3903
+ return Logger;
3904
+ }
3905
+ });
3906
+ Object.defineProperty(exports, 'LoggerOutput', {
3907
+ enumerable: true,
3908
+ get: function () {
3909
+ return LoggerOutput;
3910
+ }
3911
+ });
3912
+ Object.defineProperty(exports, 'NaviosFactory', {
3913
+ enumerable: true,
3914
+ get: function () {
3915
+ return NaviosFactory;
3916
+ }
3917
+ });
3918
+ Object.defineProperty(exports, 'NotFoundResponderToken', {
3919
+ enumerable: true,
3920
+ get: function () {
3921
+ return NotFoundResponderToken;
3922
+ }
3923
+ });
3924
+ Object.defineProperty(exports, 'ValidationErrorResponderToken', {
3925
+ enumerable: true,
3926
+ get: function () {
3927
+ return ValidationErrorResponderToken;
3928
+ }
3929
+ });
3930
+ Object.defineProperty(exports, '_ConsoleLogger', {
3931
+ enumerable: true,
3932
+ get: function () {
3933
+ return _ConsoleLogger;
3934
+ }
3935
+ });
3936
+ Object.defineProperty(exports, '_ErrorResponseProducerService', {
3937
+ enumerable: true,
3938
+ get: function () {
3939
+ return _ErrorResponseProducerService;
3940
+ }
3941
+ });
3942
+ Object.defineProperty(exports, '_GuardRunnerService', {
3943
+ enumerable: true,
3944
+ get: function () {
3945
+ return _GuardRunnerService;
3946
+ }
3947
+ });
3948
+ Object.defineProperty(exports, '_InstanceResolverService', {
3949
+ enumerable: true,
3950
+ get: function () {
3951
+ return _InstanceResolverService;
3952
+ }
3953
+ });
3954
+ Object.defineProperty(exports, '_LoggerInstance', {
3955
+ enumerable: true,
3956
+ get: function () {
3957
+ return _LoggerInstance;
3958
+ }
3959
+ });
3960
+ Object.defineProperty(exports, '_ModuleLoaderService', {
3961
+ enumerable: true,
3962
+ get: function () {
3963
+ return _ModuleLoaderService;
3964
+ }
3965
+ });
3966
+ Object.defineProperty(exports, '_NaviosApplication', {
3967
+ enumerable: true,
3968
+ get: function () {
3969
+ return _NaviosApplication;
3970
+ }
3971
+ });
3972
+ Object.defineProperty(exports, '_NaviosEnvironment', {
3973
+ enumerable: true,
3974
+ get: function () {
3975
+ return _NaviosEnvironment;
3976
+ }
3977
+ });
3978
+ Object.defineProperty(exports, '__toESM', {
3979
+ enumerable: true,
3980
+ get: function () {
3981
+ return __toESM;
3982
+ }
3983
+ });
3984
+ Object.defineProperty(exports, 'adapterSupports', {
3985
+ enumerable: true,
3986
+ get: function () {
3987
+ return adapterSupports;
3988
+ }
3989
+ });
3990
+ Object.defineProperty(exports, 'addLeadingSlash', {
3991
+ enumerable: true,
3992
+ get: function () {
3993
+ return addLeadingSlash;
3994
+ }
3995
+ });
3996
+ Object.defineProperty(exports, 'assertAdapterSupports', {
3997
+ enumerable: true,
3998
+ get: function () {
3999
+ return assertAdapterSupports;
4000
+ }
4001
+ });
4002
+ Object.defineProperty(exports, 'clc', {
4003
+ enumerable: true,
4004
+ get: function () {
4005
+ return clc;
4006
+ }
4007
+ });
4008
+ Object.defineProperty(exports, 'filterLogLevels', {
4009
+ enumerable: true,
4010
+ get: function () {
4011
+ return filterLogLevels;
4012
+ }
4013
+ });
4014
+ Object.defineProperty(exports, 'generateRequestId', {
4015
+ enumerable: true,
4016
+ get: function () {
4017
+ return generateRequestId;
4018
+ }
4019
+ });
4020
+ Object.defineProperty(exports, 'getRequestId', {
4021
+ enumerable: true,
4022
+ get: function () {
4023
+ return getRequestId;
4024
+ }
4025
+ });
4026
+ Object.defineProperty(exports, 'isConstructor', {
4027
+ enumerable: true,
4028
+ get: function () {
4029
+ return isConstructor;
4030
+ }
4031
+ });
4032
+ Object.defineProperty(exports, 'isEmpty', {
4033
+ enumerable: true,
4034
+ get: function () {
4035
+ return isEmpty;
4036
+ }
4037
+ });
4038
+ Object.defineProperty(exports, 'isFunction', {
4039
+ enumerable: true,
4040
+ get: function () {
4041
+ return isFunction;
4042
+ }
4043
+ });
4044
+ Object.defineProperty(exports, 'isLogLevel', {
4045
+ enumerable: true,
4046
+ get: function () {
4047
+ return isLogLevel;
4048
+ }
4049
+ });
4050
+ Object.defineProperty(exports, 'isLogLevelEnabled', {
4051
+ enumerable: true,
4052
+ get: function () {
4053
+ return isLogLevelEnabled;
4054
+ }
4055
+ });
4056
+ Object.defineProperty(exports, 'isNil', {
4057
+ enumerable: true,
4058
+ get: function () {
4059
+ return isNil;
4060
+ }
4061
+ });
4062
+ Object.defineProperty(exports, 'isNumber', {
4063
+ enumerable: true,
4064
+ get: function () {
4065
+ return isNumber;
4066
+ }
4067
+ });
4068
+ Object.defineProperty(exports, 'isObject', {
4069
+ enumerable: true,
4070
+ get: function () {
4071
+ return isObject;
4072
+ }
4073
+ });
4074
+ Object.defineProperty(exports, 'isPlainObject', {
4075
+ enumerable: true,
4076
+ get: function () {
4077
+ return isPlainObject;
4078
+ }
4079
+ });
4080
+ Object.defineProperty(exports, 'isString', {
4081
+ enumerable: true,
4082
+ get: function () {
4083
+ return isString;
4084
+ }
4085
+ });
4086
+ Object.defineProperty(exports, 'isSymbol', {
4087
+ enumerable: true,
4088
+ get: function () {
4089
+ return isSymbol;
4090
+ }
4091
+ });
4092
+ Object.defineProperty(exports, 'isUndefined', {
4093
+ enumerable: true,
4094
+ get: function () {
4095
+ return isUndefined;
4096
+ }
4097
+ });
4098
+ Object.defineProperty(exports, 'loggerOptionsSchema', {
4099
+ enumerable: true,
4100
+ get: function () {
4101
+ return loggerOptionsSchema;
4102
+ }
4103
+ });
4104
+ Object.defineProperty(exports, 'normalizePath', {
4105
+ enumerable: true,
4106
+ get: function () {
4107
+ return normalizePath;
4108
+ }
4109
+ });
4110
+ Object.defineProperty(exports, 'runWithRequestId', {
4111
+ enumerable: true,
4112
+ get: function () {
4113
+ return runWithRequestId;
4114
+ }
4115
+ });
4116
+ Object.defineProperty(exports, 'setRequestIdEnabled', {
4117
+ enumerable: true,
4118
+ get: function () {
4119
+ return setRequestIdEnabled;
4120
+ }
4121
+ });
4122
+ Object.defineProperty(exports, 'stripEndSlash', {
4123
+ enumerable: true,
4124
+ get: function () {
4125
+ return stripEndSlash;
4126
+ }
4127
+ });
4128
+ Object.defineProperty(exports, 'yellow', {
4129
+ enumerable: true,
4130
+ get: function () {
4131
+ return yellow;
4132
+ }
4133
+ });
4134
+ //# sourceMappingURL=navios.factory-BanZIvtR.cjs.map