@navios/commander 0.7.0 → 0.8.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, InjectableType, 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";
@@ -38,16 +38,10 @@ var __copyProps = (to, from, except, desc) => {
38
38
  }
39
39
  return to;
40
40
  };
41
- var __reExport = (target, mod, secondTarget, symbols) => {
42
- if (symbols) {
43
- __defProp(target, Symbol.toStringTag, { value: "Module" });
44
- secondTarget && __defProp(secondTarget, Symbol.toStringTag, { value: "Module" });
45
- }
46
- __copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default");
47
- };
41
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
48
42
 
49
43
  //#endregion
50
- //#region ../core/lib/use-guards.decorator-kZ3lNK8v.mjs
44
+ //#region ../core/lib/use-guards.decorator-CUww54Nt.mjs
51
45
  const EndpointMetadataKey = Symbol("EndpointMetadataKey");
52
46
  function getAllEndpointMetadata(context) {
53
47
  if (context.metadata) {
@@ -140,13 +134,13 @@ function hasModuleMetadata(target) {
140
134
  }
141
135
  /**
142
136
  * Decorator that marks a class as a Navios controller.
143
- *
137
+ *
144
138
  * Controllers handle HTTP requests and define endpoints.
145
139
  * They are request-scoped by default, meaning a new instance is created for each request.
146
- *
140
+ *
147
141
  * @param options - Controller configuration options
148
142
  * @returns A class decorator
149
- *
143
+ *
150
144
  * @example
151
145
  * ```typescript
152
146
  * @Controller({ guards: [AuthGuard] })
@@ -157,7 +151,7 @@ function hasModuleMetadata(target) {
157
151
  * }
158
152
  * }
159
153
  * ```
160
- */ function Controller({ guards } = {}) {
154
+ */ function Controller({ guards, registry } = {}) {
161
155
  return function(target, context) {
162
156
  if (context.kind !== "class") throw new Error("[Navios] @Controller decorator can only be used on classes.");
163
157
  const token = InjectionToken.create(target);
@@ -167,7 +161,7 @@ function hasModuleMetadata(target) {
167
161
  }
168
162
  return Injectable({
169
163
  token,
170
- scope: InjectableScope.Request
164
+ registry
171
165
  })(target, context);
172
166
  };
173
167
  }
@@ -176,40 +170,12 @@ const ExecutionContextInjectionToken = "ExecutionContextInjectionToken";
176
170
  const ExecutionContext = InjectionToken.create(ExecutionContextInjectionToken);
177
171
  const HttpAdapterToken = InjectionToken.create("HttpAdapterToken");
178
172
  const MultipartAdapterToken = InjectionToken.create("MultipartAdapterToken");
173
+ const NaviosOptionsToken = InjectionToken.create("NaviosOptionsToken");
179
174
  const Reply = InjectionToken.create("ReplyToken");
180
175
  const Request = InjectionToken.create("RequestToken");
181
176
  const StreamAdapterToken = InjectionToken.create("StreamAdapterToken");
182
177
  const XmlStreamAdapterToken = InjectionToken.create("XmlStreamAdapterToken");
183
- /**
184
- * Decorator that marks a method as an HTTP endpoint.
185
- *
186
- * The endpoint must be defined using @navios/builder's `declareEndpoint` method.
187
- * This ensures type safety and consistency between client and server.
188
- *
189
- * @param endpoint - The endpoint declaration from @navios/builder
190
- * @returns A method decorator
191
- *
192
- * @example
193
- * ```typescript
194
- * import { builder } from '@navios/builder'
195
- *
196
- * const api = builder()
197
- * const getUserEndpoint = api.declareEndpoint({
198
- * method: 'get',
199
- * url: '/users/$userId',
200
- * responseSchema: z.object({ id: z.string(), name: z.string() }),
201
- * })
202
- *
203
- * @Controller()
204
- * export class UserController {
205
- * @Endpoint(getUserEndpoint)
206
- * async getUser(request: EndpointParams<typeof getUserEndpoint>) {
207
- * const { userId } = request.urlParams
208
- * return { id: userId, name: 'John' }
209
- * }
210
- * }
211
- * ```
212
- */ function Endpoint(endpoint) {
178
+ function Endpoint(endpoint) {
213
179
  return (target, context) => {
214
180
  if (context.kind !== "method") throw new Error("[Navios] Endpoint decorator can only be used on methods.");
215
181
  const config = endpoint.config;
@@ -314,37 +280,8 @@ const XmlStreamAdapterToken = InjectionToken.create("XmlStreamAdapterToken");
314
280
  })(target, context);
315
281
  };
316
282
  }
317
- /**
318
- * Decorator that marks a method as a multipart/form-data endpoint.
319
- *
320
- * Use this decorator for endpoints that handle file uploads or form data.
321
- * The endpoint must be defined using @navios/builder's `declareMultipart` method.
322
- *
323
- * @param endpoint - The multipart endpoint declaration from @navios/builder
324
- * @returns A method decorator
325
- *
326
- * @example
327
- * ```typescript
328
- * const uploadFileEndpoint = api.declareMultipart({
329
- * method: 'post',
330
- * url: '/upload',
331
- * requestSchema: z.object({ file: z.instanceof(File) }),
332
- * responseSchema: z.object({ url: z.string() }),
333
- * })
334
- *
335
- * @Controller()
336
- * export class FileController {
337
- * @Multipart(uploadFileEndpoint)
338
- * async uploadFile(request: MultipartParams<typeof uploadFileEndpoint>) {
339
- * const { file } = request.data
340
- * // Handle file upload
341
- * return { url: 'https://example.com/file.jpg' }
342
- * }
343
- * }
344
- * ```
345
- */ function Multipart(endpoint) {
283
+ function Multipart(endpoint) {
346
284
  return (target, context) => {
347
- if (typeof target !== "function") throw new Error("[Navios] Endpoint decorator can only be used on functions.");
348
285
  if (context.kind !== "method") throw new Error("[Navios] Endpoint decorator can only be used on methods.");
349
286
  const config = endpoint.config;
350
287
  if (context.metadata) {
@@ -359,34 +296,8 @@ const XmlStreamAdapterToken = InjectionToken.create("XmlStreamAdapterToken");
359
296
  return target;
360
297
  };
361
298
  }
362
- /**
363
- * Decorator that marks a method as a streaming endpoint.
364
- *
365
- * Use this decorator for endpoints that stream data (e.g., file downloads, SSE).
366
- * The endpoint must be defined using @navios/builder's `declareStream` method.
367
- *
368
- * @param endpoint - The stream endpoint declaration from @navios/builder
369
- * @returns A method decorator
370
- *
371
- * @example
372
- * ```typescript
373
- * const downloadFileEndpoint = api.declareStream({
374
- * method: 'get',
375
- * url: '/files/$fileId',
376
- * })
377
- *
378
- * @Controller()
379
- * export class FileController {
380
- * @Stream(downloadFileEndpoint)
381
- * async downloadFile(request: StreamParams<typeof downloadFileEndpoint>, reply: any) {
382
- * const { fileId } = request.urlParams
383
- * // Stream file data to reply
384
- * }
385
- * }
386
- * ```
387
- */ function Stream(endpoint) {
299
+ function Stream(endpoint) {
388
300
  return (target, context) => {
389
- if (typeof target !== "function") throw new Error("[Navios] Endpoint decorator can only be used on functions.");
390
301
  if (context.kind !== "method") throw new Error("[Navios] Endpoint decorator can only be used on methods.");
391
302
  const config = endpoint.config;
392
303
  if (context.metadata) {
@@ -469,7 +380,7 @@ const XmlStreamAdapterToken = InjectionToken.create("XmlStreamAdapterToken");
469
380
  };
470
381
 
471
382
  //#endregion
472
- //#region ../core/lib/src-DzPY5s6d.mjs
383
+ //#region ../core/lib/src-gBAChVRL.mjs
473
384
  function envInt(key, defaultValue) {
474
385
  const envKey = env[key] || process.env[key];
475
386
  return envKey ? parseInt(envKey, 10) : defaultValue;
@@ -552,6 +463,15 @@ const isConstructor = (val) => val === "constructor";
552
463
  const isNil = (val) => isUndefined(val) || val === null;
553
464
  const isEmpty = (array) => !(array && array.length > 0);
554
465
  const isSymbol = (val) => typeof val === "symbol";
466
+ let requestCounter = 0;
467
+ /**
468
+ * Generates a simple incremental request ID.
469
+ * Much faster than crypto.randomUUID() and sufficient for request tracking.
470
+ *
471
+ * @returns A unique request ID string (e.g., "req-1", "req-2", ...)
472
+ */ function generateRequestId() {
473
+ return `req-${++requestCounter}`;
474
+ }
555
475
  /**
556
476
  * AsyncLocalStorage store for the current request ID.
557
477
  *
@@ -571,22 +491,42 @@ const isSymbol = (val) => typeof val === "symbol";
571
491
  * // Get current request ID (returns undefined if not in a request context)
572
492
  * const currentId = getRequestId()
573
493
  * ```
574
- */ const requestIdStore = new AsyncLocalStorage();
494
+ */ let requestIdStore = null;
495
+ function getRequestIdStore() {
496
+ if (!requestIdStore) requestIdStore = new AsyncLocalStorage();
497
+ return requestIdStore;
498
+ }
499
+ /**
500
+ * Whether request ID propagation is enabled.
501
+ * When disabled, runWithRequestId is a pass-through for better performance.
502
+ */ let requestIdEnabled = false;
503
+ /**
504
+ * Enables or disables request ID propagation.
505
+ * Called by NaviosFactory based on the enableRequestId option.
506
+ *
507
+ * @param enabled - Whether to enable request ID propagation
508
+ */ function setRequestIdEnabled(enabled) {
509
+ requestIdEnabled = enabled;
510
+ }
575
511
  /**
576
512
  * Runs a function with a request ID in the async local storage context.
513
+ * If request ID propagation is disabled, the function is called directly
514
+ * without AsyncLocalStorage overhead.
577
515
  *
578
516
  * @param requestId - The request ID to set for this context
579
517
  * @param fn - The function to run within this context
580
518
  * @returns The return value of the function
581
519
  */ function runWithRequestId(requestId, fn) {
582
- return requestIdStore.run(requestId, fn);
520
+ if (!requestIdEnabled) return fn();
521
+ return getRequestIdStore().run(requestId, fn);
583
522
  }
584
523
  /**
585
524
  * Gets the current request ID from the async local storage context.
586
525
  *
587
526
  * @returns The current request ID, or undefined if not in a request context
588
527
  */ function getRequestId() {
589
- return requestIdStore.getStore();
528
+ if (!requestIdEnabled) return;
529
+ return getRequestIdStore().getStore();
590
530
  }
591
531
  /**
592
532
  * Injection token for the logger output service.
@@ -608,7 +548,7 @@ const isSymbol = (val) => typeof val === "symbol";
608
548
  * logger.log('Hello world') // Logs with context: [MyService]
609
549
  * ```
610
550
  */ const Logger = InjectionToken.create("Logger", loggerOptionsSchema);
611
- function applyDecs2203RFactory$13() {
551
+ function applyDecs2203RFactory$14() {
612
552
  function createAddInitializerMethod(initializers, decoratorFinishedRef) {
613
553
  return function addInitializer(initializer) {
614
554
  assertNotFinished(decoratorFinishedRef, "addInitializer");
@@ -882,10 +822,10 @@ function applyDecs2203RFactory$13() {
882
822
  };
883
823
  };
884
824
  }
885
- function _apply_decs_2203_r$13(targetClass, memberDecs, classDecs, parentClass) {
886
- return (_apply_decs_2203_r$13 = applyDecs2203RFactory$13())(targetClass, memberDecs, classDecs, parentClass);
825
+ function _apply_decs_2203_r$14(targetClass, memberDecs, classDecs, parentClass) {
826
+ return (_apply_decs_2203_r$14 = applyDecs2203RFactory$14())(targetClass, memberDecs, classDecs, parentClass);
887
827
  }
888
- var _dec$13, _initClass$13;
828
+ var _dec$14, _initClass$14;
889
829
  const DEFAULT_DEPTH = 5;
890
830
  const DEFAULT_LOG_LEVELS = [
891
831
  "log",
@@ -904,10 +844,10 @@ const dateTimeFormatter = new Intl.DateTimeFormat(void 0, {
904
844
  month: "2-digit"
905
845
  });
906
846
  let _ConsoleLogger;
907
- _dec$13 = Injectable({ token: LoggerOutput });
847
+ _dec$14 = Injectable({ token: LoggerOutput });
908
848
  (class {
909
849
  static {
910
- ({c: [_ConsoleLogger, _initClass$13]} = _apply_decs_2203_r$13(this, [], [_dec$13]));
850
+ ({c: [_ConsoleLogger, _initClass$14]} = _apply_decs_2203_r$14(this, [], [_dec$14]));
911
851
  }
912
852
  /**
913
853
  * The options of the logger.
@@ -1156,10 +1096,10 @@ _dec$13 = Injectable({ token: LoggerOutput });
1156
1096
  }
1157
1097
  }
1158
1098
  static {
1159
- _initClass$13();
1099
+ _initClass$14();
1160
1100
  }
1161
1101
  });
1162
- function applyDecs2203RFactory$12() {
1102
+ function applyDecs2203RFactory$13() {
1163
1103
  function createAddInitializerMethod(initializers, decoratorFinishedRef) {
1164
1104
  return function addInitializer(initializer) {
1165
1105
  assertNotFinished(decoratorFinishedRef, "addInitializer");
@@ -1433,15 +1373,15 @@ function applyDecs2203RFactory$12() {
1433
1373
  };
1434
1374
  };
1435
1375
  }
1436
- function _apply_decs_2203_r$12(targetClass, memberDecs, classDecs, parentClass) {
1437
- return (_apply_decs_2203_r$12 = applyDecs2203RFactory$12())(targetClass, memberDecs, classDecs, parentClass);
1376
+ function _apply_decs_2203_r$13(targetClass, memberDecs, classDecs, parentClass) {
1377
+ return (_apply_decs_2203_r$13 = applyDecs2203RFactory$13())(targetClass, memberDecs, classDecs, parentClass);
1438
1378
  }
1439
- var _dec$12, _initClass$12;
1379
+ var _dec$13, _initClass$13;
1440
1380
  let _LoggerInstance;
1441
- _dec$12 = Injectable({ token: Logger });
1381
+ _dec$13 = Injectable({ token: Logger });
1442
1382
  (class {
1443
1383
  static {
1444
- ({c: [_LoggerInstance, _initClass$12]} = _apply_decs_2203_r$12(this, [], [_dec$12]));
1384
+ ({c: [_LoggerInstance, _initClass$13]} = _apply_decs_2203_r$13(this, [], [_dec$13]));
1445
1385
  }
1446
1386
  constructor(config = {}) {
1447
1387
  this.context = config.context;
@@ -1473,10 +1413,10 @@ _dec$12 = Injectable({ token: Logger });
1473
1413
  this.localInstance?.fatal?.(message, ...optionalParams);
1474
1414
  }
1475
1415
  static {
1476
- _initClass$12();
1416
+ _initClass$13();
1477
1417
  }
1478
1418
  });
1479
- function applyDecs2203RFactory$11() {
1419
+ function applyDecs2203RFactory$12() {
1480
1420
  function createAddInitializerMethod(initializers, decoratorFinishedRef) {
1481
1421
  return function addInitializer(initializer) {
1482
1422
  assertNotFinished(decoratorFinishedRef, "addInitializer");
@@ -1750,10 +1690,10 @@ function applyDecs2203RFactory$11() {
1750
1690
  };
1751
1691
  };
1752
1692
  }
1753
- function _apply_decs_2203_r$11(targetClass, memberDecs, classDecs, parentClass) {
1754
- return (_apply_decs_2203_r$11 = applyDecs2203RFactory$11())(targetClass, memberDecs, classDecs, parentClass);
1693
+ function _apply_decs_2203_r$12(targetClass, memberDecs, classDecs, parentClass) {
1694
+ return (_apply_decs_2203_r$12 = applyDecs2203RFactory$12())(targetClass, memberDecs, classDecs, parentClass);
1755
1695
  }
1756
- var _dec$11, _initClass$11;
1696
+ var _dec$12, _initClass$12;
1757
1697
  /**
1758
1698
  * Schema for validating configuration service options.
1759
1699
  */ const ConfigServiceOptionsSchema = z$1.record(z$1.string(), z$1.unknown());
@@ -1761,11 +1701,11 @@ var _dec$11, _initClass$11;
1761
1701
  * Injection token for ConfigService.
1762
1702
  */ const ConfigServiceToken = InjectionToken.create(Symbol.for("ConfigService"), ConfigServiceOptionsSchema);
1763
1703
  let _ConfigService;
1764
- _dec$11 = Injectable({ token: ConfigServiceToken });
1704
+ _dec$12 = Injectable({ token: ConfigServiceToken });
1765
1705
  (class {
1766
1706
  config;
1767
1707
  static {
1768
- ({c: [_ConfigService, _initClass$11]} = _apply_decs_2203_r$11(this, [], [_dec$11]));
1708
+ ({c: [_ConfigService, _initClass$12]} = _apply_decs_2203_r$12(this, [], [_dec$12]));
1769
1709
  }
1770
1710
  /**
1771
1711
  * Creates a new ConfigService instance.
@@ -1847,7 +1787,7 @@ _dec$11 = Injectable({ token: ConfigServiceToken });
1847
1787
  return value;
1848
1788
  }
1849
1789
  static {
1850
- _initClass$11();
1790
+ _initClass$12();
1851
1791
  }
1852
1792
  });
1853
1793
  /**
@@ -2082,6 +2022,357 @@ _dec$11 = Injectable({ token: ConfigServiceToken });
2082
2022
  super(409, message, error);
2083
2023
  }
2084
2024
  };
2025
+ function applyDecs2203RFactory$11() {
2026
+ function createAddInitializerMethod(initializers, decoratorFinishedRef) {
2027
+ return function addInitializer(initializer) {
2028
+ assertNotFinished(decoratorFinishedRef, "addInitializer");
2029
+ assertCallable(initializer, "An initializer");
2030
+ initializers.push(initializer);
2031
+ };
2032
+ }
2033
+ function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
2034
+ var kindStr;
2035
+ switch (kind) {
2036
+ case 1:
2037
+ kindStr = "accessor";
2038
+ break;
2039
+ case 2:
2040
+ kindStr = "method";
2041
+ break;
2042
+ case 3:
2043
+ kindStr = "getter";
2044
+ break;
2045
+ case 4:
2046
+ kindStr = "setter";
2047
+ break;
2048
+ default: kindStr = "field";
2049
+ }
2050
+ var ctx = {
2051
+ kind: kindStr,
2052
+ name: isPrivate ? "#" + name : name,
2053
+ static: isStatic,
2054
+ private: isPrivate,
2055
+ metadata
2056
+ };
2057
+ var decoratorFinishedRef = { v: false };
2058
+ ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
2059
+ var get, set;
2060
+ if (kind === 0) if (isPrivate) {
2061
+ get = desc.get;
2062
+ set = desc.set;
2063
+ } else {
2064
+ get = function() {
2065
+ return this[name];
2066
+ };
2067
+ set = function(v) {
2068
+ this[name] = v;
2069
+ };
2070
+ }
2071
+ else if (kind === 2) get = function() {
2072
+ return desc.value;
2073
+ };
2074
+ else {
2075
+ if (kind === 1 || kind === 3) get = function() {
2076
+ return desc.get.call(this);
2077
+ };
2078
+ if (kind === 1 || kind === 4) set = function(v) {
2079
+ desc.set.call(this, v);
2080
+ };
2081
+ }
2082
+ ctx.access = get && set ? {
2083
+ get,
2084
+ set
2085
+ } : get ? { get } : { set };
2086
+ try {
2087
+ return dec(value, ctx);
2088
+ } finally {
2089
+ decoratorFinishedRef.v = true;
2090
+ }
2091
+ }
2092
+ function assertNotFinished(decoratorFinishedRef, fnName) {
2093
+ if (decoratorFinishedRef.v) throw new Error("attempted to call " + fnName + " after decoration was finished");
2094
+ }
2095
+ function assertCallable(fn, hint) {
2096
+ if (typeof fn !== "function") throw new TypeError(hint + " must be a function");
2097
+ }
2098
+ function assertValidReturnValue(kind, value) {
2099
+ var type = typeof value;
2100
+ if (kind === 1) {
2101
+ if (type !== "object" || value === null) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
2102
+ if (value.get !== void 0) assertCallable(value.get, "accessor.get");
2103
+ if (value.set !== void 0) assertCallable(value.set, "accessor.set");
2104
+ if (value.init !== void 0) assertCallable(value.init, "accessor.init");
2105
+ } else if (type !== "function") {
2106
+ var hint;
2107
+ if (kind === 0) hint = "field";
2108
+ else if (kind === 10) hint = "class";
2109
+ else hint = "method";
2110
+ throw new TypeError(hint + " decorators must return a function or void 0");
2111
+ }
2112
+ }
2113
+ function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
2114
+ var decs = decInfo[0];
2115
+ var desc, init, value;
2116
+ if (isPrivate) if (kind === 0 || kind === 1) desc = {
2117
+ get: decInfo[3],
2118
+ set: decInfo[4]
2119
+ };
2120
+ else if (kind === 3) desc = { get: decInfo[3] };
2121
+ else if (kind === 4) desc = { set: decInfo[3] };
2122
+ else desc = { value: decInfo[3] };
2123
+ else if (kind !== 0) desc = Object.getOwnPropertyDescriptor(base, name);
2124
+ if (kind === 1) value = {
2125
+ get: desc.get,
2126
+ set: desc.set
2127
+ };
2128
+ else if (kind === 2) value = desc.value;
2129
+ else if (kind === 3) value = desc.get;
2130
+ else if (kind === 4) value = desc.set;
2131
+ var newValue, get, set;
2132
+ if (typeof decs === "function") {
2133
+ newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
2134
+ if (newValue !== void 0) {
2135
+ assertValidReturnValue(kind, newValue);
2136
+ if (kind === 0) init = newValue;
2137
+ else if (kind === 1) {
2138
+ init = newValue.init;
2139
+ get = newValue.get || value.get;
2140
+ set = newValue.set || value.set;
2141
+ value = {
2142
+ get,
2143
+ set
2144
+ };
2145
+ } else value = newValue;
2146
+ }
2147
+ } else for (var i = decs.length - 1; i >= 0; i--) {
2148
+ var dec = decs[i];
2149
+ newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
2150
+ if (newValue !== void 0) {
2151
+ assertValidReturnValue(kind, newValue);
2152
+ var newInit;
2153
+ if (kind === 0) newInit = newValue;
2154
+ else if (kind === 1) {
2155
+ newInit = newValue.init;
2156
+ get = newValue.get || value.get;
2157
+ set = newValue.set || value.set;
2158
+ value = {
2159
+ get,
2160
+ set
2161
+ };
2162
+ } else value = newValue;
2163
+ if (newInit !== void 0) if (init === void 0) init = newInit;
2164
+ else if (typeof init === "function") init = [init, newInit];
2165
+ else init.push(newInit);
2166
+ }
2167
+ }
2168
+ if (kind === 0 || kind === 1) {
2169
+ if (init === void 0) init = function(instance, init$1) {
2170
+ return init$1;
2171
+ };
2172
+ else if (typeof init !== "function") {
2173
+ var ownInitializers = init;
2174
+ init = function(instance, init$1) {
2175
+ var value$1 = init$1;
2176
+ for (var i$1 = 0; i$1 < ownInitializers.length; i$1++) value$1 = ownInitializers[i$1].call(instance, value$1);
2177
+ return value$1;
2178
+ };
2179
+ } else {
2180
+ var originalInitializer = init;
2181
+ init = function(instance, init$1) {
2182
+ return originalInitializer.call(instance, init$1);
2183
+ };
2184
+ }
2185
+ ret.push(init);
2186
+ }
2187
+ if (kind !== 0) {
2188
+ if (kind === 1) {
2189
+ desc.get = value.get;
2190
+ desc.set = value.set;
2191
+ } else if (kind === 2) desc.value = value;
2192
+ else if (kind === 3) desc.get = value;
2193
+ else if (kind === 4) desc.set = value;
2194
+ if (isPrivate) if (kind === 1) {
2195
+ ret.push(function(instance, args) {
2196
+ return value.get.call(instance, args);
2197
+ });
2198
+ ret.push(function(instance, args) {
2199
+ return value.set.call(instance, args);
2200
+ });
2201
+ } else if (kind === 2) ret.push(value);
2202
+ else ret.push(function(instance, args) {
2203
+ return value.call(instance, args);
2204
+ });
2205
+ else Object.defineProperty(base, name, desc);
2206
+ }
2207
+ }
2208
+ function applyMemberDecs(Class, decInfos, metadata) {
2209
+ var ret = [];
2210
+ var protoInitializers;
2211
+ var staticInitializers;
2212
+ var existingProtoNonFields = /* @__PURE__ */ new Map();
2213
+ var existingStaticNonFields = /* @__PURE__ */ new Map();
2214
+ for (var i = 0; i < decInfos.length; i++) {
2215
+ var decInfo = decInfos[i];
2216
+ if (!Array.isArray(decInfo)) continue;
2217
+ var kind = decInfo[1];
2218
+ var name = decInfo[2];
2219
+ var isPrivate = decInfo.length > 3;
2220
+ var isStatic = kind >= 5;
2221
+ var base;
2222
+ var initializers;
2223
+ if (isStatic) {
2224
+ base = Class;
2225
+ kind = kind - 5;
2226
+ staticInitializers = staticInitializers || [];
2227
+ initializers = staticInitializers;
2228
+ } else {
2229
+ base = Class.prototype;
2230
+ protoInitializers = protoInitializers || [];
2231
+ initializers = protoInitializers;
2232
+ }
2233
+ if (kind !== 0 && !isPrivate) {
2234
+ var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
2235
+ var existingKind = existingNonFields.get(name) || 0;
2236
+ 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);
2237
+ else if (!existingKind && kind > 2) existingNonFields.set(name, kind);
2238
+ else existingNonFields.set(name, true);
2239
+ }
2240
+ applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
2241
+ }
2242
+ pushInitializers(ret, protoInitializers);
2243
+ pushInitializers(ret, staticInitializers);
2244
+ return ret;
2245
+ }
2246
+ function pushInitializers(ret, initializers) {
2247
+ if (initializers) ret.push(function(instance) {
2248
+ for (var i = 0; i < initializers.length; i++) initializers[i].call(instance);
2249
+ return instance;
2250
+ });
2251
+ }
2252
+ function applyClassDecs(targetClass, classDecs, metadata) {
2253
+ if (classDecs.length > 0) {
2254
+ var initializers = [];
2255
+ var newClass = targetClass;
2256
+ var name = targetClass.name;
2257
+ for (var i = classDecs.length - 1; i >= 0; i--) {
2258
+ var decoratorFinishedRef = { v: false };
2259
+ try {
2260
+ var nextNewClass = classDecs[i](newClass, {
2261
+ kind: "class",
2262
+ name,
2263
+ addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
2264
+ metadata
2265
+ });
2266
+ } finally {
2267
+ decoratorFinishedRef.v = true;
2268
+ }
2269
+ if (nextNewClass !== void 0) {
2270
+ assertValidReturnValue(10, nextNewClass);
2271
+ newClass = nextNewClass;
2272
+ }
2273
+ }
2274
+ return [defineMetadata(newClass, metadata), function() {
2275
+ for (var i$1 = 0; i$1 < initializers.length; i$1++) initializers[i$1].call(newClass);
2276
+ }];
2277
+ }
2278
+ }
2279
+ function defineMetadata(Class, metadata) {
2280
+ return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
2281
+ configurable: true,
2282
+ enumerable: true,
2283
+ value: metadata
2284
+ });
2285
+ }
2286
+ return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
2287
+ if (parentClass !== void 0) var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
2288
+ var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
2289
+ var e = applyMemberDecs(targetClass, memberDecs, metadata);
2290
+ if (!classDecs.length) defineMetadata(targetClass, metadata);
2291
+ return {
2292
+ e,
2293
+ get c() {
2294
+ return applyClassDecs(targetClass, classDecs, metadata);
2295
+ }
2296
+ };
2297
+ };
2298
+ }
2299
+ function _apply_decs_2203_r$11(targetClass, memberDecs, classDecs, parentClass) {
2300
+ return (_apply_decs_2203_r$11 = applyDecs2203RFactory$11())(targetClass, memberDecs, classDecs, parentClass);
2301
+ }
2302
+ var _dec$11, _initClass$11;
2303
+ let _InstanceResolverService;
2304
+ _dec$11 = Injectable();
2305
+ (class {
2306
+ static {
2307
+ ({c: [_InstanceResolverService, _initClass$11]} = _apply_decs_2203_r$11(this, [], [_dec$11]));
2308
+ }
2309
+ container = inject(Container);
2310
+ /**
2311
+ * Attempts to resolve a class instance, automatically detecting if it needs
2312
+ * request scope based on its dependencies.
2313
+ *
2314
+ * @param classType - The class to resolve
2315
+ * @returns A resolution result containing either a cached instance or resolver function
2316
+ */ async resolve(classType) {
2317
+ let cachedInstance = null;
2318
+ try {
2319
+ cachedInstance = await this.container.get(classType);
2320
+ } catch {
2321
+ const token = getInjectableToken(classType);
2322
+ this.container.getRegistry().updateScope(token, InjectableScope.Request);
2323
+ }
2324
+ return {
2325
+ cached: cachedInstance !== null,
2326
+ instance: cachedInstance,
2327
+ resolve: (scoped) => scoped.get(classType)
2328
+ };
2329
+ }
2330
+ /**
2331
+ * Attempts to resolve multiple class instances, automatically detecting if any need
2332
+ * request scope based on their dependencies.
2333
+ *
2334
+ * Returns `cached: true` only if ALL classes can be resolved as singletons.
2335
+ * If any class has request-scoped dependencies, returns `cached: false`.
2336
+ *
2337
+ * @param classTypes - The classes to resolve
2338
+ * @returns A resolution result containing either all cached instances or resolver function
2339
+ */ async resolveMany(classTypes) {
2340
+ if (classTypes.length === 0) return {
2341
+ cached: true,
2342
+ instances: [],
2343
+ classTypes: [],
2344
+ resolve: async () => []
2345
+ };
2346
+ const results = await Promise.all(classTypes.map(async (classType) => {
2347
+ try {
2348
+ return {
2349
+ success: true,
2350
+ instance: await this.container.get(classType)
2351
+ };
2352
+ } catch {
2353
+ const token = getInjectableToken(classType);
2354
+ this.container.getRegistry().updateScope(token, InjectableScope.Request);
2355
+ return {
2356
+ success: false,
2357
+ instance: null
2358
+ };
2359
+ }
2360
+ }));
2361
+ const allCached = results.every((r) => r.success);
2362
+ return {
2363
+ cached: allCached,
2364
+ instances: allCached ? results.map((r) => r.instance) : null,
2365
+ classTypes,
2366
+ resolve: (scoped) => Promise.all(classTypes.map((classType) => scoped.get(classType)))
2367
+ };
2368
+ }
2369
+ static {
2370
+ _initClass$11();
2371
+ }
2372
+ });
2373
+ /**
2374
+ * @deprecated Use InstanceResolverService instead
2375
+ */ const ControllerResolverService = _InstanceResolverService;
2085
2376
  function applyDecs2203RFactory$10() {
2086
2377
  function createAddInitializerMethod(initializers, decoratorFinishedRef) {
2087
2378
  return function addInitializer(initializer) {
@@ -2367,23 +2658,40 @@ _dec$10 = Injectable();
2367
2658
  ({c: [_GuardRunnerService, _initClass$10]} = _apply_decs_2203_r$10(this, [], [_dec$10]));
2368
2659
  }
2369
2660
  logger = inject(Logger, { context: _GuardRunnerService.name });
2370
- async runGuards(allGuards, executionContext, context) {
2371
- let canActivate = true;
2372
- for (const guard of Array.from(allGuards).reverse()) {
2661
+ /**
2662
+ * Runs guards that need to be resolved from a scoped container.
2663
+ * Use this when guards have request-scoped dependencies.
2664
+ */ async runGuards(allGuards, executionContext, context) {
2665
+ const guardsArray = Array.from(allGuards).reverse();
2666
+ const guardInstances = await Promise.all(guardsArray.map(async (guard) => {
2373
2667
  const guardInstance = await context.get(guard);
2374
2668
  if (!guardInstance.canActivate) throw new Error(`[Navios] Guard ${guard.name} does not implement canActivate()`);
2375
- try {
2376
- canActivate = await guardInstance.canActivate(executionContext);
2377
- if (!canActivate) break;
2378
- } catch (error) {
2379
- if (error instanceof HttpException) {
2380
- executionContext.getReply().status(error.statusCode).send(error.response);
2381
- return false;
2382
- } else {
2383
- this.logger.error("Error running guard", error);
2384
- executionContext.getReply().status(500).send({ message: "Internal server error" });
2385
- return false;
2386
- }
2669
+ return guardInstance;
2670
+ }));
2671
+ return this.executeGuards(guardInstances, executionContext);
2672
+ }
2673
+ /**
2674
+ * Runs pre-resolved guard instances.
2675
+ * Use this when all guards are singletons and have been pre-resolved at startup.
2676
+ */ async runGuardsStatic(guardInstances, executionContext) {
2677
+ return this.executeGuards(guardInstances, executionContext);
2678
+ }
2679
+ /**
2680
+ * Shared guard execution logic.
2681
+ * Iterates through guard instances and calls canActivate on each.
2682
+ */ async executeGuards(guardInstances, executionContext) {
2683
+ let canActivate = true;
2684
+ for (const guardInstance of guardInstances) try {
2685
+ canActivate = await guardInstance.canActivate(executionContext);
2686
+ if (!canActivate) break;
2687
+ } catch (error) {
2688
+ if (error instanceof HttpException) {
2689
+ executionContext.getReply().status(error.statusCode).send(error.response);
2690
+ return false;
2691
+ } else {
2692
+ this.logger.error("Error running guard", error);
2693
+ executionContext.getReply().status(500).send({ message: "Internal server error" });
2694
+ return false;
2387
2695
  }
2388
2696
  }
2389
2697
  if (!canActivate) {
@@ -2700,6 +3008,49 @@ _dec$9 = Injectable();
2700
3008
  await this.traverseModules(appModule);
2701
3009
  this.initialized = true;
2702
3010
  }
3011
+ /**
3012
+ * Extends the module tree with additional modules or controllers.
3013
+ *
3014
+ * This method is designed to be called by plugins during registration,
3015
+ * which happens after initial module loading but before route registration.
3016
+ *
3017
+ * @param extensions - Array of module extensions to add
3018
+ * @throws Error if not initialized (loadModules must be called first)
3019
+ *
3020
+ * @example
3021
+ * ```typescript
3022
+ * // In plugin registration
3023
+ * const moduleLoader = await context.container.get(ModuleLoaderService)
3024
+ * await moduleLoader.extendModules([{
3025
+ * controllers: [OpenApiJsonController, OpenApiYamlController],
3026
+ * moduleName: 'OpenApiBunModule',
3027
+ * }])
3028
+ * ```
3029
+ */ async extendModules(extensions) {
3030
+ if (!this.initialized) throw new Error("ModuleLoaderService must be initialized before extending. Call loadModules() first.");
3031
+ for (const extension of extensions) if (extension.module) await this.traverseModules(extension.module);
3032
+ else if (extension.controllers && extension.moduleName) await this.registerControllers(extension.controllers, extension.moduleName);
3033
+ else if (extension.controllers) throw new Error("moduleName is required when providing controllers without a module");
3034
+ }
3035
+ /**
3036
+ * Registers controllers under a synthetic module.
3037
+ * Used when plugins want to add controllers without a full module class.
3038
+ */ async registerControllers(controllers, moduleName) {
3039
+ if (this.modulesMetadata.has(moduleName)) {
3040
+ const existing = this.modulesMetadata.get(moduleName);
3041
+ for (const controller of controllers) existing.controllers.add(controller);
3042
+ this.logger.debug(`Extended module ${moduleName} with ${controllers.length} controllers`);
3043
+ } else {
3044
+ const metadata = {
3045
+ controllers: new Set(controllers),
3046
+ imports: /* @__PURE__ */ new Set(),
3047
+ guards: /* @__PURE__ */ new Set(),
3048
+ customAttributes: /* @__PURE__ */ new Map()
3049
+ };
3050
+ this.modulesMetadata.set(moduleName, metadata);
3051
+ this.logger.debug(`Created module ${moduleName} with ${controllers.length} controllers`);
3052
+ }
3053
+ }
2703
3054
  async traverseModules(module, parentMetadata) {
2704
3055
  const metadata = extractModuleMetadata(module);
2705
3056
  if (parentMetadata) this.mergeMetadata(metadata, parentMetadata);
@@ -5176,7 +5527,7 @@ _dec$1$1 = Factory({ token: XmlStreamAdapterToken });
5176
5527
  _initClass$1$1();
5177
5528
  }
5178
5529
  });
5179
- function applyDecs2203RFactory$14() {
5530
+ function applyDecs2203RFactory$15() {
5180
5531
  function createAddInitializerMethod(initializers, decoratorFinishedRef) {
5181
5532
  return function addInitializer(initializer) {
5182
5533
  assertNotFinished(decoratorFinishedRef, "addInitializer");
@@ -5450,15 +5801,15 @@ function applyDecs2203RFactory$14() {
5450
5801
  };
5451
5802
  };
5452
5803
  }
5453
- function _apply_decs_2203_r$14(targetClass, memberDecs, classDecs, parentClass) {
5454
- return (_apply_decs_2203_r$14 = applyDecs2203RFactory$14())(targetClass, memberDecs, classDecs, parentClass);
5804
+ function _apply_decs_2203_r$15(targetClass, memberDecs, classDecs, parentClass) {
5805
+ return (_apply_decs_2203_r$15 = applyDecs2203RFactory$15())(targetClass, memberDecs, classDecs, parentClass);
5455
5806
  }
5456
- var _dec$14, _initClass$14;
5807
+ var _dec$15, _initClass$15;
5457
5808
  let _NaviosApplication;
5458
- _dec$14 = Injectable();
5809
+ _dec$15 = Injectable();
5459
5810
  (class {
5460
5811
  static {
5461
- ({c: [_NaviosApplication, _initClass$14]} = _apply_decs_2203_r$14(this, [], [_dec$14]));
5812
+ ({c: [_NaviosApplication, _initClass$15]} = _apply_decs_2203_r$15(this, [], [_dec$15]));
5462
5813
  }
5463
5814
  environment = inject(_NaviosEnvironment);
5464
5815
  moduleLoader = inject(_ModuleLoaderService);
@@ -5467,6 +5818,7 @@ _dec$14 = Injectable();
5467
5818
  container = inject(Container);
5468
5819
  appModule = null;
5469
5820
  options = { adapter: [] };
5821
+ plugins = [];
5470
5822
  /**
5471
5823
  * Indicates whether the application has been initialized.
5472
5824
  * Set to `true` after `init()` completes successfully.
@@ -5474,7 +5826,7 @@ _dec$14 = Injectable();
5474
5826
  /**
5475
5827
  * Sets up the application with the provided module and options.
5476
5828
  * This is called automatically by NaviosFactory.create().
5477
- *
5829
+ *
5478
5830
  * @param appModule - The root application module
5479
5831
  * @param options - Application configuration options
5480
5832
  * @internal
@@ -5485,24 +5837,46 @@ _dec$14 = Injectable();
5485
5837
  }
5486
5838
  /**
5487
5839
  * Gets the dependency injection container used by this application.
5488
- *
5840
+ *
5489
5841
  * @returns The Container instance
5490
5842
  */ getContainer() {
5491
5843
  return this.container;
5492
5844
  }
5493
5845
  /**
5846
+ * Registers a plugin to be initialized after modules are loaded.
5847
+ *
5848
+ * Plugins are initialized in the order they are registered,
5849
+ * after all modules are loaded but before the server starts listening.
5850
+ *
5851
+ * @param definition - Plugin definition with options
5852
+ * @returns this for method chaining
5853
+ *
5854
+ * @example
5855
+ * ```typescript
5856
+ * import { defineOpenApiPlugin } from '@navios/openapi-fastify'
5857
+ *
5858
+ * app.usePlugin(defineOpenApiPlugin({
5859
+ * info: { title: 'My API', version: '1.0.0' },
5860
+ * }))
5861
+ * ```
5862
+ */ usePlugin(definition) {
5863
+ this.plugins.push(definition);
5864
+ return this;
5865
+ }
5866
+ /**
5494
5867
  * Initializes the application.
5495
- *
5868
+ *
5496
5869
  * This method:
5497
5870
  * - Loads all modules and their dependencies
5498
5871
  * - Sets up the HTTP server if an adapter is configured
5499
5872
  * - Calls onModuleInit hooks on all modules
5873
+ * - Initializes registered plugins
5500
5874
  * - Marks the application as initialized
5501
- *
5875
+ *
5502
5876
  * Must be called before `listen()`.
5503
- *
5877
+ *
5504
5878
  * @throws Error if app module is not set
5505
- *
5879
+ *
5506
5880
  * @example
5507
5881
  * ```typescript
5508
5882
  * const app = await NaviosFactory.create(AppModule, {
@@ -5515,6 +5889,7 @@ _dec$14 = Injectable();
5515
5889
  if (!this.appModule) throw new Error("App module is not set. Call setAppModule() first.");
5516
5890
  await this.moduleLoader.loadModules(this.appModule);
5517
5891
  if (this.environment.hasHttpSetup()) await this.httpApplication?.setupHttpServer(this.options);
5892
+ await this.initPlugins();
5518
5893
  await this.initModules();
5519
5894
  if (this.environment.hasHttpSetup()) await this.httpApplication?.ready();
5520
5895
  this.isInitialized = true;
@@ -5524,12 +5899,30 @@ _dec$14 = Injectable();
5524
5899
  const modules = this.moduleLoader.getAllModules();
5525
5900
  await this.httpApplication?.onModulesInit(modules);
5526
5901
  }
5902
+ async initPlugins() {
5903
+ if (this.plugins.length === 0) return;
5904
+ let server = null;
5905
+ try {
5906
+ server = this.httpApplication?.getServer() ?? null;
5907
+ } catch {}
5908
+ const context = {
5909
+ modules: this.moduleLoader.getAllModules(),
5910
+ server,
5911
+ container: this.container,
5912
+ globalPrefix: this.httpApplication?.getGlobalPrefix() ?? "",
5913
+ moduleLoader: this.moduleLoader
5914
+ };
5915
+ for (const { plugin, options } of this.plugins) {
5916
+ this.logger.debug(`Initializing plugin: ${plugin.name}`);
5917
+ await plugin.register(context, options);
5918
+ }
5919
+ }
5527
5920
  /**
5528
5921
  * Enables CORS (Cross-Origin Resource Sharing) for the application.
5529
- *
5922
+ *
5530
5923
  * @param options - CORS configuration options (adapter-specific)
5531
5924
  * @throws Error if HTTP application is not set
5532
- *
5925
+ *
5533
5926
  * @example
5534
5927
  * ```typescript
5535
5928
  * app.enableCors({
@@ -5544,10 +5937,10 @@ _dec$14 = Injectable();
5544
5937
  }
5545
5938
  /**
5546
5939
  * Enables multipart/form-data support for file uploads.
5547
- *
5940
+ *
5548
5941
  * @param options - Multipart configuration options (adapter-specific)
5549
5942
  * @throws Error if HTTP application is not set
5550
- *
5943
+ *
5551
5944
  * @example
5552
5945
  * ```typescript
5553
5946
  * app.enableMultipart({
@@ -5562,10 +5955,10 @@ _dec$14 = Injectable();
5562
5955
  }
5563
5956
  /**
5564
5957
  * Sets a global prefix for all routes.
5565
- *
5958
+ *
5566
5959
  * @param prefix - The prefix to prepend to all route URLs (e.g., '/api')
5567
5960
  * @throws Error if HTTP application is not set
5568
- *
5961
+ *
5569
5962
  * @example
5570
5963
  * ```typescript
5571
5964
  * app.setGlobalPrefix('/api/v1')
@@ -5577,14 +5970,14 @@ _dec$14 = Injectable();
5577
5970
  }
5578
5971
  /**
5579
5972
  * Gets the underlying HTTP server instance.
5580
- *
5973
+ *
5581
5974
  * The type of the returned server depends on the adapter used:
5582
5975
  * - Fastify adapter: Returns FastifyInstance
5583
5976
  * - Bun adapter: Returns Bun.Server
5584
- *
5977
+ *
5585
5978
  * @returns The HTTP server instance
5586
5979
  * @throws Error if HTTP application is not set
5587
- *
5980
+ *
5588
5981
  * @example
5589
5982
  * ```typescript
5590
5983
  * const server = app.getServer()
@@ -5596,10 +5989,10 @@ _dec$14 = Injectable();
5596
5989
  }
5597
5990
  /**
5598
5991
  * Starts the HTTP server and begins listening for requests.
5599
- *
5992
+ *
5600
5993
  * @param options - Listen options (port, host, etc.)
5601
5994
  * @throws Error if HTTP application is not set
5602
- *
5995
+ *
5603
5996
  * @example
5604
5997
  * ```typescript
5605
5998
  * await app.listen({ port: 3000, host: '0.0.0.0' })
@@ -5610,7 +6003,7 @@ _dec$14 = Injectable();
5610
6003
  }
5611
6004
  /**
5612
6005
  * Disposes of application resources.
5613
- *
6006
+ *
5614
6007
  * Cleans up the HTTP server and module loader.
5615
6008
  * This method is called automatically by `close()`.
5616
6009
  */ async dispose() {
@@ -5619,9 +6012,9 @@ _dec$14 = Injectable();
5619
6012
  }
5620
6013
  /**
5621
6014
  * Closes the application and cleans up all resources.
5622
- *
6015
+ *
5623
6016
  * This is an alias for `dispose()`.
5624
- *
6017
+ *
5625
6018
  * @example
5626
6019
  * ```typescript
5627
6020
  * // Graceful shutdown
@@ -5634,36 +6027,36 @@ _dec$14 = Injectable();
5634
6027
  await this.dispose();
5635
6028
  }
5636
6029
  static {
5637
- _initClass$14();
6030
+ _initClass$15();
5638
6031
  }
5639
6032
  });
5640
6033
  /**
5641
6034
  * Factory class for creating and configuring Navios applications.
5642
- *
6035
+ *
5643
6036
  * This is the main entry point for bootstrapping a Navios application.
5644
6037
  * It handles dependency injection container setup, adapter registration,
5645
6038
  * and logger configuration.
5646
- *
6039
+ *
5647
6040
  * @example
5648
6041
  * ```typescript
5649
6042
  * import { NaviosFactory } from '@navios/core'
5650
6043
  * import { defineFastifyEnvironment } from '@navios/adapter-fastify'
5651
- *
6044
+ *
5652
6045
  * const app = await NaviosFactory.create(AppModule, {
5653
6046
  * adapter: defineFastifyEnvironment(),
5654
6047
  * logger: ['log', 'error', 'warn'],
5655
6048
  * })
5656
- *
6049
+ *
5657
6050
  * await app.init()
5658
6051
  * await app.listen({ port: 3000 })
5659
6052
  * ```
5660
6053
  */ var NaviosFactory = class {
5661
6054
  /**
5662
6055
  * Creates a new Navios application instance.
5663
- *
6056
+ *
5664
6057
  * This method sets up the dependency injection container, registers the HTTP adapter,
5665
6058
  * configures logging, and initializes the application with the provided module.
5666
- *
6059
+ *
5667
6060
  * @param appModule - The root application module class decorated with @Module()
5668
6061
  * @param options - Configuration options for the application
5669
6062
  * @param options.adapter - HTTP adapter environment (required for HTTP server functionality)
@@ -5673,20 +6066,20 @@ _dec$14 = Injectable();
5673
6066
  * - `false` to disable logging
5674
6067
  * @param options.container - Optional custom dependency injection container (useful for testing)
5675
6068
  * @returns A configured NaviosApplication instance ready to be initialized
5676
- *
6069
+ *
5677
6070
  * @example
5678
6071
  * ```typescript
5679
6072
  * // Basic setup with Fastify adapter
5680
6073
  * const app = await NaviosFactory.create(AppModule, {
5681
6074
  * adapter: defineFastifyEnvironment(),
5682
6075
  * })
5683
- *
6076
+ *
5684
6077
  * // With custom logger configuration
5685
6078
  * const app = await NaviosFactory.create(AppModule, {
5686
6079
  * adapter: defineFastifyEnvironment(),
5687
6080
  * logger: ['error', 'warn', 'log'],
5688
6081
  * })
5689
- *
6082
+ *
5690
6083
  * // With custom container for testing
5691
6084
  * const container = new Container()
5692
6085
  * const app = await NaviosFactory.create(AppModule, {
@@ -5696,6 +6089,8 @@ _dec$14 = Injectable();
5696
6089
  * ```
5697
6090
  */ static async create(appModule, options = { adapter: [] }) {
5698
6091
  const container = options.container ?? new Container();
6092
+ if (options.enableRequestId === true) setRequestIdEnabled(true);
6093
+ container.getServiceLocator().getManager().storeCreatedHolder(NaviosOptionsToken.toString(), options, InjectableType.Class, InjectableScope.Singleton);
5699
6094
  await this.registerLoggerConfiguration(container, options);
5700
6095
  const adapters = Array.isArray(options.adapter) ? options.adapter : [options.adapter];
5701
6096
  for (const adapter of adapters) await this.registerEnvironment(container, adapter);
@@ -5710,7 +6105,10 @@ _dec$14 = Injectable();
5710
6105
  }
5711
6106
  static async registerLoggerConfiguration(container, options) {
5712
6107
  const { logger } = options;
5713
- if (Array.isArray(logger) || isNil(logger)) (await container.get(LoggerOutput))?.setup({ logLevels: logger });
6108
+ if (Array.isArray(logger) || isNil(logger)) {
6109
+ (await container.get(LoggerOutput))?.setup({ logLevels: logger });
6110
+ return;
6111
+ }
5714
6112
  if (logger !== true && !isNil(logger)) container.getServiceLocator().getManager().storeCreatedHolder(LoggerOutput.toString(), logger, InjectableType.Class, InjectableScope.Singleton);
5715
6113
  }
5716
6114
  };
@@ -5728,6 +6126,7 @@ var lib_exports = /* @__PURE__ */ __export({
5728
6126
  ConsoleLogger: () => _ConsoleLogger,
5729
6127
  Controller: () => Controller,
5730
6128
  ControllerMetadataKey: () => ControllerMetadataKey,
6129
+ ControllerResolverService: () => ControllerResolverService,
5731
6130
  Endpoint: () => Endpoint,
5732
6131
  EndpointAdapterFactory: () => _EndpointAdapterFactory,
5733
6132
  EndpointAdapterToken: () => EndpointAdapterToken,
@@ -5742,6 +6141,7 @@ var lib_exports = /* @__PURE__ */ __export({
5742
6141
  HttpAdapterToken: () => HttpAdapterToken,
5743
6142
  HttpCode: () => HttpCode,
5744
6143
  HttpException: () => HttpException,
6144
+ InstanceResolverService: () => _InstanceResolverService,
5745
6145
  InternalServerErrorException: () => InternalServerErrorException,
5746
6146
  LOG_LEVELS: () => LOG_LEVELS,
5747
6147
  Logger: () => Logger,
@@ -5755,6 +6155,7 @@ var lib_exports = /* @__PURE__ */ __export({
5755
6155
  MultipartAdapterToken: () => MultipartAdapterToken,
5756
6156
  NaviosApplication: () => _NaviosApplication,
5757
6157
  NaviosFactory: () => NaviosFactory,
6158
+ NaviosOptionsToken: () => NaviosOptionsToken,
5758
6159
  NotFoundException: () => NotFoundException,
5759
6160
  Reply: () => Reply,
5760
6161
  ReplyFactory: () => _ReplyFactory,
@@ -5774,6 +6175,7 @@ var lib_exports = /* @__PURE__ */ __export({
5774
6175
  extractControllerMetadata: () => extractControllerMetadata,
5775
6176
  extractModuleMetadata: () => extractModuleMetadata,
5776
6177
  filterLogLevels: () => filterLogLevels,
6178
+ generateRequestId: () => generateRequestId,
5777
6179
  getAllEndpointMetadata: () => getAllEndpointMetadata,
5778
6180
  getControllerMetadata: () => getControllerMetadata,
5779
6181
  getEndpointMetadata: () => getEndpointMetadata,
@@ -5796,13 +6198,13 @@ var lib_exports = /* @__PURE__ */ __export({
5796
6198
  loggerOptionsSchema: () => loggerOptionsSchema,
5797
6199
  normalizePath: () => normalizePath,
5798
6200
  provideConfig: () => provideConfig,
5799
- requestIdStore: () => requestIdStore,
5800
6201
  runWithRequestId: () => runWithRequestId,
6202
+ setRequestIdEnabled: () => setRequestIdEnabled,
5801
6203
  stripEndSlash: () => stripEndSlash,
5802
6204
  yellow: () => yellow
5803
6205
  });
5804
- import * as import___navios_di from "@navios/di";
5805
- __reExport(lib_exports, import___navios_di);
6206
+ import * as import__navios_di from "@navios/di";
6207
+ __reExport(lib_exports, import__navios_di);
5806
6208
 
5807
6209
  //#endregion
5808
6210
  //#region src/interfaces/commander-execution-context.interface.mts
@@ -7447,6 +7849,7 @@ var src_exports = /* @__PURE__ */ __export({
7447
7849
  ConsoleLogger: () => _ConsoleLogger,
7448
7850
  Controller: () => Controller,
7449
7851
  ControllerMetadataKey: () => ControllerMetadataKey,
7852
+ ControllerResolverService: () => ControllerResolverService,
7450
7853
  Endpoint: () => Endpoint,
7451
7854
  EndpointAdapterFactory: () => _EndpointAdapterFactory,
7452
7855
  EndpointAdapterToken: () => EndpointAdapterToken,
@@ -7461,6 +7864,7 @@ var src_exports = /* @__PURE__ */ __export({
7461
7864
  HttpAdapterToken: () => HttpAdapterToken,
7462
7865
  HttpCode: () => HttpCode,
7463
7866
  HttpException: () => HttpException,
7867
+ InstanceResolverService: () => _InstanceResolverService,
7464
7868
  InternalServerErrorException: () => InternalServerErrorException,
7465
7869
  LOG_LEVELS: () => LOG_LEVELS,
7466
7870
  Logger: () => Logger,
@@ -7474,6 +7878,7 @@ var src_exports = /* @__PURE__ */ __export({
7474
7878
  MultipartAdapterToken: () => MultipartAdapterToken,
7475
7879
  NaviosApplication: () => _NaviosApplication,
7476
7880
  NaviosFactory: () => NaviosFactory,
7881
+ NaviosOptionsToken: () => NaviosOptionsToken,
7477
7882
  NotFoundException: () => NotFoundException,
7478
7883
  Reply: () => Reply,
7479
7884
  ReplyFactory: () => _ReplyFactory,
@@ -7495,6 +7900,7 @@ var src_exports = /* @__PURE__ */ __export({
7495
7900
  extractControllerMetadata: () => extractControllerMetadata,
7496
7901
  extractModuleMetadata: () => extractModuleMetadata,
7497
7902
  filterLogLevels: () => filterLogLevels,
7903
+ generateRequestId: () => generateRequestId,
7498
7904
  getAllEndpointMetadata: () => getAllEndpointMetadata,
7499
7905
  getCliModuleMetadata: () => getCliModuleMetadata,
7500
7906
  getCommandMetadata: () => getCommandMetadata,
@@ -7521,13 +7927,13 @@ var src_exports = /* @__PURE__ */ __export({
7521
7927
  loggerOptionsSchema: () => loggerOptionsSchema,
7522
7928
  normalizePath: () => normalizePath,
7523
7929
  provideConfig: () => provideConfig,
7524
- requestIdStore: () => requestIdStore,
7525
7930
  runWithRequestId: () => runWithRequestId,
7931
+ setRequestIdEnabled: () => setRequestIdEnabled,
7526
7932
  stripEndSlash: () => stripEndSlash,
7527
7933
  yellow: () => yellow
7528
7934
  });
7529
7935
  __reExport(src_exports, lib_exports);
7530
7936
 
7531
7937
  //#endregion
7532
- 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 };
7938
+ 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 };
7533
7939
  //# sourceMappingURL=index.mjs.map