@navios/core 0.1.14 → 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 +124 -49
- package/dist/_tsup-dts-rollup.d.ts +124 -49
- package/dist/index.d.mts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +537 -471
- package/dist/index.mjs +531 -470
- 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/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/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.js
CHANGED
|
@@ -88,8 +88,9 @@ __export(src_exports, {
|
|
|
88
88
|
ControllerAdapterService: () => ControllerAdapterService,
|
|
89
89
|
ControllerMetadataKey: () => ControllerMetadataKey,
|
|
90
90
|
Endpoint: () => Endpoint,
|
|
91
|
+
EndpointAdapterService: () => EndpointAdapterService,
|
|
92
|
+
EndpointAdapterToken: () => EndpointAdapterToken,
|
|
91
93
|
EndpointMetadataKey: () => EndpointMetadataKey,
|
|
92
|
-
EndpointType: () => EndpointType,
|
|
93
94
|
ErrorsEnum: () => ErrorsEnum,
|
|
94
95
|
EventEmitter: () => EventEmitter,
|
|
95
96
|
ExecutionContext: () => ExecutionContext,
|
|
@@ -122,6 +123,8 @@ __export(src_exports, {
|
|
|
122
123
|
ModuleLoaderService: () => ModuleLoaderService,
|
|
123
124
|
ModuleMetadataKey: () => ModuleMetadataKey,
|
|
124
125
|
Multipart: () => Multipart,
|
|
126
|
+
MultipartAdapterService: () => MultipartAdapterService,
|
|
127
|
+
MultipartAdapterToken: () => MultipartAdapterToken,
|
|
125
128
|
NaviosApplication: () => NaviosApplication,
|
|
126
129
|
NaviosFactory: () => NaviosFactory,
|
|
127
130
|
NotFoundException: () => NotFoundException,
|
|
@@ -134,6 +137,8 @@ __export(src_exports, {
|
|
|
134
137
|
ServiceLocatorInstanceHolderStatus: () => ServiceLocatorInstanceHolderStatus,
|
|
135
138
|
ServiceLocatorManager: () => ServiceLocatorManager,
|
|
136
139
|
Stream: () => Stream,
|
|
140
|
+
StreamAdapterService: () => StreamAdapterService,
|
|
141
|
+
StreamAdapterToken: () => StreamAdapterToken,
|
|
137
142
|
UnauthorizedException: () => UnauthorizedException,
|
|
138
143
|
UnknownError: () => UnknownError,
|
|
139
144
|
UseGuards: () => UseGuards,
|
|
@@ -177,117 +182,6 @@ __export(src_exports, {
|
|
|
177
182
|
});
|
|
178
183
|
module.exports = __toCommonJS(src_exports);
|
|
179
184
|
|
|
180
|
-
// packages/core/src/config/utils/helpers.mts
|
|
181
|
-
var import_node_process = require("process");
|
|
182
|
-
function envInt(key, defaultValue) {
|
|
183
|
-
const envKey = import_node_process.env[key] || process.env[key];
|
|
184
|
-
return envKey ? parseInt(envKey, 10) : defaultValue;
|
|
185
|
-
}
|
|
186
|
-
function envString(key, defaultValue) {
|
|
187
|
-
return import_node_process.env[key] || process.env[key] || defaultValue || void 0;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// packages/core/src/config/config.provider.mts
|
|
191
|
-
var import_zod4 = require("zod");
|
|
192
|
-
|
|
193
|
-
// packages/core/src/logger/utils/cli-colors.util.mts
|
|
194
|
-
var isColorAllowed = () => !process.env.NO_COLOR;
|
|
195
|
-
var colorIfAllowed = (colorFn) => (text) => isColorAllowed() ? colorFn(text) : text;
|
|
196
|
-
var clc = {
|
|
197
|
-
bold: colorIfAllowed((text) => `\x1B[1m${text}\x1B[0m`),
|
|
198
|
-
green: colorIfAllowed((text) => `\x1B[32m${text}\x1B[39m`),
|
|
199
|
-
yellow: colorIfAllowed((text) => `\x1B[33m${text}\x1B[39m`),
|
|
200
|
-
red: colorIfAllowed((text) => `\x1B[31m${text}\x1B[39m`),
|
|
201
|
-
magentaBright: colorIfAllowed((text) => `\x1B[95m${text}\x1B[39m`),
|
|
202
|
-
cyanBright: colorIfAllowed((text) => `\x1B[96m${text}\x1B[39m`)
|
|
203
|
-
};
|
|
204
|
-
var yellow = colorIfAllowed(
|
|
205
|
-
(text) => `\x1B[38;5;3m${text}\x1B[39m`
|
|
206
|
-
);
|
|
207
|
-
|
|
208
|
-
// packages/core/src/logger/log-levels.mts
|
|
209
|
-
var LOG_LEVELS = [
|
|
210
|
-
"verbose",
|
|
211
|
-
"debug",
|
|
212
|
-
"log",
|
|
213
|
-
"warn",
|
|
214
|
-
"error",
|
|
215
|
-
"fatal"
|
|
216
|
-
];
|
|
217
|
-
|
|
218
|
-
// packages/core/src/logger/utils/is-log-level.util.mts
|
|
219
|
-
function isLogLevel(maybeLogLevel) {
|
|
220
|
-
return LOG_LEVELS.includes(maybeLogLevel);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// packages/core/src/logger/utils/filter-log-levelts.util.mts
|
|
224
|
-
function filterLogLevels(parseableString = "") {
|
|
225
|
-
const sanitizedString = parseableString.replaceAll(" ", "").toLowerCase();
|
|
226
|
-
if (sanitizedString[0] === ">") {
|
|
227
|
-
const orEqual = sanitizedString[1] === "=";
|
|
228
|
-
const logLevelIndex = LOG_LEVELS.indexOf(
|
|
229
|
-
sanitizedString.substring(orEqual ? 2 : 1)
|
|
230
|
-
);
|
|
231
|
-
if (logLevelIndex === -1) {
|
|
232
|
-
throw new Error(`parse error (unknown log level): ${sanitizedString}`);
|
|
233
|
-
}
|
|
234
|
-
return LOG_LEVELS.slice(orEqual ? logLevelIndex : logLevelIndex + 1);
|
|
235
|
-
} else if (sanitizedString.includes(",")) {
|
|
236
|
-
return sanitizedString.split(",").filter(isLogLevel);
|
|
237
|
-
}
|
|
238
|
-
return isLogLevel(sanitizedString) ? [sanitizedString] : LOG_LEVELS;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
// packages/core/src/logger/utils/is-log-level-enabled.mts
|
|
242
|
-
var LOG_LEVEL_VALUES = {
|
|
243
|
-
verbose: 0,
|
|
244
|
-
debug: 1,
|
|
245
|
-
log: 2,
|
|
246
|
-
warn: 3,
|
|
247
|
-
error: 4,
|
|
248
|
-
fatal: 5
|
|
249
|
-
};
|
|
250
|
-
function isLogLevelEnabled(targetLevel, logLevels) {
|
|
251
|
-
var _a;
|
|
252
|
-
if (!logLevels || Array.isArray(logLevels) && (logLevels == null ? void 0 : logLevels.length) === 0) {
|
|
253
|
-
return false;
|
|
254
|
-
}
|
|
255
|
-
if (logLevels.includes(targetLevel)) {
|
|
256
|
-
return true;
|
|
257
|
-
}
|
|
258
|
-
const highestLogLevelValue = (_a = logLevels.map((level) => LOG_LEVEL_VALUES[level]).sort((a, b) => b - a)) == null ? void 0 : _a[0];
|
|
259
|
-
const targetLevelValue = LOG_LEVEL_VALUES[targetLevel];
|
|
260
|
-
return targetLevelValue >= highestLogLevelValue;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// packages/core/src/logger/utils/shared.utils.mts
|
|
264
|
-
var isUndefined = (obj) => typeof obj === "undefined";
|
|
265
|
-
var isObject = (fn) => !isNil(fn) && typeof fn === "object";
|
|
266
|
-
var isPlainObject = (fn) => {
|
|
267
|
-
if (!isObject(fn)) {
|
|
268
|
-
return false;
|
|
269
|
-
}
|
|
270
|
-
const proto = Object.getPrototypeOf(fn);
|
|
271
|
-
if (proto === null) {
|
|
272
|
-
return true;
|
|
273
|
-
}
|
|
274
|
-
const ctor = Object.prototype.hasOwnProperty.call(proto, "constructor") && proto.constructor;
|
|
275
|
-
return typeof ctor === "function" && ctor instanceof ctor && Function.prototype.toString.call(ctor) === Function.prototype.toString.call(Object);
|
|
276
|
-
};
|
|
277
|
-
var addLeadingSlash = (path) => path && typeof path === "string" ? path.charAt(0) !== "/" && path.substring(0, 2) !== "{/" ? "/" + path : path : "";
|
|
278
|
-
var normalizePath = (path) => path ? path.startsWith("/") ? ("/" + path.replace(/\/+$/, "")).replace(/\/+/g, "/") : "/" + path.replace(/\/+$/, "") : "/";
|
|
279
|
-
var stripEndSlash = (path) => path[path.length - 1] === "/" ? path.slice(0, path.length - 1) : path;
|
|
280
|
-
var isFunction = (val) => typeof val === "function";
|
|
281
|
-
var isString = (val) => typeof val === "string";
|
|
282
|
-
var isNumber = (val) => typeof val === "number";
|
|
283
|
-
var isConstructor = (val) => val === "constructor";
|
|
284
|
-
var isNil = (val) => isUndefined(val) || val === null;
|
|
285
|
-
var isEmpty = (array) => !(array && array.length > 0);
|
|
286
|
-
var isSymbol = (val) => typeof val === "symbol";
|
|
287
|
-
|
|
288
|
-
// packages/core/src/logger/console-logger.service.mts
|
|
289
|
-
var import_util = require("util");
|
|
290
|
-
|
|
291
185
|
// packages/core/src/service-locator/decorators/injectable.decorator.mts
|
|
292
186
|
var import_common2 = require("@navios/common");
|
|
293
187
|
|
|
@@ -421,8 +315,8 @@ var ServiceLocatorEventBus = class {
|
|
|
421
315
|
}
|
|
422
316
|
listeners = /* @__PURE__ */ new Map();
|
|
423
317
|
on(ns, event, listener) {
|
|
424
|
-
var
|
|
425
|
-
(
|
|
318
|
+
var _a3;
|
|
319
|
+
(_a3 = this.logger) == null ? void 0 : _a3.debug(`[ServiceLocatorEventBus]#on(): ns:${ns} event:${event}`);
|
|
426
320
|
if (!this.listeners.has(ns)) {
|
|
427
321
|
this.listeners.set(ns, /* @__PURE__ */ new Map());
|
|
428
322
|
}
|
|
@@ -432,9 +326,9 @@ var ServiceLocatorEventBus = class {
|
|
|
432
326
|
}
|
|
433
327
|
nsEvents.get(event).add(listener);
|
|
434
328
|
return () => {
|
|
435
|
-
var
|
|
329
|
+
var _a4;
|
|
436
330
|
nsEvents.get(event).delete(listener);
|
|
437
|
-
if (((
|
|
331
|
+
if (((_a4 = nsEvents.get(event)) == null ? void 0 : _a4.size) === 0) {
|
|
438
332
|
nsEvents.delete(event);
|
|
439
333
|
}
|
|
440
334
|
if (nsEvents.size === 0) {
|
|
@@ -443,20 +337,20 @@ var ServiceLocatorEventBus = class {
|
|
|
443
337
|
};
|
|
444
338
|
}
|
|
445
339
|
async emit(key, event) {
|
|
446
|
-
var
|
|
340
|
+
var _a3, _b, _c;
|
|
447
341
|
if (!this.listeners.has(key)) {
|
|
448
342
|
return;
|
|
449
343
|
}
|
|
450
344
|
const events = this.listeners.get(key);
|
|
451
345
|
const preEvent = `pre:${event}`;
|
|
452
346
|
const postEvent = `post:${event}`;
|
|
453
|
-
(
|
|
347
|
+
(_a3 = this.logger) == null ? void 0 : _a3.debug(`[ServiceLocatorEventBus]#emit(): ${key}:${preEvent}`);
|
|
454
348
|
await Promise.allSettled(
|
|
455
349
|
[...events.get(preEvent) ?? []].map((listener) => listener(preEvent))
|
|
456
350
|
).then((results) => {
|
|
457
351
|
results.filter((result) => result.status === "rejected").forEach((result) => {
|
|
458
|
-
var
|
|
459
|
-
(
|
|
352
|
+
var _a4;
|
|
353
|
+
(_a4 = this.logger) == null ? void 0 : _a4.warn(
|
|
460
354
|
`[ServiceLocatorEventBus]#emit(): ${key}:${preEvent} rejected with`,
|
|
461
355
|
result.reason
|
|
462
356
|
);
|
|
@@ -467,8 +361,8 @@ var ServiceLocatorEventBus = class {
|
|
|
467
361
|
[...events.get(event) ?? []].map((listener) => listener(event))
|
|
468
362
|
).then((results) => {
|
|
469
363
|
const res2 = results.filter((result) => result.status === "rejected").map((result) => {
|
|
470
|
-
var
|
|
471
|
-
(
|
|
364
|
+
var _a4;
|
|
365
|
+
(_a4 = this.logger) == null ? void 0 : _a4.warn(
|
|
472
366
|
`[ServiceLocatorEventBus]#emit(): ${key}:${event} rejected with`,
|
|
473
367
|
result.reason
|
|
474
368
|
);
|
|
@@ -484,8 +378,8 @@ var ServiceLocatorEventBus = class {
|
|
|
484
378
|
[...events.get(postEvent) ?? []].map((listener) => listener(postEvent))
|
|
485
379
|
).then((results) => {
|
|
486
380
|
results.filter((result) => result.status === "rejected").forEach((result) => {
|
|
487
|
-
var
|
|
488
|
-
(
|
|
381
|
+
var _a4;
|
|
382
|
+
(_a4 = this.logger) == null ? void 0 : _a4.warn(
|
|
489
383
|
`[ServiceLocatorEventBus]#emit(): ${key}:${postEvent} rejected with`,
|
|
490
384
|
result.reason
|
|
491
385
|
);
|
|
@@ -516,13 +410,13 @@ var ServiceLocatorManager = class {
|
|
|
516
410
|
}
|
|
517
411
|
instancesHolders = /* @__PURE__ */ new Map();
|
|
518
412
|
get(name2) {
|
|
519
|
-
var
|
|
413
|
+
var _a3, _b, _c;
|
|
520
414
|
const holder = this.instancesHolders.get(name2);
|
|
521
415
|
if (holder) {
|
|
522
416
|
if (holder.ttl !== Infinity) {
|
|
523
417
|
const now = Date.now();
|
|
524
418
|
if (now - holder.createdAt > holder.ttl) {
|
|
525
|
-
(
|
|
419
|
+
(_a3 = this.logger) == null ? void 0 : _a3.log(
|
|
526
420
|
`[ServiceLocatorManager]#getInstanceHolder() TTL expired for ${holder.name}`
|
|
527
421
|
);
|
|
528
422
|
return [new InstanceExpired(holder.name), holder];
|
|
@@ -604,8 +498,8 @@ var ServiceLocator = class {
|
|
|
604
498
|
return this.invalidate(instanceName);
|
|
605
499
|
}
|
|
606
500
|
registerAbstractFactory(token, factory, type = "Singleton" /* Singleton */) {
|
|
607
|
-
var
|
|
608
|
-
(
|
|
501
|
+
var _a3;
|
|
502
|
+
(_a3 = this.logger) == null ? void 0 : _a3.log(
|
|
609
503
|
`[ServiceLocator]#registerAbstractFactory(): Registering abstract factory for ${name}`
|
|
610
504
|
);
|
|
611
505
|
if (type === "Instance" /* Instance */) {
|
|
@@ -617,7 +511,7 @@ var ServiceLocator = class {
|
|
|
617
511
|
}
|
|
618
512
|
}
|
|
619
513
|
resolveTokenArgs(token, args) {
|
|
620
|
-
var
|
|
514
|
+
var _a3, _b;
|
|
621
515
|
let realArgs = args;
|
|
622
516
|
if (token instanceof BoundInjectionToken) {
|
|
623
517
|
realArgs = token.value;
|
|
@@ -631,7 +525,7 @@ var ServiceLocator = class {
|
|
|
631
525
|
if (!token.schema) {
|
|
632
526
|
return [void 0, realArgs];
|
|
633
527
|
}
|
|
634
|
-
const validatedArgs = (
|
|
528
|
+
const validatedArgs = (_a3 = token.schema) == null ? void 0 : _a3.safeParse(realArgs);
|
|
635
529
|
if (validatedArgs && !validatedArgs.success) {
|
|
636
530
|
(_b = this.logger) == null ? void 0 : _b.error(
|
|
637
531
|
`[ServiceLocator]#getInstance(): Error validating args for ${token.name.toString()}`,
|
|
@@ -649,7 +543,7 @@ var ServiceLocator = class {
|
|
|
649
543
|
return this.makeInstanceName(token, realArgs);
|
|
650
544
|
}
|
|
651
545
|
async getInstance(token, args) {
|
|
652
|
-
var
|
|
546
|
+
var _a3, _b;
|
|
653
547
|
const [err, realArgs] = this.resolveTokenArgs(token, args);
|
|
654
548
|
if (err instanceof UnknownError) {
|
|
655
549
|
throw err;
|
|
@@ -669,7 +563,7 @@ var ServiceLocator = class {
|
|
|
669
563
|
}
|
|
670
564
|
switch (error.code) {
|
|
671
565
|
case "InstanceDestroying" /* InstanceDestroying */:
|
|
672
|
-
(
|
|
566
|
+
(_a3 = this.logger) == null ? void 0 : _a3.log(
|
|
673
567
|
`[ServiceLocator]#getInstance() TTL expired for ${holder == null ? void 0 : holder.name}`
|
|
674
568
|
);
|
|
675
569
|
await (holder == null ? void 0 : holder.destroyPromise);
|
|
@@ -695,15 +589,15 @@ var ServiceLocator = class {
|
|
|
695
589
|
return instance;
|
|
696
590
|
}
|
|
697
591
|
notifyListeners(name2, event = "create") {
|
|
698
|
-
var
|
|
699
|
-
(
|
|
592
|
+
var _a3;
|
|
593
|
+
(_a3 = this.logger) == null ? void 0 : _a3.log(
|
|
700
594
|
`[ServiceLocator]#notifyListeners() Notifying listeners for ${name2} with event ${event}`
|
|
701
595
|
);
|
|
702
596
|
return this.eventBus.emit(name2, event);
|
|
703
597
|
}
|
|
704
598
|
async createInstance(instanceName, token, args) {
|
|
705
|
-
var
|
|
706
|
-
(
|
|
599
|
+
var _a3;
|
|
600
|
+
(_a3 = this.logger) == null ? void 0 : _a3.log(
|
|
707
601
|
`[ServiceLocator]#createInstance() Creating instance for ${instanceName}`
|
|
708
602
|
);
|
|
709
603
|
let realToken = token instanceof BoundInjectionToken || token instanceof FactoryInjectionToken ? token.token : token;
|
|
@@ -718,8 +612,8 @@ var ServiceLocator = class {
|
|
|
718
612
|
}
|
|
719
613
|
}
|
|
720
614
|
async createInstanceFromAbstractFactory(instanceName, token, args) {
|
|
721
|
-
var
|
|
722
|
-
(
|
|
615
|
+
var _a3;
|
|
616
|
+
(_a3 = this.logger) == null ? void 0 : _a3.log(
|
|
723
617
|
`[ServiceLocator]#createInstanceFromAbstractFactory(): Creating instance for ${instanceName} from abstract factory`
|
|
724
618
|
);
|
|
725
619
|
const ctx = this.createContextForAbstractFactory(instanceName);
|
|
@@ -739,14 +633,14 @@ var ServiceLocator = class {
|
|
|
739
633
|
kind: "abstractFactory" /* AbstractFactory */,
|
|
740
634
|
// @ts-expect-error TS2322 This is correct type
|
|
741
635
|
creationPromise: abstractFactory(ctx, args).then(async (instance) => {
|
|
742
|
-
var
|
|
636
|
+
var _a4;
|
|
743
637
|
holder.instance = instance;
|
|
744
638
|
holder.status = "created" /* Created */;
|
|
745
639
|
holder.deps = ctx.getDependencies();
|
|
746
640
|
holder.destroyListeners = ctx.getDestroyListeners();
|
|
747
641
|
holder.ttl = ctx.getTtl();
|
|
748
642
|
if (holder.deps.length > 0) {
|
|
749
|
-
(
|
|
643
|
+
(_a4 = this.logger) == null ? void 0 : _a4.log(
|
|
750
644
|
`[ServiceLocator]#createInstanceFromAbstractFactory(): Adding subscriptions for ${instanceName} dependencies for their invalidations: ${holder.deps.join(
|
|
751
645
|
", "
|
|
752
646
|
)}`
|
|
@@ -767,8 +661,8 @@ var ServiceLocator = class {
|
|
|
767
661
|
await this.notifyListeners(instanceName);
|
|
768
662
|
return [void 0, instance];
|
|
769
663
|
}).catch((error) => {
|
|
770
|
-
var
|
|
771
|
-
(
|
|
664
|
+
var _a4;
|
|
665
|
+
(_a4 = this.logger) == null ? void 0 : _a4.error(
|
|
772
666
|
`[ServiceLocator]#createInstanceFromAbstractFactory(): Error creating instance for ${instanceName}`,
|
|
773
667
|
error
|
|
774
668
|
);
|
|
@@ -845,8 +739,8 @@ var ServiceLocator = class {
|
|
|
845
739
|
return holder.instance;
|
|
846
740
|
}
|
|
847
741
|
invalidate(service, round = 1) {
|
|
848
|
-
var
|
|
849
|
-
(
|
|
742
|
+
var _a3, _b, _c, _d, _e;
|
|
743
|
+
(_a3 = this.logger) == null ? void 0 : _a3.log(
|
|
850
744
|
`[ServiceLocator]#invalidate(): Starting Invalidating process of ${service}`
|
|
851
745
|
);
|
|
852
746
|
const toInvalidate = this.manager.filter(
|
|
@@ -867,9 +761,9 @@ var ServiceLocator = class {
|
|
|
867
761
|
);
|
|
868
762
|
promises.push(
|
|
869
763
|
(_d = holder.creationPromise) == null ? void 0 : _d.then(() => {
|
|
870
|
-
var
|
|
764
|
+
var _a4;
|
|
871
765
|
if (round > 3) {
|
|
872
|
-
(
|
|
766
|
+
(_a4 = this.logger) == null ? void 0 : _a4.error(
|
|
873
767
|
`[ServiceLocator]#invalidate(): ${key} creation is triggering a new invalidation round, but it is still not created`
|
|
874
768
|
);
|
|
875
769
|
return;
|
|
@@ -896,9 +790,9 @@ var ServiceLocator = class {
|
|
|
896
790
|
async ready() {
|
|
897
791
|
return Promise.all(
|
|
898
792
|
Array.from(this.manager.filter(() => true)).map(([, holder]) => {
|
|
899
|
-
var
|
|
793
|
+
var _a3;
|
|
900
794
|
if (holder.status === "creating" /* Creating */) {
|
|
901
|
-
return (
|
|
795
|
+
return (_a3 = holder.creationPromise) == null ? void 0 : _a3.then(() => null);
|
|
902
796
|
}
|
|
903
797
|
if (holder.status === "destroying" /* Destroying */) {
|
|
904
798
|
return holder.destroyPromise.then(() => null);
|
|
@@ -1059,7 +953,7 @@ var InjectableType = /* @__PURE__ */ ((InjectableType2) => {
|
|
|
1059
953
|
InjectableType2["Factory"] = "Factory";
|
|
1060
954
|
return InjectableType2;
|
|
1061
955
|
})(InjectableType || {});
|
|
1062
|
-
var InjectableTokenMeta = Symbol("InjectableTokenMeta");
|
|
956
|
+
var InjectableTokenMeta = Symbol.for("InjectableTokenMeta");
|
|
1063
957
|
function Injectable({
|
|
1064
958
|
scope = "Singleton" /* Singleton */,
|
|
1065
959
|
type = "Class" /* Class */,
|
|
@@ -1173,26 +1067,343 @@ function override(token, target) {
|
|
|
1173
1067
|
};
|
|
1174
1068
|
}
|
|
1175
1069
|
|
|
1070
|
+
// packages/core/src/adapters/stream-adapter.service.mts
|
|
1071
|
+
var StreamAdapterToken = InjectionToken.create(
|
|
1072
|
+
Symbol.for("StreamAdapterService")
|
|
1073
|
+
);
|
|
1074
|
+
var _StreamAdapterService_decorators, _init;
|
|
1075
|
+
_StreamAdapterService_decorators = [Injectable({
|
|
1076
|
+
token: StreamAdapterToken
|
|
1077
|
+
})];
|
|
1078
|
+
var StreamAdapterService = class {
|
|
1079
|
+
hasSchema(handlerMetadata) {
|
|
1080
|
+
const config = handlerMetadata.config;
|
|
1081
|
+
return !!config.requestSchema || !!config.querySchema;
|
|
1082
|
+
}
|
|
1083
|
+
prepareArguments(handlerMetadata) {
|
|
1084
|
+
const config = handlerMetadata.config;
|
|
1085
|
+
const getters = [];
|
|
1086
|
+
if (config.querySchema) {
|
|
1087
|
+
getters.push((target, request) => {
|
|
1088
|
+
target.params = request.query;
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
1091
|
+
if (config.requestSchema) {
|
|
1092
|
+
getters.push((target, request) => {
|
|
1093
|
+
target.data = request.body;
|
|
1094
|
+
});
|
|
1095
|
+
}
|
|
1096
|
+
if (config.url.includes("$")) {
|
|
1097
|
+
getters.push((target, request) => {
|
|
1098
|
+
target.urlParams = request.params;
|
|
1099
|
+
});
|
|
1100
|
+
}
|
|
1101
|
+
return getters;
|
|
1102
|
+
}
|
|
1103
|
+
provideHandler(controller, executionContext, handlerMetadata) {
|
|
1104
|
+
const getters = this.prepareArguments(handlerMetadata);
|
|
1105
|
+
const formatArguments = async (request) => {
|
|
1106
|
+
const argument = {};
|
|
1107
|
+
const promises = [];
|
|
1108
|
+
for (const getter of getters) {
|
|
1109
|
+
const res = getter(argument, request);
|
|
1110
|
+
if (res instanceof Promise) {
|
|
1111
|
+
promises.push(res);
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
await Promise.all(promises);
|
|
1115
|
+
return argument;
|
|
1116
|
+
};
|
|
1117
|
+
return async function(request, reply) {
|
|
1118
|
+
const controllerInstance = await inject(controller);
|
|
1119
|
+
const argument = await formatArguments(request);
|
|
1120
|
+
await controllerInstance[handlerMetadata.classMethod](argument, reply);
|
|
1121
|
+
};
|
|
1122
|
+
}
|
|
1123
|
+
provideSchema(handlerMetadata) {
|
|
1124
|
+
const schema = {};
|
|
1125
|
+
const { querySchema, requestSchema } = handlerMetadata.config;
|
|
1126
|
+
if (querySchema) {
|
|
1127
|
+
schema.querystring = querySchema;
|
|
1128
|
+
}
|
|
1129
|
+
if (requestSchema) {
|
|
1130
|
+
schema.body = requestSchema;
|
|
1131
|
+
}
|
|
1132
|
+
return schema;
|
|
1133
|
+
}
|
|
1134
|
+
};
|
|
1135
|
+
_init = __decoratorStart(null);
|
|
1136
|
+
StreamAdapterService = __decorateElement(_init, 0, "StreamAdapterService", _StreamAdapterService_decorators, StreamAdapterService);
|
|
1137
|
+
__runInitializers(_init, 1, StreamAdapterService);
|
|
1138
|
+
|
|
1139
|
+
// packages/core/src/adapters/endpoint-adapter.service.mts
|
|
1140
|
+
var EndpointAdapterToken = InjectionToken.create(
|
|
1141
|
+
Symbol.for("EndpointAdapterService")
|
|
1142
|
+
);
|
|
1143
|
+
var _EndpointAdapterService_decorators, _init2, _a;
|
|
1144
|
+
_EndpointAdapterService_decorators = [Injectable({
|
|
1145
|
+
token: EndpointAdapterToken
|
|
1146
|
+
})];
|
|
1147
|
+
var EndpointAdapterService = class extends (_a = StreamAdapterService) {
|
|
1148
|
+
hasSchema(handlerMetadata) {
|
|
1149
|
+
const config = handlerMetadata.config;
|
|
1150
|
+
return super.hasSchema(handlerMetadata) || !!config.responseSchema;
|
|
1151
|
+
}
|
|
1152
|
+
provideSchema(handlerMetadata) {
|
|
1153
|
+
const config = handlerMetadata.config;
|
|
1154
|
+
const schema = super.provideSchema(handlerMetadata);
|
|
1155
|
+
if (config.responseSchema) {
|
|
1156
|
+
schema.response = {
|
|
1157
|
+
200: config.responseSchema
|
|
1158
|
+
};
|
|
1159
|
+
}
|
|
1160
|
+
return schema;
|
|
1161
|
+
}
|
|
1162
|
+
provideHandler(controller, executionContext, handlerMetadata) {
|
|
1163
|
+
const getters = this.prepareArguments(handlerMetadata);
|
|
1164
|
+
const formatArguments = async (request) => {
|
|
1165
|
+
const argument = {};
|
|
1166
|
+
const promises = [];
|
|
1167
|
+
for (const getter of getters) {
|
|
1168
|
+
const res = getter(argument, request);
|
|
1169
|
+
if (res instanceof Promise) {
|
|
1170
|
+
promises.push(res);
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
await Promise.all(promises);
|
|
1174
|
+
return argument;
|
|
1175
|
+
};
|
|
1176
|
+
return async function(request, reply) {
|
|
1177
|
+
const controllerInstance = await inject(controller);
|
|
1178
|
+
const argument = await formatArguments(request);
|
|
1179
|
+
const result = await controllerInstance[handlerMetadata.classMethod](argument);
|
|
1180
|
+
reply.status(handlerMetadata.successStatusCode).headers(handlerMetadata.headers).send(result);
|
|
1181
|
+
};
|
|
1182
|
+
}
|
|
1183
|
+
};
|
|
1184
|
+
_init2 = __decoratorStart(_a);
|
|
1185
|
+
EndpointAdapterService = __decorateElement(_init2, 0, "EndpointAdapterService", _EndpointAdapterService_decorators, EndpointAdapterService);
|
|
1186
|
+
__runInitializers(_init2, 1, EndpointAdapterService);
|
|
1187
|
+
|
|
1188
|
+
// packages/core/src/adapters/multipart-adapter.service.mts
|
|
1189
|
+
var import_zod2 = require("zod");
|
|
1190
|
+
var MultipartAdapterToken = InjectionToken.create(
|
|
1191
|
+
Symbol.for("MultipartAdapterService")
|
|
1192
|
+
);
|
|
1193
|
+
var _MultipartAdapterService_decorators, _init3, _a2;
|
|
1194
|
+
_MultipartAdapterService_decorators = [Injectable({
|
|
1195
|
+
token: MultipartAdapterToken
|
|
1196
|
+
})];
|
|
1197
|
+
var MultipartAdapterService = class extends (_a2 = EndpointAdapterService) {
|
|
1198
|
+
prepareArguments(handlerMetadata) {
|
|
1199
|
+
const config = handlerMetadata.config;
|
|
1200
|
+
const getters = [];
|
|
1201
|
+
if (config.querySchema) {
|
|
1202
|
+
getters.push((target, request) => {
|
|
1203
|
+
target.params = request.query;
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
if (config.url.includes("$")) {
|
|
1207
|
+
getters.push((target, request) => {
|
|
1208
|
+
target.urlParams = request.params;
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1211
|
+
const requestSchema = config.requestSchema;
|
|
1212
|
+
const shape = requestSchema._def.shape();
|
|
1213
|
+
const structure = this.analyzeSchema(shape);
|
|
1214
|
+
getters.push(async (target, request) => {
|
|
1215
|
+
const req = {};
|
|
1216
|
+
for await (const part of request.parts()) {
|
|
1217
|
+
await this.populateRequest(structure, part, req);
|
|
1218
|
+
}
|
|
1219
|
+
target.data = requestSchema.parse(req);
|
|
1220
|
+
});
|
|
1221
|
+
return getters;
|
|
1222
|
+
}
|
|
1223
|
+
async populateRequest(structure, part, req) {
|
|
1224
|
+
const { isArray, isObject: isObject2 } = structure[part.fieldname] ?? {};
|
|
1225
|
+
if (isArray && !req[part.fieldname]) {
|
|
1226
|
+
req[part.fieldname] = [];
|
|
1227
|
+
}
|
|
1228
|
+
let value;
|
|
1229
|
+
if (part.type === "file") {
|
|
1230
|
+
value = new File([await part.toBuffer()], part.filename, {
|
|
1231
|
+
type: part.mimetype
|
|
1232
|
+
});
|
|
1233
|
+
} else {
|
|
1234
|
+
value = part.value;
|
|
1235
|
+
if (isObject2 && typeof value === "string") {
|
|
1236
|
+
value = JSON.parse(value);
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
if (isArray) {
|
|
1240
|
+
req[part.fieldname].push(value);
|
|
1241
|
+
} else {
|
|
1242
|
+
req[part.fieldname] = value;
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
analyzeSchema(shape) {
|
|
1246
|
+
return Object.keys(shape).reduce(
|
|
1247
|
+
(target, key) => {
|
|
1248
|
+
let schema = shape[key];
|
|
1249
|
+
const isOptional = schema instanceof import_zod2.ZodOptional;
|
|
1250
|
+
if (isOptional) {
|
|
1251
|
+
schema = schema.unwrap();
|
|
1252
|
+
}
|
|
1253
|
+
const isArray = schema instanceof import_zod2.ZodArray;
|
|
1254
|
+
if (isArray) {
|
|
1255
|
+
schema = schema.element;
|
|
1256
|
+
}
|
|
1257
|
+
const isObject2 = schema instanceof import_zod2.ZodObject;
|
|
1258
|
+
return {
|
|
1259
|
+
...target,
|
|
1260
|
+
[key]: {
|
|
1261
|
+
isArray,
|
|
1262
|
+
isOptional,
|
|
1263
|
+
isObject: isObject2
|
|
1264
|
+
}
|
|
1265
|
+
};
|
|
1266
|
+
},
|
|
1267
|
+
{}
|
|
1268
|
+
);
|
|
1269
|
+
}
|
|
1270
|
+
provideSchema(handlerMetadata) {
|
|
1271
|
+
const schema = {};
|
|
1272
|
+
const { querySchema, responseSchema } = handlerMetadata.config;
|
|
1273
|
+
if (querySchema) {
|
|
1274
|
+
schema.querystring = querySchema;
|
|
1275
|
+
}
|
|
1276
|
+
if (responseSchema) {
|
|
1277
|
+
schema.response = {
|
|
1278
|
+
200: responseSchema
|
|
1279
|
+
};
|
|
1280
|
+
}
|
|
1281
|
+
return schema;
|
|
1282
|
+
}
|
|
1283
|
+
};
|
|
1284
|
+
_init3 = __decoratorStart(_a2);
|
|
1285
|
+
MultipartAdapterService = __decorateElement(_init3, 0, "MultipartAdapterService", _MultipartAdapterService_decorators, MultipartAdapterService);
|
|
1286
|
+
__runInitializers(_init3, 1, MultipartAdapterService);
|
|
1287
|
+
|
|
1288
|
+
// packages/core/src/config/utils/helpers.mts
|
|
1289
|
+
var import_node_process = require("process");
|
|
1290
|
+
function envInt(key, defaultValue) {
|
|
1291
|
+
const envKey = import_node_process.env[key] || process.env[key];
|
|
1292
|
+
return envKey ? parseInt(envKey, 10) : defaultValue;
|
|
1293
|
+
}
|
|
1294
|
+
function envString(key, defaultValue) {
|
|
1295
|
+
return import_node_process.env[key] || process.env[key] || defaultValue || void 0;
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
// packages/core/src/config/config.provider.mts
|
|
1299
|
+
var import_zod4 = require("zod");
|
|
1300
|
+
|
|
1301
|
+
// packages/core/src/logger/utils/cli-colors.util.mts
|
|
1302
|
+
var isColorAllowed = () => !process.env.NO_COLOR;
|
|
1303
|
+
var colorIfAllowed = (colorFn) => (text) => isColorAllowed() ? colorFn(text) : text;
|
|
1304
|
+
var clc = {
|
|
1305
|
+
bold: colorIfAllowed((text) => `\x1B[1m${text}\x1B[0m`),
|
|
1306
|
+
green: colorIfAllowed((text) => `\x1B[32m${text}\x1B[39m`),
|
|
1307
|
+
yellow: colorIfAllowed((text) => `\x1B[33m${text}\x1B[39m`),
|
|
1308
|
+
red: colorIfAllowed((text) => `\x1B[31m${text}\x1B[39m`),
|
|
1309
|
+
magentaBright: colorIfAllowed((text) => `\x1B[95m${text}\x1B[39m`),
|
|
1310
|
+
cyanBright: colorIfAllowed((text) => `\x1B[96m${text}\x1B[39m`)
|
|
1311
|
+
};
|
|
1312
|
+
var yellow = colorIfAllowed(
|
|
1313
|
+
(text) => `\x1B[38;5;3m${text}\x1B[39m`
|
|
1314
|
+
);
|
|
1315
|
+
|
|
1316
|
+
// packages/core/src/logger/log-levels.mts
|
|
1317
|
+
var LOG_LEVELS = [
|
|
1318
|
+
"verbose",
|
|
1319
|
+
"debug",
|
|
1320
|
+
"log",
|
|
1321
|
+
"warn",
|
|
1322
|
+
"error",
|
|
1323
|
+
"fatal"
|
|
1324
|
+
];
|
|
1325
|
+
|
|
1326
|
+
// packages/core/src/logger/utils/is-log-level.util.mts
|
|
1327
|
+
function isLogLevel(maybeLogLevel) {
|
|
1328
|
+
return LOG_LEVELS.includes(maybeLogLevel);
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
// packages/core/src/logger/utils/filter-log-levelts.util.mts
|
|
1332
|
+
function filterLogLevels(parseableString = "") {
|
|
1333
|
+
const sanitizedString = parseableString.replaceAll(" ", "").toLowerCase();
|
|
1334
|
+
if (sanitizedString[0] === ">") {
|
|
1335
|
+
const orEqual = sanitizedString[1] === "=";
|
|
1336
|
+
const logLevelIndex = LOG_LEVELS.indexOf(
|
|
1337
|
+
sanitizedString.substring(orEqual ? 2 : 1)
|
|
1338
|
+
);
|
|
1339
|
+
if (logLevelIndex === -1) {
|
|
1340
|
+
throw new Error(`parse error (unknown log level): ${sanitizedString}`);
|
|
1341
|
+
}
|
|
1342
|
+
return LOG_LEVELS.slice(orEqual ? logLevelIndex : logLevelIndex + 1);
|
|
1343
|
+
} else if (sanitizedString.includes(",")) {
|
|
1344
|
+
return sanitizedString.split(",").filter(isLogLevel);
|
|
1345
|
+
}
|
|
1346
|
+
return isLogLevel(sanitizedString) ? [sanitizedString] : LOG_LEVELS;
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
// packages/core/src/logger/utils/is-log-level-enabled.mts
|
|
1350
|
+
var LOG_LEVEL_VALUES = {
|
|
1351
|
+
verbose: 0,
|
|
1352
|
+
debug: 1,
|
|
1353
|
+
log: 2,
|
|
1354
|
+
warn: 3,
|
|
1355
|
+
error: 4,
|
|
1356
|
+
fatal: 5
|
|
1357
|
+
};
|
|
1358
|
+
function isLogLevelEnabled(targetLevel, logLevels) {
|
|
1359
|
+
var _a3;
|
|
1360
|
+
if (!logLevels || Array.isArray(logLevels) && (logLevels == null ? void 0 : logLevels.length) === 0) {
|
|
1361
|
+
return false;
|
|
1362
|
+
}
|
|
1363
|
+
if (logLevels.includes(targetLevel)) {
|
|
1364
|
+
return true;
|
|
1365
|
+
}
|
|
1366
|
+
const highestLogLevelValue = (_a3 = logLevels.map((level) => LOG_LEVEL_VALUES[level]).sort((a, b) => b - a)) == null ? void 0 : _a3[0];
|
|
1367
|
+
const targetLevelValue = LOG_LEVEL_VALUES[targetLevel];
|
|
1368
|
+
return targetLevelValue >= highestLogLevelValue;
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
// packages/core/src/logger/utils/shared.utils.mts
|
|
1372
|
+
var isUndefined = (obj) => typeof obj === "undefined";
|
|
1373
|
+
var isObject = (fn) => !isNil(fn) && typeof fn === "object";
|
|
1374
|
+
var isPlainObject = (fn) => {
|
|
1375
|
+
if (!isObject(fn)) {
|
|
1376
|
+
return false;
|
|
1377
|
+
}
|
|
1378
|
+
const proto = Object.getPrototypeOf(fn);
|
|
1379
|
+
if (proto === null) {
|
|
1380
|
+
return true;
|
|
1381
|
+
}
|
|
1382
|
+
const ctor = Object.prototype.hasOwnProperty.call(proto, "constructor") && proto.constructor;
|
|
1383
|
+
return typeof ctor === "function" && ctor instanceof ctor && Function.prototype.toString.call(ctor) === Function.prototype.toString.call(Object);
|
|
1384
|
+
};
|
|
1385
|
+
var addLeadingSlash = (path) => path && typeof path === "string" ? path.charAt(0) !== "/" && path.substring(0, 2) !== "{/" ? "/" + path : path : "";
|
|
1386
|
+
var normalizePath = (path) => path ? path.startsWith("/") ? ("/" + path.replace(/\/+$/, "")).replace(/\/+/g, "/") : "/" + path.replace(/\/+$/, "") : "/";
|
|
1387
|
+
var stripEndSlash = (path) => path[path.length - 1] === "/" ? path.slice(0, path.length - 1) : path;
|
|
1388
|
+
var isFunction = (val) => typeof val === "function";
|
|
1389
|
+
var isString = (val) => typeof val === "string";
|
|
1390
|
+
var isNumber = (val) => typeof val === "number";
|
|
1391
|
+
var isConstructor = (val) => val === "constructor";
|
|
1392
|
+
var isNil = (val) => isUndefined(val) || val === null;
|
|
1393
|
+
var isEmpty = (array) => !(array && array.length > 0);
|
|
1394
|
+
var isSymbol = (val) => typeof val === "symbol";
|
|
1395
|
+
|
|
1396
|
+
// packages/core/src/logger/console-logger.service.mts
|
|
1397
|
+
var import_util = require("util");
|
|
1398
|
+
|
|
1176
1399
|
// packages/core/src/tokens/application.token.mts
|
|
1177
1400
|
var ApplicationInjectionToken = "ApplicationInjectionToken";
|
|
1178
1401
|
var Application = InjectionToken.create(
|
|
1179
1402
|
ApplicationInjectionToken
|
|
1180
1403
|
);
|
|
1181
1404
|
|
|
1182
|
-
// packages/core/src/
|
|
1183
|
-
var import_common3 = require("@navios/common");
|
|
1184
|
-
var import_zod2 = require("zod");
|
|
1185
|
-
|
|
1186
|
-
// packages/core/src/metadata/endpoint.metadata.mts
|
|
1405
|
+
// packages/core/src/metadata/handler.metadata.mts
|
|
1187
1406
|
var EndpointMetadataKey = Symbol("EndpointMetadataKey");
|
|
1188
|
-
var EndpointType = /* @__PURE__ */ ((EndpointType2) => {
|
|
1189
|
-
EndpointType2["Unknown"] = "unknown";
|
|
1190
|
-
EndpointType2["Endpoint"] = "endpoint";
|
|
1191
|
-
EndpointType2["Stream"] = "stream";
|
|
1192
|
-
EndpointType2["Multipart"] = "multipart";
|
|
1193
|
-
EndpointType2["Handler"] = "handler";
|
|
1194
|
-
return EndpointType2;
|
|
1195
|
-
})(EndpointType || {});
|
|
1196
1407
|
function getAllEndpointMetadata(context) {
|
|
1197
1408
|
if (context.metadata) {
|
|
1198
1409
|
const metadata = context.metadata[EndpointMetadataKey];
|
|
@@ -1219,9 +1430,10 @@ function getEndpointMetadata(target, context) {
|
|
|
1219
1430
|
classMethod: target.name,
|
|
1220
1431
|
url: "",
|
|
1221
1432
|
successStatusCode: 200,
|
|
1433
|
+
adapterToken: null,
|
|
1222
1434
|
headers: {},
|
|
1223
|
-
type: "unknown" /* Unknown */,
|
|
1224
1435
|
httpMethod: "GET",
|
|
1436
|
+
// @ts-expect-error We are using a generic type here
|
|
1225
1437
|
config: null,
|
|
1226
1438
|
guards: /* @__PURE__ */ new Set(),
|
|
1227
1439
|
customAttributes: /* @__PURE__ */ new Map()
|
|
@@ -1399,7 +1611,7 @@ var ConflictException = class extends HttpException {
|
|
|
1399
1611
|
};
|
|
1400
1612
|
|
|
1401
1613
|
// packages/core/src/services/guard-runner.service.mts
|
|
1402
|
-
var _GuardRunnerService_decorators,
|
|
1614
|
+
var _GuardRunnerService_decorators, _init4;
|
|
1403
1615
|
_GuardRunnerService_decorators = [Injectable()];
|
|
1404
1616
|
var GuardRunnerService = class {
|
|
1405
1617
|
async runGuards(allGuards, executionContext) {
|
|
@@ -1462,39 +1674,59 @@ var GuardRunnerService = class {
|
|
|
1462
1674
|
return guards;
|
|
1463
1675
|
}
|
|
1464
1676
|
};
|
|
1465
|
-
|
|
1466
|
-
GuardRunnerService = __decorateElement(
|
|
1467
|
-
__runInitializers(
|
|
1677
|
+
_init4 = __decoratorStart(null);
|
|
1678
|
+
GuardRunnerService = __decorateElement(_init4, 0, "GuardRunnerService", _GuardRunnerService_decorators, GuardRunnerService);
|
|
1679
|
+
__runInitializers(_init4, 1, GuardRunnerService);
|
|
1468
1680
|
|
|
1469
1681
|
// packages/core/src/services/controller-adapter.service.mts
|
|
1470
|
-
var _ControllerAdapterService_decorators,
|
|
1682
|
+
var _ControllerAdapterService_decorators, _init5;
|
|
1471
1683
|
_ControllerAdapterService_decorators = [Injectable()];
|
|
1472
1684
|
var _ControllerAdapterService = class _ControllerAdapterService {
|
|
1473
1685
|
guardRunner = syncInject(GuardRunnerService);
|
|
1474
1686
|
logger = syncInject(Logger, {
|
|
1475
1687
|
context: _ControllerAdapterService.name
|
|
1476
1688
|
});
|
|
1477
|
-
setupController(controller, instance, moduleMetadata) {
|
|
1689
|
+
async setupController(controller, instance, moduleMetadata) {
|
|
1690
|
+
var _a3, _b;
|
|
1478
1691
|
const controllerMetadata = extractControllerMetadata(controller);
|
|
1479
1692
|
for (const endpoint of controllerMetadata.endpoints) {
|
|
1480
|
-
const { classMethod, url, httpMethod } = endpoint;
|
|
1481
|
-
if (!url) {
|
|
1693
|
+
const { classMethod, url, httpMethod, adapterToken } = endpoint;
|
|
1694
|
+
if (!url || !adapterToken) {
|
|
1482
1695
|
throw new Error(
|
|
1483
1696
|
`[Navios] Malformed Endpoint ${controller.name}:${classMethod}`
|
|
1484
1697
|
);
|
|
1485
1698
|
}
|
|
1699
|
+
const adapter = await inject(
|
|
1700
|
+
adapterToken
|
|
1701
|
+
);
|
|
1486
1702
|
const executionContext = new ExecutionContext(
|
|
1487
1703
|
moduleMetadata,
|
|
1488
1704
|
controllerMetadata,
|
|
1489
1705
|
endpoint
|
|
1490
1706
|
);
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1707
|
+
const hasSchema = ((_a3 = adapter.hasSchema) == null ? void 0 : _a3.call(adapter, endpoint)) ?? false;
|
|
1708
|
+
if (hasSchema) {
|
|
1709
|
+
instance.withTypeProvider().route({
|
|
1710
|
+
method: httpMethod,
|
|
1711
|
+
url: url.replaceAll("$", ":"),
|
|
1712
|
+
schema: ((_b = adapter.provideSchema) == null ? void 0 : _b.call(adapter, endpoint)) ?? {},
|
|
1713
|
+
preHandler: this.providePreHandler(executionContext),
|
|
1714
|
+
handler: this.wrapHandler(
|
|
1715
|
+
executionContext,
|
|
1716
|
+
adapter.provideHandler(controller, executionContext, endpoint)
|
|
1717
|
+
)
|
|
1718
|
+
});
|
|
1719
|
+
} else {
|
|
1720
|
+
instance.route({
|
|
1721
|
+
method: httpMethod,
|
|
1722
|
+
url: url.replaceAll("$", ":"),
|
|
1723
|
+
preHandler: this.providePreHandler(executionContext),
|
|
1724
|
+
handler: this.wrapHandler(
|
|
1725
|
+
executionContext,
|
|
1726
|
+
adapter.provideHandler(controller, executionContext, endpoint)
|
|
1727
|
+
)
|
|
1728
|
+
});
|
|
1729
|
+
}
|
|
1498
1730
|
this.logger.debug(
|
|
1499
1731
|
`Registered ${httpMethod} ${url} for ${controller.name}:${classMethod}`
|
|
1500
1732
|
);
|
|
@@ -1502,217 +1734,49 @@ var _ControllerAdapterService = class _ControllerAdapterService {
|
|
|
1502
1734
|
}
|
|
1503
1735
|
providePreHandler(executionContext) {
|
|
1504
1736
|
const guards = this.guardRunner.makeContext(executionContext);
|
|
1505
|
-
return guards.size > 0 ?
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
ExecutionContextToken,
|
|
1510
|
-
executionContext
|
|
1511
|
-
);
|
|
1512
|
-
executionContext.provideRequest(request);
|
|
1513
|
-
executionContext.provideReply(reply);
|
|
1514
|
-
let canActivate = true;
|
|
1515
|
-
try {
|
|
1737
|
+
return guards.size > 0 ? this.wrapHandler(
|
|
1738
|
+
executionContext,
|
|
1739
|
+
async (request, reply) => {
|
|
1740
|
+
let canActivate = true;
|
|
1516
1741
|
canActivate = await this.guardRunner.runGuards(
|
|
1517
1742
|
guards,
|
|
1518
1743
|
executionContext
|
|
1519
1744
|
);
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
getServiceLocator().removeInstance(Reply);
|
|
1523
|
-
getServiceLocator().removeInstance(ExecutionContextToken);
|
|
1524
|
-
}
|
|
1525
|
-
if (!canActivate) {
|
|
1526
|
-
return reply;
|
|
1527
|
-
}
|
|
1528
|
-
} : void 0;
|
|
1529
|
-
}
|
|
1530
|
-
provideSchemaForConfig(endpointMetadata) {
|
|
1531
|
-
if (!endpointMetadata.config) {
|
|
1532
|
-
this.logger.warn(`No config found for endpoint ${endpointMetadata.url}`);
|
|
1533
|
-
return {};
|
|
1534
|
-
}
|
|
1535
|
-
const { querySchema, requestSchema, responseSchema } = endpointMetadata.config;
|
|
1536
|
-
const schema = {};
|
|
1537
|
-
if (querySchema) {
|
|
1538
|
-
schema.querystring = querySchema;
|
|
1539
|
-
}
|
|
1540
|
-
if (requestSchema && endpointMetadata.type !== "multipart" /* Multipart */) {
|
|
1541
|
-
schema.body = requestSchema;
|
|
1542
|
-
}
|
|
1543
|
-
if (responseSchema) {
|
|
1544
|
-
schema.response = {
|
|
1545
|
-
200: responseSchema
|
|
1546
|
-
};
|
|
1547
|
-
}
|
|
1548
|
-
return schema;
|
|
1549
|
-
}
|
|
1550
|
-
provideHandler(controller, executionContext, endpointMetadata) {
|
|
1551
|
-
switch (endpointMetadata.type) {
|
|
1552
|
-
case "unknown" /* Unknown */:
|
|
1553
|
-
this.logger.error(
|
|
1554
|
-
`Unknown endpoint type ${endpointMetadata.type} for ${controller.name}:${endpointMetadata.classMethod}`
|
|
1555
|
-
);
|
|
1556
|
-
throw new import_common3.NaviosException("Unknown endpoint type");
|
|
1557
|
-
case "endpoint" /* Endpoint */:
|
|
1558
|
-
return this.provideHandlerForConfig(
|
|
1559
|
-
controller,
|
|
1560
|
-
executionContext,
|
|
1561
|
-
endpointMetadata
|
|
1562
|
-
);
|
|
1563
|
-
case "stream" /* Stream */:
|
|
1564
|
-
return this.provideHandlerForStream(
|
|
1565
|
-
controller,
|
|
1566
|
-
executionContext,
|
|
1567
|
-
endpointMetadata
|
|
1568
|
-
);
|
|
1569
|
-
case "multipart" /* Multipart */:
|
|
1570
|
-
return this.provideHandlerForMultipart(
|
|
1571
|
-
controller,
|
|
1572
|
-
executionContext,
|
|
1573
|
-
endpointMetadata
|
|
1574
|
-
);
|
|
1575
|
-
case "handler" /* Handler */:
|
|
1576
|
-
this.logger.error("Not implemented yet");
|
|
1577
|
-
throw new import_common3.NaviosException("Not implemented yet");
|
|
1578
|
-
}
|
|
1579
|
-
}
|
|
1580
|
-
provideHandlerForConfig(controller, executionContext, endpointMetadata) {
|
|
1581
|
-
return async (request, reply) => {
|
|
1582
|
-
getServiceLocator().registerInstance(Request, request);
|
|
1583
|
-
getServiceLocator().registerInstance(Reply, reply);
|
|
1584
|
-
getServiceLocator().registerInstance(
|
|
1585
|
-
ExecutionContextToken,
|
|
1586
|
-
executionContext
|
|
1587
|
-
);
|
|
1588
|
-
executionContext.provideRequest(request);
|
|
1589
|
-
executionContext.provideReply(reply);
|
|
1590
|
-
const controllerInstance = await inject(controller);
|
|
1591
|
-
try {
|
|
1592
|
-
const { query, params, body } = request;
|
|
1593
|
-
const argument = {};
|
|
1594
|
-
if (query && Object.keys(query).length > 0) {
|
|
1595
|
-
argument.params = query;
|
|
1596
|
-
}
|
|
1597
|
-
if (params && Object.keys(params).length > 0) {
|
|
1598
|
-
argument.urlParams = params;
|
|
1599
|
-
}
|
|
1600
|
-
if (body) {
|
|
1601
|
-
argument.data = body;
|
|
1602
|
-
}
|
|
1603
|
-
const result = await controllerInstance[endpointMetadata.classMethod](argument);
|
|
1604
|
-
reply.status(endpointMetadata.successStatusCode).headers(endpointMetadata.headers).send(result);
|
|
1605
|
-
} finally {
|
|
1606
|
-
getServiceLocator().removeInstance(Request);
|
|
1607
|
-
getServiceLocator().removeInstance(Reply);
|
|
1608
|
-
getServiceLocator().removeInstance(ExecutionContextToken);
|
|
1609
|
-
}
|
|
1610
|
-
};
|
|
1611
|
-
}
|
|
1612
|
-
provideHandlerForStream(controller, executionContext, endpointMetadata) {
|
|
1613
|
-
return async (request, reply) => {
|
|
1614
|
-
getServiceLocator().registerInstance(Request, request);
|
|
1615
|
-
getServiceLocator().registerInstance(Reply, reply);
|
|
1616
|
-
getServiceLocator().registerInstance(
|
|
1617
|
-
ExecutionContextToken,
|
|
1618
|
-
executionContext
|
|
1619
|
-
);
|
|
1620
|
-
executionContext.provideRequest(request);
|
|
1621
|
-
executionContext.provideReply(reply);
|
|
1622
|
-
const controllerInstance = await inject(controller);
|
|
1623
|
-
try {
|
|
1624
|
-
const { query, params, body } = request;
|
|
1625
|
-
const argument = {};
|
|
1626
|
-
if (query && Object.keys(query).length > 0) {
|
|
1627
|
-
argument.params = query;
|
|
1628
|
-
}
|
|
1629
|
-
if (params && Object.keys(params).length > 0) {
|
|
1630
|
-
argument.urlParams = params;
|
|
1631
|
-
}
|
|
1632
|
-
if (body) {
|
|
1633
|
-
argument.data = body;
|
|
1745
|
+
if (!canActivate) {
|
|
1746
|
+
return reply;
|
|
1634
1747
|
}
|
|
1635
|
-
await controllerInstance[endpointMetadata.classMethod](argument, reply);
|
|
1636
|
-
} finally {
|
|
1637
|
-
getServiceLocator().removeInstance(Request);
|
|
1638
|
-
getServiceLocator().removeInstance(Reply);
|
|
1639
|
-
getServiceLocator().removeInstance(ExecutionContextToken);
|
|
1640
1748
|
}
|
|
1641
|
-
|
|
1749
|
+
) : void 0;
|
|
1642
1750
|
}
|
|
1643
|
-
|
|
1644
|
-
const
|
|
1645
|
-
const requestSchema = config.requestSchema;
|
|
1646
|
-
const shape = requestSchema._def.shape();
|
|
1751
|
+
wrapHandler(executionContext, handler) {
|
|
1752
|
+
const locator = getServiceLocator();
|
|
1647
1753
|
return async (request, reply) => {
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
ExecutionContextToken,
|
|
1652
|
-
executionContext
|
|
1653
|
-
);
|
|
1754
|
+
locator.registerInstance(Request, request);
|
|
1755
|
+
locator.registerInstance(Reply, reply);
|
|
1756
|
+
locator.registerInstance(ExecutionContextToken, executionContext);
|
|
1654
1757
|
executionContext.provideRequest(request);
|
|
1655
1758
|
executionContext.provideReply(reply);
|
|
1656
|
-
const controllerInstance = await inject(controller);
|
|
1657
1759
|
try {
|
|
1658
|
-
|
|
1659
|
-
const { query, params } = request;
|
|
1660
|
-
const argument = {};
|
|
1661
|
-
if (query && Object.keys(query).length > 0) {
|
|
1662
|
-
argument.params = query;
|
|
1663
|
-
}
|
|
1664
|
-
if (params && Object.keys(params).length > 0) {
|
|
1665
|
-
argument.urlParams = params;
|
|
1666
|
-
}
|
|
1667
|
-
const req = {};
|
|
1668
|
-
for await (const part of parts) {
|
|
1669
|
-
if (!shape[part.fieldname]) {
|
|
1670
|
-
throw new import_common3.NaviosException(
|
|
1671
|
-
`Invalid field name ${part.fieldname} for multipart request`
|
|
1672
|
-
);
|
|
1673
|
-
}
|
|
1674
|
-
const schema = shape[part.fieldname];
|
|
1675
|
-
if (part.type === "file") {
|
|
1676
|
-
const file = new File([await part.toBuffer()], part.filename, {
|
|
1677
|
-
type: part.mimetype
|
|
1678
|
-
});
|
|
1679
|
-
if (schema instanceof import_zod2.ZodArray) {
|
|
1680
|
-
if (!req[part.fieldname]) {
|
|
1681
|
-
req[part.fieldname] = [];
|
|
1682
|
-
}
|
|
1683
|
-
req[part.fieldname].push(file);
|
|
1684
|
-
} else {
|
|
1685
|
-
req[part.fieldname] = file;
|
|
1686
|
-
}
|
|
1687
|
-
} else {
|
|
1688
|
-
if (schema instanceof import_zod2.ZodArray) {
|
|
1689
|
-
if (!req[part.fieldname]) {
|
|
1690
|
-
req[part.fieldname] = [];
|
|
1691
|
-
}
|
|
1692
|
-
req[part.fieldname].push(part.value);
|
|
1693
|
-
} else {
|
|
1694
|
-
req[part.fieldname] = part.value;
|
|
1695
|
-
}
|
|
1696
|
-
}
|
|
1697
|
-
}
|
|
1698
|
-
argument.data = requestSchema.parse(req);
|
|
1699
|
-
const result = await controllerInstance[endpointMetadata.classMethod](argument);
|
|
1700
|
-
reply.status(endpointMetadata.successStatusCode).headers(endpointMetadata.headers).send(result);
|
|
1760
|
+
return await handler(request, reply);
|
|
1701
1761
|
} finally {
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1762
|
+
Promise.all([
|
|
1763
|
+
locator.removeInstance(Request),
|
|
1764
|
+
locator.removeInstance(Reply),
|
|
1765
|
+
locator.removeInstance(ExecutionContextToken)
|
|
1766
|
+
]).catch((err) => {
|
|
1767
|
+
this.logger.warn(`Error removing instances: ${err}`);
|
|
1768
|
+
});
|
|
1705
1769
|
}
|
|
1706
1770
|
};
|
|
1707
1771
|
}
|
|
1708
1772
|
};
|
|
1709
|
-
|
|
1710
|
-
_ControllerAdapterService = __decorateElement(
|
|
1711
|
-
__runInitializers(
|
|
1773
|
+
_init5 = __decoratorStart(null);
|
|
1774
|
+
_ControllerAdapterService = __decorateElement(_init5, 0, "ControllerAdapterService", _ControllerAdapterService_decorators, _ControllerAdapterService);
|
|
1775
|
+
__runInitializers(_init5, 1, _ControllerAdapterService);
|
|
1712
1776
|
var ControllerAdapterService = _ControllerAdapterService;
|
|
1713
1777
|
|
|
1714
1778
|
// packages/core/src/services/module-loader.service.mts
|
|
1715
|
-
var _ModuleLoaderService_decorators,
|
|
1779
|
+
var _ModuleLoaderService_decorators, _init6;
|
|
1716
1780
|
_ModuleLoaderService_decorators = [Injectable()];
|
|
1717
1781
|
var _ModuleLoaderService = class _ModuleLoaderService {
|
|
1718
1782
|
logger = syncInject(Logger, {
|
|
@@ -1774,9 +1838,9 @@ var _ModuleLoaderService = class _ModuleLoaderService {
|
|
|
1774
1838
|
this.initialized = false;
|
|
1775
1839
|
}
|
|
1776
1840
|
};
|
|
1777
|
-
|
|
1778
|
-
_ModuleLoaderService = __decorateElement(
|
|
1779
|
-
__runInitializers(
|
|
1841
|
+
_init6 = __decoratorStart(null);
|
|
1842
|
+
_ModuleLoaderService = __decorateElement(_init6, 0, "ModuleLoaderService", _ModuleLoaderService_decorators, _ModuleLoaderService);
|
|
1843
|
+
__runInitializers(_init6, 1, _ModuleLoaderService);
|
|
1780
1844
|
var ModuleLoaderService = _ModuleLoaderService;
|
|
1781
1845
|
|
|
1782
1846
|
// packages/core/src/tokens/execution-context.token.mts
|
|
@@ -1813,7 +1877,7 @@ var dateTimeFormatter = new Intl.DateTimeFormat(void 0, {
|
|
|
1813
1877
|
day: "2-digit",
|
|
1814
1878
|
month: "2-digit"
|
|
1815
1879
|
});
|
|
1816
|
-
var _ConsoleLogger_decorators,
|
|
1880
|
+
var _ConsoleLogger_decorators, _init7;
|
|
1817
1881
|
_ConsoleLogger_decorators = [Injectable()];
|
|
1818
1882
|
var _ConsoleLogger = class _ConsoleLogger {
|
|
1819
1883
|
/**
|
|
@@ -1949,8 +2013,8 @@ var _ConsoleLogger = class _ConsoleLogger {
|
|
|
1949
2013
|
this.context = this.originalContext;
|
|
1950
2014
|
}
|
|
1951
2015
|
isLevelEnabled(level) {
|
|
1952
|
-
var
|
|
1953
|
-
const logLevels = (
|
|
2016
|
+
var _a3;
|
|
2017
|
+
const logLevels = (_a3 = this.options) == null ? void 0 : _a3.logLevels;
|
|
1954
2018
|
return isLogLevelEnabled(level, logLevels);
|
|
1955
2019
|
}
|
|
1956
2020
|
getTimestamp() {
|
|
@@ -2061,8 +2125,8 @@ var _ConsoleLogger = class _ConsoleLogger {
|
|
|
2061
2125
|
`);
|
|
2062
2126
|
}
|
|
2063
2127
|
updateAndGetTimestampDiff() {
|
|
2064
|
-
var
|
|
2065
|
-
const includeTimestamp = _ConsoleLogger.lastTimestampAt && ((
|
|
2128
|
+
var _a3;
|
|
2129
|
+
const includeTimestamp = _ConsoleLogger.lastTimestampAt && ((_a3 = this.options) == null ? void 0 : _a3.timestamp);
|
|
2066
2130
|
const result = includeTimestamp ? this.formatTimestampDiff(Date.now() - _ConsoleLogger.lastTimestampAt) : "";
|
|
2067
2131
|
_ConsoleLogger.lastTimestampAt = Date.now();
|
|
2068
2132
|
return result;
|
|
@@ -2167,9 +2231,9 @@ var _ConsoleLogger = class _ConsoleLogger {
|
|
|
2167
2231
|
}
|
|
2168
2232
|
}
|
|
2169
2233
|
};
|
|
2170
|
-
|
|
2171
|
-
_ConsoleLogger = __decorateElement(
|
|
2172
|
-
__runInitializers(
|
|
2234
|
+
_init7 = __decoratorStart(null);
|
|
2235
|
+
_ConsoleLogger = __decorateElement(_init7, 0, "ConsoleLogger", _ConsoleLogger_decorators, _ConsoleLogger);
|
|
2236
|
+
__runInitializers(_init7, 1, _ConsoleLogger);
|
|
2173
2237
|
var ConsoleLogger = _ConsoleLogger;
|
|
2174
2238
|
|
|
2175
2239
|
// packages/core/src/logger/logger.factory.mts
|
|
@@ -2185,7 +2249,7 @@ var dateTimeFormatter2 = new Intl.DateTimeFormat(void 0, {
|
|
|
2185
2249
|
day: "2-digit",
|
|
2186
2250
|
month: "2-digit"
|
|
2187
2251
|
});
|
|
2188
|
-
var _LoggerInstance_decorators,
|
|
2252
|
+
var _LoggerInstance_decorators, _init8;
|
|
2189
2253
|
_LoggerInstance_decorators = [Injectable()];
|
|
2190
2254
|
var _LoggerInstance = class _LoggerInstance {
|
|
2191
2255
|
constructor(context, options = {}) {
|
|
@@ -2207,69 +2271,69 @@ var _LoggerInstance = class _LoggerInstance {
|
|
|
2207
2271
|
return _LoggerInstance.staticInstanceRef;
|
|
2208
2272
|
}
|
|
2209
2273
|
error(message, ...optionalParams) {
|
|
2210
|
-
var
|
|
2274
|
+
var _a3;
|
|
2211
2275
|
optionalParams = this.context ? (optionalParams.length ? optionalParams : [void 0]).concat(
|
|
2212
2276
|
this.context
|
|
2213
2277
|
) : optionalParams;
|
|
2214
|
-
(
|
|
2278
|
+
(_a3 = this.localInstance) == null ? void 0 : _a3.error(message, ...optionalParams);
|
|
2215
2279
|
}
|
|
2216
2280
|
log(message, ...optionalParams) {
|
|
2217
|
-
var
|
|
2281
|
+
var _a3;
|
|
2218
2282
|
optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
|
|
2219
|
-
(
|
|
2283
|
+
(_a3 = this.localInstance) == null ? void 0 : _a3.log(message, ...optionalParams);
|
|
2220
2284
|
}
|
|
2221
2285
|
warn(message, ...optionalParams) {
|
|
2222
|
-
var
|
|
2286
|
+
var _a3;
|
|
2223
2287
|
optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
|
|
2224
|
-
(
|
|
2288
|
+
(_a3 = this.localInstance) == null ? void 0 : _a3.warn(message, ...optionalParams);
|
|
2225
2289
|
}
|
|
2226
2290
|
debug(message, ...optionalParams) {
|
|
2227
|
-
var
|
|
2291
|
+
var _a3, _b;
|
|
2228
2292
|
optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
|
|
2229
|
-
(_b = (
|
|
2293
|
+
(_b = (_a3 = this.localInstance) == null ? void 0 : _a3.debug) == null ? void 0 : _b.call(_a3, message, ...optionalParams);
|
|
2230
2294
|
}
|
|
2231
2295
|
verbose(message, ...optionalParams) {
|
|
2232
|
-
var
|
|
2296
|
+
var _a3, _b;
|
|
2233
2297
|
optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
|
|
2234
|
-
(_b = (
|
|
2298
|
+
(_b = (_a3 = this.localInstance) == null ? void 0 : _a3.verbose) == null ? void 0 : _b.call(_a3, message, ...optionalParams);
|
|
2235
2299
|
}
|
|
2236
2300
|
fatal(message, ...optionalParams) {
|
|
2237
|
-
var
|
|
2301
|
+
var _a3, _b;
|
|
2238
2302
|
optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
|
|
2239
|
-
(_b = (
|
|
2303
|
+
(_b = (_a3 = this.localInstance) == null ? void 0 : _a3.fatal) == null ? void 0 : _b.call(_a3, message, ...optionalParams);
|
|
2240
2304
|
}
|
|
2241
2305
|
static error(message, ...optionalParams) {
|
|
2242
|
-
var
|
|
2243
|
-
(
|
|
2306
|
+
var _a3;
|
|
2307
|
+
(_a3 = this.staticInstanceRef) == null ? void 0 : _a3.error(message, ...optionalParams);
|
|
2244
2308
|
}
|
|
2245
2309
|
static log(message, ...optionalParams) {
|
|
2246
|
-
var
|
|
2247
|
-
(
|
|
2310
|
+
var _a3;
|
|
2311
|
+
(_a3 = this.staticInstanceRef) == null ? void 0 : _a3.log(message, ...optionalParams);
|
|
2248
2312
|
}
|
|
2249
2313
|
static warn(message, ...optionalParams) {
|
|
2250
|
-
var
|
|
2251
|
-
(
|
|
2314
|
+
var _a3;
|
|
2315
|
+
(_a3 = this.staticInstanceRef) == null ? void 0 : _a3.warn(message, ...optionalParams);
|
|
2252
2316
|
}
|
|
2253
2317
|
static debug(message, ...optionalParams) {
|
|
2254
|
-
var
|
|
2255
|
-
(_b = (
|
|
2318
|
+
var _a3, _b;
|
|
2319
|
+
(_b = (_a3 = this.staticInstanceRef) == null ? void 0 : _a3.debug) == null ? void 0 : _b.call(_a3, message, ...optionalParams);
|
|
2256
2320
|
}
|
|
2257
2321
|
static verbose(message, ...optionalParams) {
|
|
2258
|
-
var
|
|
2259
|
-
(_b = (
|
|
2322
|
+
var _a3, _b;
|
|
2323
|
+
(_b = (_a3 = this.staticInstanceRef) == null ? void 0 : _a3.verbose) == null ? void 0 : _b.call(_a3, message, ...optionalParams);
|
|
2260
2324
|
}
|
|
2261
2325
|
static fatal(message, ...optionalParams) {
|
|
2262
|
-
var
|
|
2263
|
-
(_b = (
|
|
2326
|
+
var _a3, _b;
|
|
2327
|
+
(_b = (_a3 = this.staticInstanceRef) == null ? void 0 : _a3.fatal) == null ? void 0 : _b.call(_a3, message, ...optionalParams);
|
|
2264
2328
|
}
|
|
2265
2329
|
static getTimestamp() {
|
|
2266
2330
|
return dateTimeFormatter2.format(Date.now());
|
|
2267
2331
|
}
|
|
2268
2332
|
static overrideLogger(logger) {
|
|
2269
|
-
var
|
|
2333
|
+
var _a3, _b;
|
|
2270
2334
|
if (Array.isArray(logger)) {
|
|
2271
2335
|
_LoggerInstance.logLevels = logger;
|
|
2272
|
-
return (_b = (
|
|
2336
|
+
return (_b = (_a3 = this.staticInstanceRef) == null ? void 0 : _a3.setLogLevels) == null ? void 0 : _b.call(_a3, logger);
|
|
2273
2337
|
}
|
|
2274
2338
|
if (isObject(logger)) {
|
|
2275
2339
|
this.staticInstanceRef = logger;
|
|
@@ -2282,20 +2346,20 @@ var _LoggerInstance = class _LoggerInstance {
|
|
|
2282
2346
|
return isLogLevelEnabled(level, logLevels);
|
|
2283
2347
|
}
|
|
2284
2348
|
registerLocalInstanceRef() {
|
|
2285
|
-
var
|
|
2349
|
+
var _a3;
|
|
2286
2350
|
if (this.localInstanceRef) {
|
|
2287
2351
|
return this.localInstanceRef;
|
|
2288
2352
|
}
|
|
2289
2353
|
this.localInstanceRef = new ConsoleLogger(this.context, {
|
|
2290
|
-
timestamp: (
|
|
2354
|
+
timestamp: (_a3 = this.options) == null ? void 0 : _a3.timestamp,
|
|
2291
2355
|
logLevels: _LoggerInstance.logLevels
|
|
2292
2356
|
});
|
|
2293
2357
|
return this.localInstanceRef;
|
|
2294
2358
|
}
|
|
2295
2359
|
};
|
|
2296
|
-
|
|
2297
|
-
_LoggerInstance = __decorateElement(
|
|
2298
|
-
__runInitializers(
|
|
2360
|
+
_init8 = __decoratorStart(null);
|
|
2361
|
+
_LoggerInstance = __decorateElement(_init8, 0, "LoggerInstance", _LoggerInstance_decorators, _LoggerInstance);
|
|
2362
|
+
__runInitializers(_init8, 1, _LoggerInstance);
|
|
2299
2363
|
var LoggerInstance = _LoggerInstance;
|
|
2300
2364
|
|
|
2301
2365
|
// packages/core/src/logger/logger.factory.mts
|
|
@@ -2307,7 +2371,7 @@ var LoggerOptions = import_zod3.z.object({
|
|
|
2307
2371
|
}).optional()
|
|
2308
2372
|
}).optional();
|
|
2309
2373
|
var Logger = InjectionToken.create(LoggerInjectionToken, LoggerOptions);
|
|
2310
|
-
var _LoggerFactory_decorators,
|
|
2374
|
+
var _LoggerFactory_decorators, _init9;
|
|
2311
2375
|
_LoggerFactory_decorators = [Injectable({
|
|
2312
2376
|
type: "Factory" /* Factory */,
|
|
2313
2377
|
token: Logger
|
|
@@ -2317,9 +2381,9 @@ var LoggerFactory = class {
|
|
|
2317
2381
|
return new LoggerInstance(args == null ? void 0 : args.context, args == null ? void 0 : args.options);
|
|
2318
2382
|
}
|
|
2319
2383
|
};
|
|
2320
|
-
|
|
2321
|
-
LoggerFactory = __decorateElement(
|
|
2322
|
-
__runInitializers(
|
|
2384
|
+
_init9 = __decoratorStart(null);
|
|
2385
|
+
LoggerFactory = __decorateElement(_init9, 0, "LoggerFactory", _LoggerFactory_decorators, LoggerFactory);
|
|
2386
|
+
__runInitializers(_init9, 1, LoggerFactory);
|
|
2323
2387
|
|
|
2324
2388
|
// packages/core/src/logger/pino-wrapper.mts
|
|
2325
2389
|
var PinoWrapper = class _PinoWrapper {
|
|
@@ -2341,12 +2405,12 @@ var PinoWrapper = class _PinoWrapper {
|
|
|
2341
2405
|
info() {
|
|
2342
2406
|
}
|
|
2343
2407
|
debug(message, ...optionalParams) {
|
|
2344
|
-
var
|
|
2345
|
-
(_b = (
|
|
2408
|
+
var _a3, _b;
|
|
2409
|
+
(_b = (_a3 = this.logger).debug) == null ? void 0 : _b.call(_a3, message, ...optionalParams);
|
|
2346
2410
|
}
|
|
2347
2411
|
trace(message, ...optionalParams) {
|
|
2348
|
-
var
|
|
2349
|
-
(_b = (
|
|
2412
|
+
var _a3, _b;
|
|
2413
|
+
(_b = (_a3 = this.logger).verbose) == null ? void 0 : _b.call(_a3, message, ...optionalParams);
|
|
2350
2414
|
}
|
|
2351
2415
|
silent() {
|
|
2352
2416
|
}
|
|
@@ -2374,7 +2438,7 @@ var PinoWrapper = class _PinoWrapper {
|
|
|
2374
2438
|
};
|
|
2375
2439
|
|
|
2376
2440
|
// packages/core/src/config/config.service.mts
|
|
2377
|
-
var
|
|
2441
|
+
var import_common3 = require("@navios/common");
|
|
2378
2442
|
var ConfigServiceInstance = class {
|
|
2379
2443
|
constructor(config = {}, logger) {
|
|
2380
2444
|
this.config = config;
|
|
@@ -2384,7 +2448,7 @@ var ConfigServiceInstance = class {
|
|
|
2384
2448
|
return this.config;
|
|
2385
2449
|
}
|
|
2386
2450
|
get(key) {
|
|
2387
|
-
var
|
|
2451
|
+
var _a3, _b;
|
|
2388
2452
|
try {
|
|
2389
2453
|
const parts = String(key).split(".");
|
|
2390
2454
|
let value = this.config;
|
|
@@ -2396,8 +2460,8 @@ var ConfigServiceInstance = class {
|
|
|
2396
2460
|
}
|
|
2397
2461
|
return value ?? null;
|
|
2398
2462
|
} catch (error) {
|
|
2399
|
-
(_b = (
|
|
2400
|
-
|
|
2463
|
+
(_b = (_a3 = this.logger).debug) == null ? void 0 : _b.call(
|
|
2464
|
+
_a3,
|
|
2401
2465
|
`Failed to get config value for key ${String(key)}`,
|
|
2402
2466
|
error
|
|
2403
2467
|
);
|
|
@@ -2413,7 +2477,7 @@ var ConfigServiceInstance = class {
|
|
|
2413
2477
|
if (value === null) {
|
|
2414
2478
|
const message = errorMessage || `Configuration value for key "${String(key)}" is not defined`;
|
|
2415
2479
|
this.logger.error(message);
|
|
2416
|
-
throw new
|
|
2480
|
+
throw new import_common3.NaviosException(message);
|
|
2417
2481
|
}
|
|
2418
2482
|
return value;
|
|
2419
2483
|
}
|
|
@@ -2424,7 +2488,7 @@ var ConfigProviderOptions = import_zod4.z.object({
|
|
|
2424
2488
|
load: import_zod4.z.function()
|
|
2425
2489
|
});
|
|
2426
2490
|
var ConfigProvider = InjectionToken.create(ConfigServiceInstance, ConfigProviderOptions);
|
|
2427
|
-
var _ConfigProviderFactory_decorators,
|
|
2491
|
+
var _ConfigProviderFactory_decorators, _init10;
|
|
2428
2492
|
_ConfigProviderFactory_decorators = [Injectable({
|
|
2429
2493
|
token: ConfigProvider,
|
|
2430
2494
|
type: "Factory" /* Factory */
|
|
@@ -2438,16 +2502,19 @@ var ConfigProviderFactory = class {
|
|
|
2438
2502
|
const logger = this.logger;
|
|
2439
2503
|
try {
|
|
2440
2504
|
const config = await load();
|
|
2441
|
-
return new ConfigServiceInstance(
|
|
2505
|
+
return new ConfigServiceInstance(
|
|
2506
|
+
config,
|
|
2507
|
+
logger
|
|
2508
|
+
);
|
|
2442
2509
|
} catch (error) {
|
|
2443
2510
|
logger.error("Error loading config", error);
|
|
2444
2511
|
throw error;
|
|
2445
2512
|
}
|
|
2446
2513
|
}
|
|
2447
2514
|
};
|
|
2448
|
-
|
|
2449
|
-
ConfigProviderFactory = __decorateElement(
|
|
2450
|
-
__runInitializers(
|
|
2515
|
+
_init10 = __decoratorStart(null);
|
|
2516
|
+
ConfigProviderFactory = __decorateElement(_init10, 0, "ConfigProviderFactory", _ConfigProviderFactory_decorators, ConfigProviderFactory);
|
|
2517
|
+
__runInitializers(_init10, 1, ConfigProviderFactory);
|
|
2451
2518
|
function provideConfig(options) {
|
|
2452
2519
|
return InjectionToken.bound(ConfigProvider, options);
|
|
2453
2520
|
}
|
|
@@ -2471,7 +2538,6 @@ function Controller({ guards } = {}) {
|
|
|
2471
2538
|
}
|
|
2472
2539
|
return Injectable({
|
|
2473
2540
|
token,
|
|
2474
|
-
type: "Class" /* Class */,
|
|
2475
2541
|
scope: "Instance" /* Instance */
|
|
2476
2542
|
})(target, context);
|
|
2477
2543
|
};
|
|
@@ -2493,14 +2559,17 @@ function Endpoint(endpoint) {
|
|
|
2493
2559
|
}
|
|
2494
2560
|
const config = endpoint.config;
|
|
2495
2561
|
if (context.metadata) {
|
|
2496
|
-
let endpointMetadata = getEndpointMetadata(
|
|
2562
|
+
let endpointMetadata = getEndpointMetadata(
|
|
2563
|
+
target,
|
|
2564
|
+
context
|
|
2565
|
+
);
|
|
2497
2566
|
if (endpointMetadata.config && endpointMetadata.config.url) {
|
|
2498
2567
|
throw new Error(
|
|
2499
2568
|
`[Navios] Endpoint ${config.method} ${config.url} already exists. Please use a different method or url.`
|
|
2500
2569
|
);
|
|
2501
2570
|
}
|
|
2502
2571
|
endpointMetadata.config = config;
|
|
2503
|
-
endpointMetadata.
|
|
2572
|
+
endpointMetadata.adapterToken = EndpointAdapterToken;
|
|
2504
2573
|
endpointMetadata.classMethod = target.name;
|
|
2505
2574
|
endpointMetadata.httpMethod = config.method;
|
|
2506
2575
|
endpointMetadata.url = config.url;
|
|
@@ -2516,11 +2585,6 @@ function Header(name2, value) {
|
|
|
2516
2585
|
throw new Error("[Navios] Header decorator can only be used on methods.");
|
|
2517
2586
|
}
|
|
2518
2587
|
const metadata = getEndpointMetadata(target, context);
|
|
2519
|
-
if (metadata.type === "stream" /* Stream */) {
|
|
2520
|
-
throw new Error(
|
|
2521
|
-
"[Navios] HttpCode decorator cannot be used on stream endpoints."
|
|
2522
|
-
);
|
|
2523
|
-
}
|
|
2524
2588
|
metadata.headers[name2] = value;
|
|
2525
2589
|
return target;
|
|
2526
2590
|
};
|
|
@@ -2535,42 +2599,34 @@ function HttpCode(code) {
|
|
|
2535
2599
|
);
|
|
2536
2600
|
}
|
|
2537
2601
|
const metadata = getEndpointMetadata(target, context);
|
|
2538
|
-
if (metadata.type === "stream" /* Stream */) {
|
|
2539
|
-
throw new Error(
|
|
2540
|
-
"[Navios] HttpCode decorator cannot be used on stream endpoints."
|
|
2541
|
-
);
|
|
2542
|
-
}
|
|
2543
2602
|
metadata.successStatusCode = code;
|
|
2544
2603
|
return target;
|
|
2545
2604
|
};
|
|
2546
2605
|
}
|
|
2547
2606
|
|
|
2548
2607
|
// packages/core/src/decorators/module.decorator.mts
|
|
2549
|
-
function Module(
|
|
2608
|
+
function Module({ controllers = [], imports = [], guards = [] } = {
|
|
2609
|
+
controllers: [],
|
|
2610
|
+
imports: [],
|
|
2611
|
+
guards: []
|
|
2612
|
+
}) {
|
|
2550
2613
|
return (target, context) => {
|
|
2551
2614
|
if (context.kind !== "class") {
|
|
2552
2615
|
throw new Error("[Navios] @Module decorator can only be used on classes.");
|
|
2553
2616
|
}
|
|
2554
2617
|
const token = InjectionToken.create(target);
|
|
2555
2618
|
const moduleMetadata = getModuleMetadata(target, context);
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
moduleMetadata.controllers.add(controller);
|
|
2559
|
-
}
|
|
2619
|
+
for (const controller of controllers) {
|
|
2620
|
+
moduleMetadata.controllers.add(controller);
|
|
2560
2621
|
}
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
moduleMetadata.imports.add(importedModule);
|
|
2564
|
-
}
|
|
2622
|
+
for (const importedModule of imports) {
|
|
2623
|
+
moduleMetadata.imports.add(importedModule);
|
|
2565
2624
|
}
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
moduleMetadata.guards.add(guard);
|
|
2569
|
-
}
|
|
2625
|
+
for (const guard of Array.from(guards).reverse()) {
|
|
2626
|
+
moduleMetadata.guards.add(guard);
|
|
2570
2627
|
}
|
|
2571
2628
|
return Injectable({
|
|
2572
2629
|
token,
|
|
2573
|
-
type: "Class" /* Class */,
|
|
2574
2630
|
scope: "Singleton" /* Singleton */
|
|
2575
2631
|
})(target, context);
|
|
2576
2632
|
};
|
|
@@ -2592,14 +2648,17 @@ function Multipart(endpoint) {
|
|
|
2592
2648
|
}
|
|
2593
2649
|
const config = endpoint.config;
|
|
2594
2650
|
if (context.metadata) {
|
|
2595
|
-
let endpointMetadata = getEndpointMetadata(
|
|
2651
|
+
let endpointMetadata = getEndpointMetadata(
|
|
2652
|
+
target,
|
|
2653
|
+
context
|
|
2654
|
+
);
|
|
2596
2655
|
if (endpointMetadata.config && endpointMetadata.config.url) {
|
|
2597
2656
|
throw new Error(
|
|
2598
2657
|
`[Navios] Endpoint ${config.method} ${config.url} already exists. Please use a different method or url.`
|
|
2599
2658
|
);
|
|
2600
2659
|
}
|
|
2601
2660
|
endpointMetadata.config = config;
|
|
2602
|
-
endpointMetadata.
|
|
2661
|
+
endpointMetadata.adapterToken = MultipartAdapterToken;
|
|
2603
2662
|
endpointMetadata.classMethod = target.name;
|
|
2604
2663
|
endpointMetadata.httpMethod = config.method;
|
|
2605
2664
|
endpointMetadata.url = config.url;
|
|
@@ -2623,14 +2682,17 @@ function Stream(endpoint) {
|
|
|
2623
2682
|
}
|
|
2624
2683
|
const config = endpoint.config;
|
|
2625
2684
|
if (context.metadata) {
|
|
2626
|
-
let endpointMetadata = getEndpointMetadata(
|
|
2685
|
+
let endpointMetadata = getEndpointMetadata(
|
|
2686
|
+
target,
|
|
2687
|
+
context
|
|
2688
|
+
);
|
|
2627
2689
|
if (endpointMetadata.config && endpointMetadata.config.url) {
|
|
2628
2690
|
throw new Error(
|
|
2629
2691
|
`[Navios] Endpoint ${config.method} ${config.url} already exists. Please use a different method or url.`
|
|
2630
2692
|
);
|
|
2631
2693
|
}
|
|
2632
2694
|
endpointMetadata.config = config;
|
|
2633
|
-
endpointMetadata.
|
|
2695
|
+
endpointMetadata.adapterToken = StreamAdapterToken;
|
|
2634
2696
|
endpointMetadata.classMethod = target.name;
|
|
2635
2697
|
endpointMetadata.httpMethod = config.method;
|
|
2636
2698
|
endpointMetadata.url = config.url;
|
|
@@ -2726,7 +2788,7 @@ var import_cors = __toESM(require("@fastify/cors"), 1);
|
|
|
2726
2788
|
var import_multipart = __toESM(require("@fastify/multipart"), 1);
|
|
2727
2789
|
var import_fastify = require("fastify");
|
|
2728
2790
|
var import_fastify_type_provider_zod = require("fastify-type-provider-zod");
|
|
2729
|
-
var _NaviosApplication_decorators,
|
|
2791
|
+
var _NaviosApplication_decorators, _init11;
|
|
2730
2792
|
_NaviosApplication_decorators = [Injectable()];
|
|
2731
2793
|
var _NaviosApplication = class _NaviosApplication {
|
|
2732
2794
|
moduleLoader = syncInject(ModuleLoaderService);
|
|
@@ -2818,7 +2880,7 @@ var _NaviosApplication = class _NaviosApplication {
|
|
|
2818
2880
|
message: "Not Found",
|
|
2819
2881
|
error: "NotFound"
|
|
2820
2882
|
};
|
|
2821
|
-
this.logger.error(`Route not found: ${req.url}`);
|
|
2883
|
+
this.logger.error(`Route not found: [${req.method}] ${req.url}`);
|
|
2822
2884
|
return reply.status(404).send(response);
|
|
2823
2885
|
});
|
|
2824
2886
|
}
|
|
@@ -2839,15 +2901,14 @@ var _NaviosApplication = class _NaviosApplication {
|
|
|
2839
2901
|
}
|
|
2840
2902
|
promises.push(
|
|
2841
2903
|
this.server.register(
|
|
2842
|
-
(instance, opts
|
|
2904
|
+
async (instance, opts) => {
|
|
2843
2905
|
for (const controller of moduleMetadata.controllers) {
|
|
2844
|
-
this.controllerAdapter.setupController(
|
|
2906
|
+
await this.controllerAdapter.setupController(
|
|
2845
2907
|
controller,
|
|
2846
2908
|
instance,
|
|
2847
2909
|
moduleMetadata
|
|
2848
2910
|
);
|
|
2849
2911
|
}
|
|
2850
|
-
done();
|
|
2851
2912
|
},
|
|
2852
2913
|
{
|
|
2853
2914
|
prefix: this.globalPrefix ?? ""
|
|
@@ -2892,9 +2953,9 @@ var _NaviosApplication = class _NaviosApplication {
|
|
|
2892
2953
|
await this.dispose();
|
|
2893
2954
|
}
|
|
2894
2955
|
};
|
|
2895
|
-
|
|
2896
|
-
_NaviosApplication = __decorateElement(
|
|
2897
|
-
__runInitializers(
|
|
2956
|
+
_init11 = __decoratorStart(null);
|
|
2957
|
+
_NaviosApplication = __decorateElement(_init11, 0, "NaviosApplication", _NaviosApplication_decorators, _NaviosApplication);
|
|
2958
|
+
__runInitializers(_init11, 1, _NaviosApplication);
|
|
2898
2959
|
var NaviosApplication = _NaviosApplication;
|
|
2899
2960
|
|
|
2900
2961
|
// packages/core/src/navios.factory.mts
|
|
@@ -2931,8 +2992,9 @@ var NaviosFactory = class {
|
|
|
2931
2992
|
ControllerAdapterService,
|
|
2932
2993
|
ControllerMetadataKey,
|
|
2933
2994
|
Endpoint,
|
|
2995
|
+
EndpointAdapterService,
|
|
2996
|
+
EndpointAdapterToken,
|
|
2934
2997
|
EndpointMetadataKey,
|
|
2935
|
-
EndpointType,
|
|
2936
2998
|
ErrorsEnum,
|
|
2937
2999
|
EventEmitter,
|
|
2938
3000
|
ExecutionContext,
|
|
@@ -2965,6 +3027,8 @@ var NaviosFactory = class {
|
|
|
2965
3027
|
ModuleLoaderService,
|
|
2966
3028
|
ModuleMetadataKey,
|
|
2967
3029
|
Multipart,
|
|
3030
|
+
MultipartAdapterService,
|
|
3031
|
+
MultipartAdapterToken,
|
|
2968
3032
|
NaviosApplication,
|
|
2969
3033
|
NaviosFactory,
|
|
2970
3034
|
NotFoundException,
|
|
@@ -2977,6 +3041,8 @@ var NaviosFactory = class {
|
|
|
2977
3041
|
ServiceLocatorInstanceHolderStatus,
|
|
2978
3042
|
ServiceLocatorManager,
|
|
2979
3043
|
Stream,
|
|
3044
|
+
StreamAdapterService,
|
|
3045
|
+
StreamAdapterToken,
|
|
2980
3046
|
UnauthorizedException,
|
|
2981
3047
|
UnknownError,
|
|
2982
3048
|
UseGuards,
|