@navios/core 0.1.13 → 0.1.15
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/dist/_tsup-dts-rollup.d.mts +133 -49
- package/dist/_tsup-dts-rollup.d.ts +133 -49
- package/dist/index.d.mts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +1184 -1090
- package/dist/index.mjs +1179 -1090
- package/package.json +1 -1
- package/src/adapters/endpoint-adapter.service.mts +75 -0
- package/src/adapters/handler-adapter.interface.mts +21 -0
- package/src/adapters/index.mts +4 -0
- package/src/adapters/multipart-adapter.service.mts +130 -0
- package/src/adapters/stream-adapter.service.mts +95 -0
- package/src/attribute.factory.mts +13 -13
- package/src/config/config.provider.mts +8 -2
- package/src/decorators/controller.decorator.mts +0 -2
- package/src/decorators/endpoint.decorator.mts +7 -3
- package/src/decorators/header.decorator.mts +1 -6
- package/src/decorators/http-code.decorator.mts +1 -6
- package/src/decorators/module.decorator.mts +13 -15
- package/src/decorators/multipart.decorator.mts +7 -3
- package/src/decorators/stream.decorator.mts +7 -3
- package/src/index.mts +1 -0
- package/src/logger/console-logger.service.mts +41 -3
- package/src/logger/logger.service.mts +0 -1
- package/src/metadata/controller.metadata.mts +3 -3
- package/src/metadata/{endpoint.metadata.mts → handler.metadata.mts} +17 -24
- package/src/metadata/index.mts +1 -1
- package/src/navios.application.mts +3 -4
- package/src/service-locator/__tests__/injection-token.spec.mts +10 -5
- package/src/service-locator/decorators/injectable.decorator.mts +53 -4
- package/src/service-locator/inject.mts +14 -0
- package/src/service-locator/interfaces/factory.interface.mts +9 -1
- package/src/service-locator/service-locator.mts +1 -0
- package/src/service-locator/sync-injector.mts +14 -0
- package/src/services/controller-adapter.service.mts +59 -240
- package/src/services/execution-context.mts +4 -3
package/dist/index.mjs
CHANGED
|
@@ -46,117 +46,6 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
|
|
|
46
46
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
47
47
|
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
48
48
|
|
|
49
|
-
// packages/core/src/config/utils/helpers.mts
|
|
50
|
-
import { env } from "node:process";
|
|
51
|
-
function envInt(key, defaultValue) {
|
|
52
|
-
const envKey = env[key] || process.env[key];
|
|
53
|
-
return envKey ? parseInt(envKey, 10) : defaultValue;
|
|
54
|
-
}
|
|
55
|
-
function envString(key, defaultValue) {
|
|
56
|
-
return env[key] || process.env[key] || defaultValue || void 0;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// packages/core/src/config/config.provider.mts
|
|
60
|
-
import { z as z3 } from "zod";
|
|
61
|
-
|
|
62
|
-
// packages/core/src/logger/utils/cli-colors.util.mts
|
|
63
|
-
var isColorAllowed = () => !process.env.NO_COLOR;
|
|
64
|
-
var colorIfAllowed = (colorFn) => (text) => isColorAllowed() ? colorFn(text) : text;
|
|
65
|
-
var clc = {
|
|
66
|
-
bold: colorIfAllowed((text) => `\x1B[1m${text}\x1B[0m`),
|
|
67
|
-
green: colorIfAllowed((text) => `\x1B[32m${text}\x1B[39m`),
|
|
68
|
-
yellow: colorIfAllowed((text) => `\x1B[33m${text}\x1B[39m`),
|
|
69
|
-
red: colorIfAllowed((text) => `\x1B[31m${text}\x1B[39m`),
|
|
70
|
-
magentaBright: colorIfAllowed((text) => `\x1B[95m${text}\x1B[39m`),
|
|
71
|
-
cyanBright: colorIfAllowed((text) => `\x1B[96m${text}\x1B[39m`)
|
|
72
|
-
};
|
|
73
|
-
var yellow = colorIfAllowed(
|
|
74
|
-
(text) => `\x1B[38;5;3m${text}\x1B[39m`
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
// packages/core/src/logger/log-levels.mts
|
|
78
|
-
var LOG_LEVELS = [
|
|
79
|
-
"verbose",
|
|
80
|
-
"debug",
|
|
81
|
-
"log",
|
|
82
|
-
"warn",
|
|
83
|
-
"error",
|
|
84
|
-
"fatal"
|
|
85
|
-
];
|
|
86
|
-
|
|
87
|
-
// packages/core/src/logger/utils/is-log-level.util.mts
|
|
88
|
-
function isLogLevel(maybeLogLevel) {
|
|
89
|
-
return LOG_LEVELS.includes(maybeLogLevel);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// packages/core/src/logger/utils/filter-log-levelts.util.mts
|
|
93
|
-
function filterLogLevels(parseableString = "") {
|
|
94
|
-
const sanitizedString = parseableString.replaceAll(" ", "").toLowerCase();
|
|
95
|
-
if (sanitizedString[0] === ">") {
|
|
96
|
-
const orEqual = sanitizedString[1] === "=";
|
|
97
|
-
const logLevelIndex = LOG_LEVELS.indexOf(
|
|
98
|
-
sanitizedString.substring(orEqual ? 2 : 1)
|
|
99
|
-
);
|
|
100
|
-
if (logLevelIndex === -1) {
|
|
101
|
-
throw new Error(`parse error (unknown log level): ${sanitizedString}`);
|
|
102
|
-
}
|
|
103
|
-
return LOG_LEVELS.slice(orEqual ? logLevelIndex : logLevelIndex + 1);
|
|
104
|
-
} else if (sanitizedString.includes(",")) {
|
|
105
|
-
return sanitizedString.split(",").filter(isLogLevel);
|
|
106
|
-
}
|
|
107
|
-
return isLogLevel(sanitizedString) ? [sanitizedString] : LOG_LEVELS;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// packages/core/src/logger/utils/is-log-level-enabled.mts
|
|
111
|
-
var LOG_LEVEL_VALUES = {
|
|
112
|
-
verbose: 0,
|
|
113
|
-
debug: 1,
|
|
114
|
-
log: 2,
|
|
115
|
-
warn: 3,
|
|
116
|
-
error: 4,
|
|
117
|
-
fatal: 5
|
|
118
|
-
};
|
|
119
|
-
function isLogLevelEnabled(targetLevel, logLevels) {
|
|
120
|
-
var _a;
|
|
121
|
-
if (!logLevels || Array.isArray(logLevels) && (logLevels == null ? void 0 : logLevels.length) === 0) {
|
|
122
|
-
return false;
|
|
123
|
-
}
|
|
124
|
-
if (logLevels.includes(targetLevel)) {
|
|
125
|
-
return true;
|
|
126
|
-
}
|
|
127
|
-
const highestLogLevelValue = (_a = logLevels.map((level) => LOG_LEVEL_VALUES[level]).sort((a, b) => b - a)) == null ? void 0 : _a[0];
|
|
128
|
-
const targetLevelValue = LOG_LEVEL_VALUES[targetLevel];
|
|
129
|
-
return targetLevelValue >= highestLogLevelValue;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// packages/core/src/logger/utils/shared.utils.mts
|
|
133
|
-
var isUndefined = (obj) => typeof obj === "undefined";
|
|
134
|
-
var isObject = (fn) => !isNil(fn) && typeof fn === "object";
|
|
135
|
-
var isPlainObject = (fn) => {
|
|
136
|
-
if (!isObject(fn)) {
|
|
137
|
-
return false;
|
|
138
|
-
}
|
|
139
|
-
const proto = Object.getPrototypeOf(fn);
|
|
140
|
-
if (proto === null) {
|
|
141
|
-
return true;
|
|
142
|
-
}
|
|
143
|
-
const ctor = Object.prototype.hasOwnProperty.call(proto, "constructor") && proto.constructor;
|
|
144
|
-
return typeof ctor === "function" && ctor instanceof ctor && Function.prototype.toString.call(ctor) === Function.prototype.toString.call(Object);
|
|
145
|
-
};
|
|
146
|
-
var addLeadingSlash = (path) => path && typeof path === "string" ? path.charAt(0) !== "/" && path.substring(0, 2) !== "{/" ? "/" + path : path : "";
|
|
147
|
-
var normalizePath = (path) => path ? path.startsWith("/") ? ("/" + path.replace(/\/+$/, "")).replace(/\/+/g, "/") : "/" + path.replace(/\/+$/, "") : "/";
|
|
148
|
-
var stripEndSlash = (path) => path[path.length - 1] === "/" ? path.slice(0, path.length - 1) : path;
|
|
149
|
-
var isFunction = (val) => typeof val === "function";
|
|
150
|
-
var isString = (val) => typeof val === "string";
|
|
151
|
-
var isNumber = (val) => typeof val === "number";
|
|
152
|
-
var isConstructor = (val) => val === "constructor";
|
|
153
|
-
var isNil = (val) => isUndefined(val) || val === null;
|
|
154
|
-
var isEmpty = (array) => !(array && array.length > 0);
|
|
155
|
-
var isSymbol = (val) => typeof val === "symbol";
|
|
156
|
-
|
|
157
|
-
// packages/core/src/logger/console-logger.service.mts
|
|
158
|
-
import { inspect } from "util";
|
|
159
|
-
|
|
160
49
|
// packages/core/src/service-locator/decorators/injectable.decorator.mts
|
|
161
50
|
import { NaviosException as NaviosException2 } from "@navios/common";
|
|
162
51
|
|
|
@@ -290,8 +179,8 @@ var ServiceLocatorEventBus = class {
|
|
|
290
179
|
}
|
|
291
180
|
listeners = /* @__PURE__ */ new Map();
|
|
292
181
|
on(ns, event, listener) {
|
|
293
|
-
var
|
|
294
|
-
(
|
|
182
|
+
var _a3;
|
|
183
|
+
(_a3 = this.logger) == null ? void 0 : _a3.debug(`[ServiceLocatorEventBus]#on(): ns:${ns} event:${event}`);
|
|
295
184
|
if (!this.listeners.has(ns)) {
|
|
296
185
|
this.listeners.set(ns, /* @__PURE__ */ new Map());
|
|
297
186
|
}
|
|
@@ -301,9 +190,9 @@ var ServiceLocatorEventBus = class {
|
|
|
301
190
|
}
|
|
302
191
|
nsEvents.get(event).add(listener);
|
|
303
192
|
return () => {
|
|
304
|
-
var
|
|
193
|
+
var _a4;
|
|
305
194
|
nsEvents.get(event).delete(listener);
|
|
306
|
-
if (((
|
|
195
|
+
if (((_a4 = nsEvents.get(event)) == null ? void 0 : _a4.size) === 0) {
|
|
307
196
|
nsEvents.delete(event);
|
|
308
197
|
}
|
|
309
198
|
if (nsEvents.size === 0) {
|
|
@@ -312,20 +201,20 @@ var ServiceLocatorEventBus = class {
|
|
|
312
201
|
};
|
|
313
202
|
}
|
|
314
203
|
async emit(key, event) {
|
|
315
|
-
var
|
|
204
|
+
var _a3, _b, _c;
|
|
316
205
|
if (!this.listeners.has(key)) {
|
|
317
206
|
return;
|
|
318
207
|
}
|
|
319
208
|
const events = this.listeners.get(key);
|
|
320
209
|
const preEvent = `pre:${event}`;
|
|
321
210
|
const postEvent = `post:${event}`;
|
|
322
|
-
(
|
|
211
|
+
(_a3 = this.logger) == null ? void 0 : _a3.debug(`[ServiceLocatorEventBus]#emit(): ${key}:${preEvent}`);
|
|
323
212
|
await Promise.allSettled(
|
|
324
213
|
[...events.get(preEvent) ?? []].map((listener) => listener(preEvent))
|
|
325
214
|
).then((results) => {
|
|
326
215
|
results.filter((result) => result.status === "rejected").forEach((result) => {
|
|
327
|
-
var
|
|
328
|
-
(
|
|
216
|
+
var _a4;
|
|
217
|
+
(_a4 = this.logger) == null ? void 0 : _a4.warn(
|
|
329
218
|
`[ServiceLocatorEventBus]#emit(): ${key}:${preEvent} rejected with`,
|
|
330
219
|
result.reason
|
|
331
220
|
);
|
|
@@ -336,8 +225,8 @@ var ServiceLocatorEventBus = class {
|
|
|
336
225
|
[...events.get(event) ?? []].map((listener) => listener(event))
|
|
337
226
|
).then((results) => {
|
|
338
227
|
const res2 = results.filter((result) => result.status === "rejected").map((result) => {
|
|
339
|
-
var
|
|
340
|
-
(
|
|
228
|
+
var _a4;
|
|
229
|
+
(_a4 = this.logger) == null ? void 0 : _a4.warn(
|
|
341
230
|
`[ServiceLocatorEventBus]#emit(): ${key}:${event} rejected with`,
|
|
342
231
|
result.reason
|
|
343
232
|
);
|
|
@@ -353,8 +242,8 @@ var ServiceLocatorEventBus = class {
|
|
|
353
242
|
[...events.get(postEvent) ?? []].map((listener) => listener(postEvent))
|
|
354
243
|
).then((results) => {
|
|
355
244
|
results.filter((result) => result.status === "rejected").forEach((result) => {
|
|
356
|
-
var
|
|
357
|
-
(
|
|
245
|
+
var _a4;
|
|
246
|
+
(_a4 = this.logger) == null ? void 0 : _a4.warn(
|
|
358
247
|
`[ServiceLocatorEventBus]#emit(): ${key}:${postEvent} rejected with`,
|
|
359
248
|
result.reason
|
|
360
249
|
);
|
|
@@ -385,13 +274,13 @@ var ServiceLocatorManager = class {
|
|
|
385
274
|
}
|
|
386
275
|
instancesHolders = /* @__PURE__ */ new Map();
|
|
387
276
|
get(name2) {
|
|
388
|
-
var
|
|
277
|
+
var _a3, _b, _c;
|
|
389
278
|
const holder = this.instancesHolders.get(name2);
|
|
390
279
|
if (holder) {
|
|
391
280
|
if (holder.ttl !== Infinity) {
|
|
392
281
|
const now = Date.now();
|
|
393
282
|
if (now - holder.createdAt > holder.ttl) {
|
|
394
|
-
(
|
|
283
|
+
(_a3 = this.logger) == null ? void 0 : _a3.log(
|
|
395
284
|
`[ServiceLocatorManager]#getInstanceHolder() TTL expired for ${holder.name}`
|
|
396
285
|
);
|
|
397
286
|
return [new InstanceExpired(holder.name), holder];
|
|
@@ -466,14 +355,15 @@ var ServiceLocator = class {
|
|
|
466
355
|
destroyPromise: null,
|
|
467
356
|
creationPromise: null
|
|
468
357
|
});
|
|
358
|
+
this.eventBus.emit(instanceName, "create");
|
|
469
359
|
}
|
|
470
360
|
removeInstance(token) {
|
|
471
361
|
const instanceName = this.getInstanceIdentifier(token, void 0);
|
|
472
362
|
return this.invalidate(instanceName);
|
|
473
363
|
}
|
|
474
364
|
registerAbstractFactory(token, factory, type = "Singleton" /* Singleton */) {
|
|
475
|
-
var
|
|
476
|
-
(
|
|
365
|
+
var _a3;
|
|
366
|
+
(_a3 = this.logger) == null ? void 0 : _a3.log(
|
|
477
367
|
`[ServiceLocator]#registerAbstractFactory(): Registering abstract factory for ${name}`
|
|
478
368
|
);
|
|
479
369
|
if (type === "Instance" /* Instance */) {
|
|
@@ -485,7 +375,7 @@ var ServiceLocator = class {
|
|
|
485
375
|
}
|
|
486
376
|
}
|
|
487
377
|
resolveTokenArgs(token, args) {
|
|
488
|
-
var
|
|
378
|
+
var _a3, _b;
|
|
489
379
|
let realArgs = args;
|
|
490
380
|
if (token instanceof BoundInjectionToken) {
|
|
491
381
|
realArgs = token.value;
|
|
@@ -499,7 +389,7 @@ var ServiceLocator = class {
|
|
|
499
389
|
if (!token.schema) {
|
|
500
390
|
return [void 0, realArgs];
|
|
501
391
|
}
|
|
502
|
-
const validatedArgs = (
|
|
392
|
+
const validatedArgs = (_a3 = token.schema) == null ? void 0 : _a3.safeParse(realArgs);
|
|
503
393
|
if (validatedArgs && !validatedArgs.success) {
|
|
504
394
|
(_b = this.logger) == null ? void 0 : _b.error(
|
|
505
395
|
`[ServiceLocator]#getInstance(): Error validating args for ${token.name.toString()}`,
|
|
@@ -517,7 +407,7 @@ var ServiceLocator = class {
|
|
|
517
407
|
return this.makeInstanceName(token, realArgs);
|
|
518
408
|
}
|
|
519
409
|
async getInstance(token, args) {
|
|
520
|
-
var
|
|
410
|
+
var _a3, _b;
|
|
521
411
|
const [err, realArgs] = this.resolveTokenArgs(token, args);
|
|
522
412
|
if (err instanceof UnknownError) {
|
|
523
413
|
throw err;
|
|
@@ -537,7 +427,7 @@ var ServiceLocator = class {
|
|
|
537
427
|
}
|
|
538
428
|
switch (error.code) {
|
|
539
429
|
case "InstanceDestroying" /* InstanceDestroying */:
|
|
540
|
-
(
|
|
430
|
+
(_a3 = this.logger) == null ? void 0 : _a3.log(
|
|
541
431
|
`[ServiceLocator]#getInstance() TTL expired for ${holder == null ? void 0 : holder.name}`
|
|
542
432
|
);
|
|
543
433
|
await (holder == null ? void 0 : holder.destroyPromise);
|
|
@@ -563,15 +453,15 @@ var ServiceLocator = class {
|
|
|
563
453
|
return instance;
|
|
564
454
|
}
|
|
565
455
|
notifyListeners(name2, event = "create") {
|
|
566
|
-
var
|
|
567
|
-
(
|
|
456
|
+
var _a3;
|
|
457
|
+
(_a3 = this.logger) == null ? void 0 : _a3.log(
|
|
568
458
|
`[ServiceLocator]#notifyListeners() Notifying listeners for ${name2} with event ${event}`
|
|
569
459
|
);
|
|
570
460
|
return this.eventBus.emit(name2, event);
|
|
571
461
|
}
|
|
572
462
|
async createInstance(instanceName, token, args) {
|
|
573
|
-
var
|
|
574
|
-
(
|
|
463
|
+
var _a3;
|
|
464
|
+
(_a3 = this.logger) == null ? void 0 : _a3.log(
|
|
575
465
|
`[ServiceLocator]#createInstance() Creating instance for ${instanceName}`
|
|
576
466
|
);
|
|
577
467
|
let realToken = token instanceof BoundInjectionToken || token instanceof FactoryInjectionToken ? token.token : token;
|
|
@@ -586,8 +476,8 @@ var ServiceLocator = class {
|
|
|
586
476
|
}
|
|
587
477
|
}
|
|
588
478
|
async createInstanceFromAbstractFactory(instanceName, token, args) {
|
|
589
|
-
var
|
|
590
|
-
(
|
|
479
|
+
var _a3;
|
|
480
|
+
(_a3 = this.logger) == null ? void 0 : _a3.log(
|
|
591
481
|
`[ServiceLocator]#createInstanceFromAbstractFactory(): Creating instance for ${instanceName} from abstract factory`
|
|
592
482
|
);
|
|
593
483
|
const ctx = this.createContextForAbstractFactory(instanceName);
|
|
@@ -607,14 +497,14 @@ var ServiceLocator = class {
|
|
|
607
497
|
kind: "abstractFactory" /* AbstractFactory */,
|
|
608
498
|
// @ts-expect-error TS2322 This is correct type
|
|
609
499
|
creationPromise: abstractFactory(ctx, args).then(async (instance) => {
|
|
610
|
-
var
|
|
500
|
+
var _a4;
|
|
611
501
|
holder.instance = instance;
|
|
612
502
|
holder.status = "created" /* Created */;
|
|
613
503
|
holder.deps = ctx.getDependencies();
|
|
614
504
|
holder.destroyListeners = ctx.getDestroyListeners();
|
|
615
505
|
holder.ttl = ctx.getTtl();
|
|
616
506
|
if (holder.deps.length > 0) {
|
|
617
|
-
(
|
|
507
|
+
(_a4 = this.logger) == null ? void 0 : _a4.log(
|
|
618
508
|
`[ServiceLocator]#createInstanceFromAbstractFactory(): Adding subscriptions for ${instanceName} dependencies for their invalidations: ${holder.deps.join(
|
|
619
509
|
", "
|
|
620
510
|
)}`
|
|
@@ -635,8 +525,8 @@ var ServiceLocator = class {
|
|
|
635
525
|
await this.notifyListeners(instanceName);
|
|
636
526
|
return [void 0, instance];
|
|
637
527
|
}).catch((error) => {
|
|
638
|
-
var
|
|
639
|
-
(
|
|
528
|
+
var _a4;
|
|
529
|
+
(_a4 = this.logger) == null ? void 0 : _a4.error(
|
|
640
530
|
`[ServiceLocator]#createInstanceFromAbstractFactory(): Error creating instance for ${instanceName}`,
|
|
641
531
|
error
|
|
642
532
|
);
|
|
@@ -713,8 +603,8 @@ var ServiceLocator = class {
|
|
|
713
603
|
return holder.instance;
|
|
714
604
|
}
|
|
715
605
|
invalidate(service, round = 1) {
|
|
716
|
-
var
|
|
717
|
-
(
|
|
606
|
+
var _a3, _b, _c, _d, _e;
|
|
607
|
+
(_a3 = this.logger) == null ? void 0 : _a3.log(
|
|
718
608
|
`[ServiceLocator]#invalidate(): Starting Invalidating process of ${service}`
|
|
719
609
|
);
|
|
720
610
|
const toInvalidate = this.manager.filter(
|
|
@@ -735,9 +625,9 @@ var ServiceLocator = class {
|
|
|
735
625
|
);
|
|
736
626
|
promises.push(
|
|
737
627
|
(_d = holder.creationPromise) == null ? void 0 : _d.then(() => {
|
|
738
|
-
var
|
|
628
|
+
var _a4;
|
|
739
629
|
if (round > 3) {
|
|
740
|
-
(
|
|
630
|
+
(_a4 = this.logger) == null ? void 0 : _a4.error(
|
|
741
631
|
`[ServiceLocator]#invalidate(): ${key} creation is triggering a new invalidation round, but it is still not created`
|
|
742
632
|
);
|
|
743
633
|
return;
|
|
@@ -764,9 +654,9 @@ var ServiceLocator = class {
|
|
|
764
654
|
async ready() {
|
|
765
655
|
return Promise.all(
|
|
766
656
|
Array.from(this.manager.filter(() => true)).map(([, holder]) => {
|
|
767
|
-
var
|
|
657
|
+
var _a3;
|
|
768
658
|
if (holder.status === "creating" /* Creating */) {
|
|
769
|
-
return (
|
|
659
|
+
return (_a3 = holder.creationPromise) == null ? void 0 : _a3.then(() => null);
|
|
770
660
|
}
|
|
771
661
|
if (holder.status === "destroying" /* Destroying */) {
|
|
772
662
|
return holder.destroyPromise.then(() => null);
|
|
@@ -927,7 +817,7 @@ var InjectableType = /* @__PURE__ */ ((InjectableType2) => {
|
|
|
927
817
|
InjectableType2["Factory"] = "Factory";
|
|
928
818
|
return InjectableType2;
|
|
929
819
|
})(InjectableType || {});
|
|
930
|
-
var InjectableTokenMeta = Symbol("InjectableTokenMeta");
|
|
820
|
+
var InjectableTokenMeta = Symbol.for("InjectableTokenMeta");
|
|
931
821
|
function Injectable({
|
|
932
822
|
scope = "Singleton" /* Singleton */,
|
|
933
823
|
type = "Class" /* Class */,
|
|
@@ -1041,127 +931,937 @@ function override(token, target) {
|
|
|
1041
931
|
};
|
|
1042
932
|
}
|
|
1043
933
|
|
|
1044
|
-
// packages/core/src/
|
|
1045
|
-
var
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
var _ConsoleLogger = class _ConsoleLogger {
|
|
1065
|
-
/**
|
|
1066
|
-
* The options of the logger.
|
|
1067
|
-
*/
|
|
1068
|
-
options;
|
|
1069
|
-
/**
|
|
1070
|
-
* The context of the logger (can be set manually or automatically inferred).
|
|
1071
|
-
*/
|
|
1072
|
-
context;
|
|
1073
|
-
/**
|
|
1074
|
-
* The original context of the logger (set in the constructor).
|
|
1075
|
-
*/
|
|
1076
|
-
originalContext;
|
|
1077
|
-
/**
|
|
1078
|
-
* The options used for the "inspect" method.
|
|
1079
|
-
*/
|
|
1080
|
-
inspectOptions;
|
|
1081
|
-
/**
|
|
1082
|
-
* The last timestamp at which the log message was printed.
|
|
1083
|
-
*/
|
|
1084
|
-
static lastTimestampAt;
|
|
1085
|
-
constructor(contextOrOptions, options) {
|
|
1086
|
-
let [context, opts] = isString(contextOrOptions) ? [contextOrOptions, options] : options ? [void 0, options] : [contextOrOptions == null ? void 0 : contextOrOptions.context, contextOrOptions];
|
|
1087
|
-
opts = opts ?? {};
|
|
1088
|
-
opts.logLevels ??= DEFAULT_LOG_LEVELS;
|
|
1089
|
-
opts.colors ??= opts.colors ?? (opts.json ? false : true);
|
|
1090
|
-
opts.prefix ??= "Navios";
|
|
1091
|
-
this.options = opts;
|
|
1092
|
-
this.inspectOptions = this.getInspectOptions();
|
|
1093
|
-
if (context) {
|
|
1094
|
-
this.context = context;
|
|
1095
|
-
this.originalContext = context;
|
|
934
|
+
// packages/core/src/adapters/stream-adapter.service.mts
|
|
935
|
+
var StreamAdapterToken = InjectionToken.create(
|
|
936
|
+
Symbol.for("StreamAdapterService")
|
|
937
|
+
);
|
|
938
|
+
var _StreamAdapterService_decorators, _init;
|
|
939
|
+
_StreamAdapterService_decorators = [Injectable({
|
|
940
|
+
token: StreamAdapterToken
|
|
941
|
+
})];
|
|
942
|
+
var StreamAdapterService = class {
|
|
943
|
+
hasSchema(handlerMetadata) {
|
|
944
|
+
const config = handlerMetadata.config;
|
|
945
|
+
return !!config.requestSchema || !!config.querySchema;
|
|
946
|
+
}
|
|
947
|
+
prepareArguments(handlerMetadata) {
|
|
948
|
+
const config = handlerMetadata.config;
|
|
949
|
+
const getters = [];
|
|
950
|
+
if (config.querySchema) {
|
|
951
|
+
getters.push((target, request) => {
|
|
952
|
+
target.params = request.query;
|
|
953
|
+
});
|
|
1096
954
|
}
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
955
|
+
if (config.requestSchema) {
|
|
956
|
+
getters.push((target, request) => {
|
|
957
|
+
target.data = request.body;
|
|
958
|
+
});
|
|
1101
959
|
}
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
this.printMessages(messages, context, "log");
|
|
1107
|
-
}
|
|
1108
|
-
error(message, ...optionalParams) {
|
|
1109
|
-
if (!this.isLevelEnabled("error")) {
|
|
1110
|
-
return;
|
|
960
|
+
if (config.url.includes("$")) {
|
|
961
|
+
getters.push((target, request) => {
|
|
962
|
+
target.urlParams = request.params;
|
|
963
|
+
});
|
|
1111
964
|
}
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
965
|
+
return getters;
|
|
966
|
+
}
|
|
967
|
+
provideHandler(controller, executionContext, handlerMetadata) {
|
|
968
|
+
const getters = this.prepareArguments(handlerMetadata);
|
|
969
|
+
const formatArguments = async (request) => {
|
|
970
|
+
const argument = {};
|
|
971
|
+
const promises = [];
|
|
972
|
+
for (const getter of getters) {
|
|
973
|
+
const res = getter(argument, request);
|
|
974
|
+
if (res instanceof Promise) {
|
|
975
|
+
promises.push(res);
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
await Promise.all(promises);
|
|
979
|
+
return argument;
|
|
980
|
+
};
|
|
981
|
+
return async function(request, reply) {
|
|
982
|
+
const controllerInstance = await inject(controller);
|
|
983
|
+
const argument = await formatArguments(request);
|
|
984
|
+
await controllerInstance[handlerMetadata.classMethod](argument, reply);
|
|
985
|
+
};
|
|
1115
986
|
}
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
987
|
+
provideSchema(handlerMetadata) {
|
|
988
|
+
const schema = {};
|
|
989
|
+
const { querySchema, requestSchema } = handlerMetadata.config;
|
|
990
|
+
if (querySchema) {
|
|
991
|
+
schema.querystring = querySchema;
|
|
1119
992
|
}
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
...optionalParams
|
|
1123
|
-
]);
|
|
1124
|
-
this.printMessages(messages, context, "warn");
|
|
1125
|
-
}
|
|
1126
|
-
debug(message, ...optionalParams) {
|
|
1127
|
-
if (!this.isLevelEnabled("debug")) {
|
|
1128
|
-
return;
|
|
993
|
+
if (requestSchema) {
|
|
994
|
+
schema.body = requestSchema;
|
|
1129
995
|
}
|
|
1130
|
-
|
|
1131
|
-
message,
|
|
1132
|
-
...optionalParams
|
|
1133
|
-
]);
|
|
1134
|
-
this.printMessages(messages, context, "debug");
|
|
996
|
+
return schema;
|
|
1135
997
|
}
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
998
|
+
};
|
|
999
|
+
_init = __decoratorStart(null);
|
|
1000
|
+
StreamAdapterService = __decorateElement(_init, 0, "StreamAdapterService", _StreamAdapterService_decorators, StreamAdapterService);
|
|
1001
|
+
__runInitializers(_init, 1, StreamAdapterService);
|
|
1002
|
+
|
|
1003
|
+
// packages/core/src/adapters/endpoint-adapter.service.mts
|
|
1004
|
+
var EndpointAdapterToken = InjectionToken.create(
|
|
1005
|
+
Symbol.for("EndpointAdapterService")
|
|
1006
|
+
);
|
|
1007
|
+
var _EndpointAdapterService_decorators, _init2, _a;
|
|
1008
|
+
_EndpointAdapterService_decorators = [Injectable({
|
|
1009
|
+
token: EndpointAdapterToken
|
|
1010
|
+
})];
|
|
1011
|
+
var EndpointAdapterService = class extends (_a = StreamAdapterService) {
|
|
1012
|
+
hasSchema(handlerMetadata) {
|
|
1013
|
+
const config = handlerMetadata.config;
|
|
1014
|
+
return super.hasSchema(handlerMetadata) || !!config.responseSchema;
|
|
1015
|
+
}
|
|
1016
|
+
provideSchema(handlerMetadata) {
|
|
1017
|
+
const config = handlerMetadata.config;
|
|
1018
|
+
const schema = super.provideSchema(handlerMetadata);
|
|
1019
|
+
if (config.responseSchema) {
|
|
1020
|
+
schema.response = {
|
|
1021
|
+
200: config.responseSchema
|
|
1022
|
+
};
|
|
1139
1023
|
}
|
|
1140
|
-
|
|
1141
|
-
message,
|
|
1142
|
-
...optionalParams
|
|
1143
|
-
]);
|
|
1144
|
-
this.printMessages(messages, context, "verbose");
|
|
1024
|
+
return schema;
|
|
1145
1025
|
}
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1026
|
+
provideHandler(controller, executionContext, handlerMetadata) {
|
|
1027
|
+
const getters = this.prepareArguments(handlerMetadata);
|
|
1028
|
+
const formatArguments = async (request) => {
|
|
1029
|
+
const argument = {};
|
|
1030
|
+
const promises = [];
|
|
1031
|
+
for (const getter of getters) {
|
|
1032
|
+
const res = getter(argument, request);
|
|
1033
|
+
if (res instanceof Promise) {
|
|
1034
|
+
promises.push(res);
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
await Promise.all(promises);
|
|
1038
|
+
return argument;
|
|
1039
|
+
};
|
|
1040
|
+
return async function(request, reply) {
|
|
1041
|
+
const controllerInstance = await inject(controller);
|
|
1042
|
+
const argument = await formatArguments(request);
|
|
1043
|
+
const result = await controllerInstance[handlerMetadata.classMethod](argument);
|
|
1044
|
+
reply.status(handlerMetadata.successStatusCode).headers(handlerMetadata.headers).send(result);
|
|
1045
|
+
};
|
|
1155
1046
|
}
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1047
|
+
};
|
|
1048
|
+
_init2 = __decoratorStart(_a);
|
|
1049
|
+
EndpointAdapterService = __decorateElement(_init2, 0, "EndpointAdapterService", _EndpointAdapterService_decorators, EndpointAdapterService);
|
|
1050
|
+
__runInitializers(_init2, 1, EndpointAdapterService);
|
|
1051
|
+
|
|
1052
|
+
// packages/core/src/adapters/multipart-adapter.service.mts
|
|
1053
|
+
import { ZodArray, ZodObject, ZodOptional as ZodOptional2 } from "zod";
|
|
1054
|
+
var MultipartAdapterToken = InjectionToken.create(
|
|
1055
|
+
Symbol.for("MultipartAdapterService")
|
|
1056
|
+
);
|
|
1057
|
+
var _MultipartAdapterService_decorators, _init3, _a2;
|
|
1058
|
+
_MultipartAdapterService_decorators = [Injectable({
|
|
1059
|
+
token: MultipartAdapterToken
|
|
1060
|
+
})];
|
|
1061
|
+
var MultipartAdapterService = class extends (_a2 = EndpointAdapterService) {
|
|
1062
|
+
prepareArguments(handlerMetadata) {
|
|
1063
|
+
const config = handlerMetadata.config;
|
|
1064
|
+
const getters = [];
|
|
1065
|
+
if (config.querySchema) {
|
|
1066
|
+
getters.push((target, request) => {
|
|
1067
|
+
target.params = request.query;
|
|
1068
|
+
});
|
|
1163
1069
|
}
|
|
1164
|
-
|
|
1070
|
+
if (config.url.includes("$")) {
|
|
1071
|
+
getters.push((target, request) => {
|
|
1072
|
+
target.urlParams = request.params;
|
|
1073
|
+
});
|
|
1074
|
+
}
|
|
1075
|
+
const requestSchema = config.requestSchema;
|
|
1076
|
+
const shape = requestSchema._def.shape();
|
|
1077
|
+
const structure = this.analyzeSchema(shape);
|
|
1078
|
+
getters.push(async (target, request) => {
|
|
1079
|
+
const req = {};
|
|
1080
|
+
for await (const part of request.parts()) {
|
|
1081
|
+
await this.populateRequest(structure, part, req);
|
|
1082
|
+
}
|
|
1083
|
+
target.data = requestSchema.parse(req);
|
|
1084
|
+
});
|
|
1085
|
+
return getters;
|
|
1086
|
+
}
|
|
1087
|
+
async populateRequest(structure, part, req) {
|
|
1088
|
+
const { isArray, isObject: isObject2 } = structure[part.fieldname] ?? {};
|
|
1089
|
+
if (isArray && !req[part.fieldname]) {
|
|
1090
|
+
req[part.fieldname] = [];
|
|
1091
|
+
}
|
|
1092
|
+
let value;
|
|
1093
|
+
if (part.type === "file") {
|
|
1094
|
+
value = new File([await part.toBuffer()], part.filename, {
|
|
1095
|
+
type: part.mimetype
|
|
1096
|
+
});
|
|
1097
|
+
} else {
|
|
1098
|
+
value = part.value;
|
|
1099
|
+
if (isObject2 && typeof value === "string") {
|
|
1100
|
+
value = JSON.parse(value);
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
if (isArray) {
|
|
1104
|
+
req[part.fieldname].push(value);
|
|
1105
|
+
} else {
|
|
1106
|
+
req[part.fieldname] = value;
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
analyzeSchema(shape) {
|
|
1110
|
+
return Object.keys(shape).reduce(
|
|
1111
|
+
(target, key) => {
|
|
1112
|
+
let schema = shape[key];
|
|
1113
|
+
const isOptional = schema instanceof ZodOptional2;
|
|
1114
|
+
if (isOptional) {
|
|
1115
|
+
schema = schema.unwrap();
|
|
1116
|
+
}
|
|
1117
|
+
const isArray = schema instanceof ZodArray;
|
|
1118
|
+
if (isArray) {
|
|
1119
|
+
schema = schema.element;
|
|
1120
|
+
}
|
|
1121
|
+
const isObject2 = schema instanceof ZodObject;
|
|
1122
|
+
return {
|
|
1123
|
+
...target,
|
|
1124
|
+
[key]: {
|
|
1125
|
+
isArray,
|
|
1126
|
+
isOptional,
|
|
1127
|
+
isObject: isObject2
|
|
1128
|
+
}
|
|
1129
|
+
};
|
|
1130
|
+
},
|
|
1131
|
+
{}
|
|
1132
|
+
);
|
|
1133
|
+
}
|
|
1134
|
+
provideSchema(handlerMetadata) {
|
|
1135
|
+
const schema = {};
|
|
1136
|
+
const { querySchema, responseSchema } = handlerMetadata.config;
|
|
1137
|
+
if (querySchema) {
|
|
1138
|
+
schema.querystring = querySchema;
|
|
1139
|
+
}
|
|
1140
|
+
if (responseSchema) {
|
|
1141
|
+
schema.response = {
|
|
1142
|
+
200: responseSchema
|
|
1143
|
+
};
|
|
1144
|
+
}
|
|
1145
|
+
return schema;
|
|
1146
|
+
}
|
|
1147
|
+
};
|
|
1148
|
+
_init3 = __decoratorStart(_a2);
|
|
1149
|
+
MultipartAdapterService = __decorateElement(_init3, 0, "MultipartAdapterService", _MultipartAdapterService_decorators, MultipartAdapterService);
|
|
1150
|
+
__runInitializers(_init3, 1, MultipartAdapterService);
|
|
1151
|
+
|
|
1152
|
+
// packages/core/src/config/utils/helpers.mts
|
|
1153
|
+
import { env } from "node:process";
|
|
1154
|
+
function envInt(key, defaultValue) {
|
|
1155
|
+
const envKey = env[key] || process.env[key];
|
|
1156
|
+
return envKey ? parseInt(envKey, 10) : defaultValue;
|
|
1157
|
+
}
|
|
1158
|
+
function envString(key, defaultValue) {
|
|
1159
|
+
return env[key] || process.env[key] || defaultValue || void 0;
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
// packages/core/src/config/config.provider.mts
|
|
1163
|
+
import { z as z3 } from "zod";
|
|
1164
|
+
|
|
1165
|
+
// packages/core/src/logger/utils/cli-colors.util.mts
|
|
1166
|
+
var isColorAllowed = () => !process.env.NO_COLOR;
|
|
1167
|
+
var colorIfAllowed = (colorFn) => (text) => isColorAllowed() ? colorFn(text) : text;
|
|
1168
|
+
var clc = {
|
|
1169
|
+
bold: colorIfAllowed((text) => `\x1B[1m${text}\x1B[0m`),
|
|
1170
|
+
green: colorIfAllowed((text) => `\x1B[32m${text}\x1B[39m`),
|
|
1171
|
+
yellow: colorIfAllowed((text) => `\x1B[33m${text}\x1B[39m`),
|
|
1172
|
+
red: colorIfAllowed((text) => `\x1B[31m${text}\x1B[39m`),
|
|
1173
|
+
magentaBright: colorIfAllowed((text) => `\x1B[95m${text}\x1B[39m`),
|
|
1174
|
+
cyanBright: colorIfAllowed((text) => `\x1B[96m${text}\x1B[39m`)
|
|
1175
|
+
};
|
|
1176
|
+
var yellow = colorIfAllowed(
|
|
1177
|
+
(text) => `\x1B[38;5;3m${text}\x1B[39m`
|
|
1178
|
+
);
|
|
1179
|
+
|
|
1180
|
+
// packages/core/src/logger/log-levels.mts
|
|
1181
|
+
var LOG_LEVELS = [
|
|
1182
|
+
"verbose",
|
|
1183
|
+
"debug",
|
|
1184
|
+
"log",
|
|
1185
|
+
"warn",
|
|
1186
|
+
"error",
|
|
1187
|
+
"fatal"
|
|
1188
|
+
];
|
|
1189
|
+
|
|
1190
|
+
// packages/core/src/logger/utils/is-log-level.util.mts
|
|
1191
|
+
function isLogLevel(maybeLogLevel) {
|
|
1192
|
+
return LOG_LEVELS.includes(maybeLogLevel);
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
// packages/core/src/logger/utils/filter-log-levelts.util.mts
|
|
1196
|
+
function filterLogLevels(parseableString = "") {
|
|
1197
|
+
const sanitizedString = parseableString.replaceAll(" ", "").toLowerCase();
|
|
1198
|
+
if (sanitizedString[0] === ">") {
|
|
1199
|
+
const orEqual = sanitizedString[1] === "=";
|
|
1200
|
+
const logLevelIndex = LOG_LEVELS.indexOf(
|
|
1201
|
+
sanitizedString.substring(orEqual ? 2 : 1)
|
|
1202
|
+
);
|
|
1203
|
+
if (logLevelIndex === -1) {
|
|
1204
|
+
throw new Error(`parse error (unknown log level): ${sanitizedString}`);
|
|
1205
|
+
}
|
|
1206
|
+
return LOG_LEVELS.slice(orEqual ? logLevelIndex : logLevelIndex + 1);
|
|
1207
|
+
} else if (sanitizedString.includes(",")) {
|
|
1208
|
+
return sanitizedString.split(",").filter(isLogLevel);
|
|
1209
|
+
}
|
|
1210
|
+
return isLogLevel(sanitizedString) ? [sanitizedString] : LOG_LEVELS;
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
// packages/core/src/logger/utils/is-log-level-enabled.mts
|
|
1214
|
+
var LOG_LEVEL_VALUES = {
|
|
1215
|
+
verbose: 0,
|
|
1216
|
+
debug: 1,
|
|
1217
|
+
log: 2,
|
|
1218
|
+
warn: 3,
|
|
1219
|
+
error: 4,
|
|
1220
|
+
fatal: 5
|
|
1221
|
+
};
|
|
1222
|
+
function isLogLevelEnabled(targetLevel, logLevels) {
|
|
1223
|
+
var _a3;
|
|
1224
|
+
if (!logLevels || Array.isArray(logLevels) && (logLevels == null ? void 0 : logLevels.length) === 0) {
|
|
1225
|
+
return false;
|
|
1226
|
+
}
|
|
1227
|
+
if (logLevels.includes(targetLevel)) {
|
|
1228
|
+
return true;
|
|
1229
|
+
}
|
|
1230
|
+
const highestLogLevelValue = (_a3 = logLevels.map((level) => LOG_LEVEL_VALUES[level]).sort((a, b) => b - a)) == null ? void 0 : _a3[0];
|
|
1231
|
+
const targetLevelValue = LOG_LEVEL_VALUES[targetLevel];
|
|
1232
|
+
return targetLevelValue >= highestLogLevelValue;
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
// packages/core/src/logger/utils/shared.utils.mts
|
|
1236
|
+
var isUndefined = (obj) => typeof obj === "undefined";
|
|
1237
|
+
var isObject = (fn) => !isNil(fn) && typeof fn === "object";
|
|
1238
|
+
var isPlainObject = (fn) => {
|
|
1239
|
+
if (!isObject(fn)) {
|
|
1240
|
+
return false;
|
|
1241
|
+
}
|
|
1242
|
+
const proto = Object.getPrototypeOf(fn);
|
|
1243
|
+
if (proto === null) {
|
|
1244
|
+
return true;
|
|
1245
|
+
}
|
|
1246
|
+
const ctor = Object.prototype.hasOwnProperty.call(proto, "constructor") && proto.constructor;
|
|
1247
|
+
return typeof ctor === "function" && ctor instanceof ctor && Function.prototype.toString.call(ctor) === Function.prototype.toString.call(Object);
|
|
1248
|
+
};
|
|
1249
|
+
var addLeadingSlash = (path) => path && typeof path === "string" ? path.charAt(0) !== "/" && path.substring(0, 2) !== "{/" ? "/" + path : path : "";
|
|
1250
|
+
var normalizePath = (path) => path ? path.startsWith("/") ? ("/" + path.replace(/\/+$/, "")).replace(/\/+/g, "/") : "/" + path.replace(/\/+$/, "") : "/";
|
|
1251
|
+
var stripEndSlash = (path) => path[path.length - 1] === "/" ? path.slice(0, path.length - 1) : path;
|
|
1252
|
+
var isFunction = (val) => typeof val === "function";
|
|
1253
|
+
var isString = (val) => typeof val === "string";
|
|
1254
|
+
var isNumber = (val) => typeof val === "number";
|
|
1255
|
+
var isConstructor = (val) => val === "constructor";
|
|
1256
|
+
var isNil = (val) => isUndefined(val) || val === null;
|
|
1257
|
+
var isEmpty = (array) => !(array && array.length > 0);
|
|
1258
|
+
var isSymbol = (val) => typeof val === "symbol";
|
|
1259
|
+
|
|
1260
|
+
// packages/core/src/logger/console-logger.service.mts
|
|
1261
|
+
import { inspect } from "util";
|
|
1262
|
+
|
|
1263
|
+
// packages/core/src/tokens/application.token.mts
|
|
1264
|
+
var ApplicationInjectionToken = "ApplicationInjectionToken";
|
|
1265
|
+
var Application = InjectionToken.create(
|
|
1266
|
+
ApplicationInjectionToken
|
|
1267
|
+
);
|
|
1268
|
+
|
|
1269
|
+
// packages/core/src/metadata/handler.metadata.mts
|
|
1270
|
+
var EndpointMetadataKey = Symbol("EndpointMetadataKey");
|
|
1271
|
+
function getAllEndpointMetadata(context) {
|
|
1272
|
+
if (context.metadata) {
|
|
1273
|
+
const metadata = context.metadata[EndpointMetadataKey];
|
|
1274
|
+
if (metadata) {
|
|
1275
|
+
return metadata;
|
|
1276
|
+
} else {
|
|
1277
|
+
context.metadata[EndpointMetadataKey] = /* @__PURE__ */ new Set();
|
|
1278
|
+
return context.metadata[EndpointMetadataKey];
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
throw new Error("[Navios] Wrong environment.");
|
|
1282
|
+
}
|
|
1283
|
+
function getEndpointMetadata(target, context) {
|
|
1284
|
+
if (context.metadata) {
|
|
1285
|
+
const metadata = getAllEndpointMetadata(context);
|
|
1286
|
+
if (metadata) {
|
|
1287
|
+
const endpointMetadata = Array.from(metadata).find(
|
|
1288
|
+
(item) => item.classMethod === target.name
|
|
1289
|
+
);
|
|
1290
|
+
if (endpointMetadata) {
|
|
1291
|
+
return endpointMetadata;
|
|
1292
|
+
} else {
|
|
1293
|
+
const newMetadata = {
|
|
1294
|
+
classMethod: target.name,
|
|
1295
|
+
url: "",
|
|
1296
|
+
successStatusCode: 200,
|
|
1297
|
+
adapterToken: null,
|
|
1298
|
+
headers: {},
|
|
1299
|
+
httpMethod: "GET",
|
|
1300
|
+
// @ts-expect-error We are using a generic type here
|
|
1301
|
+
config: null,
|
|
1302
|
+
guards: /* @__PURE__ */ new Set(),
|
|
1303
|
+
customAttributes: /* @__PURE__ */ new Map()
|
|
1304
|
+
};
|
|
1305
|
+
metadata.add(newMetadata);
|
|
1306
|
+
return newMetadata;
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
throw new Error("[Navios] Wrong environment.");
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
// packages/core/src/metadata/controller.metadata.mts
|
|
1314
|
+
var ControllerMetadataKey = Symbol("ControllerMetadataKey");
|
|
1315
|
+
function getControllerMetadata(target, context) {
|
|
1316
|
+
if (context.metadata) {
|
|
1317
|
+
const metadata = context.metadata[ControllerMetadataKey];
|
|
1318
|
+
if (metadata) {
|
|
1319
|
+
return metadata;
|
|
1320
|
+
} else {
|
|
1321
|
+
const endpointsMetadata = getAllEndpointMetadata(context);
|
|
1322
|
+
const newMetadata = {
|
|
1323
|
+
endpoints: endpointsMetadata,
|
|
1324
|
+
guards: /* @__PURE__ */ new Set(),
|
|
1325
|
+
customAttributes: /* @__PURE__ */ new Map()
|
|
1326
|
+
};
|
|
1327
|
+
context.metadata[ControllerMetadataKey] = newMetadata;
|
|
1328
|
+
target[ControllerMetadataKey] = newMetadata;
|
|
1329
|
+
return newMetadata;
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
throw new Error("[Navios] Wrong environment.");
|
|
1333
|
+
}
|
|
1334
|
+
function extractControllerMetadata(target) {
|
|
1335
|
+
const metadata = target[ControllerMetadataKey];
|
|
1336
|
+
if (!metadata) {
|
|
1337
|
+
throw new Error(
|
|
1338
|
+
"[Navios] Controller metadata not found. Make sure to use @Controller decorator."
|
|
1339
|
+
);
|
|
1340
|
+
}
|
|
1341
|
+
return metadata;
|
|
1342
|
+
}
|
|
1343
|
+
function hasControllerMetadata(target) {
|
|
1344
|
+
const metadata = target[ControllerMetadataKey];
|
|
1345
|
+
return !!metadata;
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
// packages/core/src/metadata/module.metadata.mts
|
|
1349
|
+
var ModuleMetadataKey = Symbol("ControllerMetadataKey");
|
|
1350
|
+
function getModuleMetadata(target, context) {
|
|
1351
|
+
if (context.metadata) {
|
|
1352
|
+
const metadata = context.metadata[ModuleMetadataKey];
|
|
1353
|
+
if (metadata) {
|
|
1354
|
+
return metadata;
|
|
1355
|
+
} else {
|
|
1356
|
+
const newMetadata = {
|
|
1357
|
+
controllers: /* @__PURE__ */ new Set(),
|
|
1358
|
+
imports: /* @__PURE__ */ new Set(),
|
|
1359
|
+
guards: /* @__PURE__ */ new Set(),
|
|
1360
|
+
customAttributes: /* @__PURE__ */ new Map()
|
|
1361
|
+
};
|
|
1362
|
+
context.metadata[ModuleMetadataKey] = newMetadata;
|
|
1363
|
+
target[ModuleMetadataKey] = newMetadata;
|
|
1364
|
+
return newMetadata;
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
throw new Error("[Navios] Wrong environment.");
|
|
1368
|
+
}
|
|
1369
|
+
function extractModuleMetadata(target) {
|
|
1370
|
+
const metadata = target[ModuleMetadataKey];
|
|
1371
|
+
if (!metadata) {
|
|
1372
|
+
throw new Error(
|
|
1373
|
+
`[Navios] Module metadata not found for ${target.name}. Make sure to use @Module decorator.`
|
|
1374
|
+
);
|
|
1375
|
+
}
|
|
1376
|
+
return metadata;
|
|
1377
|
+
}
|
|
1378
|
+
function hasModuleMetadata(target) {
|
|
1379
|
+
return !!target[ModuleMetadataKey];
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
// packages/core/src/services/execution-context.mts
|
|
1383
|
+
var ExecutionContext = class {
|
|
1384
|
+
constructor(module, controller, handler) {
|
|
1385
|
+
this.module = module;
|
|
1386
|
+
this.controller = controller;
|
|
1387
|
+
this.handler = handler;
|
|
1388
|
+
}
|
|
1389
|
+
request;
|
|
1390
|
+
reply;
|
|
1391
|
+
getModule() {
|
|
1392
|
+
return this.module;
|
|
1393
|
+
}
|
|
1394
|
+
getController() {
|
|
1395
|
+
return this.controller;
|
|
1396
|
+
}
|
|
1397
|
+
getHandler() {
|
|
1398
|
+
return this.handler;
|
|
1399
|
+
}
|
|
1400
|
+
getRequest() {
|
|
1401
|
+
if (!this.request) {
|
|
1402
|
+
throw new Error(
|
|
1403
|
+
"[Navios] Request is not set. Make sure to set it before using it."
|
|
1404
|
+
);
|
|
1405
|
+
}
|
|
1406
|
+
return this.request;
|
|
1407
|
+
}
|
|
1408
|
+
getReply() {
|
|
1409
|
+
if (!this.reply) {
|
|
1410
|
+
throw new Error(
|
|
1411
|
+
"[Navios] Reply is not set. Make sure to set it before using it."
|
|
1412
|
+
);
|
|
1413
|
+
}
|
|
1414
|
+
return this.reply;
|
|
1415
|
+
}
|
|
1416
|
+
provideRequest(request) {
|
|
1417
|
+
this.request = request;
|
|
1418
|
+
}
|
|
1419
|
+
provideReply(reply) {
|
|
1420
|
+
this.reply = reply;
|
|
1421
|
+
}
|
|
1422
|
+
};
|
|
1423
|
+
|
|
1424
|
+
// packages/core/src/exceptions/http.exception.mts
|
|
1425
|
+
var HttpException = class {
|
|
1426
|
+
constructor(statusCode, response, error) {
|
|
1427
|
+
this.statusCode = statusCode;
|
|
1428
|
+
this.response = response;
|
|
1429
|
+
this.error = error;
|
|
1430
|
+
}
|
|
1431
|
+
};
|
|
1432
|
+
|
|
1433
|
+
// packages/core/src/exceptions/bad-request.exception.mts
|
|
1434
|
+
var BadRequestException = class extends HttpException {
|
|
1435
|
+
constructor(message) {
|
|
1436
|
+
super(400, message);
|
|
1437
|
+
}
|
|
1438
|
+
};
|
|
1439
|
+
|
|
1440
|
+
// packages/core/src/exceptions/forbidden.exception.mts
|
|
1441
|
+
var ForbiddenException = class extends HttpException {
|
|
1442
|
+
constructor(message) {
|
|
1443
|
+
super(403, message);
|
|
1444
|
+
}
|
|
1445
|
+
};
|
|
1446
|
+
|
|
1447
|
+
// packages/core/src/exceptions/internal-server-error.exception.mts
|
|
1448
|
+
var InternalServerErrorException = class extends HttpException {
|
|
1449
|
+
constructor(message, error) {
|
|
1450
|
+
super(500, message, error);
|
|
1451
|
+
}
|
|
1452
|
+
};
|
|
1453
|
+
|
|
1454
|
+
// packages/core/src/exceptions/not-found.exception.mts
|
|
1455
|
+
var NotFoundException = class extends HttpException {
|
|
1456
|
+
constructor(response, error) {
|
|
1457
|
+
super(404, response, error);
|
|
1458
|
+
this.response = response;
|
|
1459
|
+
this.error = error;
|
|
1460
|
+
}
|
|
1461
|
+
};
|
|
1462
|
+
|
|
1463
|
+
// packages/core/src/exceptions/unauthorized.exception.mts
|
|
1464
|
+
var UnauthorizedException = class extends HttpException {
|
|
1465
|
+
constructor(message, error) {
|
|
1466
|
+
super(401, message, error);
|
|
1467
|
+
}
|
|
1468
|
+
};
|
|
1469
|
+
|
|
1470
|
+
// packages/core/src/exceptions/conflict.exception.mts
|
|
1471
|
+
var ConflictException = class extends HttpException {
|
|
1472
|
+
constructor(message, error) {
|
|
1473
|
+
super(409, message, error);
|
|
1474
|
+
}
|
|
1475
|
+
};
|
|
1476
|
+
|
|
1477
|
+
// packages/core/src/services/guard-runner.service.mts
|
|
1478
|
+
var _GuardRunnerService_decorators, _init4;
|
|
1479
|
+
_GuardRunnerService_decorators = [Injectable()];
|
|
1480
|
+
var GuardRunnerService = class {
|
|
1481
|
+
async runGuards(allGuards, executionContext) {
|
|
1482
|
+
let canActivate = true;
|
|
1483
|
+
for (const guard of Array.from(allGuards).reverse()) {
|
|
1484
|
+
const guardInstance = await inject(
|
|
1485
|
+
guard
|
|
1486
|
+
);
|
|
1487
|
+
if (!guardInstance.canActivate) {
|
|
1488
|
+
throw new Error(
|
|
1489
|
+
`[Navios] Guard ${guard.name} does not implement canActivate()`
|
|
1490
|
+
);
|
|
1491
|
+
}
|
|
1492
|
+
try {
|
|
1493
|
+
canActivate = await guardInstance.canActivate(executionContext);
|
|
1494
|
+
if (!canActivate) {
|
|
1495
|
+
break;
|
|
1496
|
+
}
|
|
1497
|
+
} catch (error) {
|
|
1498
|
+
if (error instanceof HttpException) {
|
|
1499
|
+
executionContext.getReply().status(error.statusCode).send(error.response);
|
|
1500
|
+
return false;
|
|
1501
|
+
} else {
|
|
1502
|
+
executionContext.getReply().status(500).send({
|
|
1503
|
+
message: "Internal server error",
|
|
1504
|
+
error: error.message
|
|
1505
|
+
});
|
|
1506
|
+
return false;
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
if (!canActivate) {
|
|
1511
|
+
executionContext.getReply().status(403).send({
|
|
1512
|
+
message: "Forbidden"
|
|
1513
|
+
});
|
|
1514
|
+
return false;
|
|
1515
|
+
}
|
|
1516
|
+
return canActivate;
|
|
1517
|
+
}
|
|
1518
|
+
makeContext(executionContext) {
|
|
1519
|
+
const guards = /* @__PURE__ */ new Set();
|
|
1520
|
+
const endpointGuards = executionContext.getHandler().guards;
|
|
1521
|
+
const controllerGuards = executionContext.getController().guards;
|
|
1522
|
+
const moduleGuards = executionContext.getModule().guards;
|
|
1523
|
+
if (endpointGuards.size > 0) {
|
|
1524
|
+
for (const guard of endpointGuards) {
|
|
1525
|
+
guards.add(guard);
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
if (controllerGuards.size > 0) {
|
|
1529
|
+
for (const guard of controllerGuards) {
|
|
1530
|
+
guards.add(guard);
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
if (moduleGuards.size > 0) {
|
|
1534
|
+
for (const guard of moduleGuards) {
|
|
1535
|
+
guards.add(guard);
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
return guards;
|
|
1539
|
+
}
|
|
1540
|
+
};
|
|
1541
|
+
_init4 = __decoratorStart(null);
|
|
1542
|
+
GuardRunnerService = __decorateElement(_init4, 0, "GuardRunnerService", _GuardRunnerService_decorators, GuardRunnerService);
|
|
1543
|
+
__runInitializers(_init4, 1, GuardRunnerService);
|
|
1544
|
+
|
|
1545
|
+
// packages/core/src/services/controller-adapter.service.mts
|
|
1546
|
+
var _ControllerAdapterService_decorators, _init5;
|
|
1547
|
+
_ControllerAdapterService_decorators = [Injectable()];
|
|
1548
|
+
var _ControllerAdapterService = class _ControllerAdapterService {
|
|
1549
|
+
guardRunner = syncInject(GuardRunnerService);
|
|
1550
|
+
logger = syncInject(Logger, {
|
|
1551
|
+
context: _ControllerAdapterService.name
|
|
1552
|
+
});
|
|
1553
|
+
async setupController(controller, instance, moduleMetadata) {
|
|
1554
|
+
var _a3, _b;
|
|
1555
|
+
const controllerMetadata = extractControllerMetadata(controller);
|
|
1556
|
+
for (const endpoint of controllerMetadata.endpoints) {
|
|
1557
|
+
const { classMethod, url, httpMethod, adapterToken } = endpoint;
|
|
1558
|
+
if (!url || !adapterToken) {
|
|
1559
|
+
throw new Error(
|
|
1560
|
+
`[Navios] Malformed Endpoint ${controller.name}:${classMethod}`
|
|
1561
|
+
);
|
|
1562
|
+
}
|
|
1563
|
+
const adapter = await inject(
|
|
1564
|
+
adapterToken
|
|
1565
|
+
);
|
|
1566
|
+
const executionContext = new ExecutionContext(
|
|
1567
|
+
moduleMetadata,
|
|
1568
|
+
controllerMetadata,
|
|
1569
|
+
endpoint
|
|
1570
|
+
);
|
|
1571
|
+
const hasSchema = ((_a3 = adapter.hasSchema) == null ? void 0 : _a3.call(adapter, endpoint)) ?? false;
|
|
1572
|
+
if (hasSchema) {
|
|
1573
|
+
instance.withTypeProvider().route({
|
|
1574
|
+
method: httpMethod,
|
|
1575
|
+
url: url.replaceAll("$", ":"),
|
|
1576
|
+
schema: ((_b = adapter.provideSchema) == null ? void 0 : _b.call(adapter, endpoint)) ?? {},
|
|
1577
|
+
preHandler: this.providePreHandler(executionContext),
|
|
1578
|
+
handler: this.wrapHandler(
|
|
1579
|
+
executionContext,
|
|
1580
|
+
adapter.provideHandler(controller, executionContext, endpoint)
|
|
1581
|
+
)
|
|
1582
|
+
});
|
|
1583
|
+
} else {
|
|
1584
|
+
instance.route({
|
|
1585
|
+
method: httpMethod,
|
|
1586
|
+
url: url.replaceAll("$", ":"),
|
|
1587
|
+
preHandler: this.providePreHandler(executionContext),
|
|
1588
|
+
handler: this.wrapHandler(
|
|
1589
|
+
executionContext,
|
|
1590
|
+
adapter.provideHandler(controller, executionContext, endpoint)
|
|
1591
|
+
)
|
|
1592
|
+
});
|
|
1593
|
+
}
|
|
1594
|
+
this.logger.debug(
|
|
1595
|
+
`Registered ${httpMethod} ${url} for ${controller.name}:${classMethod}`
|
|
1596
|
+
);
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
providePreHandler(executionContext) {
|
|
1600
|
+
const guards = this.guardRunner.makeContext(executionContext);
|
|
1601
|
+
return guards.size > 0 ? this.wrapHandler(
|
|
1602
|
+
executionContext,
|
|
1603
|
+
async (request, reply) => {
|
|
1604
|
+
let canActivate = true;
|
|
1605
|
+
canActivate = await this.guardRunner.runGuards(
|
|
1606
|
+
guards,
|
|
1607
|
+
executionContext
|
|
1608
|
+
);
|
|
1609
|
+
if (!canActivate) {
|
|
1610
|
+
return reply;
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
) : void 0;
|
|
1614
|
+
}
|
|
1615
|
+
wrapHandler(executionContext, handler) {
|
|
1616
|
+
const locator = getServiceLocator();
|
|
1617
|
+
return async (request, reply) => {
|
|
1618
|
+
locator.registerInstance(Request, request);
|
|
1619
|
+
locator.registerInstance(Reply, reply);
|
|
1620
|
+
locator.registerInstance(ExecutionContextToken, executionContext);
|
|
1621
|
+
executionContext.provideRequest(request);
|
|
1622
|
+
executionContext.provideReply(reply);
|
|
1623
|
+
try {
|
|
1624
|
+
return await handler(request, reply);
|
|
1625
|
+
} finally {
|
|
1626
|
+
Promise.all([
|
|
1627
|
+
locator.removeInstance(Request),
|
|
1628
|
+
locator.removeInstance(Reply),
|
|
1629
|
+
locator.removeInstance(ExecutionContextToken)
|
|
1630
|
+
]).catch((err) => {
|
|
1631
|
+
this.logger.warn(`Error removing instances: ${err}`);
|
|
1632
|
+
});
|
|
1633
|
+
}
|
|
1634
|
+
};
|
|
1635
|
+
}
|
|
1636
|
+
};
|
|
1637
|
+
_init5 = __decoratorStart(null);
|
|
1638
|
+
_ControllerAdapterService = __decorateElement(_init5, 0, "ControllerAdapterService", _ControllerAdapterService_decorators, _ControllerAdapterService);
|
|
1639
|
+
__runInitializers(_init5, 1, _ControllerAdapterService);
|
|
1640
|
+
var ControllerAdapterService = _ControllerAdapterService;
|
|
1641
|
+
|
|
1642
|
+
// packages/core/src/services/module-loader.service.mts
|
|
1643
|
+
var _ModuleLoaderService_decorators, _init6;
|
|
1644
|
+
_ModuleLoaderService_decorators = [Injectable()];
|
|
1645
|
+
var _ModuleLoaderService = class _ModuleLoaderService {
|
|
1646
|
+
logger = syncInject(Logger, {
|
|
1647
|
+
context: _ModuleLoaderService.name
|
|
1648
|
+
});
|
|
1649
|
+
modulesMetadata = /* @__PURE__ */ new Map();
|
|
1650
|
+
loadedModules = /* @__PURE__ */ new Map();
|
|
1651
|
+
initialized = false;
|
|
1652
|
+
async loadModules(appModule) {
|
|
1653
|
+
if (this.initialized) {
|
|
1654
|
+
return;
|
|
1655
|
+
}
|
|
1656
|
+
await this.traverseModules(appModule);
|
|
1657
|
+
this.initialized = true;
|
|
1658
|
+
}
|
|
1659
|
+
async traverseModules(module, parentMetadata) {
|
|
1660
|
+
const metadata = extractModuleMetadata(module);
|
|
1661
|
+
if (parentMetadata) {
|
|
1662
|
+
this.mergeMetadata(metadata, parentMetadata);
|
|
1663
|
+
}
|
|
1664
|
+
const moduleName = module.name;
|
|
1665
|
+
if (this.modulesMetadata.has(moduleName)) {
|
|
1666
|
+
return;
|
|
1667
|
+
}
|
|
1668
|
+
this.modulesMetadata.set(moduleName, metadata);
|
|
1669
|
+
const imports = metadata.imports ?? /* @__PURE__ */ new Set();
|
|
1670
|
+
const loadingPromises = Array.from(imports).map(
|
|
1671
|
+
async (importedModule) => this.traverseModules(importedModule, metadata)
|
|
1672
|
+
);
|
|
1673
|
+
await Promise.all(loadingPromises);
|
|
1674
|
+
const instance = await inject(module);
|
|
1675
|
+
if (instance.onModuleInit) {
|
|
1676
|
+
await instance.onModuleInit();
|
|
1677
|
+
}
|
|
1678
|
+
this.logger.debug(`Module ${moduleName} loaded`);
|
|
1679
|
+
this.loadedModules.set(moduleName, instance);
|
|
1680
|
+
}
|
|
1681
|
+
mergeMetadata(metadata, parentMetadata) {
|
|
1682
|
+
if (parentMetadata.guards) {
|
|
1683
|
+
for (const guard of parentMetadata.guards) {
|
|
1684
|
+
metadata.guards.add(guard);
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
if (parentMetadata.customAttributes) {
|
|
1688
|
+
for (const [key, value] of parentMetadata.customAttributes) {
|
|
1689
|
+
if (metadata.customAttributes.has(key)) {
|
|
1690
|
+
continue;
|
|
1691
|
+
}
|
|
1692
|
+
metadata.customAttributes.set(key, value);
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
getAllModules() {
|
|
1697
|
+
return this.modulesMetadata;
|
|
1698
|
+
}
|
|
1699
|
+
dispose() {
|
|
1700
|
+
this.modulesMetadata.clear();
|
|
1701
|
+
this.loadedModules.clear();
|
|
1702
|
+
this.initialized = false;
|
|
1703
|
+
}
|
|
1704
|
+
};
|
|
1705
|
+
_init6 = __decoratorStart(null);
|
|
1706
|
+
_ModuleLoaderService = __decorateElement(_init6, 0, "ModuleLoaderService", _ModuleLoaderService_decorators, _ModuleLoaderService);
|
|
1707
|
+
__runInitializers(_init6, 1, _ModuleLoaderService);
|
|
1708
|
+
var ModuleLoaderService = _ModuleLoaderService;
|
|
1709
|
+
|
|
1710
|
+
// packages/core/src/tokens/execution-context.token.mts
|
|
1711
|
+
var ExecutionContextInjectionToken = "ExecutionContextInjectionToken";
|
|
1712
|
+
var ExecutionContextToken = InjectionToken.create(
|
|
1713
|
+
ExecutionContextInjectionToken
|
|
1714
|
+
);
|
|
1715
|
+
|
|
1716
|
+
// packages/core/src/tokens/reply.token.mts
|
|
1717
|
+
var ReplyInjectionToken = "ReplyInjectionToken";
|
|
1718
|
+
var Reply = InjectionToken.create(ReplyInjectionToken);
|
|
1719
|
+
|
|
1720
|
+
// packages/core/src/tokens/request.token.mts
|
|
1721
|
+
var RequestInjectionToken = "RequestInjectionToken";
|
|
1722
|
+
var Request = InjectionToken.create(
|
|
1723
|
+
RequestInjectionToken
|
|
1724
|
+
);
|
|
1725
|
+
|
|
1726
|
+
// packages/core/src/logger/console-logger.service.mts
|
|
1727
|
+
var DEFAULT_DEPTH = 5;
|
|
1728
|
+
var DEFAULT_LOG_LEVELS = [
|
|
1729
|
+
"log",
|
|
1730
|
+
"error",
|
|
1731
|
+
"warn",
|
|
1732
|
+
"debug",
|
|
1733
|
+
"verbose",
|
|
1734
|
+
"fatal"
|
|
1735
|
+
];
|
|
1736
|
+
var dateTimeFormatter = new Intl.DateTimeFormat(void 0, {
|
|
1737
|
+
year: "numeric",
|
|
1738
|
+
hour: "numeric",
|
|
1739
|
+
minute: "numeric",
|
|
1740
|
+
second: "numeric",
|
|
1741
|
+
day: "2-digit",
|
|
1742
|
+
month: "2-digit"
|
|
1743
|
+
});
|
|
1744
|
+
var _ConsoleLogger_decorators, _init7;
|
|
1745
|
+
_ConsoleLogger_decorators = [Injectable()];
|
|
1746
|
+
var _ConsoleLogger = class _ConsoleLogger {
|
|
1747
|
+
/**
|
|
1748
|
+
* The options of the logger.
|
|
1749
|
+
*/
|
|
1750
|
+
options;
|
|
1751
|
+
/**
|
|
1752
|
+
* The context of the logger (can be set manually or automatically inferred).
|
|
1753
|
+
*/
|
|
1754
|
+
context;
|
|
1755
|
+
/**
|
|
1756
|
+
* Request ID (if enabled).
|
|
1757
|
+
*/
|
|
1758
|
+
requestId = null;
|
|
1759
|
+
/**
|
|
1760
|
+
* The original context of the logger (set in the constructor).
|
|
1761
|
+
*/
|
|
1762
|
+
originalContext;
|
|
1763
|
+
/**
|
|
1764
|
+
* The options used for the "inspect" method.
|
|
1765
|
+
*/
|
|
1766
|
+
inspectOptions;
|
|
1767
|
+
/**
|
|
1768
|
+
* The last timestamp at which the log message was printed.
|
|
1769
|
+
*/
|
|
1770
|
+
static lastTimestampAt;
|
|
1771
|
+
constructor(contextOrOptions, options) {
|
|
1772
|
+
let [context, opts] = isString(contextOrOptions) ? [contextOrOptions, options] : options ? [void 0, options] : [contextOrOptions == null ? void 0 : contextOrOptions.context, contextOrOptions];
|
|
1773
|
+
opts = opts ?? {};
|
|
1774
|
+
opts.logLevels ??= DEFAULT_LOG_LEVELS;
|
|
1775
|
+
opts.colors ??= opts.colors ?? (opts.json ? false : true);
|
|
1776
|
+
opts.prefix ??= "Navios";
|
|
1777
|
+
this.options = opts;
|
|
1778
|
+
this.inspectOptions = this.getInspectOptions();
|
|
1779
|
+
if (context) {
|
|
1780
|
+
this.context = context;
|
|
1781
|
+
this.originalContext = context;
|
|
1782
|
+
}
|
|
1783
|
+
if (opts == null ? void 0 : opts.requestId) {
|
|
1784
|
+
const locator = getServiceLocator();
|
|
1785
|
+
locator.getEventBus().on(locator.getInstanceIdentifier(Request, void 0), "create", () => {
|
|
1786
|
+
const request = locator.getSyncInstance(Request, void 0);
|
|
1787
|
+
this.requestId = (request == null ? void 0 : request.id) ?? null;
|
|
1788
|
+
});
|
|
1789
|
+
locator.getEventBus().on(
|
|
1790
|
+
locator.getInstanceIdentifier(Request, void 0),
|
|
1791
|
+
"destroy",
|
|
1792
|
+
() => {
|
|
1793
|
+
this.requestId = null;
|
|
1794
|
+
}
|
|
1795
|
+
);
|
|
1796
|
+
}
|
|
1797
|
+
}
|
|
1798
|
+
log(message, ...optionalParams) {
|
|
1799
|
+
if (!this.isLevelEnabled("log")) {
|
|
1800
|
+
return;
|
|
1801
|
+
}
|
|
1802
|
+
const { messages, context } = this.getContextAndMessagesToPrint([
|
|
1803
|
+
message,
|
|
1804
|
+
...optionalParams
|
|
1805
|
+
]);
|
|
1806
|
+
this.printMessages(messages, context, "log");
|
|
1807
|
+
}
|
|
1808
|
+
error(message, ...optionalParams) {
|
|
1809
|
+
if (!this.isLevelEnabled("error")) {
|
|
1810
|
+
return;
|
|
1811
|
+
}
|
|
1812
|
+
const { messages, context, stack } = this.getContextAndStackAndMessagesToPrint([message, ...optionalParams]);
|
|
1813
|
+
this.printMessages(messages, context, "error", "stderr", stack);
|
|
1814
|
+
this.printStackTrace(stack);
|
|
1815
|
+
}
|
|
1816
|
+
warn(message, ...optionalParams) {
|
|
1817
|
+
if (!this.isLevelEnabled("warn")) {
|
|
1818
|
+
return;
|
|
1819
|
+
}
|
|
1820
|
+
const { messages, context } = this.getContextAndMessagesToPrint([
|
|
1821
|
+
message,
|
|
1822
|
+
...optionalParams
|
|
1823
|
+
]);
|
|
1824
|
+
this.printMessages(messages, context, "warn");
|
|
1825
|
+
}
|
|
1826
|
+
debug(message, ...optionalParams) {
|
|
1827
|
+
if (!this.isLevelEnabled("debug")) {
|
|
1828
|
+
return;
|
|
1829
|
+
}
|
|
1830
|
+
const { messages, context } = this.getContextAndMessagesToPrint([
|
|
1831
|
+
message,
|
|
1832
|
+
...optionalParams
|
|
1833
|
+
]);
|
|
1834
|
+
this.printMessages(messages, context, "debug");
|
|
1835
|
+
}
|
|
1836
|
+
verbose(message, ...optionalParams) {
|
|
1837
|
+
if (!this.isLevelEnabled("verbose")) {
|
|
1838
|
+
return;
|
|
1839
|
+
}
|
|
1840
|
+
const { messages, context } = this.getContextAndMessagesToPrint([
|
|
1841
|
+
message,
|
|
1842
|
+
...optionalParams
|
|
1843
|
+
]);
|
|
1844
|
+
this.printMessages(messages, context, "verbose");
|
|
1845
|
+
}
|
|
1846
|
+
fatal(message, ...optionalParams) {
|
|
1847
|
+
if (!this.isLevelEnabled("fatal")) {
|
|
1848
|
+
return;
|
|
1849
|
+
}
|
|
1850
|
+
const { messages, context } = this.getContextAndMessagesToPrint([
|
|
1851
|
+
message,
|
|
1852
|
+
...optionalParams
|
|
1853
|
+
]);
|
|
1854
|
+
this.printMessages(messages, context, "fatal");
|
|
1855
|
+
}
|
|
1856
|
+
/**
|
|
1857
|
+
* Set log levels
|
|
1858
|
+
* @param levels log levels
|
|
1859
|
+
*/
|
|
1860
|
+
setLogLevels(levels) {
|
|
1861
|
+
if (!this.options) {
|
|
1862
|
+
this.options = {};
|
|
1863
|
+
}
|
|
1864
|
+
this.options.logLevels = levels;
|
|
1165
1865
|
}
|
|
1166
1866
|
/**
|
|
1167
1867
|
* Set logger context
|
|
@@ -1177,8 +1877,8 @@ var _ConsoleLogger = class _ConsoleLogger {
|
|
|
1177
1877
|
this.context = this.originalContext;
|
|
1178
1878
|
}
|
|
1179
1879
|
isLevelEnabled(level) {
|
|
1180
|
-
var
|
|
1181
|
-
const logLevels = (
|
|
1880
|
+
var _a3;
|
|
1881
|
+
const logLevels = (_a3 = this.options) == null ? void 0 : _a3.logLevels;
|
|
1182
1882
|
return isLogLevelEnabled(level, logLevels);
|
|
1183
1883
|
}
|
|
1184
1884
|
getTimestamp() {
|
|
@@ -1223,12 +1923,15 @@ var _ConsoleLogger = class _ConsoleLogger {
|
|
|
1223
1923
|
if (options.errorStack) {
|
|
1224
1924
|
logObject.stack = options.errorStack;
|
|
1225
1925
|
}
|
|
1926
|
+
if (this.options.requestId && this.requestId) {
|
|
1927
|
+
logObject.requestId = this.requestId;
|
|
1928
|
+
}
|
|
1226
1929
|
const formattedMessage = !this.options.colors && this.inspectOptions.compact === true ? JSON.stringify(logObject, this.stringifyReplacer) : inspect(logObject, this.inspectOptions);
|
|
1227
1930
|
process[options.writeStreamType ?? "stdout"].write(`${formattedMessage}
|
|
1228
1931
|
`);
|
|
1229
1932
|
}
|
|
1230
1933
|
formatPid(pid) {
|
|
1231
|
-
return `[${this.options.prefix}] ${pid}
|
|
1934
|
+
return `[${this.options.prefix}] ${pid} - `;
|
|
1232
1935
|
}
|
|
1233
1936
|
formatContext(context) {
|
|
1234
1937
|
if (!context) {
|
|
@@ -1241,9 +1944,15 @@ var _ConsoleLogger = class _ConsoleLogger {
|
|
|
1241
1944
|
const output = this.stringifyMessage(message, logLevel);
|
|
1242
1945
|
pidMessage = this.colorize(pidMessage, logLevel);
|
|
1243
1946
|
formattedLogLevel = this.colorize(formattedLogLevel, logLevel);
|
|
1244
|
-
return `${pidMessage}${this.getTimestamp()} ${formattedLogLevel} ${contextMessage}${output}${timestampDiff}
|
|
1947
|
+
return `${pidMessage}${this.getRequestId()}${this.getTimestamp()} ${formattedLogLevel} ${contextMessage}${output}${timestampDiff}
|
|
1245
1948
|
`;
|
|
1246
1949
|
}
|
|
1950
|
+
getRequestId() {
|
|
1951
|
+
if (this.options.requestId && this.requestId) {
|
|
1952
|
+
return `(${this.colorize(this.requestId, "log")}) `;
|
|
1953
|
+
}
|
|
1954
|
+
return "";
|
|
1955
|
+
}
|
|
1247
1956
|
stringifyMessage(message, logLevel) {
|
|
1248
1957
|
if (isFunction(message)) {
|
|
1249
1958
|
const messageAsStr = Function.prototype.toString.call(message);
|
|
@@ -1280,8 +1989,8 @@ var _ConsoleLogger = class _ConsoleLogger {
|
|
|
1280
1989
|
`);
|
|
1281
1990
|
}
|
|
1282
1991
|
updateAndGetTimestampDiff() {
|
|
1283
|
-
var
|
|
1284
|
-
const includeTimestamp = _ConsoleLogger.lastTimestampAt && ((
|
|
1992
|
+
var _a3;
|
|
1993
|
+
const includeTimestamp = _ConsoleLogger.lastTimestampAt && ((_a3 = this.options) == null ? void 0 : _a3.timestamp);
|
|
1285
1994
|
const result = includeTimestamp ? this.formatTimestampDiff(Date.now() - _ConsoleLogger.lastTimestampAt) : "";
|
|
1286
1995
|
_ConsoleLogger.lastTimestampAt = Date.now();
|
|
1287
1996
|
return result;
|
|
@@ -1386,9 +2095,9 @@ var _ConsoleLogger = class _ConsoleLogger {
|
|
|
1386
2095
|
}
|
|
1387
2096
|
}
|
|
1388
2097
|
};
|
|
1389
|
-
|
|
1390
|
-
_ConsoleLogger = __decorateElement(
|
|
1391
|
-
__runInitializers(
|
|
2098
|
+
_init7 = __decoratorStart(null);
|
|
2099
|
+
_ConsoleLogger = __decorateElement(_init7, 0, "ConsoleLogger", _ConsoleLogger_decorators, _ConsoleLogger);
|
|
2100
|
+
__runInitializers(_init7, 1, _ConsoleLogger);
|
|
1392
2101
|
var ConsoleLogger = _ConsoleLogger;
|
|
1393
2102
|
|
|
1394
2103
|
// packages/core/src/logger/logger.factory.mts
|
|
@@ -1404,7 +2113,7 @@ var dateTimeFormatter2 = new Intl.DateTimeFormat(void 0, {
|
|
|
1404
2113
|
day: "2-digit",
|
|
1405
2114
|
month: "2-digit"
|
|
1406
2115
|
});
|
|
1407
|
-
var _LoggerInstance_decorators,
|
|
2116
|
+
var _LoggerInstance_decorators, _init8;
|
|
1408
2117
|
_LoggerInstance_decorators = [Injectable()];
|
|
1409
2118
|
var _LoggerInstance = class _LoggerInstance {
|
|
1410
2119
|
constructor(context, options = {}) {
|
|
@@ -1426,69 +2135,69 @@ var _LoggerInstance = class _LoggerInstance {
|
|
|
1426
2135
|
return _LoggerInstance.staticInstanceRef;
|
|
1427
2136
|
}
|
|
1428
2137
|
error(message, ...optionalParams) {
|
|
1429
|
-
var
|
|
2138
|
+
var _a3;
|
|
1430
2139
|
optionalParams = this.context ? (optionalParams.length ? optionalParams : [void 0]).concat(
|
|
1431
2140
|
this.context
|
|
1432
2141
|
) : optionalParams;
|
|
1433
|
-
(
|
|
2142
|
+
(_a3 = this.localInstance) == null ? void 0 : _a3.error(message, ...optionalParams);
|
|
1434
2143
|
}
|
|
1435
2144
|
log(message, ...optionalParams) {
|
|
1436
|
-
var
|
|
2145
|
+
var _a3;
|
|
1437
2146
|
optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
|
|
1438
|
-
(
|
|
2147
|
+
(_a3 = this.localInstance) == null ? void 0 : _a3.log(message, ...optionalParams);
|
|
1439
2148
|
}
|
|
1440
2149
|
warn(message, ...optionalParams) {
|
|
1441
|
-
var
|
|
2150
|
+
var _a3;
|
|
1442
2151
|
optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
|
|
1443
|
-
(
|
|
2152
|
+
(_a3 = this.localInstance) == null ? void 0 : _a3.warn(message, ...optionalParams);
|
|
1444
2153
|
}
|
|
1445
2154
|
debug(message, ...optionalParams) {
|
|
1446
|
-
var
|
|
2155
|
+
var _a3, _b;
|
|
1447
2156
|
optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
|
|
1448
|
-
(_b = (
|
|
2157
|
+
(_b = (_a3 = this.localInstance) == null ? void 0 : _a3.debug) == null ? void 0 : _b.call(_a3, message, ...optionalParams);
|
|
1449
2158
|
}
|
|
1450
2159
|
verbose(message, ...optionalParams) {
|
|
1451
|
-
var
|
|
2160
|
+
var _a3, _b;
|
|
1452
2161
|
optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
|
|
1453
|
-
(_b = (
|
|
2162
|
+
(_b = (_a3 = this.localInstance) == null ? void 0 : _a3.verbose) == null ? void 0 : _b.call(_a3, message, ...optionalParams);
|
|
1454
2163
|
}
|
|
1455
2164
|
fatal(message, ...optionalParams) {
|
|
1456
|
-
var
|
|
2165
|
+
var _a3, _b;
|
|
1457
2166
|
optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
|
|
1458
|
-
(_b = (
|
|
2167
|
+
(_b = (_a3 = this.localInstance) == null ? void 0 : _a3.fatal) == null ? void 0 : _b.call(_a3, message, ...optionalParams);
|
|
1459
2168
|
}
|
|
1460
2169
|
static error(message, ...optionalParams) {
|
|
1461
|
-
var
|
|
1462
|
-
(
|
|
2170
|
+
var _a3;
|
|
2171
|
+
(_a3 = this.staticInstanceRef) == null ? void 0 : _a3.error(message, ...optionalParams);
|
|
1463
2172
|
}
|
|
1464
2173
|
static log(message, ...optionalParams) {
|
|
1465
|
-
var
|
|
1466
|
-
(
|
|
2174
|
+
var _a3;
|
|
2175
|
+
(_a3 = this.staticInstanceRef) == null ? void 0 : _a3.log(message, ...optionalParams);
|
|
1467
2176
|
}
|
|
1468
2177
|
static warn(message, ...optionalParams) {
|
|
1469
|
-
var
|
|
1470
|
-
(
|
|
2178
|
+
var _a3;
|
|
2179
|
+
(_a3 = this.staticInstanceRef) == null ? void 0 : _a3.warn(message, ...optionalParams);
|
|
1471
2180
|
}
|
|
1472
2181
|
static debug(message, ...optionalParams) {
|
|
1473
|
-
var
|
|
1474
|
-
(_b = (
|
|
2182
|
+
var _a3, _b;
|
|
2183
|
+
(_b = (_a3 = this.staticInstanceRef) == null ? void 0 : _a3.debug) == null ? void 0 : _b.call(_a3, message, ...optionalParams);
|
|
1475
2184
|
}
|
|
1476
2185
|
static verbose(message, ...optionalParams) {
|
|
1477
|
-
var
|
|
1478
|
-
(_b = (
|
|
2186
|
+
var _a3, _b;
|
|
2187
|
+
(_b = (_a3 = this.staticInstanceRef) == null ? void 0 : _a3.verbose) == null ? void 0 : _b.call(_a3, message, ...optionalParams);
|
|
1479
2188
|
}
|
|
1480
2189
|
static fatal(message, ...optionalParams) {
|
|
1481
|
-
var
|
|
1482
|
-
(_b = (
|
|
2190
|
+
var _a3, _b;
|
|
2191
|
+
(_b = (_a3 = this.staticInstanceRef) == null ? void 0 : _a3.fatal) == null ? void 0 : _b.call(_a3, message, ...optionalParams);
|
|
1483
2192
|
}
|
|
1484
2193
|
static getTimestamp() {
|
|
1485
2194
|
return dateTimeFormatter2.format(Date.now());
|
|
1486
2195
|
}
|
|
1487
2196
|
static overrideLogger(logger) {
|
|
1488
|
-
var
|
|
2197
|
+
var _a3, _b;
|
|
1489
2198
|
if (Array.isArray(logger)) {
|
|
1490
2199
|
_LoggerInstance.logLevels = logger;
|
|
1491
|
-
return (_b = (
|
|
2200
|
+
return (_b = (_a3 = this.staticInstanceRef) == null ? void 0 : _a3.setLogLevels) == null ? void 0 : _b.call(_a3, logger);
|
|
1492
2201
|
}
|
|
1493
2202
|
if (isObject(logger)) {
|
|
1494
2203
|
this.staticInstanceRef = logger;
|
|
@@ -1501,20 +2210,20 @@ var _LoggerInstance = class _LoggerInstance {
|
|
|
1501
2210
|
return isLogLevelEnabled(level, logLevels);
|
|
1502
2211
|
}
|
|
1503
2212
|
registerLocalInstanceRef() {
|
|
1504
|
-
var
|
|
2213
|
+
var _a3;
|
|
1505
2214
|
if (this.localInstanceRef) {
|
|
1506
2215
|
return this.localInstanceRef;
|
|
1507
2216
|
}
|
|
1508
2217
|
this.localInstanceRef = new ConsoleLogger(this.context, {
|
|
1509
|
-
timestamp: (
|
|
2218
|
+
timestamp: (_a3 = this.options) == null ? void 0 : _a3.timestamp,
|
|
1510
2219
|
logLevels: _LoggerInstance.logLevels
|
|
1511
2220
|
});
|
|
1512
2221
|
return this.localInstanceRef;
|
|
1513
2222
|
}
|
|
1514
2223
|
};
|
|
1515
|
-
|
|
1516
|
-
_LoggerInstance = __decorateElement(
|
|
1517
|
-
__runInitializers(
|
|
2224
|
+
_init8 = __decoratorStart(null);
|
|
2225
|
+
_LoggerInstance = __decorateElement(_init8, 0, "LoggerInstance", _LoggerInstance_decorators, _LoggerInstance);
|
|
2226
|
+
__runInitializers(_init8, 1, _LoggerInstance);
|
|
1518
2227
|
var LoggerInstance = _LoggerInstance;
|
|
1519
2228
|
|
|
1520
2229
|
// packages/core/src/logger/logger.factory.mts
|
|
@@ -1526,7 +2235,7 @@ var LoggerOptions = z2.object({
|
|
|
1526
2235
|
}).optional()
|
|
1527
2236
|
}).optional();
|
|
1528
2237
|
var Logger = InjectionToken.create(LoggerInjectionToken, LoggerOptions);
|
|
1529
|
-
var _LoggerFactory_decorators,
|
|
2238
|
+
var _LoggerFactory_decorators, _init9;
|
|
1530
2239
|
_LoggerFactory_decorators = [Injectable({
|
|
1531
2240
|
type: "Factory" /* Factory */,
|
|
1532
2241
|
token: Logger
|
|
@@ -1536,9 +2245,9 @@ var LoggerFactory = class {
|
|
|
1536
2245
|
return new LoggerInstance(args == null ? void 0 : args.context, args == null ? void 0 : args.options);
|
|
1537
2246
|
}
|
|
1538
2247
|
};
|
|
1539
|
-
|
|
1540
|
-
LoggerFactory = __decorateElement(
|
|
1541
|
-
__runInitializers(
|
|
2248
|
+
_init9 = __decoratorStart(null);
|
|
2249
|
+
LoggerFactory = __decorateElement(_init9, 0, "LoggerFactory", _LoggerFactory_decorators, LoggerFactory);
|
|
2250
|
+
__runInitializers(_init9, 1, LoggerFactory);
|
|
1542
2251
|
|
|
1543
2252
|
// packages/core/src/logger/pino-wrapper.mts
|
|
1544
2253
|
var PinoWrapper = class _PinoWrapper {
|
|
@@ -1560,12 +2269,12 @@ var PinoWrapper = class _PinoWrapper {
|
|
|
1560
2269
|
info() {
|
|
1561
2270
|
}
|
|
1562
2271
|
debug(message, ...optionalParams) {
|
|
1563
|
-
var
|
|
1564
|
-
(_b = (
|
|
2272
|
+
var _a3, _b;
|
|
2273
|
+
(_b = (_a3 = this.logger).debug) == null ? void 0 : _b.call(_a3, message, ...optionalParams);
|
|
1565
2274
|
}
|
|
1566
2275
|
trace(message, ...optionalParams) {
|
|
1567
|
-
var
|
|
1568
|
-
(_b = (
|
|
2276
|
+
var _a3, _b;
|
|
2277
|
+
(_b = (_a3 = this.logger).verbose) == null ? void 0 : _b.call(_a3, message, ...optionalParams);
|
|
1569
2278
|
}
|
|
1570
2279
|
silent() {
|
|
1571
2280
|
}
|
|
@@ -1603,7 +2312,7 @@ var ConfigServiceInstance = class {
|
|
|
1603
2312
|
return this.config;
|
|
1604
2313
|
}
|
|
1605
2314
|
get(key) {
|
|
1606
|
-
var
|
|
2315
|
+
var _a3, _b;
|
|
1607
2316
|
try {
|
|
1608
2317
|
const parts = String(key).split(".");
|
|
1609
2318
|
let value = this.config;
|
|
@@ -1615,8 +2324,8 @@ var ConfigServiceInstance = class {
|
|
|
1615
2324
|
}
|
|
1616
2325
|
return value ?? null;
|
|
1617
2326
|
} catch (error) {
|
|
1618
|
-
(_b = (
|
|
1619
|
-
|
|
2327
|
+
(_b = (_a3 = this.logger).debug) == null ? void 0 : _b.call(
|
|
2328
|
+
_a3,
|
|
1620
2329
|
`Failed to get config value for key ${String(key)}`,
|
|
1621
2330
|
error
|
|
1622
2331
|
);
|
|
@@ -1643,7 +2352,7 @@ var ConfigProviderOptions = z3.object({
|
|
|
1643
2352
|
load: z3.function()
|
|
1644
2353
|
});
|
|
1645
2354
|
var ConfigProvider = InjectionToken.create(ConfigServiceInstance, ConfigProviderOptions);
|
|
1646
|
-
var _ConfigProviderFactory_decorators,
|
|
2355
|
+
var _ConfigProviderFactory_decorators, _init10;
|
|
1647
2356
|
_ConfigProviderFactory_decorators = [Injectable({
|
|
1648
2357
|
token: ConfigProvider,
|
|
1649
2358
|
type: "Factory" /* Factory */
|
|
@@ -1657,267 +2366,50 @@ var ConfigProviderFactory = class {
|
|
|
1657
2366
|
const logger = this.logger;
|
|
1658
2367
|
try {
|
|
1659
2368
|
const config = await load();
|
|
1660
|
-
return new ConfigServiceInstance(
|
|
2369
|
+
return new ConfigServiceInstance(
|
|
2370
|
+
config,
|
|
2371
|
+
logger
|
|
2372
|
+
);
|
|
1661
2373
|
} catch (error) {
|
|
1662
2374
|
logger.error("Error loading config", error);
|
|
1663
2375
|
throw error;
|
|
1664
2376
|
}
|
|
1665
|
-
}
|
|
1666
|
-
};
|
|
1667
|
-
|
|
1668
|
-
ConfigProviderFactory = __decorateElement(
|
|
1669
|
-
__runInitializers(
|
|
1670
|
-
function provideConfig(options) {
|
|
1671
|
-
return InjectionToken.bound(ConfigProvider, options);
|
|
1672
|
-
}
|
|
1673
|
-
|
|
1674
|
-
// packages/core/src/metadata/endpoint.metadata.mts
|
|
1675
|
-
var EndpointMetadataKey = Symbol("EndpointMetadataKey");
|
|
1676
|
-
var EndpointType = /* @__PURE__ */ ((EndpointType2) => {
|
|
1677
|
-
EndpointType2["Unknown"] = "unknown";
|
|
1678
|
-
EndpointType2["Endpoint"] = "endpoint";
|
|
1679
|
-
EndpointType2["Stream"] = "stream";
|
|
1680
|
-
EndpointType2["Multipart"] = "multipart";
|
|
1681
|
-
EndpointType2["Handler"] = "handler";
|
|
1682
|
-
return EndpointType2;
|
|
1683
|
-
})(EndpointType || {});
|
|
1684
|
-
function getAllEndpointMetadata(context) {
|
|
1685
|
-
if (context.metadata) {
|
|
1686
|
-
const metadata = context.metadata[EndpointMetadataKey];
|
|
1687
|
-
if (metadata) {
|
|
1688
|
-
return metadata;
|
|
1689
|
-
} else {
|
|
1690
|
-
context.metadata[EndpointMetadataKey] = /* @__PURE__ */ new Set();
|
|
1691
|
-
return context.metadata[EndpointMetadataKey];
|
|
1692
|
-
}
|
|
1693
|
-
}
|
|
1694
|
-
throw new Error("[Navios] Wrong environment.");
|
|
1695
|
-
}
|
|
1696
|
-
function getEndpointMetadata(target, context) {
|
|
1697
|
-
if (context.metadata) {
|
|
1698
|
-
const metadata = getAllEndpointMetadata(context);
|
|
1699
|
-
if (metadata) {
|
|
1700
|
-
const endpointMetadata = Array.from(metadata).find(
|
|
1701
|
-
(item) => item.classMethod === target.name
|
|
1702
|
-
);
|
|
1703
|
-
if (endpointMetadata) {
|
|
1704
|
-
return endpointMetadata;
|
|
1705
|
-
} else {
|
|
1706
|
-
const newMetadata = {
|
|
1707
|
-
classMethod: target.name,
|
|
1708
|
-
url: "",
|
|
1709
|
-
successStatusCode: 200,
|
|
1710
|
-
headers: {},
|
|
1711
|
-
type: "unknown" /* Unknown */,
|
|
1712
|
-
httpMethod: "GET",
|
|
1713
|
-
config: null,
|
|
1714
|
-
guards: /* @__PURE__ */ new Set(),
|
|
1715
|
-
customAttributes: /* @__PURE__ */ new Map()
|
|
1716
|
-
};
|
|
1717
|
-
metadata.add(newMetadata);
|
|
1718
|
-
return newMetadata;
|
|
1719
|
-
}
|
|
1720
|
-
}
|
|
1721
|
-
}
|
|
1722
|
-
throw new Error("[Navios] Wrong environment.");
|
|
1723
|
-
}
|
|
1724
|
-
|
|
1725
|
-
// packages/core/src/metadata/controller.metadata.mts
|
|
1726
|
-
var ControllerMetadataKey = Symbol("ControllerMetadataKey");
|
|
1727
|
-
function getControllerMetadata(target, context) {
|
|
1728
|
-
if (context.metadata) {
|
|
1729
|
-
const metadata = context.metadata[ControllerMetadataKey];
|
|
1730
|
-
if (metadata) {
|
|
1731
|
-
return metadata;
|
|
1732
|
-
} else {
|
|
1733
|
-
const endpointsMetadata = getAllEndpointMetadata(context);
|
|
1734
|
-
const newMetadata = {
|
|
1735
|
-
endpoints: endpointsMetadata,
|
|
1736
|
-
guards: /* @__PURE__ */ new Set(),
|
|
1737
|
-
customAttributes: /* @__PURE__ */ new Map()
|
|
1738
|
-
};
|
|
1739
|
-
context.metadata[ControllerMetadataKey] = newMetadata;
|
|
1740
|
-
target[ControllerMetadataKey] = newMetadata;
|
|
1741
|
-
return newMetadata;
|
|
1742
|
-
}
|
|
1743
|
-
}
|
|
1744
|
-
throw new Error("[Navios] Wrong environment.");
|
|
1745
|
-
}
|
|
1746
|
-
function extractControllerMetadata(target) {
|
|
1747
|
-
const metadata = target[ControllerMetadataKey];
|
|
1748
|
-
if (!metadata) {
|
|
1749
|
-
throw new Error(
|
|
1750
|
-
"[Navios] Controller metadata not found. Make sure to use @Controller decorator."
|
|
1751
|
-
);
|
|
1752
|
-
}
|
|
1753
|
-
return metadata;
|
|
1754
|
-
}
|
|
1755
|
-
function hasControllerMetadata(target) {
|
|
1756
|
-
const metadata = target[ControllerMetadataKey];
|
|
1757
|
-
return !!metadata;
|
|
1758
|
-
}
|
|
1759
|
-
|
|
1760
|
-
// packages/core/src/metadata/module.metadata.mts
|
|
1761
|
-
var ModuleMetadataKey = Symbol("ControllerMetadataKey");
|
|
1762
|
-
function getModuleMetadata(target, context) {
|
|
1763
|
-
if (context.metadata) {
|
|
1764
|
-
const metadata = context.metadata[ModuleMetadataKey];
|
|
1765
|
-
if (metadata) {
|
|
1766
|
-
return metadata;
|
|
1767
|
-
} else {
|
|
1768
|
-
const newMetadata = {
|
|
1769
|
-
controllers: /* @__PURE__ */ new Set(),
|
|
1770
|
-
imports: /* @__PURE__ */ new Set(),
|
|
1771
|
-
guards: /* @__PURE__ */ new Set(),
|
|
1772
|
-
customAttributes: /* @__PURE__ */ new Map()
|
|
1773
|
-
};
|
|
1774
|
-
context.metadata[ModuleMetadataKey] = newMetadata;
|
|
1775
|
-
target[ModuleMetadataKey] = newMetadata;
|
|
1776
|
-
return newMetadata;
|
|
1777
|
-
}
|
|
1778
|
-
}
|
|
1779
|
-
throw new Error("[Navios] Wrong environment.");
|
|
1780
|
-
}
|
|
1781
|
-
function extractModuleMetadata(target) {
|
|
1782
|
-
const metadata = target[ModuleMetadataKey];
|
|
1783
|
-
if (!metadata) {
|
|
1784
|
-
throw new Error(
|
|
1785
|
-
`[Navios] Module metadata not found for ${target.name}. Make sure to use @Module decorator.`
|
|
1786
|
-
);
|
|
1787
|
-
}
|
|
1788
|
-
return metadata;
|
|
1789
|
-
}
|
|
1790
|
-
function hasModuleMetadata(target) {
|
|
1791
|
-
return !!target[ModuleMetadataKey];
|
|
1792
|
-
}
|
|
1793
|
-
|
|
1794
|
-
// packages/core/src/decorators/controller.decorator.mts
|
|
1795
|
-
function Controller({ guards } = {}) {
|
|
1796
|
-
return function(target, context) {
|
|
1797
|
-
if (context.kind !== "class") {
|
|
1798
|
-
throw new Error(
|
|
1799
|
-
"[Navios] @Controller decorator can only be used on classes."
|
|
1800
|
-
);
|
|
1801
|
-
}
|
|
1802
|
-
const token = InjectionToken.create(target);
|
|
1803
|
-
if (context.metadata) {
|
|
1804
|
-
const controllerMetadata = getControllerMetadata(target, context);
|
|
1805
|
-
if (guards) {
|
|
1806
|
-
for (const guard of Array.from(guards).reverse()) {
|
|
1807
|
-
controllerMetadata.guards.add(guard);
|
|
1808
|
-
}
|
|
1809
|
-
}
|
|
1810
|
-
}
|
|
1811
|
-
return Injectable({
|
|
1812
|
-
token,
|
|
1813
|
-
type: "Class" /* Class */,
|
|
1814
|
-
scope: "Instance" /* Instance */
|
|
1815
|
-
})(target, context);
|
|
1816
|
-
};
|
|
1817
|
-
}
|
|
1818
|
-
|
|
1819
|
-
// packages/core/src/decorators/endpoint.decorator.mts
|
|
1820
|
-
import "zod";
|
|
1821
|
-
function Endpoint(endpoint) {
|
|
1822
|
-
return (target, context) => {
|
|
1823
|
-
if (typeof target !== "function") {
|
|
1824
|
-
throw new Error(
|
|
1825
|
-
"[Navios] Endpoint decorator can only be used on functions."
|
|
1826
|
-
);
|
|
1827
|
-
}
|
|
1828
|
-
if (context.kind !== "method") {
|
|
1829
|
-
throw new Error(
|
|
1830
|
-
"[Navios] Endpoint decorator can only be used on methods."
|
|
1831
|
-
);
|
|
1832
|
-
}
|
|
1833
|
-
const config = endpoint.config;
|
|
1834
|
-
if (context.metadata) {
|
|
1835
|
-
let endpointMetadata = getEndpointMetadata(target, context);
|
|
1836
|
-
if (endpointMetadata.config && endpointMetadata.config.url) {
|
|
1837
|
-
throw new Error(
|
|
1838
|
-
`[Navios] Endpoint ${config.method} ${config.url} already exists. Please use a different method or url.`
|
|
1839
|
-
);
|
|
1840
|
-
}
|
|
1841
|
-
endpointMetadata.config = config;
|
|
1842
|
-
endpointMetadata.type = "endpoint" /* Endpoint */;
|
|
1843
|
-
endpointMetadata.classMethod = target.name;
|
|
1844
|
-
endpointMetadata.httpMethod = config.method;
|
|
1845
|
-
endpointMetadata.url = config.url;
|
|
1846
|
-
}
|
|
1847
|
-
return target;
|
|
1848
|
-
};
|
|
1849
|
-
}
|
|
1850
|
-
|
|
1851
|
-
// packages/core/src/decorators/header.decorator.mts
|
|
1852
|
-
function Header(name2, value) {
|
|
1853
|
-
return (target, context) => {
|
|
1854
|
-
if (context.kind !== "method") {
|
|
1855
|
-
throw new Error("[Navios] Header decorator can only be used on methods.");
|
|
1856
|
-
}
|
|
1857
|
-
const metadata = getEndpointMetadata(target, context);
|
|
1858
|
-
if (metadata.type === "stream" /* Stream */) {
|
|
1859
|
-
throw new Error(
|
|
1860
|
-
"[Navios] HttpCode decorator cannot be used on stream endpoints."
|
|
1861
|
-
);
|
|
1862
|
-
}
|
|
1863
|
-
metadata.headers[name2] = value;
|
|
1864
|
-
return target;
|
|
1865
|
-
};
|
|
1866
|
-
}
|
|
1867
|
-
|
|
1868
|
-
// packages/core/src/decorators/http-code.decorator.mts
|
|
1869
|
-
function HttpCode(code) {
|
|
1870
|
-
return (target, context) => {
|
|
1871
|
-
if (context.kind !== "method") {
|
|
1872
|
-
throw new Error(
|
|
1873
|
-
"[Navios] HttpCode decorator can only be used on methods."
|
|
1874
|
-
);
|
|
1875
|
-
}
|
|
1876
|
-
const metadata = getEndpointMetadata(target, context);
|
|
1877
|
-
if (metadata.type === "stream" /* Stream */) {
|
|
1878
|
-
throw new Error(
|
|
1879
|
-
"[Navios] HttpCode decorator cannot be used on stream endpoints."
|
|
1880
|
-
);
|
|
1881
|
-
}
|
|
1882
|
-
metadata.successStatusCode = code;
|
|
1883
|
-
return target;
|
|
1884
|
-
};
|
|
2377
|
+
}
|
|
2378
|
+
};
|
|
2379
|
+
_init10 = __decoratorStart(null);
|
|
2380
|
+
ConfigProviderFactory = __decorateElement(_init10, 0, "ConfigProviderFactory", _ConfigProviderFactory_decorators, ConfigProviderFactory);
|
|
2381
|
+
__runInitializers(_init10, 1, ConfigProviderFactory);
|
|
2382
|
+
function provideConfig(options) {
|
|
2383
|
+
return InjectionToken.bound(ConfigProvider, options);
|
|
1885
2384
|
}
|
|
1886
2385
|
|
|
1887
|
-
// packages/core/src/decorators/
|
|
1888
|
-
function
|
|
1889
|
-
return (target, context)
|
|
2386
|
+
// packages/core/src/decorators/controller.decorator.mts
|
|
2387
|
+
function Controller({ guards } = {}) {
|
|
2388
|
+
return function(target, context) {
|
|
1890
2389
|
if (context.kind !== "class") {
|
|
1891
|
-
throw new Error(
|
|
2390
|
+
throw new Error(
|
|
2391
|
+
"[Navios] @Controller decorator can only be used on classes."
|
|
2392
|
+
);
|
|
1892
2393
|
}
|
|
1893
2394
|
const token = InjectionToken.create(target);
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
if (metadata.imports) {
|
|
1901
|
-
for (const importedModule of metadata.imports) {
|
|
1902
|
-
moduleMetadata.imports.add(importedModule);
|
|
1903
|
-
}
|
|
1904
|
-
}
|
|
1905
|
-
if (metadata.guards) {
|
|
1906
|
-
for (const guard of Array.from(metadata.guards).reverse()) {
|
|
1907
|
-
moduleMetadata.guards.add(guard);
|
|
2395
|
+
if (context.metadata) {
|
|
2396
|
+
const controllerMetadata = getControllerMetadata(target, context);
|
|
2397
|
+
if (guards) {
|
|
2398
|
+
for (const guard of Array.from(guards).reverse()) {
|
|
2399
|
+
controllerMetadata.guards.add(guard);
|
|
2400
|
+
}
|
|
1908
2401
|
}
|
|
1909
2402
|
}
|
|
1910
2403
|
return Injectable({
|
|
1911
2404
|
token,
|
|
1912
|
-
|
|
1913
|
-
scope: "Singleton" /* Singleton */
|
|
2405
|
+
scope: "Instance" /* Instance */
|
|
1914
2406
|
})(target, context);
|
|
1915
2407
|
};
|
|
1916
2408
|
}
|
|
1917
2409
|
|
|
1918
|
-
// packages/core/src/decorators/
|
|
2410
|
+
// packages/core/src/decorators/endpoint.decorator.mts
|
|
1919
2411
|
import "zod";
|
|
1920
|
-
function
|
|
2412
|
+
function Endpoint(endpoint) {
|
|
1921
2413
|
return (target, context) => {
|
|
1922
2414
|
if (typeof target !== "function") {
|
|
1923
2415
|
throw new Error(
|
|
@@ -1931,14 +2423,17 @@ function Multipart(endpoint) {
|
|
|
1931
2423
|
}
|
|
1932
2424
|
const config = endpoint.config;
|
|
1933
2425
|
if (context.metadata) {
|
|
1934
|
-
let endpointMetadata = getEndpointMetadata(
|
|
2426
|
+
let endpointMetadata = getEndpointMetadata(
|
|
2427
|
+
target,
|
|
2428
|
+
context
|
|
2429
|
+
);
|
|
1935
2430
|
if (endpointMetadata.config && endpointMetadata.config.url) {
|
|
1936
2431
|
throw new Error(
|
|
1937
2432
|
`[Navios] Endpoint ${config.method} ${config.url} already exists. Please use a different method or url.`
|
|
1938
2433
|
);
|
|
1939
2434
|
}
|
|
1940
2435
|
endpointMetadata.config = config;
|
|
1941
|
-
endpointMetadata.
|
|
2436
|
+
endpointMetadata.adapterToken = EndpointAdapterToken;
|
|
1942
2437
|
endpointMetadata.classMethod = target.name;
|
|
1943
2438
|
endpointMetadata.httpMethod = config.method;
|
|
1944
2439
|
endpointMetadata.url = config.url;
|
|
@@ -1947,563 +2442,153 @@ function Multipart(endpoint) {
|
|
|
1947
2442
|
};
|
|
1948
2443
|
}
|
|
1949
2444
|
|
|
1950
|
-
// packages/core/src/decorators/
|
|
1951
|
-
function
|
|
2445
|
+
// packages/core/src/decorators/header.decorator.mts
|
|
2446
|
+
function Header(name2, value) {
|
|
1952
2447
|
return (target, context) => {
|
|
1953
|
-
if (typeof target !== "function") {
|
|
1954
|
-
throw new Error(
|
|
1955
|
-
"[Navios] Endpoint decorator can only be used on functions."
|
|
1956
|
-
);
|
|
1957
|
-
}
|
|
1958
2448
|
if (context.kind !== "method") {
|
|
1959
|
-
throw new Error(
|
|
1960
|
-
"[Navios] Endpoint decorator can only be used on methods."
|
|
1961
|
-
);
|
|
1962
|
-
}
|
|
1963
|
-
const config = endpoint.config;
|
|
1964
|
-
if (context.metadata) {
|
|
1965
|
-
let endpointMetadata = getEndpointMetadata(target, context);
|
|
1966
|
-
if (endpointMetadata.config && endpointMetadata.config.url) {
|
|
1967
|
-
throw new Error(
|
|
1968
|
-
`[Navios] Endpoint ${config.method} ${config.url} already exists. Please use a different method or url.`
|
|
1969
|
-
);
|
|
1970
|
-
}
|
|
1971
|
-
endpointMetadata.config = config;
|
|
1972
|
-
endpointMetadata.type = "stream" /* Stream */;
|
|
1973
|
-
endpointMetadata.classMethod = target.name;
|
|
1974
|
-
endpointMetadata.httpMethod = config.method;
|
|
1975
|
-
endpointMetadata.url = config.url;
|
|
2449
|
+
throw new Error("[Navios] Header decorator can only be used on methods.");
|
|
1976
2450
|
}
|
|
2451
|
+
const metadata = getEndpointMetadata(target, context);
|
|
2452
|
+
metadata.headers[name2] = value;
|
|
1977
2453
|
return target;
|
|
1978
2454
|
};
|
|
1979
2455
|
}
|
|
1980
2456
|
|
|
1981
|
-
// packages/core/src/decorators/
|
|
1982
|
-
function
|
|
1983
|
-
return
|
|
1984
|
-
if (context.kind
|
|
1985
|
-
const controllerMetadata = getControllerMetadata(
|
|
1986
|
-
target,
|
|
1987
|
-
context
|
|
1988
|
-
);
|
|
1989
|
-
for (const guard of guards.reverse()) {
|
|
1990
|
-
controllerMetadata.guards.add(guard);
|
|
1991
|
-
}
|
|
1992
|
-
} else if (context.kind === "method") {
|
|
1993
|
-
const endpointMetadata = getEndpointMetadata(target, context);
|
|
1994
|
-
for (const guard of guards.reverse()) {
|
|
1995
|
-
endpointMetadata.guards.add(guard);
|
|
1996
|
-
}
|
|
1997
|
-
} else {
|
|
2457
|
+
// packages/core/src/decorators/http-code.decorator.mts
|
|
2458
|
+
function HttpCode(code) {
|
|
2459
|
+
return (target, context) => {
|
|
2460
|
+
if (context.kind !== "method") {
|
|
1998
2461
|
throw new Error(
|
|
1999
|
-
"[Navios]
|
|
2462
|
+
"[Navios] HttpCode decorator can only be used on methods."
|
|
2000
2463
|
);
|
|
2001
2464
|
}
|
|
2465
|
+
const metadata = getEndpointMetadata(target, context);
|
|
2466
|
+
metadata.successStatusCode = code;
|
|
2002
2467
|
return target;
|
|
2003
2468
|
};
|
|
2004
2469
|
}
|
|
2005
|
-
|
|
2006
|
-
// packages/core/src/
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
// packages/core/src/exceptions/bad-request.exception.mts
|
|
2016
|
-
var BadRequestException = class extends HttpException {
|
|
2017
|
-
constructor(message) {
|
|
2018
|
-
super(400, message);
|
|
2019
|
-
}
|
|
2020
|
-
};
|
|
2021
|
-
|
|
2022
|
-
// packages/core/src/exceptions/forbidden.exception.mts
|
|
2023
|
-
var ForbiddenException = class extends HttpException {
|
|
2024
|
-
constructor(message) {
|
|
2025
|
-
super(403, message);
|
|
2026
|
-
}
|
|
2027
|
-
};
|
|
2028
|
-
|
|
2029
|
-
// packages/core/src/exceptions/internal-server-error.exception.mts
|
|
2030
|
-
var InternalServerErrorException = class extends HttpException {
|
|
2031
|
-
constructor(message, error) {
|
|
2032
|
-
super(500, message, error);
|
|
2033
|
-
}
|
|
2034
|
-
};
|
|
2035
|
-
|
|
2036
|
-
// packages/core/src/exceptions/not-found.exception.mts
|
|
2037
|
-
var NotFoundException = class extends HttpException {
|
|
2038
|
-
constructor(response, error) {
|
|
2039
|
-
super(404, response, error);
|
|
2040
|
-
this.response = response;
|
|
2041
|
-
this.error = error;
|
|
2042
|
-
}
|
|
2043
|
-
};
|
|
2044
|
-
|
|
2045
|
-
// packages/core/src/exceptions/unauthorized.exception.mts
|
|
2046
|
-
var UnauthorizedException = class extends HttpException {
|
|
2047
|
-
constructor(message, error) {
|
|
2048
|
-
super(401, message, error);
|
|
2049
|
-
}
|
|
2050
|
-
};
|
|
2051
|
-
|
|
2052
|
-
// packages/core/src/exceptions/conflict.exception.mts
|
|
2053
|
-
var ConflictException = class extends HttpException {
|
|
2054
|
-
constructor(message, error) {
|
|
2055
|
-
super(409, message, error);
|
|
2056
|
-
}
|
|
2057
|
-
};
|
|
2058
|
-
|
|
2059
|
-
// packages/core/src/services/controller-adapter.service.mts
|
|
2060
|
-
import { NaviosException as NaviosException4 } from "@navios/common";
|
|
2061
|
-
import { ZodArray } from "zod";
|
|
2062
|
-
|
|
2063
|
-
// packages/core/src/tokens/application.token.mts
|
|
2064
|
-
var ApplicationInjectionToken = "ApplicationInjectionToken";
|
|
2065
|
-
var Application = InjectionToken.create(
|
|
2066
|
-
ApplicationInjectionToken
|
|
2067
|
-
);
|
|
2068
|
-
|
|
2069
|
-
// packages/core/src/tokens/execution-context.token.mts
|
|
2070
|
-
var ExecutionContextInjectionToken = "ExecutionContextInjectionToken";
|
|
2071
|
-
var ExecutionContextToken = InjectionToken.create(
|
|
2072
|
-
ExecutionContextInjectionToken
|
|
2073
|
-
);
|
|
2074
|
-
|
|
2075
|
-
// packages/core/src/tokens/reply.token.mts
|
|
2076
|
-
var ReplyInjectionToken = "ReplyInjectionToken";
|
|
2077
|
-
var Reply = InjectionToken.create(ReplyInjectionToken);
|
|
2078
|
-
|
|
2079
|
-
// packages/core/src/tokens/request.token.mts
|
|
2080
|
-
var RequestInjectionToken = "RequestInjectionToken";
|
|
2081
|
-
var Request = InjectionToken.create(
|
|
2082
|
-
RequestInjectionToken
|
|
2083
|
-
);
|
|
2084
|
-
|
|
2085
|
-
// packages/core/src/services/execution-context.mts
|
|
2086
|
-
var ExecutionContext2 = class {
|
|
2087
|
-
constructor(module, controller, handler) {
|
|
2088
|
-
this.module = module;
|
|
2089
|
-
this.controller = controller;
|
|
2090
|
-
this.handler = handler;
|
|
2091
|
-
}
|
|
2092
|
-
request;
|
|
2093
|
-
reply;
|
|
2094
|
-
getModule() {
|
|
2095
|
-
return this.module;
|
|
2096
|
-
}
|
|
2097
|
-
getController() {
|
|
2098
|
-
return this.controller;
|
|
2099
|
-
}
|
|
2100
|
-
getHandler() {
|
|
2101
|
-
return this.handler;
|
|
2102
|
-
}
|
|
2103
|
-
getRequest() {
|
|
2104
|
-
if (!this.request) {
|
|
2105
|
-
throw new Error(
|
|
2106
|
-
"[Navios] Request is not set. Make sure to set it before using it."
|
|
2107
|
-
);
|
|
2108
|
-
}
|
|
2109
|
-
return this.request;
|
|
2110
|
-
}
|
|
2111
|
-
getReply() {
|
|
2112
|
-
if (!this.reply) {
|
|
2113
|
-
throw new Error(
|
|
2114
|
-
"[Navios] Reply is not set. Make sure to set it before using it."
|
|
2115
|
-
);
|
|
2116
|
-
}
|
|
2117
|
-
return this.reply;
|
|
2118
|
-
}
|
|
2119
|
-
provideRequest(request) {
|
|
2120
|
-
this.request = request;
|
|
2121
|
-
}
|
|
2122
|
-
provideReply(reply) {
|
|
2123
|
-
this.reply = reply;
|
|
2124
|
-
}
|
|
2125
|
-
};
|
|
2126
|
-
|
|
2127
|
-
// packages/core/src/services/guard-runner.service.mts
|
|
2128
|
-
var _GuardRunnerService_decorators, _init5;
|
|
2129
|
-
_GuardRunnerService_decorators = [Injectable()];
|
|
2130
|
-
var GuardRunnerService = class {
|
|
2131
|
-
async runGuards(allGuards, executionContext) {
|
|
2132
|
-
let canActivate = true;
|
|
2133
|
-
for (const guard of Array.from(allGuards).reverse()) {
|
|
2134
|
-
const guardInstance = await inject(
|
|
2135
|
-
guard
|
|
2136
|
-
);
|
|
2137
|
-
if (!guardInstance.canActivate) {
|
|
2138
|
-
throw new Error(
|
|
2139
|
-
`[Navios] Guard ${guard.name} does not implement canActivate()`
|
|
2140
|
-
);
|
|
2141
|
-
}
|
|
2142
|
-
try {
|
|
2143
|
-
canActivate = await guardInstance.canActivate(executionContext);
|
|
2144
|
-
if (!canActivate) {
|
|
2145
|
-
break;
|
|
2146
|
-
}
|
|
2147
|
-
} catch (error) {
|
|
2148
|
-
if (error instanceof HttpException) {
|
|
2149
|
-
executionContext.getReply().status(error.statusCode).send(error.response);
|
|
2150
|
-
return false;
|
|
2151
|
-
} else {
|
|
2152
|
-
executionContext.getReply().status(500).send({
|
|
2153
|
-
message: "Internal server error",
|
|
2154
|
-
error: error.message
|
|
2155
|
-
});
|
|
2156
|
-
return false;
|
|
2157
|
-
}
|
|
2158
|
-
}
|
|
2159
|
-
}
|
|
2160
|
-
if (!canActivate) {
|
|
2161
|
-
executionContext.getReply().status(403).send({
|
|
2162
|
-
message: "Forbidden"
|
|
2163
|
-
});
|
|
2164
|
-
return false;
|
|
2165
|
-
}
|
|
2166
|
-
return canActivate;
|
|
2167
|
-
}
|
|
2168
|
-
makeContext(executionContext) {
|
|
2169
|
-
const guards = /* @__PURE__ */ new Set();
|
|
2170
|
-
const endpointGuards = executionContext.getHandler().guards;
|
|
2171
|
-
const controllerGuards = executionContext.getController().guards;
|
|
2172
|
-
const moduleGuards = executionContext.getModule().guards;
|
|
2173
|
-
if (endpointGuards.size > 0) {
|
|
2174
|
-
for (const guard of endpointGuards) {
|
|
2175
|
-
guards.add(guard);
|
|
2176
|
-
}
|
|
2470
|
+
|
|
2471
|
+
// packages/core/src/decorators/module.decorator.mts
|
|
2472
|
+
function Module({ controllers = [], imports = [], guards = [] } = {
|
|
2473
|
+
controllers: [],
|
|
2474
|
+
imports: [],
|
|
2475
|
+
guards: []
|
|
2476
|
+
}) {
|
|
2477
|
+
return (target, context) => {
|
|
2478
|
+
if (context.kind !== "class") {
|
|
2479
|
+
throw new Error("[Navios] @Module decorator can only be used on classes.");
|
|
2177
2480
|
}
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2481
|
+
const token = InjectionToken.create(target);
|
|
2482
|
+
const moduleMetadata = getModuleMetadata(target, context);
|
|
2483
|
+
for (const controller of controllers) {
|
|
2484
|
+
moduleMetadata.controllers.add(controller);
|
|
2182
2485
|
}
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
guards.add(guard);
|
|
2186
|
-
}
|
|
2486
|
+
for (const importedModule of imports) {
|
|
2487
|
+
moduleMetadata.imports.add(importedModule);
|
|
2187
2488
|
}
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
}
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2489
|
+
for (const guard of Array.from(guards).reverse()) {
|
|
2490
|
+
moduleMetadata.guards.add(guard);
|
|
2491
|
+
}
|
|
2492
|
+
return Injectable({
|
|
2493
|
+
token,
|
|
2494
|
+
scope: "Singleton" /* Singleton */
|
|
2495
|
+
})(target, context);
|
|
2496
|
+
};
|
|
2497
|
+
}
|
|
2194
2498
|
|
|
2195
|
-
// packages/core/src/
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
});
|
|
2203
|
-
setupController(controller, instance, moduleMetadata) {
|
|
2204
|
-
const controllerMetadata = extractControllerMetadata(controller);
|
|
2205
|
-
for (const endpoint of controllerMetadata.endpoints) {
|
|
2206
|
-
const { classMethod, url, httpMethod } = endpoint;
|
|
2207
|
-
if (!url) {
|
|
2208
|
-
throw new Error(
|
|
2209
|
-
`[Navios] Malformed Endpoint ${controller.name}:${classMethod}`
|
|
2210
|
-
);
|
|
2211
|
-
}
|
|
2212
|
-
const executionContext = new ExecutionContext2(
|
|
2213
|
-
moduleMetadata,
|
|
2214
|
-
controllerMetadata,
|
|
2215
|
-
endpoint
|
|
2499
|
+
// packages/core/src/decorators/multipart.decorator.mts
|
|
2500
|
+
import "zod";
|
|
2501
|
+
function Multipart(endpoint) {
|
|
2502
|
+
return (target, context) => {
|
|
2503
|
+
if (typeof target !== "function") {
|
|
2504
|
+
throw new Error(
|
|
2505
|
+
"[Navios] Endpoint decorator can only be used on functions."
|
|
2216
2506
|
);
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
preHandler: this.providePreHandler(executionContext),
|
|
2222
|
-
handler: this.provideHandler(controller, executionContext, endpoint)
|
|
2223
|
-
});
|
|
2224
|
-
this.logger.debug(
|
|
2225
|
-
`Registered ${httpMethod} ${url} for ${controller.name}:${classMethod}`
|
|
2507
|
+
}
|
|
2508
|
+
if (context.kind !== "method") {
|
|
2509
|
+
throw new Error(
|
|
2510
|
+
"[Navios] Endpoint decorator can only be used on methods."
|
|
2226
2511
|
);
|
|
2227
2512
|
}
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
getServiceLocator().registerInstance(Reply, reply);
|
|
2234
|
-
getServiceLocator().registerInstance(
|
|
2235
|
-
ExecutionContextToken,
|
|
2236
|
-
executionContext
|
|
2513
|
+
const config = endpoint.config;
|
|
2514
|
+
if (context.metadata) {
|
|
2515
|
+
let endpointMetadata = getEndpointMetadata(
|
|
2516
|
+
target,
|
|
2517
|
+
context
|
|
2237
2518
|
);
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
try {
|
|
2242
|
-
canActivate = await this.guardRunner.runGuards(
|
|
2243
|
-
guards,
|
|
2244
|
-
executionContext
|
|
2519
|
+
if (endpointMetadata.config && endpointMetadata.config.url) {
|
|
2520
|
+
throw new Error(
|
|
2521
|
+
`[Navios] Endpoint ${config.method} ${config.url} already exists. Please use a different method or url.`
|
|
2245
2522
|
);
|
|
2246
|
-
} finally {
|
|
2247
|
-
getServiceLocator().removeInstance(Request);
|
|
2248
|
-
getServiceLocator().removeInstance(Reply);
|
|
2249
|
-
getServiceLocator().removeInstance(ExecutionContextToken);
|
|
2250
|
-
}
|
|
2251
|
-
if (!canActivate) {
|
|
2252
|
-
return reply;
|
|
2253
2523
|
}
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
return {};
|
|
2260
|
-
}
|
|
2261
|
-
const { querySchema, requestSchema, responseSchema } = endpointMetadata.config;
|
|
2262
|
-
const schema = {};
|
|
2263
|
-
if (querySchema) {
|
|
2264
|
-
schema.querystring = querySchema;
|
|
2524
|
+
endpointMetadata.config = config;
|
|
2525
|
+
endpointMetadata.adapterToken = MultipartAdapterToken;
|
|
2526
|
+
endpointMetadata.classMethod = target.name;
|
|
2527
|
+
endpointMetadata.httpMethod = config.method;
|
|
2528
|
+
endpointMetadata.url = config.url;
|
|
2265
2529
|
}
|
|
2266
|
-
|
|
2267
|
-
|
|
2530
|
+
return target;
|
|
2531
|
+
};
|
|
2532
|
+
}
|
|
2533
|
+
|
|
2534
|
+
// packages/core/src/decorators/stream.decorator.mts
|
|
2535
|
+
function Stream(endpoint) {
|
|
2536
|
+
return (target, context) => {
|
|
2537
|
+
if (typeof target !== "function") {
|
|
2538
|
+
throw new Error(
|
|
2539
|
+
"[Navios] Endpoint decorator can only be used on functions."
|
|
2540
|
+
);
|
|
2268
2541
|
}
|
|
2269
|
-
if (
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2542
|
+
if (context.kind !== "method") {
|
|
2543
|
+
throw new Error(
|
|
2544
|
+
"[Navios] Endpoint decorator can only be used on methods."
|
|
2545
|
+
);
|
|
2273
2546
|
}
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
case "endpoint" /* Endpoint */:
|
|
2284
|
-
return this.provideHandlerForConfig(
|
|
2285
|
-
controller,
|
|
2286
|
-
executionContext,
|
|
2287
|
-
endpointMetadata
|
|
2288
|
-
);
|
|
2289
|
-
case "stream" /* Stream */:
|
|
2290
|
-
return this.provideHandlerForStream(
|
|
2291
|
-
controller,
|
|
2292
|
-
executionContext,
|
|
2293
|
-
endpointMetadata
|
|
2294
|
-
);
|
|
2295
|
-
case "multipart" /* Multipart */:
|
|
2296
|
-
return this.provideHandlerForMultipart(
|
|
2297
|
-
controller,
|
|
2298
|
-
executionContext,
|
|
2299
|
-
endpointMetadata
|
|
2547
|
+
const config = endpoint.config;
|
|
2548
|
+
if (context.metadata) {
|
|
2549
|
+
let endpointMetadata = getEndpointMetadata(
|
|
2550
|
+
target,
|
|
2551
|
+
context
|
|
2552
|
+
);
|
|
2553
|
+
if (endpointMetadata.config && endpointMetadata.config.url) {
|
|
2554
|
+
throw new Error(
|
|
2555
|
+
`[Navios] Endpoint ${config.method} ${config.url} already exists. Please use a different method or url.`
|
|
2300
2556
|
);
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2557
|
+
}
|
|
2558
|
+
endpointMetadata.config = config;
|
|
2559
|
+
endpointMetadata.adapterToken = StreamAdapterToken;
|
|
2560
|
+
endpointMetadata.classMethod = target.name;
|
|
2561
|
+
endpointMetadata.httpMethod = config.method;
|
|
2562
|
+
endpointMetadata.url = config.url;
|
|
2304
2563
|
}
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2564
|
+
return target;
|
|
2565
|
+
};
|
|
2566
|
+
}
|
|
2567
|
+
|
|
2568
|
+
// packages/core/src/decorators/use-guards.decorator.mts
|
|
2569
|
+
function UseGuards(...guards) {
|
|
2570
|
+
return function(target, context) {
|
|
2571
|
+
if (context.kind === "class") {
|
|
2572
|
+
const controllerMetadata = getControllerMetadata(
|
|
2573
|
+
target,
|
|
2574
|
+
context
|
|
2313
2575
|
);
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
const controllerInstance = await inject(controller);
|
|
2317
|
-
try {
|
|
2318
|
-
const { query, params, body } = request;
|
|
2319
|
-
const argument = {};
|
|
2320
|
-
if (query && Object.keys(query).length > 0) {
|
|
2321
|
-
argument.params = query;
|
|
2322
|
-
}
|
|
2323
|
-
if (params && Object.keys(params).length > 0) {
|
|
2324
|
-
argument.urlParams = params;
|
|
2325
|
-
}
|
|
2326
|
-
if (body) {
|
|
2327
|
-
argument.data = body;
|
|
2328
|
-
}
|
|
2329
|
-
const result = await controllerInstance[endpointMetadata.classMethod](argument);
|
|
2330
|
-
reply.status(endpointMetadata.successStatusCode).headers(endpointMetadata.headers).send(result);
|
|
2331
|
-
} finally {
|
|
2332
|
-
getServiceLocator().removeInstance(Request);
|
|
2333
|
-
getServiceLocator().removeInstance(Reply);
|
|
2334
|
-
getServiceLocator().removeInstance(ExecutionContextToken);
|
|
2576
|
+
for (const guard of guards.reverse()) {
|
|
2577
|
+
controllerMetadata.guards.add(guard);
|
|
2335
2578
|
}
|
|
2336
|
-
}
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
getServiceLocator().registerInstance(Request, request);
|
|
2341
|
-
getServiceLocator().registerInstance(Reply, reply);
|
|
2342
|
-
getServiceLocator().registerInstance(
|
|
2343
|
-
ExecutionContextToken,
|
|
2344
|
-
executionContext
|
|
2345
|
-
);
|
|
2346
|
-
executionContext.provideRequest(request);
|
|
2347
|
-
executionContext.provideReply(reply);
|
|
2348
|
-
const controllerInstance = await inject(controller);
|
|
2349
|
-
try {
|
|
2350
|
-
const { query, params, body } = request;
|
|
2351
|
-
const argument = {};
|
|
2352
|
-
if (query && Object.keys(query).length > 0) {
|
|
2353
|
-
argument.params = query;
|
|
2354
|
-
}
|
|
2355
|
-
if (params && Object.keys(params).length > 0) {
|
|
2356
|
-
argument.urlParams = params;
|
|
2357
|
-
}
|
|
2358
|
-
if (body) {
|
|
2359
|
-
argument.data = body;
|
|
2360
|
-
}
|
|
2361
|
-
await controllerInstance[endpointMetadata.classMethod](argument, reply);
|
|
2362
|
-
} finally {
|
|
2363
|
-
getServiceLocator().removeInstance(Request);
|
|
2364
|
-
getServiceLocator().removeInstance(Reply);
|
|
2365
|
-
getServiceLocator().removeInstance(ExecutionContextToken);
|
|
2579
|
+
} else if (context.kind === "method") {
|
|
2580
|
+
const endpointMetadata = getEndpointMetadata(target, context);
|
|
2581
|
+
for (const guard of guards.reverse()) {
|
|
2582
|
+
endpointMetadata.guards.add(guard);
|
|
2366
2583
|
}
|
|
2367
|
-
}
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
const config = endpointMetadata.config;
|
|
2371
|
-
const requestSchema = config.requestSchema;
|
|
2372
|
-
const shape = requestSchema._def.shape();
|
|
2373
|
-
return async (request, reply) => {
|
|
2374
|
-
getServiceLocator().registerInstance(Request, request);
|
|
2375
|
-
getServiceLocator().registerInstance(Reply, reply);
|
|
2376
|
-
getServiceLocator().registerInstance(
|
|
2377
|
-
ExecutionContextToken,
|
|
2378
|
-
executionContext
|
|
2584
|
+
} else {
|
|
2585
|
+
throw new Error(
|
|
2586
|
+
"[Navios] @UseGuards decorator can only be used on classes or methods."
|
|
2379
2587
|
);
|
|
2380
|
-
executionContext.provideRequest(request);
|
|
2381
|
-
executionContext.provideReply(reply);
|
|
2382
|
-
const controllerInstance = await inject(controller);
|
|
2383
|
-
try {
|
|
2384
|
-
const parts = request.parts();
|
|
2385
|
-
const { query, params } = request;
|
|
2386
|
-
const argument = {};
|
|
2387
|
-
if (query && Object.keys(query).length > 0) {
|
|
2388
|
-
argument.params = query;
|
|
2389
|
-
}
|
|
2390
|
-
if (params && Object.keys(params).length > 0) {
|
|
2391
|
-
argument.urlParams = params;
|
|
2392
|
-
}
|
|
2393
|
-
const req = {};
|
|
2394
|
-
for await (const part of parts) {
|
|
2395
|
-
if (!shape[part.fieldname]) {
|
|
2396
|
-
throw new NaviosException4(
|
|
2397
|
-
`Invalid field name ${part.fieldname} for multipart request`
|
|
2398
|
-
);
|
|
2399
|
-
}
|
|
2400
|
-
const schema = shape[part.fieldname];
|
|
2401
|
-
if (part.type === "file") {
|
|
2402
|
-
const file = new File([await part.toBuffer()], part.filename, {
|
|
2403
|
-
type: part.mimetype
|
|
2404
|
-
});
|
|
2405
|
-
if (schema instanceof ZodArray) {
|
|
2406
|
-
if (!req[part.fieldname]) {
|
|
2407
|
-
req[part.fieldname] = [];
|
|
2408
|
-
}
|
|
2409
|
-
req[part.fieldname].push(file);
|
|
2410
|
-
} else {
|
|
2411
|
-
req[part.fieldname] = file;
|
|
2412
|
-
}
|
|
2413
|
-
} else {
|
|
2414
|
-
if (schema instanceof ZodArray) {
|
|
2415
|
-
if (!req[part.fieldname]) {
|
|
2416
|
-
req[part.fieldname] = [];
|
|
2417
|
-
}
|
|
2418
|
-
req[part.fieldname].push(part.value);
|
|
2419
|
-
} else {
|
|
2420
|
-
req[part.fieldname] = part.value;
|
|
2421
|
-
}
|
|
2422
|
-
}
|
|
2423
|
-
}
|
|
2424
|
-
argument.data = requestSchema.parse(req);
|
|
2425
|
-
const result = await controllerInstance[endpointMetadata.classMethod](argument);
|
|
2426
|
-
reply.status(endpointMetadata.successStatusCode).headers(endpointMetadata.headers).send(result);
|
|
2427
|
-
} finally {
|
|
2428
|
-
getServiceLocator().removeInstance(Request);
|
|
2429
|
-
getServiceLocator().removeInstance(Reply);
|
|
2430
|
-
getServiceLocator().removeInstance(ExecutionContextToken);
|
|
2431
|
-
}
|
|
2432
|
-
};
|
|
2433
|
-
}
|
|
2434
|
-
};
|
|
2435
|
-
_init6 = __decoratorStart(null);
|
|
2436
|
-
_ControllerAdapterService = __decorateElement(_init6, 0, "ControllerAdapterService", _ControllerAdapterService_decorators, _ControllerAdapterService);
|
|
2437
|
-
__runInitializers(_init6, 1, _ControllerAdapterService);
|
|
2438
|
-
var ControllerAdapterService = _ControllerAdapterService;
|
|
2439
|
-
|
|
2440
|
-
// packages/core/src/services/module-loader.service.mts
|
|
2441
|
-
var _ModuleLoaderService_decorators, _init7;
|
|
2442
|
-
_ModuleLoaderService_decorators = [Injectable()];
|
|
2443
|
-
var _ModuleLoaderService = class _ModuleLoaderService {
|
|
2444
|
-
logger = syncInject(Logger, {
|
|
2445
|
-
context: _ModuleLoaderService.name
|
|
2446
|
-
});
|
|
2447
|
-
modulesMetadata = /* @__PURE__ */ new Map();
|
|
2448
|
-
loadedModules = /* @__PURE__ */ new Map();
|
|
2449
|
-
initialized = false;
|
|
2450
|
-
async loadModules(appModule) {
|
|
2451
|
-
if (this.initialized) {
|
|
2452
|
-
return;
|
|
2453
|
-
}
|
|
2454
|
-
await this.traverseModules(appModule);
|
|
2455
|
-
this.initialized = true;
|
|
2456
|
-
}
|
|
2457
|
-
async traverseModules(module, parentMetadata) {
|
|
2458
|
-
const metadata = extractModuleMetadata(module);
|
|
2459
|
-
if (parentMetadata) {
|
|
2460
|
-
this.mergeMetadata(metadata, parentMetadata);
|
|
2461
|
-
}
|
|
2462
|
-
const moduleName = module.name;
|
|
2463
|
-
if (this.modulesMetadata.has(moduleName)) {
|
|
2464
|
-
return;
|
|
2465
|
-
}
|
|
2466
|
-
this.modulesMetadata.set(moduleName, metadata);
|
|
2467
|
-
const imports = metadata.imports ?? /* @__PURE__ */ new Set();
|
|
2468
|
-
const loadingPromises = Array.from(imports).map(
|
|
2469
|
-
async (importedModule) => this.traverseModules(importedModule, metadata)
|
|
2470
|
-
);
|
|
2471
|
-
await Promise.all(loadingPromises);
|
|
2472
|
-
const instance = await inject(module);
|
|
2473
|
-
if (instance.onModuleInit) {
|
|
2474
|
-
await instance.onModuleInit();
|
|
2475
|
-
}
|
|
2476
|
-
this.logger.debug(`Module ${moduleName} loaded`);
|
|
2477
|
-
this.loadedModules.set(moduleName, instance);
|
|
2478
|
-
}
|
|
2479
|
-
mergeMetadata(metadata, parentMetadata) {
|
|
2480
|
-
if (parentMetadata.guards) {
|
|
2481
|
-
for (const guard of parentMetadata.guards) {
|
|
2482
|
-
metadata.guards.add(guard);
|
|
2483
|
-
}
|
|
2484
|
-
}
|
|
2485
|
-
if (parentMetadata.customAttributes) {
|
|
2486
|
-
for (const [key, value] of parentMetadata.customAttributes) {
|
|
2487
|
-
if (metadata.customAttributes.has(key)) {
|
|
2488
|
-
continue;
|
|
2489
|
-
}
|
|
2490
|
-
metadata.customAttributes.set(key, value);
|
|
2491
|
-
}
|
|
2492
2588
|
}
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
}
|
|
2497
|
-
dispose() {
|
|
2498
|
-
this.modulesMetadata.clear();
|
|
2499
|
-
this.loadedModules.clear();
|
|
2500
|
-
this.initialized = false;
|
|
2501
|
-
}
|
|
2502
|
-
};
|
|
2503
|
-
_init7 = __decoratorStart(null);
|
|
2504
|
-
_ModuleLoaderService = __decorateElement(_init7, 0, "ModuleLoaderService", _ModuleLoaderService_decorators, _ModuleLoaderService);
|
|
2505
|
-
__runInitializers(_init7, 1, _ModuleLoaderService);
|
|
2506
|
-
var ModuleLoaderService = _ModuleLoaderService;
|
|
2589
|
+
return target;
|
|
2590
|
+
};
|
|
2591
|
+
}
|
|
2507
2592
|
|
|
2508
2593
|
// packages/core/src/attribute.factory.mts
|
|
2509
2594
|
var AttributeFactory = class {
|
|
@@ -2570,7 +2655,7 @@ import {
|
|
|
2570
2655
|
serializerCompiler,
|
|
2571
2656
|
validatorCompiler
|
|
2572
2657
|
} from "fastify-type-provider-zod";
|
|
2573
|
-
var _NaviosApplication_decorators,
|
|
2658
|
+
var _NaviosApplication_decorators, _init11;
|
|
2574
2659
|
_NaviosApplication_decorators = [Injectable()];
|
|
2575
2660
|
var _NaviosApplication = class _NaviosApplication {
|
|
2576
2661
|
moduleLoader = syncInject(ModuleLoaderService);
|
|
@@ -2662,7 +2747,7 @@ var _NaviosApplication = class _NaviosApplication {
|
|
|
2662
2747
|
message: "Not Found",
|
|
2663
2748
|
error: "NotFound"
|
|
2664
2749
|
};
|
|
2665
|
-
this.logger.error(`Route not found: ${req.url}`);
|
|
2750
|
+
this.logger.error(`Route not found: [${req.method}] ${req.url}`);
|
|
2666
2751
|
return reply.status(404).send(response);
|
|
2667
2752
|
});
|
|
2668
2753
|
}
|
|
@@ -2683,15 +2768,14 @@ var _NaviosApplication = class _NaviosApplication {
|
|
|
2683
2768
|
}
|
|
2684
2769
|
promises.push(
|
|
2685
2770
|
this.server.register(
|
|
2686
|
-
(instance, opts
|
|
2771
|
+
async (instance, opts) => {
|
|
2687
2772
|
for (const controller of moduleMetadata.controllers) {
|
|
2688
|
-
this.controllerAdapter.setupController(
|
|
2773
|
+
await this.controllerAdapter.setupController(
|
|
2689
2774
|
controller,
|
|
2690
2775
|
instance,
|
|
2691
2776
|
moduleMetadata
|
|
2692
2777
|
);
|
|
2693
2778
|
}
|
|
2694
|
-
done();
|
|
2695
2779
|
},
|
|
2696
2780
|
{
|
|
2697
2781
|
prefix: this.globalPrefix ?? ""
|
|
@@ -2736,9 +2820,9 @@ var _NaviosApplication = class _NaviosApplication {
|
|
|
2736
2820
|
await this.dispose();
|
|
2737
2821
|
}
|
|
2738
2822
|
};
|
|
2739
|
-
|
|
2740
|
-
_NaviosApplication = __decorateElement(
|
|
2741
|
-
__runInitializers(
|
|
2823
|
+
_init11 = __decoratorStart(null);
|
|
2824
|
+
_NaviosApplication = __decorateElement(_init11, 0, "NaviosApplication", _NaviosApplication_decorators, _NaviosApplication);
|
|
2825
|
+
__runInitializers(_init11, 1, _NaviosApplication);
|
|
2742
2826
|
var NaviosApplication = _NaviosApplication;
|
|
2743
2827
|
|
|
2744
2828
|
// packages/core/src/navios.factory.mts
|
|
@@ -2774,11 +2858,12 @@ export {
|
|
|
2774
2858
|
ControllerAdapterService,
|
|
2775
2859
|
ControllerMetadataKey,
|
|
2776
2860
|
Endpoint,
|
|
2861
|
+
EndpointAdapterService,
|
|
2862
|
+
EndpointAdapterToken,
|
|
2777
2863
|
EndpointMetadataKey,
|
|
2778
|
-
EndpointType,
|
|
2779
2864
|
ErrorsEnum,
|
|
2780
2865
|
EventEmitter,
|
|
2781
|
-
|
|
2866
|
+
ExecutionContext,
|
|
2782
2867
|
ExecutionContextInjectionToken,
|
|
2783
2868
|
ExecutionContextToken,
|
|
2784
2869
|
FactoryInjectionToken,
|
|
@@ -2808,6 +2893,8 @@ export {
|
|
|
2808
2893
|
ModuleLoaderService,
|
|
2809
2894
|
ModuleMetadataKey,
|
|
2810
2895
|
Multipart,
|
|
2896
|
+
MultipartAdapterService,
|
|
2897
|
+
MultipartAdapterToken,
|
|
2811
2898
|
NaviosApplication,
|
|
2812
2899
|
NaviosFactory,
|
|
2813
2900
|
NotFoundException,
|
|
@@ -2820,6 +2907,8 @@ export {
|
|
|
2820
2907
|
ServiceLocatorInstanceHolderStatus,
|
|
2821
2908
|
ServiceLocatorManager,
|
|
2822
2909
|
Stream,
|
|
2910
|
+
StreamAdapterService,
|
|
2911
|
+
StreamAdapterToken,
|
|
2823
2912
|
UnauthorizedException,
|
|
2824
2913
|
UnknownError,
|
|
2825
2914
|
UseGuards,
|