@navios/commander 0.7.1 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { Container, Factory, Injectable, InjectableScope, InjectableType, InjectionToken, inject } from "@navios/di";
1
+ import { Container, Factory, Injectable, InjectableScope, InjectionToken, getInjectableToken, inject } from "@navios/di";
2
2
  import { env } from "node:process";
3
3
  import z, { z as z$1 } from "zod/v4";
4
4
  import { inspect } from "util";
@@ -41,7 +41,7 @@ var __copyProps = (to, from, except, desc) => {
41
41
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
42
42
 
43
43
  //#endregion
44
- //#region ../core/lib/use-guards.decorator-kZ3lNK8v.mjs
44
+ //#region ../core/lib/use-guards.decorator-CzVXuLkz.mjs
45
45
  const EndpointMetadataKey = Symbol("EndpointMetadataKey");
46
46
  function getAllEndpointMetadata(context) {
47
47
  if (context.metadata) {
@@ -134,13 +134,13 @@ function hasModuleMetadata(target) {
134
134
  }
135
135
  /**
136
136
  * Decorator that marks a class as a Navios controller.
137
- *
137
+ *
138
138
  * Controllers handle HTTP requests and define endpoints.
139
139
  * They are request-scoped by default, meaning a new instance is created for each request.
140
- *
140
+ *
141
141
  * @param options - Controller configuration options
142
142
  * @returns A class decorator
143
- *
143
+ *
144
144
  * @example
145
145
  * ```typescript
146
146
  * @Controller({ guards: [AuthGuard] })
@@ -151,7 +151,7 @@ function hasModuleMetadata(target) {
151
151
  * }
152
152
  * }
153
153
  * ```
154
- */ function Controller({ guards } = {}) {
154
+ */ function Controller({ guards, registry, priority, scope } = {}) {
155
155
  return function(target, context) {
156
156
  if (context.kind !== "class") throw new Error("[Navios] @Controller decorator can only be used on classes.");
157
157
  const token = InjectionToken.create(target);
@@ -161,7 +161,9 @@ function hasModuleMetadata(target) {
161
161
  }
162
162
  return Injectable({
163
163
  token,
164
- scope: InjectableScope.Request
164
+ registry,
165
+ priority,
166
+ scope
165
167
  })(target, context);
166
168
  };
167
169
  }
@@ -170,40 +172,12 @@ const ExecutionContextInjectionToken = "ExecutionContextInjectionToken";
170
172
  const ExecutionContext = InjectionToken.create(ExecutionContextInjectionToken);
171
173
  const HttpAdapterToken = InjectionToken.create("HttpAdapterToken");
172
174
  const MultipartAdapterToken = InjectionToken.create("MultipartAdapterToken");
175
+ const NaviosOptionsToken = InjectionToken.create("NaviosOptionsToken");
173
176
  const Reply = InjectionToken.create("ReplyToken");
174
177
  const Request = InjectionToken.create("RequestToken");
175
178
  const StreamAdapterToken = InjectionToken.create("StreamAdapterToken");
176
179
  const XmlStreamAdapterToken = InjectionToken.create("XmlStreamAdapterToken");
177
- /**
178
- * Decorator that marks a method as an HTTP endpoint.
179
- *
180
- * The endpoint must be defined using @navios/builder's `declareEndpoint` method.
181
- * This ensures type safety and consistency between client and server.
182
- *
183
- * @param endpoint - The endpoint declaration from @navios/builder
184
- * @returns A method decorator
185
- *
186
- * @example
187
- * ```typescript
188
- * import { builder } from '@navios/builder'
189
- *
190
- * const api = builder()
191
- * const getUserEndpoint = api.declareEndpoint({
192
- * method: 'get',
193
- * url: '/users/$userId',
194
- * responseSchema: z.object({ id: z.string(), name: z.string() }),
195
- * })
196
- *
197
- * @Controller()
198
- * export class UserController {
199
- * @Endpoint(getUserEndpoint)
200
- * async getUser(request: EndpointParams<typeof getUserEndpoint>) {
201
- * const { userId } = request.urlParams
202
- * return { id: userId, name: 'John' }
203
- * }
204
- * }
205
- * ```
206
- */ function Endpoint(endpoint) {
180
+ function Endpoint(endpoint) {
207
181
  return (target, context) => {
208
182
  if (context.kind !== "method") throw new Error("[Navios] Endpoint decorator can only be used on methods.");
209
183
  const config = endpoint.config;
@@ -274,13 +248,13 @@ const XmlStreamAdapterToken = InjectionToken.create("XmlStreamAdapterToken");
274
248
  }
275
249
  /**
276
250
  * Decorator that marks a class as a Navios module.
277
- *
251
+ *
278
252
  * Modules are the basic building blocks of a Navios application.
279
253
  * They organize controllers, services, and other modules into logical units.
280
- *
254
+ *
281
255
  * @param options - Module configuration options
282
256
  * @returns A class decorator
283
- *
257
+ *
284
258
  * @example
285
259
  * ```typescript
286
260
  * @Module({
@@ -290,7 +264,7 @@ const XmlStreamAdapterToken = InjectionToken.create("XmlStreamAdapterToken");
290
264
  * })
291
265
  * export class AppModule {}
292
266
  * ```
293
- */ function Module({ controllers = [], imports = [], guards = [] } = {
267
+ */ function Module({ controllers = [], imports = [], guards = [], priority, registry } = {
294
268
  controllers: [],
295
269
  imports: [],
296
270
  guards: []
@@ -304,41 +278,14 @@ const XmlStreamAdapterToken = InjectionToken.create("XmlStreamAdapterToken");
304
278
  for (const guard of Array.from(guards).reverse()) moduleMetadata.guards.add(guard);
305
279
  return Injectable({
306
280
  token,
307
- scope: InjectableScope.Singleton
281
+ scope: InjectableScope.Singleton,
282
+ priority,
283
+ registry
308
284
  })(target, context);
309
285
  };
310
286
  }
311
- /**
312
- * Decorator that marks a method as a multipart/form-data endpoint.
313
- *
314
- * Use this decorator for endpoints that handle file uploads or form data.
315
- * The endpoint must be defined using @navios/builder's `declareMultipart` method.
316
- *
317
- * @param endpoint - The multipart endpoint declaration from @navios/builder
318
- * @returns A method decorator
319
- *
320
- * @example
321
- * ```typescript
322
- * const uploadFileEndpoint = api.declareMultipart({
323
- * method: 'post',
324
- * url: '/upload',
325
- * requestSchema: z.object({ file: z.instanceof(File) }),
326
- * responseSchema: z.object({ url: z.string() }),
327
- * })
328
- *
329
- * @Controller()
330
- * export class FileController {
331
- * @Multipart(uploadFileEndpoint)
332
- * async uploadFile(request: MultipartParams<typeof uploadFileEndpoint>) {
333
- * const { file } = request.data
334
- * // Handle file upload
335
- * return { url: 'https://example.com/file.jpg' }
336
- * }
337
- * }
338
- * ```
339
- */ function Multipart(endpoint) {
287
+ function Multipart(endpoint) {
340
288
  return (target, context) => {
341
- if (typeof target !== "function") throw new Error("[Navios] Endpoint decorator can only be used on functions.");
342
289
  if (context.kind !== "method") throw new Error("[Navios] Endpoint decorator can only be used on methods.");
343
290
  const config = endpoint.config;
344
291
  if (context.metadata) {
@@ -353,34 +300,8 @@ const XmlStreamAdapterToken = InjectionToken.create("XmlStreamAdapterToken");
353
300
  return target;
354
301
  };
355
302
  }
356
- /**
357
- * Decorator that marks a method as a streaming endpoint.
358
- *
359
- * Use this decorator for endpoints that stream data (e.g., file downloads, SSE).
360
- * The endpoint must be defined using @navios/builder's `declareStream` method.
361
- *
362
- * @param endpoint - The stream endpoint declaration from @navios/builder
363
- * @returns A method decorator
364
- *
365
- * @example
366
- * ```typescript
367
- * const downloadFileEndpoint = api.declareStream({
368
- * method: 'get',
369
- * url: '/files/$fileId',
370
- * })
371
- *
372
- * @Controller()
373
- * export class FileController {
374
- * @Stream(downloadFileEndpoint)
375
- * async downloadFile(request: StreamParams<typeof downloadFileEndpoint>, reply: any) {
376
- * const { fileId } = request.urlParams
377
- * // Stream file data to reply
378
- * }
379
- * }
380
- * ```
381
- */ function Stream(endpoint) {
303
+ function Stream(endpoint) {
382
304
  return (target, context) => {
383
- if (typeof target !== "function") throw new Error("[Navios] Endpoint decorator can only be used on functions.");
384
305
  if (context.kind !== "method") throw new Error("[Navios] Endpoint decorator can only be used on methods.");
385
306
  const config = endpoint.config;
386
307
  if (context.metadata) {
@@ -463,7 +384,7 @@ const XmlStreamAdapterToken = InjectionToken.create("XmlStreamAdapterToken");
463
384
  };
464
385
 
465
386
  //#endregion
466
- //#region ../core/lib/src-DpPBxmjz.mjs
387
+ //#region ../core/lib/src-Bo23RIo-.mjs
467
388
  function envInt(key, defaultValue) {
468
389
  const envKey = env[key] || process.env[key];
469
390
  return envKey ? parseInt(envKey, 10) : defaultValue;
@@ -546,6 +467,15 @@ const isConstructor = (val) => val === "constructor";
546
467
  const isNil = (val) => isUndefined(val) || val === null;
547
468
  const isEmpty = (array) => !(array && array.length > 0);
548
469
  const isSymbol = (val) => typeof val === "symbol";
470
+ let requestCounter = 0;
471
+ /**
472
+ * Generates a simple incremental request ID.
473
+ * Much faster than crypto.randomUUID() and sufficient for request tracking.
474
+ *
475
+ * @returns A unique request ID string (e.g., "req-1", "req-2", ...)
476
+ */ function generateRequestId() {
477
+ return `req-${++requestCounter}`;
478
+ }
549
479
  /**
550
480
  * AsyncLocalStorage store for the current request ID.
551
481
  *
@@ -565,22 +495,42 @@ const isSymbol = (val) => typeof val === "symbol";
565
495
  * // Get current request ID (returns undefined if not in a request context)
566
496
  * const currentId = getRequestId()
567
497
  * ```
568
- */ const requestIdStore = new AsyncLocalStorage();
498
+ */ let requestIdStore = null;
499
+ function getRequestIdStore() {
500
+ if (!requestIdStore) requestIdStore = new AsyncLocalStorage();
501
+ return requestIdStore;
502
+ }
503
+ /**
504
+ * Whether request ID propagation is enabled.
505
+ * When disabled, runWithRequestId is a pass-through for better performance.
506
+ */ let requestIdEnabled = false;
507
+ /**
508
+ * Enables or disables request ID propagation.
509
+ * Called by NaviosFactory based on the enableRequestId option.
510
+ *
511
+ * @param enabled - Whether to enable request ID propagation
512
+ */ function setRequestIdEnabled(enabled) {
513
+ requestIdEnabled = enabled;
514
+ }
569
515
  /**
570
516
  * Runs a function with a request ID in the async local storage context.
517
+ * If request ID propagation is disabled, the function is called directly
518
+ * without AsyncLocalStorage overhead.
571
519
  *
572
520
  * @param requestId - The request ID to set for this context
573
521
  * @param fn - The function to run within this context
574
522
  * @returns The return value of the function
575
523
  */ function runWithRequestId(requestId, fn) {
576
- return requestIdStore.run(requestId, fn);
524
+ if (!requestIdEnabled) return fn();
525
+ return getRequestIdStore().run(requestId, fn);
577
526
  }
578
527
  /**
579
528
  * Gets the current request ID from the async local storage context.
580
529
  *
581
530
  * @returns The current request ID, or undefined if not in a request context
582
531
  */ function getRequestId() {
583
- return requestIdStore.getStore();
532
+ if (!requestIdEnabled) return;
533
+ return getRequestIdStore().getStore();
584
534
  }
585
535
  /**
586
536
  * Injection token for the logger output service.
@@ -602,7 +552,7 @@ const isSymbol = (val) => typeof val === "symbol";
602
552
  * logger.log('Hello world') // Logs with context: [MyService]
603
553
  * ```
604
554
  */ const Logger = InjectionToken.create("Logger", loggerOptionsSchema);
605
- function applyDecs2203RFactory$13() {
555
+ function applyDecs2203RFactory$14() {
606
556
  function createAddInitializerMethod(initializers, decoratorFinishedRef) {
607
557
  return function addInitializer(initializer) {
608
558
  assertNotFinished(decoratorFinishedRef, "addInitializer");
@@ -876,10 +826,10 @@ function applyDecs2203RFactory$13() {
876
826
  };
877
827
  };
878
828
  }
879
- function _apply_decs_2203_r$13(targetClass, memberDecs, classDecs, parentClass) {
880
- return (_apply_decs_2203_r$13 = applyDecs2203RFactory$13())(targetClass, memberDecs, classDecs, parentClass);
829
+ function _apply_decs_2203_r$14(targetClass, memberDecs, classDecs, parentClass) {
830
+ return (_apply_decs_2203_r$14 = applyDecs2203RFactory$14())(targetClass, memberDecs, classDecs, parentClass);
881
831
  }
882
- var _dec$13, _initClass$13;
832
+ var _dec$14, _initClass$14;
883
833
  const DEFAULT_DEPTH = 5;
884
834
  const DEFAULT_LOG_LEVELS = [
885
835
  "log",
@@ -898,10 +848,10 @@ const dateTimeFormatter = new Intl.DateTimeFormat(void 0, {
898
848
  month: "2-digit"
899
849
  });
900
850
  let _ConsoleLogger;
901
- _dec$13 = Injectable({ token: LoggerOutput });
851
+ _dec$14 = Injectable({ token: LoggerOutput });
902
852
  (class {
903
853
  static {
904
- ({c: [_ConsoleLogger, _initClass$13]} = _apply_decs_2203_r$13(this, [], [_dec$13]));
854
+ ({c: [_ConsoleLogger, _initClass$14]} = _apply_decs_2203_r$14(this, [], [_dec$14]));
905
855
  }
906
856
  /**
907
857
  * The options of the logger.
@@ -1150,10 +1100,10 @@ _dec$13 = Injectable({ token: LoggerOutput });
1150
1100
  }
1151
1101
  }
1152
1102
  static {
1153
- _initClass$13();
1103
+ _initClass$14();
1154
1104
  }
1155
1105
  });
1156
- function applyDecs2203RFactory$12() {
1106
+ function applyDecs2203RFactory$13() {
1157
1107
  function createAddInitializerMethod(initializers, decoratorFinishedRef) {
1158
1108
  return function addInitializer(initializer) {
1159
1109
  assertNotFinished(decoratorFinishedRef, "addInitializer");
@@ -1427,15 +1377,15 @@ function applyDecs2203RFactory$12() {
1427
1377
  };
1428
1378
  };
1429
1379
  }
1430
- function _apply_decs_2203_r$12(targetClass, memberDecs, classDecs, parentClass) {
1431
- return (_apply_decs_2203_r$12 = applyDecs2203RFactory$12())(targetClass, memberDecs, classDecs, parentClass);
1380
+ function _apply_decs_2203_r$13(targetClass, memberDecs, classDecs, parentClass) {
1381
+ return (_apply_decs_2203_r$13 = applyDecs2203RFactory$13())(targetClass, memberDecs, classDecs, parentClass);
1432
1382
  }
1433
- var _dec$12, _initClass$12;
1383
+ var _dec$13, _initClass$13;
1434
1384
  let _LoggerInstance;
1435
- _dec$12 = Injectable({ token: Logger });
1385
+ _dec$13 = Injectable({ token: Logger });
1436
1386
  (class {
1437
1387
  static {
1438
- ({c: [_LoggerInstance, _initClass$12]} = _apply_decs_2203_r$12(this, [], [_dec$12]));
1388
+ ({c: [_LoggerInstance, _initClass$13]} = _apply_decs_2203_r$13(this, [], [_dec$13]));
1439
1389
  }
1440
1390
  constructor(config = {}) {
1441
1391
  this.context = config.context;
@@ -1467,10 +1417,10 @@ _dec$12 = Injectable({ token: Logger });
1467
1417
  this.localInstance?.fatal?.(message, ...optionalParams);
1468
1418
  }
1469
1419
  static {
1470
- _initClass$12();
1420
+ _initClass$13();
1471
1421
  }
1472
1422
  });
1473
- function applyDecs2203RFactory$11() {
1423
+ function applyDecs2203RFactory$12() {
1474
1424
  function createAddInitializerMethod(initializers, decoratorFinishedRef) {
1475
1425
  return function addInitializer(initializer) {
1476
1426
  assertNotFinished(decoratorFinishedRef, "addInitializer");
@@ -1744,10 +1694,10 @@ function applyDecs2203RFactory$11() {
1744
1694
  };
1745
1695
  };
1746
1696
  }
1747
- function _apply_decs_2203_r$11(targetClass, memberDecs, classDecs, parentClass) {
1748
- return (_apply_decs_2203_r$11 = applyDecs2203RFactory$11())(targetClass, memberDecs, classDecs, parentClass);
1697
+ function _apply_decs_2203_r$12(targetClass, memberDecs, classDecs, parentClass) {
1698
+ return (_apply_decs_2203_r$12 = applyDecs2203RFactory$12())(targetClass, memberDecs, classDecs, parentClass);
1749
1699
  }
1750
- var _dec$11, _initClass$11;
1700
+ var _dec$12, _initClass$12;
1751
1701
  /**
1752
1702
  * Schema for validating configuration service options.
1753
1703
  */ const ConfigServiceOptionsSchema = z$1.record(z$1.string(), z$1.unknown());
@@ -1755,11 +1705,11 @@ var _dec$11, _initClass$11;
1755
1705
  * Injection token for ConfigService.
1756
1706
  */ const ConfigServiceToken = InjectionToken.create(Symbol.for("ConfigService"), ConfigServiceOptionsSchema);
1757
1707
  let _ConfigService;
1758
- _dec$11 = Injectable({ token: ConfigServiceToken });
1708
+ _dec$12 = Injectable({ token: ConfigServiceToken });
1759
1709
  (class {
1760
1710
  config;
1761
1711
  static {
1762
- ({c: [_ConfigService, _initClass$11]} = _apply_decs_2203_r$11(this, [], [_dec$11]));
1712
+ ({c: [_ConfigService, _initClass$12]} = _apply_decs_2203_r$12(this, [], [_dec$12]));
1763
1713
  }
1764
1714
  /**
1765
1715
  * Creates a new ConfigService instance.
@@ -1841,7 +1791,7 @@ _dec$11 = Injectable({ token: ConfigServiceToken });
1841
1791
  return value;
1842
1792
  }
1843
1793
  static {
1844
- _initClass$11();
1794
+ _initClass$12();
1845
1795
  }
1846
1796
  });
1847
1797
  /**
@@ -2076,6 +2026,357 @@ _dec$11 = Injectable({ token: ConfigServiceToken });
2076
2026
  super(409, message, error);
2077
2027
  }
2078
2028
  };
2029
+ function applyDecs2203RFactory$11() {
2030
+ function createAddInitializerMethod(initializers, decoratorFinishedRef) {
2031
+ return function addInitializer(initializer) {
2032
+ assertNotFinished(decoratorFinishedRef, "addInitializer");
2033
+ assertCallable(initializer, "An initializer");
2034
+ initializers.push(initializer);
2035
+ };
2036
+ }
2037
+ function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
2038
+ var kindStr;
2039
+ switch (kind) {
2040
+ case 1:
2041
+ kindStr = "accessor";
2042
+ break;
2043
+ case 2:
2044
+ kindStr = "method";
2045
+ break;
2046
+ case 3:
2047
+ kindStr = "getter";
2048
+ break;
2049
+ case 4:
2050
+ kindStr = "setter";
2051
+ break;
2052
+ default: kindStr = "field";
2053
+ }
2054
+ var ctx = {
2055
+ kind: kindStr,
2056
+ name: isPrivate ? "#" + name : name,
2057
+ static: isStatic,
2058
+ private: isPrivate,
2059
+ metadata
2060
+ };
2061
+ var decoratorFinishedRef = { v: false };
2062
+ ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
2063
+ var get, set;
2064
+ if (kind === 0) if (isPrivate) {
2065
+ get = desc.get;
2066
+ set = desc.set;
2067
+ } else {
2068
+ get = function() {
2069
+ return this[name];
2070
+ };
2071
+ set = function(v) {
2072
+ this[name] = v;
2073
+ };
2074
+ }
2075
+ else if (kind === 2) get = function() {
2076
+ return desc.value;
2077
+ };
2078
+ else {
2079
+ if (kind === 1 || kind === 3) get = function() {
2080
+ return desc.get.call(this);
2081
+ };
2082
+ if (kind === 1 || kind === 4) set = function(v) {
2083
+ desc.set.call(this, v);
2084
+ };
2085
+ }
2086
+ ctx.access = get && set ? {
2087
+ get,
2088
+ set
2089
+ } : get ? { get } : { set };
2090
+ try {
2091
+ return dec(value, ctx);
2092
+ } finally {
2093
+ decoratorFinishedRef.v = true;
2094
+ }
2095
+ }
2096
+ function assertNotFinished(decoratorFinishedRef, fnName) {
2097
+ if (decoratorFinishedRef.v) throw new Error("attempted to call " + fnName + " after decoration was finished");
2098
+ }
2099
+ function assertCallable(fn, hint) {
2100
+ if (typeof fn !== "function") throw new TypeError(hint + " must be a function");
2101
+ }
2102
+ function assertValidReturnValue(kind, value) {
2103
+ var type = typeof value;
2104
+ if (kind === 1) {
2105
+ if (type !== "object" || value === null) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
2106
+ if (value.get !== void 0) assertCallable(value.get, "accessor.get");
2107
+ if (value.set !== void 0) assertCallable(value.set, "accessor.set");
2108
+ if (value.init !== void 0) assertCallable(value.init, "accessor.init");
2109
+ } else if (type !== "function") {
2110
+ var hint;
2111
+ if (kind === 0) hint = "field";
2112
+ else if (kind === 10) hint = "class";
2113
+ else hint = "method";
2114
+ throw new TypeError(hint + " decorators must return a function or void 0");
2115
+ }
2116
+ }
2117
+ function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
2118
+ var decs = decInfo[0];
2119
+ var desc, init, value;
2120
+ if (isPrivate) if (kind === 0 || kind === 1) desc = {
2121
+ get: decInfo[3],
2122
+ set: decInfo[4]
2123
+ };
2124
+ else if (kind === 3) desc = { get: decInfo[3] };
2125
+ else if (kind === 4) desc = { set: decInfo[3] };
2126
+ else desc = { value: decInfo[3] };
2127
+ else if (kind !== 0) desc = Object.getOwnPropertyDescriptor(base, name);
2128
+ if (kind === 1) value = {
2129
+ get: desc.get,
2130
+ set: desc.set
2131
+ };
2132
+ else if (kind === 2) value = desc.value;
2133
+ else if (kind === 3) value = desc.get;
2134
+ else if (kind === 4) value = desc.set;
2135
+ var newValue, get, set;
2136
+ if (typeof decs === "function") {
2137
+ newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
2138
+ if (newValue !== void 0) {
2139
+ assertValidReturnValue(kind, newValue);
2140
+ if (kind === 0) init = newValue;
2141
+ else if (kind === 1) {
2142
+ init = newValue.init;
2143
+ get = newValue.get || value.get;
2144
+ set = newValue.set || value.set;
2145
+ value = {
2146
+ get,
2147
+ set
2148
+ };
2149
+ } else value = newValue;
2150
+ }
2151
+ } else for (var i = decs.length - 1; i >= 0; i--) {
2152
+ var dec = decs[i];
2153
+ newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
2154
+ if (newValue !== void 0) {
2155
+ assertValidReturnValue(kind, newValue);
2156
+ var newInit;
2157
+ if (kind === 0) newInit = newValue;
2158
+ else if (kind === 1) {
2159
+ newInit = newValue.init;
2160
+ get = newValue.get || value.get;
2161
+ set = newValue.set || value.set;
2162
+ value = {
2163
+ get,
2164
+ set
2165
+ };
2166
+ } else value = newValue;
2167
+ if (newInit !== void 0) if (init === void 0) init = newInit;
2168
+ else if (typeof init === "function") init = [init, newInit];
2169
+ else init.push(newInit);
2170
+ }
2171
+ }
2172
+ if (kind === 0 || kind === 1) {
2173
+ if (init === void 0) init = function(instance, init$1) {
2174
+ return init$1;
2175
+ };
2176
+ else if (typeof init !== "function") {
2177
+ var ownInitializers = init;
2178
+ init = function(instance, init$1) {
2179
+ var value$1 = init$1;
2180
+ for (var i$1 = 0; i$1 < ownInitializers.length; i$1++) value$1 = ownInitializers[i$1].call(instance, value$1);
2181
+ return value$1;
2182
+ };
2183
+ } else {
2184
+ var originalInitializer = init;
2185
+ init = function(instance, init$1) {
2186
+ return originalInitializer.call(instance, init$1);
2187
+ };
2188
+ }
2189
+ ret.push(init);
2190
+ }
2191
+ if (kind !== 0) {
2192
+ if (kind === 1) {
2193
+ desc.get = value.get;
2194
+ desc.set = value.set;
2195
+ } else if (kind === 2) desc.value = value;
2196
+ else if (kind === 3) desc.get = value;
2197
+ else if (kind === 4) desc.set = value;
2198
+ if (isPrivate) if (kind === 1) {
2199
+ ret.push(function(instance, args) {
2200
+ return value.get.call(instance, args);
2201
+ });
2202
+ ret.push(function(instance, args) {
2203
+ return value.set.call(instance, args);
2204
+ });
2205
+ } else if (kind === 2) ret.push(value);
2206
+ else ret.push(function(instance, args) {
2207
+ return value.call(instance, args);
2208
+ });
2209
+ else Object.defineProperty(base, name, desc);
2210
+ }
2211
+ }
2212
+ function applyMemberDecs(Class, decInfos, metadata) {
2213
+ var ret = [];
2214
+ var protoInitializers;
2215
+ var staticInitializers;
2216
+ var existingProtoNonFields = /* @__PURE__ */ new Map();
2217
+ var existingStaticNonFields = /* @__PURE__ */ new Map();
2218
+ for (var i = 0; i < decInfos.length; i++) {
2219
+ var decInfo = decInfos[i];
2220
+ if (!Array.isArray(decInfo)) continue;
2221
+ var kind = decInfo[1];
2222
+ var name = decInfo[2];
2223
+ var isPrivate = decInfo.length > 3;
2224
+ var isStatic = kind >= 5;
2225
+ var base;
2226
+ var initializers;
2227
+ if (isStatic) {
2228
+ base = Class;
2229
+ kind = kind - 5;
2230
+ staticInitializers = staticInitializers || [];
2231
+ initializers = staticInitializers;
2232
+ } else {
2233
+ base = Class.prototype;
2234
+ protoInitializers = protoInitializers || [];
2235
+ initializers = protoInitializers;
2236
+ }
2237
+ if (kind !== 0 && !isPrivate) {
2238
+ var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
2239
+ var existingKind = existingNonFields.get(name) || 0;
2240
+ 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);
2241
+ else if (!existingKind && kind > 2) existingNonFields.set(name, kind);
2242
+ else existingNonFields.set(name, true);
2243
+ }
2244
+ applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
2245
+ }
2246
+ pushInitializers(ret, protoInitializers);
2247
+ pushInitializers(ret, staticInitializers);
2248
+ return ret;
2249
+ }
2250
+ function pushInitializers(ret, initializers) {
2251
+ if (initializers) ret.push(function(instance) {
2252
+ for (var i = 0; i < initializers.length; i++) initializers[i].call(instance);
2253
+ return instance;
2254
+ });
2255
+ }
2256
+ function applyClassDecs(targetClass, classDecs, metadata) {
2257
+ if (classDecs.length > 0) {
2258
+ var initializers = [];
2259
+ var newClass = targetClass;
2260
+ var name = targetClass.name;
2261
+ for (var i = classDecs.length - 1; i >= 0; i--) {
2262
+ var decoratorFinishedRef = { v: false };
2263
+ try {
2264
+ var nextNewClass = classDecs[i](newClass, {
2265
+ kind: "class",
2266
+ name,
2267
+ addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
2268
+ metadata
2269
+ });
2270
+ } finally {
2271
+ decoratorFinishedRef.v = true;
2272
+ }
2273
+ if (nextNewClass !== void 0) {
2274
+ assertValidReturnValue(10, nextNewClass);
2275
+ newClass = nextNewClass;
2276
+ }
2277
+ }
2278
+ return [defineMetadata(newClass, metadata), function() {
2279
+ for (var i$1 = 0; i$1 < initializers.length; i$1++) initializers[i$1].call(newClass);
2280
+ }];
2281
+ }
2282
+ }
2283
+ function defineMetadata(Class, metadata) {
2284
+ return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
2285
+ configurable: true,
2286
+ enumerable: true,
2287
+ value: metadata
2288
+ });
2289
+ }
2290
+ return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
2291
+ if (parentClass !== void 0) var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
2292
+ var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
2293
+ var e = applyMemberDecs(targetClass, memberDecs, metadata);
2294
+ if (!classDecs.length) defineMetadata(targetClass, metadata);
2295
+ return {
2296
+ e,
2297
+ get c() {
2298
+ return applyClassDecs(targetClass, classDecs, metadata);
2299
+ }
2300
+ };
2301
+ };
2302
+ }
2303
+ function _apply_decs_2203_r$11(targetClass, memberDecs, classDecs, parentClass) {
2304
+ return (_apply_decs_2203_r$11 = applyDecs2203RFactory$11())(targetClass, memberDecs, classDecs, parentClass);
2305
+ }
2306
+ var _dec$11, _initClass$11;
2307
+ let _InstanceResolverService;
2308
+ _dec$11 = Injectable();
2309
+ (class {
2310
+ static {
2311
+ ({c: [_InstanceResolverService, _initClass$11]} = _apply_decs_2203_r$11(this, [], [_dec$11]));
2312
+ }
2313
+ container = inject(Container);
2314
+ /**
2315
+ * Attempts to resolve a class instance, automatically detecting if it needs
2316
+ * request scope based on its dependencies.
2317
+ *
2318
+ * @param classType - The class to resolve
2319
+ * @returns A resolution result containing either a cached instance or resolver function
2320
+ */ async resolve(classType) {
2321
+ let cachedInstance = null;
2322
+ try {
2323
+ cachedInstance = await this.container.get(classType);
2324
+ } catch {
2325
+ const token = getInjectableToken(classType);
2326
+ this.container.getRegistry().updateScope(token, InjectableScope.Request);
2327
+ }
2328
+ return {
2329
+ cached: cachedInstance !== null,
2330
+ instance: cachedInstance,
2331
+ resolve: (scoped) => scoped.get(classType)
2332
+ };
2333
+ }
2334
+ /**
2335
+ * Attempts to resolve multiple class instances, automatically detecting if any need
2336
+ * request scope based on their dependencies.
2337
+ *
2338
+ * Returns `cached: true` only if ALL classes can be resolved as singletons.
2339
+ * If any class has request-scoped dependencies, returns `cached: false`.
2340
+ *
2341
+ * @param classTypes - The classes to resolve
2342
+ * @returns A resolution result containing either all cached instances or resolver function
2343
+ */ async resolveMany(classTypes) {
2344
+ if (classTypes.length === 0) return {
2345
+ cached: true,
2346
+ instances: [],
2347
+ classTypes: [],
2348
+ resolve: async () => []
2349
+ };
2350
+ const results = await Promise.all(classTypes.map(async (classType) => {
2351
+ try {
2352
+ return {
2353
+ success: true,
2354
+ instance: await this.container.get(classType)
2355
+ };
2356
+ } catch {
2357
+ const token = getInjectableToken(classType);
2358
+ this.container.getRegistry().updateScope(token, InjectableScope.Request);
2359
+ return {
2360
+ success: false,
2361
+ instance: null
2362
+ };
2363
+ }
2364
+ }));
2365
+ const allCached = results.every((r) => r.success);
2366
+ return {
2367
+ cached: allCached,
2368
+ instances: allCached ? results.map((r) => r.instance) : null,
2369
+ classTypes,
2370
+ resolve: (scoped) => Promise.all(classTypes.map((classType) => scoped.get(classType)))
2371
+ };
2372
+ }
2373
+ static {
2374
+ _initClass$11();
2375
+ }
2376
+ });
2377
+ /**
2378
+ * @deprecated Use InstanceResolverService instead
2379
+ */ const ControllerResolverService = _InstanceResolverService;
2079
2380
  function applyDecs2203RFactory$10() {
2080
2381
  function createAddInitializerMethod(initializers, decoratorFinishedRef) {
2081
2382
  return function addInitializer(initializer) {
@@ -2361,23 +2662,40 @@ _dec$10 = Injectable();
2361
2662
  ({c: [_GuardRunnerService, _initClass$10]} = _apply_decs_2203_r$10(this, [], [_dec$10]));
2362
2663
  }
2363
2664
  logger = inject(Logger, { context: _GuardRunnerService.name });
2364
- async runGuards(allGuards, executionContext, context) {
2365
- let canActivate = true;
2366
- for (const guard of Array.from(allGuards).reverse()) {
2665
+ /**
2666
+ * Runs guards that need to be resolved from a scoped container.
2667
+ * Use this when guards have request-scoped dependencies.
2668
+ */ async runGuards(allGuards, executionContext, context) {
2669
+ const guardsArray = Array.from(allGuards).reverse();
2670
+ const guardInstances = await Promise.all(guardsArray.map(async (guard) => {
2367
2671
  const guardInstance = await context.get(guard);
2368
2672
  if (!guardInstance.canActivate) throw new Error(`[Navios] Guard ${guard.name} does not implement canActivate()`);
2369
- try {
2370
- canActivate = await guardInstance.canActivate(executionContext);
2371
- if (!canActivate) break;
2372
- } catch (error) {
2373
- if (error instanceof HttpException) {
2374
- executionContext.getReply().status(error.statusCode).send(error.response);
2375
- return false;
2376
- } else {
2377
- this.logger.error("Error running guard", error);
2378
- executionContext.getReply().status(500).send({ message: "Internal server error" });
2379
- return false;
2380
- }
2673
+ return guardInstance;
2674
+ }));
2675
+ return this.executeGuards(guardInstances, executionContext);
2676
+ }
2677
+ /**
2678
+ * Runs pre-resolved guard instances.
2679
+ * Use this when all guards are singletons and have been pre-resolved at startup.
2680
+ */ async runGuardsStatic(guardInstances, executionContext) {
2681
+ return this.executeGuards(guardInstances, executionContext);
2682
+ }
2683
+ /**
2684
+ * Shared guard execution logic.
2685
+ * Iterates through guard instances and calls canActivate on each.
2686
+ */ async executeGuards(guardInstances, executionContext) {
2687
+ let canActivate = true;
2688
+ for (const guardInstance of guardInstances) try {
2689
+ canActivate = await guardInstance.canActivate(executionContext);
2690
+ if (!canActivate) break;
2691
+ } catch (error) {
2692
+ if (error instanceof HttpException) {
2693
+ executionContext.getReply().status(error.statusCode).send(error.response);
2694
+ return false;
2695
+ } else {
2696
+ this.logger.error("Error running guard", error);
2697
+ executionContext.getReply().status(500).send({ message: "Internal server error" });
2698
+ return false;
2381
2699
  }
2382
2700
  }
2383
2701
  if (!canActivate) {
@@ -2694,10 +3012,53 @@ _dec$9 = Injectable();
2694
3012
  await this.traverseModules(appModule);
2695
3013
  this.initialized = true;
2696
3014
  }
3015
+ /**
3016
+ * Extends the module tree with additional modules or controllers.
3017
+ *
3018
+ * This method is designed to be called by plugins during registration,
3019
+ * which happens after initial module loading but before route registration.
3020
+ *
3021
+ * @param extensions - Array of module extensions to add
3022
+ * @throws Error if not initialized (loadModules must be called first)
3023
+ *
3024
+ * @example
3025
+ * ```typescript
3026
+ * // In plugin registration
3027
+ * const moduleLoader = await context.container.get(ModuleLoaderService)
3028
+ * await moduleLoader.extendModules([{
3029
+ * controllers: [OpenApiJsonController, OpenApiYamlController],
3030
+ * moduleName: 'OpenApiBunModule',
3031
+ * }])
3032
+ * ```
3033
+ */ async extendModules(extensions) {
3034
+ if (!this.initialized) throw new Error("ModuleLoaderService must be initialized before extending. Call loadModules() first.");
3035
+ for (const extension of extensions) if (extension.module) await this.traverseModules(extension.module);
3036
+ else if (extension.controllers && extension.moduleName) await this.registerControllers(extension.controllers, extension.moduleName);
3037
+ else if (extension.controllers) throw new Error("moduleName is required when providing controllers without a module");
3038
+ }
3039
+ /**
3040
+ * Registers controllers under a synthetic module.
3041
+ * Used when plugins want to add controllers without a full module class.
3042
+ */ async registerControllers(controllers, moduleName) {
3043
+ if (this.modulesMetadata.has(moduleName)) {
3044
+ const existing = this.modulesMetadata.get(moduleName);
3045
+ for (const controller of controllers) existing.controllers.add(controller);
3046
+ this.logger.debug(`Extended module ${moduleName} with ${controllers.length} controllers`);
3047
+ } else {
3048
+ const metadata = {
3049
+ controllers: new Set(controllers),
3050
+ imports: /* @__PURE__ */ new Set(),
3051
+ guards: /* @__PURE__ */ new Set(),
3052
+ customAttributes: /* @__PURE__ */ new Map()
3053
+ };
3054
+ this.modulesMetadata.set(moduleName, metadata);
3055
+ this.logger.debug(`Created module ${moduleName} with ${controllers.length} controllers`);
3056
+ }
3057
+ }
2697
3058
  async traverseModules(module, parentMetadata) {
2698
3059
  const metadata = extractModuleMetadata(module);
2699
3060
  if (parentMetadata) this.mergeMetadata(metadata, parentMetadata);
2700
- const moduleName = module.name;
3061
+ const moduleName = getInjectableToken(module).id;
2701
3062
  if (this.modulesMetadata.has(moduleName)) return;
2702
3063
  try {
2703
3064
  this.modulesMetadata.set(moduleName, metadata);
@@ -3094,7 +3455,7 @@ _dec$8 = Injectable();
3094
3455
  }
3095
3456
  httpTokens = /* @__PURE__ */ new Map();
3096
3457
  setupHttpEnvironment(tokens) {
3097
- this.httpTokens = tokens;
3458
+ for (const [token, value] of tokens) this.httpTokens.set(token, value);
3098
3459
  }
3099
3460
  getHttpToken(token) {
3100
3461
  return this.httpTokens.get(token);
@@ -5170,7 +5531,7 @@ _dec$1$1 = Factory({ token: XmlStreamAdapterToken });
5170
5531
  _initClass$1$1();
5171
5532
  }
5172
5533
  });
5173
- function applyDecs2203RFactory$14() {
5534
+ function applyDecs2203RFactory$15() {
5174
5535
  function createAddInitializerMethod(initializers, decoratorFinishedRef) {
5175
5536
  return function addInitializer(initializer) {
5176
5537
  assertNotFinished(decoratorFinishedRef, "addInitializer");
@@ -5444,15 +5805,15 @@ function applyDecs2203RFactory$14() {
5444
5805
  };
5445
5806
  };
5446
5807
  }
5447
- function _apply_decs_2203_r$14(targetClass, memberDecs, classDecs, parentClass) {
5448
- return (_apply_decs_2203_r$14 = applyDecs2203RFactory$14())(targetClass, memberDecs, classDecs, parentClass);
5808
+ function _apply_decs_2203_r$15(targetClass, memberDecs, classDecs, parentClass) {
5809
+ return (_apply_decs_2203_r$15 = applyDecs2203RFactory$15())(targetClass, memberDecs, classDecs, parentClass);
5449
5810
  }
5450
- var _dec$14, _initClass$14;
5811
+ var _dec$15, _initClass$15;
5451
5812
  let _NaviosApplication;
5452
- _dec$14 = Injectable();
5813
+ _dec$15 = Injectable();
5453
5814
  (class {
5454
5815
  static {
5455
- ({c: [_NaviosApplication, _initClass$14]} = _apply_decs_2203_r$14(this, [], [_dec$14]));
5816
+ ({c: [_NaviosApplication, _initClass$15]} = _apply_decs_2203_r$15(this, [], [_dec$15]));
5456
5817
  }
5457
5818
  environment = inject(_NaviosEnvironment);
5458
5819
  moduleLoader = inject(_ModuleLoaderService);
@@ -5469,7 +5830,7 @@ _dec$14 = Injectable();
5469
5830
  /**
5470
5831
  * Sets up the application with the provided module and options.
5471
5832
  * This is called automatically by NaviosFactory.create().
5472
- *
5833
+ *
5473
5834
  * @param appModule - The root application module
5474
5835
  * @param options - Application configuration options
5475
5836
  * @internal
@@ -5480,7 +5841,7 @@ _dec$14 = Injectable();
5480
5841
  }
5481
5842
  /**
5482
5843
  * Gets the dependency injection container used by this application.
5483
- *
5844
+ *
5484
5845
  * @returns The Container instance
5485
5846
  */ getContainer() {
5486
5847
  return this.container;
@@ -5532,8 +5893,8 @@ _dec$14 = Injectable();
5532
5893
  if (!this.appModule) throw new Error("App module is not set. Call setAppModule() first.");
5533
5894
  await this.moduleLoader.loadModules(this.appModule);
5534
5895
  if (this.environment.hasHttpSetup()) await this.httpApplication?.setupHttpServer(this.options);
5535
- await this.initModules();
5536
5896
  await this.initPlugins();
5897
+ await this.initModules();
5537
5898
  if (this.environment.hasHttpSetup()) await this.httpApplication?.ready();
5538
5899
  this.isInitialized = true;
5539
5900
  this.logger.debug("Navios application initialized");
@@ -5544,11 +5905,16 @@ _dec$14 = Injectable();
5544
5905
  }
5545
5906
  async initPlugins() {
5546
5907
  if (this.plugins.length === 0) return;
5908
+ let server = null;
5909
+ try {
5910
+ server = this.httpApplication?.getServer() ?? null;
5911
+ } catch {}
5547
5912
  const context = {
5548
5913
  modules: this.moduleLoader.getAllModules(),
5549
- server: this.httpApplication?.getServer() ?? null,
5914
+ server,
5550
5915
  container: this.container,
5551
- globalPrefix: this.httpApplication?.getGlobalPrefix() ?? ""
5916
+ globalPrefix: this.httpApplication?.getGlobalPrefix() ?? "",
5917
+ moduleLoader: this.moduleLoader
5552
5918
  };
5553
5919
  for (const { plugin, options } of this.plugins) {
5554
5920
  this.logger.debug(`Initializing plugin: ${plugin.name}`);
@@ -5557,10 +5923,10 @@ _dec$14 = Injectable();
5557
5923
  }
5558
5924
  /**
5559
5925
  * Enables CORS (Cross-Origin Resource Sharing) for the application.
5560
- *
5926
+ *
5561
5927
  * @param options - CORS configuration options (adapter-specific)
5562
5928
  * @throws Error if HTTP application is not set
5563
- *
5929
+ *
5564
5930
  * @example
5565
5931
  * ```typescript
5566
5932
  * app.enableCors({
@@ -5575,10 +5941,10 @@ _dec$14 = Injectable();
5575
5941
  }
5576
5942
  /**
5577
5943
  * Enables multipart/form-data support for file uploads.
5578
- *
5944
+ *
5579
5945
  * @param options - Multipart configuration options (adapter-specific)
5580
5946
  * @throws Error if HTTP application is not set
5581
- *
5947
+ *
5582
5948
  * @example
5583
5949
  * ```typescript
5584
5950
  * app.enableMultipart({
@@ -5593,10 +5959,10 @@ _dec$14 = Injectable();
5593
5959
  }
5594
5960
  /**
5595
5961
  * Sets a global prefix for all routes.
5596
- *
5962
+ *
5597
5963
  * @param prefix - The prefix to prepend to all route URLs (e.g., '/api')
5598
5964
  * @throws Error if HTTP application is not set
5599
- *
5965
+ *
5600
5966
  * @example
5601
5967
  * ```typescript
5602
5968
  * app.setGlobalPrefix('/api/v1')
@@ -5608,14 +5974,14 @@ _dec$14 = Injectable();
5608
5974
  }
5609
5975
  /**
5610
5976
  * Gets the underlying HTTP server instance.
5611
- *
5977
+ *
5612
5978
  * The type of the returned server depends on the adapter used:
5613
5979
  * - Fastify adapter: Returns FastifyInstance
5614
5980
  * - Bun adapter: Returns Bun.Server
5615
- *
5981
+ *
5616
5982
  * @returns The HTTP server instance
5617
5983
  * @throws Error if HTTP application is not set
5618
- *
5984
+ *
5619
5985
  * @example
5620
5986
  * ```typescript
5621
5987
  * const server = app.getServer()
@@ -5627,10 +5993,10 @@ _dec$14 = Injectable();
5627
5993
  }
5628
5994
  /**
5629
5995
  * Starts the HTTP server and begins listening for requests.
5630
- *
5996
+ *
5631
5997
  * @param options - Listen options (port, host, etc.)
5632
5998
  * @throws Error if HTTP application is not set
5633
- *
5999
+ *
5634
6000
  * @example
5635
6001
  * ```typescript
5636
6002
  * await app.listen({ port: 3000, host: '0.0.0.0' })
@@ -5641,7 +6007,7 @@ _dec$14 = Injectable();
5641
6007
  }
5642
6008
  /**
5643
6009
  * Disposes of application resources.
5644
- *
6010
+ *
5645
6011
  * Cleans up the HTTP server and module loader.
5646
6012
  * This method is called automatically by `close()`.
5647
6013
  */ async dispose() {
@@ -5650,9 +6016,9 @@ _dec$14 = Injectable();
5650
6016
  }
5651
6017
  /**
5652
6018
  * Closes the application and cleans up all resources.
5653
- *
6019
+ *
5654
6020
  * This is an alias for `dispose()`.
5655
- *
6021
+ *
5656
6022
  * @example
5657
6023
  * ```typescript
5658
6024
  * // Graceful shutdown
@@ -5665,36 +6031,36 @@ _dec$14 = Injectable();
5665
6031
  await this.dispose();
5666
6032
  }
5667
6033
  static {
5668
- _initClass$14();
6034
+ _initClass$15();
5669
6035
  }
5670
6036
  });
5671
6037
  /**
5672
6038
  * Factory class for creating and configuring Navios applications.
5673
- *
6039
+ *
5674
6040
  * This is the main entry point for bootstrapping a Navios application.
5675
6041
  * It handles dependency injection container setup, adapter registration,
5676
6042
  * and logger configuration.
5677
- *
6043
+ *
5678
6044
  * @example
5679
6045
  * ```typescript
5680
6046
  * import { NaviosFactory } from '@navios/core'
5681
6047
  * import { defineFastifyEnvironment } from '@navios/adapter-fastify'
5682
- *
6048
+ *
5683
6049
  * const app = await NaviosFactory.create(AppModule, {
5684
6050
  * adapter: defineFastifyEnvironment(),
5685
6051
  * logger: ['log', 'error', 'warn'],
5686
6052
  * })
5687
- *
6053
+ *
5688
6054
  * await app.init()
5689
6055
  * await app.listen({ port: 3000 })
5690
6056
  * ```
5691
6057
  */ var NaviosFactory = class {
5692
6058
  /**
5693
6059
  * Creates a new Navios application instance.
5694
- *
6060
+ *
5695
6061
  * This method sets up the dependency injection container, registers the HTTP adapter,
5696
6062
  * configures logging, and initializes the application with the provided module.
5697
- *
6063
+ *
5698
6064
  * @param appModule - The root application module class decorated with @Module()
5699
6065
  * @param options - Configuration options for the application
5700
6066
  * @param options.adapter - HTTP adapter environment (required for HTTP server functionality)
@@ -5704,20 +6070,20 @@ _dec$14 = Injectable();
5704
6070
  * - `false` to disable logging
5705
6071
  * @param options.container - Optional custom dependency injection container (useful for testing)
5706
6072
  * @returns A configured NaviosApplication instance ready to be initialized
5707
- *
6073
+ *
5708
6074
  * @example
5709
6075
  * ```typescript
5710
6076
  * // Basic setup with Fastify adapter
5711
6077
  * const app = await NaviosFactory.create(AppModule, {
5712
6078
  * adapter: defineFastifyEnvironment(),
5713
6079
  * })
5714
- *
6080
+ *
5715
6081
  * // With custom logger configuration
5716
6082
  * const app = await NaviosFactory.create(AppModule, {
5717
6083
  * adapter: defineFastifyEnvironment(),
5718
6084
  * logger: ['error', 'warn', 'log'],
5719
6085
  * })
5720
- *
6086
+ *
5721
6087
  * // With custom container for testing
5722
6088
  * const container = new Container()
5723
6089
  * const app = await NaviosFactory.create(AppModule, {
@@ -5726,7 +6092,9 @@ _dec$14 = Injectable();
5726
6092
  * })
5727
6093
  * ```
5728
6094
  */ static async create(appModule, options = { adapter: [] }) {
5729
- const container = options.container ?? new Container();
6095
+ const container = options.container ?? new Container(options.registry);
6096
+ if (options.enableRequestId === true) setRequestIdEnabled(true);
6097
+ container.addInstance(NaviosOptionsToken, options);
5730
6098
  await this.registerLoggerConfiguration(container, options);
5731
6099
  const adapters = Array.isArray(options.adapter) ? options.adapter : [options.adapter];
5732
6100
  for (const adapter of adapters) await this.registerEnvironment(container, adapter);
@@ -5741,8 +6109,14 @@ _dec$14 = Injectable();
5741
6109
  }
5742
6110
  static async registerLoggerConfiguration(container, options) {
5743
6111
  const { logger } = options;
5744
- if (Array.isArray(logger) || isNil(logger)) (await container.get(LoggerOutput))?.setup({ logLevels: logger });
5745
- if (logger !== true && !isNil(logger)) container.getServiceLocator().getManager().storeCreatedHolder(LoggerOutput.toString(), logger, InjectableType.Class, InjectableScope.Singleton);
6112
+ if (Array.isArray(logger) || isNil(logger) || options.enableRequestId) {
6113
+ (await container.get(LoggerOutput))?.setup({
6114
+ logLevels: Array.isArray(logger) ? logger : void 0,
6115
+ requestId: options.enableRequestId ?? false
6116
+ });
6117
+ return;
6118
+ }
6119
+ if (logger !== true && !isNil(logger)) container.addInstance(LoggerOutput, logger);
5746
6120
  }
5747
6121
  };
5748
6122
 
@@ -5759,6 +6133,7 @@ var lib_exports = /* @__PURE__ */ __export({
5759
6133
  ConsoleLogger: () => _ConsoleLogger,
5760
6134
  Controller: () => Controller,
5761
6135
  ControllerMetadataKey: () => ControllerMetadataKey,
6136
+ ControllerResolverService: () => ControllerResolverService,
5762
6137
  Endpoint: () => Endpoint,
5763
6138
  EndpointAdapterFactory: () => _EndpointAdapterFactory,
5764
6139
  EndpointAdapterToken: () => EndpointAdapterToken,
@@ -5773,6 +6148,7 @@ var lib_exports = /* @__PURE__ */ __export({
5773
6148
  HttpAdapterToken: () => HttpAdapterToken,
5774
6149
  HttpCode: () => HttpCode,
5775
6150
  HttpException: () => HttpException,
6151
+ InstanceResolverService: () => _InstanceResolverService,
5776
6152
  InternalServerErrorException: () => InternalServerErrorException,
5777
6153
  LOG_LEVELS: () => LOG_LEVELS,
5778
6154
  Logger: () => Logger,
@@ -5786,6 +6162,7 @@ var lib_exports = /* @__PURE__ */ __export({
5786
6162
  MultipartAdapterToken: () => MultipartAdapterToken,
5787
6163
  NaviosApplication: () => _NaviosApplication,
5788
6164
  NaviosFactory: () => NaviosFactory,
6165
+ NaviosOptionsToken: () => NaviosOptionsToken,
5789
6166
  NotFoundException: () => NotFoundException,
5790
6167
  Reply: () => Reply,
5791
6168
  ReplyFactory: () => _ReplyFactory,
@@ -5805,6 +6182,7 @@ var lib_exports = /* @__PURE__ */ __export({
5805
6182
  extractControllerMetadata: () => extractControllerMetadata,
5806
6183
  extractModuleMetadata: () => extractModuleMetadata,
5807
6184
  filterLogLevels: () => filterLogLevels,
6185
+ generateRequestId: () => generateRequestId,
5808
6186
  getAllEndpointMetadata: () => getAllEndpointMetadata,
5809
6187
  getControllerMetadata: () => getControllerMetadata,
5810
6188
  getEndpointMetadata: () => getEndpointMetadata,
@@ -5827,8 +6205,8 @@ var lib_exports = /* @__PURE__ */ __export({
5827
6205
  loggerOptionsSchema: () => loggerOptionsSchema,
5828
6206
  normalizePath: () => normalizePath,
5829
6207
  provideConfig: () => provideConfig,
5830
- requestIdStore: () => requestIdStore,
5831
6208
  runWithRequestId: () => runWithRequestId,
6209
+ setRequestIdEnabled: () => setRequestIdEnabled,
5832
6210
  stripEndSlash: () => stripEndSlash,
5833
6211
  yellow: () => yellow
5834
6212
  });
@@ -6314,7 +6692,7 @@ var CliModuleLoaderService = class {
6314
6692
  async traverseModules(module, parentMetadata) {
6315
6693
  const metadata = extractCliModuleMetadata(module);
6316
6694
  if (parentMetadata) this.mergeMetadata(metadata, parentMetadata);
6317
- const moduleName = module.name;
6695
+ const moduleName = (0, lib_exports.getInjectableToken)(module).id;
6318
6696
  if (this.modulesMetadata.has(moduleName)) return;
6319
6697
  this.modulesMetadata.set(moduleName, metadata);
6320
6698
  for (const command of metadata.commands) {
@@ -7403,14 +7781,16 @@ var CommanderApplication = class {
7403
7781
  * }
7404
7782
  * }
7405
7783
  * ```
7406
- */ function Command({ path, optionsSchema }) {
7784
+ */ function Command({ path, optionsSchema, priority, registry }) {
7407
7785
  return function(target, context) {
7408
7786
  if (context.kind !== "class") throw new Error("[Navios Commander] @Command decorator can only be used on classes.");
7409
7787
  const token = lib_exports.InjectionToken.create(target);
7410
7788
  if (context.metadata) getCommandMetadata(target, context, path, optionsSchema);
7411
7789
  return (0, lib_exports.Injectable)({
7412
7790
  token,
7413
- scope: lib_exports.InjectableScope.Singleton
7791
+ scope: lib_exports.InjectableScope.Singleton,
7792
+ priority,
7793
+ registry
7414
7794
  })(target, context);
7415
7795
  };
7416
7796
  }
@@ -7438,7 +7818,7 @@ var CommanderApplication = class {
7438
7818
  * })
7439
7819
  * export class AppModule {}
7440
7820
  * ```
7441
- */ function CliModule({ commands = [], imports = [] } = {
7821
+ */ function CliModule({ commands = [], imports = [], priority, registry } = {
7442
7822
  commands: [],
7443
7823
  imports: []
7444
7824
  }) {
@@ -7450,7 +7830,9 @@ var CommanderApplication = class {
7450
7830
  for (const importedModule of imports) moduleMetadata.imports.add(importedModule);
7451
7831
  return (0, lib_exports.Injectable)({
7452
7832
  token,
7453
- scope: lib_exports.InjectableScope.Singleton
7833
+ scope: lib_exports.InjectableScope.Singleton,
7834
+ priority,
7835
+ registry
7454
7836
  })(target, context);
7455
7837
  };
7456
7838
  }
@@ -7478,6 +7860,7 @@ var src_exports = /* @__PURE__ */ __export({
7478
7860
  ConsoleLogger: () => _ConsoleLogger,
7479
7861
  Controller: () => Controller,
7480
7862
  ControllerMetadataKey: () => ControllerMetadataKey,
7863
+ ControllerResolverService: () => ControllerResolverService,
7481
7864
  Endpoint: () => Endpoint,
7482
7865
  EndpointAdapterFactory: () => _EndpointAdapterFactory,
7483
7866
  EndpointAdapterToken: () => EndpointAdapterToken,
@@ -7492,6 +7875,7 @@ var src_exports = /* @__PURE__ */ __export({
7492
7875
  HttpAdapterToken: () => HttpAdapterToken,
7493
7876
  HttpCode: () => HttpCode,
7494
7877
  HttpException: () => HttpException,
7878
+ InstanceResolverService: () => _InstanceResolverService,
7495
7879
  InternalServerErrorException: () => InternalServerErrorException,
7496
7880
  LOG_LEVELS: () => LOG_LEVELS,
7497
7881
  Logger: () => Logger,
@@ -7505,6 +7889,7 @@ var src_exports = /* @__PURE__ */ __export({
7505
7889
  MultipartAdapterToken: () => MultipartAdapterToken,
7506
7890
  NaviosApplication: () => _NaviosApplication,
7507
7891
  NaviosFactory: () => NaviosFactory,
7892
+ NaviosOptionsToken: () => NaviosOptionsToken,
7508
7893
  NotFoundException: () => NotFoundException,
7509
7894
  Reply: () => Reply,
7510
7895
  ReplyFactory: () => _ReplyFactory,
@@ -7526,6 +7911,7 @@ var src_exports = /* @__PURE__ */ __export({
7526
7911
  extractControllerMetadata: () => extractControllerMetadata,
7527
7912
  extractModuleMetadata: () => extractModuleMetadata,
7528
7913
  filterLogLevels: () => filterLogLevels,
7914
+ generateRequestId: () => generateRequestId,
7529
7915
  getAllEndpointMetadata: () => getAllEndpointMetadata,
7530
7916
  getCliModuleMetadata: () => getCliModuleMetadata,
7531
7917
  getCommandMetadata: () => getCommandMetadata,
@@ -7552,13 +7938,13 @@ var src_exports = /* @__PURE__ */ __export({
7552
7938
  loggerOptionsSchema: () => loggerOptionsSchema,
7553
7939
  normalizePath: () => normalizePath,
7554
7940
  provideConfig: () => provideConfig,
7555
- requestIdStore: () => requestIdStore,
7556
7941
  runWithRequestId: () => runWithRequestId,
7942
+ setRequestIdEnabled: () => setRequestIdEnabled,
7557
7943
  stripEndSlash: () => stripEndSlash,
7558
7944
  yellow: () => yellow
7559
7945
  });
7560
7946
  __reExport(src_exports, lib_exports);
7561
7947
 
7562
7948
  //#endregion
7563
- export { AttributeFactory, BadRequestException, CliModule, _CliModuleLoaderService as CliModuleLoaderService, CliModuleMetadataKey, _CliParserService as CliParserService, Command, CommandExecutionContext, CommandMetadataKey, _CommanderApplication as CommanderApplication, CommanderExecutionContext, CommanderFactory, ConfigProviderOptions, _ConfigService as ConfigService, ConfigServiceOptionsSchema, ConfigServiceToken, ConflictException, _ConsoleLogger as ConsoleLogger, Controller, ControllerMetadataKey, Endpoint, _EndpointAdapterFactory as EndpointAdapterFactory, EndpointAdapterToken, EndpointMetadataKey, EnvConfigProvider, ExecutionContext, ExecutionContextInjectionToken, ForbiddenException, _GuardRunnerService as GuardRunnerService, Header, _HttpAdapterFactory as HttpAdapterFactory, HttpAdapterToken, HttpCode, HttpException, InternalServerErrorException, LOG_LEVELS, Logger, _LoggerInstance as LoggerInstance, LoggerOutput, Module, _ModuleLoaderService as ModuleLoaderService, ModuleMetadataKey, Multipart, _MultipartAdapterFactory as MultipartAdapterFactory, MultipartAdapterToken, _NaviosApplication as NaviosApplication, NaviosFactory, NotFoundException, Reply, _ReplyFactory as ReplyFactory, Request, _RequestFactory as RequestFactory, Stream, _StreamAdapterFactory as StreamAdapterFactory, StreamAdapterToken, UnauthorizedException, UseGuards, _XmlStreamAdapterFactory as XmlStreamAdapterFactory, XmlStreamAdapterToken, addLeadingSlash, clc, envInt, envString, extractCliModuleMetadata, extractCommandMetadata, extractControllerMetadata, extractModuleMetadata, filterLogLevels, getAllEndpointMetadata, getCliModuleMetadata, getCommandMetadata, getControllerMetadata, getEndpointMetadata, getModuleMetadata, getRequestId, hasCliModuleMetadata, hasCommandMetadata, hasControllerMetadata, hasModuleMetadata, isConstructor, isEmpty, isFunction, isLogLevel, isLogLevelEnabled, isNil, isNumber, isObject, isPlainObject, isString, isSymbol, isUndefined, loggerOptionsSchema, normalizePath, provideConfig, requestIdStore, runWithRequestId, stripEndSlash, yellow };
7949
+ export { AttributeFactory, BadRequestException, CliModule, _CliModuleLoaderService as CliModuleLoaderService, CliModuleMetadataKey, _CliParserService as CliParserService, Command, CommandExecutionContext, CommandMetadataKey, _CommanderApplication as CommanderApplication, CommanderExecutionContext, CommanderFactory, ConfigProviderOptions, _ConfigService as ConfigService, ConfigServiceOptionsSchema, ConfigServiceToken, ConflictException, _ConsoleLogger as ConsoleLogger, Controller, ControllerMetadataKey, ControllerResolverService, Endpoint, _EndpointAdapterFactory as EndpointAdapterFactory, EndpointAdapterToken, EndpointMetadataKey, EnvConfigProvider, ExecutionContext, ExecutionContextInjectionToken, ForbiddenException, _GuardRunnerService as GuardRunnerService, Header, _HttpAdapterFactory as HttpAdapterFactory, HttpAdapterToken, HttpCode, HttpException, _InstanceResolverService as InstanceResolverService, InternalServerErrorException, LOG_LEVELS, Logger, _LoggerInstance as LoggerInstance, LoggerOutput, Module, _ModuleLoaderService as ModuleLoaderService, ModuleMetadataKey, Multipart, _MultipartAdapterFactory as MultipartAdapterFactory, MultipartAdapterToken, _NaviosApplication as NaviosApplication, NaviosFactory, NaviosOptionsToken, NotFoundException, Reply, _ReplyFactory as ReplyFactory, Request, _RequestFactory as RequestFactory, Stream, _StreamAdapterFactory as StreamAdapterFactory, StreamAdapterToken, UnauthorizedException, UseGuards, _XmlStreamAdapterFactory as XmlStreamAdapterFactory, XmlStreamAdapterToken, addLeadingSlash, clc, envInt, envString, extractCliModuleMetadata, extractCommandMetadata, extractControllerMetadata, extractModuleMetadata, filterLogLevels, generateRequestId, getAllEndpointMetadata, getCliModuleMetadata, getCommandMetadata, getControllerMetadata, getEndpointMetadata, getModuleMetadata, getRequestId, hasCliModuleMetadata, hasCommandMetadata, hasControllerMetadata, hasModuleMetadata, isConstructor, isEmpty, isFunction, isLogLevel, isLogLevelEnabled, isNil, isNumber, isObject, isPlainObject, isString, isSymbol, isUndefined, loggerOptionsSchema, normalizePath, provideConfig, runWithRequestId, setRequestIdEnabled, stripEndSlash, yellow };
7564
7950
  //# sourceMappingURL=index.mjs.map