@navios/core 0.7.1 → 0.8.0
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 +31 -0
- package/lib/{index-DW9EPAE6.d.mts → index-BDNl7j1G.d.cts} +515 -346
- package/lib/index-BDNl7j1G.d.cts.map +1 -0
- package/lib/{index-pHp-dIGt.d.cts → index-BoP0cWT6.d.mts} +515 -346
- package/lib/index-BoP0cWT6.d.mts.map +1 -0
- package/lib/index.cjs +12 -3
- 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 +1 -1
- package/lib/legacy-compat/index.cjs.map +1 -1
- package/lib/legacy-compat/index.d.cts +1 -1
- package/lib/legacy-compat/index.d.mts +1 -1
- package/lib/legacy-compat/index.mjs +1 -1
- package/lib/legacy-compat/index.mjs.map +1 -1
- package/lib/{src-QnxR5b7c.cjs → src-B6eISODM.cjs} +465 -47
- package/lib/src-B6eISODM.cjs.map +1 -0
- package/lib/{src-DyvCDuKO.mjs → src-gBAChVRL.mjs} +445 -45
- package/lib/src-gBAChVRL.mjs.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-B6q_N0sf.cjs → use-guards.decorator-COR-9mZY.cjs} +20 -94
- package/lib/use-guards.decorator-COR-9mZY.cjs.map +1 -0
- package/lib/{use-guards.decorator-kZ3lNK8v.mjs → use-guards.decorator-CUww54Nt.mjs} +14 -94
- package/lib/use-guards.decorator-CUww54Nt.mjs.map +1 -0
- package/package.json +4 -4
- package/src/__tests__/controller-resolver.spec.mts +223 -0
- package/src/__tests__/controller.spec.mts +1 -1
- package/src/decorators/controller.decorator.mts +11 -6
- package/src/decorators/endpoint.decorator.mts +60 -12
- package/src/decorators/multipart.decorator.mts +67 -24
- package/src/decorators/stream.decorator.mts +65 -24
- package/src/interfaces/abstract-http-handler-adapter.interface.mts +31 -1
- package/src/legacy-compat/decorators/endpoint.decorator.mts +1 -1
- package/src/legacy-compat/decorators/multipart.decorator.mts +1 -1
- package/src/legacy-compat/decorators/stream.decorator.mts +1 -1
- package/src/logger/logger.service.mts +0 -2
- package/src/navios.application.mts +14 -0
- package/src/navios.factory.mts +19 -0
- package/src/services/guard-runner.service.mts +46 -9
- package/src/services/index.mts +1 -0
- package/src/services/instance-resolver.service.mts +186 -0
- package/src/stores/request-id.store.mts +45 -3
- package/src/tokens/index.mts +1 -0
- package/src/tokens/navios-options.token.mts +6 -0
- package/lib/index-DW9EPAE6.d.mts.map +0 -1
- package/lib/index-pHp-dIGt.d.cts.map +0 -1
- package/lib/src-DyvCDuKO.mjs.map +0 -1
- package/lib/src-QnxR5b7c.cjs.map +0 -1
- package/lib/use-guards.decorator-B6q_N0sf.cjs.map +0 -1
- package/lib/use-guards.decorator-kZ3lNK8v.mjs.map +0 -1
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import * as _navios_di0 from "@navios/di";
|
|
2
|
-
import { AnyInjectableType, ClassType, ClassTypeWithInstance, Container, FactoryContext, FactoryInjectionToken, InjectionToken, ScopedContainer } from "@navios/di";
|
|
2
|
+
import { AnyInjectableType, ClassType, ClassTypeWithInstance, Container, FactoryContext, FactoryInjectionToken, InjectionToken, Registry, ScopedContainer } from "@navios/di";
|
|
3
3
|
import z, { ZodDiscriminatedUnion, ZodObject, ZodType, z as z$1 } from "zod/v4";
|
|
4
4
|
import { BaseEndpointConfig, BaseStreamConfig, EndpointFunctionArgs, HttpMethod, Util_FlatObject } from "@navios/builder";
|
|
5
5
|
import { InspectOptions } from "util";
|
|
6
6
|
import { OutgoingHttpHeaders } from "http";
|
|
7
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
8
7
|
|
|
9
8
|
//#region src/config/utils/helpers.d.mts
|
|
10
9
|
declare function envInt(key: keyof NodeJS.ProcessEnv, defaultValue: number): number;
|
|
@@ -220,6 +219,11 @@ interface ControllerOptions {
|
|
|
220
219
|
* Guards are executed in reverse order (last guard first).
|
|
221
220
|
*/
|
|
222
221
|
guards?: ClassType[] | Set<ClassType>;
|
|
222
|
+
/**
|
|
223
|
+
* Registry to use for the controller.
|
|
224
|
+
* Registry is used to store the controller and its endpoints.
|
|
225
|
+
*/
|
|
226
|
+
registry?: Registry;
|
|
223
227
|
}
|
|
224
228
|
/**
|
|
225
229
|
* Decorator that marks a class as a Navios controller.
|
|
@@ -242,7 +246,8 @@ interface ControllerOptions {
|
|
|
242
246
|
* ```
|
|
243
247
|
*/
|
|
244
248
|
declare function Controller({
|
|
245
|
-
guards
|
|
249
|
+
guards,
|
|
250
|
+
registry
|
|
246
251
|
}?: ControllerOptions): (target: ClassType, context: ClassDecoratorContext) => ClassType;
|
|
247
252
|
//#endregion
|
|
248
253
|
//#region src/decorators/endpoint.decorator.d.mts
|
|
@@ -328,9 +333,12 @@ type EndpointResult<EndpointDeclaration extends {
|
|
|
328
333
|
* }
|
|
329
334
|
* ```
|
|
330
335
|
*/
|
|
336
|
+
declare function Endpoint<Method extends HttpMethod = HttpMethod, Url extends string = string, QuerySchema = undefined, ResponseSchema extends ZodType = ZodType, RequestSchema = ZodType, Params = (QuerySchema extends ZodType ? RequestSchema extends ZodType ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema, true> : EndpointFunctionArgs<Url, QuerySchema, undefined, true> : RequestSchema extends ZodType ? EndpointFunctionArgs<Url, undefined, RequestSchema, true> : EndpointFunctionArgs<Url, undefined, undefined, true>)>(endpoint: {
|
|
337
|
+
config: BaseEndpointConfig<Method, Url, QuerySchema, ResponseSchema, RequestSchema>;
|
|
338
|
+
}): (target: (params: Params) => Promise<z$1.input<ResponseSchema>> | z$1.input<ResponseSchema>, context: ClassMethodDecoratorContext) => void;
|
|
331
339
|
declare function Endpoint<Method extends HttpMethod = HttpMethod, Url extends string = string, QuerySchema = undefined, ResponseSchema extends ZodType = ZodType, RequestSchema = ZodType>(endpoint: {
|
|
332
340
|
config: BaseEndpointConfig<Method, Url, QuerySchema, ResponseSchema, RequestSchema>;
|
|
333
|
-
}): (target: (
|
|
341
|
+
}): (target: () => Promise<z$1.input<ResponseSchema>> | z$1.input<ResponseSchema>, context: ClassMethodDecoratorContext) => void;
|
|
334
342
|
//#endregion
|
|
335
343
|
//#region src/metadata/handler.metadata.d.mts
|
|
336
344
|
declare const EndpointMetadataKey: unique symbol;
|
|
@@ -914,9 +922,30 @@ interface AbstractHttpAdapterInterface<ServerInstance, CorsOptions = AbstractHtt
|
|
|
914
922
|
}
|
|
915
923
|
//#endregion
|
|
916
924
|
//#region src/interfaces/abstract-http-handler-adapter.interface.d.mts
|
|
925
|
+
/**
|
|
926
|
+
* Static handler result - handler can be called without a scoped container.
|
|
927
|
+
* Used when the controller and all its dependencies are singletons.
|
|
928
|
+
*/
|
|
929
|
+
type StaticHandler<TRequest = any, TReply = any> = {
|
|
930
|
+
isStatic: true;
|
|
931
|
+
handler: (request: TRequest, reply: TReply) => Promise<any>;
|
|
932
|
+
};
|
|
933
|
+
/**
|
|
934
|
+
* Dynamic handler result - handler requires a scoped container for resolution.
|
|
935
|
+
* Used when the controller or its dependencies need per-request resolution.
|
|
936
|
+
*/
|
|
937
|
+
type DynamicHandler<TRequest = any, TReply = any> = {
|
|
938
|
+
isStatic: false;
|
|
939
|
+
handler: (scoped: ScopedContainer, request: TRequest, reply: TReply) => Promise<any>;
|
|
940
|
+
};
|
|
941
|
+
/**
|
|
942
|
+
* Handler result returned by provideHandler.
|
|
943
|
+
* Can be either static (pre-resolved) or dynamic (needs scoped container).
|
|
944
|
+
*/
|
|
945
|
+
type HandlerResult<TRequest = any, TReply = any> = StaticHandler<TRequest, TReply> | DynamicHandler<TRequest, TReply>;
|
|
917
946
|
interface AbstractHttpHandlerAdapterInterface {
|
|
918
947
|
prepareArguments?: (handlerMetadata: HandlerMetadata<any>) => ((target: Record<string, any>, request: any) => Promise<void> | void)[];
|
|
919
|
-
provideHandler: (controller: ClassType, handlerMetadata: HandlerMetadata<any>) =>
|
|
948
|
+
provideHandler: (controller: ClassType, handlerMetadata: HandlerMetadata<any>) => Promise<HandlerResult>;
|
|
920
949
|
}
|
|
921
950
|
//#endregion
|
|
922
951
|
//#region src/interfaces/can-activate.d.mts
|
|
@@ -1286,9 +1315,12 @@ type MultipartResult<EndpointDeclaration extends {
|
|
|
1286
1315
|
* }
|
|
1287
1316
|
* ```
|
|
1288
1317
|
*/
|
|
1318
|
+
declare function Multipart<Method extends HttpMethod = HttpMethod, Url extends string = string, QuerySchema = undefined, ResponseSchema extends ZodType = ZodType, RequestSchema = ZodType, Params = (QuerySchema extends ZodObject ? RequestSchema extends ZodType ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema, true> : EndpointFunctionArgs<Url, QuerySchema, undefined, true> : RequestSchema extends ZodType ? EndpointFunctionArgs<Url, undefined, RequestSchema, true> : EndpointFunctionArgs<Url, undefined, undefined, true>)>(endpoint: {
|
|
1319
|
+
config: BaseEndpointConfig<Method, Url, QuerySchema, ResponseSchema, RequestSchema>;
|
|
1320
|
+
}): (target: (params: Params) => Promise<z$1.input<ResponseSchema>> | z$1.input<ResponseSchema>, context: ClassMethodDecoratorContext) => void;
|
|
1289
1321
|
declare function Multipart<Method extends HttpMethod = HttpMethod, Url extends string = string, QuerySchema = undefined, ResponseSchema extends ZodType = ZodType, RequestSchema = ZodType>(endpoint: {
|
|
1290
1322
|
config: BaseEndpointConfig<Method, Url, QuerySchema, ResponseSchema, RequestSchema>;
|
|
1291
|
-
}): (target: (
|
|
1323
|
+
}): (target: () => Promise<z$1.input<ResponseSchema>> | z$1.input<ResponseSchema>, context: ClassMethodDecoratorContext) => void;
|
|
1292
1324
|
//#endregion
|
|
1293
1325
|
//#region src/decorators/stream.decorator.d.mts
|
|
1294
1326
|
/**
|
|
@@ -1327,9 +1359,15 @@ type StreamParams<EndpointDeclaration extends {
|
|
|
1327
1359
|
* }
|
|
1328
1360
|
* ```
|
|
1329
1361
|
*/
|
|
1362
|
+
declare function Stream<Method extends HttpMethod = HttpMethod, Url extends string = string, QuerySchema = undefined, RequestSchema = ZodType, Params = (QuerySchema extends ZodObject ? RequestSchema extends ZodType ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema, true> : EndpointFunctionArgs<Url, QuerySchema, undefined, true> : RequestSchema extends ZodType ? EndpointFunctionArgs<Url, undefined, RequestSchema, true> : EndpointFunctionArgs<Url, undefined, undefined, true>)>(endpoint: {
|
|
1363
|
+
config: BaseStreamConfig<Method, Url, QuerySchema, RequestSchema>;
|
|
1364
|
+
}): (target: (params: Params, reply: any) => any, context: ClassMethodDecoratorContext) => void;
|
|
1365
|
+
declare function Stream<Method extends HttpMethod = HttpMethod, Url extends string = string, QuerySchema = undefined, RequestSchema = ZodType, Params = (QuerySchema extends ZodObject ? RequestSchema extends ZodType ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema, true> : EndpointFunctionArgs<Url, QuerySchema, undefined, true> : RequestSchema extends ZodType ? EndpointFunctionArgs<Url, undefined, RequestSchema, true> : EndpointFunctionArgs<Url, undefined, undefined, true>)>(endpoint: {
|
|
1366
|
+
config: BaseStreamConfig<Method, Url, QuerySchema, RequestSchema>;
|
|
1367
|
+
}): (target: (params: Params) => any, context: ClassMethodDecoratorContext) => void;
|
|
1330
1368
|
declare function Stream<Method extends HttpMethod = HttpMethod, Url extends string = string, QuerySchema = undefined, RequestSchema = ZodType>(endpoint: {
|
|
1331
1369
|
config: BaseStreamConfig<Method, Url, QuerySchema, RequestSchema>;
|
|
1332
|
-
}): (target: (
|
|
1370
|
+
}): (target: () => any, context: ClassMethodDecoratorContext) => void;
|
|
1333
1371
|
//#endregion
|
|
1334
1372
|
//#region src/decorators/use-guards.decorator.d.mts
|
|
1335
1373
|
/**
|
|
@@ -1569,37 +1607,153 @@ declare class ConflictException extends HttpException {
|
|
|
1569
1607
|
constructor(message: string | object, error?: Error);
|
|
1570
1608
|
}
|
|
1571
1609
|
//#endregion
|
|
1610
|
+
//#region src/services/instance-resolver.service.d.mts
|
|
1611
|
+
/**
|
|
1612
|
+
* Result of instance resolution attempt.
|
|
1613
|
+
* Contains either a cached singleton instance or a resolver function
|
|
1614
|
+
* that can be used to get a fresh instance per request.
|
|
1615
|
+
*/
|
|
1616
|
+
interface InstanceResolution<T = any> {
|
|
1617
|
+
/**
|
|
1618
|
+
* Whether the instance was successfully cached as a singleton.
|
|
1619
|
+
* If true, `instance` contains the cached instance.
|
|
1620
|
+
* If false, the class has request-scoped dependencies and
|
|
1621
|
+
* must be resolved per-request using `resolve()`.
|
|
1622
|
+
*/
|
|
1623
|
+
cached: boolean;
|
|
1624
|
+
/**
|
|
1625
|
+
* The cached instance (only available if `cached` is true).
|
|
1626
|
+
*/
|
|
1627
|
+
instance: T | null;
|
|
1628
|
+
/**
|
|
1629
|
+
* Resolves the instance from a scoped container.
|
|
1630
|
+
* Use this when `cached` is false to get a fresh instance per request.
|
|
1631
|
+
*/
|
|
1632
|
+
resolve: (scoped: ScopedContainer) => Promise<T>;
|
|
1633
|
+
}
|
|
1634
|
+
/**
|
|
1635
|
+
* Result of resolving multiple instances.
|
|
1636
|
+
* Contains either all cached singleton instances or a resolver function.
|
|
1637
|
+
*/
|
|
1638
|
+
interface MultiInstanceResolution<T = any> {
|
|
1639
|
+
/**
|
|
1640
|
+
* Whether ALL instances were successfully cached as singletons.
|
|
1641
|
+
* If true, `instances` contains all cached instances.
|
|
1642
|
+
* If false, at least one class has request-scoped dependencies.
|
|
1643
|
+
*/
|
|
1644
|
+
cached: boolean;
|
|
1645
|
+
/**
|
|
1646
|
+
* The cached instances (only available if `cached` is true).
|
|
1647
|
+
* Order matches the input array order.
|
|
1648
|
+
*/
|
|
1649
|
+
instances: T[] | null;
|
|
1650
|
+
/**
|
|
1651
|
+
* The original class types for dynamic resolution.
|
|
1652
|
+
*/
|
|
1653
|
+
classTypes: ClassType[];
|
|
1654
|
+
/**
|
|
1655
|
+
* Resolves all instances from a scoped container.
|
|
1656
|
+
* Use this when `cached` is false to get fresh instances per request.
|
|
1657
|
+
*/
|
|
1658
|
+
resolve: (scoped: ScopedContainer) => Promise<T[]>;
|
|
1659
|
+
}
|
|
1660
|
+
/**
|
|
1661
|
+
* Service responsible for resolving class instances with automatic scope detection.
|
|
1662
|
+
*
|
|
1663
|
+
* This service attempts to resolve classes as singletons from the root container.
|
|
1664
|
+
* If resolution fails (because the class has request-scoped dependencies),
|
|
1665
|
+
* it automatically updates the class's scope to Request and provides a
|
|
1666
|
+
* resolver function for per-request instantiation.
|
|
1667
|
+
*
|
|
1668
|
+
* This enables optimal performance:
|
|
1669
|
+
* - Classes without request-scoped deps stay as singletons (faster)
|
|
1670
|
+
* - Classes with request-scoped deps are automatically promoted to request scope
|
|
1671
|
+
*
|
|
1672
|
+
* @example
|
|
1673
|
+
* ```ts
|
|
1674
|
+
* const resolution = await instanceResolver.resolve(UserController)
|
|
1675
|
+
*
|
|
1676
|
+
* if (resolution.cached) {
|
|
1677
|
+
* // Use cached singleton
|
|
1678
|
+
* return resolution.instance.handleRequest(req)
|
|
1679
|
+
* } else {
|
|
1680
|
+
* // Resolve per request
|
|
1681
|
+
* const controller = await resolution.resolve(scopedContainer)
|
|
1682
|
+
* return controller.handleRequest(req)
|
|
1683
|
+
* }
|
|
1684
|
+
* ```
|
|
1685
|
+
*/
|
|
1686
|
+
declare class InstanceResolverService {
|
|
1687
|
+
private container;
|
|
1688
|
+
/**
|
|
1689
|
+
* Attempts to resolve a class instance, automatically detecting if it needs
|
|
1690
|
+
* request scope based on its dependencies.
|
|
1691
|
+
*
|
|
1692
|
+
* @param classType - The class to resolve
|
|
1693
|
+
* @returns A resolution result containing either a cached instance or resolver function
|
|
1694
|
+
*/
|
|
1695
|
+
resolve<T>(classType: ClassType): Promise<InstanceResolution<T>>;
|
|
1696
|
+
/**
|
|
1697
|
+
* Attempts to resolve multiple class instances, automatically detecting if any need
|
|
1698
|
+
* request scope based on their dependencies.
|
|
1699
|
+
*
|
|
1700
|
+
* Returns `cached: true` only if ALL classes can be resolved as singletons.
|
|
1701
|
+
* If any class has request-scoped dependencies, returns `cached: false`.
|
|
1702
|
+
*
|
|
1703
|
+
* @param classTypes - The classes to resolve
|
|
1704
|
+
* @returns A resolution result containing either all cached instances or resolver function
|
|
1705
|
+
*/
|
|
1706
|
+
resolveMany<T>(classTypes: ClassType[]): Promise<MultiInstanceResolution<T>>;
|
|
1707
|
+
}
|
|
1708
|
+
/**
|
|
1709
|
+
* @deprecated Use InstanceResolverService instead
|
|
1710
|
+
*/
|
|
1711
|
+
declare const ControllerResolverService: typeof InstanceResolverService;
|
|
1712
|
+
/**
|
|
1713
|
+
* @deprecated Use InstanceResolution instead
|
|
1714
|
+
*/
|
|
1715
|
+
type ControllerResolution<T = any> = InstanceResolution<T>;
|
|
1716
|
+
//#endregion
|
|
1572
1717
|
//#region src/services/guard-runner.service.d.mts
|
|
1573
1718
|
declare class GuardRunnerService {
|
|
1574
1719
|
private readonly logger;
|
|
1720
|
+
/**
|
|
1721
|
+
* Runs guards that need to be resolved from a scoped container.
|
|
1722
|
+
* Use this when guards have request-scoped dependencies.
|
|
1723
|
+
*/
|
|
1575
1724
|
runGuards(allGuards: Set<ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>>, executionContext: AbstractExecutionContext, context: ScopedContainer): Promise<boolean>;
|
|
1725
|
+
/**
|
|
1726
|
+
* Runs pre-resolved guard instances.
|
|
1727
|
+
* Use this when all guards are singletons and have been pre-resolved at startup.
|
|
1728
|
+
*/
|
|
1729
|
+
runGuardsStatic(guardInstances: CanActivate[], executionContext: AbstractExecutionContext): Promise<boolean>;
|
|
1730
|
+
/**
|
|
1731
|
+
* Shared guard execution logic.
|
|
1732
|
+
* Iterates through guard instances and calls canActivate on each.
|
|
1733
|
+
*/
|
|
1734
|
+
private executeGuards;
|
|
1576
1735
|
makeContext(moduleMetadata: ModuleMetadata, controllerMetadata: ControllerMetadata, endpoint: HandlerMetadata): Set<ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>>;
|
|
1577
1736
|
}
|
|
1578
1737
|
//#endregion
|
|
1579
1738
|
//#region src/stores/request-id.store.d.mts
|
|
1580
1739
|
/**
|
|
1581
|
-
*
|
|
1582
|
-
*
|
|
1583
|
-
* This allows logging and other services to access the current request ID
|
|
1584
|
-
* without explicitly passing it through the call stack.
|
|
1585
|
-
*
|
|
1586
|
-
* @example
|
|
1587
|
-
* ```typescript
|
|
1588
|
-
* import { requestIdStore, runWithRequestId, getRequestId } from '@navios/core'
|
|
1740
|
+
* Generates a simple incremental request ID.
|
|
1741
|
+
* Much faster than crypto.randomUUID() and sufficient for request tracking.
|
|
1589
1742
|
*
|
|
1590
|
-
*
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
*
|
|
1743
|
+
* @returns A unique request ID string (e.g., "req-1", "req-2", ...)
|
|
1744
|
+
*/
|
|
1745
|
+
declare function generateRequestId(): string;
|
|
1746
|
+
/**
|
|
1747
|
+
* Enables or disables request ID propagation.
|
|
1748
|
+
* Called by NaviosFactory based on the enableRequestId option.
|
|
1595
1749
|
*
|
|
1596
|
-
*
|
|
1597
|
-
* const currentId = getRequestId()
|
|
1598
|
-
* ```
|
|
1750
|
+
* @param enabled - Whether to enable request ID propagation
|
|
1599
1751
|
*/
|
|
1600
|
-
declare
|
|
1752
|
+
declare function setRequestIdEnabled(enabled: boolean): void;
|
|
1601
1753
|
/**
|
|
1602
1754
|
* Runs a function with a request ID in the async local storage context.
|
|
1755
|
+
* If request ID propagation is disabled, the function is called directly
|
|
1756
|
+
* without AsyncLocalStorage overhead.
|
|
1603
1757
|
*
|
|
1604
1758
|
* @param requestId - The request ID to set for this context
|
|
1605
1759
|
* @param fn - The function to run within this context
|
|
@@ -1626,354 +1780,138 @@ declare const HttpAdapterToken: InjectionToken<AbstractHttpAdapterInterface<any,
|
|
|
1626
1780
|
//#region src/tokens/multipart-adapter.token.d.mts
|
|
1627
1781
|
declare const MultipartAdapterToken: InjectionToken<AbstractHttpHandlerAdapterInterface, undefined, false>;
|
|
1628
1782
|
//#endregion
|
|
1629
|
-
//#region src/
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
declare const Request: InjectionToken<any, undefined, false>;
|
|
1634
|
-
//#endregion
|
|
1635
|
-
//#region src/tokens/stream-adapter.token.d.mts
|
|
1636
|
-
declare const StreamAdapterToken: InjectionToken<AbstractHttpHandlerAdapterInterface, undefined, false>;
|
|
1637
|
-
//#endregion
|
|
1638
|
-
//#region src/tokens/xml-stream-adapter.token.d.mts
|
|
1639
|
-
declare const XmlStreamAdapterToken: InjectionToken<AbstractHttpHandlerAdapterInterface, undefined, false>;
|
|
1783
|
+
//#region src/navios.environment.d.mts
|
|
1784
|
+
interface NaviosEnvironmentOptions {
|
|
1785
|
+
httpTokens?: Map<InjectionToken<any, undefined>, AnyInjectableType>;
|
|
1786
|
+
}
|
|
1640
1787
|
//#endregion
|
|
1641
|
-
//#region src/
|
|
1788
|
+
//#region src/navios.application.d.mts
|
|
1642
1789
|
/**
|
|
1643
|
-
*
|
|
1644
|
-
*
|
|
1645
|
-
* Attributes are custom metadata decorators that can be applied to modules,
|
|
1646
|
-
* controllers, and endpoints.
|
|
1790
|
+
* Options for configuring the Navios application context.
|
|
1791
|
+
* These options control dependency injection and logging behavior.
|
|
1647
1792
|
*/
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1793
|
+
interface NaviosApplicationContextOptions {
|
|
1794
|
+
/**
|
|
1795
|
+
* Specifies the logger to use. Pass `false` to turn off logging.
|
|
1796
|
+
*
|
|
1797
|
+
* - `LoggerService` instance: Use a custom logger implementation
|
|
1798
|
+
* - `LogLevel[]`: Enable specific log levels (e.g., ['error', 'warn', 'log'])
|
|
1799
|
+
* - `false`: Disable logging completely
|
|
1800
|
+
*/
|
|
1801
|
+
logger?: LoggerService | LogLevel[] | false;
|
|
1802
|
+
/**
|
|
1803
|
+
* Specifies a custom container to use. Useful for testing.
|
|
1804
|
+
* If not provided, a new Container will be created.
|
|
1805
|
+
*/
|
|
1806
|
+
container?: Container;
|
|
1807
|
+
}
|
|
1651
1808
|
/**
|
|
1652
|
-
*
|
|
1653
|
-
*
|
|
1654
|
-
* @typeParam T - The Zod schema type for validation
|
|
1809
|
+
* Complete options for creating a Navios application.
|
|
1810
|
+
* Extends NaviosApplicationContextOptions with adapter configuration.
|
|
1655
1811
|
*/
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1812
|
+
interface NaviosApplicationOptions extends NaviosApplicationContextOptions {
|
|
1813
|
+
/**
|
|
1814
|
+
* HTTP adapter environment(s) to use for the application.
|
|
1815
|
+
* Can be a single adapter or an array of adapters.
|
|
1816
|
+
*
|
|
1817
|
+
* @example
|
|
1818
|
+
* ```typescript
|
|
1819
|
+
* adapter: defineFastifyEnvironment()
|
|
1820
|
+
* // or
|
|
1821
|
+
* adapter: [defineFastifyEnvironment(), defineBunEnvironment()]
|
|
1822
|
+
* ```
|
|
1823
|
+
*/
|
|
1824
|
+
adapter: NaviosEnvironmentOptions | NaviosEnvironmentOptions[];
|
|
1825
|
+
/**
|
|
1826
|
+
* Whether to validate response schemas.
|
|
1827
|
+
* When `false`, response schema validation is skipped for better performance.
|
|
1828
|
+
* @default true
|
|
1829
|
+
*/
|
|
1830
|
+
validateResponses?: boolean;
|
|
1831
|
+
/**
|
|
1832
|
+
* Whether to enable request ID propagation via AsyncLocalStorage.
|
|
1833
|
+
* When `true`, request IDs are available via `getRequestId()` throughout the request.
|
|
1834
|
+
* @default false
|
|
1835
|
+
*/
|
|
1836
|
+
enableRequestId?: boolean;
|
|
1837
|
+
}
|
|
1660
1838
|
/**
|
|
1661
|
-
*
|
|
1662
|
-
*
|
|
1663
|
-
* Attributes allow you to add custom metadata to modules, controllers, and endpoints.
|
|
1664
|
-
* This is useful for cross-cutting concerns like rate limiting, caching, API versioning, etc.
|
|
1665
|
-
*
|
|
1666
|
-
* @example
|
|
1667
|
-
* ```typescript
|
|
1668
|
-
* // Create a simple boolean attribute
|
|
1669
|
-
* const Public = AttributeFactory.createAttribute(Symbol.for('Public'))
|
|
1670
|
-
*
|
|
1671
|
-
* // Use it as a decorator
|
|
1672
|
-
* @Controller()
|
|
1673
|
-
* @Public()
|
|
1674
|
-
* export class PublicController { }
|
|
1839
|
+
* Main application class for Navios.
|
|
1675
1840
|
*
|
|
1676
|
-
*
|
|
1677
|
-
*
|
|
1678
|
-
* // Skip authentication
|
|
1679
|
-
* }
|
|
1680
|
-
* ```
|
|
1841
|
+
* This class represents a Navios application instance and provides methods
|
|
1842
|
+
* for initializing, configuring, and managing the HTTP server.
|
|
1681
1843
|
*
|
|
1682
1844
|
* @example
|
|
1683
1845
|
* ```typescript
|
|
1684
|
-
*
|
|
1685
|
-
*
|
|
1686
|
-
*
|
|
1687
|
-
* z.object({ requests: z.number(), window: z.number() })
|
|
1688
|
-
* )
|
|
1689
|
-
*
|
|
1690
|
-
* // Use it with a value
|
|
1691
|
-
* @Endpoint(apiEndpoint)
|
|
1692
|
-
* @RateLimit({ requests: 100, window: 60000 })
|
|
1693
|
-
* async handler() { }
|
|
1846
|
+
* const app = await NaviosFactory.create(AppModule, {
|
|
1847
|
+
* adapter: defineFastifyEnvironment(),
|
|
1848
|
+
* })
|
|
1694
1849
|
*
|
|
1695
|
-
*
|
|
1696
|
-
*
|
|
1697
|
-
*
|
|
1850
|
+
* app.setGlobalPrefix('/api')
|
|
1851
|
+
* app.enableCors({ origin: ['http://localhost:3000'] })
|
|
1852
|
+
* await app.init()
|
|
1853
|
+
* await app.listen({ port: 3000, host: '0.0.0.0' })
|
|
1698
1854
|
* ```
|
|
1699
1855
|
*/
|
|
1700
|
-
declare class
|
|
1856
|
+
declare class NaviosApplication {
|
|
1857
|
+
private environment;
|
|
1858
|
+
private moduleLoader;
|
|
1859
|
+
private httpApplication;
|
|
1860
|
+
private logger;
|
|
1861
|
+
protected container: Container;
|
|
1862
|
+
private appModule;
|
|
1863
|
+
private options;
|
|
1864
|
+
private plugins;
|
|
1701
1865
|
/**
|
|
1702
|
-
*
|
|
1703
|
-
*
|
|
1704
|
-
|
|
1705
|
-
|
|
1866
|
+
* Indicates whether the application has been initialized.
|
|
1867
|
+
* Set to `true` after `init()` completes successfully.
|
|
1868
|
+
*/
|
|
1869
|
+
isInitialized: boolean;
|
|
1870
|
+
/**
|
|
1871
|
+
* Sets up the application with the provided module and options.
|
|
1872
|
+
* This is called automatically by NaviosFactory.create().
|
|
1706
1873
|
*
|
|
1707
|
-
* @
|
|
1708
|
-
*
|
|
1709
|
-
*
|
|
1874
|
+
* @param appModule - The root application module
|
|
1875
|
+
* @param options - Application configuration options
|
|
1876
|
+
* @internal
|
|
1877
|
+
*/
|
|
1878
|
+
setup(appModule: ClassTypeWithInstance<NaviosModule>, options?: NaviosApplicationOptions): Promise<void>;
|
|
1879
|
+
/**
|
|
1880
|
+
* Gets the dependency injection container used by this application.
|
|
1710
1881
|
*
|
|
1711
|
-
* @
|
|
1712
|
-
* @Controller()
|
|
1713
|
-
* export class PublicController { }
|
|
1714
|
-
* ```
|
|
1882
|
+
* @returns The Container instance
|
|
1715
1883
|
*/
|
|
1716
|
-
|
|
1884
|
+
getContainer(): Container;
|
|
1717
1885
|
/**
|
|
1718
|
-
*
|
|
1886
|
+
* Registers a plugin to be initialized after modules are loaded.
|
|
1719
1887
|
*
|
|
1720
|
-
*
|
|
1721
|
-
*
|
|
1722
|
-
*
|
|
1888
|
+
* Plugins are initialized in the order they are registered,
|
|
1889
|
+
* after all modules are loaded but before the server starts listening.
|
|
1890
|
+
*
|
|
1891
|
+
* @param definition - Plugin definition with options
|
|
1892
|
+
* @returns this for method chaining
|
|
1723
1893
|
*
|
|
1724
1894
|
* @example
|
|
1725
1895
|
* ```typescript
|
|
1726
|
-
*
|
|
1727
|
-
* Symbol.for('RateLimit'),
|
|
1728
|
-
* z.object({ requests: z.number(), window: z.number() })
|
|
1729
|
-
* )
|
|
1896
|
+
* import { defineOpenApiPlugin } from '@navios/openapi-fastify'
|
|
1730
1897
|
*
|
|
1731
|
-
*
|
|
1732
|
-
*
|
|
1733
|
-
*
|
|
1898
|
+
* app.usePlugin(defineOpenApiPlugin({
|
|
1899
|
+
* info: { title: 'My API', version: '1.0.0' },
|
|
1900
|
+
* }))
|
|
1734
1901
|
* ```
|
|
1735
1902
|
*/
|
|
1736
|
-
|
|
1903
|
+
usePlugin<TOptions>(definition: PluginDefinition<TOptions>): this;
|
|
1737
1904
|
/**
|
|
1738
|
-
*
|
|
1905
|
+
* Initializes the application.
|
|
1739
1906
|
*
|
|
1740
|
-
*
|
|
1741
|
-
*
|
|
1907
|
+
* This method:
|
|
1908
|
+
* - Loads all modules and their dependencies
|
|
1909
|
+
* - Sets up the HTTP server if an adapter is configured
|
|
1910
|
+
* - Calls onModuleInit hooks on all modules
|
|
1911
|
+
* - Initializes registered plugins
|
|
1912
|
+
* - Marks the application as initialized
|
|
1742
1913
|
*
|
|
1743
|
-
*
|
|
1744
|
-
* @param target - The metadata object (module, controller, or handler)
|
|
1745
|
-
* @returns The attribute value, `true` for simple attributes, or `null` if not found
|
|
1746
|
-
*
|
|
1747
|
-
* @example
|
|
1748
|
-
* ```typescript
|
|
1749
|
-
* const isPublic = AttributeFactory.get(Public, controllerMetadata)
|
|
1750
|
-
* // isPublic is true | null
|
|
1751
|
-
*
|
|
1752
|
-
* const rateLimit = AttributeFactory.get(RateLimit, endpointMetadata)
|
|
1753
|
-
* // rateLimit is { requests: number, window: number } | null
|
|
1754
|
-
* ```
|
|
1755
|
-
*/
|
|
1756
|
-
static get(attribute: ClassAttribute, target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>): true | null;
|
|
1757
|
-
static get<T extends ZodType>(attribute: ClassSchemaAttribute<T>, target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>): z$1.output<T> | null;
|
|
1758
|
-
/**
|
|
1759
|
-
* Gets all values of an attribute from metadata (useful when an attribute can appear multiple times).
|
|
1760
|
-
*
|
|
1761
|
-
* Returns `null` if the attribute is not present.
|
|
1762
|
-
*
|
|
1763
|
-
* @param attribute - The attribute decorator
|
|
1764
|
-
* @param target - The metadata object (module, controller, or handler)
|
|
1765
|
-
* @returns An array of attribute values, or `null` if not found
|
|
1766
|
-
*
|
|
1767
|
-
* @example
|
|
1768
|
-
* ```typescript
|
|
1769
|
-
* const tags = AttributeFactory.getAll(Tag, endpointMetadata)
|
|
1770
|
-
* // tags is string[] | null
|
|
1771
|
-
* ```
|
|
1772
|
-
*/
|
|
1773
|
-
static getAll(attribute: ClassAttribute, target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>): Array<true> | null;
|
|
1774
|
-
static getAll<T extends ZodType>(attribute: ClassSchemaAttribute<T>, target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>): Array<z$1.output<T>> | null;
|
|
1775
|
-
/**
|
|
1776
|
-
* Gets the last value of an attribute from an array of metadata objects.
|
|
1777
|
-
*
|
|
1778
|
-
* Searches from the end of the array backwards, useful for finding the most
|
|
1779
|
-
* specific attribute value (e.g., endpoint-level overrides module-level).
|
|
1780
|
-
*
|
|
1781
|
-
* @param attribute - The attribute decorator
|
|
1782
|
-
* @param target - An array of metadata objects (typically [module, controller, handler])
|
|
1783
|
-
* @returns The last attribute value found, or `null` if not found
|
|
1784
|
-
*
|
|
1785
|
-
* @example
|
|
1786
|
-
* ```typescript
|
|
1787
|
-
* // Check attribute hierarchy: endpoint -> controller -> module
|
|
1788
|
-
* const rateLimit = AttributeFactory.getLast(RateLimit, [
|
|
1789
|
-
* moduleMetadata,
|
|
1790
|
-
* controllerMetadata,
|
|
1791
|
-
* endpointMetadata
|
|
1792
|
-
* ])
|
|
1793
|
-
* ```
|
|
1794
|
-
*/
|
|
1795
|
-
static getLast(attribute: ClassAttribute, target: (ModuleMetadata | ControllerMetadata | HandlerMetadata<any>)[]): true | null;
|
|
1796
|
-
static getLast<T extends ZodType>(attribute: ClassSchemaAttribute<T>, target: (ModuleMetadata | ControllerMetadata | HandlerMetadata<any>)[]): z$1.output<T> | null;
|
|
1797
|
-
/**
|
|
1798
|
-
* Checks if an attribute is present on the metadata object.
|
|
1799
|
-
*
|
|
1800
|
-
* @param attribute - The attribute decorator
|
|
1801
|
-
* @param target - The metadata object (module, controller, or handler)
|
|
1802
|
-
* @returns `true` if the attribute is present, `false` otherwise
|
|
1803
|
-
*
|
|
1804
|
-
* @example
|
|
1805
|
-
* ```typescript
|
|
1806
|
-
* if (AttributeFactory.has(Public, controllerMetadata)) {
|
|
1807
|
-
* // Skip authentication
|
|
1808
|
-
* }
|
|
1809
|
-
* ```
|
|
1810
|
-
*/
|
|
1811
|
-
static has(attribute: ClassAttribute, target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>): boolean;
|
|
1812
|
-
static has<T extends ZodType>(attribute: ClassSchemaAttribute<T>, target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>): boolean;
|
|
1813
|
-
}
|
|
1814
|
-
//#endregion
|
|
1815
|
-
//#region src/factories/endpoint-adapter.factory.d.mts
|
|
1816
|
-
declare class EndpointAdapterFactory {
|
|
1817
|
-
private readonly environment;
|
|
1818
|
-
create(ctx: FactoryContext): Promise<any>;
|
|
1819
|
-
}
|
|
1820
|
-
//#endregion
|
|
1821
|
-
//#region src/factories/http-adapter.factory.d.mts
|
|
1822
|
-
declare class HttpAdapterFactory {
|
|
1823
|
-
private readonly environment;
|
|
1824
|
-
create(ctx: FactoryContext): Promise<any>;
|
|
1825
|
-
}
|
|
1826
|
-
//#endregion
|
|
1827
|
-
//#region src/factories/multipart-adapter.factory.d.mts
|
|
1828
|
-
declare class MultipartAdapterFactory {
|
|
1829
|
-
private readonly environment;
|
|
1830
|
-
create(ctx: FactoryContext): Promise<any>;
|
|
1831
|
-
}
|
|
1832
|
-
//#endregion
|
|
1833
|
-
//#region src/factories/request.factory.d.mts
|
|
1834
|
-
declare class RequestFactory {
|
|
1835
|
-
private readonly environment;
|
|
1836
|
-
create(ctx: FactoryContext): Promise<any>;
|
|
1837
|
-
}
|
|
1838
|
-
//#endregion
|
|
1839
|
-
//#region src/factories/reply.factory.d.mts
|
|
1840
|
-
declare class ReplyFactory {
|
|
1841
|
-
private readonly environment;
|
|
1842
|
-
create(ctx: FactoryContext): Promise<any>;
|
|
1843
|
-
}
|
|
1844
|
-
//#endregion
|
|
1845
|
-
//#region src/factories/stream-adapter.factory.d.mts
|
|
1846
|
-
declare class StreamAdapterFactory {
|
|
1847
|
-
private readonly environment;
|
|
1848
|
-
create(ctx: FactoryContext): Promise<any>;
|
|
1849
|
-
}
|
|
1850
|
-
//#endregion
|
|
1851
|
-
//#region src/factories/xml-stream-adapter.factory.d.mts
|
|
1852
|
-
declare class XmlStreamAdapterFactory {
|
|
1853
|
-
private readonly environment;
|
|
1854
|
-
create(ctx: FactoryContext): Promise<any>;
|
|
1855
|
-
}
|
|
1856
|
-
//#endregion
|
|
1857
|
-
//#region src/navios.environment.d.mts
|
|
1858
|
-
interface NaviosEnvironmentOptions {
|
|
1859
|
-
httpTokens?: Map<InjectionToken<any, undefined>, AnyInjectableType>;
|
|
1860
|
-
}
|
|
1861
|
-
//#endregion
|
|
1862
|
-
//#region src/navios.application.d.mts
|
|
1863
|
-
/**
|
|
1864
|
-
* Options for configuring the Navios application context.
|
|
1865
|
-
* These options control dependency injection and logging behavior.
|
|
1866
|
-
*/
|
|
1867
|
-
interface NaviosApplicationContextOptions {
|
|
1868
|
-
/**
|
|
1869
|
-
* Specifies the logger to use. Pass `false` to turn off logging.
|
|
1870
|
-
*
|
|
1871
|
-
* - `LoggerService` instance: Use a custom logger implementation
|
|
1872
|
-
* - `LogLevel[]`: Enable specific log levels (e.g., ['error', 'warn', 'log'])
|
|
1873
|
-
* - `false`: Disable logging completely
|
|
1874
|
-
*/
|
|
1875
|
-
logger?: LoggerService | LogLevel[] | false;
|
|
1876
|
-
/**
|
|
1877
|
-
* Specifies a custom container to use. Useful for testing.
|
|
1878
|
-
* If not provided, a new Container will be created.
|
|
1879
|
-
*/
|
|
1880
|
-
container?: Container;
|
|
1881
|
-
}
|
|
1882
|
-
/**
|
|
1883
|
-
* Complete options for creating a Navios application.
|
|
1884
|
-
* Extends NaviosApplicationContextOptions with adapter configuration.
|
|
1885
|
-
*/
|
|
1886
|
-
interface NaviosApplicationOptions extends NaviosApplicationContextOptions {
|
|
1887
|
-
/**
|
|
1888
|
-
* HTTP adapter environment(s) to use for the application.
|
|
1889
|
-
* Can be a single adapter or an array of adapters.
|
|
1890
|
-
*
|
|
1891
|
-
* @example
|
|
1892
|
-
* ```typescript
|
|
1893
|
-
* adapter: defineFastifyEnvironment()
|
|
1894
|
-
* // or
|
|
1895
|
-
* adapter: [defineFastifyEnvironment(), defineBunEnvironment()]
|
|
1896
|
-
* ```
|
|
1897
|
-
*/
|
|
1898
|
-
adapter: NaviosEnvironmentOptions | NaviosEnvironmentOptions[];
|
|
1899
|
-
}
|
|
1900
|
-
/**
|
|
1901
|
-
* Main application class for Navios.
|
|
1902
|
-
*
|
|
1903
|
-
* This class represents a Navios application instance and provides methods
|
|
1904
|
-
* for initializing, configuring, and managing the HTTP server.
|
|
1905
|
-
*
|
|
1906
|
-
* @example
|
|
1907
|
-
* ```typescript
|
|
1908
|
-
* const app = await NaviosFactory.create(AppModule, {
|
|
1909
|
-
* adapter: defineFastifyEnvironment(),
|
|
1910
|
-
* })
|
|
1911
|
-
*
|
|
1912
|
-
* app.setGlobalPrefix('/api')
|
|
1913
|
-
* app.enableCors({ origin: ['http://localhost:3000'] })
|
|
1914
|
-
* await app.init()
|
|
1915
|
-
* await app.listen({ port: 3000, host: '0.0.0.0' })
|
|
1916
|
-
* ```
|
|
1917
|
-
*/
|
|
1918
|
-
declare class NaviosApplication {
|
|
1919
|
-
private environment;
|
|
1920
|
-
private moduleLoader;
|
|
1921
|
-
private httpApplication;
|
|
1922
|
-
private logger;
|
|
1923
|
-
protected container: Container;
|
|
1924
|
-
private appModule;
|
|
1925
|
-
private options;
|
|
1926
|
-
private plugins;
|
|
1927
|
-
/**
|
|
1928
|
-
* Indicates whether the application has been initialized.
|
|
1929
|
-
* Set to `true` after `init()` completes successfully.
|
|
1930
|
-
*/
|
|
1931
|
-
isInitialized: boolean;
|
|
1932
|
-
/**
|
|
1933
|
-
* Sets up the application with the provided module and options.
|
|
1934
|
-
* This is called automatically by NaviosFactory.create().
|
|
1935
|
-
*
|
|
1936
|
-
* @param appModule - The root application module
|
|
1937
|
-
* @param options - Application configuration options
|
|
1938
|
-
* @internal
|
|
1939
|
-
*/
|
|
1940
|
-
setup(appModule: ClassTypeWithInstance<NaviosModule>, options?: NaviosApplicationOptions): Promise<void>;
|
|
1941
|
-
/**
|
|
1942
|
-
* Gets the dependency injection container used by this application.
|
|
1943
|
-
*
|
|
1944
|
-
* @returns The Container instance
|
|
1945
|
-
*/
|
|
1946
|
-
getContainer(): Container;
|
|
1947
|
-
/**
|
|
1948
|
-
* Registers a plugin to be initialized after modules are loaded.
|
|
1949
|
-
*
|
|
1950
|
-
* Plugins are initialized in the order they are registered,
|
|
1951
|
-
* after all modules are loaded but before the server starts listening.
|
|
1952
|
-
*
|
|
1953
|
-
* @param definition - Plugin definition with options
|
|
1954
|
-
* @returns this for method chaining
|
|
1955
|
-
*
|
|
1956
|
-
* @example
|
|
1957
|
-
* ```typescript
|
|
1958
|
-
* import { defineOpenApiPlugin } from '@navios/openapi-fastify'
|
|
1959
|
-
*
|
|
1960
|
-
* app.usePlugin(defineOpenApiPlugin({
|
|
1961
|
-
* info: { title: 'My API', version: '1.0.0' },
|
|
1962
|
-
* }))
|
|
1963
|
-
* ```
|
|
1964
|
-
*/
|
|
1965
|
-
usePlugin<TOptions>(definition: PluginDefinition<TOptions>): this;
|
|
1966
|
-
/**
|
|
1967
|
-
* Initializes the application.
|
|
1968
|
-
*
|
|
1969
|
-
* This method:
|
|
1970
|
-
* - Loads all modules and their dependencies
|
|
1971
|
-
* - Sets up the HTTP server if an adapter is configured
|
|
1972
|
-
* - Calls onModuleInit hooks on all modules
|
|
1973
|
-
* - Initializes registered plugins
|
|
1974
|
-
* - Marks the application as initialized
|
|
1975
|
-
*
|
|
1976
|
-
* Must be called before `listen()`.
|
|
1914
|
+
* Must be called before `listen()`.
|
|
1977
1915
|
*
|
|
1978
1916
|
* @throws Error if app module is not set
|
|
1979
1917
|
*
|
|
@@ -2087,6 +2025,237 @@ declare class NaviosApplication {
|
|
|
2087
2025
|
close(): Promise<void>;
|
|
2088
2026
|
}
|
|
2089
2027
|
//#endregion
|
|
2028
|
+
//#region src/tokens/navios-options.token.d.mts
|
|
2029
|
+
declare const NaviosOptionsToken: InjectionToken<NaviosApplicationOptions, undefined, false>;
|
|
2030
|
+
//#endregion
|
|
2031
|
+
//#region src/tokens/reply.token.d.mts
|
|
2032
|
+
declare const Reply: InjectionToken<any, undefined, false>;
|
|
2033
|
+
//#endregion
|
|
2034
|
+
//#region src/tokens/request.token.d.mts
|
|
2035
|
+
declare const Request: InjectionToken<any, undefined, false>;
|
|
2036
|
+
//#endregion
|
|
2037
|
+
//#region src/tokens/stream-adapter.token.d.mts
|
|
2038
|
+
declare const StreamAdapterToken: InjectionToken<AbstractHttpHandlerAdapterInterface, undefined, false>;
|
|
2039
|
+
//#endregion
|
|
2040
|
+
//#region src/tokens/xml-stream-adapter.token.d.mts
|
|
2041
|
+
declare const XmlStreamAdapterToken: InjectionToken<AbstractHttpHandlerAdapterInterface, undefined, false>;
|
|
2042
|
+
//#endregion
|
|
2043
|
+
//#region src/attribute.factory.d.mts
|
|
2044
|
+
/**
|
|
2045
|
+
* Type for a class attribute decorator without a value.
|
|
2046
|
+
*
|
|
2047
|
+
* Attributes are custom metadata decorators that can be applied to modules,
|
|
2048
|
+
* controllers, and endpoints.
|
|
2049
|
+
*/
|
|
2050
|
+
type ClassAttribute = (() => <T>(target: T, context: ClassDecoratorContext | ClassMethodDecoratorContext) => T) & {
|
|
2051
|
+
token: symbol;
|
|
2052
|
+
};
|
|
2053
|
+
/**
|
|
2054
|
+
* Type for a class attribute decorator with a validated value.
|
|
2055
|
+
*
|
|
2056
|
+
* @typeParam T - The Zod schema type for validation
|
|
2057
|
+
*/
|
|
2058
|
+
type ClassSchemaAttribute<T extends ZodType> = ((value: z$1.input<T>) => <T>(target: T, context: ClassDecoratorContext | ClassMethodDecoratorContext) => T) & {
|
|
2059
|
+
token: symbol;
|
|
2060
|
+
schema: ZodType;
|
|
2061
|
+
};
|
|
2062
|
+
/**
|
|
2063
|
+
* Factory for creating custom attribute decorators.
|
|
2064
|
+
*
|
|
2065
|
+
* Attributes allow you to add custom metadata to modules, controllers, and endpoints.
|
|
2066
|
+
* This is useful for cross-cutting concerns like rate limiting, caching, API versioning, etc.
|
|
2067
|
+
*
|
|
2068
|
+
* @example
|
|
2069
|
+
* ```typescript
|
|
2070
|
+
* // Create a simple boolean attribute
|
|
2071
|
+
* const Public = AttributeFactory.createAttribute(Symbol.for('Public'))
|
|
2072
|
+
*
|
|
2073
|
+
* // Use it as a decorator
|
|
2074
|
+
* @Controller()
|
|
2075
|
+
* @Public()
|
|
2076
|
+
* export class PublicController { }
|
|
2077
|
+
*
|
|
2078
|
+
* // Check if attribute exists
|
|
2079
|
+
* if (AttributeFactory.has(Public, controllerMetadata)) {
|
|
2080
|
+
* // Skip authentication
|
|
2081
|
+
* }
|
|
2082
|
+
* ```
|
|
2083
|
+
*
|
|
2084
|
+
* @example
|
|
2085
|
+
* ```typescript
|
|
2086
|
+
* // Create an attribute with a validated value
|
|
2087
|
+
* const RateLimit = AttributeFactory.createAttribute(
|
|
2088
|
+
* Symbol.for('RateLimit'),
|
|
2089
|
+
* z.object({ requests: z.number(), window: z.number() })
|
|
2090
|
+
* )
|
|
2091
|
+
*
|
|
2092
|
+
* // Use it with a value
|
|
2093
|
+
* @Endpoint(apiEndpoint)
|
|
2094
|
+
* @RateLimit({ requests: 100, window: 60000 })
|
|
2095
|
+
* async handler() { }
|
|
2096
|
+
*
|
|
2097
|
+
* // Get the value
|
|
2098
|
+
* const limit = AttributeFactory.get(RateLimit, endpointMetadata)
|
|
2099
|
+
* // limit is typed as { requests: number, window: number } | null
|
|
2100
|
+
* ```
|
|
2101
|
+
*/
|
|
2102
|
+
declare class AttributeFactory {
|
|
2103
|
+
/**
|
|
2104
|
+
* Creates a simple attribute decorator without a value.
|
|
2105
|
+
*
|
|
2106
|
+
* @param token - A unique symbol to identify this attribute
|
|
2107
|
+
* @returns A decorator function that can be applied to classes or methods
|
|
2108
|
+
*
|
|
2109
|
+
* @example
|
|
2110
|
+
* ```typescript
|
|
2111
|
+
* const Public = AttributeFactory.createAttribute(Symbol.for('Public'))
|
|
2112
|
+
*
|
|
2113
|
+
* @Public()
|
|
2114
|
+
* @Controller()
|
|
2115
|
+
* export class PublicController { }
|
|
2116
|
+
* ```
|
|
2117
|
+
*/
|
|
2118
|
+
static createAttribute(token: symbol): ClassAttribute;
|
|
2119
|
+
/**
|
|
2120
|
+
* Creates an attribute decorator with a validated value.
|
|
2121
|
+
*
|
|
2122
|
+
* @param token - A unique symbol to identify this attribute
|
|
2123
|
+
* @param schema - A Zod schema to validate the attribute value
|
|
2124
|
+
* @returns A decorator function that accepts a value and can be applied to classes or methods
|
|
2125
|
+
*
|
|
2126
|
+
* @example
|
|
2127
|
+
* ```typescript
|
|
2128
|
+
* const RateLimit = AttributeFactory.createAttribute(
|
|
2129
|
+
* Symbol.for('RateLimit'),
|
|
2130
|
+
* z.object({ requests: z.number(), window: z.number() })
|
|
2131
|
+
* )
|
|
2132
|
+
*
|
|
2133
|
+
* @RateLimit({ requests: 100, window: 60000 })
|
|
2134
|
+
* @Endpoint(apiEndpoint)
|
|
2135
|
+
* async handler() { }
|
|
2136
|
+
* ```
|
|
2137
|
+
*/
|
|
2138
|
+
static createAttribute<T extends ZodType>(token: symbol, schema: T): ClassSchemaAttribute<T>;
|
|
2139
|
+
/**
|
|
2140
|
+
* Gets the value of an attribute from metadata.
|
|
2141
|
+
*
|
|
2142
|
+
* Returns `null` if the attribute is not present.
|
|
2143
|
+
* For simple attributes (without values), returns `true` if present.
|
|
2144
|
+
*
|
|
2145
|
+
* @param attribute - The attribute decorator
|
|
2146
|
+
* @param target - The metadata object (module, controller, or handler)
|
|
2147
|
+
* @returns The attribute value, `true` for simple attributes, or `null` if not found
|
|
2148
|
+
*
|
|
2149
|
+
* @example
|
|
2150
|
+
* ```typescript
|
|
2151
|
+
* const isPublic = AttributeFactory.get(Public, controllerMetadata)
|
|
2152
|
+
* // isPublic is true | null
|
|
2153
|
+
*
|
|
2154
|
+
* const rateLimit = AttributeFactory.get(RateLimit, endpointMetadata)
|
|
2155
|
+
* // rateLimit is { requests: number, window: number } | null
|
|
2156
|
+
* ```
|
|
2157
|
+
*/
|
|
2158
|
+
static get(attribute: ClassAttribute, target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>): true | null;
|
|
2159
|
+
static get<T extends ZodType>(attribute: ClassSchemaAttribute<T>, target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>): z$1.output<T> | null;
|
|
2160
|
+
/**
|
|
2161
|
+
* Gets all values of an attribute from metadata (useful when an attribute can appear multiple times).
|
|
2162
|
+
*
|
|
2163
|
+
* Returns `null` if the attribute is not present.
|
|
2164
|
+
*
|
|
2165
|
+
* @param attribute - The attribute decorator
|
|
2166
|
+
* @param target - The metadata object (module, controller, or handler)
|
|
2167
|
+
* @returns An array of attribute values, or `null` if not found
|
|
2168
|
+
*
|
|
2169
|
+
* @example
|
|
2170
|
+
* ```typescript
|
|
2171
|
+
* const tags = AttributeFactory.getAll(Tag, endpointMetadata)
|
|
2172
|
+
* // tags is string[] | null
|
|
2173
|
+
* ```
|
|
2174
|
+
*/
|
|
2175
|
+
static getAll(attribute: ClassAttribute, target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>): Array<true> | null;
|
|
2176
|
+
static getAll<T extends ZodType>(attribute: ClassSchemaAttribute<T>, target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>): Array<z$1.output<T>> | null;
|
|
2177
|
+
/**
|
|
2178
|
+
* Gets the last value of an attribute from an array of metadata objects.
|
|
2179
|
+
*
|
|
2180
|
+
* Searches from the end of the array backwards, useful for finding the most
|
|
2181
|
+
* specific attribute value (e.g., endpoint-level overrides module-level).
|
|
2182
|
+
*
|
|
2183
|
+
* @param attribute - The attribute decorator
|
|
2184
|
+
* @param target - An array of metadata objects (typically [module, controller, handler])
|
|
2185
|
+
* @returns The last attribute value found, or `null` if not found
|
|
2186
|
+
*
|
|
2187
|
+
* @example
|
|
2188
|
+
* ```typescript
|
|
2189
|
+
* // Check attribute hierarchy: endpoint -> controller -> module
|
|
2190
|
+
* const rateLimit = AttributeFactory.getLast(RateLimit, [
|
|
2191
|
+
* moduleMetadata,
|
|
2192
|
+
* controllerMetadata,
|
|
2193
|
+
* endpointMetadata
|
|
2194
|
+
* ])
|
|
2195
|
+
* ```
|
|
2196
|
+
*/
|
|
2197
|
+
static getLast(attribute: ClassAttribute, target: (ModuleMetadata | ControllerMetadata | HandlerMetadata<any>)[]): true | null;
|
|
2198
|
+
static getLast<T extends ZodType>(attribute: ClassSchemaAttribute<T>, target: (ModuleMetadata | ControllerMetadata | HandlerMetadata<any>)[]): z$1.output<T> | null;
|
|
2199
|
+
/**
|
|
2200
|
+
* Checks if an attribute is present on the metadata object.
|
|
2201
|
+
*
|
|
2202
|
+
* @param attribute - The attribute decorator
|
|
2203
|
+
* @param target - The metadata object (module, controller, or handler)
|
|
2204
|
+
* @returns `true` if the attribute is present, `false` otherwise
|
|
2205
|
+
*
|
|
2206
|
+
* @example
|
|
2207
|
+
* ```typescript
|
|
2208
|
+
* if (AttributeFactory.has(Public, controllerMetadata)) {
|
|
2209
|
+
* // Skip authentication
|
|
2210
|
+
* }
|
|
2211
|
+
* ```
|
|
2212
|
+
*/
|
|
2213
|
+
static has(attribute: ClassAttribute, target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>): boolean;
|
|
2214
|
+
static has<T extends ZodType>(attribute: ClassSchemaAttribute<T>, target: ModuleMetadata | ControllerMetadata | HandlerMetadata<any>): boolean;
|
|
2215
|
+
}
|
|
2216
|
+
//#endregion
|
|
2217
|
+
//#region src/factories/endpoint-adapter.factory.d.mts
|
|
2218
|
+
declare class EndpointAdapterFactory {
|
|
2219
|
+
private readonly environment;
|
|
2220
|
+
create(ctx: FactoryContext): Promise<any>;
|
|
2221
|
+
}
|
|
2222
|
+
//#endregion
|
|
2223
|
+
//#region src/factories/http-adapter.factory.d.mts
|
|
2224
|
+
declare class HttpAdapterFactory {
|
|
2225
|
+
private readonly environment;
|
|
2226
|
+
create(ctx: FactoryContext): Promise<any>;
|
|
2227
|
+
}
|
|
2228
|
+
//#endregion
|
|
2229
|
+
//#region src/factories/multipart-adapter.factory.d.mts
|
|
2230
|
+
declare class MultipartAdapterFactory {
|
|
2231
|
+
private readonly environment;
|
|
2232
|
+
create(ctx: FactoryContext): Promise<any>;
|
|
2233
|
+
}
|
|
2234
|
+
//#endregion
|
|
2235
|
+
//#region src/factories/request.factory.d.mts
|
|
2236
|
+
declare class RequestFactory {
|
|
2237
|
+
private readonly environment;
|
|
2238
|
+
create(ctx: FactoryContext): Promise<any>;
|
|
2239
|
+
}
|
|
2240
|
+
//#endregion
|
|
2241
|
+
//#region src/factories/reply.factory.d.mts
|
|
2242
|
+
declare class ReplyFactory {
|
|
2243
|
+
private readonly environment;
|
|
2244
|
+
create(ctx: FactoryContext): Promise<any>;
|
|
2245
|
+
}
|
|
2246
|
+
//#endregion
|
|
2247
|
+
//#region src/factories/stream-adapter.factory.d.mts
|
|
2248
|
+
declare class StreamAdapterFactory {
|
|
2249
|
+
private readonly environment;
|
|
2250
|
+
create(ctx: FactoryContext): Promise<any>;
|
|
2251
|
+
}
|
|
2252
|
+
//#endregion
|
|
2253
|
+
//#region src/factories/xml-stream-adapter.factory.d.mts
|
|
2254
|
+
declare class XmlStreamAdapterFactory {
|
|
2255
|
+
private readonly environment;
|
|
2256
|
+
create(ctx: FactoryContext): Promise<any>;
|
|
2257
|
+
}
|
|
2258
|
+
//#endregion
|
|
2090
2259
|
//#region src/navios.factory.d.mts
|
|
2091
2260
|
/**
|
|
2092
2261
|
* Factory class for creating and configuring Navios applications.
|
|
@@ -2152,5 +2321,5 @@ declare class NaviosFactory {
|
|
|
2152
2321
|
private static registerLoggerConfiguration;
|
|
2153
2322
|
}
|
|
2154
2323
|
//#endregion
|
|
2155
|
-
export {
|
|
2156
|
-
//# sourceMappingURL=index-
|
|
2324
|
+
export { PluginContext as $, EndpointMetadataKey as $t, ControllerResolution as A, isString as At, BadRequestException as B, clc as Bt, ExecutionContextInjectionToken as C, isConstructor as Ct, runWithRequestId as D, isNumber as Dt, getRequestId as E, isNil as Et, ConflictException as F, isLogLevelEnabled as Ft, Multipart as G, extractModuleMetadata as Gt, UseGuards as H, AbstractExecutionContext as Ht, UnauthorizedException as I, isLogLevel as It, Module as J, ControllerMetadata as Jt, MultipartParams as K, getModuleMetadata as Kt, NotFoundException as L, filterLogLevels as Lt, InstanceResolution as M, isUndefined as Mt, InstanceResolverService as N, normalizePath as Nt, setRequestIdEnabled as O, isObject as Ot, MultiInstanceResolution as P, stripEndSlash as Pt, NaviosPlugin as Q, hasControllerMetadata as Qt, InternalServerErrorException as R, LOG_LEVELS as Rt, ExecutionContext as S, addLeadingSlash as St, generateRequestId as T, isFunction as Tt, Stream as U, ModuleMetadata as Ut, HttpException as V, yellow as Vt, StreamParams as W, ModuleMetadataKey as Wt, HttpCode as X, extractControllerMetadata as Xt, ModuleOptions as Y, ControllerMetadataKey as Yt, Header as Z, getControllerMetadata as Zt, NaviosApplication as _, PathImpl as _n, loggerOptionsSchema as _t, RequestFactory as a, EndpointResult as an, OmitIndexSignature as at, MultipartAdapterToken as b, envInt as bn, ConsoleLoggerOptions as bt, EndpointAdapterFactory as c, ConfigProviderOptions as cn, DynamicHandler as ct, ClassSchemaAttribute as d, ConfigService as dn, AbstractHttpAdapterInterface as dt, HandlerMetadata as en, PluginDefinition as et, XmlStreamAdapterToken as f, ConfigServiceOptions as fn, AbstractHttpListenOptions as ft, NaviosOptionsToken as g, Path as gn, LoggerOutput as gt, Reply as h, ConfigServiceInterface as hn, LoggerOptions as ht, ReplyFactory as i, EndpointParams as in, HttpHeader as it, ControllerResolverService as j, isSymbol as jt, GuardRunnerService as k, isPlainObject as kt, AttributeFactory as l, EnvConfigProvider as ln, HandlerResult as lt, Request as m, ConfigServiceToken as mn, Logger as mt, XmlStreamAdapterFactory as n, getEndpointMetadata as nn, ModuleLoaderService as nt, MultipartAdapterFactory as o, Controller as on, CanActivate as ot, StreamAdapterToken as p, ConfigServiceOptionsSchema as pn, AbstractHttpCorsOptions as pt, MultipartResult as q, hasModuleMetadata as qt, StreamAdapterFactory as r, Endpoint as rn, NaviosModule as rt, HttpAdapterFactory as s, ControllerOptions as sn, AbstractHttpHandlerAdapterInterface as st, NaviosFactory as t, getAllEndpointMetadata as tn, ModuleExtension as tt, ClassAttribute as u, provideConfig as un, StaticHandler as ut, NaviosApplicationContextOptions as v, PathImpl2 as vn, LoggerInstance as vt, EndpointAdapterToken as w, isEmpty as wt, HttpAdapterToken as x, envString as xn, LoggerService as xt, NaviosApplicationOptions as y, PathValue as yn, ConsoleLogger as yt, ForbiddenException as z, LogLevel as zt };
|
|
2325
|
+
//# sourceMappingURL=index-BoP0cWT6.d.mts.map
|