@navios/core 0.7.1 → 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.
Files changed (53) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/lib/{index-DW9EPAE6.d.mts → index-BDNl7j1G.d.cts} +515 -346
  3. package/lib/index-BDNl7j1G.d.cts.map +1 -0
  4. package/lib/{index-pHp-dIGt.d.cts → index-BoP0cWT6.d.mts} +515 -346
  5. package/lib/index-BoP0cWT6.d.mts.map +1 -0
  6. package/lib/index.cjs +12 -3
  7. package/lib/index.d.cts +2 -2
  8. package/lib/index.d.mts +2 -2
  9. package/lib/index.mjs +3 -3
  10. package/lib/legacy-compat/index.cjs +1 -1
  11. package/lib/legacy-compat/index.cjs.map +1 -1
  12. package/lib/legacy-compat/index.d.cts +1 -1
  13. package/lib/legacy-compat/index.d.mts +1 -1
  14. package/lib/legacy-compat/index.mjs +1 -1
  15. package/lib/legacy-compat/index.mjs.map +1 -1
  16. package/lib/{src-QnxR5b7c.cjs → src-B6eISODM.cjs} +465 -47
  17. package/lib/src-B6eISODM.cjs.map +1 -0
  18. package/lib/{src-DyvCDuKO.mjs → src-gBAChVRL.mjs} +445 -45
  19. package/lib/src-gBAChVRL.mjs.map +1 -0
  20. package/lib/testing/index.cjs +2 -2
  21. package/lib/testing/index.d.cts +1 -1
  22. package/lib/testing/index.d.mts +1 -1
  23. package/lib/testing/index.mjs +2 -2
  24. package/lib/{use-guards.decorator-B6q_N0sf.cjs → use-guards.decorator-COR-9mZY.cjs} +20 -94
  25. package/lib/use-guards.decorator-COR-9mZY.cjs.map +1 -0
  26. package/lib/{use-guards.decorator-kZ3lNK8v.mjs → use-guards.decorator-CUww54Nt.mjs} +14 -94
  27. package/lib/use-guards.decorator-CUww54Nt.mjs.map +1 -0
  28. package/package.json +4 -4
  29. package/src/__tests__/controller-resolver.spec.mts +223 -0
  30. package/src/__tests__/controller.spec.mts +1 -1
  31. package/src/decorators/controller.decorator.mts +11 -6
  32. package/src/decorators/endpoint.decorator.mts +60 -12
  33. package/src/decorators/multipart.decorator.mts +67 -24
  34. package/src/decorators/stream.decorator.mts +65 -24
  35. package/src/interfaces/abstract-http-handler-adapter.interface.mts +31 -1
  36. package/src/legacy-compat/decorators/endpoint.decorator.mts +1 -1
  37. package/src/legacy-compat/decorators/multipart.decorator.mts +1 -1
  38. package/src/legacy-compat/decorators/stream.decorator.mts +1 -1
  39. package/src/logger/logger.service.mts +0 -2
  40. package/src/navios.application.mts +14 -0
  41. package/src/navios.factory.mts +19 -0
  42. package/src/services/guard-runner.service.mts +46 -9
  43. package/src/services/index.mts +1 -0
  44. package/src/services/instance-resolver.service.mts +186 -0
  45. package/src/stores/request-id.store.mts +45 -3
  46. package/src/tokens/index.mts +1 -0
  47. package/src/tokens/navios-options.token.mts +6 -0
  48. package/lib/index-DW9EPAE6.d.mts.map +0 -1
  49. package/lib/index-pHp-dIGt.d.cts.map +0 -1
  50. package/lib/src-DyvCDuKO.mjs.map +0 -1
  51. package/lib/src-QnxR5b7c.cjs.map +0 -1
  52. package/lib/use-guards.decorator-B6q_N0sf.cjs.map +0 -1
  53. package/lib/use-guards.decorator-kZ3lNK8v.mjs.map +0 -1
@@ -1,5 +1,5 @@
1
- import { O as getEndpointMetadata, T as hasControllerMetadata, b as getModuleMetadata, c as XmlStreamAdapterToken, d as Reply, f as MultipartAdapterToken, g as EndpointAdapterToken, l as StreamAdapterToken, p as HttpAdapterToken, u as Request, w as getControllerMetadata, x as hasModuleMetadata, y as extractModuleMetadata } from "./use-guards.decorator-kZ3lNK8v.mjs";
2
- import { Container, Factory, Injectable, InjectableScope, InjectableType, InjectionToken, inject } from "@navios/di";
1
+ import { E as hasControllerMetadata, S as hasModuleMetadata, T as getControllerMetadata, _ as EndpointAdapterToken, b as extractModuleMetadata, c as XmlStreamAdapterToken, d as Reply, f as NaviosOptionsToken, k as getEndpointMetadata, l as StreamAdapterToken, m as HttpAdapterToken, p as MultipartAdapterToken, u as Request, x as getModuleMetadata } from "./use-guards.decorator-CUww54Nt.mjs";
2
+ import { Container, Factory, Injectable, InjectableScope, InjectableType, InjectionToken, getInjectableToken, inject } from "@navios/di";
3
3
  import { env } from "node:process";
4
4
  import z, { z as z$1 } from "zod/v4";
5
5
  import { NaviosError } from "@navios/builder";
@@ -110,6 +110,15 @@ const isSymbol = (val) => typeof val === "symbol";
110
110
 
111
111
  //#endregion
112
112
  //#region src/stores/request-id.store.mts
113
+ let requestCounter = 0;
114
+ /**
115
+ * Generates a simple incremental request ID.
116
+ * Much faster than crypto.randomUUID() and sufficient for request tracking.
117
+ *
118
+ * @returns A unique request ID string (e.g., "req-1", "req-2", ...)
119
+ */ function generateRequestId() {
120
+ return `req-${++requestCounter}`;
121
+ }
113
122
  /**
114
123
  * AsyncLocalStorage store for the current request ID.
115
124
  *
@@ -129,22 +138,42 @@ const isSymbol = (val) => typeof val === "symbol";
129
138
  * // Get current request ID (returns undefined if not in a request context)
130
139
  * const currentId = getRequestId()
131
140
  * ```
132
- */ const requestIdStore = new AsyncLocalStorage();
141
+ */ let requestIdStore = null;
142
+ function getRequestIdStore() {
143
+ if (!requestIdStore) requestIdStore = new AsyncLocalStorage();
144
+ return requestIdStore;
145
+ }
146
+ /**
147
+ * Whether request ID propagation is enabled.
148
+ * When disabled, runWithRequestId is a pass-through for better performance.
149
+ */ let requestIdEnabled = false;
150
+ /**
151
+ * Enables or disables request ID propagation.
152
+ * Called by NaviosFactory based on the enableRequestId option.
153
+ *
154
+ * @param enabled - Whether to enable request ID propagation
155
+ */ function setRequestIdEnabled(enabled) {
156
+ requestIdEnabled = enabled;
157
+ }
133
158
  /**
134
159
  * Runs a function with a request ID in the async local storage context.
160
+ * If request ID propagation is disabled, the function is called directly
161
+ * without AsyncLocalStorage overhead.
135
162
  *
136
163
  * @param requestId - The request ID to set for this context
137
164
  * @param fn - The function to run within this context
138
165
  * @returns The return value of the function
139
166
  */ function runWithRequestId(requestId, fn) {
140
- return requestIdStore.run(requestId, fn);
167
+ if (!requestIdEnabled) return fn();
168
+ return getRequestIdStore().run(requestId, fn);
141
169
  }
142
170
  /**
143
171
  * Gets the current request ID from the async local storage context.
144
172
  *
145
173
  * @returns The current request ID, or undefined if not in a request context
146
174
  */ function getRequestId() {
147
- return requestIdStore.getStore();
175
+ if (!requestIdEnabled) return;
176
+ return getRequestIdStore().getStore();
148
177
  }
149
178
 
150
179
  //#endregion
@@ -172,7 +201,7 @@ const isSymbol = (val) => typeof val === "symbol";
172
201
 
173
202
  //#endregion
174
203
  //#region src/logger/console-logger.service.mts
175
- function applyDecs2203RFactory$13() {
204
+ function applyDecs2203RFactory$14() {
176
205
  function createAddInitializerMethod(initializers, decoratorFinishedRef) {
177
206
  return function addInitializer(initializer) {
178
207
  assertNotFinished(decoratorFinishedRef, "addInitializer");
@@ -446,10 +475,10 @@ function applyDecs2203RFactory$13() {
446
475
  };
447
476
  };
448
477
  }
449
- function _apply_decs_2203_r$13(targetClass, memberDecs, classDecs, parentClass) {
450
- return (_apply_decs_2203_r$13 = applyDecs2203RFactory$13())(targetClass, memberDecs, classDecs, parentClass);
478
+ function _apply_decs_2203_r$14(targetClass, memberDecs, classDecs, parentClass) {
479
+ return (_apply_decs_2203_r$14 = applyDecs2203RFactory$14())(targetClass, memberDecs, classDecs, parentClass);
451
480
  }
452
- var _dec$13, _initClass$13;
481
+ var _dec$14, _initClass$14;
453
482
  const DEFAULT_DEPTH = 5;
454
483
  const DEFAULT_LOG_LEVELS = [
455
484
  "log",
@@ -468,10 +497,10 @@ const dateTimeFormatter = new Intl.DateTimeFormat(void 0, {
468
497
  month: "2-digit"
469
498
  });
470
499
  let _ConsoleLogger;
471
- _dec$13 = Injectable({ token: LoggerOutput });
500
+ _dec$14 = Injectable({ token: LoggerOutput });
472
501
  var ConsoleLogger = class {
473
502
  static {
474
- ({c: [_ConsoleLogger, _initClass$13]} = _apply_decs_2203_r$13(this, [], [_dec$13]));
503
+ ({c: [_ConsoleLogger, _initClass$14]} = _apply_decs_2203_r$14(this, [], [_dec$14]));
475
504
  }
476
505
  /**
477
506
  * The options of the logger.
@@ -720,13 +749,13 @@ var ConsoleLogger = class {
720
749
  }
721
750
  }
722
751
  static {
723
- _initClass$13();
752
+ _initClass$14();
724
753
  }
725
754
  };
726
755
 
727
756
  //#endregion
728
757
  //#region src/logger/logger.service.mts
729
- function applyDecs2203RFactory$12() {
758
+ function applyDecs2203RFactory$13() {
730
759
  function createAddInitializerMethod(initializers, decoratorFinishedRef) {
731
760
  return function addInitializer(initializer) {
732
761
  assertNotFinished(decoratorFinishedRef, "addInitializer");
@@ -1000,15 +1029,15 @@ function applyDecs2203RFactory$12() {
1000
1029
  };
1001
1030
  };
1002
1031
  }
1003
- function _apply_decs_2203_r$12(targetClass, memberDecs, classDecs, parentClass) {
1004
- return (_apply_decs_2203_r$12 = applyDecs2203RFactory$12())(targetClass, memberDecs, classDecs, parentClass);
1032
+ function _apply_decs_2203_r$13(targetClass, memberDecs, classDecs, parentClass) {
1033
+ return (_apply_decs_2203_r$13 = applyDecs2203RFactory$13())(targetClass, memberDecs, classDecs, parentClass);
1005
1034
  }
1006
- var _dec$12, _initClass$12;
1035
+ var _dec$13, _initClass$13;
1007
1036
  let _LoggerInstance;
1008
- _dec$12 = Injectable({ token: Logger });
1037
+ _dec$13 = Injectable({ token: Logger });
1009
1038
  var LoggerInstance = class {
1010
1039
  static {
1011
- ({c: [_LoggerInstance, _initClass$12]} = _apply_decs_2203_r$12(this, [], [_dec$12]));
1040
+ ({c: [_LoggerInstance, _initClass$13]} = _apply_decs_2203_r$13(this, [], [_dec$13]));
1012
1041
  }
1013
1042
  constructor(config = {}) {
1014
1043
  this.context = config.context;
@@ -1021,8 +1050,6 @@ var LoggerInstance = class {
1021
1050
  }
1022
1051
  log(message, ...optionalParams) {
1023
1052
  optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1024
- console.log("log", message, optionalParams);
1025
- console.log("localInstance", this.localInstance);
1026
1053
  this.localInstance?.log(message, ...optionalParams);
1027
1054
  }
1028
1055
  warn(message, ...optionalParams) {
@@ -1042,13 +1069,13 @@ var LoggerInstance = class {
1042
1069
  this.localInstance?.fatal?.(message, ...optionalParams);
1043
1070
  }
1044
1071
  static {
1045
- _initClass$12();
1072
+ _initClass$13();
1046
1073
  }
1047
1074
  };
1048
1075
 
1049
1076
  //#endregion
1050
1077
  //#region src/config/config.service.mts
1051
- function applyDecs2203RFactory$11() {
1078
+ function applyDecs2203RFactory$12() {
1052
1079
  function createAddInitializerMethod(initializers, decoratorFinishedRef) {
1053
1080
  return function addInitializer(initializer) {
1054
1081
  assertNotFinished(decoratorFinishedRef, "addInitializer");
@@ -1322,10 +1349,10 @@ function applyDecs2203RFactory$11() {
1322
1349
  };
1323
1350
  };
1324
1351
  }
1325
- function _apply_decs_2203_r$11(targetClass, memberDecs, classDecs, parentClass) {
1326
- return (_apply_decs_2203_r$11 = applyDecs2203RFactory$11())(targetClass, memberDecs, classDecs, parentClass);
1352
+ function _apply_decs_2203_r$12(targetClass, memberDecs, classDecs, parentClass) {
1353
+ return (_apply_decs_2203_r$12 = applyDecs2203RFactory$12())(targetClass, memberDecs, classDecs, parentClass);
1327
1354
  }
1328
- var _dec$11, _initClass$11;
1355
+ var _dec$12, _initClass$12;
1329
1356
  /**
1330
1357
  * Schema for validating configuration service options.
1331
1358
  */ const ConfigServiceOptionsSchema = z$1.record(z$1.string(), z$1.unknown());
@@ -1333,11 +1360,11 @@ var _dec$11, _initClass$11;
1333
1360
  * Injection token for ConfigService.
1334
1361
  */ const ConfigServiceToken = InjectionToken.create(Symbol.for("ConfigService"), ConfigServiceOptionsSchema);
1335
1362
  let _ConfigService;
1336
- _dec$11 = Injectable({ token: ConfigServiceToken });
1363
+ _dec$12 = Injectable({ token: ConfigServiceToken });
1337
1364
  var ConfigService = class {
1338
1365
  config;
1339
1366
  static {
1340
- ({c: [_ConfigService, _initClass$11]} = _apply_decs_2203_r$11(this, [], [_dec$11]));
1367
+ ({c: [_ConfigService, _initClass$12]} = _apply_decs_2203_r$12(this, [], [_dec$12]));
1341
1368
  }
1342
1369
  /**
1343
1370
  * Creates a new ConfigService instance.
@@ -1419,7 +1446,7 @@ var ConfigService = class {
1419
1446
  return value;
1420
1447
  }
1421
1448
  static {
1422
- _initClass$11();
1449
+ _initClass$12();
1423
1450
  }
1424
1451
  };
1425
1452
 
@@ -1679,6 +1706,360 @@ var ConfigService = class {
1679
1706
  }
1680
1707
  };
1681
1708
 
1709
+ //#endregion
1710
+ //#region src/services/instance-resolver.service.mts
1711
+ function applyDecs2203RFactory$11() {
1712
+ function createAddInitializerMethod(initializers, decoratorFinishedRef) {
1713
+ return function addInitializer(initializer) {
1714
+ assertNotFinished(decoratorFinishedRef, "addInitializer");
1715
+ assertCallable(initializer, "An initializer");
1716
+ initializers.push(initializer);
1717
+ };
1718
+ }
1719
+ function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
1720
+ var kindStr;
1721
+ switch (kind) {
1722
+ case 1:
1723
+ kindStr = "accessor";
1724
+ break;
1725
+ case 2:
1726
+ kindStr = "method";
1727
+ break;
1728
+ case 3:
1729
+ kindStr = "getter";
1730
+ break;
1731
+ case 4:
1732
+ kindStr = "setter";
1733
+ break;
1734
+ default: kindStr = "field";
1735
+ }
1736
+ var ctx = {
1737
+ kind: kindStr,
1738
+ name: isPrivate ? "#" + name : name,
1739
+ static: isStatic,
1740
+ private: isPrivate,
1741
+ metadata
1742
+ };
1743
+ var decoratorFinishedRef = { v: false };
1744
+ ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
1745
+ var get, set;
1746
+ if (kind === 0) if (isPrivate) {
1747
+ get = desc.get;
1748
+ set = desc.set;
1749
+ } else {
1750
+ get = function() {
1751
+ return this[name];
1752
+ };
1753
+ set = function(v) {
1754
+ this[name] = v;
1755
+ };
1756
+ }
1757
+ else if (kind === 2) get = function() {
1758
+ return desc.value;
1759
+ };
1760
+ else {
1761
+ if (kind === 1 || kind === 3) get = function() {
1762
+ return desc.get.call(this);
1763
+ };
1764
+ if (kind === 1 || kind === 4) set = function(v) {
1765
+ desc.set.call(this, v);
1766
+ };
1767
+ }
1768
+ ctx.access = get && set ? {
1769
+ get,
1770
+ set
1771
+ } : get ? { get } : { set };
1772
+ try {
1773
+ return dec(value, ctx);
1774
+ } finally {
1775
+ decoratorFinishedRef.v = true;
1776
+ }
1777
+ }
1778
+ function assertNotFinished(decoratorFinishedRef, fnName) {
1779
+ if (decoratorFinishedRef.v) throw new Error("attempted to call " + fnName + " after decoration was finished");
1780
+ }
1781
+ function assertCallable(fn, hint) {
1782
+ if (typeof fn !== "function") throw new TypeError(hint + " must be a function");
1783
+ }
1784
+ function assertValidReturnValue(kind, value) {
1785
+ var type = typeof value;
1786
+ if (kind === 1) {
1787
+ if (type !== "object" || value === null) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
1788
+ if (value.get !== void 0) assertCallable(value.get, "accessor.get");
1789
+ if (value.set !== void 0) assertCallable(value.set, "accessor.set");
1790
+ if (value.init !== void 0) assertCallable(value.init, "accessor.init");
1791
+ } else if (type !== "function") {
1792
+ var hint;
1793
+ if (kind === 0) hint = "field";
1794
+ else if (kind === 10) hint = "class";
1795
+ else hint = "method";
1796
+ throw new TypeError(hint + " decorators must return a function or void 0");
1797
+ }
1798
+ }
1799
+ function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
1800
+ var decs = decInfo[0];
1801
+ var desc, init, value;
1802
+ if (isPrivate) if (kind === 0 || kind === 1) desc = {
1803
+ get: decInfo[3],
1804
+ set: decInfo[4]
1805
+ };
1806
+ else if (kind === 3) desc = { get: decInfo[3] };
1807
+ else if (kind === 4) desc = { set: decInfo[3] };
1808
+ else desc = { value: decInfo[3] };
1809
+ else if (kind !== 0) desc = Object.getOwnPropertyDescriptor(base, name);
1810
+ if (kind === 1) value = {
1811
+ get: desc.get,
1812
+ set: desc.set
1813
+ };
1814
+ else if (kind === 2) value = desc.value;
1815
+ else if (kind === 3) value = desc.get;
1816
+ else if (kind === 4) value = desc.set;
1817
+ var newValue, get, set;
1818
+ if (typeof decs === "function") {
1819
+ newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
1820
+ if (newValue !== void 0) {
1821
+ assertValidReturnValue(kind, newValue);
1822
+ if (kind === 0) init = newValue;
1823
+ else if (kind === 1) {
1824
+ init = newValue.init;
1825
+ get = newValue.get || value.get;
1826
+ set = newValue.set || value.set;
1827
+ value = {
1828
+ get,
1829
+ set
1830
+ };
1831
+ } else value = newValue;
1832
+ }
1833
+ } else for (var i = decs.length - 1; i >= 0; i--) {
1834
+ var dec = decs[i];
1835
+ newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
1836
+ if (newValue !== void 0) {
1837
+ assertValidReturnValue(kind, newValue);
1838
+ var newInit;
1839
+ if (kind === 0) newInit = newValue;
1840
+ else if (kind === 1) {
1841
+ newInit = newValue.init;
1842
+ get = newValue.get || value.get;
1843
+ set = newValue.set || value.set;
1844
+ value = {
1845
+ get,
1846
+ set
1847
+ };
1848
+ } else value = newValue;
1849
+ if (newInit !== void 0) if (init === void 0) init = newInit;
1850
+ else if (typeof init === "function") init = [init, newInit];
1851
+ else init.push(newInit);
1852
+ }
1853
+ }
1854
+ if (kind === 0 || kind === 1) {
1855
+ if (init === void 0) init = function(instance, init$1) {
1856
+ return init$1;
1857
+ };
1858
+ else if (typeof init !== "function") {
1859
+ var ownInitializers = init;
1860
+ init = function(instance, init$1) {
1861
+ var value$1 = init$1;
1862
+ for (var i$1 = 0; i$1 < ownInitializers.length; i$1++) value$1 = ownInitializers[i$1].call(instance, value$1);
1863
+ return value$1;
1864
+ };
1865
+ } else {
1866
+ var originalInitializer = init;
1867
+ init = function(instance, init$1) {
1868
+ return originalInitializer.call(instance, init$1);
1869
+ };
1870
+ }
1871
+ ret.push(init);
1872
+ }
1873
+ if (kind !== 0) {
1874
+ if (kind === 1) {
1875
+ desc.get = value.get;
1876
+ desc.set = value.set;
1877
+ } else if (kind === 2) desc.value = value;
1878
+ else if (kind === 3) desc.get = value;
1879
+ else if (kind === 4) desc.set = value;
1880
+ if (isPrivate) if (kind === 1) {
1881
+ ret.push(function(instance, args) {
1882
+ return value.get.call(instance, args);
1883
+ });
1884
+ ret.push(function(instance, args) {
1885
+ return value.set.call(instance, args);
1886
+ });
1887
+ } else if (kind === 2) ret.push(value);
1888
+ else ret.push(function(instance, args) {
1889
+ return value.call(instance, args);
1890
+ });
1891
+ else Object.defineProperty(base, name, desc);
1892
+ }
1893
+ }
1894
+ function applyMemberDecs(Class, decInfos, metadata) {
1895
+ var ret = [];
1896
+ var protoInitializers;
1897
+ var staticInitializers;
1898
+ var existingProtoNonFields = /* @__PURE__ */ new Map();
1899
+ var existingStaticNonFields = /* @__PURE__ */ new Map();
1900
+ for (var i = 0; i < decInfos.length; i++) {
1901
+ var decInfo = decInfos[i];
1902
+ if (!Array.isArray(decInfo)) continue;
1903
+ var kind = decInfo[1];
1904
+ var name = decInfo[2];
1905
+ var isPrivate = decInfo.length > 3;
1906
+ var isStatic = kind >= 5;
1907
+ var base;
1908
+ var initializers;
1909
+ if (isStatic) {
1910
+ base = Class;
1911
+ kind = kind - 5;
1912
+ staticInitializers = staticInitializers || [];
1913
+ initializers = staticInitializers;
1914
+ } else {
1915
+ base = Class.prototype;
1916
+ protoInitializers = protoInitializers || [];
1917
+ initializers = protoInitializers;
1918
+ }
1919
+ if (kind !== 0 && !isPrivate) {
1920
+ var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
1921
+ var existingKind = existingNonFields.get(name) || 0;
1922
+ 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);
1923
+ else if (!existingKind && kind > 2) existingNonFields.set(name, kind);
1924
+ else existingNonFields.set(name, true);
1925
+ }
1926
+ applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
1927
+ }
1928
+ pushInitializers(ret, protoInitializers);
1929
+ pushInitializers(ret, staticInitializers);
1930
+ return ret;
1931
+ }
1932
+ function pushInitializers(ret, initializers) {
1933
+ if (initializers) ret.push(function(instance) {
1934
+ for (var i = 0; i < initializers.length; i++) initializers[i].call(instance);
1935
+ return instance;
1936
+ });
1937
+ }
1938
+ function applyClassDecs(targetClass, classDecs, metadata) {
1939
+ if (classDecs.length > 0) {
1940
+ var initializers = [];
1941
+ var newClass = targetClass;
1942
+ var name = targetClass.name;
1943
+ for (var i = classDecs.length - 1; i >= 0; i--) {
1944
+ var decoratorFinishedRef = { v: false };
1945
+ try {
1946
+ var nextNewClass = classDecs[i](newClass, {
1947
+ kind: "class",
1948
+ name,
1949
+ addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
1950
+ metadata
1951
+ });
1952
+ } finally {
1953
+ decoratorFinishedRef.v = true;
1954
+ }
1955
+ if (nextNewClass !== void 0) {
1956
+ assertValidReturnValue(10, nextNewClass);
1957
+ newClass = nextNewClass;
1958
+ }
1959
+ }
1960
+ return [defineMetadata(newClass, metadata), function() {
1961
+ for (var i$1 = 0; i$1 < initializers.length; i$1++) initializers[i$1].call(newClass);
1962
+ }];
1963
+ }
1964
+ }
1965
+ function defineMetadata(Class, metadata) {
1966
+ return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
1967
+ configurable: true,
1968
+ enumerable: true,
1969
+ value: metadata
1970
+ });
1971
+ }
1972
+ return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
1973
+ if (parentClass !== void 0) var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
1974
+ var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
1975
+ var e = applyMemberDecs(targetClass, memberDecs, metadata);
1976
+ if (!classDecs.length) defineMetadata(targetClass, metadata);
1977
+ return {
1978
+ e,
1979
+ get c() {
1980
+ return applyClassDecs(targetClass, classDecs, metadata);
1981
+ }
1982
+ };
1983
+ };
1984
+ }
1985
+ function _apply_decs_2203_r$11(targetClass, memberDecs, classDecs, parentClass) {
1986
+ return (_apply_decs_2203_r$11 = applyDecs2203RFactory$11())(targetClass, memberDecs, classDecs, parentClass);
1987
+ }
1988
+ var _dec$11, _initClass$11;
1989
+ let _InstanceResolverService;
1990
+ _dec$11 = Injectable();
1991
+ var InstanceResolverService = class {
1992
+ static {
1993
+ ({c: [_InstanceResolverService, _initClass$11]} = _apply_decs_2203_r$11(this, [], [_dec$11]));
1994
+ }
1995
+ container = inject(Container);
1996
+ /**
1997
+ * Attempts to resolve a class instance, automatically detecting if it needs
1998
+ * request scope based on its dependencies.
1999
+ *
2000
+ * @param classType - The class to resolve
2001
+ * @returns A resolution result containing either a cached instance or resolver function
2002
+ */ async resolve(classType) {
2003
+ let cachedInstance = null;
2004
+ try {
2005
+ cachedInstance = await this.container.get(classType);
2006
+ } catch {
2007
+ const token = getInjectableToken(classType);
2008
+ this.container.getRegistry().updateScope(token, InjectableScope.Request);
2009
+ }
2010
+ return {
2011
+ cached: cachedInstance !== null,
2012
+ instance: cachedInstance,
2013
+ resolve: (scoped) => scoped.get(classType)
2014
+ };
2015
+ }
2016
+ /**
2017
+ * Attempts to resolve multiple class instances, automatically detecting if any need
2018
+ * request scope based on their dependencies.
2019
+ *
2020
+ * Returns `cached: true` only if ALL classes can be resolved as singletons.
2021
+ * If any class has request-scoped dependencies, returns `cached: false`.
2022
+ *
2023
+ * @param classTypes - The classes to resolve
2024
+ * @returns A resolution result containing either all cached instances or resolver function
2025
+ */ async resolveMany(classTypes) {
2026
+ if (classTypes.length === 0) return {
2027
+ cached: true,
2028
+ instances: [],
2029
+ classTypes: [],
2030
+ resolve: async () => []
2031
+ };
2032
+ const results = await Promise.all(classTypes.map(async (classType) => {
2033
+ try {
2034
+ return {
2035
+ success: true,
2036
+ instance: await this.container.get(classType)
2037
+ };
2038
+ } catch {
2039
+ const token = getInjectableToken(classType);
2040
+ this.container.getRegistry().updateScope(token, InjectableScope.Request);
2041
+ return {
2042
+ success: false,
2043
+ instance: null
2044
+ };
2045
+ }
2046
+ }));
2047
+ const allCached = results.every((r) => r.success);
2048
+ return {
2049
+ cached: allCached,
2050
+ instances: allCached ? results.map((r) => r.instance) : null,
2051
+ classTypes,
2052
+ resolve: (scoped) => Promise.all(classTypes.map((classType) => scoped.get(classType)))
2053
+ };
2054
+ }
2055
+ static {
2056
+ _initClass$11();
2057
+ }
2058
+ };
2059
+ /**
2060
+ * @deprecated Use InstanceResolverService instead
2061
+ */ const ControllerResolverService = _InstanceResolverService;
2062
+
1682
2063
  //#endregion
1683
2064
  //#region src/services/guard-runner.service.mts
1684
2065
  function applyDecs2203RFactory$10() {
@@ -1966,23 +2347,40 @@ var GuardRunnerService = class {
1966
2347
  ({c: [_GuardRunnerService, _initClass$10]} = _apply_decs_2203_r$10(this, [], [_dec$10]));
1967
2348
  }
1968
2349
  logger = inject(Logger, { context: _GuardRunnerService.name });
1969
- async runGuards(allGuards, executionContext, context) {
1970
- let canActivate = true;
1971
- for (const guard of Array.from(allGuards).reverse()) {
2350
+ /**
2351
+ * Runs guards that need to be resolved from a scoped container.
2352
+ * Use this when guards have request-scoped dependencies.
2353
+ */ async runGuards(allGuards, executionContext, context) {
2354
+ const guardsArray = Array.from(allGuards).reverse();
2355
+ const guardInstances = await Promise.all(guardsArray.map(async (guard) => {
1972
2356
  const guardInstance = await context.get(guard);
1973
2357
  if (!guardInstance.canActivate) throw new Error(`[Navios] Guard ${guard.name} does not implement canActivate()`);
1974
- try {
1975
- canActivate = await guardInstance.canActivate(executionContext);
1976
- if (!canActivate) break;
1977
- } catch (error) {
1978
- if (error instanceof HttpException) {
1979
- executionContext.getReply().status(error.statusCode).send(error.response);
1980
- return false;
1981
- } else {
1982
- this.logger.error("Error running guard", error);
1983
- executionContext.getReply().status(500).send({ message: "Internal server error" });
1984
- return false;
1985
- }
2358
+ return guardInstance;
2359
+ }));
2360
+ return this.executeGuards(guardInstances, executionContext);
2361
+ }
2362
+ /**
2363
+ * Runs pre-resolved guard instances.
2364
+ * Use this when all guards are singletons and have been pre-resolved at startup.
2365
+ */ async runGuardsStatic(guardInstances, executionContext) {
2366
+ return this.executeGuards(guardInstances, executionContext);
2367
+ }
2368
+ /**
2369
+ * Shared guard execution logic.
2370
+ * Iterates through guard instances and calls canActivate on each.
2371
+ */ async executeGuards(guardInstances, executionContext) {
2372
+ let canActivate = true;
2373
+ for (const guardInstance of guardInstances) try {
2374
+ canActivate = await guardInstance.canActivate(executionContext);
2375
+ if (!canActivate) break;
2376
+ } catch (error) {
2377
+ if (error instanceof HttpException) {
2378
+ executionContext.getReply().status(error.statusCode).send(error.response);
2379
+ return false;
2380
+ } else {
2381
+ this.logger.error("Error running guard", error);
2382
+ executionContext.getReply().status(500).send({ message: "Internal server error" });
2383
+ return false;
1986
2384
  }
1987
2385
  }
1988
2386
  if (!canActivate) {
@@ -5416,6 +5814,8 @@ var NaviosApplication = class {
5416
5814
  * ```
5417
5815
  */ static async create(appModule, options = { adapter: [] }) {
5418
5816
  const container = options.container ?? new Container();
5817
+ if (options.enableRequestId === true) setRequestIdEnabled(true);
5818
+ container.getServiceLocator().getManager().storeCreatedHolder(NaviosOptionsToken.toString(), options, InjectableType.Class, InjectableScope.Singleton);
5419
5819
  await this.registerLoggerConfiguration(container, options);
5420
5820
  const adapters = Array.isArray(options.adapter) ? options.adapter : [options.adapter];
5421
5821
  for (const adapter of adapters) await this.registerEnvironment(container, adapter);
@@ -5439,5 +5839,5 @@ var NaviosApplication = class {
5439
5839
  };
5440
5840
 
5441
5841
  //#endregion
5442
- export { envInt as $, loggerOptionsSchema as A, isObject as B, ConfigServiceOptionsSchema as C, _ConsoleLogger as D, _LoggerInstance as E, isConstructor as F, normalizePath as G, isString as H, isEmpty as I, filterLogLevels as J, stripEndSlash as K, isFunction as L, requestIdStore as M, runWithRequestId as N, Logger as O, addLeadingSlash as P, yellow as Q, isNil as R, provideConfig as S, _ConfigService as T, isSymbol as U, isPlainObject as V, isUndefined as W, LOG_LEVELS as X, isLogLevel as Y, clc as Z, ForbiddenException as _, _ReplyFactory as a, ConfigProviderOptions as b, _HttpAdapterFactory as c, _ModuleLoaderService as d, envString as et, _GuardRunnerService as f, InternalServerErrorException as g, NotFoundException as h, _StreamAdapterFactory as i, getRequestId as j, LoggerOutput as k, _EndpointAdapterFactory as l, UnauthorizedException as m, _NaviosApplication as n, _RequestFactory as o, ConflictException as p, isLogLevelEnabled as q, _XmlStreamAdapterFactory as r, _MultipartAdapterFactory as s, NaviosFactory as t, AttributeFactory as u, BadRequestException as v, ConfigServiceToken as w, EnvConfigProvider as x, HttpException as y, isNumber as z };
5443
- //# sourceMappingURL=src-DyvCDuKO.mjs.map
5842
+ export { LOG_LEVELS as $, Logger as A, isFunction as B, EnvConfigProvider as C, _ConfigService as D, ConfigServiceToken as E, runWithRequestId as F, isString as G, isNumber as H, setRequestIdEnabled as I, normalizePath as J, isSymbol as K, addLeadingSlash as L, loggerOptionsSchema as M, generateRequestId as N, _LoggerInstance as O, getRequestId as P, isLogLevel as Q, isConstructor as R, ConfigProviderOptions as S, ConfigServiceOptionsSchema as T, isObject as U, isNil as V, isPlainObject as W, isLogLevelEnabled as X, stripEndSlash as Y, filterLogLevels as Z, NotFoundException as _, _ReplyFactory as a, BadRequestException as b, _HttpAdapterFactory as c, _ModuleLoaderService as d, clc as et, _GuardRunnerService as f, UnauthorizedException as g, ConflictException as h, _StreamAdapterFactory as i, LoggerOutput as j, _ConsoleLogger as k, _EndpointAdapterFactory as l, _InstanceResolverService as m, _NaviosApplication as n, envInt as nt, _RequestFactory as o, ControllerResolverService as p, isUndefined as q, _XmlStreamAdapterFactory as r, envString as rt, _MultipartAdapterFactory as s, NaviosFactory as t, yellow as tt, AttributeFactory as u, InternalServerErrorException as v, provideConfig as w, HttpException as x, ForbiddenException as y, isEmpty as z };
5843
+ //# sourceMappingURL=src-gBAChVRL.mjs.map