@navios/core 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/CHANGELOG.md +78 -0
- package/lib/{index-DW9EPAE6.d.mts → index-D9MNh6Tx.d.mts} +534 -342
- package/lib/index-D9MNh6Tx.d.mts.map +1 -0
- package/lib/{index-pHp-dIGt.d.cts → index-Db1d3cwD.d.cts} +534 -342
- package/lib/index-Db1d3cwD.d.cts.map +1 -0
- package/lib/index.cjs +12 -3
- package/lib/index.d.cts +2 -2
- package/lib/index.d.mts +2 -2
- package/lib/index.mjs +3 -3
- package/lib/legacy-compat/index.cjs +1 -1
- package/lib/legacy-compat/index.cjs.map +1 -1
- package/lib/legacy-compat/index.d.cts +3 -3
- package/lib/legacy-compat/index.d.cts.map +1 -1
- package/lib/legacy-compat/index.d.mts +3 -3
- package/lib/legacy-compat/index.d.mts.map +1 -1
- package/lib/legacy-compat/index.mjs +1 -1
- package/lib/legacy-compat/index.mjs.map +1 -1
- package/lib/{src-QnxR5b7c.cjs → src-BRPtJ9fG.cjs} +474 -53
- package/lib/src-BRPtJ9fG.cjs.map +1 -0
- package/lib/{src-DyvCDuKO.mjs → src-Bo23RIo-.mjs} +454 -51
- package/lib/src-Bo23RIo-.mjs.map +1 -0
- package/lib/testing/index.cjs +346 -29
- package/lib/testing/index.cjs.map +1 -1
- package/lib/testing/index.d.cts +299 -63
- package/lib/testing/index.d.cts.map +1 -1
- package/lib/testing/index.d.mts +299 -63
- package/lib/testing/index.d.mts.map +1 -1
- package/lib/testing/index.mjs +347 -31
- package/lib/testing/index.mjs.map +1 -1
- package/lib/{use-guards.decorator-B6q_N0sf.cjs → use-guards.decorator-Bs8oDHOi.cjs} +29 -99
- package/lib/use-guards.decorator-Bs8oDHOi.cjs.map +1 -0
- package/lib/{use-guards.decorator-kZ3lNK8v.mjs → use-guards.decorator-CzVXuLkz.mjs} +23 -99
- package/lib/use-guards.decorator-CzVXuLkz.mjs.map +1 -0
- package/package.json +4 -4
- package/src/__tests__/controller-resolver.spec.mts +229 -0
- package/src/__tests__/controller.spec.mts +1 -1
- package/src/__tests__/testing-module.spec.mts +459 -0
- package/src/__tests__/unit-testing-module.spec.mts +424 -0
- package/src/decorators/controller.decorator.mts +29 -7
- package/src/decorators/endpoint.decorator.mts +60 -12
- package/src/decorators/module.decorator.mts +23 -5
- package/src/decorators/multipart.decorator.mts +67 -24
- package/src/decorators/stream.decorator.mts +65 -24
- package/src/interfaces/abstract-http-handler-adapter.interface.mts +31 -1
- package/src/legacy-compat/__type-tests__/legacy-decorators.spec-d.mts +2 -6
- package/src/legacy-compat/decorators/endpoint.decorator.mts +1 -1
- package/src/legacy-compat/decorators/multipart.decorator.mts +5 -5
- package/src/legacy-compat/decorators/stream.decorator.mts +5 -5
- package/src/logger/logger.service.mts +0 -2
- package/src/navios.application.mts +23 -9
- package/src/navios.environment.mts +3 -1
- package/src/navios.factory.mts +19 -18
- package/src/services/guard-runner.service.mts +46 -9
- package/src/services/index.mts +1 -0
- package/src/services/instance-resolver.service.mts +187 -0
- package/src/services/module-loader.service.mts +3 -2
- package/src/stores/request-id.store.mts +45 -3
- package/src/testing/index.mts +1 -0
- package/src/testing/testing-module.mts +255 -93
- package/src/testing/unit-testing-module.mts +298 -0
- package/src/tokens/index.mts +1 -0
- package/src/tokens/navios-options.token.mts +6 -0
- package/lib/index-DW9EPAE6.d.mts.map +0 -1
- package/lib/index-pHp-dIGt.d.cts.map +0 -1
- package/lib/src-DyvCDuKO.mjs.map +0 -1
- package/lib/src-QnxR5b7c.cjs.map +0 -1
- package/lib/use-guards.decorator-B6q_N0sf.cjs.map +0 -1
- package/lib/use-guards.decorator-kZ3lNK8v.mjs.map +0 -1
|
@@ -25,7 +25,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
25
|
}) : target, mod));
|
|
26
26
|
|
|
27
27
|
//#endregion
|
|
28
|
-
const require_use_guards_decorator = require('./use-guards.decorator-
|
|
28
|
+
const require_use_guards_decorator = require('./use-guards.decorator-Bs8oDHOi.cjs');
|
|
29
29
|
let _navios_di = require("@navios/di");
|
|
30
30
|
let node_process = require("node:process");
|
|
31
31
|
let zod_v4 = require("zod/v4");
|
|
@@ -138,6 +138,15 @@ const isSymbol = (val) => typeof val === "symbol";
|
|
|
138
138
|
|
|
139
139
|
//#endregion
|
|
140
140
|
//#region src/stores/request-id.store.mts
|
|
141
|
+
let requestCounter = 0;
|
|
142
|
+
/**
|
|
143
|
+
* Generates a simple incremental request ID.
|
|
144
|
+
* Much faster than crypto.randomUUID() and sufficient for request tracking.
|
|
145
|
+
*
|
|
146
|
+
* @returns A unique request ID string (e.g., "req-1", "req-2", ...)
|
|
147
|
+
*/ function generateRequestId() {
|
|
148
|
+
return `req-${++requestCounter}`;
|
|
149
|
+
}
|
|
141
150
|
/**
|
|
142
151
|
* AsyncLocalStorage store for the current request ID.
|
|
143
152
|
*
|
|
@@ -157,22 +166,42 @@ const isSymbol = (val) => typeof val === "symbol";
|
|
|
157
166
|
* // Get current request ID (returns undefined if not in a request context)
|
|
158
167
|
* const currentId = getRequestId()
|
|
159
168
|
* ```
|
|
160
|
-
*/
|
|
169
|
+
*/ let requestIdStore = null;
|
|
170
|
+
function getRequestIdStore() {
|
|
171
|
+
if (!requestIdStore) requestIdStore = new node_async_hooks.AsyncLocalStorage();
|
|
172
|
+
return requestIdStore;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Whether request ID propagation is enabled.
|
|
176
|
+
* When disabled, runWithRequestId is a pass-through for better performance.
|
|
177
|
+
*/ let requestIdEnabled = false;
|
|
178
|
+
/**
|
|
179
|
+
* Enables or disables request ID propagation.
|
|
180
|
+
* Called by NaviosFactory based on the enableRequestId option.
|
|
181
|
+
*
|
|
182
|
+
* @param enabled - Whether to enable request ID propagation
|
|
183
|
+
*/ function setRequestIdEnabled(enabled) {
|
|
184
|
+
requestIdEnabled = enabled;
|
|
185
|
+
}
|
|
161
186
|
/**
|
|
162
187
|
* Runs a function with a request ID in the async local storage context.
|
|
188
|
+
* If request ID propagation is disabled, the function is called directly
|
|
189
|
+
* without AsyncLocalStorage overhead.
|
|
163
190
|
*
|
|
164
191
|
* @param requestId - The request ID to set for this context
|
|
165
192
|
* @param fn - The function to run within this context
|
|
166
193
|
* @returns The return value of the function
|
|
167
194
|
*/ function runWithRequestId(requestId, fn) {
|
|
168
|
-
|
|
195
|
+
if (!requestIdEnabled) return fn();
|
|
196
|
+
return getRequestIdStore().run(requestId, fn);
|
|
169
197
|
}
|
|
170
198
|
/**
|
|
171
199
|
* Gets the current request ID from the async local storage context.
|
|
172
200
|
*
|
|
173
201
|
* @returns The current request ID, or undefined if not in a request context
|
|
174
202
|
*/ function getRequestId() {
|
|
175
|
-
|
|
203
|
+
if (!requestIdEnabled) return;
|
|
204
|
+
return getRequestIdStore().getStore();
|
|
176
205
|
}
|
|
177
206
|
|
|
178
207
|
//#endregion
|
|
@@ -200,7 +229,7 @@ const isSymbol = (val) => typeof val === "symbol";
|
|
|
200
229
|
|
|
201
230
|
//#endregion
|
|
202
231
|
//#region src/logger/console-logger.service.mts
|
|
203
|
-
function applyDecs2203RFactory$
|
|
232
|
+
function applyDecs2203RFactory$14() {
|
|
204
233
|
function createAddInitializerMethod(initializers, decoratorFinishedRef) {
|
|
205
234
|
return function addInitializer(initializer) {
|
|
206
235
|
assertNotFinished(decoratorFinishedRef, "addInitializer");
|
|
@@ -474,10 +503,10 @@ function applyDecs2203RFactory$13() {
|
|
|
474
503
|
};
|
|
475
504
|
};
|
|
476
505
|
}
|
|
477
|
-
function _apply_decs_2203_r$
|
|
478
|
-
return (_apply_decs_2203_r$
|
|
506
|
+
function _apply_decs_2203_r$14(targetClass, memberDecs, classDecs, parentClass) {
|
|
507
|
+
return (_apply_decs_2203_r$14 = applyDecs2203RFactory$14())(targetClass, memberDecs, classDecs, parentClass);
|
|
479
508
|
}
|
|
480
|
-
var _dec$
|
|
509
|
+
var _dec$14, _initClass$14;
|
|
481
510
|
const DEFAULT_DEPTH = 5;
|
|
482
511
|
const DEFAULT_LOG_LEVELS = [
|
|
483
512
|
"log",
|
|
@@ -496,10 +525,10 @@ const dateTimeFormatter = new Intl.DateTimeFormat(void 0, {
|
|
|
496
525
|
month: "2-digit"
|
|
497
526
|
});
|
|
498
527
|
let _ConsoleLogger;
|
|
499
|
-
_dec$
|
|
528
|
+
_dec$14 = (0, _navios_di.Injectable)({ token: LoggerOutput });
|
|
500
529
|
var ConsoleLogger = class {
|
|
501
530
|
static {
|
|
502
|
-
({c: [_ConsoleLogger, _initClass$
|
|
531
|
+
({c: [_ConsoleLogger, _initClass$14]} = _apply_decs_2203_r$14(this, [], [_dec$14]));
|
|
503
532
|
}
|
|
504
533
|
/**
|
|
505
534
|
* The options of the logger.
|
|
@@ -748,13 +777,13 @@ var ConsoleLogger = class {
|
|
|
748
777
|
}
|
|
749
778
|
}
|
|
750
779
|
static {
|
|
751
|
-
_initClass$
|
|
780
|
+
_initClass$14();
|
|
752
781
|
}
|
|
753
782
|
};
|
|
754
783
|
|
|
755
784
|
//#endregion
|
|
756
785
|
//#region src/logger/logger.service.mts
|
|
757
|
-
function applyDecs2203RFactory$
|
|
786
|
+
function applyDecs2203RFactory$13() {
|
|
758
787
|
function createAddInitializerMethod(initializers, decoratorFinishedRef) {
|
|
759
788
|
return function addInitializer(initializer) {
|
|
760
789
|
assertNotFinished(decoratorFinishedRef, "addInitializer");
|
|
@@ -1028,15 +1057,15 @@ function applyDecs2203RFactory$12() {
|
|
|
1028
1057
|
};
|
|
1029
1058
|
};
|
|
1030
1059
|
}
|
|
1031
|
-
function _apply_decs_2203_r$
|
|
1032
|
-
return (_apply_decs_2203_r$
|
|
1060
|
+
function _apply_decs_2203_r$13(targetClass, memberDecs, classDecs, parentClass) {
|
|
1061
|
+
return (_apply_decs_2203_r$13 = applyDecs2203RFactory$13())(targetClass, memberDecs, classDecs, parentClass);
|
|
1033
1062
|
}
|
|
1034
|
-
var _dec$
|
|
1063
|
+
var _dec$13, _initClass$13;
|
|
1035
1064
|
let _LoggerInstance;
|
|
1036
|
-
_dec$
|
|
1065
|
+
_dec$13 = (0, _navios_di.Injectable)({ token: Logger });
|
|
1037
1066
|
var LoggerInstance = class {
|
|
1038
1067
|
static {
|
|
1039
|
-
({c: [_LoggerInstance, _initClass$
|
|
1068
|
+
({c: [_LoggerInstance, _initClass$13]} = _apply_decs_2203_r$13(this, [], [_dec$13]));
|
|
1040
1069
|
}
|
|
1041
1070
|
constructor(config = {}) {
|
|
1042
1071
|
this.context = config.context;
|
|
@@ -1049,8 +1078,6 @@ var LoggerInstance = class {
|
|
|
1049
1078
|
}
|
|
1050
1079
|
log(message, ...optionalParams) {
|
|
1051
1080
|
optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
|
|
1052
|
-
console.log("log", message, optionalParams);
|
|
1053
|
-
console.log("localInstance", this.localInstance);
|
|
1054
1081
|
this.localInstance?.log(message, ...optionalParams);
|
|
1055
1082
|
}
|
|
1056
1083
|
warn(message, ...optionalParams) {
|
|
@@ -1070,13 +1097,13 @@ var LoggerInstance = class {
|
|
|
1070
1097
|
this.localInstance?.fatal?.(message, ...optionalParams);
|
|
1071
1098
|
}
|
|
1072
1099
|
static {
|
|
1073
|
-
_initClass$
|
|
1100
|
+
_initClass$13();
|
|
1074
1101
|
}
|
|
1075
1102
|
};
|
|
1076
1103
|
|
|
1077
1104
|
//#endregion
|
|
1078
1105
|
//#region src/config/config.service.mts
|
|
1079
|
-
function applyDecs2203RFactory$
|
|
1106
|
+
function applyDecs2203RFactory$12() {
|
|
1080
1107
|
function createAddInitializerMethod(initializers, decoratorFinishedRef) {
|
|
1081
1108
|
return function addInitializer(initializer) {
|
|
1082
1109
|
assertNotFinished(decoratorFinishedRef, "addInitializer");
|
|
@@ -1350,10 +1377,10 @@ function applyDecs2203RFactory$11() {
|
|
|
1350
1377
|
};
|
|
1351
1378
|
};
|
|
1352
1379
|
}
|
|
1353
|
-
function _apply_decs_2203_r$
|
|
1354
|
-
return (_apply_decs_2203_r$
|
|
1380
|
+
function _apply_decs_2203_r$12(targetClass, memberDecs, classDecs, parentClass) {
|
|
1381
|
+
return (_apply_decs_2203_r$12 = applyDecs2203RFactory$12())(targetClass, memberDecs, classDecs, parentClass);
|
|
1355
1382
|
}
|
|
1356
|
-
var _dec$
|
|
1383
|
+
var _dec$12, _initClass$12;
|
|
1357
1384
|
/**
|
|
1358
1385
|
* Schema for validating configuration service options.
|
|
1359
1386
|
*/ const ConfigServiceOptionsSchema = zod_v4.z.record(zod_v4.z.string(), zod_v4.z.unknown());
|
|
@@ -1361,11 +1388,11 @@ var _dec$11, _initClass$11;
|
|
|
1361
1388
|
* Injection token for ConfigService.
|
|
1362
1389
|
*/ const ConfigServiceToken = _navios_di.InjectionToken.create(Symbol.for("ConfigService"), ConfigServiceOptionsSchema);
|
|
1363
1390
|
let _ConfigService;
|
|
1364
|
-
_dec$
|
|
1391
|
+
_dec$12 = (0, _navios_di.Injectable)({ token: ConfigServiceToken });
|
|
1365
1392
|
var ConfigService = class {
|
|
1366
1393
|
config;
|
|
1367
1394
|
static {
|
|
1368
|
-
({c: [_ConfigService, _initClass$
|
|
1395
|
+
({c: [_ConfigService, _initClass$12]} = _apply_decs_2203_r$12(this, [], [_dec$12]));
|
|
1369
1396
|
}
|
|
1370
1397
|
/**
|
|
1371
1398
|
* Creates a new ConfigService instance.
|
|
@@ -1447,7 +1474,7 @@ var ConfigService = class {
|
|
|
1447
1474
|
return value;
|
|
1448
1475
|
}
|
|
1449
1476
|
static {
|
|
1450
|
-
_initClass$
|
|
1477
|
+
_initClass$12();
|
|
1451
1478
|
}
|
|
1452
1479
|
};
|
|
1453
1480
|
|
|
@@ -1707,6 +1734,360 @@ var ConfigService = class {
|
|
|
1707
1734
|
}
|
|
1708
1735
|
};
|
|
1709
1736
|
|
|
1737
|
+
//#endregion
|
|
1738
|
+
//#region src/services/instance-resolver.service.mts
|
|
1739
|
+
function applyDecs2203RFactory$11() {
|
|
1740
|
+
function createAddInitializerMethod(initializers, decoratorFinishedRef) {
|
|
1741
|
+
return function addInitializer(initializer) {
|
|
1742
|
+
assertNotFinished(decoratorFinishedRef, "addInitializer");
|
|
1743
|
+
assertCallable(initializer, "An initializer");
|
|
1744
|
+
initializers.push(initializer);
|
|
1745
|
+
};
|
|
1746
|
+
}
|
|
1747
|
+
function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
|
|
1748
|
+
var kindStr;
|
|
1749
|
+
switch (kind) {
|
|
1750
|
+
case 1:
|
|
1751
|
+
kindStr = "accessor";
|
|
1752
|
+
break;
|
|
1753
|
+
case 2:
|
|
1754
|
+
kindStr = "method";
|
|
1755
|
+
break;
|
|
1756
|
+
case 3:
|
|
1757
|
+
kindStr = "getter";
|
|
1758
|
+
break;
|
|
1759
|
+
case 4:
|
|
1760
|
+
kindStr = "setter";
|
|
1761
|
+
break;
|
|
1762
|
+
default: kindStr = "field";
|
|
1763
|
+
}
|
|
1764
|
+
var ctx = {
|
|
1765
|
+
kind: kindStr,
|
|
1766
|
+
name: isPrivate ? "#" + name : name,
|
|
1767
|
+
static: isStatic,
|
|
1768
|
+
private: isPrivate,
|
|
1769
|
+
metadata
|
|
1770
|
+
};
|
|
1771
|
+
var decoratorFinishedRef = { v: false };
|
|
1772
|
+
ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
|
|
1773
|
+
var get, set;
|
|
1774
|
+
if (kind === 0) if (isPrivate) {
|
|
1775
|
+
get = desc.get;
|
|
1776
|
+
set = desc.set;
|
|
1777
|
+
} else {
|
|
1778
|
+
get = function() {
|
|
1779
|
+
return this[name];
|
|
1780
|
+
};
|
|
1781
|
+
set = function(v) {
|
|
1782
|
+
this[name] = v;
|
|
1783
|
+
};
|
|
1784
|
+
}
|
|
1785
|
+
else if (kind === 2) get = function() {
|
|
1786
|
+
return desc.value;
|
|
1787
|
+
};
|
|
1788
|
+
else {
|
|
1789
|
+
if (kind === 1 || kind === 3) get = function() {
|
|
1790
|
+
return desc.get.call(this);
|
|
1791
|
+
};
|
|
1792
|
+
if (kind === 1 || kind === 4) set = function(v) {
|
|
1793
|
+
desc.set.call(this, v);
|
|
1794
|
+
};
|
|
1795
|
+
}
|
|
1796
|
+
ctx.access = get && set ? {
|
|
1797
|
+
get,
|
|
1798
|
+
set
|
|
1799
|
+
} : get ? { get } : { set };
|
|
1800
|
+
try {
|
|
1801
|
+
return dec(value, ctx);
|
|
1802
|
+
} finally {
|
|
1803
|
+
decoratorFinishedRef.v = true;
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
function assertNotFinished(decoratorFinishedRef, fnName) {
|
|
1807
|
+
if (decoratorFinishedRef.v) throw new Error("attempted to call " + fnName + " after decoration was finished");
|
|
1808
|
+
}
|
|
1809
|
+
function assertCallable(fn, hint) {
|
|
1810
|
+
if (typeof fn !== "function") throw new TypeError(hint + " must be a function");
|
|
1811
|
+
}
|
|
1812
|
+
function assertValidReturnValue(kind, value) {
|
|
1813
|
+
var type = typeof value;
|
|
1814
|
+
if (kind === 1) {
|
|
1815
|
+
if (type !== "object" || value === null) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
|
|
1816
|
+
if (value.get !== void 0) assertCallable(value.get, "accessor.get");
|
|
1817
|
+
if (value.set !== void 0) assertCallable(value.set, "accessor.set");
|
|
1818
|
+
if (value.init !== void 0) assertCallable(value.init, "accessor.init");
|
|
1819
|
+
} else if (type !== "function") {
|
|
1820
|
+
var hint;
|
|
1821
|
+
if (kind === 0) hint = "field";
|
|
1822
|
+
else if (kind === 10) hint = "class";
|
|
1823
|
+
else hint = "method";
|
|
1824
|
+
throw new TypeError(hint + " decorators must return a function or void 0");
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
|
|
1828
|
+
var decs = decInfo[0];
|
|
1829
|
+
var desc, init, value;
|
|
1830
|
+
if (isPrivate) if (kind === 0 || kind === 1) desc = {
|
|
1831
|
+
get: decInfo[3],
|
|
1832
|
+
set: decInfo[4]
|
|
1833
|
+
};
|
|
1834
|
+
else if (kind === 3) desc = { get: decInfo[3] };
|
|
1835
|
+
else if (kind === 4) desc = { set: decInfo[3] };
|
|
1836
|
+
else desc = { value: decInfo[3] };
|
|
1837
|
+
else if (kind !== 0) desc = Object.getOwnPropertyDescriptor(base, name);
|
|
1838
|
+
if (kind === 1) value = {
|
|
1839
|
+
get: desc.get,
|
|
1840
|
+
set: desc.set
|
|
1841
|
+
};
|
|
1842
|
+
else if (kind === 2) value = desc.value;
|
|
1843
|
+
else if (kind === 3) value = desc.get;
|
|
1844
|
+
else if (kind === 4) value = desc.set;
|
|
1845
|
+
var newValue, get, set;
|
|
1846
|
+
if (typeof decs === "function") {
|
|
1847
|
+
newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
|
|
1848
|
+
if (newValue !== void 0) {
|
|
1849
|
+
assertValidReturnValue(kind, newValue);
|
|
1850
|
+
if (kind === 0) init = newValue;
|
|
1851
|
+
else if (kind === 1) {
|
|
1852
|
+
init = newValue.init;
|
|
1853
|
+
get = newValue.get || value.get;
|
|
1854
|
+
set = newValue.set || value.set;
|
|
1855
|
+
value = {
|
|
1856
|
+
get,
|
|
1857
|
+
set
|
|
1858
|
+
};
|
|
1859
|
+
} else value = newValue;
|
|
1860
|
+
}
|
|
1861
|
+
} else for (var i = decs.length - 1; i >= 0; i--) {
|
|
1862
|
+
var dec = decs[i];
|
|
1863
|
+
newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
|
|
1864
|
+
if (newValue !== void 0) {
|
|
1865
|
+
assertValidReturnValue(kind, newValue);
|
|
1866
|
+
var newInit;
|
|
1867
|
+
if (kind === 0) newInit = newValue;
|
|
1868
|
+
else if (kind === 1) {
|
|
1869
|
+
newInit = newValue.init;
|
|
1870
|
+
get = newValue.get || value.get;
|
|
1871
|
+
set = newValue.set || value.set;
|
|
1872
|
+
value = {
|
|
1873
|
+
get,
|
|
1874
|
+
set
|
|
1875
|
+
};
|
|
1876
|
+
} else value = newValue;
|
|
1877
|
+
if (newInit !== void 0) if (init === void 0) init = newInit;
|
|
1878
|
+
else if (typeof init === "function") init = [init, newInit];
|
|
1879
|
+
else init.push(newInit);
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
if (kind === 0 || kind === 1) {
|
|
1883
|
+
if (init === void 0) init = function(instance, init$1) {
|
|
1884
|
+
return init$1;
|
|
1885
|
+
};
|
|
1886
|
+
else if (typeof init !== "function") {
|
|
1887
|
+
var ownInitializers = init;
|
|
1888
|
+
init = function(instance, init$1) {
|
|
1889
|
+
var value$1 = init$1;
|
|
1890
|
+
for (var i$1 = 0; i$1 < ownInitializers.length; i$1++) value$1 = ownInitializers[i$1].call(instance, value$1);
|
|
1891
|
+
return value$1;
|
|
1892
|
+
};
|
|
1893
|
+
} else {
|
|
1894
|
+
var originalInitializer = init;
|
|
1895
|
+
init = function(instance, init$1) {
|
|
1896
|
+
return originalInitializer.call(instance, init$1);
|
|
1897
|
+
};
|
|
1898
|
+
}
|
|
1899
|
+
ret.push(init);
|
|
1900
|
+
}
|
|
1901
|
+
if (kind !== 0) {
|
|
1902
|
+
if (kind === 1) {
|
|
1903
|
+
desc.get = value.get;
|
|
1904
|
+
desc.set = value.set;
|
|
1905
|
+
} else if (kind === 2) desc.value = value;
|
|
1906
|
+
else if (kind === 3) desc.get = value;
|
|
1907
|
+
else if (kind === 4) desc.set = value;
|
|
1908
|
+
if (isPrivate) if (kind === 1) {
|
|
1909
|
+
ret.push(function(instance, args) {
|
|
1910
|
+
return value.get.call(instance, args);
|
|
1911
|
+
});
|
|
1912
|
+
ret.push(function(instance, args) {
|
|
1913
|
+
return value.set.call(instance, args);
|
|
1914
|
+
});
|
|
1915
|
+
} else if (kind === 2) ret.push(value);
|
|
1916
|
+
else ret.push(function(instance, args) {
|
|
1917
|
+
return value.call(instance, args);
|
|
1918
|
+
});
|
|
1919
|
+
else Object.defineProperty(base, name, desc);
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
function applyMemberDecs(Class, decInfos, metadata) {
|
|
1923
|
+
var ret = [];
|
|
1924
|
+
var protoInitializers;
|
|
1925
|
+
var staticInitializers;
|
|
1926
|
+
var existingProtoNonFields = /* @__PURE__ */ new Map();
|
|
1927
|
+
var existingStaticNonFields = /* @__PURE__ */ new Map();
|
|
1928
|
+
for (var i = 0; i < decInfos.length; i++) {
|
|
1929
|
+
var decInfo = decInfos[i];
|
|
1930
|
+
if (!Array.isArray(decInfo)) continue;
|
|
1931
|
+
var kind = decInfo[1];
|
|
1932
|
+
var name = decInfo[2];
|
|
1933
|
+
var isPrivate = decInfo.length > 3;
|
|
1934
|
+
var isStatic = kind >= 5;
|
|
1935
|
+
var base;
|
|
1936
|
+
var initializers;
|
|
1937
|
+
if (isStatic) {
|
|
1938
|
+
base = Class;
|
|
1939
|
+
kind = kind - 5;
|
|
1940
|
+
staticInitializers = staticInitializers || [];
|
|
1941
|
+
initializers = staticInitializers;
|
|
1942
|
+
} else {
|
|
1943
|
+
base = Class.prototype;
|
|
1944
|
+
protoInitializers = protoInitializers || [];
|
|
1945
|
+
initializers = protoInitializers;
|
|
1946
|
+
}
|
|
1947
|
+
if (kind !== 0 && !isPrivate) {
|
|
1948
|
+
var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
|
|
1949
|
+
var existingKind = existingNonFields.get(name) || 0;
|
|
1950
|
+
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);
|
|
1951
|
+
else if (!existingKind && kind > 2) existingNonFields.set(name, kind);
|
|
1952
|
+
else existingNonFields.set(name, true);
|
|
1953
|
+
}
|
|
1954
|
+
applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
|
|
1955
|
+
}
|
|
1956
|
+
pushInitializers(ret, protoInitializers);
|
|
1957
|
+
pushInitializers(ret, staticInitializers);
|
|
1958
|
+
return ret;
|
|
1959
|
+
}
|
|
1960
|
+
function pushInitializers(ret, initializers) {
|
|
1961
|
+
if (initializers) ret.push(function(instance) {
|
|
1962
|
+
for (var i = 0; i < initializers.length; i++) initializers[i].call(instance);
|
|
1963
|
+
return instance;
|
|
1964
|
+
});
|
|
1965
|
+
}
|
|
1966
|
+
function applyClassDecs(targetClass, classDecs, metadata) {
|
|
1967
|
+
if (classDecs.length > 0) {
|
|
1968
|
+
var initializers = [];
|
|
1969
|
+
var newClass = targetClass;
|
|
1970
|
+
var name = targetClass.name;
|
|
1971
|
+
for (var i = classDecs.length - 1; i >= 0; i--) {
|
|
1972
|
+
var decoratorFinishedRef = { v: false };
|
|
1973
|
+
try {
|
|
1974
|
+
var nextNewClass = classDecs[i](newClass, {
|
|
1975
|
+
kind: "class",
|
|
1976
|
+
name,
|
|
1977
|
+
addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
|
|
1978
|
+
metadata
|
|
1979
|
+
});
|
|
1980
|
+
} finally {
|
|
1981
|
+
decoratorFinishedRef.v = true;
|
|
1982
|
+
}
|
|
1983
|
+
if (nextNewClass !== void 0) {
|
|
1984
|
+
assertValidReturnValue(10, nextNewClass);
|
|
1985
|
+
newClass = nextNewClass;
|
|
1986
|
+
}
|
|
1987
|
+
}
|
|
1988
|
+
return [defineMetadata(newClass, metadata), function() {
|
|
1989
|
+
for (var i$1 = 0; i$1 < initializers.length; i$1++) initializers[i$1].call(newClass);
|
|
1990
|
+
}];
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1993
|
+
function defineMetadata(Class, metadata) {
|
|
1994
|
+
return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
|
|
1995
|
+
configurable: true,
|
|
1996
|
+
enumerable: true,
|
|
1997
|
+
value: metadata
|
|
1998
|
+
});
|
|
1999
|
+
}
|
|
2000
|
+
return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
|
|
2001
|
+
if (parentClass !== void 0) var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
|
|
2002
|
+
var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
|
|
2003
|
+
var e = applyMemberDecs(targetClass, memberDecs, metadata);
|
|
2004
|
+
if (!classDecs.length) defineMetadata(targetClass, metadata);
|
|
2005
|
+
return {
|
|
2006
|
+
e,
|
|
2007
|
+
get c() {
|
|
2008
|
+
return applyClassDecs(targetClass, classDecs, metadata);
|
|
2009
|
+
}
|
|
2010
|
+
};
|
|
2011
|
+
};
|
|
2012
|
+
}
|
|
2013
|
+
function _apply_decs_2203_r$11(targetClass, memberDecs, classDecs, parentClass) {
|
|
2014
|
+
return (_apply_decs_2203_r$11 = applyDecs2203RFactory$11())(targetClass, memberDecs, classDecs, parentClass);
|
|
2015
|
+
}
|
|
2016
|
+
var _dec$11, _initClass$11;
|
|
2017
|
+
let _InstanceResolverService;
|
|
2018
|
+
_dec$11 = (0, _navios_di.Injectable)();
|
|
2019
|
+
var InstanceResolverService = class {
|
|
2020
|
+
static {
|
|
2021
|
+
({c: [_InstanceResolverService, _initClass$11]} = _apply_decs_2203_r$11(this, [], [_dec$11]));
|
|
2022
|
+
}
|
|
2023
|
+
container = (0, _navios_di.inject)(_navios_di.Container);
|
|
2024
|
+
/**
|
|
2025
|
+
* Attempts to resolve a class instance, automatically detecting if it needs
|
|
2026
|
+
* request scope based on its dependencies.
|
|
2027
|
+
*
|
|
2028
|
+
* @param classType - The class to resolve
|
|
2029
|
+
* @returns A resolution result containing either a cached instance or resolver function
|
|
2030
|
+
*/ async resolve(classType) {
|
|
2031
|
+
let cachedInstance = null;
|
|
2032
|
+
try {
|
|
2033
|
+
cachedInstance = await this.container.get(classType);
|
|
2034
|
+
} catch {
|
|
2035
|
+
const token = (0, _navios_di.getInjectableToken)(classType);
|
|
2036
|
+
this.container.getRegistry().updateScope(token, _navios_di.InjectableScope.Request);
|
|
2037
|
+
}
|
|
2038
|
+
return {
|
|
2039
|
+
cached: cachedInstance !== null,
|
|
2040
|
+
instance: cachedInstance,
|
|
2041
|
+
resolve: (scoped) => scoped.get(classType)
|
|
2042
|
+
};
|
|
2043
|
+
}
|
|
2044
|
+
/**
|
|
2045
|
+
* Attempts to resolve multiple class instances, automatically detecting if any need
|
|
2046
|
+
* request scope based on their dependencies.
|
|
2047
|
+
*
|
|
2048
|
+
* Returns `cached: true` only if ALL classes can be resolved as singletons.
|
|
2049
|
+
* If any class has request-scoped dependencies, returns `cached: false`.
|
|
2050
|
+
*
|
|
2051
|
+
* @param classTypes - The classes to resolve
|
|
2052
|
+
* @returns A resolution result containing either all cached instances or resolver function
|
|
2053
|
+
*/ async resolveMany(classTypes) {
|
|
2054
|
+
if (classTypes.length === 0) return {
|
|
2055
|
+
cached: true,
|
|
2056
|
+
instances: [],
|
|
2057
|
+
classTypes: [],
|
|
2058
|
+
resolve: async () => []
|
|
2059
|
+
};
|
|
2060
|
+
const results = await Promise.all(classTypes.map(async (classType) => {
|
|
2061
|
+
try {
|
|
2062
|
+
return {
|
|
2063
|
+
success: true,
|
|
2064
|
+
instance: await this.container.get(classType)
|
|
2065
|
+
};
|
|
2066
|
+
} catch {
|
|
2067
|
+
const token = (0, _navios_di.getInjectableToken)(classType);
|
|
2068
|
+
this.container.getRegistry().updateScope(token, _navios_di.InjectableScope.Request);
|
|
2069
|
+
return {
|
|
2070
|
+
success: false,
|
|
2071
|
+
instance: null
|
|
2072
|
+
};
|
|
2073
|
+
}
|
|
2074
|
+
}));
|
|
2075
|
+
const allCached = results.every((r) => r.success);
|
|
2076
|
+
return {
|
|
2077
|
+
cached: allCached,
|
|
2078
|
+
instances: allCached ? results.map((r) => r.instance) : null,
|
|
2079
|
+
classTypes,
|
|
2080
|
+
resolve: (scoped) => Promise.all(classTypes.map((classType) => scoped.get(classType)))
|
|
2081
|
+
};
|
|
2082
|
+
}
|
|
2083
|
+
static {
|
|
2084
|
+
_initClass$11();
|
|
2085
|
+
}
|
|
2086
|
+
};
|
|
2087
|
+
/**
|
|
2088
|
+
* @deprecated Use InstanceResolverService instead
|
|
2089
|
+
*/ const ControllerResolverService = _InstanceResolverService;
|
|
2090
|
+
|
|
1710
2091
|
//#endregion
|
|
1711
2092
|
//#region src/services/guard-runner.service.mts
|
|
1712
2093
|
function applyDecs2203RFactory$10() {
|
|
@@ -1994,23 +2375,40 @@ var GuardRunnerService = class {
|
|
|
1994
2375
|
({c: [_GuardRunnerService, _initClass$10]} = _apply_decs_2203_r$10(this, [], [_dec$10]));
|
|
1995
2376
|
}
|
|
1996
2377
|
logger = (0, _navios_di.inject)(Logger, { context: _GuardRunnerService.name });
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2378
|
+
/**
|
|
2379
|
+
* Runs guards that need to be resolved from a scoped container.
|
|
2380
|
+
* Use this when guards have request-scoped dependencies.
|
|
2381
|
+
*/ async runGuards(allGuards, executionContext, context) {
|
|
2382
|
+
const guardsArray = Array.from(allGuards).reverse();
|
|
2383
|
+
const guardInstances = await Promise.all(guardsArray.map(async (guard) => {
|
|
2000
2384
|
const guardInstance = await context.get(guard);
|
|
2001
2385
|
if (!guardInstance.canActivate) throw new Error(`[Navios] Guard ${guard.name} does not implement canActivate()`);
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2386
|
+
return guardInstance;
|
|
2387
|
+
}));
|
|
2388
|
+
return this.executeGuards(guardInstances, executionContext);
|
|
2389
|
+
}
|
|
2390
|
+
/**
|
|
2391
|
+
* Runs pre-resolved guard instances.
|
|
2392
|
+
* Use this when all guards are singletons and have been pre-resolved at startup.
|
|
2393
|
+
*/ async runGuardsStatic(guardInstances, executionContext) {
|
|
2394
|
+
return this.executeGuards(guardInstances, executionContext);
|
|
2395
|
+
}
|
|
2396
|
+
/**
|
|
2397
|
+
* Shared guard execution logic.
|
|
2398
|
+
* Iterates through guard instances and calls canActivate on each.
|
|
2399
|
+
*/ async executeGuards(guardInstances, executionContext) {
|
|
2400
|
+
let canActivate = true;
|
|
2401
|
+
for (const guardInstance of guardInstances) try {
|
|
2402
|
+
canActivate = await guardInstance.canActivate(executionContext);
|
|
2403
|
+
if (!canActivate) break;
|
|
2404
|
+
} catch (error) {
|
|
2405
|
+
if (error instanceof HttpException) {
|
|
2406
|
+
executionContext.getReply().status(error.statusCode).send(error.response);
|
|
2407
|
+
return false;
|
|
2408
|
+
} else {
|
|
2409
|
+
this.logger.error("Error running guard", error);
|
|
2410
|
+
executionContext.getReply().status(500).send({ message: "Internal server error" });
|
|
2411
|
+
return false;
|
|
2014
2412
|
}
|
|
2015
2413
|
}
|
|
2016
2414
|
if (!canActivate) {
|
|
@@ -2376,7 +2774,7 @@ var ModuleLoaderService = class {
|
|
|
2376
2774
|
async traverseModules(module$1, parentMetadata) {
|
|
2377
2775
|
const metadata = require_use_guards_decorator.extractModuleMetadata(module$1);
|
|
2378
2776
|
if (parentMetadata) this.mergeMetadata(metadata, parentMetadata);
|
|
2379
|
-
const moduleName = module$1.
|
|
2777
|
+
const moduleName = (0, _navios_di.getInjectableToken)(module$1).id;
|
|
2380
2778
|
if (this.modulesMetadata.has(moduleName)) return;
|
|
2381
2779
|
try {
|
|
2382
2780
|
this.modulesMetadata.set(moduleName, metadata);
|
|
@@ -2779,7 +3177,7 @@ var NaviosEnvironment = class {
|
|
|
2779
3177
|
}
|
|
2780
3178
|
httpTokens = /* @__PURE__ */ new Map();
|
|
2781
3179
|
setupHttpEnvironment(tokens) {
|
|
2782
|
-
this.httpTokens
|
|
3180
|
+
for (const [token, value] of tokens) this.httpTokens.set(token, value);
|
|
2783
3181
|
}
|
|
2784
3182
|
getHttpToken(token) {
|
|
2785
3183
|
return this.httpTokens.get(token);
|
|
@@ -5443,7 +5841,9 @@ var NaviosApplication = class {
|
|
|
5443
5841
|
* })
|
|
5444
5842
|
* ```
|
|
5445
5843
|
*/ static async create(appModule, options = { adapter: [] }) {
|
|
5446
|
-
const container = options.container ?? new _navios_di.Container();
|
|
5844
|
+
const container = options.container ?? new _navios_di.Container(options.registry);
|
|
5845
|
+
if (options.enableRequestId === true) setRequestIdEnabled(true);
|
|
5846
|
+
container.addInstance(require_use_guards_decorator.NaviosOptionsToken, options);
|
|
5447
5847
|
await this.registerLoggerConfiguration(container, options);
|
|
5448
5848
|
const adapters = Array.isArray(options.adapter) ? options.adapter : [options.adapter];
|
|
5449
5849
|
for (const adapter of adapters) await this.registerEnvironment(container, adapter);
|
|
@@ -5458,11 +5858,14 @@ var NaviosApplication = class {
|
|
|
5458
5858
|
}
|
|
5459
5859
|
static async registerLoggerConfiguration(container, options) {
|
|
5460
5860
|
const { logger } = options;
|
|
5461
|
-
if (Array.isArray(logger) || isNil(logger)) {
|
|
5462
|
-
(await container.get(LoggerOutput))?.setup({
|
|
5861
|
+
if (Array.isArray(logger) || isNil(logger) || options.enableRequestId) {
|
|
5862
|
+
(await container.get(LoggerOutput))?.setup({
|
|
5863
|
+
logLevels: Array.isArray(logger) ? logger : void 0,
|
|
5864
|
+
requestId: options.enableRequestId ?? false
|
|
5865
|
+
});
|
|
5463
5866
|
return;
|
|
5464
5867
|
}
|
|
5465
|
-
if (logger !== true && !isNil(logger)) container.
|
|
5868
|
+
if (logger !== true && !isNil(logger)) container.addInstance(LoggerOutput, logger);
|
|
5466
5869
|
}
|
|
5467
5870
|
};
|
|
5468
5871
|
|
|
@@ -5503,6 +5906,12 @@ Object.defineProperty(exports, 'ConflictException', {
|
|
|
5503
5906
|
return ConflictException;
|
|
5504
5907
|
}
|
|
5505
5908
|
});
|
|
5909
|
+
Object.defineProperty(exports, 'ControllerResolverService', {
|
|
5910
|
+
enumerable: true,
|
|
5911
|
+
get: function () {
|
|
5912
|
+
return ControllerResolverService;
|
|
5913
|
+
}
|
|
5914
|
+
});
|
|
5506
5915
|
Object.defineProperty(exports, 'EnvConfigProvider', {
|
|
5507
5916
|
enumerable: true,
|
|
5508
5917
|
get: function () {
|
|
@@ -5593,6 +6002,12 @@ Object.defineProperty(exports, '_HttpAdapterFactory', {
|
|
|
5593
6002
|
return _HttpAdapterFactory;
|
|
5594
6003
|
}
|
|
5595
6004
|
});
|
|
6005
|
+
Object.defineProperty(exports, '_InstanceResolverService', {
|
|
6006
|
+
enumerable: true,
|
|
6007
|
+
get: function () {
|
|
6008
|
+
return _InstanceResolverService;
|
|
6009
|
+
}
|
|
6010
|
+
});
|
|
5596
6011
|
Object.defineProperty(exports, '_LoggerInstance', {
|
|
5597
6012
|
enumerable: true,
|
|
5598
6013
|
get: function () {
|
|
@@ -5677,6 +6092,12 @@ Object.defineProperty(exports, 'filterLogLevels', {
|
|
|
5677
6092
|
return filterLogLevels;
|
|
5678
6093
|
}
|
|
5679
6094
|
});
|
|
6095
|
+
Object.defineProperty(exports, 'generateRequestId', {
|
|
6096
|
+
enumerable: true,
|
|
6097
|
+
get: function () {
|
|
6098
|
+
return generateRequestId;
|
|
6099
|
+
}
|
|
6100
|
+
});
|
|
5680
6101
|
Object.defineProperty(exports, 'getRequestId', {
|
|
5681
6102
|
enumerable: true,
|
|
5682
6103
|
get: function () {
|
|
@@ -5773,16 +6194,16 @@ Object.defineProperty(exports, 'provideConfig', {
|
|
|
5773
6194
|
return provideConfig;
|
|
5774
6195
|
}
|
|
5775
6196
|
});
|
|
5776
|
-
Object.defineProperty(exports, '
|
|
6197
|
+
Object.defineProperty(exports, 'runWithRequestId', {
|
|
5777
6198
|
enumerable: true,
|
|
5778
6199
|
get: function () {
|
|
5779
|
-
return
|
|
6200
|
+
return runWithRequestId;
|
|
5780
6201
|
}
|
|
5781
6202
|
});
|
|
5782
|
-
Object.defineProperty(exports, '
|
|
6203
|
+
Object.defineProperty(exports, 'setRequestIdEnabled', {
|
|
5783
6204
|
enumerable: true,
|
|
5784
6205
|
get: function () {
|
|
5785
|
-
return
|
|
6206
|
+
return setRequestIdEnabled;
|
|
5786
6207
|
}
|
|
5787
6208
|
});
|
|
5788
6209
|
Object.defineProperty(exports, 'stripEndSlash', {
|
|
@@ -5797,4 +6218,4 @@ Object.defineProperty(exports, 'yellow', {
|
|
|
5797
6218
|
return yellow;
|
|
5798
6219
|
}
|
|
5799
6220
|
});
|
|
5800
|
-
//# sourceMappingURL=src-
|
|
6221
|
+
//# sourceMappingURL=src-BRPtJ9fG.cjs.map
|