@navios/core 0.1.2 → 0.1.3

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/index.d.mts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { AnyZodObject, ZodOptional, z, ZodType } from 'zod';
2
2
  import { BaseEndpointConfig, EndpointFunctionArgs, HttpMethod } from '@navios/common';
3
+ import { HttpHeader } from 'fastify/types/utils.js';
3
4
  import * as fastify from 'fastify';
4
5
  import { FastifyRequest, FastifyReply, FastifyInstance, FastifyServerOptions, FastifyListenOptions } from 'fastify';
5
6
  import { InspectOptions } from 'util';
@@ -657,10 +658,10 @@ declare class PinoWrapper {
657
658
  fatal(message: any, ...optionalParams: any[]): void;
658
659
  error(message: any, ...optionalParams: any[]): void;
659
660
  warn(message: any, ...optionalParams: any[]): void;
660
- info(message: any, ...optionalParams: any[]): void;
661
+ info(): void;
661
662
  debug(message: any, ...optionalParams: any[]): void;
662
663
  trace(message: any, ...optionalParams: any[]): void;
663
- silent(message: any, ...optionalParams: any[]): void;
664
+ silent(): void;
664
665
  child(options: any): PinoWrapper;
665
666
  get level(): any;
666
667
  }
@@ -708,6 +709,10 @@ declare function Endpoint<Method extends HttpMethod = HttpMethod, Url extends st
708
709
  config: BaseEndpointConfig<Method, Url, QuerySchema, ResponseSchema, RequestSchema>;
709
710
  }): (target: (params: QuerySchema extends AnyZodObject ? RequestSchema extends ZodType ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema> : EndpointFunctionArgs<Url, QuerySchema, undefined> : RequestSchema extends ZodType ? EndpointFunctionArgs<Url, undefined, RequestSchema> : EndpointFunctionArgs<Url, undefined, undefined>) => z.input<ResponseSchema>, context: ClassMethodDecoratorContext) => (params: QuerySchema extends AnyZodObject ? RequestSchema extends ZodType ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema> : EndpointFunctionArgs<Url, QuerySchema, undefined> : RequestSchema extends ZodType ? EndpointFunctionArgs<Url, undefined, RequestSchema> : EndpointFunctionArgs<Url, undefined, undefined>) => z.input<ResponseSchema>;
710
711
 
712
+ declare function Header(name: HttpHeader, value: string | number | string[]): <T extends Function>(target: T, context: ClassMethodDecoratorContext) => T;
713
+
714
+ declare function HttpCode(code: number): <T extends Function>(target: T, context: ClassMethodDecoratorContext) => T;
715
+
711
716
  interface ModuleOptions {
712
717
  controllers?: ClassType[] | Set<ClassType>;
713
718
  imports?: ClassType[] | Set<ClassType>;
@@ -716,9 +721,17 @@ interface ModuleOptions {
716
721
  declare function Module(metadata: ModuleOptions): (target: ClassType, context: ClassDecoratorContext) => ClassType;
717
722
 
718
723
  declare const EndpointMetadataKey: unique symbol;
724
+ declare enum EndpointType {
725
+ Unknown = "unknown",
726
+ Config = "config",
727
+ Handler = "handler"
728
+ }
719
729
  interface EndpointMetadata {
720
730
  classMethod: string;
721
731
  url: string;
732
+ successStatusCode: number;
733
+ type: EndpointType;
734
+ headers: Partial<Record<HttpHeader, number | string | string[] | undefined>>;
722
735
  httpMethod: HttpMethod;
723
736
  config: BaseEndpointConfig | null;
724
737
  guards: Set<ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>>;
@@ -779,6 +792,10 @@ declare class ControllerAdapterService {
779
792
  guardRunner: GuardRunnerService;
780
793
  private logger;
781
794
  setupController(controller: ClassType, instance: FastifyInstance, moduleMetadata: ModuleMetadata): void;
795
+ providePreHandler(executionContext: ExecutionContext): ((request: FastifyRequest, reply: FastifyReply) => Promise<undefined>) | undefined;
796
+ private provideSchemaForConfig;
797
+ private provideHandler;
798
+ private provideHandlerForConfig;
782
799
  }
783
800
 
784
801
  declare class ModuleLoaderService {
@@ -884,6 +901,7 @@ declare class NaviosApplication {
884
901
  setup(appModule: ClassTypeWithInstance<NaviosModule>, options?: NaviosApplicationOptions): void;
885
902
  init(): Promise<void>;
886
903
  private getFastifyInstance;
904
+ private configureFastifyInstance;
887
905
  private initModules;
888
906
  enableCors(options: FastifyCorsOptions): void;
889
907
  setGlobalPrefix(prefix: string): void;
@@ -896,4 +914,4 @@ declare class NaviosFactory {
896
914
  private static registerLoggerConfiguration;
897
915
  }
898
916
 
899
- export { Application, AttributeFactory, BadRequestException, type CanActivate, type ChannelEmitter, type ClassAttribute, type ClassSchemaAttribute, type ClassType, type ClassTypeWithInstance, ConfigProvider, ConfigProviderFactory, ConfigProviderInjectionToken, ConfigProviderOptions, type ConfigService, ConfigServiceInstance, ConflictException, ConsoleLogger, type ConsoleLoggerOptions, Controller, ControllerAdapterService, type ControllerMetadata, ControllerMetadataKey, type ControllerOptions, Endpoint, type EndpointMetadata, EndpointMetadataKey, type EndpointParams, ErrorsEnum, EventEmitter, type EventEmitterInterface, type EventsArgs, type EventsConfig, type EventsNames, ExecutionContext, ExecutionContextInjectionToken, ExecutionContextToken, FactoryNotFound, ForbiddenException, GuardRunnerService, HttpException, Injectable, type InjectableMetadata, type InjectableOptions, InjectableScope, InjectableTokenMeta, InjectableType, InjectionToken, InstanceDestroying, InstanceExpired, InstanceNotFound, InternalServerErrorException, LOG_LEVELS, type LogLevel, Logger, LoggerFactory, LoggerInjectionToken, LoggerInstance, LoggerOptions, type LoggerService, Module, ModuleLoaderService, type ModuleMetadata, ModuleMetadataKey, type ModuleOptions, NaviosApplication, type NaviosApplicationContextOptions, type NaviosApplicationOptions, NaviosFactory, type NaviosModule, NotFoundException, type Path, type PathImpl, type PathImpl2, type PathValue, PinoWrapper, Reply, Request, ServiceLocator, type ServiceLocatorAbstractFactoryContext, ServiceLocatorEventBus, type ServiceLocatorInstanceDestroyListener, type ServiceLocatorInstanceEffect, type ServiceLocatorInstanceHolder, type ServiceLocatorInstanceHolderCreated, type ServiceLocatorInstanceHolderCreating, type ServiceLocatorInstanceHolderDestroying, ServiceLocatorInstanceHolderKind, ServiceLocatorInstanceHolderStatus, ServiceLocatorManager, UnauthorizedException, UnknownError, UseGuards, addLeadingSlash, clc, envInt, envString, extractControllerMetadata, extractModuleMetadata, filterLogLevels, getAllEndpointMetadata, getControllerMetadata, getEndpointMetadata, getInjectableToken, getModuleMetadata, getServiceLocator, hasControllerMetadata, hasModuleMetadata, inject, isConstructor, isEmpty, isFunction, isLogLevel, isLogLevelEnabled, isNil, isNumber, isObject, isPlainObject, isString, isSymbol, isUndefined, makeConfigToken, normalizePath, override, provideServiceLocator, setPromiseCollector, stripEndSlash, syncInject, yellow };
917
+ export { Application, AttributeFactory, BadRequestException, type CanActivate, type ChannelEmitter, type ClassAttribute, type ClassSchemaAttribute, type ClassType, type ClassTypeWithInstance, ConfigProvider, ConfigProviderFactory, ConfigProviderInjectionToken, ConfigProviderOptions, type ConfigService, ConfigServiceInstance, ConflictException, ConsoleLogger, type ConsoleLoggerOptions, Controller, ControllerAdapterService, type ControllerMetadata, ControllerMetadataKey, type ControllerOptions, Endpoint, type EndpointMetadata, EndpointMetadataKey, type EndpointParams, EndpointType, ErrorsEnum, EventEmitter, type EventEmitterInterface, type EventsArgs, type EventsConfig, type EventsNames, ExecutionContext, ExecutionContextInjectionToken, ExecutionContextToken, FactoryNotFound, ForbiddenException, GuardRunnerService, Header, HttpCode, HttpException, Injectable, type InjectableMetadata, type InjectableOptions, InjectableScope, InjectableTokenMeta, InjectableType, InjectionToken, InstanceDestroying, InstanceExpired, InstanceNotFound, InternalServerErrorException, LOG_LEVELS, type LogLevel, Logger, LoggerFactory, LoggerInjectionToken, LoggerInstance, LoggerOptions, type LoggerService, Module, ModuleLoaderService, type ModuleMetadata, ModuleMetadataKey, type ModuleOptions, NaviosApplication, type NaviosApplicationContextOptions, type NaviosApplicationOptions, NaviosFactory, type NaviosModule, NotFoundException, type Path, type PathImpl, type PathImpl2, type PathValue, PinoWrapper, Reply, Request, ServiceLocator, type ServiceLocatorAbstractFactoryContext, ServiceLocatorEventBus, type ServiceLocatorInstanceDestroyListener, type ServiceLocatorInstanceEffect, type ServiceLocatorInstanceHolder, type ServiceLocatorInstanceHolderCreated, type ServiceLocatorInstanceHolderCreating, type ServiceLocatorInstanceHolderDestroying, ServiceLocatorInstanceHolderKind, ServiceLocatorInstanceHolderStatus, ServiceLocatorManager, UnauthorizedException, UnknownError, UseGuards, addLeadingSlash, clc, envInt, envString, extractControllerMetadata, extractModuleMetadata, filterLogLevels, getAllEndpointMetadata, getControllerMetadata, getEndpointMetadata, getInjectableToken, getModuleMetadata, getServiceLocator, hasControllerMetadata, hasModuleMetadata, inject, isConstructor, isEmpty, isFunction, isLogLevel, isLogLevelEnabled, isNil, isNumber, isObject, isPlainObject, isString, isSymbol, isUndefined, makeConfigToken, normalizePath, override, provideServiceLocator, setPromiseCollector, stripEndSlash, syncInject, yellow };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { AnyZodObject, ZodOptional, z, ZodType } from 'zod';
2
2
  import { BaseEndpointConfig, EndpointFunctionArgs, HttpMethod } from '@navios/common';
3
+ import { HttpHeader } from 'fastify/types/utils.js';
3
4
  import * as fastify from 'fastify';
4
5
  import { FastifyRequest, FastifyReply, FastifyInstance, FastifyServerOptions, FastifyListenOptions } from 'fastify';
5
6
  import { InspectOptions } from 'util';
@@ -657,10 +658,10 @@ declare class PinoWrapper {
657
658
  fatal(message: any, ...optionalParams: any[]): void;
658
659
  error(message: any, ...optionalParams: any[]): void;
659
660
  warn(message: any, ...optionalParams: any[]): void;
660
- info(message: any, ...optionalParams: any[]): void;
661
+ info(): void;
661
662
  debug(message: any, ...optionalParams: any[]): void;
662
663
  trace(message: any, ...optionalParams: any[]): void;
663
- silent(message: any, ...optionalParams: any[]): void;
664
+ silent(): void;
664
665
  child(options: any): PinoWrapper;
665
666
  get level(): any;
666
667
  }
@@ -708,6 +709,10 @@ declare function Endpoint<Method extends HttpMethod = HttpMethod, Url extends st
708
709
  config: BaseEndpointConfig<Method, Url, QuerySchema, ResponseSchema, RequestSchema>;
709
710
  }): (target: (params: QuerySchema extends AnyZodObject ? RequestSchema extends ZodType ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema> : EndpointFunctionArgs<Url, QuerySchema, undefined> : RequestSchema extends ZodType ? EndpointFunctionArgs<Url, undefined, RequestSchema> : EndpointFunctionArgs<Url, undefined, undefined>) => z.input<ResponseSchema>, context: ClassMethodDecoratorContext) => (params: QuerySchema extends AnyZodObject ? RequestSchema extends ZodType ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema> : EndpointFunctionArgs<Url, QuerySchema, undefined> : RequestSchema extends ZodType ? EndpointFunctionArgs<Url, undefined, RequestSchema> : EndpointFunctionArgs<Url, undefined, undefined>) => z.input<ResponseSchema>;
710
711
 
712
+ declare function Header(name: HttpHeader, value: string | number | string[]): <T extends Function>(target: T, context: ClassMethodDecoratorContext) => T;
713
+
714
+ declare function HttpCode(code: number): <T extends Function>(target: T, context: ClassMethodDecoratorContext) => T;
715
+
711
716
  interface ModuleOptions {
712
717
  controllers?: ClassType[] | Set<ClassType>;
713
718
  imports?: ClassType[] | Set<ClassType>;
@@ -716,9 +721,17 @@ interface ModuleOptions {
716
721
  declare function Module(metadata: ModuleOptions): (target: ClassType, context: ClassDecoratorContext) => ClassType;
717
722
 
718
723
  declare const EndpointMetadataKey: unique symbol;
724
+ declare enum EndpointType {
725
+ Unknown = "unknown",
726
+ Config = "config",
727
+ Handler = "handler"
728
+ }
719
729
  interface EndpointMetadata {
720
730
  classMethod: string;
721
731
  url: string;
732
+ successStatusCode: number;
733
+ type: EndpointType;
734
+ headers: Partial<Record<HttpHeader, number | string | string[] | undefined>>;
722
735
  httpMethod: HttpMethod;
723
736
  config: BaseEndpointConfig | null;
724
737
  guards: Set<ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>>;
@@ -779,6 +792,10 @@ declare class ControllerAdapterService {
779
792
  guardRunner: GuardRunnerService;
780
793
  private logger;
781
794
  setupController(controller: ClassType, instance: FastifyInstance, moduleMetadata: ModuleMetadata): void;
795
+ providePreHandler(executionContext: ExecutionContext): ((request: FastifyRequest, reply: FastifyReply) => Promise<undefined>) | undefined;
796
+ private provideSchemaForConfig;
797
+ private provideHandler;
798
+ private provideHandlerForConfig;
782
799
  }
783
800
 
784
801
  declare class ModuleLoaderService {
@@ -884,6 +901,7 @@ declare class NaviosApplication {
884
901
  setup(appModule: ClassTypeWithInstance<NaviosModule>, options?: NaviosApplicationOptions): void;
885
902
  init(): Promise<void>;
886
903
  private getFastifyInstance;
904
+ private configureFastifyInstance;
887
905
  private initModules;
888
906
  enableCors(options: FastifyCorsOptions): void;
889
907
  setGlobalPrefix(prefix: string): void;
@@ -896,4 +914,4 @@ declare class NaviosFactory {
896
914
  private static registerLoggerConfiguration;
897
915
  }
898
916
 
899
- export { Application, AttributeFactory, BadRequestException, type CanActivate, type ChannelEmitter, type ClassAttribute, type ClassSchemaAttribute, type ClassType, type ClassTypeWithInstance, ConfigProvider, ConfigProviderFactory, ConfigProviderInjectionToken, ConfigProviderOptions, type ConfigService, ConfigServiceInstance, ConflictException, ConsoleLogger, type ConsoleLoggerOptions, Controller, ControllerAdapterService, type ControllerMetadata, ControllerMetadataKey, type ControllerOptions, Endpoint, type EndpointMetadata, EndpointMetadataKey, type EndpointParams, ErrorsEnum, EventEmitter, type EventEmitterInterface, type EventsArgs, type EventsConfig, type EventsNames, ExecutionContext, ExecutionContextInjectionToken, ExecutionContextToken, FactoryNotFound, ForbiddenException, GuardRunnerService, HttpException, Injectable, type InjectableMetadata, type InjectableOptions, InjectableScope, InjectableTokenMeta, InjectableType, InjectionToken, InstanceDestroying, InstanceExpired, InstanceNotFound, InternalServerErrorException, LOG_LEVELS, type LogLevel, Logger, LoggerFactory, LoggerInjectionToken, LoggerInstance, LoggerOptions, type LoggerService, Module, ModuleLoaderService, type ModuleMetadata, ModuleMetadataKey, type ModuleOptions, NaviosApplication, type NaviosApplicationContextOptions, type NaviosApplicationOptions, NaviosFactory, type NaviosModule, NotFoundException, type Path, type PathImpl, type PathImpl2, type PathValue, PinoWrapper, Reply, Request, ServiceLocator, type ServiceLocatorAbstractFactoryContext, ServiceLocatorEventBus, type ServiceLocatorInstanceDestroyListener, type ServiceLocatorInstanceEffect, type ServiceLocatorInstanceHolder, type ServiceLocatorInstanceHolderCreated, type ServiceLocatorInstanceHolderCreating, type ServiceLocatorInstanceHolderDestroying, ServiceLocatorInstanceHolderKind, ServiceLocatorInstanceHolderStatus, ServiceLocatorManager, UnauthorizedException, UnknownError, UseGuards, addLeadingSlash, clc, envInt, envString, extractControllerMetadata, extractModuleMetadata, filterLogLevels, getAllEndpointMetadata, getControllerMetadata, getEndpointMetadata, getInjectableToken, getModuleMetadata, getServiceLocator, hasControllerMetadata, hasModuleMetadata, inject, isConstructor, isEmpty, isFunction, isLogLevel, isLogLevelEnabled, isNil, isNumber, isObject, isPlainObject, isString, isSymbol, isUndefined, makeConfigToken, normalizePath, override, provideServiceLocator, setPromiseCollector, stripEndSlash, syncInject, yellow };
917
+ export { Application, AttributeFactory, BadRequestException, type CanActivate, type ChannelEmitter, type ClassAttribute, type ClassSchemaAttribute, type ClassType, type ClassTypeWithInstance, ConfigProvider, ConfigProviderFactory, ConfigProviderInjectionToken, ConfigProviderOptions, type ConfigService, ConfigServiceInstance, ConflictException, ConsoleLogger, type ConsoleLoggerOptions, Controller, ControllerAdapterService, type ControllerMetadata, ControllerMetadataKey, type ControllerOptions, Endpoint, type EndpointMetadata, EndpointMetadataKey, type EndpointParams, EndpointType, ErrorsEnum, EventEmitter, type EventEmitterInterface, type EventsArgs, type EventsConfig, type EventsNames, ExecutionContext, ExecutionContextInjectionToken, ExecutionContextToken, FactoryNotFound, ForbiddenException, GuardRunnerService, Header, HttpCode, HttpException, Injectable, type InjectableMetadata, type InjectableOptions, InjectableScope, InjectableTokenMeta, InjectableType, InjectionToken, InstanceDestroying, InstanceExpired, InstanceNotFound, InternalServerErrorException, LOG_LEVELS, type LogLevel, Logger, LoggerFactory, LoggerInjectionToken, LoggerInstance, LoggerOptions, type LoggerService, Module, ModuleLoaderService, type ModuleMetadata, ModuleMetadataKey, type ModuleOptions, NaviosApplication, type NaviosApplicationContextOptions, type NaviosApplicationOptions, NaviosFactory, type NaviosModule, NotFoundException, type Path, type PathImpl, type PathImpl2, type PathValue, PinoWrapper, Reply, Request, ServiceLocator, type ServiceLocatorAbstractFactoryContext, ServiceLocatorEventBus, type ServiceLocatorInstanceDestroyListener, type ServiceLocatorInstanceEffect, type ServiceLocatorInstanceHolder, type ServiceLocatorInstanceHolderCreated, type ServiceLocatorInstanceHolderCreating, type ServiceLocatorInstanceHolderDestroying, ServiceLocatorInstanceHolderKind, ServiceLocatorInstanceHolderStatus, ServiceLocatorManager, UnauthorizedException, UnknownError, UseGuards, addLeadingSlash, clc, envInt, envString, extractControllerMetadata, extractModuleMetadata, filterLogLevels, getAllEndpointMetadata, getControllerMetadata, getEndpointMetadata, getInjectableToken, getModuleMetadata, getServiceLocator, hasControllerMetadata, hasModuleMetadata, inject, isConstructor, isEmpty, isFunction, isLogLevel, isLogLevelEnabled, isNil, isNumber, isObject, isPlainObject, isString, isSymbol, isUndefined, makeConfigToken, normalizePath, override, provideServiceLocator, setPromiseCollector, stripEndSlash, syncInject, yellow };
package/dist/index.js CHANGED
@@ -89,6 +89,7 @@ __export(src_exports, {
89
89
  ControllerMetadataKey: () => ControllerMetadataKey,
90
90
  Endpoint: () => Endpoint,
91
91
  EndpointMetadataKey: () => EndpointMetadataKey,
92
+ EndpointType: () => EndpointType,
92
93
  ErrorsEnum: () => ErrorsEnum,
93
94
  EventEmitter: () => EventEmitter,
94
95
  ExecutionContext: () => ExecutionContext2,
@@ -97,6 +98,8 @@ __export(src_exports, {
97
98
  FactoryNotFound: () => FactoryNotFound,
98
99
  ForbiddenException: () => ForbiddenException,
99
100
  GuardRunnerService: () => GuardRunnerService,
101
+ Header: () => Header,
102
+ HttpCode: () => HttpCode,
100
103
  HttpException: () => HttpException,
101
104
  Injectable: () => Injectable,
102
105
  InjectableScope: () => InjectableScope,
@@ -1567,7 +1570,6 @@ var _LoggerInstance = class _LoggerInstance {
1567
1570
  }
1568
1571
  static overrideLogger(logger) {
1569
1572
  var _a, _b;
1570
- console.log(logger);
1571
1573
  if (Array.isArray(logger)) {
1572
1574
  _LoggerInstance.logLevels = logger;
1573
1575
  return (_b = (_a = this.staticInstanceRef) == null ? void 0 : _a.setLogLevels) == null ? void 0 : _b.call(_a, logger);
@@ -1639,8 +1641,7 @@ var PinoWrapper = class _PinoWrapper {
1639
1641
  warn(message, ...optionalParams) {
1640
1642
  this.logger.warn(message, ...optionalParams);
1641
1643
  }
1642
- info(message, ...optionalParams) {
1643
- this.logger.log(message, ...optionalParams);
1644
+ info() {
1644
1645
  }
1645
1646
  debug(message, ...optionalParams) {
1646
1647
  var _a, _b;
@@ -1650,7 +1651,7 @@ var PinoWrapper = class _PinoWrapper {
1650
1651
  var _a, _b;
1651
1652
  (_b = (_a = this.logger).verbose) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1652
1653
  }
1653
- silent(message, ...optionalParams) {
1654
+ silent() {
1654
1655
  }
1655
1656
  child(options) {
1656
1657
  const keys = Object.keys(options);
@@ -1669,9 +1670,9 @@ var PinoWrapper = class _PinoWrapper {
1669
1670
  }
1670
1671
  const levels = LoggerInstance["logLevels"];
1671
1672
  if (levels) {
1672
- return levels[0];
1673
+ return levels.find((level) => level !== "verbose");
1673
1674
  }
1674
- return "info";
1675
+ return "warn";
1675
1676
  }
1676
1677
  };
1677
1678
 
@@ -1770,6 +1771,12 @@ function makeConfigToken(options) {
1770
1771
 
1771
1772
  // packages/core/src/metadata/endpoint.metadata.mts
1772
1773
  var EndpointMetadataKey = Symbol("EndpointMetadataKey");
1774
+ var EndpointType = /* @__PURE__ */ ((EndpointType2) => {
1775
+ EndpointType2["Unknown"] = "unknown";
1776
+ EndpointType2["Config"] = "config";
1777
+ EndpointType2["Handler"] = "handler";
1778
+ return EndpointType2;
1779
+ })(EndpointType || {});
1773
1780
  function getAllEndpointMetadata(context) {
1774
1781
  if (context.metadata) {
1775
1782
  const metadata = context.metadata[EndpointMetadataKey];
@@ -1795,6 +1802,9 @@ function getEndpointMetadata(target, context) {
1795
1802
  const newMetadata = {
1796
1803
  classMethod: target.name,
1797
1804
  url: "",
1805
+ successStatusCode: 200,
1806
+ headers: {},
1807
+ type: "unknown" /* Unknown */,
1798
1808
  httpMethod: "GET",
1799
1809
  config: null,
1800
1810
  guards: /* @__PURE__ */ new Set(),
@@ -1924,6 +1934,7 @@ function Endpoint(endpoint) {
1924
1934
  );
1925
1935
  }
1926
1936
  endpointMetadata.config = config;
1937
+ endpointMetadata.type = "config" /* Config */;
1927
1938
  endpointMetadata.classMethod = target.name;
1928
1939
  endpointMetadata.httpMethod = config.method;
1929
1940
  endpointMetadata.url = config.url;
@@ -1932,6 +1943,32 @@ function Endpoint(endpoint) {
1932
1943
  };
1933
1944
  }
1934
1945
 
1946
+ // packages/core/src/decorators/header.decorator.mts
1947
+ function Header(name2, value) {
1948
+ return (target, context) => {
1949
+ if (context.kind !== "method") {
1950
+ throw new Error("[Navios] Header decorator can only be used on methods.");
1951
+ }
1952
+ const metadata = getEndpointMetadata(target, context);
1953
+ metadata.headers[name2] = value;
1954
+ return target;
1955
+ };
1956
+ }
1957
+
1958
+ // packages/core/src/decorators/http-code.decorator.mts
1959
+ function HttpCode(code) {
1960
+ return (target, context) => {
1961
+ if (context.kind !== "method") {
1962
+ throw new Error(
1963
+ "[Navios] HttpCode decorator can only be used on methods."
1964
+ );
1965
+ }
1966
+ const metadata = getEndpointMetadata(target, context);
1967
+ metadata.successStatusCode = code;
1968
+ return target;
1969
+ };
1970
+ }
1971
+
1935
1972
  // packages/core/src/decorators/module.decorator.mts
1936
1973
  function Module(metadata) {
1937
1974
  return (target, context) => {
@@ -2041,6 +2078,9 @@ var ConflictException = class extends HttpException {
2041
2078
  }
2042
2079
  };
2043
2080
 
2081
+ // packages/core/src/services/controller-adapter.service.mts
2082
+ var import_common2 = require("@navios/common");
2083
+
2044
2084
  // packages/core/src/tokens/application.token.mts
2045
2085
  var ApplicationInjectionToken = "ApplicationInjectionToken";
2046
2086
  var Application = InjectionToken.create(
@@ -2184,8 +2224,8 @@ var _ControllerAdapterService = class _ControllerAdapterService {
2184
2224
  setupController(controller, instance, moduleMetadata) {
2185
2225
  const controllerMetadata = extractControllerMetadata(controller);
2186
2226
  for (const endpoint of controllerMetadata.endpoints) {
2187
- const { classMethod, url, httpMethod, config } = endpoint;
2188
- if (!url || !config) {
2227
+ const { classMethod, url, httpMethod } = endpoint;
2228
+ if (!url) {
2189
2229
  throw new Error(
2190
2230
  `[Navios] Malformed Endpoint ${controller.name}:${classMethod}`
2191
2231
  );
@@ -2195,91 +2235,115 @@ var _ControllerAdapterService = class _ControllerAdapterService {
2195
2235
  controllerMetadata,
2196
2236
  endpoint
2197
2237
  );
2198
- const guards = this.guardRunner.makeContext(executionContext);
2199
- const { querySchema, requestSchema, responseSchema } = config;
2200
- const schema = {};
2201
- if (querySchema) {
2202
- schema.querystring = querySchema;
2203
- }
2204
- if (requestSchema) {
2205
- schema.body = requestSchema;
2206
- }
2207
- if (responseSchema) {
2208
- schema.response = {
2209
- 200: responseSchema
2210
- };
2211
- }
2212
2238
  instance.withTypeProvider().route({
2213
2239
  method: httpMethod,
2214
2240
  url: url.replaceAll("$", ":"),
2215
- schema,
2216
- preHandler: async (request, reply) => {
2217
- if (guards.size > 0) {
2218
- getServiceLocator().registerInstance(Request, request);
2219
- getServiceLocator().registerInstance(Reply, reply);
2220
- getServiceLocator().registerInstance(
2221
- ExecutionContextToken,
2222
- executionContext
2223
- );
2224
- executionContext.provideRequest(request);
2225
- executionContext.provideReply(reply);
2226
- const canActivate = await this.guardRunner.runGuards(
2227
- guards,
2228
- executionContext
2229
- );
2230
- getServiceLocator().removeInstance(Request);
2231
- getServiceLocator().removeInstance(Reply);
2232
- getServiceLocator().removeInstance(ExecutionContextToken);
2233
- if (!canActivate) {
2234
- return reply;
2235
- }
2236
- }
2237
- },
2238
- handler: async (request, reply) => {
2239
- getServiceLocator().registerInstance(Request, request);
2240
- getServiceLocator().registerInstance(Reply, reply);
2241
- getServiceLocator().registerInstance(
2242
- ExecutionContextToken,
2243
- executionContext
2244
- );
2245
- executionContext.provideRequest(request);
2246
- executionContext.provideReply(reply);
2247
- const controllerInstance = await inject(controller);
2248
- try {
2249
- const { query, params, body } = request;
2250
- const argument = {};
2251
- if (query && Object.keys(query).length > 0) {
2252
- argument.params = query;
2253
- }
2254
- if (params && Object.keys(params).length > 0) {
2255
- argument.urlParams = params;
2256
- }
2257
- if (body) {
2258
- argument.data = body;
2259
- }
2260
- const result = await controllerInstance[classMethod](argument);
2261
- reply.status(200).send(result);
2262
- } catch (error) {
2263
- if (error instanceof HttpException) {
2264
- reply.status(error.statusCode).send(error.response);
2265
- } else {
2266
- reply.status(500).send({
2267
- message: "Internal server error",
2268
- error: error.message
2269
- });
2270
- }
2271
- } finally {
2272
- getServiceLocator().removeInstance(Request);
2273
- getServiceLocator().removeInstance(Reply);
2274
- getServiceLocator().removeInstance(ExecutionContextToken);
2275
- }
2276
- }
2241
+ schema: this.provideSchemaForConfig(endpoint),
2242
+ preHandler: this.providePreHandler(executionContext),
2243
+ handler: this.provideHandler(controller, executionContext, endpoint)
2277
2244
  });
2278
2245
  this.logger.debug(
2279
2246
  `Registered ${httpMethod} ${url} for ${controller.name}:${classMethod}`
2280
2247
  );
2281
2248
  }
2282
2249
  }
2250
+ providePreHandler(executionContext) {
2251
+ const guards = this.guardRunner.makeContext(executionContext);
2252
+ return guards.size > 0 ? async (request, reply) => {
2253
+ getServiceLocator().registerInstance(Request, request);
2254
+ getServiceLocator().registerInstance(Reply, reply);
2255
+ getServiceLocator().registerInstance(
2256
+ ExecutionContextToken,
2257
+ executionContext
2258
+ );
2259
+ executionContext.provideRequest(request);
2260
+ executionContext.provideReply(reply);
2261
+ let canActivate = true;
2262
+ try {
2263
+ canActivate = await this.guardRunner.runGuards(
2264
+ guards,
2265
+ executionContext
2266
+ );
2267
+ } finally {
2268
+ getServiceLocator().removeInstance(Request);
2269
+ getServiceLocator().removeInstance(Reply);
2270
+ getServiceLocator().removeInstance(ExecutionContextToken);
2271
+ }
2272
+ if (!canActivate) {
2273
+ return reply;
2274
+ }
2275
+ } : void 0;
2276
+ }
2277
+ provideSchemaForConfig(endpointMetadata) {
2278
+ if (!endpointMetadata.config) {
2279
+ this.logger.warn(`No config found for endpoint ${endpointMetadata.url}`);
2280
+ return {};
2281
+ }
2282
+ const { querySchema, requestSchema, responseSchema } = endpointMetadata.config;
2283
+ const schema = {};
2284
+ if (querySchema) {
2285
+ schema.querystring = querySchema;
2286
+ }
2287
+ if (requestSchema) {
2288
+ schema.body = requestSchema;
2289
+ }
2290
+ if (responseSchema) {
2291
+ schema.response = {
2292
+ 200: responseSchema
2293
+ };
2294
+ }
2295
+ return schema;
2296
+ }
2297
+ provideHandler(controller, executionContext, endpointMetadata) {
2298
+ switch (endpointMetadata.type) {
2299
+ case "unknown" /* Unknown */:
2300
+ this.logger.error(
2301
+ `Unknown endpoint type ${endpointMetadata.type} for ${controller.name}:${endpointMetadata.classMethod}`
2302
+ );
2303
+ throw new import_common2.NaviosException("Unknown endpoint type");
2304
+ case "config" /* Config */:
2305
+ return this.provideHandlerForConfig(
2306
+ controller,
2307
+ executionContext,
2308
+ endpointMetadata
2309
+ );
2310
+ case "handler" /* Handler */:
2311
+ this.logger.error("Not implemented yet");
2312
+ throw new import_common2.NaviosException("Not implemented yet");
2313
+ }
2314
+ }
2315
+ provideHandlerForConfig(controller, executionContext, endpointMetadata) {
2316
+ return async (request, reply) => {
2317
+ getServiceLocator().registerInstance(Request, request);
2318
+ getServiceLocator().registerInstance(Reply, reply);
2319
+ getServiceLocator().registerInstance(
2320
+ ExecutionContextToken,
2321
+ executionContext
2322
+ );
2323
+ executionContext.provideRequest(request);
2324
+ executionContext.provideReply(reply);
2325
+ const controllerInstance = await inject(controller);
2326
+ try {
2327
+ const { query, params, body } = request;
2328
+ const argument = {};
2329
+ if (query && Object.keys(query).length > 0) {
2330
+ argument.params = query;
2331
+ }
2332
+ if (params && Object.keys(params).length > 0) {
2333
+ argument.urlParams = params;
2334
+ }
2335
+ if (body) {
2336
+ argument.data = body;
2337
+ }
2338
+ const result = await controllerInstance[endpointMetadata.classMethod](argument);
2339
+ reply.status(endpointMetadata.successStatusCode).headers(endpointMetadata.headers).send(result);
2340
+ } finally {
2341
+ getServiceLocator().removeInstance(Request);
2342
+ getServiceLocator().removeInstance(Reply);
2343
+ getServiceLocator().removeInstance(ExecutionContextToken);
2344
+ }
2345
+ };
2346
+ }
2283
2347
  };
2284
2348
  _init6 = __decoratorStart(null);
2285
2349
  _ControllerAdapterService = __decorateElement(_init6, 0, "ControllerAdapterService", _ControllerAdapterService_decorators, _ControllerAdapterService);
@@ -2433,6 +2497,7 @@ var _NaviosApplication = class _NaviosApplication {
2433
2497
  }
2434
2498
  await this.moduleLoader.loadModules(this.appModule);
2435
2499
  this.server = await this.getFastifyInstance(this.options);
2500
+ this.configureFastifyInstance(this.server);
2436
2501
  getServiceLocator().registerInstance(Application, this.server);
2437
2502
  this.server.setValidatorCompiler(import_fastify_type_provider_zod.validatorCompiler);
2438
2503
  this.server.setSerializerCompiler(import_fastify_type_provider_zod.serializerCompiler);
@@ -2440,6 +2505,7 @@ var _NaviosApplication = class _NaviosApplication {
2440
2505
  await this.server.register(import_cors.default, this.corsOptions);
2441
2506
  }
2442
2507
  await this.initModules();
2508
+ await this.server.ready();
2443
2509
  this.logger.debug("Navios application initialized");
2444
2510
  }
2445
2511
  async getFastifyInstance(rawOptions) {
@@ -2469,6 +2535,35 @@ var _NaviosApplication = class _NaviosApplication {
2469
2535
  });
2470
2536
  }
2471
2537
  }
2538
+ configureFastifyInstance(fastifyInstance) {
2539
+ fastifyInstance.setErrorHandler((error, request, reply) => {
2540
+ if (error instanceof HttpException) {
2541
+ return reply.status(error.statusCode).send(error.response);
2542
+ } else {
2543
+ const statusCode = error.statusCode || 500;
2544
+ const message = error.message || "Internal Server Error";
2545
+ const response = {
2546
+ statusCode,
2547
+ message,
2548
+ error: error.name || "InternalServerError"
2549
+ };
2550
+ this.logger.error(
2551
+ `Error occurred: ${error.message} on ${request.url}`,
2552
+ error
2553
+ );
2554
+ return reply.status(statusCode).send(response);
2555
+ }
2556
+ });
2557
+ fastifyInstance.setNotFoundHandler((req, reply) => {
2558
+ const response = {
2559
+ statusCode: 404,
2560
+ message: "Not Found",
2561
+ error: "NotFound"
2562
+ };
2563
+ this.logger.error(`Route not found: ${req.url}`);
2564
+ return reply.status(404).send(response);
2565
+ });
2566
+ }
2472
2567
  async initModules() {
2473
2568
  const modules = this.moduleLoader.getAllModules();
2474
2569
  const promises = [];
@@ -2512,7 +2607,8 @@ var _NaviosApplication = class _NaviosApplication {
2512
2607
  if (!this.server) {
2513
2608
  throw new Error("Server is not initialized. Call init() first.");
2514
2609
  }
2515
- await this.server.listen(options);
2610
+ const res = await this.server.listen(options);
2611
+ this.logger.debug(`Navios is listening on ${res}`);
2516
2612
  }
2517
2613
  };
2518
2614
  _init8 = __decoratorStart(null);
@@ -2555,6 +2651,7 @@ var NaviosFactory = class {
2555
2651
  ControllerMetadataKey,
2556
2652
  Endpoint,
2557
2653
  EndpointMetadataKey,
2654
+ EndpointType,
2558
2655
  ErrorsEnum,
2559
2656
  EventEmitter,
2560
2657
  ExecutionContext,
@@ -2563,6 +2660,8 @@ var NaviosFactory = class {
2563
2660
  FactoryNotFound,
2564
2661
  ForbiddenException,
2565
2662
  GuardRunnerService,
2663
+ Header,
2664
+ HttpCode,
2566
2665
  HttpException,
2567
2666
  Injectable,
2568
2667
  InjectableScope,