@navios/core 0.9.0 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/lib/{index-D9MNh6Tx.d.mts → index-B2ulzZIr.d.cts} +31 -2
- package/lib/index-B2ulzZIr.d.cts.map +1 -0
- package/lib/{index-Db1d3cwD.d.cts → index-C8lUQePd.d.mts} +31 -2
- package/lib/index-C8lUQePd.d.mts.map +1 -0
- package/lib/index.cjs +5 -2
- package/lib/index.d.cts +2 -2
- package/lib/index.d.mts +2 -2
- package/lib/index.mjs +3 -3
- package/lib/legacy-compat/index.cjs +160 -1
- package/lib/legacy-compat/index.cjs.map +1 -1
- package/lib/legacy-compat/index.d.cts +239 -6
- package/lib/legacy-compat/index.d.cts.map +1 -1
- package/lib/legacy-compat/index.d.mts +239 -6
- package/lib/legacy-compat/index.d.mts.map +1 -1
- package/lib/legacy-compat/index.mjs +154 -2
- package/lib/legacy-compat/index.mjs.map +1 -1
- package/lib/{src-Bo23RIo-.mjs → src-Baabu2R8.mjs} +6 -4
- package/lib/src-Baabu2R8.mjs.map +1 -0
- package/lib/{src-BRPtJ9fG.cjs → src-Cu9OAnfp.cjs} +6 -4
- package/lib/src-Cu9OAnfp.cjs.map +1 -0
- package/lib/testing/index.cjs +2 -2
- package/lib/testing/index.d.cts +1 -1
- package/lib/testing/index.d.mts +1 -1
- package/lib/testing/index.mjs +2 -2
- package/lib/{use-guards.decorator-CzVXuLkz.mjs → use-guards.decorator-ChJVzYLW.mjs} +27 -2
- package/lib/use-guards.decorator-ChJVzYLW.mjs.map +1 -0
- package/lib/{use-guards.decorator-Bs8oDHOi.cjs → use-guards.decorator-EvI2m2DK.cjs} +45 -2
- package/lib/use-guards.decorator-EvI2m2DK.cjs.map +1 -0
- package/package.json +4 -4
- package/src/attribute.factory.mts +19 -3
- package/src/legacy-compat/__type-tests__/legacy-decorators.spec-d.mts +112 -4
- package/src/legacy-compat/attribute.factory.mts +365 -0
- package/src/legacy-compat/context-compat.mts +2 -0
- package/src/legacy-compat/decorators/factory.decorator.mts +37 -0
- package/src/legacy-compat/decorators/index.mts +2 -0
- package/src/legacy-compat/decorators/injectable.decorator.mts +41 -0
- package/src/legacy-compat/decorators/stream.decorator.mts +21 -14
- package/src/legacy-compat/index.mts +15 -3
- package/src/metadata/index.mts +1 -0
- package/src/metadata/navios-managed.metadata.mts +42 -0
- package/lib/index-D9MNh6Tx.d.mts.map +0 -1
- package/lib/index-Db1d3cwD.d.cts.map +0 -1
- package/lib/src-BRPtJ9fG.cjs.map +0 -1
- package/lib/src-Bo23RIo-.mjs.map +0 -1
- package/lib/use-guards.decorator-Bs8oDHOi.cjs.map +0 -1
- package/lib/use-guards.decorator-CzVXuLkz.mjs.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_src = require('./src-
|
|
1
|
+
const require_src = require('./src-Cu9OAnfp.cjs');
|
|
2
2
|
let _navios_di = require("@navios/di");
|
|
3
3
|
|
|
4
4
|
//#region src/metadata/handler.metadata.mts
|
|
@@ -99,6 +99,31 @@ function hasModuleMetadata(target) {
|
|
|
99
99
|
return !!target[ModuleMetadataKey];
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/metadata/navios-managed.metadata.mts
|
|
104
|
+
/**
|
|
105
|
+
* Symbol used to identify Navios-managed classes (Controller, Module, MessageController, etc.).
|
|
106
|
+
* This allows AttributeFactory to work with any Navios-managed class type generically.
|
|
107
|
+
*/ const NaviosManagedMetadataKey = Symbol("NaviosManagedMetadataKey");
|
|
108
|
+
/**
|
|
109
|
+
* Gets managed metadata from a class if it exists.
|
|
110
|
+
* This is a generic function that works with any Navios-managed class type.
|
|
111
|
+
*
|
|
112
|
+
* @param target - The class to check
|
|
113
|
+
* @returns The metadata with customAttributes, or null if not managed
|
|
114
|
+
*/ function getManagedMetadata(target) {
|
|
115
|
+
if (target[NaviosManagedMetadataKey]) return target[NaviosManagedMetadataKey];
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Checks if a class is Navios-managed (has managed metadata).
|
|
120
|
+
*
|
|
121
|
+
* @param target - The class to check
|
|
122
|
+
* @returns true if the class is Navios-managed
|
|
123
|
+
*/ function hasManagedMetadata(target) {
|
|
124
|
+
return getManagedMetadata(target) !== null;
|
|
125
|
+
}
|
|
126
|
+
|
|
102
127
|
//#endregion
|
|
103
128
|
//#region src/decorators/controller.decorator.mts
|
|
104
129
|
/**
|
|
@@ -459,6 +484,12 @@ Object.defineProperty(exports, 'MultipartAdapterToken', {
|
|
|
459
484
|
return MultipartAdapterToken;
|
|
460
485
|
}
|
|
461
486
|
});
|
|
487
|
+
Object.defineProperty(exports, 'NaviosManagedMetadataKey', {
|
|
488
|
+
enumerable: true,
|
|
489
|
+
get: function () {
|
|
490
|
+
return NaviosManagedMetadataKey;
|
|
491
|
+
}
|
|
492
|
+
});
|
|
462
493
|
Object.defineProperty(exports, 'NaviosOptionsToken', {
|
|
463
494
|
enumerable: true,
|
|
464
495
|
get: function () {
|
|
@@ -531,6 +562,12 @@ Object.defineProperty(exports, 'getEndpointMetadata', {
|
|
|
531
562
|
return getEndpointMetadata;
|
|
532
563
|
}
|
|
533
564
|
});
|
|
565
|
+
Object.defineProperty(exports, 'getManagedMetadata', {
|
|
566
|
+
enumerable: true,
|
|
567
|
+
get: function () {
|
|
568
|
+
return getManagedMetadata;
|
|
569
|
+
}
|
|
570
|
+
});
|
|
534
571
|
Object.defineProperty(exports, 'getModuleMetadata', {
|
|
535
572
|
enumerable: true,
|
|
536
573
|
get: function () {
|
|
@@ -543,10 +580,16 @@ Object.defineProperty(exports, 'hasControllerMetadata', {
|
|
|
543
580
|
return hasControllerMetadata;
|
|
544
581
|
}
|
|
545
582
|
});
|
|
583
|
+
Object.defineProperty(exports, 'hasManagedMetadata', {
|
|
584
|
+
enumerable: true,
|
|
585
|
+
get: function () {
|
|
586
|
+
return hasManagedMetadata;
|
|
587
|
+
}
|
|
588
|
+
});
|
|
546
589
|
Object.defineProperty(exports, 'hasModuleMetadata', {
|
|
547
590
|
enumerable: true,
|
|
548
591
|
get: function () {
|
|
549
592
|
return hasModuleMetadata;
|
|
550
593
|
}
|
|
551
594
|
});
|
|
552
|
-
//# sourceMappingURL=use-guards.decorator-
|
|
595
|
+
//# sourceMappingURL=use-guards.decorator-EvI2m2DK.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-guards.decorator-EvI2m2DK.cjs","names":["EndpointMetadataKey","Symbol","getAllEndpointMetadata","context","metadata","Set","Error","getEndpointMetadata","target","endpointMetadata","Array","from","find","item","classMethod","name","newMetadata","url","successStatusCode","adapterToken","headers","httpMethod","config","guards","customAttributes","Map","add","getAllEndpointMetadata","ControllerMetadataKey","Symbol","getControllerMetadata","target","context","metadata","endpointsMetadata","newMetadata","endpoints","guards","Set","customAttributes","Map","Error","extractControllerMetadata","hasControllerMetadata","ModuleMetadataKey","Symbol","getModuleMetadata","target","context","metadata","newMetadata","controllers","Set","imports","guards","customAttributes","Map","Error","extractModuleMetadata","name","hasModuleMetadata","NaviosManagedMetadataKey","Symbol","getManagedMetadata","target","hasManagedMetadata","Injectable","InjectionToken","getControllerMetadata","Controller","guards","registry","priority","scope","target","context","kind","Error","token","create","metadata","controllerMetadata","guard","Array","from","reverse","add","InjectionToken","EndpointAdapterToken","create","InjectionToken","ExecutionContextInjectionToken","ExecutionContext","create","InjectionToken","HttpAdapterToken","create","InjectionToken","MultipartAdapterToken","create","InjectionToken","NaviosOptionsToken","create","InjectionToken","Reply","create","InjectionToken","Request","create","InjectionToken","StreamAdapterToken","create","InjectionToken","XmlStreamAdapterToken","create","getEndpointMetadata","EndpointAdapterToken","Endpoint","endpoint","target","context","kind","Error","config","metadata","endpointMetadata","url","method","adapterToken","classMethod","name","httpMethod","getEndpointMetadata","Header","name","value","target","context","kind","Error","metadata","headers","getEndpointMetadata","HttpCode","code","target","context","kind","Error","metadata","successStatusCode","Injectable","InjectableScope","InjectionToken","getModuleMetadata","Module","controllers","imports","guards","priority","registry","target","context","kind","Error","token","create","moduleMetadata","controller","add","importedModule","guard","Array","from","reverse","scope","Singleton","getEndpointMetadata","MultipartAdapterToken","Multipart","endpoint","target","context","kind","Error","config","metadata","endpointMetadata","url","method","adapterToken","classMethod","name","httpMethod","getEndpointMetadata","StreamAdapterToken","Stream","endpoint","target","context","kind","Error","config","metadata","endpointMetadata","url","method","adapterToken","classMethod","name","httpMethod","getControllerMetadata","getEndpointMetadata","UseGuards","guards","target","context","kind","controllerMetadata","guard","reverse","add","endpointMetadata","Error"],"sources":["../src/metadata/handler.metadata.mts","../src/metadata/controller.metadata.mts","../src/metadata/module.metadata.mts","../src/metadata/navios-managed.metadata.mts","../src/decorators/controller.decorator.mts","../src/tokens/endpoint-adapter.token.mts","../src/tokens/execution-context.token.mts","../src/tokens/http-adapter.token.mts","../src/tokens/multipart-adapter.token.mts","../src/tokens/navios-options.token.mts","../src/tokens/reply.token.mts","../src/tokens/request.token.mts","../src/tokens/stream-adapter.token.mts","../src/tokens/xml-stream-adapter.token.mts","../src/decorators/endpoint.decorator.mts","../src/decorators/header.decorator.mts","../src/decorators/http-code.decorator.mts","../src/decorators/module.decorator.mts","../src/decorators/multipart.decorator.mts","../src/decorators/stream.decorator.mts","../src/decorators/use-guards.decorator.mts"],"sourcesContent":["import type { HttpMethod } from '@navios/builder'\nimport type { ClassTypeWithInstance, InjectionToken } from '@navios/di'\n\nimport type {\n AbstractHttpHandlerAdapterInterface,\n CanActivate,\n HttpHeader,\n} from '../interfaces/index.mjs'\n\nexport const EndpointMetadataKey = Symbol('EndpointMetadataKey')\n\nexport interface HandlerMetadata<Config = null> {\n classMethod: string\n url: string\n successStatusCode: number\n adapterToken:\n | InjectionToken<AbstractHttpHandlerAdapterInterface, undefined>\n | ClassTypeWithInstance<AbstractHttpHandlerAdapterInterface>\n | null\n headers: Partial<Record<HttpHeader, number | string | string[] | undefined>>\n httpMethod: HttpMethod\n config: Config\n guards: Set<\n ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>\n >\n customAttributes: Map<string | symbol, any>\n}\n\nexport function getAllEndpointMetadata(\n context: ClassMethodDecoratorContext | ClassDecoratorContext,\n): Set<HandlerMetadata<any>> {\n if (context.metadata) {\n const metadata = context.metadata[EndpointMetadataKey] as\n | Set<HandlerMetadata>\n | undefined\n if (metadata) {\n return metadata\n } else {\n context.metadata[EndpointMetadataKey] = new Set<HandlerMetadata<any>>()\n return context.metadata[EndpointMetadataKey] as Set<HandlerMetadata<any>>\n }\n }\n throw new Error('[Navios] Wrong environment.')\n}\n\nexport function getEndpointMetadata<Config = any>(\n target: Function,\n context: ClassMethodDecoratorContext,\n): HandlerMetadata<Config> {\n if (context.metadata) {\n const metadata = getAllEndpointMetadata(context)\n if (metadata) {\n const endpointMetadata = Array.from(metadata).find(\n (item) => item.classMethod === target.name,\n )\n if (endpointMetadata) {\n return endpointMetadata\n } else {\n const newMetadata: HandlerMetadata<Config> = {\n classMethod: target.name,\n url: '',\n successStatusCode: 200,\n adapterToken: null,\n headers: {},\n httpMethod: 'GET',\n // @ts-expect-error We are using a generic type here\n config: null,\n guards: new Set<\n | ClassTypeWithInstance<CanActivate>\n | InjectionToken<CanActivate, undefined>\n >(),\n customAttributes: new Map<string | symbol, any>(),\n }\n metadata.add(newMetadata)\n return newMetadata\n }\n }\n }\n throw new Error('[Navios] Wrong environment.')\n}\n","import type {\n ClassType,\n ClassTypeWithInstance,\n InjectionToken,\n} from '@navios/di'\n\nimport type { CanActivate } from '../interfaces/index.mjs'\nimport type { HandlerMetadata } from './handler.metadata.mjs'\n\nimport { getAllEndpointMetadata } from './handler.metadata.mjs'\n\nexport const ControllerMetadataKey = Symbol('ControllerMetadataKey')\n\nexport interface ControllerMetadata {\n endpoints: Set<HandlerMetadata>\n guards: Set<\n ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>\n >\n customAttributes: Map<string | symbol, any>\n}\n\nexport function getControllerMetadata(\n target: ClassType,\n context: ClassDecoratorContext,\n): ControllerMetadata {\n if (context.metadata) {\n const metadata = context.metadata[ControllerMetadataKey] as\n | ControllerMetadata\n | undefined\n if (metadata) {\n return metadata\n } else {\n const endpointsMetadata = getAllEndpointMetadata(context)\n const newMetadata: ControllerMetadata = {\n endpoints: endpointsMetadata,\n guards: new Set<\n | ClassTypeWithInstance<CanActivate>\n | InjectionToken<CanActivate, undefined>\n >(),\n customAttributes: new Map<string | symbol, any>(),\n }\n context.metadata[ControllerMetadataKey] = newMetadata\n // @ts-expect-error We add a custom metadata key to the target\n target[ControllerMetadataKey] = newMetadata\n return newMetadata\n }\n }\n throw new Error('[Navios] Wrong environment.')\n}\n\nexport function extractControllerMetadata(\n target: ClassType,\n): ControllerMetadata {\n // @ts-expect-error We add a custom metadata key to the target\n const metadata = target[ControllerMetadataKey] as\n | ControllerMetadata\n | undefined\n if (!metadata) {\n throw new Error(\n '[Navios] Controller metadata not found. Make sure to use @Controller decorator.',\n )\n }\n return metadata\n}\n\nexport function hasControllerMetadata(target: ClassType): boolean {\n // @ts-expect-error We add a custom metadata key to the target\n const metadata = target[ControllerMetadataKey] as\n | ControllerMetadata\n | undefined\n return !!metadata\n}\n","import type {\n ClassType,\n ClassTypeWithInstance,\n InjectionToken,\n} from '@navios/di'\n\nimport type { CanActivate } from '../index.mjs'\n\nexport const ModuleMetadataKey = Symbol('ControllerMetadataKey')\n\nexport interface ModuleMetadata {\n controllers: Set<ClassType>\n imports: Set<ClassType>\n guards: Set<\n ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>\n >\n customAttributes: Map<string | symbol, any>\n}\n\nexport function getModuleMetadata(\n target: ClassType,\n context: ClassDecoratorContext,\n): ModuleMetadata {\n if (context.metadata) {\n const metadata = context.metadata[ModuleMetadataKey] as\n | ModuleMetadata\n | undefined\n if (metadata) {\n return metadata\n } else {\n const newMetadata: ModuleMetadata = {\n controllers: new Set<ClassType>(),\n imports: new Set<ClassType>(),\n guards: new Set<\n | ClassTypeWithInstance<CanActivate>\n | InjectionToken<CanActivate, undefined>\n >(),\n customAttributes: new Map<string | symbol, any>(),\n }\n context.metadata[ModuleMetadataKey] = newMetadata\n // @ts-expect-error We add a custom metadata key to the target\n target[ModuleMetadataKey] = newMetadata\n return newMetadata\n }\n }\n throw new Error('[Navios] Wrong environment.')\n}\n\nexport function extractModuleMetadata(target: ClassType): ModuleMetadata {\n // @ts-expect-error We add a custom metadata key to the target\n const metadata = target[ModuleMetadataKey] as ModuleMetadata | undefined\n if (!metadata) {\n throw new Error(\n `[Navios] Module metadata not found for ${target.name}. Make sure to use @Module decorator.`,\n )\n }\n return metadata\n}\n\nexport function hasModuleMetadata(target: ClassType): boolean {\n // @ts-expect-error We add a custom metadata key to the target\n return !!target[ModuleMetadataKey]\n}\n","import type { ClassType } from '@navios/di'\n\n/**\n * Symbol used to identify Navios-managed classes (Controller, Module, MessageController, etc.).\n * This allows AttributeFactory to work with any Navios-managed class type generically.\n */\nexport const NaviosManagedMetadataKey = Symbol('NaviosManagedMetadataKey')\n\n/**\n * Interface for metadata that has custom attributes.\n * Used by Navios-managed classes (Controller, Module, MessageController, etc.).\n */\nexport interface ManagedMetadata {\n customAttributes: Map<string | symbol, any>\n}\n\n/**\n * Gets managed metadata from a class if it exists.\n * This is a generic function that works with any Navios-managed class type.\n *\n * @param target - The class to check\n * @returns The metadata with customAttributes, or null if not managed\n */\nexport function getManagedMetadata(target: ClassType): ManagedMetadata | null {\n // @ts-expect-error - Checking for managed metadata key\n if (target[NaviosManagedMetadataKey]) {\n // @ts-expect-error - Accessing managed metadata\n return target[NaviosManagedMetadataKey] as ManagedMetadata\n }\n return null\n}\n\n/**\n * Checks if a class is Navios-managed (has managed metadata).\n *\n * @param target - The class to check\n * @returns true if the class is Navios-managed\n */\nexport function hasManagedMetadata(target: ClassType): boolean {\n return getManagedMetadata(target) !== null\n}\n\n","import type { ClassType, InjectableScope } from '@navios/di'\n\nimport { Injectable, InjectionToken, Registry } from '@navios/di'\n\nimport { getControllerMetadata } from '../metadata/index.mjs'\n\n/**\n * Options for configuring a Navios controller.\n */\nexport interface ControllerOptions {\n /**\n * Guards to apply to all endpoints in this controller.\n * Guards are executed in reverse order (last guard first).\n */\n guards?: ClassType[] | Set<ClassType>\n /**\n * Registry to use for the controller.\n * Registry is used to store the controller and its endpoints.\n */\n registry?: Registry\n /**\n * Priority to use for the controller.\n * Priority is used to sort the controller in the registry.\n */\n priority?: number\n /**\n * Scope to use for the controller.\n * Scope is used to determine the scope of the controller.\n */\n scope?: InjectableScope\n}\n\n/**\n * Decorator that marks a class as a Navios controller.\n *\n * Controllers handle HTTP requests and define endpoints.\n * They are request-scoped by default, meaning a new instance is created for each request.\n *\n * @param options - Controller configuration options\n * @returns A class decorator\n *\n * @example\n * ```typescript\n * @Controller({ guards: [AuthGuard] })\n * export class UserController {\n * @Endpoint(getUserEndpoint)\n * async getUser(request: EndpointParams<typeof getUserEndpoint>) {\n * // Handle request\n * }\n * }\n * ```\n */\nexport function Controller({\n guards,\n registry,\n priority,\n scope,\n}: ControllerOptions = {}) {\n return function (target: ClassType, context: ClassDecoratorContext) {\n if (context.kind !== 'class') {\n throw new Error(\n '[Navios] @Controller decorator can only be used on classes.',\n )\n }\n const token = InjectionToken.create(target)\n if (context.metadata) {\n const controllerMetadata = getControllerMetadata(target, context)\n if (guards) {\n for (const guard of Array.from(guards).reverse()) {\n controllerMetadata.guards.add(guard)\n }\n }\n }\n return Injectable({\n token,\n registry,\n priority,\n scope,\n })(target, context)\n }\n}\n","import { InjectionToken } from '@navios/di'\n\nimport type { AbstractHttpHandlerAdapterInterface } from '../interfaces/index.mjs'\n\nexport const EndpointAdapterToken =\n InjectionToken.create<AbstractHttpHandlerAdapterInterface>(\n 'EndpointAdapterToken',\n )\n","import { InjectionToken } from '@navios/di'\n\nimport type { AbstractExecutionContext } from '../interfaces/index.mjs'\n\nexport const ExecutionContextInjectionToken = 'ExecutionContextInjectionToken'\n\nexport const ExecutionContext = InjectionToken.create<AbstractExecutionContext>(\n ExecutionContextInjectionToken,\n)\n","import { InjectionToken } from '@navios/di'\n\nimport type { AbstractHttpAdapterInterface } from '../interfaces/index.mjs'\n\nexport const HttpAdapterToken =\n InjectionToken.create<AbstractHttpAdapterInterface<any, any, any, any>>(\n 'HttpAdapterToken',\n )\n","import { InjectionToken } from '@navios/di'\n\nimport type { AbstractHttpHandlerAdapterInterface } from '../interfaces/index.mjs'\n\nexport const MultipartAdapterToken =\n InjectionToken.create<AbstractHttpHandlerAdapterInterface>(\n 'MultipartAdapterToken',\n )\n","import { InjectionToken } from '@navios/di'\n\nimport type { NaviosApplicationOptions } from '../navios.application.mjs'\n\nexport const NaviosOptionsToken =\n InjectionToken.create<NaviosApplicationOptions>('NaviosOptionsToken')\n","import { InjectionToken } from '@navios/di'\n\nexport const Reply = InjectionToken.create<any>('ReplyToken')\n","import { InjectionToken } from '@navios/di'\n\nexport const Request = InjectionToken.create<any>('RequestToken')\n","import { InjectionToken } from '@navios/di'\n\nimport type { AbstractHttpHandlerAdapterInterface } from '../interfaces/index.mjs'\n\nexport const StreamAdapterToken =\n InjectionToken.create<AbstractHttpHandlerAdapterInterface>(\n 'StreamAdapterToken',\n )\n","import { InjectionToken } from '@navios/di'\n\nimport type { AbstractHttpHandlerAdapterInterface } from '../interfaces/index.mjs'\n\nexport const XmlStreamAdapterToken =\n InjectionToken.create<AbstractHttpHandlerAdapterInterface>(\n 'XmlStreamAdapterToken',\n )\n","import type {\n BaseEndpointConfig,\n EndpointFunctionArgs,\n HttpMethod,\n Util_FlatObject,\n} from '@navios/builder'\nimport type { z, ZodType } from 'zod/v4'\n\nimport { ZodDiscriminatedUnion } from 'zod/v4'\n\nimport { getEndpointMetadata } from '../metadata/index.mjs'\nimport { EndpointAdapterToken } from '../tokens/index.mjs'\n\n/**\n * Extracts the typed parameters for an endpoint handler function.\n *\n * This utility type extracts URL parameters, query parameters, and request body\n * from an endpoint declaration and flattens them into a single object.\n *\n * @typeParam EndpointDeclaration - The endpoint declaration from @navios/builder\n *\n * @example\n * ```typescript\n * const getUserEndpoint = api.declareEndpoint({\n * method: 'get',\n * url: '/users/$userId',\n * querySchema: z.object({ include: z.string().optional() }),\n * responseSchema: z.object({ id: z.string(), name: z.string() }),\n * })\n *\n * @Endpoint(getUserEndpoint)\n * async getUser(request: EndpointParams<typeof getUserEndpoint>) {\n * // request.urlParams.userId is typed as string\n * // request.query.include is typed as string | undefined\n * }\n * ```\n */\nexport type EndpointParams<\n EndpointDeclaration extends {\n config: BaseEndpointConfig<any, any, any, any, any>\n },\n Url extends string = EndpointDeclaration['config']['url'],\n QuerySchema = EndpointDeclaration['config']['querySchema'],\n> = QuerySchema extends ZodType\n ? EndpointDeclaration['config']['requestSchema'] extends ZodType\n ? Util_FlatObject<\n EndpointFunctionArgs<\n Url,\n QuerySchema,\n EndpointDeclaration['config']['requestSchema'],\n true\n >\n >\n : Util_FlatObject<EndpointFunctionArgs<Url, QuerySchema, undefined, true>>\n : EndpointDeclaration['config']['requestSchema'] extends ZodType\n ? Util_FlatObject<\n EndpointFunctionArgs<\n Url,\n undefined,\n EndpointDeclaration['config']['requestSchema'],\n true\n >\n >\n : Util_FlatObject<EndpointFunctionArgs<Url, undefined, undefined, true>>\n\n/**\n * Extracts the typed return value for an endpoint handler function.\n *\n * This utility type extracts the response schema from an endpoint declaration\n * and returns the appropriate Promise type.\n *\n * @typeParam EndpointDeclaration - The endpoint declaration from @navios/builder\n *\n * @example\n * ```typescript\n * const getUserEndpoint = api.declareEndpoint({\n * method: 'get',\n * url: '/users/$userId',\n * responseSchema: z.object({ id: z.string(), name: z.string() }),\n * })\n *\n * @Endpoint(getUserEndpoint)\n * async getUser(request: EndpointParams<typeof getUserEndpoint>): EndpointResult<typeof getUserEndpoint> {\n * return { id: '1', name: 'John' } // Type-checked against responseSchema\n * }\n * ```\n */\nexport type EndpointResult<\n EndpointDeclaration extends {\n config: BaseEndpointConfig<any, any, any, any, any>\n },\n> =\n EndpointDeclaration['config']['responseSchema'] extends ZodDiscriminatedUnion<\n infer Options\n >\n ? Promise<z.input<Options[number]>>\n : Promise<z.input<EndpointDeclaration['config']['responseSchema']>>\n\n/**\n * Decorator that marks a method as an HTTP endpoint.\n *\n * The endpoint must be defined using @navios/builder's `declareEndpoint` method.\n * This ensures type safety and consistency between client and server.\n *\n * @param endpoint - The endpoint declaration from @navios/builder\n * @returns A method decorator\n *\n * @example\n * ```typescript\n * import { builder } from '@navios/builder'\n *\n * const api = builder()\n * const getUserEndpoint = api.declareEndpoint({\n * method: 'get',\n * url: '/users/$userId',\n * responseSchema: z.object({ id: z.string(), name: z.string() }),\n * })\n *\n * @Controller()\n * export class UserController {\n * @Endpoint(getUserEndpoint)\n * async getUser(request: EndpointParams<typeof getUserEndpoint>) {\n * const { userId } = request.urlParams\n * return { id: userId, name: 'John' }\n * }\n * }\n * ```\n */\nexport function Endpoint<\n Method extends HttpMethod = HttpMethod,\n Url extends string = string,\n QuerySchema = undefined,\n ResponseSchema extends ZodType = ZodType,\n RequestSchema = ZodType,\n Params = QuerySchema extends ZodType\n ? RequestSchema extends ZodType\n ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema, true>\n : EndpointFunctionArgs<Url, QuerySchema, undefined, true>\n : RequestSchema extends ZodType\n ? EndpointFunctionArgs<Url, undefined, RequestSchema, true>\n : EndpointFunctionArgs<Url, undefined, undefined, true>,\n>(endpoint: {\n config: BaseEndpointConfig<\n Method,\n Url,\n QuerySchema,\n ResponseSchema,\n RequestSchema\n >\n}): (\n target: (\n params: Params,\n ) => Promise<z.input<ResponseSchema>> | z.input<ResponseSchema>,\n context: ClassMethodDecoratorContext,\n) => void\nexport function Endpoint<\n Method extends HttpMethod = HttpMethod,\n Url extends string = string,\n QuerySchema = undefined,\n ResponseSchema extends ZodType = ZodType,\n RequestSchema = ZodType,\n>(endpoint: {\n config: BaseEndpointConfig<\n Method,\n Url,\n QuerySchema,\n ResponseSchema,\n RequestSchema\n >\n}): (\n target: () => Promise<z.input<ResponseSchema>> | z.input<ResponseSchema>,\n context: ClassMethodDecoratorContext,\n) => void\nexport function Endpoint<\n Method extends HttpMethod = HttpMethod,\n Url extends string = string,\n QuerySchema = undefined,\n ResponseSchema extends ZodType = ZodType,\n RequestSchema = ZodType,\n>(endpoint: {\n config: BaseEndpointConfig<\n Method,\n Url,\n QuerySchema,\n ResponseSchema,\n RequestSchema\n >\n}) {\n type Params = QuerySchema extends ZodType\n ? RequestSchema extends ZodType\n ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema, true>\n : EndpointFunctionArgs<Url, QuerySchema, undefined, true>\n : RequestSchema extends ZodType\n ? EndpointFunctionArgs<Url, undefined, RequestSchema, true>\n : EndpointFunctionArgs<Url, undefined, undefined, true>\n\n type Handler =\n | ((\n params: Params,\n ) => Promise<z.input<ResponseSchema>> | z.input<ResponseSchema>)\n | (() => Promise<z.input<ResponseSchema>> | z.input<ResponseSchema>)\n\n return (target: Handler, context: ClassMethodDecoratorContext) => {\n if (context.kind !== 'method') {\n throw new Error(\n '[Navios] Endpoint decorator can only be used on methods.',\n )\n }\n const config = endpoint.config\n if (context.metadata) {\n let endpointMetadata = getEndpointMetadata<BaseEndpointConfig>(\n target,\n context,\n )\n if (endpointMetadata.config && endpointMetadata.config.url) {\n throw new Error(\n `[Navios] Endpoint ${config.method} ${config.url} already exists. Please use a different method or url.`,\n )\n }\n // @ts-expect-error We don't need to set correctly in the metadata\n endpointMetadata.config = config\n endpointMetadata.adapterToken = EndpointAdapterToken\n endpointMetadata.classMethod = target.name\n endpointMetadata.httpMethod = config.method\n endpointMetadata.url = config.url\n }\n return target\n }\n}\n","import type { HttpHeader } from '../interfaces/index.mjs'\n\nimport { getEndpointMetadata } from '../metadata/index.mjs'\n\n/**\n * Decorator that sets a custom HTTP response header for an endpoint.\n * \n * @param name - The header name (e.g., 'Content-Type', 'Cache-Control')\n * @param value - The header value (string, number, or array of strings)\n * @returns A method decorator\n * \n * @example\n * ```typescript\n * @Controller()\n * export class UserController {\n * @Endpoint(getUserEndpoint)\n * @Header('Cache-Control', 'max-age=3600')\n * async getUser() {\n * return { id: '1', name: 'John' }\n * }\n * }\n * ```\n */\nexport function Header(name: HttpHeader, value: string | number | string[]) {\n return <T extends Function>(\n target: T,\n context: ClassMethodDecoratorContext,\n ) => {\n if (context.kind !== 'method') {\n throw new Error('[Navios] Header decorator can only be used on methods.')\n }\n const metadata = getEndpointMetadata(target, context)\n\n metadata.headers[name] = value\n\n return target\n }\n}\n","import { getEndpointMetadata } from '../metadata/index.mjs'\n\n/**\n * Decorator that sets a custom HTTP status code for successful responses.\n * \n * By default, endpoints return 200 OK. Use this decorator to return a different status code.\n * \n * @param code - The HTTP status code to return (e.g., 201, 204, 202)\n * @returns A method decorator\n * \n * @example\n * ```typescript\n * @Controller()\n * export class UserController {\n * @Endpoint(createUserEndpoint)\n * @HttpCode(201)\n * async createUser() {\n * return { id: '1', name: 'John' }\n * }\n * }\n * ```\n */\nexport function HttpCode(code: number) {\n return <T extends Function>(\n target: T,\n context: ClassMethodDecoratorContext,\n ) => {\n if (context.kind !== 'method') {\n throw new Error(\n '[Navios] HttpCode decorator can only be used on methods.',\n )\n }\n const metadata = getEndpointMetadata(target, context)\n metadata.successStatusCode = code\n\n return target\n }\n}\n","import type { ClassType, Registry } from '@navios/di'\n\nimport { Injectable, InjectableScope, InjectionToken } from '@navios/di'\n\nimport { getModuleMetadata } from '../metadata/index.mjs'\n\n/**\n * Options for configuring a Navios module.\n */\nexport interface ModuleOptions {\n /**\n * Controllers to register in this module.\n * Controllers handle HTTP requests and define endpoints.\n */\n controllers?: ClassType[] | Set<ClassType>\n /**\n * Other modules to import into this module.\n * Imported modules' controllers and services become available.\n */\n imports?: ClassType[] | Set<ClassType>\n /**\n * Guards to apply to all controllers in this module.\n * Guards are executed in reverse order (last guard first).\n */\n guards?: ClassType[] | Set<ClassType>\n /**\n * Priority to use for the module.\n * Priority is used to sort the module in the registry.\n */\n priority?: number\n /**\n * Registry to use for the module.\n * Registry is used to store the module and its controllers.\n */\n registry?: Registry\n}\n\n/**\n * Decorator that marks a class as a Navios module.\n *\n * Modules are the basic building blocks of a Navios application.\n * They organize controllers, services, and other modules into logical units.\n *\n * @param options - Module configuration options\n * @returns A class decorator\n *\n * @example\n * ```typescript\n * @Module({\n * controllers: [UserController, AuthController],\n * imports: [DatabaseModule],\n * guards: [AuthGuard],\n * })\n * export class AppModule {}\n * ```\n */\nexport function Module(\n {\n controllers = [],\n imports = [],\n guards = [],\n priority,\n registry,\n }: ModuleOptions = {\n controllers: [],\n imports: [],\n guards: [],\n },\n) {\n return (target: ClassType, context: ClassDecoratorContext) => {\n if (context.kind !== 'class') {\n throw new Error('[Navios] @Module decorator can only be used on classes.')\n }\n // Register the module in the service locator\n const token = InjectionToken.create(target)\n const moduleMetadata = getModuleMetadata(target, context)\n for (const controller of controllers) {\n moduleMetadata.controllers.add(controller)\n }\n for (const importedModule of imports) {\n moduleMetadata.imports.add(importedModule)\n }\n for (const guard of Array.from(guards).reverse()) {\n moduleMetadata.guards.add(guard)\n }\n\n return Injectable({\n token,\n scope: InjectableScope.Singleton,\n priority,\n registry,\n })(target, context)\n }\n}\n","import type {\n BaseEndpointConfig,\n EndpointFunctionArgs,\n HttpMethod,\n Util_FlatObject,\n} from '@navios/builder'\nimport type { z, ZodObject, ZodType } from 'zod/v4'\n\nimport { ZodDiscriminatedUnion } from 'zod/v4'\n\nimport { getEndpointMetadata } from '../metadata/index.mjs'\nimport { MultipartAdapterToken } from '../tokens/index.mjs'\n\n/**\n * Extracts the typed parameters for a multipart endpoint handler function.\n *\n * Similar to `EndpointParams`, but specifically for multipart/form-data endpoints.\n *\n * @typeParam EndpointDeclaration - The endpoint declaration from @navios/builder\n */\nexport type MultipartParams<\n EndpointDeclaration extends {\n config: BaseEndpointConfig<any, any, any, any, any>\n },\n Url extends string = EndpointDeclaration['config']['url'],\n QuerySchema = EndpointDeclaration['config']['querySchema'],\n> = QuerySchema extends ZodObject\n ? EndpointDeclaration['config']['requestSchema'] extends ZodType\n ? Util_FlatObject<\n EndpointFunctionArgs<\n Url,\n QuerySchema,\n EndpointDeclaration['config']['requestSchema'],\n true\n >\n >\n : Util_FlatObject<EndpointFunctionArgs<Url, QuerySchema, undefined, true>>\n : EndpointDeclaration['config']['requestSchema'] extends ZodType\n ? Util_FlatObject<\n EndpointFunctionArgs<\n Url,\n undefined,\n EndpointDeclaration['config']['requestSchema'],\n true\n >\n >\n : Util_FlatObject<EndpointFunctionArgs<Url, undefined, undefined, true>>\n\n/**\n * Extracts the typed return value for a multipart endpoint handler function.\n *\n * @typeParam EndpointDeclaration - The endpoint declaration from @navios/builder\n */\nexport type MultipartResult<\n EndpointDeclaration extends {\n config: BaseEndpointConfig<any, any, any, any, any>\n },\n> =\n EndpointDeclaration['config']['responseSchema'] extends ZodDiscriminatedUnion<\n infer Options\n >\n ? Promise<z.input<Options[number]>>\n : Promise<z.input<EndpointDeclaration['config']['responseSchema']>>\n\n/**\n * Decorator that marks a method as a multipart/form-data endpoint.\n *\n * Use this decorator for endpoints that handle file uploads or form data.\n * The endpoint must be defined using @navios/builder's `declareMultipart` method.\n *\n * @param endpoint - The multipart endpoint declaration from @navios/builder\n * @returns A method decorator\n *\n * @example\n * ```typescript\n * const uploadFileEndpoint = api.declareMultipart({\n * method: 'post',\n * url: '/upload',\n * requestSchema: z.object({ file: z.instanceof(File) }),\n * responseSchema: z.object({ url: z.string() }),\n * })\n *\n * @Controller()\n * export class FileController {\n * @Multipart(uploadFileEndpoint)\n * async uploadFile(request: MultipartParams<typeof uploadFileEndpoint>) {\n * const { file } = request.data\n * // Handle file upload\n * return { url: 'https://example.com/file.jpg' }\n * }\n * }\n * ```\n */\nexport function Multipart<\n Method extends HttpMethod = HttpMethod,\n Url extends string = string,\n QuerySchema = undefined,\n ResponseSchema extends ZodType = ZodType,\n RequestSchema = ZodType,\n Params = QuerySchema extends ZodObject\n ? RequestSchema extends ZodType\n ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema, true>\n : EndpointFunctionArgs<Url, QuerySchema, undefined, true>\n : RequestSchema extends ZodType\n ? EndpointFunctionArgs<Url, undefined, RequestSchema, true>\n : EndpointFunctionArgs<Url, undefined, undefined, true>,\n>(endpoint: {\n config: BaseEndpointConfig<\n Method,\n Url,\n QuerySchema,\n ResponseSchema,\n RequestSchema\n >\n}): (\n target: (\n params: Params,\n ) => Promise<z.input<ResponseSchema>> | z.input<ResponseSchema>,\n context: ClassMethodDecoratorContext,\n) => void\nexport function Multipart<\n Method extends HttpMethod = HttpMethod,\n Url extends string = string,\n QuerySchema = undefined,\n ResponseSchema extends ZodType = ZodType,\n RequestSchema = ZodType,\n>(endpoint: {\n config: BaseEndpointConfig<\n Method,\n Url,\n QuerySchema,\n ResponseSchema,\n RequestSchema\n >\n}): (\n target: () => Promise<z.input<ResponseSchema>> | z.input<ResponseSchema>,\n context: ClassMethodDecoratorContext,\n) => void\nexport function Multipart<\n Method extends HttpMethod = HttpMethod,\n Url extends string = string,\n QuerySchema = undefined,\n ResponseSchema extends ZodType = ZodType,\n RequestSchema = ZodType,\n>(endpoint: {\n config: BaseEndpointConfig<\n Method,\n Url,\n QuerySchema,\n ResponseSchema,\n RequestSchema\n >\n}) {\n type Params = QuerySchema extends ZodObject\n ? RequestSchema extends ZodType\n ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema, true>\n : EndpointFunctionArgs<Url, QuerySchema, undefined, true>\n : RequestSchema extends ZodType\n ? EndpointFunctionArgs<Url, undefined, RequestSchema, true>\n : EndpointFunctionArgs<Url, undefined, undefined, true>\n\n type Handler =\n | ((\n params: Params,\n ) => Promise<z.input<ResponseSchema>> | z.input<ResponseSchema>)\n | (() => Promise<z.input<ResponseSchema>> | z.input<ResponseSchema>)\n\n return (target: Handler, context: ClassMethodDecoratorContext) => {\n if (context.kind !== 'method') {\n throw new Error(\n '[Navios] Endpoint decorator can only be used on methods.',\n )\n }\n const config = endpoint.config\n if (context.metadata) {\n let endpointMetadata = getEndpointMetadata<BaseEndpointConfig>(\n target,\n context,\n )\n if (endpointMetadata.config && endpointMetadata.config.url) {\n throw new Error(\n `[Navios] Endpoint ${config.method} ${config.url} already exists. Please use a different method or url.`,\n )\n }\n // @ts-expect-error We don't need to set correctly in the metadata\n endpointMetadata.config = config\n endpointMetadata.adapterToken = MultipartAdapterToken\n endpointMetadata.classMethod = target.name\n endpointMetadata.httpMethod = config.method\n endpointMetadata.url = config.url\n }\n return target\n }\n}\n","import type {\n BaseStreamConfig,\n EndpointFunctionArgs,\n HttpMethod,\n Util_FlatObject,\n} from '@navios/builder'\nimport type { ZodObject, ZodType } from 'zod/v4'\n\nimport { getEndpointMetadata } from '../metadata/index.mjs'\nimport { StreamAdapterToken } from '../tokens/index.mjs'\n\n/**\n * Extracts the typed parameters for a stream endpoint handler function.\n *\n * Similar to `EndpointParams`, but specifically for streaming endpoints.\n *\n * @typeParam EndpointDeclaration - The stream endpoint declaration from @navios/builder\n */\nexport type StreamParams<\n EndpointDeclaration extends {\n config: BaseStreamConfig<any, any, any, any>\n },\n Url extends string = EndpointDeclaration['config']['url'],\n QuerySchema = EndpointDeclaration['config']['querySchema'],\n> = QuerySchema extends ZodObject\n ? EndpointDeclaration['config']['requestSchema'] extends ZodType\n ? Util_FlatObject<\n EndpointFunctionArgs<\n Url,\n QuerySchema,\n EndpointDeclaration['config']['requestSchema'],\n true\n >\n >\n : Util_FlatObject<EndpointFunctionArgs<Url, QuerySchema, undefined, true>>\n : EndpointDeclaration['config']['requestSchema'] extends ZodType\n ? Util_FlatObject<\n EndpointFunctionArgs<\n Url,\n undefined,\n EndpointDeclaration['config']['requestSchema'],\n true\n >\n >\n : Util_FlatObject<EndpointFunctionArgs<Url, undefined, undefined, true>>\n\n/**\n * Decorator that marks a method as a streaming endpoint.\n *\n * Use this decorator for endpoints that stream data (e.g., file downloads, SSE).\n * The endpoint must be defined using @navios/builder's `declareStream` method.\n *\n * @param endpoint - The stream endpoint declaration from @navios/builder\n * @returns A method decorator\n *\n * @example\n * ```typescript\n * const downloadFileEndpoint = api.declareStream({\n * method: 'get',\n * url: '/files/$fileId',\n * })\n *\n * @Controller()\n * export class FileController {\n * @Stream(downloadFileEndpoint)\n * async downloadFile(request: StreamParams<typeof downloadFileEndpoint>, reply: any) {\n * const { fileId } = request.urlParams\n * // Stream file data to reply\n * }\n * }\n * ```\n */\nexport function Stream<\n Method extends HttpMethod = HttpMethod,\n Url extends string = string,\n QuerySchema = undefined,\n RequestSchema = ZodType,\n Params = QuerySchema extends ZodObject\n ? RequestSchema extends ZodType\n ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema, true>\n : EndpointFunctionArgs<Url, QuerySchema, undefined, true>\n : RequestSchema extends ZodType\n ? EndpointFunctionArgs<Url, undefined, RequestSchema, true>\n : EndpointFunctionArgs<Url, undefined, undefined, true>,\n>(endpoint: {\n config: BaseStreamConfig<Method, Url, QuerySchema, RequestSchema>\n}): (\n target: (params: Params, reply: any) => any,\n context: ClassMethodDecoratorContext,\n) => void\n// Bun doesn't support reply parameter\nexport function Stream<\n Method extends HttpMethod = HttpMethod,\n Url extends string = string,\n QuerySchema = undefined,\n RequestSchema = ZodType,\n Params = QuerySchema extends ZodObject\n ? RequestSchema extends ZodType\n ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema, true>\n : EndpointFunctionArgs<Url, QuerySchema, undefined, true>\n : RequestSchema extends ZodType\n ? EndpointFunctionArgs<Url, undefined, RequestSchema, true>\n : EndpointFunctionArgs<Url, undefined, undefined, true>,\n>(endpoint: {\n config: BaseStreamConfig<Method, Url, QuerySchema, RequestSchema>\n}): (\n target: (params: Params) => any,\n context: ClassMethodDecoratorContext,\n) => void\nexport function Stream<\n Method extends HttpMethod = HttpMethod,\n Url extends string = string,\n QuerySchema = undefined,\n RequestSchema = ZodType,\n>(endpoint: {\n config: BaseStreamConfig<Method, Url, QuerySchema, RequestSchema>\n}): (target: () => any, context: ClassMethodDecoratorContext) => void\nexport function Stream<\n Method extends HttpMethod = HttpMethod,\n Url extends string = string,\n QuerySchema = undefined,\n RequestSchema = ZodType,\n>(endpoint: {\n config: BaseStreamConfig<Method, Url, QuerySchema, RequestSchema>\n}) {\n type Params = QuerySchema extends ZodObject\n ? RequestSchema extends ZodType\n ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema, true>\n : EndpointFunctionArgs<Url, QuerySchema, undefined, true>\n : RequestSchema extends ZodType\n ? EndpointFunctionArgs<Url, undefined, RequestSchema, true>\n : EndpointFunctionArgs<Url, undefined, undefined, true>\n\n type Handler =\n | ((params: Params, reply: any) => any)\n | ((params: Params) => any)\n | (() => any)\n\n return (target: Handler, context: ClassMethodDecoratorContext) => {\n if (context.kind !== 'method') {\n throw new Error(\n '[Navios] Endpoint decorator can only be used on methods.',\n )\n }\n const config = endpoint.config\n if (context.metadata) {\n let endpointMetadata = getEndpointMetadata<BaseStreamConfig>(\n target,\n context,\n )\n if (endpointMetadata.config && endpointMetadata.config.url) {\n throw new Error(\n `[Navios] Endpoint ${config.method} ${config.url} already exists. Please use a different method or url.`,\n )\n }\n // @ts-expect-error We don't need to set correctly in the metadata\n endpointMetadata.config = config\n endpointMetadata.adapterToken = StreamAdapterToken\n endpointMetadata.classMethod = target.name\n endpointMetadata.httpMethod = config.method\n endpointMetadata.url = config.url\n }\n return target\n }\n}\n","import type {\n ClassType,\n ClassTypeWithInstance,\n InjectionToken,\n} from '@navios/di'\n\nimport type { CanActivate } from '../interfaces/index.mjs'\n\nimport {\n getControllerMetadata,\n getEndpointMetadata,\n} from '../metadata/index.mjs'\n\n/**\n * Decorator that applies guards to a controller or endpoint.\n * \n * Guards are used for authentication, authorization, and request validation.\n * They implement the `CanActivate` interface and are executed before the endpoint handler.\n * Guards can be applied at the module, controller, or endpoint level.\n * \n * @param guards - Guard classes or injection tokens to apply\n * @returns A class or method decorator\n * \n * @example\n * ```typescript\n * // Apply to a controller\n * @Controller()\n * @UseGuards(AuthGuard, RoleGuard)\n * export class UserController {\n * @Endpoint(getUserEndpoint)\n * async getUser() { }\n * }\n * \n * // Apply to a specific endpoint\n * @Controller()\n * export class UserController {\n * @Endpoint(getUserEndpoint)\n * @UseGuards(AuthGuard)\n * async getUser() { }\n * }\n * ```\n */\nexport function UseGuards(\n ...guards: (\n | ClassTypeWithInstance<CanActivate>\n | InjectionToken<CanActivate, undefined>\n )[]\n) {\n return function <T extends Function>(\n target: T,\n context: ClassMethodDecoratorContext | ClassDecoratorContext,\n ): T {\n if (context.kind === 'class') {\n const controllerMetadata = getControllerMetadata(\n target as unknown as ClassType,\n context,\n )\n for (const guard of guards.reverse()) {\n controllerMetadata.guards.add(guard)\n }\n } else if (context.kind === 'method') {\n const endpointMetadata = getEndpointMetadata(target, context)\n for (const guard of guards.reverse()) {\n endpointMetadata.guards.add(guard)\n }\n } else {\n throw new Error(\n '[Navios] @UseGuards decorator can only be used on classes or methods.',\n )\n }\n return target\n }\n}\n"],"mappings":";;;;AASA,MAAaA,sBAAsBC,OAAO,sBAAA;AAmB1C,SAAgBC,uBACdC,SAA4D;AAE5D,KAAIA,QAAQC,UAAU;EACpB,MAAMA,WAAWD,QAAQC,SAASJ;AAGlC,MAAII,SACF,QAAOA;OACF;AACLD,WAAQC,SAASJ,uCAAuB,IAAIK,KAAAA;AAC5C,UAAOF,QAAQC,SAASJ;;;AAG5B,OAAM,IAAIM,MAAM,8BAAA;;AAGlB,SAAgBC,oBACdC,QACAL,SAAoC;AAEpC,KAAIA,QAAQC,UAAU;EACpB,MAAMA,WAAWF,uBAAuBC,QAAAA;AACxC,MAAIC,UAAU;GACZ,MAAMK,mBAAmBC,MAAMC,KAAKP,SAAAA,CAAUQ,MAC3CC,SAASA,KAAKC,gBAAgBN,OAAOO,KAAI;AAE5C,OAAIN,iBACF,QAAOA;QACF;IACL,MAAMO,cAAuC;KAC3CF,aAAaN,OAAOO;KACpBE,KAAK;KACLC,mBAAmB;KACnBC,cAAc;KACdC,SAAS,EAAC;KACVC,YAAY;KAEZC,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AAUE,iBAAiBF,OAAOG,IACrD,OAAM,IAAIJ,MACR,qBAAqBC,OAAOI,OAAO,GAAGJ,OAAOG,IAAI,wDAAuD;AAI5GD,oBAAiBF,SAASA;AAC1BE,oBAAiBG,eAAeZ;AAChCS,oBAAiBI,cAAcV,OAAOW;AACtCL,oBAAiBM,aAAaR,OAAOI;AACrCF,oBAAiBC,MAAMH,OAAOG;;AAEhC,SAAOP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GCxHX,SAAgBe,UACd,GAAGC,QAGA;AAEH,QAAO,SACLC,QACAC,SAA4D;AAE5D,MAAIA,QAAQC,SAAS,SAAS;GAC5B,MAAMC,qBAAqBP,sBACzBI,QACAC,QAAAA;AAEF,QAAK,MAAMG,SAASL,OAAOM,SAAO,CAChCF,oBAAmBJ,OAAOO,IAAIF,MAAAA;aAEvBH,QAAQC,SAAS,UAAU;GACpC,MAAMK,mBAAmBV,oBAAoBG,QAAQC,QAAAA;AACrD,QAAK,MAAMG,SAASL,OAAOM,SAAO,CAChCE,kBAAiBR,OAAOO,IAAIF,MAAAA;QAG9B,OAAM,IAAII,MACR,wEAAA;AAGJ,SAAOR"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@navios/core",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "Oleksandr Hanzha",
|
|
6
6
|
"email": "alex@granted.name"
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"@navios/builder": "^0.5.
|
|
15
|
+
"@navios/builder": "^0.5.3",
|
|
16
16
|
"zod": "^3.25.0 || ^4.0.0"
|
|
17
17
|
},
|
|
18
18
|
"typings": "./lib/index.d.mts",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
}
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@navios/builder": "^0.5.
|
|
54
|
+
"@navios/builder": "^0.5.3",
|
|
55
55
|
"@types/supertest": "^6.0.3",
|
|
56
56
|
"supertest": "^7.1.4",
|
|
57
57
|
"tsx": "^4.21.0",
|
|
@@ -59,6 +59,6 @@
|
|
|
59
59
|
"zod": "^4.2.1"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@navios/di": "^0.9.
|
|
62
|
+
"@navios/di": "^0.9.1"
|
|
63
63
|
}
|
|
64
64
|
}
|
|
@@ -14,6 +14,10 @@ import {
|
|
|
14
14
|
hasControllerMetadata,
|
|
15
15
|
hasModuleMetadata,
|
|
16
16
|
} from './metadata/index.mjs'
|
|
17
|
+
import {
|
|
18
|
+
getManagedMetadata,
|
|
19
|
+
hasManagedMetadata,
|
|
20
|
+
} from './metadata/navios-managed.metadata.mjs'
|
|
17
21
|
|
|
18
22
|
/**
|
|
19
23
|
* Type for a class attribute decorator without a value.
|
|
@@ -139,17 +143,29 @@ export class AttributeFactory {
|
|
|
139
143
|
context.kind === 'class' && hasControllerMetadata(target as ClassType)
|
|
140
144
|
const isModule =
|
|
141
145
|
context.kind === 'class' && hasModuleMetadata(target as ClassType)
|
|
142
|
-
|
|
146
|
+
const isManaged =
|
|
147
|
+
context.kind === 'class' && hasManagedMetadata(target as ClassType)
|
|
148
|
+
if (context.kind === 'class' && !isController && !isModule && !isManaged) {
|
|
143
149
|
throw new Error(
|
|
144
|
-
'[Navios] Attribute can only be applied to classes with @Controller
|
|
150
|
+
'[Navios] Attribute can only be applied to classes with @Controller, @Module, or other Navios-managed decorators',
|
|
145
151
|
)
|
|
146
152
|
}
|
|
147
153
|
let metadata =
|
|
148
154
|
context.kind === 'class'
|
|
149
155
|
? isController
|
|
150
156
|
? getControllerMetadata(target as any, context)
|
|
151
|
-
:
|
|
157
|
+
: isModule
|
|
158
|
+
? getModuleMetadata(target as any, context)
|
|
159
|
+
: isManaged
|
|
160
|
+
? getManagedMetadata(target as any)!
|
|
161
|
+
: null
|
|
152
162
|
: getEndpointMetadata(target, context)
|
|
163
|
+
|
|
164
|
+
if (!metadata) {
|
|
165
|
+
throw new Error(
|
|
166
|
+
'[Navios] Could not determine metadata for attribute target',
|
|
167
|
+
)
|
|
168
|
+
}
|
|
153
169
|
if (schema) {
|
|
154
170
|
const validatedValue = schema.safeParse(value)
|
|
155
171
|
if (!validatedValue.success) {
|
|
@@ -13,10 +13,12 @@ import type {
|
|
|
13
13
|
} from '../index.mjs'
|
|
14
14
|
|
|
15
15
|
import {
|
|
16
|
+
AttributeFactory,
|
|
16
17
|
Controller,
|
|
17
18
|
Endpoint,
|
|
18
19
|
Header,
|
|
19
20
|
HttpCode,
|
|
21
|
+
Injectable,
|
|
20
22
|
Module,
|
|
21
23
|
Multipart,
|
|
22
24
|
Stream,
|
|
@@ -259,10 +261,10 @@ describe('Legacy Decorators Type Safety', () => {
|
|
|
259
261
|
test('should enforce correct parameter type', () => {
|
|
260
262
|
@Controller()
|
|
261
263
|
class FileController {
|
|
264
|
+
// @ts-expect-error - legacy decorator is not typed
|
|
262
265
|
@Stream(downloadFileEndpoint)
|
|
263
266
|
async downloadFile(
|
|
264
267
|
request: StreamParams<typeof downloadFileEndpoint>,
|
|
265
|
-
reply: any,
|
|
266
268
|
): Promise<void> {
|
|
267
269
|
// TypeScript should infer:
|
|
268
270
|
// - request.urlParams.fileId: string | number
|
|
@@ -277,17 +279,20 @@ describe('Legacy Decorators Type Safety', () => {
|
|
|
277
279
|
expectTypeOf(FileController).toBeConstructibleWith()
|
|
278
280
|
})
|
|
279
281
|
|
|
280
|
-
test('should
|
|
282
|
+
test('should work without reply parameter (Bun compatibility)', () => {
|
|
281
283
|
@Controller()
|
|
282
284
|
class FileController {
|
|
283
|
-
// @ts-expect-error -
|
|
285
|
+
// @ts-expect-error - legacy decorator is not typed
|
|
284
286
|
@Stream(downloadFileEndpoint)
|
|
285
287
|
async downloadFile(
|
|
286
288
|
request: StreamParams<typeof downloadFileEndpoint>,
|
|
287
289
|
): Promise<void> {
|
|
288
|
-
// Stream methods
|
|
290
|
+
// Stream methods can work without reply parameter (for Bun)
|
|
291
|
+
expectTypeOf(request.urlParams.fileId).toEqualTypeOf<string>()
|
|
289
292
|
}
|
|
290
293
|
}
|
|
294
|
+
|
|
295
|
+
expectTypeOf(FileController).toBeConstructibleWith()
|
|
291
296
|
})
|
|
292
297
|
})
|
|
293
298
|
|
|
@@ -372,6 +377,109 @@ describe('Legacy Decorators Type Safety', () => {
|
|
|
372
377
|
})
|
|
373
378
|
})
|
|
374
379
|
|
|
380
|
+
describe('Injectable decorator', () => {
|
|
381
|
+
test('should work with services', () => {
|
|
382
|
+
@Injectable()
|
|
383
|
+
class UserService {
|
|
384
|
+
getUser(id: string) {
|
|
385
|
+
return { id, name: 'John' }
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
expectTypeOf(UserService).toBeConstructibleWith()
|
|
390
|
+
})
|
|
391
|
+
|
|
392
|
+
test('should work with controller dependencies', () => {
|
|
393
|
+
@Injectable()
|
|
394
|
+
class UserService {
|
|
395
|
+
getUser(id: string) {
|
|
396
|
+
return { id, name: 'John' }
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
@Controller()
|
|
401
|
+
class UserController {
|
|
402
|
+
constructor(private readonly userService: UserService) {}
|
|
403
|
+
|
|
404
|
+
@Endpoint(getUserEndpoint)
|
|
405
|
+
async getUser(
|
|
406
|
+
request: EndpointParams<typeof getUserEndpoint>,
|
|
407
|
+
): EndpointResult<typeof getUserEndpoint> {
|
|
408
|
+
return this.userService.getUser(request.urlParams.userId.toString())
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
expectTypeOf(UserController).toBeConstructibleWith(
|
|
413
|
+
{} as InstanceType<typeof UserService>,
|
|
414
|
+
)
|
|
415
|
+
})
|
|
416
|
+
})
|
|
417
|
+
|
|
418
|
+
describe('AttributeFactory', () => {
|
|
419
|
+
test('should create simple attribute for controllers', () => {
|
|
420
|
+
const Public = AttributeFactory.createAttribute(Symbol.for('Public'))
|
|
421
|
+
|
|
422
|
+
// Note: In legacy decorators, decorators are applied bottom-to-top
|
|
423
|
+
// So @Controller() must be at the bottom to run first
|
|
424
|
+
@Public()
|
|
425
|
+
@Controller()
|
|
426
|
+
class PublicController {
|
|
427
|
+
@Endpoint(getUserEndpoint)
|
|
428
|
+
async getUser(
|
|
429
|
+
request: EndpointParams<typeof getUserEndpoint>,
|
|
430
|
+
): EndpointResult<typeof getUserEndpoint> {
|
|
431
|
+
return { id: '1', name: 'John' }
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
expectTypeOf(PublicController).toBeConstructibleWith()
|
|
436
|
+
expectTypeOf(Public.token).toEqualTypeOf<symbol>()
|
|
437
|
+
})
|
|
438
|
+
|
|
439
|
+
test('should create attribute with schema for endpoints', () => {
|
|
440
|
+
const RateLimit = AttributeFactory.createAttribute(
|
|
441
|
+
Symbol.for('RateLimit'),
|
|
442
|
+
z.object({ requests: z.number(), window: z.number() }),
|
|
443
|
+
)
|
|
444
|
+
|
|
445
|
+
@Controller()
|
|
446
|
+
class RateLimitedController {
|
|
447
|
+
// Note: For method decorators, @Endpoint must be at the bottom
|
|
448
|
+
// @ts-expect-error - legacy decorator is not typed correctly
|
|
449
|
+
@RateLimit({ requests: 100, window: 60000 })
|
|
450
|
+
@Endpoint(getUserEndpoint)
|
|
451
|
+
async getUser(
|
|
452
|
+
request: EndpointParams<typeof getUserEndpoint>,
|
|
453
|
+
): EndpointResult<typeof getUserEndpoint> {
|
|
454
|
+
return { id: '1', name: 'John' }
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
expectTypeOf(RateLimitedController).toBeConstructibleWith()
|
|
459
|
+
expectTypeOf(RateLimit.token).toEqualTypeOf<symbol>()
|
|
460
|
+
expectTypeOf(RateLimit.schema).toBeObject()
|
|
461
|
+
})
|
|
462
|
+
|
|
463
|
+
test('should create attribute for modules', () => {
|
|
464
|
+
const ApiVersion = AttributeFactory.createAttribute(
|
|
465
|
+
Symbol.for('ApiVersion'),
|
|
466
|
+
z.string(),
|
|
467
|
+
)
|
|
468
|
+
|
|
469
|
+
@Controller()
|
|
470
|
+
class VersionedController {}
|
|
471
|
+
|
|
472
|
+
// Note: In legacy decorators, @Module must be at the bottom
|
|
473
|
+
@ApiVersion('v2')
|
|
474
|
+
@Module({
|
|
475
|
+
controllers: [VersionedController],
|
|
476
|
+
})
|
|
477
|
+
class VersionedModule {}
|
|
478
|
+
|
|
479
|
+
expectTypeOf(VersionedModule).toBeConstructibleWith()
|
|
480
|
+
})
|
|
481
|
+
})
|
|
482
|
+
|
|
375
483
|
describe('Integration test - full controller', () => {
|
|
376
484
|
test('should work with all decorators together', () => {
|
|
377
485
|
@Controller({
|