@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.
Files changed (34) hide show
  1. package/dist/_tsup-dts-rollup.d.mts +124 -49
  2. package/dist/_tsup-dts-rollup.d.ts +124 -49
  3. package/dist/index.d.mts +8 -2
  4. package/dist/index.d.ts +8 -2
  5. package/dist/index.js +537 -471
  6. package/dist/index.mjs +531 -470
  7. package/package.json +1 -1
  8. package/src/adapters/endpoint-adapter.service.mts +75 -0
  9. package/src/adapters/handler-adapter.interface.mts +21 -0
  10. package/src/adapters/index.mts +4 -0
  11. package/src/adapters/multipart-adapter.service.mts +130 -0
  12. package/src/adapters/stream-adapter.service.mts +95 -0
  13. package/src/attribute.factory.mts +13 -13
  14. package/src/config/config.provider.mts +8 -2
  15. package/src/decorators/controller.decorator.mts +0 -2
  16. package/src/decorators/endpoint.decorator.mts +7 -3
  17. package/src/decorators/header.decorator.mts +1 -6
  18. package/src/decorators/http-code.decorator.mts +1 -6
  19. package/src/decorators/module.decorator.mts +13 -15
  20. package/src/decorators/multipart.decorator.mts +7 -3
  21. package/src/decorators/stream.decorator.mts +7 -3
  22. package/src/index.mts +1 -0
  23. package/src/logger/logger.service.mts +0 -1
  24. package/src/metadata/controller.metadata.mts +3 -3
  25. package/src/metadata/{endpoint.metadata.mts → handler.metadata.mts} +17 -24
  26. package/src/metadata/index.mts +1 -1
  27. package/src/navios.application.mts +3 -4
  28. package/src/service-locator/__tests__/injection-token.spec.mts +10 -5
  29. package/src/service-locator/decorators/injectable.decorator.mts +53 -4
  30. package/src/service-locator/inject.mts +14 -0
  31. package/src/service-locator/interfaces/factory.interface.mts +9 -1
  32. package/src/service-locator/sync-injector.mts +14 -0
  33. package/src/services/controller-adapter.service.mts +59 -240
  34. 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 _a;
294
- (_a = this.logger) == null ? void 0 : _a.debug(`[ServiceLocatorEventBus]#on(): ns:${ns} event:${event}`);
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 _a2;
193
+ var _a4;
305
194
  nsEvents.get(event).delete(listener);
306
- if (((_a2 = nsEvents.get(event)) == null ? void 0 : _a2.size) === 0) {
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 _a, _b, _c;
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
- (_a = this.logger) == null ? void 0 : _a.debug(`[ServiceLocatorEventBus]#emit(): ${key}:${preEvent}`);
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 _a2;
328
- (_a2 = this.logger) == null ? void 0 : _a2.warn(
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 _a2;
340
- (_a2 = this.logger) == null ? void 0 : _a2.warn(
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 _a2;
357
- (_a2 = this.logger) == null ? void 0 : _a2.warn(
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 _a, _b, _c;
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
- (_a = this.logger) == null ? void 0 : _a.log(
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];
@@ -473,8 +362,8 @@ var ServiceLocator = class {
473
362
  return this.invalidate(instanceName);
474
363
  }
475
364
  registerAbstractFactory(token, factory, type = "Singleton" /* Singleton */) {
476
- var _a;
477
- (_a = this.logger) == null ? void 0 : _a.log(
365
+ var _a3;
366
+ (_a3 = this.logger) == null ? void 0 : _a3.log(
478
367
  `[ServiceLocator]#registerAbstractFactory(): Registering abstract factory for ${name}`
479
368
  );
480
369
  if (type === "Instance" /* Instance */) {
@@ -486,7 +375,7 @@ var ServiceLocator = class {
486
375
  }
487
376
  }
488
377
  resolveTokenArgs(token, args) {
489
- var _a, _b;
378
+ var _a3, _b;
490
379
  let realArgs = args;
491
380
  if (token instanceof BoundInjectionToken) {
492
381
  realArgs = token.value;
@@ -500,7 +389,7 @@ var ServiceLocator = class {
500
389
  if (!token.schema) {
501
390
  return [void 0, realArgs];
502
391
  }
503
- const validatedArgs = (_a = token.schema) == null ? void 0 : _a.safeParse(realArgs);
392
+ const validatedArgs = (_a3 = token.schema) == null ? void 0 : _a3.safeParse(realArgs);
504
393
  if (validatedArgs && !validatedArgs.success) {
505
394
  (_b = this.logger) == null ? void 0 : _b.error(
506
395
  `[ServiceLocator]#getInstance(): Error validating args for ${token.name.toString()}`,
@@ -518,7 +407,7 @@ var ServiceLocator = class {
518
407
  return this.makeInstanceName(token, realArgs);
519
408
  }
520
409
  async getInstance(token, args) {
521
- var _a, _b;
410
+ var _a3, _b;
522
411
  const [err, realArgs] = this.resolveTokenArgs(token, args);
523
412
  if (err instanceof UnknownError) {
524
413
  throw err;
@@ -538,7 +427,7 @@ var ServiceLocator = class {
538
427
  }
539
428
  switch (error.code) {
540
429
  case "InstanceDestroying" /* InstanceDestroying */:
541
- (_a = this.logger) == null ? void 0 : _a.log(
430
+ (_a3 = this.logger) == null ? void 0 : _a3.log(
542
431
  `[ServiceLocator]#getInstance() TTL expired for ${holder == null ? void 0 : holder.name}`
543
432
  );
544
433
  await (holder == null ? void 0 : holder.destroyPromise);
@@ -564,15 +453,15 @@ var ServiceLocator = class {
564
453
  return instance;
565
454
  }
566
455
  notifyListeners(name2, event = "create") {
567
- var _a;
568
- (_a = this.logger) == null ? void 0 : _a.log(
456
+ var _a3;
457
+ (_a3 = this.logger) == null ? void 0 : _a3.log(
569
458
  `[ServiceLocator]#notifyListeners() Notifying listeners for ${name2} with event ${event}`
570
459
  );
571
460
  return this.eventBus.emit(name2, event);
572
461
  }
573
462
  async createInstance(instanceName, token, args) {
574
- var _a;
575
- (_a = this.logger) == null ? void 0 : _a.log(
463
+ var _a3;
464
+ (_a3 = this.logger) == null ? void 0 : _a3.log(
576
465
  `[ServiceLocator]#createInstance() Creating instance for ${instanceName}`
577
466
  );
578
467
  let realToken = token instanceof BoundInjectionToken || token instanceof FactoryInjectionToken ? token.token : token;
@@ -587,8 +476,8 @@ var ServiceLocator = class {
587
476
  }
588
477
  }
589
478
  async createInstanceFromAbstractFactory(instanceName, token, args) {
590
- var _a;
591
- (_a = this.logger) == null ? void 0 : _a.log(
479
+ var _a3;
480
+ (_a3 = this.logger) == null ? void 0 : _a3.log(
592
481
  `[ServiceLocator]#createInstanceFromAbstractFactory(): Creating instance for ${instanceName} from abstract factory`
593
482
  );
594
483
  const ctx = this.createContextForAbstractFactory(instanceName);
@@ -608,14 +497,14 @@ var ServiceLocator = class {
608
497
  kind: "abstractFactory" /* AbstractFactory */,
609
498
  // @ts-expect-error TS2322 This is correct type
610
499
  creationPromise: abstractFactory(ctx, args).then(async (instance) => {
611
- var _a2;
500
+ var _a4;
612
501
  holder.instance = instance;
613
502
  holder.status = "created" /* Created */;
614
503
  holder.deps = ctx.getDependencies();
615
504
  holder.destroyListeners = ctx.getDestroyListeners();
616
505
  holder.ttl = ctx.getTtl();
617
506
  if (holder.deps.length > 0) {
618
- (_a2 = this.logger) == null ? void 0 : _a2.log(
507
+ (_a4 = this.logger) == null ? void 0 : _a4.log(
619
508
  `[ServiceLocator]#createInstanceFromAbstractFactory(): Adding subscriptions for ${instanceName} dependencies for their invalidations: ${holder.deps.join(
620
509
  ", "
621
510
  )}`
@@ -636,8 +525,8 @@ var ServiceLocator = class {
636
525
  await this.notifyListeners(instanceName);
637
526
  return [void 0, instance];
638
527
  }).catch((error) => {
639
- var _a2;
640
- (_a2 = this.logger) == null ? void 0 : _a2.error(
528
+ var _a4;
529
+ (_a4 = this.logger) == null ? void 0 : _a4.error(
641
530
  `[ServiceLocator]#createInstanceFromAbstractFactory(): Error creating instance for ${instanceName}`,
642
531
  error
643
532
  );
@@ -714,8 +603,8 @@ var ServiceLocator = class {
714
603
  return holder.instance;
715
604
  }
716
605
  invalidate(service, round = 1) {
717
- var _a, _b, _c, _d, _e;
718
- (_a = this.logger) == null ? void 0 : _a.log(
606
+ var _a3, _b, _c, _d, _e;
607
+ (_a3 = this.logger) == null ? void 0 : _a3.log(
719
608
  `[ServiceLocator]#invalidate(): Starting Invalidating process of ${service}`
720
609
  );
721
610
  const toInvalidate = this.manager.filter(
@@ -736,9 +625,9 @@ var ServiceLocator = class {
736
625
  );
737
626
  promises.push(
738
627
  (_d = holder.creationPromise) == null ? void 0 : _d.then(() => {
739
- var _a2;
628
+ var _a4;
740
629
  if (round > 3) {
741
- (_a2 = this.logger) == null ? void 0 : _a2.error(
630
+ (_a4 = this.logger) == null ? void 0 : _a4.error(
742
631
  `[ServiceLocator]#invalidate(): ${key} creation is triggering a new invalidation round, but it is still not created`
743
632
  );
744
633
  return;
@@ -765,9 +654,9 @@ var ServiceLocator = class {
765
654
  async ready() {
766
655
  return Promise.all(
767
656
  Array.from(this.manager.filter(() => true)).map(([, holder]) => {
768
- var _a;
657
+ var _a3;
769
658
  if (holder.status === "creating" /* Creating */) {
770
- return (_a = holder.creationPromise) == null ? void 0 : _a.then(() => null);
659
+ return (_a3 = holder.creationPromise) == null ? void 0 : _a3.then(() => null);
771
660
  }
772
661
  if (holder.status === "destroying" /* Destroying */) {
773
662
  return holder.destroyPromise.then(() => null);
@@ -928,7 +817,7 @@ var InjectableType = /* @__PURE__ */ ((InjectableType2) => {
928
817
  InjectableType2["Factory"] = "Factory";
929
818
  return InjectableType2;
930
819
  })(InjectableType || {});
931
- var InjectableTokenMeta = Symbol("InjectableTokenMeta");
820
+ var InjectableTokenMeta = Symbol.for("InjectableTokenMeta");
932
821
  function Injectable({
933
822
  scope = "Singleton" /* Singleton */,
934
823
  type = "Class" /* Class */,
@@ -1042,26 +931,343 @@ function override(token, target) {
1042
931
  };
1043
932
  }
1044
933
 
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
+ });
954
+ }
955
+ if (config.requestSchema) {
956
+ getters.push((target, request) => {
957
+ target.data = request.body;
958
+ });
959
+ }
960
+ if (config.url.includes("$")) {
961
+ getters.push((target, request) => {
962
+ target.urlParams = request.params;
963
+ });
964
+ }
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
+ };
986
+ }
987
+ provideSchema(handlerMetadata) {
988
+ const schema = {};
989
+ const { querySchema, requestSchema } = handlerMetadata.config;
990
+ if (querySchema) {
991
+ schema.querystring = querySchema;
992
+ }
993
+ if (requestSchema) {
994
+ schema.body = requestSchema;
995
+ }
996
+ return schema;
997
+ }
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
+ };
1023
+ }
1024
+ return schema;
1025
+ }
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
+ };
1046
+ }
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
+ });
1069
+ }
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
+
1045
1263
  // packages/core/src/tokens/application.token.mts
1046
1264
  var ApplicationInjectionToken = "ApplicationInjectionToken";
1047
1265
  var Application = InjectionToken.create(
1048
1266
  ApplicationInjectionToken
1049
1267
  );
1050
1268
 
1051
- // packages/core/src/services/controller-adapter.service.mts
1052
- import { NaviosException as NaviosException3 } from "@navios/common";
1053
- import { ZodArray } from "zod";
1054
-
1055
- // packages/core/src/metadata/endpoint.metadata.mts
1269
+ // packages/core/src/metadata/handler.metadata.mts
1056
1270
  var EndpointMetadataKey = Symbol("EndpointMetadataKey");
1057
- var EndpointType = /* @__PURE__ */ ((EndpointType2) => {
1058
- EndpointType2["Unknown"] = "unknown";
1059
- EndpointType2["Endpoint"] = "endpoint";
1060
- EndpointType2["Stream"] = "stream";
1061
- EndpointType2["Multipart"] = "multipart";
1062
- EndpointType2["Handler"] = "handler";
1063
- return EndpointType2;
1064
- })(EndpointType || {});
1065
1271
  function getAllEndpointMetadata(context) {
1066
1272
  if (context.metadata) {
1067
1273
  const metadata = context.metadata[EndpointMetadataKey];
@@ -1088,9 +1294,10 @@ function getEndpointMetadata(target, context) {
1088
1294
  classMethod: target.name,
1089
1295
  url: "",
1090
1296
  successStatusCode: 200,
1297
+ adapterToken: null,
1091
1298
  headers: {},
1092
- type: "unknown" /* Unknown */,
1093
1299
  httpMethod: "GET",
1300
+ // @ts-expect-error We are using a generic type here
1094
1301
  config: null,
1095
1302
  guards: /* @__PURE__ */ new Set(),
1096
1303
  customAttributes: /* @__PURE__ */ new Map()
@@ -1268,7 +1475,7 @@ var ConflictException = class extends HttpException {
1268
1475
  };
1269
1476
 
1270
1477
  // packages/core/src/services/guard-runner.service.mts
1271
- var _GuardRunnerService_decorators, _init;
1478
+ var _GuardRunnerService_decorators, _init4;
1272
1479
  _GuardRunnerService_decorators = [Injectable()];
1273
1480
  var GuardRunnerService = class {
1274
1481
  async runGuards(allGuards, executionContext) {
@@ -1331,39 +1538,59 @@ var GuardRunnerService = class {
1331
1538
  return guards;
1332
1539
  }
1333
1540
  };
1334
- _init = __decoratorStart(null);
1335
- GuardRunnerService = __decorateElement(_init, 0, "GuardRunnerService", _GuardRunnerService_decorators, GuardRunnerService);
1336
- __runInitializers(_init, 1, GuardRunnerService);
1541
+ _init4 = __decoratorStart(null);
1542
+ GuardRunnerService = __decorateElement(_init4, 0, "GuardRunnerService", _GuardRunnerService_decorators, GuardRunnerService);
1543
+ __runInitializers(_init4, 1, GuardRunnerService);
1337
1544
 
1338
1545
  // packages/core/src/services/controller-adapter.service.mts
1339
- var _ControllerAdapterService_decorators, _init2;
1546
+ var _ControllerAdapterService_decorators, _init5;
1340
1547
  _ControllerAdapterService_decorators = [Injectable()];
1341
1548
  var _ControllerAdapterService = class _ControllerAdapterService {
1342
1549
  guardRunner = syncInject(GuardRunnerService);
1343
1550
  logger = syncInject(Logger, {
1344
1551
  context: _ControllerAdapterService.name
1345
1552
  });
1346
- setupController(controller, instance, moduleMetadata) {
1553
+ async setupController(controller, instance, moduleMetadata) {
1554
+ var _a3, _b;
1347
1555
  const controllerMetadata = extractControllerMetadata(controller);
1348
1556
  for (const endpoint of controllerMetadata.endpoints) {
1349
- const { classMethod, url, httpMethod } = endpoint;
1350
- if (!url) {
1557
+ const { classMethod, url, httpMethod, adapterToken } = endpoint;
1558
+ if (!url || !adapterToken) {
1351
1559
  throw new Error(
1352
1560
  `[Navios] Malformed Endpoint ${controller.name}:${classMethod}`
1353
1561
  );
1354
1562
  }
1563
+ const adapter = await inject(
1564
+ adapterToken
1565
+ );
1355
1566
  const executionContext = new ExecutionContext(
1356
1567
  moduleMetadata,
1357
1568
  controllerMetadata,
1358
1569
  endpoint
1359
1570
  );
1360
- instance.withTypeProvider().route({
1361
- method: httpMethod,
1362
- url: url.replaceAll("$", ":"),
1363
- schema: this.provideSchemaForConfig(endpoint),
1364
- preHandler: this.providePreHandler(executionContext),
1365
- handler: this.provideHandler(controller, executionContext, endpoint)
1366
- });
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
+ }
1367
1594
  this.logger.debug(
1368
1595
  `Registered ${httpMethod} ${url} for ${controller.name}:${classMethod}`
1369
1596
  );
@@ -1371,217 +1598,49 @@ var _ControllerAdapterService = class _ControllerAdapterService {
1371
1598
  }
1372
1599
  providePreHandler(executionContext) {
1373
1600
  const guards = this.guardRunner.makeContext(executionContext);
1374
- return guards.size > 0 ? async (request, reply) => {
1375
- getServiceLocator().registerInstance(Request, request);
1376
- getServiceLocator().registerInstance(Reply, reply);
1377
- getServiceLocator().registerInstance(
1378
- ExecutionContextToken,
1379
- executionContext
1380
- );
1381
- executionContext.provideRequest(request);
1382
- executionContext.provideReply(reply);
1383
- let canActivate = true;
1384
- try {
1601
+ return guards.size > 0 ? this.wrapHandler(
1602
+ executionContext,
1603
+ async (request, reply) => {
1604
+ let canActivate = true;
1385
1605
  canActivate = await this.guardRunner.runGuards(
1386
1606
  guards,
1387
1607
  executionContext
1388
1608
  );
1389
- } finally {
1390
- getServiceLocator().removeInstance(Request);
1391
- getServiceLocator().removeInstance(Reply);
1392
- getServiceLocator().removeInstance(ExecutionContextToken);
1393
- }
1394
- if (!canActivate) {
1395
- return reply;
1396
- }
1397
- } : void 0;
1398
- }
1399
- provideSchemaForConfig(endpointMetadata) {
1400
- if (!endpointMetadata.config) {
1401
- this.logger.warn(`No config found for endpoint ${endpointMetadata.url}`);
1402
- return {};
1403
- }
1404
- const { querySchema, requestSchema, responseSchema } = endpointMetadata.config;
1405
- const schema = {};
1406
- if (querySchema) {
1407
- schema.querystring = querySchema;
1408
- }
1409
- if (requestSchema && endpointMetadata.type !== "multipart" /* Multipart */) {
1410
- schema.body = requestSchema;
1411
- }
1412
- if (responseSchema) {
1413
- schema.response = {
1414
- 200: responseSchema
1415
- };
1416
- }
1417
- return schema;
1418
- }
1419
- provideHandler(controller, executionContext, endpointMetadata) {
1420
- switch (endpointMetadata.type) {
1421
- case "unknown" /* Unknown */:
1422
- this.logger.error(
1423
- `Unknown endpoint type ${endpointMetadata.type} for ${controller.name}:${endpointMetadata.classMethod}`
1424
- );
1425
- throw new NaviosException3("Unknown endpoint type");
1426
- case "endpoint" /* Endpoint */:
1427
- return this.provideHandlerForConfig(
1428
- controller,
1429
- executionContext,
1430
- endpointMetadata
1431
- );
1432
- case "stream" /* Stream */:
1433
- return this.provideHandlerForStream(
1434
- controller,
1435
- executionContext,
1436
- endpointMetadata
1437
- );
1438
- case "multipart" /* Multipart */:
1439
- return this.provideHandlerForMultipart(
1440
- controller,
1441
- executionContext,
1442
- endpointMetadata
1443
- );
1444
- case "handler" /* Handler */:
1445
- this.logger.error("Not implemented yet");
1446
- throw new NaviosException3("Not implemented yet");
1447
- }
1448
- }
1449
- provideHandlerForConfig(controller, executionContext, endpointMetadata) {
1450
- return async (request, reply) => {
1451
- getServiceLocator().registerInstance(Request, request);
1452
- getServiceLocator().registerInstance(Reply, reply);
1453
- getServiceLocator().registerInstance(
1454
- ExecutionContextToken,
1455
- executionContext
1456
- );
1457
- executionContext.provideRequest(request);
1458
- executionContext.provideReply(reply);
1459
- const controllerInstance = await inject(controller);
1460
- try {
1461
- const { query, params, body } = request;
1462
- const argument = {};
1463
- if (query && Object.keys(query).length > 0) {
1464
- argument.params = query;
1465
- }
1466
- if (params && Object.keys(params).length > 0) {
1467
- argument.urlParams = params;
1468
- }
1469
- if (body) {
1470
- argument.data = body;
1471
- }
1472
- const result = await controllerInstance[endpointMetadata.classMethod](argument);
1473
- reply.status(endpointMetadata.successStatusCode).headers(endpointMetadata.headers).send(result);
1474
- } finally {
1475
- getServiceLocator().removeInstance(Request);
1476
- getServiceLocator().removeInstance(Reply);
1477
- getServiceLocator().removeInstance(ExecutionContextToken);
1478
- }
1479
- };
1480
- }
1481
- provideHandlerForStream(controller, executionContext, endpointMetadata) {
1482
- return async (request, reply) => {
1483
- getServiceLocator().registerInstance(Request, request);
1484
- getServiceLocator().registerInstance(Reply, reply);
1485
- getServiceLocator().registerInstance(
1486
- ExecutionContextToken,
1487
- executionContext
1488
- );
1489
- executionContext.provideRequest(request);
1490
- executionContext.provideReply(reply);
1491
- const controllerInstance = await inject(controller);
1492
- try {
1493
- const { query, params, body } = request;
1494
- const argument = {};
1495
- if (query && Object.keys(query).length > 0) {
1496
- argument.params = query;
1497
- }
1498
- if (params && Object.keys(params).length > 0) {
1499
- argument.urlParams = params;
1500
- }
1501
- if (body) {
1502
- argument.data = body;
1609
+ if (!canActivate) {
1610
+ return reply;
1503
1611
  }
1504
- await controllerInstance[endpointMetadata.classMethod](argument, reply);
1505
- } finally {
1506
- getServiceLocator().removeInstance(Request);
1507
- getServiceLocator().removeInstance(Reply);
1508
- getServiceLocator().removeInstance(ExecutionContextToken);
1509
1612
  }
1510
- };
1613
+ ) : void 0;
1511
1614
  }
1512
- provideHandlerForMultipart(controller, executionContext, endpointMetadata) {
1513
- const config = endpointMetadata.config;
1514
- const requestSchema = config.requestSchema;
1515
- const shape = requestSchema._def.shape();
1615
+ wrapHandler(executionContext, handler) {
1616
+ const locator = getServiceLocator();
1516
1617
  return async (request, reply) => {
1517
- getServiceLocator().registerInstance(Request, request);
1518
- getServiceLocator().registerInstance(Reply, reply);
1519
- getServiceLocator().registerInstance(
1520
- ExecutionContextToken,
1521
- executionContext
1522
- );
1618
+ locator.registerInstance(Request, request);
1619
+ locator.registerInstance(Reply, reply);
1620
+ locator.registerInstance(ExecutionContextToken, executionContext);
1523
1621
  executionContext.provideRequest(request);
1524
1622
  executionContext.provideReply(reply);
1525
- const controllerInstance = await inject(controller);
1526
1623
  try {
1527
- const parts = request.parts();
1528
- const { query, params } = request;
1529
- const argument = {};
1530
- if (query && Object.keys(query).length > 0) {
1531
- argument.params = query;
1532
- }
1533
- if (params && Object.keys(params).length > 0) {
1534
- argument.urlParams = params;
1535
- }
1536
- const req = {};
1537
- for await (const part of parts) {
1538
- if (!shape[part.fieldname]) {
1539
- throw new NaviosException3(
1540
- `Invalid field name ${part.fieldname} for multipart request`
1541
- );
1542
- }
1543
- const schema = shape[part.fieldname];
1544
- if (part.type === "file") {
1545
- const file = new File([await part.toBuffer()], part.filename, {
1546
- type: part.mimetype
1547
- });
1548
- if (schema instanceof ZodArray) {
1549
- if (!req[part.fieldname]) {
1550
- req[part.fieldname] = [];
1551
- }
1552
- req[part.fieldname].push(file);
1553
- } else {
1554
- req[part.fieldname] = file;
1555
- }
1556
- } else {
1557
- if (schema instanceof ZodArray) {
1558
- if (!req[part.fieldname]) {
1559
- req[part.fieldname] = [];
1560
- }
1561
- req[part.fieldname].push(part.value);
1562
- } else {
1563
- req[part.fieldname] = part.value;
1564
- }
1565
- }
1566
- }
1567
- argument.data = requestSchema.parse(req);
1568
- const result = await controllerInstance[endpointMetadata.classMethod](argument);
1569
- reply.status(endpointMetadata.successStatusCode).headers(endpointMetadata.headers).send(result);
1624
+ return await handler(request, reply);
1570
1625
  } finally {
1571
- getServiceLocator().removeInstance(Request);
1572
- getServiceLocator().removeInstance(Reply);
1573
- getServiceLocator().removeInstance(ExecutionContextToken);
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
+ });
1574
1633
  }
1575
1634
  };
1576
1635
  }
1577
1636
  };
1578
- _init2 = __decoratorStart(null);
1579
- _ControllerAdapterService = __decorateElement(_init2, 0, "ControllerAdapterService", _ControllerAdapterService_decorators, _ControllerAdapterService);
1580
- __runInitializers(_init2, 1, _ControllerAdapterService);
1637
+ _init5 = __decoratorStart(null);
1638
+ _ControllerAdapterService = __decorateElement(_init5, 0, "ControllerAdapterService", _ControllerAdapterService_decorators, _ControllerAdapterService);
1639
+ __runInitializers(_init5, 1, _ControllerAdapterService);
1581
1640
  var ControllerAdapterService = _ControllerAdapterService;
1582
1641
 
1583
1642
  // packages/core/src/services/module-loader.service.mts
1584
- var _ModuleLoaderService_decorators, _init3;
1643
+ var _ModuleLoaderService_decorators, _init6;
1585
1644
  _ModuleLoaderService_decorators = [Injectable()];
1586
1645
  var _ModuleLoaderService = class _ModuleLoaderService {
1587
1646
  logger = syncInject(Logger, {
@@ -1643,9 +1702,9 @@ var _ModuleLoaderService = class _ModuleLoaderService {
1643
1702
  this.initialized = false;
1644
1703
  }
1645
1704
  };
1646
- _init3 = __decoratorStart(null);
1647
- _ModuleLoaderService = __decorateElement(_init3, 0, "ModuleLoaderService", _ModuleLoaderService_decorators, _ModuleLoaderService);
1648
- __runInitializers(_init3, 1, _ModuleLoaderService);
1705
+ _init6 = __decoratorStart(null);
1706
+ _ModuleLoaderService = __decorateElement(_init6, 0, "ModuleLoaderService", _ModuleLoaderService_decorators, _ModuleLoaderService);
1707
+ __runInitializers(_init6, 1, _ModuleLoaderService);
1649
1708
  var ModuleLoaderService = _ModuleLoaderService;
1650
1709
 
1651
1710
  // packages/core/src/tokens/execution-context.token.mts
@@ -1682,7 +1741,7 @@ var dateTimeFormatter = new Intl.DateTimeFormat(void 0, {
1682
1741
  day: "2-digit",
1683
1742
  month: "2-digit"
1684
1743
  });
1685
- var _ConsoleLogger_decorators, _init4;
1744
+ var _ConsoleLogger_decorators, _init7;
1686
1745
  _ConsoleLogger_decorators = [Injectable()];
1687
1746
  var _ConsoleLogger = class _ConsoleLogger {
1688
1747
  /**
@@ -1818,8 +1877,8 @@ var _ConsoleLogger = class _ConsoleLogger {
1818
1877
  this.context = this.originalContext;
1819
1878
  }
1820
1879
  isLevelEnabled(level) {
1821
- var _a;
1822
- const logLevels = (_a = this.options) == null ? void 0 : _a.logLevels;
1880
+ var _a3;
1881
+ const logLevels = (_a3 = this.options) == null ? void 0 : _a3.logLevels;
1823
1882
  return isLogLevelEnabled(level, logLevels);
1824
1883
  }
1825
1884
  getTimestamp() {
@@ -1930,8 +1989,8 @@ var _ConsoleLogger = class _ConsoleLogger {
1930
1989
  `);
1931
1990
  }
1932
1991
  updateAndGetTimestampDiff() {
1933
- var _a;
1934
- const includeTimestamp = _ConsoleLogger.lastTimestampAt && ((_a = this.options) == null ? void 0 : _a.timestamp);
1992
+ var _a3;
1993
+ const includeTimestamp = _ConsoleLogger.lastTimestampAt && ((_a3 = this.options) == null ? void 0 : _a3.timestamp);
1935
1994
  const result = includeTimestamp ? this.formatTimestampDiff(Date.now() - _ConsoleLogger.lastTimestampAt) : "";
1936
1995
  _ConsoleLogger.lastTimestampAt = Date.now();
1937
1996
  return result;
@@ -2036,9 +2095,9 @@ var _ConsoleLogger = class _ConsoleLogger {
2036
2095
  }
2037
2096
  }
2038
2097
  };
2039
- _init4 = __decoratorStart(null);
2040
- _ConsoleLogger = __decorateElement(_init4, 0, "ConsoleLogger", _ConsoleLogger_decorators, _ConsoleLogger);
2041
- __runInitializers(_init4, 1, _ConsoleLogger);
2098
+ _init7 = __decoratorStart(null);
2099
+ _ConsoleLogger = __decorateElement(_init7, 0, "ConsoleLogger", _ConsoleLogger_decorators, _ConsoleLogger);
2100
+ __runInitializers(_init7, 1, _ConsoleLogger);
2042
2101
  var ConsoleLogger = _ConsoleLogger;
2043
2102
 
2044
2103
  // packages/core/src/logger/logger.factory.mts
@@ -2054,7 +2113,7 @@ var dateTimeFormatter2 = new Intl.DateTimeFormat(void 0, {
2054
2113
  day: "2-digit",
2055
2114
  month: "2-digit"
2056
2115
  });
2057
- var _LoggerInstance_decorators, _init5;
2116
+ var _LoggerInstance_decorators, _init8;
2058
2117
  _LoggerInstance_decorators = [Injectable()];
2059
2118
  var _LoggerInstance = class _LoggerInstance {
2060
2119
  constructor(context, options = {}) {
@@ -2076,69 +2135,69 @@ var _LoggerInstance = class _LoggerInstance {
2076
2135
  return _LoggerInstance.staticInstanceRef;
2077
2136
  }
2078
2137
  error(message, ...optionalParams) {
2079
- var _a;
2138
+ var _a3;
2080
2139
  optionalParams = this.context ? (optionalParams.length ? optionalParams : [void 0]).concat(
2081
2140
  this.context
2082
2141
  ) : optionalParams;
2083
- (_a = this.localInstance) == null ? void 0 : _a.error(message, ...optionalParams);
2142
+ (_a3 = this.localInstance) == null ? void 0 : _a3.error(message, ...optionalParams);
2084
2143
  }
2085
2144
  log(message, ...optionalParams) {
2086
- var _a;
2145
+ var _a3;
2087
2146
  optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
2088
- (_a = this.localInstance) == null ? void 0 : _a.log(message, ...optionalParams);
2147
+ (_a3 = this.localInstance) == null ? void 0 : _a3.log(message, ...optionalParams);
2089
2148
  }
2090
2149
  warn(message, ...optionalParams) {
2091
- var _a;
2150
+ var _a3;
2092
2151
  optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
2093
- (_a = this.localInstance) == null ? void 0 : _a.warn(message, ...optionalParams);
2152
+ (_a3 = this.localInstance) == null ? void 0 : _a3.warn(message, ...optionalParams);
2094
2153
  }
2095
2154
  debug(message, ...optionalParams) {
2096
- var _a, _b;
2155
+ var _a3, _b;
2097
2156
  optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
2098
- (_b = (_a = this.localInstance) == null ? void 0 : _a.debug) == null ? void 0 : _b.call(_a, message, ...optionalParams);
2157
+ (_b = (_a3 = this.localInstance) == null ? void 0 : _a3.debug) == null ? void 0 : _b.call(_a3, message, ...optionalParams);
2099
2158
  }
2100
2159
  verbose(message, ...optionalParams) {
2101
- var _a, _b;
2160
+ var _a3, _b;
2102
2161
  optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
2103
- (_b = (_a = this.localInstance) == null ? void 0 : _a.verbose) == null ? void 0 : _b.call(_a, message, ...optionalParams);
2162
+ (_b = (_a3 = this.localInstance) == null ? void 0 : _a3.verbose) == null ? void 0 : _b.call(_a3, message, ...optionalParams);
2104
2163
  }
2105
2164
  fatal(message, ...optionalParams) {
2106
- var _a, _b;
2165
+ var _a3, _b;
2107
2166
  optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
2108
- (_b = (_a = this.localInstance) == null ? void 0 : _a.fatal) == null ? void 0 : _b.call(_a, message, ...optionalParams);
2167
+ (_b = (_a3 = this.localInstance) == null ? void 0 : _a3.fatal) == null ? void 0 : _b.call(_a3, message, ...optionalParams);
2109
2168
  }
2110
2169
  static error(message, ...optionalParams) {
2111
- var _a;
2112
- (_a = this.staticInstanceRef) == null ? void 0 : _a.error(message, ...optionalParams);
2170
+ var _a3;
2171
+ (_a3 = this.staticInstanceRef) == null ? void 0 : _a3.error(message, ...optionalParams);
2113
2172
  }
2114
2173
  static log(message, ...optionalParams) {
2115
- var _a;
2116
- (_a = this.staticInstanceRef) == null ? void 0 : _a.log(message, ...optionalParams);
2174
+ var _a3;
2175
+ (_a3 = this.staticInstanceRef) == null ? void 0 : _a3.log(message, ...optionalParams);
2117
2176
  }
2118
2177
  static warn(message, ...optionalParams) {
2119
- var _a;
2120
- (_a = this.staticInstanceRef) == null ? void 0 : _a.warn(message, ...optionalParams);
2178
+ var _a3;
2179
+ (_a3 = this.staticInstanceRef) == null ? void 0 : _a3.warn(message, ...optionalParams);
2121
2180
  }
2122
2181
  static debug(message, ...optionalParams) {
2123
- var _a, _b;
2124
- (_b = (_a = this.staticInstanceRef) == null ? void 0 : _a.debug) == null ? void 0 : _b.call(_a, message, ...optionalParams);
2182
+ var _a3, _b;
2183
+ (_b = (_a3 = this.staticInstanceRef) == null ? void 0 : _a3.debug) == null ? void 0 : _b.call(_a3, message, ...optionalParams);
2125
2184
  }
2126
2185
  static verbose(message, ...optionalParams) {
2127
- var _a, _b;
2128
- (_b = (_a = this.staticInstanceRef) == null ? void 0 : _a.verbose) == null ? void 0 : _b.call(_a, message, ...optionalParams);
2186
+ var _a3, _b;
2187
+ (_b = (_a3 = this.staticInstanceRef) == null ? void 0 : _a3.verbose) == null ? void 0 : _b.call(_a3, message, ...optionalParams);
2129
2188
  }
2130
2189
  static fatal(message, ...optionalParams) {
2131
- var _a, _b;
2132
- (_b = (_a = this.staticInstanceRef) == null ? void 0 : _a.fatal) == null ? void 0 : _b.call(_a, message, ...optionalParams);
2190
+ var _a3, _b;
2191
+ (_b = (_a3 = this.staticInstanceRef) == null ? void 0 : _a3.fatal) == null ? void 0 : _b.call(_a3, message, ...optionalParams);
2133
2192
  }
2134
2193
  static getTimestamp() {
2135
2194
  return dateTimeFormatter2.format(Date.now());
2136
2195
  }
2137
2196
  static overrideLogger(logger) {
2138
- var _a, _b;
2197
+ var _a3, _b;
2139
2198
  if (Array.isArray(logger)) {
2140
2199
  _LoggerInstance.logLevels = logger;
2141
- return (_b = (_a = this.staticInstanceRef) == null ? void 0 : _a.setLogLevels) == null ? void 0 : _b.call(_a, logger);
2200
+ return (_b = (_a3 = this.staticInstanceRef) == null ? void 0 : _a3.setLogLevels) == null ? void 0 : _b.call(_a3, logger);
2142
2201
  }
2143
2202
  if (isObject(logger)) {
2144
2203
  this.staticInstanceRef = logger;
@@ -2151,20 +2210,20 @@ var _LoggerInstance = class _LoggerInstance {
2151
2210
  return isLogLevelEnabled(level, logLevels);
2152
2211
  }
2153
2212
  registerLocalInstanceRef() {
2154
- var _a;
2213
+ var _a3;
2155
2214
  if (this.localInstanceRef) {
2156
2215
  return this.localInstanceRef;
2157
2216
  }
2158
2217
  this.localInstanceRef = new ConsoleLogger(this.context, {
2159
- timestamp: (_a = this.options) == null ? void 0 : _a.timestamp,
2218
+ timestamp: (_a3 = this.options) == null ? void 0 : _a3.timestamp,
2160
2219
  logLevels: _LoggerInstance.logLevels
2161
2220
  });
2162
2221
  return this.localInstanceRef;
2163
2222
  }
2164
2223
  };
2165
- _init5 = __decoratorStart(null);
2166
- _LoggerInstance = __decorateElement(_init5, 0, "LoggerInstance", _LoggerInstance_decorators, _LoggerInstance);
2167
- __runInitializers(_init5, 1, _LoggerInstance);
2224
+ _init8 = __decoratorStart(null);
2225
+ _LoggerInstance = __decorateElement(_init8, 0, "LoggerInstance", _LoggerInstance_decorators, _LoggerInstance);
2226
+ __runInitializers(_init8, 1, _LoggerInstance);
2168
2227
  var LoggerInstance = _LoggerInstance;
2169
2228
 
2170
2229
  // packages/core/src/logger/logger.factory.mts
@@ -2176,7 +2235,7 @@ var LoggerOptions = z2.object({
2176
2235
  }).optional()
2177
2236
  }).optional();
2178
2237
  var Logger = InjectionToken.create(LoggerInjectionToken, LoggerOptions);
2179
- var _LoggerFactory_decorators, _init6;
2238
+ var _LoggerFactory_decorators, _init9;
2180
2239
  _LoggerFactory_decorators = [Injectable({
2181
2240
  type: "Factory" /* Factory */,
2182
2241
  token: Logger
@@ -2186,9 +2245,9 @@ var LoggerFactory = class {
2186
2245
  return new LoggerInstance(args == null ? void 0 : args.context, args == null ? void 0 : args.options);
2187
2246
  }
2188
2247
  };
2189
- _init6 = __decoratorStart(null);
2190
- LoggerFactory = __decorateElement(_init6, 0, "LoggerFactory", _LoggerFactory_decorators, LoggerFactory);
2191
- __runInitializers(_init6, 1, LoggerFactory);
2248
+ _init9 = __decoratorStart(null);
2249
+ LoggerFactory = __decorateElement(_init9, 0, "LoggerFactory", _LoggerFactory_decorators, LoggerFactory);
2250
+ __runInitializers(_init9, 1, LoggerFactory);
2192
2251
 
2193
2252
  // packages/core/src/logger/pino-wrapper.mts
2194
2253
  var PinoWrapper = class _PinoWrapper {
@@ -2210,12 +2269,12 @@ var PinoWrapper = class _PinoWrapper {
2210
2269
  info() {
2211
2270
  }
2212
2271
  debug(message, ...optionalParams) {
2213
- var _a, _b;
2214
- (_b = (_a = this.logger).debug) == null ? void 0 : _b.call(_a, message, ...optionalParams);
2272
+ var _a3, _b;
2273
+ (_b = (_a3 = this.logger).debug) == null ? void 0 : _b.call(_a3, message, ...optionalParams);
2215
2274
  }
2216
2275
  trace(message, ...optionalParams) {
2217
- var _a, _b;
2218
- (_b = (_a = this.logger).verbose) == null ? void 0 : _b.call(_a, message, ...optionalParams);
2276
+ var _a3, _b;
2277
+ (_b = (_a3 = this.logger).verbose) == null ? void 0 : _b.call(_a3, message, ...optionalParams);
2219
2278
  }
2220
2279
  silent() {
2221
2280
  }
@@ -2243,7 +2302,7 @@ var PinoWrapper = class _PinoWrapper {
2243
2302
  };
2244
2303
 
2245
2304
  // packages/core/src/config/config.service.mts
2246
- import { NaviosException as NaviosException4 } from "@navios/common";
2305
+ import { NaviosException as NaviosException3 } from "@navios/common";
2247
2306
  var ConfigServiceInstance = class {
2248
2307
  constructor(config = {}, logger) {
2249
2308
  this.config = config;
@@ -2253,7 +2312,7 @@ var ConfigServiceInstance = class {
2253
2312
  return this.config;
2254
2313
  }
2255
2314
  get(key) {
2256
- var _a, _b;
2315
+ var _a3, _b;
2257
2316
  try {
2258
2317
  const parts = String(key).split(".");
2259
2318
  let value = this.config;
@@ -2265,8 +2324,8 @@ var ConfigServiceInstance = class {
2265
2324
  }
2266
2325
  return value ?? null;
2267
2326
  } catch (error) {
2268
- (_b = (_a = this.logger).debug) == null ? void 0 : _b.call(
2269
- _a,
2327
+ (_b = (_a3 = this.logger).debug) == null ? void 0 : _b.call(
2328
+ _a3,
2270
2329
  `Failed to get config value for key ${String(key)}`,
2271
2330
  error
2272
2331
  );
@@ -2282,7 +2341,7 @@ var ConfigServiceInstance = class {
2282
2341
  if (value === null) {
2283
2342
  const message = errorMessage || `Configuration value for key "${String(key)}" is not defined`;
2284
2343
  this.logger.error(message);
2285
- throw new NaviosException4(message);
2344
+ throw new NaviosException3(message);
2286
2345
  }
2287
2346
  return value;
2288
2347
  }
@@ -2293,7 +2352,7 @@ var ConfigProviderOptions = z3.object({
2293
2352
  load: z3.function()
2294
2353
  });
2295
2354
  var ConfigProvider = InjectionToken.create(ConfigServiceInstance, ConfigProviderOptions);
2296
- var _ConfigProviderFactory_decorators, _init7;
2355
+ var _ConfigProviderFactory_decorators, _init10;
2297
2356
  _ConfigProviderFactory_decorators = [Injectable({
2298
2357
  token: ConfigProvider,
2299
2358
  type: "Factory" /* Factory */
@@ -2307,16 +2366,19 @@ var ConfigProviderFactory = class {
2307
2366
  const logger = this.logger;
2308
2367
  try {
2309
2368
  const config = await load();
2310
- return new ConfigServiceInstance(config, logger);
2369
+ return new ConfigServiceInstance(
2370
+ config,
2371
+ logger
2372
+ );
2311
2373
  } catch (error) {
2312
2374
  logger.error("Error loading config", error);
2313
2375
  throw error;
2314
2376
  }
2315
2377
  }
2316
2378
  };
2317
- _init7 = __decoratorStart(null);
2318
- ConfigProviderFactory = __decorateElement(_init7, 0, "ConfigProviderFactory", _ConfigProviderFactory_decorators, ConfigProviderFactory);
2319
- __runInitializers(_init7, 1, ConfigProviderFactory);
2379
+ _init10 = __decoratorStart(null);
2380
+ ConfigProviderFactory = __decorateElement(_init10, 0, "ConfigProviderFactory", _ConfigProviderFactory_decorators, ConfigProviderFactory);
2381
+ __runInitializers(_init10, 1, ConfigProviderFactory);
2320
2382
  function provideConfig(options) {
2321
2383
  return InjectionToken.bound(ConfigProvider, options);
2322
2384
  }
@@ -2340,7 +2402,6 @@ function Controller({ guards } = {}) {
2340
2402
  }
2341
2403
  return Injectable({
2342
2404
  token,
2343
- type: "Class" /* Class */,
2344
2405
  scope: "Instance" /* Instance */
2345
2406
  })(target, context);
2346
2407
  };
@@ -2362,14 +2423,17 @@ function Endpoint(endpoint) {
2362
2423
  }
2363
2424
  const config = endpoint.config;
2364
2425
  if (context.metadata) {
2365
- let endpointMetadata = getEndpointMetadata(target, context);
2426
+ let endpointMetadata = getEndpointMetadata(
2427
+ target,
2428
+ context
2429
+ );
2366
2430
  if (endpointMetadata.config && endpointMetadata.config.url) {
2367
2431
  throw new Error(
2368
2432
  `[Navios] Endpoint ${config.method} ${config.url} already exists. Please use a different method or url.`
2369
2433
  );
2370
2434
  }
2371
2435
  endpointMetadata.config = config;
2372
- endpointMetadata.type = "endpoint" /* Endpoint */;
2436
+ endpointMetadata.adapterToken = EndpointAdapterToken;
2373
2437
  endpointMetadata.classMethod = target.name;
2374
2438
  endpointMetadata.httpMethod = config.method;
2375
2439
  endpointMetadata.url = config.url;
@@ -2385,11 +2449,6 @@ function Header(name2, value) {
2385
2449
  throw new Error("[Navios] Header decorator can only be used on methods.");
2386
2450
  }
2387
2451
  const metadata = getEndpointMetadata(target, context);
2388
- if (metadata.type === "stream" /* Stream */) {
2389
- throw new Error(
2390
- "[Navios] HttpCode decorator cannot be used on stream endpoints."
2391
- );
2392
- }
2393
2452
  metadata.headers[name2] = value;
2394
2453
  return target;
2395
2454
  };
@@ -2404,42 +2463,34 @@ function HttpCode(code) {
2404
2463
  );
2405
2464
  }
2406
2465
  const metadata = getEndpointMetadata(target, context);
2407
- if (metadata.type === "stream" /* Stream */) {
2408
- throw new Error(
2409
- "[Navios] HttpCode decorator cannot be used on stream endpoints."
2410
- );
2411
- }
2412
2466
  metadata.successStatusCode = code;
2413
2467
  return target;
2414
2468
  };
2415
2469
  }
2416
2470
 
2417
2471
  // packages/core/src/decorators/module.decorator.mts
2418
- function Module(metadata) {
2472
+ function Module({ controllers = [], imports = [], guards = [] } = {
2473
+ controllers: [],
2474
+ imports: [],
2475
+ guards: []
2476
+ }) {
2419
2477
  return (target, context) => {
2420
2478
  if (context.kind !== "class") {
2421
2479
  throw new Error("[Navios] @Module decorator can only be used on classes.");
2422
2480
  }
2423
2481
  const token = InjectionToken.create(target);
2424
2482
  const moduleMetadata = getModuleMetadata(target, context);
2425
- if (metadata.controllers) {
2426
- for (const controller of metadata.controllers) {
2427
- moduleMetadata.controllers.add(controller);
2428
- }
2483
+ for (const controller of controllers) {
2484
+ moduleMetadata.controllers.add(controller);
2429
2485
  }
2430
- if (metadata.imports) {
2431
- for (const importedModule of metadata.imports) {
2432
- moduleMetadata.imports.add(importedModule);
2433
- }
2486
+ for (const importedModule of imports) {
2487
+ moduleMetadata.imports.add(importedModule);
2434
2488
  }
2435
- if (metadata.guards) {
2436
- for (const guard of Array.from(metadata.guards).reverse()) {
2437
- moduleMetadata.guards.add(guard);
2438
- }
2489
+ for (const guard of Array.from(guards).reverse()) {
2490
+ moduleMetadata.guards.add(guard);
2439
2491
  }
2440
2492
  return Injectable({
2441
2493
  token,
2442
- type: "Class" /* Class */,
2443
2494
  scope: "Singleton" /* Singleton */
2444
2495
  })(target, context);
2445
2496
  };
@@ -2461,14 +2512,17 @@ function Multipart(endpoint) {
2461
2512
  }
2462
2513
  const config = endpoint.config;
2463
2514
  if (context.metadata) {
2464
- let endpointMetadata = getEndpointMetadata(target, context);
2515
+ let endpointMetadata = getEndpointMetadata(
2516
+ target,
2517
+ context
2518
+ );
2465
2519
  if (endpointMetadata.config && endpointMetadata.config.url) {
2466
2520
  throw new Error(
2467
2521
  `[Navios] Endpoint ${config.method} ${config.url} already exists. Please use a different method or url.`
2468
2522
  );
2469
2523
  }
2470
2524
  endpointMetadata.config = config;
2471
- endpointMetadata.type = "multipart" /* Multipart */;
2525
+ endpointMetadata.adapterToken = MultipartAdapterToken;
2472
2526
  endpointMetadata.classMethod = target.name;
2473
2527
  endpointMetadata.httpMethod = config.method;
2474
2528
  endpointMetadata.url = config.url;
@@ -2492,14 +2546,17 @@ function Stream(endpoint) {
2492
2546
  }
2493
2547
  const config = endpoint.config;
2494
2548
  if (context.metadata) {
2495
- let endpointMetadata = getEndpointMetadata(target, context);
2549
+ let endpointMetadata = getEndpointMetadata(
2550
+ target,
2551
+ context
2552
+ );
2496
2553
  if (endpointMetadata.config && endpointMetadata.config.url) {
2497
2554
  throw new Error(
2498
2555
  `[Navios] Endpoint ${config.method} ${config.url} already exists. Please use a different method or url.`
2499
2556
  );
2500
2557
  }
2501
2558
  endpointMetadata.config = config;
2502
- endpointMetadata.type = "stream" /* Stream */;
2559
+ endpointMetadata.adapterToken = StreamAdapterToken;
2503
2560
  endpointMetadata.classMethod = target.name;
2504
2561
  endpointMetadata.httpMethod = config.method;
2505
2562
  endpointMetadata.url = config.url;
@@ -2598,7 +2655,7 @@ import {
2598
2655
  serializerCompiler,
2599
2656
  validatorCompiler
2600
2657
  } from "fastify-type-provider-zod";
2601
- var _NaviosApplication_decorators, _init8;
2658
+ var _NaviosApplication_decorators, _init11;
2602
2659
  _NaviosApplication_decorators = [Injectable()];
2603
2660
  var _NaviosApplication = class _NaviosApplication {
2604
2661
  moduleLoader = syncInject(ModuleLoaderService);
@@ -2690,7 +2747,7 @@ var _NaviosApplication = class _NaviosApplication {
2690
2747
  message: "Not Found",
2691
2748
  error: "NotFound"
2692
2749
  };
2693
- this.logger.error(`Route not found: ${req.url}`);
2750
+ this.logger.error(`Route not found: [${req.method}] ${req.url}`);
2694
2751
  return reply.status(404).send(response);
2695
2752
  });
2696
2753
  }
@@ -2711,15 +2768,14 @@ var _NaviosApplication = class _NaviosApplication {
2711
2768
  }
2712
2769
  promises.push(
2713
2770
  this.server.register(
2714
- (instance, opts, done) => {
2771
+ async (instance, opts) => {
2715
2772
  for (const controller of moduleMetadata.controllers) {
2716
- this.controllerAdapter.setupController(
2773
+ await this.controllerAdapter.setupController(
2717
2774
  controller,
2718
2775
  instance,
2719
2776
  moduleMetadata
2720
2777
  );
2721
2778
  }
2722
- done();
2723
2779
  },
2724
2780
  {
2725
2781
  prefix: this.globalPrefix ?? ""
@@ -2764,9 +2820,9 @@ var _NaviosApplication = class _NaviosApplication {
2764
2820
  await this.dispose();
2765
2821
  }
2766
2822
  };
2767
- _init8 = __decoratorStart(null);
2768
- _NaviosApplication = __decorateElement(_init8, 0, "NaviosApplication", _NaviosApplication_decorators, _NaviosApplication);
2769
- __runInitializers(_init8, 1, _NaviosApplication);
2823
+ _init11 = __decoratorStart(null);
2824
+ _NaviosApplication = __decorateElement(_init11, 0, "NaviosApplication", _NaviosApplication_decorators, _NaviosApplication);
2825
+ __runInitializers(_init11, 1, _NaviosApplication);
2770
2826
  var NaviosApplication = _NaviosApplication;
2771
2827
 
2772
2828
  // packages/core/src/navios.factory.mts
@@ -2802,8 +2858,9 @@ export {
2802
2858
  ControllerAdapterService,
2803
2859
  ControllerMetadataKey,
2804
2860
  Endpoint,
2861
+ EndpointAdapterService,
2862
+ EndpointAdapterToken,
2805
2863
  EndpointMetadataKey,
2806
- EndpointType,
2807
2864
  ErrorsEnum,
2808
2865
  EventEmitter,
2809
2866
  ExecutionContext,
@@ -2836,6 +2893,8 @@ export {
2836
2893
  ModuleLoaderService,
2837
2894
  ModuleMetadataKey,
2838
2895
  Multipart,
2896
+ MultipartAdapterService,
2897
+ MultipartAdapterToken,
2839
2898
  NaviosApplication,
2840
2899
  NaviosFactory,
2841
2900
  NotFoundException,
@@ -2848,6 +2907,8 @@ export {
2848
2907
  ServiceLocatorInstanceHolderStatus,
2849
2908
  ServiceLocatorManager,
2850
2909
  Stream,
2910
+ StreamAdapterService,
2911
+ StreamAdapterToken,
2851
2912
  UnauthorizedException,
2852
2913
  UnknownError,
2853
2914
  UseGuards,